Merge commit '609acfd2a1067f49e51925776484b070a24d8301' into eclair-mr2-plus-aosp * commit '609acfd2a1067f49e51925776484b070a24d8301': Fix issue 2242614: Wired headset not recognized: bogus "state" in ACTION_HEADSET_PLUG broadcast.
This commit is contained in:
@ -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>
|
||||
*/
|
||||
|
@ -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,
|
||||
|
@ -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), "");
|
||||
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), "");
|
||||
}
|
||||
}
|
||||
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), "");
|
||||
}
|
||||
mHeadsetState = state;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
||||
intent.putExtra("state", mHeadsetState);
|
||||
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", state);
|
||||
intent.putExtra("name", mHeadsetName);
|
||||
intent.putExtra("microphone", microphone);
|
||||
|
||||
// TODO: Should we require a permission?
|
||||
ActivityManagerNative.broadcastStickyIntent(intent, null);
|
||||
|
Reference in New Issue
Block a user