public class CategoryManager {
- public static final String SETTING_PKG = "com.android.settings";
-
private static final String TAG = "CategoryManager";
private static CategoryManager sInstance;
import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
+import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.service.settings.suggestions.Suggestion;
import android.text.TextUtils;
@VisibleForTesting
void onBindTile(DashboardItemHolder holder, Tile tile) {
- Drawable icon = mCache.getIcon(tile.icon);
- if (!TextUtils.equals(tile.icon.getResPackage(), mContext.getPackageName())
+ Icon tileIcon = tile.getIcon();
+ Drawable icon = mCache.getIcon(tileIcon);
+ if (!TextUtils.equals(tileIcon.getResPackage(), mContext.getPackageName())
&& !(icon instanceof RoundedHomepageIcon)) {
icon = new RoundedHomepageIcon(mContext, icon);
try {
TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT, 0 /* default */);
if (colorRes != 0) {
final int bgColor = mContext.getPackageManager()
- .getResourcesForApplication(tile.icon.getResPackage())
+ .getResourcesForApplication(tileIcon.getResPackage())
.getColor(colorRes, null /* theme */);
((RoundedHomepageIcon) icon).setBackgroundColor(bgColor);
}
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Failed to set background color for " + tile.intent.getPackage());
}
- mCache.updateIcon(tile.icon, icon);
+ mCache.updateIcon(tileIcon, icon);
}
holder.icon.setImageDrawable(icon);
holder.title.setText(tile.title);
@VisibleForTesting
void bindIcon(Preference preference, Tile tile) {
- if (tile.icon != null) {
- preference.setIcon(tile.icon.loadDrawable(preference.getContext()));
+ final Icon tileIcon = tile.getIcon();
+ if (tileIcon != null) {
+ preference.setIcon(tileIcon.loadDrawable(preference.getContext()));
} else if (tile.metaData != null
&& tile.metaData.containsKey(META_DATA_PREFERENCE_ICON_URI)) {
ThreadUtils.postOnBackgroundThread(() -> {
@VisibleForTesting
boolean tintTileIcon(Tile tile) {
- if (tile.icon == null) {
+ if (tile.getIcon() == null) {
return false;
}
// First check if the tile has set the icon tintable metadata.
/**
* Refresh preference items backed by DashboardCategory.
*/
- @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
+ @VisibleForTesting
void refreshDashboardTiles(final String TAG) {
final PreferenceScreen screen = getPreferenceScreen();
continue;
}
if (tintTileIcon(tile)) {
- tile.icon.setTint(tintColor);
+ tile.getIcon().setTint(tintColor);
}
if (mDashboardTilePrefKeys.contains(key)) {
// Have the key already, will rebind.
package com.android.settings.accounts;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.UserHandle;
+import androidx.preference.Preference;
+
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.dashboard.DashboardFeatureProviderImpl;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.robolectric.Shadows;
import org.robolectric.util.ReflectionHelpers;
-import androidx.preference.Preference;
-
@RunWith(SettingsRobolectricTestRunner.class)
public class AccountDetailDashboardFragmentTest {
@Test
public void testCategory_isAccountDetail() {
assertThat(new AccountDetailDashboardFragment().getCategoryKey())
- .isEqualTo(CategoryKey.CATEGORY_ACCOUNT_DETAIL);
+ .isEqualTo(CategoryKey.CATEGORY_ACCOUNT_DETAIL);
}
@Test
public void refreshDashboardTiles_HasAccountType_shouldDisplay() {
- final Tile tile = new Tile();
+ final Tile tile = new Tile(new ActivityInfo());
final Bundle metaData = new Bundle();
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
metaData.putString(METADATA_ACCOUNT_TYPE, "com.abc");
@Test
public void refreshDashboardTiles_NoAccountType_shouldNotDisplay() {
- final Tile tile = new Tile();
+ final Tile tile = new Tile(new ActivityInfo());
final Bundle metaData = new Bundle();
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
tile.metaData = metaData;
@Test
public void refreshDashboardTiles_OtherAccountType_shouldNotDisplay() {
- final Tile tile = new Tile();
+ final Tile tile = new Tile(new ActivityInfo());
final Bundle metaData = new Bundle();
metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT_DETAIL);
metaData.putString(METADATA_ACCOUNT_TYPE, "com.other");
final PackageManager packageManager = mock(PackageManager.class);
ReflectionHelpers.setField(dashboardFeatureProvider, "mPackageManager", packageManager);
when(packageManager.resolveActivity(any(Intent.class), anyInt()))
- .thenReturn(mock(ResolveInfo.class));
+ .thenReturn(mock(ResolveInfo.class));
- final Tile tile = new Tile();
+ final Tile tile = new Tile(new ActivityInfo());
tile.key = "key";
tile.metaData = new Bundle();
tile.metaData.putString(METADATA_CATEGORY, CategoryKey.CATEGORY_ACCOUNT);
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.content.pm.ApplicationInfo;
import android.util.Pair;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.shadows.ShadowApplication;
import java.util.HashMap;
@RunWith(SettingsRobolectricTestRunner.class)
public class CategoryManagerTest {
+ private ActivityInfo mActivityInfo;
private Context mContext;
private CategoryManager mCategoryManager;
private Map<Pair<String, String>, Tile> mTileByComponentCache;
@Before
public void setUp() {
- mContext = ShadowApplication.getInstance().getApplicationContext();
+ mContext = RuntimeEnvironment.application;
+ mActivityInfo = new ActivityInfo();
+ mActivityInfo.applicationInfo = new ApplicationInfo();
mTileByComponentCache = new HashMap<>();
mCategoryByKeyMap = new HashMap<>();
mCategoryManager = CategoryManager.get(mContext);
@Test
public void backwardCompatCleanupForCategory_shouldNotChangeCategoryForNewKeys() {
- final Tile tile1 = new Tile();
- final Tile tile2 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
+ final Tile tile2 = new Tile(mActivityInfo);
tile1.category = CategoryKey.CATEGORY_ACCOUNT;
tile2.category = CategoryKey.CATEGORY_ACCOUNT;
final DashboardCategory category = new DashboardCategory();
@Test
public void backwardCompatCleanupForCategory_shouldNotChangeCategoryForMixedKeys() {
- final Tile tile1 = new Tile();
- final Tile tile2 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
+ final Tile tile2 = new Tile(mActivityInfo);
final String oldCategory = "com.android.settings.category.wireless";
tile1.category = CategoryKey.CATEGORY_ACCOUNT;
tile2.category = oldCategory;
@Test
public void backwardCompatCleanupForCategory_shouldChangeCategoryForOldKeys() {
- final Tile tile1 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
final String oldCategory = "com.android.settings.category.wireless";
tile1.category = oldCategory;
final DashboardCategory category1 = new DashboardCategory();
// Create some fake tiles that are not sorted.
final String testPackage = "com.android.test";
final DashboardCategory category = new DashboardCategory();
- final Tile tile1 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
tile1.intent =
new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 100;
- final Tile tile2 = new Tile();
+ final Tile tile2 = new Tile(mActivityInfo);
tile2.intent =
new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 50;
- final Tile tile3 = new Tile();
+ final Tile tile3 = new Tile(mActivityInfo);
tile3.intent =
new Intent().setComponent(new ComponentName(testPackage, "class3"));
tile3.priority = 200;
final String testPackage1 = "com.android.test1";
final String testPackage2 = "com.android.test2";
final DashboardCategory category = new DashboardCategory();
- final Tile tile1 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
tile1.intent =
new Intent().setComponent(new ComponentName(testPackage2, "class1"));
tile1.priority = 100;
- final Tile tile2 = new Tile();
+ final Tile tile2 = new Tile(mActivityInfo);
tile2.intent =
new Intent().setComponent(new ComponentName(testPackage1, "class2"));
tile2.priority = 100;
- final Tile tile3 = new Tile();
+ final Tile tile3 = new Tile(mActivityInfo);
tile3.intent =
new Intent().setComponent(new ComponentName(testPackage1, "class3"));
tile3.priority = 50;
mCategoryByKeyMap.put(CategoryKey.CATEGORY_HOMEPAGE, category);
// Sort their priorities
- mCategoryManager.sortCategories(ShadowApplication.getInstance().getApplicationContext(),
- mCategoryByKeyMap);
+ mCategoryManager.sortCategories(mContext, mCategoryByKeyMap);
// Verify they are now sorted.
assertThat(category.getTile(0)).isSameAs(tile2);
@Test
public void sortCategories_internalPackageTiles_shouldSkipTileForInternalPackage() {
// Create some fake tiles that are not sorted.
- final String testPackage =
- ShadowApplication.getInstance().getApplicationContext().getPackageName();
+ final String testPackage = mContext.getPackageName();
final DashboardCategory category = new DashboardCategory();
- final Tile tile1 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
tile1.intent =
new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 100;
- final Tile tile2 = new Tile();
+ final Tile tile2 = new Tile(mActivityInfo);
tile2.intent =
new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 100;
- final Tile tile3 = new Tile();
+ final Tile tile3 = new Tile(mActivityInfo);
tile3.intent =
new Intent().setComponent(new ComponentName(testPackage, "class3"));
tile3.priority = 50;
mCategoryByKeyMap.put(CategoryKey.CATEGORY_HOMEPAGE, category);
// Sort their priorities
- mCategoryManager.sortCategories(ShadowApplication.getInstance().getApplicationContext(),
- mCategoryByKeyMap);
+ mCategoryManager.sortCategories(mContext, mCategoryByKeyMap);
// Verify the sorting order is not changed
assertThat(category.getTile(0)).isSameAs(tile1);
@Test
public void sortCategories_internalAndExternalPackageTiles_shouldRetainPriorityOrdering() {
// Inject one external tile among internal tiles.
- final String testPackage =
- ShadowApplication.getInstance().getApplicationContext().getPackageName();
+ final String testPackage = mContext.getPackageName();
final String testPackage2 = "com.google.test2";
final DashboardCategory category = new DashboardCategory();
- final Tile tile1 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
tile1.intent = new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 2;
- final Tile tile2 = new Tile();
+ final Tile tile2 = new Tile(mActivityInfo);
tile2.intent = new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 1;
- final Tile tile3 = new Tile();
+ final Tile tile3 = new Tile(mActivityInfo);
tile3.intent = new Intent().setComponent(new ComponentName(testPackage2, "class0"));
tile3.priority = 0;
- final Tile tile4 = new Tile();
+ final Tile tile4 = new Tile(mActivityInfo);
tile4.intent = new Intent().setComponent(new ComponentName(testPackage, "class3"));
tile4.priority = -1;
category.addTile(tile1);
mCategoryByKeyMap.put(CategoryKey.CATEGORY_HOMEPAGE, category);
// Sort their priorities
- mCategoryManager.sortCategories(ShadowApplication.getInstance().getApplicationContext(),
- mCategoryByKeyMap);
+ mCategoryManager.sortCategories(mContext, mCategoryByKeyMap);
// Verify the sorting order is not changed
assertThat(category.getTile(0)).isSameAs(tile1);
@Test
public void sortCategories_samePriority_internalPackageTileShouldTakePrecedence() {
// Inject one external tile among internal tiles with same priority.
- final String testPackage =
- ShadowApplication.getInstance().getApplicationContext().getPackageName();
+ final String testPackage = mContext.getPackageName();
final String testPackage2 = "com.google.test2";
final String testPackage3 = "com.abcde.test3";
final DashboardCategory category = new DashboardCategory();
- final Tile tile1 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
tile1.intent = new Intent().setComponent(new ComponentName(testPackage2, "class1"));
tile1.priority = 1;
- final Tile tile2 = new Tile();
+ final Tile tile2 = new Tile(mActivityInfo);
tile2.intent = new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 1;
- final Tile tile3 = new Tile();
+ final Tile tile3 = new Tile(mActivityInfo);
tile3.intent = new Intent().setComponent(new ComponentName(testPackage3, "class3"));
tile3.priority = 1;
category.addTile(tile1);
mCategoryByKeyMap.put(CategoryKey.CATEGORY_HOMEPAGE, category);
// Sort their priorities
- mCategoryManager.sortCategories(ShadowApplication.getInstance().getApplicationContext(),
- mCategoryByKeyMap);
+ mCategoryManager.sortCategories(mContext, mCategoryByKeyMap);
// Verify the sorting order is internal first, follow by package name ordering
assertThat(category.getTile(0)).isSameAs(tile2);
@Test
public void filterTiles_noDuplicate_noChange() {
// Create some unique tiles
- final String testPackage =
- ShadowApplication.getInstance().getApplicationContext().getPackageName();
+ final String testPackage = mContext.getPackageName();
final DashboardCategory category = new DashboardCategory();
- final Tile tile1 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
tile1.intent =
new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 100;
- final Tile tile2 = new Tile();
+ final Tile tile2 = new Tile(mActivityInfo);
tile2.intent =
new Intent().setComponent(new ComponentName(testPackage, "class2"));
tile2.priority = 100;
- final Tile tile3 = new Tile();
+ final Tile tile3 = new Tile(mActivityInfo);
tile3.intent =
new Intent().setComponent(new ComponentName(testPackage, "class3"));
tile3.priority = 50;
@Test
public void filterTiles_hasDuplicate_shouldOnlyKeepUniqueTiles() {
// Create tiles pointing to same intent.
- final String testPackage =
- ShadowApplication.getInstance().getApplicationContext().getPackageName();
+ final String testPackage = mContext.getPackageName();
final DashboardCategory category = new DashboardCategory();
- final Tile tile1 = new Tile();
+ final Tile tile1 = new Tile(mActivityInfo);
tile1.intent =
new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile1.priority = 100;
- final Tile tile2 = new Tile();
+ final Tile tile2 = new Tile(mActivityInfo);
tile2.intent =
new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile2.priority = 100;
- final Tile tile3 = new Tile();
+ final Tile tile3 = new Tile(mActivityInfo);
tile3.intent =
new Intent().setComponent(new ComponentName(testPackage, "class1"));
tile3.priority = 50;
package com.android.settings.dashboard;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import android.app.PendingIntent;
import android.content.Context;
+import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.view.WindowManager;
import android.widget.TextView;
+import androidx.recyclerview.widget.RecyclerView;
+
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.dashboard.conditional.Condition;
import java.util.ArrayList;
import java.util.List;
-import androidx.recyclerview.widget.RecyclerView;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
public class DashboardAdapterTest {
private Resources mResources;
@Mock
private WindowManager mWindowManager;
+ private ActivityInfo mActivityInfo;
private FakeFeatureFactory mFactory;
private DashboardAdapter mDashboardAdapter;
private List<Condition> mConditionList;
public void setUp() {
MockitoAnnotations.initMocks(this);
mFactory = FakeFeatureFactory.setupForTest();
+ mActivityInfo = new ActivityInfo();
when(mFactory.dashboardFeatureProvider.shouldTintIcon()).thenReturn(true);
when(mContext.getSystemService(Context.WINDOW_SERVICE)).thenReturn(mWindowManager);
adapter.onBindSuggestion(holder, 0);
- final DashboardData dashboardData = adapter.mDashboardData;
reset(adapter); // clear interactions tracking
final Suggestion suggestionToRemove = suggestions.get(1);
@Test
public void onSuggestionClosed_notInSuggestionList_shouldNotUpdateSuggestionList() {
final DashboardAdapter adapter =
- spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
- null /* conditions */, null /* suggestionControllerMixin */,
- null /* lifecycle */));
+ spy(new DashboardAdapter(mContext, null /* savedInstanceState */,
+ null /* conditions */, null /* suggestionControllerMixin */,
+ null /* lifecycle */));
final List<Suggestion> suggestions = makeSuggestionsV2("pkg1");
adapter.setSuggestions(suggestions);
- final DashboardData dashboardData = adapter.mDashboardData;
+
reset(adapter); // clear interactions tracking
adapter.onSuggestionClosed(mock(Suggestion.class));
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
final DashboardAdapter.DashboardItemHolder holder =
new DashboardAdapter.DashboardItemHolder(view);
- final Tile tile = new Tile();
- tile.icon = Icon.createWithResource(context, R.drawable.ic_settings);
+ final Tile tile = spy(new Tile(mActivityInfo));
+ doReturn(Icon.createWithResource(context, R.drawable.ic_settings))
+ .when(tile).getIcon();
final IconCache iconCache = mock(IconCache.class);
- when(iconCache.getIcon(tile.icon)).thenReturn(context.getDrawable(R.drawable.ic_settings));
+ when(iconCache.getIcon(tile.getIcon()))
+ .thenReturn(context.getDrawable(R.drawable.ic_settings));
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
final DashboardAdapter.DashboardItemHolder holder =
new DashboardAdapter.DashboardItemHolder(view);
- final Tile tile = new Tile();
- tile.icon = Icon.createWithResource(context, R.drawable.ic_settings);
- when(tile.icon.getResPackage()).thenReturn("another.package");
+ final Tile tile = spy(new Tile(mActivityInfo));
+ final Icon icon = Icon.createWithResource(context, R.drawable.ic_settings);
+ doReturn(icon).when(tile).getIcon();
final IconCache iconCache = new IconCache(context);
doReturn("another.package").when(context).getPackageName();
mDashboardAdapter.onBindTile(holder, tile);
- assertThat(iconCache.getIcon(tile.icon)).isInstanceOf(RoundedHomepageIcon.class);
+ assertThat(iconCache.getIcon(tile.getIcon())).isInstanceOf(RoundedHomepageIcon.class);
}
@Test
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
final DashboardAdapter.DashboardItemHolder holder =
new DashboardAdapter.DashboardItemHolder(view);
- final Tile tile = new Tile();
+ final Tile tile = spy(new Tile(mActivityInfo));
tile.metaData = new Bundle();
tile.metaData.putInt(TileUtils.META_DATA_PREFERENCE_ICON_BACKGROUND_HINT,
R.color.memory_critical);
- tile.icon = Icon.createWithResource(context, R.drawable.ic_settings);
+ doReturn(Icon.createWithResource(context, R.drawable.ic_settings))
+ .when(tile).getIcon();
final IconCache iconCache = new IconCache(context);
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
doReturn("another.package").when(context).getPackageName();
mDashboardAdapter.onBindTile(holder, tile);
- final RoundedHomepageIcon homepageIcon = (RoundedHomepageIcon) iconCache.getIcon(tile.icon);
+ final RoundedHomepageIcon homepageIcon = (RoundedHomepageIcon) iconCache.getIcon(
+ tile.getIcon());
assertThat(homepageIcon.mBackgroundColor)
.isEqualTo(RuntimeEnvironment.application.getColor(R.color.memory_critical));
}
final View view = LayoutInflater.from(context).inflate(R.layout.dashboard_tile, null);
final DashboardAdapter.DashboardItemHolder holder =
new DashboardAdapter.DashboardItemHolder(view);
- final Tile tile = new Tile();
- tile.icon = mock(Icon.class);
- when(tile.icon.getResPackage()).thenReturn("another.package");
+ final Tile tile = spy(new Tile(mActivityInfo));
+ doReturn(mock(Icon.class)).when(tile).getIcon();
+ when(tile.getIcon().getResPackage()).thenReturn("another.package");
final IconCache iconCache = mock(IconCache.class);
- when(iconCache.getIcon(tile.icon)).thenReturn(mock(RoundedHomepageIcon.class));
+ when(iconCache.getIcon(tile.getIcon())).thenReturn(mock(RoundedHomepageIcon.class));
mDashboardAdapter = new DashboardAdapter(context, null /* savedInstanceState */,
null /* conditions */, null /* suggestionControllerMixin */, null /* lifecycle */);
mDashboardAdapter.onBindTile(holder, tile);
- verify(iconCache, never()).updateIcon(eq(tile.icon), any(RoundedHomepageIcon.class));
+ verify(iconCache, never()).updateIcon(eq(tile.getIcon()), any(RoundedHomepageIcon.class));
}
private List<Suggestion> makeSuggestionsV2(String... pkgNames) {
import static com.android.settingslib.drawer.TileUtils.META_DATA_KEY_PROFILE;
import static com.android.settingslib.drawer.TileUtils.PROFILE_ALL;
import static com.android.settingslib.drawer.TileUtils.PROFILE_PRIMARY;
+
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.eq;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
import android.os.UserHandle;
import android.os.UserManager;
+import androidx.preference.Preference;
+
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import java.util.ArrayList;
-import androidx.preference.Preference;
-
@RunWith(SettingsRobolectricTestRunner.class)
@Config(shadows = ShadowUserManager.class)
public class DashboardFeatureProviderImplTest {
private FakeFeatureFactory mFeatureFactory;
private Context mContext;
+ private ActivityInfo mActivityInfo;
private DashboardFeatureProviderImpl mImpl;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+ mActivityInfo = new ActivityInfo();
doReturn(mPackageManager).when(mContext).getPackageManager();
when(mPackageManager.resolveActivity(any(Intent.class), anyInt()))
- .thenReturn(new ResolveInfo());
+ .thenReturn(new ResolveInfo());
mFeatureFactory = FakeFeatureFactory.setupForTest();
mImpl = new DashboardFeatureProviderImpl(mContext);
}
@Test
public void bindPreference_shouldBindAllData() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = spy(new Tile(mActivityInfo));
tile.title = "title";
tile.summary = "summary";
- tile.icon = Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565));
+ doReturn(Icon.createWithBitmap(Bitmap.createBitmap(1, 1, Bitmap.Config.RGB_565)))
+ .when(tile).getIcon();
tile.metaData = new Bundle();
tile.metaData.putString(SettingsActivity.META_DATA_KEY_FRAGMENT_CLASS, "HI");
tile.priority = 10;
@Test
public void bindPreference_noFragmentMetadata_shouldBindIntent() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.priority = 10;
tile.intent = new Intent();
@Test
public void bindPreference_noFragmentMetadata_shouldBindToProfileSelector() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.userHandle = new ArrayList<>();
tile.userHandle.add(mock(UserHandle.class));
@Test
public void bindPreference_noFragmentMetadataSingleUser_shouldBindToDirectLaunchIntent() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.userHandle = new ArrayList<>();
tile.userHandle.add(mock(UserHandle.class));
@Test
public void bindPreference_toInternalSettingActivity_shouldBindToDirectLaunchIntentAndNotLog() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.userHandle = new ArrayList<>();
tile.userHandle.add(mock(UserHandle.class));
@Test
public void bindPreference_withNullKeyNullPriority_shouldGenerateKeyAndPriority() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
@Test
public void bindPreference_noSummary_shouldSetSummaryToPlaceholder() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
@Test
public void bindPreference_hasSummary_shouldSetSummary() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.summary = "test";
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
@Config(shadows = {ShadowTileUtils.class, ShadowThreadUtils.class})
public void bindPreference_hasSummaryUri_shouldLoadSummaryFromContentProvider() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
tile.metaData = new Bundle();
@Test
public void bindPreference_withNullKeyTileKey_shouldUseTileKey() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.key = "key";
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
@Config(shadows = {ShadowTileUtils.class, ShadowThreadUtils.class})
public void bindPreference_withIconUri_shouldLoadIconFromContentProvider() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.key = "key";
tile.intent = new Intent();
tile.intent.setComponent(
public void bindPreference_withBaseOrder_shouldOffsetPriority() {
final int baseOrder = 100;
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.priority = 10;
mImpl.bindPreferenceToTile(mActivity, MetricsProto.MetricsEvent.VIEW_UNKNOWN,
public void bindPreference_withOrderMetadata_shouldUseOrderInMetadata() {
final Preference preference = new Preference(RuntimeEnvironment.application);
final int testOrder = -30;
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.metaData.putInt(mImpl.META_DATA_KEY_ORDER, testOrder);
tile.priority = 10;
@Test
public void bindPreference_invalidOrderMetadata_shouldIgnore() {
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.metaData.putString(mImpl.META_DATA_KEY_ORDER, "hello");
tile.priority = 10;
public void bindPreference_withIntentActionMetadata_shouldSetLaunchAction() {
Activity activity = Robolectric.buildActivity(Activity.class).get();
final Preference preference = new Preference(RuntimeEnvironment.application);
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.key = "key";
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
Activity activity = Robolectric.buildActivity(Activity.class).get();
final ShadowApplication application = ShadowApplication.getInstance();
final Preference preference = new Preference(application.getApplicationContext());
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.key = "key";
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
mImpl = new DashboardFeatureProviderImpl(mActivity);
ReflectionHelpers.setField(mImpl, "mCategoryManager", mCategoryManager);
final DashboardCategory category = new DashboardCategory();
- category.addTile(new Tile());
+ category.addTile(new Tile(mActivityInfo));
when(mCategoryManager
.getTilesByCategory(any(Context.class), eq(CategoryKey.CATEGORY_HOMEPAGE)))
.thenReturn(category);
@Test
public void openTileIntent_profileSelectionDialog_shouldShow() {
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.intent = new Intent();
tile.intent.setComponent(new ComponentName("pkg", "class"));
mImpl.openTileIntent(mActivity, tile);
verify(mActivity, never())
- .startActivityForResult(any(Intent.class), eq(0));
+ .startActivityForResult(any(Intent.class), eq(0));
verify(mActivity).getFragmentManager();
}
@Test
public void openTileIntent_profileSelectionDialog_explicitMetadataShouldShow() {
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_ALL);
tile.intent = new Intent();
mImpl.openTileIntent(mActivity, tile);
verify(mActivity, never())
- .startActivityForResult(any(Intent.class), eq(0));
+ .startActivityForResult(any(Intent.class), eq(0));
verify(mActivity).getFragmentManager();
}
+
@Test
public void openTileIntent_profileSelectionDialog_shouldNotShow() {
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
tile.metaData.putString(META_DATA_KEY_PROFILE, PROFILE_PRIMARY);
tile.intent = new Intent();
mImpl.openTileIntent(mActivity, tile);
verify(mActivity)
- .startActivityForResult(any(Intent.class), eq(0));
+ .startActivityForResult(any(Intent.class), eq(0));
verify(mActivity, never()).getFragmentManager();
}
}
package com.android.settings.dashboard;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.ArgumentMatchers.nullable;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
import android.graphics.drawable.Icon;
import android.os.Bundle;
+import androidx.preference.Preference;
+import androidx.preference.PreferenceManager;
+import androidx.preference.PreferenceScreen;
+
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import java.util.ArrayList;
import java.util.List;
-import androidx.preference.Preference;
-import androidx.preference.PreferenceManager;
-import androidx.preference.PreferenceScreen;
-
@RunWith(SettingsRobolectricTestRunner.class)
public class DashboardFragmentTest {
@Mock
private FakeFeatureFactory mFakeFeatureFactory;
+ private ActivityInfo mActivityInfo;
private DashboardCategory mDashboardCategory;
private Context mContext;
private TestFragment mTestFragment;
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
+ mActivityInfo = new ActivityInfo();
mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
mDashboardCategory = new DashboardCategory();
- mDashboardCategory.addTile(new Tile());
+ mDashboardCategory.addTile(new Tile(mActivityInfo));
mTestFragment = new TestFragment(RuntimeEnvironment.application);
when(mFakeFeatureFactory.dashboardFeatureProvider
.getTilesForCategory(nullable(String.class)))
@Test
public void tintTileIcon_hasMetadata_shouldReturnIconTintableMetadata() {
- final Tile tile = new Tile();
- tile.icon = mock(Icon.class);
+ final Tile tile = spy(new Tile(mActivityInfo));
+ doReturn(mock(Icon.class)).when(tile).getIcon();
final Bundle metaData = new Bundle();
tile.metaData = metaData;
@Test
public void tintTileIcon_noIcon_shouldReturnFalse() {
- final Tile tile = new Tile();
+ final Tile tile = new Tile(mActivityInfo);
tile.metaData = new Bundle();
assertThat(mTestFragment.tintTileIcon(tile)).isFalse();
@Test
public void tintTileIcon_noMetadata_shouldReturnPackageNameCheck() {
- final Tile tile = new Tile();
- tile.icon = mock(Icon.class);
+ final Tile tile = spy(new Tile(mActivityInfo));
+ doReturn(mock(Icon.class)).when(tile).getIcon();
final Intent intent = new Intent();
tile.intent = intent;
intent.setComponent(
- new ComponentName(RuntimeEnvironment.application.getPackageName(), "TestClass"));
+ new ComponentName(RuntimeEnvironment.application.getPackageName(), "TestClass"));
assertThat(mTestFragment.tintTileIcon(tile)).isFalse();
intent.setComponent(new ComponentName("OtherPackage", "TestClass"));
import static com.google.common.truth.Truth.assertThat;
+import android.content.pm.ActivityInfo;
import android.view.View;
import android.widget.TextView;
+import androidx.recyclerview.widget.RecyclerView;
+
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settingslib.drawer.Tile;
import org.junit.runner.RunWith;
import org.robolectric.RuntimeEnvironment;
-import androidx.recyclerview.widget.RecyclerView;
-
@RunWith(SettingsRobolectricTestRunner.class)
public class DashboardItemAnimatorTest {
public void SetUp() {
mDashboardItemAnimator = new DashboardItemAnimator();
mViewHolder = new ViewHolder(new TextView(RuntimeEnvironment.application));
- mViewHolder.itemView.setTag(new Tile());
+ mViewHolder.itemView.setTag(new Tile(new ActivityInfo()));
}
@Test
public void testAnimateChange_NoPositionChange_NoPendingAnimation() {
final boolean hasPendingAnimation =
- mDashboardItemAnimator.animateChange(mViewHolder, mViewHolder, 0, 1, 0, 1);
+ mDashboardItemAnimator.animateChange(mViewHolder, mViewHolder, 0, 1, 0, 1);
assertThat(hasPendingAnimation).isFalse();
}
@Test
public void testAnimateChange_HasPositionChange_HasPendingAnimation() {
final boolean hasPendingAnimation =
- mDashboardItemAnimator.animateChange(mViewHolder, mViewHolder, 0, 0, 1, 1);
+ mDashboardItemAnimator.animateChange(mViewHolder, mViewHolder, 0, 0, 1, 1);
assertThat(hasPendingAnimation).isTrue();
}
mDashboardItemAnimator.animateMove(mViewHolder, 0, 0, 1, 1);
final boolean hasPendingAnimation =
- mDashboardItemAnimator.animateChange(mViewHolder, mViewHolder, 0, 1, 0, 1);
+ mDashboardItemAnimator.animateChange(mViewHolder, mViewHolder, 0, 1, 0, 1);
assertThat(hasPendingAnimation).isFalse();
}
package com.android.settings.dashboard;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Mockito.verifyZeroInteractions;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Intent;
+import android.content.pm.ActivityInfo;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
MockitoAnnotations.initMocks(this);
mFeatureFactory = FakeFeatureFactory.setupForTest();
- mTile = new Tile();
+ mTile = new Tile(new ActivityInfo());
mTile.summary = SUMMARY_1;
mCallbackInvoked = false;
public void testUpdateSummaryToCache_hasCache_shouldUpdate() {
final String testSummary = "test_summary";
final DashboardCategory category = new DashboardCategory();
- final Tile tile = new Tile();
+ final Tile tile = new Tile(new ActivityInfo());
tile.key = "123";
tile.intent = new Intent();
category.addTile(tile);
package com.android.settings.dashboard.suggestions;
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import android.app.ActivityManager;
import android.content.Context;
+import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.hardware.fingerprint.FingerprintManager;
import android.service.settings.suggestions.Suggestion;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.mockito.Answers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
@Config(shadows = ShadowSecureSettings.class)
public class SuggestionFeatureProviderImplTest {
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ @Mock
private Context mContext;
@Mock
private SuggestionControllerMixinCompat mSuggestionControllerMixin;
@Mock
private FingerprintManager mFingerprintManager;
+ private ActivityInfo mActivityInfo;
private FakeFeatureFactory mFactory;
private SuggestionFeatureProviderImpl mProvider;
public void setUp() {
MockitoAnnotations.initMocks(this);
mFactory = FakeFeatureFactory.setupForTest();
+ mActivityInfo = new ActivityInfo();
when(mContext.getPackageManager()).thenReturn(mPackageManager);
// Explicit casting to object due to MockitoCast bug
when((Object) mContext.getSystemService(FingerprintManager.class))
@Test
public void filterExclusiveSuggestions_shouldOnlyKeepFirst3() {
final List<Tile> suggestions = new ArrayList<>();
- suggestions.add(new Tile());
- suggestions.add(new Tile());
- suggestions.add(new Tile());
- suggestions.add(new Tile());
- suggestions.add(new Tile());
- suggestions.add(new Tile());
- suggestions.add(new Tile());
+ suggestions.add(new Tile(mActivityInfo));
+ suggestions.add(new Tile(mActivityInfo));
+ suggestions.add(new Tile(mActivityInfo));
+ suggestions.add(new Tile(mActivityInfo));
+ suggestions.add(new Tile(mActivityInfo));
+ suggestions.add(new Tile(mActivityInfo));
+ suggestions.add(new Tile(mActivityInfo));
mProvider.filterExclusiveSuggestions(suggestions);