Search in sources :

Example 16 with PackageWithUser

use of com.android.server.pm.ShortcutUser.PackageWithUser in project android_frameworks_base by DirtyUnicorns.

the class ShortcutLauncher method pinShortcuts.

public void pinShortcuts(@UserIdInt int packageUserId, @NonNull String packageName, @NonNull List<String> ids) {
    final ShortcutPackage packageShortcuts = mShortcutUser.getPackageShortcutsIfExists(packageName);
    if (packageShortcuts == null) {
        // No need to instantiate.
        return;
    }
    final PackageWithUser pu = PackageWithUser.of(packageUserId, packageName);
    final int idSize = ids.size();
    if (idSize == 0) {
        mPinnedShortcuts.remove(pu);
    } else {
        final ArraySet<String> prevSet = mPinnedShortcuts.get(pu);
        // Pin shortcuts.  Make sure only pin the ones that were visible to the caller.
        // i.e. a non-dynamic, pinned shortcut by *other launchers* shouldn't be pinned here.
        final ArraySet<String> newSet = new ArraySet<>();
        for (int i = 0; i < idSize; i++) {
            final String id = ids.get(i);
            final ShortcutInfo si = packageShortcuts.findShortcutById(id);
            if (si == null) {
                continue;
            }
            if (si.isDynamic() || si.isManifestShortcut() || (prevSet != null && prevSet.contains(id))) {
                newSet.add(id);
            }
        }
        mPinnedShortcuts.put(pu, newSet);
    }
    packageShortcuts.refreshPinnedFlags();
}
Also used : ArraySet(android.util.ArraySet) ShortcutInfo(android.content.pm.ShortcutInfo) PackageWithUser(com.android.server.pm.ShortcutUser.PackageWithUser)

Example 17 with PackageWithUser

use of com.android.server.pm.ShortcutUser.PackageWithUser in project android_frameworks_base by DirtyUnicorns.

the class ShortcutLauncher method onRestoreBlocked.

/**
     * Called when the new package can't receive the backup, due to signature or version mismatch.
     */
@Override
protected void onRestoreBlocked() {
    final ArrayList<PackageWithUser> pinnedPackages = new ArrayList<>(mPinnedShortcuts.keySet());
    mPinnedShortcuts.clear();
    for (int i = pinnedPackages.size() - 1; i >= 0; i--) {
        final PackageWithUser pu = pinnedPackages.get(i);
        final ShortcutPackage p = mShortcutUser.getPackageShortcutsIfExists(pu.packageName);
        if (p != null) {
            p.refreshPinnedFlags();
        }
    }
}
Also used : PackageWithUser(com.android.server.pm.ShortcutUser.PackageWithUser) ArrayList(java.util.ArrayList)

Example 18 with PackageWithUser

use of com.android.server.pm.ShortcutUser.PackageWithUser in project android_frameworks_base by DirtyUnicorns.

the class ShortcutService method checkPackageChanges.

/**
     * Called when a user is unlocked.
     * - Check all known packages still exist, and otherwise perform cleanup.
     * - If a package still exists, check the version code.  If it's been updated, may need to
     * update timestamps of its shortcuts.
     */
@VisibleForTesting
void checkPackageChanges(@UserIdInt int ownerUserId) {
    if (DEBUG) {
        Slog.d(TAG, "checkPackageChanges() ownerUserId=" + ownerUserId);
    }
    if (injectIsSafeModeEnabled()) {
        Slog.i(TAG, "Safe mode, skipping checkPackageChanges()");
        return;
    }
    final long start = injectElapsedRealtime();
    try {
        final ArrayList<PackageWithUser> gonePackages = new ArrayList<>();
        synchronized (mLock) {
            final ShortcutUser user = getUserShortcutsLocked(ownerUserId);
            // Find packages that have been uninstalled.
            user.forAllPackageItems(spi -> {
                if (spi.getPackageInfo().isShadow()) {
                    return;
                }
                if (!isPackageInstalled(spi.getPackageName(), spi.getPackageUserId())) {
                    if (DEBUG) {
                        Slog.d(TAG, "Uninstalled: " + spi.getPackageName() + " user " + spi.getPackageUserId());
                    }
                    gonePackages.add(PackageWithUser.of(spi));
                }
            });
            if (gonePackages.size() > 0) {
                for (int i = gonePackages.size() - 1; i >= 0; i--) {
                    final PackageWithUser pu = gonePackages.get(i);
                    cleanUpPackageLocked(pu.packageName, ownerUserId, pu.userId, /* appStillExists = */
                    false);
                }
            }
            rescanUpdatedPackagesLocked(ownerUserId, user.getLastAppScanTime(), /* forceRescan=*/
            false);
        }
    } finally {
        logDurationStat(Stats.CHECK_PACKAGE_CHANGES, start);
    }
    verifyStates();
}
Also used : PackageWithUser(com.android.server.pm.ShortcutUser.PackageWithUser) ArrayList(java.util.ArrayList) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Example 19 with PackageWithUser

