diff options
author | Amith Yamasani <yamasani@google.com> | 2015-07-08 15:50:13 -0700 |
---|---|---|
committer | Amith Yamasani <yamasani@google.com> | 2015-07-09 10:40:44 -0700 |
commit | f64cb1803819d0f7f194adc6d1934e73c694d791 (patch) | |
tree | 8d53f79c1a0d4732c44bb9ac740002a62a522504 /services | |
parent | 4f5630e51d03980e80fde93154f5a0302c8179a2 (diff) | |
download | frameworks_base-f64cb1803819d0f7f194adc6d1934e73c694d791.zip frameworks_base-f64cb1803819d0f7f194adc6d1934e73c694d791.tar.gz frameworks_base-f64cb1803819d0f7f194adc6d1934e73c694d791.tar.bz2 |
Dispatch onUserSwitched callbacks on handler thread
This avoids multiple threads calling beginBroadcast on the observers
list.
Bug: 22339693
Change-Id: I78a154415ccd17c9460b25589d46dadcdb850941
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/am/ActivityManagerService.java | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java index 4217c59..88a0c8f 100644 --- a/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/services/core/java/com/android/server/am/ActivityManagerService.java @@ -1353,6 +1353,7 @@ public final class ActivityManagerService extends ActivityManagerNative static final int FOREGROUND_PROFILE_CHANGED_MSG = 53; static final int DISPATCH_UIDS_CHANGED_MSG = 54; static final int REPORT_TIME_TRACKER_MSG = 55; + static final int REPORT_USER_SWITCH_COMPLETE_MSG = 56; static final int FIRST_ACTIVITY_STACK_MSG = 100; static final int FIRST_BROADCAST_QUEUE_MSG = 200; @@ -2014,6 +2015,9 @@ public final class ActivityManagerService extends ActivityManagerNative AppTimeTracker tracker = (AppTimeTracker)msg.obj; tracker.deliverResult(mContext); } break; + case REPORT_USER_SWITCH_COMPLETE_MSG: { + dispatchUserSwitchComplete(msg.arg1); + } break; } } }; @@ -19910,7 +19914,7 @@ public final class ActivityManagerService extends ActivityManagerNative } } - completeSwitchAndInitalize(uss, newUserId, true, false); + completeSwitchAndInitialize(uss, newUserId, true, false); } void moveUserToForeground(UserState uss, int oldUserId, int newUserId) { @@ -19926,10 +19930,10 @@ public final class ActivityManagerService extends ActivityManagerNative } void continueUserSwitch(UserState uss, int oldUserId, int newUserId) { - completeSwitchAndInitalize(uss, newUserId, false, true); + completeSwitchAndInitialize(uss, newUserId, false, true); } - void completeSwitchAndInitalize(UserState uss, int newUserId, + void completeSwitchAndInitialize(UserState uss, int newUserId, boolean clearInitializing, boolean clearSwitching) { boolean unfrozen = false; synchronized (this) { @@ -19946,18 +19950,25 @@ public final class ActivityManagerService extends ActivityManagerNative } } if (unfrozen) { - final int N = mUserSwitchObservers.beginBroadcast(); - for (int i=0; i<N; i++) { - try { - mUserSwitchObservers.getBroadcastItem(i).onUserSwitchComplete(newUserId); - } catch (RemoteException e) { - } - } - mUserSwitchObservers.finishBroadcast(); + mHandler.removeMessages(REPORT_USER_SWITCH_COMPLETE_MSG); + mHandler.sendMessage(mHandler.obtainMessage(REPORT_USER_SWITCH_COMPLETE_MSG, + newUserId, 0)); } stopGuestUserIfBackground(); } + /** Called on handler thread */ + void dispatchUserSwitchComplete(int userId) { + final int observerCount = mUserSwitchObservers.beginBroadcast(); + for (int i = 0; i < observerCount; i++) { + try { + mUserSwitchObservers.getBroadcastItem(i).onUserSwitchComplete(userId); + } catch (RemoteException e) { + } + } + mUserSwitchObservers.finishBroadcast(); + } + /** * Stops the guest user if it has gone to the background. */ |