diff options
Diffstat (limited to 'services')
3 files changed, 55 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/notification/NotificationManagerService.java b/services/core/java/com/android/server/notification/NotificationManagerService.java index 1008653..25998da 100644 --- a/services/core/java/com/android/server/notification/NotificationManagerService.java +++ b/services/core/java/com/android/server/notification/NotificationManagerService.java @@ -36,6 +36,9 @@ import android.app.NotificationManager; import android.app.NotificationManager.Policy; import android.app.PendingIntent; import android.app.StatusBarManager; +import android.app.usage.UsageEvents; +import android.app.usage.UsageStats; +import android.app.usage.UsageStatsManagerInternal; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.ContentResolver; @@ -97,6 +100,7 @@ import android.widget.Toast; import com.android.internal.R; import com.android.internal.util.FastXmlSerializer; import com.android.server.EventLogTags; +import com.android.server.LocalServices; import com.android.server.SystemService; import com.android.server.lights.Light; import com.android.server.lights.LightsManager; @@ -236,6 +240,7 @@ public class NotificationManagerService extends SystemService { ArrayList<String> mLights = new ArrayList<>(); private AppOpsManager mAppOps; + private UsageStatsManagerInternal mAppUsageStats; private Archive mArchive; @@ -871,6 +876,7 @@ public class NotificationManagerService extends SystemService { mAm = ActivityManagerNative.getDefault(); mAppOps = (AppOpsManager) getContext().getSystemService(Context.APP_OPS_SERVICE); mVibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE); + mAppUsageStats = LocalServices.getService(UsageStatsManagerInternal.class); mHandler = new WorkerHandler(); mRankingThread.start(); @@ -1405,6 +1411,41 @@ public class NotificationManagerService extends SystemService { } } + @Override + public void setNotificationsShownFromListener(INotificationListener token, String[] keys) { + final int callingUid = Binder.getCallingUid(); + final int callingPid = Binder.getCallingPid(); + long identity = Binder.clearCallingIdentity(); + try { + synchronized (mNotificationList) { + final ManagedServiceInfo info = mListeners.checkServiceTokenLocked(token); + if (keys != null) { + final int N = keys.length; + for (int i = 0; i < N; i++) { + NotificationRecord r = mNotificationsByKey.get(keys[i]); + if (r == null) continue; + final int userId = r.sbn.getUserId(); + if (userId != info.userid && userId != UserHandle.USER_ALL && + !mUserProfiles.isCurrentProfile(userId)) { + throw new SecurityException("Disallowed call from listener: " + + info.service); + } + if (!r.isSeen()) { + if (DBG) Slog.d(TAG, "Marking notification as seen " + keys[i]); + mAppUsageStats.reportEvent(r.sbn.getPackageName(), + userId == UserHandle.USER_ALL ? UserHandle.USER_OWNER + : userId, + UsageEvents.Event.INTERACTION); + r.setSeen(); + } + } + } + } + } finally { + Binder.restoreCallingIdentity(identity); + } + } + private void cancelNotificationFromListenerLocked(ManagedServiceInfo info, int callingUid, int callingPid, String pkg, String tag, int id, int userId) { cancelNotification(callingUid, callingPid, pkg, tag, id, 0, diff --git a/services/core/java/com/android/server/notification/NotificationRecord.java b/services/core/java/com/android/server/notification/NotificationRecord.java index 5569a09..e106a4a 100644 --- a/services/core/java/com/android/server/notification/NotificationRecord.java +++ b/services/core/java/com/android/server/notification/NotificationRecord.java @@ -50,6 +50,8 @@ public final class NotificationRecord { NotificationUsageStats.SingleNotificationStats stats; boolean isCanceled; int score; + /** Whether the notification was seen by the user via one of the notification listeners. */ + boolean mIsSeen; // These members are used by NotificationSignalExtractors // to communicate with the ranking module. @@ -301,6 +303,16 @@ public final class NotificationRecord { return mGlobalSortKey; } + /** Check if any of the listeners have marked this notification as seen by the user. */ + public boolean isSeen() { + return mIsSeen; + } + + /** Mark the notification as seen by the user. */ + public void setSeen() { + mIsSeen = true; + } + public void setAuthoritativeRank(int authoritativeRank) { mAuthoritativeRank = authoritativeRank; } diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index edeeaba..04984d3 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -28,6 +28,7 @@ import android.app.usage.UsageEvents.Event; import android.app.usage.UsageStats; import android.app.usage.UsageStatsManagerInternal; import android.app.usage.UsageStatsManagerInternal.AppIdleStateChangeListener; +import android.appwidget.AppWidgetManager; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -435,9 +436,7 @@ public class UsageStatsService extends SystemService implements DevicePolicyManager dpm = getContext().getSystemService(DevicePolicyManager.class); if (dpm == null) return false; List<ComponentName> components = dpm.getActiveAdminsAsUser(userId); - if (components == null) { - return false; - } + if (components == null) return false; final int size = components.size(); for (int i = 0; i < size; i++) { if (components.get(i).getPackageName().equals(packageName)) { |