Search in sources :

Example 1 with CompatibilityChangeInfo

use of com.android.internal.compat.CompatibilityChangeInfo 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 CompatibilityChangeInfo

use of com.android.internal.compat.CompatibilityChangeInfo 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 CompatibilityChangeInfo

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

the class PlatformCompatDashboard method addChangePreferencesToCategory.

private void addChangePreferencesToCategory(List<CompatibilityChangeInfo> changes, PreferenceCategory category, CompatibilityChangeConfig configMappings) {
    for (CompatibilityChangeInfo change : changes) {
        final Preference preference = createPreferenceForChange(getPreferenceScreen().getContext(), change, configMappings);
        category.addPreference(preference);
    }
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo)

Example 4 with CompatibilityChangeInfo

use of com.android.internal.compat.CompatibilityChangeInfo 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 5 with CompatibilityChangeInfo

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

the class PlatformCompatDashboardTest method setUp.

@Before
public void setUp() throws RemoteException, NameNotFoundException {
    MockitoAnnotations.initMocks(this);
    mChanges = new CompatibilityChangeInfo[5];
    mChanges[0] = new CompatibilityChangeInfo(1L, "Default_Enabled", 0, 0, false, false, "", false);
    mChanges[1] = new CompatibilityChangeInfo(2L, "Default_Disabled", 0, 0, true, false, "", false);
    mChanges[2] = new CompatibilityChangeInfo(3L, "Enabled_Since_SDK_1_1", -1, 1, false, false, "", false);
    mChanges[3] = new CompatibilityChangeInfo(4L, "Enabled_Since_SDK_1_2", -1, 1, false, false, "", false);
    mChanges[4] = new CompatibilityChangeInfo(5L, "Enabled_Since_SDK_2", -1, 2, false, false, "", false);
    when(mPlatformCompat.listUIChanges()).thenReturn(mChanges);
    when(mPlatformCompat.getOverrideValidator()).thenReturn(mOverrideValidator);
    // By default, allow any change
    when(mOverrideValidator.getOverrideAllowedState(anyLong(), anyString())).thenReturn(new OverrideAllowedState(ALLOWED, -1, -1));
    mContext = spy(RuntimeEnvironment.application);
    mPreferenceManager = new PreferenceManager(mContext);
    mPreferenceScreen = mPreferenceManager.createPreferenceScreen(mContext);
    mApplicationInfo.packageName = APP_NAME;
    mDashboard = spy(new PlatformCompatDashboard());
    mDashboard.mSelectedApp = APP_NAME;
    doReturn(mApplicationInfo).when(mDashboard).getApplicationInfo();
    doReturn(mContext).when(mDashboard).getContext();
    doReturn(mPlatformCompat).when(mDashboard).getPlatformCompat();
    doReturn(mPreferenceScreen).when(mDashboard).getPreferenceScreen();
    doReturn(mPreferenceManager).when(mDashboard).getPreferenceManager();
    doReturn(mPackageManager).when(mContext).getPackageManager();
}
Also used : OverrideAllowedState(com.android.internal.compat.OverrideAllowedState) PreferenceManager(androidx.preference.PreferenceManager) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo) Before(org.junit.Before)

Aggregations

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