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

Commit 6950c491 authored by Yuyang Huang's avatar Yuyang Huang
Browse files

Skip mAudioManager callback if it is null

When HearingAidService (in thread A) calls `Stop`, it unregisters callback for `onAudioDevicesRemoved` and sets `mAudioManager` to null.
The `onAudioDevicesRemoved` callback goes to AudioManager's message queue (in thread B), and when AudioManager starts to process it, it finds `mAudioManager` is null, and crashes.

Bug: 277851145
Change-Id: I685015efb1d5412479875580b82cfefa3611263a
Test: atest avatar
parent c4351876
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -748,7 +748,11 @@ public class HearingAidService extends ProfileService {
                    if (DBG) {
                    if (DBG) {
                        Log.d(TAG, " onAudioDevicesRemoved: device type: " + deviceInfo.getType());
                        Log.d(TAG, " onAudioDevicesRemoved: device type: " + deviceInfo.getType());
                    }
                    }
                    if (mAudioManager != null) {
                        mAudioManager.unregisterAudioDeviceCallback(this);
                        mAudioManager.unregisterAudioDeviceCallback(this);
                    } else {
                        Log.w(TAG, "onAudioDevicesRemoved: mAudioManager is null");
                    }
                }
                }
            }
            }
        }
        }
@@ -764,7 +768,11 @@ public class HearingAidService extends ProfileService {
                    if (DBG) {
                    if (DBG) {
                        Log.d(TAG, " onAudioDevicesAdded: device type: " + deviceInfo.getType());
                        Log.d(TAG, " onAudioDevicesAdded: device type: " + deviceInfo.getType());
                    }
                    }
                    if (mAudioManager != null) {
                        mAudioManager.unregisterAudioDeviceCallback(this);
                        mAudioManager.unregisterAudioDeviceCallback(this);
                    } else {
                        Log.w(TAG, "onAudioDevicesAdded: mAudioManager is null");
                    }
                }
                }
            }
            }
        }
        }