From c31482154b32f70963c909f2cff590282c30cf68 Mon Sep 17 00:00:00 2001 From: LuK1337 Date: Mon, 20 Jun 2022 12:27:27 +0200 Subject: [PATCH] sm7125: Pass call state to audio hal and patch RIL Simon1511: libsec-ril sets a prop (ril.dds.call.slotid) when in call with Sim1 or Sim2. Patch libsec-ril to make that prop vendor lable-able (vendor.calls.slotid). Then use that prop to check which Sim is currently in a call (0 for Sim1 and 1 for Sim2) and pass the arguments to audio HAL depending on that. Note for later: Check whether passing [g_]call_state is really needed Change-Id: I5a0dfd3b100287a2cf1ec3c156292487dc4da3d5 --- audio/Android.bp | 5 ++++ audio/PrimaryDevice.cpp | 34 ++++++++++++++++++++++++++++ audio/include/core/default/Device.h | 3 ++- extract-files.sh | 8 +++++++ proprietary-files.txt | 2 +- sepolicy/vendor/hal_audio_default.te | 2 ++ sepolicy/vendor/property_contexts | 1 + 7 files changed, 53 insertions(+), 2 deletions(-) diff --git a/audio/Android.bp b/audio/Android.bp index 24a7292..e361b15 100644 --- a/audio/Android.bp +++ b/audio/Android.bp @@ -69,6 +69,7 @@ cc_library_shared { "android.hardware.audio@2.0-util", "android.hardware.audio.common@2.0", "android.hardware.audio.common@2.0-util", + "libcutils", ], cflags: [ "-DMAJOR_VERSION=2", @@ -86,6 +87,7 @@ cc_library_shared { "android.hardware.audio@4.0-util", "android.hardware.audio.common@4.0", "android.hardware.audio.common@4.0-util", + "libcutils", ], cflags: [ "-DMAJOR_VERSION=4", @@ -102,6 +104,7 @@ cc_library_shared { "android.hardware.audio@5.0-util", "android.hardware.audio.common@5.0", "android.hardware.audio.common@5.0-util", + "libcutils", ], cflags: [ "-DMAJOR_VERSION=5", @@ -118,6 +121,7 @@ cc_library_shared { "android.hardware.audio@6.0-util", "android.hardware.audio.common@6.0", "android.hardware.audio.common@6.0-util", + "libcutils", ], cflags: [ "-DMAJOR_VERSION=6", @@ -136,6 +140,7 @@ cc_library_shared { "android.hardware.audio.common@7.0-enums", "android.hardware.audio.common@7.0-util", "libbase", + "libcutils", ], cflags: [ "-DMAJOR_VERSION=7", diff --git a/audio/PrimaryDevice.cpp b/audio/PrimaryDevice.cpp index fe56177..6dc634a 100644 --- a/audio/PrimaryDevice.cpp +++ b/audio/PrimaryDevice.cpp @@ -19,6 +19,11 @@ #include "core/default/PrimaryDevice.h" #include "core/default/Util.h" +#include +#include +#include +#include + #if MAJOR_VERSION >= 4 #include #endif @@ -204,6 +209,35 @@ Return PrimaryDevice::setVoiceVolume(float volume) { } Return PrimaryDevice::setMode(AudioMode mode) { + /* On stock ROM Samsung sets the g_call_state and g_call_sim_slot audio parameters + * in the framework, breaking it on AOSP ROMs. For the audio params call_state and + * g_call_state 2 corresponds to CALL_ACTIVE and 1 to CALL_INACTIVE respectively. + * For the g_call_sim_slot parameter 0x01 describes SIM1 and 0x02 SIM2. + */ + + char simSlot[92]; + + // This prop returns either -1 (no SIM is calling), + // 0 (SIM1 is calling) or 1 (SIM2 is calling) + property_get("vendor.calls.slotid", simSlot, ""); + + // Wait until RIL reports which SIM is being used + while (strcmp(simSlot, "-1") == 0 && mode == AudioMode::IN_CALL) { + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + property_get("vendor.calls.slotid", simSlot, ""); + } + + if (strcmp(simSlot, "0") == 0) { + // SIM1 + mDevice->halSetParameters("call_state=2;g_call_state=2;g_call_sim_slot=0x01"); + } else if (strcmp(simSlot, "1") == 0) { + // SIM2 + mDevice->halSetParameters("call_state=2;g_call_state=2;g_call_sim_slot=0x02"); + } else if (strcmp(simSlot, "-1") == 0) { + // No call + mDevice->halSetParameters("call_state=1;g_call_state=1"); + } + // INVALID, CURRENT, CNT, MAX are reserved for internal use. // TODO: remove the values from the HIDL interface switch (mode) { diff --git a/audio/include/core/default/Device.h b/audio/include/core/default/Device.h index 94cad53..4c51609 100644 --- a/audio/include/core/default/Device.h +++ b/audio/include/core/default/Device.h @@ -142,6 +142,8 @@ struct Device : public IDevice, public ParametersUtil { uint32_t version() const { return mDevice->common.version; } + int halSetParameters(const char* keysAndValues) override; + private: bool mIsClosed; audio_hw_device_t* mDevice; @@ -160,7 +162,6 @@ struct Device : public IDevice, public ParametersUtil { // Methods from ParametersUtil. char* halGetParameters(const char* keys) override; - int halSetParameters(const char* keysAndValues) override; }; } // namespace implementation diff --git a/extract-files.sh b/extract-files.sh index ce3cdae..ee34516 100755 --- a/extract-files.sh +++ b/extract-files.sh @@ -63,4 +63,12 @@ BLOB_ROOT="$ANDROID_ROOT"/vendor/"$VENDOR"/"$DEVICE_COMMON"/proprietary # Replace libutils with vndk30 libutils "${PATCHELF}" --replace-needed libutils.so libutils-v30.so $BLOB_ROOT/vendor/lib64/hw/android.hardware.health@2.0-impl-2.1-samsung.so +function blob_fixup() { + case "${1}" in + vendor/lib64/libsec-ril.so) + sed -i 's/ril.dds.call.slotid/vendor.calls.slotid/g' "${2}" + ;; + esac +} + "${MY_DIR}/setup-makefiles.sh" diff --git a/proprietary-files.txt b/proprietary-files.txt index 84142a3..ec1f12f 100644 --- a/proprietary-files.txt +++ b/proprietary-files.txt @@ -978,7 +978,7 @@ vendor/lib64/libnetmgr.so vendor/lib64/libnetmgr_common.so vendor/lib/libqrtr.so vendor/lib64/libqrtr.so -vendor/lib64/libsec-ril.so +vendor/lib64/libsec-ril.so|1d97ef6504c6380466d4ea82b3428f496e4d0ab8 vendor/lib64/libsecril-client.so vendor/lib/libsystem_health_mon.so vendor/lib64/libsystem_health_mon.so diff --git a/sepolicy/vendor/hal_audio_default.te b/sepolicy/vendor/hal_audio_default.te index 81e9192..a819e93 100644 --- a/sepolicy/vendor/hal_audio_default.te +++ b/sepolicy/vendor/hal_audio_default.te @@ -5,3 +5,5 @@ allow hal_audio_default imei_efs_file:dir search; allow hal_audio_default imei_efs_file:file { read open getattr }; allow hal_audio_default efs_file:dir search; + +get_prop(hal_audio_default, vendor_radio_prop) diff --git a/sepolicy/vendor/property_contexts b/sepolicy/vendor/property_contexts index 5aa7a85..fd97af0 100644 --- a/sepolicy/vendor/property_contexts +++ b/sepolicy/vendor/property_contexts @@ -21,6 +21,7 @@ vendor.sec.rild. u:object_r:vendor_radio_prop:s0 ro.vendor.sec.radio. u:object_r:vendor_radio_prop:s0 ro.vendor.use_data_netmgrd u:object_r:vendor_radio_prop:s0 ro.vendor.epdg.support u:object_r:vendor_radio_prop:s0 +vendor.calls.slotid u:object_r:vendor_radio_prop:s0 # Sensors vendor.sensor.file.permission u:object_r:vendor_sensors_prop:s0