Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4e6db90f authored by Peiyong Lin's avatar Peiyong Lin Committed by Gerrit Code Review
Browse files

Merge "Unconditionally enable ANGLE developer option UI." into main

parents 643136bb 8fc1391a
Loading
Loading
Loading
Loading
+9 −29
Original line number Diff line number Diff line
@@ -51,9 +51,6 @@ public class GraphicsDriverEnableAngleAsSystemDriverController

    private boolean mShouldToggleSwitchBackOnRebootDialogDismiss;

    @VisibleForTesting
    static final String PROPERTY_RO_GFX_ANGLE_SUPPORTED = "ro.gfx.angle.supported";

    @VisibleForTesting
    static final String PROPERTY_PERSISTENT_GRAPHICS_EGL = "persist.graphics.egl";

@@ -97,11 +94,6 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
        return mSystemProperties.getBoolean(PROPERTY_DEBUG_ANGLE_DEVELOPER_OPTION, false);
    }

    private boolean isAngleSupported() {
        return TextUtils.equals(
                        mSystemProperties.get(PROPERTY_RO_GFX_ANGLE_SUPPORTED, ""), "true");
    }

    @VisibleForTesting
    GraphicsDriverEnableAngleAsSystemDriverController(
            Context context, DevelopmentSettingsDashboardFragment fragment, Injector injector) {
@@ -145,10 +137,6 @@ public class GraphicsDriverEnableAngleAsSystemDriverController

    /** Return the default value of "persist.graphics.egl" */
    public boolean isDefaultValue() {
        if (!isAngleSupported()) {
            return true;
        }

        final String currentGlesDriver =
                mSystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL, "");
        // default value of "persist.graphics.egl" is ""
@@ -158,17 +146,11 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
    @Override
    public void updateState(Preference preference) {
        super.updateState(preference);
        if (isAngleSupported()) {
            // set switch on if "persist.graphics.egl" is "angle" and angle is built in /vendor
            // set switch off otherwise.
        // set switch on if "persist.graphics.egl" is "angle".
        final String currentGlesDriver =
                mSystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL, "");
        final boolean isAngle = TextUtils.equals(ANGLE_DRIVER_SUFFIX, currentGlesDriver);
        ((SwitchPreference) mPreference).setChecked(isAngle);
        } else {
            mPreference.setEnabled(false);
            ((SwitchPreference) mPreference).setChecked(false);
        }

        // 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
@@ -182,13 +164,11 @@ public class GraphicsDriverEnableAngleAsSystemDriverController
    protected void onDeveloperOptionsSwitchDisabled() {
        // 1) disable the switch
        super.onDeveloperOptionsSwitchDisabled();
        if (isAngleSupported()) {
        // 2) set the persist.graphics.egl empty string
        GraphicsEnvironment.getInstance().toggleAngleAsSystemDriver(false);
        // 3) reset the switch
        ((SwitchPreference) mPreference).setChecked(false);
    }
    }

    void toggleSwitchBack() {
        final String currentGlesDriver =
+2 −24
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ 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;

import static com.google.common.truth.Truth.assertThat;

@@ -79,7 +78,6 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerTest {

    @Test
    public void onPreferenceChange_switchOn_shouldEnableAngleAsSystemDriver() {
        ShadowSystemProperties.override(PROPERTY_RO_GFX_ANGLE_SUPPORTED, "true");
        // since GraphicsEnvironment is mocked in Robolectric test environment,
        // we will override the system property persist.graphics.egl as if it is changed by
        // mGraphicsEnvironment.toggleAngleAsSystemDriver(true).
@@ -96,7 +94,6 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerTest {

    @Test
    public void onPreferenceChange_switchOff_shouldDisableAngleAsSystemDriver() {
        ShadowSystemProperties.override(PROPERTY_RO_GFX_ANGLE_SUPPORTED, "true");
        // since GraphicsEnvironment is mocked in Robolectric test environment,
        // we will override the system property persist.graphics.egl as if it is changed by
        // mGraphicsEnvironment.toggleAngleAsSystemDriver(false).
@@ -112,30 +109,14 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerTest {
    }

    @Test
    public void updateState_angleNotSupported_preferenceShouldNotBeChecked() {
        ShadowSystemProperties.override(PROPERTY_RO_GFX_ANGLE_SUPPORTED, "");
        mController.updateState(mPreference);
        verify(mPreference).setChecked(false);
    }

    @Test
    public void updateState_angleNotSupported_preferenceShouldNotBeEnabled() {
        ShadowSystemProperties.override(PROPERTY_RO_GFX_ANGLE_SUPPORTED, "");
        mController.updateState(mPreference);
        verify(mPreference).setEnabled(false);
    }

    @Test
    public void updateState_angleSupported_angleUsed_preferenceShouldBeChecked() {
        ShadowSystemProperties.override(PROPERTY_RO_GFX_ANGLE_SUPPORTED, "true");
    public void updateState_angleUsed_preferenceShouldBeChecked() {
        ShadowSystemProperties.override(PROPERTY_PERSISTENT_GRAPHICS_EGL, ANGLE_DRIVER_SUFFIX);
        mController.updateState(mPreference);
        verify(mPreference).setChecked(true);
    }

    @Test
    public void updateState_angleSupported_angleNotUsed_preferenceShouldNotBeChecked() {
        ShadowSystemProperties.override(PROPERTY_RO_GFX_ANGLE_SUPPORTED, "true");
    public void updateState_angleNotUsed_preferenceShouldNotBeChecked() {
        ShadowSystemProperties.override(PROPERTY_PERSISTENT_GRAPHICS_EGL, "");
        mController.updateState(mPreference);
        verify(mPreference).setChecked(false);
@@ -143,7 +124,6 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerTest {

    @Test
    public void onDeveloperOptionSwitchDisabled_shouldDisableAngleAsSystemDriver() {
        ShadowSystemProperties.override(PROPERTY_RO_GFX_ANGLE_SUPPORTED, "true");
        mController.onDeveloperOptionsSwitchDisabled();
        final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
        assertThat(systemEGLDriver).isEqualTo("");
@@ -151,14 +131,12 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerTest {

    @Test
    public void onDeveloperOptionSwitchDisabled_preferenceShouldNotBeChecked() {
        ShadowSystemProperties.override(PROPERTY_RO_GFX_ANGLE_SUPPORTED, "true");
        mController.onDeveloperOptionsSwitchDisabled();
        verify(mPreference).setChecked(false);
    }

    @Test
    public void onDeveloperOptionsSwitchDisabled_preferenceShouldNotBeEnabled() {
        ShadowSystemProperties.override(PROPERTY_RO_GFX_ANGLE_SUPPORTED, "true");
        mController.onDeveloperOptionsSwitchDisabled();
        verify(mPreference).setEnabled(false);
    }
+3 −33
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static com.android.settings.development.graphicsdriver.GraphicsDriverEnab
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;

@@ -181,31 +180,13 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
    }

    @Test
    public void updateState_angleNotSupported_PreferenceShouldDisabled() {
        when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any())).thenReturn("");
        mController.updateState(mPreference);
        assertThat(mPreference.isEnabled()).isFalse();
    }

    @Test
    public void updateState_angleNotSupported_PreferenceShouldNotBeChecked() {
        when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any())).thenReturn("");
        mController.updateState(mPreference);
        assertThat(mPreference.isChecked()).isFalse();
    }

    @Test
    public void updateState_angleSupported_PreferenceShouldEnabled() {
        when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any()))
                .thenReturn("true");
    public void updateState_PreferenceShouldEnabled() {
        mController.updateState(mPreference);
        assertThat(mPreference.isEnabled()).isTrue();
    }

    @Test
    public void updateState_angleSupported_angleIsSystemGLESDriver_PreferenceShouldBeChecked() {
        when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any()))
                .thenReturn("true");
    public void updateState_angleIsSystemGLESDriver_PreferenceShouldBeChecked() {
        when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any()))
                .thenReturn(ANGLE_DRIVER_SUFFIX);
        mController.updateState(mPreference);
@@ -213,10 +194,7 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
    }

    @Test
    public void
            updateState_angleSupported_angleIsNotSystemGLESDriver_PreferenceShouldNotBeChecked() {
        when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any()))
                .thenReturn("true");
    public void updateState_angleIsNotSystemGLESDriver_PreferenceShouldNotBeChecked() {
        when(mSystemPropertiesMock.get(eq(PROPERTY_PERSISTENT_GRAPHICS_EGL), any())).thenReturn("");
        mController.updateState(mPreference);
        assertThat(mPreference.isChecked()).isFalse();
@@ -232,8 +210,6 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {

        // Test that onDeveloperOptionSwitchDisabled,
        // persist.graphics.egl updates to ""
        when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any()))
                .thenReturn("true");
        mController.onDeveloperOptionsSwitchDisabled();
        propertyChangeSignal1.wait(100);
        final String systemEGLDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
@@ -245,16 +221,12 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {

    @Test
    public void onDeveloperOptionSwitchDisabled_PreferenceShouldNotBeChecked() {
        when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any()))
                .thenReturn("true");
        mController.onDeveloperOptionsSwitchDisabled();
        assertThat(mPreference.isChecked()).isFalse();
    }

    @Test
    public void onDeveloperOptionSwitchDisabled_PreferenceShouldDisabled() {
        when(mSystemPropertiesMock.get(eq(PROPERTY_RO_GFX_ANGLE_SUPPORTED), any()))
                .thenReturn("true");
        mController.onDeveloperOptionsSwitchDisabled();
        assertThat(mPreference.isEnabled()).isFalse();
    }
@@ -480,8 +452,6 @@ public class GraphicsDriverEnableAngleAsSystemDriverControllerJUnitTest {
        // 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()))