Add developer option switch to set ANGLE as the default system driver

This change adds a new developer option switch called
"Enable ANGLE". It defaults to off. User can choose
to toggle it on and off, and the value of the system
property "persist.graphics.egl" is changed accordingly:

switch off: persist.graphics.egl=""
switch on: persist.graphics.egl="angle"

When user toggles the switch, a reboot window is
popped up asking user to reboot now to make the change
takes effect. If user chooses to cancel the reboot,
the switch is toggled back. This enforces that a reboot
is required whenever the "persis.graphics.egl" value
changes.

Upon reboot, we will load either ANGLE or native
GLES driver as the system driver, based on the value of
"persist.graphics.egl".

The switch is disabled if ANGLE is not installed
in /vendor partition. We use the system property
"ro.gfx.angle.supported" as an indicator. We set the
two conditions together in angle.mk file. Any device
mk file that inherits angle.mk file will result in
ANGLE libs installed in /vendor and "ro.gfx.angle.supported"
set to true.

Bug: b/270994705
Test: m; flash and check Pixel 7 boots fine
atest SettingsRoboTests:GraphicsDriverEnableAngleAsSystemDriverControllerTest

Change-Id: I565eff614472bb6ba50742e7dfa49b50dca2809f
This commit is contained in:
Yuxin Hu
2023-04-19 02:40:13 +00:00
parent 0927e2af1d
commit 25b270c0f8
9 changed files with 351 additions and 20 deletions

View File

@@ -19,7 +19,6 @@ package com.android.settings.development;
import static android.provider.Settings.Global.DEVELOPMENT_FORCE_DESKTOP_MODE_ON_EXTERNAL_DISPLAYS;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
@@ -83,12 +82,6 @@ public class DesktopModePreferenceController extends DeveloperOptionsPreferenceC
((SwitchPreference) mPreference).setChecked(false);
}
@Override
public void onRebootConfirmed() {
final Intent intent = new Intent(Intent.ACTION_REBOOT);
mContext.startActivity(intent);
}
@VisibleForTesting
String getBuildType() {
return Build.TYPE;

View File

@@ -66,6 +66,7 @@ import com.android.settings.development.bluetooth.BluetoothCodecDialogPreference
import com.android.settings.development.bluetooth.BluetoothHDAudioPreferenceController;
import com.android.settings.development.bluetooth.BluetoothQualityDialogPreferenceController;
import com.android.settings.development.bluetooth.BluetoothSampleRateDialogPreferenceController;
import com.android.settings.development.graphicsdriver.GraphicsDriverEnableAngleAsSystemDriverController;
import com.android.settings.development.qstile.DevelopmentTiles;
import com.android.settings.development.storage.SharedDataPreferenceController;
import com.android.settings.overlay.FeatureFactory;
@@ -640,6 +641,7 @@ public class DevelopmentSettingsDashboardFragment extends RestrictedDashboardFra
controllers.add(new SelectDebugAppPreferenceController(context, fragment));
controllers.add(new WaitForDebuggerPreferenceController(context));
controllers.add(new EnableGpuDebugLayersPreferenceController(context));
controllers.add(new GraphicsDriverEnableAngleAsSystemDriverController(context, fragment));
controllers.add(new ForcePeakRefreshRatePreferenceController(context));
controllers.add(new EnableVerboseVendorLoggingPreferenceController(context));
controllers.add(new VerifyAppsOverUsbPreferenceController(context));

View File

@@ -17,7 +17,6 @@
package com.android.settings.development;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.provider.Settings;
@@ -81,12 +80,6 @@ public class FreeformWindowsPreferenceController extends DeveloperOptionsPrefere
((SwitchPreference) mPreference).setChecked(false);
}
@Override
public void onRebootConfirmed() {
final Intent intent = new Intent(Intent.ACTION_REBOOT);
mContext.startActivity(intent);
}
@VisibleForTesting
String getBuildType() {
return Build.TYPE;

View File

@@ -37,22 +37,33 @@ public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment
private static final String TAG = "FreeformPrefRebootDlg";
private final int mMessageId;
private final int mCancelButtonId;
private final RebootConfirmationDialogHost mHost;
/**
* Show an instance of this dialog.
*/
public static void show(Fragment fragment, int messageId, RebootConfirmationDialogHost host) {
show(fragment, messageId, R.string.reboot_dialog_reboot_later, host);
}
/**
* Show an instance of this dialog with cancel button string set as cancelButtonId
*/
public static void show(Fragment fragment, int messageId,
int cancelButtonId, RebootConfirmationDialogHost host) {
final FragmentManager manager = fragment.getActivity().getSupportFragmentManager();
if (manager.findFragmentByTag(TAG) == null) {
final RebootConfirmationDialogFragment dialog =
new RebootConfirmationDialogFragment(messageId, host);
new RebootConfirmationDialogFragment(messageId, cancelButtonId, host);
dialog.show(manager, TAG);
}
}
private RebootConfirmationDialogFragment(int messageId, RebootConfirmationDialogHost host) {
private RebootConfirmationDialogFragment(int messageId,
int cancelButtonId, RebootConfirmationDialogHost host) {
mMessageId = messageId;
mCancelButtonId = cancelButtonId;
mHost = host;
}
@@ -66,12 +77,16 @@ public class RebootConfirmationDialogFragment extends InstrumentedDialogFragment
return new AlertDialog.Builder(getActivity())
.setMessage(mMessageId)
.setPositiveButton(R.string.reboot_dialog_reboot_now, this)
.setNegativeButton(R.string.reboot_dialog_reboot_later, null)
.setNegativeButton(mCancelButtonId, this)
.create();
}
@Override
public void onClick(DialogInterface dialog, int which) {
mHost.onRebootConfirmed();
if (which == DialogInterface.BUTTON_POSITIVE) {
mHost.onRebootConfirmed(getContext());
} else {
mHost.onRebootCancelled();
}
}
}

