blob: fa25c5516dc1691697384804155e74312f6a0cae [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
64 void setUpdatableDriverPath(const std::string& driverPath) override {
65 Parcel data, reply;
66 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
67 data.writeUtf8AsUtf16(driverPath);
68
69 remote()->transact(BnGpuService::SET_UPDATABLE_DRIVER_PATH, data, &reply,
70 IBinder::FLAG_ONEWAY);
71 }
72
73 std::string getUpdatableDriverPath() override {
74 Parcel data, reply;
75 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
76
77 status_t error = remote()->transact(BnGpuService::GET_UPDATABLE_DRIVER_PATH, data, &reply);
78 std::string driverPath;
79 if (error == OK) {
80 error = reply.readUtf8FromUtf16(&driverPath);
81 }
82 return driverPath;
83 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080084};
85
86IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
87
88status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
89 uint32_t flags) {
90 ALOGV("onTransact code[0x%X]", code);
91
92 status_t status;
93 switch (code) {
94 case SET_GPU_STATS: {
95 CHECK_INTERFACE(IGpuService, data, reply);
96
97 std::string driverPackageName;
98 if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status;
99
100 std::string driverVersionName;
101 if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status;
102
103 uint64_t driverVersionCode;
104 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
105
Yiwei Zhang96c01712019-02-19 16:00:25 -0800106 int64_t driverBuildTime;
107 if ((status = data.readInt64(&driverBuildTime)) != OK) return status;
Yiwei Zhang512a7232019-02-15 16:04:41 -0800108
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800109 std::string appPackageName;
110 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
111
Yiwei Zhang794d2952019-05-06 17:43:59 -0700112 int32_t vulkanVersion;
113 if ((status = data.readInt32(&vulkanVersion)) != OK) return status;
114
Yiwei Zhangd9861812019-02-13 11:51:55 -0800115 int32_t driver;
116 if ((status = data.readInt32(&driver)) != OK) return status;
117
118 bool isDriverLoaded;
119 if ((status = data.readBool(&isDriverLoaded)) != OK) return status;
120
121 int64_t driverLoadingTime;
122 if ((status = data.readInt64(&driverLoadingTime)) != OK) return status;
123
Yiwei Zhang96c01712019-02-19 16:00:25 -0800124 setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime,
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -0700125 appPackageName, vulkanVersion, static_cast<GpuStatsInfo::Driver>(driver),
Yiwei Zhang794d2952019-05-06 17:43:59 -0700126 isDriverLoaded, driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800127
128 return OK;
129 }
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700130 case SET_TARGET_STATS: {
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700131 CHECK_INTERFACE(IGpuService, data, reply);
132
133 std::string appPackageName;
134 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
135
136 uint64_t driverVersionCode;
137 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
138
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700139 int32_t stats;
140 if ((status = data.readInt32(&stats)) != OK) return status;
141
142 uint64_t value;
143 if ((status = data.readUint64(&value)) != OK) return status;
144
145 setTargetStats(appPackageName, driverVersionCode,
146 static_cast<GpuStatsInfo::Stats>(stats), value);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700147
148 return OK;
149 }
Peiyong Lin0acbfdc2020-06-17 18:47:12 -0700150 case SET_UPDATABLE_DRIVER_PATH: {
151 CHECK_INTERFACE(IGpuService, data, reply);
152
153 std::string driverPath;
154 if ((status = data.readUtf8FromUtf16(&driverPath)) != OK) return status;
155
156 setUpdatableDriverPath(driverPath);
157 return OK;
158 }
159 case GET_UPDATABLE_DRIVER_PATH: {
160 CHECK_INTERFACE(IGpuService, data, reply);
161
162 std::string driverPath = getUpdatableDriverPath();
163 return reply->writeUtf8AsUtf16(driverPath);
164 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800165 case SHELL_COMMAND_TRANSACTION: {
166 int in = data.readFileDescriptor();
167 int out = data.readFileDescriptor();
168 int err = data.readFileDescriptor();
169
170 std::vector<String16> args;
171 data.readString16Vector(&args);
172
173 sp<IBinder> unusedCallback;
174 if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status;
175
176 sp<IResultReceiver> resultReceiver;
177 if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status;
178
179 status = shellCommand(in, out, err, args);
180 if (resultReceiver != nullptr) resultReceiver->send(status);
181
182 return OK;
183 }
184 default:
185 return BBinder::onTransact(code, data, reply, flags);
186 }
187}
188
189} // namespace android