Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spotify connect #1009

Open
spafm opened this issue Mar 18, 2018 · 38 comments
Open

Spotify connect #1009

spafm opened this issue Mar 18, 2018 · 38 comments
Labels
bug 🐛 can't fix 💔 Issues that are not in AdAways hands specific-app/site-related 📱 Related to a particular site or app or concrete context workaround available 🛠️

Comments

@spafm
Copy link

spafm commented Mar 18, 2018

There is a problem with Spotify app:
"Spotify connect" is not displayed as "available device" if hosts file contains blank lines.

spot

@guest4711
Copy link

Blank lines are valid in hostfiles on all systems (any *BSD, *UX, even on DOS and WIN). So it's a problem of Spotify app to be reported there.

@AnDrOiiiD
Copy link

@guest4711 no it's not fault from the Spotify App as it works if you disable Adaway!

@spafm simply whitelist: spclient.wg.spotify.com

@srwi
Copy link

srwi commented Apr 6, 2018

Whitelisting spclient.wg.spotify.com worked for me too. Thanks!

@srwi
Copy link

srwi commented Apr 11, 2018

Update: Whitelisting spclient.wg.spotify.com stopped working for me.

@simkin
Copy link

simkin commented Apr 25, 2018

Same issue, workaround is not working

@srwi
Copy link

srwi commented Apr 25, 2018

Spotify connect currently works for me by whitelisting the following:

*spotify.com*
104.199.64.74
104.199.65.25
239.255.255.250
35.186.244.62
224.0.0.251

@simkin
Copy link

simkin commented Apr 25, 2018

Somehow not working for me, seems the wildcard *spotify.com* is not catching all.
I see that the client connects to: gew1-accesspoint-b-fl0z.ap.spotify.com

Where the bold characters are randomly generated it seems

@leonardopc
Copy link

I have the same problem, whitelisting all of the previous IPs and spotify.com does not currently work.

@antxxxx
Copy link

antxxxx commented May 4, 2018

I am having the same issue and none of the whitelisting mentioned works.
Some other information that may be helpful.

My laptop running spotify always appears in the spotify app in my phone when it is running, but my sonos speakers normally do not
If I use spotify connect from my laptop to start playing spotify through one of my sonos speakers, then the sonos speaker I am playing on does appear in the spotify app on my phone
Disabling adaway makes all sonos speakers appear in the spotify app on my phone

@simkin
Copy link

simkin commented May 10, 2018

Latest beta fixes this problem

@antxxxx
Copy link

antxxxx commented May 10, 2018

Is that spotify, sonos or adaway beta that fixes the problem?

@simkin
Copy link

simkin commented May 10, 2018

Adaway beta client, shared on xda forum

@antxxxx
Copy link

antxxxx commented May 11, 2018

I tried version 4.0.2 from the xda forum and still had the same issue.

However I have managed to come up with a workaround to get it to work. The problem is in the way the spotify app resolves localhost, so although this works, the reason it is not working is spotify and not a problem with adaway.

To get it to work, I download and apply latest hosts in adaway. Then I opened the hosts file and at the top, you will see 2 entries for localhost - one with an ipv4 address and one with an ipv6 address

127.0.0.1 localhost
::1 localhost

I changed one of the entries to have a different name and saved it - eg

127.0.0.1 localhost
::1 localhost-ipv6

Then spotify app saw my sonos speakers as spotify connect devices.

The downside of this is that it needs to be done each time new files are downloaded in adaway

@martinderm
Copy link

Maybe this Issue should be linked here? https://github.com/AdAway/AdAway/wiki/ProblematicApps

@DaBozzz
Copy link

DaBozzz commented Jul 13, 2018

@antxxxx Thank you so much, your solution solved it for me!

@kalpik
Copy link

kalpik commented Jul 14, 2018

@AnTxXx Thanks! This was driving me crazy!

Any chance this could be fixed within adaway?

@AnTxXx
Copy link

AnTxXx commented Jul 18, 2018

@kalpik you forgot one x (@antxxxx), wrong antxxx :p

@HamonTeacher
Copy link

I having the same issue but fixed it. Thanks to @antxxxx

@anzetal
Copy link

anzetal commented Aug 5, 2018

@antxxxx
How did you edit the file? Any text editor app I use always crashes due to to the sheer number of entries in the file. I tried using sed too but that didn't work

@Vankog Vankog added bug 🐛 won't fix For issues that cannot be resolved or won't be, because of ... reasons specific-app/site-related 📱 Related to a particular site or app or concrete context labels Aug 8, 2018
@Vankog
Copy link
Member

Vankog commented Aug 8, 2018

The localhost entries are standard on virtually all computers. They are NOT blocking rules! These are legitimate entries.

At least the IPv4 version (127.0.0.1 localhost) should be kept. Otherwise all kind of apps and system features might break. If you keep the IPv4 version it should be quite safe to delete the IPv6 entry (::1 localhost or similar) completely, though. There is no value in changing it to another host name. It'll just unnecessarily block the name you changed it to.

@Vankog Vankog added workaround available 🛠️ can't fix 💔 Issues that are not in AdAways hands labels Aug 8, 2018
@antxxxx
Copy link

antxxxx commented Aug 8, 2018

@Vankog agree - its not a problem with adaway and should not be fixed here - the problem is how spotify resolves localhost.

@anzetal - I think I ended up copying the file to my laptop and editing it on there, which I know is not a good solution. I use a custom tasker task now to download the adaway blocking host files and have a toggle to quickly disable or enable using it, and I just disable host file blocking when I want to use spotify and sonos

@Crystal-RainSlide
Copy link

Will adding redirect rule ::1 localhost-ipv6 work, or should we delete/modify ::1 localhost?

@Vankog
Copy link
Member

