init_gsi: Add support for optional alternate CAF audio policy

This commit is contained in:
Peter Cai 2022-09-03 22:44:41 -04:00
parent 276d4b620b
commit 15ca354dfe
6 changed files with 41 additions and 1 deletions

View file

@ -7,6 +7,7 @@ cc_binary {
// SoC-specific quirks // SoC-specific quirks
"quirks/soc/mtk_ril.cpp", "quirks/soc/mtk_ril.cpp",
"quirks/soc/caf_audio.cpp",
// Device-specific quirks // Device-specific quirks
"quirks/device/unihertz_keylayout.cpp", "quirks/device/unihertz_keylayout.cpp",

View file

@ -59,6 +59,8 @@ int main(int argc, char **argv) {
// Reset SPL / device model related props during late init // Reset SPL / device model related props during late init
// so that they are set before keystore / vold is started. // so that they are set before keystore / vold is started.
handle_device_model_props(); handle_device_model_props();
} else if (argc >= 2 && strcmp(argv[1], "--post-fs-data") == 0) {
Quirks::RunPostData();
} else { } else {
Quirks::Run(); Quirks::Run();
} }

View file

@ -4,5 +4,9 @@ on late-init
on post-fs on post-fs
exec u:r:init_gsi:s0 root -- /system_ext/bin/init_gsi exec u:r:init_gsi:s0 root -- /system_ext/bin/init_gsi
# When we call our post-fs-data actions, we would like persist properties to be available
on load_persist_props_action
exec u:r:init_gsi:s0 root -- /system_ext/bin/init_gsi --post-fs-data
on property:persist.sys.gsi.hw.mainkeys=* on property:persist.sys.gsi.hw.mainkeys=*
setprop qemu.hw.mainkeys ${persist.sys.gsi.hw.mainkeys} setprop qemu.hw.mainkeys ${persist.sys.gsi.hw.mainkeys}

View file

@ -40,6 +40,16 @@ void Quirks::Run() {
} }
} }
void Quirks::RunPostData() {
if (quirks == nullptr) return;
for (DeviceQuirk* quirk : *quirks) {
if (quirk->ShouldRun()) {
quirk->RunPostData();
}
}
}
// Utility functions for use with quirks // Utility functions for use with quirks
#define QUIRKS_TMP_BASE_PATH "/mnt/quirks" #define QUIRKS_TMP_BASE_PATH "/mnt/quirks"
#define QUIRKS_TMP_FILES_PATH QUIRKS_TMP_BASE_PATH "/files" #define QUIRKS_TMP_FILES_PATH QUIRKS_TMP_BASE_PATH "/files"

View file

@ -29,7 +29,8 @@ class DeviceQuirk {
public: public:
DeviceQuirk(); DeviceQuirk();
virtual bool ShouldRun() = 0; virtual bool ShouldRun() = 0;
virtual void Run() = 0; virtual void Run() {}
virtual void RunPostData() {}
virtual ~DeviceQuirk(); virtual ~DeviceQuirk();
}; };
@ -39,6 +40,7 @@ public:
namespace Quirks { namespace Quirks {
void Add(DeviceQuirk* quirk); void Add(DeviceQuirk* quirk);
void Run(); void Run();
void RunPostData();
int OverrideWithBindMount(filesystem::path src, filesystem::path dst); int OverrideWithBindMount(filesystem::path src, filesystem::path dst);

View file

@ -0,0 +1,21 @@
#include "../../quirks.h"
#include <android-base/properties.h>
#include <filesystem>
using namespace std;
class CafAudioQuirk : DeviceQuirk {
public:
bool ShouldRun() {
return filesystem::exists("/vendor/etc/audio/audio_policy_configuration.xml");
}
void RunPostData() {
if (android::base::GetBoolProperty("persist.sys.gsi.alternate_audio_policy", false)) {
Quirks::OverrideWithBindMount("/vendor/etc/audio/audio_policy_configuration.xml", "/vendor/etc/audio_policy_configuration.xml");
android::base::SetProperty("ctl.restart", "audioserver"); // Ensure our new policy is loaded into audioserver
}
}
};
LOAD_QUIRK(CafAudioQuirk);