Search in sources :

Example 1 with RestrictedAppPreference

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);
}
Also used : Preference(androidx.preference.Preference) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) List(java.util.List) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) Map(java.util.Map)

Example 2 with RestrictedAppPreference

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);
        }
    }
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) Preference(androidx.preference.Preference) List(java.util.List) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) Map(java.util.Map)

Example 3 with RestrictedAppPreference

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();
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) Preference(androidx.preference.Preference) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) ArrayList(java.util.ArrayList) List(java.util.List) ComponentName(android.content.ComponentName) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) Test(org.junit.Test)

Example 4 with RestrictedAppPreference

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);
            }
        }
    }
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) Preference(androidx.preference.Preference) List(java.util.List) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) Map(java.util.Map)

Example 5 with RestrictedAppPreference

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();
}
Also used : Context(android.content.Context) ArrayList(java.util.ArrayList) ArrayMap(android.util.ArrayMap) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) Preference(androidx.preference.Preference) UserManager(android.os.UserManager) ShadowUserManager(com.android.settings.testutils.shadow.ShadowUserManager) ArrayList(java.util.ArrayList) List(java.util.List) ComponentName(android.content.ComponentName) RestrictedAppPreference(com.android.settings.widget.RestrictedAppPreference) Test(org.junit.Test)

Aggregations

Preference (androidx.preference.Preference)5 RestrictedAppPreference (com.android.settings.widget.RestrictedAppPreference)5 List (java.util.List)5 Map (java.util.Map)3 ComponentName (android.content.ComponentName)2 Context (android.content.Context)2 UserManager (android.os.UserManager)2 ArrayMap (android.util.ArrayMap)2 PreferenceCategory (androidx.preference.PreferenceCategory)2 ShadowUserManager (com.android.settings.testutils.shadow.ShadowUserManager)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2