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

Commit c7c113d4 authored by arangelov's avatar arangelov
Browse files

Start the web help page in the correct user

Test: ManagedDeviceActionDisabledByAdminControllerTest
Test: manually observed the policy transparency dialog
with launching the admin policies screen
Test: manually observed the policy transparency dialog
with launching the web help page
Fixes: 191727929

Change-Id: I03aaf2ddbaff3ea515404b257d1590c08ae3ab65
parent 940921d0
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -33,15 +33,17 @@ public final class ActionDisabledByAdminControllerFactory {

    /**
     * Returns the relevant instance of {@link ActionDisabledByAdminController}.
     * @param userHandle user on which to launch the help page, if necessary
     */
    public static ActionDisabledByAdminController createInstance(Context context,
            String restriction, DeviceAdminStringProvider stringProvider) {
            String restriction, DeviceAdminStringProvider stringProvider,
            UserHandle userHandle) {
        if (doesBiometricRequireParentalConsent(context, restriction)) {
            return new BiometricActionDisabledByAdminController(stringProvider);
        } else if (isFinancedDevice(context)) {
            return new FinancedDeviceActionDisabledByAdminController(stringProvider);
        } else {
            return new ManagedDeviceActionDisabledByAdminController(stringProvider);
            return new ManagedDeviceActionDisabledByAdminController(stringProvider, userHandle);
        }
    }

+5 −4
Original line number Diff line number Diff line
@@ -54,11 +54,12 @@ public abstract class ActionDisabledLearnMoreButtonLauncher {
    /**
     * Sets up a "learn more" button which launches a help page
     */
    public final void setupLearnMoreButtonToLaunchHelpPage(Context context, String url) {
    public final void setupLearnMoreButtonToLaunchHelpPage(
            Context context, String url, UserHandle userHandle) {
        requireNonNull(context, "context cannot be null");
        requireNonNull(url, "url cannot be null");

        setLearnMoreButton(() -> showHelpPage(context, url));
        setLearnMoreButton(() -> showHelpPage(context, url, userHandle));
    }

    /**
@@ -105,8 +106,8 @@ public abstract class ActionDisabledLearnMoreButtonLauncher {
     * Shows the help page using the given {@code url}.
     */
    @VisibleForTesting
    public void showHelpPage(Context context, String url) {
        context.startActivityAsUser(createLearnMoreIntent(url), UserHandle.of(context.getUserId()));
    public void showHelpPage(Context context, String url, UserHandle userHandle) {
        context.startActivityAsUser(createLearnMoreIntent(url), userHandle);
        finishSelf();
    }

+16 −2
Original line number Diff line number Diff line
@@ -16,13 +16,18 @@

package com.android.settingslib.enterprise;

import static java.util.Objects.requireNonNull;

import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.os.UserHandle;
import android.os.UserManager;
import android.text.TextUtils;

import androidx.annotation.Nullable;

import java.util.Objects;


/**
 * An {@link ActionDisabledByAdminController} to be used with managed devices.
@@ -30,8 +35,17 @@ import androidx.annotation.Nullable;
final class ManagedDeviceActionDisabledByAdminController
        extends BaseActionDisabledByAdminController {

    ManagedDeviceActionDisabledByAdminController(DeviceAdminStringProvider stringProvider) {
    private final UserHandle mUserHandle;

    /**
     * Constructs a {@link ManagedDeviceActionDisabledByAdminController}
     * @param userHandle - user on which to launch the help web page, if necessary
     */
    ManagedDeviceActionDisabledByAdminController(
            DeviceAdminStringProvider stringProvider,
            UserHandle userHandle) {
        super(stringProvider);
        mUserHandle = requireNonNull(userHandle);
    }

    @Override
@@ -43,7 +57,7 @@ final class ManagedDeviceActionDisabledByAdminController
            mLauncher.setupLearnMoreButtonToShowAdminPolicies(context, mEnforcementAdminUserId,
                    mEnforcedAdmin);
        } else {
            mLauncher.setupLearnMoreButtonToLaunchHelpPage(context, url);
            mLauncher.setupLearnMoreButtonToLaunchHelpPage(context, url, mUserHandle);
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ public final class ActionDisabledByAdminControllerTestUtils {
            }

            @Override
            public void showHelpPage(Context context, String url) {
            public void showHelpPage(Context context, String url, UserHandle userHandle) {
                mLearnMoreButtonAction = LEARN_MORE_ACTION_LAUNCH_HELP_PAGE;
            }

+5 −3
Original line number Diff line number Diff line
@@ -181,18 +181,20 @@ public final class ActionDisabledLearnMoreButtonLauncherTest {
    @Test
    public void testSetupLearnMoreButtonToLaunchHelpPage_nullContext() {
        assertThrows(NullPointerException.class,
                () -> mLauncher.setupLearnMoreButtonToLaunchHelpPage(/* context= */ null, URL));
                () -> mLauncher.setupLearnMoreButtonToLaunchHelpPage(
                        /* context= */ null, URL, CONTEXT_USER));
    }

    @Test
    public void testSetupLearnMoreButtonToLaunchHelpPage_nullUrl() {
        assertThrows(NullPointerException.class,
                () -> mLauncher.setupLearnMoreButtonToLaunchHelpPage(mContext, /* url= */ null));
                () -> mLauncher.setupLearnMoreButtonToLaunchHelpPage(
                        mContext, /* url= */ null, CONTEXT_USER));
    }

    @Test
    public void testSetupLearnMoreButtonToLaunchHelpPage() {
        mLauncher.setupLearnMoreButtonToLaunchHelpPage(mContext, URL);
        mLauncher.setupLearnMoreButtonToLaunchHelpPage(mContext, URL, CONTEXT_USER);
        tapLearnMore();

        verify(mContext).startActivityAsUser(mIntentCaptor.capture(), eq(CONTEXT_USER));
Loading