Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "GpuService" |
| 18 | |
| 19 | #include <graphicsenv/IGpuService.h> |
| 20 | |
| 21 | #include <binder/IResultReceiver.h> |
| 22 | #include <binder/Parcel.h> |
| 23 | |
| 24 | namespace android { |
| 25 | |
| 26 | class BpGpuService : public BpInterface<IGpuService> { |
| 27 | public: |
| 28 | explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {} |
| 29 | |
Peiyong Lin | 0acbfdc | 2020-06-17 18:47:12 -0700 | [diff] [blame] | 30 | void setGpuStats(const std::string& driverPackageName, const std::string& driverVersionName, |
| 31 | uint64_t driverVersionCode, int64_t driverBuildTime, |
| 32 | const std::string& appPackageName, const int32_t vulkanVersion, |
| 33 | GpuStatsInfo::Driver driver, bool isDriverLoaded, |
| 34 | int64_t driverLoadingTime) override { |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 35 | Parcel data, reply; |
| 36 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); |
| 37 | |
| 38 | data.writeUtf8AsUtf16(driverPackageName); |
| 39 | data.writeUtf8AsUtf16(driverVersionName); |
| 40 | data.writeUint64(driverVersionCode); |
Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 41 | data.writeInt64(driverBuildTime); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 42 | data.writeUtf8AsUtf16(appPackageName); |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 43 | data.writeInt32(vulkanVersion); |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 44 | data.writeInt32(static_cast<int32_t>(driver)); |
| 45 | data.writeBool(isDriverLoaded); |
| 46 | data.writeInt64(driverLoadingTime); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 47 | |
Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 48 | remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 49 | } |
Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 50 | |
Peiyong Lin | 0acbfdc | 2020-06-17 18:47:12 -0700 | [diff] [blame] | 51 | void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, |
| 52 | const GpuStatsInfo::Stats stats, const uint64_t value) override { |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 53 | Parcel data, reply; |
| 54 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); |
| 55 | |
| 56 | data.writeUtf8AsUtf16(appPackageName); |
| 57 | data.writeUint64(driverVersionCode); |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 58 | data.writeInt32(static_cast<int32_t>(stats)); |
| 59 | data.writeUint64(value); |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 60 | |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 61 | remote()->transact(BnGpuService::SET_TARGET_STATS, data, &reply, IBinder::FLAG_ONEWAY); |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 62 | } |
Peiyong Lin | 0acbfdc | 2020-06-17 18:47:12 -0700 | [diff] [blame] | 63 | |
Serdar Kocdemir | b2901c9 | 2022-11-17 00:39:05 +0000 | [diff] [blame] | 64 | void setTargetStatsArray(const std::string& appPackageName, const uint64_t driverVersionCode, |
| 65 | const GpuStatsInfo::Stats stats, const uint64_t* values, |
| 66 | const uint32_t valueCount) override { |
Serdar Kocdemir | 0ae2927 | 2023-10-09 14:33:59 +0100 | [diff] [blame] | 67 | Parcel data, reply; |
| 68 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); |
| 69 | |
| 70 | data.writeUtf8AsUtf16(appPackageName); |
| 71 | data.writeUint64(driverVersionCode); |
| 72 | data.writeInt32(static_cast<int32_t>(stats)); |
| 73 | data.writeUint32(valueCount); |
| 74 | data.write(values, valueCount * sizeof(uint64_t)); |
| 75 | |
| 76 | remote()->transact(BnGpuService::SET_TARGET_STATS_ARRAY, data, &reply, |
| 77 | IBinder::FLAG_ONEWAY); |
Serdar Kocdemir | b2901c9 | 2022-11-17 00:39:05 +0000 | [diff] [blame] | 78 | } |
| 79 | |
Tom Murphy | c23fcd0 | 2024-03-13 10:22:06 +0000 | [diff] [blame^] | 80 | void addVulkanEngineName(const std::string& appPackageName, const uint64_t driverVersionCode, |
| 81 | const char* engineName) override { |
| 82 | Parcel data, reply; |
| 83 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); |
| 84 | |
| 85 | data.writeUtf8AsUtf16(appPackageName); |
| 86 | data.writeUint64(driverVersionCode); |
| 87 | data.writeCString(engineName); |
| 88 | |
| 89 | remote()->transact(BnGpuService::ADD_VULKAN_ENGINE_NAME, data, &reply, |
| 90 | IBinder::FLAG_ONEWAY); |
| 91 | } |
| 92 | |
Peiyong Lin | 0acbfdc | 2020-06-17 18:47:12 -0700 | [diff] [blame] | 93 | void setUpdatableDriverPath(const std::string& driverPath) override { |
| 94 | Parcel data, reply; |
| 95 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); |
| 96 | data.writeUtf8AsUtf16(driverPath); |
| 97 | |
| 98 | remote()->transact(BnGpuService::SET_UPDATABLE_DRIVER_PATH, data, &reply, |
| 99 | IBinder::FLAG_ONEWAY); |
| 100 | } |
| 101 | |
Yuxin Hu | b69e988 | 2023-04-13 03:51:41 +0000 | [diff] [blame] | 102 | void toggleAngleAsSystemDriver(bool enabled) override { |
| 103 | Parcel data, reply; |
| 104 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); |
| 105 | data.writeBool(enabled); |
| 106 | |
| 107 | remote()->transact(BnGpuService::TOGGLE_ANGLE_AS_SYSTEM_DRIVER, data, &reply, |
| 108 | IBinder::FLAG_ONEWAY); |
| 109 | } |
| 110 | |
Peiyong Lin | 0acbfdc | 2020-06-17 18:47:12 -0700 | [diff] [blame] | 111 | std::string getUpdatableDriverPath() override { |
| 112 | Parcel data, reply; |
| 113 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); |
| 114 | |
| 115 | status_t error = remote()->transact(BnGpuService::GET_UPDATABLE_DRIVER_PATH, data, &reply); |
| 116 | std::string driverPath; |
| 117 | if (error == OK) { |
| 118 | error = reply.readUtf8FromUtf16(&driverPath); |
| 119 | } |
| 120 | return driverPath; |
| 121 | } |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 122 | }; |
| 123 | |
| 124 | IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); |
| 125 | |
| 126 | status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 127 | uint32_t flags) { |
| 128 | ALOGV("onTransact code[0x%X]", code); |
| 129 | |
| 130 | status_t status; |
| 131 | switch (code) { |
| 132 | case SET_GPU_STATS: { |
| 133 | CHECK_INTERFACE(IGpuService, data, reply); |
| 134 | |
| 135 | std::string driverPackageName; |
| 136 | if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status; |
| 137 | |
| 138 | std::string driverVersionName; |
| 139 | if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status; |
| 140 | |
| 141 | uint64_t driverVersionCode; |
| 142 | if ((status = data.readUint64(&driverVersionCode)) != OK) return status; |
| 143 | |
Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 144 | int64_t driverBuildTime; |
| 145 | if ((status = data.readInt64(&driverBuildTime)) != OK) return status; |
Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 146 | |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 147 | std::string appPackageName; |
| 148 | if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; |
| 149 | |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 150 | int32_t vulkanVersion; |
| 151 | if ((status = data.readInt32(&vulkanVersion)) != OK) return status; |
| 152 | |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 153 | int32_t driver; |
| 154 | if ((status = data.readInt32(&driver)) != OK) return status; |
| 155 | |
| 156 | bool isDriverLoaded; |
| 157 | if ((status = data.readBool(&isDriverLoaded)) != OK) return status; |
| 158 | |
| 159 | int64_t driverLoadingTime; |
| 160 | if ((status = data.readInt64(&driverLoadingTime)) != OK) return status; |
| 161 | |
Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 162 | setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime, |
Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 163 | appPackageName, vulkanVersion, static_cast<GpuStatsInfo::Driver>(driver), |
Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 164 | isDriverLoaded, driverLoadingTime); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 165 | |
| 166 | return OK; |
| 167 | } |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 168 | case SET_TARGET_STATS: { |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 169 | CHECK_INTERFACE(IGpuService, data, reply); |
| 170 | |
| 171 | std::string appPackageName; |
| 172 | if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; |
| 173 | |
| 174 | uint64_t driverVersionCode; |
| 175 | if ((status = data.readUint64(&driverVersionCode)) != OK) return status; |
| 176 | |
Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 177 | int32_t stats; |
| 178 | if ((status = data.readInt32(&stats)) != OK) return status; |
| 179 | |
| 180 | uint64_t value; |
| 181 | if ((status = data.readUint64(&value)) != OK) return status; |
| 182 | |
| 183 | setTargetStats(appPackageName, driverVersionCode, |
| 184 | static_cast<GpuStatsInfo::Stats>(stats), value); |
Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 185 | |
| 186 | return OK; |
| 187 | } |
Serdar Kocdemir | 0ae2927 | 2023-10-09 14:33:59 +0100 | [diff] [blame] | 188 | case SET_TARGET_STATS_ARRAY: { |
| 189 | CHECK_INTERFACE(IGpuService, data, reply); |
| 190 | |
| 191 | std::string appPackageName; |
| 192 | if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; |
| 193 | |
| 194 | uint64_t driverVersionCode; |
| 195 | if ((status = data.readUint64(&driverVersionCode)) != OK) return status; |
| 196 | |
| 197 | int32_t stats; |
| 198 | if ((status = data.readInt32(&stats)) != OK) return status; |
| 199 | |
| 200 | uint32_t valueCount; |
| 201 | if ((status = data.readUint32(&valueCount)) != OK) return status; |
| 202 | |
| 203 | std::vector<uint64_t> values(valueCount); |
| 204 | if ((status = data.read(values.data(), valueCount * sizeof(uint64_t))) != OK) { |
| 205 | return status; |
| 206 | } |
| 207 | |
| 208 | setTargetStatsArray(appPackageName, driverVersionCode, |
| 209 | static_cast<GpuStatsInfo::Stats>(stats), values.data(), valueCount); |
| 210 | |
| 211 | return OK; |
| 212 | } |
Tom Murphy | c23fcd0 | 2024-03-13 10:22:06 +0000 | [diff] [blame^] | 213 | case ADD_VULKAN_ENGINE_NAME: { |
| 214 | CHECK_INTERFACE(IGpuService, data, reply); |
| 215 | |
| 216 | std::string appPackageName; |
| 217 | if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; |
| 218 | |
| 219 | uint64_t driverVersionCode; |
| 220 | if ((status = data.readUint64(&driverVersionCode)) != OK) return status; |
| 221 | |
| 222 | const char* engineName; |
| 223 | if ((engineName = data.readCString()) == nullptr) return BAD_VALUE; |
| 224 | |
| 225 | addVulkanEngineName(appPackageName, driverVersionCode, engineName); |
| 226 | return OK; |
| 227 | } |
Peiyong Lin | 0acbfdc | 2020-06-17 18:47:12 -0700 | [diff] [blame] | 228 | case SET_UPDATABLE_DRIVER_PATH: { |
| 229 | CHECK_INTERFACE(IGpuService, data, reply); |
| 230 | |
| 231 | std::string driverPath; |
| 232 | if ((status = data.readUtf8FromUtf16(&driverPath)) != OK) return status; |
| 233 | |
| 234 | setUpdatableDriverPath(driverPath); |
| 235 | return OK; |
| 236 | } |
| 237 | case GET_UPDATABLE_DRIVER_PATH: { |
| 238 | CHECK_INTERFACE(IGpuService, data, reply); |
| 239 | |
| 240 | std::string driverPath = getUpdatableDriverPath(); |
| 241 | return reply->writeUtf8AsUtf16(driverPath); |
| 242 | } |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 243 | case SHELL_COMMAND_TRANSACTION: { |
Serdar Kocdemir | d6df2ed | 2023-08-01 18:17:29 +0100 | [diff] [blame] | 244 | int in = dup(data.readFileDescriptor()); |
| 245 | int out = dup(data.readFileDescriptor()); |
| 246 | int err = dup(data.readFileDescriptor()); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 247 | |
| 248 | std::vector<String16> args; |
| 249 | data.readString16Vector(&args); |
| 250 | |
| 251 | sp<IBinder> unusedCallback; |
| 252 | if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status; |
| 253 | |
| 254 | sp<IResultReceiver> resultReceiver; |
| 255 | if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status; |
| 256 | |
| 257 | status = shellCommand(in, out, err, args); |
| 258 | if (resultReceiver != nullptr) resultReceiver->send(status); |
Serdar Kocdemir | d6df2ed | 2023-08-01 18:17:29 +0100 | [diff] [blame] | 259 | ::close(in); |
| 260 | ::close(out); |
| 261 | ::close(err); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 262 | |
| 263 | return OK; |
| 264 | } |
Yuxin Hu | b69e988 | 2023-04-13 03:51:41 +0000 | [diff] [blame] | 265 | case TOGGLE_ANGLE_AS_SYSTEM_DRIVER: { |
| 266 | CHECK_INTERFACE(IGpuService, data, reply); |
| 267 | |
| 268 | bool enableAngleAsSystemDriver; |
| 269 | if ((status = data.readBool(&enableAngleAsSystemDriver)) != OK) return status; |
| 270 | |
| 271 | toggleAngleAsSystemDriver(enableAngleAsSystemDriver); |
| 272 | return OK; |
| 273 | } |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 274 | default: |
| 275 | return BBinder::onTransact(code, data, reply, flags); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | } // namespace android |