Merge "Always include uid as part of recentApp key" into qt-dev
am: 08ef7bd52b
Change-Id: I305672e35b3df07cb9bd0f0635033e1106a0f884
This commit is contained in:
@@ -79,7 +79,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
private final PackageManager mPm;
|
private final PackageManager mPm;
|
||||||
private final NotificationBackend mNotificationBackend;
|
private final NotificationBackend mNotificationBackend;
|
||||||
private IUsageStatsManager mUsageStatsManager;
|
private IUsageStatsManager mUsageStatsManager;
|
||||||
private final int mUserId;
|
|
||||||
private final IconDrawableFactory mIconDrawableFactory;
|
private final IconDrawableFactory mIconDrawableFactory;
|
||||||
|
|
||||||
private Calendar mCal;
|
private Calendar mCal;
|
||||||
@@ -104,7 +103,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
ApplicationsState appState, Fragment host) {
|
ApplicationsState appState, Fragment host) {
|
||||||
super(context);
|
super(context);
|
||||||
mIconDrawableFactory = IconDrawableFactory.newInstance(context);
|
mIconDrawableFactory = IconDrawableFactory.newInstance(context);
|
||||||
mUserId = UserHandle.myUserId();
|
|
||||||
mPm = context.getPackageManager();
|
mPm = context.getPackageManager();
|
||||||
mHost = host;
|
mHost = host;
|
||||||
mApplicationsState = appState;
|
mApplicationsState = appState;
|
||||||
@@ -177,7 +175,6 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (events != null) {
|
if (events != null) {
|
||||||
|
|
||||||
ArrayMap<String, NotifyingApp> aggregatedStats = new ArrayMap<>();
|
ArrayMap<String, NotifyingApp> aggregatedStats = new ArrayMap<>();
|
||||||
|
|
||||||
UsageEvents.Event event = new UsageEvents.Event();
|
UsageEvents.Event event = new UsageEvents.Event();
|
||||||
@@ -205,7 +202,8 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getKey(int userId, String pkg) {
|
@VisibleForTesting
|
||||||
|
static String getKey(int userId, String pkg) {
|
||||||
return userId + "|" + pkg;
|
return userId + "|" + pkg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,12 +250,13 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean rebindPref = true;
|
boolean rebindPref = true;
|
||||||
NotificationAppPreference pref = appPreferences.remove(pkgName);
|
NotificationAppPreference pref = appPreferences.remove(getKey(app.getUserId(),
|
||||||
|
pkgName));
|
||||||
if (pref == null) {
|
if (pref == null) {
|
||||||
pref = new NotificationAppPreference(prefContext);
|
pref = new NotificationAppPreference(prefContext);
|
||||||
rebindPref = false;
|
rebindPref = false;
|
||||||
}
|
}
|
||||||
pref.setKey(pkgName);
|
pref.setKey(getKey(app.getUserId(), pkgName));
|
||||||
pref.setTitle(appEntry.label);
|
pref.setTitle(appEntry.label);
|
||||||
pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
|
pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
|
||||||
pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL);
|
pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL);
|
||||||
@@ -267,11 +266,11 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName);
|
args.putString(AppInfoBase.ARG_PACKAGE_NAME, pkgName);
|
||||||
args.putInt(AppInfoBase.ARG_PACKAGE_UID, appEntry.info.uid);
|
args.putInt(AppInfoBase.ARG_PACKAGE_UID, appEntry.info.uid);
|
||||||
|
|
||||||
pref.setIntent(new SubSettingLauncher(mHost.getActivity())
|
pref.setIntent(new SubSettingLauncher(mHost.getActivity())
|
||||||
.setDestination(AppNotificationSettings.class.getName())
|
.setDestination(AppNotificationSettings.class.getName())
|
||||||
.setTitleRes(R.string.notifications_title)
|
.setTitleRes(R.string.notifications_title)
|
||||||
.setArguments(args)
|
.setArguments(args)
|
||||||
|
.setUserHandle(new UserHandle(UserHandle.getUserId(appEntry.info.uid)))
|
||||||
.setSourceMetricsCategory(
|
.setSourceMetricsCategory(
|
||||||
SettingsEnums.MANAGE_APPLICATIONS_NOTIFICATIONS)
|
SettingsEnums.MANAGE_APPLICATIONS_NOTIFICATIONS)
|
||||||
.toIntent());
|
.toIntent());
|
||||||
@@ -301,11 +300,11 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
int count = 0;
|
int count = 0;
|
||||||
for (NotifyingApp app : mApps) {
|
for (NotifyingApp app : mApps) {
|
||||||
final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(
|
final ApplicationsState.AppEntry appEntry = mApplicationsState.getEntry(
|
||||||
app.getPackage(), mUserId);
|
app.getPackage(), app.getUserId());
|
||||||
if (appEntry == null) {
|
if (appEntry == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!shouldIncludePkgInRecents(app.getPackage())) {
|
if (!shouldIncludePkgInRecents(app.getPackage(), app.getUserId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
displayableApps.add(app);
|
displayableApps.add(app);
|
||||||
@@ -321,14 +320,14 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC
|
|||||||
/**
|
/**
|
||||||
* Whether or not the app should be included in recent list.
|
* Whether or not the app should be included in recent list.
|
||||||
*/
|
*/
|
||||||
private boolean shouldIncludePkgInRecents(String pkgName) {
|
private boolean shouldIncludePkgInRecents(String pkgName, int userId) {
|
||||||
final Intent launchIntent = new Intent().addCategory(Intent.CATEGORY_LAUNCHER)
|
final Intent launchIntent = new Intent().addCategory(Intent.CATEGORY_LAUNCHER)
|
||||||
.setPackage(pkgName);
|
.setPackage(pkgName);
|
||||||
|
|
||||||
if (mPm.resolveActivity(launchIntent, 0) == null) {
|
if (mPm.resolveActivity(launchIntent, 0) == null) {
|
||||||
// Not visible on launcher -> likely not a user visible app, skip if non-instant.
|
// Not visible on launcher -> likely not a user visible app, skip if non-instant.
|
||||||
final ApplicationsState.AppEntry appEntry =
|
final ApplicationsState.AppEntry appEntry =
|
||||||
mApplicationsState.getEntry(pkgName, mUserId);
|
mApplicationsState.getEntry(pkgName, userId);
|
||||||
if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) {
|
if (appEntry == null || appEntry.info == null || !AppUtils.isInstant(appEntry.info)) {
|
||||||
Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName);
|
Log.d(TAG, "Not a user visible or instant app, skipping " + pkgName);
|
||||||
return false;
|
return false;
|
||||||
|
@@ -168,7 +168,6 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void display_showRecents() throws Exception {
|
public void display_showRecents() throws Exception {
|
||||||
|
|
||||||
List<Event> events = new ArrayList<>();
|
List<Event> events = new ArrayList<>();
|
||||||
Event app = new Event();
|
Event app = new Event();
|
||||||
app.mEventType = Event.NOTIFICATION_INTERRUPTION;
|
app.mEventType = Event.NOTIFICATION_INTERRUPTION;
|
||||||
@@ -262,8 +261,12 @@ public class RecentNotifyingAppsPreferenceControllerTest {
|
|||||||
ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
|
ArgumentCaptor<Preference> prefCaptor = ArgumentCaptor.forClass(Preference.class);
|
||||||
verify(mCategory, times(2)).addPreference(prefCaptor.capture());
|
verify(mCategory, times(2)).addPreference(prefCaptor.capture());
|
||||||
List<Preference> prefs = prefCaptor.getAllValues();
|
List<Preference> prefs = prefCaptor.getAllValues();
|
||||||
assertThat(prefs.get(1).getKey()).isEqualTo(app.getPackageName());
|
assertThat(prefs.get(1).getKey()).isEqualTo(
|
||||||
assertThat(prefs.get(0).getKey()).isEqualTo(app1.getPackageName());
|
RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(),
|
||||||
|
app.getPackageName()));
|
||||||
|
assertThat(prefs.get(0).getKey()).isEqualTo(
|
||||||
|
RecentNotifyingAppsPreferenceController.getKey(UserHandle.myUserId(),
|
||||||
|
app1.getPackageName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Reference in New Issue
Block a user