Add new API to toggle ANGLE as the default system GLES driver
Bug:b/270994705
Test: Flash, verify Pixel 7 can boot.
Toggle the developer option switch.
adb shell getprop persist.graphics.egl is returning
right values with switch set on and off.
Change-Id: Idce453d79e97c48cc965900315799784a001e053
diff --git a/services/gpuservice/GpuService.cpp b/services/gpuservice/GpuService.cpp
index aaa8c18..5e7b2e8 100644
--- a/services/gpuservice/GpuService.cpp
+++ b/services/gpuservice/GpuService.cpp
@@ -19,6 +19,7 @@
#include "GpuService.h"
#include <android-base/stringprintf.h>
+#include <android-base/properties.h>
#include <binder/IPCThreadState.h>
#include <binder/IResultReceiver.h>
#include <binder/Parcel.h>
@@ -46,6 +47,8 @@
} // namespace
const String16 sDump("android.permission.DUMP");
+const String16 sAccessGpuServicePermission("android.permission.ACCESS_GPU_SERVICE");
+const std::string sAngleGlesDriverSuffix = "angle";
const char* const GpuService::SERVICE_NAME = "gpu";
@@ -88,6 +91,29 @@
mGpuStats->insertTargetStatsArray(appPackageName, driverVersionCode, stats, values, valueCount);
}
+void GpuService::toggleAngleAsSystemDriver(bool enabled) {
+ IPCThreadState* ipc = IPCThreadState::self();
+ const int pid = ipc->getCallingPid();
+ const int uid = ipc->getCallingUid();
+
+ // only system_server with the ACCESS_GPU_SERVICE permission is allowed to set
+ // persist.graphics.egl
+ if (uid != AID_SYSTEM ||
+ !PermissionCache::checkPermission(sAccessGpuServicePermission, pid, uid)) {
+ ALOGE("Permission Denial: can't set persist.graphics.egl from setAngleAsSystemDriver() "
+ "pid=%d, uid=%d\n", pid, uid);
+ return;
+ }
+
+ std::lock_guard<std::mutex> lock(mLock);
+ if (enabled) {
+ android::base::SetProperty("persist.graphics.egl", sAngleGlesDriverSuffix);
+ } else {
+ android::base::SetProperty("persist.graphics.egl", "");
+ }
+}
+
+
void GpuService::setUpdatableDriverPath(const std::string& driverPath) {
IPCThreadState* ipc = IPCThreadState::self();
const int pid = ipc->getCallingPid();