summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2009-11-12 22:49:51 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2009-11-12 22:49:51 -0800
commite8302a64c7fb2e12bd04ac70114682c3a1260d03 (patch)
treededa93cfee3b09e28c7fbd2e0de76fd479c819da
parent2058977493230bec659e94756b1220b80fa7874a (diff)
parent1aa9f3cac31a7c2b50fcb3c9259cead8d638ae54 (diff)
downloadframeworks_base-e8302a64c7fb2e12bd04ac70114682c3a1260d03.zip
frameworks_base-e8302a64c7fb2e12bd04ac70114682c3a1260d03.tar.gz
frameworks_base-e8302a64c7fb2e12bd04ac70114682c3a1260d03.tar.bz2
am 1aa9f3ca: Merge change I923d7d72 into eclair
Merge commit '1aa9f3cac31a7c2b50fcb3c9259cead8d638ae54' into eclair-plus-aosp * commit '1aa9f3cac31a7c2b50fcb3c9259cead8d638ae54': Fix issue 2242614: Wired headset not recognized: bogus "state" in ACTION_HEADSET_PLUG broadcast.
-rw-r--r--core/java/android/content/Intent.java1
-rw-r--r--include/media/AudioSystem.h6
-rw-r--r--media/java/android/media/AudioService.java103
-rw-r--r--media/java/android/media/AudioSystem.java3
-rw-r--r--services/java/com/android/server/HeadsetObserver.java32
5 files changed, 53 insertions, 92 deletions
diff --git a/core/java/android/content/Intent.java b/core/java/android/content/Intent.java
index 398f211..0085f26 100644
--- a/core/java/android/content/Intent.java
+++ b/core/java/android/content/Intent.java
@@ -1678,6 +1678,7 @@ public class Intent implements Parcelable {
* <ul>
* <li><em>state</em> - 0 for unplugged, 1 for plugged. </li>
* <li><em>name</em> - Headset type, human readable string </li>
+ * <li><em>microphone</em> - 1 if headset has a microphone, 0 otherwise </li>
* </ul>
* </ul>
*/
diff --git a/include/media/AudioSystem.h b/include/media/AudioSystem.h
index e066177..bc3dd36 100644
--- a/include/media/AudioSystem.h
+++ b/include/media/AudioSystem.h
@@ -239,15 +239,11 @@ public:
DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100,
DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200,
DEVICE_OUT_AUX_DIGITAL = 0x400,
- DEVICE_OUT_FM_HEADPHONE = 0x800,
- DEVICE_OUT_FM_SPEAKER = 0x1000,
- DEVICE_OUT_TTY = 0x2000,
DEVICE_OUT_DEFAULT = 0x8000,
DEVICE_OUT_ALL = (DEVICE_OUT_EARPIECE | DEVICE_OUT_SPEAKER | DEVICE_OUT_WIRED_HEADSET |
DEVICE_OUT_WIRED_HEADPHONE | DEVICE_OUT_BLUETOOTH_SCO | DEVICE_OUT_BLUETOOTH_SCO_HEADSET |
DEVICE_OUT_BLUETOOTH_SCO_CARKIT | DEVICE_OUT_BLUETOOTH_A2DP | DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
- DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL | DEVICE_OUT_FM_HEADPHONE |
- DEVICE_OUT_FM_SPEAKER | DEVICE_OUT_TTY | DEVICE_OUT_DEFAULT),
+ DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER | DEVICE_OUT_AUX_DIGITAL | DEVICE_OUT_DEFAULT),
// input devices
DEVICE_IN_COMMUNICATION = 0x10000,
diff --git a/media/java/android/media/AudioService.java b/media/java/android/media/AudioService.java
index 58a0bba..3b40612 100644
--- a/media/java/android/media/AudioService.java
+++ b/media/java/android/media/AudioService.java
@@ -222,15 +222,6 @@ public class AudioService extends IAudioService.Stub {
// Broadcast receiver for device connections intent broadcasts
private final BroadcastReceiver mReceiver = new AudioServiceBroadcastReceiver();
- //TODO: use common definitions with HeadsetObserver
- private static final int BIT_HEADSET = (1 << 0);
- private static final int BIT_HEADSET_NO_MIC = (1 << 1);
- private static final int BIT_TTY = (1 << 2);
- private static final int BIT_FM_HEADSET = (1 << 3);
- private static final int BIT_FM_SPEAKER = (1 << 4);
-
- private int mHeadsetState;
-
// Devices currently connected
private HashMap <Integer, String> mConnectedDevices = new HashMap <Integer, String>();
@@ -254,7 +245,6 @@ public class AudioService extends IAudioService.Stub {
mVolumePanel = new VolumePanel(context, this);
mSettingsObserver = new SettingsObserver();
mMode = AudioSystem.MODE_NORMAL;
- mHeadsetState = 0;
mForcedUseForComm = AudioSystem.FORCE_NONE;
createAudioSystemThread();
readPersistedSettings();
@@ -1460,72 +1450,35 @@ public class AudioService extends IAudioService.Stub {
}
} else if (action.equals(Intent.ACTION_HEADSET_PLUG)) {
int state = intent.getIntExtra("state", 0);
- if ((state & BIT_HEADSET) == 0 &&
- (mHeadsetState & BIT_HEADSET) != 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,
- AudioSystem.DEVICE_STATE_UNAVAILABLE,
- "");
- mConnectedDevices.remove(AudioSystem.DEVICE_OUT_WIRED_HEADSET);
- } else if ((state & BIT_HEADSET) != 0 &&
- (mHeadsetState & BIT_HEADSET) == 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,
- AudioSystem.DEVICE_STATE_AVAILABLE,
- "");
- mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_WIRED_HEADSET), "");
- }
- if ((state & BIT_HEADSET_NO_MIC) == 0 &&
- (mHeadsetState & BIT_HEADSET_NO_MIC) != 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE,
- AudioSystem.DEVICE_STATE_UNAVAILABLE,
- "");
- mConnectedDevices.remove(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE);
- } else if ((state & BIT_HEADSET_NO_MIC) != 0 &&
- (mHeadsetState & BIT_HEADSET_NO_MIC) == 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE,
- AudioSystem.DEVICE_STATE_AVAILABLE,
- "");
- mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE), "");
- }
- if ((state & BIT_TTY) == 0 &&
- (mHeadsetState & BIT_TTY) != 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_TTY,
- AudioSystem.DEVICE_STATE_UNAVAILABLE,
- "");
- mConnectedDevices.remove(AudioSystem.DEVICE_OUT_TTY);
- } else if ((state & BIT_TTY) != 0 &&
- (mHeadsetState & BIT_TTY) == 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_TTY,
- AudioSystem.DEVICE_STATE_AVAILABLE,
- "");
- mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_TTY), "");
- }
- if ((state & BIT_FM_HEADSET) == 0 &&
- (mHeadsetState & BIT_FM_HEADSET) != 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_HEADPHONE,
- AudioSystem.DEVICE_STATE_UNAVAILABLE,
- "");
- mConnectedDevices.remove(AudioSystem.DEVICE_OUT_FM_HEADPHONE);
- } else if ((state & BIT_FM_HEADSET) != 0 &&
- (mHeadsetState & BIT_FM_HEADSET) == 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_HEADPHONE,
- AudioSystem.DEVICE_STATE_AVAILABLE,
- "");
- mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_FM_HEADPHONE), "");
- }
- if ((state & BIT_FM_SPEAKER) == 0 &&
- (mHeadsetState & BIT_FM_SPEAKER) != 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_SPEAKER,
- AudioSystem.DEVICE_STATE_UNAVAILABLE,
- "");
- mConnectedDevices.remove(AudioSystem.DEVICE_OUT_FM_SPEAKER);
- } else if ((state & BIT_FM_SPEAKER) != 0 &&
- (mHeadsetState & BIT_FM_SPEAKER) == 0) {
- AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_FM_SPEAKER,
- AudioSystem.DEVICE_STATE_AVAILABLE,
- "");
- mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_FM_SPEAKER), "");
+ int microphone = intent.getIntExtra("microphone", 0);
+
+ if (microphone != 0) {
+ boolean isConnected = mConnectedDevices.containsKey(AudioSystem.DEVICE_OUT_WIRED_HEADSET);
+ if (state == 0 && isConnected) {
+ AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,
+ AudioSystem.DEVICE_STATE_UNAVAILABLE,
+ "");
+ mConnectedDevices.remove(AudioSystem.DEVICE_OUT_WIRED_HEADSET);
+ } else if (state == 1 && !isConnected) {
+ AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADSET,
+ AudioSystem.DEVICE_STATE_AVAILABLE,
+ "");
+ mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_WIRED_HEADSET), "");
+ }
+ } else {
+ boolean isConnected = mConnectedDevices.containsKey(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE);
+ if (state == 0 && isConnected) {
+ AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE,
+ AudioSystem.DEVICE_STATE_UNAVAILABLE,
+ "");
+ mConnectedDevices.remove(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE);
+ } else if (state == 1 && !isConnected) {
+ AudioSystem.setDeviceConnectionState(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE,
+ AudioSystem.DEVICE_STATE_AVAILABLE,
+ "");
+ mConnectedDevices.put( new Integer(AudioSystem.DEVICE_OUT_WIRED_HEADPHONE), "");
+ }
}
- mHeadsetState = state;
}
}
}
diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java
index dbf6d9d..9fe5328 100644
--- a/media/java/android/media/AudioSystem.java
+++ b/media/java/android/media/AudioSystem.java
@@ -243,9 +243,6 @@ public class AudioSystem
public static final int DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES = 0x100;
public static final int DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER = 0x200;
public static final int DEVICE_OUT_AUX_DIGITAL = 0x400;
- public static final int DEVICE_OUT_FM_HEADPHONE = 0x800;
- public static final int DEVICE_OUT_FM_SPEAKER = 0x1000;
- public static final int DEVICE_OUT_TTY = 0x2000;
public static final int DEVICE_OUT_DEFAULT = 0x8000;
// input devices
public static final int DEVICE_IN_COMMUNICATION = 0x10000;
diff --git a/services/java/com/android/server/HeadsetObserver.java b/services/java/com/android/server/HeadsetObserver.java
index bee3108..58fa69e 100644
--- a/services/java/com/android/server/HeadsetObserver.java
+++ b/services/java/com/android/server/HeadsetObserver.java
@@ -43,9 +43,6 @@ class HeadsetObserver extends UEventObserver {
private static final int BIT_HEADSET = (1 << 0);
private static final int BIT_HEADSET_NO_MIC = (1 << 1);
- private static final int BIT_TTY = (1 << 2);
- private static final int BIT_FM_HEADSET = (1 << 3);
- private static final int BIT_FM_SPEAKER = (1 << 4);
private int mHeadsetState;
private int mPrevHeadsetState;
@@ -102,15 +99,18 @@ class HeadsetObserver extends UEventObserver {
}
private synchronized final void update(String newName, int newState) {
- if (newName != mHeadsetName || newState != mHeadsetState) {
+ // Retain only relevant bits
+ int headsetState = newState & (BIT_HEADSET|BIT_HEADSET_NO_MIC);
+
+ if (headsetState != mHeadsetState) {
boolean isUnplug = false;
- if ( (mHeadsetState & BIT_HEADSET) > 0 || (mHeadsetState & BIT_HEADSET_NO_MIC) > 0) {
- if ((newState & BIT_HEADSET) == 0 && (newState & BIT_HEADSET_NO_MIC) == 0)
- isUnplug = true;
+ if (((mHeadsetState & BIT_HEADSET) != 0 && (headsetState & BIT_HEADSET) == 0) ||
+ ((mHeadsetState & BIT_HEADSET_NO_MIC) != 0 && (headsetState & BIT_HEADSET_NO_MIC) == 0)) {
+ isUnplug = true;
}
mHeadsetName = newName;
mPrevHeadsetState = mHeadsetState;
- mHeadsetState = newState;
+ mHeadsetState = headsetState;
mPendingIntent = true;
if (isUnplug) {
@@ -135,9 +135,23 @@ class HeadsetObserver extends UEventObserver {
// Pack up the values and broadcast them to everyone
Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
+ int state = 0;
+ int microphone = 0;
+
+ if ((mHeadsetState & BIT_HEADSET) != (mPrevHeadsetState & BIT_HEADSET)) {
+ microphone = 1;
+ if ((mHeadsetState & BIT_HEADSET) != 0) {
+ state = 1;
+ }
+ } else if ((mHeadsetState & BIT_HEADSET_NO_MIC) != (mPrevHeadsetState & BIT_HEADSET_NO_MIC)) {
+ if ((mHeadsetState & BIT_HEADSET_NO_MIC) != 0) {
+ state = 1;
+ }
+ }
- intent.putExtra("state", mHeadsetState);
+ intent.putExtra("state", state);
intent.putExtra("name", mHeadsetName);
+ intent.putExtra("microphone", microphone);
// TODO: Should we require a permission?
ActivityManagerNative.broadcastStickyIntent(intent, null);