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

Commit 1fbf4040 authored by Sal Savage's avatar Sal Savage Committed by Gerrit Code Review
Browse files

Merge "Refactor btservice logging to be unguarded" into main

parents 14a42fb6 c97241ae
Loading
Loading
Loading
Loading
+55 −136
Original line number Original line Diff line number Diff line
@@ -101,7 +101,6 @@ import java.util.Set;
 */
 */
public class ActiveDeviceManager implements AdapterService.BluetoothStateCallback {
public class ActiveDeviceManager implements AdapterService.BluetoothStateCallback {
    private static final String TAG = ActiveDeviceManager.class.getSimpleName();
    private static final String TAG = ActiveDeviceManager.class.getSimpleName();
    private static final boolean DBG = true;
    @VisibleForTesting
    @VisibleForTesting
    static final int A2DP_HFP_SYNC_CONNECTION_TIMEOUT_MS = 5_000;
    static final int A2DP_HFP_SYNC_CONNECTION_TIMEOUT_MS = 5_000;


@@ -220,9 +219,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
    }
    }


    private void handleAdapterStateChanged(int currentState) {
    private void handleAdapterStateChanged(int currentState) {
        if (DBG) {
        Log.d(TAG, "handleAdapterStateChanged: currentState=" + currentState);
        Log.d(TAG, "handleAdapterStateChanged: currentState=" + currentState);
        }
        if (currentState == BluetoothAdapter.STATE_ON) {
        if (currentState == BluetoothAdapter.STATE_ON) {
            resetState();
            resetState();
        }
        }
@@ -241,13 +238,9 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
     */
     */
    private void handleA2dpConnected(BluetoothDevice device) {
    private void handleA2dpConnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleA2dpConnected: " + device);
            Log.d(TAG, "handleA2dpConnected: " + device);
            }
            if (mA2dpConnectedDevices.contains(device)) {
            if (mA2dpConnectedDevices.contains(device)) {
                if (DBG) {
                Log.d(TAG, "This device is already connected: " + device);
                Log.d(TAG, "This device is already connected: " + device);
                }
                return;
                return;
            }
            }
            mA2dpConnectedDevices.add(device);
            mA2dpConnectedDevices.add(device);
@@ -282,10 +275,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                        setLeAudioActiveDevice(null, true);
                        setLeAudioActiveDevice(null, true);
                    }
                    }
                } else {
                } else {
                    if (DBG) {
                    Log.d(TAG, "A2DP activation is suspended until HFP connected: "
                    Log.d(TAG, "A2DP activation is suspended until HFP connected: "
                            + device);
                            + device);
                    }
                    if (mPendingActiveDevice != null) {
                    if (mPendingActiveDevice != null) {
                        mHandler.removeCallbacksAndMessages(mPendingActiveDevice);
                        mHandler.removeCallbacksAndMessages(mPendingActiveDevice);
                    }
                    }
@@ -316,13 +307,9 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
     */
     */
    private void handleHfpConnected(BluetoothDevice device) {
    private void handleHfpConnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleHfpConnected: " + device);
            Log.d(TAG, "handleHfpConnected: " + device);
            }
            if (mHfpConnectedDevices.contains(device)) {
            if (mHfpConnectedDevices.contains(device)) {
                if (DBG) {
                Log.d(TAG, "This device is already connected: " + device);
                Log.d(TAG, "This device is already connected: " + device);
                }
                return;
                return;
            }
            }
            mHfpConnectedDevices.add(device);
            mHfpConnectedDevices.add(device);
@@ -367,10 +354,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                        setLeAudioActiveDevice(null, true);
                        setLeAudioActiveDevice(null, true);
                    }
                    }
                } else {
                } else {
                    if (DBG) {
                    Log.d(TAG, "HFP activation is suspended until A2DP connected: "
                    Log.d(TAG, "HFP activation is suspended until A2DP connected: "
                            + device);
                            + device);
                    }
                    if (mPendingActiveDevice != null) {
                    if (mPendingActiveDevice != null) {
                        mHandler.removeCallbacksAndMessages(mPendingActiveDevice);
                        mHandler.removeCallbacksAndMessages(mPendingActiveDevice);
                    }
                    }
@@ -390,13 +375,9 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleHearingAidConnected(BluetoothDevice device) {
    private void handleHearingAidConnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleHearingAidConnected: " + device);
            Log.d(TAG, "handleHearingAidConnected: " + device);
            }
            if (mHearingAidConnectedDevices.contains(device)) {
            if (mHearingAidConnectedDevices.contains(device)) {
                if (DBG) {
                Log.d(TAG, "This device is already connected: " + device);
                Log.d(TAG, "This device is already connected: " + device);
                }
                return;
                return;
            }
            }
            mHearingAidConnectedDevices.add(device);
            mHearingAidConnectedDevices.add(device);
@@ -419,9 +400,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleLeAudioConnected(BluetoothDevice device) {
    private void handleLeAudioConnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleLeAudioConnected: " + device);
            Log.d(TAG, "handleLeAudioConnected: " + device);
            }


            final LeAudioService leAudioService = mFactory.getLeAudioService();
            final LeAudioService leAudioService = mFactory.getLeAudioService();
            if (leAudioService == null || device == null) {
            if (leAudioService == null || device == null) {
@@ -430,9 +409,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
            leAudioService.deviceConnected(device);
            leAudioService.deviceConnected(device);


            if (mLeAudioConnectedDevices.contains(device)) {
            if (mLeAudioConnectedDevices.contains(device)) {
                if (DBG) {
                Log.d(TAG, "This device is already connected: " + device);
                Log.d(TAG, "This device is already connected: " + device);
                }
                return;
                return;
            }
            }


@@ -466,13 +443,9 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleHapConnected(BluetoothDevice device) {
    private void handleHapConnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleHapConnected: " + device);
            Log.d(TAG, "handleHapConnected: " + device);
            }
            if (mLeHearingAidConnectedDevices.contains(device)) {
            if (mLeHearingAidConnectedDevices.contains(device)) {
                if (DBG) {
                Log.d(TAG, "This device is already connected: " + device);
                Log.d(TAG, "This device is already connected: " + device);
                }
                return;
                return;
            }
            }
            mLeHearingAidConnectedDevices.add(device);
            mLeHearingAidConnectedDevices.add(device);
@@ -501,10 +474,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleA2dpDisconnected(BluetoothDevice device) {
    private void handleA2dpDisconnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleA2dpDisconnected: " + device
            Log.d(TAG, "handleA2dpDisconnected: " + device
                    + ", mA2dpActiveDevice=" + mA2dpActiveDevice);
                    + ", mA2dpActiveDevice=" + mA2dpActiveDevice);
            }
            mA2dpConnectedDevices.remove(device);
            mA2dpConnectedDevices.remove(device);
            if (Objects.equals(mA2dpActiveDevice, device)) {
            if (Objects.equals(mA2dpActiveDevice, device)) {
                if (!setFallbackDeviceActiveLocked()) {
                if (!setFallbackDeviceActiveLocked()) {
@@ -516,10 +487,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleHfpDisconnected(BluetoothDevice device) {
    private void handleHfpDisconnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleHfpDisconnected: " + device
            Log.d(TAG, "handleHfpDisconnected: " + device
                    + ", mHfpActiveDevice=" + mHfpActiveDevice);
                    + ", mHfpActiveDevice=" + mHfpActiveDevice);
            }
            mHfpConnectedDevices.remove(device);
            mHfpConnectedDevices.remove(device);
            if (Objects.equals(mHfpActiveDevice, device)) {
            if (Objects.equals(mHfpActiveDevice, device)) {
                if (mHfpConnectedDevices.isEmpty()) {
                if (mHfpConnectedDevices.isEmpty()) {
@@ -532,10 +501,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleHearingAidDisconnected(BluetoothDevice device) {
    private void handleHearingAidDisconnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleHearingAidDisconnected: " + device
            Log.d(TAG, "handleHearingAidDisconnected: " + device
                    + ", mHearingAidActiveDevices=" + mHearingAidActiveDevices);
                    + ", mHearingAidActiveDevices=" + mHearingAidActiveDevices);
            }
            mHearingAidConnectedDevices.remove(device);
            mHearingAidConnectedDevices.remove(device);
            if (mHearingAidActiveDevices.remove(device) && mHearingAidActiveDevices.isEmpty()) {
            if (mHearingAidActiveDevices.remove(device) && mHearingAidActiveDevices.isEmpty()) {
                if (!setFallbackDeviceActiveLocked()) {
                if (!setFallbackDeviceActiveLocked()) {
@@ -547,10 +514,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleLeAudioDisconnected(BluetoothDevice device) {
    private void handleLeAudioDisconnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleLeAudioDisconnected: " + device
            Log.d(TAG, "handleLeAudioDisconnected: " + device
                    + ", mLeAudioActiveDevice=" + mLeAudioActiveDevice);
                    + ", mLeAudioActiveDevice=" + mLeAudioActiveDevice);
            }


            final LeAudioService leAudioService = mFactory.getLeAudioService();
            final LeAudioService leAudioService = mFactory.getLeAudioService();
            if (leAudioService == null || device == null) {
            if (leAudioService == null || device == null) {
@@ -573,10 +538,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleHapDisconnected(BluetoothDevice device) {
    private void handleHapDisconnected(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleHapDisconnected: " + device
            Log.d(TAG, "handleHapDisconnected: " + device
                    + ", mLeHearingAidActiveDevice=" + mLeHearingAidActiveDevice);
                    + ", mLeHearingAidActiveDevice=" + mLeHearingAidActiveDevice);
            }
            mLeHearingAidConnectedDevices.remove(device);
            mLeHearingAidConnectedDevices.remove(device);
            mPendingLeHearingAidActiveDevice.remove(device);
            mPendingLeHearingAidActiveDevice.remove(device);
            if (Objects.equals(mLeHearingAidActiveDevice, device)) {
            if (Objects.equals(mLeHearingAidActiveDevice, device)) {
@@ -597,10 +560,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
     */
     */
    private void handleA2dpActiveDeviceChanged(BluetoothDevice device) {
    private void handleA2dpActiveDeviceChanged(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleA2dpActiveDeviceChanged: " + device
            Log.d(TAG, "handleA2dpActiveDeviceChanged: " + device
                    + ", mA2dpActiveDevice=" + mA2dpActiveDevice);
                    + ", mA2dpActiveDevice=" + mA2dpActiveDevice);
            }
            if (!Objects.equals(mA2dpActiveDevice, device)) {
            if (!Objects.equals(mA2dpActiveDevice, device)) {
                if (device != null) {
                if (device != null) {
                    setHearingAidActiveDevice(null, true);
                    setHearingAidActiveDevice(null, true);
@@ -663,10 +624,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
     */
     */
    private void handleHfpActiveDeviceChanged(BluetoothDevice device) {
    private void handleHfpActiveDeviceChanged(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleHfpActiveDeviceChanged: " + device
            Log.d(TAG, "handleHfpActiveDeviceChanged: " + device
                    + ", mHfpActiveDevice=" + mHfpActiveDevice);
                    + ", mHfpActiveDevice=" + mHfpActiveDevice);
            }
            if (!Objects.equals(mHfpActiveDevice, device)) {
            if (!Objects.equals(mHfpActiveDevice, device)) {
                if (device != null) {
                if (device != null) {
                    setHearingAidActiveDevice(null, true);
                    setHearingAidActiveDevice(null, true);
@@ -719,10 +678,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleHearingAidActiveDeviceChanged(BluetoothDevice device) {
    private void handleHearingAidActiveDeviceChanged(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleHearingAidActiveDeviceChanged: " + device
            Log.d(TAG, "handleHearingAidActiveDeviceChanged: " + device
                    + ", mHearingAidActiveDevices=" + mHearingAidActiveDevices);
                    + ", mHearingAidActiveDevices=" + mHearingAidActiveDevices);
            }
            // Just assign locally the new value
            // Just assign locally the new value
            final HearingAidService hearingAidService = mFactory.getHearingAidService();
            final HearingAidService hearingAidService = mFactory.getHearingAidService();
            if (hearingAidService != null) {
            if (hearingAidService != null) {
@@ -745,10 +702,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private void handleLeAudioActiveDeviceChanged(BluetoothDevice device) {
    private void handleLeAudioActiveDeviceChanged(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "handleLeAudioActiveDeviceChanged: " + device
            Log.d(TAG, "handleLeAudioActiveDeviceChanged: " + device
                    + ", mLeAudioActiveDevice=" + mLeAudioActiveDevice);
                    + ", mLeAudioActiveDevice=" + mLeAudioActiveDevice);
            }
            if (device != null && !mLeAudioConnectedDevices.contains(device)) {
            if (device != null && !mLeAudioConnectedDevices.contains(device)) {
                mLeAudioConnectedDevices.add(device);
                mLeAudioConnectedDevices.add(device);
            }
            }
@@ -786,15 +741,11 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


        @Override
        @Override
        public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
        public void onAudioDevicesAdded(AudioDeviceInfo[] addedDevices) {
            if (DBG) {
            Log.d(TAG, "onAudioDevicesAdded");
            Log.d(TAG, "onAudioDevicesAdded");
            }
            boolean hasAddedWiredDevice = false;
            boolean hasAddedWiredDevice = false;
            for (AudioDeviceInfo deviceInfo : addedDevices) {
            for (AudioDeviceInfo deviceInfo : addedDevices) {
                if (DBG) {
                Log.d(TAG, "Audio device added: " + deviceInfo.getProductName() + " type: "
                Log.d(TAG, "Audio device added: " + deviceInfo.getProductName() + " type: "
                        + deviceInfo.getType());
                        + deviceInfo.getType());
                }
                if (isWiredAudioHeadset(deviceInfo)) {
                if (isWiredAudioHeadset(deviceInfo)) {
                    hasAddedWiredDevice = true;
                    hasAddedWiredDevice = true;
                    break;
                    break;
@@ -819,9 +770,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
    }
    }


    void start() {
    void start() {
        if (DBG) {
        Log.d(TAG, "start()");
        Log.d(TAG, "start()");
        }


        mHandlerThread = new HandlerThread("BluetoothActiveDeviceManager");
        mHandlerThread = new HandlerThread("BluetoothActiveDeviceManager");
        BluetoothMethodProxy mp = BluetoothMethodProxy.getInstance();
        BluetoothMethodProxy mp = BluetoothMethodProxy.getInstance();
@@ -833,9 +782,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
    }
    }


    void cleanup() {
    void cleanup() {
        if (DBG) {
        Log.d(TAG, "cleanup()");
        Log.d(TAG, "cleanup()");
        }


        mAudioManager.unregisterAudioDeviceCallback(mAudioManagerAudioDeviceCallback);
        mAudioManager.unregisterAudioDeviceCallback(mAudioManagerAudioDeviceCallback);
        mAdapterService.unregisterBluetoothStateCallback(this);
        mAdapterService.unregisterBluetoothStateCallback(this);
@@ -866,10 +813,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private boolean setA2dpActiveDevice(@Nullable BluetoothDevice device,
    private boolean setA2dpActiveDevice(@Nullable BluetoothDevice device,
            boolean hasFallbackDevice) {
            boolean hasFallbackDevice) {
        if (DBG) {
        Log.d(TAG, "setA2dpActiveDevice(" + device + ")"
        Log.d(TAG, "setA2dpActiveDevice(" + device + ")"
                + (device == null ? " hasFallbackDevice=" + hasFallbackDevice : ""));
                + (device == null ? " hasFallbackDevice=" + hasFallbackDevice : ""));
        }
        synchronized (mLock) {
        synchronized (mLock) {
            if (mPendingActiveDevice != null) {
            if (mPendingActiveDevice != null) {
                mHandler.removeCallbacksAndMessages(mPendingActiveDevice);
                mHandler.removeCallbacksAndMessages(mPendingActiveDevice);
@@ -902,9 +847,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    private boolean setHfpActiveDevice(BluetoothDevice device) {
    private boolean setHfpActiveDevice(BluetoothDevice device) {
        synchronized (mLock) {
        synchronized (mLock) {
            if (DBG) {
            Log.d(TAG, "setHfpActiveDevice(" + device + ")");
            Log.d(TAG, "setHfpActiveDevice(" + device + ")");
            }
            if (mPendingActiveDevice != null) {
            if (mPendingActiveDevice != null) {
                mHandler.removeCallbacksAndMessages(mPendingActiveDevice);
                mHandler.removeCallbacksAndMessages(mPendingActiveDevice);
                mPendingActiveDevice = null;
                mPendingActiveDevice = null;
@@ -932,10 +875,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private boolean setHearingAidActiveDevice(@Nullable BluetoothDevice device,
    private boolean setHearingAidActiveDevice(@Nullable BluetoothDevice device,
            boolean hasFallbackDevice) {
            boolean hasFallbackDevice) {
        if (DBG) {
        Log.d(TAG, "setHearingAidActiveDevice(" + device + ")"
        Log.d(TAG, "setHearingAidActiveDevice(" + device + ")"
                + (device == null ? " hasFallbackDevice=" + hasFallbackDevice : ""));
                + (device == null ? " hasFallbackDevice=" + hasFallbackDevice : ""));
        }


        final HearingAidService hearingAidService = mFactory.getHearingAidService();
        final HearingAidService hearingAidService = mFactory.getHearingAidService();
        if (hearingAidService == null) {
        if (hearingAidService == null) {
@@ -972,10 +913,8 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac


    private boolean setLeAudioActiveDevice(@Nullable BluetoothDevice device,
    private boolean setLeAudioActiveDevice(@Nullable BluetoothDevice device,
            boolean hasFallbackDevice) {
            boolean hasFallbackDevice) {
        if (DBG) {
        Log.d(TAG, "setLeAudioActiveDevice(" + device + ")"
        Log.d(TAG, "setLeAudioActiveDevice(" + device + ")"
                + (device == null ? " hasFallbackDevice=" + hasFallbackDevice : ""));
                + (device == null ? " hasFallbackDevice=" + hasFallbackDevice : ""));
        }
        synchronized (mLock) {
        synchronized (mLock) {
            final LeAudioService leAudioService = mFactory.getLeAudioService();
            final LeAudioService leAudioService = mFactory.getLeAudioService();
            if (leAudioService == null) {
            if (leAudioService == null) {
@@ -989,9 +928,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                    if ((mLeAudioActiveDevice != null)
                    if ((mLeAudioActiveDevice != null)
                            && (Objects.equals(
                            && (Objects.equals(
                                    mLeAudioActiveDevice, leAudioService.getLeadDevice(device)))) {
                                    mLeAudioActiveDevice, leAudioService.getLeadDevice(device)))) {
                        if (DBG) {
                        Log.d(TAG, "New LeAudioDevice is a part of an active group");
                        Log.d(TAG, "New LeAudioDevice is a part of an active group");
                        }
                        return true;
                        return true;
                    }
                    }
                }
                }
@@ -1042,9 +979,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private boolean setFallbackDeviceActiveLocked() {
    private boolean setFallbackDeviceActiveLocked() {
        if (DBG) {
        Log.d(TAG, "setFallbackDeviceActive");
        Log.d(TAG, "setFallbackDeviceActive");
        }
        mDbManager = mAdapterService.getDatabase();
        mDbManager = mAdapterService.getDatabase();
        List<BluetoothDevice> connectedHearingAidDevices = new ArrayList<>();
        List<BluetoothDevice> connectedHearingAidDevices = new ArrayList<>();
        if (!mHearingAidConnectedDevices.isEmpty()) {
        if (!mHearingAidConnectedDevices.isEmpty()) {
@@ -1058,17 +993,13 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                    mDbManager.getMostRecentlyConnectedDevicesInList(connectedHearingAidDevices);
                    mDbManager.getMostRecentlyConnectedDevicesInList(connectedHearingAidDevices);
            if (device != null) {
            if (device != null) {
                if (mHearingAidConnectedDevices.contains(device)) {
                if (mHearingAidConnectedDevices.contains(device)) {
                    if (DBG) {
                    Log.d(TAG, "Found a hearing aid fallback device: " + device);
                    Log.d(TAG, "Found a hearing aid fallback device: " + device);
                    }
                    setHearingAidActiveDevice(device);
                    setHearingAidActiveDevice(device);
                    setA2dpActiveDevice(null, true);
                    setA2dpActiveDevice(null, true);
                    setHfpActiveDevice(null);
                    setHfpActiveDevice(null);
                    setLeAudioActiveDevice(null, true);
                    setLeAudioActiveDevice(null, true);
                } else {
                } else {
                    if (DBG) {
                    Log.d(TAG, "Found a LE hearing aid fallback device: " + device);
                    Log.d(TAG, "Found a LE hearing aid fallback device: " + device);
                    }
                    setLeHearingAidActiveDevice(device);
                    setLeHearingAidActiveDevice(device);
                    setHearingAidActiveDevice(null, true);
                    setHearingAidActiveDevice(null, true);
                    setA2dpActiveDevice(null, true);
                    setA2dpActiveDevice(null, true);
@@ -1112,9 +1043,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
        if (device != null) {
        if (device != null) {
            if (mAudioManager.getMode() == AudioManager.MODE_NORMAL) {
            if (mAudioManager.getMode() == AudioManager.MODE_NORMAL) {
                if (Objects.equals(a2dpFallbackDevice, device)) {
                if (Objects.equals(a2dpFallbackDevice, device)) {
                    if (DBG) {
                    Log.d(TAG, "Found an A2DP fallback device: " + device);
                    Log.d(TAG, "Found an A2DP fallback device: " + device);
                    }
                    setA2dpActiveDevice(device);
                    setA2dpActiveDevice(device);
                    if (Objects.equals(headsetFallbackDevice, device)) {
                    if (Objects.equals(headsetFallbackDevice, device)) {
                        setHfpActiveDevice(device);
                        setHfpActiveDevice(device);
@@ -1128,9 +1057,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                    }
                    }
                    setHearingAidActiveDevice(null, true);
                    setHearingAidActiveDevice(null, true);
                } else {
                } else {
                    if (DBG) {
                    Log.d(TAG, "Found a LE audio fallback device: " + device);
                    Log.d(TAG, "Found a LE audio fallback device: " + device);
                    }
                    if (!setLeAudioActiveDevice(device)) {
                    if (!setLeAudioActiveDevice(device)) {
                        return false;
                        return false;
                    }
                    }
@@ -1143,9 +1070,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                }
                }
            } else {
            } else {
                if (Objects.equals(headsetFallbackDevice, device)) {
                if (Objects.equals(headsetFallbackDevice, device)) {
                    if (DBG) {
                    Log.d(TAG, "Found a HFP fallback device: " + device);
                    Log.d(TAG, "Found a HFP fallback device: " + device);
                    }
                    setHfpActiveDevice(device);
                    setHfpActiveDevice(device);
                    if (Objects.equals(a2dpFallbackDevice, device)) {
                    if (Objects.equals(a2dpFallbackDevice, device)) {
                        setA2dpActiveDevice(a2dpFallbackDevice);
                        setA2dpActiveDevice(a2dpFallbackDevice);
@@ -1157,9 +1082,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
                    }
                    }
                    setHearingAidActiveDevice(null, true);
                    setHearingAidActiveDevice(null, true);
                } else {
                } else {
                    if (DBG) {
                    Log.d(TAG, "Found a LE audio fallback device: " + device);
                    Log.d(TAG, "Found a LE audio fallback device: " + device);
                    }
                    setLeAudioActiveDevice(device);
                    setLeAudioActiveDevice(device);
                    if (!Utils.isDualModeAudioEnabled()) {
                    if (!Utils.isDualModeAudioEnabled()) {
                        setA2dpActiveDevice(null, true);
                        setA2dpActiveDevice(null, true);
@@ -1171,9 +1094,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
            return true;
            return true;
        }
        }


        if (DBG) {
        Log.d(TAG, "No fallback devices are found");
        Log.d(TAG, "No fallback devices are found");
        }
        return false;
        return false;
    }
    }


@@ -1274,9 +1195,7 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
    @VisibleForTesting
    @VisibleForTesting
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
    void wiredAudioDeviceConnected() {
    void wiredAudioDeviceConnected() {
        if (DBG) {
        Log.d(TAG, "wiredAudioDeviceConnected");
        Log.d(TAG, "wiredAudioDeviceConnected");
        }
        setA2dpActiveDevice(null, true);
        setA2dpActiveDevice(null, true);
        setHfpActiveDevice(null);
        setHfpActiveDevice(null);
        setHearingAidActiveDevice(null, true);
        setHearingAidActiveDevice(null, true);
+7 −14
Original line number Original line Diff line number Diff line
@@ -20,26 +20,21 @@ import android.util.Log;


public class AdapterApp extends Application {
public class AdapterApp extends Application {
    private static final String TAG = "BluetoothAdapterApp";
    private static final String TAG = "BluetoothAdapterApp";
    private static final boolean DBG = false;
    //For Debugging only
    //For Debugging only
    private static int sRefCount = 0;
    private static int sRefCount = 0;


    public AdapterApp() {
    public AdapterApp() {
        super();
        super();
        if (DBG) {
        synchronized (AdapterApp.class) {
        synchronized (AdapterApp.class) {
            sRefCount++;
            sRefCount++;
            Log.d(TAG, "REFCOUNT: Constructed " + this + " Instance Count = " + sRefCount);
            Log.d(TAG, "REFCOUNT: Constructed " + this + " Instance Count = " + sRefCount);
        }
        }
    }
    }
    }


    @Override
    @Override
    public void onCreate() {
    public void onCreate() {
        super.onCreate();
        super.onCreate();
        if (DBG) {
        Log.d(TAG, "onCreate");
        Log.d(TAG, "onCreate");
        }
        try {
        try {
            DataMigration.run(this);
            DataMigration.run(this);
        } catch (Exception e) {
        } catch (Exception e) {
@@ -49,11 +44,9 @@ public class AdapterApp extends Application {


    @Override
    @Override
    protected void finalize() {
    protected void finalize() {
        if (DBG) {
        synchronized (AdapterApp.class) {
        synchronized (AdapterApp.class) {
            sRefCount--;
            sRefCount--;
            Log.d(TAG, "REFCOUNT: Finalized: " + this + ", Instance Count = " + sRefCount);
            Log.d(TAG, "REFCOUNT: Finalized: " + this + ", Instance Count = " + sRefCount);
        }
        }
    }
    }
}
}
}
+2 −8
Original line number Original line Diff line number Diff line
@@ -75,8 +75,6 @@ import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArrayList;


class AdapterProperties {
class AdapterProperties {
    private static final boolean DBG = true;
    private static final boolean VDBG = false;
    private static final String TAG = "AdapterProperties";
    private static final String TAG = "AdapterProperties";


    private static final String MAX_CONNECTED_AUDIO_DEVICES_PROPERTY =
    private static final String MAX_CONNECTED_AUDIO_DEVICES_PROPERTY =
@@ -1321,16 +1319,12 @@ class AdapterProperties {
    }
    }


    private static void infoLog(String msg) {
    private static void infoLog(String msg) {
        if (VDBG) {
        Log.i(TAG, msg);
        Log.i(TAG, msg);
    }
    }
    }


    private static void debugLog(String msg) {
    private static void debugLog(String msg) {
        if (DBG) {
        Log.d(TAG, msg);
        Log.d(TAG, msg);
    }
    }
    }


    private static void errorLog(String msg) {
    private static void errorLog(String msg) {
        Log.e(TAG, msg);
        Log.e(TAG, msg);
+9 −21
Original line number Original line Diff line number Diff line
@@ -182,8 +182,6 @@ import java.util.stream.Collectors;


public class AdapterService extends Service {
public class AdapterService extends Service {
    private static final String TAG = "BluetoothAdapterService";
    private static final String TAG = "BluetoothAdapterService";
    private static final boolean DBG = true;
    private static final boolean VERBOSE = false;


    private static final int MESSAGE_PROFILE_SERVICE_STATE_CHANGED = 1;
    private static final int MESSAGE_PROFILE_SERVICE_STATE_CHANGED = 1;
    private static final int MESSAGE_PROFILE_SERVICE_REGISTERED = 2;
    private static final int MESSAGE_PROFILE_SERVICE_REGISTERED = 2;
@@ -346,9 +344,7 @@ public class AdapterService extends Service {
    };
    };


    static {
    static {
        if (DBG) {
        Log.d(TAG, "Loading JNI Library");
        Log.d(TAG, "Loading JNI Library");
        }
        if (Utils.isInstrumentationTestMode()) {
        if (Utils.isInstrumentationTestMode()) {
            Log.w(TAG, "App is instrumented. Skip loading the native");
            Log.w(TAG, "App is instrumented. Skip loading the native");
        } else {
        } else {
@@ -1597,12 +1593,10 @@ public class AdapterService extends Service {
                    + BluetoothProfile.getProfileName(profile) + "): remote device Uuids Empty");
                    + BluetoothProfile.getProfileName(profile) + "): remote device Uuids Empty");
        }
        }


        if (VERBOSE) {
        Log.v(TAG, "isProfileSupported(device=" + device + ", profile="
        Log.v(TAG, "isProfileSupported(device=" + device + ", profile="
                + BluetoothProfile.getProfileName(profile) + "): local_uuids="
                + BluetoothProfile.getProfileName(profile) + "): local_uuids="
                + Arrays.toString(localDeviceUuids) + ", remote_uuids="
                + Arrays.toString(localDeviceUuids) + ", remote_uuids="
                + Arrays.toString(remoteDeviceUuids));
                + Arrays.toString(remoteDeviceUuids));
        }


        if (profile == BluetoothProfile.HEADSET) {
        if (profile == BluetoothProfile.HEADSET) {
            return (Utils.arrayContains(localDeviceUuids, BluetoothUuid.HSP_AG)
            return (Utils.arrayContains(localDeviceUuids, BluetoothUuid.HSP_AG)
@@ -7587,16 +7581,12 @@ public class AdapterService extends Service {
    }
    }


    private void debugLog(String msg) {
    private void debugLog(String msg) {
        if (DBG) {
        Log.d(TAG, msg);
        Log.d(TAG, msg);
    }
    }
    }


    private void verboseLog(String msg) {
    private void verboseLog(String msg) {
        if (VERBOSE) {
        Log.v(TAG, msg);
        Log.v(TAG, msg);
    }
    }
    }


    private void errorLog(String msg) {
    private void errorLog(String msg) {
        Log.e(TAG, msg);
        Log.e(TAG, msg);
@@ -8122,11 +8112,9 @@ public class AdapterService extends Service {
            return;
            return;
        }
        }
        Log.i(TAG, "sendUuidsInternal: Received service discovery UUIDs for device " + device);
        Log.i(TAG, "sendUuidsInternal: Received service discovery UUIDs for device " + device);
        if (DBG) {
        for (int i = 0; i < uuids.length; i++) {
        for (int i = 0; i < uuids.length; i++) {
            Log.d(TAG, "sendUuidsInternal: index=" + i + " uuid=" + uuids[i]);
            Log.d(TAG, "sendUuidsInternal: index=" + i + " uuid=" + uuids[i]);
        }
        }
        }
        if (mPhonePolicy != null) {
        if (mPhonePolicy != null) {
            mPhonePolicy.onUuidsDiscovered(device, uuids);
            mPhonePolicy.onUuidsDiscovered(device, uuids);
        }
        }
+1 −4
Original line number Original line Diff line number Diff line
@@ -56,7 +56,6 @@ import com.android.internal.util.StateMachine;
 */
 */


final class AdapterState extends StateMachine {
final class AdapterState extends StateMachine {
    private static final boolean DBG = true;
    private static final String TAG = AdapterState.class.getSimpleName();
    private static final String TAG = AdapterState.class.getSimpleName();


    static final int USER_TURN_ON = 1;
    static final int USER_TURN_ON = 1;
@@ -162,10 +161,8 @@ final class AdapterState extends StateMachine {
        }
        }


        void infoLog(String msg) {
        void infoLog(String msg) {
            if (DBG) {
            Log.i(TAG, BluetoothAdapter.nameForState(getStateValue()) + " : " + msg);
            Log.i(TAG, BluetoothAdapter.nameForState(getStateValue()) + " : " + msg);
        }
        }
        }


        void errorLog(String msg) {
        void errorLog(String msg) {
            Log.e(TAG, BluetoothAdapter.nameForState(getStateValue()) + " : " + msg);
            Log.e(TAG, BluetoothAdapter.nameForState(getStateValue()) + " : " + msg);
Loading