Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 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: |
| 28 | explicit BpGpuService(const sp<IBinder>& impl) : BpInterface<IGpuService>(impl) {} |
| 29 | |
Greg Kaiser | 210bb7e | 2019-02-12 12:40:05 -0800 | [diff] [blame] | 30 | virtual void setGpuStats(const std::string& driverPackageName, |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame^] | 31 | const std::string& driverVersionName, uint64_t driverVersionCode, |
| 32 | const std::string& appPackageName, GraphicsEnv::Driver driver, |
| 33 | bool isDriverLoaded, int64_t driverLoadingTime) { |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 34 | Parcel data, reply; |
| 35 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); |
| 36 | |
| 37 | data.writeUtf8AsUtf16(driverPackageName); |
| 38 | data.writeUtf8AsUtf16(driverVersionName); |
| 39 | data.writeUint64(driverVersionCode); |
| 40 | data.writeUtf8AsUtf16(appPackageName); |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame^] | 41 | data.writeInt32(static_cast<int32_t>(driver)); |
| 42 | data.writeBool(isDriverLoaded); |
| 43 | data.writeInt64(driverLoadingTime); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 44 | |
| 45 | remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply); |
| 46 | } |
| 47 | }; |
| 48 | |
| 49 | IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); |
| 50 | |
| 51 | status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 52 | uint32_t flags) { |
| 53 | ALOGV("onTransact code[0x%X]", code); |
| 54 | |
| 55 | status_t status; |
| 56 | switch (code) { |
| 57 | case SET_GPU_STATS: { |
| 58 | CHECK_INTERFACE(IGpuService, data, reply); |
| 59 | |
| 60 | std::string driverPackageName; |
| 61 | if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status; |
| 62 | |
| 63 | std::string driverVersionName; |
| 64 | if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status; |
| 65 | |
| 66 | uint64_t driverVersionCode; |
| 67 | if ((status = data.readUint64(&driverVersionCode)) != OK) return status; |
| 68 | |
| 69 | std::string appPackageName; |
| 70 | if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; |
| 71 | |
Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame^] | 72 | int32_t driver; |
| 73 | if ((status = data.readInt32(&driver)) != OK) return status; |
| 74 | |
| 75 | bool isDriverLoaded; |
| 76 | if ((status = data.readBool(&isDriverLoaded)) != OK) return status; |
| 77 | |
| 78 | int64_t driverLoadingTime; |
| 79 | if ((status = data.readInt64(&driverLoadingTime)) != OK) return status; |
| 80 | |
| 81 | setGpuStats(driverPackageName, driverVersionName, driverVersionCode, appPackageName, |
| 82 | static_cast<GraphicsEnv::Driver>(driver), isDriverLoaded, |
| 83 | driverLoadingTime); |
Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 84 | |
| 85 | return OK; |
| 86 | } |
| 87 | case SHELL_COMMAND_TRANSACTION: { |
| 88 | int in = data.readFileDescriptor(); |
| 89 | int out = data.readFileDescriptor(); |
| 90 | int err = data.readFileDescriptor(); |
| 91 | |
| 92 | std::vector<String16> args; |
| 93 | data.readString16Vector(&args); |
| 94 | |
| 95 | sp<IBinder> unusedCallback; |
| 96 | if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status; |
| 97 | |
| 98 | sp<IResultReceiver> resultReceiver; |
| 99 | if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status; |
| 100 | |
| 101 | status = shellCommand(in, out, err, args); |
| 102 | if (resultReceiver != nullptr) resultReceiver->send(status); |
| 103 | |
| 104 | return OK; |
| 105 | } |
| 106 | default: |
| 107 | return BBinder::onTransact(code, data, reply, flags); |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | } // namespace android |