Launch existing Task when taskId is given to ConfirmDeviceCredential
When using ConfirmDeviceCredential as the Work Challenge, we sometimes have intercepted a task launching from recents. In this case, read the taskId given as an extra and request that task to be started from recents instead of launching a new intent. Change-Id: Icca92f246e8f025b64de1f138493fc4069f98829
This commit is contained in:
@@ -197,18 +197,10 @@ public final class ChooseLockSettingsHelper {
|
|||||||
if (external) {
|
if (external) {
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
|
intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
|
||||||
if (mFragment != null) {
|
if (mFragment != null) {
|
||||||
IntentSender intentSender = mFragment.getActivity().getIntent()
|
copyOptionalExtras(mFragment.getActivity().getIntent(), intent);
|
||||||
.getParcelableExtra(Intent.EXTRA_INTENT);
|
|
||||||
if (intentSender != null) {
|
|
||||||
intent.putExtra(Intent.EXTRA_INTENT, intentSender);
|
|
||||||
}
|
|
||||||
mFragment.startActivity(intent);
|
mFragment.startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
IntentSender intentSender = mActivity.getIntent()
|
copyOptionalExtras(mActivity.getIntent(), intent);
|
||||||
.getParcelableExtra(Intent.EXTRA_INTENT);
|
|
||||||
if (intentSender != null) {
|
|
||||||
intent.putExtra(Intent.EXTRA_INTENT, intentSender);
|
|
||||||
}
|
|
||||||
mActivity.startActivity(intent);
|
mActivity.startActivity(intent);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -220,4 +212,22 @@ public final class ChooseLockSettingsHelper {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void copyOptionalExtras(Intent inIntent, Intent outIntent) {
|
||||||
|
IntentSender intentSender = inIntent.getParcelableExtra(Intent.EXTRA_INTENT);
|
||||||
|
if (intentSender != null) {
|
||||||
|
outIntent.putExtra(Intent.EXTRA_INTENT, intentSender);
|
||||||
|
}
|
||||||
|
int taskId = inIntent.getIntExtra(Intent.EXTRA_TASK_ID, -1);
|
||||||
|
if (taskId != -1) {
|
||||||
|
outIntent.putExtra(Intent.EXTRA_TASK_ID, taskId);
|
||||||
|
}
|
||||||
|
// If we will launch another activity once credentials are confirmed, exclude from recents.
|
||||||
|
// This is a workaround to a framework bug where affinity is incorrect for activities
|
||||||
|
// that are started from a no display activity, as is ConfirmDeviceCredentialActivity.
|
||||||
|
// TODO: Remove once that bug is fixed.
|
||||||
|
if (intentSender != null || taskId != -1) {
|
||||||
|
outIntent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,9 +17,15 @@
|
|||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.app.ActivityManagerNative;
|
||||||
|
import android.app.ActivityOptions;
|
||||||
|
import android.app.IActivityManager;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.IntentSender;
|
import android.content.IntentSender;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.RemoteException;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
@@ -127,6 +133,18 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void checkForPendingIntent() {
|
protected void checkForPendingIntent() {
|
||||||
|
int taskId = getActivity().getIntent().getIntExtra(Intent.EXTRA_TASK_ID, -1);
|
||||||
|
if (taskId != -1) {
|
||||||
|
try {
|
||||||
|
IActivityManager activityManager = ActivityManagerNative.getDefault();
|
||||||
|
final ActivityOptions options = ActivityOptions.makeBasic();
|
||||||
|
options.setLaunchStackId(ActivityManager.StackId.INVALID_STACK_ID);
|
||||||
|
activityManager.startActivityFromRecents(taskId, options.toBundle());
|
||||||
|
return;
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
// Do nothing.
|
||||||
|
}
|
||||||
|
}
|
||||||
IntentSender intentSender = getActivity().getIntent()
|
IntentSender intentSender = getActivity().getIntent()
|
||||||
.getParcelableExtra(Intent.EXTRA_INTENT);
|
.getParcelableExtra(Intent.EXTRA_INTENT);
|
||||||
if (intentSender != null) {
|
if (intentSender != null) {
|
||||||
|
Reference in New Issue
Block a user