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

Commit 3cf415c6 authored by The Android Open Source Project's avatar The Android Open Source Project Committed by Xin Li
Browse files

Merge ab/7633965

Bug: 169893837
Merged-In: I3ef19b77bc33546a3e80bca75532d017b4712054
Change-Id: I595fb801f4519177825f3fdc0021fb874a36aa31
parents fe3d6da4 5666c0d4
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -1025,6 +1025,10 @@ public final class BluetoothA2dp implements BluetoothProfile {
    public boolean setBufferLengthMillis(@BluetoothCodecConfig.SourceCodecType int codec,
            int value) {
        if (VDBG) log("setBufferLengthMillis(" + codec + ", " + value + ")");
        if (value < 0) {
            Log.e(TAG, "Trying to set audio buffer length to a negative value: " + value);
            return false;
        }
        try {
            final IBluetoothA2dp service = getService();
            if (service != null && isEnabled()) {
+12 −10
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
 */
public final class BluetoothAdapter {
    private static final String TAG = "BluetoothAdapter";
    private static final String DESCRIPTOR = "android.bluetooth.BluetoothAdapter";
    private static final boolean DBG = true;
    private static final boolean VDBG = false;

@@ -805,7 +806,7 @@ public final class BluetoothAdapter {
        mManagerService = Objects.requireNonNull(managerService);
        mAttributionSource = Objects.requireNonNull(attributionSource);
        mLeScanClients = new HashMap<LeScanCallback, ScanCallback>();
        mToken = new Binder();
        mToken = new Binder(DESCRIPTOR);
    }

    /**
@@ -1799,9 +1800,10 @@ public final class BluetoothAdapter {
     * <i>discoverable</i> (inquiry scan enabled). Many Bluetooth devices are
     * not discoverable by default, and need to be entered into a special mode.
     * <p>If Bluetooth state is not {@link #STATE_ON}, this API
     * will return false. After turning on Bluetooth,
     * wait for {@link #ACTION_STATE_CHANGED} with {@link #STATE_ON}
     * to get the updated value.
     * will return false. After turning on Bluetooth, wait for {@link #ACTION_STATE_CHANGED}
     * with {@link #STATE_ON} to get the updated value.
     * <p>If a device is currently bonding, this request will be queued and executed once that
     * device has finished bonding. If a request is already queued, this request will be ignored.
     *
     * @return true on success, false on error
     */
@@ -3516,22 +3518,22 @@ public final class BluetoothAdapter {
    }

    /**
     * Determines whether a String Bluetooth address, such as "00:43:A8:23:10:F0"
     * Determines whether a String Bluetooth address, such as "F0:43:A8:23:10:00"
     * is a RANDOM STATIC address.
     *
     * RANDOM STATIC: (addr & 0b11) == 0b11
     * RANDOM RESOLVABLE: (addr & 0b11) == 0b10
     * RANDOM non-RESOLVABLE: (addr & 0b11) == 0b00
     * RANDOM STATIC: (addr & 0xC0) == 0xC0
     * RANDOM RESOLVABLE: (addr &  0xC0) == 0x40
     * RANDOM non-RESOLVABLE: (addr &  0xC0) == 0x00
     *
     * @param address Bluetooth address as string
     * @return true if the 2 Least Significant Bits of the address equals 0b11.
     * @return true if the 2 Most Significant Bits of the address equals 0xC0.
     *
     * @hide
     */
    public static boolean isAddressRandomStatic(@NonNull String address) {
        requireNonNull(address);
        return checkBluetoothAddress(address)
                && (Integer.parseInt(address.split(":")[5], 16) & 0b11) == 0b11;
                && (Integer.parseInt(address.split(":")[0], 16) & 0xC0) == 0xC0;
    }

    /** {@hide} */
+2 −1
Original line number Diff line number Diff line
@@ -1775,7 +1775,8 @@ public final class BluetoothDevice implements Parcelable, Attributable {
     * in getting the SDP records or if the process takes a long time, or the device is bonding and
     * we have its UUIDs cached, {@link #ACTION_UUID} intent is sent with the UUIDs that is
     * currently present in the cache. Clients should use the {@link #getUuids} to get UUIDs
     * if service discovery is not to be performed.
     * if service discovery is not to be performed. If there is an ongoing bonding process,
     * service discovery or device inquiry, the request will be queued.
     *
     * @return False if the check fails, True if the process of initiating an ACL connection
     * to the remote device was started or cached UUIDs will be broadcast.
+23 −1
Original line number Diff line number Diff line
@@ -168,6 +168,15 @@ public final class ScanFilter implements Parcelable {
                dest.writeByteArray(mManufacturerDataMask);
            }
        }

        // IRK
        if (mDeviceAddress != null) {
            dest.writeInt(mAddressType);
            dest.writeInt(mIrk == null ? 0 : 1);
            if (mIrk != null) {
                dest.writeByteArray(mIrk);
            }
        }
    }

    /**
@@ -187,8 +196,10 @@ public final class ScanFilter implements Parcelable {
            if (in.readInt() == 1) {
                builder.setDeviceName(in.readString());
            }
            String address = null;
            // If we have a non-null address
            if (in.readInt() == 1) {
                builder.setDeviceAddress(in.readString());
                address = in.readString();
            }
            if (in.readInt() == 1) {
                ParcelUuid uuid = in.readParcelable(ParcelUuid.class.getClassLoader());
@@ -245,6 +256,17 @@ public final class ScanFilter implements Parcelable {
                }
            }

            // IRK
            if (address != null) {
                final int addressType = in.readInt();
                if (in.readInt() == 1) {
                    final byte[] irk = new byte[16];
                    in.readByteArray(irk);
                    builder.setDeviceAddress(address, addressType, irk);
                } else {
                    builder.setDeviceAddress(address, addressType);
                }
            }
            return builder.build();
        }
    };
+24 −2
Original line number Diff line number Diff line
@@ -2505,6 +2505,16 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
        mContext.sendBroadcastAsUser(intent, UserHandle.ALL, null, getTempAllowlistBroadcastOptions());
    }

    private boolean isBleState(int state) {
        switch (state) {
            case BluetoothAdapter.STATE_BLE_ON:
            case BluetoothAdapter.STATE_BLE_TURNING_ON:
            case BluetoothAdapter.STATE_BLE_TURNING_OFF:
                return true;
        }
        return false;
    }

    @RequiresPermission(allOf = {
            android.Manifest.permission.BLUETOOTH_CONNECT,
            android.Manifest.permission.BLUETOOTH_PRIVILEGED,
@@ -2527,8 +2537,15 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                sendBluetoothServiceDownCallback();
                unbindAndFinish();
                sendBleStateChanged(prevState, newState);
                // Don't broadcast as it has already been broadcast before
                isStandardBroadcast = false;

                /* Currently, the OFF intent is broadcasted externally only when we transition
                 * from TURNING_OFF to BLE_ON state. So if the previous state is a BLE state,
                 * we are guaranteed that the OFF intent has been broadcasted earlier and we
                 * can safely skip it.
                 * Conversely, if the previous state is not a BLE state, it indicates that some
                 * sort of crash has occurred, moving us directly to STATE_OFF without ever
                 * passing through BLE_ON. We should broadcast the OFF intent in this case. */
                isStandardBroadcast = !isBleState(prevState);

            } else if (!intermediate_off) {
                // connect to GattService
@@ -2581,6 +2598,11 @@ class BluetoothManagerService extends IBluetoothManager.Stub {
                // Show prevState of BLE_ON as OFF to standard users
                prevState = BluetoothAdapter.STATE_OFF;
            }
            if (DBG) {
                Slog.d(TAG,
                        "Sending State Change: " + BluetoothAdapter.nameForState(prevState) + " > "
                                + BluetoothAdapter.nameForState(newState));
            }
            Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
            intent.putExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, prevState);
            intent.putExtra(BluetoothAdapter.EXTRA_STATE, newState);