Prevent crashes when user is stopping

Added defensive checks to prevent sporadic crashes due to various race
conditions when user is stopped:
* onPackageBroadcastReceived - moved the check inside the synchronized block.
  This guarantees that onUserStopped (that also grabs mLock) is not yet
  called and we can proceed.
* stopListening - Since it is invoked before onUserStopped callback, we can call
  ensureGroupStateLoadedLocked(userId, false). The state will be subsequently cleaned
  up in the onUserStopped.

Test: manual user switching + SecondaryUserContentResolverTest and
      ManagedUserContentResolverTest
Fixes: 37472670
Fixes: 36890589

Change-Id: I44d0a0c004e9c3e6cfb37a24cb8a5b6f20a42f13
This commit is contained in:
Fyodor Kupolov
2017-05-05 14:07:50 -07:00
parent bd886e52b8
commit 1406fb72ec

View File

@@ -373,11 +373,6 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
private void onPackageBroadcastReceived(Intent intent, int userId) {
if (!mUserManager.isUserUnlockingOrUnlocked(userId) ||
isProfileWithLockedParent(userId)) {
return;
}
final String action = intent.getAction();
boolean added = false;
boolean changed = false;
@@ -408,7 +403,11 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
}
synchronized (mLock) {
ensureGroupStateLoadedLocked(userId);
if (!mUserManager.isUserUnlockingOrUnlocked(userId) ||
isProfileWithLockedParent(userId)) {
return;
}
ensureGroupStateLoadedLocked(userId, /* enforceUserUnlockingOrUnlocked */ false);
Bundle extras = intent.getExtras();
@@ -844,7 +843,7 @@ class AppWidgetServiceImpl extends IAppWidgetService.Stub implements WidgetBacku
mSecurityPolicy.enforceCallFromPackage(callingPackage);
synchronized (mLock) {
ensureGroupStateLoadedLocked(userId);
ensureGroupStateLoadedLocked(userId, /* enforceUserUnlockingOrUnlocked */ false);
// NOTE: The lookup is enforcing security across users by making
// sure the caller can only access hosts it owns.