* limitations under the License.
*/
+#define LOG_TAG "lshal"
+#include <android-base/logging.h>
+
#include "Lshal.h"
#include <set>
#include <string>
+#include <hidl/ServiceManagement.h>
+
+#include "DebugCommand.h"
#include "ListCommand.h"
#include "PipeRelay.h"
return hv;
}
-// static
-void Lshal::emitDebugInfo(
- const sp<IServiceManager> &serviceManager,
+Status Lshal::emitDebugInfo(
const std::string &interfaceName,
const std::string &instanceName,
const std::vector<std::string> &options,
- std::ostream &out) {
+ std::ostream &out,
+ NullableOStream<std::ostream> err) const {
using android::hidl::base::V1_0::IBase;
hardware::Return<sp<IBase>> retBase =
- serviceManager->get(interfaceName, instanceName);
+ ::android::hardware::defaultServiceManager()->get(interfaceName, instanceName);
+
+ if (!retBase.isOk()) {
+ std::string msg = "Cannot get " + interfaceName + "/" + instanceName + ": "
+ + retBase.description();
+ err << msg << std::endl;
+ LOG(ERROR) << msg;
+ return TRANSACTION_ERROR;
+ }
- sp<IBase> base;
- if (!retBase.isOk() || (base = retBase) == nullptr) {
- mErr << interfaceName << "/" << instanceName << " does not exist." << std::endl;
- return;
+ sp<IBase> base = retBase;
+ if (base == nullptr) {
+ std::string msg = interfaceName + "/" + instanceName + " does not exist, or "
+ + "no permission to connect.";
+ err << msg << std::endl;
+ LOG(ERROR) << msg;
+ return NO_INTERFACE;
}
PipeRelay relay(out);
if (relay.initCheck() != OK) {
- mErr << "PipeRelay::initCheck() FAILED w/ " << relay.initCheck() << std::endl;
- return;
+ std::string msg = "PipeRelay::initCheck() FAILED w/ " + std::to_string(relay.initCheck());
+ err << msg << std::endl;
+ LOG(ERROR) << msg;
+ return IO_ERROR;
}
deleted_unique_ptr<native_handle_t> fdHandle(
hardware::Return<void> ret = base->debug(fdHandle.get(), convert(options));
if (!ret.isOk()) {
- LOG(ERROR)
- << interfaceName
- << "::debug(...) FAILED. (instance "
- << instanceName
- << ")";
+ std::string msg = "debug() FAILED on " + interfaceName + "/" + instanceName + ": "
+ + ret.description();
+ err << msg << std::endl;
+ LOG(ERROR) << msg;
+ return TRANSACTION_ERROR;
}
+ return OK;
}
Status Lshal::parseArgs(const Arg &arg) {
return ListCommand{*this}.main(mCommand, arg);
}
if (mCommand == "debug") {
- // TODO(b/37725279) implement this
- return OK;
+ return DebugCommand{*this}.main(mCommand, arg);
}
usage();
return USAGE;