Felipe Leme | 6a276ba | 2016-11-28 09:42:12 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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 | |
Felipe Leme | e83f9fb | 2016-11-15 15:08:47 -0800 | [diff] [blame] | 17 | #define LOG_TAG "dumpstate" |
| 18 | |
| 19 | #include "DumpstateDevice.h" |
| 20 | |
| 21 | #include <log/log.h> |
| 22 | |
| 23 | #include "DumpstateUtil.h" |
| 24 | |
Steven Moreland | 92a95b2 | 2016-12-01 09:29:48 -0800 | [diff] [blame] | 25 | using android::os::dumpstate::DumpFileToFd; |
| 26 | using android::os::dumpstate::RunCommandToFd; |
| 27 | |
Felipe Leme | e83f9fb | 2016-11-15 15:08:47 -0800 | [diff] [blame] | 28 | namespace android { |
| 29 | namespace hardware { |
| 30 | namespace dumpstate { |
| 31 | namespace V1_0 { |
| 32 | namespace implementation { |
| 33 | |
| 34 | // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow. |
Colin Cross | 94a069e | 2016-11-22 21:31:36 -0800 | [diff] [blame] | 35 | Return<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) { |
Steven Moreland | 92a95b2 | 2016-12-01 09:29:48 -0800 | [diff] [blame] | 36 | // NOTE: this is just an example on how to use the DumpstateUtil.h functions to implement |
| 37 | // this interface - since HIDL_FETCH_IDumpstateDevice() is not defined, this function will never |
| 38 | // be called by dumpstate. |
| 39 | |
Steven Moreland | 34ace43 | 2017-05-23 16:06:04 -0700 | [diff] [blame] | 40 | if (handle == nullptr || handle->numFds < 1) { |
Felipe Leme | e83f9fb | 2016-11-15 15:08:47 -0800 | [diff] [blame] | 41 | ALOGE("no FDs\n"); |
| 42 | return Void(); |
| 43 | } |
| 44 | |
| 45 | int fd = handle->data[0]; |
| 46 | if (fd < 0) { |
| 47 | ALOGE("invalid FD: %d\n", handle->data[0]); |
| 48 | return Void(); |
| 49 | } |
| 50 | ALOGD("DumpstateDevice::dumpstateBoard() FD: %d\n", fd); |
| 51 | ALOGI("Dumpstate HIDL not provided by device\n"); |
| 52 | dprintf(fd, "Dumpstate HIDL not provided by device; providing bogus data.\n"); |
| 53 | |
Felipe Leme | 6a276ba | 2016-11-28 09:42:12 -0800 | [diff] [blame] | 54 | // Shows some examples on how to use the libdumpstateutil API. |
Sandeep Patil | fd472b8 | 2017-04-14 19:09:29 -0700 | [diff] [blame] | 55 | RunCommandToFd(fd, "DATE", {"/vendor/bin/date"}); |
Felipe Leme | 6a276ba | 2016-11-28 09:42:12 -0800 | [diff] [blame] | 56 | DumpFileToFd(fd, "HOSTS", "/system/etc/hosts"); |
Felipe Leme | e83f9fb | 2016-11-15 15:08:47 -0800 | [diff] [blame] | 57 | |
| 58 | return Void(); |
| 59 | } |
| 60 | |
Felipe Leme | e83f9fb | 2016-11-15 15:08:47 -0800 | [diff] [blame] | 61 | } // namespace implementation |
| 62 | } // namespace V1_0 |
| 63 | } // namespace dumpstate |
| 64 | } // namespace hardware |
| 65 | } // namespace android |