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

Commit 10f2429e authored by David Duarte's avatar David Duarte Committed by Gerrit Code Review
Browse files

Merge "BluetoothAdapter: Move permission check in getProfileProxy" into main

parents 9983f693 5c32dbcf
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ import android.bluetooth.le.ScanSettings;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.AttributionSource;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Binder;
import android.os.BluetoothServiceManager;
import android.os.Build;
@@ -3685,11 +3686,20 @@ public final class BluetoothAdapter {
            return false;
        }

        // Preserve legacy compatibility where apps were depending on
        // registerStateChangeCallback() performing a permissions check which
        // has been relaxed in modern platform versions
        if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.R
                && context.checkSelfPermission(android.Manifest.permission.BLUETOOTH)
                        != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Need BLUETOOTH permission");
        }

        BluetoothProfile profileProxy = constructor.apply(context, this);

        BluetoothProfileConnector connector = new BluetoothProfileConnector(profileProxy, profile);
        mProfileConnectors.put(profileProxy, connector);
        connector.connect(context, listener);
        connector.connect(context.getPackageName(), listener);

        return true;
    }
+0 −16
Original line number Diff line number Diff line
@@ -18,9 +18,6 @@ package android.bluetooth;

import android.annotation.SuppressLint;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
@@ -165,19 +162,6 @@ public final class BluetoothProfileConnector extends Handler {
        }
    }

    void connect(Context context, BluetoothProfile.ServiceListener listener) {
        // Preserve legacy compatibility where apps were depending on
        // registerStateChangeCallback() performing a permissions check which
        // has been relaxed in modern platform versions
        if (context.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.R
                && context.checkSelfPermission(android.Manifest.permission.BLUETOOTH)
                        != PackageManager.PERMISSION_GRANTED) {
            throw new SecurityException("Need BLUETOOTH permission");
        }

        connect(context.getPackageName(), listener);
    }

    /** @hide */
    public void connect(String packageName, BluetoothProfile.ServiceListener listener) {
        mPackageName = packageName;