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

Commit 3f7cbce0 authored by William Escande's avatar William Escande
Browse files

Framework cleanup to prepare API change on permission

In order to smoothly merge aosp/3185962, this change is cleaning up some
annotation / code / various miscellaneous small fixes that helps
having a smaller "api change" CL.

Bug: 349682934
Test: m com.android.btservices
Flag: Exempt refactor
Change-Id: I624309d41db7c8af1a78409b3ebdf9e8cc68e284
parent f09387b5
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -29,11 +29,11 @@ interface IBluetoothPbapClient {
    boolean connect(in BluetoothDevice device, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    boolean disconnect(in BluetoothDevice device, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    List<BluetoothDevice> getConnectedDevices(in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    List<BluetoothDevice> getDevicesMatchingConnectionStates(in int[] states, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT)")
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    int getConnectionState(in BluetoothDevice device, in AttributionSource attributionSource);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    boolean setConnectionPolicy(in BluetoothDevice device, int connectionPolicy, in AttributionSource attributionSource);
+2 −0
Original line number Diff line number Diff line
@@ -248,6 +248,7 @@ public class BluetoothMethodProxy {
    }

    /** Proxies {@link PeriodicAdvertisingManager#transferSync}. */
    @SuppressLint("AndroidFrameworkRequiresPermission") // TODO: b/350563786
    public void periodicAdvertisingManagerTransferSync(
            PeriodicAdvertisingManager manager,
            BluetoothDevice bda,
@@ -257,6 +258,7 @@ public class BluetoothMethodProxy {
    }

    /** Proxies {@link PeriodicAdvertisingManager#transferSetInfo}. */
    @SuppressLint("AndroidFrameworkRequiresPermission") // TODO: b/350563786
    public void periodicAdvertisingManagerTransferSetInfo(
            PeriodicAdvertisingManager manager,
            BluetoothDevice bda,
+1 −1
Original line number Diff line number Diff line
@@ -3739,7 +3739,7 @@ public class AdapterService extends Service {

            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);

            return service.mDatabaseManager.getCustomMeta(device, key);
            return service.getMetadata(device, key);
        }

        @Override
+17 −14
Original line number Diff line number Diff line
@@ -1253,21 +1253,7 @@ public class BluetoothMapService extends ProfileService {
    static class BluetoothMapBinder extends IBluetoothMap.Stub implements IProfileServiceBinder {
        private BluetoothMapService mService;

        @RequiresPermission(BLUETOOTH_CONNECT)
        private BluetoothMapService getService(AttributionSource source) {
            if (Utils.isInstrumentationTestMode()) {
                return mService;
            }
            if (!Utils.checkServiceAvailable(mService, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
                return null;
            }
            return mService;
        }

        BluetoothMapBinder(BluetoothMapService service) {
            Log.v(TAG, "BluetoothMapBinder()");
            mService = service;
        }

@@ -1276,6 +1262,23 @@ public class BluetoothMapService extends ProfileService {
            mService = null;
        }

        @RequiresPermission(BLUETOOTH_CONNECT)
        private BluetoothMapService getService(AttributionSource source) {
            // Cache mService because it can change while getService is called
            BluetoothMapService service = mService;

            if (Utils.isInstrumentationTestMode()) {
                return service;
            }

            if (!Utils.checkServiceAvailable(service, TAG)
                    || !Utils.checkCallerIsSystemOrActiveOrManagedUser(service, TAG)
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                return null;
            }
            return service;
        }

        @Override
        public int getState(AttributionSource source) {
            Log.v(TAG, "getState()");
+14 −10
Original line number Diff line number Diff line
@@ -429,23 +429,27 @@ public class MapClientService extends ProfileService {
            mService = service;
        }

        @Override
        public void cleanup() {
            mService = null;
        }

        @RequiresPermission(BLUETOOTH_CONNECT)
        private MapClientService getService(AttributionSource source) {
            // Cache mService because it can change while getService is called
            MapClientService service = mService;

            if (Utils.isInstrumentationTestMode()) {
                return mService;
                return service;
            }
            if (!Utils.checkServiceAvailable(mService, TAG)

            if (!Utils.checkServiceAvailable(service, TAG)
                    || !(getCallingUserHandle().isSystem()
                            || Utils.checkCallerIsSystemOrActiveOrManagedUser(mService, TAG))
                    || !Utils.checkConnectPermissionForDataDelivery(mService, source, TAG)) {
                            || Utils.checkCallerIsSystemOrActiveOrManagedUser(service, TAG))
                    || !Utils.checkConnectPermissionForDataDelivery(service, source, TAG)) {
                return null;
            }
            return mService;
        }

        @Override
        public void cleanup() {
            mService = null;
            return service;
        }

        @Override
Loading