diff --git a/services/core/java/android/app/usage/UsageStatsManagerInternal.java b/services/core/java/android/app/usage/UsageStatsManagerInternal.java index 21fc19ec3079c..435d294a3e8e0 100644 --- a/services/core/java/android/app/usage/UsageStatsManagerInternal.java +++ b/services/core/java/android/app/usage/UsageStatsManagerInternal.java @@ -17,6 +17,7 @@ package android.app.usage; import android.annotation.CurrentTimeMillisLong; +import android.annotation.ElapsedRealtimeLong; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; @@ -25,6 +26,7 @@ import android.content.ComponentName; import android.content.LocusId; import android.content.res.Configuration; import android.os.IBinder; +import android.os.SystemClock; import android.os.UserHandle; import android.os.UserManager; @@ -362,4 +364,52 @@ public abstract class UsageStatsManagerInternal { /** Unregister a listener from being notified of every estimated launch time change. */ public abstract void unregisterLaunchTimeChangedListener( @NonNull EstimatedLaunchTimeChangedListener listener); + + /** + * Reports a broadcast dispatched event to the UsageStatsManager. + * + * @param sourceUid uid of the package that sent the broadcast. + * @param targetPackage name of the package that the broadcast is targeted to. + * @param targetUser user that {@code targetPackage} belongs to. + * @param idForResponseEvent ID to be used for recording any response events corresponding + * to this broadcast. + * @param timestampMs time (in millis) when the broadcast was dispatched, in + * {@link SystemClock#elapsedRealtime()} timebase. + */ + public abstract void reportBroadcastDispatched(int sourceUid, @NonNull String targetPackage, + @NonNull UserHandle targetUser, long idForResponseEvent, + @ElapsedRealtimeLong long timestampMs); + + /** + * Reports a notification posted event to the UsageStatsManager. + * + * @param packageName name of the package which posted the notification. + * @param user user that {@code packageName} belongs to. + * @param timestampMs time (in millis) when the notification was posted, in + * {@link SystemClock#elapsedRealtime()} timebase. + */ + public abstract void reportNotificationPosted(@NonNull String packageName, + @NonNull UserHandle user, @ElapsedRealtimeLong long timestampMs); + + /** + * Reports a notification updated event to the UsageStatsManager. + * + * @param packageName name of the package which updated the notification. + * @param user user that {@code packageName} belongs to. + * @param timestampMs time (in millis) when the notification was updated, in + * {@link SystemClock#elapsedRealtime()} timebase. + */ + public abstract void reportNotificationUpdated(@NonNull String packageName, + @NonNull UserHandle user, @ElapsedRealtimeLong long timestampMs); + + /** + * Reports a notification removed event to the UsageStatsManager. + * + * @param packageName name of the package which removed the notification. + * @param user user that {@code packageName} belongs to. + * @param timestampMs time (in millis) when the notification was removed, in + * {@link SystemClock#elapsedRealtime()} timebase. + */ + public abstract void reportNotificationRemoved(@NonNull String packageName, + @NonNull UserHandle user, @ElapsedRealtimeLong long timestampMs); } diff --git a/services/usage/java/com/android/server/usage/UsageStatsService.java b/services/usage/java/com/android/server/usage/UsageStatsService.java index 997c8832f4a9a..559eb388fe57f 100644 --- a/services/usage/java/com/android/server/usage/UsageStatsService.java +++ b/services/usage/java/com/android/server/usage/UsageStatsService.java @@ -33,6 +33,7 @@ import static android.text.format.DateUtils.HOUR_IN_MILLIS; import android.Manifest; import android.annotation.CurrentTimeMillisLong; +import android.annotation.ElapsedRealtimeLong; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.UserIdInt; @@ -2947,6 +2948,27 @@ public class UsageStatsService extends SystemService implements @NonNull EstimatedLaunchTimeChangedListener listener) { UsageStatsService.this.unregisterLaunchTimeChangedListener(listener); } + + @Override + public void reportBroadcastDispatched(int sourceUid, @NonNull String targetPackage, + @NonNull UserHandle targetUser, long idForResponseEvent, + @ElapsedRealtimeLong long timestampMs) { + } + + @Override + public void reportNotificationPosted(@NonNull String packageName, + @NonNull UserHandle user, @ElapsedRealtimeLong long timestampMs) { + } + + @Override + public void reportNotificationUpdated(@NonNull String packageName, + @NonNull UserHandle user, @ElapsedRealtimeLong long timestampMs) { + } + + @Override + public void reportNotificationRemoved(@NonNull String packageName, + @NonNull UserHandle user, @ElapsedRealtimeLong long timestampMs) { + } } private class MyPackageMonitor extends PackageMonitor {