Search in sources :

Example 31 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.

the class BridgedAppsPreferenceControllerTest method onPreferenceChange_true.

@Test
public void onPreferenceChange_true() {
    VersionedPackage vp = new VersionedPackage("pkg", 567);
    VersionedPackage vp2 = new VersionedPackage("pkg", 10567);
    ArraySet<VersionedPackage> vps = new ArraySet<>();
    vps.add(vp);
    vps.add(vp2);
    NotificationListenerFilter nlf = new NotificationListenerFilter(FLAG_FILTER_TYPE_ONGOING | FLAG_FILTER_TYPE_CONVERSATIONS, vps);
    when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
    when(mNm.getListenerFilter(mCn, 0)).thenReturn(nlf);
    CheckBoxPreference pref = new CheckBoxPreference(mContext);
    pref.setKey("pkg|567");
    mController.onPreferenceChange(pref, true);
    ArgumentCaptor<NotificationListenerFilter> captor = ArgumentCaptor.forClass(NotificationListenerFilter.class);
    verify(mNm).setListenerFilter(eq(mCn), eq(0), captor.capture());
    assertThat(captor.getValue().getDisallowedPackages().size()).isEqualTo(1);
    assertThat(captor.getValue().getDisallowedPackages()).contains(new VersionedPackage("pkg", 10567));
}
Also used : ArraySet(android.util.ArraySet) CheckBoxPreference(androidx.preference.CheckBoxPreference) VersionedPackage(android.content.pm.VersionedPackage) NotificationListenerFilter(android.service.notification.NotificationListenerFilter) Test(org.junit.Test)

Example 32 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.

the class BridgedAppsPreferenceControllerTest method onRebuildComplete_doesNotReaddToScreen.

@Test
public void onRebuildComplete_doesNotReaddToScreen() {
    when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
    when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
    CheckBoxPreference p = mock(CheckBoxPreference.class);
    when(p.getKey()).thenReturn("pkg|12300");
    mScreen.addPreference(p);
    ArrayList<ApplicationsState.AppEntry> entries = new ArrayList<>();
    entries.add(mAppEntry);
    entries.add(mAppEntry2);
    mController.onRebuildComplete(entries);
    assertThat(mScreen.getPreferenceCount()).isEqualTo(2);
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) ArrayList(java.util.ArrayList) NotificationListenerFilter(android.service.notification.NotificationListenerFilter) Test(org.junit.Test)

Example 33 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.

the class TypeFilterPreferenceControllerTest method onPreferenceChange_true.

@Test
public void onPreferenceChange_true() {
    NotificationListenerFilter nlf = new NotificationListenerFilter(FLAG_FILTER_TYPE_ONGOING | FLAG_FILTER_TYPE_CONVERSATIONS, new ArraySet<>());
    when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
    when(mNm.getListenerFilter(mCn, 0)).thenReturn(nlf);
    CheckBoxPreference pref = new CheckBoxPreference(mContext);
    mController.onPreferenceChange(pref, true);
    ArgumentCaptor<NotificationListenerFilter> captor = ArgumentCaptor.forClass(NotificationListenerFilter.class);
    verify(mNm).setListenerFilter(eq(mCn), eq(0), captor.capture());
    assertThat(captor.getValue().getTypes()).isEqualTo(FLAG_FILTER_TYPE_CONVERSATIONS | FLAG_FILTER_TYPE_ONGOING | mController.getType());
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) NotificationListenerFilter(android.service.notification.NotificationListenerFilter) Test(org.junit.Test)

Example 34 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.

the class TypeFilterPreferenceControllerTest method updateState_enabled_metaData_notTheDisableFilter.

@Test
public void updateState_enabled_metaData_notTheDisableFilter() {
    mSi.metaData = new Bundle();
    mSi.metaData.putCharSequence("test", "value");
    when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
    when(mNm.getListenerFilter(mCn, 0)).thenReturn(new NotificationListenerFilter());
    CheckBoxPreference pref = new CheckBoxPreference(mContext);
    mController.updateState(pref);
    assertThat(pref.isEnabled()).isTrue();
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) Bundle(android.os.Bundle) NotificationListenerFilter(android.service.notification.NotificationListenerFilter) Test(org.junit.Test)

Example 35 with CheckBoxPreference

use of androidx.preference.CheckBoxPreference in project android_packages_apps_Settings by omnirom.

the class TypeFilterPreferenceControllerTest method updateState_unchecked.

@Test
public void updateState_unchecked() {
    NotificationListenerFilter nlf = new NotificationListenerFilter(mController.getType() - 1, new ArraySet<>());
    when(mNm.isNotificationListenerAccessGranted(mCn)).thenReturn(true);
    when(mNm.getListenerFilter(mCn, 0)).thenReturn(nlf);
    CheckBoxPreference pref = new CheckBoxPreference(mContext);
    mController.updateState(pref);
    assertThat(pref.isChecked()).isFalse();
}
Also used : CheckBoxPreference(androidx.preference.CheckBoxPreference) NotificationListenerFilter(android.service.notification.NotificationListenerFilter) Test(org.junit.Test)

Aggregations

CheckBoxPreference (androidx.preference.CheckBoxPreference)36 Test (org.junit.Test)16 NotificationListenerFilter (android.service.notification.NotificationListenerFilter)14 Preference (androidx.preference.Preference)8 ListPreference (androidx.preference.ListPreference)7 Bundle (android.os.Bundle)6 VersionedPackage (android.content.pm.VersionedPackage)4 SparseLongArray (android.util.SparseLongArray)4 AppInfo (com.android.settings.fuelgauge.batterytip.AppInfo)4 AppCheckBoxPreference (com.android.settings.widget.AppCheckBoxPreference)4 Context (android.content.Context)3 SharedPreferences (android.content.SharedPreferences)3 PackageManager (android.content.pm.PackageManager)3 ArraySet (android.util.ArraySet)3 EditTextPreference (androidx.preference.EditTextPreference)3 PreferenceCategory (androidx.preference.PreferenceCategory)3 SeekBarPreference (androidx.preference.SeekBarPreference)3 ArrayList (java.util.ArrayList)3 ApplicationInfo (android.content.pm.ApplicationInfo)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2