1 /* 2 * Copyright (C) 2020 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 #pragma once 17 18 #include <android/hardware/dumpstate/1.1/IDumpstateDevice.h> 19 20 #include <automotive/filesystem> 21 #include <functional> 22 23 #include <grpc++/grpc++.h> 24 25 #include "DumpstateServer.grpc.pb.h" 26 #include "DumpstateServer.pb.h" 27 28 namespace android::hardware::dumpstate::V1_1::implementation { 29 30 namespace fs = android::hardware::automotive::filesystem; 31 32 class DumpstateDevice : public IDumpstateDevice { 33 public: 34 explicit DumpstateDevice(const std::string& addr); 35 36 // Methods from ::android::hardware::dumpstate::V1_0::IDumpstateDevice follow. 37 Return<void> dumpstateBoard(const hidl_handle& h) override; 38 39 // Methods from ::android::hardware::dumpstate::V1_1::IDumpstateDevice follow. 40 Return<DumpstateStatus> dumpstateBoard_1_1(const hidl_handle& h, const DumpstateMode mode, 41 const uint64_t timeoutMillis) override; 42 Return<void> setVerboseLoggingEnabled(const bool enable) override; 43 Return<bool> getVerboseLoggingEnabled() override; 44 45 bool isHealthy(); 46 47 Return<void> debug(const hidl_handle& fd, const hidl_vec<hidl_string>& options); 48 49 private: 50 bool dumpRemoteLogs(::grpc::ClientReaderInterface<dumpstate_proto::DumpstateBuffer>* reader, 51 const fs::path& dumpPath); 52 bool dumpString(const std::string& text, const fs::path& dumpPath); 53 54 bool dumpHelperSystem(int textFd, int binFd); 55 56 void debugDumpServices(std::function<void(std::string)> f); 57 58 std::vector<std::string> getAvailableServices(); 59 60 std::string mServiceAddr; 61 std::shared_ptr<::grpc::Channel> mGrpcChannel; 62 std::unique_ptr<dumpstate_proto::DumpstateServer::Stub> mGrpcStub; 63 }; 64 65 sp<DumpstateDevice> makeVirtualizationDumpstateDevice(const std::string& addr); 66 67 } // namespace android::hardware::dumpstate::V1_1::implementation 68