summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
author Andrey Yepin <ayepin@google.com> 2024-08-08 21:27:31 -0700
committer Andrey Yepin <ayepin@google.com> 2024-08-12 16:54:40 -0700
commit45aee5e60a4f300bed30db58d3aa66c4a1917866 (patch)
tree95ea65332bacc11f4c7ede6f483f708539ecc57d /java/src
parent014824053450ef297505d1058987f95a4c5d3231 (diff)
Per-profile caller-provided direct target collections
Instead of (partially) relying on the active profile value when deciding whether the caller-provided direct targets should be added to the list, define a list of caller-provided targets for each profile and use those lists unconditionally. Bug: 343300158 Test: manual tests: launche the ShareTest app from different profiles and confirm that the caller-provided targes are added only to the right profile (the profile the Chooser was launched from). Flag: EXEMPT refactoring Change-Id: I9c4ba35d48a090b21f96ddf4723f7b28654acb48
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/intentresolver/ChooserActivity.java46
1 files changed, 30 insertions, 16 deletions
diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java
index b0344565..845d1e1d 100644
--- a/java/src/com/android/intentresolver/ChooserActivity.java
+++ b/java/src/com/android/intentresolver/ChooserActivity.java
@@ -1362,7 +1362,13 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
&& !mProfileAvailability.isAvailable(profile)) {
continue;
}
- ProfileRecord record = createProfileRecord(profile, targetIntentFilter, factory);
+ ProfileRecord record = createProfileRecord(
+ profile,
+ targetIntentFilter,
+ launchedAsProfile.equals(profile)
+ ? mRequest.getCallerChooserTargets()
+ : Collections.emptyList(),
+ factory);
if (profile.equals(launchedAsProfile) && record.shortcutLoader == null) {
Tracer.INSTANCE.endLaunchToShortcutTrace();
}
@@ -1370,7 +1376,10 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
}
private ProfileRecord createProfileRecord(
- Profile profile, IntentFilter targetIntentFilter, AppPredictorFactory factory) {
+ Profile profile,
+ IntentFilter targetIntentFilter,
+ List<ChooserTarget> callerTargets,
+ AppPredictorFactory factory) {
UserHandle userHandle = profile.getPrimary().getHandle();
AppPredictor appPredictor = factory.create(userHandle);
ShortcutLoader shortcutLoader = ActivityManager.isLowRamDeviceStatic()
@@ -1381,7 +1390,8 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
userHandle,
targetIntentFilter,
shortcutsResult -> onShortcutsLoaded(userHandle, shortcutsResult));
- ProfileRecord record = new ProfileRecord(profile, appPredictor, shortcutLoader);
+ ProfileRecord record = new ProfileRecord(
+ profile, appPredictor, shortcutLoader, callerTargets);
mProfileRecords.put(userHandle.getIdentifier(), record);
return record;
}
@@ -1655,17 +1665,18 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
}
}
- private void addCallerChooserTargets() {
- if (!mRequest.getCallerChooserTargets().isEmpty()) {
- // Send the caller's chooser targets only to the default profile.
- if (mChooserMultiProfilePagerAdapter.getActiveProfile() == findSelectedProfile()) {
- mChooserMultiProfilePagerAdapter.getActiveListAdapter().addServiceResults(
- /* origTarget */ null,
- new ArrayList<>(mRequest.getCallerChooserTargets()),
- TARGET_TYPE_DEFAULT,
- /* directShareShortcutInfoCache */ Collections.emptyMap(),
- /* directShareAppTargetCache */ Collections.emptyMap());
- }
+ private void addCallerChooserTargets(ChooserListAdapter adapter) {
+ ProfileRecord record = getProfileRecord(adapter.getUserHandle());
+ List<ChooserTarget> callerTargets = record == null
+ ? Collections.emptyList()
+ : record.callerTargets;
+ if (!callerTargets.isEmpty()) {
+ adapter.addServiceResults(
+ /* origTarget */ null,
+ new ArrayList<>(mRequest.getCallerChooserTargets()),
+ TARGET_TYPE_DEFAULT,
+ /* directShareShortcutInfoCache */ Collections.emptyMap(),
+ /* directShareAppTargetCache */ Collections.emptyMap());
}
}
@@ -2408,7 +2419,7 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
if (duration >= 0) {
Log.d(TAG, "app target loading time " + duration + " ms");
}
- addCallerChooserTargets();
+ addCallerChooserTargets(chooserListAdapter);
getEventLog().logSharesheetAppLoadComplete();
maybeQueryAdditionalPostProcessingTargets(
listProfileUserHandle,
@@ -2689,15 +2700,18 @@ public class ChooserActivity extends Hilt_ChooserActivity implements
*/
@Nullable
public final ShortcutLoader shortcutLoader;
+ public final List<ChooserTarget> callerTargets;
public long loadingStartTime;
private ProfileRecord(
Profile profile,
@Nullable AppPredictor appPredictor,
- @Nullable ShortcutLoader shortcutLoader) {
+ @Nullable ShortcutLoader shortcutLoader,
+ List<ChooserTarget> callerTargets) {
this.profile = profile;
this.appPredictor = appPredictor;
this.shortcutLoader = shortcutLoader;
+ this.callerTargets = callerTargets;
}
public void destroy() {