Search in sources :

Example 11 with Preference

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

the class AccountDetailDashboardFragmentTest method refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent.

@Test
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
    final DashboardFeatureProviderImpl dashboardFeatureProvider = new DashboardFeatureProviderImpl(mContext);
    final PackageManager packageManager = mock(PackageManager.class);
    ReflectionHelpers.setField(dashboardFeatureProvider, "mPackageManager", packageManager);
    when(packageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(mock(ResolveInfo.class));
    final Tile tile = new Tile(mActivityInfo, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_KEYHINT, "key");
    mActivityInfo.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
    mActivityInfo.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
    mActivityInfo.metaData.putString(META_DATA_PREFERENCE_TITLE, "summary");
    mActivityInfo.metaData.putString("com.android.settings.intent.action", Intent.ACTION_ASSIST);
    tile.userHandle = null;
    mFragment.displayTile(tile);
    final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
    final Preference preference = new Preference(mContext);
    dashboardFeatureProvider.bindPreferenceToTile(activity, false, /* forceRoundedIcon */
    MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, preference, tile, null, /* key */
    Preference.DEFAULT_ORDER);
    assertThat(preference.getKey()).isEqualTo(tile.getKey(mContext));
    preference.performClick();
    final Intent intent = Shadows.shadowOf(activity).getNextStartedActivityForResult().intent;
    assertThat(intent.getStringExtra("extra.accountName")).isEqualTo("name1@abc.com");
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) FragmentActivity(androidx.fragment.app.FragmentActivity) PackageManager(android.content.pm.PackageManager) Preference(androidx.preference.Preference) DashboardFeatureProviderImpl(com.android.settings.dashboard.DashboardFeatureProviderImpl) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) Test(org.junit.Test)

Example 12 with Preference

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

the class AccountPreferenceControllerTest method onResume_twoAccountsOfSameType_shouldAddThreePreferences.

@Test
public void onResume_twoAccountsOfSameType_shouldAddThreePreferences() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", 0));
    when(mUserManager.isManagedProfile()).thenReturn(false);
    when(mUserManager.isRestrictedProfile()).thenReturn(false);
    when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
    Account[] accounts = { new Account("Account1", "com.acct1") };
    when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
    Account[] accountType1 = { new Account("Account11", "com.acct1"), new Account("Account12", "com.acct1") };
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
    AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
    when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
    AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
    when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
    when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
    mController.onResume();
    // should add 2 individual account and the Add account preference
    verify(preferenceGroup, times(3)).addPreference(any(Preference.class));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) Preference(androidx.preference.Preference) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Example 13 with Preference

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

the class EmergencyInfoPreferenceControllerTest method handlePreferenceTreeClick_shouldStartActivity.

@Test
public void handlePreferenceTreeClick_shouldStartActivity() {
    final ShadowApplication application = ShadowApplication.getInstance();
    final Activity activity = Robolectric.setupActivity(Activity.class);
    final Preference preference = new Preference(activity);
    preference.setKey("emergency_info");
    mController = new EmergencyInfoPreferenceController(activity, preference.getKey());
    mController.handlePreferenceTreeClick(preference);
    assertThat(application.getNextStartedActivity().getAction()).isEqualTo("android.settings.EDIT_EMERGENCY_INFO");
}
Also used : Preference(androidx.preference.Preference) Activity(android.app.Activity) ShadowApplication(org.robolectric.shadows.ShadowApplication) Test(org.junit.Test)

Example 14 with Preference

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

the class EmergencyInfoPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    mController = new EmergencyInfoPreferenceController(mContext, "test_key");
    mPreference = new Preference(Robolectric.setupActivity(Activity.class));
    mPreference.setKey(mController.getPreferenceKey());
    when(mScreen.findPreference(mPreference.getKey())).thenReturn(mPreference);
    when(mContext.getResources().getBoolean(R.bool.config_show_emergency_info_in_device_info)).thenReturn(true);
}
Also used : Preference(androidx.preference.Preference) Before(org.junit.Before)

Example 15 with Preference

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

the class AllAppsInfoPreferenceControllerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    final Context context = spy(RuntimeEnvironment.application);
    final Preference preference = new Preference(context);
    doReturn(mUserManager).when(context).getSystemService(Context.USER_SERVICE);
    when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {});
    mController = new AllAppsInfoPreferenceController(context, "test_key");
    mController.mPreference = preference;
}
Also used : Context(android.content.Context) Preference(androidx.preference.Preference) Before(org.junit.Before)

Aggregations

Preference (androidx.preference.Preference)860 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)41 Tile (com.android.settingslib.drawer.Tile)40 PreferenceCategory (androidx.preference.PreferenceCategory)39 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