Loading services/audioflinger/AudioFlinger.cpp +0 −43 Original line number Diff line number Diff line Loading @@ -148,21 +148,6 @@ static void sMediaLogInit() } } // Keep a strong reference to external vibrator service static sp<os::IExternalVibratorService> sExternalVibratorService; static sp<os::IExternalVibratorService> getExternalVibratorService() { if (sExternalVibratorService == 0) { sp<IBinder> binder = defaultServiceManager()->getService( String16("external_vibrator_service")); if (binder != 0) { sExternalVibratorService = interface_cast<os::IExternalVibratorService>(binder); } } return sExternalVibratorService; } // Creates association between Binder code to name for IAudioFlinger. #define IAUDIOFLINGER_BINDER_METHOD_MACRO_LIST \ BINDER_METHOD_ENTRY(createTrack) \ Loading Loading @@ -675,34 +660,6 @@ status_t AudioFlinger::openMmapStream(MmapStreamInterface::stream_direction_t di return ret; } /* static */ os::HapticScale AudioFlinger::onExternalVibrationStart( const sp<os::ExternalVibration>& externalVibration) { sp<os::IExternalVibratorService> evs = getExternalVibratorService(); if (evs != nullptr) { int32_t ret; binder::Status status = evs->onExternalVibrationStart(*externalVibration, &ret); if (status.isOk()) { ALOGD("%s, start external vibration with intensity as %d", __func__, ret); return os::ExternalVibration::externalVibrationScaleToHapticScale(ret); } } ALOGD("%s, start external vibration with intensity as MUTE due to %s", __func__, evs == nullptr ? "external vibration service not found" : "error when querying intensity"); return os::HapticScale::MUTE; } /* static */ void AudioFlinger::onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration) { sp<os::IExternalVibratorService> evs = getExternalVibratorService(); if (evs != 0) { ALOGD("%s, stopping external vibration", __func__); evs->onExternalVibrationStop(*externalVibration); } } status_t AudioFlinger::addEffectToHal( const struct audio_port_config *device, const sp<EffectHalInterface>& effect) { AutoMutex lock(mHardwareLock); Loading services/audioflinger/AudioFlinger.h +0 −5 Original line number Diff line number Diff line Loading @@ -480,11 +480,6 @@ public: const sp<MmapStreamCallback>& callback, sp<MmapStreamInterface>& interface, audio_port_handle_t *handle); static os::HapticScale onExternalVibrationStart( const sp<os::ExternalVibration>& externalVibration); static void onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration); private: // FIXME The 400 is temporarily too high until a leak of writers in media.log is fixed. static const size_t kLogMemorySize = 400 * 1024; Loading services/audioflinger/Threads.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -97,6 +97,7 @@ #include <afutils/DumpTryLock.h> #include <afutils/Permission.h> #include <afutils/TypedLogger.h> #include <afutils/Vibrator.h> // ---------------------------------------------------------------------------- Loading Loading @@ -2838,7 +2839,7 @@ NO_THREAD_SAFETY_ANALYSIS // release and re-acquire mLock // Unlock due to VibratorService will lock for this call and will // call Tracks.mute/unmute which also require thread's lock. mLock.unlock(); const os::HapticScale intensity = AudioFlinger::onExternalVibrationStart( const os::HapticScale intensity = afutils::onExternalVibrationStart( track->getExternalVibration()); std::optional<media::AudioVibratorInfo> vibratorInfo; { Loading Loading @@ -4655,7 +4656,7 @@ NO_THREAD_SAFETY_ANALYSIS // release and re-acquire mLock mLock.unlock(); // Unlock due to VibratorService will lock for this call and will // call Tracks.mute/unmute which also require thread's lock. AudioFlinger::onExternalVibrationStop(track->getExternalVibration()); afutils::onExternalVibrationStop(track->getExternalVibration()); mLock.lock(); // When the track is stop, set the haptic intensity as MUTE Loading services/audioflinger/afutils/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ cc_library { "Permission.cpp", "PropertyUtils.cpp", "TypedLogger.cpp", "Vibrator.cpp", ], shared_libs: [ Loading @@ -55,6 +56,7 @@ cc_library { "libnbaio", "libnblog", "libutils", "libvibrator", ], static_libs: [ Loading services/audioflinger/afutils/Vibrator.cpp 0 → 100644 +71 −0 Original line number Diff line number Diff line /* * * Copyright 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. */ #define LOG_TAG "AudioFlinger::Vibrator" //#define LOG_NDEBUG 0 #include "Vibrator.h" #include <android/os/IExternalVibratorService.h> #include <binder/IServiceManager.h> #include <utils/Log.h> #include <mutex> namespace android::afutils { static sp<os::IExternalVibratorService> getExternalVibratorService() { static std::mutex m; static sp<os::IExternalVibratorService> sExternalVibratorService; std::lock_guard l(m); if (sExternalVibratorService == nullptr) { const sp<IBinder> binder = defaultServiceManager()->getService( String16("external_vibrator_service")); if (binder != nullptr) { sExternalVibratorService = interface_cast<os::IExternalVibratorService>(binder); } } return sExternalVibratorService; } os::HapticScale onExternalVibrationStart(const sp<os::ExternalVibration>& externalVibration) { const sp<os::IExternalVibratorService> evs = getExternalVibratorService(); if (evs != nullptr) { int32_t ret; binder::Status status = evs->onExternalVibrationStart(*externalVibration, &ret); if (status.isOk()) { ALOGD("%s, start external vibration with intensity as %d", __func__, ret); return os::ExternalVibration::externalVibrationScaleToHapticScale(ret); } } ALOGD("%s, start external vibration with intensity as MUTE due to %s", __func__, evs == nullptr ? "external vibration service not found" : "error when querying intensity"); return os::HapticScale::MUTE; } void onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration) { const sp<os::IExternalVibratorService> evs = getExternalVibratorService(); if (evs != nullptr) { ALOGD("%s, stop external vibration", __func__); evs->onExternalVibrationStop(*externalVibration); } } } // namespace android::afutils Loading
services/audioflinger/AudioFlinger.cpp +0 −43 Original line number Diff line number Diff line Loading @@ -148,21 +148,6 @@ static void sMediaLogInit() } } // Keep a strong reference to external vibrator service static sp<os::IExternalVibratorService> sExternalVibratorService; static sp<os::IExternalVibratorService> getExternalVibratorService() { if (sExternalVibratorService == 0) { sp<IBinder> binder = defaultServiceManager()->getService( String16("external_vibrator_service")); if (binder != 0) { sExternalVibratorService = interface_cast<os::IExternalVibratorService>(binder); } } return sExternalVibratorService; } // Creates association between Binder code to name for IAudioFlinger. #define IAUDIOFLINGER_BINDER_METHOD_MACRO_LIST \ BINDER_METHOD_ENTRY(createTrack) \ Loading Loading @@ -675,34 +660,6 @@ status_t AudioFlinger::openMmapStream(MmapStreamInterface::stream_direction_t di return ret; } /* static */ os::HapticScale AudioFlinger::onExternalVibrationStart( const sp<os::ExternalVibration>& externalVibration) { sp<os::IExternalVibratorService> evs = getExternalVibratorService(); if (evs != nullptr) { int32_t ret; binder::Status status = evs->onExternalVibrationStart(*externalVibration, &ret); if (status.isOk()) { ALOGD("%s, start external vibration with intensity as %d", __func__, ret); return os::ExternalVibration::externalVibrationScaleToHapticScale(ret); } } ALOGD("%s, start external vibration with intensity as MUTE due to %s", __func__, evs == nullptr ? "external vibration service not found" : "error when querying intensity"); return os::HapticScale::MUTE; } /* static */ void AudioFlinger::onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration) { sp<os::IExternalVibratorService> evs = getExternalVibratorService(); if (evs != 0) { ALOGD("%s, stopping external vibration", __func__); evs->onExternalVibrationStop(*externalVibration); } } status_t AudioFlinger::addEffectToHal( const struct audio_port_config *device, const sp<EffectHalInterface>& effect) { AutoMutex lock(mHardwareLock); Loading
services/audioflinger/AudioFlinger.h +0 −5 Original line number Diff line number Diff line Loading @@ -480,11 +480,6 @@ public: const sp<MmapStreamCallback>& callback, sp<MmapStreamInterface>& interface, audio_port_handle_t *handle); static os::HapticScale onExternalVibrationStart( const sp<os::ExternalVibration>& externalVibration); static void onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration); private: // FIXME The 400 is temporarily too high until a leak of writers in media.log is fixed. static const size_t kLogMemorySize = 400 * 1024; Loading
services/audioflinger/Threads.cpp +3 −2 Original line number Diff line number Diff line Loading @@ -97,6 +97,7 @@ #include <afutils/DumpTryLock.h> #include <afutils/Permission.h> #include <afutils/TypedLogger.h> #include <afutils/Vibrator.h> // ---------------------------------------------------------------------------- Loading Loading @@ -2838,7 +2839,7 @@ NO_THREAD_SAFETY_ANALYSIS // release and re-acquire mLock // Unlock due to VibratorService will lock for this call and will // call Tracks.mute/unmute which also require thread's lock. mLock.unlock(); const os::HapticScale intensity = AudioFlinger::onExternalVibrationStart( const os::HapticScale intensity = afutils::onExternalVibrationStart( track->getExternalVibration()); std::optional<media::AudioVibratorInfo> vibratorInfo; { Loading Loading @@ -4655,7 +4656,7 @@ NO_THREAD_SAFETY_ANALYSIS // release and re-acquire mLock mLock.unlock(); // Unlock due to VibratorService will lock for this call and will // call Tracks.mute/unmute which also require thread's lock. AudioFlinger::onExternalVibrationStop(track->getExternalVibration()); afutils::onExternalVibrationStop(track->getExternalVibration()); mLock.lock(); // When the track is stop, set the haptic intensity as MUTE Loading
services/audioflinger/afutils/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ cc_library { "Permission.cpp", "PropertyUtils.cpp", "TypedLogger.cpp", "Vibrator.cpp", ], shared_libs: [ Loading @@ -55,6 +56,7 @@ cc_library { "libnbaio", "libnblog", "libutils", "libvibrator", ], static_libs: [ Loading
services/audioflinger/afutils/Vibrator.cpp 0 → 100644 +71 −0 Original line number Diff line number Diff line /* * * Copyright 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. */ #define LOG_TAG "AudioFlinger::Vibrator" //#define LOG_NDEBUG 0 #include "Vibrator.h" #include <android/os/IExternalVibratorService.h> #include <binder/IServiceManager.h> #include <utils/Log.h> #include <mutex> namespace android::afutils { static sp<os::IExternalVibratorService> getExternalVibratorService() { static std::mutex m; static sp<os::IExternalVibratorService> sExternalVibratorService; std::lock_guard l(m); if (sExternalVibratorService == nullptr) { const sp<IBinder> binder = defaultServiceManager()->getService( String16("external_vibrator_service")); if (binder != nullptr) { sExternalVibratorService = interface_cast<os::IExternalVibratorService>(binder); } } return sExternalVibratorService; } os::HapticScale onExternalVibrationStart(const sp<os::ExternalVibration>& externalVibration) { const sp<os::IExternalVibratorService> evs = getExternalVibratorService(); if (evs != nullptr) { int32_t ret; binder::Status status = evs->onExternalVibrationStart(*externalVibration, &ret); if (status.isOk()) { ALOGD("%s, start external vibration with intensity as %d", __func__, ret); return os::ExternalVibration::externalVibrationScaleToHapticScale(ret); } } ALOGD("%s, start external vibration with intensity as MUTE due to %s", __func__, evs == nullptr ? "external vibration service not found" : "error when querying intensity"); return os::HapticScale::MUTE; } void onExternalVibrationStop(const sp<os::ExternalVibration>& externalVibration) { const sp<os::IExternalVibratorService> evs = getExternalVibratorService(); if (evs != nullptr) { ALOGD("%s, stop external vibration", __func__); evs->onExternalVibrationStop(*externalVibration); } } } // namespace android::afutils