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

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

Issue 93233003: Mute audio when volume is zero on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: henrika@'s comment Created 7 years 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/android/opensles_output.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java
diff --git a/media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java b/media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java
index db674f52d3b9f2a0a43978447f7078cdb5ef1671..93171a76975b7398ecef3e276e5b0eba9f98b5ca 100644
--- a/media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java
+++ b/media/base/android/java/src/org/chromium/media/AudioManagerAndroid.java
@@ -7,16 +7,23 @@ package org.chromium.media;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
+import android.database.ContentObserver;
import android.media.AudioFormat;
import android.media.AudioManager;
import android.media.AudioRecord;
import android.media.AudioTrack;
+import android.net.Uri;
import android.os.Build;
+import android.os.Handler;
+import android.os.Looper;
import android.os.Process;
+import android.provider.Settings;
+import android.provider.Settings.System;
import android.util.Log;
import java.util.Arrays;
@@ -106,6 +113,7 @@ class AudioManagerAndroid {
private final AudioManager mAudioManager;
private final Context mContext;
+ private final long mNativeAudioManagerAndroid;
private boolean mHasBluetoothPermission = false;
private boolean mIsInitialized = false;
@@ -117,18 +125,28 @@ class AudioManagerAndroid {
// Contains a list of currently available audio devices.
private boolean[] mAudioDevices = new boolean[DEVICE_COUNT];
+ private final ContentResolver mContentResolver;
+ private SettingsObserver mSettingsObserver = null;
+ private SettingsObserverThread mSettingsObserverThread = null;
+ private int mCurrentVolume;
+ private final Object mSettingsObserverLock = new Object();
+
// Broadcast receiver for wired headset intent broadcasts.
private BroadcastReceiver mWiredHeadsetReceiver;
/** Construction */
@CalledByNative
- private static AudioManagerAndroid createAudioManagerAndroid(Context context) {
- return new AudioManagerAndroid(context);
+ private static AudioManagerAndroid createAudioManagerAndroid(
+ Context context,
+ long nativeAudioManagerAndroid) {
+ return new AudioManagerAndroid(context, nativeAudioManagerAndroid);
}
- private AudioManagerAndroid(Context context) {
+ private AudioManagerAndroid(Context context, long nativeAudioManagerAndroid) {
mContext = context;
+ mNativeAudioManagerAndroid = nativeAudioManagerAndroid;
mAudioManager = (AudioManager)mContext.getSystemService(Context.AUDIO_SERVICE);
+ mContentResolver = mContext.getContentResolver();
}
/**
@@ -174,6 +192,16 @@ class AudioManagerAndroid {
initBluetooth();
mIsInitialized = true;
+
+ mSettingsObserverThread = new SettingsObserverThread();
+ mSettingsObserverThread.start();
+ synchronized(mSettingsObserverLock) {
+ try {
+ mSettingsObserverLock.wait();
+ } catch (InterruptedException e) {
+ Log.e(TAG, "unregisterHeadsetReceiver exception: " + e.getMessage());
+ }
+ }
}
/**
@@ -185,6 +213,14 @@ class AudioManagerAndroid {
if (!mIsInitialized)
return;
+ if (mSettingsObserverThread != null ) {
+ mSettingsObserverThread = null;
+ }
+ if (mSettingsObserver != null) {
+ mContentResolver.unregisterContentObserver(mSettingsObserver);
+ mSettingsObserver = null;
+ }
+
unregisterForWiredHeadsetIntentBroadcast();
// Restore previously stored audio states.
@@ -553,4 +589,40 @@ class AudioManagerAndroid {
private void loge(String msg) {
Log.e(TAG, msg);
}
+
+ private class SettingsObserver extends ContentObserver {
+ SettingsObserver() {
+ super(new Handler());
+ mContentResolver.registerContentObserver(Settings.System.CONTENT_URI, true, this);
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ int volume = mAudioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL);
+ nativeSetMute(mNativeAudioManagerAndroid, (volume == 0));
+ }
+ }
+
+ private native void nativeSetMute(long nativeAudioManagerAndroid, boolean muted);
+
+ private class SettingsObserverThread extends Thread {
+ SettingsObserverThread() {
+ super("SettinsObserver");
+ }
+
+ @Override
+ public void run() {
+ // Set this thread up so the handler will work on it.
+ Looper.prepare();
+
+ synchronized(mSettingsObserverLock) {
+ mSettingsObserver = new SettingsObserver();
+ mSettingsObserverLock.notify();
+ }
+
+ // Listen for volume change.
+ Looper.loop();
+ }
+ }
}
« no previous file with comments | « media/audio/android/opensles_output.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698