Disable UI in Settings app when DISALLOW_CONFIG_LOCATION_MODE is set.
Bug: 67674888 Test: m -j RunSettingsRoboTest Change-Id: I13a4fa4a3122bfd9b84f935c0aa83c019490eac9
This commit is contained in:
@@ -34,6 +34,7 @@ import com.android.settingslib.core.lifecycle.events.OnPause;
|
|||||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||||
|
|
||||||
import static com.android.settingslib.Utils.updateLocationMode;
|
import static com.android.settingslib.Utils.updateLocationMode;
|
||||||
|
import static com.android.settingslib.RestrictedLockUtils.checkIfRestrictionEnforced;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class that listens to location settings change and modifies location settings
|
* A class that listens to location settings change and modifies location settings
|
||||||
@@ -140,8 +141,14 @@ public class LocationEnabler implements LifecycleObserver, OnResume, OnPause {
|
|||||||
}
|
}
|
||||||
|
|
||||||
RestrictedLockUtils.EnforcedAdmin getShareLocationEnforcedAdmin(int userId) {
|
RestrictedLockUtils.EnforcedAdmin getShareLocationEnforcedAdmin(int userId) {
|
||||||
return RestrictedLockUtils.checkIfRestrictionEnforced(
|
RestrictedLockUtils.EnforcedAdmin admin = checkIfRestrictionEnforced(
|
||||||
mContext, UserManager.DISALLOW_SHARE_LOCATION, userId);
|
mContext, UserManager.DISALLOW_SHARE_LOCATION, userId);
|
||||||
|
|
||||||
|
if (admin == null) {
|
||||||
|
admin = RestrictedLockUtils.checkIfRestrictionEnforced(
|
||||||
|
mContext, UserManager.DISALLOW_CONFIG_LOCATION_MODE, userId);
|
||||||
|
}
|
||||||
|
return admin;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasShareLocationRestriction(int userId) {
|
boolean hasShareLocationRestriction(int userId) {
|
||||||
|
@@ -209,6 +209,23 @@ public class LocationEnablerTest {
|
|||||||
assertThat(mEnabler.isManagedProfileRestrictedByBase()).isTrue();
|
assertThat(mEnabler.isManagedProfileRestrictedByBase()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setRestriction_getShareLocationEnforcedAdmin_shouldReturnEnforcedAdmin() {
|
||||||
|
int userId = UserHandle.myUserId();
|
||||||
|
List<UserManager.EnforcingUser> enforcingUsers = new ArrayList<>();
|
||||||
|
// Add two enforcing users so that RestrictedLockUtils.checkIfRestrictionEnforced returns
|
||||||
|
// non-null.
|
||||||
|
enforcingUsers.add(new UserManager.EnforcingUser(userId,
|
||||||
|
UserManager.RESTRICTION_SOURCE_DEVICE_OWNER));
|
||||||
|
enforcingUsers.add(new UserManager.EnforcingUser(userId,
|
||||||
|
UserManager.RESTRICTION_SOURCE_PROFILE_OWNER));
|
||||||
|
when(mUserManager.getUserRestrictionSources(
|
||||||
|
UserManager.DISALLOW_CONFIG_LOCATION_MODE, UserHandle.of(userId)))
|
||||||
|
.thenReturn(enforcingUsers);
|
||||||
|
|
||||||
|
assertThat(mEnabler.getShareLocationEnforcedAdmin(userId) != null).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
private void mockManagedProfile() {
|
private void mockManagedProfile() {
|
||||||
final List<UserHandle> userProfiles = new ArrayList<>();
|
final List<UserHandle> userProfiles = new ArrayList<>();
|
||||||
final UserHandle userHandle = mock(UserHandle.class);
|
final UserHandle userHandle = mock(UserHandle.class);
|
||||||
@@ -223,4 +240,6 @@ public class LocationEnablerTest {
|
|||||||
private static ArgumentMatcher<Intent> actionMatches(String expected) {
|
private static ArgumentMatcher<Intent> actionMatches(String expected) {
|
||||||
return intent -> TextUtils.equals(expected, intent.getAction());
|
return intent -> TextUtils.equals(expected, intent.getAction());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user