Set calling user as intent extra to indicate intent resolver edge case
Instead of relying on the user hint in the intent, we now explicitly set the calling user as an intent extra. Fixes: 149741820 Test: atest ChooserActivityTest Test: atest ResolverActivityTest Test: manual Change-Id: Iaa37fc1330abbb419035d899fad166afc53aaea8
This commit is contained in:
@@ -18,6 +18,7 @@ package com.android.internal.app;
|
||||
|
||||
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
|
||||
|
||||
import static com.android.internal.app.ResolverActivity.EXTRA_CALLING_USER;
|
||||
import static com.android.internal.app.ResolverActivity.EXTRA_SELECTED_PROFILE;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
@@ -246,6 +247,7 @@ public class IntentForwarderActivity extends Activity {
|
||||
int selectedProfile = findSelectedProfile(className);
|
||||
sanitizeIntent(intentReceived);
|
||||
intentReceived.putExtra(EXTRA_SELECTED_PROFILE, selectedProfile);
|
||||
intentReceived.putExtra(EXTRA_CALLING_USER, UserHandle.of(callingUserId));
|
||||
startActivityAsCaller(intentReceived, null, null, false, userId);
|
||||
finish();
|
||||
}
|
||||
|
||||
@@ -184,6 +184,18 @@ public class ResolverActivity extends Activity implements
|
||||
static final String EXTRA_SELECTED_PROFILE =
|
||||
"com.android.internal.app.ResolverActivity.EXTRA_SELECTED_PROFILE";
|
||||
|
||||
/**
|
||||
* {@link UserHandle} extra to indicate the user of the user that the starting intent
|
||||
* originated from.
|
||||
* <p>This is not necessarily the same as {@link #getUserId()} or {@link UserHandle#myUserId()},
|
||||
* as there are edge cases when the intent resolver is launched in the other profile.
|
||||
* For example, when we have 0 resolved apps in current profile and multiple resolved
|
||||
* apps in the other profile, opening a link from the current profile launches the intent
|
||||
* resolver in the other one. b/148536209 for more info.
|
||||
*/
|
||||
static final String EXTRA_CALLING_USER =
|
||||
"com.android.internal.app.ResolverActivity.EXTRA_CALLING_USER";
|
||||
|
||||
static final int PROFILE_PERSONAL = AbstractMultiProfilePagerAdapter.PROFILE_PERSONAL;
|
||||
static final int PROFILE_WORK = AbstractMultiProfilePagerAdapter.PROFILE_WORK;
|
||||
|
||||
@@ -470,17 +482,20 @@ public class ResolverActivity extends Activity implements
|
||||
// the intent resolver is started in the other profile. Since this is the only case when
|
||||
// this happens, we check for it here and set the current profile's tab.
|
||||
int selectedProfile = getCurrentProfile();
|
||||
UserHandle intentUser = UserHandle.of(getLaunchingUserId());
|
||||
UserHandle intentUser = getIntent().hasExtra(EXTRA_CALLING_USER)
|
||||
? getIntent().getParcelableExtra(EXTRA_CALLING_USER)
|
||||
: getUser();
|
||||
if (!getUser().equals(intentUser)) {
|
||||
if (getPersonalProfileUserHandle().equals(intentUser)) {
|
||||
selectedProfile = PROFILE_PERSONAL;
|
||||
} else if (getWorkProfileUserHandle().equals(intentUser)) {
|
||||
selectedProfile = PROFILE_WORK;
|
||||
}
|
||||
}
|
||||
int selectedProfileExtra = getSelectedProfileExtra();
|
||||
if (selectedProfileExtra != -1) {
|
||||
selectedProfile = selectedProfileExtra;
|
||||
} else {
|
||||
int selectedProfileExtra = getSelectedProfileExtra();
|
||||
if (selectedProfileExtra != -1) {
|
||||
selectedProfile = selectedProfileExtra;
|
||||
}
|
||||
}
|
||||
// We only show the default app for the profile of the current user. The filterLastUsed
|
||||
// flag determines whether to show a default app and that app is not shown in the
|
||||
@@ -535,22 +550,6 @@ public class ResolverActivity extends Activity implements
|
||||
return selectedProfile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user id of the user that the starting intent originated from.
|
||||
* <p>This is not necessarily equal to {@link #getUserId()} or {@link UserHandle#myUserId()},
|
||||
* as there are edge cases when the intent resolver is launched in the other profile.
|
||||
* For example, when we have 0 resolved apps in current profile and multiple resolved apps
|
||||
* in the other profile, opening a link from the current profile launches the intent resolver
|
||||
* in the other one. b/148536209 for more info.
|
||||
*/
|
||||
private int getLaunchingUserId() {
|
||||
int contentUserHint = getIntent().getContentUserHint();
|
||||
if (contentUserHint == UserHandle.USER_CURRENT) {
|
||||
return UserHandle.myUserId();
|
||||
}
|
||||
return contentUserHint;
|
||||
}
|
||||
|
||||
protected @Profile int getCurrentProfile() {
|
||||
return (UserHandle.myUserId() == UserHandle.USER_SYSTEM ? PROFILE_PERSONAL : PROFILE_WORK);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user