View File

@@ -16,13 +16,26 @@
package com.android.settings.development;
import android.content.Context;
import android.content.Intent;
/**
* Host of {@link RebootConfirmationDialogFragment} that provides callback when user
* interacts with the UI.
*/
public interface RebootConfirmationDialogHost {
/**
* Called when user made a decision on whether to reboot the device.
* Called when user made a decision to reboot the device.
*/
void onRebootConfirmed();
default void onRebootConfirmed(Context context) {
// user presses button "Reboot now", reboot the device
final Intent intent = new Intent(Intent.ACTION_REBOOT);
context.startActivity(intent);
}
/**
* Called when user made a decision to cancel the reboot
* Default to do nothing
*/
default void onRebootCancelled() {}
}

View File

@@ -0,0 +1,139 @@
/*
* Copyright (C) 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.development.graphicsdriver;
import android.content.Context;
import android.os.GraphicsEnvironment;
import android.os.SystemProperties;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.settings.R;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
import com.android.settings.development.RebootConfirmationDialogFragment;
import com.android.settings.development.RebootConfirmationDialogHost;
import com.android.settingslib.development.DeveloperOptionsPreferenceController;
/**
* Controller to handle the events when user toggles this developer option switch: Enable ANGLE
*/
public class GraphicsDriverEnableAngleAsSystemDriverController
extends DeveloperOptionsPreferenceController
implements Preference.OnPreferenceChangeListener,
PreferenceControllerMixin,
RebootConfirmationDialogHost {
private static final String TAG = "GraphicsEnableAngleCtrl";
private static final String ENABLE_ANELE_AS_SYSTEM_DRIVER_KEY = "enable_angle_as_system_driver";
private final DevelopmentSettingsDashboardFragment mFragment;
@VisibleForTesting
static final String PROPERTY_RO_GFX_ANGLE_SUPPORTED = "ro.gfx.angle.supported";
@VisibleForTesting
static final String PROPERTY_PERSISTENT_GRAPHICS_EGL = "persist.graphics.egl";
@VisibleForTesting
static final String ANGLE_DRIVER_SUFFIX = "angle";
public GraphicsDriverEnableAngleAsSystemDriverController(
Context context, DevelopmentSettingsDashboardFragment fragment) {
super(context);
mFragment = fragment;
}
@Override
public String getPreferenceKey() {
return ENABLE_ANELE_AS_SYSTEM_DRIVER_KEY;
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean enableAngleAsSystemDriver = (Boolean) newValue;
// set "persist.graphics.egl" to "angle" if enableAngleAsSystemDriver is true
// set "persist.graphics.egl" to "" if enableAngleAsSystemDriver is false
GraphicsEnvironment.getInstance().toggleAngleAsSystemDriver(enableAngleAsSystemDriver);
// pop up a window asking user to reboot to make the new "persist.graphics.egl" take effect
RebootConfirmationDialogFragment.show(
mFragment, R.string.reboot_dialog_enable_angle_as_system_driver,
R.string.cancel, this);
return true;
}
@Override
public void updateState(Preference preference) {
// set switch on if "persist.graphics.egl" is "angle" and angle is built in /vendor
// set switch off otherwise.
final String currentGlesDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
final boolean isAngle = TextUtils.equals(ANGLE_DRIVER_SUFFIX, currentGlesDriver);
final boolean isAngleSupported =
TextUtils.equals(SystemProperties.get(PROPERTY_RO_GFX_ANGLE_SUPPORTED), "true");
((SwitchPreference) mPreference).setChecked(isAngle && isAngleSupported);
((SwitchPreference) mPreference).setEnabled(isAngleSupported);
}
@Override
protected void onDeveloperOptionsSwitchEnabled() {
// only enable the switch if ro.gfx.angle.supported is true
// we use ro.gfx.angle.supported to indicate if ANGLE libs are installed under /vendor
final boolean isAngleSupported =
TextUtils.equals(SystemProperties.get(PROPERTY_RO_GFX_ANGLE_SUPPORTED), "true");
((SwitchPreference) mPreference).setEnabled(isAngleSupported);
}
@Override
protected void onDeveloperOptionsSwitchDisabled() {
// 1) set the persist.graphics.egl empty string
GraphicsEnvironment.getInstance().toggleAngleAsSystemDriver(false);
// 2) reset the switch
((SwitchPreference) mPreference).setChecked(false);
// 3) disable switch
((SwitchPreference) mPreference).setEnabled(false);
}
@Override
public void onRebootCancelled() {
// if user presses button "Cancel", do not reboot the device, and toggles switch back
final String currentGlesDriver = SystemProperties.get(PROPERTY_PERSISTENT_GRAPHICS_EGL);
if (TextUtils.equals(ANGLE_DRIVER_SUFFIX, currentGlesDriver)) {
// if persist.graphics.egl = "angle", set the property value back to ""
GraphicsEnvironment.getInstance().toggleAngleAsSystemDriver(false);
// toggle switch off
((SwitchPreference) mPreference).setChecked(false);
return;
}
if (TextUtils.isEmpty(currentGlesDriver)) {
// if persist.graphicx.egl = "", set the persist.graphics.egl back to "angle"
GraphicsEnvironment.getInstance().toggleAngleAsSystemDriver(true);
// toggle switch on
((SwitchPreference) mPreference).setChecked(true);
return;
}
// if persist.graphics.egl holds values other than the above two, log error message
Log.e(TAG, "Invalid persist.graphics.egl property value");
}
}