Further refactoring on ActionDisabledByAdminDialog classes.
Bug: 184107103 Bug: 188836559 Test: m -j RunSettingsRoboTests ROBOTEST_FILTER=ActionDisabledByAdminDialogHelperTest Test: atest ActionDisabledLearnMoreButtonLauncherImplTest Test: adb shell am start -e android.app.extra.RESTRICTION no_install_unknown-sources -a android.settings.SHOW_ADMIN_SUPPORT_DETAILS Test: manual verification with CtsVerifier Change-Id: I3c4056d82834b5e2a4afbd958be7c9d0b9af543e
This commit is contained in:
@@ -45,30 +45,25 @@ import java.util.Objects;
|
|||||||
/**
|
/**
|
||||||
* Helper class for {@link ActionDisabledByAdminDialog} which sets up the dialog.
|
* Helper class for {@link ActionDisabledByAdminDialog} which sets up the dialog.
|
||||||
*/
|
*/
|
||||||
public class ActionDisabledByAdminDialogHelper {
|
public final class ActionDisabledByAdminDialogHelper {
|
||||||
|
|
||||||
private static final String TAG = ActionDisabledByAdminDialogHelper.class.getName();
|
private static final String TAG = ActionDisabledByAdminDialogHelper.class.getName();
|
||||||
@VisibleForTesting EnforcedAdmin mEnforcedAdmin;
|
@VisibleForTesting EnforcedAdmin mEnforcedAdmin;
|
||||||
private ViewGroup mDialogView;
|
private ViewGroup mDialogView;
|
||||||
private String mRestriction = null;
|
private String mRestriction;
|
||||||
private final Activity mActivity;
|
|
||||||
private final ActionDisabledByAdminController mActionDisabledByAdminController;
|
private final ActionDisabledByAdminController mActionDisabledByAdminController;
|
||||||
|
private final Activity mActivity;
|
||||||
|
|
||||||
public ActionDisabledByAdminDialogHelper(Activity activity) {
|
public ActionDisabledByAdminDialogHelper(Activity activity) {
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mActionDisabledByAdminController =
|
mDialogView = (ViewGroup) LayoutInflater.from(mActivity).inflate(
|
||||||
ActionDisabledByAdminControllerFactory.createInstance(
|
R.layout.admin_support_details_dialog, null);
|
||||||
mActivity.getSystemService(DevicePolicyManager.class),
|
mActionDisabledByAdminController = ActionDisabledByAdminControllerFactory
|
||||||
new ActionDisabledLearnMoreButtonLauncherImpl(),
|
.createInstance(mActivity, new DeviceAdminStringProviderImpl(mActivity));
|
||||||
new DeviceAdminStringProviderImpl(mActivity));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private @UserIdInt int getEnforcementAdminUserId(@NonNull EnforcedAdmin admin) {
|
private @UserIdInt int getEnforcementAdminUserId(@NonNull EnforcedAdmin admin) {
|
||||||
if (admin.user == null) {
|
return admin.user == null ? UserHandle.USER_NULL : admin.user.getIdentifier();
|
||||||
return UserHandle.USER_NULL;
|
|
||||||
} else {
|
|
||||||
return admin.user.getIdentifier();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private @UserIdInt int getEnforcementAdminUserId() {
|
private @UserIdInt int getEnforcementAdminUserId() {
|
||||||
@@ -77,21 +72,24 @@ public class ActionDisabledByAdminDialogHelper {
|
|||||||
|
|
||||||
public AlertDialog.Builder prepareDialogBuilder(String restriction,
|
public AlertDialog.Builder prepareDialogBuilder(String restriction,
|
||||||
EnforcedAdmin enforcedAdmin) {
|
EnforcedAdmin enforcedAdmin) {
|
||||||
mEnforcedAdmin = enforcedAdmin;
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity)
|
||||||
mRestriction = restriction;
|
.setPositiveButton(R.string.okay, null)
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
|
.setView(mDialogView);
|
||||||
mDialogView = (ViewGroup) LayoutInflater.from(mActivity).inflate(
|
prepareDialogBuilder(builder, restriction, enforcedAdmin);
|
||||||
R.layout.admin_support_details_dialog, null);
|
|
||||||
initializeDialogViews(mDialogView, mEnforcedAdmin, getEnforcementAdminUserId(),
|
|
||||||
mRestriction, mActionDisabledByAdminController);
|
|
||||||
builder.setPositiveButton(R.string.okay, null).setView(mDialogView);
|
|
||||||
maybeSetLearnMoreButton(builder);
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void maybeSetLearnMoreButton(AlertDialog.Builder builder) {
|
void prepareDialogBuilder(AlertDialog.Builder builder, String restriction,
|
||||||
mActionDisabledByAdminController.setupLearnMoreButton(mActivity, builder);
|
EnforcedAdmin enforcedAdmin) {
|
||||||
|
mActionDisabledByAdminController.initialize(
|
||||||
|
new ActionDisabledLearnMoreButtonLauncherImpl(mActivity, builder));
|
||||||
|
|
||||||
|
mEnforcedAdmin = enforcedAdmin;
|
||||||
|
mRestriction = restriction;
|
||||||
|
initializeDialogViews(mDialogView, mEnforcedAdmin, getEnforcementAdminUserId(),
|
||||||
|
mRestriction);
|
||||||
|
mActionDisabledByAdminController.setupLearnMoreButton(mActivity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDialog(String restriction, EnforcedAdmin admin) {
|
public void updateDialog(String restriction, EnforcedAdmin admin) {
|
||||||
@@ -101,17 +99,17 @@ public class ActionDisabledByAdminDialogHelper {
|
|||||||
mEnforcedAdmin = admin;
|
mEnforcedAdmin = admin;
|
||||||
mRestriction = restriction;
|
mRestriction = restriction;
|
||||||
initializeDialogViews(mDialogView, mEnforcedAdmin, getEnforcementAdminUserId(),
|
initializeDialogViews(mDialogView, mEnforcedAdmin, getEnforcementAdminUserId(),
|
||||||
mRestriction, mActionDisabledByAdminController);
|
mRestriction);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeDialogViews(View root, EnforcedAdmin enforcedAdmin, int userId,
|
private void initializeDialogViews(View root, EnforcedAdmin enforcedAdmin, int userId,
|
||||||
String restriction, ActionDisabledByAdminController controller) {
|
String restriction) {
|
||||||
ComponentName admin = enforcedAdmin.component;
|
ComponentName admin = enforcedAdmin.component;
|
||||||
if (admin == null) {
|
if (admin == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
controller.updateEnforcedAdmin(enforcedAdmin, userId);
|
mActionDisabledByAdminController.updateEnforcedAdmin(enforcedAdmin, userId);
|
||||||
setAdminSupportIcon(root, admin, userId);
|
setAdminSupportIcon(root, admin, userId);
|
||||||
|
|
||||||
if (isNotCurrentUserOrProfile(admin, userId)) {
|
if (isNotCurrentUserOrProfile(admin, userId)) {
|
||||||
@@ -148,8 +146,7 @@ public class ActionDisabledByAdminDialogHelper {
|
|||||||
if (titleView == null) {
|
if (titleView == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
titleView.setText(
|
titleView.setText(mActionDisabledByAdminController.getAdminSupportTitle(restriction));
|
||||||
mActionDisabledByAdminController.getAdminSupportTitle(restriction));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@@ -20,104 +20,67 @@ import static java.util.Objects.requireNonNull;
|
|||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Settings;
|
import com.android.settings.Settings;
|
||||||
import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd;
|
import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd;
|
||||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
|
||||||
import com.android.settingslib.enterprise.ActionDisabledLearnMoreButtonLauncher;
|
import com.android.settingslib.enterprise.ActionDisabledLearnMoreButtonLauncher;
|
||||||
|
|
||||||
import java.util.function.BiConsumer;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class to set up the "Learn more" button in the action disabled dialog.
|
* Helper class to set up the "Learn more" button in the action disabled dialog.
|
||||||
*/
|
*/
|
||||||
public class ActionDisabledLearnMoreButtonLauncherImpl
|
public final class ActionDisabledLearnMoreButtonLauncherImpl
|
||||||
implements ActionDisabledLearnMoreButtonLauncher {
|
extends ActionDisabledLearnMoreButtonLauncher {
|
||||||
|
|
||||||
static final BiConsumer<Activity, EnforcedAdmin> SHOW_ADMIN_POLICIES =
|
private final Activity mActivity;
|
||||||
(activity, enforcedAdmin) -> {
|
private final AlertDialog.Builder mBuilder;
|
||||||
showAdminPolicies(enforcedAdmin, activity);
|
|
||||||
activity.finish();
|
|
||||||
};
|
|
||||||
|
|
||||||
static final BiConsumer<Activity, String> LAUNCH_HELP_PAGE = (activity, url) -> {
|
ActionDisabledLearnMoreButtonLauncherImpl(Activity activity, AlertDialog.Builder builder) {
|
||||||
launchLearnMoreHelpPage(activity, url);
|
mActivity = requireNonNull(activity, "activity cannot be null");
|
||||||
activity.finish();
|
mBuilder = requireNonNull(builder, "builder cannot be null");
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setupLearnMoreButtonToShowAdminPolicies(
|
|
||||||
Context context,
|
|
||||||
Object alertDialogBuilder,
|
|
||||||
int enforcementAdminUserId,
|
|
||||||
EnforcedAdmin enforcedAdmin) {
|
|
||||||
requireNonNull(context);
|
|
||||||
requireNonNull(alertDialogBuilder);
|
|
||||||
requireNonNull(enforcedAdmin);
|
|
||||||
// The "Learn more" button appears only if the restriction is enforced by an admin in the
|
|
||||||
// same profile group. Otherwise the admin package and its policies are not accessible to
|
|
||||||
// the current user.
|
|
||||||
final UserManager um = UserManager.get(context);
|
|
||||||
if (um.isSameProfileGroup(enforcementAdminUserId, um.getUserHandle())) {
|
|
||||||
setupLearnMoreButton((AlertDialog.Builder) alertDialogBuilder, () ->
|
|
||||||
SHOW_ADMIN_POLICIES.accept((Activity) context, enforcedAdmin));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setupLearnMoreButtonToLaunchHelpPage(
|
public void setLearnMoreButton(Runnable action) {
|
||||||
Context context,
|
requireNonNull(action, "action cannot be null");
|
||||||
Object alertDialogBuilder,
|
|
||||||
String url) {
|
mBuilder.setNeutralButton(R.string.learn_more, (dialog, which) -> action.run());
|
||||||
requireNonNull(context);
|
|
||||||
requireNonNull(alertDialogBuilder);
|
|
||||||
requireNonNull(url);
|
|
||||||
setupLearnMoreButton((AlertDialog.Builder) alertDialogBuilder,
|
|
||||||
() -> LAUNCH_HELP_PAGE.accept((Activity) context, url));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setupLearnMoreButton(AlertDialog.Builder builder, Runnable runnable) {
|
@Override
|
||||||
builder.setNeutralButton(R.string.learn_more, (dialog, which) -> {
|
protected void launchShowAdminPolicies(Context context, UserHandle user, ComponentName admin) {
|
||||||
runnable.run();
|
requireNonNull(context, "context cannot be null");
|
||||||
});
|
requireNonNull(user, "user cannot be null");
|
||||||
|
requireNonNull(admin, "admin cannot be null");
|
||||||
|
|
||||||
|
Intent intent = new Intent()
|
||||||
|
.setClass(mActivity, DeviceAdminAdd.class)
|
||||||
|
.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, admin)
|
||||||
|
.putExtra(DeviceAdminAdd.EXTRA_CALLED_FROM_SUPPORT_DIALOG, true);
|
||||||
|
// DeviceAdminAdd class may need to run as managed profile.
|
||||||
|
mActivity.startActivityAsUser(intent, user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void launchLearnMoreHelpPage(Activity activity, String url) {
|
@Override
|
||||||
activity.startActivityAsUser(createLearnMoreIntent(url), UserHandle.SYSTEM);
|
protected void launchShowAdminSettings(Context context) {
|
||||||
|
requireNonNull(context, "context cannot be null");
|
||||||
|
|
||||||
|
Intent intent = new Intent()
|
||||||
|
.setClass(mActivity, Settings.DeviceAdminSettingsActivity.class)
|
||||||
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
|
// Activity merges both managed profile and parent users
|
||||||
|
// admins so show as same user as this activity.
|
||||||
|
mActivity.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Intent createLearnMoreIntent(String url) {
|
@Override
|
||||||
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
protected void finishSelf() {
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
mActivity.finish();
|
||||||
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
|
|
||||||
return intent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void showAdminPolicies(
|
|
||||||
EnforcedAdmin enforcedAdmin,
|
|
||||||
Activity activity) {
|
|
||||||
final Intent intent = new Intent();
|
|
||||||
if (enforcedAdmin.component != null) {
|
|
||||||
intent.setClass(activity, DeviceAdminAdd.class);
|
|
||||||
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN,
|
|
||||||
enforcedAdmin.component);
|
|
||||||
intent.putExtra(DeviceAdminAdd.EXTRA_CALLED_FROM_SUPPORT_DIALOG, true);
|
|
||||||
// DeviceAdminAdd class may need to run as managed profile.
|
|
||||||
activity.startActivityAsUser(intent, enforcedAdmin.user);
|
|
||||||
} else {
|
|
||||||
intent.setClass(activity, Settings.DeviceAdminSettingsActivity.class);
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
||||||
// Activity merges both managed profile and parent users
|
|
||||||
// admins so show as same user as this activity.
|
|
||||||
activity.startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -200,24 +200,21 @@ public class ActionDisabledByAdminDialogHelperTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testMaybeSetLearnMoreButton() {
|
public void testMaybeSetLearnMoreButton() {
|
||||||
final UserManager userManager = RuntimeEnvironment.application.getSystemService(
|
UserManager userManager = RuntimeEnvironment.application
|
||||||
UserManager.class);
|
.getSystemService(UserManager.class);
|
||||||
final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
|
ShadowUserManager userManagerShadow = Shadow.extract(userManager);
|
||||||
mHelper.prepareDialogBuilder(
|
|
||||||
/* restriction= */ null, ENFORCED_ADMIN);
|
|
||||||
|
|
||||||
// Set up for shadow call.
|
// Set up for shadow call.
|
||||||
userManagerShadow.getSameProfileGroupIds().put(USER_ID, 0);
|
userManagerShadow.getSameProfileGroupIds().put(USER_ID, 0);
|
||||||
|
|
||||||
// Test that the button is shown when user IDs are in the same profile group
|
// Test that the button is shown when user IDs are in the same profile group
|
||||||
AlertDialog.Builder builder = mock(AlertDialog.Builder.class);
|
AlertDialog.Builder builder = mock(AlertDialog.Builder.class);
|
||||||
mHelper.maybeSetLearnMoreButton(builder);
|
mHelper.prepareDialogBuilder(builder, /* restriction= */ null, ENFORCED_ADMIN);
|
||||||
verify(builder).setNeutralButton(anyInt(), any());
|
verify(builder).setNeutralButton(anyInt(), any());
|
||||||
|
|
||||||
// Test that the button is not shown when user IDs are not in the same profile group
|
// Test that the button is not shown when user IDs are not in the same profile group
|
||||||
userManagerShadow.getSameProfileGroupIds().clear();
|
userManagerShadow.getSameProfileGroupIds().clear();
|
||||||
builder = mock(AlertDialog.Builder.class);
|
builder = mock(AlertDialog.Builder.class);
|
||||||
mHelper.maybeSetLearnMoreButton(builder);
|
mHelper.prepareDialogBuilder(builder, /* restriction= */ null, ENFORCED_ADMIN);
|
||||||
verify(builder, never()).setNeutralButton(anyInt(), any());
|
verify(builder, never()).setNeutralButton(anyInt(), any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -24,86 +24,104 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.eq;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
|
import android.os.UserManager;
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.test.runner.AndroidJUnit4;
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
import com.android.settings.Settings;
|
import com.android.settings.Settings;
|
||||||
import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd;
|
import com.android.settings.applications.specialaccess.deviceadmin.DeviceAdminAdd;
|
||||||
import com.android.settingslib.RestrictedLockUtils;
|
|
||||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.junit.MockitoJUnit;
|
||||||
|
import org.mockito.junit.MockitoRule;
|
||||||
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class ActionDisabledLearnMoreButtonLauncherImplTest {
|
public class ActionDisabledLearnMoreButtonLauncherImplTest {
|
||||||
|
|
||||||
private static final int ENFORCED_ADMIN_USER_ID = 123;
|
private static final int ENFORCED_ADMIN_USER_ID = 123;
|
||||||
|
private static final UserHandle ENFORCED_ADMIN_USER = UserHandle.of(ENFORCED_ADMIN_USER_ID);
|
||||||
|
|
||||||
|
private static final int CONTEXT_USER_ID = -ENFORCED_ADMIN_USER_ID;
|
||||||
|
private static final UserHandle CONTEXT_USER = UserHandle.of(CONTEXT_USER_ID);
|
||||||
|
|
||||||
private static final ComponentName ADMIN_COMPONENT =
|
private static final ComponentName ADMIN_COMPONENT =
|
||||||
new ComponentName("some.package.name", "some.package.name.SomeClass");
|
new ComponentName("some.package.name", "some.package.name.SomeClass");
|
||||||
private static final String URL = "https://testexample.com";
|
private static final String URL = "https://testexample.com";
|
||||||
private static final Uri URI = Uri.parse(URL);
|
private static final Uri URI = Uri.parse(URL);
|
||||||
|
|
||||||
|
@Rule
|
||||||
|
public final MockitoRule mMockitoRule = MockitoJUnit.rule();
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<Intent> mIntentCaptor;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private AlertDialog.Builder mBuilder;
|
||||||
|
|
||||||
|
private ActionDisabledLearnMoreButtonLauncherImpl mImpl;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private UserManager mUserManager;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
// Can't mock getSystemService(Class) directly because it's final
|
||||||
|
when(mActivity.getSystemServiceName(UserManager.class)).thenReturn(Context.USER_SERVICE);
|
||||||
|
when(mActivity.getSystemService(Context.USER_SERVICE)).thenReturn(mUserManager);
|
||||||
|
|
||||||
|
when(mActivity.getUserId()).thenReturn(CONTEXT_USER_ID);
|
||||||
|
when(mUserManager.getUserHandle()).thenReturn(CONTEXT_USER_ID);
|
||||||
|
|
||||||
|
mImpl = new ActionDisabledLearnMoreButtonLauncherImpl(mActivity, mBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void showAdminPolicies_noComponent_works() {
|
public void launchShowAdminSettings_works() {
|
||||||
final EnforcedAdmin enforcedAdmin = createEnforcedAdmin(/* component= */ null);
|
mImpl.launchShowAdminSettings(mActivity);
|
||||||
|
|
||||||
ActionDisabledLearnMoreButtonLauncherImpl.SHOW_ADMIN_POLICIES
|
verify(mActivity).startActivity(mIntentCaptor.capture());
|
||||||
.accept(mActivity, enforcedAdmin);
|
assertDeviceAdminSettingsActivity(mIntentCaptor.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
@Test
|
||||||
verify(mActivity).startActivity(captor.capture());
|
public void launchShowAdminPolicies_works() {
|
||||||
assertThat(captor.getValue().getComponent().getClassName())
|
mImpl.launchShowAdminPolicies(mActivity, ENFORCED_ADMIN_USER, ADMIN_COMPONENT);
|
||||||
|
|
||||||
|
verify(mActivity).startActivityAsUser(mIntentCaptor.capture(), eq(ENFORCED_ADMIN_USER));
|
||||||
|
assertDeviceAdminAddIntent(mIntentCaptor.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void showHelpPage_works() {
|
||||||
|
mImpl.showHelpPage(mActivity, URL);
|
||||||
|
|
||||||
|
verify(mActivity).startActivityAsUser(mIntentCaptor.capture(), eq(CONTEXT_USER));
|
||||||
|
assertActionViewIntent(mIntentCaptor.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertDeviceAdminSettingsActivity(Intent intent) {
|
||||||
|
assertThat(intent.getComponent().getClassName())
|
||||||
.isEqualTo(Settings.DeviceAdminSettingsActivity.class.getName());
|
.isEqualTo(Settings.DeviceAdminSettingsActivity.class.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void showAdminPolicies_withComponent_works() {
|
|
||||||
final EnforcedAdmin enforcedAdmin = createEnforcedAdmin(ADMIN_COMPONENT);
|
|
||||||
|
|
||||||
ActionDisabledLearnMoreButtonLauncherImpl.SHOW_ADMIN_POLICIES
|
|
||||||
.accept(mActivity, enforcedAdmin);
|
|
||||||
|
|
||||||
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
|
||||||
verify(mActivity).startActivityAsUser(
|
|
||||||
captor.capture(),
|
|
||||||
eq(UserHandle.of(ENFORCED_ADMIN_USER_ID)));
|
|
||||||
assertDeviceAdminAddIntent(captor.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void launchHelpPage_works() {
|
|
||||||
ActionDisabledLearnMoreButtonLauncherImpl.LAUNCH_HELP_PAGE.accept(mActivity, URL);
|
|
||||||
|
|
||||||
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
|
||||||
verify(mActivity).startActivityAsUser(captor.capture(), eq(UserHandle.SYSTEM));
|
|
||||||
assertActionViewIntent(captor.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
private EnforcedAdmin createEnforcedAdmin(ComponentName component) {
|
|
||||||
return new RestrictedLockUtils.EnforcedAdmin(
|
|
||||||
component, UserHandle.of(ENFORCED_ADMIN_USER_ID));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void assertDeviceAdminAddIntent(Intent intent) {
|
private void assertDeviceAdminAddIntent(Intent intent) {
|
||||||
assertThat(intent.getComponent().getClassName())
|
assertThat(intent.getComponent().getClassName())
|
||||||
.isEqualTo(DeviceAdminAdd.class.getName());
|
.isEqualTo(DeviceAdminAdd.class.getName());
|
||||||
|
Reference in New Issue
Block a user