Fix (still-disabled) sharesheet "token flow."

Per b/132321687, we need to leave the system-side share
activity open (not call finish()) until the SysUI-side
chooser finishes, or else we'll invalidate the start-
activity token that the SysUI (delegate) chooser needs
when it launches the target activity.

Note that the delegated flow is still disabled by the
flag in DisplayResolveInfo.

Bug: 132321687,199743918
Test: Reproduced crash condition & confirmed fix manually.
Change-Id: Ic467dfe4eb417ca846c0ecf2e8a0067bd5275e9f
This commit is contained in:
Joshua Trask
2021-09-15 12:38:29 -04:00
parent 37b480c72a
commit 2ed0753a2e
2 changed files with 41 additions and 9 deletions

View File

@@ -1163,7 +1163,9 @@ public class ChooserActivity extends ResolverActivity implements
-1);
// Action bar is user-independent, always start as primary
safelyStartActivityAsUser(ti, getPersonalProfileUserHandle());
finish();
if (!mAwaitingDelegateResponse) {
finish();
}
}
);
b.setId(R.id.chooser_nearby_button);
@@ -1185,7 +1187,9 @@ public class ChooserActivity extends ResolverActivity implements
-1);
// Action bar is user-independent, always start as primary
safelyStartActivityAsUser(ti, getPersonalProfileUserHandle());
finish();
if (!mAwaitingDelegateResponse) {
finish();
}
}
);
b.setId(R.id.chooser_edit_button);
@@ -2212,7 +2216,9 @@ public class ChooserActivity extends ResolverActivity implements
TargetInfo clonedTarget = selectedTarget.cloneFilledIn(matchingIntent, 0);
if (super.onTargetSelected(clonedTarget, false)) {
updateModelAndChooserCounts(clonedTarget);
finish();
if (!mAwaitingDelegateResponse) {
finish();
}
return;
}
}

View File

@@ -152,6 +152,8 @@ public class ResolverActivity extends Activity implements
/** See {@link #setRetainInOnStop}. */
private boolean mRetainInOnStop;
private static final int REQUEST_CODE_RETURN_FROM_DELEGATE_CHOOSER = 20;
private static final String EXTRA_SHOW_FRAGMENT_ARGS = ":settings:show_fragment_args";
private static final String EXTRA_FRAGMENT_ARG_KEY = ":settings:fragment_args_key";
private static final String OPEN_LINKS_COMPONENT_KEY = "app_link_state";
@@ -203,6 +205,8 @@ public class ResolverActivity extends Activity implements
private UserHandle mWorkProfileUserHandle;
protected boolean mAwaitingDelegateResponse;
/**
* Get the string resource to be used as a label for the link to the resolver activity for an
* action.
@@ -584,7 +588,9 @@ public class ResolverActivity extends Activity implements
mProfileSwitchMessageId = -1;
onTargetSelected(dri, false);
finish();
if (!mAwaitingDelegateResponse) {
finish();
}
}
/**
@@ -1026,7 +1032,9 @@ public class ResolverActivity extends Activity implements
mMultiProfilePagerAdapter.getActiveListAdapter().hasFilteredItem()
? MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_APP_FEATURED
: MetricsProto.MetricsEvent.ACTION_HIDE_APP_DISAMBIG_NONE_FEATURED);
finish();
if (!mAwaitingDelegateResponse) {
finish();
}
}
}
@@ -1354,15 +1362,31 @@ public class ResolverActivity extends Activity implements
chooserIntent.putExtra(ActivityTaskManager.EXTRA_IGNORE_TARGET_SECURITY,
ignoreTargetSecurity);
chooserIntent.putExtra(Intent.EXTRA_USER_ID, userId);
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT
| Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
startActivity(chooserIntent);
chooserIntent.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
// Don't close until the delegate finishes, or the token will be invalidated.
mAwaitingDelegateResponse = true;
startActivityForResult(chooserIntent, REQUEST_CODE_RETURN_FROM_DELEGATE_CHOOSER);
} catch (RemoteException e) {
Log.e(TAG, e.toString());
}
return true;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_RETURN_FROM_DELEGATE_CHOOSER:
// Repeat the delegate's result as our own.
setResult(resultCode, data);
finish();
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
public void onActivityStarted(TargetInfo cti) {
// Do nothing
}
@@ -2152,7 +2176,9 @@ public class ResolverActivity extends Activity implements
.getItem(selections[0].getIndex());
if (ra.onTargetSelected(ti, false)) {
ra.mPickOptionRequest = null;
ra.finish();
if (!ra.mAwaitingDelegateResponse) {
ra.finish();
}
}
}
}