diff options
-rw-r--r-- | cmds/dumpsys/dumpsys.cpp | 19 | ||||
-rw-r--r-- | cmds/dumpsys/dumpsys.h | 7 | ||||
-rw-r--r-- | cmds/dumpsys/tests/dumpsys_test.cpp | 21 | ||||
-rw-r--r-- | libs/binder/Stability.cpp | 4 | ||||
-rw-r--r-- | libs/binder/include/binder/Stability.h | 2 | ||||
-rw-r--r-- | libs/binder/tests/binderStabilityTest.cpp | 2 | ||||
-rw-r--r-- | libs/binder/tests/unit_fuzzers/StabilityFuzzFunctions.h | 14 |
7 files changed, 47 insertions, 22 deletions
diff --git a/cmds/dumpsys/dumpsys.cpp b/cmds/dumpsys/dumpsys.cpp index ba1c449dbf..83a52b85a3 100644 --- a/cmds/dumpsys/dumpsys.cpp +++ b/cmds/dumpsys/dumpsys.cpp @@ -24,6 +24,7 @@ #include <android-base/unique_fd.h> #include <binder/Parcel.h> #include <binder/ProcessState.h> +#include <binder/Stability.h> #include <binder/TextOutput.h> #include <binderdebug/BinderDebug.h> #include <serviceutils/PriorityDumper.h> @@ -69,12 +70,13 @@ static void usage() { " -t TIMEOUT_SEC: TIMEOUT to use in seconds instead of default 10 seconds\n" " -T TIMEOUT_MS: TIMEOUT to use in milliseconds instead of default 10 seconds\n" " --pid: dump PID instead of usual dump\n" - " --thread: dump thread usage instead of usual dump\n" " --proto: filter services that support dumping data in proto format. Dumps\n" " will be in proto format.\n" " --priority LEVEL: filter services based on specified priority\n" " LEVEL must be one of CRITICAL | HIGH | NORMAL\n" " --skip SERVICES: dumps all services but SERVICES (comma-separated list)\n" + " --stability: dump binder stability information instead of usual dump\n" + " --thread: dump thread usage instead of usual dump\n" " SERVICE [ARGS]: dumps only service SERVICE, optionally passing ARGS to it\n"); } @@ -128,12 +130,13 @@ int Dumpsys::main(int argc, char* const argv[]) { Type type = Type::DUMP; int timeoutArgMs = 10000; int priorityFlags = IServiceManager::DUMP_FLAG_PRIORITY_ALL; - static struct option longOptions[] = {{"thread", no_argument, 0, 0}, + static struct option longOptions[] = {{"help", no_argument, 0, 0}, {"pid", no_argument, 0, 0}, {"priority", required_argument, 0, 0}, {"proto", no_argument, 0, 0}, {"skip", no_argument, 0, 0}, - {"help", no_argument, 0, 0}, + {"stability", no_argument, 0, 0}, + {"thread", no_argument, 0, 0}, {0, 0, 0, 0}}; // Must reset optind, otherwise subsequent calls will fail (wouldn't happen on main.cpp, but @@ -167,6 +170,8 @@ int Dumpsys::main(int argc, char* const argv[]) { } } else if (!strcmp(longOptions[optionIndex].name, "pid")) { type = Type::PID; + } else if (!strcmp(longOptions[optionIndex].name, "stability")) { + type = Type::STABILITY; } else if (!strcmp(longOptions[optionIndex].name, "thread")) { type = Type::THREAD; } @@ -335,6 +340,11 @@ static status_t dumpPidToFd(const sp<IBinder>& service, const unique_fd& fd) { return OK; } +static status_t dumpStabilityToFd(const sp<IBinder>& service, const unique_fd& fd) { + WriteStringToFd(internal::Stability::debugToString(service) + "\n", fd); + return OK; +} + static status_t dumpThreadsToFd(const sp<IBinder>& service, const unique_fd& fd) { pid_t pid; status_t status = service->getDebugPid(&pid); @@ -382,6 +392,9 @@ status_t Dumpsys::startDumpThread(Type type, const String16& serviceName, case Type::PID: err = dumpPidToFd(service, remote_end); break; + case Type::STABILITY: + err = dumpStabilityToFd(service, remote_end); + break; case Type::THREAD: err = dumpThreadsToFd(service, remote_end); break; diff --git a/cmds/dumpsys/dumpsys.h b/cmds/dumpsys/dumpsys.h index 349947ce12..1b3ae6a81c 100644 --- a/cmds/dumpsys/dumpsys.h +++ b/cmds/dumpsys/dumpsys.h @@ -52,9 +52,10 @@ class Dumpsys { static void setServiceArgs(Vector<String16>& args, bool asProto, int priorityFlags); enum class Type { - DUMP, // dump using `dump` function - PID, // dump pid of server only - THREAD, // dump thread usage of server only + DUMP, // dump using `dump` function + PID, // dump pid of server only + STABILITY, // dump stability information of server + THREAD, // dump thread usage of server only }; /** diff --git a/cmds/dumpsys/tests/dumpsys_test.cpp b/cmds/dumpsys/tests/dumpsys_test.cpp index c9d2dbb883..277f445931 100644 --- a/cmds/dumpsys/tests/dumpsys_test.cpp +++ b/cmds/dumpsys/tests/dumpsys_test.cpp @@ -582,6 +582,27 @@ TEST_F(DumpsysTest, ListServiceWithPid) { AssertOutput(std::to_string(getpid()) + "\n"); } +// Tests 'dumpsys --stability' +TEST_F(DumpsysTest, ListAllServicesWithStability) { + ExpectListServices({"Locksmith", "Valet"}); + ExpectCheckService("Locksmith"); + ExpectCheckService("Valet"); + + CallMain({"--stability"}); + + AssertRunningServices({"Locksmith", "Valet"}); + AssertOutputContains("stability"); +} + +// Tests 'dumpsys --stability service_name' +TEST_F(DumpsysTest, ListServiceWithStability) { + ExpectCheckService("Locksmith"); + + CallMain({"--stability", "Locksmith"}); + + AssertOutputContains("stability"); +} + // Tests 'dumpsys --thread' TEST_F(DumpsysTest, ListAllServicesWithThread) { ExpectListServices({"Locksmith", "Valet"}); diff --git a/libs/binder/Stability.cpp b/libs/binder/Stability.cpp index 709cf67127..601ce96db6 100644 --- a/libs/binder/Stability.cpp +++ b/libs/binder/Stability.cpp @@ -79,9 +79,9 @@ void Stability::markVintf(IBinder* binder) { LOG_ALWAYS_FATAL_IF(result != OK, "Should only mark known object."); } -void Stability::debugLogStability(const std::string& tag, const sp<IBinder>& binder) { +std::string Stability::debugToString(const sp<IBinder>& binder) { auto stability = getCategory(binder.get()); - ALOGE("%s: stability is %s", tag.c_str(), stability.debugString().c_str()); + return stability.debugString(); } void Stability::markVndk(IBinder* binder) { diff --git a/libs/binder/include/binder/Stability.h b/libs/binder/include/binder/Stability.h index f4bfac890a..6bc607f298 100644 --- a/libs/binder/include/binder/Stability.h +++ b/libs/binder/include/binder/Stability.h @@ -100,7 +100,7 @@ public: static void markVintf(IBinder* binder); // WARNING: for debugging only - static void debugLogStability(const std::string& tag, const sp<IBinder>& binder); + static std::string debugToString(const sp<IBinder>& binder); // WARNING: This is only ever expected to be called by auto-generated code or tests. // You likely want to change or modify the stability of the interface you are using. diff --git a/libs/binder/tests/binderStabilityTest.cpp b/libs/binder/tests/binderStabilityTest.cpp index 2ce13df4b3..6c3b3d9087 100644 --- a/libs/binder/tests/binderStabilityTest.cpp +++ b/libs/binder/tests/binderStabilityTest.cpp @@ -102,7 +102,7 @@ public: return Status::ok(); } Status sendAndCallBinder(const sp<IBinder>& binder) override { - Stability::debugLogStability("sendAndCallBinder got binder", binder); + ALOGI("Debug log stability: %s", Stability::debugToString(binder).c_str()); return Status::fromExceptionCode(BadStableBinder::doUserTransaction(binder)); } Status returnNoStabilityBinder(sp<IBinder>* _aidl_return) override { diff --git a/libs/binder/tests/unit_fuzzers/StabilityFuzzFunctions.h b/libs/binder/tests/unit_fuzzers/StabilityFuzzFunctions.h index 8b4ed702af..371dcbd4bb 100644 --- a/libs/binder/tests/unit_fuzzers/StabilityFuzzFunctions.h +++ b/libs/binder/tests/unit_fuzzers/StabilityFuzzFunctions.h @@ -31,37 +31,27 @@ static bool marked = false; static const std::vector< std::function<void(FuzzedDataProvider*, android::sp<android::IBinder> const&)>> gStabilityOperations = { - // markCompilationUnit(IBinder* binder) [](FuzzedDataProvider*, android::sp<android::IBinder> const& bbinder) -> void { if (!marked) { android::internal::Stability::markCompilationUnit(bbinder.get()); marked = true; } }, - - // markVintf(IBinder* binder) [](FuzzedDataProvider*, android::sp<android::IBinder> const& bbinder) -> void { if (!marked) { android::internal::Stability::markVintf(bbinder.get()); marked = true; } }, - - // debugLogStability(const std::string& tag, const sp<IBinder>& binder) - [](FuzzedDataProvider* fdp, android::sp<android::IBinder> const& bbinder) -> void { - std::string tag = fdp->ConsumeRandomLengthString(STABILITY_MAX_TAG_LENGTH); - android::internal::Stability::debugLogStability(tag, bbinder); + [](FuzzedDataProvider*, android::sp<android::IBinder> const& bbinder) -> void { + (void)android::internal::Stability::debugToString(bbinder); }, - - // markVndk(IBinder* binder) [](FuzzedDataProvider*, android::sp<android::IBinder> const& bbinder) -> void { if (!marked) { android::internal::Stability::markVndk(bbinder.get()); marked = true; } }, - - // requiresVintfDeclaration(const sp<IBinder>& binder) [](FuzzedDataProvider*, android::sp<android::IBinder> const& bbinder) -> void { android::internal::Stability::requiresVintfDeclaration(bbinder); }}; |