Merge "Start the web help page in the correct user" into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a8fd69468a
@@ -33,15 +33,17 @@ public final class ActionDisabledByAdminControllerFactory {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the relevant instance of {@link ActionDisabledByAdminController}.
|
* 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,
|
public static ActionDisabledByAdminController createInstance(Context context,
|
||||||
String restriction, DeviceAdminStringProvider stringProvider) {
|
String restriction, DeviceAdminStringProvider stringProvider,
|
||||||
|
UserHandle userHandle) {
|
||||||
if (doesBiometricRequireParentalConsent(context, restriction)) {
|
if (doesBiometricRequireParentalConsent(context, restriction)) {
|
||||||
return new BiometricActionDisabledByAdminController(stringProvider);
|
return new BiometricActionDisabledByAdminController(stringProvider);
|
||||||
} else if (isFinancedDevice(context)) {
|
} else if (isFinancedDevice(context)) {
|
||||||
return new FinancedDeviceActionDisabledByAdminController(stringProvider);
|
return new FinancedDeviceActionDisabledByAdminController(stringProvider);
|
||||||
} else {
|
} 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
|
* 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(context, "context cannot be null");
|
||||||
requireNonNull(url, "url 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}.
|
* Shows the help page using the given {@code url}.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void showHelpPage(Context context, String url) {
|
public void showHelpPage(Context context, String url, UserHandle userHandle) {
|
||||||
context.startActivityAsUser(createLearnMoreIntent(url), UserHandle.of(context.getUserId()));
|
context.startActivityAsUser(createLearnMoreIntent(url), userHandle);
|
||||||
finishSelf();
|
finishSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,18 @@
|
|||||||
|
|
||||||
package com.android.settingslib.enterprise;
|
package com.android.settingslib.enterprise;
|
||||||
|
|
||||||
|
import static java.util.Objects.requireNonNull;
|
||||||
|
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An {@link ActionDisabledByAdminController} to be used with managed devices.
|
* An {@link ActionDisabledByAdminController} to be used with managed devices.
|
||||||
@@ -30,8 +35,17 @@ import androidx.annotation.Nullable;
|
|||||||
final class ManagedDeviceActionDisabledByAdminController
|
final class ManagedDeviceActionDisabledByAdminController
|
||||||
extends BaseActionDisabledByAdminController {
|
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);
|
super(stringProvider);
|
||||||
|
mUserHandle = requireNonNull(userHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -43,7 +57,7 @@ final class ManagedDeviceActionDisabledByAdminController
|
|||||||
mLauncher.setupLearnMoreButtonToShowAdminPolicies(context, mEnforcementAdminUserId,
|
mLauncher.setupLearnMoreButtonToShowAdminPolicies(context, mEnforcementAdminUserId,
|
||||||
mEnforcedAdmin);
|
mEnforcedAdmin);
|
||||||
} else {
|
} else {
|
||||||
mLauncher.setupLearnMoreButtonToLaunchHelpPage(context, url);
|
mLauncher.setupLearnMoreButtonToLaunchHelpPage(context, url, mUserHandle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ public final class ActionDisabledByAdminControllerTestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void showHelpPage(Context context, String url) {
|
public void showHelpPage(Context context, String url, UserHandle userHandle) {
|
||||||
mLearnMoreButtonAction = LEARN_MORE_ACTION_LAUNCH_HELP_PAGE;
|
mLearnMoreButtonAction = LEARN_MORE_ACTION_LAUNCH_HELP_PAGE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -181,18 +181,20 @@ public final class ActionDisabledLearnMoreButtonLauncherTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSetupLearnMoreButtonToLaunchHelpPage_nullContext() {
|
public void testSetupLearnMoreButtonToLaunchHelpPage_nullContext() {
|
||||||
assertThrows(NullPointerException.class,
|
assertThrows(NullPointerException.class,
|
||||||
() -> mLauncher.setupLearnMoreButtonToLaunchHelpPage(/* context= */ null, URL));
|
() -> mLauncher.setupLearnMoreButtonToLaunchHelpPage(
|
||||||
|
/* context= */ null, URL, CONTEXT_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetupLearnMoreButtonToLaunchHelpPage_nullUrl() {
|
public void testSetupLearnMoreButtonToLaunchHelpPage_nullUrl() {
|
||||||
assertThrows(NullPointerException.class,
|
assertThrows(NullPointerException.class,
|
||||||
() -> mLauncher.setupLearnMoreButtonToLaunchHelpPage(mContext, /* url= */ null));
|
() -> mLauncher.setupLearnMoreButtonToLaunchHelpPage(
|
||||||
|
mContext, /* url= */ null, CONTEXT_USER));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetupLearnMoreButtonToLaunchHelpPage() {
|
public void testSetupLearnMoreButtonToLaunchHelpPage() {
|
||||||
mLauncher.setupLearnMoreButtonToLaunchHelpPage(mContext, URL);
|
mLauncher.setupLearnMoreButtonToLaunchHelpPage(mContext, URL, CONTEXT_USER);
|
||||||
tapLearnMore();
|
tapLearnMore();
|
||||||
|
|
||||||
verify(mContext).startActivityAsUser(mIntentCaptor.capture(), eq(CONTEXT_USER));
|
verify(mContext).startActivityAsUser(mIntentCaptor.capture(), eq(CONTEXT_USER));
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ public class ManagedDeviceActionDisabledByAdminControllerTest {
|
|||||||
private ManagedDeviceActionDisabledByAdminController createController(String url) {
|
private ManagedDeviceActionDisabledByAdminController createController(String url) {
|
||||||
ManagedDeviceActionDisabledByAdminController controller =
|
ManagedDeviceActionDisabledByAdminController controller =
|
||||||
new ManagedDeviceActionDisabledByAdminController(
|
new ManagedDeviceActionDisabledByAdminController(
|
||||||
new FakeDeviceAdminStringProvider(url));
|
new FakeDeviceAdminStringProvider(url), mContext.getUser());
|
||||||
controller.initialize(mTestUtils.createLearnMoreButtonLauncher());
|
controller.initialize(mTestUtils.createLearnMoreButtonLauncher());
|
||||||
controller.updateEnforcedAdmin(ENFORCED_ADMIN, ENFORCEMENT_ADMIN_USER_ID);
|
controller.updateEnforcedAdmin(ENFORCED_ADMIN, ENFORCEMENT_ADMIN_USER_ID);
|
||||||
return controller;
|
return controller;
|
||||||
|
|||||||
Reference in New Issue
Block a user