react-native-audio-browser 0.2.0-next.53 → 0.2.0-next.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (599) hide show
  1. package/README.md +32 -19
  2. package/android/src/cast/java/com/audiobrowser/cast/CastSupport.kt +8 -10
  3. package/android/src/main/java/com/audiobrowser/AudioBrowser.kt +96 -243
  4. package/android/src/main/java/com/audiobrowser/AudioBrowserLifecycleModule.kt +8 -12
  5. package/android/src/main/java/com/audiobrowser/AudioBrowserPackage.kt +1 -3
  6. package/android/src/main/java/com/audiobrowser/Callbacks.kt +1 -10
  7. package/android/src/main/java/com/audiobrowser/ForegroundStart.kt +13 -18
  8. package/android/src/main/java/com/audiobrowser/HeadlessTaskService.kt +3 -7
  9. package/android/src/main/java/com/audiobrowser/RemoteOutputs.kt +8 -10
  10. package/android/src/main/java/com/audiobrowser/Service.kt +20 -61
  11. package/android/src/main/java/com/audiobrowser/ServiceBinding.kt +9 -17
  12. package/android/src/main/java/com/audiobrowser/browser/ArtworkResolutionRegistry.kt +10 -9
  13. package/android/src/main/java/com/audiobrowser/browser/BrowseArtworkRegistry.kt +11 -8
  14. package/android/src/main/java/com/audiobrowser/browser/BrowserManager.kt +117 -448
  15. package/android/src/main/java/com/audiobrowser/browser/BrowserUrlResolution.kt +21 -60
  16. package/android/src/main/java/com/audiobrowser/browser/InertStyleDiagnostic.kt +20 -80
  17. package/android/src/main/java/com/audiobrowser/browser/JsonArtwork.kt +6 -10
  18. package/android/src/main/java/com/audiobrowser/browser/JsonModels.kt +7 -24
  19. package/android/src/main/java/com/audiobrowser/browser/RouteMatch.kt +2 -4
  20. package/android/src/main/java/com/audiobrowser/browser/SectionScope.kt +13 -31
  21. package/android/src/main/java/com/audiobrowser/browser/SimpleRouter.kt +12 -40
  22. package/android/src/main/java/com/audiobrowser/browser/StyleResolver.kt +15 -26
  23. package/android/src/main/java/com/audiobrowser/browser/TrackLoadHandler.kt +5 -15
  24. package/android/src/main/java/com/audiobrowser/extension/EnumExtensions.kt +1 -0
  25. package/android/src/main/java/com/audiobrowser/extension/NumberExt.kt +2 -0
  26. package/android/src/main/java/com/audiobrowser/extension/ResolvedTrackExt.kt +4 -8
  27. package/android/src/main/java/com/audiobrowser/extension/TappedTrack.kt +4 -6
  28. package/android/src/main/java/com/audiobrowser/extension/TrackIdentity.kt +3 -7
  29. package/android/src/main/java/com/audiobrowser/http/HttpClient.kt +13 -22
  30. package/android/src/main/java/com/audiobrowser/http/RequestConfigBuilder.kt +17 -38
  31. package/android/src/main/java/com/audiobrowser/model/IcyTitle.kt +5 -6
  32. package/android/src/main/java/com/audiobrowser/model/PlaybackMetadata.kt +4 -9
  33. package/android/src/main/java/com/audiobrowser/model/PlayerSetupOptions.kt +18 -29
  34. package/android/src/main/java/com/audiobrowser/model/PlayerUpdateOptions.kt +6 -16
  35. package/android/src/main/java/com/audiobrowser/player/AutomaticBufferManager.kt +15 -45
  36. package/android/src/main/java/com/audiobrowser/player/CapabilityControls.kt +23 -59
  37. package/android/src/main/java/com/audiobrowser/player/CrossOriginHeaderStripper.kt +14 -26
  38. package/android/src/main/java/com/audiobrowser/player/DynamicLoadControl.kt +15 -43
  39. package/android/src/main/java/com/audiobrowser/player/EnginePlayback.kt +4 -4
  40. package/android/src/main/java/com/audiobrowser/player/EqualizerController.kt +15 -21
  41. package/android/src/main/java/com/audiobrowser/player/InterceptingPlayer.kt +14 -31
  42. package/android/src/main/java/com/audiobrowser/player/LocalEngine.kt +8 -8
  43. package/android/src/main/java/com/audiobrowser/player/MediaFactory.kt +16 -27
  44. package/android/src/main/java/com/audiobrowser/player/MediaSessionCallback.kt +119 -237
  45. package/android/src/main/java/com/audiobrowser/player/MediaSessionCommandManager.kt +48 -145
  46. package/android/src/main/java/com/audiobrowser/player/NowPlayingUpdater.kt +39 -100
  47. package/android/src/main/java/com/audiobrowser/player/PlaybackErrorClassifier.kt +16 -26
  48. package/android/src/main/java/com/audiobrowser/player/PlaybackStateMachine.kt +22 -28
  49. package/android/src/main/java/com/audiobrowser/player/PlaybackStateStore.kt +28 -64
  50. package/android/src/main/java/com/audiobrowser/player/PlaybackTimer.kt +8 -4
  51. package/android/src/main/java/com/audiobrowser/player/Player.kt +117 -405
  52. package/android/src/main/java/com/audiobrowser/player/PlayerCapabilitiesExt.kt +1 -1
  53. package/android/src/main/java/com/audiobrowser/player/PlayerEngineFactory.kt +11 -19
  54. package/android/src/main/java/com/audiobrowser/player/PlayerListener.kt +30 -96
  55. package/android/src/main/java/com/audiobrowser/player/RetryLoadErrorHandlingPolicy.kt +39 -95
  56. package/android/src/main/java/com/audiobrowser/player/ShuffleOrderLedBy.kt +7 -13
  57. package/android/src/main/java/com/audiobrowser/player/SleepTimer.kt +13 -30
  58. package/android/src/main/java/com/audiobrowser/player/SleepTimerManager.kt +7 -11
  59. package/android/src/main/java/com/audiobrowser/player/StuckRecoveryPolicy.kt +9 -22
  60. package/android/src/main/java/com/audiobrowser/player/TransformingDataSource.kt +22 -54
  61. package/android/src/main/java/com/audiobrowser/player/VolumeFader.kt +8 -15
  62. package/android/src/main/java/com/audiobrowser/remote/RemoteItem.kt +9 -8
  63. package/android/src/main/java/com/audiobrowser/remote/RemoteOutputsController.kt +13 -10
  64. package/android/src/main/java/com/audiobrowser/remote/RemotePlayback.kt +8 -8
  65. package/android/src/main/java/com/audiobrowser/remote/RemoteQueue.kt +12 -5
  66. package/android/src/main/java/com/audiobrowser/remote/RemoteSwitchingPlayer.kt +28 -48
  67. package/android/src/main/java/com/audiobrowser/sonos/DeviceDescriptionParser.kt +11 -19
  68. package/android/src/main/java/com/audiobrowser/sonos/DidlLite.kt +2 -2
  69. package/android/src/main/java/com/audiobrowser/sonos/SoapClient.kt +6 -6
  70. package/android/src/main/java/com/audiobrowser/sonos/SoapEnvelopes.kt +8 -9
  71. package/android/src/main/java/com/audiobrowser/sonos/SoapResponseParser.kt +11 -18
  72. package/android/src/main/java/com/audiobrowser/sonos/SonosDiscoverer.kt +10 -10
  73. package/android/src/main/java/com/audiobrowser/sonos/SonosOutputs.kt +10 -10
  74. package/android/src/main/java/com/audiobrowser/sonos/SonosPlayer.kt +21 -33
  75. package/android/src/main/java/com/audiobrowser/sonos/SonosRemote.kt +4 -6
  76. package/android/src/main/java/com/audiobrowser/sonos/SonosRouteProviderService.kt +9 -10
  77. package/android/src/main/java/com/audiobrowser/sonos/SonosStreamUri.kt +7 -7
  78. package/android/src/main/java/com/audiobrowser/sonos/SonosTransport.kt +5 -4
  79. package/android/src/main/java/com/audiobrowser/sonos/SsdpDiscovery.kt +8 -3
  80. package/android/src/main/java/com/audiobrowser/sonos/SsdpMessages.kt +4 -6
  81. package/android/src/main/java/com/audiobrowser/sonos/ZoneGroupState.kt +13 -11
  82. package/android/src/main/java/com/audiobrowser/tls/AiaCertChaser.kt +34 -71
  83. package/android/src/main/java/com/audiobrowser/tls/AiaChasingExtendedTrustManager.kt +20 -37
  84. package/android/src/main/java/com/audiobrowser/tls/AiaChasingTrustManager.kt +18 -27
  85. package/android/src/main/java/com/audiobrowser/tls/AiaTls.kt +14 -29
  86. package/android/src/main/java/com/audiobrowser/tls/CachingCertificateFetcher.kt +68 -133
  87. package/android/src/main/java/com/audiobrowser/util/ArtworkContentProvider.kt +10 -22
  88. package/android/src/main/java/com/audiobrowser/util/ArtworkRoutes.kt +6 -6
  89. package/android/src/main/java/com/audiobrowser/util/ArtworkUris.kt +4 -3
  90. package/android/src/main/java/com/audiobrowser/util/ArtworkVariant.kt +2 -13
  91. package/android/src/main/java/com/audiobrowser/util/Automotive.kt +2 -4
  92. package/android/src/main/java/com/audiobrowser/util/BatteryOptimizationHelper.kt +3 -9
  93. package/android/src/main/java/com/audiobrowser/util/BatteryWarningStore.kt +4 -14
  94. package/android/src/main/java/com/audiobrowser/util/BrowserPathHelper.kt +21 -85
  95. package/android/src/main/java/com/audiobrowser/util/CoilArtworkLoader.kt +7 -7
  96. package/android/src/main/java/com/audiobrowser/util/CoilArtworkLoaderHolder.kt +5 -8
  97. package/android/src/main/java/com/audiobrowser/util/CoilBitmapLoader.kt +8 -24
  98. package/android/src/main/java/com/audiobrowser/util/EqualizerManager.kt +7 -39
  99. package/android/src/main/java/com/audiobrowser/util/MediaExtrasBuilder.kt +10 -14
  100. package/android/src/main/java/com/audiobrowser/util/MetadataAdapter.kt +5 -9
  101. package/android/src/main/java/com/audiobrowser/util/NetworkConnectivityMonitor.kt +5 -9
  102. package/android/src/main/java/com/audiobrowser/util/OutputMonitor.kt +21 -50
  103. package/android/src/main/java/com/audiobrowser/util/OutputSwitcher.kt +7 -20
  104. package/android/src/main/java/com/audiobrowser/util/PlayingStateFactory.kt +3 -5
  105. package/android/src/main/java/com/audiobrowser/util/RatingFavorites.kt +4 -5
  106. package/android/src/main/java/com/audiobrowser/util/StyleWire.kt +5 -5
  107. package/android/src/main/java/com/audiobrowser/util/SvgArtworkRenderer.kt +5 -9
  108. package/android/src/main/java/com/audiobrowser/util/SystemVolumeMonitor.kt +6 -9
  109. package/android/src/main/java/com/audiobrowser/util/TrackFactory.kt +25 -47
  110. package/android/src/nocast/java/com/audiobrowser/cast/CastSupport.kt +0 -2
  111. package/android/src/test/java/com/audiobrowser/ForegroundStartTest.kt +1 -2
  112. package/android/src/test/java/com/audiobrowser/LegacyRatingTest.kt +3 -3
  113. package/android/src/test/java/com/audiobrowser/ServiceBindingTest.kt +0 -13
  114. package/android/src/test/java/com/audiobrowser/ServiceTaskRemovedTest.kt +2 -3
  115. package/android/src/test/java/com/audiobrowser/TestFixtures.kt +5 -14
  116. package/android/src/test/java/com/audiobrowser/browser/BrowseArtworkRegistryTest.kt +1 -1
  117. package/android/src/test/java/com/audiobrowser/browser/BrowserManagerBuildApiRequestTest.kt +2 -8
  118. package/android/src/test/java/com/audiobrowser/browser/BrowserManagerFavoritesTest.kt +2 -12
  119. package/android/src/test/java/com/audiobrowser/browser/BrowserManagerLayerResolutionTest.kt +5 -28
  120. package/android/src/test/java/com/audiobrowser/browser/BrowserManagerTest.kt +11 -43
  121. package/android/src/test/java/com/audiobrowser/browser/BrowserUrlResolutionTest.kt +4 -13
  122. package/android/src/test/java/com/audiobrowser/browser/InertStyleDiagnosticTest.kt +2 -11
  123. package/android/src/test/java/com/audiobrowser/browser/JsonArtworkTest.kt +0 -2
  124. package/android/src/test/java/com/audiobrowser/browser/JsonStyleTest.kt +3 -8
  125. package/android/src/test/java/com/audiobrowser/browser/SectionScopeTest.kt +2 -14
  126. package/android/src/test/java/com/audiobrowser/browser/SimpleRouterTest.kt +1 -5
  127. package/android/src/test/java/com/audiobrowser/browser/StyleResolverTest.kt +2 -13
  128. package/android/src/test/java/com/audiobrowser/extension/TappedTrackTest.kt +1 -7
  129. package/android/src/test/java/com/audiobrowser/extension/TrackIdentityTest.kt +0 -5
  130. package/android/src/test/java/com/audiobrowser/http/RequestConfigBuilderTest.kt +8 -16
  131. package/android/src/test/java/com/audiobrowser/model/IcyTitleTest.kt +1 -1
  132. package/android/src/test/java/com/audiobrowser/player/BrowseTilesTest.kt +12 -29
  133. package/android/src/test/java/com/audiobrowser/player/CapabilityControlsTest.kt +3 -12
  134. package/android/src/test/java/com/audiobrowser/player/CrossOriginHeaderStripperTest.kt +0 -7
  135. package/android/src/test/java/com/audiobrowser/player/DynamicLoadControlTest.kt +0 -1
  136. package/android/src/test/java/com/audiobrowser/player/EqualizerControllerTest.kt +0 -9
  137. package/android/src/test/java/com/audiobrowser/player/LiveSeekCommandTest.kt +1 -2
  138. package/android/src/test/java/com/audiobrowser/player/MediaSessionSlotMappingTest.kt +0 -9
  139. package/android/src/test/java/com/audiobrowser/player/NowPlayingUpdaterTest.kt +15 -22
  140. package/android/src/test/java/com/audiobrowser/player/PlaybackErrorClassifierTest.kt +1 -24
  141. package/android/src/test/java/com/audiobrowser/player/PlaybackStateMachineTest.kt +0 -20
  142. package/android/src/test/java/com/audiobrowser/player/PlaybackStateStoreTrackJsonTest.kt +1 -6
  143. package/android/src/test/java/com/audiobrowser/player/PlaybackTimerTest.kt +2 -4
  144. package/android/src/test/java/com/audiobrowser/player/PlayerCastTest.kt +2 -2
  145. package/android/src/test/java/com/audiobrowser/player/PlayerEngineFactoryTest.kt +0 -3
  146. package/android/src/test/java/com/audiobrowser/player/PlayerInvalidTrackTest.kt +0 -1
  147. package/android/src/test/java/com/audiobrowser/player/PlayerSetupTest.kt +3 -2
  148. package/android/src/test/java/com/audiobrowser/player/PlayerSonosTest.kt +5 -1
  149. package/android/src/test/java/com/audiobrowser/player/PlayerSuppressionTest.kt +5 -7
  150. package/android/src/test/java/com/audiobrowser/player/RetryLoadErrorHandlingPolicyTest.kt +4 -35
  151. package/android/src/test/java/com/audiobrowser/player/SessionErrorMaskTest.kt +0 -5
  152. package/android/src/test/java/com/audiobrowser/player/ShuffleOrderLedByTest.kt +1 -8
  153. package/android/src/test/java/com/audiobrowser/player/StandardSkipTest.kt +4 -6
  154. package/android/src/test/java/com/audiobrowser/player/StuckRecoveryPolicyTest.kt +11 -11
  155. package/android/src/test/java/com/audiobrowser/player/TransformingDataSourceTest.kt +2 -23
  156. package/android/src/test/java/com/audiobrowser/remote/FakeRemote.kt +9 -10
  157. package/android/src/test/java/com/audiobrowser/remote/RemoteSwitchingPlayerTest.kt +0 -1
  158. package/android/src/test/java/com/audiobrowser/sonos/DeviceDescriptionParserTest.kt +1 -3
  159. package/android/src/test/java/com/audiobrowser/sonos/DidlLiteTest.kt +0 -1
  160. package/android/src/test/java/com/audiobrowser/sonos/SoapClientTest.kt +0 -3
  161. package/android/src/test/java/com/audiobrowser/sonos/SoapEnvelopesTest.kt +0 -1
  162. package/android/src/test/java/com/audiobrowser/sonos/SoapResponseParserTest.kt +0 -1
  163. package/android/src/test/java/com/audiobrowser/sonos/SonosDiscovererTest.kt +2 -0
  164. package/android/src/test/java/com/audiobrowser/sonos/SonosPlayerTest.kt +0 -1
  165. package/android/src/test/java/com/audiobrowser/sonos/SonosRemoteTest.kt +1 -1
  166. package/android/src/test/java/com/audiobrowser/sonos/SonosRoutesTest.kt +2 -0
  167. package/android/src/test/java/com/audiobrowser/sonos/SonosTransportTest.kt +2 -6
  168. package/android/src/test/java/com/audiobrowser/sonos/SsdpMessagesTest.kt +0 -2
  169. package/android/src/test/java/com/audiobrowser/tls/AiaCertChaserTest.kt +13 -37
  170. package/android/src/test/java/com/audiobrowser/tls/AiaChasingTrustManagerTest.kt +10 -24
  171. package/android/src/test/java/com/audiobrowser/tls/CachingCertificateFetcherCallSiteTest.kt +15 -39
  172. package/android/src/test/java/com/audiobrowser/tls/CachingCertificateFetcherTest.kt +4 -10
  173. package/android/src/test/java/com/audiobrowser/util/ArtworkContentProviderTest.kt +2 -11
  174. package/android/src/test/java/com/audiobrowser/util/ArtworkUrisTest.kt +0 -1
  175. package/android/src/test/java/com/audiobrowser/util/BrowserPathHelperTest.kt +0 -4
  176. package/android/src/test/java/com/audiobrowser/util/CoilArtworkLoaderHolderTest.kt +1 -1
  177. package/android/src/test/java/com/audiobrowser/util/CoilArtworkLoaderTest.kt +0 -5
  178. package/android/src/test/java/com/audiobrowser/util/FakeImageLoader.kt +2 -2
  179. package/android/src/test/java/com/audiobrowser/util/MediaExtrasBuilderTest.kt +4 -12
  180. package/android/src/test/java/com/audiobrowser/util/OutputMonitorTest.kt +1 -1
  181. package/android/src/test/java/com/audiobrowser/util/PlayingStateFactoryTest.kt +0 -4
  182. package/android/src/test/java/com/audiobrowser/util/TrackFactoryBrowseTest.kt +1 -1
  183. package/android/src/test/java/com/audiobrowser/util/TrackFactoryMediaIdTest.kt +4 -6
  184. package/android/src/testCast/java/com/audiobrowser/cast/CastEndsTest.kt +1 -1
  185. package/android/src/testCast/java/com/audiobrowser/cast/SendingMediaItemConverterTest.kt +1 -0
  186. package/ios/AVPlayerEngine.swift +13 -21
  187. package/ios/AVPlayerEngineCallbacks.swift +2 -4
  188. package/ios/Browser/BrowseGate.swift +7 -8
  189. package/ios/Browser/BrowserConfig.swift +19 -34
  190. package/ios/Browser/BrowserError.swift +0 -1
  191. package/ios/Browser/BrowserManager.swift +29 -75
  192. package/ios/Browser/BrowserPathHelper.swift +13 -93
  193. package/ios/Browser/FavoriteSet.swift +7 -10
  194. package/ios/Browser/InertStyleDiagnostic.swift +17 -82
  195. package/ios/Browser/JsonModels.swift +11 -51
  196. package/ios/Browser/NavigationErrorState.swift +3 -2
  197. package/ios/Browser/PageResolver.swift +13 -23
  198. package/ios/Browser/RequestLayer.swift +16 -20
  199. package/ios/Browser/RequestPipeline.swift +33 -43
  200. package/ios/Browser/SearchDrillIn.swift +7 -13
  201. package/ios/Browser/SectionScope.swift +14 -26
  202. package/ios/Browser/SimpleRouter.swift +8 -15
  203. package/ios/Browser/StyleResolver.swift +12 -29
  204. package/ios/Browser/TabBarEntries.swift +6 -11
  205. package/ios/Browser/TrackIdTemplate.swift +6 -14
  206. package/ios/CarPlay/CPInterfaceController+Safe.swift +19 -28
  207. package/ios/CarPlay/CarPlayArtworkResolver.swift +5 -9
  208. package/ios/CarPlay/CarPlayController.swift +4 -4
  209. package/ios/CarPlay/CarPlayImageLoader.swift +11 -26
  210. package/ios/CarPlay/CarPlayListItemFactory.swift +30 -80
  211. package/ios/CarPlay/CarPlayNowPlayingManager.swift +19 -54
  212. package/ios/CarPlay/CarPlaySession+Navigator.swift +10 -10
  213. package/ios/CarPlay/CarPlaySession+PageLoader.swift +6 -5
  214. package/ios/CarPlay/CarPlaySession+Refresher.swift +2 -2
  215. package/ios/CarPlay/CarPlaySession+TabBar.swift +19 -26
  216. package/ios/CarPlay/CarPlaySession.swift +13 -17
  217. package/ios/CarPlay/CarPlayTemplates.swift +6 -7
  218. package/ios/CarPlay/IntentHandlers.swift +3 -5
  219. package/ios/CarPlay/MediaIntentCriteria.swift +15 -29
  220. package/ios/CarPlay/MediaIntentHandler.swift +4 -7
  221. package/ios/CarPlay/MediaIntentPlayback.swift +9 -8
  222. package/ios/CarPlay/NowPlayingButtonRules.swift +3 -4
  223. package/ios/CarPlay/SectionPresentation.swift +18 -28
  224. package/ios/CarPlay/TopTemplateReplacer.swift +8 -9
  225. package/ios/Extension/Capability+RemoteCommand.swift +3 -3
  226. package/ios/Extension/ChapterMetadata+AVFoundation.swift +2 -5
  227. package/ios/Extension/CxxVectorConformances.swift +4 -16
  228. package/ios/Extension/NavigationError+Conversion.swift +4 -7
  229. package/ios/Extension/PlayerCapabilities+Favorite.swift +0 -1
  230. package/ios/Extension/RequestConfig+Copying.swift +2 -6
  231. package/ios/Extension/ResolvedTrack+Copying.swift +2 -8
  232. package/ios/Extension/SearchParams+Query.swift +4 -4
  233. package/ios/Extension/Section+Copying.swift +3 -6
  234. package/ios/Extension/String+IcyCharset.swift +5 -5
  235. package/ios/Extension/TimedMetadata+AVFoundation.swift +6 -12
  236. package/ios/Extension/Track+AVPlayer.swift +1 -2
  237. package/ios/Extension/Track+Copying.swift +2 -8
  238. package/ios/Extension/Track+Identity.swift +4 -9
  239. package/ios/Extension/TrackMetadata+AVFoundation.swift +10 -13
  240. package/ios/Extension/UIApplication+ActiveScene.swift +6 -14
  241. package/ios/Extension/Variant+Artwork.swift +8 -22
  242. package/ios/Http/HttpClient.swift +3 -3
  243. package/ios/HybridAudioBrowser+Browser.swift +10 -16
  244. package/ios/HybridAudioBrowser+Options.swift +6 -9
  245. package/ios/HybridAudioBrowser+Player.swift +8 -16
  246. package/ios/HybridAudioBrowser+PlayerCallbacks.swift +4 -5
  247. package/ios/HybridAudioBrowser+Stubs.swift +5 -7
  248. package/ios/HybridAudioBrowser.swift +54 -79
  249. package/ios/Model/NitroTypeStubs.swift +15 -22
  250. package/ios/Model/PlayerUpdateOptions.swift +6 -21
  251. package/ios/Model/RemoteCommand.swift +2 -2
  252. package/ios/Model/TrackPlayerError.swift +9 -22
  253. package/ios/NowPlayingInfo/NowPlayingInfoController.swift +21 -40
  254. package/ios/NowPlayingInfo/SilentAudioPrimer.swift +10 -16
  255. package/ios/Observer/ItemObserver.swift +7 -5
  256. package/ios/Observer/PlayerObserver.swift +5 -5
  257. package/ios/PlaybackEvent.swift +2 -2
  258. package/ios/Player/AirPlayStallJudgement.swift +7 -9
  259. package/ios/Player/AudioSessionController.swift +14 -15
  260. package/ios/Player/DeferredSeek.swift +2 -2
  261. package/ios/Player/EndOfTrackJudgement.swift +6 -13
  262. package/ios/Player/ErrorStatus.swift +8 -7
  263. package/ios/Player/MediaLoader.swift +20 -24
  264. package/ios/Player/NowPlayingLines.swift +1 -4
  265. package/ios/Player/NowPlayingUpdater.swift +35 -61
  266. package/ios/Player/PersistedPlaybackState.swift +1 -2
  267. package/ios/Player/PlaybackFailure.swift +20 -24
  268. package/ios/Player/PlaybackPersistence.swift +5 -6
  269. package/ios/Player/PlaybackStateMachine.swift +8 -11
  270. package/ios/Player/PlaybackTimer.swift +8 -11
  271. package/ios/Player/Player.swift +6 -13
  272. package/ios/Player/PlayerEngine.swift +20 -20
  273. package/ios/Player/PlayerStatusTypes.swift +1 -2
  274. package/ios/Player/QueueManager.swift +23 -67
  275. package/ios/Player/RetryLoop.swift +39 -50
  276. package/ios/Player/ShuffleOrder.swift +17 -57
  277. package/ios/Player/SleepTimerManager.swift +13 -28
  278. package/ios/Player/VolumeFader.swift +16 -16
  279. package/ios/RemoteCommand/RemoteCommandCallbacks.swift +6 -16
  280. package/ios/RemoteCommand/RemoteCommandController.swift +8 -10
  281. package/ios/Tests/AirPlayStallJudgementTests.swift +4 -4
  282. package/ios/Tests/BrowserPathHelperTests.swift +3 -6
  283. package/ios/Tests/DeferredSeekTests.swift +1 -3
  284. package/ios/Tests/EmitterTests.swift +0 -1
  285. package/ios/Tests/EndOfTrackJudgementTests.swift +1 -6
  286. package/ios/Tests/FavoriteSetTests.swift +1 -0
  287. package/ios/Tests/GenerationMemoTests.swift +2 -2
  288. package/ios/Tests/InertStyleDiagnosticTests.swift +4 -10
  289. package/ios/Tests/JsonModelsTests.swift +5 -12
  290. package/ios/Tests/LRUCacheTests.swift +1 -5
  291. package/ios/Tests/MediaIntentCriteriaTests.swift +2 -7
  292. package/ios/Tests/MediaLoaderTests.swift +3 -12
  293. package/ios/Tests/ObserverTests.swift +3 -3
  294. package/ios/Tests/PlaybackErrorTests.swift +7 -9
  295. package/ios/Tests/PlaybackFailureTests.swift +9 -17
  296. package/ios/Tests/PlaybackPersistenceTests.swift +1 -0
  297. package/ios/Tests/PlaybackStateMachineTests.swift +1 -16
  298. package/ios/Tests/PlaybackTimerTests.swift +2 -3
  299. package/ios/Tests/PlayerPolicyTests.swift +10 -26
  300. package/ios/Tests/PlayerTests.swift +53 -88
  301. package/ios/Tests/PlayingStateTests.swift +0 -1
  302. package/ios/Tests/QueueManagerTests.swift +30 -80
  303. package/ios/Tests/RemoteCommandControllerTests.swift +5 -13
  304. package/ios/Tests/ResolvedTrackCopyingTests.swift +0 -2
  305. package/ios/Tests/RetryLoopTests.swift +12 -35
  306. package/ios/Tests/SearchDrillInTests.swift +4 -5
  307. package/ios/Tests/SectionPresentationTests.swift +3 -16
  308. package/ios/Tests/SectionScopeTests.swift +3 -6
  309. package/ios/Tests/SimpleRouterTests.swift +1 -5
  310. package/ios/Tests/SleepTimerManagerTests.swift +8 -11
  311. package/ios/Tests/StyleResolverTests.swift +4 -13
  312. package/ios/Tests/Support/ManualSleepTimerScheduler.swift +3 -8
  313. package/ios/Tests/Support/TestTypes.swift +5 -15
  314. package/ios/Tests/TabBarEntriesTests.swift +0 -2
  315. package/ios/Tests/TimedMetadataAVFoundationTests.swift +2 -3
  316. package/ios/Tests/TopTemplateReplacerTests.swift +1 -1
  317. package/ios/Tests/TrackIdTemplateTests.swift +2 -6
  318. package/ios/Tests/TrackMetadataAVFoundationTests.swift +1 -4
  319. package/ios/Tests/TrackSelectorTests.swift +3 -15
  320. package/ios/TrackSelector.swift +13 -25
  321. package/ios/Util/ArtworkFreshness.swift +6 -6
  322. package/ios/Util/ArtworkImageFetcher.swift +19 -20
  323. package/ios/Util/ConcurrentMap.swift +2 -2
  324. package/ios/Util/Emitter.swift +8 -13
  325. package/ios/Util/NetworkMonitor.swift +4 -6
  326. package/ios/Util/OutputPicker.swift +1 -1
  327. package/ios/Util/ReadyValue.swift +3 -2
  328. package/ios/Util/SFSymbolRenderer.swift +17 -30
  329. package/ios/Util/SVGProcessor.swift +5 -9
  330. package/lib/commonjs/CLAUDE.md +7 -2
  331. package/lib/commonjs/features/battery.js +16 -12
  332. package/lib/commonjs/features/battery.js.map +1 -1
  333. package/lib/commonjs/features/browser-config.js +1 -1
  334. package/lib/commonjs/features/browser.js +74 -24
  335. package/lib/commonjs/features/browser.js.map +1 -1
  336. package/lib/commonjs/features/carConnection.js +3 -4
  337. package/lib/commonjs/features/carConnection.js.map +1 -1
  338. package/lib/commonjs/features/equalizer.js +9 -5
  339. package/lib/commonjs/features/equalizer.js.map +1 -1
  340. package/lib/commonjs/features/errors.js +35 -21
  341. package/lib/commonjs/features/errors.js.map +1 -1
  342. package/lib/commonjs/features/favorites.js +15 -13
  343. package/lib/commonjs/features/favorites.js.map +1 -1
  344. package/lib/commonjs/features/gate.js +12 -6
  345. package/lib/commonjs/features/gate.js.map +1 -1
  346. package/lib/commonjs/features/metadata.js +16 -14
  347. package/lib/commonjs/features/metadata.js.map +1 -1
  348. package/lib/commonjs/features/network.js +5 -1
  349. package/lib/commonjs/features/network.js.map +1 -1
  350. package/lib/commonjs/features/nowPlaying.js +28 -14
  351. package/lib/commonjs/features/nowPlaying.js.map +1 -1
  352. package/lib/commonjs/features/output.js +8 -4
  353. package/lib/commonjs/features/output.js.map +1 -1
  354. package/lib/commonjs/features/playback/controls.js +10 -5
  355. package/lib/commonjs/features/playback/controls.js.map +1 -1
  356. package/lib/commonjs/features/playback/playWhenReady.js +6 -5
  357. package/lib/commonjs/features/playback/playWhenReady.js.map +1 -1
  358. package/lib/commonjs/features/playback/playing.js +5 -3
  359. package/lib/commonjs/features/playback/playing.js.map +1 -1
  360. package/lib/commonjs/features/playback/progress.js +11 -5
  361. package/lib/commonjs/features/playback/progress.js.map +1 -1
  362. package/lib/commonjs/features/playback/state.js +3 -3
  363. package/lib/commonjs/features/playback/state.js.map +1 -1
  364. package/lib/commonjs/features/playback/trackPlaybackTime.js +6 -1
  365. package/lib/commonjs/features/playback/trackPlaybackTime.js.map +1 -1
  366. package/lib/commonjs/features/playback/volume.js +6 -5
  367. package/lib/commonjs/features/playback/volume.js.map +1 -1
  368. package/lib/commonjs/features/player/options.js +20 -10
  369. package/lib/commonjs/features/player/options.js.map +1 -1
  370. package/lib/commonjs/features/player/setup.js +34 -38
  371. package/lib/commonjs/features/player/setup.js.map +1 -1
  372. package/lib/commonjs/features/queue/activeTrack.js +0 -1
  373. package/lib/commonjs/features/queue/activeTrack.js.map +1 -1
  374. package/lib/commonjs/features/queue/queue.js +48 -20
  375. package/lib/commonjs/features/queue/queue.js.map +1 -1
  376. package/lib/commonjs/features/queue/repeatMode.js +2 -1
  377. package/lib/commonjs/features/queue/repeatMode.js.map +1 -1
  378. package/lib/commonjs/features/queue/shuffle.js +0 -1
  379. package/lib/commonjs/features/queue/shuffle.js.map +1 -1
  380. package/lib/commonjs/features/remoteControls.js +59 -35
  381. package/lib/commonjs/features/remoteControls.js.map +1 -1
  382. package/lib/commonjs/features/sleepTimer.js +15 -6
  383. package/lib/commonjs/features/sleepTimer.js.map +1 -1
  384. package/lib/commonjs/utils/LazyNativeEmitter.js +6 -9
  385. package/lib/commonjs/utils/LazyNativeEmitter.js.map +1 -1
  386. package/lib/commonjs/utils/NativeUpdatedValue.js +13 -12
  387. package/lib/commonjs/utils/NativeUpdatedValue.js.map +1 -1
  388. package/lib/commonjs/utils/getTrackIdentity.js +6 -4
  389. package/lib/commonjs/utils/getTrackIdentity.js.map +1 -1
  390. package/lib/commonjs/utils/useDebug.js +16 -3
  391. package/lib/commonjs/utils/useDebug.js.map +1 -1
  392. package/lib/commonjs/web/NativeAudioBrowser.js +2 -4
  393. package/lib/commonjs/web/NativeAudioBrowser.js.map +1 -1
  394. package/lib/commonjs/web/browser/parseSearchResponse.js +3 -4
  395. package/lib/commonjs/web/browser/parseSearchResponse.js.map +1 -1
  396. package/lib/commonjs/web/browser/sections.js +1 -1
  397. package/lib/commonjs/web/util/BrowserPathHelper.js +1 -3
  398. package/lib/commonjs/web/util/BrowserPathHelper.js.map +1 -1
  399. package/lib/module/CLAUDE.md +7 -2
  400. package/lib/module/features/battery.js +16 -12
  401. package/lib/module/features/battery.js.map +1 -1
  402. package/lib/module/features/browser-config.js +1 -1
  403. package/lib/module/features/browser.js +74 -24
  404. package/lib/module/features/browser.js.map +1 -1
  405. package/lib/module/features/carConnection.js +3 -4
  406. package/lib/module/features/carConnection.js.map +1 -1
  407. package/lib/module/features/equalizer.js +9 -5
  408. package/lib/module/features/equalizer.js.map +1 -1
  409. package/lib/module/features/errors.js +35 -21
  410. package/lib/module/features/errors.js.map +1 -1
  411. package/lib/module/features/favorites.js +15 -13
  412. package/lib/module/features/favorites.js.map +1 -1
  413. package/lib/module/features/gate.js +12 -6
  414. package/lib/module/features/gate.js.map +1 -1
  415. package/lib/module/features/metadata.js +16 -14
  416. package/lib/module/features/metadata.js.map +1 -1
  417. package/lib/module/features/network.js +5 -1
  418. package/lib/module/features/network.js.map +1 -1
  419. package/lib/module/features/nowPlaying.js +28 -14
  420. package/lib/module/features/nowPlaying.js.map +1 -1
  421. package/lib/module/features/output.js +8 -4
  422. package/lib/module/features/output.js.map +1 -1
  423. package/lib/module/features/playback/controls.js +10 -5
  424. package/lib/module/features/playback/controls.js.map +1 -1
  425. package/lib/module/features/playback/playWhenReady.js +6 -5
  426. package/lib/module/features/playback/playWhenReady.js.map +1 -1
  427. package/lib/module/features/playback/playing.js +5 -3
  428. package/lib/module/features/playback/playing.js.map +1 -1
  429. package/lib/module/features/playback/progress.js +11 -5
  430. package/lib/module/features/playback/progress.js.map +1 -1
  431. package/lib/module/features/playback/state.js +3 -3
  432. package/lib/module/features/playback/state.js.map +1 -1
  433. package/lib/module/features/playback/trackPlaybackTime.js +6 -1
  434. package/lib/module/features/playback/trackPlaybackTime.js.map +1 -1
  435. package/lib/module/features/playback/volume.js +6 -5
  436. package/lib/module/features/playback/volume.js.map +1 -1
  437. package/lib/module/features/player/options.js +20 -10
  438. package/lib/module/features/player/options.js.map +1 -1
  439. package/lib/module/features/player/setup.js +34 -38
  440. package/lib/module/features/player/setup.js.map +1 -1
  441. package/lib/module/features/queue/activeTrack.js +0 -1
  442. package/lib/module/features/queue/activeTrack.js.map +1 -1
  443. package/lib/module/features/queue/queue.js +48 -20
  444. package/lib/module/features/queue/queue.js.map +1 -1
  445. package/lib/module/features/queue/repeatMode.js +2 -1
  446. package/lib/module/features/queue/repeatMode.js.map +1 -1
  447. package/lib/module/features/queue/shuffle.js +0 -1
  448. package/lib/module/features/queue/shuffle.js.map +1 -1
  449. package/lib/module/features/remoteControls.js +59 -35
  450. package/lib/module/features/remoteControls.js.map +1 -1
  451. package/lib/module/features/sleepTimer.js +15 -6
  452. package/lib/module/features/sleepTimer.js.map +1 -1
  453. package/lib/module/utils/LazyNativeEmitter.js +6 -9
  454. package/lib/module/utils/LazyNativeEmitter.js.map +1 -1
  455. package/lib/module/utils/NativeUpdatedValue.js +13 -12
  456. package/lib/module/utils/NativeUpdatedValue.js.map +1 -1
  457. package/lib/module/utils/getTrackIdentity.js +6 -4
  458. package/lib/module/utils/getTrackIdentity.js.map +1 -1
  459. package/lib/module/utils/useDebug.js +16 -3
  460. package/lib/module/utils/useDebug.js.map +1 -1
  461. package/lib/module/web/NativeAudioBrowser.js +2 -4
  462. package/lib/module/web/NativeAudioBrowser.js.map +1 -1
  463. package/lib/module/web/browser/parseSearchResponse.js +3 -4
  464. package/lib/module/web/browser/parseSearchResponse.js.map +1 -1
  465. package/lib/module/web/browser/sections.js +1 -1
  466. package/lib/module/web/util/BrowserPathHelper.js +1 -3
  467. package/lib/module/web/util/BrowserPathHelper.js.map +1 -1
  468. package/lib/typescript/src/features/battery.d.ts +17 -12
  469. package/lib/typescript/src/features/battery.d.ts.map +1 -1
  470. package/lib/typescript/src/features/browser.d.ts +64 -24
  471. package/lib/typescript/src/features/browser.d.ts.map +1 -1
  472. package/lib/typescript/src/features/carConnection.d.ts +3 -4
  473. package/lib/typescript/src/features/carConnection.d.ts.map +1 -1
  474. package/lib/typescript/src/features/equalizer.d.ts +9 -5
  475. package/lib/typescript/src/features/equalizer.d.ts.map +1 -1
  476. package/lib/typescript/src/features/errors.d.ts +37 -22
  477. package/lib/typescript/src/features/errors.d.ts.map +1 -1
  478. package/lib/typescript/src/features/favorites.d.ts +15 -13
  479. package/lib/typescript/src/features/favorites.d.ts.map +1 -1
  480. package/lib/typescript/src/features/gate.d.ts +14 -8
  481. package/lib/typescript/src/features/gate.d.ts.map +1 -1
  482. package/lib/typescript/src/features/metadata.d.ts +37 -17
  483. package/lib/typescript/src/features/metadata.d.ts.map +1 -1
  484. package/lib/typescript/src/features/network.d.ts +5 -1
  485. package/lib/typescript/src/features/network.d.ts.map +1 -1
  486. package/lib/typescript/src/features/nowPlaying.d.ts +28 -14
  487. package/lib/typescript/src/features/nowPlaying.d.ts.map +1 -1
  488. package/lib/typescript/src/features/output.d.ts +8 -4
  489. package/lib/typescript/src/features/output.d.ts.map +1 -1
  490. package/lib/typescript/src/features/playback/controls.d.ts +10 -5
  491. package/lib/typescript/src/features/playback/controls.d.ts.map +1 -1
  492. package/lib/typescript/src/features/playback/playWhenReady.d.ts +6 -5
  493. package/lib/typescript/src/features/playback/playWhenReady.d.ts.map +1 -1
  494. package/lib/typescript/src/features/playback/playing.d.ts +16 -3
  495. package/lib/typescript/src/features/playback/playing.d.ts.map +1 -1
  496. package/lib/typescript/src/features/playback/progress.d.ts +11 -5
  497. package/lib/typescript/src/features/playback/progress.d.ts.map +1 -1
  498. package/lib/typescript/src/features/playback/state.d.ts +8 -3
  499. package/lib/typescript/src/features/playback/state.d.ts.map +1 -1
  500. package/lib/typescript/src/features/playback/trackPlaybackTime.d.ts +9 -2
  501. package/lib/typescript/src/features/playback/trackPlaybackTime.d.ts.map +1 -1
  502. package/lib/typescript/src/features/playback/volume.d.ts +6 -5
  503. package/lib/typescript/src/features/playback/volume.d.ts.map +1 -1
  504. package/lib/typescript/src/features/player/options.d.ts +52 -37
  505. package/lib/typescript/src/features/player/options.d.ts.map +1 -1
  506. package/lib/typescript/src/features/player/setup.d.ts +65 -60
  507. package/lib/typescript/src/features/player/setup.d.ts.map +1 -1
  508. package/lib/typescript/src/features/queue/activeTrack.d.ts +0 -1
  509. package/lib/typescript/src/features/queue/activeTrack.d.ts.map +1 -1
  510. package/lib/typescript/src/features/queue/queue.d.ts +48 -20
  511. package/lib/typescript/src/features/queue/queue.d.ts.map +1 -1
  512. package/lib/typescript/src/features/queue/repeatMode.d.ts +1 -1
  513. package/lib/typescript/src/features/queue/repeatMode.d.ts.map +1 -1
  514. package/lib/typescript/src/features/queue/shuffle.d.ts +0 -1
  515. package/lib/typescript/src/features/queue/shuffle.d.ts.map +1 -1
  516. package/lib/typescript/src/features/remoteControls.d.ts +58 -25
  517. package/lib/typescript/src/features/remoteControls.d.ts.map +1 -1
  518. package/lib/typescript/src/features/sleepTimer.d.ts +15 -7
  519. package/lib/typescript/src/features/sleepTimer.d.ts.map +1 -1
  520. package/lib/typescript/src/types/browser-nodes.d.ts +54 -57
  521. package/lib/typescript/src/types/browser-nodes.d.ts.map +1 -1
  522. package/lib/typescript/src/types/browser.d.ts +181 -144
  523. package/lib/typescript/src/types/browser.d.ts.map +1 -1
  524. package/lib/typescript/src/utils/LazyNativeEmitter.d.ts +6 -9
  525. package/lib/typescript/src/utils/LazyNativeEmitter.d.ts.map +1 -1
  526. package/lib/typescript/src/utils/NativeUpdatedValue.d.ts +13 -12
  527. package/lib/typescript/src/utils/NativeUpdatedValue.d.ts.map +1 -1
  528. package/lib/typescript/src/utils/getTrackIdentity.d.ts +6 -4
  529. package/lib/typescript/src/utils/getTrackIdentity.d.ts.map +1 -1
  530. package/lib/typescript/src/utils/useDebug.d.ts +16 -3
  531. package/lib/typescript/src/utils/useDebug.d.ts.map +1 -1
  532. package/package.json +1 -1
  533. package/src/CLAUDE.md +7 -2
  534. package/src/docs-floors.test.ts +71 -0
  535. package/src/features/battery.ts +17 -13
  536. package/src/features/browser-config.ts +1 -1
  537. package/src/features/browser.ts +65 -24
  538. package/src/features/carConnection.ts +3 -4
  539. package/src/features/equalizer.ts +9 -5
  540. package/src/features/errors.ts +37 -22
  541. package/src/features/favorites.ts +15 -13
  542. package/src/features/gate.ts +14 -8
  543. package/src/features/metadata.ts +37 -17
  544. package/src/features/network.ts +5 -1
  545. package/src/features/nowPlaying.ts +28 -14
  546. package/src/features/output.ts +8 -4
  547. package/src/features/playback/controls.ts +10 -5
  548. package/src/features/playback/playWhenReady.ts +6 -5
  549. package/src/features/playback/playing.ts +16 -3
  550. package/src/features/playback/progress.ts +11 -5
  551. package/src/features/playback/state.ts +8 -3
  552. package/src/features/playback/trackPlaybackTime.ts +9 -2
  553. package/src/features/playback/volume.ts +6 -5
  554. package/src/features/player/options.ts +54 -43
  555. package/src/features/player/setup.ts +67 -61
  556. package/src/features/queue/activeTrack.ts +0 -1
  557. package/src/features/queue/queue.ts +48 -20
  558. package/src/features/queue/repeatMode.ts +1 -1
  559. package/src/features/queue/shuffle.ts +0 -1
  560. package/src/features/remoteControls.ts +59 -35
  561. package/src/features/sleepTimer.ts +15 -7
  562. package/src/types/browser-nodes.ts +54 -57
  563. package/src/types/browser.ts +183 -146
  564. package/src/utils/LazyNativeEmitter.ts +6 -9
  565. package/src/utils/NativeUpdatedValue.ts +13 -12
  566. package/src/utils/getTrackIdentity.ts +6 -4
  567. package/src/utils/useDebug.ts +16 -3
  568. package/src/web/NativeAudioBrowser.ts +2 -4
  569. package/src/web/browser/parseSearchResponse.ts +3 -4
  570. package/src/web/browser/sections.ts +1 -1
  571. package/src/web/util/BrowserPathHelper.ts +1 -3
  572. package/website/guide/android-auto.md +25 -13
  573. package/website/guide/android-certificates.md +199 -120
  574. package/website/guide/artwork.md +93 -48
  575. package/website/guide/audio-output.md +86 -68
  576. package/website/guide/automotive.md +15 -10
  577. package/website/guide/basic-usage.md +5 -2
  578. package/website/guide/battery.md +50 -23
  579. package/website/guide/browser.md +155 -68
  580. package/website/guide/carplay.md +132 -49
  581. package/website/guide/configuration.md +85 -49
  582. package/website/guide/equalizer.md +36 -32
  583. package/website/guide/errors.md +106 -64
  584. package/website/guide/favorites.md +41 -31
  585. package/website/guide/gate.md +24 -10
  586. package/website/guide/getting-started.md +55 -2
  587. package/website/guide/hooks.md +53 -47
  588. package/website/guide/live-streams.md +80 -49
  589. package/website/guide/metadata.md +87 -53
  590. package/website/guide/migrating-from-track-player.md +94 -49
  591. package/website/guide/native-callback-fetch.md +46 -36
  592. package/website/guide/network.md +36 -20
  593. package/website/guide/now-playing.md +72 -44
  594. package/website/guide/playback.md +112 -35
  595. package/website/guide/queue.md +77 -43
  596. package/website/guide/remote-controls.md +87 -29
  597. package/website/guide/search.md +37 -22
  598. package/website/guide/sleep-timer.md +35 -14
  599. package/website/guide/track.md +59 -35
