Title: [279119] trunk/Source/WebCore
- Revision
- 279119
- Author
- [email protected]
- Date
- 2021-06-22 09:17:45 -0700 (Tue, 22 Jun 2021)
Log Message
[Cocoa] iOS device steals BT headphones from other devices during silent playback
https://bugs.webkit.org/show_bug.cgi?id=227227
<rdar://78792479>
Reviewed by Eric Carlson.
Source/WebCore:
Explicitly disable smart routing when WebKit itself does not explicitly activate its AVAudioSession.
The audio session will be implicitly activated even for audio-less or silent media playback, and
this will prevent headsets from being "stolen" when that session is implicitly activated.
* platform/audio/ios/AudioSessionIOS.h:
* platform/audio/ios/AudioSessionIOS.mm:
(WebCore::setEligibleForSmartRouting):
(WebCore::AudioSessionIOS::AudioSessionIOS):
(WebCore::AudioSessionIOS::tryToSetActiveInternal):
Source/WebCore/PAL:
* pal/spi/cocoa/AVFoundationSPI.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (279118 => 279119)
--- trunk/Source/WebCore/ChangeLog 2021-06-22 16:16:18 UTC (rev 279118)
+++ trunk/Source/WebCore/ChangeLog 2021-06-22 16:17:45 UTC (rev 279119)
@@ -1,3 +1,21 @@
+2021-06-22 Jer Noble <[email protected]>
+
+ [Cocoa] iOS device steals BT headphones from other devices during silent playback
+ https://bugs.webkit.org/show_bug.cgi?id=227227
+ <rdar://78792479>
+
+ Reviewed by Eric Carlson.
+
+ Explicitly disable smart routing when WebKit itself does not explicitly activate its AVAudioSession.
+ The audio session will be implicitly activated even for audio-less or silent media playback, and
+ this will prevent headsets from being "stolen" when that session is implicitly activated.
+
+ * platform/audio/ios/AudioSessionIOS.h:
+ * platform/audio/ios/AudioSessionIOS.mm:
+ (WebCore::setEligibleForSmartRouting):
+ (WebCore::AudioSessionIOS::AudioSessionIOS):
+ (WebCore::AudioSessionIOS::tryToSetActiveInternal):
+
2021-06-22 Rob Buis <[email protected]>
Make rendererIsEverNeeded check less strict
Modified: trunk/Source/WebCore/PAL/ChangeLog (279118 => 279119)
--- trunk/Source/WebCore/PAL/ChangeLog 2021-06-22 16:16:18 UTC (rev 279118)
+++ trunk/Source/WebCore/PAL/ChangeLog 2021-06-22 16:17:45 UTC (rev 279119)
@@ -1,3 +1,13 @@
+2021-06-22 Jer Noble <[email protected]>
+
+ [Cocoa] iOS device steals BT headphones from other devices during silent playback
+ https://bugs.webkit.org/show_bug.cgi?id=227227
+ <rdar://78792479>
+
+ Reviewed by Eric Carlson.
+
+ * pal/spi/cocoa/AVFoundationSPI.h:
+
2021-06-20 Wenson Hsieh <[email protected]>
[macOS] Rename WKVisualSearchPreviewController to WKQuickLookPreviewController
Modified: trunk/Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h (279118 => 279119)
--- trunk/Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h 2021-06-22 16:16:18 UTC (rev 279118)
+++ trunk/Source/WebCore/PAL/pal/spi/cocoa/AVFoundationSPI.h 2021-06-22 16:17:45 UTC (rev 279119)
@@ -393,6 +393,8 @@
@interface AVAudioSession (AVAudioSessionPrivate)
- (instancetype)initAuxiliarySession;
@property (readonly) NSString* routingContextUID;
+@property (readonly) BOOL eligibleForBTSmartRoutingConsideration;
+- (BOOL)setEligibleForBTSmartRoutingConsideration:(BOOL)inValue error:(NSError **)outError;
@end
NS_ASSUME_NONNULL_END
Modified: trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.h (279118 => 279119)
--- trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.h 2021-06-22 16:16:18 UTC (rev 279118)
+++ trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.h 2021-06-22 16:17:45 UTC (rev 279119)
@@ -65,7 +65,7 @@
void endInterruption(MayResume) final;
AudioSession::CategoryType m_categoryOverride { AudioSession::CategoryType::None };
- RefPtr<WTF::WorkQueue> m_workQueue;
+ Ref<WTF::WorkQueue> m_workQueue;
RetainPtr<WebInterruptionObserverHelper> m_interruptionObserverHelper;
};
Modified: trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm (279118 => 279119)
--- trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm 2021-06-22 16:16:18 UTC (rev 279118)
+++ trunk/Source/WebCore/platform/audio/ios/AudioSessionIOS.mm 2021-06-22 16:17:45 UTC (rev 279119)
@@ -96,11 +96,34 @@
namespace WebCore {
+static void setEligibleForSmartRouting(bool eligible)
+{
+ ASSERT(!isMainThread());
+
+ auto *session = [PAL::getAVAudioSessionClass() sharedInstance];
+ if (![session respondsToSelector:@selector(setEligibleForBTSmartRoutingConsideration:error:)]
+ || ![session respondsToSelector:@selector(eligibleForBTSmartRoutingConsideration)])
+ return;
+
+ if (session.eligibleForBTSmartRoutingConsideration == eligible)
+ return;
+
+ NSError *error = nil;
+ if (![session setEligibleForBTSmartRoutingConsideration:eligible error:&error])
+ RELEASE_LOG_ERROR(Media, "failed to set eligible to %d with error: %@", eligible, error.localizedDescription);
+}
+
AudioSessionIOS::AudioSessionIOS()
+ : m_workQueue(WorkQueue::create("AudioSession Activation Queue"))
{
BEGIN_BLOCK_OBJC_EXCEPTIONS
m_interruptionObserverHelper = adoptNS([[WebInterruptionObserverHelper alloc] initWithCallback:this]);
END_BLOCK_OBJC_EXCEPTIONS
+
+ m_workQueue->dispatch([] {
+ setEligibleForSmartRouting(false);
+ });
+
}
AudioSessionIOS::~AudioSessionIOS()
@@ -240,9 +263,6 @@
bool AudioSessionIOS::tryToSetActiveInternal(bool active)
{
- if (!m_workQueue)
- m_workQueue = WorkQueue::create("AudioSession Activation Queue");
-
// We need to deactivate the session on another queue because the AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation option
// means that AVAudioSession may synchronously unduck previously ducked clients. Activation needs to complete before this method
// returns, so do it synchronously on the same serial queue.
@@ -250,6 +270,7 @@
bool success = false;
m_workQueue->dispatchSync([&success] {
NSError *error = nil;
+ setEligibleForSmartRouting(true);
[[PAL::getAVAudioSessionClass() sharedInstance] setActive:YES withOptions:0 error:&error];
success = !error;
});
@@ -259,6 +280,7 @@
m_workQueue->dispatch([] {
NSError *error = nil;
[[PAL::getAVAudioSessionClass() sharedInstance] setActive:NO withOptions:0 error:&error];
+ setEligibleForSmartRouting(false);
});
return true;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes