From 805dbb836a238d6a52ccace511bf4fe0239b78c8 Mon Sep 17 00:00:00 2001 From: Simon1511 Date: Wed, 1 Nov 2023 13:02:37 +0100 Subject: [PATCH] sm7125-common: audio: add dedicated service to pass g_call_sim_slot This is a partial revert of c31482154b32f70963c909f2cff590282c30cf68 Change-Id: Ibba1b588ee5836e8f51dfdb96231da66d7f3b09a --- BoardConfigCommon.mk | 4 +- audio/impl/Android.bp | 6 --- audio/impl/PrimaryDevice.cpp | 34 ------------ audio/impl/include/core/default/Device.h | 3 +- audio/service/Android.bp | 30 +++++++++++ audio/service/audio_parameter_service.cpp | 58 +++++++++++++++++++++ audio/service/audio_parameter_service.rc | 19 +++++++ common.mk | 3 +- sepolicy/private/audio_parameter_service.te | 9 ++++ sepolicy/private/file_contexts | 1 + sepolicy/public/property.te | 1 + sepolicy/vendor/hal_audio_default.te | 2 +- sepolicy/vendor/property_contexts | 3 +- sepolicy/vendor/rild.te | 3 ++ 14 files changed, 129 insertions(+), 47 deletions(-) create mode 100644 audio/service/Android.bp create mode 100644 audio/service/audio_parameter_service.cpp create mode 100644 audio/service/audio_parameter_service.rc create mode 100644 sepolicy/private/audio_parameter_service.te create mode 100644 sepolicy/private/file_contexts create mode 100644 sepolicy/public/property.te diff --git a/BoardConfigCommon.mk b/BoardConfigCommon.mk index e19a0d0..4d4f098 100644 --- a/BoardConfigCommon.mk +++ b/BoardConfigCommon.mk @@ -219,8 +219,8 @@ TARGET_RELEASETOOLS_EXTENSIONS := $(COMMON_PATH)/releasetools # SePolicy include device/qcom/sepolicy_vndr/SEPolicy.mk BOARD_VENDOR_SEPOLICY_DIRS += $(COMMON_PATH)/sepolicy/vendor -PRODUCT_PRIVATE_SEPOLICY_DIRS += $(COMMON_PATH)/sepolicy/private -PRODUCT_PUBLIC_SEPOLICY_DIRS += $(COMMON_PATH)/sepolicy/public +SYSTEM_EXT_PRIVATE_SEPOLICY_DIRS += $(COMMON_PATH)/sepolicy/private +SYSTEM_EXT_PUBLIC_SEPOLICY_DIRS += $(COMMON_PATH)/sepolicy/public # Vibrator $(call soong_config_set,samsungVibratorVars,duration_amplitude,true) diff --git a/audio/impl/Android.bp b/audio/impl/Android.bp index 297c747..daf358d 100644 --- a/audio/impl/Android.bp +++ b/audio/impl/Android.bp @@ -68,7 +68,6 @@ 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,7 +85,6 @@ 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", @@ -103,7 +101,6 @@ 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", @@ -120,7 +117,6 @@ 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", @@ -139,7 +135,6 @@ cc_library_shared { "android.hardware.audio.common@7.0-enums", "android.hardware.audio.common@7.0-util", "libbase", - "libcutils", ], cflags: [ "-DMAJOR_VERSION=7", @@ -159,7 +154,6 @@ cc_library_shared { "android.hardware.audio.common@7.1-enums", "android.hardware.audio.common@7.1-util", "libbase", - "libcutils", ], cflags: [ "-DMAJOR_VERSION=7", diff --git a/audio/impl/PrimaryDevice.cpp b/audio/impl/PrimaryDevice.cpp index fdd6cdd..cf162f1 100644 --- a/audio/impl/PrimaryDevice.cpp +++ b/audio/impl/PrimaryDevice.cpp @@ -19,11 +19,6 @@ #include "core/default/PrimaryDevice.h" #include "core/default/Util.h" -#include -#include -#include -#include - #if MAJOR_VERSION >= 4 #include #endif @@ -213,35 +208,6 @@ 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/impl/include/core/default/Device.h b/audio/impl/include/core/default/Device.h index f0e7afd..0696f97 100644 --- a/audio/impl/include/core/default/Device.h +++ b/audio/impl/include/core/default/Device.h @@ -173,8 +173,6 @@ 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; @@ -193,6 +191,7 @@ 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/audio/service/Android.bp b/audio/service/Android.bp new file mode 100644 index 0000000..edc370e --- /dev/null +++ b/audio/service/Android.bp @@ -0,0 +1,30 @@ +// +// Copyright (C) 2023 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +cc_binary { + name: "audio_parameter_service.samsung_sm7125", + init_rc: ["audio_parameter_service.rc"], + system_ext_specific: true, + srcs: [ + "audio_parameter_service.cpp", + ], + shared_libs: [ + "libbase", + "libutils", + "libhidlbase", + "liblog", + "android.hardware.audio@7.0", + ], +} diff --git a/audio/service/audio_parameter_service.cpp b/audio/service/audio_parameter_service.cpp new file mode 100644 index 0000000..03c7054 --- /dev/null +++ b/audio/service/audio_parameter_service.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2023 The LineageOS Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +using android::base::GetProperty; +using android::base::SetProperty; +using android::sp; +using ::android::hardware::hidl_string; + +int main() { + sp<::android::hardware::audio::V7_0::IDevice> audioDevice; + + LOG(DEBUG) << "Passing g_call_sim_slot parameter"; + + if (!audioDevice) { + ::android::hardware::audio::V7_0::IDevicesFactory::getService()->openDevice( + "primary", [&](::android::hardware::audio::V7_0::Result, const sp<::android::hardware::audio::V7_0::IDevice>& result) { + audioDevice = result; + }); + } + + if (audioDevice != nullptr) { + std::string value = ""; + + if (strcmp(GetProperty("vendor.calls.slotid", "-1").c_str(), "0") == 0) { + // SIM 1 + value = "0x01"; + } else if (strcmp(GetProperty("vendor.calls.slotid", "-1").c_str(), "1") == 0) { + // SIM 2 + value = "0x02"; + } + + audioDevice->setParameters({}, {{"g_call_sim_slot", value}}); + } + + if (audioDevice != nullptr) + audioDevice->close(); + + SetProperty("vendor.calls.parameter_state", "1"); + + return 0; +} diff --git a/audio/service/audio_parameter_service.rc b/audio/service/audio_parameter_service.rc new file mode 100644 index 0000000..35f8357 --- /dev/null +++ b/audio/service/audio_parameter_service.rc @@ -0,0 +1,19 @@ +service audio_parameter_service /system_ext/bin/audio_parameter_service.samsung_sm7125 + oneshot + disabled + +on boot + setprop vendor.calls.parameter_state 0 + +on property:vendor.calls.slotid=0 && property:vendor.calls.parameter_state=0 + stop audioserver + start audioserver + start audio_parameter_service + +on property:vendor.calls.slotid=1 && property:vendor.calls.parameter_state=0 + stop audioserver + start audioserver + start audio_parameter_service + +on property:vendor.calls.slotid=-1 && property:vendor.calls.parameter_state=1 + setprop vendor.calls.parameter_state 0 diff --git a/common.mk b/common.mk index 432e817..af67469 100644 --- a/common.mk +++ b/common.mk @@ -76,7 +76,8 @@ PRODUCT_PACKAGES += \ libqcomvisualizer \ libqcomvoiceprocessing \ libqcompostprocbundle \ - libvolumelistener + libvolumelistener \ + audio_parameter_service.samsung_sm7125 TARGET_EXCLUDES_AUDIOFX := true diff --git a/sepolicy/private/audio_parameter_service.te b/sepolicy/private/audio_parameter_service.te new file mode 100644 index 0000000..3d3c8ec --- /dev/null +++ b/sepolicy/private/audio_parameter_service.te @@ -0,0 +1,9 @@ +type audio_parameter_service, domain, coredomain; +type audio_parameter_service_exec, system_file_type, exec_type, file_type; + +init_daemon_domain(audio_parameter_service) + +hal_client_domain(audio_parameter_service, hal_audio) + +get_prop(audio_parameter_service, vendor_call_prop) +set_prop(audio_parameter_service, vendor_call_prop) diff --git a/sepolicy/private/file_contexts b/sepolicy/private/file_contexts new file mode 100644 index 0000000..9dfd308 --- /dev/null +++ b/sepolicy/private/file_contexts @@ -0,0 +1 @@ +/(system_ext|system/system_ext)/bin/audio_parameter_service.samsung_sm7125 u:object_r:audio_parameter_service_exec:s0 diff --git a/sepolicy/public/property.te b/sepolicy/public/property.te new file mode 100644 index 0000000..1ca4b02 --- /dev/null +++ b/sepolicy/public/property.te @@ -0,0 +1 @@ +system_public_prop(vendor_call_prop) diff --git a/sepolicy/vendor/hal_audio_default.te b/sepolicy/vendor/hal_audio_default.te index 28b8882..6592d9e 100644 --- a/sepolicy/vendor/hal_audio_default.te +++ b/sepolicy/vendor/hal_audio_default.te @@ -6,4 +6,4 @@ 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) \ No newline at end of file +get_prop(hal_audio_default, vendor_call_prop) diff --git a/sepolicy/vendor/property_contexts b/sepolicy/vendor/property_contexts index ba633e7..3101192 100644 --- a/sepolicy/vendor/property_contexts +++ b/sepolicy/vendor/property_contexts @@ -22,7 +22,8 @@ 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 u:object_r:vendor_radio_prop:s0 + +vendor.calls u:object_r:vendor_call_prop:s0 # Sensors vendor.sensor.file.permission u:object_r:vendor_sensors_prop:s0 diff --git a/sepolicy/vendor/rild.te b/sepolicy/vendor/rild.te index 873bdec..7f87c2b 100644 --- a/sepolicy/vendor/rild.te +++ b/sepolicy/vendor/rild.te @@ -3,6 +3,9 @@ get_prop(rild, vendor_radio_prop) get_prop(rild, radio_prop) +set_prop(rild, vendor_call_prop) +get_prop(rild, vendor_call_prop) + allow rild block_device:dir search; allow rild mnt_vendor_file:dir { getattr search };