Merge "Start the web help page in the correct user" into sc-dev am: a8fd69468a
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15110194 Change-Id: I292cfebc7f5e6b3ad9c6c994532e149f8bd68c80
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user