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: Ib41c8a3c46afcc2d62a4c1a924212bcd98bcfbe4 Merged-In: Iabf5dcf2612fe718f2f0886e2e5e9b76f37af1e1
This commit is contained in:
@@ -1283,9 +1283,6 @@ public class ResolverActivity extends Activity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (target != null) {
|
if (target != null) {
|
||||||
if (intent != null && isLaunchingTargetInOtherProfile()) {
|
|
||||||
prepareIntentForCrossProfileLaunch(intent);
|
|
||||||
}
|
|
||||||
safelyStartActivity(target);
|
safelyStartActivity(target);
|
||||||
|
|
||||||
// Rely on the ActivityManager to pop up a dialog regarding app suspension
|
// Rely on the ActivityManager to pop up a dialog regarding app suspension
|
||||||
@@ -1298,15 +1295,6 @@ public class ResolverActivity extends Activity implements
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareIntentForCrossProfileLaunch(Intent intent) {
|
|
||||||
intent.fixUris(UserHandle.myUserId());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isLaunchingTargetInOtherProfile() {
|
|
||||||
return mMultiProfilePagerAdapter.getCurrentUserHandle().getIdentifier()
|
|
||||||
!= UserHandle.myUserId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void safelyStartActivity(TargetInfo cti) {
|
public void safelyStartActivity(TargetInfo cti) {
|
||||||
// We're dispatching intents that might be coming from legacy apps, so
|
// We're dispatching intents that might be coming from legacy apps, so
|
||||||
@@ -1508,9 +1496,6 @@ public class ResolverActivity extends Activity implements
|
|||||||
|
|
||||||
findViewById(R.id.button_open).setOnClickListener(v -> {
|
findViewById(R.id.button_open).setOnClickListener(v -> {
|
||||||
Intent intent = otherProfileResolveInfo.getResolvedIntent();
|
Intent intent = otherProfileResolveInfo.getResolvedIntent();
|
||||||
if (intent != null) {
|
|
||||||
prepareIntentForCrossProfileLaunch(intent);
|
|
||||||
}
|
|
||||||
safelyStartActivityAsUser(otherProfileResolveInfo,
|
safelyStartActivityAsUser(otherProfileResolveInfo,
|
||||||
inactiveAdapter.mResolverListController.getUserHandle());
|
inactiveAdapter.mResolverListController.getUserHandle());
|
||||||
finish();
|
finish();
|
||||||
|
|||||||
@@ -172,12 +172,14 @@ public class DisplayResolveInfo implements TargetInfo, Parcelable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) {
|
public boolean startAsCaller(ResolverActivity activity, Bundle options, int userId) {
|
||||||
|
TargetInfo.prepareIntentForCrossProfileLaunch(mResolvedIntent, userId);
|
||||||
activity.startActivityAsCaller(mResolvedIntent, options, false, userId);
|
activity.startActivityAsCaller(mResolvedIntent, options, false, userId);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean startAsUser(Activity activity, Bundle options, UserHandle user) {
|
public boolean startAsUser(Activity activity, Bundle options, UserHandle user) {
|
||||||
|
TargetInfo.prepareIntentForCrossProfileLaunch(mResolvedIntent, user.getIdentifier());
|
||||||
activity.startActivityAsUser(mResolvedIntent, options, user);
|
activity.startActivityAsUser(mResolvedIntent, options, user);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ public final class SelectableTargetInfo implements ChooserTargetInfo {
|
|||||||
}
|
}
|
||||||
intent.setComponent(mChooserTarget.getComponentName());
|
intent.setComponent(mChooserTarget.getComponentName());
|
||||||
intent.putExtras(mChooserTarget.getIntentExtras());
|
intent.putExtras(mChooserTarget.getIntentExtras());
|
||||||
|
TargetInfo.prepareIntentForCrossProfileLaunch(intent, userId);
|
||||||
|
|
||||||
// Important: we will ignore the target security checks in ActivityManager
|
// Important: we will ignore the target security checks in ActivityManager
|
||||||
// if and only if the ChooserTarget's target package is the same package
|
// if and only if the ChooserTarget's target package is the same package
|
||||||
|
|||||||
@@ -130,4 +130,15 @@ public interface TargetInfo {
|
|||||||
* @return true if this target should be pinned to the front by the request of the user
|
* @return true if this target should be pinned to the front by the request of the user
|
||||||
*/
|
*/
|
||||||
boolean isPinned();
|
boolean isPinned();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fix the URIs in {@code intent} if cross-profile sharing is required. This should be called
|
||||||
|
* before launching the intent as another user.
|
||||||
|
*/
|
||||||
|
static void prepareIntentForCrossProfileLaunch(Intent intent, int targetUserId) {
|
||||||
|
final int currentUserId = UserHandle.myUserId();
|
||||||
|
if (targetUserId != currentUserId) {
|
||||||
|
intent.fixUris(currentUserId);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user