Commit 30e5fe97 authored by benm@chromium.org's avatar benm@chromium.org

[Android] Use exceptions rather that Log.wtf on Android

AudioManagerAndroid uses Log.wtf to signal error conditions. However,
the undefined behavior of this function depending on device
configuration makes debugging difficult. Throw exceptions instead.

Review URL: https://codereview.chromium.org/340083002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278807 0039d316-1c4b-4281-b951-d872f2087c98
parent e41d59c2
...@@ -313,8 +313,7 @@ class AudioManagerAndroid { ...@@ -313,8 +313,7 @@ class AudioManagerAndroid {
if (on) { if (on) {
if (mSavedAudioMode != AudioManager.MODE_INVALID) { if (mSavedAudioMode != AudioManager.MODE_INVALID) {
Log.wtf(TAG, "Audio mode has already been set"); throw new IllegalStateException("Audio mode has already been set");
return;
} }
// Store the current audio mode the first time we try to // Store the current audio mode the first time we try to
...@@ -322,8 +321,9 @@ class AudioManagerAndroid { ...@@ -322,8 +321,9 @@ class AudioManagerAndroid {
try { try {
mSavedAudioMode = mAudioManager.getMode(); mSavedAudioMode = mAudioManager.getMode();
} catch (SecurityException e) { } catch (SecurityException e) {
Log.wtf(TAG, "getMode exception: ", e);
logDeviceInfo(); logDeviceInfo();
throw e;
} }
// Store microphone mute state and speakerphone state so it can // Store microphone mute state and speakerphone state so it can
...@@ -334,8 +334,8 @@ class AudioManagerAndroid { ...@@ -334,8 +334,8 @@ class AudioManagerAndroid {
try { try {
mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); mAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
} catch (SecurityException e) { } catch (SecurityException e) {
Log.wtf(TAG, "setMode exception: ", e);
logDeviceInfo(); logDeviceInfo();
throw e;
} }
// Start observing volume changes to detect when the // Start observing volume changes to detect when the
...@@ -347,8 +347,7 @@ class AudioManagerAndroid { ...@@ -347,8 +347,7 @@ class AudioManagerAndroid {
} else { } else {
if (mSavedAudioMode == AudioManager.MODE_INVALID) { if (mSavedAudioMode == AudioManager.MODE_INVALID) {
Log.wtf(TAG, "Audio mode has not yet been set"); throw new IllegalStateException("Audio mode has not yet been set");
return;
} }
stopObservingVolumeChanges(); stopObservingVolumeChanges();
...@@ -362,8 +361,8 @@ class AudioManagerAndroid { ...@@ -362,8 +361,8 @@ class AudioManagerAndroid {
try { try {
mAudioManager.setMode(mSavedAudioMode); mAudioManager.setMode(mSavedAudioMode);
} catch (SecurityException e) { } catch (SecurityException e) {
Log.wtf(TAG, "setMode exception: ", e);
logDeviceInfo(); logDeviceInfo();
throw e;
} }
mSavedAudioMode = AudioManager.MODE_INVALID; mSavedAudioMode = AudioManager.MODE_INVALID;
} }
...@@ -541,12 +540,12 @@ class AudioManagerAndroid { ...@@ -541,12 +540,12 @@ class AudioManagerAndroid {
} }
/** /**
* Helper method for debugging purposes. Logs message if method is not * Helper method for debugging purposes. Ensures that method is
* called on same thread as this object was created on. * called on same thread as this object was created on.
*/ */
private void checkIfCalledOnValidThread() { private void checkIfCalledOnValidThread() {
if (DEBUG && !mNonThreadSafe.calledOnValidThread()) { if (DEBUG && !mNonThreadSafe.calledOnValidThread()) {
Log.wtf(TAG, "Method is not called on valid thread"); throw new IllegalStateException("Method is not called on valid thread");
} }
} }
...@@ -655,35 +654,19 @@ class AudioManagerAndroid { ...@@ -655,35 +654,19 @@ class AudioManagerAndroid {
if (runningOnJellyBeanMR2OrHigher()) { if (runningOnJellyBeanMR2OrHigher()) {
// Use BluetoothManager to get the BluetoothAdapter for // Use BluetoothManager to get the BluetoothAdapter for
// Android 4.3 and above. // Android 4.3 and above.
try {
BluetoothManager btManager = BluetoothManager btManager =
(BluetoothManager)mContext.getSystemService( (BluetoothManager)mContext.getSystemService(
Context.BLUETOOTH_SERVICE); Context.BLUETOOTH_SERVICE);
btAdapter = btManager.getAdapter(); btAdapter = btManager.getAdapter();
} catch (Exception e) {
Log.wtf(TAG, "BluetoothManager.getAdapter exception", e);
return false;
}
} else { } else {
// Use static method for Android 4.2 and below to get the // Use static method for Android 4.2 and below to get the
// BluetoothAdapter. // BluetoothAdapter.
try {
btAdapter = BluetoothAdapter.getDefaultAdapter(); btAdapter = BluetoothAdapter.getDefaultAdapter();
} catch (Exception e) {
Log.wtf(TAG, "BluetoothAdapter.getDefaultAdapter exception", e);
return false;
}
} }
int profileConnectionState; int profileConnectionState;
try {
profileConnectionState = btAdapter.getProfileConnectionState( profileConnectionState = btAdapter.getProfileConnectionState(
android.bluetooth.BluetoothProfile.HEADSET); android.bluetooth.BluetoothProfile.HEADSET);
} catch (Exception e) {
Log.wtf(TAG, "BluetoothAdapter.getProfileConnectionState exception", e);
profileConnectionState =
android.bluetooth.BluetoothProfile.STATE_DISCONNECTED;
}
// Ensure that Bluetooth is enabled and that a device which supports the // Ensure that Bluetooth is enabled and that a device which supports the
// headset and handsfree profile is connected. // headset and handsfree profile is connected.
...@@ -1088,8 +1071,8 @@ class AudioManagerAndroid { ...@@ -1088,8 +1071,8 @@ class AudioManagerAndroid {
// Ensure that the observer is activated during communication mode. // Ensure that the observer is activated during communication mode.
if (mAudioManager.getMode() != AudioManager.MODE_IN_COMMUNICATION) { if (mAudioManager.getMode() != AudioManager.MODE_IN_COMMUNICATION) {
Log.wtf(TAG, "Only enable SettingsObserver in COMM mode"); throw new IllegalStateException(
return; "Only enable SettingsObserver in COMM mode");
} }
// Get stream volume for the voice stream and deliver callback if // Get stream volume for the voice stream and deliver callback if
...@@ -1120,7 +1103,7 @@ class AudioManagerAndroid { ...@@ -1120,7 +1103,7 @@ class AudioManagerAndroid {
try { try {
mSettingsObserverThread.join(); mSettingsObserverThread.join();
} catch (InterruptedException e) { } catch (InterruptedException e) {
Log.wtf(TAG, "Thread.join() exception: ", e); Log.e(TAG, "Thread.join() exception: ", e);
} }
mSettingsObserverThread = null; mSettingsObserverThread = null;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment