Defer release of the wake lock

This allows the headset button to fuction for a short period after
pausing
This commit is contained in:
Christopher Eby committed 2012-05-16 10:11:27 -05:00
1 parent c307995b73
commit 496d28411a
1 file changed
+18 -3
+18 -3
View File
@@ -191,7 +191,10 @@ public final class PlaybackService extends Service
* Minimum time in milliseconds between shake actions.
*/
private static final int MIN_SHAKE_PERIOD = 500;
/**
* Defer release of mWakeLock for this time (in ms).
*/
private static final int WAKE_LOCK_DELAY = 60000;
/**
* If set, music will play.
@@ -744,6 +747,8 @@ public final class PlaybackService extends Service
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
CompatFroyo.requestAudioFocus(mAudioManager);
}
mHandler.removeMessages(RELEASE_WAKE_LOCK);
try {
if (mWakeLock != null)
mWakeLock.acquire();
@@ -761,8 +766,10 @@ public final class PlaybackService extends Service
stopForeground(true);
}
if (mWakeLock != null && mWakeLock.isHeld())
mWakeLock.release();
// Delay release of the wake lock. This allows the headset
// button to continue to function for a short period after
// pausing.
mHandler.sendEmptyMessageDelayed(RELEASE_WAKE_LOCK, WAKE_LOCK_DELAY);
}
setupSensor();
@@ -1172,6 +1179,10 @@ public final class PlaybackService extends Service
loadPreference(key);
}
/**
* Calls {@link PowerManager.WakeLock#release()} on mWakeLock.
*/
private static final int RELEASE_WAKE_LOCK = 1;
/**
* Run the given query and add the results to the timeline.
*
@@ -1252,6 +1263,10 @@ public final class PlaybackService extends Service
case BROADCAST_CHANGE:
broadcastChange(message.arg1, (Song)message.obj, message.getWhen());
break;
case RELEASE_WAKE_LOCK:
if (mWakeLock != null && mWakeLock.isHeld())
mWakeLock.release();
break;
default:
return false;
}