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

Commit 8336dbda authored by Marie Janssen's avatar Marie Janssen
Browse files

AVRCP: Fix crash when app change during shutdown

If you turned off Bluetooth and then immediately changed the app that
media keys went to, a NPE could be generated.

Test: shutdown bt then quick-switch to telecom immediately
Change-Id: Ifbca7446d94aa411b642b42131f603c8f9d1c31e
Bug: 37865933
parent 5a142ac8
Loading
Loading
Loading
Loading
+6 −4
Original line number Original line Diff line number Diff line
@@ -334,16 +334,18 @@ public final class Avrcp {


    public void doQuit() {
    public void doQuit() {
        if (DEBUG) Log.d(TAG, "doQuit");
        if (DEBUG) Log.d(TAG, "doQuit");
        if (mMediaController != null) mMediaController.unregisterCallback(mMediaControllerCb);
        if (mMediaSessionManager != null) {
            mMediaSessionManager.setCallback(null, null);
            mMediaSessionManager.removeOnActiveSessionsChangedListener(mActiveSessionListener);
        }

        mHandler.removeCallbacksAndMessages(null);
        mHandler.removeCallbacksAndMessages(null);
        Looper looper = mHandler.getLooper();
        Looper looper = mHandler.getLooper();
        if (looper != null) {
        if (looper != null) {
            looper.quit();
            looper.quit();
        }
        }


        if (mMediaController != null) mMediaController.unregisterCallback(mMediaControllerCb);

        mMediaSessionManager.removeOnActiveSessionsChangedListener(mActiveSessionListener);

        mHandler = null;
        mHandler = null;
        mContext.unregisterReceiver(mAvrcpReceiver);
        mContext.unregisterReceiver(mAvrcpReceiver);
        mContext.unregisterReceiver(mBootReceiver);
        mContext.unregisterReceiver(mBootReceiver);