diff --git a/mobile/android/base/MemoryMonitor.java b/mobile/android/base/MemoryMonitor.java index 1bbda53bf2ef..31d10964ca05 100644 --- a/mobile/android/base/MemoryMonitor.java +++ b/mobile/android/base/MemoryMonitor.java @@ -152,7 +152,7 @@ class MemoryMonitor extends BroadcastReceiver { if (GeckoApp.checkLaunchState(GeckoApp.LaunchState.GeckoRunning)) { GeckoAppShell.onLowMemory(); } - ScreenshotHandler.disableScreenshot(); + ScreenshotHandler.disableScreenshot(false); GeckoAppShell.geckoEventSync(); } } @@ -169,7 +169,7 @@ class MemoryMonitor extends BroadcastReceiver { Log.d(LOGTAG, "Decreased memory pressure to " + newLevel); if (newLevel == MEMORY_PRESSURE_NONE) { - ScreenshotHandler.enableScreenshot(); + ScreenshotHandler.enableScreenshot(false); } return true; diff --git a/mobile/android/base/ScreenshotHandler.java b/mobile/android/base/ScreenshotHandler.java index 25c717198450..e5bc348b26cb 100644 --- a/mobile/android/base/ScreenshotHandler.java +++ b/mobile/android/base/ScreenshotHandler.java @@ -12,6 +12,7 @@ import org.mozilla.gecko.gfx.RectUtils; import org.mozilla.gecko.gfx.ScreenshotLayer; import org.mozilla.gecko.mozglue.DirectBufferAllocator; import org.mozilla.gecko.util.FloatUtils; +import org.mozilla.gecko.PrefsHelper; import android.graphics.Rect; import android.graphics.RectF; @@ -28,11 +29,14 @@ public final class ScreenshotHandler implements Runnable { public static final int SCREENSHOT_THUMBNAIL = 0; public static final int SCREENSHOT_CHECKERBOARD = 1; + private static final String SCREENSHOT_DISABLED_PREF = "gfx.java.screenshot.enabled"; + private static final String LOGTAG = "GeckoScreenshotHandler"; private static final int BYTES_FOR_16BPP = 2; private static final int MAX_PIXELS_PER_SLICE = 100000; private static boolean sDisableScreenshot; + private static boolean sForceDisabled; private static ScreenshotHandler sInstance; private final int mMaxTextureSize; @@ -80,6 +84,14 @@ public final class ScreenshotHandler implements Runnable { mBuffer = DirectBufferAllocator.allocate(mMaxPixels * BYTES_FOR_16BPP); mDirtyRect = new RectF(); clearDirtyRect(); + PrefsHelper.getPref(SCREENSHOT_DISABLED_PREF, + new PrefsHelper.PrefHandlerBase() { + @Override public void prefValue(String pref, boolean value) { + if (SCREENSHOT_DISABLED_PREF.equals(pref) && !value) + disableScreenshot(true); + } + } + ); } private void cleanup() { @@ -96,9 +108,19 @@ public final class ScreenshotHandler implements Runnable { // Invoked via reflection from robocop test public static synchronized void disableScreenshot() { + disableScreenshot(true); + } + + // Invoked via reflection from robocop test + public static synchronized void disableScreenshot(boolean forced) { if (sDisableScreenshot) { + if (!sForceDisabled) + sForceDisabled = forced; return; } + + sForceDisabled = forced; + sDisableScreenshot = true; if (sInstance != null) { sInstance.cleanup(); @@ -107,11 +129,12 @@ public final class ScreenshotHandler implements Runnable { Log.i(LOGTAG, "Screenshotting disabled"); } - public static synchronized void enableScreenshot() { - if (!sDisableScreenshot) { + public static synchronized void enableScreenshot(boolean forced) { + if (!sDisableScreenshot || (sForceDisabled && !forced)) { return; } sDisableScreenshot = false; + sForceDisabled = false; Log.i(LOGTAG, "Screenshotting enabled"); }