| 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 | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 33 | GraphicsEnv::Driver driver, bool isDriverLoaded, | 
|  | 34 | 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 | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 43 | data.writeInt32(static_cast<int32_t>(driver)); | 
|  | 44 | data.writeBool(isDriverLoaded); | 
|  | 45 | data.writeInt64(driverLoadingTime); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 46 |  | 
| Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 47 | remote()->transact(BnGpuService::SET_GPU_STATS, data, &reply, IBinder::FLAG_ONEWAY); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 48 | } | 
| Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 49 |  | 
|  | 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 Zhang | 178e067 | 2019-03-04 14:17:12 -0800 | [diff] [blame] | 70 |  | 
|  | 71 | virtual status_t getGpuStatsAppInfo(std::vector<GpuStatsAppInfo>* outStats) const { | 
|  | 72 | if (!outStats) return UNEXPECTED_NULL; | 
|  | 73 |  | 
|  | 74 | Parcel data, reply; | 
|  | 75 | status_t status; | 
|  | 76 |  | 
|  | 77 | if ((status = data.writeInterfaceToken(IGpuService::getInterfaceDescriptor())) != OK) { | 
|  | 78 | return status; | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | if ((status = remote()->transact(BnGpuService::GET_GPU_STATS_APP_INFO, data, &reply)) != | 
|  | 82 | OK) { | 
|  | 83 | return status; | 
|  | 84 | } | 
|  | 85 |  | 
|  | 86 | int32_t result = 0; | 
|  | 87 | if ((status = reply.readInt32(&result)) != OK) return status; | 
|  | 88 | if (result != OK) return result; | 
|  | 89 |  | 
|  | 90 | outStats->clear(); | 
|  | 91 | return reply.readParcelableVector(outStats); | 
|  | 92 | } | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 93 | }; | 
|  | 94 |  | 
|  | 95 | IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); | 
|  | 96 |  | 
|  | 97 | status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, | 
|  | 98 | uint32_t flags) { | 
|  | 99 | ALOGV("onTransact code[0x%X]", code); | 
|  | 100 |  | 
|  | 101 | status_t status; | 
|  | 102 | switch (code) { | 
|  | 103 | case SET_GPU_STATS: { | 
|  | 104 | CHECK_INTERFACE(IGpuService, data, reply); | 
|  | 105 |  | 
|  | 106 | std::string driverPackageName; | 
|  | 107 | if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status; | 
|  | 108 |  | 
|  | 109 | std::string driverVersionName; | 
|  | 110 | if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status; | 
|  | 111 |  | 
|  | 112 | uint64_t driverVersionCode; | 
|  | 113 | if ((status = data.readUint64(&driverVersionCode)) != OK) return status; | 
|  | 114 |  | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 115 | int64_t driverBuildTime; | 
|  | 116 | if ((status = data.readInt64(&driverBuildTime)) != OK) return status; | 
| Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 117 |  | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 118 | std::string appPackageName; | 
|  | 119 | if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; | 
|  | 120 |  | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 121 | int32_t driver; | 
|  | 122 | if ((status = data.readInt32(&driver)) != OK) return status; | 
|  | 123 |  | 
|  | 124 | bool isDriverLoaded; | 
|  | 125 | if ((status = data.readBool(&isDriverLoaded)) != OK) return status; | 
|  | 126 |  | 
|  | 127 | int64_t driverLoadingTime; | 
|  | 128 | if ((status = data.readInt64(&driverLoadingTime)) != OK) return status; | 
|  | 129 |  | 
| Yiwei Zhang | 96c0171 | 2019-02-19 16:00:25 -0800 | [diff] [blame] | 130 | setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildTime, | 
| Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 131 | appPackageName, static_cast<GraphicsEnv::Driver>(driver), isDriverLoaded, | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 132 | driverLoadingTime); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 133 |  | 
|  | 134 | return OK; | 
|  | 135 | } | 
| Yiwei Zhang | baea97f | 2019-02-27 16:35:37 -0800 | [diff] [blame] | 136 | case GET_GPU_STATS_GLOBAL_INFO: { | 
|  | 137 | CHECK_INTERFACE(IGpuService, data, reply); | 
|  | 138 |  | 
|  | 139 | std::vector<GpuStatsGlobalInfo> stats; | 
|  | 140 | const status_t result = getGpuStatsGlobalInfo(&stats); | 
|  | 141 |  | 
|  | 142 | if ((status = reply->writeInt32(result)) != OK) return status; | 
|  | 143 | if (result != OK) return result; | 
|  | 144 |  | 
|  | 145 | if ((status = reply->writeParcelableVector(stats)) != OK) return status; | 
|  | 146 |  | 
|  | 147 | return OK; | 
|  | 148 | } | 
| Yiwei Zhang | 178e067 | 2019-03-04 14:17:12 -0800 | [diff] [blame] | 149 | case GET_GPU_STATS_APP_INFO: { | 
|  | 150 | CHECK_INTERFACE(IGpuService, data, reply); | 
|  | 151 |  | 
|  | 152 | std::vector<GpuStatsAppInfo> stats; | 
|  | 153 | const status_t result = getGpuStatsAppInfo(&stats); | 
|  | 154 |  | 
|  | 155 | if ((status = reply->writeInt32(result)) != OK) return status; | 
|  | 156 | if (result != OK) return result; | 
|  | 157 |  | 
|  | 158 | if ((status = reply->writeParcelableVector(stats)) != OK) return status; | 
|  | 159 |  | 
|  | 160 | return OK; | 
|  | 161 | } | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 162 | case SHELL_COMMAND_TRANSACTION: { | 
|  | 163 | int in = data.readFileDescriptor(); | 
|  | 164 | int out = data.readFileDescriptor(); | 
|  | 165 | int err = data.readFileDescriptor(); | 
|  | 166 |  | 
|  | 167 | std::vector<String16> args; | 
|  | 168 | data.readString16Vector(&args); | 
|  | 169 |  | 
|  | 170 | sp<IBinder> unusedCallback; | 
|  | 171 | if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status; | 
|  | 172 |  | 
|  | 173 | sp<IResultReceiver> resultReceiver; | 
|  | 174 | if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status; | 
|  | 175 |  | 
|  | 176 | status = shellCommand(in, out, err, args); | 
|  | 177 | if (resultReceiver != nullptr) resultReceiver->send(status); | 
|  | 178 |  | 
|  | 179 | return OK; | 
|  | 180 | } | 
|  | 181 | default: | 
|  | 182 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 183 | } | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | } // namespace android |