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

Commit dfc99e59 authored by Bishoy Gendy's avatar Bishoy Gendy
Browse files

Ignore setForegroundAllowance calls in case of MediaSession2

- For an app to fullfill FGS requirements, it needs to have a
user-engaged media session that is linked to a media style notification.

- Currently notifications can't be linked to a MediaSession2, so we
don't report the changes in user engagement in cases of MediaSession2.

Bug: 295518668
Test: Non functional change for non MediaSession2 cases.
Change-Id: Iae81139a20b39e9f59dfacc43512a00c7abd8f05
parent e2484b21
Loading
Loading
Loading
Loading
+4 −21
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ public class MediaSession2Record extends MediaSessionRecordImpl {
    private boolean mIsClosed;

    private final int mPid;
    private final ForegroundServiceDelegationOptions mForegroundServiceDelegationOptions;

    public MediaSession2Record(
            Session2Token sessionToken,
@@ -76,25 +75,6 @@ public class MediaSession2Record extends MediaSessionRecordImpl {
                    .build();
            mPid = pid;
            mPolicies = policies;
            mForegroundServiceDelegationOptions =
                    new ForegroundServiceDelegationOptions.Builder()
                            .setClientPid(mPid)
                            .setClientUid(getUid())
                            .setClientPackageName(getPackageName())
                            .setClientAppThread(null)
                            .setSticky(false)
                            .setClientInstanceName(
                                    "MediaSessionFgsDelegate_"
                                            + getUid()
                                            + "_"
                                            + mPid
                                            + "_"
                                            + getPackageName())
                            .setForegroundServiceTypes(0)
                            .setDelegationService(
                                    ForegroundServiceDelegationOptions
                                            .DELEGATION_SERVICE_MEDIA_PLAYBACK)
                            .build();
        }
    }

@@ -119,7 +99,10 @@ public class MediaSession2Record extends MediaSessionRecordImpl {

    @Override
    public ForegroundServiceDelegationOptions getForegroundServiceDelegationOptions() {
        return mForegroundServiceDelegationOptions;
        // For an app to be eligible for FGS delegation, it needs a media session liked to a media
        // notification. Currently, notifications cannot be linked to MediaSession2 so it is not
        // supported.
        return null;
    }

    @Override
+1 −3
Original line number Diff line number Diff line
@@ -610,9 +610,7 @@ public class MediaSessionService extends SystemService implements Monitor {
        }
        ForegroundServiceDelegationOptions foregroundServiceDelegationOptions =
                record.getForegroundServiceDelegationOptions();
        if (foregroundServiceDelegationOptions == null
                || foregroundServiceDelegationOptions.mClientPid == Process.INVALID_PID) {
            // This record doesn't support FGS delegation. In practice, this is MediaSession2.
        if (foregroundServiceDelegationOptions == null) {
            return;
        }
        if (allowRunningInForeground) {