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:
Alastor Wu
2017-08-29 15:28:23 +08:00
parent d27956623b
commit 6c3ba5f12b
4 changed files with 44 additions and 6 deletions

View File

@@ -530,13 +530,21 @@ public class GeckoAppShell
PowerManager.WakeLock wl = mWakeLocks.get(lock); 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) { if (state == WakeLockDelegate.STATE_LOCKED_FOREGROUND && wl == null) {
final PowerManager pm = (PowerManager) final PowerManager pm = (PowerManager)
getApplicationContext().getSystemService(Context.POWER_SERVICE); 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); 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 // 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. // WakeLock is released, causing the illumination to remain on a bit longer.
wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |

View File

@@ -17,6 +17,14 @@ public interface WakeLockDelegate {
* Wake-lock for the screen. * Wake-lock for the screen.
*/ */
final String LOCK_SCREEN = "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; final int LOCKS_COUNT = 2;

View File

@@ -67,6 +67,12 @@ private:
return NS_OK; 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") || bool shouldKeepDisplayOn = aTopic.EqualsASCII("screen") ||
aTopic.EqualsASCII("video-playing"); aTopic.EqualsASCII("video-playing");
CFStringRef assertionType = shouldKeepDisplayOn ? CFStringRef assertionType = shouldKeepDisplayOn ?
@@ -77,6 +83,9 @@ private:
// Note the wake lock code ensures that we're not sent duplicate // Note the wake lock code ensures that we're not sent duplicate
// "locked-foreground" notifications when multiple wake locks are held. // "locked-foreground" notifications when multiple wake locks are held.
if (aState.EqualsASCII("locked-foreground")) { if (aState.EqualsASCII("locked-foreground")) {
if (assertionId != kIOPMNullAssertionID) {
return NS_OK;
}
// Prevent screen saver. // Prevent screen saver.
CFStringRef cf_topic = CFStringRef cf_topic =
::CFStringCreateWithCharacters(kCFAllocatorDefault, ::CFStringCreateWithCharacters(kCFAllocatorDefault,
@@ -100,6 +109,7 @@ private:
if (result != kIOReturnSuccess) { if (result != kIOReturnSuccess) {
NS_WARNING("failed to release screensaver"); NS_WARNING("failed to release screensaver");
} }
assertionId = kIOPMNullAssertionID;
} }
} }
return NS_OK; return NS_OK;

View File

@@ -45,7 +45,7 @@ static mozilla::LazyLogModule gWinWakeLockLog("WinWakeLock");
class WinWakeLockListener final : public nsIDOMMozWakeLockListener class WinWakeLockListener final : public nsIDOMMozWakeLockListener
{ {
public: public:
NS_DECL_ISUPPORTS; NS_DECL_ISUPPORTS
private: private:
~WinWakeLockListener() {} ~WinWakeLockListener() {}
@@ -56,13 +56,23 @@ private:
!aTopic.EqualsASCII("video-playing")) { !aTopic.EqualsASCII("video-playing")) {
return NS_OK; 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 // Note the wake lock code ensures that we're not sent duplicate
// "locked-foreground" notifications when multiple wake locks are held. // "locked-foreground" notifications when multiple wake locks are held.
if (aState.EqualsASCII("locked-foreground")) { if (aState.EqualsASCII("locked-foreground")) {
WAKE_LOCK_LOG("WinWakeLock: Blocking screen saver"); WAKE_LOCK_LOG("WinWakeLock: Blocking screen saver");
if (shouldKeepDisplayOn) { if (mRequireForDisplay) {
// Prevent the display turning off and block the screen saver. // Prevent the display turning off and block the screen saver.
SetThreadExecutionState(ES_DISPLAY_REQUIRED|ES_CONTINUOUS); SetThreadExecutionState(ES_DISPLAY_REQUIRED|ES_CONTINUOUS);
} else { } else {
@@ -75,6 +85,8 @@ private:
} }
return NS_OK; return NS_OK;
} }
bool mRequireForDisplay = false;
}; };
NS_IMPL_ISUPPORTS(WinWakeLockListener, nsIDOMMozWakeLockListener) NS_IMPL_ISUPPORTS(WinWakeLockListener, nsIDOMMozWakeLockListener)