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
This commit is contained in:
parent
3ed60cec02
commit
047f0aca49
11 changed files with 296 additions and 116 deletions
9
modem/android_property_manager/Android.bp
Normal file
9
modem/android_property_manager/Android.bp
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
package {
|
||||||
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library {
|
||||||
|
name: "modem_android_property_manager",
|
||||||
|
export_include_dirs: [ "include" ],
|
||||||
|
vendor_available: true,
|
||||||
|
}
|
23
modem/android_property_manager/fake/Android.bp
Normal file
23
modem/android_property_manager/fake/Android.bp
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
package {
|
||||||
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
|
}
|
||||||
|
|
||||||
|
// When `modem_android_property_manager_fake` 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: "modem_android_property_manager_fake_defaults",
|
||||||
|
static_libs: [
|
||||||
|
"modem_android_property_manager",
|
||||||
|
"libbase",
|
||||||
|
"modem_log_constants",
|
||||||
|
],
|
||||||
|
}
|
||||||
|
|
||||||
|
cc_library_static {
|
||||||
|
name: "modem_android_property_manager_fake",
|
||||||
|
export_include_dirs: [ "include" ],
|
||||||
|
srcs: [ "fake_android_property_manager.cpp" ],
|
||||||
|
defaults: [ "modem_android_property_manager_fake_defaults" ],
|
||||||
|
vendor_available: true,
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
#include "fake_android_property_manager.h"
|
||||||
|
|
||||||
|
#include <android-base/parseint.h>
|
||||||
|
#include <android-base/result.h>
|
||||||
|
|
||||||
|
#include <cerrno>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "modem_log_constants.h"
|
||||||
|
|
||||||
|
namespace pixel_modem {
|
||||||
|
|
||||||
|
bool FakeAndroidPropertyManager::GetBoolProperty(const std::string& key,
|
||||||
|
bool default_value) {
|
||||||
|
auto value_result = GetProperty(key);
|
||||||
|
return value_result.ok() ? (*value_result) == kTruthString : default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string FakeAndroidPropertyManager::GetProperty(
|
||||||
|
const std::string& key, const std::string& default_value) {
|
||||||
|
auto value_result = GetProperty(key);
|
||||||
|
return value_result.ok() ? *value_result : default_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
int FakeAndroidPropertyManager::GetIntProperty(const std::string& key,
|
||||||
|
int default_value) {
|
||||||
|
int value = default_value;
|
||||||
|
|
||||||
|
auto property_result = GetProperty(key);
|
||||||
|
if (property_result.ok()) {
|
||||||
|
android::base::ParseInt<int>((*property_result).data(), &value);
|
||||||
|
}
|
||||||
|
return 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.
|
||||||
|
*/
|
||||||
|
bool FakeAndroidPropertyManager::SetProperty(const std::string& key,
|
||||||
|
const std::string& value) {
|
||||||
|
if (key == logging::kModemLoggingEnabledProperty) {
|
||||||
|
property_map_[logging::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;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets android system property if present.
|
||||||
|
*
|
||||||
|
* @param[in] key Name of property.
|
||||||
|
*
|
||||||
|
* @return Status of get operation and value if successful.
|
||||||
|
* @retval EINVAL Key not present in map.
|
||||||
|
*/
|
||||||
|
android::base::Result<std::string> FakeAndroidPropertyManager::GetProperty(
|
||||||
|
const std::string& key) {
|
||||||
|
const auto it = property_map_.find(key);
|
||||||
|
if (it == property_map_.end()) {
|
||||||
|
return android::base::Error()
|
||||||
|
<< "Property: " << key << " not found." << EINVAL;
|
||||||
|
}
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace pixel_modem
|
|
@ -0,0 +1,54 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "android-base/result.h"
|
||||||
|
#include "android_property_manager.h"
|
||||||
|
|
||||||
|
namespace pixel_modem {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fake Implementation of AndroidPropertyManager that mocks some of the
|
||||||
|
* property changing behaviour from pixellogger's `modem_logging_control`.
|
||||||
|
*/
|
||||||
|
class FakeAndroidPropertyManager : public AndroidPropertyManager {
|
||||||
|
public:
|
||||||
|
bool GetBoolProperty(const std::string& key, bool default_value) override;
|
||||||
|
|
||||||
|
std::string GetProperty(const std::string& key,
|
||||||
|
const std::string& default_value) override;
|
||||||
|
|
||||||
|
int GetIntProperty(const std::string& key, int default_value) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
bool SetProperty(const std::string& key, const std::string& value) override;
|
||||||
|
|
||||||
|
inline bool ModemLoggingHasRestarted() {
|
||||||
|
return modem_logging_has_restarted_;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
/**
|
||||||
|
* @brief Gets android system property if present.
|
||||||
|
*
|
||||||
|
* @param[in] key Name of property.
|
||||||
|
*
|
||||||
|
* @return Status of get operation and value if successful.
|
||||||
|
* @retval EINVAL Key not present in map.
|
||||||
|
*/
|
||||||
|
android::base::Result<std::string> GetProperty(const std::string& key);
|
||||||
|
|
||||||
|
std::map<std::string, std::string> property_map_;
|
||||||
|
bool modem_logging_has_been_off_ = false;
|
||||||
|
bool modem_logging_has_restarted_ = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pixel_modem
|
18
modem/android_property_manager/impl/Android.bp
Normal file
18
modem/android_property_manager/impl/Android.bp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package {
|
||||||
|
default_applicable_licenses: ["Android-Apache-2.0"],
|
||||||
|
}
|
||||||
|
|
||||||
|
modem_android_property_manager_impl_public_deps = [
|
||||||
|
"modem_android_property_manager",
|
||||||
|
]
|
||||||
|
|
||||||
|
cc_library_shared {
|
||||||
|
name: "modem_android_property_manager_impl",
|
||||||
|
export_include_dirs: [ "include" ],
|
||||||
|
srcs: [ "android_property_manager_impl.cpp" ],
|
||||||
|
shared_libs: modem_android_property_manager_impl_public_deps + [
|
||||||
|
"libbase",
|
||||||
|
],
|
||||||
|
export_shared_lib_headers: modem_android_property_manager_impl_public_deps,
|
||||||
|
vendor_available: true,
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
#include "android_property_manager_impl.h"
|
||||||
|
|
||||||
|
#include <android-base/properties.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace pixel_modem {
|
||||||
|
|
||||||
|
bool AndroidPropertyManagerImpl::GetBoolProperty(const std::string& key,
|
||||||
|
bool default_value) {
|
||||||
|
return android::base::GetBoolProperty(key, default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AndroidPropertyManagerImpl::GetProperty(
|
||||||
|
const std::string& key, const std::string& default_value) {
|
||||||
|
return android::base::GetProperty(key, default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
int AndroidPropertyManagerImpl::GetIntProperty(const std::string& key,
|
||||||
|
int default_value) {
|
||||||
|
return android::base::GetIntProperty(key, default_value);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AndroidPropertyManagerImpl::SetProperty(const std::string& key,
|
||||||
|
const std::string& value) {
|
||||||
|
return android::base::SetProperty(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace pixel_modem
|
|
@ -0,0 +1,25 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "android_property_manager.h"
|
||||||
|
|
||||||
|
namespace pixel_modem {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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;
|
||||||
|
|
||||||
|
std::string GetProperty(const std::string& key,
|
||||||
|
const std::string& default_value) override;
|
||||||
|
|
||||||
|
int GetIntProperty(const std::string& key, int default_value) override;
|
||||||
|
|
||||||
|
bool SetProperty(const std::string& key, const std::string& value) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace pixel_modem
|
|
@ -1,8 +1,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
namespace pixel_modem::logging {
|
namespace pixel_modem {
|
||||||
|
|
||||||
|
// Used to set boolean parameters to true / false
|
||||||
|
inline constexpr std::string_view kTruthString = "true";
|
||||||
|
inline constexpr std::string_view kFalseString = "false";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Interface for interacting with Android System Properties.
|
* @brief Interface for interacting with Android System Properties.
|
||||||
|
@ -10,11 +16,12 @@ namespace pixel_modem::logging {
|
||||||
class AndroidPropertyManager {
|
class AndroidPropertyManager {
|
||||||
public:
|
public:
|
||||||
virtual ~AndroidPropertyManager() = default;
|
virtual ~AndroidPropertyManager() = default;
|
||||||
virtual bool GetBoolProperty(const std::string& key, bool default_value);
|
virtual bool GetBoolProperty(const std::string& key, bool default_value) = 0;
|
||||||
virtual std::string GetProperty(const std::string& key,
|
virtual std::string GetProperty(const std::string& key,
|
||||||
const std::string& default_value);
|
const std::string& default_value) = 0;
|
||||||
virtual int GetIntProperty(const std::string& key, int default_value);
|
virtual int GetIntProperty(const std::string& key, int default_value) = 0;
|
||||||
virtual void SetProperty(const std::string& key, const std::string& value);
|
virtual bool SetProperty(const std::string& key,
|
||||||
|
const std::string& value) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace pixel_modem::logging
|
} // namespace pixel_modem
|
|
@ -1,5 +1,5 @@
|
||||||
package {
|
package {
|
||||||
default_applicable_licenses: ["Android-Apache-2.0"],
|
default_applicable_licenses: [ "Android-Apache-2.0" ],
|
||||||
}
|
}
|
||||||
|
|
||||||
sh_binary {
|
sh_binary {
|
||||||
|
@ -9,16 +9,38 @@ sh_binary {
|
||||||
sub_dir: "dump",
|
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 {
|
cc_defaults {
|
||||||
name: "dump_modemlog_defaults",
|
name: "modem_log_dumper_defaults",
|
||||||
srcs: [ "modem_log_dumper.cpp" ],
|
shared_libs: modem_log_dumper_public_deps + [
|
||||||
local_include_dirs: [ "include" ],
|
"libbase",
|
||||||
shared_libs: [ "liblog" ],
|
// 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 {
|
cc_binary {
|
||||||
name: "dump_modemlog",
|
name: "dump_modemlog",
|
||||||
srcs: ["dump_modemlog.cpp"],
|
srcs: [ "dump_modemlog.cpp" ],
|
||||||
cflags: [
|
cflags: [
|
||||||
"-Wall",
|
"-Wall",
|
||||||
"-Wextra",
|
"-Wextra",
|
||||||
|
@ -28,17 +50,27 @@ cc_binary {
|
||||||
"libbase",
|
"libbase",
|
||||||
"libdump",
|
"libdump",
|
||||||
"liblog",
|
"liblog",
|
||||||
|
"modem_android_property_manager_impl",
|
||||||
|
"modem_log_dumper",
|
||||||
],
|
],
|
||||||
defaults: [ "dump_modemlog_defaults" ],
|
|
||||||
vendor: true,
|
vendor: true,
|
||||||
relative_install_path: "dump",
|
relative_install_path: "dump",
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_test {
|
cc_test {
|
||||||
name: "dump_modemlog_test",
|
name: "dump_modemlog_test",
|
||||||
srcs: [ "*_test.cpp" ],
|
srcs: [ "modem_log_dumper_test.cpp" ],
|
||||||
defaults: [ "dump_modemlog_defaults" ],
|
defaults: [
|
||||||
local_include_dirs: [ "test/include" ],
|
"modem_log_dumper_defaults",
|
||||||
static_libs: [ "libgmock" ],
|
"modem_android_property_manager_fake_defaults",
|
||||||
|
],
|
||||||
|
static_libs: [
|
||||||
|
"modem_log_dumper",
|
||||||
|
"modem_android_property_manager_fake",
|
||||||
|
"libgmock",
|
||||||
|
],
|
||||||
vendor: true,
|
vendor: true,
|
||||||
|
// Shared libs in vendor folder are guarded by SEPolicy, so tests need root
|
||||||
|
// access to run them.
|
||||||
|
require_root: true,
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,33 +16,12 @@
|
||||||
#include <android-base/properties.h>
|
#include <android-base/properties.h>
|
||||||
#include <dump/pixel_dump.h>
|
#include <dump/pixel_dump.h>
|
||||||
|
|
||||||
|
#include "android_property_manager_impl.h"
|
||||||
#include "dumper.h"
|
#include "dumper.h"
|
||||||
#include "modem_log_dumper.h"
|
#include "modem_log_dumper.h"
|
||||||
|
|
||||||
namespace pixel_modem::logging {
|
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
|
* @brief Implementation of Dumper that directly forwards to their corresponding
|
||||||
* dumpstate methods.
|
* dumpstate methods.
|
||||||
|
@ -62,8 +41,7 @@ class DumperImpl : public Dumper {
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
pixel_modem::logging::DumperImpl dumper_impl;
|
pixel_modem::logging::DumperImpl dumper_impl;
|
||||||
pixel_modem::logging::AndroidPropertyManagerImpl
|
pixel_modem::AndroidPropertyManagerImpl android_property_manager_impl;
|
||||||
android_property_manager_impl;
|
|
||||||
pixel_modem::logging::ModemLogDumper modem_log_dumper(
|
pixel_modem::logging::ModemLogDumper modem_log_dumper(
|
||||||
dumper_impl, android_property_manager_impl);
|
dumper_impl, android_property_manager_impl);
|
||||||
|
|
||||||
|
|
|
@ -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
|
|
Loading…
Add table
Add a link
Reference in a new issue