Merge "Fix cached app icon being used in app list."

This commit is contained in:
TreeHugger Robot
2018-07-19 21:16:34 +00:00
committed by Android (Google) Code Review
2 changed files with 61 additions and 60 deletions

View File

@@ -54,6 +54,7 @@ import android.os.UserManager;
import android.preference.PreferenceFrameLayout; import android.preference.PreferenceFrameLayout;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.IconDrawableFactory;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
@@ -862,6 +863,7 @@ public class ManageApplications extends InstrumentedFragment
private final Context mContext; private final Context mContext;
private final AppStateBaseBridge mExtraInfoBridge; private final AppStateBaseBridge mExtraInfoBridge;
private final LoadingViewController mLoadingViewController; private final LoadingViewController mLoadingViewController;
private final IconDrawableFactory mIconDrawableFactory;
private AppFilterItem mAppFilter; private AppFilterItem mAppFilter;
private ArrayList<ApplicationsState.AppEntry> mEntries; private ArrayList<ApplicationsState.AppEntry> mEntries;
@@ -894,6 +896,7 @@ public class ManageApplications extends InstrumentedFragment
mManageApplications.mListContainer mManageApplications.mListContainer
); );
mContext = manageApplications.getActivity(); mContext = manageApplications.getActivity();
mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
mAppFilter = appFilter; mAppFilter = appFilter;
if (mManageApplications.mListType == LIST_TYPE_NOTIFICATION) { if (mManageApplications.mListType == LIST_TYPE_NOTIFICATION) {
mExtraInfoBridge = new AppStateNotificationBridge(mContext, mState, this, mExtraInfoBridge = new AppStateNotificationBridge(mContext, mState, this,
@@ -1318,8 +1321,7 @@ public class ManageApplications extends InstrumentedFragment
ApplicationsState.AppEntry entry = mEntries.get(position); ApplicationsState.AppEntry entry = mEntries.get(position);
synchronized (entry) { synchronized (entry) {
holder.setTitle(entry.label); holder.setTitle(entry.label);
mState.ensureIcon(entry); holder.setIcon(mIconDrawableFactory.getBadgedIcon(entry.info));
holder.setIcon(entry.icon);
updateSummary(holder, entry); updateSummary(holder, entry);
updateSwitch(holder, entry); updateSwitch(holder, entry);
holder.updateDisableView(entry.info); holder.updateDisableView(entry.info);

View File

@@ -37,6 +37,9 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
import android.content.Context; import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.os.Bundle; import android.os.Bundle;
import android.os.Looper; import android.os.Looper;
import android.os.UserManager; import android.os.UserManager;
@@ -74,6 +77,14 @@ public class ManageApplicationsTest {
private ApplicationsState.Session mSession; private ApplicationsState.Session mSession;
@Mock @Mock
private Menu mMenu; private Menu mMenu;
@Mock
private FragmentActivity mActivity;
@Mock
private Resources mResources;
@Mock
private UserManager mUserManager;
@Mock
private PackageManager mPackageManager;
private MenuItem mAppReset; private MenuItem mAppReset;
private MenuItem mSortRecent; private MenuItem mSortRecent;
private MenuItem mSortFrequent; private MenuItem mSortFrequent;
@@ -89,7 +100,11 @@ public class ManageApplicationsTest {
when(mState.newSession(any())).thenReturn(mSession); when(mState.newSession(any())).thenReturn(mSession);
when(mState.getBackgroundLooper()).thenReturn(Looper.myLooper()); when(mState.getBackgroundLooper()).thenReturn(Looper.myLooper());
mFragment = new ManageApplications(); mFragment = spy(new ManageApplications());
when(mFragment.getActivity()).thenReturn(mActivity);
when(mActivity.getResources()).thenReturn(mResources);
when(mActivity.getSystemService(UserManager.class)).thenReturn(mUserManager);
when(mActivity.getPackageManager()).thenReturn(mPackageManager);
} }
@Test @Test
@@ -126,10 +141,8 @@ public class ManageApplicationsTest {
@Test @Test
public void onCreateView_shouldNotShowLoadingContainer() { public void onCreateView_shouldNotShowLoadingContainer() {
final ManageApplications fragment = spy(new ManageApplications()); ReflectionHelpers.setField(mFragment, "mResetAppsHelper", mock(ResetAppsHelper.class));
ReflectionHelpers.setField(fragment, "mResetAppsHelper", doNothing().when(mFragment).createHeader();
mock(ResetAppsHelper.class));
doNothing().when(fragment).createHeader();
final LayoutInflater layoutInflater = mock(LayoutInflater.class); final LayoutInflater layoutInflater = mock(LayoutInflater.class);
final View view = mock(View.class); final View view = mock(View.class);
@@ -137,19 +150,17 @@ public class ManageApplicationsTest {
when(layoutInflater.inflate(anyInt(), eq(null))).thenReturn(view); when(layoutInflater.inflate(anyInt(), eq(null))).thenReturn(view);
when(view.findViewById(R.id.loading_container)).thenReturn(loadingContainer); when(view.findViewById(R.id.loading_container)).thenReturn(loadingContainer);
fragment.onCreateView(layoutInflater, mock(ViewGroup.class), null); mFragment.onCreateView(layoutInflater, mock(ViewGroup.class), null);
verify(loadingContainer, never()).setVisibility(View.VISIBLE); verify(loadingContainer, never()).setVisibility(View.VISIBLE);
} }
@Test @Test
public void updateLoading_appLoaded_shouldNotDelayCallToHandleLoadingContainer() { public void updateLoading_appLoaded_shouldNotDelayCallToHandleLoadingContainer() {
final ManageApplications fragment = mock(ManageApplications.class); ReflectionHelpers.setField(mFragment, "mLoadingContainer", mock(View.class));
ReflectionHelpers.setField(fragment, "mLoadingContainer", mock(View.class)); ReflectionHelpers.setField(mFragment, "mListContainer", mock(View.class));
ReflectionHelpers.setField(fragment, "mListContainer", mock(View.class));
when(fragment.getActivity()).thenReturn(mock(FragmentActivity.class));
final ManageApplications.ApplicationsAdapter adapter = final ManageApplications.ApplicationsAdapter adapter =
spy(new ManageApplications.ApplicationsAdapter(mState, fragment, spy(new ManageApplications.ApplicationsAdapter(mState, mFragment,
AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle())); AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle()));
final LoadingViewController loadingViewController = final LoadingViewController loadingViewController =
mock(LoadingViewController.class); mock(LoadingViewController.class);
@@ -168,12 +179,10 @@ public class ManageApplicationsTest {
@Test @Test
public void updateLoading_appNotLoaded_shouldDelayCallToHandleLoadingContainer() { public void updateLoading_appNotLoaded_shouldDelayCallToHandleLoadingContainer() {
final ManageApplications fragment = mock(ManageApplications.class); ReflectionHelpers.setField(mFragment, "mLoadingContainer", mock(View.class));
ReflectionHelpers.setField(fragment, "mLoadingContainer", mock(View.class)); ReflectionHelpers.setField(mFragment, "mListContainer", mock(View.class));
ReflectionHelpers.setField(fragment, "mListContainer", mock(View.class));
when(fragment.getActivity()).thenReturn(mock(FragmentActivity.class));
final ManageApplications.ApplicationsAdapter adapter = final ManageApplications.ApplicationsAdapter adapter =
spy(new ManageApplications.ApplicationsAdapter(mState, fragment, spy(new ManageApplications.ApplicationsAdapter(mState, mFragment,
AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle())); AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle()));
final LoadingViewController loadingViewController = final LoadingViewController loadingViewController =
mock(LoadingViewController.class); mock(LoadingViewController.class);
@@ -200,21 +209,19 @@ public class ManageApplicationsTest {
@Test @Test
public void onRebuildComplete_shouldHideLoadingView() { public void onRebuildComplete_shouldHideLoadingView() {
final Context context = RuntimeEnvironment.application; final Context context = RuntimeEnvironment.application;
final ManageApplications fragment = mock(ManageApplications.class);
final RecyclerView recyclerView = mock(RecyclerView.class); final RecyclerView recyclerView = mock(RecyclerView.class);
final View emptyView = mock(View.class); final View emptyView = mock(View.class);
ReflectionHelpers.setField(fragment, "mRecyclerView", recyclerView); ReflectionHelpers.setField(mFragment, "mRecyclerView", recyclerView);
ReflectionHelpers.setField(fragment, "mEmptyView", emptyView); ReflectionHelpers.setField(mFragment, "mEmptyView", emptyView);
final View loadingContainer = mock(View.class); final View loadingContainer = mock(View.class);
when(loadingContainer.getContext()).thenReturn(context); when(loadingContainer.getContext()).thenReturn(context);
final View listContainer = mock(View.class); final View listContainer = mock(View.class);
when(listContainer.getVisibility()).thenReturn(View.INVISIBLE); when(listContainer.getVisibility()).thenReturn(View.INVISIBLE);
when(listContainer.getContext()).thenReturn(context); when(listContainer.getContext()).thenReturn(context);
ReflectionHelpers.setField(fragment, "mLoadingContainer", loadingContainer); ReflectionHelpers.setField(mFragment, "mLoadingContainer", loadingContainer);
ReflectionHelpers.setField(fragment, "mListContainer", listContainer); ReflectionHelpers.setField(mFragment, "mListContainer", listContainer);
when(fragment.getActivity()).thenReturn(mock(FragmentActivity.class));
final ManageApplications.ApplicationsAdapter adapter = final ManageApplications.ApplicationsAdapter adapter =
spy(new ManageApplications.ApplicationsAdapter(mState, fragment, spy(new ManageApplications.ApplicationsAdapter(mState, mFragment,
AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle())); AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle()));
final LoadingViewController loadingViewController = final LoadingViewController loadingViewController =
mock(LoadingViewController.class); mock(LoadingViewController.class);
@@ -231,6 +238,8 @@ public class ManageApplicationsTest {
final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>(); final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>();
appList.add(mock(ApplicationsState.AppEntry.class)); appList.add(mock(ApplicationsState.AppEntry.class));
when(mSession.getAllApps()).thenReturn(appList); when(mSession.getAllApps()).thenReturn(appList);
ReflectionHelpers.setField(
mFragment, "mFilterAdapter", mock(ManageApplications.FilterSpinnerAdapter.class));
adapter.onRebuildComplete(null); adapter.onRebuildComplete(null);
@@ -241,8 +250,7 @@ public class ManageApplicationsTest {
public void notifyItemChange_recyclerViewIdle_shouldNotify() { public void notifyItemChange_recyclerViewIdle_shouldNotify() {
final RecyclerView recyclerView = mock(RecyclerView.class); final RecyclerView recyclerView = mock(RecyclerView.class);
final ManageApplications.ApplicationsAdapter adapter = final ManageApplications.ApplicationsAdapter adapter =
spy(new ManageApplications.ApplicationsAdapter(mState, spy(new ManageApplications.ApplicationsAdapter(mState, mFragment,
mock(ManageApplications.class),
AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle())); AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle()));
adapter.onAttachedToRecyclerView(recyclerView); adapter.onAttachedToRecyclerView(recyclerView);
@@ -256,8 +264,7 @@ public class ManageApplicationsTest {
public void notifyItemChange_recyclerViewScrolling_shouldNotifyWhenIdle() { public void notifyItemChange_recyclerViewScrolling_shouldNotifyWhenIdle() {
final RecyclerView recyclerView = mock(RecyclerView.class); final RecyclerView recyclerView = mock(RecyclerView.class);
final ManageApplications.ApplicationsAdapter adapter = final ManageApplications.ApplicationsAdapter adapter =
spy(new ManageApplications.ApplicationsAdapter(mState, spy(new ManageApplications.ApplicationsAdapter(mState, mFragment,
mock(ManageApplications.class),
AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle())); AppFilterRegistry.getInstance().get(FILTER_APPS_ALL), new Bundle()));
adapter.onAttachedToRecyclerView(recyclerView); adapter.onAttachedToRecyclerView(recyclerView);
@@ -273,20 +280,19 @@ public class ManageApplicationsTest {
@Test @Test
public void applicationsAdapter_onBindViewHolder_updateSwitch_notifications() { public void applicationsAdapter_onBindViewHolder_updateSwitch_notifications() {
ManageApplications manageApplications = mock(ManageApplications.class); when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
when(manageApplications.getActivity()).thenReturn(mock(FragmentActivity.class)); ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
UserManager um = mock(UserManager.class); mFragment.mListType = LIST_TYPE_NOTIFICATION;
when(um.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
ReflectionHelpers.setField(manageApplications, "mUserManager", um);
manageApplications.mListType = LIST_TYPE_NOTIFICATION;
ApplicationViewHolder holder = mock(ApplicationViewHolder.class); ApplicationViewHolder holder = mock(ApplicationViewHolder.class);
ReflectionHelpers.setField(holder, "itemView", mock(View.class)); ReflectionHelpers.setField(holder, "itemView", mock(View.class));
ManageApplications.ApplicationsAdapter adapter = ManageApplications.ApplicationsAdapter adapter =
new ManageApplications.ApplicationsAdapter(mState, new ManageApplications.ApplicationsAdapter(mState,
manageApplications, mock(AppFilterItem.class), mFragment, mock(AppFilterItem.class),
mock(Bundle.class)); mock(Bundle.class));
final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>(); final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>();
appList.add(mock(ApplicationsState.AppEntry.class)); final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
appEntry.info = mock(ApplicationInfo.class);
appList.add(appEntry);
ReflectionHelpers.setField(adapter, "mEntries", appList); ReflectionHelpers.setField(adapter, "mEntries", appList);
adapter.onBindViewHolder(holder, 0); adapter.onBindViewHolder(holder, 0);
@@ -295,19 +301,17 @@ public class ManageApplicationsTest {
@Test @Test
public void applicationsAdapter_onBindViewHolder_updateSwitch_notNotifications() { public void applicationsAdapter_onBindViewHolder_updateSwitch_notNotifications() {
ManageApplications manageApplications = mock(ManageApplications.class); mFragment.mListType = LIST_TYPE_MAIN;
manageApplications.mListType = LIST_TYPE_MAIN;
ApplicationViewHolder holder = mock(ApplicationViewHolder.class); ApplicationViewHolder holder = mock(ApplicationViewHolder.class);
ReflectionHelpers.setField(holder, "itemView", mock(View.class)); ReflectionHelpers.setField(holder, "itemView", mock(View.class));
UserManager um = mock(UserManager.class); when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
when(um.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{}); ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
ReflectionHelpers.setField(manageApplications, "mUserManager", um); ManageApplications.ApplicationsAdapter adapter = new ManageApplications.ApplicationsAdapter(
ManageApplications.ApplicationsAdapter adapter = mState, mFragment, mock(AppFilterItem.class), mock(Bundle.class));
new ManageApplications.ApplicationsAdapter(mState,
manageApplications, mock(AppFilterItem.class),
mock(Bundle.class));
final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>(); final ArrayList<ApplicationsState.AppEntry> appList = new ArrayList<>();
appList.add(mock(ApplicationsState.AppEntry.class)); final ApplicationsState.AppEntry appEntry = mock(ApplicationsState.AppEntry.class);
appEntry.info = mock(ApplicationInfo.class);
appList.add(appEntry);
ReflectionHelpers.setField(adapter, "mEntries", appList); ReflectionHelpers.setField(adapter, "mEntries", appList);
adapter.onBindViewHolder(holder, 0); adapter.onBindViewHolder(holder, 0);
@@ -316,23 +320,18 @@ public class ManageApplicationsTest {
@Test @Test
public void sortOrderSavedOnRebuild() { public void sortOrderSavedOnRebuild() {
ManageApplications manageApplications = mock(ManageApplications.class); when(mUserManager.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{});
when(manageApplications.getActivity()).thenReturn(mock(FragmentActivity.class)); ReflectionHelpers.setField(mFragment, "mUserManager", mUserManager);
UserManager um = mock(UserManager.class); mFragment.mListType = LIST_TYPE_NOTIFICATION;
when(um.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[]{}); mFragment.mSortOrder = -1;
ReflectionHelpers.setField(manageApplications, "mUserManager", um); ManageApplications.ApplicationsAdapter adapter = new ManageApplications.ApplicationsAdapter(
manageApplications.mListType = LIST_TYPE_NOTIFICATION; mState, mFragment, mock(AppFilterItem.class), mock(Bundle.class));
manageApplications.mSortOrder = -1;
ManageApplications.ApplicationsAdapter adapter =
new ManageApplications.ApplicationsAdapter(mState,
manageApplications, mock(AppFilterItem.class),
mock(Bundle.class));
adapter.rebuild(mSortRecent.getItemId()); adapter.rebuild(mSortRecent.getItemId());
assertThat(manageApplications.mSortOrder).isEqualTo(mSortRecent.getItemId()); assertThat(mFragment.mSortOrder).isEqualTo(mSortRecent.getItemId());
adapter.rebuild(mSortFrequent.getItemId()); adapter.rebuild(mSortFrequent.getItemId());
assertThat(manageApplications.mSortOrder).isEqualTo(mSortFrequent.getItemId()); assertThat(mFragment.mSortOrder).isEqualTo(mSortFrequent.getItemId());
} }
private void setUpOptionMenus() { private void setUpOptionMenus() {