Search in sources :

Example 1 with CompatibilityChangeConfig

use of com.android.internal.compat.CompatibilityChangeConfig in project android_packages_apps_Settings by omnirom.

the class PlatformCompatDashboardTest method createPreferenceForChange_defaultEnabledChange_createCheckedEntry.

@Test
public void createPreferenceForChange_defaultEnabledChange_createCheckedEntry() {
    CompatibilityChangeInfo enabledChange = mChanges[0];
    CompatibilityChangeConfig config = new CompatibilityChangeConfig(new ChangeConfig(new HashSet<Long>(Arrays.asList(enabledChange.getId())), new HashSet<Long>()));
    Preference enabledPreference = mDashboard.createPreferenceForChange(mContext, enabledChange, config);
    SwitchPreference enabledSwitchPreference = (SwitchPreference) enabledPreference;
    assertThat(enabledPreference.getSummary()).isEqualTo(mChanges[0].getName());
    assertThat(enabledPreference instanceof SwitchPreference).isTrue();
    assertThat(enabledSwitchPreference.isChecked()).isTrue();
    assertThat(enabledSwitchPreference.isEnabled()).isTrue();
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) SwitchPreference(androidx.preference.SwitchPreference) ChangeConfig(android.compat.Compatibility.ChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 2 with CompatibilityChangeConfig

use of com.android.internal.compat.CompatibilityChangeConfig in project android_packages_apps_Settings by omnirom.

the class PlatformCompatDashboardTest method createPreferenceForChange_defaultDisabledChange_createUncheckedEntry.

@Test
public void createPreferenceForChange_defaultDisabledChange_createUncheckedEntry() {
    CompatibilityChangeInfo disabledChange = mChanges[1];
    CompatibilityChangeConfig config = new CompatibilityChangeConfig(new ChangeConfig(new HashSet<Long>(), new HashSet<Long>(Arrays.asList(disabledChange.getId()))));
    Preference disabledPreference = mDashboard.createPreferenceForChange(mContext, disabledChange, config);
    assertThat(disabledPreference.getSummary()).isEqualTo(mChanges[1].getName());
    SwitchPreference disabledSwitchPreference = (SwitchPreference) disabledPreference;
    assertThat(disabledSwitchPreference.isChecked()).isFalse();
    assertThat(disabledSwitchPreference.isEnabled()).isTrue();
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) SwitchPreference(androidx.preference.SwitchPreference) ChangeConfig(android.compat.Compatibility.ChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with CompatibilityChangeConfig

use of com.android.internal.compat.CompatibilityChangeConfig in project android_packages_apps_Settings by omnirom.

the class PlatformCompatDashboard method addPreferences.

private void addPreferences(ApplicationInfo applicationInfo) {
    getPreferenceScreen().removeAll();
    getPreferenceScreen().addPreference(createAppPreference(applicationInfo));
    // Differentiate compatibility changes into default enabled, default disabled and enabled
    // after target sdk.
    final CompatibilityChangeConfig configMappings = getAppChangeMappings();
    final List<CompatibilityChangeInfo> enabledChanges = new ArrayList<>();
    final List<CompatibilityChangeInfo> disabledChanges = new ArrayList<>();
    final Map<Integer, List<CompatibilityChangeInfo>> targetSdkChanges = new TreeMap<>();
    for (CompatibilityChangeInfo change : mChanges) {
        if (change.getEnableSinceTargetSdk() > 0) {
            List<CompatibilityChangeInfo> sdkChanges;
            if (!targetSdkChanges.containsKey(change.getEnableSinceTargetSdk())) {
                sdkChanges = new ArrayList<>();
                targetSdkChanges.put(change.getEnableSinceTargetSdk(), sdkChanges);
            } else {
                sdkChanges = targetSdkChanges.get(change.getEnableSinceTargetSdk());
            }
            sdkChanges.add(change);
        } else if (change.getDisabled()) {
            disabledChanges.add(change);
        } else {
            enabledChanges.add(change);
        }
    }
    createChangeCategoryPreference(enabledChanges, configMappings, getString(R.string.platform_compat_default_enabled_title));
    createChangeCategoryPreference(disabledChanges, configMappings, getString(R.string.platform_compat_default_disabled_title));
    for (Integer sdk : targetSdkChanges.keySet()) {
        createChangeCategoryPreference(targetSdkChanges.get(sdk), configMappings, getString(R.string.platform_compat_target_sdk_title, sdk));
    }
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo)

Example 4 with CompatibilityChangeConfig

use of com.android.internal.compat.CompatibilityChangeConfig in project android_packages_apps_Settings by omnirom.

the class PlatformCompatDashboardTest method createChangeCategoryPreference_enabledAndDisabled_hasTitleAndEntries.

@Test
public void createChangeCategoryPreference_enabledAndDisabled_hasTitleAndEntries() {
    Set<Long> enabledChanges = new HashSet<>();
    enabledChanges.add(mChanges[0].getId());
    enabledChanges.add(mChanges[1].getId());
    enabledChanges.add(mChanges[2].getId());
    Set<Long> disabledChanges = new HashSet<>();
    disabledChanges.add(mChanges[3].getId());
    disabledChanges.add(mChanges[4].getId());
    CompatibilityChangeConfig config = new CompatibilityChangeConfig(new ChangeConfig(enabledChanges, disabledChanges));
    List<CompatibilityChangeInfo> changesToAdd = new ArrayList<>();
    for (int i = 0; i < mChanges.length; ++i) {
        changesToAdd.add(new CompatibilityChangeInfo(mChanges[i].getId(), mChanges[i].getName(), -1, mChanges[i].getEnableSinceTargetSdk(), mChanges[i].getDisabled(), mChanges[i].getLoggingOnly(), mChanges[i].getDescription(), mChanges[i].getOverridable()));
    }
    PreferenceCategory category = mDashboard.createChangeCategoryPreference(changesToAdd, config, "foo");
    assertThat(category.getTitle()).isEqualTo("foo");
    assertThat(category.getPreferenceCount()).isEqualTo(mChanges.length);
    for (int i = 0; i < mChanges.length; ++i) {
        Preference childPreference = category.getPreference(i);
        assertThat(childPreference instanceof SwitchPreference).isTrue();
    }
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) SwitchPreference(androidx.preference.SwitchPreference) ChangeConfig(android.compat.Compatibility.ChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ArrayList(java.util.ArrayList) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) HashSet(java.util.HashSet) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo) Test(org.junit.Test)

Example 5 with CompatibilityChangeConfig

use of com.android.internal.compat.CompatibilityChangeConfig in project android_packages_apps_Settings by omnirom.

the class PlatformCompatDashboardTest method createPreferenceForChange_cannotOverride_createDisabledEntry.

@Test
public void createPreferenceForChange_cannotOverride_createDisabledEntry() throws RemoteException {
    CompatibilityChangeInfo enabledChange = mChanges[0];
    CompatibilityChangeConfig config = new CompatibilityChangeConfig(new ChangeConfig(new HashSet<Long>(Arrays.asList(enabledChange.getId())), new HashSet<Long>()));
    when(mOverrideValidator.getOverrideAllowedState(anyLong(), anyString())).thenReturn(new OverrideAllowedState(DISABLED_NOT_DEBUGGABLE, -1, -1));
    Preference preference = mDashboard.createPreferenceForChange(mContext, enabledChange, config);
    SwitchPreference switchPreference = (SwitchPreference) preference;
    assertThat(preference.getSummary()).isEqualTo(mChanges[0].getName());
    assertThat(preference instanceof SwitchPreference).isTrue();
    assertThat(switchPreference.isChecked()).isTrue();
    assertThat(switchPreference.isEnabled()).isFalse();
}
Also used : OverrideAllowedState(com.android.internal.compat.OverrideAllowedState) SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) SwitchPreference(androidx.preference.SwitchPreference) ChangeConfig(android.compat.Compatibility.ChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

CompatibilityChangeConfig (com.android.internal.compat.CompatibilityChangeConfig)5 CompatibilityChangeInfo (com.android.internal.compat.CompatibilityChangeInfo)5 ChangeConfig (android.compat.Compatibility.ChangeConfig)4 Preference (androidx.preference.Preference)4 SwitchPreference (androidx.preference.SwitchPreference)4 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 PreferenceCategory (androidx.preference.PreferenceCategory)1 OverrideAllowedState (com.android.internal.compat.OverrideAllowedState)1 List (java.util.List)1 TreeMap (java.util.TreeMap)1 ArgumentMatchers.anyLong (org.mockito.ArgumentMatchers.anyLong)1