15
15
// License along with this library; if not, write to the Free Software
16
16
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
#include "oxide_android_properties.h"
18
#include "oxide_hybris_utils.h"
20
#if defined(ENABLE_HYBRIS)
22
21
#include <hybris/properties/properties.h>
23
#include "base/files/file_path.h"
24
#include "base/lazy_instance.h"
25
#include "base/logging.h"
26
#include "base/native_library.h"
23
27
#include "base/strings/stringprintf.h"
26
#include "base/logging.h"
27
#include "base/memory/singleton.h"
31
// Copied from base/sys_info_internal.h
32
template<typename T, T (*F)(void)>
33
class LazyHybrisValue {
38
~LazyHybrisValue() { }
40
const T& value() { return value_; }
45
DISALLOW_COPY_AND_ASSIGN(LazyHybrisValue);
48
struct DevicePropertyData {
49
HybrisUtils::DeviceProperties properties;
33
#if defined(ENABLE_HYBRIS)
34
55
std::string ParseOSVersion(const char* os_version_str) {
35
56
int32_t major, minor, bugfix;
53
74
return base::StringPrintf("%d.%d.%d", major, minor, bugfix);
59
AndroidProperties::AndroidProperties()
61
#if defined(ENABLE_HYBRIS)
77
DevicePropertyData PopulateDeviceProperties() {
78
DevicePropertyData data;
79
data.available = false;
62
81
char value[PROP_VALUE_MAX];
64
83
if (::property_get("ro.product.name", value, nullptr) <= 0) {
87
data.available = true;
88
data.properties.product = value;
71
90
::property_get("ro.product.device", value, nullptr);
91
data.properties.device = value;
74
93
::property_get("ro.product.board", value, nullptr);
94
data.properties.board = value;
77
96
::property_get("ro.product.brand", value, nullptr);
97
data.properties.brand = value;
80
99
::property_get("ro.product.model", value, nullptr);
100
data.properties.model = value;
83
102
::property_get("ro.build.version.release", value, nullptr);
84
os_version_ = ParseOSVersion(value);
88
AndroidProperties::~AndroidProperties() {}
91
AndroidProperties* AndroidProperties::GetInstance() {
92
return base::Singleton<AndroidProperties>::get();
95
bool AndroidProperties::Available() const {
99
std::string AndroidProperties::GetProduct() const {
104
std::string AndroidProperties::GetDevice() const {
109
std::string AndroidProperties::GetBoard() const {
114
std::string AndroidProperties::GetBrand() const {
119
std::string AndroidProperties::GetModel() const {
124
std::string AndroidProperties::GetOSVersion() const {
103
data.properties.os_version = ParseOSVersion(value);
108
bool UsingAndroidEGL() {
109
base::NativeLibrary egl_lib =
110
base::LoadNativeLibrary(base::FilePath("libEGL.so.1"), nullptr);
115
return !!base::GetFunctionPointerFromNativeLibrary(
116
egl_lib, "hybris_egl_display_get_mapping");
119
#if defined(ENABLE_HYBRIS_CAMERA)
120
bool CameraCompatAvailable() {
121
base::NativeLibrary camera_lib =
122
base::LoadNativeLibrary(base::FilePath("libcamera.so.1"), nullptr);
125
typedef void (*hybris_camera_initialize_fn)();
126
auto hybris_camera_initialize =
127
reinterpret_cast<hybris_camera_initialize_fn>(
128
base::GetFunctionPointerFromNativeLibrary(camera_lib,
129
"hybris_camera_initialize"));
130
DCHECK(hybris_camera_initialize);
132
hybris_camera_initialize();
135
reinterpret_cast<void**>(base::GetFunctionPointerFromNativeLibrary(
136
camera_lib, "camera_handle"));
144
LazyHybrisValue<DevicePropertyData, PopulateDeviceProperties>>
145
g_device_properties = LAZY_INSTANCE_INITIALIZER;
146
base::LazyInstance<LazyHybrisValue<bool, UsingAndroidEGL>>
147
g_using_android_egl = LAZY_INSTANCE_INITIALIZER;
148
#if defined(ENABLE_HYBRIS_CAMERA)
149
base::LazyInstance<LazyHybrisValue<bool, CameraCompatAvailable>>
150
g_camera_compat_available = LAZY_INSTANCE_INITIALIZER;
156
bool HybrisUtils::HasDeviceProperties() {
157
return g_device_properties.Get().value().available;
161
const HybrisUtils::DeviceProperties& HybrisUtils::GetDeviceProperties() {
162
DCHECK(HasDeviceProperties());
163
return g_device_properties.Get().value().properties;
167
bool HybrisUtils::IsUsingAndroidEGL() {
168
return g_using_android_egl.Get().value();
171
#if defined(ENABLE_HYBRIS_CAMERA)
173
bool HybrisUtils::IsCameraCompatAvailable() {
174
return g_camera_compat_available.Get().value();
129
178
} // namespace oxide