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

Commit 738a915a authored by Antony Sargent's avatar Antony Sargent
Browse files

Respect the RESTRICT_LOCAL_NETWORK app compat flag

If the permissions required on a route include a new permission being
added for local network access, we only require the permission to be
held if the corresponding app compat flag is turned on, and we also
accept the existing NEARBY_WIFI_DEVICES permission as meeting the
requirement since it will be in the same permission group.

Bug: 386260596
Test: atest MediaRouter2HostSideTest
Flag: com.android.media.flags.enable_route_visibility_control_compat_fixes
Change-Id: I3a9bc3d1943b4c7e902e9b276e8a9c13bc1831a8
parent 27743398
Loading
Loading
Loading
Loading
+29 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import android.annotation.Nullable;
import android.annotation.RequiresPermission;
import android.app.ActivityManager;
import android.app.AppOpsManager;
import android.app.compat.CompatChanges;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
@@ -2773,7 +2774,8 @@ class MediaRouter2ServiceImpl {
                boolean hasAllInSet = true;
                for (String permission : permissionSet) {
                    if (mContext.checkPermission(permission, mPid, mUid)
                            != PackageManager.PERMISSION_GRANTED) {
                            != PackageManager.PERMISSION_GRANTED
                            && !permissionAllowedForAppCompat(permission)) {
                        hasAllInSet = false;
                        break;
                    }
@@ -2800,6 +2802,32 @@ class MediaRouter2ServiceImpl {
                    "Router %s (id=%d,pid=%d,userId=%d,uid=%d)",
                    mPackageName, mRouterId, mPid, mUserRecord.mUserId, mUid);
        }

        /**
         * Returns whether the given permission should be considered to be satisfied because of the
         * app compatibility setting for local networking restrictions.
         *
         * TODO(b/386260596): This is a temporary workaround, which we hope to remove in the next
         * release.
         */
        private boolean permissionAllowedForAppCompat(String permission) {
            if (!Flags.enableRouteVisibilityControlCompatFixes()) {
                return false;
            }
            // TODO(b/386260596) - replace this string with a Manifest.permission constant once
            // one is available.
            if (TextUtils.equals(permission, "android.permission.ACCESS_LOCAL_NETWORK")) {
                // TODO(b/386260596) - this id is defined as RESTRICT_LOCAL_NETWORK in the
                //  connectivity module's ConnectivityCompatChanges.java - see if we can move it to
                //  a shared location so we can avoid duplicating it here.
                if (!CompatChanges.isChangeEnabled(365139289L, mUid)) {
                    return true;
                }
                return mContext.checkPermission(Manifest.permission.NEARBY_WIFI_DEVICES, mPid, mUid)
                        == PackageManager.PERMISSION_GRANTED;
            }
            return false;
        }
    }

    final class ManagerRecord implements IBinder.DeathRecipient {