| 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 | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 32 | const std::string& driverBuildDate, const std::string& appPackageName, | 
|  | 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 | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 41 | data.writeUtf8AsUtf16(driverBuildDate); | 
| 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 | } | 
|  | 49 | }; | 
|  | 50 |  | 
|  | 51 | IMPLEMENT_META_INTERFACE(GpuService, "android.graphicsenv.IGpuService"); | 
|  | 52 |  | 
|  | 53 | status_t BnGpuService::onTransact(uint32_t code, const Parcel& data, Parcel* reply, | 
|  | 54 | uint32_t flags) { | 
|  | 55 | ALOGV("onTransact code[0x%X]", code); | 
|  | 56 |  | 
|  | 57 | status_t status; | 
|  | 58 | switch (code) { | 
|  | 59 | case SET_GPU_STATS: { | 
|  | 60 | CHECK_INTERFACE(IGpuService, data, reply); | 
|  | 61 |  | 
|  | 62 | std::string driverPackageName; | 
|  | 63 | if ((status = data.readUtf8FromUtf16(&driverPackageName)) != OK) return status; | 
|  | 64 |  | 
|  | 65 | std::string driverVersionName; | 
|  | 66 | if ((status = data.readUtf8FromUtf16(&driverVersionName)) != OK) return status; | 
|  | 67 |  | 
|  | 68 | uint64_t driverVersionCode; | 
|  | 69 | if ((status = data.readUint64(&driverVersionCode)) != OK) return status; | 
|  | 70 |  | 
| Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 71 | std::string driverBuildDate; | 
|  | 72 | if ((status = data.readUtf8FromUtf16(&driverBuildDate)) != OK) return status; | 
|  | 73 |  | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 74 | std::string appPackageName; | 
|  | 75 | if ((status = data.readUtf8FromUtf16(&appPackageName)) != OK) return status; | 
|  | 76 |  | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 77 | int32_t driver; | 
|  | 78 | if ((status = data.readInt32(&driver)) != OK) return status; | 
|  | 79 |  | 
|  | 80 | bool isDriverLoaded; | 
|  | 81 | if ((status = data.readBool(&isDriverLoaded)) != OK) return status; | 
|  | 82 |  | 
|  | 83 | int64_t driverLoadingTime; | 
|  | 84 | if ((status = data.readInt64(&driverLoadingTime)) != OK) return status; | 
|  | 85 |  | 
| Yiwei Zhang | 512a723 | 2019-02-15 16:04:41 -0800 | [diff] [blame] | 86 | setGpuStats(driverPackageName, driverVersionName, driverVersionCode, driverBuildDate, | 
|  | 87 | appPackageName, static_cast<GraphicsEnv::Driver>(driver), isDriverLoaded, | 
| Yiwei Zhang | d986181 | 2019-02-13 11:51:55 -0800 | [diff] [blame] | 88 | driverLoadingTime); | 
| Yiwei Zhang | cb9d4e4 | 2019-02-06 20:22:59 -0800 | [diff] [blame] | 89 |  | 
|  | 90 | return OK; | 
|  | 91 | } | 
|  | 92 | case SHELL_COMMAND_TRANSACTION: { | 
|  | 93 | int in = data.readFileDescriptor(); | 
|  | 94 | int out = data.readFileDescriptor(); | 
|  | 95 | int err = data.readFileDescriptor(); | 
|  | 96 |  | 
|  | 97 | std::vector<String16> args; | 
|  | 98 | data.readString16Vector(&args); | 
|  | 99 |  | 
|  | 100 | sp<IBinder> unusedCallback; | 
|  | 101 | if ((status = data.readNullableStrongBinder(&unusedCallback)) != OK) return status; | 
|  | 102 |  | 
|  | 103 | sp<IResultReceiver> resultReceiver; | 
|  | 104 | if ((status = data.readNullableStrongBinder(&resultReceiver)) != OK) return status; | 
|  | 105 |  | 
|  | 106 | status = shellCommand(in, out, err, args); | 
|  | 107 | if (resultReceiver != nullptr) resultReceiver->send(status); | 
|  | 108 |  | 
|  | 109 | return OK; | 
|  | 110 | } | 
|  | 111 | default: | 
|  | 112 | return BBinder::onTransact(code, data, reply, flags); | 
|  | 113 | } | 
|  | 114 | } | 
|  | 115 |  | 
|  | 116 | } // namespace android |