Use Tile.getIcon() to avoid caching issue
Bug: 77600770 Test: robotests Change-Id: Icb21f5da9b542abc239b04b71813290ad3104ffb
This commit is contained in:
@@ -39,8 +39,6 @@ import java.util.Set;
|
||||
|
||||
public class CategoryManager {
|
||||
|
||||
public static final String SETTING_PKG = "com.android.settings";
|
||||
|
||||
private static final String TAG = "CategoryManager";
|
||||
|
||||
private static CategoryManager sInstance;
|
||||
|
@@ -19,6 +19,7 @@ import android.app.Activity;
|
||||
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;
|
||||
@@ -314,8 +315,9 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
|
||||
@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 {
|
||||
@@ -324,7 +326,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
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);
|
||||
}
|
||||
@@ -332,7 +334,7 @@ public class DashboardAdapter extends RecyclerView.Adapter<DashboardAdapter.Dash
|
||||
} 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);
|
||||
|
@@ -238,8 +238,9 @@ public class DashboardFeatureProviderImpl implements DashboardFeatureProvider {
|
||||
|
||||
@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(() -> {
|
||||
|
@@ -256,7 +256,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
|
||||
@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.
|
||||
@@ -330,7 +330,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
/**
|
||||
* Refresh preference items backed by DashboardCategory.
|
||||
*/
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
|
||||
@VisibleForTesting
|
||||
void refreshDashboardTiles(final String TAG) {
|
||||
final PreferenceScreen screen = getPreferenceScreen();
|
||||
|
||||
@@ -370,7 +370,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
||||
continue;
|
||||
}
|
||||
if (tintTileIcon(tile)) {
|
||||
tile.icon.setTint(tintColor);
|
||||
tile.getIcon().setTint(tintColor);
|
||||
}
|
||||
if (mDashboardTilePrefKeys.contains(key)) {
|
||||
// Have the key already, will rebind.
|
||||
|
@@ -16,6 +16,7 @@
|
||||
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;
|
||||
@@ -25,11 +26,14 @@ import android.accounts.Account;
|
||||
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;
|
||||
@@ -44,8 +48,6 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.Shadows;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class AccountDetailDashboardFragmentTest {
|
||||
|
||||
@@ -72,12 +74,12 @@ 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");
|
||||
@@ -88,7 +90,7 @@ public class AccountDetailDashboardFragmentTest {
|
||||
|
||||
@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;
|
||||
@@ -98,7 +100,7 @@ public class AccountDetailDashboardFragmentTest {
|
||||
|
||||
@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");
|
||||
@@ -114,9 +116,9 @@ public class AccountDetailDashboardFragmentTest {
|
||||
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);
|
||||
|
@@ -21,6 +21,8 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
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;
|
||||
@@ -31,6 +33,7 @@ import com.android.settingslib.drawer.Tile;
|
||||
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;
|
||||
@@ -39,6 +42,7 @@ import java.util.Map;
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class CategoryManagerTest {
|
||||
|
||||
private ActivityInfo mActivityInfo;
|
||||
private Context mContext;
|
||||
private CategoryManager mCategoryManager;
|
||||
private Map<Pair<String, String>, Tile> mTileByComponentCache;
|
||||
@@ -46,7 +50,9 @@ public class CategoryManagerTest {
|
||||
|
||||
@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);
|
||||
@@ -59,8 +65,8 @@ public class CategoryManagerTest {
|
||||
|
||||
@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();
|
||||
@@ -78,8 +84,8 @@ public class CategoryManagerTest {
|
||||
|
||||
@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;
|
||||
@@ -102,7 +108,7 @@ public class CategoryManagerTest {
|
||||
|
||||
@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();
|
||||
@@ -126,15 +132,15 @@ public class CategoryManagerTest {
|
||||
// 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;
|
||||
@@ -159,15 +165,15 @@ public class CategoryManagerTest {
|
||||
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;
|
||||
@@ -177,8 +183,7 @@ public class CategoryManagerTest {
|
||||
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);
|
||||
@@ -189,18 +194,17 @@ public class CategoryManagerTest {
|
||||
@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;
|
||||
@@ -210,8 +214,7 @@ public class CategoryManagerTest {
|
||||
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);
|
||||
@@ -222,20 +225,19 @@ public class CategoryManagerTest {
|
||||
@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);
|
||||
@@ -245,8 +247,7 @@ public class CategoryManagerTest {
|
||||
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);
|
||||
@@ -258,18 +259,17 @@ public class CategoryManagerTest {
|
||||
@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);
|
||||
@@ -278,8 +278,7 @@ public class CategoryManagerTest {
|
||||
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);
|
||||
@@ -290,18 +289,17 @@ public class CategoryManagerTest {
|
||||
@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;
|
||||
@@ -318,18 +316,17 @@ public class CategoryManagerTest {
|
||||
@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;
|
||||
|
@@ -16,6 +16,7 @@
|
||||
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;
|
||||
@@ -28,6 +29,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
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;
|
||||
@@ -39,6 +41,8 @@ import android.view.View;
|
||||
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;
|
||||
@@ -63,8 +67,6 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
|
||||
public class DashboardAdapterTest {
|
||||
@@ -79,6 +81,7 @@ public class DashboardAdapterTest {
|
||||
private Resources mResources;
|
||||
@Mock
|
||||
private WindowManager mWindowManager;
|
||||
private ActivityInfo mActivityInfo;
|
||||
private FakeFeatureFactory mFactory;
|
||||
private DashboardAdapter mDashboardAdapter;
|
||||
private List<Condition> mConditionList;
|
||||
@@ -87,6 +90,7 @@ public class DashboardAdapterTest {
|
||||
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);
|
||||
@@ -123,7 +127,6 @@ public class DashboardAdapterTest {
|
||||
|
||||
adapter.onBindSuggestion(holder, 0);
|
||||
|
||||
final DashboardData dashboardData = adapter.mDashboardData;
|
||||
reset(adapter); // clear interactions tracking
|
||||
|
||||
final Suggestion suggestionToRemove = suggestions.get(1);
|
||||
@@ -154,12 +157,12 @@ public class DashboardAdapterTest {
|
||||
@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));
|
||||
@@ -198,10 +201,12 @@ public class DashboardAdapterTest {
|
||||
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 */);
|
||||
@@ -217,9 +222,9 @@ public class DashboardAdapterTest {
|
||||
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);
|
||||
|
||||
@@ -230,7 +235,7 @@ public class DashboardAdapterTest {
|
||||
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
|
||||
@@ -239,11 +244,12 @@ public class DashboardAdapterTest {
|
||||
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 */);
|
||||
@@ -252,7 +258,8 @@ public class DashboardAdapterTest {
|
||||
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));
|
||||
}
|
||||
@@ -263,12 +270,12 @@ public class DashboardAdapterTest {
|
||||
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 */);
|
||||
@@ -276,7 +283,7 @@ public class DashboardAdapterTest {
|
||||
|
||||
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) {
|
||||
|
@@ -19,7 +19,9 @@ package com.android.settings.dashboard;
|
||||
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;
|
||||
@@ -35,6 +37,7 @@ import android.app.Activity;
|
||||
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;
|
||||
@@ -43,6 +46,8 @@ import android.os.Bundle;
|
||||
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;
|
||||
@@ -73,8 +78,6 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = ShadowUserManager.class)
|
||||
public class DashboardFeatureProviderImplTest {
|
||||
@@ -90,15 +93,17 @@ 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);
|
||||
}
|
||||
@@ -111,10 +116,11 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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;
|
||||
@@ -132,7 +138,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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();
|
||||
@@ -149,7 +155,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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));
|
||||
@@ -170,7 +176,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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));
|
||||
@@ -195,7 +201,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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));
|
||||
@@ -231,7 +237,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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,
|
||||
@@ -244,7 +250,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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,
|
||||
@@ -257,7 +263,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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"));
|
||||
@@ -271,7 +277,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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();
|
||||
@@ -287,7 +293,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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"));
|
||||
@@ -301,7 +307,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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(
|
||||
@@ -318,7 +324,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
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,
|
||||
@@ -331,7 +337,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
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;
|
||||
@@ -344,7 +350,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
@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;
|
||||
@@ -358,7 +364,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
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"));
|
||||
@@ -384,7 +390,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
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"));
|
||||
@@ -431,7 +437,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
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);
|
||||
@@ -461,7 +467,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
|
||||
@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"));
|
||||
@@ -472,13 +478,13 @@ public class DashboardFeatureProviderImplTest {
|
||||
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();
|
||||
@@ -490,12 +496,13 @@ public class DashboardFeatureProviderImplTest {
|
||||
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();
|
||||
@@ -507,7 +514,7 @@ public class DashboardFeatureProviderImplTest {
|
||||
mImpl.openTileIntent(mActivity, tile);
|
||||
|
||||
verify(mActivity)
|
||||
.startActivityForResult(any(Intent.class), eq(0));
|
||||
.startActivityForResult(any(Intent.class), eq(0));
|
||||
verify(mActivity, never()).getFragmentManager();
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,9 @@
|
||||
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;
|
||||
@@ -27,9 +29,14 @@ import static org.mockito.Mockito.when;
|
||||
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;
|
||||
@@ -50,15 +57,12 @@ import org.robolectric.util.ReflectionHelpers;
|
||||
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;
|
||||
@@ -67,9 +71,10 @@ public class DashboardFragmentTest {
|
||||
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)))
|
||||
@@ -177,8 +182,8 @@ public class DashboardFragmentTest {
|
||||
|
||||
@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;
|
||||
|
||||
@@ -191,7 +196,7 @@ public class DashboardFragmentTest {
|
||||
|
||||
@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();
|
||||
@@ -199,12 +204,12 @@ public class DashboardFragmentTest {
|
||||
|
||||
@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"));
|
||||
|
@@ -18,9 +18,12 @@ package com.android.settings.dashboard;
|
||||
|
||||
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;
|
||||
|
||||
@@ -29,8 +32,6 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DashboardItemAnimatorTest {
|
||||
|
||||
@@ -41,20 +42,20 @@ 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();
|
||||
}
|
||||
|
||||
@@ -64,7 +65,7 @@ public class DashboardItemAnimatorTest {
|
||||
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();
|
||||
}
|
||||
|
||||
|
@@ -17,11 +17,13 @@
|
||||
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;
|
||||
@@ -51,7 +53,7 @@ public class SummaryLoaderTest {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mFeatureFactory = FakeFeatureFactory.setupForTest();
|
||||
|
||||
mTile = new Tile();
|
||||
mTile = new Tile(new ActivityInfo());
|
||||
mTile.summary = SUMMARY_1;
|
||||
mCallbackInvoked = false;
|
||||
|
||||
@@ -84,7 +86,7 @@ public class SummaryLoaderTest {
|
||||
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);
|
||||
|
@@ -17,6 +17,7 @@
|
||||
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;
|
||||
@@ -27,6 +28,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
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;
|
||||
@@ -45,7 +47,6 @@ import org.junit.After;
|
||||
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;
|
||||
@@ -58,7 +59,7 @@ import java.util.List;
|
||||
@Config(shadows = ShadowSecureSettings.class)
|
||||
public class SuggestionFeatureProviderImplTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private SuggestionControllerMixinCompat mSuggestionControllerMixin;
|
||||
@@ -71,6 +72,7 @@ public class SuggestionFeatureProviderImplTest {
|
||||
@Mock
|
||||
private FingerprintManager mFingerprintManager;
|
||||
|
||||
private ActivityInfo mActivityInfo;
|
||||
private FakeFeatureFactory mFactory;
|
||||
private SuggestionFeatureProviderImpl mProvider;
|
||||
|
||||
@@ -78,6 +80,7 @@ public class SuggestionFeatureProviderImplTest {
|
||||
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))
|
||||
@@ -145,13 +148,13 @@ public class SuggestionFeatureProviderImplTest {
|
||||
@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);
|
||||
|
||||
|
Reference in New Issue
Block a user