diff options
author | Varun Shah <varunshah@google.com> | 2020-02-04 14:01:12 -0800 |
---|---|---|
committer | Varun Shah <varunshah@google.com> | 2020-02-13 12:01:13 -0800 |
commit | 0cbb6b63ee696f156499ed8873efc95602c01440 (patch) | |
tree | 0fc402f65d19e12692cd9f86541ec75f014051f2 /services/usage | |
parent | 3b726119ac628e0a7016ef22d2b14e1802dcfd48 (diff) |
Obfuscate visibility of notification-related events.
UsageStats will return obfuscated NOTIFICATION_SEEN or
NOTIFICATION_INTERRUPTION events to callers of #queryEvents
and #queryEventsForUser if they don't hold the MANAGE_NOTIFICATIONS
permission.
Additionaly, refactor the query API in UsageStats to take in flags as
defined in UsageEvents to make future obfuscation/visibility parameters
cleaner.
Also, add the MANAGE_NOTIFICATIONS permission to shell for CTS test.
Bug: 144724524
Test: atest android.app.usage.cts.UsageStatsTest
Test: atest com.android.server.people.data.UsageStatsQueryHelperTest
Test: atest android.content.pm.cts.shortcutmanager.ShortcutManagerUsageTest
Change-Id: I118de7e589ac8dd5924d3740c70903fa484b79b5
Diffstat (limited to 'services/usage')
-rw-r--r-- | services/usage/java/com/android/server/usage/UsageStatsService.java | 54 | ||||
-rw-r--r-- | services/usage/java/com/android/server/usage/UserUsageStatsService.java | 24 |
2 files changed, 52 insertions, 26 deletions
diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 420695dc51e4..df5b311bbab1 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -500,6 +500,19 @@ public class UsageStatsService extends SystemService implements == PackageManager.PERMISSION_GRANTED); } + /** + * Obfuscate both {@link UsageEvents.Event#NOTIFICATION_SEEN} and + * {@link UsageEvents.Event#NOTIFICATION_INTERRUPTION} events if the provided calling uid does + * not hold the {@link android.Manifest.permission.MANAGE_NOTIFICATIONS} permission. + */ + private boolean shouldObfuscateNotificationEvents(int callingPid, int callingUid) { + if (callingUid == Process.SYSTEM_UID) { + return false; + } + return !(getContext().checkPermission(android.Manifest.permission.MANAGE_NOTIFICATIONS, + callingPid, callingUid) == PackageManager.PERMISSION_GRANTED); + } + private static void deleteRecursively(File f) { File[] files = f.listFiles(); if (files != null) { @@ -1038,9 +1051,7 @@ public class UsageStatsService extends SystemService implements /** * Called by the Binder stub. */ - UsageEvents queryEvents(int userId, long beginTime, long endTime, - boolean shouldObfuscateInstantApps, boolean shouldHideShortcutInvocationEvents, - boolean shouldHideLocusIdEvents) { + UsageEvents queryEvents(int userId, long beginTime, long endTime, int flags) { synchronized (mLock) { if (!mUserUnlockedStates.get(userId)) { Slog.w(TAG, "Failed to query events for locked user " + userId); @@ -1051,8 +1062,7 @@ public class UsageStatsService extends SystemService implements if (service == null) { return null; // user was stopped or removed } - return service.queryEvents(beginTime, endTime, shouldObfuscateInstantApps, - shouldHideShortcutInvocationEvents, shouldHideLocusIdEvents); + return service.queryEvents(beginTime, endTime, flags); } } @@ -1475,10 +1485,15 @@ public class UsageStatsService extends SystemService implements try { final boolean hideShortcutInvocationEvents = shouldHideShortcutInvocationEvents( userId, callingPackage, callingPid, callingUid); - boolean shouldHideLocusIdEvents = shouldHideLocusIdEvents(callingPid, callingUid); - return UsageStatsService.this.queryEvents(userId, beginTime, endTime, - obfuscateInstantApps, hideShortcutInvocationEvents, - shouldHideLocusIdEvents); + final boolean hideLocusIdEvents = shouldHideLocusIdEvents(callingPid, callingUid); + final boolean obfuscateNotificationEvents = shouldObfuscateNotificationEvents( + callingPid, callingUid); + int flags = UsageEvents.SHOW_ALL_EVENT_DATA; + if (obfuscateInstantApps) flags |= UsageEvents.OBFUSCATE_INSTANT_APPS; + if (hideShortcutInvocationEvents) flags |= UsageEvents.HIDE_SHORTCUT_EVENTS; + if (hideLocusIdEvents) flags |= UsageEvents.HIDE_LOCUS_EVENTS; + if (obfuscateNotificationEvents) flags |= UsageEvents.OBFUSCATE_NOTIFICATION_EVENTS; + return UsageStatsService.this.queryEvents(userId, beginTime, endTime, flags); } finally { Binder.restoreCallingIdentity(token); } @@ -1525,10 +1540,15 @@ public class UsageStatsService extends SystemService implements try { final boolean hideShortcutInvocationEvents = shouldHideShortcutInvocationEvents( userId, callingPackage, callingPid, callingUid); - boolean shouldHideLocusIdEvents = shouldHideLocusIdEvents(callingPid, callingUid); - return UsageStatsService.this.queryEvents(userId, beginTime, endTime, - obfuscateInstantApps, hideShortcutInvocationEvents, - shouldHideLocusIdEvents); + final boolean obfuscateNotificationEvents = shouldObfuscateNotificationEvents( + callingPid, callingUid); + boolean hideLocusIdEvents = shouldHideLocusIdEvents(callingPid, callingUid); + int flags = UsageEvents.SHOW_ALL_EVENT_DATA; + if (obfuscateInstantApps) flags |= UsageEvents.OBFUSCATE_INSTANT_APPS; + if (hideShortcutInvocationEvents) flags |= UsageEvents.HIDE_SHORTCUT_EVENTS; + if (hideLocusIdEvents) flags |= UsageEvents.HIDE_LOCUS_EVENTS; + if (obfuscateNotificationEvents) flags |= UsageEvents.OBFUSCATE_NOTIFICATION_EVENTS; + return UsageStatsService.this.queryEvents(userId, beginTime, endTime, flags); } finally { Binder.restoreCallingIdentity(token); } @@ -2144,12 +2164,8 @@ public class UsageStatsService extends SystemService implements } @Override - public UsageEvents queryEventsForUser(int userId, long beginTime, long endTime, - boolean obfuscateInstantApps, boolean shouldHideShortcutInvocationEvents, - boolean shouldHideLocusIdEvents) { - return UsageStatsService.this.queryEvents( - userId, beginTime, endTime, obfuscateInstantApps, - shouldHideShortcutInvocationEvents, shouldHideLocusIdEvents); + public UsageEvents queryEventsForUser(int userId, long beginTime, long endTime, int flags) { + return UsageStatsService.this.queryEvents(userId, beginTime, endTime, flags); } @Override diff --git a/services/usage/java/com/android/server/usage/UserUsageStatsService.java b/services/usage/java/com/android/server/usage/UserUsageStatsService.java index d9317ace6e24..db26d88dbfbb 100644 --- a/services/usage/java/com/android/server/usage/UserUsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UserUsageStatsService.java @@ -18,6 +18,10 @@ package com.android.server.usage; import static android.app.usage.UsageEvents.Event.DEVICE_SHUTDOWN; import static android.app.usage.UsageEvents.Event.DEVICE_STARTUP; +import static android.app.usage.UsageEvents.HIDE_LOCUS_EVENTS; +import static android.app.usage.UsageEvents.HIDE_SHORTCUT_EVENTS; +import static android.app.usage.UsageEvents.OBFUSCATE_INSTANT_APPS; +import static android.app.usage.UsageEvents.OBFUSCATE_NOTIFICATION_EVENTS; import static android.app.usage.UsageStatsManager.INTERVAL_BEST; import static android.app.usage.UsageStatsManager.INTERVAL_COUNT; import static android.app.usage.UsageStatsManager.INTERVAL_DAILY; @@ -481,8 +485,7 @@ class UserUsageStatsService { return queryStats(bucketType, beginTime, endTime, sEventStatsCombiner); } - UsageEvents queryEvents(final long beginTime, final long endTime, boolean obfuscateInstantApps, - boolean hideShortcutInvocationEvents, boolean hideLocusIdEvents) { + UsageEvents queryEvents(final long beginTime, final long endTime, int flags) { if (!validRange(checkAndGetTimeLocked(), beginTime, endTime)) { return null; } @@ -500,15 +503,22 @@ class UserUsageStatsService { } Event event = stats.events.get(i); - if (hideShortcutInvocationEvents - && event.mEventType == Event.SHORTCUT_INVOCATION) { + final int eventType = event.mEventType; + if (eventType == Event.SHORTCUT_INVOCATION + && (flags & HIDE_SHORTCUT_EVENTS) == HIDE_SHORTCUT_EVENTS) { continue; } - if (hideLocusIdEvents - && event.mEventType == Event.LOCUS_ID_SET) { + if (eventType == Event.LOCUS_ID_SET + && (flags & HIDE_LOCUS_EVENTS) == HIDE_LOCUS_EVENTS) { continue; } - if (obfuscateInstantApps) { + if ((eventType == Event.NOTIFICATION_SEEN + || eventType == Event.NOTIFICATION_INTERRUPTION) + && (flags & OBFUSCATE_NOTIFICATION_EVENTS) + == OBFUSCATE_NOTIFICATION_EVENTS) { + event = event.getObfuscatedNotificationEvent(); + } + if ((flags & OBFUSCATE_INSTANT_APPS) == OBFUSCATE_INSTANT_APPS) { event = event.getObfuscatedIfInstantApp(); } if (event.mPackage != null) { |