Merge "Dispatch onUserSwitched callbacks on handler thread" into mnc-dev

This commit is contained in:
Amith Yamasani
2015-07-09 17:56:48 +00:00
committed by Android (Google) Code Review

View File

@@ -1353,6 +1353,7 @@ public final class ActivityManagerService extends ActivityManagerNative
static final int FOREGROUND_PROFILE_CHANGED_MSG = 53; static final int FOREGROUND_PROFILE_CHANGED_MSG = 53;
static final int DISPATCH_UIDS_CHANGED_MSG = 54; static final int DISPATCH_UIDS_CHANGED_MSG = 54;
static final int REPORT_TIME_TRACKER_MSG = 55; 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_ACTIVITY_STACK_MSG = 100;
static final int FIRST_BROADCAST_QUEUE_MSG = 200; static final int FIRST_BROADCAST_QUEUE_MSG = 200;
@@ -2014,6 +2015,9 @@ public final class ActivityManagerService extends ActivityManagerNative
AppTimeTracker tracker = (AppTimeTracker)msg.obj; AppTimeTracker tracker = (AppTimeTracker)msg.obj;
tracker.deliverResult(mContext); tracker.deliverResult(mContext);
} break; } 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) { 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) { 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 clearInitializing, boolean clearSwitching) {
boolean unfrozen = false; boolean unfrozen = false;
synchronized (this) { synchronized (this) {
@@ -19946,18 +19950,25 @@ public final class ActivityManagerService extends ActivityManagerNative
} }
} }
if (unfrozen) { if (unfrozen) {
final int N = mUserSwitchObservers.beginBroadcast(); mHandler.removeMessages(REPORT_USER_SWITCH_COMPLETE_MSG);
for (int i=0; i<N; i++) { mHandler.sendMessage(mHandler.obtainMessage(REPORT_USER_SWITCH_COMPLETE_MSG,
try { newUserId, 0));
mUserSwitchObservers.getBroadcastItem(i).onUserSwitchComplete(newUserId);
} catch (RemoteException e) {
}
}
mUserSwitchObservers.finishBroadcast();
} }
stopGuestUserIfBackground(); 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. * Stops the guest user if it has gone to the background.
*/ */