From 4670d3efe26e500b4c06b2e436bff11e7b9200ae Mon Sep 17 00:00:00 2001 From: Jeff Sharkey Date: Thu, 26 May 2016 11:02:28 -0600 Subject: [PATCH] Delay PACKAGE_RESTARTED until after data cleared. Some system internals are using the PACKAGE_RESTARTED broadcast to rebind to services, which would fail if the package was still frozen due to a long-running clear data operation. To avoid this, delay both the PACKAGE_RESTARTED and PACKAGE_DATA_CLEARED broadcasts until after the clear operation has finished. Bug: 28964281 Change-Id: I18ac36c39ba90498b1eb0cc495da1f16c24614bf --- .../server/am/ActivityManagerService.java | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 45e76e5b89401..9b3129ba9b91e 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -5419,9 +5419,32 @@ public final class ActivityManagerService extends ActivityManagerNative } } + final int pkgUidF = pkgUid; + final int userIdF = userId; + final IPackageDataObserver localObserver = new IPackageDataObserver.Stub() { + @Override + public void onRemoveCompleted(String packageName, boolean succeeded) + throws RemoteException { + synchronized (ActivityManagerService.this) { + finishForceStopPackageLocked(packageName, pkgUidF); + } + + final Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, + Uri.fromParts("package", packageName, null)); + intent.putExtra(Intent.EXTRA_UID, pkgUidF); + intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(pkgUidF)); + broadcastIntentInPackage("android", Process.SYSTEM_UID, intent, + null, null, 0, null, null, null, null, false, false, userIdF); + + if (observer != null) { + observer.onRemoveCompleted(packageName, succeeded); + } + } + }; + try { // Clear application user data - pm.clearApplicationUserData(packageName, observer, userId); + pm.clearApplicationUserData(packageName, localObserver, userId); synchronized(this) { // Remove all permissions granted from/to this package @@ -5433,12 +5456,6 @@ public final class ActivityManagerService extends ActivityManagerNative inm.removeAutomaticZenRules(packageName); inm.setNotificationPolicyAccessGranted(packageName, false); - Intent intent = new Intent(Intent.ACTION_PACKAGE_DATA_CLEARED, - Uri.fromParts("package", packageName, null)); - intent.putExtra(Intent.EXTRA_UID, pkgUid); - intent.putExtra(Intent.EXTRA_USER_HANDLE, UserHandle.getUserId(pkgUid)); - broadcastIntentInPackage("android", Process.SYSTEM_UID, intent, - null, null, 0, null, null, null, null, false, false, userId); } catch (RemoteException e) { } } finally { @@ -5623,6 +5640,7 @@ public final class ActivityManagerService extends ActivityManagerNative } if (mUserController.isUserRunningLocked(user, 0)) { forceStopPackageLocked(packageName, pkgUid, "from pid " + callingPid); + finishForceStopPackageLocked(packageName, pkgUid); } } } @@ -5814,6 +5832,9 @@ public final class ActivityManagerService extends ActivityManagerNative private void forceStopPackageLocked(final String packageName, int uid, String reason) { forceStopPackageLocked(packageName, UserHandle.getAppId(uid), false, false, true, false, false, UserHandle.getUserId(uid), reason); + } + + private void finishForceStopPackageLocked(final String packageName, int uid) { Intent intent = new Intent(Intent.ACTION_PACKAGE_RESTARTED, Uri.fromParts("package", packageName, null)); if (!mProcessesReady) {