Loading core/java/android/view/ViewRootImpl.java +3 −21 Original line number Diff line number Diff line Loading @@ -154,7 +154,6 @@ import android.os.SystemClock; import android.os.SystemProperties; import android.os.Trace; import android.os.UserHandle; import android.provider.Settings; import android.sysprop.DisplayProperties; import android.text.TextUtils; import android.util.AndroidRuntimeException; Loading Loading @@ -1734,21 +1733,8 @@ public final class ViewRootImpl implements ViewParent, return getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; } /** Returns true if force dark should be enabled according to various settings */ @VisibleForTesting public boolean isForceDarkEnabled() { boolean isForceInvertEnabled = Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* def= */ 0, UserHandle.myUserId()) == 1; // Force invert ignores all developer opt-outs. // We also ignore dark theme, since the app developer can override the user's preference // for dark mode in configuration.uiMode. Instead, we assume that the force invert setting // will be enabled at the same time dark theme is in the Settings app. if (isForceInvertEnabled) { return true; } private void updateForceDarkMode() { if (mAttachInfo.mThreadedRenderer == null) return; boolean useAutoDark = getNightMode() == Configuration.UI_MODE_NIGHT_YES; Loading @@ -1760,12 +1746,8 @@ public final class ViewRootImpl implements ViewParent, && a.getBoolean(R.styleable.Theme_forceDarkAllowed, forceDarkAllowedDefault); a.recycle(); } return useAutoDark; } private void updateForceDarkMode() { if (mAttachInfo.mThreadedRenderer == null) return; if (mAttachInfo.mThreadedRenderer.setForceDark(isForceDarkEnabled())) { if (mAttachInfo.mThreadedRenderer.setForceDark(useAutoDark)) { // TODO: Don't require regenerating all display lists to apply this setting invalidateWorld(mView); } Loading core/tests/coretests/src/android/view/ViewRootImplTest.java +0 −111 Original line number Diff line number Diff line Loading @@ -38,17 +38,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import android.app.Instrumentation; import android.app.UiModeManager; import android.content.Context; import android.hardware.display.DisplayManagerGlobal; import android.os.Binder; import android.os.SystemProperties; import android.platform.test.annotations.Presubmit; import android.provider.Settings; import android.util.Log; import android.view.WindowInsets.Side; import android.view.WindowInsets.Type; Loading @@ -57,9 +52,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; import com.android.compatibility.common.util.ShellIdentityUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; Loading @@ -79,7 +71,6 @@ import java.util.concurrent.TimeUnit; @SmallTest @RunWith(AndroidJUnit4.class) public class ViewRootImplTest { private static final String TAG = "ViewRootImplTest"; private ViewRootImpl mViewRootImpl; private volatile boolean mKeyReceived = false; Loading Loading @@ -110,18 +101,6 @@ public class ViewRootImplTest { mViewRootImpl = new ViewRootImpl(sContext, sContext.getDisplayNoVerify())); } @After public void teardown() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.resetToDefaults(sContext.getContentResolver(), TAG); var uiModeManager = sContext.getSystemService(UiModeManager.class); uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO); setForceDarkSysProp(false); }); } @Test public void adjustLayoutParamsForCompatibility_layoutFullscreen() { final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(TYPE_APPLICATION); Loading Loading @@ -421,96 +400,6 @@ public class ViewRootImplTest { assertThat(result).isFalse(); } @Test public void forceInvertOffDarkThemeOff_forceDarkModeDisabled() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.putInt( sContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* value= */ 0 ); var uiModeManager = sContext.getSystemService(UiModeManager.class); uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO); }); sInstrumentation.runOnMainSync(() -> mViewRootImpl.updateConfiguration(sContext.getDisplayNoVerify().getDisplayId()) ); assertThat(mViewRootImpl.isForceDarkEnabled()).isFalse(); } @Test public void forceInvertOnDarkThemeOff_forceDarkModeEnabled() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.putInt( sContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* value= */ 1 ); var uiModeManager = sContext.getSystemService(UiModeManager.class); uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO); }); sInstrumentation.runOnMainSync(() -> mViewRootImpl.updateConfiguration(sContext.getDisplayNoVerify().getDisplayId()) ); assertThat(mViewRootImpl.isForceDarkEnabled()).isTrue(); } @Test public void forceInvertOffForceDarkOff_forceDarkModeDisabled() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.putInt( sContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* value= */ 0 ); // TODO(b/297556388): figure out how to set this without getting blocked by SELinux assumeTrue(setForceDarkSysProp(true)); }); sInstrumentation.runOnMainSync(() -> mViewRootImpl.updateConfiguration(sContext.getDisplayNoVerify().getDisplayId()) ); assertThat(mViewRootImpl.isForceDarkEnabled()).isFalse(); } @Test public void forceInvertOffForceDarkOn_forceDarkModeEnabled() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.putInt( sContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* value= */ 0 ); assumeTrue(setForceDarkSysProp(true)); }); sInstrumentation.runOnMainSync(() -> mViewRootImpl.updateConfiguration(sContext.getDisplayNoVerify().getDisplayId()) ); assertThat(mViewRootImpl.isForceDarkEnabled()).isTrue(); } private boolean setForceDarkSysProp(boolean isForceDarkEnabled) { try { SystemProperties.set( ThreadedRenderer.DEBUG_FORCE_DARK, Boolean.toString(isForceDarkEnabled) ); return true; } catch (Exception e) { Log.e(TAG, "Failed to set force_dark sysprop", e); return false; } } class KeyView extends View { KeyView(Context context) { super(context); Loading Loading
core/java/android/view/ViewRootImpl.java +3 −21 Original line number Diff line number Diff line Loading @@ -154,7 +154,6 @@ import android.os.SystemClock; import android.os.SystemProperties; import android.os.Trace; import android.os.UserHandle; import android.provider.Settings; import android.sysprop.DisplayProperties; import android.text.TextUtils; import android.util.AndroidRuntimeException; Loading Loading @@ -1734,21 +1733,8 @@ public final class ViewRootImpl implements ViewParent, return getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; } /** Returns true if force dark should be enabled according to various settings */ @VisibleForTesting public boolean isForceDarkEnabled() { boolean isForceInvertEnabled = Settings.Secure.getIntForUser( mContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* def= */ 0, UserHandle.myUserId()) == 1; // Force invert ignores all developer opt-outs. // We also ignore dark theme, since the app developer can override the user's preference // for dark mode in configuration.uiMode. Instead, we assume that the force invert setting // will be enabled at the same time dark theme is in the Settings app. if (isForceInvertEnabled) { return true; } private void updateForceDarkMode() { if (mAttachInfo.mThreadedRenderer == null) return; boolean useAutoDark = getNightMode() == Configuration.UI_MODE_NIGHT_YES; Loading @@ -1760,12 +1746,8 @@ public final class ViewRootImpl implements ViewParent, && a.getBoolean(R.styleable.Theme_forceDarkAllowed, forceDarkAllowedDefault); a.recycle(); } return useAutoDark; } private void updateForceDarkMode() { if (mAttachInfo.mThreadedRenderer == null) return; if (mAttachInfo.mThreadedRenderer.setForceDark(isForceDarkEnabled())) { if (mAttachInfo.mThreadedRenderer.setForceDark(useAutoDark)) { // TODO: Don't require regenerating all display lists to apply this setting invalidateWorld(mView); } Loading
core/tests/coretests/src/android/view/ViewRootImplTest.java +0 −111 Original line number Diff line number Diff line Loading @@ -38,17 +38,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.junit.Assume.assumeTrue; import android.app.Instrumentation; import android.app.UiModeManager; import android.content.Context; import android.hardware.display.DisplayManagerGlobal; import android.os.Binder; import android.os.SystemProperties; import android.platform.test.annotations.Presubmit; import android.provider.Settings; import android.util.Log; import android.view.WindowInsets.Side; import android.view.WindowInsets.Type; Loading @@ -57,9 +52,6 @@ import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import androidx.test.platform.app.InstrumentationRegistry; import com.android.compatibility.common.util.ShellIdentityUtils; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; Loading @@ -79,7 +71,6 @@ import java.util.concurrent.TimeUnit; @SmallTest @RunWith(AndroidJUnit4.class) public class ViewRootImplTest { private static final String TAG = "ViewRootImplTest"; private ViewRootImpl mViewRootImpl; private volatile boolean mKeyReceived = false; Loading Loading @@ -110,18 +101,6 @@ public class ViewRootImplTest { mViewRootImpl = new ViewRootImpl(sContext, sContext.getDisplayNoVerify())); } @After public void teardown() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.resetToDefaults(sContext.getContentResolver(), TAG); var uiModeManager = sContext.getSystemService(UiModeManager.class); uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO); setForceDarkSysProp(false); }); } @Test public void adjustLayoutParamsForCompatibility_layoutFullscreen() { final WindowManager.LayoutParams attrs = new WindowManager.LayoutParams(TYPE_APPLICATION); Loading Loading @@ -421,96 +400,6 @@ public class ViewRootImplTest { assertThat(result).isFalse(); } @Test public void forceInvertOffDarkThemeOff_forceDarkModeDisabled() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.putInt( sContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* value= */ 0 ); var uiModeManager = sContext.getSystemService(UiModeManager.class); uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO); }); sInstrumentation.runOnMainSync(() -> mViewRootImpl.updateConfiguration(sContext.getDisplayNoVerify().getDisplayId()) ); assertThat(mViewRootImpl.isForceDarkEnabled()).isFalse(); } @Test public void forceInvertOnDarkThemeOff_forceDarkModeEnabled() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.putInt( sContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* value= */ 1 ); var uiModeManager = sContext.getSystemService(UiModeManager.class); uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO); }); sInstrumentation.runOnMainSync(() -> mViewRootImpl.updateConfiguration(sContext.getDisplayNoVerify().getDisplayId()) ); assertThat(mViewRootImpl.isForceDarkEnabled()).isTrue(); } @Test public void forceInvertOffForceDarkOff_forceDarkModeDisabled() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.putInt( sContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* value= */ 0 ); // TODO(b/297556388): figure out how to set this without getting blocked by SELinux assumeTrue(setForceDarkSysProp(true)); }); sInstrumentation.runOnMainSync(() -> mViewRootImpl.updateConfiguration(sContext.getDisplayNoVerify().getDisplayId()) ); assertThat(mViewRootImpl.isForceDarkEnabled()).isFalse(); } @Test public void forceInvertOffForceDarkOn_forceDarkModeEnabled() { ShellIdentityUtils.invokeWithShellPermissions(() -> { Settings.Secure.putInt( sContext.getContentResolver(), Settings.Secure.ACCESSIBILITY_FORCE_INVERT_COLOR_ENABLED, /* value= */ 0 ); assumeTrue(setForceDarkSysProp(true)); }); sInstrumentation.runOnMainSync(() -> mViewRootImpl.updateConfiguration(sContext.getDisplayNoVerify().getDisplayId()) ); assertThat(mViewRootImpl.isForceDarkEnabled()).isTrue(); } private boolean setForceDarkSysProp(boolean isForceDarkEnabled) { try { SystemProperties.set( ThreadedRenderer.DEBUG_FORCE_DARK, Boolean.toString(isForceDarkEnabled) ); return true; } catch (Exception e) { Log.e(TAG, "Failed to set force_dark sysprop", e); return false; } } class KeyView extends View { KeyView(Context context) { super(context); Loading