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

Commit 30ab48c3 authored by Bishoy Gendy's avatar Bishoy Gendy
Browse files

Decouple Fgs logic from UsageStats reporting logic

- The logic for Fgs will be different (For the PAUSED state) there
will be a time window before calling stopFgs.

- UsageStats reporting has its feature flag, so it shouldn't be hidden
by Fgs flag.

- Fgs will not support MediaSesson2 because it is not linkable to
notifciations, this doesn't apply to UsageStats reporting.

Bug: 295518668
Bug: 297052684
Test: Non functional change
Change-Id: If06fc75a7f83e49759264aa30cda3c7834bbf1b6
parent 8ba3cbca
Loading
Loading
Loading
Loading
+11 −9
Original line number Diff line number Diff line
@@ -312,14 +312,15 @@ public class MediaSessionService extends SystemService implements Monitor {
                }
                user.mPriorityStack.onSessionActiveStateChanged(record);
            }
            boolean allowRunningInForeground = record.isActive()
                    && (playbackState == null || playbackState.isActive());
            boolean isUserEngaged =
                    record.isActive() && (playbackState == null || playbackState.isActive());

            Log.d(TAG, "onSessionActiveStateChanged: "
                    + "record=" + record
                    + "playbackState=" + playbackState
                    + "allowRunningInForeground=" + allowRunningInForeground);
            setForegroundServiceAllowance(record, allowRunningInForeground);
                    + "allowRunningInForeground=" + isUserEngaged);
            setForegroundServiceAllowance(record, /* allowRunningInForeground= */ isUserEngaged);
            reportMediaInteractionEvent(record, isUserEngaged);
            mHandler.postSessionsChanged(record);
        }
    }
@@ -417,12 +418,14 @@ public class MediaSessionService extends SystemService implements Monitor {
            }
            user.mPriorityStack.onPlaybackStateChanged(record, shouldUpdatePriority);
            if (playbackState != null) {
                boolean allowRunningInForeground = playbackState.isActive() && record.isActive();
                boolean isUserEngaged = playbackState.isActive() && record.isActive();
                Log.d(TAG, "onSessionPlaybackStateChanged: "
                        + "record=" + record
                        + "playbackState=" + playbackState
                        + "allowRunningInForeground=" + allowRunningInForeground);
                setForegroundServiceAllowance(record, allowRunningInForeground);
                        + "allowRunningInForeground=" + isUserEngaged);
                setForegroundServiceAllowance(
                        record, /* allowRunningInForeground= */ isUserEngaged);
                reportMediaInteractionEvent(record, isUserEngaged);
            }
        }
    }
@@ -590,6 +593,7 @@ public class MediaSessionService extends SystemService implements Monitor {

        Log.d(TAG, "destroySessionLocked: record=" + session);
        setForegroundServiceAllowance(session, /* allowRunningInForeground= */ false);
        reportMediaInteractionEvent(session, /* userEngaged= */ false);
        mHandler.postSessionsChanged(session);
    }

@@ -608,11 +612,9 @@ public class MediaSessionService extends SystemService implements Monitor {
        if (allowRunningInForeground) {
            mActivityManagerInternal.startForegroundServiceDelegate(
                    foregroundServiceDelegationOptions, /* connection= */ null);
            reportMediaInteractionEvent(record, /* userEngaged= */ true);
        } else {
            mActivityManagerInternal.stopForegroundServiceDelegate(
                    foregroundServiceDelegationOptions);
            reportMediaInteractionEvent(record, /* userEngaged= */ false);
        }
    }