Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c041a183 authored by Bishoy Gendy's avatar Bishoy Gendy Committed by Android (Google) Code Review
Browse files

Merge "Report MediaSession2 usages" into main

parents ccfd4b8f e2484b21
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -169,7 +169,8 @@ public class MediaSessionService extends SystemService implements Monitor {
    private UsageStatsManagerInternal mUsageStatsManagerInternal;

    /* Maps uid with all user engaging session tokens associated to it */
    private final SparseArray<Set<MediaSession.Token>> mUserEngagingSessions = new SparseArray<>();
    private final SparseArray<Set<MediaSessionRecordImpl>> mUserEngagingSessions =
            new SparseArray<>();

    // The FullUserRecord of the current users. (i.e. The foreground user that isn't a profile)
    // It's always not null after the MediaSessionService is started.
@@ -640,23 +641,21 @@ public class MediaSessionService extends SystemService implements Monitor {
    }

    private void reportMediaInteractionEvent(MediaSessionRecordImpl record, boolean userEngaged) {
        if (!android.app.usage.Flags.userInteractionTypeApi()
                || !(record instanceof MediaSessionRecord)) {
        if (!android.app.usage.Flags.userInteractionTypeApi()) {
            return;
        }

        String packageName = record.getPackageName();
        int sessionUid = record.getUid();
        MediaSession.Token token = ((MediaSessionRecord) record).getSessionToken();
        if (userEngaged) {
            if (!mUserEngagingSessions.contains(sessionUid)) {
                mUserEngagingSessions.put(sessionUid, new HashSet<>());
                reportUserInteractionEvent(
                    USAGE_STATS_ACTION_START, record.getUserId(), packageName);
            }
            mUserEngagingSessions.get(sessionUid).add(token);
            mUserEngagingSessions.get(sessionUid).add(record);
        } else if (mUserEngagingSessions.contains(sessionUid)) {
            mUserEngagingSessions.get(sessionUid).remove(token);
            mUserEngagingSessions.get(sessionUid).remove(record);
            if (mUserEngagingSessions.get(sessionUid).isEmpty()) {
                reportUserInteractionEvent(
                    USAGE_STATS_ACTION_STOP, record.getUserId(), packageName);