blob: 0b0bf445aebb95f3ef6ad3f0db382d9ff33f7aac [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 Zhang512a7232019-02-15 16:04:41 -080033 GraphicsEnv::Driver driver, bool isDriverLoaded,
34 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 Zhangd9861812019-02-13 11:51:55 -080043 data.writeInt32(static_cast<int32_t>(driver));
44 data.writeBool(isDriverLoaded);
45 data.writeInt64(driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080046
Yiwei Zhang512a7232019-02-15 16:04:41 -080047 remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080048 }
Yiwei Zhangbaea97f2019-02-27 16:35:37 -080049
50 virtual status_t getGpuStatsGlobalInfo(std::vector<GpuStatsGlobalInfo>* outStats) const {
51 if (!outStats) return UNEXPECTED_NULL;
52
53 Parcel data, reply;
54 status_t status;
55
56 if ((status = data.writeInterfaceToken(IGpuService::getInterfaceDescriptor())) != OK)
57 return status;
58
59 if ((status = remote()->transact(BnGpuService::GET_GPU_STATS_GLOBAL_INFO, data, &reply)) !=
60 OK)
61 return status;
62
63 int32_t result = 0;
64 if ((status = reply.readInt32(&result)) != OK) return status;
65 if (result != OK) return result;
66
67 outStats->clear();
68 return reply.readParcelableVector(outStats);
69 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080070};
71
72IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
73
74status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
75 uint32_t flags) {
76 ALOGV("onTransact code[0x%X]", code);
77
78 status_t status;
79 switch (code) {
80 case SET_GPU_STATS: {
81 CHECK_INTERFACE(IGpuService, data, reply);
82
83 std::string driverPackageName;
84 if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status;
85
86 std::string driverVersionName;
87 if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status;
88
89 uint64_t driverVersionCode;
90 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
91
Yiwei Zhang96c01712019-02-19 16:00:25 -080092 int64_t driverBuildTime;
93 if ((status = data.readInt64(&driverBuildTime)) != OK) return status;
Yiwei Zhang512a7232019-02-15 16:04:41 -080094
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -080095 std::string appPackageName;
96 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
97
Yiwei Zhangd9861812019-02-13 11:51:55 -080098 int32_t driver;
99 if ((status = data.readInt32(&driver)) != OK) return status;
100
101 bool isDriverLoaded;
102 if ((status = data.readBool(&isDriverLoaded)) != OK) return status;
103
104 int64_t driverLoadingTime;
105 if ((status = data.readInt64(&driverLoadingTime)) != OK) return status;
106
Yiwei Zhang96c01712019-02-19 16:00:25 -0800107 setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime,
Yiwei Zhang512a7232019-02-15 16:04:41 -0800108 appPackageName, static_cast<GraphicsEnv::Driver>(driver), isDriverLoaded,
Yiwei Zhangd9861812019-02-13 11:51:55 -0800109 driverLoadingTime);
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800110
111 return OK;
112 }
Yiwei Zhangbaea97f2019-02-27 16:35:37 -0800113 case GET_GPU_STATS_GLOBAL_INFO: {
114 CHECK_INTERFACE(IGpuService, data, reply);
115
116 std::vector<GpuStatsGlobalInfo> stats;
117 const status_t result = getGpuStatsGlobalInfo(&stats);
118
119 if ((status = reply->writeInt32(result)) != OK) return status;
120 if (result != OK) return result;
121
122 if ((status = reply->writeParcelableVector(stats)) != OK) return status;
123
124 return OK;
125 }
Yiwei Zhangcb9d4e42019-02-06 20:22:59 -0800126 case SHELL_COMMAND_TRANSACTION: {
127 int in = data.readFileDescriptor();
128 int out = data.readFileDescriptor();
129 int err = data.readFileDescriptor();
130
131 std::vector<String16> args;
132 data.readString16Vector(&args);
133
134 sp<IBinder> unusedCallback;
135 if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status;
136
137 sp<IResultReceiver> resultReceiver;
138 if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status;
139
140 status = shellCommand(in, out, err, args);
141 if (resultReceiver != nullptr) resultReceiver->send(status);
142
143 return OK;
144 }
145 default:
146 return BBinder::onTransact(code, data, reply, flags);
147 }
148}
149
150} // namespace android