Native Android client for Spotify, built with Jetpack Compose
Kotlin ad-freeadblockandroidjetpack-composekotlinlyricsmusic-playermusic-videomyspotispotifyspotify-adblockerspotify-clientspotify-connectspotui
Play telemetry (melody, gabo) leaves from the app like the playback states, without the WebView's package-name header
kota-zo1569523145f5
diff --git a/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.kt b/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.ktindex 9ececa51..1a5a94cc 100644--- a/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.kt+++ b/base/host-android/src/main/kotlin/app/myspoti/host/android/ControlRelay.kt@@ -277,13 +277,19 @@ internal class ControlRelay(private val view: WebView, private val fingerprint:* "X-Requested-With: <our package>" — no browser does that, and it was measured on the wire* riding on the telemetry and on the audio files themselves. Relaying through OkHttp is what* removes it; the playback commands were only the first ones (that header alone was enough to- * silence them). One rule on Spotify's side is all it takes to flag every install, so the- * whole API goes through here now.+ * silence them). One rule on Spotify's side is all it takes to flag every install.+ *+ * Only the text endpoints are on the list, the ones whose bodies survive a `String`:+ * the playback commands and states, and the telemetry that reports what was played+ * (`melody`: the plays and the milliseconds really heard, base64 JSON; `gabo-receiver-service`:+ * the event batches). That report is what counts a listen in the history and in Wrapped,+ * and it left the WebView with the package name on it while the commands did not. Widening+ * this to everything else broke the page (protobuf and binary bodies, see the notes).** Login and consent hosts stay out: their flows post forms and redirect, and a relay would* have to reproduce every step exactly to sign in.*/- private val RELAYED = Regex("^https://[a-z0-9-]+(\\.[a-z0-9-]+)*\\.spotify\\.com/(connect-state|track-playback)/v1/")+ private val RELAYED = Regex("^https://[a-z0-9-]+(\\.[a-z0-9-]+)*\\.spotify\\.com/((connect-state|track-playback|melody)/v1/|gabo-receiver-service/)")private val NOT_RELAYED = Regex("^https://(accounts|challenge|www)\\.spotify\\.com/")fun isRelayed(url: String) = RELAYED.containsMatchIn(url) && !NOT_RELAYED.containsMatchIn(url)@@ -323,7 +329,7 @@ internal class ControlRelay(private val view: WebView, private val fingerprint:if (window.__mspMuted) { this.muted = false; this.volume = 0.001; }return play.apply(this, arguments);};- const relayed = /^https:\/\/([a-z0-9-]+\.)*spotify\.com\/(connect-state|track-playback)\/v1\//;+ const relayed = /^https:\/\/([a-z0-9-]+\.)*spotify\.com\/((connect-state|track-playback|melody)\/v1\/|gabo-receiver-service\/)/;const notRelayed = /^https:\/\/(accounts|challenge|www)\.spotify\.com\//;const pending = new Map();let seq = 0;diff --git a/base/host-android/src/test/kotlin/app/myspoti/host/android/ControlRelayTest.kt b/base/host-android/src/test/kotlin/app/myspoti/host/android/ControlRelayTest.ktnew file mode 100644index 00000000..20d276c2--- /dev/null+++ b/base/host-android/src/test/kotlin/app/myspoti/host/android/ControlRelayTest.kt@@ -0,0 +1,26 @@+package app.myspoti.host.android++import org.junit.Assert.assertFalse+import org.junit.Assert.assertTrue+import org.junit.Test++class ControlRelayTest {++ @Test fun `playback commands and states leave from the app`() {+ assertTrue(ControlRelay.isRelayed("https://gew4-spclient.spotify.com/connect-state/v1/player/command/from/a/to/b"))+ assertTrue(ControlRelay.isRelayed("https://gew4-spclient.spotify.com/track-playback/v1/devices/a/state"))+ }++ // What reports a listen (the milliseconds really played) must not leave with the package name.+ @Test fun `play telemetry leaves from the app`() {+ assertTrue(ControlRelay.isRelayed("https://gew4-spclient.spotify.com/melody/v1/msg/batch"))+ assertTrue(ControlRelay.isRelayed("https://gew4-spclient.spotify.com/gabo-receiver-service/v3/events"))+ assertTrue(ControlRelay.isRelayed("https://gew4-spclient.spotify.com/gabo-receiver-service/public/v3/events"))+ }++ @Test fun `sign-in, audio and pages stay with the WebView`() {+ assertFalse(ControlRelay.isRelayed("https://accounts.spotify.com/melody/v1/x"))+ assertFalse(ControlRelay.isRelayed("https://audio-fa.scdn.co/audio/abc"))+ assertFalse(ControlRelay.isRelayed("https://gew4-spclient.spotify.com/widevine-license/v1/audio/license"))+ }+}