Bug 1373888 - part7 : modify platform wakelocks. r=cpearce,snorp,spohl
* OSX Make the lock of the type kIOPMAssertionTypeNoDisplaySleep and kIOPMAssertionTypeNoIdleSleep as a singleton. Won't need to require an extra lock. * Windows Add |mRequireForDisplay| to ensure the "audio-playing" won't overwrite the previous display requirement. * Android Add "audio-playing" and "video-playing", and make sure the audio-lock won't be cancel when receiving "WakeLockDelegate.STATE_LOCKED_BACKGROUND". MozReview-Commit-ID: 97oNX7H2qij
This commit is contained in:
@@ -530,13 +530,21 @@ public class GeckoAppShell
|
||||
|
||||
PowerManager.WakeLock wl = mWakeLocks.get(lock);
|
||||
|
||||
// we should still hold the lock for background audio.
|
||||
if (WakeLockDelegate.LOCK_AUDIO_PLAYING.equals(lock) &&
|
||||
state == WakeLockDelegate.STATE_LOCKED_BACKGROUND) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (state == WakeLockDelegate.STATE_LOCKED_FOREGROUND && wl == null) {
|
||||
final PowerManager pm = (PowerManager)
|
||||
getApplicationContext().getSystemService(Context.POWER_SERVICE);
|
||||
|
||||
if (WakeLockDelegate.LOCK_CPU.equals(lock)) {
|
||||
if (WakeLockDelegate.LOCK_CPU.equals(lock) ||
|
||||
WakeLockDelegate.LOCK_AUDIO_PLAYING.equals(lock)) {
|
||||
wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, lock);
|
||||
} else if (WakeLockDelegate.LOCK_SCREEN.equals(lock)) {
|
||||
} else if (WakeLockDelegate.LOCK_SCREEN.equals(lock) ||
|
||||
WakeLockDelegate.LOCK_VIDEO_PLAYING.equals(lock)) {
|
||||
// ON_AFTER_RELEASE is set, the user activity timer will be reset when the
|
||||
// WakeLock is released, causing the illumination to remain on a bit longer.
|
||||
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
|
||||
|
||||
@@ -17,6 +17,14 @@ public interface WakeLockDelegate {
|
||||
* Wake-lock for the screen.
|
||||
*/
|
||||
final String LOCK_SCREEN = "screen";
|
||||
/**
|
||||
* Wake-lock for the audio-playing, eqaul to LOCK_CPU.
|
||||
*/
|
||||
final String LOCK_AUDIO_PLAYING = "audio-playing";
|
||||
/**
|
||||
* Wake-lock for the video-playing, eqaul to LOCK_SCREEN..
|
||||
*/
|
||||
final String LOCK_VIDEO_PLAYING = "video-playing";
|
||||
|
||||
final int LOCKS_COUNT = 2;
|
||||
|
||||
|
||||
@@ -67,6 +67,12 @@ private:
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// we should still hold the lock for background audio.
|
||||
if (aTopic.EqualsASCII("audio-playing") &&
|
||||
aState.EqualsASCII("locked-background")) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool shouldKeepDisplayOn = aTopic.EqualsASCII("screen") ||
|
||||
aTopic.EqualsASCII("video-playing");
|
||||
CFStringRef assertionType = shouldKeepDisplayOn ?
|
||||
@@ -77,6 +83,9 @@ private:
|
||||
// Note the wake lock code ensures that we're not sent duplicate
|
||||
// "locked-foreground" notifications when multiple wake locks are held.
|
||||
if (aState.EqualsASCII("locked-foreground")) {
|
||||
if (assertionId != kIOPMNullAssertionID) {
|
||||
return NS_OK;
|
||||
}
|
||||
// Prevent screen saver.
|
||||
CFStringRef cf_topic =
|
||||
::CFStringCreateWithCharacters(kCFAllocatorDefault,
|
||||
@@ -100,6 +109,7 @@ private:
|
||||
if (result != kIOReturnSuccess) {
|
||||
NS_WARNING("failed to release screensaver");
|
||||
}
|
||||
assertionId = kIOPMNullAssertionID;
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
@@ -45,7 +45,7 @@ static mozilla::LazyLogModule gWinWakeLockLog("WinWakeLock");
|
||||
class WinWakeLockListener final : public nsIDOMMozWakeLockListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS;
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
private:
|
||||
~WinWakeLockListener() {}
|
||||
@@ -56,13 +56,23 @@ private:
|
||||
!aTopic.EqualsASCII("video-playing")) {
|
||||
return NS_OK;
|
||||
}
|
||||
bool shouldKeepDisplayOn = aTopic.EqualsASCII("screen") ||
|
||||
aTopic.EqualsASCII("video-playing");
|
||||
|
||||
// we should still hold the lock for background audio.
|
||||
if (aTopic.EqualsASCII("audio-playing") &&
|
||||
aState.EqualsASCII("locked-background")) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aTopic.EqualsASCII("screen") ||
|
||||
aTopic.EqualsASCII("video-playing")) {
|
||||
mRequireForDisplay = aState.EqualsASCII("locked-foreground");
|
||||
}
|
||||
|
||||
// Note the wake lock code ensures that we're not sent duplicate
|
||||
// "locked-foreground" notifications when multiple wake locks are held.
|
||||
if (aState.EqualsASCII("locked-foreground")) {
|
||||
WAKE_LOCK_LOG("WinWakeLock: Blocking screen saver");
|
||||
if (shouldKeepDisplayOn) {
|
||||
if (mRequireForDisplay) {
|
||||
// Prevent the display turning off and block the screen saver.
|
||||
SetThreadExecutionState(ES_DISPLAY_REQUIRED|ES_CONTINUOUS);
|
||||
} else {
|
||||
@@ -75,6 +85,8 @@ private:
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool mRequireForDisplay = false;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS(WinWakeLockListener, nsIDOMMozWakeLockListener)
|
||||
|
||||
Reference in New Issue
Block a user