dump_modemlog: move android_property_manager
android_property_manager is moved to its own folder in the root of the
modem folder. This is so that libeomservice proxy has a specific build
target to include.
Test: build, flash, check modem logs in bugreport
Bug: 302435001
Change-Id: Ifc4a0c888717f5c28cf9b642d0b978b495be29d0
diff --git a/modem/dump_modemlog/Android.bp b/modem/dump_modemlog/Android.bp
index b264609..cad6e49 100644
--- a/modem/dump_modemlog/Android.bp
+++ b/modem/dump_modemlog/Android.bp
@@ -1,5 +1,5 @@
package {
- default_applicable_licenses: ["Android-Apache-2.0"],
+ default_applicable_licenses: [ "Android-Apache-2.0" ],
}
sh_binary {
@@ -9,16 +9,38 @@
sub_dir: "dump",
}
+// Modem Log Dumper
+
+modem_log_dumper_public_deps = [
+ "modem_android_property_manager",
+]
+
+// When `modem_log_dumper` is included statically, its dependencies are not
+// transitively included, so the target will also have to include this default
+// to restate them.
cc_defaults {
- name: "dump_modemlog_defaults",
- srcs: [ "modem_log_dumper.cpp" ],
- local_include_dirs: [ "include" ],
- shared_libs: [ "liblog" ],
+ name: "modem_log_dumper_defaults",
+ shared_libs: modem_log_dumper_public_deps + [
+ "libbase",
+ // liblog is not directly used by us, but it's a transitive dependency of libbase
+ "liblog",
+ ],
}
+cc_library {
+ name: "modem_log_dumper",
+ srcs: [ "modem_log_dumper.cpp" ],
+ defaults: [ "modem_log_dumper_defaults" ],
+ export_shared_lib_headers: modem_log_dumper_public_deps,
+ export_include_dirs: [ "include" ],
+ vendor_available: true,
+}
+
+// dump_modemlog
+
cc_binary {
name: "dump_modemlog",
- srcs: ["dump_modemlog.cpp"],
+ srcs: [ "dump_modemlog.cpp" ],
cflags: [
"-Wall",
"-Wextra",
@@ -28,17 +50,27 @@
"libbase",
"libdump",
"liblog",
+ "modem_android_property_manager_impl",
+ "modem_log_dumper",
],
- defaults: [ "dump_modemlog_defaults" ],
vendor: true,
relative_install_path: "dump",
}
cc_test {
name: "dump_modemlog_test",
- srcs: [ "*_test.cpp" ],
- defaults: [ "dump_modemlog_defaults" ],
- local_include_dirs: [ "test/include" ],
- static_libs: [ "libgmock" ],
+ srcs: [ "modem_log_dumper_test.cpp" ],
+ defaults: [
+ "modem_log_dumper_defaults",
+ "modem_android_property_manager_fake_defaults",
+ ],
+ static_libs: [
+ "modem_log_dumper",
+ "modem_android_property_manager_fake",
+ "libgmock",
+ ],
vendor: true,
+ // Shared libs in vendor folder are guarded by SEPolicy, so tests need root
+ // access to run them.
+ require_root: true,
}
diff --git a/modem/dump_modemlog/dump_modemlog.cpp b/modem/dump_modemlog/dump_modemlog.cpp
index 47181cb..bed936c 100644
--- a/modem/dump_modemlog/dump_modemlog.cpp
+++ b/modem/dump_modemlog/dump_modemlog.cpp
@@ -16,34 +16,13 @@
#include <android-base/properties.h>
#include <dump/pixel_dump.h>
+#include "android_property_manager_impl.h"
#include "dumper.h"
#include "modem_log_dumper.h"
namespace pixel_modem::logging {
/**
- * @brief Implementation of AndroidPropertyManager that directly forwards to
- * android base methods.
- */
-class AndroidPropertyManagerImpl : public AndroidPropertyManager {
- public:
- bool GetBoolProperty(const std::string& key, bool default_value) override {
- return android::base::GetBoolProperty(key, default_value);
- };
-
- std::string GetProperty(const std::string& key,
- const std::string& default_value) override {
- return android::base::GetProperty(key, default_value);
- };
- int GetIntProperty(const std::string& key, int default_value) override {
- return android::base::GetIntProperty(key, default_value);
- };
- void SetProperty(const std::string& key, const std::string& value) override {
- android::base::SetProperty(key, value);
- };
-};
-
-/**
* @brief Implementation of Dumper that directly forwards to their corresponding
* dumpstate methods.
*/
@@ -62,8 +41,7 @@
int main() {
pixel_modem::logging::DumperImpl dumper_impl;
- pixel_modem::logging::AndroidPropertyManagerImpl
- android_property_manager_impl;
+ pixel_modem::AndroidPropertyManagerImpl android_property_manager_impl;
pixel_modem::logging::ModemLogDumper modem_log_dumper(
dumper_impl, android_property_manager_impl);
diff --git a/modem/dump_modemlog/include/android_property_manager.h b/modem/dump_modemlog/include/android_property_manager.h
deleted file mode 100644
index eb426c3..0000000
--- a/modem/dump_modemlog/include/android_property_manager.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#pragma once
-
-#include <string>
-
-namespace pixel_modem::logging {
-
-/**
- * @brief Interface for interacting with Android System Properties.
- */
-class AndroidPropertyManager {
- public:
- virtual ~AndroidPropertyManager() = default;
- virtual bool GetBoolProperty(const std::string& key, bool default_value);
- virtual std::string GetProperty(const std::string& key,
- const std::string& default_value);
- virtual int GetIntProperty(const std::string& key, int default_value);
- virtual void SetProperty(const std::string& key, const std::string& value);
-};
-
-} // namespace pixel_modem::logging
diff --git a/modem/dump_modemlog/test/include/fake_android_property_manager.h b/modem/dump_modemlog/test/include/fake_android_property_manager.h
deleted file mode 100644
index 0d5731a..0000000
--- a/modem/dump_modemlog/test/include/fake_android_property_manager.h
+++ /dev/null
@@ -1,75 +0,0 @@
-
-
-#include <map>
-#include <string>
-#include <string_view>
-
-#include "android_property_manager.h"
-#include "modem_log_constants.h"
-
-namespace pixel_modem::logging {
-
-/**
- * @brief Fake Implementation of AndroidPropertyManager that mocks some of the
- * property changing behaviour from pixellogger's `modem_logging_control`.
- */
-class FakeAndroidPropertyManager : public AndroidPropertyManager {
- public:
- inline constexpr static std::string_view kTruthString = "true";
- inline constexpr static std::string_view kFalseString = "false";
-
- bool GetBoolProperty(const std::string& key, bool default_value) override {
- return MapContainsKey(key) ? GetPropertyInternal(key) == kTruthString
- : default_value;
- };
-
- std::string GetProperty(const std::string& key,
- const std::string& default_value) override {
- return MapContainsKey(key) ? GetPropertyInternal(key) : default_value;
- ;
- };
-
- int GetIntProperty(const std::string& key, int default_value) override {
- return MapContainsKey(key) ? std::stoi(GetPropertyInternal(key))
- : default_value;
- };
-
- /**
- * This function needs to copy the behaviour of `modem_logging_control` to
- * ensure that the right properties are being set in order.
- *
- * More specifically, this function will also set the
- * `kModemLoggingStatusProperty` whenever `kModemLoggingEnabledProperty` is
- * set to simulate modem logging stopping / starting.
- */
- void SetProperty(const std::string& key, const std::string& value) override {
- if (key == kModemLoggingEnabledProperty) {
- property_map_[kModemLoggingStatusProperty.data()] = value;
-
- // need to track if modem logging has restarted or not
- if (value == kFalseString) {
- modem_logging_has_been_off_ = true;
- }
- if (modem_logging_has_been_off_ && (value == kTruthString)) {
- modem_logging_has_restarted_ = true;
- }
- }
- property_map_[key] = value;
- };
-
- bool ModemLoggingHasRestarted() { return modem_logging_has_restarted_; }
-
- private:
- bool MapContainsKey(const std::string& key) {
- return property_map_.find(key) != property_map_.end();
- }
- std::string GetPropertyInternal(const std::string& key) {
- return property_map_.find(key)->second;
- }
-
- std::map<std::string, std::string> property_map_;
- bool modem_logging_has_been_off_ = false;
- bool modem_logging_has_restarted_ = false;
-};
-
-} // namespace pixel_modem::logging