init_gsi: Add generic mechanism to preset properties

This commit is contained in:
Peter Cai 2023-08-22 05:23:42 -04:00
parent b9fb2010ee
commit b591179d67
6 changed files with 49 additions and 26 deletions

View File

@ -4,6 +4,9 @@ cc_binary {
srcs: [
"init_gsi.cpp",
"quirks.cpp",
// Per-device / SoC preset properties
"quirks/preset_props.cpp",
// SoC-specific quirks
"quirks/soc/mtk_ril.cpp",
@ -12,7 +15,6 @@ cc_binary {
// Device-specific quirks
"quirks/device/unihertz_keylayout.cpp",
"quirks/device/ulefone_power_armor_13.cpp",
],
shared_libs: ["libbase", "libdl", "liblog", "libutils"],
static_libs: ["libresetprop", "libc++fs"],

View File

@ -9,9 +9,6 @@
using namespace android;
using namespace std;
// From libresetprop
extern int setprop(const char *name, const char *value, bool trigger);
void override_ro_prop(string prefix, string source, string postfix, string value) {
if (value.length() == 0) return;

View File

@ -3,6 +3,7 @@
#include "quirks.h"
#include <cstdarg>
#include <regex>
#include <sstream>
#include <vector>
@ -11,6 +12,19 @@
#include <sys/stat.h>
#include <unistd.h>
// Utility function used with preset properties
void __set_props(int _ignore, ...) {
va_list args;
va_start(args, _ignore);
while (auto key = va_arg(args, const char*)) {
auto val = va_arg(args, const char*);
setprop(key, val, true);
}
va_end(args);
}
// Default constructor to add self to the loaded list of quirks
DeviceQuirk::DeviceQuirk() {
Quirks::Add(this);

View File

@ -8,6 +8,9 @@
#include <sys/wait.h>
#include <unistd.h>
// From libresetprop
extern int setprop(const char *name, const char *value, bool trigger);
#define PROP_STARTS_WITH(prop, prefix) \
(android::base::GetProperty(prop, "").rfind(prefix, 0) == 0)
#define FP_STARTS_WITH(prefix) \
@ -37,6 +40,20 @@ public:
#define LOAD_QUIRK(NAME) \
static NAME _ignored;
void __set_props(int _ignore, ...);
#define CONCAT_(x,y) x##y
#define CONCAT(x,y) CONCAT_(x,y)
#define UNIQUE_NAME CONCAT(_unique_name_, __LINE__)
#define PRESET_PROPS(cond, ...) \
class UNIQUE_NAME: DeviceQuirk { \
public: \
bool ShouldRun() { return cond; } \
void Run() { __set_props(0, __VA_ARGS__, NULL); } \
}; \
static UNIQUE_NAME CONCAT(_ignored, UNIQUE_NAME);
namespace Quirks {
void Add(DeviceQuirk* quirk);
void Run();

View File

@ -1,22 +0,0 @@
#include "../../quirks.h"
#include <android-base/properties.h>
#include <filesystem>
using namespace std;
class UlefonePowerArmor13Quirks : DeviceQuirk {
public:
bool ShouldRun() {
return FP_STARTS_WITH("Ulefone/Power_Armor_13/");
}
void Run() {
// Set the A2DP offload properties to disabled so legacy policy is loaded
android::base::SetProperty("persist.bluetooth.a2dp_offload.disabled", "true");
android::base::SetProperty("persist.bluetooth.bluetooth_audio_hal.disabled", "true");
}
};
LOAD_QUIRK(UlefonePowerArmor13Quirks);

View File

@ -0,0 +1,15 @@
#include "../quirks.h"
#include <android-base/properties.h>
// Disable navbar by default on devices known to have physical keys
PRESET_PROPS(
FP_STARTS_WITH("Unihertz/Jelly") || FP_STARTS_WITH("Unihertz/Atom"),
"persist.sys.gsi.hw.mainkeys", "1"
);
// Some xiaomi devices: Override default network mode to enable 5G
PRESET_PROPS(
FP_STARTS_WITH("Redmi/gauguin"),
"ro.telephony.default_network", "33,22"
);