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

Commit 32a057e5 authored by xiaowang's avatar xiaowang Committed by Jakub Tyszkowski
Browse files

BassClient: Cleanup unnecessary code regarding auto assistant

Test: mm -j $(nproc)
Bug: 238847802
Change-Id: I70d8359e6eda496b5b9d8c83fbaa48ec3495b6b5
parent 8b89988e
Loading
Loading
Loading
Loading
+0 −0

File mode changed from 100755 to 100644.

+0 −13
Original line number Diff line number Diff line
@@ -92,7 +92,6 @@ public class BassClientService extends ProfileService {
    private AdapterService mAdapterService;
    private DatabaseManager mDatabaseManager;
    private BluetoothAdapter mBluetoothAdapter = null;
    private BassUtils mBassUtils = null;
    private Map<BluetoothDevice, BluetoothDevice> mActiveSourceMap;
    /* Caching the PeriodicAdvertisementResult from Broadcast source */
    /* This is stored at service so that each device state machine can access
@@ -279,7 +278,6 @@ public class BassClientService extends ProfileService {
        registerReceiver(mIntentReceiver, filter, Context.RECEIVER_NOT_EXPORTED);

        setBassClientService(this);
        mBassUtils = new BassUtils(this);
        // Saving PSync stuff for future addition
        mDeviceToSyncHandleMap = new HashMap<BluetoothDevice, Integer>();
        mPeriodicAdvertisementResultMap = new HashMap<BluetoothDevice,
@@ -324,10 +322,6 @@ public class BassClientService extends ProfileService {
            mActiveSourceMap.clear();
            mActiveSourceMap = null;
        }
        if (mBassUtils != null) {
            mBassUtils.cleanUp();
            mBassUtils = null;
        }
        if (mPendingGroupOp != null) {
            mPendingGroupOp.clear();
        }
@@ -340,13 +334,6 @@ public class BassClientService extends ProfileService {
        return super.onUnbind(intent);
    }

    /**
     * getBassUtils
     */
    public BassUtils getBassUtils() {
        return mBassUtils;
    }

    BluetoothDevice getDeviceForSyncHandle(int syncHandle) {
        if (mDeviceToSyncHandleMap == null) {
            return null;
+0 −5
Original line number Diff line number Diff line
@@ -178,7 +178,6 @@ public class BassClientStateMachine extends StateMachine {
    private final Map<Integer, Boolean> mPendingRemove = new HashMap();
    // Psync and PAST interfaces
    private PeriodicAdvertisingManager mPeriodicAdvManager;
    private boolean mAutoAssist = false;
    private boolean mAutoTriggered = false;
    private boolean mNoStopScanOffload = false;
    private boolean mDefNoPAS = false;
@@ -606,10 +605,6 @@ public class BassClientStateMachine extends StateMachine {
                            advHandle, mPeriodicAdvCallback);
                } else {
                    Log.e(TAG, "There is no valid sync handle for this Source");
                    if (mAutoAssist) {
                        // Initiate Auto Assist procedure for this device
                        mService.getBassUtils().triggerAutoAssist(recvState);
                    }
                }
            }
        } else if (state == BluetoothLeBroadcastReceiveState.PA_SYNC_STATE_SYNCHRONIZED
+1 −6
Original line number Diff line number Diff line
@@ -37,12 +37,7 @@ public class BassConstants {
            UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
    public static final ParcelUuid BASIC_AUDIO_UUID =
            ParcelUuid.fromString("00001851-0000-1000-8000-00805F9B34FB");
    public static final int AA_START_SCAN = 1;
    public static final int AA_SCAN_SUCCESS = 2;
    public static final int AA_SCAN_FAILURE = 3;
    public static final int AA_SCAN_TIMEOUT = 4;
    // timeout for internal scan
    public static final int AA_SCAN_TIMEOUT_MS = 1000;

    public static final int INVALID_SYNC_HANDLE = -1;
    public static final int INVALID_ADV_SID = -1;
    public static final int INVALID_ADV_ADDRESS_TYPE = -1;
+0 −82
Original line number Diff line number Diff line
@@ -16,27 +16,12 @@

package com.android.bluetooth.bass_client;

import android.annotation.NonNull;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothLeBroadcastReceiveState;
import android.bluetooth.IBluetoothLeBroadcastAssistantCallback;
import android.bluetooth.le.BluetoothLeScanner;
import android.bluetooth.le.ScanCallback;
import android.bluetooth.le.ScanFilter;
import android.bluetooth.le.ScanResult;
import android.os.Handler;
import android.os.Message;
import android.os.ParcelUuid;
import android.util.Log;

import com.android.bluetooth.btservice.ServiceFactory;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Bass Utility functions
@@ -44,73 +29,6 @@ import java.util.Map;
class BassUtils {
    private static final String TAG = "BassUtils";

    // Using ArrayList as KEY to hashmap. May be not risk
    // in this case as It is used to track the callback to cancel Scanning later
    private final Map<ArrayList<IBluetoothLeBroadcastAssistantCallback>, ScanCallback>
            mLeAudioSourceScanCallbacks =
            new HashMap<ArrayList<IBluetoothLeBroadcastAssistantCallback>, ScanCallback>();
    private final Map<BluetoothDevice, ScanCallback> mBassAutoAssist =
            new HashMap<BluetoothDevice, ScanCallback>();

    /*LE Scan related members*/
    private boolean mBroadcastersAround = false;
    private BluetoothAdapter mBluetoothAdapter = null;
    private BluetoothLeScanner mLeScanner = null;
    private BassClientService mService = null;
    private ServiceFactory mFactory = new ServiceFactory();

    BassUtils(BassClientService service) {
        mService = service;
        mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
        mLeScanner = mBluetoothAdapter.getBluetoothLeScanner();
    }

    void cleanUp() {
        if (mLeAudioSourceScanCallbacks != null) {
            mLeAudioSourceScanCallbacks.clear();
        }
        if (mBassAutoAssist != null) {
            mBassAutoAssist.clear();
        }
    }

    private final Handler mAutoAssistScanHandler =
            new Handler() {
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    switch (msg.what) {
                        case BassConstants.AA_START_SCAN:
                            Message m = obtainMessage(BassConstants.AA_SCAN_TIMEOUT);
                            sendMessageDelayed(m, BassConstants.AA_SCAN_TIMEOUT_MS);
                            mService.startSearchingForSources(null);
                            break;
                        case BassConstants.AA_SCAN_SUCCESS:
                            // Able to find to desired desired Source Device
                            ScanResult scanRes = (ScanResult) msg.obj;
                            BluetoothDevice dev = scanRes.getDevice();
                            mService.stopSearchingForSources();
                            mService.selectSource(dev, scanRes, true);
                            break;
                        case BassConstants.AA_SCAN_FAILURE:
                            // Not able to find the given source
                            break;
                        case BassConstants.AA_SCAN_TIMEOUT:
                            mService.stopSearchingForSources();
                            break;
                    }
                }
            };

    @NonNull Handler getAutoAssistScanHandler() {
        return mAutoAssistScanHandler;
    }

    void triggerAutoAssist(BluetoothLeBroadcastReceiveState recvState) {
        Message msg = mAutoAssistScanHandler.obtainMessage(BassConstants.AA_START_SCAN);
        msg.obj = recvState.getSourceDevice();
        mAutoAssistScanHandler.sendMessage(msg);
    }

    static boolean containUuid(List<ScanFilter> filters, ParcelUuid uuid) {
        for (ScanFilter filter: filters) {
            if (filter.getServiceUuid().equals(uuid)) {
Loading