blob: 9a34aff299a950ce02fbd6af5e167f5d07af1973 [file] [log] [blame]
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -08001/*
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
24namespace android {
25
26class BpGpuService : public BpInterface<IGpuService> {
27public:
28 explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}
29
Peiyong Lin0acbfdc2020-06-17 18:47:12 -070030 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 Zhangcb9d4e42019-02-06 20:22:59 -080035 Parcel data, reply;
36 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
37
38 data.writeUtf8AsUtf16(driverPackageName);
39 data.writeUtf8AsUtf16(driverVersionName);
40 data.writeUint64(driverVersionCode);
Yiwei Zhang96c01712019-02-19 16:00:25 -080041 data.writeInt64(driverBuildTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080042 data.writeUtf8AsUtf16(appPackageName);
Yiwei Zhang794d2952019-05-06 17:43:59 -070043 data.writeInt32(vulkanVersion);
Yiwei Zhangd9861812019-02-13 11:51:55 -080044 data.writeInt32(static_cast<int32_t>(driver));
45 data.writeBool(isDriverLoaded);
46 data.writeInt64(driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080047
Yiwei Zhang512a7232019-02-15 16:04:41 -080048 remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080049 }
Yiwei Zhangbaea97f2019-02-27 16:35:37 -080050
Peiyong Lin0acbfdc2020-06-17 18:47:12 -070051 void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
52 const GpuStatsInfo::Stats stats, const uint64_t value) override {
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -070053 Parcel data, reply;
54 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
55
56 data.writeUtf8AsUtf16(appPackageName);
57 data.writeUint64(driverVersionCode);
Yiwei Zhangbcba4112019-07-03 13:39:32 -070058 data.writeInt32(static_cast<int32_t>(stats));
59 data.writeUint64(value);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -070060
Yiwei Zhangbcba4112019-07-03 13:39:32 -070061 remote()->transact(BnGpuService::SET_TARGET_STATS, data, &reply, IBinder::FLAG_ONEWAY);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -070062 }
Peiyong Lin0acbfdc2020-06-17 18:47:12 -070063
Serdar Kocdemirb2901c92022-11-17 00:39:05 +000064 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 Kocdemir0ae29272023-10-09 14:33:59 +010067 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 Kocdemirb2901c92022-11-17 00:39:05 +000078 }
79
Tom Murphyc23fcd02024-03-13 10:22:06 +000080 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 Lin0acbfdc2020-06-17 18:47:12 -070093 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 Hub69e9882023-04-13 03:51:41 +0000102 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 Lin0acbfdc2020-06-17 18:47:12 -0700111 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 }
Tim Van Patten04502462025-01-13 14:03:59 -0700122
123 FeatureOverrides getFeatureOverrides() override {
124 Parcel data, reply;
125 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
126
127 FeatureOverrides featureOverrides;
128 status_t error =
129 remote()->transact(BnGpuService::GET_FEATURE_CONFIG_OVERRIDES, data, &reply);
130 if (error != OK) {
131 return featureOverrides;
132 }
133
134 featureOverrides.readFromParcel(&reply);
135 return featureOverrides;
136 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800137};
138
139IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
140
141status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
142 uint32_t flags) {
143 ALOGV("onTransact code[0x%X]", code);
144
145 status_t status;
146 switch (code) {
147 case SET_GPU_STATS: {
148 CHECK_INTERFACE(IGpuService, data, reply);
149
150 std::string driverPackageName;
151 if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status;
152
153 std::string driverVersionName;
154 if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status;
155
156 uint64_t driverVersionCode;
157 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
158
Yiwei Zhang96c01712019-02-19 16:00:25 -0800159 int64_t driverBuildTime;
160 if ((status = data.readInt64(&driverBuildTime)) != OK) return status;
Yiwei Zhang512a7232019-02-15 16:04:41 -0800161
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800162 std::string appPackageName;
163 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
164
Yiwei Zhang794d2952019-05-06 17:43:59 -0700165 int32_t vulkanVersion;
166 if ((status = data.readInt32(&vulkanVersion)) != OK) return status;
167
Yiwei Zhangd9861812019-02-13 11:51:55 -0800168 int32_t driver;
169 if ((status = data.readInt32(&driver)) != OK) return status;
170
171 bool isDriverLoaded;
172 if ((status = data.readBool(&isDriverLoaded)) != OK) return status;
173
174 int64_t driverLoadingTime;
175 if ((status = data.readInt64(&driverLoadingTime)) != OK) return status;
176
Yiwei Zhang96c01712019-02-19 16:00:25 -0800177 setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime,
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -0700178 appPackageName, vulkanVersion, static_cast<GpuStatsInfo::Driver>(driver),
Yiwei Zhang794d2952019-05-06 17:43:59 -0700179 isDriverLoaded, driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800180
181 return OK;
182 }
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700183 case SET_TARGET_STATS: {
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700184 CHECK_INTERFACE(IGpuService, data, reply);
185
186 std::string appPackageName;
187 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
188
189 uint64_t driverVersionCode;
190 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
191
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700192 int32_t stats;
193 if ((status = data.readInt32(&stats)) != OK) return status;
194
195 uint64_t value;
196 if ((status = data.readUint64(&value)) != OK) return status;
197
198 setTargetStats(appPackageName, driverVersionCode,
199 static_cast<GpuStatsInfo::Stats>(stats), value);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700200
201 return OK;
202 }
Serdar Kocdemir0ae29272023-10-09 14:33:59 +0100203 case SET_TARGET_STATS_ARRAY: {
204 CHECK_INTERFACE(IGpuService, data, reply);
205
206 std::string appPackageName;
207 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
208
209 uint64_t driverVersionCode;
210 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
211
212 int32_t stats;
213 if ((status = data.readInt32(&stats)) != OK) return status;
214
215 uint32_t valueCount;
216 if ((status = data.readUint32(&valueCount)) != OK) return status;
217
218 std::vector<uint64_t> values(valueCount);
219 if ((status = data.read(values.data(), valueCount * sizeof(uint64_t))) != OK) {
220 return status;
221 }
222
223 setTargetStatsArray(appPackageName, driverVersionCode,
224 static_cast<GpuStatsInfo::Stats>(stats), values.data(), valueCount);
225
226 return OK;
227 }
Tom Murphyc23fcd02024-03-13 10:22:06 +0000228 case ADD_VULKAN_ENGINE_NAME: {
229 CHECK_INTERFACE(IGpuService, data, reply);
230
231 std::string appPackageName;
232 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
233
234 uint64_t driverVersionCode;
235 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
236
237 const char* engineName;
238 if ((engineName = data.readCString()) == nullptr) return BAD_VALUE;
239
240 addVulkanEngineName(appPackageName, driverVersionCode, engineName);
241 return OK;
242 }
Peiyong Lin0acbfdc2020-06-17 18:47:12 -0700243 case SET_UPDATABLE_DRIVER_PATH: {
244 CHECK_INTERFACE(IGpuService, data, reply);
245
246 std::string driverPath;
247 if ((status = data.readUtf8FromUtf16(&driverPath)) != OK) return status;
248
249 setUpdatableDriverPath(driverPath);
250 return OK;
251 }
252 case GET_UPDATABLE_DRIVER_PATH: {
253 CHECK_INTERFACE(IGpuService, data, reply);
254
255 std::string driverPath = getUpdatableDriverPath();
256 return reply->writeUtf8AsUtf16(driverPath);
257 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800258 case SHELL_COMMAND_TRANSACTION: {
Serdar Kocdemird6df2ed2023-08-01 18:17:29 +0100259 int in = dup(data.readFileDescriptor());
260 int out = dup(data.readFileDescriptor());
261 int err = dup(data.readFileDescriptor());
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800262
263 std::vector<String16> args;
264 data.readString16Vector(&args);
265
266 sp<IBinder> unusedCallback;
267 if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status;
268
269 sp<IResultReceiver> resultReceiver;
270 if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status;
271
272 status = shellCommand(in, out, err, args);
273 if (resultReceiver != nullptr) resultReceiver->send(status);
Serdar Kocdemird6df2ed2023-08-01 18:17:29 +0100274 ::close(in);
275 ::close(out);
276 ::close(err);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800277
278 return OK;
279 }
Yuxin Hub69e9882023-04-13 03:51:41 +0000280 case TOGGLE_ANGLE_AS_SYSTEM_DRIVER: {
281 CHECK_INTERFACE(IGpuService, data, reply);
282
283 bool enableAngleAsSystemDriver;
284 if ((status = data.readBool(&enableAngleAsSystemDriver)) != OK) return status;
285
286 toggleAngleAsSystemDriver(enableAngleAsSystemDriver);
287 return OK;
288 }
Tim Van Patten04502462025-01-13 14:03:59 -0700289 case GET_FEATURE_CONFIG_OVERRIDES: {
290 CHECK_INTERFACE(IGpuService, data, reply);
291
292 // Get the FeatureOverrides from gpuservice, which implements the IGpuService interface
293 // with GpuService::getFeatureOverrides().
294 FeatureOverrides featureOverrides = getFeatureOverrides();
295 featureOverrides.writeToParcel(reply);
296 return OK;
297 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800298 default:
299 return BBinder::onTransact(code, data, reply, flags);
300 }
301}
302
303} // namespace android