blob: 5dc195c438234f0533309594df037bf3a5fdd6fa [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
Peiyong Lin0acbfdc2020-06-17 18:47:12 -070080 void setUpdatableDriverPath(const std::string& driverPath) override {
81 Parcel data, reply;
82 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
83 data.writeUtf8AsUtf16(driverPath);
84
85 remote()->transact(BnGpuService::SET_UPDATABLE_DRIVER_PATH, data, &reply,
86 IBinder::FLAG_ONEWAY);
87 }
88
Yuxin Hub69e9882023-04-13 03:51:41 +000089 void toggleAngleAsSystemDriver(bool enabled) override {
90 Parcel data, reply;
91 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
92 data.writeBool(enabled);
93
94 remote()->transact(BnGpuService::TOGGLE_ANGLE_AS_SYSTEM_DRIVER, data, &reply,
95 IBinder::FLAG_ONEWAY);
96 }
97
Peiyong Lin0acbfdc2020-06-17 18:47:12 -070098 std::string getUpdatableDriverPath() override {
99 Parcel data, reply;
100 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
101
102 status_t error = remote()->transact(BnGpuService::GET_UPDATABLE_DRIVER_PATH, data, &reply);
103 std::string driverPath;
104 if (error == OK) {
105 error = reply.readUtf8FromUtf16(&driverPath);
106 }
107 return driverPath;
108 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800109};
110
111IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
112
113status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
114 uint32_t flags) {
115 ALOGV("onTransact code[0x%X]", code);
116
117 status_t status;
118 switch (code) {
119 case SET_GPU_STATS: {
120 CHECK_INTERFACE(IGpuService, data, reply);
121
122 std::string driverPackageName;
123 if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status;
124
125 std::string driverVersionName;
126 if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status;
127
128 uint64_t driverVersionCode;
129 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
130
Yiwei Zhang96c01712019-02-19 16:00:25 -0800131 int64_t driverBuildTime;
132 if ((status = data.readInt64(&driverBuildTime)) != OK) return status;
Yiwei Zhang512a7232019-02-15 16:04:41 -0800133
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800134 std::string appPackageName;
135 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
136
Yiwei Zhang794d2952019-05-06 17:43:59 -0700137 int32_t vulkanVersion;
138 if ((status = data.readInt32(&vulkanVersion)) != OK) return status;
139
Yiwei Zhangd9861812019-02-13 11:51:55 -0800140 int32_t driver;
141 if ((status = data.readInt32(&driver)) != OK) return status;
142
143 bool isDriverLoaded;
144 if ((status = data.readBool(&isDriverLoaded)) != OK) return status;
145
146 int64_t driverLoadingTime;
147 if ((status = data.readInt64(&driverLoadingTime)) != OK) return status;
148
Yiwei Zhang96c01712019-02-19 16:00:25 -0800149 setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime,
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -0700150 appPackageName, vulkanVersion, static_cast<GpuStatsInfo::Driver>(driver),
Yiwei Zhang794d2952019-05-06 17:43:59 -0700151 isDriverLoaded, driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800152
153 return OK;
154 }
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700155 case SET_TARGET_STATS: {
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700156 CHECK_INTERFACE(IGpuService, data, reply);
157
158 std::string appPackageName;
159 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
160
161 uint64_t driverVersionCode;
162 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
163
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700164 int32_t stats;
165 if ((status = data.readInt32(&stats)) != OK) return status;
166
167 uint64_t value;
168 if ((status = data.readUint64(&value)) != OK) return status;
169
170 setTargetStats(appPackageName, driverVersionCode,
171 static_cast<GpuStatsInfo::Stats>(stats), value);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700172
173 return OK;
174 }
Serdar Kocdemir0ae29272023-10-09 14:33:59 +0100175 case SET_TARGET_STATS_ARRAY: {
176 CHECK_INTERFACE(IGpuService, data, reply);
177
178 std::string appPackageName;
179 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
180
181 uint64_t driverVersionCode;
182 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
183
184 int32_t stats;
185 if ((status = data.readInt32(&stats)) != OK) return status;
186
187 uint32_t valueCount;
188 if ((status = data.readUint32(&valueCount)) != OK) return status;
189
190 std::vector<uint64_t> values(valueCount);
191 if ((status = data.read(values.data(), valueCount * sizeof(uint64_t))) != OK) {
192 return status;
193 }
194
195 setTargetStatsArray(appPackageName, driverVersionCode,
196 static_cast<GpuStatsInfo::Stats>(stats), values.data(), valueCount);
197
198 return OK;
199 }
Peiyong Lin0acbfdc2020-06-17 18:47:12 -0700200 case SET_UPDATABLE_DRIVER_PATH: {
201 CHECK_INTERFACE(IGpuService, data, reply);
202
203 std::string driverPath;
204 if ((status = data.readUtf8FromUtf16(&driverPath)) != OK) return status;
205
206 setUpdatableDriverPath(driverPath);
207 return OK;
208 }
209 case GET_UPDATABLE_DRIVER_PATH: {
210 CHECK_INTERFACE(IGpuService, data, reply);
211
212 std::string driverPath = getUpdatableDriverPath();
213 return reply->writeUtf8AsUtf16(driverPath);
214 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800215 case SHELL_COMMAND_TRANSACTION: {
Serdar Kocdemird6df2ed2023-08-01 18:17:29 +0100216 int in = dup(data.readFileDescriptor());
217 int out = dup(data.readFileDescriptor());
218 int err = dup(data.readFileDescriptor());
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800219
220 std::vector<String16> args;
221 data.readString16Vector(&args);
222
223 sp<IBinder> unusedCallback;
224 if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status;
225
226 sp<IResultReceiver> resultReceiver;
227 if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status;
228
229 status = shellCommand(in, out, err, args);
230 if (resultReceiver != nullptr) resultReceiver->send(status);
Serdar Kocdemird6df2ed2023-08-01 18:17:29 +0100231 ::close(in);
232 ::close(out);
233 ::close(err);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800234
235 return OK;
236 }
Yuxin Hub69e9882023-04-13 03:51:41 +0000237 case TOGGLE_ANGLE_AS_SYSTEM_DRIVER: {
238 CHECK_INTERFACE(IGpuService, data, reply);
239
240 bool enableAngleAsSystemDriver;
241 if ((status = data.readBool(&enableAngleAsSystemDriver)) != OK) return status;
242
243 toggleAngleAsSystemDriver(enableAngleAsSystemDriver);
244 return OK;
245 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800246 default:
247 return BBinder::onTransact(code, data, reply, flags);
248 }
249}
250
251} // namespace android