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