Search in sources :

Example 61 with PreferenceManager

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

the class UsbDetailsPowerRoleControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mLifecycle = new Lifecycle(() -> mLifecycle);
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    when(mFragment.getActivity()).thenReturn(mActivity);
    when(mActivity.getApplicationContext()).thenReturn(mContext);
    when(mFragment.getContext()).thenReturn(mContext);
    when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
    when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
    mDetailsPowerRoleController = new UsbDetailsPowerRoleController(mContext, mFragment, mUsbBackend);
    mPreference = new PreferenceCategory(mContext);
    mPreference.setKey(mDetailsPowerRoleController.getPreferenceKey());
    mScreen.addPreference(mPreference);
    mDetailsPowerRoleController.mHandler = mHandler;
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 62 with PreferenceManager

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

the class UsbDetailsDataRoleControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mContext = RuntimeEnvironment.application;
    mLifecycle = new Lifecycle(() -> mLifecycle);
    mPreferenceManager = new PreferenceManager(mContext);
    mScreen = mPreferenceManager.createPreferenceScreen(mContext);
    when(mFragment.getActivity()).thenReturn(mActivity);
    when(mActivity.getApplicationContext()).thenReturn(mContext);
    when(mFragment.getContext()).thenReturn(mContext);
    when(mFragment.getPreferenceManager()).thenReturn(mPreferenceManager);
    when(mFragment.getPreferenceScreen()).thenReturn(mScreen);
    mDetailsDataRoleController = new UsbDetailsDataRoleController(mContext, mFragment, mUsbBackend);
    mPreference = new PreferenceCategory(mContext);
    mPreference.setKey(mDetailsDataRoleController.getPreferenceKey());
    mScreen.addPreference(mPreference);
    mDetailsDataRoleController.mHandler = mHandler;
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) Lifecycle(com.android.settingslib.core.lifecycle.Lifecycle) PreferenceManager(androidx.preference.PreferenceManager) Before(org.junit.Before)

Example 63 with PreferenceManager

use of androidx.preference.PreferenceManager 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)

Example 64 with PreferenceManager

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

the class GraphicsDriverAppPreferenceControllerTest method loadConfig.

private void loadConfig(String optIn, String prereleaseOptIn, String optOut) {
    Settings.Global.putString(mResolver, Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_IN_APPS, optIn);
    Settings.Global.putString(mResolver, Settings.Global.UPDATABLE_DRIVER_PRERELEASE_OPT_IN_APPS, prereleaseOptIn);
    Settings.Global.putString(mResolver, Settings.Global.UPDATABLE_DRIVER_PRODUCTION_OPT_OUT_APPS, optOut);
    mController = new GraphicsDriverAppPreferenceController(mContext, "testKey");
    mController.mEntryList = mContext.getResources().getStringArray(R.array.graphics_driver_app_preference_values);
    mGroup = spy(new PreferenceCategory(mContext));
    final PreferenceManager preferenceManager = new PreferenceManager(mContext);
    when(mGroup.getContext()).thenReturn(mContext);
    when(mGroup.getPreferenceManager()).thenReturn(preferenceManager);
    when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mGroup);
    mController.displayPreference(mScreen);
}
Also used : PreferenceCategory(androidx.preference.PreferenceCategory) PreferenceManager(androidx.preference.PreferenceManager)

Example 65 with PreferenceManager

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

the class RecentConversationsPreferenceControllerTest method testRemoveConversations.

@Test
public void testRemoveConversations() throws Exception {
    ShortcutInfo si = mock(ShortcutInfo.class);
    when(si.getId()).thenReturn("person");
    when(si.getPackage()).thenReturn("pkg");
    ConversationChannel ccw = new ConversationChannel(si, 6, new NotificationChannel("hi", "hi", 4), new NotificationChannelGroup("hi", "group"), 7, false);
    ConversationChannel ccw2 = new ConversationChannel(si, 6, new NotificationChannel("bye", "bye", 4), new NotificationChannelGroup("hi", "group"), 7, true);
    PreferenceCategory group = new PreferenceCategory(mContext);
    PreferenceScreen screen = new PreferenceManager(mContext).createPreferenceScreen(mContext);
    screen.addPreference(group);
    RecentConversationPreference pref = mController.createConversationPref(new PreferenceCategory(mContext), ccw, 100);
    final View view = View.inflate(mContext, pref.getLayoutResource(), null);
    PreferenceViewHolder holder = spy(PreferenceViewHolder.createInstanceForTests(view));
    View delete = View.inflate(mContext, pref.getSecondTargetResId(), null);
    when(holder.findViewById(pref.getClearId())).thenReturn(delete);
    group.addPreference(pref);
    RecentConversationPreference pref2 = mController.createConversationPref(new PreferenceCategory(mContext), ccw2, 100);
    final View view2 = View.inflate(mContext, pref2.getLayoutResource(), null);
    PreferenceViewHolder holder2 = spy(PreferenceViewHolder.createInstanceForTests(view2));
    View delete2 = View.inflate(mContext, pref2.getSecondTargetResId(), null);
    when(holder2.findViewById(pref.getClearId())).thenReturn(delete2);
    group.addPreference(pref2);
    LayoutPreference clearAll = mController.getClearAll(group);
    group.addPreference(clearAll);
    clearAll.findViewById(R.id.conversation_settings_clear_recents).performClick();
    verify(mPs).removeAllRecentConversations();
    assertThat((Preference) group.findPreference("hi:person")).isNull();
    assertThat((Preference) group.findPreference("bye:person")).isNotNull();
}
Also used : NotificationChannel(android.app.NotificationChannel) LayoutPreference(com.android.settingslib.widget.LayoutPreference) NotificationChannelGroup(android.app.NotificationChannelGroup) ShortcutInfo(android.content.pm.ShortcutInfo) ConversationChannel(android.app.people.ConversationChannel) PreferenceScreen(androidx.preference.PreferenceScreen) PreferenceCategory(androidx.preference.PreferenceCategory) LayoutPreference(com.android.settingslib.widget.LayoutPreference) Preference(androidx.preference.Preference) PreferenceManager(androidx.preference.PreferenceManager) View(android.view.View) PreferenceViewHolder(androidx.preference.PreferenceViewHolder) Test(org.junit.Test)

Aggregations

PreferenceManager (androidx.preference.PreferenceManager)87 Before (org.junit.Before)67 Preference (androidx.preference.Preference)23 PreferenceCategory (androidx.preference.PreferenceCategory)22 PreferenceScreen (androidx.preference.PreferenceScreen)19 Test (org.junit.Test)18 Lifecycle (com.android.settingslib.core.lifecycle.Lifecycle)15 Context (android.content.Context)5 LifecycleRegistry (androidx.lifecycle.LifecycleRegistry)5 ArrayList (java.util.ArrayList)5 NotificationChannel (android.app.NotificationChannel)4 ShortcutInfo (android.content.pm.ShortcutInfo)4 View (android.view.View)4 NotificationChannelGroup (android.app.NotificationChannelGroup)3 ConversationChannel (android.app.people.ConversationChannel)3 PackageInfo (android.content.pm.PackageInfo)3 PersistableBundle (android.os.PersistableBundle)3 BluetoothManager (android.bluetooth.BluetoothManager)2 SoftApConfiguration (android.net.wifi.SoftApConfiguration)2 WifiManager (android.net.wifi.WifiManager)2