Update property retrival method

[ Merge of http://go/wvgerrit/70203 ]

The earlier property_get() method had a limitation on property length.
Properties of some new devices exceed that length. An error message
is returned rather than a truncated string. Replace its use with
android::base::GetProperty() which does not have a length limitation.

Bug: 115358798
Test: WV unit/integration tests
Change-Id: I46ce9a7e77bcd031225d0082f83c57d484fe5405
This commit is contained in:
Rahul Frias
2019-01-11 00:57:32 -08:00
parent a4e66ac673
commit ef00d6ffa5
20 changed files with 49 additions and 38 deletions

View File

@@ -96,10 +96,11 @@ LOCAL_C_INCLUDES := \
vendor/widevine/libwvdrmengine/oemcrypto/include \
LOCAL_HEADER_LIBRARIES := \
libbase_headers \
libutils_headers \
LOCAL_SHARED_LIBRARIES := \
liblog
liblog \
LOCAL_CFLAGS := -DCORE_UTIL_IMPLEMENTATION
@@ -182,7 +183,7 @@ LOCAL_STATIC_LIBRARIES := \
libwvlevel3 \
LOCAL_SHARED_LIBRARIES := \
libcutils \
libbase \
libdl \
liblog \
libprotobuf-cpp-lite \
@@ -247,7 +248,7 @@ LOCAL_SHARED_LIBRARIES := \
android.hardware.drm@1.1 \
android.hardware.drm@1.2 \
android.hidl.memory@1.0 \
libcutils \
libbase \
libdl \
libhidlbase \
libhidlmemory \

View File

@@ -9,7 +9,7 @@
#include <sstream>
#include <string>
#include <cutils/properties.h>
#include <android-base/properties.h>
#include "log.h"
@@ -24,7 +24,6 @@ const char kFactoryKeyboxPath[] = "/factory/wv.keys";
const char kWVCdmVersion[] = "15.0.0";
bool GetAndroidProperty(const char* key, std::string* value) {
char val[PROPERTY_VALUE_MAX];
if (!key) {
LOGW("GetAndroidProperty: Invalid property key parameter");
return false;
@@ -35,10 +34,9 @@ bool GetAndroidProperty(const char* key, std::string* value) {
return false;
}
if (property_get(key, val, "Unknown") <= 0) return false;
*value = android::base::GetProperty(key, "");
*value = val;
return true;
return value->size() > 0;
}
} // namespace

View File

@@ -43,7 +43,7 @@ LOCAL_STATIC_LIBRARIES := \
libwvlevel3 \
LOCAL_SHARED_LIBRARIES := \
libcutils \
libbase \
libdl \
liblog \
libmedia_omx \

View File

@@ -5,7 +5,7 @@
#include <errno.h>
#include <sstream>
#include <cutils/properties.h>
#include <android-base/properties.h>
#include <gmock/gmock.h>
#include <gtest/gtest.h>
@@ -4771,10 +4771,10 @@ INSTANTIATE_TEST_CASE_P(Cdm, WvCdmSessionSharingNoKeyTest,
&single_encrypted_sub_sample));
TEST(VersionNumberTest, VersionNumberChangeCanary) {
char release_number[PROPERTY_VALUE_MAX];
ASSERT_GT(property_get("ro.build.version.release", release_number, "Unknown"),
0);
EXPECT_STREQ("Q", release_number)
std::string release_number =
android::base::GetProperty("ro.build.version.release", "");
ASSERT_TRUE(release_number.size() > 0);
EXPECT_STREQ("Q", release_number.c_str())
<< "The Android version number has changed. You need to update this test "
"and also possibly update the Widevine version number in "
"properties_android.cpp.";

View File

@@ -43,7 +43,7 @@ LOCAL_STATIC_LIBRARIES := \
libwvlevel3 \
LOCAL_SHARED_LIBRARIES := \
libcutils \
libbase \
libdl \
liblog \
libmedia_omx \

View File

@@ -5,6 +5,7 @@ LOCAL_CFLAGS := \
-Wno-unused \
-Wno-unused-parameter
LOCAL_C_INCLUDES := \
system/core/base/include \
system/core/include \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/util/include \

View File

@@ -5,6 +5,7 @@ LOCAL_CFLAGS := \
-Wno-unused \
-Wno-unused-parameter
LOCAL_C_INCLUDES := \
system/core/base/include \
system/core/include \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/util/include \

View File

@@ -5,6 +5,7 @@ LOCAL_CFLAGS := \
-Wno-unused \
-Wno-unused-parameter
LOCAL_C_INCLUDES := \
system/core/base/include \
system/core/include \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/util/include \

View File

@@ -5,6 +5,7 @@ LOCAL_CFLAGS := \
-Wno-unused \
-Wno-unused-parameter
LOCAL_C_INCLUDES := \
system/core/base/include \
system/core/include \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/util/include \

View File

@@ -2,31 +2,29 @@
#include <string.h>
#include <string>
// The function property_get is defined differently if it comes from the IN_APP
// version or from the Android OS.
#if defined(IN_APP_FASTBALL)
#include "properties_fastball.h"
#else
#include <cutils/properties.h>
#include <android-base/properties.h>
#endif
namespace wvoec3 {
const char *getUniqueID(size_t *len) {
static char temp_value[PROPERTY_VALUE_MAX * 2];
int actual_len = property_get("ro.serialno", temp_value, NULL);
if (actual_len <= 0) {
actual_len = property_get("net.hostname", temp_value, NULL);
}
if (actual_len <= 0) {
strncpy(temp_value, "0123456789abc", PROPERTY_VALUE_MAX);
static std::string unique_id;
unique_id = android::base::GetProperty("ro.serialno", "");
if (unique_id.empty()) {
unique_id = android::base::GetProperty("net.hostname", "0123456789abc");
}
#if defined(IN_APP_FASTBALL) || defined(IN_APP_MOVIES)
actual_len +=
property_get("package.name", temp_value + actual_len, "com.google.inapp");
unique_id += android::base::GetProperty("package.name", "com.google.inapp");
#endif
*len = actual_len;
return temp_value;
*len = unique_id.size();
return unique_id.c_str();
}
} // namespace wvoec3

View File

@@ -5,6 +5,7 @@ LOCAL_CFLAGS := \
-Wno-unused \
-Wno-unused-parameter
LOCAL_C_INCLUDES := \
system/core/base/include \
system/core/include \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/util/include \

View File

@@ -5,6 +5,7 @@ LOCAL_CFLAGS := \
-Wno-unused \
-Wno-unused-parameter
LOCAL_C_INCLUDES := \
system/core/base/include \
system/core/include \
vendor/widevine/libwvdrmengine/cdm/core/include \
vendor/widevine/libwvdrmengine/cdm/util/include \

View File

@@ -31,6 +31,7 @@ LOCAL_STATIC_LIBRARIES := \
libwvdrmcryptoplugin \
LOCAL_SHARED_LIBRARIES := \
libbase \
libcutils \
libdl \
liblog \
@@ -94,6 +95,7 @@ LOCAL_SHARED_LIBRARIES := \
android.hardware.drm@1.1 \
android.hardware.drm@1.2 \
android.hidl.memory@1.0 \
libbase \
libbinder \
libcutils \
libdl \

View File

@@ -32,7 +32,7 @@ LOCAL_STATIC_LIBRARIES := \
libwvdrmdrmplugin \
LOCAL_SHARED_LIBRARIES := \
libcutils \
libbase \
libdl \
liblog \
libprotobuf-cpp-lite \
@@ -96,7 +96,7 @@ LOCAL_SHARED_LIBRARIES := \
android.hardware.drm@1.2 \
android.hidl.memory@1.0 \
libbinder \
libcutils \
libbase \
libdl \
libhidlbase \
libhidlmemory \

View File

@@ -27,7 +27,7 @@ LOCAL_C_INCLUDES += \
vendor/widevine/libwvdrmengine/cdm/util/include \
LOCAL_SHARED_LIBRARIES := \
libcutils \
libbase \
libdl \
liblog \
libmedia \

View File

@@ -30,7 +30,7 @@ LOCAL_STATIC_LIBRARIES := \
libcdm_utils \
LOCAL_SHARED_LIBRARIES := \
libcutils \
libbase \
libdl \
liblog \
libmedia_omx \

View File

@@ -10,7 +10,7 @@
#include "WVDrmFactory.h"
#include "cutils/properties.h"
#include "android-base/properties.h"
#include "wv_cdm_constants.h"
#include "wv_content_decryption_module.h"
#include "HidlTypes.h"
@@ -57,11 +57,13 @@ Return<void> WVDrmFactory::createPlugin(
bool WVDrmFactory::areSpoidsEnabled() {
// Check what this device's first API level was.
int32_t firstApiLevel = property_get_int32("ro.product.first_api_level", 0);
int32_t firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.product.first_api_level", 0);
if (firstApiLevel == 0) {
// First API Level is 0 on factory ROMs, but we can assume the current SDK
// version is the first if it's a factory ROM.
firstApiLevel = property_get_int32("ro.build.version.sdk", 0);
firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.build.version.sdk", 0);
}
return firstApiLevel >= 26; // Android O
}

View File

@@ -72,7 +72,7 @@ LOCAL_SHARED_LIBRARIES := \
android.hardware.drm@1.0 \
android.hardware.drm@1.1 \
android.hardware.drm@1.2 \
libcutils \
libbase \
libdl \
libhidlbase \
libhidlmemory \

View File

@@ -9,6 +9,8 @@
#include "WVDrmFactory.h"
#include "HidlTypes.h"
#include "android-base/properties.h"
namespace wvdrm {
namespace hardware {
namespace drm {
@@ -97,11 +99,13 @@ TEST(WVDrmFactoryTest, DoesNotSupportUnsupportedContainerFormats) {
TEST(WVDrmFactoryTest, CalculatesSpoidUseCorrectly) {
WVDrmFactory factory;
int32_t firstApiLevel = property_get_int32("ro.product.first_api_level", 0);
int32_t firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.product.first_api_level", 0);
if (firstApiLevel == 0) {
// First API Level is 0 on factory ROMs, but we can assume the current SDK
// version is the first if it's a factory ROM.
firstApiLevel = property_get_int32("ro.build.version.sdk", 0);
firstApiLevel =
android::base::GetIntProperty<int32_t>("ro.build.version.sdk", 0);
}
bool shouldUseSpoids = (firstApiLevel >= 26); // Android O

View File

@@ -28,7 +28,7 @@ LOCAL_STATIC_LIBRARIES := \
libcrypto
LOCAL_SHARED_LIBRARIES := \
libcutils \
libbase \
liblog \
libssl \
libutils \