Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(711)

Side by Side Diff: media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java

Issue 1002883002: Fix up if statement curly braces issues. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 package org.chromium.media; 5 package org.chromium.media;
6 6
7 import android.annotation.TargetApi; 7 import android.annotation.TargetApi;
8 import android.bluetooth.BluetoothAdapter; 8 import android.bluetooth.BluetoothAdapter;
9 import android.bluetooth.BluetoothManager; 9 import android.bluetooth.BluetoothManager;
10 import android.content.BroadcastReceiver; 10 import android.content.BroadcastReceiver;
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 /** 227 /**
228 * Saves the initial speakerphone and microphone state. 228 * Saves the initial speakerphone and microphone state.
229 * Populates the list of available audio devices and registers receivers 229 * Populates the list of available audio devices and registers receivers
230 * for broadcast intents related to wired headset and Bluetooth devices. 230 * for broadcast intents related to wired headset and Bluetooth devices.
231 */ 231 */
232 @CalledByNative 232 @CalledByNative
233 private void init() { 233 private void init() {
234 checkIfCalledOnValidThread(); 234 checkIfCalledOnValidThread();
235 if (DEBUG) logd("init"); 235 if (DEBUG) logd("init");
236 if (DEBUG) logDeviceInfo(); 236 if (DEBUG) logDeviceInfo();
237 if (mIsInitialized) 237 if (mIsInitialized) return;
238 return;
239 238
240 // Check if process has MODIFY_AUDIO_SETTINGS and RECORD_AUDIO 239 // Check if process has MODIFY_AUDIO_SETTINGS and RECORD_AUDIO
241 // permissions. Both are required for full functionality. 240 // permissions. Both are required for full functionality.
242 mHasModifyAudioSettingsPermission = hasPermission( 241 mHasModifyAudioSettingsPermission = hasPermission(
243 android.Manifest.permission.MODIFY_AUDIO_SETTINGS); 242 android.Manifest.permission.MODIFY_AUDIO_SETTINGS);
244 if (DEBUG && !mHasModifyAudioSettingsPermission) { 243 if (DEBUG && !mHasModifyAudioSettingsPermission) {
245 logd("MODIFY_AUDIO_SETTINGS permission is missing"); 244 logd("MODIFY_AUDIO_SETTINGS permission is missing");
246 } 245 }
247 mHasRecordAudioPermission = hasPermission( 246 mHasRecordAudioPermission = hasPermission(
248 android.Manifest.permission.RECORD_AUDIO); 247 android.Manifest.permission.RECORD_AUDIO);
(...skipping 20 matching lines...) Expand all
269 } 268 }
270 269
271 /** 270 /**
272 * Unregister all previously registered intent receivers and restore 271 * Unregister all previously registered intent receivers and restore
273 * the stored state (stored in {@link #init()}). 272 * the stored state (stored in {@link #init()}).
274 */ 273 */
275 @CalledByNative 274 @CalledByNative
276 private void close() { 275 private void close() {
277 checkIfCalledOnValidThread(); 276 checkIfCalledOnValidThread();
278 if (DEBUG) logd("close"); 277 if (DEBUG) logd("close");
279 if (!mIsInitialized) 278 if (!mIsInitialized) return;
280 return;
281 279
282 stopObservingVolumeChanges(); 280 stopObservingVolumeChanges();
283 unregisterForWiredHeadsetIntentBroadcast(); 281 unregisterForWiredHeadsetIntentBroadcast();
284 unregisterBluetoothIntentsIfNeeded(); 282 unregisterBluetoothIntentsIfNeeded();
285 283
286 mIsInitialized = false; 284 mIsInitialized = false;
287 } 285 }
288 286
289 /** 287 /**
290 * Saves current audio mode and sets audio mode to MODE_IN_COMMUNICATION 288 * Saves current audio mode and sets audio mode to MODE_IN_COMMUNICATION
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 * 364 *
367 * @param deviceId Unique device ID (integer converted to string) 365 * @param deviceId Unique device ID (integer converted to string)
368 * representing the selected device. This string is empty if the so-called 366 * representing the selected device. This string is empty if the so-called
369 * default device is requested. 367 * default device is requested.
370 * Required permissions: android.Manifest.permission.MODIFY_AUDIO_SETTINGS 368 * Required permissions: android.Manifest.permission.MODIFY_AUDIO_SETTINGS
371 * and android.Manifest.permission.RECORD_AUDIO. 369 * and android.Manifest.permission.RECORD_AUDIO.
372 */ 370 */
373 @CalledByNative 371 @CalledByNative
374 private boolean setDevice(String deviceId) { 372 private boolean setDevice(String deviceId) {
375 if (DEBUG) logd("setDevice: " + deviceId); 373 if (DEBUG) logd("setDevice: " + deviceId);
376 if (!mIsInitialized) 374 if (!mIsInitialized) return false;
377 return false;
378 if (!mHasModifyAudioSettingsPermission || !mHasRecordAudioPermission) { 375 if (!mHasModifyAudioSettingsPermission || !mHasRecordAudioPermission) {
379 Log.w(TAG, "Requires MODIFY_AUDIO_SETTINGS and RECORD_AUDIO"); 376 Log.w(TAG, "Requires MODIFY_AUDIO_SETTINGS and RECORD_AUDIO");
380 Log.w(TAG, "Selected device will not be available for recording"); 377 Log.w(TAG, "Selected device will not be available for recording");
381 return false; 378 return false;
382 } 379 }
383 380
384 int intDeviceId = deviceId.isEmpty() ? DEVICE_DEFAULT : Integer.parseInt (deviceId); 381 int intDeviceId = deviceId.isEmpty() ? DEVICE_DEFAULT : Integer.parseInt (deviceId);
385 382
386 if (intDeviceId == DEVICE_DEFAULT) { 383 if (intDeviceId == DEVICE_DEFAULT) {
387 boolean devices[] = null; 384 boolean devices[] = null;
(...skipping 22 matching lines...) Expand all
410 /** 407 /**
411 * @return the current list of available audio devices. 408 * @return the current list of available audio devices.
412 * Note that this call does not trigger any update of the list of devices, 409 * Note that this call does not trigger any update of the list of devices,
413 * it only copies the current state in to the output array. 410 * it only copies the current state in to the output array.
414 * Required permissions: android.Manifest.permission.MODIFY_AUDIO_SETTINGS 411 * Required permissions: android.Manifest.permission.MODIFY_AUDIO_SETTINGS
415 * and android.Manifest.permission.RECORD_AUDIO. 412 * and android.Manifest.permission.RECORD_AUDIO.
416 */ 413 */
417 @CalledByNative 414 @CalledByNative
418 private AudioDeviceName[] getAudioInputDeviceNames() { 415 private AudioDeviceName[] getAudioInputDeviceNames() {
419 if (DEBUG) logd("getAudioInputDeviceNames"); 416 if (DEBUG) logd("getAudioInputDeviceNames");
420 if (!mIsInitialized) 417 if (!mIsInitialized) return null;
421 return null;
422 if (!mHasModifyAudioSettingsPermission || !mHasRecordAudioPermission) { 418 if (!mHasModifyAudioSettingsPermission || !mHasRecordAudioPermission) {
423 Log.w(TAG, "Requires MODIFY_AUDIO_SETTINGS and RECORD_AUDIO"); 419 Log.w(TAG, "Requires MODIFY_AUDIO_SETTINGS and RECORD_AUDIO");
424 Log.w(TAG, "No audio device will be available for recording"); 420 Log.w(TAG, "No audio device will be available for recording");
425 return null; 421 return null;
426 } 422 }
427 423
428 boolean devices[] = null; 424 boolean devices[] = null;
429 synchronized (mLock) { 425 synchronized (mLock) {
430 devices = mAudioDevices.clone(); 426 devices = mAudioDevices.clone();
431 } 427 }
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1014 /** 1010 /**
1015 * For now, just log the state change but the idea is that we should 1011 * For now, just log the state change but the idea is that we should
1016 * notify a registered state change listener (if any) that there has 1012 * notify a registered state change listener (if any) that there has
1017 * been a change in the state. 1013 * been a change in the state.
1018 * TODO(henrika): add support for state change listener. 1014 * TODO(henrika): add support for state change listener.
1019 */ 1015 */
1020 private void reportUpdate() { 1016 private void reportUpdate() {
1021 synchronized (mLock) { 1017 synchronized (mLock) {
1022 List<String> devices = new ArrayList<String>(); 1018 List<String> devices = new ArrayList<String>();
1023 for (int i = 0; i < DEVICE_COUNT; ++i) { 1019 for (int i = 0; i < DEVICE_COUNT; ++i) {
1024 if (mAudioDevices[i]) 1020 if (mAudioDevices[i]) devices.add(DEVICE_NAMES[i]);
1025 devices.add(DEVICE_NAMES[i]);
1026 } 1021 }
1027 if (DEBUG) { 1022 if (DEBUG) {
1028 logd("reportUpdate: requested=" + mRequestedAudioDevice 1023 logd("reportUpdate: requested=" + mRequestedAudioDevice
1029 + ", btSco=" + mBluetoothScoState 1024 + ", btSco=" + mBluetoothScoState
1030 + ", devices=" + devices); 1025 + ", devices=" + devices);
1031 } 1026 }
1032 } 1027 }
1033 } 1028 }
1034 1029
1035 /** Information about the current build, taken from system properties. */ 1030 /** Information about the current build, taken from system properties. */
(...skipping 15 matching lines...) Expand all
1051 } 1046 }
1052 1047
1053 /** Trivial helper method for error logging */ 1048 /** Trivial helper method for error logging */
1054 private static void loge(String msg) { 1049 private static void loge(String msg) {
1055 Log.e(TAG, msg); 1050 Log.e(TAG, msg);
1056 } 1051 }
1057 1052
1058 /** Start thread which observes volume changes on the voice stream. */ 1053 /** Start thread which observes volume changes on the voice stream. */
1059 private void startObservingVolumeChanges() { 1054 private void startObservingVolumeChanges() {
1060 if (DEBUG) logd("startObservingVolumeChanges"); 1055 if (DEBUG) logd("startObservingVolumeChanges");
1061 if (mSettingsObserverThread != null) 1056 if (mSettingsObserverThread != null) return;
1062 return;
1063 mSettingsObserverThread = new HandlerThread("SettingsObserver"); 1057 mSettingsObserverThread = new HandlerThread("SettingsObserver");
1064 mSettingsObserverThread.start(); 1058 mSettingsObserverThread.start();
1065 1059
1066 mSettingsObserver = new ContentObserver( 1060 mSettingsObserver = new ContentObserver(
1067 new Handler(mSettingsObserverThread.getLooper())) { 1061 new Handler(mSettingsObserverThread.getLooper())) {
1068 1062
1069 @Override 1063 @Override
1070 public void onChange(boolean selfChange) { 1064 public void onChange(boolean selfChange) {
1071 if (DEBUG) logd("SettingsObserver.onChange: " + selfChange); 1065 if (DEBUG) logd("SettingsObserver.onChange: " + selfChange);
1072 super.onChange(selfChange); 1066 super.onChange(selfChange);
(...skipping 14 matching lines...) Expand all
1087 } 1081 }
1088 }; 1082 };
1089 1083
1090 mContentResolver.registerContentObserver( 1084 mContentResolver.registerContentObserver(
1091 Settings.System.CONTENT_URI, true, mSettingsObserver); 1085 Settings.System.CONTENT_URI, true, mSettingsObserver);
1092 } 1086 }
1093 1087
1094 /** Quit observer thread and stop listening for volume changes. */ 1088 /** Quit observer thread and stop listening for volume changes. */
1095 private void stopObservingVolumeChanges() { 1089 private void stopObservingVolumeChanges() {
1096 if (DEBUG) logd("stopObservingVolumeChanges"); 1090 if (DEBUG) logd("stopObservingVolumeChanges");
1097 if (mSettingsObserverThread == null) 1091 if (mSettingsObserverThread == null) return;
1098 return;
1099 1092
1100 mContentResolver.unregisterContentObserver(mSettingsObserver); 1093 mContentResolver.unregisterContentObserver(mSettingsObserver);
1101 mSettingsObserver = null; 1094 mSettingsObserver = null;
1102 1095
1103 mSettingsObserverThread.quit(); 1096 mSettingsObserverThread.quit();
1104 try { 1097 try {
1105 mSettingsObserverThread.join(); 1098 mSettingsObserverThread.join();
1106 } catch (InterruptedException e) { 1099 } catch (InterruptedException e) {
1107 Log.e(TAG, "Thread.join() exception: ", e); 1100 Log.e(TAG, "Thread.join() exception: ", e);
1108 } 1101 }
1109 mSettingsObserverThread = null; 1102 mSettingsObserverThread = null;
1110 } 1103 }
1111 1104
1112 private native void nativeSetMute(long nativeAudioManagerAndroid, boolean mu ted); 1105 private native void nativeSetMute(long nativeAudioManagerAndroid, boolean mu ted);
1113 } 1106 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698