Move to libbase properties
The libcutils interface cannot read properties with value length > 92
characters, whereas the libbase one can. ro.build.fingerprint may be
larger than this size in the future, so we move to libbase to prepare.
Bug: 23102347
Bug: 34954705
Test: unit tests
Change-Id: Idca886021bdd71623052a452faf582532725ffdc
diff --git a/Android.mk b/Android.mk
index 8807666..0b6ee17 100644
--- a/Android.mk
+++ b/Android.mk
@@ -488,7 +488,7 @@
# library dependencies of these static libraries.
LOCAL_STATIC_LIBRARIES += \
$(ue_common_shared_libraries) \
- libcutils \
+ libbase \
liblog \
$(ue_libpayload_consumer_exported_shared_libraries:-host=) \
$(ue_update_metadata_protos_exported_shared_libraries) \
diff --git a/hardware_android.cc b/hardware_android.cc
index 5e2ee11..86432a9 100644
--- a/hardware_android.cc
+++ b/hardware_android.cc
@@ -21,19 +21,23 @@
#include <sys/types.h>
#include <algorithm>
+#include <memory>
#include <bootloader.h>
+#include <android-base/properties.h>
#include <base/files/file_util.h>
#include <base/strings/stringprintf.h>
#include <brillo/make_unique_ptr.h>
-#include <cutils/properties.h>
#include "update_engine/common/hardware.h"
#include "update_engine/common/platform_constants.h"
#include "update_engine/common/utils.h"
#include "update_engine/utils_android.h"
+using android::base::GetBoolProperty;
+using android::base::GetIntProperty;
+using android::base::GetProperty;
using std::string;
namespace chromeos_update_engine {
@@ -121,7 +125,7 @@
//
// In case of a non-bool value, we take the most restrictive option and
// assume we are in an official-build.
- return property_get_bool("ro.secure", 1) != 0;
+ return GetBoolProperty("ro.secure", true);
}
bool HardwareAndroid::IsNormalBootMode() const {
@@ -129,7 +133,7 @@
// update_engine will allow extra developers options, such as providing a
// different update URL. In case of error, we assume the build is in
// normal-mode.
- return property_get_bool("ro.debuggable", 0) != 1;
+ return !GetBoolProperty("ro.debuggable", false);
}
bool HardwareAndroid::AreDevFeaturesEnabled() const {
@@ -149,26 +153,19 @@
}
string HardwareAndroid::GetHardwareClass() const {
- char manufacturer[PROPERTY_VALUE_MAX];
- char sku[PROPERTY_VALUE_MAX];
- char revision[PROPERTY_VALUE_MAX];
- property_get(kPropBootHardwareSKU, sku, "");
- property_get(kPropProductManufacturer, manufacturer, "");
- property_get(kPropBootRevision, revision, "");
+ auto manufacturer = GetProperty(kPropProductManufacturer, "");
+ auto sku = GetProperty(kPropBootHardwareSKU, "");
+ auto revision = GetProperty(kPropBootRevision, "");
- return base::StringPrintf("%s:%s:%s", manufacturer, sku, revision);
+ return manufacturer + ":" + sku + ":" + revision;
}
string HardwareAndroid::GetFirmwareVersion() const {
- char bootloader[PROPERTY_VALUE_MAX];
- property_get(kPropBootBootloader, bootloader, "");
- return bootloader;
+ return GetProperty(kPropBootBootloader, "");
}
string HardwareAndroid::GetECVersion() const {
- char baseband[PROPERTY_VALUE_MAX];
- property_get(kPropBootBaseband, baseband, "");
- return baseband;
+ return GetProperty(kPropBootBaseband, "");
}
int HardwareAndroid::GetPowerwashCount() const {
@@ -201,7 +198,7 @@
}
int64_t HardwareAndroid::GetBuildTimestamp() const {
- return property_get_int64(kPropBuildDateUTC, 0);
+ return GetIntProperty<int64_t>(kPropBuildDateUTC, 0);
}
} // namespace chromeos_update_engine
diff --git a/image_properties_android.cc b/image_properties_android.cc
index d52c40b..886a6b6 100644
--- a/image_properties_android.cc
+++ b/image_properties_android.cc
@@ -18,10 +18,10 @@
#include <string>
+#include <android-base/properties.h>
#include <base/logging.h>
#include <brillo/osrelease_reader.h>
#include <brillo/strings/string_utils.h>
-#include <cutils/properties.h>
#include "update_engine/common/boot_control_interface.h"
#include "update_engine/common/constants.h"
@@ -29,6 +29,7 @@
#include "update_engine/common/prefs_interface.h"
#include "update_engine/system_state.h"
+using android::base::GetProperty;
using std::string;
namespace chromeos_update_engine {
@@ -97,15 +98,9 @@
result.system_version =
GetStringWithDefault(osrelease, kSystemVersion, "0.0.0.0");
- char prop[PROPERTY_VALUE_MAX];
- property_get(kPropProductName, prop, "brillo");
- result.board = prop;
-
- property_get(kPropBuildFingerprint, prop, "none");
- result.build_fingerprint = prop;
-
- property_get(kPropBuildType, prop, "");
- result.build_type = prop;
+ result.board = GetProperty(kPropProductName, "brillo");
+ result.build_fingerprint = GetProperty(kPropBuildFingerprint, "none");
+ result.build_type = GetProperty(kPropBuildType, "");
// Brillo images don't have a channel assigned. We stored the name of the
// channel where we got the image from in prefs at the time of the update, so
diff --git a/utils_android.cc b/utils_android.cc
index 38d62ea..393e65a 100644
--- a/utils_android.cc
+++ b/utils_android.cc
@@ -16,7 +16,6 @@
#include "update_engine/utils_android.h"
-#include <cutils/properties.h>
#include <fs_mgr.h>
using std::string;