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

Commit e3f7af39 authored by Santiago Seifert's avatar Santiago Seifert
Browse files

Stop preventing scans when the screen is off

- Companion apps need to be able to scan even when the screen is off.
- The uid importance should be sufficient to enforce that (non-companion)
  apps don't scan when they are not in the foreground (or the screen is
  off).

Bug: 304234628
Test: atest MediaRouter2HostSideTest CtsMediaBetterTogetherTestCases
Change-Id: Ie1ddc6b4ca9c0fc313cb2ee209603d3338e67f6a
parent a1bfd75d
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -20,3 +20,10 @@ flag {
     description: "Use Audio Policies implementation for device and Bluetooth route controllers."
     bug: "280576228"
}

flag {
    namespace: "media_solutions"
     name: "disable_screen_off_broadcast_receiver"
     description: "Disables the broadcast receiver that prevents scanning when the screen is off."
     bug: "304234628"
}
+9 −5
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ import android.util.SparseArray;

import com.android.internal.annotations.GuardedBy;
import com.android.internal.util.function.pooled.PooledLambda;
import com.android.media.flags.Flags;
import com.android.server.LocalServices;
import com.android.server.pm.UserManagerInternal;

@@ -161,11 +162,13 @@ class MediaRouter2ServiceImpl {
        mPowerManager = mContext.getSystemService(PowerManager.class);
        mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);

        if (!Flags.disableScreenOffBroadcastReceiver()) {
            IntentFilter screenOnOffIntentFilter = new IntentFilter();
            screenOnOffIntentFilter.addAction(ACTION_SCREEN_ON);
            screenOnOffIntentFilter.addAction(ACTION_SCREEN_OFF);

            mContext.registerReceiver(mScreenOnOffReceiver, screenOnOffIntentFilter);
        }

        mContext.getPackageManager().addOnPermissionsChangeListener(this::onPermissionsChanged);

        MediaFeatureFlagManager.getInstance()
@@ -2778,7 +2781,8 @@ class MediaRouter2ServiceImpl {
            List<ManagerRecord> managerRecords = getManagerRecords();

            boolean isManagerScanning = false;
            if (service.mPowerManager.isInteractive()) {
            if (Flags.disableScreenOffBroadcastReceiver()
                    || service.mPowerManager.isInteractive()) {
                isManagerScanning = managerRecords.stream().anyMatch(manager ->
                        manager.mIsScanning && service.mActivityManager
                                .getPackageImportance(manager.mOwnerPackageName)