mUserId = getIntent().getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
+ final UserHandle user;
+ if (mUserId == UserHandle.USER_NULL) {
+ user = null;
+ } else {
+ user = UserHandle.of(mUserId);
+ }
+
DevicePolicyManager dpm = getSystemService(DevicePolicyManager.class);
final int numberOfCertificates = getIntent().getIntExtra(
Settings.EXTRA_NUMBER_OF_CERTIFICATES, 1);
- final int titleId = RestrictedLockUtils.getProfileOrDeviceOwner(this, mUserId) != null
+ final int titleId = RestrictedLockUtils.getProfileOrDeviceOwner(this, user) != null
? R.plurals.ssl_ca_cert_settings_button // Check certificate
: R.plurals.ssl_ca_cert_dialog_title; // Trust or remove certificate
final CharSequence title = getResources().getQuantityText(titleId, numberOfCertificates);
public EnforcedAdmin getRestrictionEnforcedAdmin() {
mEnforcedAdmin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(getActivity(),
mRestrictionKey, UserHandle.myUserId());
- if (mEnforcedAdmin != null && mEnforcedAdmin.userId == UserHandle.USER_NULL) {
- mEnforcedAdmin.userId = UserHandle.myUserId();
+ if (mEnforcedAdmin != null && mEnforcedAdmin.user == null) {
+ mEnforcedAdmin.user = UserHandle.of(UserHandle.myUserId());
}
return mEnforcedAdmin;
}
&& !mDpm.isCaCertApproved(certHolder.getAlias(), certHolder.getUserId());
final boolean isProfileOrDeviceOwner = RestrictedLockUtils.getProfileOrDeviceOwner(
- mActivity, certHolder.getUserId()) != null;
+ mActivity, UserHandle.of(certHolder.getUserId())) != null;
// Show trust button only when it requires consumer user (non-PO/DO) to approve
CharSequence displayText = mActivity.getText(!isProfileOrDeviceOwner && mNeedsApproval
public EnforcedAdmin getRestrictionEnforcedAdmin() {
mEnforcedAdmin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(getActivity(),
mRestrictionKey, UserHandle.myUserId());
- if (mEnforcedAdmin != null && mEnforcedAdmin.userId == UserHandle.USER_NULL) {
- mEnforcedAdmin.userId = UserHandle.myUserId();
+ if (mEnforcedAdmin != null && mEnforcedAdmin.user == null) {
+ mEnforcedAdmin.user = UserHandle.of(UserHandle.myUserId());
}
return mEnforcedAdmin;
}
@androidx.annotation.VisibleForTesting
EnforcedAdmin getAdminDetailsFromIntent(Intent intent) {
- final EnforcedAdmin admin = new EnforcedAdmin(null, UserHandle.myUserId());
+ final EnforcedAdmin admin = new EnforcedAdmin(null, UserHandle.of(UserHandle.myUserId()));
if (intent == null) {
return admin;
}
admin.component = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
- admin.userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
+
+ int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
+ if (userId == UserHandle.USER_NULL) {
+ admin.user = null;
+ } else {
+ admin.user = UserHandle.of(userId);
+ }
return admin;
}
package com.android.settings.enterprise;
+import android.annotation.UserIdInt;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.ComponentName;
mActivity = activity;
}
+ private @UserIdInt int getEnforcementAdminUserId() {
+ if (mEnforcedAdmin.user == null) {
+ return UserHandle.USER_NULL;
+ } else {
+ return mEnforcedAdmin.user.getIdentifier();
+ }
+ }
+
public AlertDialog.Builder prepareDialogBuilder(String restriction,
EnforcedAdmin enforcedAdmin) {
mEnforcedAdmin = enforcedAdmin;
final AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
mDialogView = (ViewGroup) LayoutInflater.from(builder.getContext()).inflate(
R.layout.admin_support_details_dialog, null);
- initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
+ initializeDialogViews(mDialogView, mEnforcedAdmin.component, getEnforcementAdminUserId(),
mRestriction);
return builder
.setPositiveButton(R.string.okay, null)
}
mEnforcedAdmin = admin;
mRestriction = restriction;
- initializeDialogViews(mDialogView, mEnforcedAdmin.component, mEnforcedAdmin.userId,
+ initializeDialogViews(mDialogView, mEnforcedAdmin.component, getEnforcementAdminUserId(),
mRestriction);
}
}
setAdminSupportTitle(root, restriction);
- setAdminSupportDetails(mActivity, root, new EnforcedAdmin(admin, userId));
+
+ final UserHandle user;
+ if (userId == UserHandle.USER_NULL) {
+ user = null;
+ } else {
+ user = UserHandle.of(userId);
+ }
+
+ setAdminSupportDetails(mActivity, root, new EnforcedAdmin(admin, user));
}
@VisibleForTesting
if (enforcedAdmin == null || enforcedAdmin.component == null) {
return;
}
+
+ final int userId;
+ if (enforcedAdmin.user == null) {
+ userId = UserHandle.USER_NULL;
+ } else {
+ userId = enforcedAdmin.user.getIdentifier();
+ }
+
final DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService(
Context.DEVICE_POLICY_SERVICE);
if (!RestrictedLockUtilsInternal.isAdminInCurrentUserOrProfile(activity,
enforcedAdmin.component) || !RestrictedLockUtils.isCurrentUserOrProfile(
- activity, enforcedAdmin.userId)) {
+ activity, userId)) {
enforcedAdmin.component = null;
} else {
- if (enforcedAdmin.userId == UserHandle.USER_NULL) {
- enforcedAdmin.userId = UserHandle.myUserId();
+ if (enforcedAdmin.user == null) {
+ enforcedAdmin.user = UserHandle.of(UserHandle.myUserId());
}
CharSequence supportMessage = null;
if (UserHandle.isSameApp(Process.myUid(), Process.SYSTEM_UID)) {
- supportMessage = dpm.getShortSupportMessageForUser(
- enforcedAdmin.component, enforcedAdmin.userId);
+ supportMessage = dpm.getShortSupportMessageForUser(enforcedAdmin.component, userId);
}
if (supportMessage != null) {
final TextView textView = root.findViewById(R.id.admin_support_msg);
enforcedAdmin.component);
intent.putExtra(DeviceAdminAdd.EXTRA_CALLED_FROM_SUPPORT_DIALOG, true);
// DeviceAdminAdd class may need to run as managed profile.
- activity.startActivityAsUser(intent,
- new UserHandle(enforcedAdmin.userId));
+ activity.startActivityAsUser(intent, enforcedAdmin.user);
} else {
intent.setClass(activity, Settings.DeviceAdminSettingsActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
+import android.os.UserHandle;
import android.os.UserManager;
import android.view.View;
@BeforeClass
public static void beforeClass() {
- sFakeEnforcedAdmin = new EnforcedAdmin(new ComponentName("test.package", "test.Class"), 10);
+ sFakeEnforcedAdmin = new EnforcedAdmin(new ComponentName("test.package", "test.Class"),
+ UserHandle.of(10));
}
@Mock
import android.content.Intent;
import android.content.pm.UserInfo;
import android.os.Process;
+import android.os.UserHandle;
import android.os.UserManager;
import android.view.ViewGroup;
import android.widget.FrameLayout;
final int userId = 123;
final ComponentName component = new ComponentName("some.package.name",
"some.package.name.SomeClass");
- final EnforcedAdmin admin = new EnforcedAdmin(component, userId);
+ final EnforcedAdmin admin = new EnforcedAdmin(component, UserHandle.of(userId));
mHelper.showAdminPolicies(admin, mActivity);
@Test
public void testShowAdminPoliciesWithoutComponent() {
final int userId = 123;
- final EnforcedAdmin admin = new EnforcedAdmin(null, userId);
+ final EnforcedAdmin admin = new EnforcedAdmin(null, UserHandle.of(userId));
mHelper.showAdminPolicies(admin, mActivity);
final Intent intent = mActivityShadow.getNextStartedActivity();
assertEquals(intent.getComponent(), new ComponentName(mActivity,
final ViewGroup view = new FrameLayout(mActivity);
final ComponentName component = new ComponentName("some.package.name",
"some.package.name.SomeClass");
- final EnforcedAdmin admin = new EnforcedAdmin(component, 123);
+ final EnforcedAdmin admin = new EnforcedAdmin(component, UserHandle.of(123));
final TextView textView = new TextView(mActivity);
textView.setId(R.id.admin_support_msg);
final ShadowUserManager userManagerShadow = Shadow.extract(userManager);
final ComponentName component = new ComponentName("some.package.name",
"some.package.name.SomeClass");
- final EnforcedAdmin admin = new EnforcedAdmin(component, 123);
+ final EnforcedAdmin admin = new EnforcedAdmin(component, UserHandle.of(123));
dpmShadow.setShortSupportMessageForUser(component, 123, "some message");
dpmShadow.setIsAdminActiveAsUser(false);
public void testGetAdminDetailsFromIntent() {
final int userId = 123;
final ComponentName component = new ComponentName("com.some.package", ".SomeClass");
- final EnforcedAdmin expectedAdmin = new EnforcedAdmin(component, userId);
+ final EnforcedAdmin expectedAdmin = new EnforcedAdmin(component, UserHandle.of(userId));
final Intent intent = new Intent();
intent.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, component);
@Test
public void testGetAdminDetailsFromNullIntent() {
final int userId = UserHandle.myUserId();
- final EnforcedAdmin expectedAdmin = new EnforcedAdmin(null, userId);
+ final EnforcedAdmin expectedAdmin = new EnforcedAdmin(null, UserHandle.of(userId));
Assert.assertEquals(expectedAdmin, mDialog.getAdminDetailsFromIntent(null));
}