2017-05-10 03:49:45 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2019-06-25 17:54:34 +02:00
|
|
|
#pragma once
|
2017-05-10 03:49:45 +02:00
|
|
|
|
2017-09-14 01:53:37 +02:00
|
|
|
#include <getopt.h>
|
2017-05-10 03:49:45 +02:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <android-base/macros.h>
|
|
|
|
#include <android/hidl/manager/1.0/IServiceManager.h>
|
2020-12-12 00:11:17 +01:00
|
|
|
#include <binderdebug/BinderDebug.h>
|
2018-05-02 00:25:23 +02:00
|
|
|
#include <hidl-util/FqInstance.h>
|
|
|
|
#include <vintf/HalManifest.h>
|
2018-05-25 23:20:00 +02:00
|
|
|
#include <vintf/VintfObject.h>
|
2017-05-10 03:49:45 +02:00
|
|
|
|
2017-09-07 22:54:28 +02:00
|
|
|
#include "Command.h"
|
2017-05-10 03:49:45 +02:00
|
|
|
#include "NullableOStream.h"
|
|
|
|
#include "TableEntry.h"
|
2017-08-30 02:28:12 +02:00
|
|
|
#include "TextTable.h"
|
2017-05-10 03:49:45 +02:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
namespace android {
|
|
|
|
namespace lshal {
|
|
|
|
|
|
|
|
class Lshal;
|
|
|
|
|
2018-05-16 20:14:46 +02:00
|
|
|
enum class HalType {
|
|
|
|
BINDERIZED_SERVICES = 0,
|
|
|
|
PASSTHROUGH_CLIENTS,
|
2018-06-26 01:15:56 +02:00
|
|
|
PASSTHROUGH_LIBRARIES,
|
|
|
|
VINTF_MANIFEST,
|
2018-06-28 21:39:50 +02:00
|
|
|
LAZY_HALS,
|
2020-08-08 03:24:06 +02:00
|
|
|
|
|
|
|
// Not a real HalType. Used to determine all HalTypes.
|
|
|
|
LAST,
|
2018-05-16 20:14:46 +02:00
|
|
|
};
|
|
|
|
|
2017-09-07 22:54:28 +02:00
|
|
|
class ListCommand : public Command {
|
2017-05-10 03:49:45 +02:00
|
|
|
public:
|
2018-12-21 00:47:01 +01:00
|
|
|
explicit ListCommand(Lshal &lshal) : Command(lshal) {}
|
2017-09-08 03:06:13 +02:00
|
|
|
virtual ~ListCommand() = default;
|
2017-09-09 03:00:31 +02:00
|
|
|
Status main(const Arg &arg) override;
|
|
|
|
void usage() const override;
|
2017-09-13 20:25:28 +02:00
|
|
|
std::string getSimpleDescription() const override;
|
|
|
|
std::string getName() const override { return GetName(); }
|
|
|
|
|
|
|
|
static std::string GetName();
|
2017-09-14 01:53:37 +02:00
|
|
|
|
|
|
|
struct RegisteredOption {
|
|
|
|
// short alternative, e.g. 'v'. If '\0', no short options is available.
|
|
|
|
char shortOption;
|
|
|
|
// long alternative, e.g. 'init-vintf'
|
|
|
|
std::string longOption;
|
|
|
|
// no_argument, required_argument or optional_argument
|
|
|
|
int hasArg;
|
|
|
|
// value written to 'flag' by getopt_long
|
|
|
|
int val;
|
|
|
|
// operation when the argument is present
|
|
|
|
std::function<Status(ListCommand* thiz, const char* arg)> op;
|
|
|
|
// help message
|
|
|
|
std::string help;
|
|
|
|
|
|
|
|
const std::string& getHelpMessageForArgument() const;
|
|
|
|
};
|
|
|
|
// A list of acceptable command line options
|
|
|
|
// key: value returned by getopt_long
|
|
|
|
using RegisteredOptions = std::vector<RegisteredOption>;
|
|
|
|
|
2018-02-03 00:17:51 +01:00
|
|
|
static std::string INIT_VINTF_NOTES;
|
|
|
|
|
2017-09-08 00:08:22 +02:00
|
|
|
protected:
|
2017-09-09 03:00:31 +02:00
|
|
|
Status parseArgs(const Arg &arg);
|
2018-05-25 23:20:00 +02:00
|
|
|
// Retrieve first-hand information
|
2017-05-10 03:49:45 +02:00
|
|
|
Status fetch();
|
2018-05-25 23:20:00 +02:00
|
|
|
// Retrieve derived information base on existing table
|
2017-09-15 01:02:52 +02:00
|
|
|
virtual void postprocess();
|
2017-09-08 01:44:27 +02:00
|
|
|
Status dump();
|
2018-06-26 01:21:29 +02:00
|
|
|
void putEntry(HalType type, TableEntry &&entry);
|
2017-05-10 03:49:45 +02:00
|
|
|
Status fetchPassthrough(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
|
|
|
|
Status fetchBinderized(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
|
|
|
|
Status fetchAllLibraries(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager);
|
2018-06-26 01:15:56 +02:00
|
|
|
Status fetchManifestHals();
|
2018-06-28 21:39:50 +02:00
|
|
|
Status fetchLazyHals();
|
2017-05-24 20:23:08 +02:00
|
|
|
|
2017-09-15 03:07:43 +02:00
|
|
|
Status fetchBinderizedEntry(const sp<::android::hidl::manager::V1_0::IServiceManager> &manager,
|
|
|
|
TableEntry *entry);
|
|
|
|
|
2020-02-25 21:27:14 +01:00
|
|
|
// Get relevant information for a PID by parsing files under
|
|
|
|
// /dev/binderfs/binder_logs or /d/binder.
|
2017-09-15 02:49:30 +02:00
|
|
|
// It is a virtual member function so that it can be mocked.
|
2020-12-12 00:11:17 +01:00
|
|
|
virtual bool getPidInfo(pid_t serverPid, BinderPidInfo *info) const;
|
2017-09-15 02:49:30 +02:00
|
|
|
// Retrieve from mCachedPidInfos and call getPidInfo if necessary.
|
2020-12-12 00:11:17 +01:00
|
|
|
const BinderPidInfo* getPidInfoCached(pid_t serverPid);
|
2017-05-24 20:23:08 +02:00
|
|
|
|
2017-09-08 01:44:27 +02:00
|
|
|
void dumpTable(const NullableOStream<std::ostream>& out) const;
|
|
|
|
void dumpVintf(const NullableOStream<std::ostream>& out) const;
|
2017-08-30 02:28:12 +02:00
|
|
|
void addLine(TextTable *table, const std::string &interfaceName, const std::string &transport,
|
|
|
|
const std::string &arch, const std::string &threadUsage, const std::string &server,
|
|
|
|
const std::string &serverCmdline, const std::string &address,
|
|
|
|
const std::string &clients, const std::string &clientCmdlines) const;
|
|
|
|
void addLine(TextTable *table, const TableEntry &entry);
|
2017-09-08 03:06:13 +02:00
|
|
|
// Read and return /proc/{pid}/cmdline.
|
|
|
|
virtual std::string parseCmdline(pid_t pid) const;
|
2017-05-10 03:49:45 +02:00
|
|
|
// Return /proc/{pid}/cmdline if it exists, else empty string.
|
2018-02-03 00:17:51 +01:00
|
|
|
const std::string& getCmdline(pid_t pid);
|
2017-05-10 03:49:45 +02:00
|
|
|
// Call getCmdline on all pid in pids. If it returns empty string, the process might
|
|
|
|
// have died, and the pid is removed from pids.
|
|
|
|
void removeDeadProcesses(Pids *pids);
|
2018-02-03 00:17:51 +01:00
|
|
|
|
|
|
|
virtual Partition getPartition(pid_t pid);
|
2018-05-02 00:25:23 +02:00
|
|
|
Partition resolvePartition(Partition processPartition, const FqInstance &fqInstance) const;
|
2018-02-03 00:17:51 +01:00
|
|
|
|
2018-05-25 23:20:00 +02:00
|
|
|
VintfInfo getVintfInfo(const std::string &fqInstanceName, vintf::TransportArch ta) const;
|
|
|
|
// Allow to mock these functions for testing.
|
|
|
|
virtual std::shared_ptr<const vintf::HalManifest> getDeviceManifest() const;
|
|
|
|
virtual std::shared_ptr<const vintf::CompatibilityMatrix> getDeviceMatrix() const;
|
|
|
|
virtual std::shared_ptr<const vintf::HalManifest> getFrameworkManifest() const;
|
|
|
|
virtual std::shared_ptr<const vintf::CompatibilityMatrix> getFrameworkMatrix() const;
|
|
|
|
|
2017-05-10 03:49:45 +02:00
|
|
|
void forEachTable(const std::function<void(Table &)> &f);
|
|
|
|
void forEachTable(const std::function<void(const Table &)> &f) const;
|
2018-06-26 01:32:01 +02:00
|
|
|
Table* tableForType(HalType type);
|
|
|
|
const Table* tableForType(HalType type) const;
|
2017-05-10 03:49:45 +02:00
|
|
|
|
2017-09-08 23:59:04 +02:00
|
|
|
NullableOStream<std::ostream> err() const;
|
|
|
|
NullableOStream<std::ostream> out() const;
|
|
|
|
|
2017-09-14 01:53:37 +02:00
|
|
|
void registerAllOptions();
|
|
|
|
|
2018-05-02 00:25:23 +02:00
|
|
|
// helper functions to dumpVintf.
|
|
|
|
bool addEntryWithInstance(const TableEntry &entry, vintf::HalManifest *manifest) const;
|
|
|
|
bool addEntryWithoutInstance(const TableEntry &entry, const vintf::HalManifest *manifest) const;
|
|
|
|
|
2018-06-26 01:15:56 +02:00
|
|
|
// Helper function. Whether to fetch entries corresponding to a given HAL type.
|
|
|
|
bool shouldFetchHalType(const HalType &type) const;
|
|
|
|
|
|
|
|
void initFetchTypes();
|
2018-05-16 20:14:46 +02:00
|
|
|
|
2018-06-28 21:39:50 +02:00
|
|
|
// Helper functions ti add HALs that are listed in VINTF manifest to LAZY_HALS table.
|
|
|
|
bool hasHwbinderEntry(const TableEntry& entry) const;
|
|
|
|
bool hasPassthroughEntry(const TableEntry& entry) const;
|
|
|
|
|
2017-05-10 03:49:45 +02:00
|
|
|
Table mServicesTable{};
|
|
|
|
Table mPassthroughRefTable{};
|
|
|
|
Table mImplementationsTable{};
|
2018-06-26 01:15:56 +02:00
|
|
|
Table mManifestHalsTable{};
|
2018-06-28 21:39:50 +02:00
|
|
|
Table mLazyHalsTable{};
|
2017-05-10 03:49:45 +02:00
|
|
|
|
2017-09-08 01:44:27 +02:00
|
|
|
std::string mFileOutputPath;
|
2017-05-10 03:49:45 +02:00
|
|
|
TableEntryCompare mSortColumn = nullptr;
|
|
|
|
|
|
|
|
bool mEmitDebugInfo = false;
|
|
|
|
|
2018-02-03 00:17:51 +01:00
|
|
|
// If true, output in VINTF format. Output only entries from the specified partition.
|
2017-05-10 03:49:45 +02:00
|
|
|
bool mVintf = false;
|
2018-02-03 00:17:51 +01:00
|
|
|
Partition mVintfPartition = Partition::UNKNOWN;
|
2017-05-13 01:56:43 +02:00
|
|
|
|
|
|
|
// If true, explanatory text are not emitted.
|
|
|
|
bool mNeat = false;
|
|
|
|
|
2018-06-26 01:15:56 +02:00
|
|
|
// Type(s) of HAL associations to list.
|
|
|
|
std::vector<HalType> mListTypes{};
|
|
|
|
// Type(s) of HAL associations to fetch.
|
|
|
|
std::set<HalType> mFetchTypes{};
|
2018-05-16 20:14:46 +02:00
|
|
|
|
2017-05-10 03:49:45 +02:00
|
|
|
// If an entry does not exist, need to ask /proc/{pid}/cmdline to get it.
|
|
|
|
// If an entry exist but is an empty string, process might have died.
|
|
|
|
// If an entry exist and not empty, it contains the cached content of /proc/{pid}/cmdline.
|
|
|
|
std::map<pid_t, std::string> mCmdlines;
|
|
|
|
|
2017-09-15 02:49:30 +02:00
|
|
|
// Cache for getPidInfo.
|
2020-12-12 00:11:17 +01:00
|
|
|
std::map<pid_t, BinderPidInfo> mCachedPidInfos;
|
2017-09-15 02:49:30 +02:00
|
|
|
|
2018-02-03 00:17:51 +01:00
|
|
|
// Cache for getPartition.
|
|
|
|
std::map<pid_t, Partition> mPartitions;
|
|
|
|
|
2017-09-14 01:53:37 +02:00
|
|
|
RegisteredOptions mOptions;
|
|
|
|
// All selected columns
|
|
|
|
std::vector<TableColumnType> mSelectedColumns;
|
|
|
|
// If true, emit cmdlines instead of PIDs
|
|
|
|
bool mEnableCmdlines = false;
|
|
|
|
|
2017-09-14 00:44:56 +02:00
|
|
|
private:
|
2017-05-10 03:49:45 +02:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(ListCommand);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lshal
|
|
|
|
} // namespace android
|