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

Commit bf910468 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

UsbService: Fix problem detecting audio accessory mode when connected at boot



Change-Id: Ie0e23b8ec88f1dd29bb956bc1d21c241f3545059
Signed-off-by: default avatarMike Lockwood <lockwood@google.com>
parent 7c38077e
Loading
Loading
Loading
Loading
+23 −26
Original line number Diff line number Diff line
@@ -322,8 +322,6 @@ public class UsbDeviceManager {
                String state = FileUtils.readTextFile(new File(STATE_PATH), 0, null).trim();
                updateState(state);
                mAdbEnabled = containsFunction(mCurrentFunctions, UsbManager.USB_FUNCTION_ADB);
                mAudioSourceEnabled = containsFunction(mCurrentFunctions,
                        UsbManager.USB_FUNCTION_AUDIO_SOURCE);

                // Upgrade step for previous versions that used persist.service.adb.enable
                String value = SystemProperties.get("persist.service.adb.enable", "");
@@ -537,7 +535,10 @@ public class UsbDeviceManager {
            mContext.sendStickyBroadcast(intent);
        }

        private void updateAudioSourceFunction(boolean enabled) {
        private void updateAudioSourceFunction() {
            boolean enabled = containsFunction(mCurrentFunctions,
                    UsbManager.USB_FUNCTION_AUDIO_SOURCE);
            if (enabled != mAudioSourceEnabled) {
                // send a sticky broadcast containing current USB state
                Intent intent = new Intent(Intent.ACTION_USB_AUDIO_ACCESSORY_PLUG);
                intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
@@ -554,10 +555,10 @@ public class UsbDeviceManager {
                        Slog.e(TAG, "could not open audio source PCM file", e);
                    }
                }

                mContext.sendStickyBroadcast(intent);
                mAudioSourceEnabled = enabled;
            }
        }

        @Override
        public void handleMessage(Message msg) {
@@ -578,11 +579,7 @@ public class UsbDeviceManager {
                    }
                    if (mBootCompleted) {
                        updateUsbState();
                        boolean audioSourceEnabled = containsFunction(mCurrentFunctions,
                                UsbManager.USB_FUNCTION_AUDIO_SOURCE);
                        if (audioSourceEnabled != mAudioSourceEnabled) {
                            updateAudioSourceFunction(audioSourceEnabled);
                        }
                        updateAudioSourceFunction();
                    }
                    break;
                case MSG_ENABLE_ADB:
@@ -597,13 +594,13 @@ public class UsbDeviceManager {
                    updateUsbNotification();
                    updateAdbNotification();
                    updateUsbState();
                    updateAudioSourceFunction();
                    break;
                case MSG_BOOT_COMPLETED:
                    mBootCompleted = true;
                    if (mCurrentAccessory != null) {
                        mSettingsManager.accessoryAttached(mCurrentAccessory);
                    }
                    updateAudioSourceFunction(mAudioSourceEnabled);
                    break;
            }
        }