Bug 1022669 - Do not lock screen for audio. r=snorp
--- a/content/html/content/public/HTMLMediaElement.h
+++ b/content/html/content/public/HTMLMediaElement.h
@@ -1225,16 +1225,19 @@ protected:
bool mMediaSecurityVerified;
// The CORS mode when loading the media element
CORSMode mCORSMode;
// True if the media has an audio track
bool mHasAudio;
+ // True if the media has a video track
+ bool mHasVideo;
+
// True if the media's channel's download has been suspended.
bool mDownloadSuspendedByCache;
// Audio Channel.
AudioChannel mAudioChannel;
// The audio channel has been faded.
bool mAudioChannelFaded;
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -2054,16 +2054,17 @@ HTMLMediaElement::HTMLMediaElement(alrea
mAllowSuspendAfterFirstFrame(true),
mHasPlayedOrSeeked(false),
mHasSelfReference(false),
mShuttingDown(false),
mSuspendedForPreloadNone(false),
mMediaSecurityVerified(false),
mCORSMode(CORS_NONE),
mHasAudio(false),
+ mHasVideo(false),
mDownloadSuspendedByCache(false),
mAudioChannelFaded(false),
mPlayingThroughTheAudioChannel(false),
mDisableVideo(false),
mWaitingFor(MediaWaitingFor::None)
{
#ifdef PR_LOGGING
if (!gMediaElementLog) {
@@ -2917,16 +2918,17 @@ void HTMLMediaElement::ProcessMediaFragm
mFragmentStart = parser.GetStartTime();
}
}
void HTMLMediaElement::MetadataLoaded(const MediaInfo* aInfo,
const MetadataTags* aTags)
{
mHasAudio = aInfo->HasAudio();
+ mHasVideo = aInfo->HasVideo();
mTags = aTags;
mLoadedDataFired = false;
ChangeReadyState(nsIDOMHTMLMediaElement::HAVE_METADATA);
DispatchAsyncEvent(NS_LITERAL_STRING("durationchange"));
DispatchAsyncEvent(NS_LITERAL_STRING("loadedmetadata"));
if (mDecoder && mDecoder->IsTransportSeekable() && mDecoder->IsMediaSeekable()) {
ProcessMediaFragmentURI();
mDecoder->SetFragmentEndTime(mFragmentEnd);
@@ -3323,24 +3325,26 @@ VideoFrameContainer* HTMLMediaElement::G
// If we have loaded the metadata, and the size of the video is still
// (-1, -1), the media has no video. Don't go a create a video frame
// container.
if (mReadyState >= nsIDOMHTMLMediaElement::HAVE_METADATA &&
mMediaSize == nsIntSize(-1, -1)) {
return nullptr;
}
- if (mVideoFrameContainer)
- return mVideoFrameContainer;
-
// Only video frames need an image container.
if (!IsVideo()) {
return nullptr;
}
+ mHasVideo = true;
+
+ if (mVideoFrameContainer)
+ return mVideoFrameContainer;
+
mVideoFrameContainer =
new VideoFrameContainer(this, LayerManager::CreateAsynchronousImageContainer());
return mVideoFrameContainer;
}
nsresult HTMLMediaElement::DispatchEvent(const nsAString& aName)
{
--- a/content/html/content/src/HTMLVideoElement.cpp
+++ b/content/html/content/src/HTMLVideoElement.cpp
@@ -242,17 +242,17 @@ HTMLVideoElement::UpdateScreenWakeLock()
if (mScreenWakeLock && (mPaused || hidden)) {
ErrorResult rv;
mScreenWakeLock->Unlock(rv);
NS_WARN_IF_FALSE(!rv.Failed(), "Failed to unlock the wakelock.");
mScreenWakeLock = nullptr;
return;
}
- if (!mScreenWakeLock && !mPaused && !hidden) {
+ if (!mScreenWakeLock && !mPaused && !hidden && mHasVideo) {
nsRefPtr<power::PowerManagerService> pmService =
power::PowerManagerService::GetInstance();
NS_ENSURE_TRUE_VOID(pmService);
ErrorResult rv;
mScreenWakeLock = pmService->NewWakeLock(NS_LITERAL_STRING("screen"),
OwnerDoc()->GetInnerWindow(),
rv);
--- a/mobile/android/base/GeckoApp.java
+++ b/mobile/android/base/GeckoApp.java
@@ -2330,24 +2330,35 @@ public abstract class GeckoApp
{
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
}
+ private static final String CPU = "cpu";
+ private static final String SCREEN = "screen";
+
// Called when a Gecko Hal WakeLock is changed
public void notifyWakeLockChanged(String topic, String state) {
PowerManager.WakeLock wl = mWakeLocks.get(topic);
if (state.equals("locked-foreground") && wl == null) {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
- wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, topic);
- wl.acquire();
- mWakeLocks.put(topic, wl);
+
+ if (CPU.equals(topic)) {
+ wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, topic);
+ } else if (SCREEN.equals(topic)) {
+ wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, topic);
+ }
+
+ if (wl != null) {
+ wl.acquire();
+ mWakeLocks.put(topic, wl);
+ }
} else if (!state.equals("locked-foreground") && wl != null) {
wl.release();
mWakeLocks.remove(topic);
}
}
public void notifyCheckUpdateResult(String result) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Update:CheckResult", result));