@@ -17,76 +17,52 @@ import kotlin.concurrent.thread
17
17
  import timber.log.Timber
18
18
 
19
19
  /**
20
- * Fetches and caches issuer certificates from AIA "CA Issuers" URLs. Used by
21
- * [AiaChasingTrustManager] to fill in intermediates a server failed to send.
20
+ * Fetches and caches issuer certificates from AIA "CA Issuers" URLs, for [AiaChasingTrustManager]
21
+ * to fill in intermediates a server failed to send.
22
22
  *
23
- * Runs on the TLS handshake thread, so it is bounded on every axis and never throws — a failed,
24
- * oversized or slow fetch resolves to an empty list, and the handshake then fails exactly as it
25
- * would have without AIA chasing. Every input here is chosen by a server we are already failing to
26
- * validate: the AIA extension names the host, port and path, and then that host chooses the
27
- * response. So:
28
- * - the URL is rejected unless it is free of control characters ([isSafeUrl]),
29
- * - a response is capped at [MAX_RESPONSE_BYTES] and [MAX_RESPONSE_MILLIS],
30
- * - at most [MAX_REDIRECTS] redirects are followed,
31
- * - the cache holds at most [MAX_CACHE_ENTRIES], and only successful fetches, so a round trip
32
- * happens at most once per intermediate while transient failures stay retryable,
33
- * - the whole call — every connect, handshake, read and redirect hop — ends at the caller's
34
- * `deadlineNanos`: each per-operation timeout is clipped to the time remaining, connect and read
35
- * by their socket timeouts and the TLS handshake plus the exchange by a watchdog that closes the
36
- * underlying transport, and once the deadline has passed nothing further is even started.
23
+ * Runs on the TLS handshake thread and never throws: a failed, oversized or slow fetch is an empty
24
+ * list. Every input is chosen by the server being validated (the AIA URL names host, port and path;
25
+ * that host picks the response), so the URL must pass [isSafeUrl], a response is capped at
26
+ * [MAX_RESPONSE_BYTES] and [MAX_RESPONSE_MILLIS], at most [MAX_REDIRECTS] redirects are followed,
27
+ * and every connect, handshake, read and redirect hop ends at the caller's deadline. Only
28
+ * successful fetches are cached, so failures stay retryable.
37
29
  *
38
- * The one step no deadline reaches is DNS: `InetSocketAddress` resolves synchronously and Java
39
- * exposes no timeout for it, so a lookup begun just inside the deadline can overrun it by its own
40
- * duration. A lookup is never *started* past the deadline, and [AiaCertChaser.MAX_URLS_PER_CERT]
41
- * keeps the count down — a certificate can only make us resolve a few names, not a few hundred.
30
+ * DNS is the one step no deadline reaches: `InetSocketAddress` resolves synchronously with no
31
+ * timeout, so a lookup started just inside the deadline can overrun it. None is started past it,
32
+ * and [AiaCertChaser.MAX_URLS_PER_CERT] bounds how many names a certificate can make us resolve.
42
33
  *
43
- * Both schemes go over a raw [Socket] rather than `HttpURLConnection`. For `http` that is because
44
- * CA "CA Issuers" URLs are virtually always plain `http` — the CA/Browser Forum Baseline
45
- * Requirements mandate it, to avoid a chicken-and-egg TLS dependency when fetching the certificate
46
- * needed to complete a TLS chain — while Android blocks cleartext `HttpURLConnection` traffic by
47
- * default on apps targeting API 28+. A raw socket is not subject to `NetworkSecurityPolicy`, so the
48
- * fetch succeeds regardless of the host app's cleartext setting; safely, because the fetched
49
- * certificate is still cryptographically verified to be the real issuer before
50
- * [AiaChasingTrustManager] trusts it.
51
- *
52
- * For `https` it is because `HttpURLConnection.getInputStream()` performs the connect, request and
53
- * response *headers* before returning a stream, so a read cap applied to that stream bounds only
54
- * the body: a server dripping header bytes just inside the per-read timeout would hold the
55
- * handshake thread for as long as it liked. Reading the headers ourselves puts them inside the same
56
- * budget as the body. It also keeps one redirect policy — the platform stack would otherwise follow
57
- * its own, ignoring [MAX_REDIRECTS].
34
+ * Both schemes go over a raw [Socket], not `HttpURLConnection`:
35
+ * - `http`: CA Issuers URLs are plain `http` (the CA/Browser Forum Baseline Requirements mandate
36
+ * it), and Android blocks cleartext `HttpURLConnection` from API 28 targets. A raw socket is not
37
+ * subject to `NetworkSecurityPolicy`; the fetched certificate is still verified as the real
38
+ * issuer before it is trusted.
39
+ * - `https`: `HttpURLConnection` reads the response headers before handing back a stream, outside
40
+ * any read cap, so a server dripping header bytes could hold the handshake thread indefinitely.
41
+ * It would also follow its own redirect policy instead of [MAX_REDIRECTS].
58
42
  */
