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

Commit 18d4da93 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8521661 from 86d72f65 to tm-qpr1-release

Change-Id: I14b81da359056fba9bb7456b3966785f0f6f51aa
parents 923aa95c 86d72f65
Loading
Loading
Loading
Loading
+59 −11
Original line number Diff line number Diff line
@@ -63,9 +63,12 @@ import android.bluetooth.BluetoothGattCallback;
import android.bluetooth.BluetoothGattCharacteristic;
import android.bluetooth.BluetoothGattDescriptor;
import android.bluetooth.BluetoothGattService;
import android.bluetooth.BluetoothLeAudioCodecConfigMetadata;
import android.bluetooth.BluetoothLeAudioContentMetadata;
import android.bluetooth.BluetoothLeBroadcastChannel;
import android.bluetooth.BluetoothLeBroadcastMetadata;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.bluetooth.BluetoothLeBroadcastSubgroup;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothStatusCodes;
import android.bluetooth.le.PeriodicAdvertisingCallback;
@@ -390,6 +393,40 @@ public class BassClientStateMachine extends StateMachine {
        mNoStopScanOffload = false;
    }

    private BluetoothLeBroadcastMetadata getBroadcastMetadataFromBaseData(BaseData baseData,
            BluetoothDevice device) {
        BluetoothLeBroadcastMetadata.Builder metaData =
                new BluetoothLeBroadcastMetadata.Builder();
        int index = 0;
        for (BaseData.BaseInformation baseLevel2 : baseData.getLevelTwo()) {
            BluetoothLeBroadcastSubgroup.Builder subGroup =
                    new BluetoothLeBroadcastSubgroup.Builder();
            for (int j = 0; j < baseLevel2.numSubGroups; j ++) {
                BaseData.BaseInformation baseLevel3 =
                        baseData.getLevelThree().get(index++);
                BluetoothLeBroadcastChannel.Builder channel =
                        new BluetoothLeBroadcastChannel.Builder();
                channel.setChannelIndex(baseLevel3.index);
                channel.setCodecMetadata(BluetoothLeAudioCodecConfigMetadata.
                        fromRawBytes(baseLevel3.codecConfigInfo));
                channel.setSelected(false);
                subGroup.addChannel(channel.build());
            }
            subGroup.setCodecId((long)(baseLevel2.codecId[4] << 32
                    | baseLevel2.codecId[3] << 24
                    | baseLevel2.codecId[2] << 16
                    | baseLevel2.codecId[1] << 8
                    | baseLevel2.codecId[0]));
            subGroup.setCodecSpecificConfig(BluetoothLeAudioCodecConfigMetadata.
                    fromRawBytes(baseLevel2.codecConfigInfo));
            subGroup.setContentMetadata(BluetoothLeAudioContentMetadata.
                    fromRawBytes(baseLevel2.metaData));
            metaData.addSubgroup(subGroup.build());
        }
        metaData.setSourceDevice(device, device.getAddressType());
        return metaData.build();
    }

    /** Internal periodc Advertising manager callback */
    private PeriodicAdvertisingCallback mPeriodicAdvCallback =
            new PeriodicAdvertisingCallback() {
@@ -435,6 +472,13 @@ public class BassClientStateMachine extends StateMachine {
                    // Parse the BIS indices from report's service data
                    if (mFirstTimeBisDiscovery) {
                        parseScanRecord(report.getSyncHandle(), report.getData());
                        BaseData baseData = mService.getBase(report.getSyncHandle());
                        if (baseData != null) {
                            BluetoothLeBroadcastMetadata metaData =
                                    getBroadcastMetadataFromBaseData(baseData,
                                            mService.getDeviceForSyncHandle(report.getSyncHandle()));
                            mService.getCallbacks().notifySourceFound(metaData);
                        }
                        mFirstTimeBisDiscovery = false;
                    }
                }
@@ -524,13 +568,15 @@ public class BassClientStateMachine extends StateMachine {
        }
        log("processBroadcastReceiverState: receiverState length: " + receiverState.length);

        BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
        BluetoothLeBroadcastReceiveState recvState = null;
        if (receiverState.length == 0
                || isEmpty(Arrays.copyOfRange(receiverState, 1, receiverState.length - 1))) {
            String emptyBluetoothDevice = "00:00:00:00:00:00";
            if (mPendingOperation == REMOVE_BCAST_SOURCE) {
                recvState = new BluetoothLeBroadcastReceiveState(mPendingSourceId,
                        BluetoothDevice.ADDRESS_TYPE_UNKNOWN, // sourceAddressType
                        null,   // sourceDevice
                        BluetoothDevice.ADDRESS_TYPE_PUBLIC, // sourceAddressType
                        btAdapter.getRemoteDevice(emptyBluetoothDevice),  // sourceDevice
                        0,  // sourceAdvertisingSid
                        0,  // broadcastId
                        BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_IDLE, // paSyncState
@@ -538,8 +584,8 @@ public class BassClientStateMachine extends StateMachine {
                        BluetoothLeBroadcastReceiveState.BIG_ENCRYPTION_STATE_NOT_ENCRYPTED,
                        null,   // badCode
                        0,  // numSubgroups
                        null,   // bisSyncState
                        null    // subgroupMetadata
                        Arrays.asList(new Long[0]),   // bisSyncState
                        Arrays.asList(new BluetoothLeAudioContentMetadata[0])    // subgroupMetadata
                );
            } else if (receiverState.length == 0) {
                if (mBluetoothLeBroadcastReceiveStates != null) {
@@ -551,8 +597,8 @@ public class BassClientStateMachine extends StateMachine {
                }
                mNextSourceId++;
                recvState = new BluetoothLeBroadcastReceiveState(mNextSourceId,
                        BluetoothDevice.ADDRESS_TYPE_UNKNOWN, // sourceAddressType
                        null,   // sourceDevice
                        BluetoothDevice.ADDRESS_TYPE_PUBLIC, // sourceAddressType
                        btAdapter.getRemoteDevice(emptyBluetoothDevice),   // sourceDevice
                        0,  // sourceAdvertisingSid
                        0,  // broadcastId
                        BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_IDLE, // paSyncState
@@ -560,8 +606,8 @@ public class BassClientStateMachine extends StateMachine {
                        BluetoothLeBroadcastReceiveState.BIG_ENCRYPTION_STATE_NOT_ENCRYPTED,
                        null,   // badCode
                        0,  // numSubgroups
                        null,   // bisSyncState
                        null    // subgroupMetadata
                        Arrays.asList(new Long[0]),   // bisSyncState
                        Arrays.asList(new BluetoothLeAudioContentMetadata[0])    // subgroupMetadata
                );
            }
        } else {
@@ -614,7 +660,6 @@ public class BassClientStateMachine extends StateMachine {
                    0,
                    mBroadcastSourceIdLength);
            int broadcastId = BassUtils.parseBroadcastId(broadcastIdBytes);
            BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
            byte[] sourceAddress = new byte[BassConstants.BCAST_RCVR_STATE_SRC_ADDR_SIZE];
            System.arraycopy(
                    receiverState,
@@ -672,7 +717,9 @@ public class BassClientStateMachine extends StateMachine {
            log("old sourceInfo: " + oldRecvState);
            log("new sourceInfo: " + recvState);
            mBluetoothLeBroadcastReceiveStates.replace(characteristic.getInstanceId(), recvState);
            if (oldRecvState.getSourceDevice() == null) {
            String emptyBluetoothDevice = "00:00:00:00:00:00";
            if (oldRecvState.getSourceDevice() == null
                    || oldRecvState.getSourceDevice().getAddress().equals(emptyBluetoothDevice)) {
                log("New Source Addition");
                mService.getCallbacks().notifySourceAdded(mDevice,
                        recvState.getSourceId(), BluetoothStatusCodes.REASON_LOCAL_APP_REQUEST);
@@ -682,7 +729,8 @@ public class BassClientStateMachine extends StateMachine {
                checkAndUpdateBroadcastCode(recvState);
                processPASyncState(recvState);
            } else {
                if (recvState.getSourceDevice() == null) {
                if (recvState.getSourceDevice() == null
                        || recvState.getSourceDevice().getAddress().equals(emptyBluetoothDevice)) {
                    BluetoothDevice removedDevice = oldRecvState.getSourceDevice();
                    log("sourceInfo removal" + removedDevice);
                    cancelActiveSync(removedDevice);
+5 −0
Original line number Diff line number Diff line
@@ -263,6 +263,10 @@ class AdapterProperties {
    private static void invalidateIsOffloadedFilteringSupportedCache() {
        BluetoothAdapter.invalidateIsOffloadedFilteringSupportedCache();
    }
    private static void invalidateBluetoothGetConnectionStateCache() {
        BluetoothMap.invalidateBluetoothGetConnectionStateCache();
        BluetoothSap.invalidateBluetoothGetConnectionStateCache();
    }
    private static void invalidateGetConnectionStateCache() {
        BluetoothAdapter.invalidateGetAdapterConnectionStateCache();
    }
@@ -274,6 +278,7 @@ class AdapterProperties {
        invalidateIsOffloadedFilteringSupportedCache();
        invalidateGetConnectionStateCache();
        invalidateGetBondStateCache();
        invalidateBluetoothGetConnectionStateCache();
    }

    @Override
+27 −10
Original line number Diff line number Diff line
@@ -46,8 +46,10 @@ import android.bluetooth.BluetoothAdapter.ActiveDeviceUse;
import android.bluetooth.BluetoothClass;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothFrameworkInitializer;
import android.bluetooth.BluetoothMap;
import android.bluetooth.BluetoothProfile;
import android.bluetooth.BluetoothProtoEnums;
import android.bluetooth.BluetoothSap;
import android.bluetooth.BluetoothServerSocket;
import android.bluetooth.BluetoothSocket;
import android.bluetooth.BluetoothStatusCodes;
@@ -424,6 +426,8 @@ public class AdapterService extends Service {
                        return;
                    }
                    mRunningProfiles.add(profile);
                    // TODO(b/228875190): GATT is assumed supported. GATT starting triggers hardware
                    // initializtion. Configuring a device without GATT causes start up failures.
                    if (GattService.class.getSimpleName().equals(profile.getName())) {
                        enableNative();
                    } else if (mRegisteredProfiles.size() == Config.getSupportedProfiles().length
@@ -448,7 +452,9 @@ public class AdapterService extends Service {
                        return;
                    }
                    mRunningProfiles.remove(profile);
                    // If only GATT is left, send BREDR_STOPPED.
                    // TODO(b/228875190): GATT is assumed supported. GATT is expected to be the only
                    // profile available in the "BLE ON" state. If only GATT is left, send
                    // BREDR_STOPPED. If GATT is stopped, deinitialize the hardware.
                    if ((mRunningProfiles.size() == 1 && (GattService.class.getSimpleName()
                            .equals(mRunningProfiles.get(0).getName())))) {
                        mAdapterStateMachine.sendMessage(AdapterState.BREDR_STOPPED);
@@ -645,7 +651,13 @@ public class AdapterService extends Service {
        BluetoothStatsLog.write_non_chained(BluetoothStatsLog.BLE_SCAN_STATE_CHANGED, -1, null,
                BluetoothStatsLog.BLE_SCAN_STATE_CHANGED__STATE__RESET, false, false, false);

        //Start Gatt service
        // TODO(b/228875190): GATT is assumed supported. As a result, we don't respect the
        // configuration sysprop. Configuring a device without GATT, although rare, will cause stack
        // start up errors yielding init loops.
        if (!GattService.isEnabled()) {
            Log.w(TAG,
                    "GATT is configured off but the stack assumes it to be enabled. Start anyway.");
        }
        setProfileServiceState(GattService.class, BluetoothAdapter.STATE_ON);
    }

@@ -682,10 +694,11 @@ public class AdapterService extends Service {
    void startProfileServices() {
        debugLog("startCoreServices()");
        Class[] supportedProfileServices = Config.getSupportedProfiles();
        // If we support no profiles, or we only support GATT/BLE, just move on to BREDR_STARTED
        if (supportedProfileServices.length == 0
                || (supportedProfileServices.length == 1 && GattService.class.getSimpleName()
                .equals(supportedProfileServices[0].getSimpleName()))) {
        // TODO(b/228875190): GATT is assumed supported. If we support no other profiles then just
        // move on to BREDR_STARTED. Note that configuring GATT to NOT supported will cause adapter
        // initialization failures
        if (supportedProfileServices.length == 1 && GattService.class.getSimpleName()
                .equals(supportedProfileServices[0].getSimpleName())) {
            mAdapterProperties.onBluetoothReady();
            updateUuids();
            setBluetoothClassFromConfig();
@@ -701,10 +714,10 @@ public class AdapterService extends Service {
        mAdapterProperties.setScanMode(AbstractionLayer.BT_SCAN_MODE_NONE);

        Class[] supportedProfileServices = Config.getSupportedProfiles();
        // If we support no profiles, or we only support GATT/BLE, just move on to BREDR_STOPPED
        if (supportedProfileServices.length == 0
                || (supportedProfileServices.length == 1 && (mRunningProfiles.size() == 1
                && GattService.class.getSimpleName().equals(mRunningProfiles.get(0).getName())))) {
        // TODO(b/228875190): GATT is assumed supported. If we support no profiles then just move on
        // to BREDR_STOPPED
        if (supportedProfileServices.length == 1 && (mRunningProfiles.size() == 1
                && GattService.class.getSimpleName().equals(mRunningProfiles.get(0).getName()))) {
            debugLog("stopProfileServices() - No profiles services to stop or already stopped.");
            mAdapterStateMachine.sendMessage(AdapterState.BREDR_STOPPED);
        } else {
@@ -974,6 +987,8 @@ public class AdapterService extends Service {
        BluetoothDevice.invalidateBluetoothGetBondStateCache();
        BluetoothAdapter.invalidateBluetoothGetStateCache();
        BluetoothAdapter.invalidateGetAdapterConnectionStateCache();
        BluetoothMap.invalidateBluetoothGetConnectionStateCache();
        BluetoothSap.invalidateBluetoothGetConnectionStateCache();
    }

    private void setProfileServiceState(Class service, int state) {
@@ -990,6 +1005,8 @@ public class AdapterService extends Service {

    private void setAllProfileServiceStates(Class[] services, int state) {
        for (Class service : services) {
            // TODO(b/228875190): GATT is assumed supported and treated differently as part of the
            // "BLE ON" state, despite GATT not being BLE specific.
            if (GattService.class.getSimpleName().equals(service.getSimpleName())) {
                continue;
            }
+1 −1
Original line number Diff line number Diff line
@@ -270,7 +270,7 @@ public class GattService extends ProfileService {
    private final Object mTestModeLock = new Object();

    public static boolean isEnabled() {
        return BluetoothProperties.isProfileGattEnabled().orElse(false);
        return BluetoothProperties.isProfileGattEnabled().orElse(true);
    }

    /**
+33 −28
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ public class HeadsetPhoneState {
    private PhoneStateListener mPhoneStateListener;
    private final OnSubscriptionsChangedListener mOnSubscriptionsChangedListener;
    private SignalStrengthUpdateRequest mSignalStrengthUpdateRequest;
    private final Object mPhoneStateListenerLock = new Object();

    HeadsetPhoneState(HeadsetService headsetService) {
        Objects.requireNonNull(headsetService, "headsetService is null");
@@ -145,6 +146,7 @@ public class HeadsetPhoneState {
    }

    private void startListenForPhoneState() {
        synchronized (mPhoneStateListenerLock) {
            if (mPhoneStateListener != null) {
                Log.w(TAG, "startListenForPhoneState, already listening");
                return;
@@ -167,8 +169,10 @@ public class HeadsetPhoneState {
                mTelephonyManager.setSignalStrengthUpdateRequest(mSignalStrengthUpdateRequest);
            }
        }
    }

    private void stopListenForPhoneState() {
        synchronized (mPhoneStateListenerLock) {
            if (mPhoneStateListener == null) {
                Log.i(TAG, "stopListenForPhoneState(), no listener indicates nothing is listening");
                return;
@@ -179,6 +183,7 @@ public class HeadsetPhoneState {
            mPhoneStateListener = null;
            mTelephonyManager.clearSignalStrengthUpdateRequest(mSignalStrengthUpdateRequest);
        }
    }

    int getCindService() {
        return mCindService;
Loading