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

Commit c72b8f62 authored by Sungsoo Lim's avatar Sungsoo Lim
Browse files

Combind some methods with "profile" args

Bug: 293555920
Test: atest BluetoothInstrumentationTest
Change-Id: Ib48dc7c7266e9bc180c96c3337a66f282b157078
parent 9881e645
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -1080,7 +1080,9 @@ public class A2dpService extends ProfileService {
            mActiveDevice = device;
        }

        mAdapterService.getActiveDeviceManager().a2dpActiveStateChanged(device);
        mAdapterService
                .getActiveDeviceManager()
                .profileActiveDeviceChanged(BluetoothProfile.A2DP, device);
        mAdapterService.getSilenceDeviceManager().a2dpActiveDeviceChanged(device);

        BluetoothStatsLog.write(BluetoothStatsLog.BLUETOOTH_ACTIVE_DEVICE_CHANGED,
@@ -1287,7 +1289,7 @@ public class A2dpService extends ProfileService {
        }
        mAdapterService
                .getActiveDeviceManager()
                .a2dpConnectionStateChanged(device, fromState, toState);
                .profileConnectionStateChanged(BluetoothProfile.A2DP, device, fromState, toState);
        mAdapterService
                .getSilenceDeviceManager()
                .a2dpConnectionStateChanged(device, fromState, toState);
+54 −94
Original line number Diff line number Diff line
@@ -146,114 +146,74 @@ public class ActiveDeviceManager implements AdapterService.BluetoothStateCallbac
    }

    /**
     * Called when A2DP connection state changed by A2dpService
     * Called when audio profile connection state changed
     *
     * @param profile The Bluetooth profile of which connection state changed
     * @param device The device of which connection state was changed
     * @param fromState The previous connection state of the device
     * @param toState The new connection state of the device
     */
    public void a2dpConnectionStateChanged(BluetoothDevice device, int fromState, int toState) {
    public void profileConnectionStateChanged(
            int profile, BluetoothDevice device, int fromState, int toState) {
        if (toState == BluetoothProfile.STATE_CONNECTED) {
            switch (profile) {
                case BluetoothProfile.A2DP:
                    mHandler.post(() -> handleA2dpConnected(device));
                    break;
                case BluetoothProfile.HEADSET:
                    mHandler.post(() -> handleHfpConnected(device));
                    break;
                case BluetoothProfile.LE_AUDIO:
                    mHandler.post(() -> handleLeAudioConnected(device));
                    break;
                case BluetoothProfile.HEARING_AID:
                    mHandler.post(() -> handleHearingAidConnected(device));
                    break;
                case BluetoothProfile.HAP_CLIENT:
                    mHandler.post(() -> handleHapConnected(device));
                    break;
            }
        } else if (fromState == BluetoothProfile.STATE_CONNECTED) {
            switch (profile) {
                case BluetoothProfile.A2DP:
                    mHandler.post(() -> handleA2dpDisconnected(device));
                    break;
                case BluetoothProfile.HEADSET:
                    mHandler.post(() -> handleHfpDisconnected(device));
                    break;
                case BluetoothProfile.LE_AUDIO:
                    mHandler.post(() -> handleLeAudioDisconnected(device));
                    break;
                case BluetoothProfile.HEARING_AID:
                    mHandler.post(() -> handleHearingAidDisconnected(device));
                    break;
                case BluetoothProfile.HAP_CLIENT:
                    mHandler.post(() -> handleHapDisconnected(device));
                    break;
            }
        }
    }

    /**
     * Called when A2DP active state changed by A2dpService
     * Called when active state of audio profiles changed
     *
     * @param profile The Bluetooth profile of which active state changed
     * @param device The device currently activated. {@code null} if no A2DP device activated
     */
    public void a2dpActiveStateChanged(BluetoothDevice device) {
    public void profileActiveDeviceChanged(int profile, BluetoothDevice device) {
        switch (profile) {
            case BluetoothProfile.A2DP:
                mHandler.post(() -> handleA2dpActiveDeviceChanged(device));
    }

    /**
     * Called when HFP connection state changed by HeadsetService
     *
     * @param device The device of which connection state was changed
     * @param prevState The previous connection state of the device
     * @param newState The new connection state of the device
     */
    public void hfpConnectionStateChanged(BluetoothDevice device, int prevState, int newState) {
        if (newState == BluetoothProfile.STATE_CONNECTED) {
            mHandler.post(() -> handleHfpConnected(device));
        } else if (prevState == BluetoothProfile.STATE_CONNECTED) {
            mHandler.post(() -> handleHfpDisconnected(device));
        }
    }

    /**
     * Called when HFP active state changed by HeadsetService
     *
     * @param device The device currently activated. {@code null} if no HFP device activated
     */
    public void hfpActiveStateChanged(BluetoothDevice device) {
                break;
            case BluetoothProfile.HEADSET:
                mHandler.post(() -> handleHfpActiveDeviceChanged(device));
    }

    /**
     * Called when LE audio connection state changed by LeAudioService
     *
     * @param device The device of which connection state was changed
     * @param prevState The previous connection state of the device
     * @param newState The new connection state of the device
     */
    public void leAudioConnectionStateChanged(BluetoothDevice device, int prevState, int newState) {
        if (newState == BluetoothProfile.STATE_CONNECTED) {
            mHandler.post(() -> handleLeAudioConnected(device));
        } else if (prevState == BluetoothProfile.STATE_CONNECTED) {
            mHandler.post(() -> handleLeAudioDisconnected(device));
        }
    }

    /**
     * Called when LE audio active state changed by LeAudioService
     *
     * @param device The device currently activated. {@code null} if no LE audio device activated
     */
    public void leAudioActiveStateChanged(BluetoothDevice device) {
                break;
            case BluetoothProfile.LE_AUDIO:
                mHandler.post(() -> handleLeAudioActiveDeviceChanged(device));
    }

    /**
     * Called when HearingAid connection state changed by HearingAidService
     *
     * @param device The device of which connection state was changed
     * @param prevState The previous connection state of the device
     * @param newState The new connection state of the device
     */
    public void hearingAidConnectionStateChanged(
            BluetoothDevice device, int prevState, int newState) {
        if (newState == BluetoothProfile.STATE_CONNECTED) {
            mHandler.post(() -> handleHearingAidConnected(device));
        } else if (prevState == BluetoothProfile.STATE_CONNECTED) {
            mHandler.post(() -> handleHearingAidDisconnected(device));
        }
    }

    /**
     * Called when HearingAid active state changed by HearingAidService
     *
     * @param device The device currently activated. {@code null} if no HearingAid device activated
     */
    public void hearingAidActiveStateChanged(BluetoothDevice device) {
                break;
            case BluetoothProfile.HEARING_AID:
                mHandler.post(() -> handleHearingAidActiveDeviceChanged(device));
    }

    /**
     * Called when HAP connection state changed by HapClientService
     *
     * @param device The device of which connection state was changed
     * @param prevState The previous connection state of the device
     * @param newState The new connection state of the device
     */
    public void hapConnectionStateChanged(BluetoothDevice device, int prevState, int newState) {
        if (newState == BluetoothProfile.STATE_CONNECTED) {
            mHandler.post(() -> handleHapConnected(device));
        } else if (prevState == BluetoothProfile.STATE_CONNECTED) {
            mHandler.post(() -> handleHapDisconnected(device));
                break;
        }
    }

+2 −1
Original line number Diff line number Diff line
@@ -447,7 +447,8 @@ public class HapClientService extends ProfileService {
        }
        ActiveDeviceManager adManager = mAdapterService.getActiveDeviceManager();
        if (adManager != null) {
            adManager.hapConnectionStateChanged(device, fromState, toState);
            adManager.profileConnectionStateChanged(
                    BluetoothProfile.HAP_CLIENT, device, fromState, toState);
        }
    }

+5 −2
Original line number Diff line number Diff line
@@ -730,7 +730,9 @@ public class HearingAidService extends ProfileService {
    }

    private void notifyActiveDeviceChanged() {
        mAdapterService.getActiveDeviceManager().hearingAidActiveStateChanged(mActiveDevice);
        mAdapterService
                .getActiveDeviceManager()
                .profileActiveDeviceChanged(BluetoothProfile.HEARING_AID, mActiveDevice);
        Intent intent = new Intent(BluetoothHearingAid.ACTION_ACTIVE_DEVICE_CHANGED);
        intent.putExtra(BluetoothDevice.EXTRA_DEVICE, mActiveDevice);
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
@@ -964,7 +966,8 @@ public class HearingAidService extends ProfileService {
        }
        mAdapterService
                .getActiveDeviceManager()
                .hearingAidConnectionStateChanged(device, fromState, toState);
                .profileConnectionStateChanged(
                        BluetoothProfile.HEARING_AID, device, fromState, toState);
    }

    /**
+5 −2
Original line number Diff line number Diff line
@@ -2007,7 +2007,8 @@ public class HeadsetService extends ProfileService {
                setActiveDevice(null);
            }
        }
        mActiveDeviceManager.hfpConnectionStateChanged(device, fromState, toState);
        mActiveDeviceManager.profileConnectionStateChanged(
                BluetoothProfile.HEADSET, device, fromState, toState);
        mAdapterService
                .getSilenceDeviceManager()
                .hfpConnectionStateChanged(device, fromState, toState);
@@ -2137,7 +2138,9 @@ public class HeadsetService extends ProfileService {
    private void broadcastActiveDevice(BluetoothDevice device) {
        logD("broadcastActiveDevice: " + device);

        mAdapterService.getActiveDeviceManager().hfpActiveStateChanged(device);
        mAdapterService
                .getActiveDeviceManager()
                .profileActiveDeviceChanged(BluetoothProfile.HEADSET, device);
        mAdapterService.getSilenceDeviceManager().hfpActiveDeviceChanged(device);

        BluetoothStatsLog.write(
Loading