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

Commit afa5f460 authored by Jack Pham's avatar Jack Pham Committed by Jack Pham
Browse files

Fix null pointer exception if USBPort is removed

If for some reason a USB port instance is removed, UsbPortManager
handles this by broadcasting a UsbManager.ACTION_USB_PORT_CHANGED
intent with null as the UsbPortStatus argument, leading to a null
pointer exception after UsbDeviceManager receives it. Take care of
this by checking for null in UsbHandler.updateHostState().

Bug: 156230008
Change-Id: Ia8936358c61af5b537d1eb722a55851e0061b381
parent 963c11e3
Loading
Loading
Loading
Loading
+24 −13
Original line number Diff line number Diff line
@@ -832,11 +832,13 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                    boolean prevHostConnected = mHostConnected;
                    UsbPort port = (UsbPort) args.arg1;
                    UsbPortStatus status = (UsbPortStatus) args.arg2;

                    if (status != null) {
                        mHostConnected = status.getCurrentDataRole() == DATA_ROLE_HOST;
                        mSourcePower = status.getCurrentPowerRole() == POWER_ROLE_SOURCE;
                        mSinkPower = status.getCurrentPowerRole() == POWER_ROLE_SINK;
                        mAudioAccessoryConnected = (status.getCurrentMode() == MODE_AUDIO_ACCESSORY);
                    mAudioAccessorySupported = port.isModeSupported(MODE_AUDIO_ACCESSORY);

                        // Ideally we want to see if PR_SWAP and DR_SWAP is supported.
                        // But, this should be suffice, since, all four combinations are only supported
                        // when PR_SWAP and DR_SWAP are supported.
@@ -846,6 +848,15 @@ public class UsbDeviceManager implements ActivityTaskManagerInternal.ScreenObser
                                && status.isRoleCombinationSupported(POWER_ROLE_SOURCE,
                                DATA_ROLE_DEVICE)
                                && status.isRoleCombinationSupported(POWER_ROLE_SINK, DATA_ROLE_DEVICE);
                    } else {
                        mHostConnected = false;
                        mSourcePower = false;
                        mSinkPower = false;
                        mAudioAccessoryConnected = false;
                        mSupportsAllCombinations = false;
                    }

                    mAudioAccessorySupported = port.isModeSupported(MODE_AUDIO_ACCESSORY);

                    args.recycle();
                    updateUsbNotification(false);