From d3c75bd9eb9a7e7c8dfe0c9f810fd97d3bf0376a Mon Sep 17 00:00:00 2001 From: Peiyong Lin Date: Wed, 12 Jul 2023 18:10:03 +0000 Subject: [PATCH 1/3] [Cherry-pick] Add warning on enabling ANGLE. Enabling ANGLE on incompatible devices may cause some applications to crash, add a warning. Bug: b/287909344 Test: atest SettingsRoboTests:GraphicsDriverEnableAngleAsSystemDriverControllerTest Change-Id: I4f856ee1912a59052a6aaf7dff087ce1b649935e Merged-In: I4f856ee1912a59052a6aaf7dff087ce1b649935e --- res/values/strings.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index fa79cbbb33b..34414eca499 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -10507,7 +10507,7 @@ Enable ANGLE - Enable ANGLE as system OpenGL ES driver + Enable ANGLE as default OpenGL ES driver. Enabling it on incompatible devices may break some applications. A reboot is required to change the system OpenGL ES driver From 3182b0e29838566bfd1b4abf3393420e6362bf42 Mon Sep 17 00:00:00 2001 From: Peiyong Lin Date: Fri, 22 Sep 2023 23:27:51 +0000 Subject: [PATCH 2/3] [Cherry-pick] Add debug property to safe guard ANGLE developer option UI. Add a debug property to guard ANGLE developer option UI, only when the debug property is enabled will ANGLE developer option UI be enabled. Add further clarification in the text to indicate that this is an experimental feature. Bug: b/287909344 Test: atest -c GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest Test: atest -c GraphicsDriverEnableAngleAsSystemDriverControllerTest Change-Id: Ife31f4b0426f3ce107f86cfbaf3f1aeca567e250 Merged-In: Ife31f4b0426f3ce107f86cfbaf3f1aeca567e250 --- res/values/strings.xml | 4 +-- ...erEnableAngleAsSystemDriverController.java | 26 +++++++++++++++++++ ...GraphicsDriverSystemPropertiesWrapper.java | 9 +++++++ ...ableAngleAsSystemDriverControllerTest.java | 2 ++ ...ngleAsSystemDriverControllerJUnitTest.java | 4 +++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 34414eca499..d62512274ad 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -10505,9 +10505,9 @@ - Enable ANGLE + Experimental: Enable ANGLE - Enable ANGLE as default OpenGL ES driver. Enabling it on incompatible devices may break some applications. + Warning: Enable ANGLE as default OpenGL ES driver. This feature is in experiment and may not be compatible with some camera and video apps. A reboot is required to change the system OpenGL ES driver diff --git a/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverController.java b/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverController.java index b3af95ec0cc..95cf64c6226 100644 --- a/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverController.java +++ b/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverController.java @@ -57,6 +57,10 @@ public class GraphicsDriverEnableAngleAsSystemDriverController @VisibleForTesting static final String PROPERTY_PERSISTENT_GRAPHICS_EGL = "persist.graphics.egl"; + @VisibleForTesting + static final String PROPERTY_DEBUG_ANGLE_DEVELOPER_OPTION = + "debug.graphics.angle.developeroption.enable"; + @VisibleForTesting static final String ANGLE_DRIVER_SUFFIX = "angle"; @VisibleForTesting @@ -72,6 +76,11 @@ public class GraphicsDriverEnableAngleAsSystemDriverController public void set(String key, String val) { SystemProperties.set(key, val); } + + @Override + public boolean getBoolean(String key, boolean def) { + return SystemProperties.getBoolean(key, def); + } }; } } @@ -81,6 +90,13 @@ public class GraphicsDriverEnableAngleAsSystemDriverController this(context, fragment, new Injector()); } + // Return true if the ANGLE developer option entry point is enabled. + // This can be enabled by calling: + // `adb shell setprop debug.graphics.angle.developeroption.enable true` + private boolean isAngleDeveloperOptionEnabled() { + return mSystemProperties.getBoolean(PROPERTY_DEBUG_ANGLE_DEVELOPER_OPTION, false); + } + private boolean isAngleSupported() { return TextUtils.equals( mSystemProperties.get(PROPERTY_RO_GFX_ANGLE_SUPPORTED, ""), "true"); @@ -96,6 +112,10 @@ public class GraphicsDriverEnableAngleAsSystemDriverController // Exception is when user chooses to reboot now, the switch should keep its current value // and persist its' state over reboot. mShouldToggleSwitchBackOnRebootDialogDismiss = true; + final String persistGraphicsEglValue = + mSystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL, ""); + Log.v(TAG, "Value of " + PROPERTY_PERSISTENT_GRAPHICS_EGL + " is: " + + persistGraphicsEglValue); } @Override @@ -149,6 +169,12 @@ public class GraphicsDriverEnableAngleAsSystemDriverController mPreference.setEnabled(false); ((SwitchPreference) mPreference).setChecked(false); } + + // Regardless of whether ANGLE is enabled, disable the developer option UI + // as long as UI is not enabled via debug property. + if (!isAngleDeveloperOptionEnabled()) { + mPreference.setEnabled(false); + } } @Override diff --git a/src/com/android/settings/development/graphicsdriver/GraphicsDriverSystemPropertiesWrapper.java b/src/com/android/settings/development/graphicsdriver/GraphicsDriverSystemPropertiesWrapper.java index 549cd81c565..96842821521 100644 --- a/src/com/android/settings/development/graphicsdriver/GraphicsDriverSystemPropertiesWrapper.java +++ b/src/com/android/settings/development/graphicsdriver/GraphicsDriverSystemPropertiesWrapper.java @@ -41,4 +41,13 @@ interface GraphicsDriverSystemPropertiesWrapper { * SELinux. libc will log the underlying reason. */ void set(@NonNull String key, @Nullable String val); + + /** + * Get the boolean value for the given {@code key}. + * + * @param key the key to lookup + * @param def the default value in case the property is not set or empty + * @return if the {@code key} isn't found, return {@code def}. + */ + boolean getBoolean(@NonNull String key, @NonNull boolean def); } diff --git a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerTest.java b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerTest.java index 9210b870d77..249acf5e539 100644 --- a/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerTest.java +++ b/tests/robotests/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerTest.java @@ -17,6 +17,7 @@ package com.android.settings.development.graphicsdriver; import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController.ANGLE_DRIVER_SUFFIX; +import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController.PROPERTY_DEBUG_ANGLE_DEVELOPER_OPTION; import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController.PROPERTY_PERSISTENT_GRAPHICS_EGL; import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController.PROPERTY_RO_GFX_ANGLE_SUPPORTED; @@ -67,6 +68,7 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerTest { public void setUp() { MockitoAnnotations.initMocks(this); mContext = RuntimeEnvironment.application; + ShadowSystemProperties.override(PROPERTY_DEBUG_ANGLE_DEVELOPER_OPTION, "true"); doReturn(mTransaction).when(mFragmentManager).beginTransaction(); doReturn(mFragmentManager).when(mActivity).getSupportFragmentManager(); doReturn(mActivity).when(mFragment).getActivity(); diff --git a/tests/unit/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest.java b/tests/unit/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest.java index ae35431fef7..4aa38ae4aa2 100644 --- a/tests/unit/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest.java +++ b/tests/unit/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest.java @@ -18,12 +18,14 @@ package com.android.settings.development.graphicsdriver; import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController.ANGLE_DRIVER_SUFFIX; import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController.Injector; +import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController.PROPERTY_DEBUG_ANGLE_DEVELOPER_OPTION; import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController.PROPERTY_PERSISTENT_GRAPHICS_EGL; import static com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController.PROPERTY_RO_GFX_ANGLE_SUPPORTED; import static com.google.common.truth.Truth.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; @@ -98,6 +100,8 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest { } mContext = ApplicationProvider.getApplicationContext(); + when(mSystemPropertiesMock.getBoolean(eq(PROPERTY_DEBUG_ANGLE_DEVELOPER_OPTION), + anyBoolean())).thenReturn(true); // Construct a GraphicsDriverEnableAngleAsSystemDriverController with two Overrides: // 1) Override the mSystemProperties with mSystemPropertiesMock, From 34d308924e038e6f68027e774dd404995ff942e1 Mon Sep 17 00:00:00 2001 From: Peiyong Lin Date: Thu, 12 Oct 2023 23:55:50 +0000 Subject: [PATCH 3/3] [Cherry-pick] Allow ANGLE developer option toggle UI enabled if ANGLE is enabled. Previously the ANGLE developer option toggle UI was disabled by default and a user would need to use adb command to set the debug property to true to enable it, and every reboot would reset the debug property to false again and hence disable the toggle UI again. However, since ANGLE is still in experiment, we would like to make sure it's not easy to enable but easy to disable. This patch keeps ANGLE toggle UI enabled when ANGLE is enabled so that users can easily disable. Once ANGLE is disabled, if the debug property is not set to true, the toggle UI will remain disabled. Bug: b/293503000 Test: atest -c GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest Test: atest SettingsRoboTests:GraphicsDriverEnableAngleAsSystemDriverControllerTest Change-Id: I2e63431cd0d8cf4712fc278646627fbf34a2b542 Merged-In: I2e63431cd0d8cf4712fc278646627fbf34a2b542 --- ...erEnableAngleAsSystemDriverController.java | 7 +++--- ...ngleAsSystemDriverControllerJUnitTest.java | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverController.java b/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverController.java index 95cf64c6226..992136c9b70 100644 --- a/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverController.java +++ b/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverController.java @@ -170,9 +170,10 @@ public class GraphicsDriverEnableAngleAsSystemDriverController ((SwitchPreference) mPreference).setChecked(false); } - // Regardless of whether ANGLE is enabled, disable the developer option UI - // as long as UI is not enabled via debug property. - if (!isAngleDeveloperOptionEnabled()) { + // Disable the developer option toggle UI if ANGLE is disabled, this means next time the + // debug property needs to be set to true again to enable ANGLE. If ANGLE is enabled, don't + // disable the developer option toggle UI so that it can be turned off easily. + if (!isAngleDeveloperOptionEnabled() && !((SwitchPreference) mPreference).isChecked()) { mPreference.setEnabled(false); } } diff --git a/tests/unit/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest.java b/tests/unit/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest.java index 4aa38ae4aa2..a402d919f99 100644 --- a/tests/unit/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest.java +++ b/tests/unit/src/com/android/settings/development/graphicsdriver/GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest.java @@ -24,6 +24,8 @@ import static com.android.settings.development.graphicsdriver.GraphicsDriverEnab import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.eq; @@ -472,4 +474,27 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest { SystemProperties.removeChangeCallback(propertyChangeSignal1.getCountDownJob()); SystemProperties.removeChangeCallback(propertyChangeSignal2.getCountDownJob()); } + + @Test + public void updateState_DeveloperOptionPropertyIsFalse() { + // Test that when debug.graphics.angle.developeroption.enable is false: + when(mSystemPropertiesMock.getBoolean(eq(PROPERTY_DEBUG_ANGLE_DEVELOPER_OPTION), + anyBoolean())).thenReturn(false); + when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any())) + .thenReturn("true"); + + // 1. "Enable ANGLE" switch is on, the switch should be enabled. + when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any())) + .thenReturn(ANGLE_DRIVER_SUFFIX); + mController.updateState(mPreference); + assertTrue(mPreference.isChecked()); + assertTrue(mPreference.isEnabled()); + + // 2. "Enable ANGLE" switch is off, the switch should be disabled. + when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any())) + .thenReturn(""); + mController.updateState(mPreference); + assertFalse(mPreference.isChecked()); + assertFalse(mPreference.isEnabled()); + } }