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
17 #define LOG_TAG "dumpstate"
18
19 #include "DumpstateDevice.h"
20
21 #include <hidl/HidlBinderSupport.h>
22 #include <log/log.h>
23
24 #include "DumpstateUtil.h"
25
26 using android::os::dumpstate::DumpFileToFd;
27 using android::os::dumpstate::RunCommandToFd;
28
29 namespace android {
30 namespace hardware {
31 namespace dumpstate {
32 namespace V1_0 {
33 namespace implementation {
34
35 // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow.
dumpstateBoard(const hidl_handle & handle)36 Return<void> DumpstateDevice::dumpstateBoard(const hidl_handle& handle) {
37 // NOTE: this is just an example on how to use the DumpstateUtil.h functions to implement
38 // this interface.
39
40 // Exit when dump is completed since this is a lazy HAL.
41 addPostCommandTask([]() {
42 exit(0);
43 });
44
45 if (handle == nullptr || handle->numFds < 1) {
46 ALOGE("no FDs\n");
47 return Void();
48 }
49
50 int fd = handle->data[0];
51 if (fd < 0) {
52 ALOGE("invalid FD: %d\n", handle->data[0]);
53 return Void();
54 }
55 ALOGD("DumpstateDevice::dumpstateBoard() FD: %d\n", fd);
56 ALOGI("Dumpstate HIDL not provided by device\n");
57 dprintf(fd, "Dumpstate HIDL not provided by device; providing bogus data.\n");
58
59 // Shows some examples on how to use the libdumpstateutil API.
60 RunCommandToFd(fd, "DATE", {"/vendor/bin/date"});
61 DumpFileToFd(fd, "HOSTS", "/system/etc/hosts");
62
63 return Void();
64 }
65
66 } // namespace implementation
67 } // namespace V1_0
68 } // namespace dumpstate
69 } // namespace hardware
70 } // namespace android
71