diff --git a/core/java/com/android/internal/app/ChooserActivity.java b/core/java/com/android/internal/app/ChooserActivity.java index 8b0dd8ae18ce9..1f25feb1f0287 100644 --- a/core/java/com/android/internal/app/ChooserActivity.java +++ b/core/java/com/android/internal/app/ChooserActivity.java @@ -171,17 +171,6 @@ public class ChooserActivity extends ResolverActivity implements public static final String EXTRA_PRIVATE_RETAIN_IN_ON_STOP = "com.android.internal.app.ChooserActivity.EXTRA_PRIVATE_RETAIN_IN_ON_STOP"; - /** - * Integer extra to indicate which profile should be automatically selected. - *
Can only be used if there is a work profile. - *
Possible values can be either {@link #PROFILE_PERSONAL} or {@link #PROFILE_WORK}.
- */
- static final String EXTRA_SELECTED_PROFILE =
- "com.android.internal.app.ChooserActivity.EXTRA_SELECTED_PROFILE";
-
- static final int PROFILE_PERSONAL = AbstractMultiProfilePagerAdapter.PROFILE_PERSONAL;
- static final int PROFILE_WORK = AbstractMultiProfilePagerAdapter.PROFILE_WORK;
-
private static final String PREF_NUM_SHEET_EXPANSIONS = "pref_num_sheet_expansions";
private static final String CHIP_LABEL_METADATA_KEY = "android.service.chooser.chip_label";
@@ -928,15 +917,8 @@ public class ChooserActivity extends ResolverActivity implements
}
private int findSelectedProfile() {
- int selectedProfile;
- if (getIntent().hasExtra(EXTRA_SELECTED_PROFILE)) {
- selectedProfile = getIntent().getIntExtra(EXTRA_SELECTED_PROFILE, /* defValue = */ -1);
- if (selectedProfile != PROFILE_PERSONAL && selectedProfile != PROFILE_WORK) {
- throw new IllegalArgumentException(EXTRA_SELECTED_PROFILE + " has invalid value "
- + selectedProfile + ". Must be either ChooserActivity.PROFILE_PERSONAL or "
- + "ChooserActivity.PROFILE_WORK.");
- }
- } else {
+ int selectedProfile = getSelectedProfileExtra();
+ if (selectedProfile == -1) {
selectedProfile = getProfileForUser(getUser());
}
return selectedProfile;
diff --git a/core/java/com/android/internal/app/IntentForwarderActivity.java b/core/java/com/android/internal/app/IntentForwarderActivity.java
index fca156a97a839..e65d1fe9ce537 100644
--- a/core/java/com/android/internal/app/IntentForwarderActivity.java
+++ b/core/java/com/android/internal/app/IntentForwarderActivity.java
@@ -18,6 +18,8 @@ package com.android.internal.app;
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
+import static com.android.internal.app.ResolverActivity.EXTRA_SELECTED_PROFILE;
+
import android.annotation.Nullable;
import android.annotation.StringRes;
import android.app.Activity;
@@ -26,6 +28,7 @@ import android.app.ActivityThread;
import android.app.AppGlobals;
import android.app.admin.DevicePolicyManager;
import android.compat.annotation.UnsupportedAppUsage;
+import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Intent;
import android.content.pm.ActivityInfo;
@@ -74,6 +77,9 @@ public class IntentForwarderActivity extends Activity {
private static final String TEL_SCHEME = "tel";
+ private static final ComponentName RESOLVER_COMPONENT_NAME =
+ new ComponentName("android", ResolverActivity.class.getName());
+
private Injector mInjector;
private MetricsLogger mMetricsLogger;
@@ -136,21 +142,50 @@ public class IntentForwarderActivity extends Activity {
}
newIntent.prepareToLeaveUser(callingUserId);
- maybeShowDisclosureAsync(intentReceived, newIntent, targetUserId, userMessageId);
- CompletableFuture.runAsync(() ->
- startActivityAsCaller(newIntent, targetUserId), mExecutorService)
- .thenAcceptAsync(result -> finish(), getApplicationContext().getMainExecutor());
+ final CompletableFuture Can only be used if there is a work profile.
+ * Possible values can be either {@link #PROFILE_PERSONAL} or {@link #PROFILE_WORK}.
+ */
+ static final String EXTRA_SELECTED_PROFILE =
+ "com.android.internal.app.ResolverActivity.EXTRA_SELECTED_PROFILE";
+
+ static final int PROFILE_PERSONAL = AbstractMultiProfilePagerAdapter.PROFILE_PERSONAL;
+ static final int PROFILE_WORK = AbstractMultiProfilePagerAdapter.PROFILE_WORK;
+
private BroadcastReceiver mWorkProfileStateReceiver;
private UserHandle mHeaderCreatorUser;
@@ -475,6 +486,10 @@ public class ResolverActivity extends Activity implements
selectedProfile = PROFILE_WORK;
}
}
+ 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
// resolver list. So filterLastUsed should be false for the other profile.
@@ -511,6 +526,25 @@ public class ResolverActivity extends Activity implements
return R.style.Theme_DeviceDefault_Resolver;
}
+ /**
+ * Returns {@link #PROFILE_PERSONAL} or {@link #PROFILE_WORK} if the {@link
+ * #EXTRA_SELECTED_PROFILE} extra was supplied, or {@code -1} if no extra was supplied.
+ * @throws IllegalArgumentException if the value passed to the {@link #EXTRA_SELECTED_PROFILE}
+ * extra is not {@link #PROFILE_PERSONAL} or {@link #PROFILE_WORK}
+ */
+ int getSelectedProfileExtra() {
+ int selectedProfile = -1;
+ if (getIntent().hasExtra(EXTRA_SELECTED_PROFILE)) {
+ selectedProfile = getIntent().getIntExtra(EXTRA_SELECTED_PROFILE, /* defValue = */ -1);
+ if (selectedProfile != PROFILE_PERSONAL && selectedProfile != PROFILE_WORK) {
+ throw new IllegalArgumentException(EXTRA_SELECTED_PROFILE + " has invalid value "
+ + selectedProfile + ". Must be either ResolverActivity.PROFILE_PERSONAL or "
+ + "ResolverActivity.PROFILE_WORK.");
+ }
+ }
+ return selectedProfile;
+ }
+
/**
* Returns the user id of the user that the starting intent originated from.
* This is not necessarily equal to {@link #getUserId()} or {@link UserHandle#myUserId()},