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

Commit fc26b54c authored by Chienyuan Huang's avatar Chienyuan Huang
Browse files

Add APIs to get security level of CS

Bug: 319563845
Bug: 317683528
Test: atest DistanceMeasurementManagerTest
Change-Id: I4423a62133c0a89f35f15f45c46c98529e3e0838
parent 424735e4
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -190,4 +190,10 @@ oneway interface IBluetoothGatt {
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void stopDistanceMeasurement(in ParcelUuid uuid, in BluetoothDevice device, in int method, in AttributionSource attributionSource,
                            in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void getChannelSoundingMaxSupportedSecurityLevel(in BluetoothDevice remoteDevice, in AttributionSource attributionSource,
                            in SynchronousResultReceiver receiver);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT,android.Manifest.permission.BLUETOOTH_PRIVILEGED})")
    void getLocalChannelSoundingMaxSupportedSecurityLevel(in AttributionSource attributionSource,
                            in SynchronousResultReceiver receiver);
}
+9 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.bluetooth.gatt;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothStatusCodes;
import android.bluetooth.BluetoothUtils;
import android.bluetooth.le.ChannelSoundingParams;
import android.bluetooth.le.DistanceMeasurementMethod;
import android.bluetooth.le.DistanceMeasurementParams;
import android.bluetooth.le.DistanceMeasurementResult;
@@ -140,6 +141,14 @@ public class DistanceMeasurementManager {
        }
    }

    int getChannelSoundingMaxSupportedSecurityLevel(BluetoothDevice remoteDevice) {
        return ChannelSoundingParams.CS_SECURITY_LEVEL_ONE;
    }

    int getLocalChannelSoundingMaxSupportedSecurityLevel() {
        return ChannelSoundingParams.CS_SECURITY_LEVEL_ONE;
    }

    private synchronized int stopRssiTracker(UUID uuid, String identityAddress,
            boolean timeout) {
        HashSet<DistanceMeasurementTracker> set = mRssiTrackers.get(identityAddress);
+68 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.bluetooth.IBluetoothGattServerCallback;
import android.bluetooth.le.AdvertiseData;
import android.bluetooth.le.AdvertisingSetParameters;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ChannelSoundingParams;
import android.bluetooth.le.DistanceMeasurementMethod;
import android.bluetooth.le.DistanceMeasurementParams;
import android.bluetooth.le.IAdvertisingSetCallback;
@@ -1857,6 +1858,64 @@ public class GattService extends ProfileService {
            enforceBluetoothPrivilegedPermission(service);
            return service.stopDistanceMeasurement(uuid.getUuid(), device, method);
        }

        @Override
        public void getChannelSoundingMaxSupportedSecurityLevel(
                BluetoothDevice remoteDevice,
                AttributionSource attributionSource,
                SynchronousResultReceiver receiver) {
            try {
                receiver.send(
                        getChannelSoundingMaxSupportedSecurityLevel(
                                remoteDevice, attributionSource));
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        private int getChannelSoundingMaxSupportedSecurityLevel(
                BluetoothDevice remoteDevice, AttributionSource attributionSource) {
            GattService service = getService();
            if (service == null
                    || !callerIsSystemOrActiveOrManagedUser(
                            service, TAG, "GattService getChannelSoundingMaxSupportedSecurityLevel")
                    || !Utils.checkConnectPermissionForDataDelivery(
                            service,
                            attributionSource,
                            "GattService getChannelSoundingMaxSupportedSecurityLevel")) {
                return ChannelSoundingParams.CS_SECURITY_LEVEL_UNKNOWN;
            }
            enforceBluetoothPrivilegedPermission(service);
            return service.getChannelSoundingMaxSupportedSecurityLevel(remoteDevice);
        }

        @Override
        public void getLocalChannelSoundingMaxSupportedSecurityLevel(
                AttributionSource attributionSource, SynchronousResultReceiver receiver) {
            try {
                receiver.send(getLocalChannelSoundingMaxSupportedSecurityLevel(attributionSource));
            } catch (RuntimeException e) {
                receiver.propagateException(e);
            }
        }

        private int getLocalChannelSoundingMaxSupportedSecurityLevel(
                AttributionSource attributionSource) {
            GattService service = getService();
            if (service == null
                    || !callerIsSystemOrActiveOrManagedUser(
                            service,
                            TAG,
                            "GattService getLocalChannelSoundingMaxSupportedSecurityLevel")
                    || !Utils.checkConnectPermissionForDataDelivery(
                            service,
                            attributionSource,
                            "GattService getLocalChannelSoundingMaxSupportedSecurityLevel")) {
                return ChannelSoundingParams.CS_SECURITY_LEVEL_UNKNOWN;
            }
            enforceBluetoothPrivilegedPermission(service);
            return service.getLocalChannelSoundingMaxSupportedSecurityLevel();
        }
    };

    /**************************************************************************
@@ -3599,6 +3658,15 @@ public class GattService extends ProfileService {
        return mDistanceMeasurementManager.stopDistanceMeasurement(uuid, device, method, false);
    }

    int getChannelSoundingMaxSupportedSecurityLevel(BluetoothDevice remoteDevice) {
        return mDistanceMeasurementManager.getChannelSoundingMaxSupportedSecurityLevel(
                remoteDevice);
    }

    int getLocalChannelSoundingMaxSupportedSecurityLevel() {
        return mDistanceMeasurementManager.getLocalChannelSoundingMaxSupportedSecurityLevel();
    }

    /**************************************************************************
     * GATT Service functions - CLIENT
     *************************************************************************/
+3 −0
Original line number Diff line number Diff line
@@ -1238,6 +1238,7 @@ package android.bluetooth.le {
    field public static final int CS_SECURITY_LEVEL_ONE = 1; // 0x1
    field public static final int CS_SECURITY_LEVEL_THREE = 3; // 0x3
    field public static final int CS_SECURITY_LEVEL_TWO = 2; // 0x2
    field public static final int CS_SECURITY_LEVEL_UNKNOWN = 0; // 0x0
    field public static final int LOCATION_TYPE_INDOOR = 1; // 0x1
    field public static final int LOCATION_TYPE_OUTDOOR = 2; // 0x2
    field public static final int LOCATION_TYPE_UNKNOWN = 0; // 0x0
@@ -1255,6 +1256,8 @@ package android.bluetooth.le {
  }

  public final class DistanceMeasurementManager {
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getChannelSoundingMaxSupportedSecurityLevel(@NonNull android.bluetooth.BluetoothDevice);
    method @FlaggedApi("com.android.bluetooth.flags.channel_sounding") @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int getLocalChannelSoundingMaxSupportedSecurityLevel();
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public java.util.List<android.bluetooth.le.DistanceMeasurementMethod> getSupportedMethods();
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public android.os.CancellationSignal startMeasurementSession(@NonNull android.bluetooth.le.DistanceMeasurementParams, @NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.le.DistanceMeasurementSession.Callback);
  }
+11 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ public final class ChannelSoundingParams implements Parcelable {
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(
            value = {
                CS_SECURITY_LEVEL_UNKNOWN,
                CS_SECURITY_LEVEL_ONE,
                CS_SECURITY_LEVEL_TWO,
                CS_SECURITY_LEVEL_THREE,
@@ -105,6 +106,16 @@ public final class ChannelSoundingParams implements Parcelable {
     */
    @SystemApi public static final int LOCATION_TYPE_OUTDOOR = 2;

    /**
     * Return value for {@link
     * DistanceMeasurementManager#getChannelSoundingMaxSupportedSecurityLevel(BluetoothDevice)} and
     * {@link DistanceMeasurementManager#getLocalChannelSoundingMaxSupportedSecurityLevel()} when
     * Channel Sounding is not supported, or encounters an internal error.
     *
     * @hide
     */
    @SystemApi public static final int CS_SECURITY_LEVEL_UNKNOWN = 0;

    /**
     * Either CS tone or CS RTT.
     *
Loading