blob: cb48b5dec244ab0a3278aecc2803c5dc710e10fb [file] [log] [blame]
#include <fstream>
#include <tuple>
#include <android-base/logging.h>
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <sys/_system_properties.h>
#include "vendor_init.h"
#define PROC_NFC "/proc/oppo_nfc/chipset"
#define PROC_OPERATOR "/proc/oppoVersion/operatorName"
void property_override(std::string prop, std::string value, bool add = true) {
auto pi = (prop_info *)__system_property_find(prop.c_str());
if (pi != nullptr) {
__system_property_update(pi, value.c_str(), value.size());
} else if (add) {
__system_property_add(prop.c_str(), prop.size(), value.c_str(),
value.size());
}
}
void set_ro_build_prop(const std::string &prop, const std::string &value,
bool product = true) {
std::string prop_name;
std::string prop_types[] = {
"",
"bootimage.",
"odm.",
"odm_dlkm.",
"product.",
"system.",
"system_ext.",
"vendor.",
"vendor_dlkm.",
};
for (const std::string &source : prop_types) {
if (product) {
prop_name = "ro.product." + source + prop;
} else {
prop_name = "ro." + source + "build." + prop;
}
property_override(prop_name, value, false);
}
}
bool nfc_variant() {
std::ifstream nfc_file(PROC_NFC);
nfc_file.good();
std::string chipset;
getline(nfc_file, chipset);
LOG(INFO) << "oppo_nfc : chipset " << chipset;
return (chipset != "NULL");
}
std::tuple<std::string, std::string> get_device() {
std::string device, model, line;
std::ifstream operator_file(PROC_OPERATOR);
operator_file.good();
getline(operator_file, line);
int operatorName = stoi(line);
switch (operatorName) {
// realme 6
case 101:
case 102:
case 104:
case 105:
device = "RMX2001L1";
model = "RMX2001";
break;
case 106:
device = "RMX2003L1";
model = "RMX2003";
break;
case 113:
device = "RMX2005L1";
model = "RMX2005";
break;
// realme 6i/6s/Narzo
case 111:
case 112:
case 114:
device = "RMX2002L1";
model = "RMX2002";
break;
// realme 7
case 140:
case 141:
case 146:
case 149:
device = "RMX2151L1";
model = "RMX2151";
break;
case 142:
device = "RMX2153L1";
model = "RMX2153";
break;
case 94:
case 148:
device = "RMX2155L1";
model = "RMX2155";
break;
// realme Narzo 30 4G
case 90:
case 92:
device = "RMX2156L1";
model = "RMX2156";
break;
// realme Narzo 20 Pro
case 143:
device = "RMX2161L1";
model = "RMX2161";
break;
case 145:
case 147:
device = "RMX2163L1";
model = "RMX2163";
break;
default:
LOG(ERROR) << "Unable to read operator from " << PROC_OPERATOR;
}
return {device, model};
}
void vendor_load_properties() {
#ifndef __ANDROID_RECOVERY__
auto [device, model] = get_device();
set_ro_build_prop("device", device);
set_ro_build_prop("model", model);
set_ro_build_prop("name", model);
set_ro_build_prop("product", model, false);
// for RRO
if (!device.find("RMX215")) {
property_override("ro.device", "RMX2151");
}
if (!device.find("RMX216")) {
property_override("ro.device", "RMX2161");
}
// NFC check
if (nfc_variant()) {
property_override("ro.boot.product.hardware.sku", "nfc");
}
#endif
}