From 75dc0c4d321996be2c78e89cdc7f17974930fa8d Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Tue, 24 Jul 2018 15:00:01 -0700 Subject: [PATCH 1/6] Remove unused interface API Bug: 111796429 Test: robotests Change-Id: I5887a0a48285cf61777ac7c6a896d16dd7585a26 --- src/com/android/settings/overlay/SupportFeatureProvider.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/com/android/settings/overlay/SupportFeatureProvider.java b/src/com/android/settings/overlay/SupportFeatureProvider.java index 0988fd43aa0..a9b66d6efd7 100644 --- a/src/com/android/settings/overlay/SupportFeatureProvider.java +++ b/src/com/android/settings/overlay/SupportFeatureProvider.java @@ -67,9 +67,4 @@ public interface SupportFeatureProvider { * @param activity Calling activity. */ void startSupportV2(Activity activity); - - /** - * Returns a url with information to introduce user to new device. - */ - String getNewDeviceIntroUrl(Context context); } From c00cce482992a95ed3548025da5f8828dd221e3a Mon Sep 17 00:00:00 2001 From: Mill Chen Date: Wed, 25 Jul 2018 13:32:34 +0800 Subject: [PATCH 2/6] Change floating search button icon - Add an alias name for floating search button Bug: 111665984 Test: rebuild Change-Id: I020cd4a163ae586f5b8faa0d4f8d9bc8bbd84fa4 --- res/layout/settings_homepage.xml | 2 +- res/values/aliases.xml | 1 + src/com/android/settings/homepage/HomepageFragment.java | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/res/layout/settings_homepage.xml b/res/layout/settings_homepage.xml index c36cf8b812b..fb00c7d55a1 100644 --- a/res/layout/settings_homepage.xml +++ b/res/layout/settings_homepage.xml @@ -43,7 +43,7 @@ android:id="@+id/search_fab" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:src="@drawable/ic_search_24dp" + android:src="@drawable/ic_search_floating_24dp" app:backgroundTint="@android:color/white" app:layout_anchor="@id/bar" /> diff --git a/res/values/aliases.xml b/res/values/aliases.xml index 060ba1d4dad..1be4350a99b 100644 --- a/res/values/aliases.xml +++ b/res/values/aliases.xml @@ -23,5 +23,6 @@ @layout/fingerprint_enroll_enrolling_base @layout/fingerprint_enroll_finish_base @layout/choose_lock_pattern_common + @drawable/ic_search_24dp diff --git a/src/com/android/settings/homepage/HomepageFragment.java b/src/com/android/settings/homepage/HomepageFragment.java index 9ccb8e2397b..ff89dd5a4dc 100644 --- a/src/com/android/settings/homepage/HomepageFragment.java +++ b/src/com/android/settings/homepage/HomepageFragment.java @@ -87,6 +87,8 @@ public class HomepageFragment extends InstrumentedFragment { final int screenWidthpx = getResources().getDisplayMetrics().widthPixels; final View searchbar = activity.findViewById(R.id.search_bar_container); final View bottombar = activity.findViewById(R.id.bar); + final Toolbar searchActionBar = (Toolbar) activity.findViewById(R.id.search_action_bar); + searchActionBar.setNavigationIcon(R.drawable.ic_search_floating_24dp); mBottomSheetBehavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { From 701b65ecccf8de95d6702ef529b5207c06e7c8be Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Tue, 24 Jul 2018 12:49:30 -0700 Subject: [PATCH 3/6] Use Tile.getIcon() to avoid caching issue Bug: 77600770 Test: robotests Change-Id: Icb21f5da9b542abc239b04b71813290ad3104ffb --- .../settings/dashboard/CategoryManager.java | 2 - .../settings/dashboard/DashboardAdapter.java | 10 ++- .../DashboardFeatureProviderImpl.java | 5 +- .../settings/dashboard/DashboardFragment.java | 6 +- .../AccountDetailDashboardFragmentTest.java | 18 ++-- .../dashboard/CategoryManagerTest.java | 89 +++++++++---------- .../dashboard/DashboardAdapterTest.java | 51 ++++++----- .../DashboardFeatureProviderImplTest.java | 61 +++++++------ .../dashboard/DashboardFragmentTest.java | 27 +++--- .../dashboard/DashboardItemAnimatorTest.java | 13 +-- .../settings/dashboard/SummaryLoaderTest.java | 6 +- .../SuggestionFeatureProviderImplTest.java | 21 +++-- 12 files changed, 167 insertions(+), 142 deletions(-) diff --git a/src/com/android/settings/dashboard/CategoryManager.java b/src/com/android/settings/dashboard/CategoryManager.java index f0004583444..407207226fe 100644 --- a/src/com/android/settings/dashboard/CategoryManager.java +++ b/src/com/android/settings/dashboard/CategoryManager.java @@ -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; diff --git a/src/com/android/settings/dashboard/DashboardAdapter.java b/src/com/android/settings/dashboard/DashboardAdapter.java index a76414d39e3..d93f2ed5683 100644 --- a/src/com/android/settings/dashboard/DashboardAdapter.java +++ b/src/com/android/settings/dashboard/DashboardAdapter.java @@ -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 { diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java index 2a962c1acdb..aa91b2f60ec 100644 --- a/src/com/android/settings/dashboard/DashboardFragment.java +++ b/src/com/android/settings/dashboard/DashboardFragment.java @@ -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. diff --git a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java index 36b6b80c08e..33ac5b6fabd 100644 --- a/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/accounts/AccountDetailDashboardFragmentTest.java @@ -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); diff --git a/tests/robotests/src/com/android/settings/dashboard/CategoryManagerTest.java b/tests/robotests/src/com/android/settings/dashboard/CategoryManagerTest.java index e22f07d0ec7..3bb4a654f43 100644 --- a/tests/robotests/src/com/android/settings/dashboard/CategoryManagerTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/CategoryManagerTest.java @@ -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, 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; diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java index f6786b82215..79be6cf54a5 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardAdapterTest.java @@ -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 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 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 makeSuggestionsV2(String... pkgNames) { diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java index e541b9fc953..e67711981b1 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFeatureProviderImplTest.java @@ -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(); } } diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java index 3a2f00f8924..e7453fa4039 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardFragmentTest.java @@ -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")); diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java index ee19654b7cd..b1d2031d7b6 100644 --- a/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java @@ -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(); } diff --git a/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java b/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java index 0fac2fcbc56..053bc9ce76c 100644 --- a/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/SummaryLoaderTest.java @@ -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); diff --git a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java index b1c256f17ce..70fc9d4a3b4 100644 --- a/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java +++ b/tests/robotests/src/com/android/settings/dashboard/suggestions/SuggestionFeatureProviderImplTest.java @@ -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 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); From 96dc235f6e2ce102de0d4e6adb2dafb83a1699d9 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Fri, 20 Jul 2018 12:36:42 -0700 Subject: [PATCH 4/6] Check for WiFi controller for summary population. WiFiController might return not available, so we should only surface "Wi-Fi" as a summary entry if it's available in the settings page. This also checks for empty strings in case they are declared as such in the XML (since XML can be device/product overlay'd), to avoid situations such as ", data usage". Bug: 111398942 Test: Manual check, and I see Wi-Fi no longer visible for cases where Wifi controller isn't available. Test: make RunSettingsRoboTests Change-Id: I24736a6240c50e2ea38ce424fbac2316721290d8 --- .../network/NetworkDashboardFragment.java | 36 ++++++++++++------- .../network/NetworkDashboardFragmentTest.java | 13 +++++-- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/src/com/android/settings/network/NetworkDashboardFragment.java b/src/com/android/settings/network/NetworkDashboardFragment.java index 27e1a98aa71..d5ef9aa0503 100644 --- a/src/com/android/settings/network/NetworkDashboardFragment.java +++ b/src/com/android/settings/network/NetworkDashboardFragment.java @@ -24,6 +24,7 @@ import android.content.Context; import android.icu.text.ListFormatter; import android.provider.SearchIndexableResource; import android.text.BidiFormatter; +import android.text.TextUtils; import android.util.Log; import com.android.internal.logging.nano.MetricsProto; @@ -153,21 +154,25 @@ public class NetworkDashboardFragment extends DashboardFragment implements private final Context mContext; private final SummaryLoader mSummaryLoader; + private final WifiMasterSwitchPreferenceController mWifiPreferenceController; private final MobileNetworkPreferenceController mMobileNetworkPreferenceController; private final TetherPreferenceController mTetherPreferenceController; public SummaryProvider(Context context, SummaryLoader summaryLoader) { this(context, summaryLoader, + new WifiMasterSwitchPreferenceController(context, null), new MobileNetworkPreferenceController(context), new TetherPreferenceController(context, null /* lifecycle */)); } @VisibleForTesting(otherwise = VisibleForTesting.NONE) SummaryProvider(Context context, SummaryLoader summaryLoader, + WifiMasterSwitchPreferenceController wifiPreferenceController, MobileNetworkPreferenceController mobileNetworkPreferenceController, TetherPreferenceController tetherPreferenceController) { mContext = context; mSummaryLoader = summaryLoader; + mWifiPreferenceController = wifiPreferenceController; mMobileNetworkPreferenceController = mobileNetworkPreferenceController; mTetherPreferenceController = tetherPreferenceController; } @@ -176,20 +181,27 @@ public class NetworkDashboardFragment extends DashboardFragment implements @Override public void setListening(boolean listening) { if (listening) { - final List summaries = new ArrayList<>(); + final String wifiSummary = BidiFormatter.getInstance() + .unicodeWrap(mContext.getString(R.string.wifi_settings_title)); + final String mobileSummary = mContext.getString( + R.string.network_dashboard_summary_mobile); + final String dataUsageSummary = mContext.getString( + R.string.network_dashboard_summary_data_usage); + final String hotspotSummary = mContext.getString( + R.string.network_dashboard_summary_hotspot); - summaries.add(BidiFormatter.getInstance() - .unicodeWrap(mContext.getString(R.string.wifi_settings_title))); - if (mMobileNetworkPreferenceController.isAvailable()) { - summaries.add(mContext.getString( - R.string.network_dashboard_summary_mobile)); + final List summaries = new ArrayList<>(); + if (mWifiPreferenceController.isAvailable() && !TextUtils.isEmpty(wifiSummary)) { + summaries.add(wifiSummary); } - final String dataUsageSettingSummary = mContext.getString( - R.string.network_dashboard_summary_data_usage); - summaries.add(dataUsageSettingSummary); - if (mTetherPreferenceController.isAvailable()) { - summaries.add(mContext.getString( - R.string.network_dashboard_summary_hotspot)); + if (mMobileNetworkPreferenceController.isAvailable() && !TextUtils.isEmpty(mobileSummary)) { + summaries.add(mobileSummary); + } + if (!TextUtils.isEmpty(dataUsageSummary)) { + summaries.add(dataUsageSummary); + } + if (mTetherPreferenceController.isAvailable() && !TextUtils.isEmpty(hotspotSummary)) { + summaries.add(hotspotSummary); } mSummaryLoader.setSummary(this, ListFormatter.getInstance().format(summaries)); } diff --git a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java index 187f0dc2882..d6310ab3db3 100644 --- a/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java +++ b/tests/robotests/src/com/android/settings/network/NetworkDashboardFragmentTest.java @@ -26,6 +26,7 @@ import android.provider.SearchIndexableResource; import com.android.settings.dashboard.SummaryLoader; import com.android.settings.testutils.SettingsRobolectricTestRunner; +import com.android.settings.wifi.WifiMasterSwitchPreferenceController; import com.android.settingslib.drawer.CategoryKey; import org.junit.Before; @@ -66,6 +67,8 @@ public class NetworkDashboardFragmentTest { @Test public void summaryProviderSetListening_hasMobileAndHotspot_shouldReturnMobileSummary() { + final WifiMasterSwitchPreferenceController wifiPreferenceController = + mock(WifiMasterSwitchPreferenceController.class); final MobileNetworkPreferenceController mobileNetworkPreferenceController = mock(MobileNetworkPreferenceController.class); final TetherPreferenceController tetherPreferenceController = @@ -74,12 +77,14 @@ public class NetworkDashboardFragmentTest { final SummaryLoader summaryLoader = mock(SummaryLoader.class); final SummaryLoader.SummaryProvider provider = new NetworkDashboardFragment.SummaryProvider(mContext, summaryLoader, - mobileNetworkPreferenceController, tetherPreferenceController); + wifiPreferenceController, mobileNetworkPreferenceController, + tetherPreferenceController); provider.setListening(false); verifyZeroInteractions(summaryLoader); + when(wifiPreferenceController.isAvailable()).thenReturn(true); when(mobileNetworkPreferenceController.isAvailable()).thenReturn(true); when(tetherPreferenceController.isAvailable()).thenReturn(true); @@ -90,6 +95,8 @@ public class NetworkDashboardFragmentTest { @Test public void summaryProviderSetListening_noMobileOrHotspot_shouldReturnSimpleSummary() { + final WifiMasterSwitchPreferenceController wifiPreferenceController = + mock(WifiMasterSwitchPreferenceController.class); final MobileNetworkPreferenceController mobileNetworkPreferenceController = mock(MobileNetworkPreferenceController.class); final TetherPreferenceController tetherPreferenceController = @@ -98,12 +105,14 @@ public class NetworkDashboardFragmentTest { final SummaryLoader summaryLoader = mock(SummaryLoader.class); final SummaryLoader.SummaryProvider provider = new NetworkDashboardFragment.SummaryProvider(mContext, summaryLoader, - mobileNetworkPreferenceController, tetherPreferenceController); + wifiPreferenceController, mobileNetworkPreferenceController, + tetherPreferenceController); provider.setListening(false); verifyZeroInteractions(summaryLoader); + when(wifiPreferenceController.isAvailable()).thenReturn(true); when(mobileNetworkPreferenceController.isAvailable()).thenReturn(false); when(tetherPreferenceController.isAvailable()).thenReturn(false); From 432979219872277db2a41d8f92ebb042d0dbc490 Mon Sep 17 00:00:00 2001 From: Fan Zhang Date: Wed, 25 Jul 2018 15:25:05 -0700 Subject: [PATCH 5/6] Clean up unused deps Test: rebuild Change-Id: I7caa30024046ae832cafef6598ecf74db4aba8bf --- Android.mk | 3 --- 1 file changed, 3 deletions(-) diff --git a/Android.mk b/Android.mk index a573378faea..6b0d077a214 100644 --- a/Android.mk +++ b/Android.mk @@ -25,13 +25,10 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \ androidx.slice_slice-core \ androidx.slice_slice-view \ androidx.core_core \ - androidx.legacy_legacy-support-v4 \ - androidx.legacy_legacy-support-v13 \ androidx.appcompat_appcompat \ androidx.cardview_cardview \ androidx.preference_preference \ androidx.recyclerview_recyclerview \ - androidx.legacy_legacy-preference-v14 \ com.google.android.material_material \ LOCAL_JAVA_LIBRARIES := \ From d526c973f6feadb42492977d8b293e92166ae065 Mon Sep 17 00:00:00 2001 From: Doris Ling Date: Wed, 25 Jul 2018 16:12:57 -0700 Subject: [PATCH 6/6] Restore the up time preference. - up time preference is removed when we updated to the new version of about phone settings. Add it back to the preference xml, and restore the controller for it. Change-Id: I245316e84d04f9d6f033377c944b615dd6e138a5 Fixes: 111828610 Test: manual --- res/xml/my_device_info.xml | 8 +++++ .../UptimePreferenceController.java | 35 +++++++++++++++++++ .../aboutphone/MyDeviceInfoFragment.java | 2 ++ 3 files changed, 45 insertions(+) create mode 100644 src/com/android/settings/deviceinfo/UptimePreferenceController.java diff --git a/res/xml/my_device_info.xml b/res/xml/my_device_info.xml index b70b613eb7a..22c18443d0e 100644 --- a/res/xml/my_device_info.xml +++ b/res/xml/my_device_info.xml @@ -133,6 +133,14 @@ android:summary="@string/summary_placeholder" android:selectable="false"/> + + +