FocusRequester: fix NPE
Fix NPE and potential race condition in FocusRequester.dispatchFocusResultFromExtPolicy where mFocusDispatcher was checked against null, but the method didn't return in that case. Bug: 142278598 Test: Android Auto with phone call and custom focus policy Change-Id: I88447a255132c94f8c2fbf97a1e3ee88f6d2e993
This commit is contained in:
@@ -437,7 +437,8 @@ public class FocusRequester {
|
||||
}
|
||||
|
||||
int dispatchFocusChange(int focusChange) {
|
||||
if (mFocusDispatcher == null) {
|
||||
final IAudioFocusDispatcher fd = mFocusDispatcher;
|
||||
if (fd == null) {
|
||||
if (MediaFocusControl.DEBUG) { Log.e(TAG, "dispatchFocusChange: no focus dispatcher"); }
|
||||
return AudioManager.AUDIOFOCUS_REQUEST_FAILED;
|
||||
}
|
||||
@@ -457,7 +458,7 @@ public class FocusRequester {
|
||||
mFocusLossReceived = focusChange;
|
||||
}
|
||||
try {
|
||||
mFocusDispatcher.dispatchAudioFocusChange(focusChange, mClientId);
|
||||
fd.dispatchAudioFocusChange(focusChange, mClientId);
|
||||
} catch (android.os.RemoteException e) {
|
||||
Log.e(TAG, "dispatchFocusChange: error talking to focus listener " + mClientId, e);
|
||||
return AudioManager.AUDIOFOCUS_REQUEST_FAILED;
|
||||
@@ -466,16 +467,18 @@ public class FocusRequester {
|
||||
}
|
||||
|
||||
void dispatchFocusResultFromExtPolicy(int requestResult) {
|
||||
if (mFocusDispatcher == null) {
|
||||
final IAudioFocusDispatcher fd = mFocusDispatcher;
|
||||
if (fd == null) {
|
||||
if (MediaFocusControl.DEBUG) {
|
||||
Log.e(TAG, "dispatchFocusResultFromExtPolicy: no focus dispatcher");
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (DEBUG) {
|
||||
Log.v(TAG, "dispatching result" + requestResult + " to " + mClientId);
|
||||
}
|
||||
try {
|
||||
mFocusDispatcher.dispatchFocusResultFromExtPolicy(requestResult, mClientId);
|
||||
fd.dispatchFocusResultFromExtPolicy(requestResult, mClientId);
|
||||
} catch (android.os.RemoteException e) {
|
||||
Log.e(TAG, "dispatchFocusResultFromExtPolicy: error talking to focus listener"
|
||||
+ mClientId, e);
|
||||
|
||||
Reference in New Issue
Block a user