blob: ceb52f71d8d229ff5e28eb3ff5d6f2c9becd1f47 [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 {
67 for (uint32_t i = 0; i < valueCount; i++) {
68 setTargetStats(appPackageName, driverVersionCode, stats, values[i]);
69 }
70 }
71
Peiyong Lin0acbfdc2020-06-17 18:47:12 -070072 void setUpdatableDriverPath(const std::string& driverPath) override {
73 Parcel data, reply;
74 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
75 data.writeUtf8AsUtf16(driverPath);
76
77 remote()->transact(BnGpuService::SET_UPDATABLE_DRIVER_PATH, data, &reply,
78 IBinder::FLAG_ONEWAY);
79 }
80
81 std::string getUpdatableDriverPath() override {
82 Parcel data, reply;
83 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
84
85 status_t error = remote()->transact(BnGpuService::GET_UPDATABLE_DRIVER_PATH, data, &reply);
86 std::string driverPath;
87 if (error == OK) {
88 error = reply.readUtf8FromUtf16(&driverPath);
89 }
90 return driverPath;
91 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080092};
93
94IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
95
96status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
97 uint32_t flags) {
98 ALOGV("onTransact code[0x%X]", code);
99
100 status_t status;
101 switch (code) {
102 case SET_GPU_STATS: {
103 CHECK_INTERFACE(IGpuService, data, reply);
104
105 std::string driverPackageName;
106 if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status;
107
108 std::string driverVersionName;
109 if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status;
110
111 uint64_t driverVersionCode;
112 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
113
Yiwei Zhang96c01712019-02-19 16:00:25 -0800114 int64_t driverBuildTime;
115 if ((status = data.readInt64(&driverBuildTime)) != OK) return status;
Yiwei Zhang512a7232019-02-15 16:04:41 -0800116
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800117 std::string appPackageName;
118 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
119
Yiwei Zhang794d2952019-05-06 17:43:59 -0700120 int32_t vulkanVersion;
121 if ((status = data.readInt32(&vulkanVersion)) != OK) return status;
122
Yiwei Zhangd9861812019-02-13 11:51:55 -0800123 int32_t driver;
124 if ((status = data.readInt32(&driver)) != OK) return status;
125
126 bool isDriverLoaded;
127 if ((status = data.readBool(&isDriverLoaded)) != OK) return status;
128
129 int64_t driverLoadingTime;
130 if ((status = data.readInt64(&driverLoadingTime)) != OK) return status;
131
Yiwei Zhang96c01712019-02-19 16:00:25 -0800132 setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime,
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -0700133 appPackageName, vulkanVersion, static_cast<GpuStatsInfo::Driver>(driver),
Yiwei Zhang794d2952019-05-06 17:43:59 -0700134 isDriverLoaded, driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800135
136 return OK;
137 }
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700138 case SET_TARGET_STATS: {
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700139 CHECK_INTERFACE(IGpuService, data, reply);
140
141 std::string appPackageName;
142 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
143
144 uint64_t driverVersionCode;
145 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
146
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700147 int32_t stats;
148 if ((status = data.readInt32(&stats)) != OK) return status;
149
150 uint64_t value;
151 if ((status = data.readUint64(&value)) != OK) return status;
152
153 setTargetStats(appPackageName, driverVersionCode,
154 static_cast<GpuStatsInfo::Stats>(stats), value);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700155
156 return OK;
157 }
Peiyong Lin0acbfdc2020-06-17 18:47:12 -0700158 case SET_UPDATABLE_DRIVER_PATH: {
159 CHECK_INTERFACE(IGpuService, data, reply);
160
161 std::string driverPath;
162 if ((status = data.readUtf8FromUtf16(&driverPath)) != OK) return status;
163
164 setUpdatableDriverPath(driverPath);
165 return OK;
166 }
167 case GET_UPDATABLE_DRIVER_PATH: {
168 CHECK_INTERFACE(IGpuService, data, reply);
169
170 std::string driverPath = getUpdatableDriverPath();
171 return reply->writeUtf8AsUtf16(driverPath);
172 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800173 case SHELL_COMMAND_TRANSACTION: {
174 int in = data.readFileDescriptor();
175 int out = data.readFileDescriptor();
176 int err = data.readFileDescriptor();
177
178 std::vector<String16> args;
179 data.readString16Vector(&args);
180
181 sp<IBinder> unusedCallback;
182 if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status;
183
184 sp<IResultReceiver> resultReceiver;
185 if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status;
186
187 status = shellCommand(in, out, err, args);
188 if (resultReceiver != nullptr) resultReceiver->send(status);
189
190 return OK;
191 }
192 default:
193 return BBinder::onTransact(code, data, reply, flags);
194 }
195}
196
197} // namespace android