Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 86ebaa23 authored by Clara Bayarri's avatar Clara Bayarri
Browse files

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
parent bc3a74a3
Loading
Loading
Loading
Loading
+20 −10
Original line number Diff line number Diff line
@@ -197,18 +197,10 @@ public final class ChooseLockSettingsHelper {
        if (external) {
            intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
            if (mFragment != null) {
                IntentSender intentSender = mFragment.getActivity().getIntent()
                        .getParcelableExtra(Intent.EXTRA_INTENT);
                if (intentSender != null) {
                    intent.putExtra(Intent.EXTRA_INTENT, intentSender);
                }
                copyOptionalExtras(mFragment.getActivity().getIntent(), intent);
                mFragment.startActivity(intent);
            } else {
                IntentSender intentSender = mActivity.getIntent()
                        .getParcelableExtra(Intent.EXTRA_INTENT);
                if (intentSender != null) {
                    intent.putExtra(Intent.EXTRA_INTENT, intentSender);
                }
                copyOptionalExtras(mActivity.getIntent(), intent);
                mActivity.startActivity(intent);
            }
        } else {
@@ -220,4 +212,22 @@ public final class ChooseLockSettingsHelper {
        }
        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);
        }
    }
}
+18 −0
Original line number Diff line number Diff line
@@ -17,9 +17,15 @@
package com.android.settings;

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.IntentSender;
import android.os.Bundle;
import android.os.RemoteException;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
@@ -127,6 +133,18 @@ public abstract class ConfirmDeviceCredentialBaseFragment extends InstrumentedFr
    }

    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()
                .getParcelableExtra(Intent.EXTRA_INTENT);
        if (intentSender != null) {