use of com.android.server.pm.ShortcutUser.PackageWithUser in project android_frameworks_base by ResurrectionRemix.

the class ShortcutLauncher method pinShortcuts.

public void pinShortcuts(@UserIdInt int packageUserId, @NonNull String packageName, @NonNull List<String> ids) {
    final ShortcutPackage packageShortcuts = mShortcutUser.getPackageShortcutsIfExists(packageName);
    if (packageShortcuts == null) {
        // No need to instantiate.
        return;
    }
    final PackageWithUser pu = PackageWithUser.of(packageUserId, packageName);
    final int idSize = ids.size();
    if (idSize == 0) {
        mPinnedShortcuts.remove(pu);
    } else {
        final ArraySet<String> prevSet = mPinnedShortcuts.get(pu);
        // Pin shortcuts.  Make sure only pin the ones that were visible to the caller.
        // i.e. a non-dynamic, pinned shortcut by *other launchers* shouldn't be pinned here.
        final ArraySet<String> newSet = new ArraySet<>();
        for (int i = 0; i < idSize; i++) {
            final String id = ids.get(i);
            final ShortcutInfo si = packageShortcuts.findShortcutById(id);
            if (si == null) {
                continue;
            }
            if (si.isDynamic() || si.isManifestShortcut() || (prevSet != null && prevSet.contains(id))) {
                newSet.add(id);
            }
        }
        mPinnedShortcuts.put(pu, newSet);
    }
    packageShortcuts.refreshPinnedFlags();
}
Also used : ArraySet(android.util.ArraySet) ShortcutInfo(android.content.pm.ShortcutInfo) PackageWithUser(com.android.server.pm.ShortcutUser.PackageWithUser)

Example 20 with PackageWithUser

use of com.android.server.pm.ShortcutUser.PackageWithUser in project android_frameworks_base by ResurrectionRemix.

the class ShortcutService method checkPackageChanges.

/**
     * Called when a user is unlocked.
     * - Check all known packages still exist, and otherwise perform cleanup.
     * - If a package still exists, check the version code.  If it's been updated, may need to
     * update timestamps of its shortcuts.
     */
@VisibleForTesting
void checkPackageChanges(@UserIdInt int ownerUserId) {
    if (DEBUG) {
        Slog.d(TAG, "checkPackageChanges() ownerUserId=" + ownerUserId);
    }
    if (injectIsSafeModeEnabled()) {
        Slog.i(TAG, "Safe mode, skipping checkPackageChanges()");
        return;
    }
    final long start = injectElapsedRealtime();
    try {
        final ArrayList<PackageWithUser> gonePackages = new ArrayList<>();
        synchronized (mLock) {
            final ShortcutUser user = getUserShortcutsLocked(ownerUserId);
            // Find packages that have been uninstalled.
            user.forAllPackageItems(spi -> {
                if (spi.getPackageInfo().isShadow()) {
                    return;
                }
                if (!isPackageInstalled(spi.getPackageName(), spi.getPackageUserId())) {
                    if (DEBUG) {
                        Slog.d(TAG, "Uninstalled: " + spi.getPackageName() + " user " + spi.getPackageUserId());
                    }
                    gonePackages.add(PackageWithUser.of(spi));
                }
            });
            if (gonePackages.size() > 0) {
                for (int i = gonePackages.size() - 1; i >= 0; i--) {
                    final PackageWithUser pu = gonePackages.get(i);
                    cleanUpPackageLocked(pu.packageName, ownerUserId, pu.userId, /* appStillExists = */
                    false);
                }
            }
            rescanUpdatedPackagesLocked(ownerUserId, user.getLastAppScanTime(), /* forceRescan=*/
            false);
        }
    } finally {
        logDurationStat(Stats.CHECK_PACKAGE_CHANGES, start);
    }
    verifyStates();
}
Also used : PackageWithUser(com.android.server.pm.ShortcutUser.PackageWithUser) ArrayList(java.util.ArrayList) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

PackageWithUser (com.android.server.pm.ShortcutUser.PackageWithUser)20 ArrayList (java.util.ArrayList)8 ShortcutInfo (android.content.pm.ShortcutInfo)4 ArraySet (android.util.ArraySet)4 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)4