Vankog commented Aug 10, 2018

short answer: delete ::1 localhost

long answers:

  • Adding another host won't have any effect.
    • It is like adding a block for an adserver that doesn't exist.
    • The localhost entry, which Spotify cannot handle, still exists nonetheless.
  • Renaming ::1 localhost to ::1 localhost-ipv6 effectively is the same as doing both of the above.
    • You delete the localhost entry, which will please Spotify,
    • and add a useless blocking entry.

@Crystal-RainSlide
Copy link

Thanks for your explaining~

@Vankog Vankog removed the won't fix For issues that cannot be resolved or won't be, because of ... reasons label Aug 25, 2018
@geronimoge
Copy link

Just to make sure: if spotify (connect) and adaway is active right now the only solution is the workaround as described earlier?

@github-ronk
Copy link

Summarizing the above and adding my own findings:

The following steps currently seem to mostly solve the issue (which is definitely a bug in Spotify, not in Adaway).

  1. Whitelist *.spotify.com and *.googleusercontent.com
  2. After (re)applying Adaway, do not reboot yet. Edit the hosts file and do all of:
  • Remove the ::1 localhost line
  • Remove any empty lines
  • Remove the final newline in the file (the newline ending the last line)
  1. Reboot device

@rahul-sundaresan
Copy link

rahul-sundaresan commented Nov 18, 2018

EDIT: fixed it
For those having problems editing on PC and copying the changed hosts file via adb or rooted file managers, you can use TWRP file manager to copy the modifed hosts file

@guest4711
Copy link

guest4711 commented Nov 18, 2018 via email

@github-ronk
Copy link

@rahul-sundaresan - Since I like to apply ad-away hosts frequently, I use a shell script to do the modification automatically on the phone itself in a shell window.

(this is from memory - if you want to use it, check it first, and since it must be run as root, I'm adding the expected disclaimer - use at your own risk. This script may: not work as intended, and/or brick your phone, and/or annihilate the whole universe.

function exit5() {
        echo $* - exiting in 5 seconds
        sleep 5
        exit
}

f=/system/etc/hosts
tmpf=/sdcard/myfolder/tmphosts$$.txt

[ -r $f ] || exit5 "cannot read $f"
touch $tmpf || exit5 "cannot create $tmpf"

wcoutput="$(wc -l $f)"
read n f <<<"$wcoutput"

[ "$n" -ge 2 ] || exit5 "bad number of lines $n in $f"
[ -s $tmpf ] && exit5 "non-zero size of $tmpf"

let newn=$((n - 1))
(head -"$newn" $f | grep -v '::1' | grep . ; echo -n $(tail -1 $f) ) > $tmpf

wc -l $f $tmpf
echo -n "If looks OK, hit enter to continue. Otherwise - ^C to abort: "
read && {
        cat $tmpf > $f
        echo -n DONE...
}

rm -f $tmpf
echo bye

@afflux
Copy link

afflux commented Jan 3, 2019

In case anyone wants to understand what is going on: Spotify (in liborbit-jni-spotify.so) looks up the hostname with gethostname, then will do a getaddrinfo(hostname, NULL, ...) and then checks if more than one address was returned. If that is the case, it will do setsockopt(socket, SOL_IP, IP_MULTICAST_IF, addr) for each found IPv4-Address.

On my device, gethostname returns localhost, causing getaddrinfo to return [127.0.0.1, ::1]. As this list contains more than one entry, spotify will bind the socket with IP_MULTICAST_IF to 127.0.0.1 and therefore send out the mDNS broadcast over the lo interface. With the fix, IP_MULTICAST_IF is never set as getaddrinfo returns just one address, and the broadcast will go out through the proper interface.

@github-ronk
Copy link

In case anyone wants to understand ...

Very illuminating, thanks!

@Vankog
Copy link
Member

Vankog commented Jan 3, 2019

On my device, gethostname returns localhost, causing getaddrinfo to return [127.0.0.1, ::1]. As this list contains more than one entry, spotify will bind the socket with IP_MULTICAST_IF to 127.0.0.1 and therefore send out the mDNS broadcast over the lo interface. With the fix, IP_MULTICAST_IF is never set as getaddrinfo returns just one address, and the broadcast will go out through the proper interface.

This actually sounds like a fully fledged Spotify bug. Might be worth reporting this.

127.0.0.1 localhost
::1 localhost

are totally legitimate entries that are globally established. This has nothing to do with AdAway besides the fact that it writes the two entries to the host file.
Spotify should behave accordingly.

@afflux
Copy link

afflux commented Jan 3, 2019

Yup: https://community.spotify.com/t5/Android/Spotify-Connect-not-working-when-localhost-resolves-to-more-than/td-p/4645082

@c64bob
Copy link

c64bob commented Feb 13, 2019

If anyone is interested, I have compiled a patched version of AdAway, that implements this workaround for Spotify (omits the line ::1 localhost). See https://github.com/c64bob/AdAway/releases/tag/v4.1.0

@kalpik
Copy link

kalpik commented Feb 13, 2019

Brilliant! Works perfectly :)

@jimpoison
Copy link

I cannot install the patched version on my oneplus 5t with android 9.
only error message from the packet installer says "app was not installed"
I already tried to first uninstall the original Adaway and then to install the patched one, but the error message stays the same
what could be the problem here?

@simkin
Copy link

simkin commented Mar 11, 2019

Installed fine on my 5t but only after removing/uninstalling original adaway version

@jimpoison
Copy link

i don't know what i did wrong the last time i tried that, but now it works as you described.....so my problem is solved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 can't fix 💔 Issues that are not in AdAways hands specific-app/site-related 📱 Related to a particular site or app or concrete context workaround available 🛠️
Projects
None yet
Development

No branches or pull requests