59
43
  class CachingCertificateFetcher(
60
44
  private val connectTimeoutMs: Int = 5_000,
61
45
  private val readTimeoutMs: Int = 5_000,
62
46
  private val nowNanos: () -> Long = System::nanoTime,
63
47
  ) {
64
- /**
65
- * Bounded, least-recently-used. An attacker can name any URL and serve any parseable certificate
66
- * from it, so an unbounded map would retain a megabyte per hostile handshake for the process
67
- * lifetime. A real app needs a handful of intermediates.
68
- */
48
+ // LRU and bounded: a hostile server can name any URL and serve any parseable certificate, so an
49
+ // unbounded map would grow per hostile handshake for the life of the process.
69
50
  private val cache =
70
51
  object : LinkedHashMap<String, List<X509Certificate>>(16, 0.75f, true) {
71
52
  override fun removeEldestEntry(eldest: Map.Entry<String, List<X509Certificate>>) =
72
53
  size > MAX_CACHE_ENTRIES
73
54
  }
74
55
 
75
- /**
76
- * A plain system-default socket factory for `https` AIA fetches. Without it the fetch would use
77
- * the process default — which, once this library's AIA factory is installed there, would recurse
78
- * into AIA chasing during the fetch's own handshake.
79
- */
56
+ // System-default, not the process default: once this library's AIA factory is installed as the
57
+ // process default, an `https` fetch through it would recurse into AIA chasing.
80
58
  private val plainSslSocketFactory: SSLSocketFactory by lazy {
81
59
  SSLContext.getInstance("TLS").apply { init(null, null, null) }.socketFactory
82
60
  }
83
61
 
84
62
  /**
85
- * Fetches the certificates served at [url], giving up no later than [deadlineNanos] — absolute,
86
- * on [nowNanos]'s origin. [AiaCertChaser.completeChain] passes its whole-walk deadline here, so
87
- * one budget bounds the sum of every fetch it makes. The default covers a standalone call.
88
- *
89
- * A cache hit is answered even past the deadline — it costs no I/O.
63
+ * The certificates served at [url], or empty on any failure. Gives up by [deadlineNanos],
64
+ * absolute on [nowNanos]'s clock; [AiaCertChaser.completeChain] passes its whole-chase deadline
65
+ * so one budget bounds every fetch it makes. A cache hit is answered even past the deadline.
90
66
  */
91
67
  fun fetch(
92
68
  url: String,
@@ -101,7 +77,6 @@ class CachingCertificateFetcher(
101
77
  return certs
102
78
  }
103
79
 
104
- /** Milliseconds until [deadlineNanos]; zero or negative once it has passed. */
105
80
  private fun remainingMs(deadlineNanos: Long): Long = (deadlineNanos - nowNanos()) / 1_000_000
106
81
 
107
82
  private fun download(
@@ -110,33 +85,29 @@ class CachingCertificateFetcher(
110
85
  redirectsLeft: Int = MAX_REDIRECTS,
111
86
  ): ByteArray? =
112
87
  try {
113
- // Checked before anything is started — DNS included, since it is the one step below that
114
- // no timeout reaches. Redirects recurse through here, so every hop re-checks.
88
+ // Before anything starts, DNS included. Redirects recurse through here, so every hop
89
+ // re-checks the deadline and the URL.
115
90
  require(remainingMs(deadlineNanos) > 0) { "AIA chase budget exhausted" }
116
91
  require(isSafeUrl(url)) { "AIA URL contains characters that are not valid in a URL" }
117
92
  val parsed = URL(url)
118
93
  when (parsed.protocol) {
119
- // restrict to http/https — file:, ftp: etc. are never valid CA-issuer sources
120
94
  "http" -> fetchOverSocket(parsed, deadlineNanos, redirectsLeft, secure = false)
121
95
  "https" -> fetchOverSocket(parsed, deadlineNanos, redirectsLeft, secure = true)
122
96
  else -> null
123
97
  }
124
98
  } catch (e: Exception) {
125
- // The URL is attacker-supplied text and this is the one place it survives the safety
126
- // check, so it is escaped rather than handed to the log verbatim.
99
+ // The URL is server-chosen and may be the one that failed isSafeUrl.
127
100
  Timber.w(e, "AIA CA-issuer fetch failed: %s", sanitizeForLog(url))
128
101
  null
129
102
  }
130
103
 
131
104
  /**
132
- * A connected socket to speak HTTP over, plus the plain TCP transport underneath it. They differ
133
- * for `https`: closing an `SSLSocket` writes a `close_notify` alert, which can itself block
134
- * against a peer that stopped reading — so anything that needs to *unblock* a stalled call must
135
- * close [transport], whose close is immediate and fails every read layered above it.
105
+ * The socket to speak HTTP over, and the plain TCP [transport] beneath it (the same socket for
106
+ * `http`). Closing an `SSLSocket` writes `close_notify`, which can block against a peer that
107
+ * stopped reading, so whatever must unblock a stalled call closes [transport].
136
108
  */
137
109
  private class Connection(val socket: Socket, val transport: Socket)
138
110
 
139
- /** One HTTP/1.0 exchange over a socket, TLS-wrapped when [secure], then redirects. */
140
111
  private fun fetchOverSocket(
141
112
  url: URL,
142
113
  deadlineNanos: Long,
@@ -145,7 +116,7 @@ class CachingCertificateFetcher(
145
116
  ): ByteArray? {
146
117
  val host = url.host
147
118
  val port = if (url.port != -1) url.port else if (secure) 443 else 80
148
- val path = url.file.ifEmpty { "/" } // URL.file is path + query
119
+ val path = url.file.ifEmpty { "/" } // path + query
149
120
  val connection = connect(host, port, secure, deadlineNanos)
150
121
  val raw =
151
122
  try {
@@ -155,9 +126,9 @@ class CachingCertificateFetcher(
155
126
  ) {
156
127
  val socket = connection.socket
157
128
  socket.soTimeout = timeoutMs(deadlineNanos, readTimeoutMs)
158
- // HTTP/1.0 + `Connection: close` so the server closes after the body and we can read
159
- // to EOF without parsing Content-Length. A non-default port belongs in Host, or a
160
- // name-based virtual host answers for the wrong site.
129
+ // HTTP/1.0 with `Connection: close`: the server closes after the body, so it is read to
130
+ // EOF without Content-Length. A non-default port belongs in Host, or a name-based
131
+ // virtual host answers for the wrong site.
161
132
  val hostHeader = if (port == (if (secure) 443 else 80)) host else "$host:$port"
162
133
  val request =
163
134
  "GET $path HTTP/1.0\r\n" +
@@ -178,8 +149,7 @@ class CachingCertificateFetcher(
178
149
  }
179
150
  }
180
151
  } finally {
181
- // Transport first: its close never blocks and unblocks anything above it, so the
182
- // SSLSocket's close_notify attempt afterwards fails fast instead of stalling.
152
+ // Transport first, so the SSLSocket's close_notify then fails fast instead of blocking.
183
153
  runCatching { connection.transport.close() }
184
154
  runCatching { connection.socket.close() }
185
155
  } ?: return null
@@ -187,35 +157,26 @@ class CachingCertificateFetcher(
187
157
  return when {
188
158
  response.status in 200..299 -> response.body
189
159
  response.status in 300..399 && response.location != null && redirectsLeft > 0 ->
190
- // Follow CA-issuer redirects (rare). `download` is the recursion point, so the target
191
- // goes through the same URL check and the same deadline.
192
160
  download(URL(url, response.location).toString(), deadlineNanos, redirectsLeft - 1)
193
161
  else -> null
194
162
  }
195
163
  }
196
164
 
197
165
  /**
198
- * Connects to [host]:[port], wrapping in TLS when [secure]. Both the connect and the TLS
199
- * handshake are clipped to the caller's deadline.
200
- *
201
- * The TLS socket verifies the hostname explicitly. A raw `SSLSocket` does not do it on its own,
202
- * and `SSLParameters.setEndpointIdentificationAlgorithm` is API 24+, so the platform's default
203
- * verifier is applied against the negotiated session instead — which works on every supported
204
- * level and is the same check `HttpsURLConnection` would have made.
166
+ * Connects to [host]:[port], wrapping in TLS when [secure], with the connect and handshake
167
+ * clipped to [deadlineNanos]. The hostname is verified with the platform's default verifier: a
168
+ * raw `SSLSocket` does not verify it, and `setEndpointIdentificationAlgorithm` is API 24+.
205
169
  */
206
170
  private fun connect(host: String, port: Int, secure: Boolean, deadlineNanos: Long): Connection {
207
171
  val plain = Socket()
208
- // Everything from here on closes `plain` if it throws. Android's Socket.connect, unlike
209
- // modern OpenJDK's, does not close itself on failure once the descriptor is allocated, so
210
- // every unreachable AIA host would otherwise leak one until finalization.
172
+ // Android's Socket.connect, unlike OpenJDK's, does not close itself on failure, so the catch
173
+ // below closes `plain` or every unreachable AIA host leaks a descriptor until finalization.
211
174
  var wrapper: SSLSocket? = null
212
175
  return try {
213
176
  plain.connect(InetSocketAddress(host, port), timeoutMs(deadlineNanos, connectTimeoutMs))
214
177
  if (!secure) return Connection(plain, plain)
215
- // The handshake is bounded by a watchdog, not by soTimeout: soTimeout is per-read, so a
216
- // server drip-feeding handshake bytes would stretch it indefinitely. The watchdog closes
217
- // `plain`, the transport — closing the SSLSocket instead would write a close_notify that
218
- // can block against the very peer that caused the stall.
178
+ // soTimeout is per-read, so a peer drip-feeding handshake bytes would outlast it; the
179
+ // watchdog closes the transport, not the SSLSocket (see Connection).
219
180
  withWatchdog(
220
181
  minOf(remainingMs(deadlineNanos), connectTimeoutMs + MAX_RESPONSE_MILLIS),
221
182
  abort = { plain.close() },
@@ -231,32 +192,23 @@ class CachingCertificateFetcher(
231
192
  }
232
193
  } catch (e: Exception) {
233
194
  runCatching { plain.close() }
234
- // The orphaned TLS wrapper too — with the transport already gone its close_notify attempt
235
- // fails fast, and this releases the wrapper's own buffers rather than waiting on the GC.
195
+ // Frees the wrapper's buffers now instead of at GC; with the transport closed, its
196
+ // close_notify fails fast.
236
197
  runCatching { wrapper?.close() }
237
198
  throw e
238
199
  }
239
200
  }
240
201
 
241
- /**
242
- * A per-operation socket timeout: [perOperationMs] clipped to the deadline, and never 0 ("no
243
- * timeout" to a socket) — an already-expired deadline still gets a 1 ms timeout and fails at
244
- * once.
245
- */
202
+ // Never 0, which a socket reads as "no timeout": a passed deadline gets 1 ms and fails at once.
246
203
  private fun timeoutMs(deadlineNanos: Long, perOperationMs: Int): Int =
247
204
  minOf(remainingMs(deadlineNanos), perOperationMs.toLong())
248
205
  .coerceIn(1, Int.MAX_VALUE.toLong())
249
206
  .toInt()
250
207
 
251
208
  /**
252
- * Runs [body] with a watchdog thread that invokes [abort] once [budgetMs] elapses — unless the
253
- * body has already finished, which the done flag makes visible to a watchdog waking at just that
254
- * moment, so a successful exchange cannot have its socket closed out from under it.
255
- *
256
- * The socket timeouts are per-operation and so cannot bound a peer that keeps every individual
257
- * read just inside them; [abort] — closing the underlying transport — is what actually ends a
258
- * stalled handshake or exchange: the blocked call throws, and a failed fetch is already handled
259
- * as "no AIA".
209
+ * Runs [body], calling [abort] from another thread if it is still running after [budgetMs].
210
+ * Socket timeouts are per-operation, so this is what ends a peer that keeps every read just
211
+ * inside them: [abort] closes the transport and the blocked call throws.
260
212
  */
261
213
  private inline fun <T> withWatchdog(
262
214
  budgetMs: Long,
@@ -280,35 +232,29 @@ class CachingCertificateFetcher(
280
232
  companion object {
281
233
  private const val MAX_REDIRECTS = 5
282
234
 
283
- /** Ceiling on how many fetched issuer certificates are retained. */
284
235
  const val MAX_CACHE_ENTRIES = 32
285
236
 
286
- /** Ceiling on a single AIA response, headers included. */
287
- const val MAX_RESPONSE_BYTES = 1 shl 20 // 1 MiB
237
+ /** Ceiling on one AIA response, headers included. */
238
+ const val MAX_RESPONSE_BYTES = 1 shl 20
288
239
 
289
240
  /** Ceiling on the wall-clock time spent reading one AIA response. */
290
241
  const val MAX_RESPONSE_MILLIS = 10_000L
291
242
 
292
243
  /**
293
- * Whether [url] is free of characters that have no business in a URL.
294
- *
295
- * The fetch writes the path into a request line on a raw socket, and the URL is an IA5String
296
- * copied verbatim out of a certificate a hostile server presented. `java.net.URL` preserves
297
- * control characters — `URL("http://host:6379/\r\nSET foo bar")` parses to that host and port
298
- * with the CRLF intact in `file` — so without this check a certificate could inject request
299
- * lines of its own, to any host and port the device can reach. Space is excluded too: it would
300
- * split the request line's target from its HTTP version.
244
+ * Whether [url] is free of control characters, space and DEL. The path is written into a
245
+ * request line on a raw socket, and `java.net.URL` keeps a CRLF in `file`, so a certificate's
246
+ * AIA URL could otherwise inject request lines to any host and port the device can reach; a
247
+ * space would split the request target from the HTTP version.
301
248
  */
302
249
  fun isSafeUrl(url: String): Boolean = url.none { it.code <= 0x20 || it.code == 0x7F }
303
250
 
304
- /** [text] with anything non-printable replaced, so a log line cannot be forged. */
251
+ /** [text] with what [isSafeUrl] refuses replaced by `?`, so a log line cannot be forged. */
305
252
  fun sanitizeForLog(text: String): String =
306
253
  text.map { if (it.code <= 0x20 || it.code == 0x7F) '?' else it }.joinToString("")
307
254
 
308
255
  /**
309
- * Parses every certificate from the bytes a CA-Issuers URL serves — a single DER certificate
310
- * (e.g. Let's Encrypt), a PEM file, or a PKCS#7 "certs-only" bundle. Empty if the bytes are not
311
- * parseable certificates.
256
+ * Every certificate in what a CA Issuers URL serves: a DER certificate, PEM, or a PKCS#7
257
+ * certs-only bundle. Empty if none parse.
312
258
  */
313
259
  fun parseCertificates(bytes: ByteArray): List<X509Certificate> =
314
260
  try {
@@ -320,16 +266,10 @@ class CachingCertificateFetcher(
320
266
  }
321
267
 
322
268
  /**
323
- * Reads [input] to EOF, or returns null once it exceeds [limit] bytes or [budgetMs] of
324
- * wall-clock time. Null rather than a truncated buffer: a cut-off certificate is not parseable
325
- * anyway, and "too big" or "too slow" is a failed fetch, which the caller already knows how to
326
- * treat as "no AIA".
327
- *
328
- * The byte cap alone would not bound the time. The socket's timeout is per-read, so a server
329
- * returning one byte just inside it resets the clock on every iteration and holds the handshake
330
- * thread for as long as it likes — a slow-drip stall in place of the unbounded buffer. Both
331
- * limits are needed, and the deadline is checked against [nowNanos] (injectable so a test need
332
- * not actually wait).
269
+ * [input] read to EOF, or null once it passes [limit] bytes or [budgetMs] of wall-clock time,
270
+ * as measured by [nowNanos]. The time cap matters as much as the byte cap: a socket timeout is
271
+ * per-read, so a server sending a byte just inside it would otherwise hold the thread for as
272
+ * long as the byte cap lasts.
333
273
  */
334
274
  fun readCapped(
335
275
  input: InputStream,
@@ -350,19 +290,16 @@ class CachingCertificateFetcher(
350
290
  }
351
291
  }
352
292
 
353
- /** Status code, `Location` header (if any), and decoded body of a raw HTTP response. */
354
293
  data class HttpResponse(val status: Int, val location: String?, val body: ByteArray)
355
294
 
356
295
  /**
357
- * Splits a raw HTTP/1.0 response into its status code, `Location` header, and body, decoding a
358
- * `Transfer-Encoding: chunked` body if present. Returns null if the bytes are not a
359
- * recognisable HTTP response.
296
+ * Status, `Location` and body of a raw HTTP response, with a chunked body decoded. Null if
297
+ * there is no header terminator or no numeric status.
360
298
  */
361
299
  fun parseHttpResponse(raw: ByteArray): HttpResponse? {
362
300
  val headerEnd = indexOfCrlfCrlf(raw)
363
301
  if (headerEnd < 0) return null
364
302
  val lines = String(raw, 0, headerEnd, Charsets.ISO_8859_1).split("\r\n")
365
- // Status line: "HTTP/1.1 200 OK" — the code is the second token.
366
303
  val status = lines.firstOrNull()?.split(' ')?.getOrNull(1)?.toIntOrNull() ?: return null
367
304
  var location: String? = null
368
305
  var chunked = false
@@ -386,19 +323,17 @@ class CachingCertificateFetcher(
386
323
  while (pos < body.size) {
387
324
  val eol = indexOfCrlf(body, pos)
388
325
  if (eol < 0) break
389
- // chunk-size line may carry a `;chunk-extension` suffix; the size is hex before the `;`.
390
326
  val size =
391
327
  String(body, pos, eol - pos, Charsets.ISO_8859_1)
392
328
  .substringBefore(';')
393
329
  .trim()
394
330
  .toIntOrNull(16) ?: break
395
- // `<= 0`, not `== 0`: toIntOrNull accepts a leading `-`, and a negative size would move
396
- // `pos` backwards — the same rewinding-cursor loop the DER reader had.
397
- if (size <= 0) break // last chunk, or malformed
331
+ // `<= 0`: 0 is the last chunk, and toIntOrNull accepts a `-` that would move `pos` back.
332
+ if (size <= 0) break
398
333
  val dataStart = eol + 2
399
334
  if (dataStart + size > body.size) break
400
335
  out.write(body, dataStart, size)
401
- pos = dataStart + size + 2 // skip the chunk data and its trailing CRLF
336
+ pos = dataStart + size + 2 // past the chunk's trailing CRLF
402
337
  }
403
338
  return out.toByteArray()
404
339
  }
@@ -16,27 +16,16 @@ import kotlinx.coroutines.withTimeout
16
16
  import timber.log.Timber
17
17
 
18
18
  /**
19
- * Exported, token-gated provider serving browse artwork to Android Auto / AAOS (which run in a
20
- * different uid and cannot read a non-exported provider; Media3 issues no URI grant — verified). It
21
- * NEVER fetches a caller-supplied URL: the content URI carries an opaque token, looked up in
22
- * [com.audiobrowser.browser.BrowseArtworkRegistry]; an unknown token returns null. So it cannot be
23
- * used as a fetch proxy / SSRF vector. http(s)-only on the registered finalUrl is defense-in-depth.
19
+ * Serves browse artwork to Android Auto and AAOS as PNG files. It is exported because both run in
20
+ * another uid and Media3 issues no URI grant. So it never fetches a URL the caller supplies: the
21
+ * URI carries an opaque token, and only a token in [com.audiobrowser.browser.BrowseArtworkRegistry]
22
+ * whose URL is http(s) resolves; anything else returns null.
24
23
  *
25
- * Serve design: a real on-disk file via [ParcelFileDescriptor.open] — seekable, no pipe, no writer
26
- * coroutine. The file is keyed by SHA-256 token so identical URLs always reuse the same file.
27
- *
28
- * Bug fixes over the previous pipe/coroutine design: B (FD leak): eliminated — no coroutine
29
- * launched from deps.scope; no writer that could fail to close the write-end of a pipe when the
30
- * scope is already cancelled. C (wedge DoS): eliminated — the Semaphore permit is released in a
31
- * try/finally BEFORE the file is opened for the caller; no blocking write to a pipe while holding
32
- * the permit. D (per-request re-encode): eliminated — on-disk file IS the cache; re-requests are a
33
- * cheap file open (fast path, zero decode, zero network). E (non-seekable pipe): eliminated —
34
- * ParcelFileDescriptor.open returns a regular file FD; statSize is valid; the car's image loader
35
- * can seek.
24
+ * The response is an on-disk file in [ARTWORK_SUBDIR], not a pipe: the car's image loader seeks and
25
+ * reads statSize, which a pipe reports as -1. The file doubles as the cache, keyed by token.
36
26
  */
37
27
  class ArtworkContentProvider : ContentProvider() {
38
28
 
39
- // java.util.concurrent.Semaphore — works on binder threads without a coroutine scope.
40
29
  private val gate = Semaphore(MAX_CONCURRENT)
41
30
 
42
31
  override fun onCreate(): Boolean = true
@@ -53,7 +42,6 @@ class ArtworkContentProvider : ContentProvider() {
53
42
  val artworkDir = File(context!!.cacheDir, ARTWORK_SUBDIR)
54
43
  val file = File(artworkDir, "$token.png")
55
44
 
56
- // Fast path: file already cached on disk — no permit, no decode, no network.
57
45
  if (file.exists() && file.length() > 0) {
58
46
  return try {
59
47
  ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY)
@@ -63,13 +51,13 @@ class ArtworkContentProvider : ContentProvider() {
63
51
  }
64
52
  }
65
53
 
66
- // Produce path (cache miss): bound concurrency, block on binder thread (UAMP pattern).
54
+ // openFile runs on a binder thread, which may block; the gate keeps loads from taking them all.
67
55
  if (!gate.tryAcquire(1, GATE_TIMEOUT_SECONDS, TimeUnit.SECONDS)) {
68
56
  Timber.w("Artwork gate timeout for token=$token — returning null")
69
57
  return null
70
58
  }
71
59
  try {
72
- // Re-check after acquiring — a concurrent producer may have written the file.
60
+ // Another request may have produced the file while this one waited; if pruned since, produce.
73
61
  if (file.exists() && file.length() > 0) {
74
62
  val fd =
75
63
  try {
@@ -79,10 +67,10 @@ class ArtworkContentProvider : ContentProvider() {
79
67
  null
80
68
  }
81
69
  if (fd != null) return fd
82
- // else: file was pruned/deleted concurrently — fall through to produce
83
70
  }
84
71
 
85
72
  artworkDir.mkdirs()
73
+ // Written aside and renamed, so the unlocked fast path never opens a half-written file.
86
74
  val tmp = File.createTempFile(token, ".png.tmp", artworkDir)
87
75
 
88
76
  val bitmap: Bitmap =
@@ -145,7 +133,7 @@ class ArtworkContentProvider : ContentProvider() {
145
133
  private const val LOAD_TIMEOUT_MS = 8_000L
146
134
  internal const val ARTWORK_SUBDIR = "audiobrowser-artwork"
147
135
  const val MAX_CACHE_FILES = 512
148
- /** Overridable in tests only. Production code must not change this. */
136
+ /** Tests only. */
149
137
  @JvmField internal var maxCacheFilesOverride: Int? = null
150
138
  }
151
139
 
@@ -4,12 +4,12 @@ import android.net.Uri
4
4
  import com.audiobrowser.browser.BrowseArtworkRegistry
5
5
  import com.audiobrowser.browser.ResolvedArtwork
6
6
 
7
- /** Routes artwork URLs through the [ArtworkContentProvider]: its registry and authority. */
7
+ /** Routes artwork URLs through the [ArtworkContentProvider] at [authority], via its [registry]. */
8
8
  class ArtworkRoutes(val registry: BrowseArtworkRegistry, val authority: String) {
9
9
  /**
10
- * The `content://` URI that serves http(s) [url], registered with the provider; any other URI as
11
- * it is. A [pinned] registration survives the registry's clear, as does a pinned URI of this
12
- * provider's own.
10
+ * Registers http(s) [url] and returns the `content://` URI the provider serves it at; any other
11
+ * URL comes back unchanged. [pinned] artwork survives [BrowseArtworkRegistry.clear]; pinning one
12
+ * of this provider's own URIs re-pins the artwork it already holds.
13
13
  */
14
14
  fun route(url: String, headers: Map<String, String>?, isSvg: Boolean, pinned: Boolean): String {
15
15
  val uri = Uri.parse(url)
@@ -29,8 +29,8 @@ class ArtworkRoutes(val registry: BrowseArtworkRegistry, val authority: String)
29
29
  }
30
30
 
31
31
  /**
32
- * The URL a URI shows to JS: for one of this provider's URIs the URL it serves, or null once the
33
- * registry has forgotten it; any other URI as it is.
32
+ * The URL to show JS for [uri]: for this provider's URIs the URL it serves, or null once the
33
+ * registry has dropped it; any other URI as its string.
34
34
  */
35
35
  fun publicUrl(uri: Uri): String? {
36
36
  if (uri.authority != authority) return uri.toString()
@@ -3,14 +3,15 @@ package com.audiobrowser.util
3
3
  import android.net.Uri
4
4
  import java.security.MessageDigest
5
5
 
6
- /** Builds and parses the opaque `content://<pkg>.audiobrowser.artwork/art/<token>` URIs. */
6
+ /** Builds and parses the `content://<pkg>.audiobrowser.artwork/art/<token>` artwork URIs. */
7
7
  object ArtworkUris {
8
+ // Must match the provider's `android:authorities` in AndroidManifest.xml.
8
9
  const val AUTHORITY_SUFFIX = "audiobrowser.artwork"
9
10
  private const val PATH = "art"
10
11
 
11
12
  fun authorityFor(packageName: String): String = "$packageName.$AUTHORITY_SUFFIX"
12
13
 
13
- /** Stable, opaque token for a resolved artwork URL (SHA-256 hex). */
14
+ /** A stable token for [url] that does not reveal it to whoever sees the URI (SHA-256 hex). */
14
15
  fun tokenFor(url: String): String {
15
16
  val digest = MessageDigest.getInstance("SHA-256").digest(url.toByteArray(Charsets.UTF_8))
16
17
  return digest.joinToString("") { "%02x".format(it) }
@@ -18,7 +19,7 @@ object ArtworkUris {
18
19
 
19
20
  fun contentUri(authority: String, token: String): String = "content://$authority/$PATH/$token"
20
21
 
21
- /** The `<token>` for a `…/art/<token>` content URI, or null if the shape is wrong. */
22
+ /** The `<token>` of a `content://…/art/<token>` URI, whatever its authority; else null. */
22
23
  fun parseToken(uri: Uri): String? {
23
24
  if (uri.scheme != "content") return null
24
25
  val segments = uri.pathSegments
@@ -3,22 +3,11 @@ package com.audiobrowser.util
3
3
  import com.margelo.nitro.audiobrowser.Variant_String_ArtworkVariants
4
4
 
5
5
  /**
6
- * Reading `Track.artwork`, which is either one URL or a URL per appearance.
7
- *
8
- * Android Auto is dark-only, so there is nothing here to choose: a pair always resolves to its dark
9
- * URL, which is also what a single-URL track would have shipped. The per-appearance half of the
10
- * feature is iOS/CarPlay only — see `ios/Extension/Variant+Artwork.swift`, where both URLs are kept
11
- * so a `UIImageAsset` can swap them without a re-fetch.
6
+ * The URL Android shows: the single URL, or the pair's `dark` one, since Android Auto is dark-only.
7
+ * iOS keeps both (`ios/Extension/Variant+Artwork.swift`).
12
8
  */
13
9
  val Variant_String_ArtworkVariants.url: String
14
10
  get() = match(first = { it }, second = { it.dark })
15
11
 
16
- /**
17
- * Wraps a plain URL as the single-URL side of the union.
18
- *
19
- * For the places that build a `Track` from something that only ever has one image — restored
20
- * persistence, a `MediaMetadata` handed back by the platform. Restoring collapses a pair to its
21
- * dark URL, which costs nothing here: Android Auto would have rendered that one anyway.
22
- */
23
12
  fun artworkOf(url: String?): Variant_String_ArtworkVariants? =
24
13
  url?.let { Variant_String_ArtworkVariants.First(it) }
@@ -3,13 +3,11 @@ package com.audiobrowser.util
3
3
  import android.content.Context
4
4
  import android.content.pm.PackageManager
5
5
 
6
- /**
7
- * Whether this is an Android Automotive OS device, as opposed to a phone projecting Android Auto.
8
- */
6
+ /** True on Android Automotive OS, not on a phone projecting Android Auto. */
9
7
  val Context.isAutomotive: Boolean
10
8
  get() = packageManager.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)
11
9
 
12
- /** Whether the process runs on Android Automotive OS: false until the Player sets it. */
10
+ /** [isAutomotive] for code without a Context: false until the Player sets it. */
13
11
  object Automotive {
14
12
  @Volatile var device = false
15
13
  }
@@ -28,11 +28,7 @@ object BatteryOptimizationHelper {
28
28
  RESTRICTED,
29
29
  }
30
30
 
31
- /**
32
- * Get the current battery optimization status.
33
- *
34
- * Priority: Background restriction > Battery optimization whitelist
35
- */
31
+ /** A background restriction outranks a Doze exemption: the result is then [Status.RESTRICTED]. */
36
32
  fun getStatus(context: Context): Status {
37
33
  val pm = context.getSystemService(Context.POWER_SERVICE) as PowerManager
38
34
  val isIgnoring = pm.isIgnoringBatteryOptimizations(context.packageName)
@@ -55,10 +51,8 @@ object BatteryOptimizationHelper {
55
51
  }
56
52
 
57
53
  /**
58
- * Open settings to let user change battery restrictions.
59
- *
60
- * For OPTIMIZED status: Shows a quick dialog to disable battery optimization (one tap). For
61
- * RESTRICTED status: Opens app settings where user must manually change battery setting.
54
+ * When [Status.OPTIMIZED], shows the system's one-tap exemption dialog; otherwise opens the app's
55
+ * settings page, since the dialog cannot lift a background restriction.
62
56
  */
63
57
  fun openSettings(context: Context) {
64
58
  when (getStatus(context)) {
@@ -3,32 +3,22 @@ package com.audiobrowser.util
3
3
  import android.content.Context
4
4
 
5
5
  /**
6
- * Persists foreground service start failure state using SharedPreferences.
7
- *
8
- * When Android 12+ blocks a foreground service start from background (e.g., Bluetooth resume while
9
- * app is killed), we record this failure so the app can show a warning to the user on their next
10
- * session.
6
+ * Remembers, across process death, that Android 12+ refused to start the foreground service from
7
+ * the background (`ForegroundServiceStartNotAllowedException`, e.g. a Bluetooth resume while the
8
+ * app is killed), so the app can warn the user on its next session.
11
9
  */
12
10
  object BatteryWarningStore {
13
11
  private const val PREFS_NAME = "audio_browser_battery"
14
12
  private const val KEY_WARNING_PENDING = "warning_pending"
15
13
 
16
- /**
17
- * Record that a foreground service start failure occurred. Called when
18
- * ForegroundServiceStartNotAllowedException is caught.
19
- */
20
14
  fun recordFailure(context: Context) {
21
15
  getPrefs(context).edit().putBoolean(KEY_WARNING_PENDING, true).apply()
22
16
  }
23
17
 
24
- /** Check if a warning is pending (failure occurred and not yet dismissed). */
18
+ /** True from [recordFailure] until [clearWarning]. */
25
19
  fun isWarningPending(context: Context): Boolean =
26
20
  getPrefs(context).getBoolean(KEY_WARNING_PENDING, false)
27
21
 
28
- /**
29
- * Clear the pending warning. Called when user dismisses warning or when battery status becomes
30
- * unrestricted.
31
- */
32
22
  fun clearWarning(context: Context) {
33
23
  getPrefs(context).edit().putBoolean(KEY_WARNING_PENDING, false).apply()
34
24
  }