From 4ef818a802decb5b03a248470e6c31774bd7e539 Mon Sep 17 00:00:00 2001 From: roynatech2544 Date: Sun, 16 Oct 2022 21:12:11 +0900 Subject: [PATCH] universal7885: aidl-support: Add audio route hal to fake audioserver uid --- .../apps/aidl-support/audio_route/Android.bp | 17 +++++++++ .../1/.hash | 1 + .../hardware/audio_route/IAudioRoute.aidl | 36 +++++++++++++++++++ .../hardware/audio_route/IAudioRoute.aidl | 36 +++++++++++++++++++ .../audio_route/default/Android.bp | 25 +++++++++++++ .../default/AudioRoute.cpp} | 28 +++------------ .../audio_route/default/AudioRoute.h | 27 ++++++++++++++ .../audio_route/default/service.cpp | 35 ++++++++++++++++++ ...dor.eureka.hardware.audio_route-service.rc | 4 +++ .../vendor.eureka.hardware.audio_route.xml | 6 ++++ .../hardware/audio_route/IAudioRoute.aidl | 20 +++++++++++ .../apps/aidl-support/fm/default/Android.bp | 11 +++--- .../aidl-support/fm/default/FMDevControl.cpp | 6 ++-- .../sepolicy/private/file_contexts | 1 + .../private/hal_audio_route_default.te | 10 ++++++ .../sepolicy/private/hal_fmradio_default.te | 4 --- .../sepolicy/private/service_contexts | 1 + 17 files changed, 231 insertions(+), 37 deletions(-) create mode 100644 universal7885-common/apps/aidl-support/audio_route/Android.bp create mode 100644 universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/1/.hash create mode 100644 universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/1/vendor/eureka/hardware/audio_route/IAudioRoute.aidl create mode 100644 universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/current/vendor/eureka/hardware/audio_route/IAudioRoute.aidl create mode 100644 universal7885-common/apps/aidl-support/audio_route/default/Android.bp rename universal7885-common/apps/aidl-support/{fm/default/FMAudioRouteControl.cpp => audio_route/default/AudioRoute.cpp} (61%) create mode 100644 universal7885-common/apps/aidl-support/audio_route/default/AudioRoute.h create mode 100644 universal7885-common/apps/aidl-support/audio_route/default/service.cpp create mode 100644 universal7885-common/apps/aidl-support/audio_route/default/vendor.eureka.hardware.audio_route-service.rc create mode 100644 universal7885-common/apps/aidl-support/audio_route/default/vendor.eureka.hardware.audio_route.xml create mode 100644 universal7885-common/apps/aidl-support/audio_route/vendor/eureka/hardware/audio_route/IAudioRoute.aidl create mode 100644 universal7885-common/sepolicy/private/hal_audio_route_default.te diff --git a/universal7885-common/apps/aidl-support/audio_route/Android.bp b/universal7885-common/apps/aidl-support/audio_route/Android.bp new file mode 100644 index 0000000..95c0234 --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/Android.bp @@ -0,0 +1,17 @@ +aidl_interface { + name: "vendor.eureka.hardware.audio_route", + srcs: ["vendor/eureka/hardware/audio_route/*.aidl"], + stability: "vintf", + backend: { + ndk: { + enabled: true, + }, + }, + versions_with_info: [ + { + version: "1", + imports: [], + }, + ], + +} diff --git a/universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/1/.hash b/universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/1/.hash new file mode 100644 index 0000000..f3b625d --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/1/.hash @@ -0,0 +1 @@ +e5802a2cbeff18d06e61d70381d5f1b65f2448ca diff --git a/universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/1/vendor/eureka/hardware/audio_route/IAudioRoute.aidl b/universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/1/vendor/eureka/hardware/audio_route/IAudioRoute.aidl new file mode 100644 index 0000000..98baa61 --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/1/vendor/eureka/hardware/audio_route/IAudioRoute.aidl @@ -0,0 +1,36 @@ +// Copyright (C) 2022 Eureka Team +// +// 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. +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package vendor.eureka.hardware.audio_route; +@VintfStability +interface IAudioRoute { + oneway void setParam(String param); +} diff --git a/universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/current/vendor/eureka/hardware/audio_route/IAudioRoute.aidl b/universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/current/vendor/eureka/hardware/audio_route/IAudioRoute.aidl new file mode 100644 index 0000000..98baa61 --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/aidl_api/vendor.eureka.hardware.audio_route/current/vendor/eureka/hardware/audio_route/IAudioRoute.aidl @@ -0,0 +1,36 @@ +// Copyright (C) 2022 Eureka Team +// +// 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. +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package vendor.eureka.hardware.audio_route; +@VintfStability +interface IAudioRoute { + oneway void setParam(String param); +} diff --git a/universal7885-common/apps/aidl-support/audio_route/default/Android.bp b/universal7885-common/apps/aidl-support/audio_route/default/Android.bp new file mode 100644 index 0000000..89335c2 --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/default/Android.bp @@ -0,0 +1,25 @@ +cc_binary { + name: "vendor.eureka.hardware.audio_route-service", + srcs: [ + "AudioRoute.cpp", + "service.cpp", + ], + defaults: [ + "eureka_defaults", + ], + shared_libs: [ + "libbase", + "libbinder_ndk", + "liblog", + "libutils", + "audioflinger-aidl-cpp", + "libaudiofoundation", + "libaudioutils", + "libaudioclient", + "libaudiomanager", + "vendor.eureka.hardware.audio_route-V1-ndk", + ], + header_libs: ["libaudioclient_headers"], + init_rc: ["vendor.eureka.hardware.audio_route-service.rc"], + vintf_fragments: ["vendor.eureka.hardware.audio_route.xml"], +} diff --git a/universal7885-common/apps/aidl-support/fm/default/FMAudioRouteControl.cpp b/universal7885-common/apps/aidl-support/audio_route/default/AudioRoute.cpp similarity index 61% rename from universal7885-common/apps/aidl-support/fm/default/FMAudioRouteControl.cpp rename to universal7885-common/apps/aidl-support/audio_route/default/AudioRoute.cpp index 7b6c511..43fcde9 100644 --- a/universal7885-common/apps/aidl-support/fm/default/FMAudioRouteControl.cpp +++ b/universal7885-common/apps/aidl-support/audio_route/default/AudioRoute.cpp @@ -17,34 +17,16 @@ #include #include -#include +#include "AudioRoute.h" -#define FM_FAILURE (-1) -#define FM_SUCCESS 0 #define IOHANDLE 13 using namespace android; -static int audioflinger_exynos7885_forceroute(bool speaker) { +ndk::ScopedAStatus AudioRoute::setParam(std::string param) { const sp &af = AudioSystem::get_audio_flinger(); if (af == 0) - return PERMISSION_DENIED; - if (speaker) { - af->setParameters(IOHANDLE, String8("routing=2")); - } else { - af->setParameters(IOHANDLE, String8("routing=8")); - } - return FM_SUCCESS; -} - -void setAudioFlingerSpeaker(bool enable) { - pid_t pid; - - if ((pid = fork()) < 0) { - return; - } - if (pid == 0) { - setuid(1041); - audioflinger_exynos7885_forceroute(enable); - } + return ndk::ScopedAStatus::fromExceptionCode(EX_SECURITY); + af->setParameters(IOHANDLE, String8(param.c_str())); + return ndk::ScopedAStatus::ok();; } diff --git a/universal7885-common/apps/aidl-support/audio_route/default/AudioRoute.h b/universal7885-common/apps/aidl-support/audio_route/default/AudioRoute.h new file mode 100644 index 0000000..c372b71 --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/default/AudioRoute.h @@ -0,0 +1,27 @@ +// Copyright (C) 2021 Eureka Team +// +// 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. + +#pragma once + +#include + +namespace aidl::vendor::eureka::hardware::audio_route { + +struct AudioRoute : public BnAudioRoute { + public: + AudioRoute() = default; + // Methods from aidl::vendor::eureka::hardware::fmradio::IFMRadio follow. + ::ndk::ScopedAStatus setParam(std::string param) override; +}; +} // namespace aidl::vendor::eureka::hardware::fmradio diff --git a/universal7885-common/apps/aidl-support/audio_route/default/service.cpp b/universal7885-common/apps/aidl-support/audio_route/default/service.cpp new file mode 100644 index 0000000..88d5370 --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/default/service.cpp @@ -0,0 +1,35 @@ +// Copyright (C) 2021 Eureka Team +// +// 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 + +#include "AudioRoute.h" + +using ::aidl::vendor::eureka::hardware::audio_route::AudioRoute; + +int main() { + ABinderProcess_setThreadPoolMaxThreadCount(3); + + auto service = ndk::SharedRefBase::make(); + const std::string instance = std::string() + C::descriptor + "/default"; + binder_status_t status = + AServiceManager_addService(service->asBinder().get(), instance.c_str()); + CHECK(status == STATUS_OK); + LOG(INFO) << "Register done"; + + ABinderProcess_joinThreadPool(); + return -1; // should never get here +} diff --git a/universal7885-common/apps/aidl-support/audio_route/default/vendor.eureka.hardware.audio_route-service.rc b/universal7885-common/apps/aidl-support/audio_route/default/vendor.eureka.hardware.audio_route-service.rc new file mode 100644 index 0000000..e1cfdd5 --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/default/vendor.eureka.hardware.audio_route-service.rc @@ -0,0 +1,4 @@ +service audioroute-hal-aidl /system/bin/vendor.eureka.hardware.audio_route-service + class hal + user audioserver + group audio diff --git a/universal7885-common/apps/aidl-support/audio_route/default/vendor.eureka.hardware.audio_route.xml b/universal7885-common/apps/aidl-support/audio_route/default/vendor.eureka.hardware.audio_route.xml new file mode 100644 index 0000000..d3edc6b --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/default/vendor.eureka.hardware.audio_route.xml @@ -0,0 +1,6 @@ + + + vendor.eureka.hardware.audio_route + IAudioRoute/default + + diff --git a/universal7885-common/apps/aidl-support/audio_route/vendor/eureka/hardware/audio_route/IAudioRoute.aidl b/universal7885-common/apps/aidl-support/audio_route/vendor/eureka/hardware/audio_route/IAudioRoute.aidl new file mode 100644 index 0000000..da0e2bc --- /dev/null +++ b/universal7885-common/apps/aidl-support/audio_route/vendor/eureka/hardware/audio_route/IAudioRoute.aidl @@ -0,0 +1,20 @@ +// Copyright (C) 2022 Eureka Team +// +// 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. + +package vendor.eureka.hardware.audio_route; + +@VintfStability +interface IAudioRoute { + oneway void setParam(String param); +} diff --git a/universal7885-common/apps/aidl-support/fm/default/Android.bp b/universal7885-common/apps/aidl-support/fm/default/Android.bp index 65e131b..1c87ffd 100644 --- a/universal7885-common/apps/aidl-support/fm/default/Android.bp +++ b/universal7885-common/apps/aidl-support/fm/default/Android.bp @@ -8,7 +8,6 @@ cc_binary { srcs: [ "FMSupport.cpp", "FMDevControl.cpp", - "FMAudioRouteControl.cpp", "service.cpp", ], defaults: [ @@ -21,15 +20,13 @@ cc_binary { "libbinder_ndk", "liblog", "libfileio", - "libutils", - "audioflinger-aidl-cpp", - "libaudiofoundation", - "libaudioutils", - "libaudioclient", - "libaudiomanager", "vendor.eureka.hardware.fmradio-V1-ndk", + "vendor.eureka.hardware.audio_route-V1-ndk", ], header_libs: ["libaudioclient_headers"], init_rc: ["vendor.eureka.hardware.fmradio-service.rc"], vintf_fragments: ["vendor.eureka.hardware.fmradio.xml"], + required: [ + "vendor.eureka.hardware.audio_route-service", + ], } diff --git a/universal7885-common/apps/aidl-support/fm/default/FMDevControl.cpp b/universal7885-common/apps/aidl-support/fm/default/FMDevControl.cpp index 7bd784f..1d0ec88 100644 --- a/universal7885-common/apps/aidl-support/fm/default/FMDevControl.cpp +++ b/universal7885-common/apps/aidl-support/fm/default/FMDevControl.cpp @@ -19,8 +19,7 @@ #include #include -// FMAudioRouteControl.cpp -extern void setAudioFlingerSpeaker(bool enable); +#include namespace aidl::vendor::eureka::hardware::fmradio { @@ -85,7 +84,8 @@ static int fd = -1; fm_radio_slsi::stop_search(fd); break; case SetType::SET_TYPE_FM_SPEAKER_ROUTE: - setAudioFlingerSpeaker(value); + auto svc = IAudioRoute::fromBinder(ndk::SpAIBinder(AServiceManager_waitForService("vendor.eureka.hardware.audio_route.IAudioRoute/default"))); + svc->setParam(value ? "routing=2": "routing=8"); break; default: break; diff --git a/universal7885-common/sepolicy/private/file_contexts b/universal7885-common/sepolicy/private/file_contexts index 568cf18..26526ee 100644 --- a/universal7885-common/sepolicy/private/file_contexts +++ b/universal7885-common/sepolicy/private/file_contexts @@ -13,5 +13,6 @@ # FMRadio /system/bin/vendor\.eureka\.hardware\.fmradio-service u:object_r:hal_fmradio_default_exec:s0 +/system/bin/vendor\.eureka\.hardware\.audio_route-service u:object_r:hal_audio_route_default_exec:s0 /dev/radio0 u:object_r:fm_radio_device:s0 diff --git a/universal7885-common/sepolicy/private/hal_audio_route_default.te b/universal7885-common/sepolicy/private/hal_audio_route_default.te new file mode 100644 index 0000000..fe83799 --- /dev/null +++ b/universal7885-common/sepolicy/private/hal_audio_route_default.te @@ -0,0 +1,10 @@ +type hal_audio_route_default, domain, coredomain; +type hal_audio_route_default_exec, exec_type, file_type, system_file_type; + +add_service(hal_audio_route_default, hal_fmradio_service); +init_daemon_domain(hal_audio_route_default); + +binder_use(hal_audio_route_default); + +binder_call(hal_audio_route_default, audioserver) +binder_call(audioserver, hal_audio_route_default) diff --git a/universal7885-common/sepolicy/private/hal_fmradio_default.te b/universal7885-common/sepolicy/private/hal_fmradio_default.te index 4112459..e3b88d7 100644 --- a/universal7885-common/sepolicy/private/hal_fmradio_default.te +++ b/universal7885-common/sepolicy/private/hal_fmradio_default.te @@ -12,7 +12,3 @@ allow hal_fmradio_default sysfs_fmradio_tune:dir search; allow hal_fmradio_default sysfs_virtual:dir search; allow hal_fmradio_default fm_radio_device:chr_file { read write open ioctl }; -allow hal_fmradio_default self:capability setuid; - -binder_call(hal_fmradio_default, audioserver) -binder_call(audioserver, hal_fmradio_default) diff --git a/universal7885-common/sepolicy/private/service_contexts b/universal7885-common/sepolicy/private/service_contexts index 50d04b3..952f639 100644 --- a/universal7885-common/sepolicy/private/service_contexts +++ b/universal7885-common/sepolicy/private/service_contexts @@ -8,3 +8,4 @@ vendor.eureka.hardware.parts.ISmartCharge/default u:object_r:hal_parts_service:s # FMRadio vendor.eureka.hardware.fmradio.IFMDevControl/default u:object_r:hal_fmradio_service:s0 vendor.eureka.hardware.fmradio.IFMDevControl/support u:object_r:hal_fmradio_service:s0 +vendor.eureka.hardware.audio_route.IAudioRoute/default u:object_r:hal_audio_route_service:s0