Search in sources :

Example 51 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RecentNotifyingAppsPreferenceControllerTest method display_showRecentsWithInstantApp.

@Test
public void display_showRecentsWithInstantApp() throws Exception {
    List<Event> events = new ArrayList<>();
    Event app = new Event();
    app.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app.mPackage = "com.foo.bar";
    app.mTimeStamp = System.currentTimeMillis();
    events.add(app);
    Event app1 = new Event();
    app1.mEventType = Event.NOTIFICATION_INTERRUPTION;
    app1.mPackage = "com.foo.barinstant";
    app1.mTimeStamp = System.currentTimeMillis() + 200;
    events.add(app1);
    UsageEvents usageEvents = getUsageEvents(new String[] { "com.foo.bar", "com.foo.barinstant" }, events);
    when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString())).thenReturn(usageEvents);
    ApplicationsState.AppEntry app1Entry = mock(ApplicationsState.AppEntry.class);
    ApplicationsState.AppEntry app2Entry = mock(ApplicationsState.AppEntry.class);
    app1Entry.info = mApplicationInfo;
    app2Entry.info = mApplicationInfo;
    when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId())).thenReturn(app1Entry);
    when(mAppState.getEntry(app1.getPackageName(), UserHandle.myUserId())).thenReturn(app2Entry);
    // Only the regular app app1 should have its intent resolve.
    when(mPackageManager.resolveActivity(argThat(intentMatcher(app.getPackageName())), anyInt())).thenReturn(new ResolveInfo());
    // Make sure app2 is considered an instant app.
    ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider", (InstantAppDataProvider) (ApplicationInfo info) -> {
        if (info == app2Entry.info) {
            return true;
        } else {
            return false;
        }
    });
    mController.displayPreference(mScreen);
    ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
    verify(mCategory, times(2)).addPreference(prefCaptor.capture());
    List<Preference> prefs = prefCaptor.getAllValues();
    assertThat(prefs.get(1).getKey()).isEqualTo(RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app.getPackageName()));
    assertThat(prefs.get(0).getKey()).isEqualTo(RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(), app1.getPackageName()));
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) Preference(androidx.preference.Preference) ApplicationsState(com.android.settingslib.applications.ApplicationsState) ArrayList(java.util.ArrayList) ApplicationInfo(android.content.pm.ApplicationInfo) Event(android.app.usage.UsageEvents.Event) UsageEvents(android.app.usage.UsageEvents) Test(org.junit.Test)

Example 52 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class PulseNotificationPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    when(mContext.getResources()).thenReturn(mResources);
    mController = new PulseNotificationPreferenceController(mContext, "testkey");
    mPreference = new Preference(mContext);
    mPreference.setKey(mController.getPreferenceKey());
    when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
Also used : TwoStatePreference(androidx.preference.TwoStatePreference) Preference(androidx.preference.Preference) Before(org.junit.Before)

Example 53 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RingtonePreferenceControllerBaseTest method updateState_shouldSetSummary.

@Test
public void updateState_shouldSetSummary() {
    Preference preference = mock(Preference.class);
    Settings.System.putString(mContext.getContentResolver(), Settings.System.RINGTONE, "content://test/ringtone");
    mController.updateState(preference);
    verify(preference).setSummary(anyString());
}
Also used : Preference(androidx.preference.Preference) Test(org.junit.Test)

Example 54 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SnoozeNotificationPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mController = new SnoozeNotificationPreferenceController(mContext, "key");
    mPreference = new Preference(RuntimeEnvironment.application);
    mPreference.setKey(mController.getPreferenceKey());
    when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
Also used : TwoStatePreference(androidx.preference.TwoStatePreference) Preference(androidx.preference.Preference) Before(org.junit.Before)

Example 55 with Preference

use of androidx.preference.Preference in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VibrateWhenRingPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = spy(RuntimeEnvironment.application);
    mContentResolver = mContext.getContentResolver();
    when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
    mController = new VibrateWhenRingPreferenceController(mContext, KEY_VIBRATE_WHEN_RINGING);
    mPreference = new Preference(mContext);
    mPreference.setKey(mController.getPreferenceKey());
    when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
}
Also used : TwoStatePreference(androidx.preference.TwoStatePreference) Preference(androidx.preference.Preference) Before(org.junit.Before)

Aggregations

Preference (androidx.preference.Preference)863 Test (org.junit.Test)343 Before (org.junit.Before)164 Intent (android.content.Intent)81 PreferenceScreen (androidx.preference.PreferenceScreen)81 NotificationChannel (android.app.NotificationChannel)77 SwitchPreference (androidx.preference.SwitchPreference)75 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)69 Context (android.content.Context)60 ArrayList (java.util.ArrayList)50 NotificationBackend (com.android.settings.notification.NotificationBackend)45 ListPreference (androidx.preference.ListPreference)43 PreferenceCategory (androidx.preference.PreferenceCategory)40 Tile (com.android.settingslib.drawer.Tile)40 PreferenceManager (androidx.preference.PreferenceManager)39 Activity (android.app.Activity)27 UserHandle (android.os.UserHandle)27 FooterPreference (com.android.settingslib.widget.FooterPreference)27 PackageManager (android.content.pm.PackageManager)26 Bundle (android.os.Bundle)24