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

Commit 22c2ce9c authored by David Lin's avatar David Lin
Browse files

Fix issue with USB headset not being recognized when boots



This change removes the use of obsoleted AudioManager.isWiredHeadsetOn API.

Bug: 62475394
Test: manual headset and voice call test
Change-Id: I81fb37fd26ab81b927b1cc23951c5d4e2ee6724e
Signed-off-by: default avatarDavid Lin <dtwlin@google.com>
parent f1636500
Loading
Loading
Loading
Loading
+20 −12
Original line number Diff line number Diff line
@@ -60,17 +60,7 @@ public class WiredHeadsetManager {
        }

        private void updateHeadsetStatus() {
            AudioDeviceInfo[] devices = mAudioManager.getDevices(AudioManager.GET_DEVICES_ALL);
            boolean isPluggedIn = false;
            for (AudioDeviceInfo device : devices) {
                switch (device.getType()) {
                    case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
                    case AudioDeviceInfo.TYPE_WIRED_HEADSET:
                    case AudioDeviceInfo.TYPE_USB_DEVICE:
                    case AudioDeviceInfo.TYPE_USB_HEADSET:
                        isPluggedIn = true;
                }
            }
            final boolean isPluggedIn = isWiredHeadsetPluggedIn();

            Log.i(WiredHeadsetManager.this, "ACTION_HEADSET_PLUG event, plugged in: %b, ",
                    isPluggedIn);
@@ -90,7 +80,7 @@ public class WiredHeadsetManager {

    public WiredHeadsetManager(Context context) {
        mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        mIsPluggedIn = mAudioManager.isWiredHeadsetOn();
        mIsPluggedIn = isWiredHeadsetPluggedIn();

        mAudioManager.registerAudioDeviceCallback(new WiredHeadsetCallback(), null);
    }
@@ -111,6 +101,24 @@ public class WiredHeadsetManager {
        return mIsPluggedIn;
    }

    private boolean isWiredHeadsetPluggedIn() {
        AudioDeviceInfo[] devices = mAudioManager.getDevices(AudioManager.GET_DEVICES_ALL);
        boolean isPluggedIn = false;
        for (AudioDeviceInfo device : devices) {
            switch (device.getType()) {
                case AudioDeviceInfo.TYPE_WIRED_HEADPHONES:
                case AudioDeviceInfo.TYPE_WIRED_HEADSET:
                case AudioDeviceInfo.TYPE_USB_HEADSET:
                case AudioDeviceInfo.TYPE_USB_DEVICE:
                    isPluggedIn = true;
            }
            if (isPluggedIn) {
                break;
            }
        }
        return isPluggedIn;
    }

    private void onHeadsetPluggedInChanged(boolean isPluggedIn) {
        if (mIsPluggedIn != isPluggedIn) {
            Log.v(this, "onHeadsetPluggedInChanged, mIsPluggedIn: %b -> %b", mIsPluggedIn,