diff --git a/api/current.txt b/api/current.txt
index 1c3ee82dbba0d..214acfc169e98 100755
--- a/api/current.txt
+++ b/api/current.txt
@@ -283,7 +283,6 @@ package android {
field public static final int allowBackup = 16843392; // 0x1010280
field public static final int allowClearUserData = 16842757; // 0x1010005
field public static final int allowEmbedded = 16843765; // 0x10103f5
- field public static final int allowForceDark = 16844172; // 0x101058c
field public static final int allowParallelSyncs = 16843570; // 0x1010332
field public static final int allowSingleTap = 16843353; // 0x1010259
field public static final int allowTaskReparenting = 16843268; // 0x1010204
@@ -638,6 +637,7 @@ package android {
field public static final int fontVariationSettings = 16844144; // 0x1010570
field public static final int fontWeight = 16844083; // 0x1010533
field public static final int footerDividersEnabled = 16843311; // 0x101022f
+ field public static final int forceDarkAllowed = 16844172; // 0x101058c
field public static final int forceHasOverlappingRendering = 16844065; // 0x1010521
field public static final int foreground = 16843017; // 0x1010109
field public static final int foregroundGravity = 16843264; // 0x1010200
@@ -48508,6 +48508,7 @@ package android.view {
method public final boolean isFocusableInTouchMode();
method public boolean isFocused();
method public final boolean isFocusedByDefault();
+ method public boolean isForceDarkAllowed();
method public boolean isHapticFeedbackEnabled();
method public boolean isHardwareAccelerated();
method public boolean isHorizontalFadingEdgeEnabled();
@@ -48694,6 +48695,7 @@ package android.view {
method public void setFocusable(int);
method public void setFocusableInTouchMode(boolean);
method public void setFocusedByDefault(boolean);
+ method public void setForceDarkAllowed(boolean);
method public void setForeground(android.graphics.drawable.Drawable);
method public void setForegroundGravity(int);
method public void setForegroundTintList(android.content.res.ColorStateList);
diff --git a/core/java/android/view/Surface.java b/core/java/android/view/Surface.java
index f17a45800aebf..f3cb3767ec9d6 100644
--- a/core/java/android/view/Surface.java
+++ b/core/java/android/view/Surface.java
@@ -897,7 +897,7 @@ public class Surface implements Parcelable {
HwuiContext(boolean isWideColorGamut) {
mRenderNode = RenderNode.create("HwuiCanvas", null);
mRenderNode.setClipToBounds(false);
- mRenderNode.setAllowForceDark(false);
+ mRenderNode.setForceDarkAllowed(false);
mIsWideColorGamut = isWideColorGamut;
mHwuiRenderer = nHwuiCreate(mRenderNode.mNativeRenderNode, mNativeObject,
isWideColorGamut);
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index c82918249531b..1157b287e5500 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -5542,6 +5542,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
break;
case com.android.internal.R.styleable.View_accessibilityHeading:
setAccessibilityHeading(a.getBoolean(attr, false));
+ break;
+ case R.styleable.View_forceDarkAllowed:
+ mRenderNode.setForceDarkAllowed(a.getBoolean(attr, true));
+ break;
}
}
@@ -15286,11 +15290,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* If a theme is isLightTheme="false", then force dark is globally disabled for that theme.
*
* @param allow Whether or not to allow force dark.
- *
- * @hide
*/
- public void setAllowForceDark(boolean allow) {
- if (mRenderNode.setAllowForceDark(allow)) {
+ public void setForceDarkAllowed(boolean allow) {
+ if (mRenderNode.setForceDarkAllowed(allow)) {
// Currently toggling force-dark requires a new display list push to apply
// TODO: Make it not clobber the display list so this is just a damageSelf() instead
invalidate();
@@ -15298,15 +15300,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
}
/**
- * See {@link #setAllowForceDark(boolean)}
+ * See {@link #setForceDarkAllowed(boolean)}
*
* @return true if force dark is allowed (default), false if it is disabled
- *
- * @hide
*/
@ViewDebug.ExportedProperty(category = "drawing")
- public boolean getAllowForceDark() {
- return mRenderNode.getAllowForceDark();
+ public boolean isForceDarkAllowed() {
+ return mRenderNode.isForceDarkAllowed();
}
/**
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 7da31ebe4a176..170c783676436 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -1096,15 +1096,21 @@ public final class ViewRootImpl implements ViewParent,
private void updateForceDarkMode() {
if (mAttachInfo.mThreadedRenderer == null) return;
- boolean nightMode = getNightMode() == Configuration.UI_MODE_NIGHT_YES;
- TypedArray a = mContext.obtainStyledAttributes(R.styleable.Theme);
- boolean isLightTheme = a.getBoolean(R.styleable.Theme_isLightTheme, false);
- a.recycle();
+ boolean useAutoDark = getNightMode() == Configuration.UI_MODE_NIGHT_YES;
- boolean changed = mAttachInfo.mThreadedRenderer.setForceDark(nightMode);
- changed |= mAttachInfo.mThreadedRenderer.getRootNode().setAllowForceDark(isLightTheme);
+ // Allow debug.hwui.force_dark to override the target SDK check
+ if (useAutoDark && !SystemProperties.getBoolean("debug.hwui.force_dark", false)) {
+ useAutoDark = mContext.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.Q;
+ }
- if (changed) {
+ if (useAutoDark) {
+ TypedArray a = mContext.obtainStyledAttributes(R.styleable.Theme);
+ useAutoDark = a.getBoolean(R.styleable.Theme_isLightTheme, true)
+ && a.getBoolean(R.styleable.Theme_forceDarkAllowed, true);
+ a.recycle();
+ }
+
+ if (mAttachInfo.mThreadedRenderer.setForceDark(useAutoDark)) {
// TODO: Don't require regenerating all display lists to apply this setting
invalidateWorld(mView);
}
diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml
index 32cf2e8bac865..a25c9984b1c46 100644
--- a/core/res/res/values/attrs.xml
+++ b/core/res/res/values/attrs.xml
@@ -1141,6 +1141,15 @@
+
+
+
@@ -3116,8 +3125,13 @@
{@link android.R.attr#ambientShadowAlpha} theme attribute. -->
-
-
+
+
diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml
index fd688a72b7eae..b7908297f60bd 100644
--- a/core/res/res/values/public.xml
+++ b/core/res/res/values/public.xml
@@ -2908,7 +2908,7 @@
-
+
diff --git a/graphics/java/android/graphics/Bitmap.java b/graphics/java/android/graphics/Bitmap.java
index 364fb04e57b1b..632edfa4e46a1 100644
--- a/graphics/java/android/graphics/Bitmap.java
+++ b/graphics/java/android/graphics/Bitmap.java
@@ -1294,7 +1294,7 @@ public final class Bitmap implements Parcelable {
final RenderNode node = RenderNode.create("BitmapTemporary", null);
node.setLeftTopRightBottom(0, 0, width, height);
node.setClipToBounds(false);
- node.setAllowForceDark(false);
+ node.setForceDarkAllowed(false);
final RecordingCanvas canvas = node.start(width, height);
if (source.getWidth() != width || source.getHeight() != height) {
canvas.scale(width / (float) source.getWidth(),
diff --git a/graphics/java/android/graphics/RenderNode.java b/graphics/java/android/graphics/RenderNode.java
index 60641d82cb653..b61488cba9342 100644
--- a/graphics/java/android/graphics/RenderNode.java
+++ b/graphics/java/android/graphics/RenderNode.java
@@ -931,16 +931,16 @@ public class RenderNode {
* @param allow Whether or not to allow force dark.
* @return true If the value has changed, false otherwise.
*/
- public boolean setAllowForceDark(boolean allow) {
+ public boolean setForceDarkAllowed(boolean allow) {
return nSetAllowForceDark(mNativeRenderNode, allow);
}
/**
- * See {@link #setAllowForceDark(boolean)}
+ * See {@link #setForceDarkAllowed(boolean)}
*
* @return true if force dark is allowed (default), false if it is disabled
*/
- public boolean getAllowForceDark() {
+ public boolean isForceDarkAllowed() {
return nGetAllowForceDark(mNativeRenderNode);
}
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
index 3007b6e68b78e..c84449683c1cc 100644
--- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
+++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
@@ -207,11 +207,11 @@ public class ScreenDecorations extends SystemUI implements Tunable {
mOverlay.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
mOverlay.setAlpha(0);
- mOverlay.setAllowForceDark(false);
+ mOverlay.setForceDarkAllowed(false);
mBottomOverlay.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
mBottomOverlay.setAlpha(0);
- mBottomOverlay.setAllowForceDark(false);
+ mBottomOverlay.setForceDarkAllowed(false);
updateViews();