• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 
24 namespace android {
25 
26 class BpGpuService : public BpInterface<IGpuService> {
27 public:
BpGpuService(const sp<IBinder> & impl)28     explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {}
29 
setGpuStats(const std::string & driverPackageName,const std::string & driverVersionName,uint64_t driverVersionCode,int64_t driverBuildTime,const std::string & appPackageName,const int32_t vulkanVersion,GpuStatsInfo::Driver driver,bool isDriverLoaded,int64_t driverLoadingTime)30     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 {
35         Parcel data, reply;
36         data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
37 
38         data.writeUtf8AsUtf16(driverPackageName);
39         data.writeUtf8AsUtf16(driverVersionName);
40         data.writeUint64(driverVersionCode);
41         data.writeInt64(driverBuildTime);
42         data.writeUtf8AsUtf16(appPackageName);
43         data.writeInt32(vulkanVersion);
44         data.writeInt32(static_cast<int32_t>(driver));
45         data.writeBool(isDriverLoaded);
46         data.writeInt64(driverLoadingTime);
47 
48         remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY);
49     }
50 
setTargetStats(const std::string & appPackageName,const uint64_t driverVersionCode,const GpuStatsInfo::Stats stats,const uint64_t value)51     void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode,
52                         const GpuStatsInfo::Stats stats, const uint64_t value) override {
53         Parcel data, reply;
54         data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
55 
56         data.writeUtf8AsUtf16(appPackageName);
57         data.writeUint64(driverVersionCode);
58         data.writeInt32(static_cast<int32_t>(stats));
59         data.writeUint64(value);
60 
61         remote()->transact(BnGpuService::SET_TARGET_STATS, data, &reply, IBinder::FLAG_ONEWAY);
62     }
63 
setTargetStatsArray(const std::string & appPackageName,const uint64_t driverVersionCode,const GpuStatsInfo::Stats stats,const uint64_t * values,const uint32_t valueCount)64     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 
setUpdatableDriverPath(const std::string & driverPath)72     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 
toggleAngleAsSystemDriver(bool enabled)81     void toggleAngleAsSystemDriver(bool enabled) override {
82         Parcel data, reply;
83         data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
84         data.writeBool(enabled);
85 
86         remote()->transact(BnGpuService::TOGGLE_ANGLE_AS_SYSTEM_DRIVER, data, &reply,
87                            IBinder::FLAG_ONEWAY);
88     }
89 
getUpdatableDriverPath()90     std::string getUpdatableDriverPath() override {
91         Parcel data, reply;
92         data.writeInterfaceToken(IGpuService::getInterfaceDescriptor());
93 
94         status_t error = remote()->transact(BnGpuService::GET_UPDATABLE_DRIVER_PATH, data, &reply);
95         std::string driverPath;
96         if (error == OK) {
97             error = reply.readUtf8FromUtf16(&driverPath);
98         }
99         return driverPath;
100     }
101 };
102 
103 IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService");
104 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)105 status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
106                                   uint32_t flags) {
107     ALOGV("onTransact code[0x%X]", code);
108 
109     status_t status;
110     switch (code) {
111         case SET_GPU_STATS: {
112             CHECK_INTERFACE(IGpuService, data, reply);
113 
114             std::string driverPackageName;
115             if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status;
116 
117             std::string driverVersionName;
118             if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status;
119 
120             uint64_t driverVersionCode;
121             if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
122 
123             int64_t driverBuildTime;
124             if ((status = data.readInt64(&driverBuildTime)) != OK) return status;
125 
126             std::string appPackageName;
127             if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
128 
129             int32_t vulkanVersion;
130             if ((status = data.readInt32(&vulkanVersion)) != OK) return status;
131 
132             int32_t driver;
133             if ((status = data.readInt32(&driver)) != OK) return status;
134 
135             bool isDriverLoaded;
136             if ((status = data.readBool(&isDriverLoaded)) != OK) return status;
137 
138             int64_t driverLoadingTime;
139             if ((status = data.readInt64(&driverLoadingTime)) != OK) return status;
140 
141             setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime,
142                         appPackageName, vulkanVersion, static_cast<GpuStatsInfo::Driver>(driver),
143                         isDriverLoaded, driverLoadingTime);
144 
145             return OK;
146         }
147         case SET_TARGET_STATS: {
148             CHECK_INTERFACE(IGpuService, data, reply);
149 
150             std::string appPackageName;
151             if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status;
152 
153             uint64_t driverVersionCode;
154             if ((status = data.readUint64(&driverVersionCode)) != OK) return status;
155 
156             int32_t stats;
157             if ((status = data.readInt32(&stats)) != OK) return status;
158 
159             uint64_t value;
160             if ((status = data.readUint64(&value)) != OK) return status;
161 
162             setTargetStats(appPackageName, driverVersionCode,
163                            static_cast<GpuStatsInfo::Stats>(stats), value);
164 
165             return OK;
166         }
167         case SET_UPDATABLE_DRIVER_PATH: {
168             CHECK_INTERFACE(IGpuService, data, reply);
169 
170             std::string driverPath;
171             if ((status = data.readUtf8FromUtf16(&driverPath)) != OK) return status;
172 
173             setUpdatableDriverPath(driverPath);
174             return OK;
175         }
176         case GET_UPDATABLE_DRIVER_PATH: {
177             CHECK_INTERFACE(IGpuService, data, reply);
178 
179             std::string driverPath = getUpdatableDriverPath();
180             return reply->writeUtf8AsUtf16(driverPath);
181         }
182         case SHELL_COMMAND_TRANSACTION: {
183             int in = data.readFileDescriptor();
184             int out = data.readFileDescriptor();
185             int err = data.readFileDescriptor();
186 
187             std::vector<String16> args;
188             data.readString16Vector(&args);
189 
190             sp<IBinder> unusedCallback;
191             if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status;
192 
193             sp<IResultReceiver> resultReceiver;
194             if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status;
195 
196             status = shellCommand(in, out, err, args);
197             if (resultReceiver != nullptr) resultReceiver->send(status);
198 
199             return OK;
200         }
201         case TOGGLE_ANGLE_AS_SYSTEM_DRIVER: {
202             CHECK_INTERFACE(IGpuService, data, reply);
203 
204             bool enableAngleAsSystemDriver;
205             if ((status = data.readBool(&enableAngleAsSystemDriver)) != OK) return status;
206 
207             toggleAngleAsSystemDriver(enableAngleAsSystemDriver);
208             return OK;
209         }
210         default:
211             return BBinder::onTransact(code, data, reply, flags);
212     }
213 }
214 
215 } // namespace android
216