blob: 9f5b0ff46f5535ddcb43d3f1183ecca92bdd948f [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
Greg Kaiser210bb7e2019-02-12 12:40:05 -080030 virtual void setGpuStats(const std::string& driverPackageName,
Yiwei Zhangd9861812019-02-13 11:51:55 -080031 const std::string& driverVersionName, uint64_t driverVersionCode,
Yiwei Zhang96c01712019-02-19 16:00:25 -080032 int64_t driverBuildTime, const std::string& appPackageName,
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -070033 const int32_t vulkanVersion, GpuStatsInfo::Driver driver,
Yiwei Zhang794d2952019-05-06 17:43:59 -070034 bool isDriverLoaded, int64_t driverLoadingTime) {
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
51 virtual status_t getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const {
52 if (!outStats) return UNEXPECTED_NULL;
53
54 Parcel data, reply;
55 status_t status;
56
57 if ((status = data.writeInterfaceToken(IGpuService::getInterfaceDescriptor())) != OK)
58 return status;
59
60 if ((status = remote()->transact(BnGpuService::GET_GPU_STATS_GLOBAL_INFO, data, &reply)) !=
61 OK)
62 return status;
63
64 int32_t result = 0;
65 if ((status = reply.readInt32(&result)) != OK) return status;
66 if (result != OK) return result;
67
68 outStats->clear();
69 return reply.readParcelableVector(outStats);
70 }
Yiwei Zhang178e0672019-03-04 14:17:12 -080071
72 virtual status_t getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const {
73 if (!outStats) return UNEXPECTED_NULL;
74
75 Parcel data, reply;
76 status_t status;
77
78 if ((status = data.writeInterfaceToken(IGpuService::getInterfaceDescriptor())) != OK) {
79 return status;
80 }
81
82 if ((status = remote()->transact(BnGpuService::GET_GPU_STATS_APP_INFO, data, &reply)) !=
83 OK) {
84 return status;
85 }
86
87 int32_t result = 0;
88 if ((status = reply.readInt32(&result)) != OK) return status;
89 if (result != OK) return result;
90
91 outStats->clear();
92 return reply.readParcelableVector(outStats);
93 }
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -070094
Yiwei Zhangbcba4112019-07-03 13:39:32 -070095 virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
96 const GpuStatsInfo::Stats stats, const uint64_t value) {
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -070097 Parcel data, reply;
98 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
99
100 data.writeUtf8AsUtf16(appPackageName);
101 data.writeUint64(driverVersionCode);
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700102 data.writeInt32(static_cast<int32_t>(stats));
103 data.writeUint64(value);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700104
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700105 remote()->transact(BnGpuService::SET_TARGET_STATS, data, &reply, IBinder::FLAG_ONEWAY);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700106 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800107};
108
109IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
110
111status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
112 uint32_t flags) {
113 ALOGV("onTransact code[0x%X]", code);
114
115 status_t status;
116 switch (code) {
117 case SET_GPU_STATS: {
118 CHECK_INTERFACE(IGpuService, data, reply);
119
120 std::string driverPackageName;
121 if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status;
122
123 std::string driverVersionName;
124 if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status;
125
126 uint64_t driverVersionCode;
127 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
128
Yiwei Zhang96c01712019-02-19 16:00:25 -0800129 int64_t driverBuildTime;
130 if ((status = data.readInt64(&driverBuildTime)) != OK) return status;
Yiwei Zhang512a7232019-02-15 16:04:41 -0800131
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800132 std::string appPackageName;
133 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
134
Yiwei Zhang794d2952019-05-06 17:43:59 -0700135 int32_t vulkanVersion;
136 if ((status = data.readInt32(&vulkanVersion)) != OK) return status;
137
Yiwei Zhangd9861812019-02-13 11:51:55 -0800138 int32_t driver;
139 if ((status = data.readInt32(&driver)) != OK) return status;
140
141 bool isDriverLoaded;
142 if ((status = data.readBool(&isDriverLoaded)) != OK) return status;
143
144 int64_t driverLoadingTime;
145 if ((status = data.readInt64(&driverLoadingTime)) != OK) return status;
146
Yiwei Zhang96c01712019-02-19 16:00:25 -0800147 setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime,
Yiwei Zhang27ab3ac2019-07-02 18:10:55 -0700148 appPackageName, vulkanVersion, static_cast<GpuStatsInfo::Driver>(driver),
Yiwei Zhang794d2952019-05-06 17:43:59 -0700149 isDriverLoaded, driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800150
151 return OK;
152 }
Yiwei Zhangbaea97f2019-02-27 16:35:37 -0800153 case GET_GPU_STATS_GLOBAL_INFO: {
154 CHECK_INTERFACE(IGpuService, data, reply);
155
156 std::vector<GpuStatsGlobalInfo> stats;
157 const status_t result = getGpuStatsGlobalInfo(&stats);
158
159 if ((status = reply->writeInt32(result)) != OK) return status;
160 if (result != OK) return result;
161
162 if ((status = reply->writeParcelableVector(stats)) != OK) return status;
163
164 return OK;
165 }
Yiwei Zhang178e0672019-03-04 14:17:12 -0800166 case GET_GPU_STATS_APP_INFO: {
167 CHECK_INTERFACE(IGpuService, data, reply);
168
169 std::vector<GpuStatsAppInfo> stats;
170 const status_t result = getGpuStatsAppInfo(&stats);
171
172 if ((status = reply->writeInt32(result)) != OK) return status;
173 if (result != OK) return result;
174
175 if ((status = reply->writeParcelableVector(stats)) != OK) return status;
176
177 return OK;
178 }
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700179 case SET_TARGET_STATS: {
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700180 CHECK_INTERFACE(IGpuService, data, reply);
181
182 std::string appPackageName;
183 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
184
185 uint64_t driverVersionCode;
186 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
187
Yiwei Zhangbcba4112019-07-03 13:39:32 -0700188 int32_t stats;
189 if ((status = data.readInt32(&stats)) != OK) return status;
190
191 uint64_t value;
192 if ((status = data.readUint64(&value)) != OK) return status;
193
194 setTargetStats(appPackageName, driverVersionCode,
195 static_cast<GpuStatsInfo::Stats>(stats), value);
Yiwei Zhang8c5e3bd2019-05-09 14:34:19 -0700196
197 return OK;
198 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800199 case SHELL_COMMAND_TRANSACTION: {
200 int in = data.readFileDescriptor();
201 int out = data.readFileDescriptor();
202 int err = data.readFileDescriptor();
203
204 std::vector<String16> args;
205 data.readString16Vector(&args);
206
207 sp<IBinder> unusedCallback;
208 if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status;
209
210 sp<IResultReceiver> resultReceiver;
211 if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status;
212
213 status = shellCommand(in, out, err, args);
214 if (resultReceiver != nullptr) resultReceiver->send(status);
215
216 return OK;
217 }
218 default:
219 return BBinder::onTransact(code, data, reply, flags);
220 }
221}
222
223} // namespace android