[libgraphicsenv] Add an API to enable profiling features
Set PR_SET_DUMPABLE for process that wishes to
inject Vk/GL layers via metadata. This signals the
graphics driver to enable profiling features.
Bug: 138204026
Test: Add <meta-data android:name="com.android.graphics.injectLayers.enable" android:value="true" />
to the <application> xml in the manifest of a GL/Vk app. Call
prctl(PR_GET_DUMPABLE) in a native app to verify.
Change-Id: Ife7d18f77775499629d830376a76c4599afd9c15
diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp
index 30f5f73..2859111 100644
--- a/libs/graphicsenv/GraphicsEnv.cpp
+++ b/libs/graphicsenv/GraphicsEnv.cpp
@@ -307,6 +307,13 @@
}
}
+bool GraphicsEnv::setInjectLayersPrSetDumpable() {
+ if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0) == -1) {
+ return false;
+ }
+ return true;
+}
+
void* GraphicsEnv::loadLibrary(std::string name) {
const android_dlextinfo dlextinfo = {
.flags = ANDROID_DLEXT_USE_NAMESPACE,
diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
index a47f468..83448d4 100644
--- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
+++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h
@@ -68,6 +68,14 @@
void setDriverLoaded(GpuStatsInfo::Api api, bool isDriverLoaded, int64_t driverLoadingTime);
/*
+ * Api for Vk/GL layer injection. Presently, drivers enable certain
+ * profiling features when prctl(PR_GET_DUMPABLE) returns true.
+ * Calling this when layer injection metadata is present allows the driver
+ * to enable profiling even when in a non-debuggable app
+ */
+ bool setInjectLayersPrSetDumpable();
+
+ /*
* Apis for ANGLE
*/
// Check if the requested app should use ANGLE.