Fixing tabOwnerUserHandle population.

b/266175872 points out the case where personal handle
may be populated differently than the callingUserId.
In such cases tabOwnerUserHandle should be in sync with
the current process' userHandle rather than the callingUserId.

Bug: b/266175872
Test: atest ResolverActivityTest
Change-Id: Ia3521a8878d6e7b7de891ef4f4b09c5766d12a74
This commit is contained in:
Himanshu Gupta
2023-02-06 16:51:03 +00:00
parent 3cc5ce80ae
commit 14dd80579a

View File

@@ -739,6 +739,11 @@ public class ResolverActivity extends Activity implements
}
protected UserHandle fetchPersonalProfileUserHandle() {
// ActivityManager.getCurrentUser() refers to the current Foreground user. When clone/work
// profile is active, we always make the personal tab from the foreground user.
// Outside profiles, current foreground user is potentially the same as the sharesheet
// process's user (UserHandle.myUserId()), so we continue to create personal tab with the
// current foreground user.
mPersonalProfileUserHandle = UserHandle.of(ActivityManager.getCurrentUser());
return mPersonalProfileUserHandle;
}
@@ -768,10 +773,11 @@ public class ResolverActivity extends Activity implements
}
private UserHandle fetchTabOwnerUserHandleForLaunch() {
if (isLaunchedAsCloneProfile()) {
return getPersonalProfileUserHandle();
}
return mLaunchedFromUserHandle;
// If we are in work profile's process, return WorkProfile user as owner, otherwise we
// always return PersonalProfile user as owner
return UserHandle.of(UserHandle.myUserId()).equals(getWorkProfileUserHandle())
? getWorkProfileUserHandle()
: getPersonalProfileUserHandle();
}
private boolean hasWorkProfile() {