Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 10a25c0a authored by Kenny Root's avatar Kenny Root Committed by Android (Google) Code Review
Browse files

Merge "Remove keystore entries when app data cleared" into jb-mr2-dev

parents 058835e3 6fd1c85d
Loading
Loading
Loading
Loading
+45 −23
Original line number Diff line number Diff line
@@ -8694,15 +8694,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        if (outInfo != null) {
            // A user ID was deleted here. Go through all users and remove it
            // from KeyStore.
            final int appId = outInfo.removedAppId;
            if (appId != -1) {
                final KeyStore keyStore = KeyStore.getInstance();
                if (keyStore != null) {
                    for (final int userId : sUserManager.getUserIds()) {
                        keyStore.clearUid(UserHandle.getUid(userId, appId));
                    }
                }
            }
            removeKeystoreDataIfNeeded(UserHandle.USER_ALL, outInfo.removedAppId);
        }
    }

@@ -8862,6 +8854,7 @@ public class PackageManagerService extends IPackageManager.Stub {
                outInfo.removedUsers = new int[] {removeUser};
            }
            mInstaller.clearUserData(packageName, removeUser);
            removeKeystoreDataIfNeeded(removeUser, appId);
            schedulePackageCleaning(packageName, removeUser, false);
            return true;
        }
@@ -9014,6 +9007,7 @@ public class PackageManagerService extends IPackageManager.Stub {
        }
        PackageParser.Package p;
        boolean dataOnly = false;
        final int appId;
        synchronized (mPackages) {
            p = mPackages.get(packageName);
            if (p == null) {
@@ -9025,8 +9019,6 @@ public class PackageManagerService extends IPackageManager.Stub {
                }
                p = ps.pkg;
            }
        }

            if (!dataOnly) {
                // need to check this only for fully installed applications
                if (p == null) {
@@ -9039,15 +9031,45 @@ public class PackageManagerService extends IPackageManager.Stub {
                    return false;
                }
            }
            if (p != null && p.applicationInfo != null) {
                appId = p.applicationInfo.uid;
            } else {
                appId = -1;
            }
        }
        int retCode = mInstaller.clearUserData(packageName, userId);
        if (retCode < 0) {
            Slog.w(TAG, "Couldn't remove cache files for package: "
                    + packageName);
            return false;
        }
        removeKeystoreDataIfNeeded(userId, appId);
        return true;
    }

    /**
     * Remove entries from the keystore daemon. Will only remove it if the
     * {@code appId} is valid.
     */
    private static void removeKeystoreDataIfNeeded(int userId, int appId) {
        if (appId < 0) {
            return;
        }

        final KeyStore keyStore = KeyStore.getInstance();
        if (keyStore != null) {
            if (userId == UserHandle.USER_ALL) {
                for (final int individual : sUserManager.getUserIds()) {
                    keyStore.clearUid(UserHandle.getUid(individual, appId));
                }
            } else {
                keyStore.clearUid(UserHandle.getUid(userId, appId));
            }
        } else {
            Slog.w(TAG, "Could not contact keystore to clear entries for app id " + appId);
        }
    }

    public void deleteApplicationCacheFiles(final String packageName,
            final IPackageDataObserver observer) {
        mContext.enforceCallingOrSelfPermission(