Allow reporting certain events to UsageStatsManager.

Add methods to allow reporting broadcast-dispatched,
notification-posted, notification-updated,
notification-removed events to UsageStatsManager.

Bug: 206518114
Test: atest --test-mapping apex/jobscheduler/service/java/com/android/server/usage/TEST_MAPPING
Change-Id: I0337b4004505930d21f4ef669e79ba4512b9792b
This commit is contained in:
Sudheer Shanka
2022-01-24 12:31:23 +00:00
parent ff34ced59a
commit 4e50889197
2 changed files with 72 additions and 0 deletions

View File

@@ -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);
}

View File

@@ -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 {