Loading libs/graphicsenv/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -17,14 +17,17 @@ cc_library_shared { srcs: [ "GraphicsEnv.cpp", "IGpuService.cpp" ], cflags: ["-Wall", "-Werror"], shared_libs: [ "libbase", "libbinder", "libcutils", "liblog", "libutils", ], export_include_dirs: ["include"], Loading libs/graphicsenv/GraphicsEnv.cpp +42 −5 Original line number Diff line number Diff line Loading @@ -14,8 +14,11 @@ * limitations under the License. */ #define ATRACE_TAG ATRACE_TAG_GRAPHICS //#define LOG_NDEBUG 1 #define LOG_TAG "GraphicsEnv" #include <graphicsenv/GraphicsEnv.h> #include <dlfcn.h> Loading @@ -25,15 +28,16 @@ #include <android-base/properties.h> #include <android-base/strings.h> #include <android/dlext.h> #include <binder/IServiceManager.h> #include <cutils/properties.h> #include <graphicsenv/IGpuService.h> #include <log/log.h> #include <sys/prctl.h> #include <utils/Trace.h> #include <memory> #include <string> #include <dlfcn.h> // TODO(b/37049319) Get this from a header once one exists extern "C" { android_namespace_t* android_get_exported_namespace(const char*); Loading Loading @@ -155,9 +159,16 @@ void GraphicsEnv::setDriverPath(const std::string path) { void GraphicsEnv::setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t driverVersionCode, const std::string appPackageName) { ALOGV("setGpuStats: drvPkgName[%s], drvVerName[%s], drvVerCode[%lld], appPkgName[%s]", driverPackageName.c_str(), driverVersionName.c_str(), (long long)driverVersionCode, appPackageName.c_str()); ATRACE_CALL(); ALOGV("setGpuStats:\n" "\tdriverPackageName[%s]\n" "\tdriverVersionName[%s]\n" "\tdriverVersionCode[%llu]\n" "\tappPackageName[%s]\n", driverPackageName.c_str(), driverVersionName.c_str(), (unsigned long long)driverVersionCode, appPackageName.c_str()); mGpuStats = { .driverPackageName = driverPackageName, .driverVersionName = driverVersionName, Loading @@ -166,6 +177,32 @@ void GraphicsEnv::setGpuStats(const std::string driverPackageName, }; } void GraphicsEnv::sendGpuStats() { ATRACE_CALL(); // Do not sendGpuStats for those skipping the GraphicsEnvironment setup if (mGpuStats.appPackageName.empty()) return; ALOGV("sendGpuStats:\n" "\tdriverPackageName[%s]\n" "\tdriverVersionName[%s]\n" "\tdriverVersionCode[%llu]\n" "\tappPackageName[%s]\n", mGpuStats.driverPackageName.c_str(), mGpuStats.driverVersionName.c_str(), (unsigned long long)mGpuStats.driverVersionCode, mGpuStats.appPackageName.c_str()); const sp<IBinder> binder = defaultServiceManager()->checkService(String16("gpu")); if (!binder) { ALOGE("Failed to get gpu service for [%s]", mGpuStats.appPackageName.c_str()); return; } interface_cast<IGpuService>(binder)->setGpuStats(mGpuStats.driverPackageName, mGpuStats.driverVersionName, mGpuStats.driverVersionCode, mGpuStats.appPackageName); } void* GraphicsEnv::loadLibrary(std::string name) { const android_dlextinfo dlextinfo = { .flags = ANDROID_DLEXT_USE_NAMESPACE, Loading libs/graphicsenv/IGpuService.cpp 0 → 100644 +96 −0 Original line number Diff line number Diff line /* * Copyright 2019 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. */ #define LOG_TAG "GpuService" #include <graphicsenv/IGpuService.h> #include <binder/IResultReceiver.h> #include <binder/Parcel.h> namespace android { class BpGpuService : public BpInterface<IGpuService> { public: explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {} virtual void setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t driverVersionCode, const std::string appPackageName) { Parcel data, reply; data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); data.writeUtf8AsUtf16(driverPackageName); data.writeUtf8AsUtf16(driverVersionName); data.writeUint64(driverVersionCode); data.writeUtf8AsUtf16(appPackageName); remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply); } }; IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { ALOGV("onTransact code[0x%X]", code); status_t status; switch (code) { case SET_GPU_STATS: { CHECK_INTERFACE(IGpuService, data, reply); std::string driverPackageName; if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status; std::string driverVersionName; if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status; uint64_t driverVersionCode; if ((status = data.readUint64(&driverVersionCode)) != OK) return status; std::string appPackageName; if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; setGpuStats(driverPackageName, driverVersionName, driverVersionCode, appPackageName); return OK; } case SHELL_COMMAND_TRANSACTION: { int in = data.readFileDescriptor(); int out = data.readFileDescriptor(); int err = data.readFileDescriptor(); std::vector<String16> args; data.readString16Vector(&args); sp<IBinder> unusedCallback; if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status; sp<IResultReceiver> resultReceiver; if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status; status = shellCommand(in, out, err, args); if (resultReceiver != nullptr) resultReceiver->send(status); return OK; } default: return BBinder::onTransact(code, data, reply, flags); } } } // namespace android libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ public: android_namespace_t* getDriverNamespace(); void setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t versionCode, const std::string appPackageName); void sendGpuStats(); bool shouldUseAngle(std::string appName); bool shouldUseAngle(); Loading libs/graphicsenv/include/graphicsenv/IGpuService.h 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright 2019 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. */ #pragma once #include <binder/IInterface.h> #include <cutils/compiler.h> #include <vector> namespace android { /* * This class defines the Binder IPC interface for GPU-related queries and * control. */ class IGpuService : public IInterface { public: DECLARE_META_INTERFACE(GpuService); // set GPU stats from GraphicsEnvironment. virtual void setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t driverVersionCode, const std::string appPackageName) = 0; }; class BnGpuService : public BnInterface<IGpuService> { public: enum IGpuServiceTag { SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION, // Always append new enum to the end. }; status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) override; protected: virtual status_t shellCommand(int in, int out, int err, std::vector<String16>& args) = 0; }; } // namespace android Loading
libs/graphicsenv/Android.bp +3 −0 Original line number Diff line number Diff line Loading @@ -17,14 +17,17 @@ cc_library_shared { srcs: [ "GraphicsEnv.cpp", "IGpuService.cpp" ], cflags: ["-Wall", "-Werror"], shared_libs: [ "libbase", "libbinder", "libcutils", "liblog", "libutils", ], export_include_dirs: ["include"], Loading
libs/graphicsenv/GraphicsEnv.cpp +42 −5 Original line number Diff line number Diff line Loading @@ -14,8 +14,11 @@ * limitations under the License. */ #define ATRACE_TAG ATRACE_TAG_GRAPHICS //#define LOG_NDEBUG 1 #define LOG_TAG "GraphicsEnv" #include <graphicsenv/GraphicsEnv.h> #include <dlfcn.h> Loading @@ -25,15 +28,16 @@ #include <android-base/properties.h> #include <android-base/strings.h> #include <android/dlext.h> #include <binder/IServiceManager.h> #include <cutils/properties.h> #include <graphicsenv/IGpuService.h> #include <log/log.h> #include <sys/prctl.h> #include <utils/Trace.h> #include <memory> #include <string> #include <dlfcn.h> // TODO(b/37049319) Get this from a header once one exists extern "C" { android_namespace_t* android_get_exported_namespace(const char*); Loading Loading @@ -155,9 +159,16 @@ void GraphicsEnv::setDriverPath(const std::string path) { void GraphicsEnv::setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t driverVersionCode, const std::string appPackageName) { ALOGV("setGpuStats: drvPkgName[%s], drvVerName[%s], drvVerCode[%lld], appPkgName[%s]", driverPackageName.c_str(), driverVersionName.c_str(), (long long)driverVersionCode, appPackageName.c_str()); ATRACE_CALL(); ALOGV("setGpuStats:\n" "\tdriverPackageName[%s]\n" "\tdriverVersionName[%s]\n" "\tdriverVersionCode[%llu]\n" "\tappPackageName[%s]\n", driverPackageName.c_str(), driverVersionName.c_str(), (unsigned long long)driverVersionCode, appPackageName.c_str()); mGpuStats = { .driverPackageName = driverPackageName, .driverVersionName = driverVersionName, Loading @@ -166,6 +177,32 @@ void GraphicsEnv::setGpuStats(const std::string driverPackageName, }; } void GraphicsEnv::sendGpuStats() { ATRACE_CALL(); // Do not sendGpuStats for those skipping the GraphicsEnvironment setup if (mGpuStats.appPackageName.empty()) return; ALOGV("sendGpuStats:\n" "\tdriverPackageName[%s]\n" "\tdriverVersionName[%s]\n" "\tdriverVersionCode[%llu]\n" "\tappPackageName[%s]\n", mGpuStats.driverPackageName.c_str(), mGpuStats.driverVersionName.c_str(), (unsigned long long)mGpuStats.driverVersionCode, mGpuStats.appPackageName.c_str()); const sp<IBinder> binder = defaultServiceManager()->checkService(String16("gpu")); if (!binder) { ALOGE("Failed to get gpu service for [%s]", mGpuStats.appPackageName.c_str()); return; } interface_cast<IGpuService>(binder)->setGpuStats(mGpuStats.driverPackageName, mGpuStats.driverVersionName, mGpuStats.driverVersionCode, mGpuStats.appPackageName); } void* GraphicsEnv::loadLibrary(std::string name) { const android_dlextinfo dlextinfo = { .flags = ANDROID_DLEXT_USE_NAMESPACE, Loading
libs/graphicsenv/IGpuService.cpp 0 → 100644 +96 −0 Original line number Diff line number Diff line /* * Copyright 2019 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. */ #define LOG_TAG "GpuService" #include <graphicsenv/IGpuService.h> #include <binder/IResultReceiver.h> #include <binder/Parcel.h> namespace android { class BpGpuService : public BpInterface<IGpuService> { public: explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {} virtual void setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t driverVersionCode, const std::string appPackageName) { Parcel data, reply; data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); data.writeUtf8AsUtf16(driverPackageName); data.writeUtf8AsUtf16(driverVersionName); data.writeUint64(driverVersionCode); data.writeUtf8AsUtf16(appPackageName); remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply); } }; IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) { ALOGV("onTransact code[0x%X]", code); status_t status; switch (code) { case SET_GPU_STATS: { CHECK_INTERFACE(IGpuService, data, reply); std::string driverPackageName; if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status; std::string driverVersionName; if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status; uint64_t driverVersionCode; if ((status = data.readUint64(&driverVersionCode)) != OK) return status; std::string appPackageName; if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; setGpuStats(driverPackageName, driverVersionName, driverVersionCode, appPackageName); return OK; } case SHELL_COMMAND_TRANSACTION: { int in = data.readFileDescriptor(); int out = data.readFileDescriptor(); int err = data.readFileDescriptor(); std::vector<String16> args; data.readString16Vector(&args); sp<IBinder> unusedCallback; if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status; sp<IResultReceiver> resultReceiver; if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status; status = shellCommand(in, out, err, args); if (resultReceiver != nullptr) resultReceiver->send(status); return OK; } default: return BBinder::onTransact(code, data, reply, flags); } } } // namespace android
libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +1 −0 Original line number Diff line number Diff line Loading @@ -49,6 +49,7 @@ public: android_namespace_t* getDriverNamespace(); void setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t versionCode, const std::string appPackageName); void sendGpuStats(); bool shouldUseAngle(std::string appName); bool shouldUseAngle(); Loading
libs/graphicsenv/include/graphicsenv/IGpuService.h 0 → 100644 +54 −0 Original line number Diff line number Diff line /* * Copyright 2019 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. */ #pragma once #include <binder/IInterface.h> #include <cutils/compiler.h> #include <vector> namespace android { /* * This class defines the Binder IPC interface for GPU-related queries and * control. */ class IGpuService : public IInterface { public: DECLARE_META_INTERFACE(GpuService); // set GPU stats from GraphicsEnvironment. virtual void setGpuStats(const std::string driverPackageName, const std::string driverVersionName, const uint64_t driverVersionCode, const std::string appPackageName) = 0; }; class BnGpuService : public BnInterface<IGpuService> { public: enum IGpuServiceTag { SET_GPU_STATS = IBinder::FIRST_CALL_TRANSACTION, // Always append new enum to the end. }; status_t onTransact(uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags = 0) override; protected: virtual status_t shellCommand(int in, int out, int err, std::vector<String16>& args) = 0; }; } // namespace android