From b340bb56044c125a5b8bed939b78a14a9b94bdcc Mon Sep 17 00:00:00 2001 From: Ningyuan Wang Date: Tue, 4 Apr 2017 16:21:44 -0700 Subject: [PATCH] Allow wificond to dump logs This adds the dump() function for wificond to dump logs to provided fd. Bug: 31336376 Test: compile Test: manual test, see wificond dump logs in bug report Change-Id: Ia27cee9c14728095d9843dfc08994ec981283ee3 --- server.cpp | 30 ++++++++++++++++++++++++++++++ server.h | 1 + 2 files changed, 31 insertions(+) diff --git a/server.cpp b/server.cpp index e8c56c6..434b44a 100644 --- a/server.cpp +++ b/server.cpp @@ -18,11 +18,15 @@ #include +#include #include +#include +#include #include "wificond/net/netlink_utils.h" #include "wificond/scanning/scan_utils.h" +using android::base::WriteStringToFd; using android::binder::Status; using android::sp; using android::IBinder; @@ -35,6 +39,7 @@ using android::wifi_system::HostapdManager; using android::wifi_system::InterfaceTool; using android::wifi_system::SupplicantManager; +using std::endl; using std::placeholders::_1; using std::string; using std::stringstream; @@ -44,6 +49,12 @@ using std::vector; namespace android { namespace wificond { +namespace { + +constexpr const char* kPermissionDump = "android.permission.DUMP"; + +} // namespace + Server::Server(unique_ptr if_tool, unique_ptr supplicant_manager, unique_ptr hostapd_manager, @@ -177,6 +188,25 @@ Status Server::GetApInterfaces(vector>* out_ap_interfaces) { return binder::Status::ok(); } +status_t Server::dump(int fd, const Vector& /*args*/) { + if (!PermissionCache::checkCallingPermission(String16(kPermissionDump))) { + IPCThreadState* ipc = android::IPCThreadState::self(); + LOG(ERROR) << "Caller (uid: " << ipc->getCallingUid() + << ") is not permitted to dump wificond state"; + return PERMISSION_DENIED; + } + + stringstream ss; + ss << "Current wiphy index: " << wiphy_index_ << endl; + + if (!WriteStringToFd(ss.str(), fd)) { + PLOG(ERROR) << "Failed to dump state to fd " << fd; + return FAILED_TRANSACTION; + } + + return OK; +} + void Server::MarkDownAllInterfaces() { uint32_t wiphy_index; vector interfaces; diff --git a/server.h b/server.h index a0f5b2c..f4f71d9 100644 --- a/server.h +++ b/server.h @@ -81,6 +81,7 @@ class Server : public android::net::wifi::BnWificond { std::vector>* out_client_ifs) override; android::binder::Status GetApInterfaces( std::vector>* out_ap_ifs) override; + status_t dump(int fd, const Vector& args) override; // Call this once on startup. It ignores all the invariants held // in wificond and tries to restore ourselves to a blank state by -- 2.11.0