blob: 98a63952c7d9d09a98d9621ec00d127451016370 [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
30 virtual void setGpuStats(const std::string driverPackageName,
31 const std::string driverVersionName, const uint64_t driverVersionCode,
32 const std::string appPackageName) {
33 Parcel data, reply;
34 data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
35
36 data.writeUtf8AsUtf16(driverPackageName);
37 data.writeUtf8AsUtf16(driverVersionName);
38 data.writeUint64(driverVersionCode);
39 data.writeUtf8AsUtf16(appPackageName);
40
41 remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply);
42 }
43};
44
45IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
46
47status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
48 uint32_t flags) {
49 ALOGV("onTransact code[0x%X]", code);
50
51 status_t status;
52 switch (code) {
53 case SET_GPU_STATS: {
54 CHECK_INTERFACE(IGpuService, data, reply);
55
56 std::string driverPackageName;
57 if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status;
58
59 std::string driverVersionName;
60 if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status;
61
62 uint64_t driverVersionCode;
63 if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
64
65 std::string appPackageName;
66 if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
67
68 setGpuStats(driverPackageName, driverVersionName, driverVersionCode, appPackageName);
69
70 return OK;
71 }
72 case SHELL_COMMAND_TRANSACTION: {
73 int in = data.readFileDescriptor();
74 int out = data.readFileDescriptor();
75 int err = data.readFileDescriptor();
76
77 std::vector<String16> args;
78 data.readString16Vector(&args);
79
80 sp<IBinder> unusedCallback;
81 if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status;
82
83 sp<IResultReceiver> resultReceiver;
84 if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status;
85
86 status = shellCommand(in, out, err, args);
87 if (resultReceiver != nullptr) resultReceiver->send(status);
88
89 return OK;
90 }
91 default:
92 return BBinder::onTransact(code, data, reply, flags);
93 }
94}
95
96} // namespace android