diff options
| author | 2019-05-04 14:30:29 +0000 | |
|---|---|---|
| committer | 2019-05-04 14:30:29 +0000 | |
| commit | 165ac85b3354d22a9ceefa6aed4e9a43b9ff06be (patch) | |
| tree | 97443dda2982f8d73e0b1f3f9d841d7169bc7d6c | |
| parent | e6b32f6b31b59f3b9953dc264c702d080414d753 (diff) | |
| parent | 8bd8fdf5068306ecac2850354daeb0002c4e4996 (diff) | |
Merge "Remove separate recent app tracking" into qt-dev
5 files changed, 26 insertions, 165 deletions
diff --git a/core/java/android/app/INotificationManager.aidl b/core/java/android/app/INotificationManager.aidl index b3c2429004b8..e57738fbbfdd 100644 --- a/core/java/android/app/INotificationManager.aidl +++ b/core/java/android/app/INotificationManager.aidl @@ -102,7 +102,6 @@ interface INotificationManager NotificationChannelGroup getNotificationChannelGroup(String pkg, String channelGroupId); ParceledListSlice getNotificationChannelGroups(String pkg); boolean onlyHasDefaultChannel(String pkg, int uid); - ParceledListSlice getRecentNotifyingAppsForUser(int userId); int getBlockedAppCount(int userId); boolean areChannelsBypassingDnd(); int getAppsBypassingDndCount(int uid); diff --git a/core/java/android/service/notification/NotifyingApp.java b/core/java/android/service/notification/NotifyingApp.java index a56062340709..a4fc5fde3bc2 100644 --- a/core/java/android/service/notification/NotifyingApp.java +++ b/core/java/android/service/notification/NotifyingApp.java @@ -26,27 +26,27 @@ import java.util.Objects; */ public final class NotifyingApp implements Parcelable, Comparable<NotifyingApp> { - private int mUid; + private int mUserId; private String mPkg; private long mLastNotified; public NotifyingApp() {} protected NotifyingApp(Parcel in) { - mUid = in.readInt(); + mUserId = in.readInt(); mPkg = in.readString(); mLastNotified = in.readLong(); } - public int getUid() { - return mUid; + public int getUserId() { + return mUserId; } /** - * Sets the uid of the package that sent the notification. Returns self. + * Sets the userid of the package that sent the notification. Returns self. */ - public NotifyingApp setUid(int mUid) { - this.mUid = mUid; + public NotifyingApp setUserId(int mUserId) { + this.mUserId = mUserId; return this; } @@ -74,7 +74,7 @@ public final class NotifyingApp implements Parcelable, Comparable<NotifyingApp> return this; } - public static final @android.annotation.NonNull Creator<NotifyingApp> CREATOR = new Creator<NotifyingApp>() { + public static final @NonNull Creator<NotifyingApp> CREATOR = new Creator<NotifyingApp>() { @Override public NotifyingApp createFromParcel(Parcel in) { return new NotifyingApp(in); @@ -93,7 +93,7 @@ public final class NotifyingApp implements Parcelable, Comparable<NotifyingApp> @Override public void writeToParcel(Parcel dest, int flags) { - dest.writeInt(mUid); + dest.writeInt(mUserId); dest.writeString(mPkg); dest.writeLong(mLastNotified); } @@ -103,14 +103,14 @@ public final class NotifyingApp implements Parcelable, Comparable<NotifyingApp> if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; NotifyingApp that = (NotifyingApp) o; - return getUid() == that.getUid() + return getUserId() == that.getUserId() && getLastNotified() == that.getLastNotified() && Objects.equals(mPkg, that.mPkg); } @Override public int hashCode() { - return Objects.hash(getUid(), mPkg, getLastNotified()); + return Objects.hash(getUserId(), mPkg, getLastNotified()); } /** @@ -119,10 +119,10 @@ public final class NotifyingApp implements Parcelable, Comparable<NotifyingApp> @Override public int compareTo(NotifyingApp o) { if (getLastNotified() == o.getLastNotified()) { - if (getUid() == o.getUid()) { + if (getUserId() == o.getUserId()) { return getPackage().compareTo(o.getPackage()); } - return Integer.compare(getUid(), o.getUid()); + return Integer.compare(getUserId(), o.getUserId()); } return -Long.compare(getLastNotified(), o.getLastNotified()); @@ -131,7 +131,7 @@ public final class NotifyingApp implements Parcelable, Comparable<NotifyingApp> @Override public String toString() { return "NotifyingApp{" - + "mUid=" + mUid + + "mUserId=" + mUserId + ", mPkg='" + mPkg + '\'' + ", mLastNotified=" + mLastNotified + '}'; diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 907502e6a809..3e26e013a0a5 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -121,6 +121,8 @@ import android.app.backup.BackupManager; import android.app.role.OnRoleHoldersChangedListener; import android.app.role.RoleManager; import android.app.usage.UsageEvents; +import android.app.usage.UsageStats; +import android.app.usage.UsageStatsManager; import android.app.usage.UsageStatsManagerInternal; import android.companion.ICompanionDeviceManager; import android.content.BroadcastReceiver; @@ -258,6 +260,8 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; +import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.Iterator; import java.util.List; import java.util.Map.Entry; @@ -413,7 +417,6 @@ public class NotificationManagerService extends SystemService { final ArrayMap<Integer, ArrayMap<String, String>> mAutobundledSummaries = new ArrayMap<>(); final ArrayList<ToastRecord> mToastQueue = new ArrayList<>(); final ArrayMap<String, NotificationRecord> mSummaryByGroupKey = new ArrayMap<>(); - final ArrayMap<Integer, ArrayList<NotifyingApp>> mRecentApps = new ArrayMap<>(); // The last key in this list owns the hardware. ArrayList<String> mLights = new ArrayList<>(); @@ -2209,7 +2212,6 @@ public class NotificationManagerService extends SystemService { mAppUsageStats.reportInterruptiveNotification(r.sbn.getPackageName(), r.getChannel().getId(), getRealUserId(r.sbn.getUserId())); - logRecentLocked(r); r.setRecordedInterruption(true); } } @@ -2830,16 +2832,6 @@ public class NotificationManagerService extends SystemService { } @Override - public ParceledListSlice<NotifyingApp> getRecentNotifyingAppsForUser(int userId) { - checkCallerIsSystem(); - synchronized (mNotificationLock) { - List<NotifyingApp> apps = new ArrayList<>( - mRecentApps.getOrDefault(userId, new ArrayList<>())); - return new ParceledListSlice<>(apps); - } - } - - @Override public int getBlockedAppCount(int userId) { checkCallerIsSystem(); return mPreferencesHelper.getBlockedAppCount(userId); @@ -5527,38 +5519,6 @@ public class NotificationManagerService extends SystemService { } /** - * Keeps the last 5 packages that have notified, by user. - */ - @GuardedBy("mNotificationLock") - @VisibleForTesting - protected void logRecentLocked(NotificationRecord r) { - if (r.isUpdate) { - return; - } - ArrayList<NotifyingApp> recentAppsForUser = - mRecentApps.getOrDefault(r.getUser().getIdentifier(), new ArrayList<>(6)); - NotifyingApp na = new NotifyingApp() - .setPackage(r.sbn.getPackageName()) - .setUid(r.sbn.getUid()) - .setLastNotified(r.sbn.getPostTime()); - // A new notification gets an app moved to the front of the list - for (int i = recentAppsForUser.size() - 1; i >= 0; i--) { - NotifyingApp naExisting = recentAppsForUser.get(i); - if (na.getPackage().equals(naExisting.getPackage()) - && na.getUid() == naExisting.getUid()) { - recentAppsForUser.remove(i); - break; - } - } - // time is always increasing, so always add to the front of the list - recentAppsForUser.add(0, na); - if (recentAppsForUser.size() > 5) { - recentAppsForUser.remove(recentAppsForUser.size() -1); - } - mRecentApps.put(r.getUser().getIdentifier(), recentAppsForUser); - } - - /** * Ensures that grouped notification receive their special treatment. * * <p>Cancels group children if the new notification causes a group to lose diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java index 8d56bc400d14..d2332bf86e95 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotificationManagerServiceTest.java @@ -3026,104 +3026,6 @@ public class NotificationManagerServiceTest extends UiServiceTestCase { } @Test - public void testRecents() throws Exception { - Set<NotifyingApp> expected = new HashSet<>(); - - final NotificationRecord oldest = new NotificationRecord(mContext, - generateSbn("p", 1000, 9, 0), mTestNotificationChannel); - mService.logRecentLocked(oldest); - for (int i = 1; i <= 5; i++) { - NotificationRecord r = new NotificationRecord(mContext, - generateSbn("p" + i, i, i*100, 0), mTestNotificationChannel); - expected.add(new NotifyingApp() - .setPackage(r.sbn.getPackageName()) - .setUid(r.sbn.getUid()) - .setLastNotified(r.sbn.getPostTime())); - mService.logRecentLocked(r); - } - - List<NotifyingApp> apps = mBinderService.getRecentNotifyingAppsForUser(0).getList(); - assertTrue(apps.size() == 5); - for (NotifyingApp actual : apps) { - assertTrue("got unexpected result: " + actual, expected.contains(actual)); - } - } - - @Test - public void testRecentsNoDuplicatePackages() throws Exception { - final NotificationRecord p1 = new NotificationRecord(mContext, generateSbn("p", 1, 1000, 0), - mTestNotificationChannel); - final NotificationRecord p2 = new NotificationRecord(mContext, generateSbn("p", 1, 2000, 0), - mTestNotificationChannel); - - mService.logRecentLocked(p1); - mService.logRecentLocked(p2); - - List<NotifyingApp> apps = mBinderService.getRecentNotifyingAppsForUser(0).getList(); - assertTrue(apps.size() == 1); - NotifyingApp expected = new NotifyingApp().setPackage("p").setUid(1).setLastNotified(2000); - assertEquals(expected, apps.get(0)); - } - - @Test - public void testRecentsWithDuplicatePackage() throws Exception { - Set<NotifyingApp> expected = new HashSet<>(); - - final NotificationRecord oldest = new NotificationRecord(mContext, - generateSbn("p", 1000, 9, 0), mTestNotificationChannel); - mService.logRecentLocked(oldest); - for (int i = 1; i <= 5; i++) { - NotificationRecord r = new NotificationRecord(mContext, - generateSbn("p" + i, i, i*100, 0), mTestNotificationChannel); - expected.add(new NotifyingApp() - .setPackage(r.sbn.getPackageName()) - .setUid(r.sbn.getUid()) - .setLastNotified(r.sbn.getPostTime())); - mService.logRecentLocked(r); - } - NotificationRecord r = new NotificationRecord(mContext, - generateSbn("p" + 3, 3, 300000, 0), mTestNotificationChannel); - expected.remove(new NotifyingApp() - .setPackage(r.sbn.getPackageName()) - .setUid(3) - .setLastNotified(300)); - NotifyingApp newest = new NotifyingApp() - .setPackage(r.sbn.getPackageName()) - .setUid(r.sbn.getUid()) - .setLastNotified(r.sbn.getPostTime()); - expected.add(newest); - mService.logRecentLocked(r); - - List<NotifyingApp> apps = mBinderService.getRecentNotifyingAppsForUser(0).getList(); - assertTrue(apps.size() == 5); - for (NotifyingApp actual : apps) { - assertTrue("got unexpected result: " + actual, expected.contains(actual)); - } - assertEquals(newest, apps.get(0)); - } - - @Test - public void testRecentsMultiuser() throws Exception { - final NotificationRecord user1 = new NotificationRecord(mContext, - generateSbn("p", 1000, 9, 1), mTestNotificationChannel); - mService.logRecentLocked(user1); - - final NotificationRecord user2 = new NotificationRecord(mContext, - generateSbn("p2", 100000, 9999, 2), mTestNotificationChannel); - mService.logRecentLocked(user2); - - assertEquals(0, mBinderService.getRecentNotifyingAppsForUser(0).getList().size()); - assertEquals(1, mBinderService.getRecentNotifyingAppsForUser(1).getList().size()); - assertEquals(1, mBinderService.getRecentNotifyingAppsForUser(2).getList().size()); - - assertTrue(mBinderService.getRecentNotifyingAppsForUser(2).getList().contains( - new NotifyingApp() - .setPackage(user2.sbn.getPackageName()) - .setUid(user2.sbn.getUid()) - .setLastNotified(user2.sbn.getPostTime()))); - } - - @Test public void testRestore() throws Exception { int systemChecks = mService.countSystemChecks; mBinderService.applyRestore(null, UserHandle.USER_SYSTEM); diff --git a/services/tests/uiservicestests/src/com/android/server/notification/NotifyingAppTest.java b/services/tests/uiservicestests/src/com/android/server/notification/NotifyingAppTest.java index 25e10d0740da..0c6283116594 100644 --- a/services/tests/uiservicestests/src/com/android/server/notification/NotifyingAppTest.java +++ b/services/tests/uiservicestests/src/com/android/server/notification/NotifyingAppTest.java @@ -36,7 +36,7 @@ public class NotifyingAppTest extends UiServiceTestCase { @Test public void testConstructor() { NotifyingApp na = new NotifyingApp(); - assertEquals(0, na.getUid()); + assertEquals(0, na.getUserId()); assertEquals(0, na.getLastNotified()); assertEquals(null, na.getPackage()); } @@ -49,10 +49,10 @@ public class NotifyingAppTest extends UiServiceTestCase { } @Test - public void testUid() { + public void testUserId() { NotifyingApp na = new NotifyingApp(); - na.setUid(90); - assertEquals(90, na.getUid()); + na.setUserId(90); + assertEquals(90, na.getUserId()); } @Test @@ -66,7 +66,7 @@ public class NotifyingAppTest extends UiServiceTestCase { public void testWriteToParcel() { NotifyingApp na = new NotifyingApp(); na.setPackage("package"); - na.setUid(200); + na.setUserId(200); na.setLastNotified(4000); Parcel parcel = Parcel.obtain(); @@ -75,19 +75,19 @@ public class NotifyingAppTest extends UiServiceTestCase { NotifyingApp na1 = NotifyingApp.CREATOR.createFromParcel(parcel); assertEquals(na.getLastNotified(), na1.getLastNotified()); assertEquals(na.getPackage(), na1.getPackage()); - assertEquals(na.getUid(), na1.getUid()); + assertEquals(na.getUserId(), na1.getUserId()); } @Test public void testCompareTo() { NotifyingApp na1 = new NotifyingApp(); na1.setPackage("pkg1"); - na1.setUid(1000); + na1.setUserId(1000); na1.setLastNotified(6); NotifyingApp na2 = new NotifyingApp(); na2.setPackage("a"); - na2.setUid(999); + na2.setUserId(999); na2.setLastNotified(1); assertTrue(na1.compareTo(na2) < 0); |