Fix ActionDisabledByAdminDialogHelperTest
- Revert user handling in setAdminSupportDetails to before my changes. - Implement getUserProfiles in Settings-shadows as the the Settings-shadows do not forwarded to profiles the robolectric-default shadows Test: make RunSettingsRoboTests Change-Id: Idfd4722fe55a17c57d336db943904eb1aeb6e7ce
This commit is contained in:
@@ -44,6 +44,8 @@ import com.android.settingslib.RestrictedLockUtils;
|
|||||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||||
|
|
||||||
|
import libcore.util.NonNull;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -61,14 +63,18 @@ public class ActionDisabledByAdminDialogHelper {
|
|||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private @UserIdInt int getEnforcementAdminUserId() {
|
private @UserIdInt int getEnforcementAdminUserId(@NonNull EnforcedAdmin admin) {
|
||||||
if (mEnforcedAdmin.user == null) {
|
if (admin.user == null) {
|
||||||
return UserHandle.USER_NULL;
|
return UserHandle.USER_NULL;
|
||||||
} else {
|
} else {
|
||||||
return mEnforcedAdmin.user.getIdentifier();
|
return admin.user.getIdentifier();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @UserIdInt int getEnforcementAdminUserId() {
|
||||||
|
return getEnforcementAdminUserId(mEnforcedAdmin);
|
||||||
|
}
|
||||||
|
|
||||||
public AlertDialog.Builder prepareDialogBuilder(String restriction,
|
public AlertDialog.Builder prepareDialogBuilder(String restriction,
|
||||||
EnforcedAdmin enforcedAdmin) {
|
EnforcedAdmin enforcedAdmin) {
|
||||||
mEnforcedAdmin = enforcedAdmin;
|
mEnforcedAdmin = enforcedAdmin;
|
||||||
@@ -170,18 +176,11 @@ public class ActionDisabledByAdminDialogHelper {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int userId;
|
|
||||||
if (enforcedAdmin.user == null) {
|
|
||||||
userId = UserHandle.USER_NULL;
|
|
||||||
} else {
|
|
||||||
userId = enforcedAdmin.user.getIdentifier();
|
|
||||||
}
|
|
||||||
|
|
||||||
final DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService(
|
final DevicePolicyManager dpm = (DevicePolicyManager) activity.getSystemService(
|
||||||
Context.DEVICE_POLICY_SERVICE);
|
Context.DEVICE_POLICY_SERVICE);
|
||||||
if (!RestrictedLockUtilsInternal.isAdminInCurrentUserOrProfile(activity,
|
if (!RestrictedLockUtilsInternal.isAdminInCurrentUserOrProfile(activity,
|
||||||
enforcedAdmin.component) || !RestrictedLockUtils.isCurrentUserOrProfile(
|
enforcedAdmin.component) || !RestrictedLockUtils.isCurrentUserOrProfile(
|
||||||
activity, userId)) {
|
activity, getEnforcementAdminUserId(enforcedAdmin))) {
|
||||||
enforcedAdmin.component = null;
|
enforcedAdmin.component = null;
|
||||||
} else {
|
} else {
|
||||||
if (enforcedAdmin.user == null) {
|
if (enforcedAdmin.user == null) {
|
||||||
@@ -189,7 +188,8 @@ public class ActionDisabledByAdminDialogHelper {
|
|||||||
}
|
}
|
||||||
CharSequence supportMessage = null;
|
CharSequence supportMessage = null;
|
||||||
if (UserHandle.isSameApp(Process.myUid(), Process.SYSTEM_UID)) {
|
if (UserHandle.isSameApp(Process.myUid(), Process.SYSTEM_UID)) {
|
||||||
supportMessage = dpm.getShortSupportMessageForUser(enforcedAdmin.component, userId);
|
supportMessage = dpm.getShortSupportMessageForUser(enforcedAdmin.component,
|
||||||
|
getEnforcementAdminUserId(enforcedAdmin));
|
||||||
}
|
}
|
||||||
if (supportMessage != null) {
|
if (supportMessage != null) {
|
||||||
final TextView textView = root.findViewById(R.id.admin_support_msg);
|
final TextView textView = root.findViewById(R.id.admin_support_msg);
|
||||||
|
@@ -88,6 +88,16 @@ public class ShadowUserManager extends org.robolectric.shadows.ShadowUserManager
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Implementation
|
||||||
|
public List<UserHandle> getUserProfiles(){
|
||||||
|
int[] userIds = getProfileIds(UserHandle.myUserId(), true /* enabledOnly */);
|
||||||
|
List<UserHandle> result = new ArrayList<>(userIds.length);
|
||||||
|
for (int userId : userIds) {
|
||||||
|
result.add(UserHandle.of(userId));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@Implementation
|
@Implementation
|
||||||
public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
|
public int getCredentialOwnerProfile(@UserIdInt int userHandle) {
|
||||||
return userHandle;
|
return userHandle;
|
||||||
|
Reference in New Issue
Block a user