OSDN Git Service

Fix exception in AudioService when no BT Headset is connected.
authorAndre Eisenbach <eisenbach@google.com>
Wed, 29 Oct 2014 00:03:18 +0000 (17:03 -0700)
committerAndre Eisenbach <eisenbach@google.com>
Wed, 29 Oct 2014 16:56:41 +0000 (09:56 -0700)
If AudioManager.startBluetoothSco() is invoked with no Bluetooth Headset
connected, a NullPointerException will ensue.

Added check to make sure mBluetoothHeadsetDevice is set before accessing
it.

Bug: 17601845
Change-Id: Ia00bfffbea5484230b11a74787fe3309c18f824d

media/java/android/media/AudioService.java

index a84fe44..6a69517 100644 (file)
@@ -2574,13 +2574,17 @@ public class AudioService extends IAudioService.Stub {
                             if (mScoAudioState == SCO_STATE_INACTIVE) {
                                 mScoAudioMode = scoAudioMode;
                                 if (scoAudioMode == SCO_MODE_UNDEFINED) {
-                                    mScoAudioMode = new Integer(Settings.Global.getInt(
-                                                            mContentResolver,
-                                                            "bluetooth_sco_channel_"+
-                                                            mBluetoothHeadsetDevice.getAddress(),
-                                                            SCO_MODE_VIRTUAL_CALL));
-                                    if (mScoAudioMode > SCO_MODE_MAX || mScoAudioMode < 0) {
-                                        mScoAudioMode = SCO_MODE_VIRTUAL_CALL;
+                                    if (mBluetoothHeadsetDevice != null) {
+                                        mScoAudioMode = new Integer(Settings.Global.getInt(
+                                                                mContentResolver,
+                                                                "bluetooth_sco_channel_"+
+                                                                mBluetoothHeadsetDevice.getAddress(),
+                                                                SCO_MODE_VIRTUAL_CALL));
+                                        if (mScoAudioMode > SCO_MODE_MAX || mScoAudioMode < 0) {
+                                            mScoAudioMode = SCO_MODE_VIRTUAL_CALL;
+                                        }
+                                    } else {
+                                        mScoAudioMode = SCO_MODE_RAW;
                                     }
                                 }
                                 if (mBluetoothHeadset != null && mBluetoothHeadsetDevice != null) {