Fix NPE on guest user
Test: RoboTests Fixes: 187548511 Change-Id: I86219bc5e2cf285fcc86f5c8456d7d2afcbe2c0f
This commit is contained in:
@@ -29,7 +29,6 @@ import android.os.UserManager;
|
|||||||
import android.service.notification.NotifyingApp;
|
import android.service.notification.NotifyingApp;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.ArrayMap;
|
import android.util.ArrayMap;
|
||||||
import android.util.ArraySet;
|
|
||||||
import android.util.IconDrawableFactory;
|
import android.util.IconDrawableFactory;
|
||||||
import android.util.Slog;
|
import android.util.Slog;
|
||||||
|
|
||||||
@@ -56,8 +55,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This controller displays a list of recently used apps and a "See all" button. If there is
|
* This controller displays a list of recently used apps and a "See all" button. If there is
|
||||||
@@ -149,9 +146,12 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
void refreshUi(Context prefContext) {
|
void refreshUi(Context prefContext) {
|
||||||
((PrimarySwitchPreference) mCategory.findPreference(KEY_PLACEHOLDER + 1)).setChecked(true);
|
for (int i = 1; i <= SHOW_RECENT_APP_COUNT; i++) {
|
||||||
((PrimarySwitchPreference) mCategory.findPreference(KEY_PLACEHOLDER + 2)).setChecked(true);
|
PrimarySwitchPreference app = mCategory.findPreference(KEY_PLACEHOLDER + i);
|
||||||
((PrimarySwitchPreference) mCategory.findPreference(KEY_PLACEHOLDER + 3)).setChecked(true);
|
if (app != null) {
|
||||||
|
app.setChecked(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
ThreadUtils.postOnBackgroundThread(() -> {
|
ThreadUtils.postOnBackgroundThread(() -> {
|
||||||
reloadData();
|
reloadData();
|
||||||
final List<NotifyingApp> recentApps = getDisplayableRecentAppList();
|
final List<NotifyingApp> recentApps = getDisplayableRecentAppList();
|
||||||
|
@@ -220,6 +220,42 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
verify(mSeeAllPref).setIcon(R.drawable.ic_chevron_right_24dp);
|
verify(mSeeAllPref).setIcon(R.drawable.ic_chevron_right_24dp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void display_noCrashIfLessThan3() throws Exception {
|
||||||
|
List<Event> events = new ArrayList<>();
|
||||||
|
Event app = new Event();
|
||||||
|
app.mEventType = Event.NOTIFICATION_INTERRUPTION;
|
||||||
|
app.mPackage = "a";
|
||||||
|
app.mTimeStamp = System.currentTimeMillis();
|
||||||
|
events.add(app);
|
||||||
|
ApplicationsState.AppEntry app1Entry = mock(ApplicationsState.AppEntry.class);
|
||||||
|
app1Entry.info = mApplicationInfo;
|
||||||
|
app1Entry.label = "app 1";
|
||||||
|
|
||||||
|
when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId()))
|
||||||
|
.thenReturn(app1Entry);
|
||||||
|
when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(
|
||||||
|
new ResolveInfo());
|
||||||
|
|
||||||
|
UsageEvents usageEvents = getUsageEvents(
|
||||||
|
new String[] {app.getPackageName()},
|
||||||
|
events);
|
||||||
|
when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
|
||||||
|
.thenReturn(usageEvents);
|
||||||
|
|
||||||
|
mAppEntry.info = mApplicationInfo;
|
||||||
|
|
||||||
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
|
verify(mCategory).setTitle(R.string.recent_notifications);
|
||||||
|
// Only add app1 & app2. app3 skipped because it's invalid app.
|
||||||
|
assertThat(mApp1.getTitle()).isEqualTo(app1Entry.label);
|
||||||
|
|
||||||
|
verify(mCategory).removePreferenceRecursively("app2");
|
||||||
|
|
||||||
|
mController.refreshUi(mContext);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void display_showRecentsWithInstantApp() throws Exception {
|
public void display_showRecentsWithInstantApp() throws Exception {
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
@@ -267,35 +303,12 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
mController.displayPreference(mScreen);
|
mController.displayPreference(mScreen);
|
||||||
|
|
||||||
assertThat(mApp1.getTitle()).isEqualTo(appEntry.label);
|
assertThat(mApp1.getTitle()).isEqualTo(appEntry.label);
|
||||||
|
assertThat(mApp1.getSummary()).isEqualTo("Just now");
|
||||||
assertThat(mApp2.getTitle()).isEqualTo(app1Entry.label);
|
assertThat(mApp2.getTitle()).isEqualTo(app1Entry.label);
|
||||||
|
|
||||||
verify(mCategory).removePreferenceRecursively(mApp3.getKey());
|
verify(mCategory).removePreferenceRecursively(mApp3.getKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void display_showRecents_formatSummary() throws Exception {
|
|
||||||
List<Event> events = new ArrayList<>();
|
|
||||||
Event app = new Event();
|
|
||||||
app.mEventType = Event.NOTIFICATION_INTERRUPTION;
|
|
||||||
app.mPackage = "pkg.class";
|
|
||||||
app.mTimeStamp = System.currentTimeMillis();
|
|
||||||
events.add(app);
|
|
||||||
UsageEvents usageEvents = getUsageEvents(new String[] {"pkg.class"}, events);
|
|
||||||
when(mIUsageStatsManager.queryEventsForUser(anyLong(), anyLong(), anyInt(), anyString()))
|
|
||||||
.thenReturn(usageEvents);
|
|
||||||
|
|
||||||
when(mAppState.getEntry(app.getPackageName(), UserHandle.myUserId()))
|
|
||||||
.thenReturn(mAppEntry);
|
|
||||||
when(mPackageManager.resolveActivity(any(Intent.class), anyInt())).thenReturn(
|
|
||||||
new ResolveInfo());
|
|
||||||
|
|
||||||
mAppEntry.info = mApplicationInfo;
|
|
||||||
|
|
||||||
mController.displayPreference(mScreen);
|
|
||||||
|
|
||||||
assertThat(mApp1.getSummary()).isEqualTo("Just now");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void reloadData() throws Exception {
|
public void reloadData() throws Exception {
|
||||||
when(mUserManager.getProfileIdsWithDisabled(0)).thenReturn(new int[] {0, 10});
|
when(mUserManager.getProfileIdsWithDisabled(0)).thenReturn(new int[] {0, 10});
|
||||||
|
Reference in New Issue
Block a user