Skip to content

Commit 259d5e5

Browse files
author
Amith Yamasani
committed
Resolve the correct home intent for secondary users
Fix some searches through the Activity stack. This allows SetupWizard to be launched for the second user. Change-Id: Icd306319f511c902557bd9985d80dda228e32d96
1 parent 37ee534 commit 259d5e5

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

services/java/com/android/server/am/ActivityManagerService.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,8 +2146,7 @@ boolean startHomeActivityLocked(int userId, UserStartedState startingUser) {
21462146
intent.addCategory(Intent.CATEGORY_HOME);
21472147
}
21482148
ActivityInfo aInfo =
2149-
intent.resolveActivityInfo(mContext.getPackageManager(),
2150-
STOCK_PM_FLAGS);
2149+
resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
21512150
if (aInfo != null) {
21522151
intent.setComponent(new ComponentName(
21532152
aInfo.applicationInfo.packageName, aInfo.name));
@@ -2170,6 +2169,29 @@ boolean startHomeActivityLocked(int userId, UserStartedState startingUser) {
21702169
return true;
21712170
}
21722171

2172+
private ActivityInfo resolveActivityInfo(Intent intent, int flags, int userId) {
2173+
ActivityInfo ai = null;
2174+
ComponentName comp = intent.getComponent();
2175+
try {
2176+
if (comp != null) {
2177+
ai = AppGlobals.getPackageManager().getActivityInfo(comp, flags, userId);
2178+
} else {
2179+
ResolveInfo info = AppGlobals.getPackageManager().resolveIntent(
2180+
intent,
2181+
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
2182+
flags, userId);
2183+
2184+
if (info != null) {
2185+
ai = info.activityInfo;
2186+
}
2187+
}
2188+
} catch (RemoteException e) {
2189+
// ignore
2190+
}
2191+
2192+
return ai;
2193+
}
2194+
21732195
/**
21742196
* Starts the "new version setup screen" if appropriate.
21752197
*/

services/java/com/android/server/am/ActivityStack.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,11 +422,10 @@ public void handleMessage(Message msg) {
422422
}
423423

424424
final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
425-
// TODO: Don't look for any tasks from other users
426425
int i = mHistory.size()-1;
427426
while (i >= 0) {
428427
ActivityRecord r = mHistory.get(i);
429-
if (!r.finishing && r != notTop) {
428+
if (!r.finishing && r != notTop && r.userId == mCurrentUser) {
430429
return r;
431430
}
432431
i--;
@@ -435,11 +434,10 @@ final ActivityRecord topRunningActivityLocked(ActivityRecord notTop) {
435434
}
436435

437436
final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) {
438-
// TODO: Don't look for any tasks from other users
439437
int i = mHistory.size()-1;
440438
while (i >= 0) {
441439
ActivityRecord r = mHistory.get(i);
442-
if (!r.finishing && !r.delayedResume && r != notTop) {
440+
if (!r.finishing && !r.delayedResume && r != notTop && r.userId == mCurrentUser) {
443441
return r;
444442
}
445443
i--;
@@ -457,12 +455,12 @@ final ActivityRecord topRunningNonDelayedActivityLocked(ActivityRecord notTop) {
457455
* @return Returns the HistoryRecord of the next activity on the stack.
458456
*/
459457
final ActivityRecord topRunningActivityLocked(IBinder token, int taskId) {
460-
// TODO: Don't look for any tasks from other users
461458
int i = mHistory.size()-1;
462459
while (i >= 0) {
463460
ActivityRecord r = mHistory.get(i);
464461
// Note: the taskId check depends on real taskId fields being non-zero
465-
if (!r.finishing && (token != r.appToken) && (taskId != r.task.taskId)) {
462+
if (!r.finishing && (token != r.appToken) && (taskId != r.task.taskId)
463+
&& r.userId == mCurrentUser) {
466464
return r;
467465
}
468466
i--;
@@ -1400,7 +1398,7 @@ final boolean resumeTopActivityLocked(ActivityRecord prev, Bundle options) {
14001398
// Launcher...
14011399
if (mMainStack) {
14021400
ActivityOptions.abort(options);
1403-
return mService.startHomeActivityLocked(0, null);
1401+
return mService.startHomeActivityLocked(mCurrentUser, null);
14041402
}
14051403
}
14061404

0 commit comments

Comments
 (0)