Skip to content

Commit 71f251b

Browse files
Liahav EitanOhMyVenyx
authored andcommitted
Fix sharing to another profile where an app has multiple targets
Moves the fixUris call from onTargetSelected directly to the intent launch to ensure the intent which is actually started is updated with userId specific URIs. This is a backport of ag/19657256 and ag/20063949. Bug:242165528 Bug:244876518 Bug:242605257 Test: manually share image from personal profile to work gmail, first with chat target then backing up and selecting the main target Test: manually share image from work Photos app to personal WhatsApp's frequent contact target. Change-Id: Id815984e691bf962e19e30a54f7247d16060b3b8 Merged-In: Id815984e691bf962e19e30a54f7247d16060b3b8 Merged-In: Ib41c8a3c46afcc2d62a4c1a924212bcd98bcfbe4 Merged-In: Iabf5dcf2612fe718f2f0886e2e5e9b76f37af1e1 (cherry picked from commit f50ced5) Merged-In: Id815984e691bf962e19e30a54f7247d16060b3b8
1 parent ebc061f commit 71f251b

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

core/java/com/android/internal/app/ResolverActivity.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1227,9 +1227,6 @@ protected boolean onTargetSelected(TargetInfo target, boolean always) {
12271227
}
12281228

12291229
if (target != null) {
1230-
if (intent != null && isLaunchingTargetInOtherProfile()) {
1231-
prepareIntentForCrossProfileLaunch(intent);
1232-
}
12331230
safelyStartActivity(target);
12341231

12351232
// Rely on the ActivityManager to pop up a dialog regarding app suspension
@@ -1242,15 +1239,6 @@ protected boolean onTargetSelected(TargetInfo target, boolean always) {
12421239
return true;
12431240
}
12441241

1245-
private void prepareIntentForCrossProfileLaunch(Intent intent) {
1246-
intent.fixUris(UserHandle.myUserId());
1247-
}
1248-
1249-
private boolean isLaunchingTargetInOtherProfile() {
1250-
return mMultiProfilePagerAdapter.getCurrentUserHandle().getIdentifier()
1251-
!= UserHandle.myUserId();
1252-
}
1253-
12541242
@VisibleForTesting
12551243
public void safelyStartActivity(TargetInfo cti) {
12561244
// We're dispatching intents that might be coming from legacy apps, so

core/java/com/android/internal/app/chooser/DisplayResolveInfo.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,13 +181,15 @@ public boolean startAsCaller(ResolverActivity activity, Bundle options, int user
181181
if (ENABLE_CHOOSER_DELEGATE) {
182182
return activity.startAsCallerImpl(mResolvedIntent, options, false, userId);
183183
} else {
184+
TargetInfo.prepareIntentForCrossProfileLaunch(mResolvedIntent, userId);
184185
activity.startActivityAsCaller(mResolvedIntent, options, null, false, userId);
185186
return true;
186187
}
187188
}
188189

189190
@Override
190191
public boolean startAsUser(Activity activity, Bundle options, UserHandle user) {
192+
TargetInfo.prepareIntentForCrossProfileLaunch(mResolvedIntent, user.getIdentifier());
191193
activity.startActivityAsUser(mResolvedIntent, options, user);
192194
return false;
193195
}

core/java/com/android/internal/app/chooser/SelectableTargetInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ public boolean startAsCaller(ResolverActivity activity, Bundle options, int user
229229
}
230230
intent.setComponent(mChooserTarget.getComponentName());
231231
intent.putExtras(mChooserTarget.getIntentExtras());
232+
TargetInfo.prepareIntentForCrossProfileLaunch(intent, userId);
232233

233234
// Important: we will ignore the target security checks in ActivityManager
234235
// if and only if the ChooserTarget's target package is the same package

core/java/com/android/internal/app/chooser/TargetInfo.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,15 @@ public interface TargetInfo {
130130
* @return true if this target should be pinned to the front by the request of the user
131131
*/
132132
boolean isPinned();
133+
134+
/**
135+
* Fix the URIs in {@code intent} if cross-profile sharing is required. This should be called
136+
* before launching the intent as another user.
137+
*/
138+
static void prepareIntentForCrossProfileLaunch(Intent intent, int targetUserId) {
139+
final int currentUserId = UserHandle.myUserId();
140+
if (targetUserId != currentUserId) {
141+
intent.fixUris(currentUserId);
142+
}
143+
}
133144
}

0 commit comments

Comments
 (0)