use of com.android.launcher3.util.PackageUserKey in project android_packages_apps_Trebuchet by LineageOS.
the class GridSizeMigrationTask method getValidPackages.
protected static HashSet<String> getValidPackages(Context context) {
// Initialize list of valid packages. This contain all the packages which are already on
// the device and packages which are being installed. Any item which doesn't belong to
// this set is removed.
// Since the loader removes such items anyway, removing these items here doesn't cause
// any extra data loss and gives us more free space on the grid for better migration.
HashSet<String> validPackages = new HashSet<>();
for (PackageInfo info : context.getPackageManager().getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES)) {
validPackages.add(info.packageName);
}
InstallSessionHelper.INSTANCE.get(context).getActiveSessions().keySet().forEach(packageUserKey -> validPackages.add(packageUserKey.mPackageName));
return validPackages;
}
use of com.android.launcher3.util.PackageUserKey in project android_packages_apps_Trebuchet by LineageOS.
the class InstallSessionTracker method onFinished.
@Override
public void onFinished(int sessionId, boolean success) {
// For a finished session, we can't get the session info. So use the
// packageName from our local cache.
SparseArray<PackageUserKey> activeSessions = getActiveSessionMap();
PackageUserKey key = activeSessions.get(sessionId);
activeSessions.remove(sessionId);
if (key != null && key.mPackageName != null) {
String packageName = key.mPackageName;
PackageInstallInfo info = PackageInstallInfo.fromState(success ? STATUS_INSTALLED : STATUS_FAILED, packageName, key.mUser);
mCallback.onPackageStateChanged(info);
if (!success && mInstallerCompat.promiseIconAddedForId(sessionId)) {
mCallback.onSessionFailure(packageName, key.mUser);
// If it is successful, the id is removed in the the package added flow.
mInstallerCompat.removePromiseIconId(sessionId);
}
}
}
use of com.android.launcher3.util.PackageUserKey in project Neo-Launcher by NeoApplications.
the class Workspace method updateNotificationDots.
public void updateNotificationDots(Predicate<PackageUserKey> updatedDots) {
final PackageUserKey packageUserKey = new PackageUserKey(null, null);
Predicate<ItemInfo> matcher = info -> !packageUserKey.updateFromItemInfo(info) || updatedDots.test(packageUserKey);
ItemOperator op = (info, v) -> {
if (info instanceof WorkspaceItemInfo && v instanceof BubbleTextView) {
if (matcher.test(info)) {
((BubbleTextView) v).applyDotState(info, true);
}
} else if (info instanceof FolderInfo && v instanceof FolderIcon) {
FolderInfo fi = (FolderInfo) info;
if (fi.contents.stream().anyMatch(matcher)) {
FolderDotInfo folderDotInfo = new FolderDotInfo();
for (WorkspaceItemInfo si : fi.contents) {
folderDotInfo.addDotInfo(mLauncher.getDotInfoForItem(si));
}
((FolderIcon) v).setDotInfo(folderDotInfo);
}
}
// process all the shortcuts
return false;
};
mapOverItems(op);
Folder folder = Folder.getOpen(mLauncher);
if (folder != null) {
folder.iterateOverItems(op);
}
}
use of com.android.launcher3.util.PackageUserKey in project Neo-Launcher by NeoApplications.
the class WidgetPreviewLoader method removeObsoletePreviews.
/**
* Updates the persistent DB:
* 1. Any preview generated for an old package version is removed
* 2. Any preview for an absent package is removed
* This ensures that we remove entries for packages which changed while the launcher was dead.
*
* @param packageUser if provided, specifies that list only contains previews for the
* given package/user, otherwise the list contains all previews
*/
public void removeObsoletePreviews(ArrayList<? extends ComponentKey> list, @Nullable PackageUserKey packageUser) {
Preconditions.assertWorkerThread();
LongSparseArray<HashSet<String>> validPackages = new LongSparseArray<>();
for (ComponentKey key : list) {
final long userId = mUserManager.getSerialNumberForUser(key.user);
HashSet<String> packages = validPackages.get(userId);
if (packages == null) {
packages = new HashSet<>();
validPackages.put(userId, packages);
}
packages.add(key.componentName.getPackageName());
}
LongSparseArray<HashSet<String>> packagesToDelete = new LongSparseArray<>();
long passedUserId = packageUser == null ? 0 : mUserManager.getSerialNumberForUser(packageUser.mUser);
Cursor c = null;
try {
c = mDb.query(new String[] { CacheDb.COLUMN_USER, CacheDb.COLUMN_PACKAGE, CacheDb.COLUMN_LAST_UPDATED, CacheDb.COLUMN_VERSION }, null, null);
while (c.moveToNext()) {
long userId = c.getLong(0);
String pkg = c.getString(1);
long lastUpdated = c.getLong(2);
long version = c.getLong(3);
if (packageUser != null && (!pkg.equals(packageUser.mPackageName) || userId != passedUserId)) {
// This preview is associated with a different package/user, no need to remove.
continue;
}
HashSet<String> packages = validPackages.get(userId);
if (packages != null && packages.contains(pkg)) {
long[] versions = getPackageVersion(pkg);
if (versions[0] == version && versions[1] == lastUpdated) {
// Every thing checks out
continue;
}
}
// We need to delete this package.
packages = packagesToDelete.get(userId);
if (packages == null) {
packages = new HashSet<>();
packagesToDelete.put(userId, packages);
}
packages.add(pkg);
}
for (int i = 0; i < packagesToDelete.size(); i++) {
long userId = packagesToDelete.keyAt(i);
UserHandle user = mUserManager.getUserForSerialNumber(userId);
for (String pkg : packagesToDelete.valueAt(i)) {
removePackage(pkg, user, userId);
}
}
} catch (SQLException e) {
Log.e(TAG, "Error updating widget previews", e);
} finally {
if (c != null) {
c.close();
}
}
}
use of com.android.launcher3.util.PackageUserKey in project Neo-Launcher by NeoApplications.
the class AppWidgetManagerCompatVL method getAllProviders.
@Override
public List<AppWidgetProviderInfo> getAllProviders(@Nullable PackageUserKey packageUser) {
if (FeatureFlags.GO_DISABLE_WIDGETS) {
return Collections.emptyList();
}
if (packageUser == null) {
ArrayList<AppWidgetProviderInfo> providers = new ArrayList<>();
for (UserHandle user : mUserManager.getUserProfiles()) {
providers.addAll(mAppWidgetManager.getInstalledProvidersForProfile(user));
}
Iterator<AppWidgetProviderInfo> iterator = providers.iterator();
while (iterator.hasNext()) {
if (isBlacklisted(iterator.next().provider.getPackageName())) {
iterator.remove();
}
}
if (FeatureFlags.ENABLE_CUSTOM_WIDGETS) {
providers.addAll(CustomWidgetParser.getCustomWidgets(mContext));
}
return providers;
}
if (isBlacklisted(packageUser.mPackageName)) {
return Collections.emptyList();
}
// Only get providers for the given package/user.
List<AppWidgetProviderInfo> providers = new ArrayList<>(mAppWidgetManager.getInstalledProvidersForProfile(packageUser.mUser));
Iterator<AppWidgetProviderInfo> iterator = providers.iterator();
while (iterator.hasNext()) {
if (!iterator.next().provider.getPackageName().equals(packageUser.mPackageName)) {
iterator.remove();
}
}
if (FeatureFlags.ENABLE_CUSTOM_WIDGETS && Process.myUserHandle().equals(packageUser.mUser) && mContext.getPackageName().equals(packageUser.mPackageName)) {
providers.addAll(CustomWidgetParser.getCustomWidgets(mContext));
}
return providers;
}
Aggregations