AI 145203: am: CL 145201 Hold wakelock while delaying for audio route switch after headset unplug.

Fixes bug where we go to sleep before switching audio, and we lose audio until the apps CPU wakes up again.
  Original author: npelly

Automated import of CL 145203
This commit is contained in:
Nick Pelly
2009-04-08 19:22:53 -07:00
committed by The Android Open Source Project
parent 5b13cb6486
commit babf19136c

View File

@@ -21,6 +21,8 @@ import android.content.Context;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.UEventObserver;
import android.util.Log;
import android.media.AudioManager;
@@ -38,15 +40,19 @@ class HeadsetObserver extends UEventObserver {
private static final String HEADSET_STATE_PATH = "/sys/class/switch/h2w/state";
private static final String HEADSET_NAME_PATH = "/sys/class/switch/h2w/name";
private Context mContext;
private int mHeadsetState;
private String mHeadsetName;
private boolean mAudioRouteNeedsUpdate;
private AudioManager mAudioManager;
private final Context mContext;
private final WakeLock mWakeLock; // held while there is a pending route change
public HeadsetObserver(Context context) {
mContext = context;
PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "HeadsetObserver");
mWakeLock.setReferenceCounted(false);
startObserving(HEADSET_UEVENT_MATCH);
@@ -103,6 +109,7 @@ class HeadsetObserver extends UEventObserver {
// immediate, so delay the route change by 1000ms.
// This could be improved once the audio sub-system provides an
// interface to clear the audio pipeline.
mWakeLock.acquire();
mHandler.sendEmptyMessageDelayed(0, 1000);
} else {
updateAudioRoute();
@@ -138,7 +145,8 @@ class HeadsetObserver extends UEventObserver {
@Override
public void handleMessage(Message msg) {
updateAudioRoute();
mWakeLock.release();
}
};
};
}