| 1 |
/* |
| 2 |
* Copyright (C) 2020 UBports foundation. |
| 3 |
* Author(s): Marius Gripsgard <[email protected]> |
| 4 |
* |
| 5 |
* This program is free software: you can redistribute it and/or modify it under |
| 6 |
* the terms of the GNU General Public License version 3, as published by |
| 7 |
* the Free Software Foundation. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 |
* ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
| 11 |
* SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 12 |
* General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
* |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "halium.h" |
| 20 |
|
| 21 |
#include <memory> |
| 22 |
#include <string> |
| 23 |
#include <cstring> |
| 24 |
|
| 25 |
#include <hybris/properties/properties.h> |
| 26 |
|
| 27 |
// Android props |
| 28 |
#define DEVICE_PROP_KEY "ro.product.device" |
| 29 |
#define MODEL_PROP_KEY "ro.product.model" |
| 30 |
#define MANUFACTURER_PROP_KEY "ro.product.manufacturer" |
| 31 |
#define VENDOR_MANUFACTURER_PROP_KEY "ro.product.vendor.manufacturer" |
| 32 |
#define VENDOR_DEVICE_PROP_KEY "ro.product.vendor.device" |
| 33 |
#define VENDOR_MODEL_PROP_KEY "ro.product.vendor.model" |
| 34 |
#define CHARA_PROP_KEY "ro.build.characteristics" |
| 35 |
#define DISPLAY_ID_PROP_KEY "ro.build.display.id" |
| 36 |
#define SERIAL_NUMBER_PROP_KEY "ro.serialno" |
| 37 |
|
| 38 |
std::string platform::Halium::name() |
| 39 |
{ |
| 40 |
if (hasHaliumProp(VENDOR_DEVICE_PROP_KEY)) |
| 41 |
return getHaliumProp(VENDOR_DEVICE_PROP_KEY); |
| 42 |
else if (hasHaliumProp(DEVICE_PROP_KEY)) |
| 43 |
return getHaliumProp(DEVICE_PROP_KEY); |
| 44 |
|
| 45 |
return "unknown"; |
| 46 |
} |
| 47 |
|
| 48 |
bool platform::Halium::hasValidName() |
| 49 |
{ |
| 50 |
return hasHaliumProp(VENDOR_DEVICE_PROP_KEY) || |
| 51 |
hasHaliumProp(DEVICE_PROP_KEY); |
| 52 |
} |
| 53 |
|
| 54 |
std::string platform::Halium::prettyName() |
| 55 |
{ |
| 56 |
if (hasHaliumProp(VENDOR_MODEL_PROP_KEY)) |
| 57 |
return getHaliumProp(VENDOR_MODEL_PROP_KEY); |
| 58 |
else if (hasHaliumProp(MODEL_PROP_KEY)) |
| 59 |
return getHaliumProp(MODEL_PROP_KEY); |
| 60 |
|
| 61 |
return "unknown"; |
| 62 |
} |
| 63 |
|
| 64 |
bool platform::Halium::hasValidPrettyName() |
| 65 |
{ |
| 66 |
return hasHaliumProp(VENDOR_MODEL_PROP_KEY) || |
| 67 |
hasHaliumProp(MODEL_PROP_KEY); |
| 68 |
} |
| 69 |
|
| 70 |
DeviceInfo::DeviceType platform::Halium::deviceType() { |
| 71 |
auto chara = getHaliumProp(CHARA_PROP_KEY); |
| 72 |
if (chara.find("tablet") != std::string::npos) |
| 73 |
return DeviceInfo::DeviceType::Tablet; |
| 74 |
|
| 75 |
// As this is a halium device, the best guess will be phone |
| 76 |
return DeviceInfo::DeviceType::Phone; |
| 77 |
} |
| 78 |
|
| 79 |
bool platform::Halium::hasValidDeviceType() |
| 80 |
{ |
| 81 |
return hasHaliumProp(CHARA_PROP_KEY); |
| 82 |
} |
| 83 |
|
| 84 |
DeviceInfo::DriverType platform::Halium::driverType() |
| 85 |
{ |
| 86 |
return DeviceInfo::DriverType::Halium; |
| 87 |
} |
| 88 |
|
| 89 |
std::string platform::Halium::getHaliumProp(const char* prop) |
| 90 |
{ |
| 91 |
return getHaliumProp(prop, ""); |
| 92 |
} |
| 93 |
|
| 94 |
std::string platform::Halium::getHaliumProp(const char* prop, const char* default_value) |
| 95 |
{ |
| 96 |
char value[PROP_VALUE_MAX]; |
| 97 |
property_get(prop, value, default_value); |
| 98 |
return std::string(value); |
| 99 |
} |
| 100 |
|
| 101 |
bool platform::Halium::hasHaliumProp(const char* key) |
| 102 |
{ |
| 103 |
char const* default_value = "hasnodevice"; |
| 104 |
char value[PROP_VALUE_MAX]; |
| 105 |
property_get(key, value, default_value); |
| 106 |
return strcmp(value, default_value) != 0; |
| 107 |
} |
| 108 |
|
| 109 |
bool platform::Halium::usable() |
| 110 |
{ |
| 111 |
return hasHaliumProp(VENDOR_DEVICE_PROP_KEY) || |
| 112 |
hasHaliumProp(DEVICE_PROP_KEY); |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Returns the version number, build date and other informations |
| 117 |
*/ |
| 118 |
std::string platform::Halium::buildId() |
| 119 |
{ |
| 120 |
if (hasHaliumProp(DISPLAY_ID_PROP_KEY)) |
| 121 |
return getHaliumProp(DISPLAY_ID_PROP_KEY); |
| 122 |
} |
| 123 |
/** |
| 124 |
* Returns the serial number |
| 125 |
*/ |
| 126 |
std::string platform::Halium::deviceIdentifier() |
| 127 |
{ |
| 128 |
if (hasHaliumProp(SERIAL_NUMBER_PROP_KEY)) |
| 129 |
return getHaliumProp(SERIAL_NUMBER_PROP_KEY); |
| 130 |
} |