Merge "Start the web help page in the correct user" into sc-dev

This commit is contained in:
TreeHugger Robot
2021-06-29 18:55:24 +00:00
committed by Android (Google) Code Review
6 changed files with 32 additions and 13 deletions

View File

@@ -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);
}
}

View File

@@ -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();
}

View File

@@ -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);
}
}

View File

@@ -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;
}

View File

@@ -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));

View File

@@ -116,7 +116,7 @@ public class ManagedDeviceActionDisabledByAdminControllerTest {
private ManagedDeviceActionDisabledByAdminController createController(String url) {
ManagedDeviceActionDisabledByAdminController controller =
new ManagedDeviceActionDisabledByAdminController(
new FakeDeviceAdminStringProvider(url));
new FakeDeviceAdminStringProvider(url), mContext.getUser());
controller.initialize(mTestUtils.createLearnMoreButtonLauncher());
controller.updateEnforcedAdmin(ENFORCED_ADMIN, ENFORCEMENT_ADMIN_USER_ID);
return controller;