am da4cc343
: Fix issue 2324029: In-call (and other) audio screwed up after using Pandora (ERD72).
Merge commit 'da4cc34308d65730c404b669926a92e37b378555' into eclair-mr2 * commit 'da4cc34308d65730c404b669926a92e37b378555': Fix issue 2324029: In-call (and other) audio screwed up after using Pandora (ERD72).
This commit is contained in:
@ -49,7 +49,6 @@ class HeadsetObserver extends UEventObserver {
|
|||||||
private int mHeadsetState;
|
private int mHeadsetState;
|
||||||
private int mPrevHeadsetState;
|
private int mPrevHeadsetState;
|
||||||
private String mHeadsetName;
|
private String mHeadsetName;
|
||||||
private boolean mPendingIntent;
|
|
||||||
|
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private final WakeLock mWakeLock; // held while there is a pending route change
|
private final WakeLock mWakeLock; // held while there is a pending route change
|
||||||
@ -114,7 +113,6 @@ class HeadsetObserver extends UEventObserver {
|
|||||||
mHeadsetName = newName;
|
mHeadsetName = newName;
|
||||||
mPrevHeadsetState = mHeadsetState;
|
mPrevHeadsetState = mHeadsetState;
|
||||||
mHeadsetState = headsetState;
|
mHeadsetState = headsetState;
|
||||||
mPendingIntent = true;
|
|
||||||
|
|
||||||
if (headsetState == 0) {
|
if (headsetState == 0) {
|
||||||
Intent intent = new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
|
Intent intent = new Intent(AudioManager.ACTION_AUDIO_BECOMING_NOISY);
|
||||||
@ -126,25 +124,28 @@ class HeadsetObserver extends UEventObserver {
|
|||||||
// This could be improved once the audio sub-system provides an
|
// This could be improved once the audio sub-system provides an
|
||||||
// interface to clear the audio pipeline.
|
// interface to clear the audio pipeline.
|
||||||
mWakeLock.acquire();
|
mWakeLock.acquire();
|
||||||
mHandler.sendEmptyMessageDelayed(0, 1000);
|
mHandler.sendMessageDelayed(mHandler.obtainMessage(0,
|
||||||
|
mHeadsetState,
|
||||||
|
mPrevHeadsetState,
|
||||||
|
mHeadsetName),
|
||||||
|
1000);
|
||||||
} else {
|
} else {
|
||||||
sendIntents();
|
sendIntents(mHeadsetState, mPrevHeadsetState, mHeadsetName);
|
||||||
mPendingIntent = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized final void sendIntents() {
|
private synchronized final void sendIntents(int headsetState, int prevHeadsetState, String headsetName) {
|
||||||
int allHeadsets = SUPPORTED_HEADSETS;
|
int allHeadsets = SUPPORTED_HEADSETS;
|
||||||
for (int curHeadset = 1; allHeadsets != 0; curHeadset <<= 1) {
|
for (int curHeadset = 1; allHeadsets != 0; curHeadset <<= 1) {
|
||||||
if ((curHeadset & allHeadsets) != 0) {
|
if ((curHeadset & allHeadsets) != 0) {
|
||||||
sendIntent(curHeadset);
|
sendIntent(curHeadset, headsetState, prevHeadsetState, headsetName);
|
||||||
allHeadsets &= ~curHeadset;
|
allHeadsets &= ~curHeadset;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void sendIntent(int headset) {
|
private final void sendIntent(int headset, int headsetState, int prevHeadsetState, String headsetName) {
|
||||||
if ((mHeadsetState & headset) != (mPrevHeadsetState & headset)) {
|
if ((headsetState & headset) != (prevHeadsetState & headset)) {
|
||||||
// Pack up the values and broadcast them to everyone
|
// Pack up the values and broadcast them to everyone
|
||||||
Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG);
|
Intent intent = new Intent(Intent.ACTION_HEADSET_PLUG);
|
||||||
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
|
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
|
||||||
@ -154,14 +155,14 @@ class HeadsetObserver extends UEventObserver {
|
|||||||
if ((headset & HEADSETS_WITH_MIC) != 0) {
|
if ((headset & HEADSETS_WITH_MIC) != 0) {
|
||||||
microphone = 1;
|
microphone = 1;
|
||||||
}
|
}
|
||||||
if ((mHeadsetState & headset) != 0) {
|
if ((headsetState & headset) != 0) {
|
||||||
state = 1;
|
state = 1;
|
||||||
}
|
}
|
||||||
intent.putExtra("state", state);
|
intent.putExtra("state", state);
|
||||||
intent.putExtra("name", mHeadsetName);
|
intent.putExtra("name", headsetName);
|
||||||
intent.putExtra("microphone", microphone);
|
intent.putExtra("microphone", microphone);
|
||||||
|
|
||||||
if (LOG) Log.v(TAG, "Intent.ACTION_HEADSET_PLUG: state: "+state+" name: "+mHeadsetName+" mic: "+microphone);
|
if (LOG) Log.v(TAG, "Intent.ACTION_HEADSET_PLUG: state: "+state+" name: "+headsetName+" mic: "+microphone);
|
||||||
// TODO: Should we require a permission?
|
// TODO: Should we require a permission?
|
||||||
ActivityManagerNative.broadcastStickyIntent(intent, null);
|
ActivityManagerNative.broadcastStickyIntent(intent, null);
|
||||||
}
|
}
|
||||||
@ -170,12 +171,8 @@ class HeadsetObserver extends UEventObserver {
|
|||||||
private final Handler mHandler = new Handler() {
|
private final Handler mHandler = new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
if (mPendingIntent) {
|
sendIntents(msg.arg1, msg.arg2, (String)msg.obj);
|
||||||
sendIntents();
|
|
||||||
mPendingIntent = false;
|
|
||||||
}
|
|
||||||
mWakeLock.release();
|
mWakeLock.release();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user