Merge "Clear the uninstalled package data in AppSearch." into sc-dev am: 5c86c0c10e am: 69d47118bd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14837874

Change-Id: Id337bd69896acd55a12609e5319e674e3dde9547
This commit is contained in:
Terry Wang
2021-06-18 07:33:23 +00:00
committed by Automerger Merge Worker
2 changed files with 31 additions and 7 deletions

View File

@@ -63,6 +63,7 @@ import com.android.server.appsearch.external.localstorage.stats.CallStats;
import com.android.server.appsearch.stats.LoggerInstanceManager;
import com.android.server.appsearch.stats.PlatformLogger;
import com.android.server.appsearch.util.PackageUtil;
import com.android.server.appsearch.visibilitystore.VisibilityStore;
import com.android.server.usage.StorageStatsManagerLocal;
import com.android.server.usage.StorageStatsManagerLocal.StorageStatsAugmenter;
@@ -218,11 +219,12 @@ public class AppSearchManagerService extends SystemService {
UserHandle userHandle = UserHandle.getUserHandleForUid(uid);
try {
if (isUserLocked(userHandle)) {
//TODO(b/186151459) clear the uninstalled package data when user is unlocked.
// We cannot access a locked user's directry and remove package data from it.
// We should remove those uninstalled package data when the user is unlocking.
return;
}
// Only clear the package's data if AppSearch exists for this user.
if (ImplInstanceManager.getAppSearchDir(userHandle).exists()) {
// Only clear the package's data if AppSearch exists for this user.
PlatformLogger logger = mLoggerInstanceManager.getOrCreatePlatformLogger(mContext,
userHandle, AppSearchConfig.getInstance(EXECUTOR));
AppSearchImpl impl = mImplInstanceManager.getOrCreateAppSearchImpl(mContext,
@@ -239,9 +241,34 @@ public class AppSearchManagerService extends SystemService {
@Override
public void onUserUnlocking(@NonNull TargetUser user) {
Objects.requireNonNull(user);
UserHandle userHandle = user.getUserHandle();
synchronized (mUnlockedUsersLocked) {
mUnlockedUsersLocked.add(user.getUserHandle());
mUnlockedUsersLocked.add(userHandle);
}
EXECUTOR.execute(() -> {
try {
// Only clear the package's data if AppSearch exists for this user.
if (ImplInstanceManager.getAppSearchDir(userHandle).exists()) {
PlatformLogger logger = mLoggerInstanceManager.getOrCreatePlatformLogger(
mContext, userHandle, AppSearchConfig.getInstance(EXECUTOR));
AppSearchImpl impl = mImplInstanceManager.getOrCreateAppSearchImpl(mContext,
userHandle, logger);
List<PackageInfo> installedPackageInfos = mContext
.createContextAsUser(userHandle, /*flags=*/0)
.getPackageManager()
.getInstalledPackages(/*flags=*/0);
Set<String> packagesToKeep = new ArraySet<>(installedPackageInfos.size());
for (int i = 0; i < installedPackageInfos.size(); i++) {
packagesToKeep.add(installedPackageInfos.get(i).packageName);
}
packagesToKeep.add(VisibilityStore.PACKAGE_NAME);
//TODO(b/145759910) clear visibility setting for package.
impl.prunePackageData(packagesToKeep);
}
} catch (Throwable t) {
Log.e(TAG, "Unable to prune packages for " + user, t);
}
});
}
@Override
@@ -1255,9 +1282,6 @@ public class AppSearchManagerService extends SystemService {
* @param callingUid The actual uid of the caller as determined by Binder.
* @return the user handle that the call should run as. Will always be a concrete user.
*/
// TODO(b/173553485) verifying that the caller has permission to access target user's data
// TODO(b/173553485) Handle ACTION_USER_REMOVED broadcast
// TODO(b/173553485) Implement SystemService.onUserStopping()
@NonNull
private UserHandle handleIncomingUser(@NonNull UserHandle requestedUser, int callingUid) {
int callingPid = Binder.getCallingPid();

View File

@@ -76,7 +76,7 @@ public class VisibilityStore {
* These cannot have any of the special characters used by AppSearchImpl (e.g. {@code
* AppSearchImpl#PACKAGE_DELIMITER} or {@code AppSearchImpl#DATABASE_DELIMITER}.
*/
@VisibleForTesting public static final String PACKAGE_NAME = "VS#Pkg";
public static final String PACKAGE_NAME = "VS#Pkg";
@VisibleForTesting public static final String DATABASE_NAME = "VS#Db";