use of com.android.settings.widget.RestrictedAppPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class LocationServicePreferenceController method updateState.
@Override
public void updateState(Preference preference) {
mCategoryLocationServices.removeAll();
mCategoryLocationServicesManaged.removeAll();
final Map<Integer, List<Preference>> prefs = getLocationServices();
boolean showPrimary = false;
boolean showManaged = false;
for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
for (Preference pref : entry.getValue()) {
if (pref instanceof RestrictedAppPreference) {
((RestrictedAppPreference) pref).checkRestrictionAndSetDisabled();
}
}
if (entry.getKey() == UserHandle.myUserId()) {
LocationSettings.addPreferencesSorted(entry.getValue(), mCategoryLocationServices);
showPrimary = true;
} else {
LocationSettings.addPreferencesSorted(entry.getValue(), mCategoryLocationServicesManaged);
showManaged = true;
}
}
mCategoryLocationServices.setVisible(showPrimary);
mCategoryLocationServicesManaged.setVisible(showManaged);
}
use of com.android.settings.widget.RestrictedAppPreference in project android_packages_apps_Settings by omnirom.
the class LocationInjectedServicesForWorkPreferenceController method injectLocationServices.
@Override
protected void injectLocationServices(PreferenceScreen screen) {
final PreferenceCategory categoryLocationServices = screen.findPreference(getPreferenceKey());
final Map<Integer, List<Preference>> prefs = getLocationServices();
for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
for (Preference pref : entry.getValue()) {
if (pref instanceof RestrictedAppPreference) {
((RestrictedAppPreference) pref).checkRestrictionAndSetDisabled();
}
}
if (entry.getKey() != UserHandle.myUserId()) {
LocationSettings.addPreferencesSorted(entry.getValue(), categoryLocationServices);
}
}
}
use of com.android.settings.widget.RestrictedAppPreference in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class LocationServicePreferenceControllerTest method withUserRestriction_shouldDisableLocationAccuracy.
@Test
public void withUserRestriction_shouldDisableLocationAccuracy() {
final List<Preference> preferences = new ArrayList<>();
final RestrictedAppPreference pref = new RestrictedAppPreference(mContext, UserManager.DISALLOW_CONFIG_LOCATION);
pref.setTitle("Location Accuracy");
preferences.add(pref);
final Map<Integer, List<Preference>> map = new ArrayMap<>();
map.put(UserHandle.myUserId(), preferences);
doReturn(map).when(mSettingsInjector).getInjectedSettings(any(Context.class), anyInt());
ShadowUserManager.getShadow().setProfileIdsWithDisabled(new int[] { UserHandle.myUserId() });
final int userId = UserHandle.myUserId();
List<UserManager.EnforcingUser> enforcingUsers = new ArrayList<>();
enforcingUsers.add(new UserManager.EnforcingUser(userId, UserManager.RESTRICTION_SOURCE_DEVICE_OWNER));
ComponentName componentName = new ComponentName("test", "test");
// Ensure that RestrictedLockUtils.checkIfRestrictionEnforced doesn't return null.
ShadowUserManager.getShadow().setUserRestrictionSources(UserManager.DISALLOW_CONFIG_LOCATION, UserHandle.of(userId), enforcingUsers);
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(componentName);
mController.displayPreference(mScreen);
mController.updateState(mCategoryPrimary);
assertThat(pref.isEnabled()).isFalse();
assertThat(pref.isDisabledByAdmin()).isTrue();
}
use of com.android.settings.widget.RestrictedAppPreference in project android_packages_apps_Settings by omnirom.
the class LocationInjectedServicesPreferenceController method injectLocationServices.
@Override
protected void injectLocationServices(PreferenceScreen screen) {
final PreferenceCategory categoryLocationServices = screen.findPreference(getPreferenceKey());
final Map<Integer, List<Preference>> prefs = getLocationServices();
for (Map.Entry<Integer, List<Preference>> entry : prefs.entrySet()) {
for (Preference pref : entry.getValue()) {
if (pref instanceof RestrictedAppPreference) {
((RestrictedAppPreference) pref).checkRestrictionAndSetDisabled();
}
}
if (entry.getKey() == UserHandle.myUserId()) {
if (categoryLocationServices != null) {
LocationSettings.addPreferencesSorted(entry.getValue(), categoryLocationServices);
}
}
}
}
use of com.android.settings.widget.RestrictedAppPreference in project android_packages_apps_Settings by omnirom.
the class LocationInjectedServicesPreferenceControllerTest method withUserRestriction_shouldDisableLocationAccuracy.
@Test
public void withUserRestriction_shouldDisableLocationAccuracy() {
final List<Preference> preferences = new ArrayList<>();
final RestrictedAppPreference pref = new RestrictedAppPreference(mContext, UserManager.DISALLOW_CONFIG_LOCATION);
pref.setTitle("Location Accuracy");
preferences.add(pref);
final Map<Integer, List<Preference>> map = new ArrayMap<>();
map.put(UserHandle.myUserId(), preferences);
doReturn(map).when(mSettingsInjector).getInjectedSettings(any(Context.class), anyInt());
ShadowUserManager.getShadow().setProfileIdsWithDisabled(new int[] { UserHandle.myUserId() });
final int userId = UserHandle.myUserId();
List<UserManager.EnforcingUser> enforcingUsers = new ArrayList<>();
enforcingUsers.add(new UserManager.EnforcingUser(userId, UserManager.RESTRICTION_SOURCE_DEVICE_OWNER));
ComponentName componentName = new ComponentName("test", "test");
// Ensure that RestrictedLockUtils.checkIfRestrictionEnforced doesn't return null.
ShadowUserManager.getShadow().setUserRestrictionSources(UserManager.DISALLOW_CONFIG_LOCATION, UserHandle.of(userId), enforcingUsers);
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(componentName);
mController.displayPreference(mScreen);
assertThat(pref.isEnabled()).isFalse();
assertThat(pref.isDisabledByAdmin()).isTrue();
}
Aggregations