Commit cadd6987 authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Fix onPackageAdded callback

parent 38c0b153
Pipeline #156388 passed with stage
in 8 minutes and 34 seconds
......@@ -32,6 +32,9 @@ import foundation.e.blisslauncher.BlissLauncher;
import foundation.e.blisslauncher.core.IconsHandler;
import foundation.e.blisslauncher.core.database.model.ApplicationItem;
import foundation.e.blisslauncher.features.launcher.AppProvider;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -138,4 +141,48 @@ public class AppUtils {
return null;
}
public static List<ApplicationItem> createAppItems(Context context, String packageName, UserHandle userHandle) {
List<ApplicationItem> items = new ArrayList<>();
if (AppProvider.DISABLED_PACKAGES.contains(packageName)) {
return items;
}
if (sLauncherApps == null) {
sLauncherApps = (LauncherApps) context.getSystemService(
Context.LAUNCHER_APPS_SERVICE);
}
IconsHandler iconsHandler = BlissLauncher.getApplication(context).getIconsHandler();
List<LauncherActivityInfo> matches = sLauncherApps.getActivityList(
packageName,
userHandle.getRealHandle());
if (matches == null || matches.size() == 0) {
return items;
}
for (LauncherActivityInfo info : matches) {
if (info != null) {
ApplicationItem applicationItem = new ApplicationItem(info,
userHandle);
ApplicationInfo appInfo = info.getApplicationInfo();
applicationItem.icon = iconsHandler.getDrawableIconForPackage(
info, userHandle);
String componentName = info.getComponentName().toString();
applicationItem.appType = iconsHandler.isClock(componentName)
? ApplicationItem.TYPE_CLOCK : (iconsHandler.isCalendar(
componentName)
? ApplicationItem.TYPE_CALENDAR : ApplicationItem.TYPE_DEFAULT);
applicationItem.title = info.getLabel().toString();
applicationItem.container = Constants.CONTAINER_DESKTOP;
if (appInfo.packageName.equalsIgnoreCase("com.generalmagic.magicearth")) {
applicationItem.title = "Maps";
}
applicationItem.packageName = appInfo.packageName;
items.add(applicationItem);
}
}
return items;
}
}
\ No newline at end of file
package foundation.e.blisslauncher.core.utils;
public interface FlagOp {
FlagOp NO_OP = i -> i;
int apply(int flags);
static FlagOp addFlag(int flag) {
return i -> i | flag;
}
static FlagOp removeFlag(int flag) {
return i -> i & ~flag;
}
}
......@@ -19,6 +19,8 @@ package foundation.e.blisslauncher.features.test;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.ShortcutInfo;
import android.os.Handler;
import android.os.HandlerThread;
......@@ -30,12 +32,20 @@ import android.util.Pair;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import foundation.e.blisslauncher.core.UserManagerCompat;
import foundation.e.blisslauncher.core.Utilities;
import foundation.e.blisslauncher.core.database.model.ApplicationItem;
import foundation.e.blisslauncher.core.database.model.LauncherItem;
import foundation.e.blisslauncher.core.executors.MainThreadExecutor;
import foundation.e.blisslauncher.core.utils.AppUtils;
import foundation.e.blisslauncher.core.utils.Constants;
import foundation.e.blisslauncher.core.utils.FlagOp;
import foundation.e.blisslauncher.core.utils.ItemInfoMatcher;
import foundation.e.blisslauncher.core.utils.Preconditions;
import foundation.e.blisslauncher.features.shortcuts.InstallShortcutReceiver;
......@@ -91,7 +101,18 @@ public class LauncherModel extends BroadcastReceiver implements
@Override
public void onPackageAdded(String packageName, UserHandle user) {
final Context context = mApp.getContext();
FlagOp flagOp = FlagOp.NO_OP;
final HashSet<String> packageSet = new HashSet<>(Arrays.asList(packageName));
ItemInfoMatcher matcher = ItemInfoMatcher.ofPackages(packageSet, user);
final List<LauncherItem> added = new ArrayList<>();
added.addAll(AppUtils.createAppItems(context,
packageName,
new foundation.e.blisslauncher.core.utils.UserHandle(UserManagerCompat
.getInstance(context).getSerialNumberForUser(user), user)
));
mUiExecutor.execute(() -> mCallbacks.get().bindAppsAdded(added));
}
@Override
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment