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

Commit 0ebfb20d authored by Etienne Ruffieux's avatar Etienne Ruffieux
Browse files

Adding new System API to set BT HCI snoop logging mode.

Bug: 217292806
Tag: #feature
Test: atest CtsBluetoothTestCases
Change-Id: Ie1f4fa534275845b14b5b5d8204ece67e2294d91
parent 300ebb7d
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ package android.bluetooth {
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_CONNECT) public boolean enableNoAutoConnect();
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void generateLocalOobData(int, @NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OobDataCallback);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public java.util.List<android.bluetooth.BluetoothDevice> getActiveDevices(int);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public int getBluetoothHciSnoopLoggingMode();
    method public int getConnectionState();
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public long getDiscoveryEndMillis();
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public java.util.List<android.bluetooth.BluetoothDevice> getMostRecentlyConnectedDevices();
@@ -72,6 +73,7 @@ package android.bluetooth {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public void requestControllerActivityEnergyInfo(@NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.OnBluetoothActivityEnergyInfoCallback);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public android.bluetooth.BluetoothSocket retrieveConnectedRfcommSocket(@NonNull java.util.UUID);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean setActiveDevice(@NonNull android.bluetooth.BluetoothDevice, int);
    method @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public int setBluetoothHciSnoopLoggingMode(int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_SCAN, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int setDiscoverableTimeout(@NonNull java.time.Duration);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_SCAN, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int setScanMode(int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int startRfcommServer(@NonNull String, @NonNull java.util.UUID, @NonNull android.app.PendingIntent);
@@ -83,6 +85,9 @@ package android.bluetooth {
    field public static final int ACTIVE_DEVICE_ALL = 2; // 0x2
    field public static final int ACTIVE_DEVICE_AUDIO = 0; // 0x0
    field public static final int ACTIVE_DEVICE_PHONE_CALL = 1; // 0x1
    field public static final int BT_SNOOP_LOG_MODE_DISABLED = 0; // 0x0
    field public static final int BT_SNOOP_LOG_MODE_FILTERED = 1; // 0x1
    field public static final int BT_SNOOP_LOG_MODE_FULL = 2; // 0x2
    field public static final String EXTRA_RFCOMM_LISTENER_ID = "android.bluetooth.adapter.extra.RFCOMM_LISTENER_ID";
    field public static final int STATE_BLE_ON = 15; // 0xf
  }
+95 −0
Original line number Diff line number Diff line
@@ -479,6 +479,56 @@ public final class BluetoothAdapter {
     */
    public static final int SCAN_MODE_CONNECTABLE_DISCOVERABLE = 23;


    /**
     * Used as parameter for {@link #setBluetoothHciSnoopLoggingMode}, indicates that
     * the Bluetooth HCI snoop logging should be disabled.
     *
     * @hide
     */
    @SystemApi
    public static final int BT_SNOOP_LOG_MODE_DISABLED = 0;

    /**
     * Used as parameter for {@link #setBluetoothHciSnoopLoggingMode}, indicates that
     * the Bluetooth HCI snoop logging should be enabled without collecting potential
     * Personally Identifiable Information and packet data.
     *
     * See {@link #BT_SNOOP_LOG_MODE_FULL} to enable logging of all information available.
     *
     * @hide
     */
    @SystemApi
    public static final int BT_SNOOP_LOG_MODE_FILTERED = 1;

    /**
     * Used as parameter for {@link #setSnoopLogMode}, indicates that the Bluetooth HCI snoop
     * logging should be enabled.
     *
     * See {@link #BT_SNOOP_LOG_MODE_FILTERED} to enable logging with filtered information.
     *
     * @hide
     */
    @SystemApi
    public static final int BT_SNOOP_LOG_MODE_FULL = 2;

    /** @hide */
    @IntDef(value = {
            BT_SNOOP_LOG_MODE_DISABLED,
            BT_SNOOP_LOG_MODE_FILTERED,
            BT_SNOOP_LOG_MODE_FULL
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface BluetoothSnoopLogMode {}

    /** @hide */
    @IntDef(value = {
            BluetoothStatusCodes.SUCCESS,
            BluetoothStatusCodes.ERROR_UNKNOWN,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface SetSnoopLogModeStatusCode {}

    /**
     * Device only has a display.
     *
@@ -5049,4 +5099,49 @@ public final class BluetoothAdapter {
        }
        return BluetoothProfile.PRIORITY_UNDEFINED;
    }

    /**
     * Sets the desired mode of the HCI snoop logging applied at Bluetooth startup.
     *
     * Please note that Bluetooth needs to be restarted in order for the change
     * to take effect.
     *
     * @param mode
     * @return status code indicating whether the logging mode was successfully set
     * @throws IllegalArgumentException if the mode is not a valid logging mode
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    @SetSnoopLogModeStatusCode
    public int setBluetoothHciSnoopLoggingMode(@BluetoothSnoopLogMode int mode) {
        if (mode != BT_SNOOP_LOG_MODE_DISABLED && mode != BT_SNOOP_LOG_MODE_FILTERED
                && mode != BT_SNOOP_LOG_MODE_FULL) {
            throw new IllegalArgumentException("Invalid Bluetooth HCI snoop log mode param value");
        }
        try {
            return mManagerService.setBtHciSnoopLogMode(mode);
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
        return BluetoothStatusCodes.ERROR_UNKNOWN;
    }

    /**
     * Gets the current desired mode of HCI snoop logging applied at Bluetooth startup.
     *
     * @return the current HCI snoop logging mode applied at Bluetooth startup
     * @hide
     */
    @SystemApi
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    @BluetoothSnoopLogMode
    public int getBluetoothHciSnoopLoggingMode() {
        try {
            return mManagerService.getBtHciSnoopLogMode();
        } catch (RemoteException e) {
            Log.e(TAG, "", e);
        }
        return BT_SNOOP_LOG_MODE_DISABLED;
    }
}
+48 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.bluetooth.BluetoothHearingAid;
import android.bluetooth.BluetoothLeAudio;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.BluetoothStatusCodes;
import android.bluetooth.IBluetooth;
import android.bluetooth.IBluetoothCallback;
import android.bluetooth.IBluetoothGatt;
@@ -3350,4 +3351,51 @@ public class BluetoothManagerService extends IBluetoothManager.Stub {
            Binder.restoreCallingIdentity(ident);
        }
    }

    /**
     * Sets Bluetooth HCI snoop log mode
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    @Override
    public int setBtHciSnoopLogMode(int mode) {
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        switch (mode) {
            case BluetoothAdapter.BT_SNOOP_LOG_MODE_DISABLED:
                BluetoothProperties.snoop_log_mode(
                        BluetoothProperties.snoop_log_mode_values.DISABLED);
                break;
            case BluetoothAdapter.BT_SNOOP_LOG_MODE_FILTERED:
                BluetoothProperties.snoop_log_mode(
                        BluetoothProperties.snoop_log_mode_values.FILTERED);
                break;
            case BluetoothAdapter.BT_SNOOP_LOG_MODE_FULL:
                BluetoothProperties.snoop_log_mode(
                        BluetoothProperties.snoop_log_mode_values.FULL);
                break;
            default:
                BluetoothProperties.snoop_log_mode(
                        BluetoothProperties.snoop_log_mode_values.EMPTY);
                return BluetoothStatusCodes.ERROR_UNKNOWN;
        }
        return BluetoothStatusCodes.SUCCESS;
    }

    /**
     * Gets Bluetooth HCI snoop log mode
     */
    @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)
    @Override
    public int getBtHciSnoopLogMode() {
        mContext.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED,
                "Need BLUETOOTH_PRIVILEGED permission");
        BluetoothProperties.snoop_log_mode_values mode = BluetoothProperties.snoop_log_mode()
                .orElse(BluetoothProperties.snoop_log_mode_values.DISABLED);
        if (mode == BluetoothProperties.snoop_log_mode_values.FILTERED) {
            return BluetoothAdapter.BT_SNOOP_LOG_MODE_FILTERED;
        } else if (mode == BluetoothProperties.snoop_log_mode_values.FULL) {
            return BluetoothAdapter.BT_SNOOP_LOG_MODE_FULL;
        }
        return BluetoothAdapter.BT_SNOOP_LOG_MODE_DISABLED;
    }
}
+5 −0
Original line number Diff line number Diff line
@@ -70,4 +70,9 @@ interface IBluetoothManager
    boolean isBleAppPresent();
    @JavaPassthrough(annotation="@android.annotation.RequiresNoPermission")
    boolean isHearingAidProfileSupported();

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    int setBtHciSnoopLogMode(int mode);
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    int getBtHciSnoopLogMode();
}