(This is a merge of http://go/wvgerrit/13761 from the Widevine repository.) This cleans up our includes to be in Google Style Guide order and in alphabetic order, for the parts of the code that are expected to follow Google Style. This also converts places in our code that were including C headers in the C++ style (i.e. <cstring> instead of <string.h>) to use C style instead. This is because, although it was not causing problems for us yet, on Android these actually include different headers. (<cstring> is provided by libcxx, while <string.h> is provided by Bionic) Lastly, this change puts all headers that do not come from within our project in <brackets> instead of "quotes," which was not being done consistently. This change is explicitly NOT trying to standardize the spacing of our header includes. I have tried to respect, in each file, the spacing style already present. Change-Id: If3dc06532ab9b68010285d64518ef21dce3d6354
140 lines
3.5 KiB
C++
140 lines
3.5 KiB
C++
// Copyright 2013 Google Inc. All Rights Reserved.
|
|
|
|
#include "properties.h"
|
|
|
|
#include <unistd.h>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
#include <cutils/properties.h>
|
|
|
|
#include "log.h"
|
|
|
|
namespace {
|
|
|
|
const char kBasePathPrefix[] = "/data/mediadrm/IDM";
|
|
const char kL1Dir[] = "/L1/";
|
|
const char kL2Dir[] = "/L2/";
|
|
const char kL3Dir[] = "/L3/";
|
|
const char kFactoryKeyboxPath[] = "/factory/wv.keys";
|
|
|
|
bool GetAndroidProperty(const char* key, std::string* value) {
|
|
char val[PROPERTY_VALUE_MAX];
|
|
if (!key) {
|
|
LOGW("GetAndroidProperty: Invalid property key parameter");
|
|
return false;
|
|
}
|
|
|
|
if (!value) {
|
|
LOGW("GetAndroidProperty: Invalid property value parameter");
|
|
return false;
|
|
}
|
|
|
|
if (property_get(key, val, "Unknown") <= 0) return false;
|
|
|
|
*value = val;
|
|
return true;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace wvcdm {
|
|
|
|
bool Properties::GetCompanyName(std::string* company_name) {
|
|
if (!company_name) {
|
|
LOGW("Properties::GetCompanyName: Invalid parameter");
|
|
return false;
|
|
}
|
|
return GetAndroidProperty("ro.product.manufacturer", company_name);
|
|
}
|
|
|
|
bool Properties::GetModelName(std::string* model_name) {
|
|
if (!model_name) {
|
|
LOGW("Properties::GetModelName: Invalid parameter");
|
|
return false;
|
|
}
|
|
return GetAndroidProperty("ro.product.model", model_name);
|
|
}
|
|
|
|
bool Properties::GetArchitectureName(std::string* arch_name) {
|
|
if (!arch_name) {
|
|
LOGW("Properties::GetArchitectureName: Invalid parameter");
|
|
return false;
|
|
}
|
|
return GetAndroidProperty("ro.product.cpu.abi", arch_name);
|
|
}
|
|
|
|
bool Properties::GetDeviceName(std::string* device_name) {
|
|
if (!device_name) {
|
|
LOGW("Properties::GetDeviceName: Invalid parameter");
|
|
return false;
|
|
}
|
|
return GetAndroidProperty("ro.product.device", device_name);
|
|
}
|
|
|
|
bool Properties::GetProductName(std::string* product_name) {
|
|
if (!product_name) {
|
|
LOGW("Properties::GetProductName: Invalid parameter");
|
|
return false;
|
|
}
|
|
return GetAndroidProperty("ro.product.name", product_name);
|
|
}
|
|
|
|
bool Properties::GetBuildInfo(std::string* build_info) {
|
|
if (!build_info) {
|
|
LOGW("Properties::GetBuildInfo: Invalid parameter");
|
|
return false;
|
|
}
|
|
return GetAndroidProperty("ro.build.fingerprint", build_info);
|
|
}
|
|
|
|
bool Properties::GetOsVersion(std::string* os_version) {
|
|
if (!os_version) {
|
|
LOGW("Properties::GetOsVersion: Invalid parameter");
|
|
return false;
|
|
}
|
|
return GetAndroidProperty("ro.build.version.release", os_version);
|
|
}
|
|
|
|
bool Properties::GetDeviceFilesBasePath(CdmSecurityLevel security_level,
|
|
std::string* base_path) {
|
|
if (!base_path) {
|
|
LOGW("Properties::GetDeviceFilesBasePath: Invalid parameter");
|
|
return false;
|
|
}
|
|
std::stringstream ss;
|
|
ss << kBasePathPrefix << getuid();
|
|
switch (security_level) {
|
|
case kSecurityLevelL1: ss << kL1Dir; break;
|
|
case kSecurityLevelL2: ss << kL2Dir; break;
|
|
case kSecurityLevelL3: ss << kL3Dir; break;
|
|
default:
|
|
LOGW("Properties::GetDeviceFilesBasePath: Unknown security level: %d",
|
|
security_level);
|
|
return false;
|
|
}
|
|
|
|
*base_path = ss.str();
|
|
return true;
|
|
}
|
|
|
|
bool Properties::GetFactoryKeyboxPath(std::string* keybox) {
|
|
if (!keybox) {
|
|
LOGW("Properties::GetFactoryKeyboxPath: Invalid parameter");
|
|
return false;
|
|
}
|
|
*keybox = kFactoryKeyboxPath;
|
|
return true;
|
|
}
|
|
|
|
bool Properties::GetOEMCryptoPath(std::string* library_name) {
|
|
if (!library_name) {
|
|
LOGW("Properties::GetOEMCryptoPath: Invalid parameter");
|
|
return false;
|
|
}
|
|
*library_name = "liboemcrypto.so";
|
|
return true;
|
|
}
|
|
|
|
} // namespace wvcdm
|