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

Commit df340332 authored by Liahav Eitan's avatar Liahav Eitan
Browse files

TestAPI to skip user confirmation dialog when launching cross-profile intents

This is required since ag/21334979 added a new UI for user confirmation, but some tests rely on being able to easily launch intents cross-profile.

Bug: 270573663
Test: atest com.android.cts.devicepolicy.ManagedProfileCrossProfileTest
Change-Id: I68a65ae42c1d135a5054e1fd3a1dc030e6154cf7
parent 010b989e
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -16,14 +16,17 @@

package com.android.internal.app;

import static android.Manifest.permission.INTERACT_ACROSS_USERS;
import static android.app.admin.DevicePolicyResources.Strings.Core.FORWARD_INTENT_TO_PERSONAL;
import static android.app.admin.DevicePolicyResources.Strings.Core.FORWARD_INTENT_TO_WORK;
import static android.content.pm.PackageManager.MATCH_DEFAULT_ONLY;
import static android.content.pm.PackageManager.PERMISSION_GRANTED;

import static com.android.internal.app.ResolverActivity.EXTRA_CALLING_USER;
import static com.android.internal.app.ResolverActivity.EXTRA_SELECTED_PROFILE;

import android.annotation.Nullable;
import android.annotation.TestApi;
import android.app.Activity;
import android.app.ActivityThread;
import android.app.AppGlobals;
@@ -79,6 +82,10 @@ public class IntentForwarderActivity extends Activity {
    public static String FORWARD_INTENT_TO_MANAGED_PROFILE
            = "com.android.internal.app.ForwardIntentToManagedProfile";

    @TestApi
    public static final String EXTRA_SKIP_USER_CONFIRMATION =
            "com.android.internal.app.EXTRA_SKIP_USER_CONFIRMATION";

    private static final Set<String> ALLOWED_TEXT_MESSAGE_SCHEMES
            = new HashSet<>(Arrays.asList("sms", "smsto", "mms", "mmsto"));

@@ -181,6 +188,15 @@ public class IntentForwarderActivity extends Activity {
            return;
        }

        if (launchIntent.getBooleanExtra(EXTRA_SKIP_USER_CONFIRMATION, /* defaultValue= */ false)
                && getCallingPackage() != null
                && PERMISSION_GRANTED == getPackageManager().checkPermission(
                        INTERACT_ACROSS_USERS, getCallingPackage())) {
            startActivityAsCaller(launchIntent, targetUserId);
            finish();
            return;
        }

        int layoutId = R.layout.miniresolver;
        setContentView(layoutId);