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

Commit aa0a9cb5 authored by Liang Li's avatar Liang Li Committed by Jayden Kim
Browse files

Read RFCOMM socket offload capabilities from bluetooth low power proccesor

Bug: 342012881
Bug: 367419086
Test: atest CtsBluetoothTestCases
Change-Id: I0cdc2efb0d1448ee65a44ac6d41597e14ab23d5a
parent 73d8ba1e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -341,4 +341,7 @@ interface IBluetooth

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    boolean isLeCocSocketOffloadSupported(in AttributionSource source);

    @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED)")
    boolean isRfcommSocketOffloadSupported(in AttributionSource source);
}
+12 −1
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ class AdapterProperties {
    private boolean mIsLeChannelSoundingSupported;

    private int mNumberOfSupportedOffloadedLeCocSockets;
    private int mNumberOfSupportedOffloadedRfcommSockets = 0;

    // Lock for all getters and setters.
    // If finer grained locking is needer, more locks
@@ -1035,18 +1036,28 @@ class AdapterProperties {
        return mNumberOfSupportedOffloadedLeCocSockets;
    }

    /**
     * @return the mNumberOfSupportedOffloadedRfcommSockets
     */
    int getNumberOfSupportedOffloadedRfcommSockets() {
        return mNumberOfSupportedOffloadedRfcommSockets;
    }

    private void updateLppOffloadFeatureSupport(byte[] val) {
        if (val.length < 1) {
            Log.e(TAG, "BT_PROPERTY_LPP_OFFLOAD_FEATURES: invalid value length");
            return;
        }
        // TODO(b/342012881) Read mNumberOfSupportedOffloadedRfcommSockets from host stack
        mNumberOfSupportedOffloadedLeCocSockets = (0xFF & ((int) val[0]));

        Log.d(
                TAG,
                "BT_PROPERTY_LPP_OFFLOAD_FEATURES: update from Offload HAL"
                        + " mNumberOfSupportedOffloadedLeCocSockets = "
                        + mNumberOfSupportedOffloadedLeCocSockets);
                        + mNumberOfSupportedOffloadedLeCocSockets
                        + " mNumberOfSupportedOffloadedRfcommSockets = "
                        + mNumberOfSupportedOffloadedRfcommSockets);
    }

    void onBluetoothReady() {
+21 −0
Original line number Diff line number Diff line
@@ -4397,6 +4397,16 @@ public class AdapterService extends Service {
            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            return service.isLeCocSocketOffloadSupported();
        }

        @Override
        public boolean isRfcommSocketOffloadSupported(AttributionSource source) {
            AdapterService service = getService();
            if (service == null) {
                return false;
            }
            service.enforceCallingOrSelfPermission(BLUETOOTH_PRIVILEGED, null);
            return service.isRfcommSocketOffloadSupported();
        }
    }

    /**
@@ -7177,4 +7187,15 @@ public class AdapterService extends Service {
        int val = getNumberOfSupportedOffloadedLeCocSockets();
        return val > 0;
    }

    /** Get the number of the supported offloaded RFCOMM sockets. */
    public int getNumberOfSupportedOffloadedRfcommSockets() {
        return mAdapterProperties.getNumberOfSupportedOffloadedRfcommSockets();
    }

    /** Check if the offloaded RFCOMM socket is supported. */
    public boolean isRfcommSocketOffloadSupported() {
        int val = getNumberOfSupportedOffloadedRfcommSockets();
        return val > 0;
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -129,6 +129,7 @@ package android.bluetooth {
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int isDistanceMeasurementSupported();
    method @FlaggedApi("com.android.bluetooth.flags.socket_settings_api") @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean isLeCocSocketOffloadSupported();
    method public boolean isLeEnabled();
    method @FlaggedApi("com.android.bluetooth.flags.socket_settings_api") @RequiresPermission(android.Manifest.permission.BLUETOOTH_PRIVILEGED) public boolean isRfcommSocketOffloadSupported();
    method @NonNull public static String nameForState(int);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public int notifyActiveDeviceChangeApplied(@NonNull android.bluetooth.BluetoothDevice);
    method @RequiresPermission(allOf={android.Manifest.permission.BLUETOOTH_CONNECT, android.Manifest.permission.BLUETOOTH_PRIVILEGED}) public boolean registerBluetoothConnectionCallback(@NonNull java.util.concurrent.Executor, @NonNull android.bluetooth.BluetoothAdapter.BluetoothConnectionCallback);
+47 −0
Original line number Diff line number Diff line
@@ -6009,4 +6009,51 @@ public final class BluetoothAdapter {
        }
        return false;
    }

    /**
     * Returns whether RFCOMM socket hardware offload is supported.
     *
     * <p>Bluetooth socket hardware offload allows the system to handle Bluetooth communication on a
     * low-power processor, improving efficiency and reducing power consumption. This is achieved by
     * providing channel information of an already connected {@link BluetoothSocket} to offload
     * endpoints (e.g., offload stacks and applications). The offload stack can then decode received
     * packets and pass them to the appropriate offload application without waking up the main
     * application processor. This API allows offload endpoints to utilize Bluetooth sockets while
     * the host stack retains control over the connection.
     *
     * <p>To configure a socket for hardware offload, use the following {@link
     * BluetoothSocketSettings} methods:
     *
     * <ul>
     *   <li>{@link BluetoothSocketSettings#setDataPath(int)} with {@link
     *       BluetoothSocketSettings#DATA_PATH_HARDWARE_OFFLOAD}
     *   <li>{@link BluetoothSocketSettings#setHubId(long)}
     *   <li>{@link BluetoothSocketSettings#setEndpointId(long)}
     * </ul>
     *
     * <p>This functionality is provided as a System API because only OEM specific system
     * applications can be offloaded as endpoints in the low-power processor.
     *
     * @return {@code true} if RFCOMM socket hardware offload is supported, {@code false} otherwise.
     * @hide
     */
    @SystemApi
    @FlaggedApi(Flags.FLAG_SOCKET_SETTINGS_API)
    @RequiresPermission(BLUETOOTH_PRIVILEGED)
    public boolean isRfcommSocketOffloadSupported() {
        if (!isEnabled()) {
            return false;
        }
        mServiceLock.readLock().lock();
        try {
            if (mService != null) {
                return mService.isRfcommSocketOffloadSupported(mAttributionSource);
            }
        } catch (RemoteException e) {
            Log.e(TAG, e.toString() + "\n" + Log.getStackTraceString(new Throwable()));
        } finally {
            mServiceLock.readLock().unlock();
        }
        return false;
    }
}