Search in sources :

Example 6 with DashboardFeatureProviderImpl

use of com.android.settings.dashboard.DashboardFeatureProviderImpl in project platform_packages_apps_Settings by BlissRoms.

the class AccountDetailDashboardFragmentTest method refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent.

@Test
public void refreshDashboardTiles_HasAccountType_shouldAddAccountNameToIntent() {
    FakeFeatureFactory.setupForTest(mActivity);
    final FakeFeatureFactory featureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mActivity);
    final DashboardFeatureProviderImpl dashboardFeatureProvider = new DashboardFeatureProviderImpl(mActivity);
    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();
    tile.key = "key";
    tile.metaData = new Bundle();
    tile.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
    tile.metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
    tile.metaData.putString("com.android.settings.intent.action", Intent.ACTION_ASSIST);
    tile.intent = new Intent();
    tile.userHandle = null;
    mFragment.displayTile(tile);
    final Activity activity = Robolectric.buildActivity(Activity.class).get();
    final Preference preference = new Preference(mContext);
    dashboardFeatureProvider.bindPreferenceToTile(activity, MetricsProto.MetricsEvent.DASHBOARD_SUMMARY, preference, tile, "key", Preference.DEFAULT_ORDER);
    preference.performClick();
    final Intent intent = shadowOf(activity).getNextStartedActivityForResult().intent;
    assertThat(intent.getStringExtra("extra.accountName")).isEqualTo("name1@abc.com");
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) Preference(android.support.v7.preference.Preference) Bundle(android.os.Bundle) DashboardFeatureProviderImpl(com.android.settings.dashboard.DashboardFeatureProviderImpl) Tile(com.android.settingslib.drawer.Tile) Activity(android.app.Activity) Intent(android.content.Intent) FakeFeatureFactory(com.android.settings.testutils.FakeFeatureFactory) Test(org.junit.Test)

Example 7 with DashboardFeatureProviderImpl

use of com.android.settings.dashboard.DashboardFeatureProviderImpl in project android_packages_apps_Settings by omnirom.

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 ActivityTile(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.bindPreferenceToTileAndGetObservers(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) ActivityTile(com.android.settingslib.drawer.ActivityTile) Tile(com.android.settingslib.drawer.Tile) Intent(android.content.Intent) ActivityTile(com.android.settingslib.drawer.ActivityTile) Test(org.junit.Test)

Aggregations

Intent (android.content.Intent)7 PackageManager (android.content.pm.PackageManager)7 ResolveInfo (android.content.pm.ResolveInfo)7 DashboardFeatureProviderImpl (com.android.settings.dashboard.DashboardFeatureProviderImpl)7 Tile (com.android.settingslib.drawer.Tile)7 Test (org.junit.Test)7 Activity (android.app.Activity)5 Bundle (android.os.Bundle)5 Preference (android.support.v7.preference.Preference)5 FakeFeatureFactory (com.android.settings.testutils.FakeFeatureFactory)5 FragmentActivity (androidx.fragment.app.FragmentActivity)2 Preference (androidx.preference.Preference)2 ActivityTile (com.android.settingslib.drawer.ActivityTile)1