| 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, | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 32 | int64_t driverBuildTime, const std::string& appPackageName, | 
| Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 33 | const int32_t vulkanVersion, GpuStatsInfo::Driver driver, | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 34 | bool isDriverLoaded, int64_t driverLoadingTime) { | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 35 | Parcel data, reply; | 
|  | 36 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); | 
|  | 37 |  | 
|  | 38 | data.writeUtf8AsUtf16(driverPackageName); | 
|  | 39 | data.writeUtf8AsUtf16(driverVersionName); | 
|  | 40 | data.writeUint64(driverVersionCode); | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 41 | data.writeInt64(driverBuildTime); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 42 | data.writeUtf8AsUtf16(appPackageName); | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 43 | data.writeInt32(vulkanVersion); | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 44 | data.writeInt32(static_cast<int32_t>(driver)); | 
|  | 45 | data.writeBool(isDriverLoaded); | 
|  | 46 | data.writeInt64(driverLoadingTime); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 47 |  | 
| Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 48 | remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 49 | } | 
| Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 50 |  | 
| Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 51 | virtual void setTargetStats(const std::string& appPackageName, const uint64_t driverVersionCode, | 
|  | 52 | const GpuStatsInfo::Stats stats, const uint64_t value) { | 
| Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 53 | Parcel data, reply; | 
|  | 54 | data.writeInterfaceToken(IGpuService::getInterfaceDescriptor()); | 
|  | 55 |  | 
|  | 56 | data.writeUtf8AsUtf16(appPackageName); | 
|  | 57 | data.writeUint64(driverVersionCode); | 
| Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 58 | data.writeInt32(static_cast<int32_t>(stats)); | 
|  | 59 | data.writeUint64(value); | 
| Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 60 |  | 
| Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 61 | remote()->transact(BnGpuService::SET_TARGET_STATS, data, &reply, IBinder::FLAG_ONEWAY); | 
| Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 62 | } | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 63 | }; | 
|  | 64 |  | 
|  | 65 | IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); | 
|  | 66 |  | 
|  | 67 | status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, | 
|  | 68 | uint32_t flags) { | 
|  | 69 | ALOGV("onTransact code[0x%X]", code); | 
|  | 70 |  | 
|  | 71 | status_t status; | 
|  | 72 | switch (code) { | 
|  | 73 | case SET_GPU_STATS: { | 
|  | 74 | CHECK_INTERFACE(IGpuService, data, reply); | 
|  | 75 |  | 
|  | 76 | std::string driverPackageName; | 
|  | 77 | if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status; | 
|  | 78 |  | 
|  | 79 | std::string driverVersionName; | 
|  | 80 | if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status; | 
|  | 81 |  | 
|  | 82 | uint64_t driverVersionCode; | 
|  | 83 | if ((status = data.readUint64(&driverVersionCode)) != OK) return status; | 
|  | 84 |  | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 85 | int64_t driverBuildTime; | 
|  | 86 | if ((status = data.readInt64(&driverBuildTime)) != OK) return status; | 
| Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 87 |  | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 88 | std::string appPackageName; | 
|  | 89 | if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; | 
|  | 90 |  | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 91 | int32_t vulkanVersion; | 
|  | 92 | if ((status = data.readInt32(&vulkanVersion)) != OK) return status; | 
|  | 93 |  | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 94 | int32_t driver; | 
|  | 95 | if ((status = data.readInt32(&driver)) != OK) return status; | 
|  | 96 |  | 
|  | 97 | bool isDriverLoaded; | 
|  | 98 | if ((status = data.readBool(&isDriverLoaded)) != OK) return status; | 
|  | 99 |  | 
|  | 100 | int64_t driverLoadingTime; | 
|  | 101 | if ((status = data.readInt64(&driverLoadingTime)) != OK) return status; | 
|  | 102 |  | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 103 | setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime, | 
| Yiwei Zhang | 27ab3ac | 2019-07-02 18:10:55 -0700 | [diff] [blame] | 104 | appPackageName, vulkanVersion, static_cast<GpuStatsInfo::Driver>(driver), | 
| Yiwei Zhang | 794d295 | 2019-05-06 17:43:59 -0700 | [diff] [blame] | 105 | isDriverLoaded, driverLoadingTime); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 106 |  | 
|  | 107 | return OK; | 
|  | 108 | } | 
| Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 109 | case SET_TARGET_STATS: { | 
| Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 110 | CHECK_INTERFACE(IGpuService, data, reply); | 
|  | 111 |  | 
|  | 112 | std::string appPackageName; | 
|  | 113 | if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; | 
|  | 114 |  | 
|  | 115 | uint64_t driverVersionCode; | 
|  | 116 | if ((status = data.readUint64(&driverVersionCode)) != OK) return status; | 
|  | 117 |  | 
| Yiwei Zhang | bcba411 | 2019-07-03 13:39:32 -0700 | [diff] [blame] | 118 | int32_t stats; | 
|  | 119 | if ((status = data.readInt32(&stats)) != OK) return status; | 
|  | 120 |  | 
|  | 121 | uint64_t value; | 
|  | 122 | if ((status = data.readUint64(&value)) != OK) return status; | 
|  | 123 |  | 
|  | 124 | setTargetStats(appPackageName, driverVersionCode, | 
|  | 125 | static_cast<GpuStatsInfo::Stats>(stats), value); | 
| Yiwei Zhang | 8c5e3bd | 2019-05-09 14:34:19 -0700 | [diff] [blame] | 126 |  | 
|  | 127 | return OK; | 
|  | 128 | } | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 129 | case SHELL_COMMAND_TRANSACTION: { | 
|  | 130 | int in = data.readFileDescriptor(); | 
|  | 131 | int out = data.readFileDescriptor(); | 
|  | 132 | int err = data.readFileDescriptor(); | 
|  | 133 |  | 
|  | 134 | std::vector<String16> args; | 
|  | 135 | data.readString16Vector(&args); | 
|  | 136 |  | 
|  | 137 | sp<IBinder> unusedCallback; | 
|  | 138 | if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status; | 
|  | 139 |  | 
|  | 140 | sp<IResultReceiver> resultReceiver; | 
|  | 141 | if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status; | 
|  | 142 |  | 
|  | 143 | status = shellCommand(in, out, err, args); | 
|  | 144 | if (resultReceiver != nullptr) resultReceiver->send(status); | 
|  | 145 |  | 
|  | 146 | return OK; | 
|  | 147 | } | 
|  | 148 | default: | 
|  | 149 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 150 | } | 
|  | 151 | } | 
|  | 152 |  | 
|  | 153 | } // namespace android |