signalapp / Signal-Android

A private messenger for Android.
https://signal.org
GNU Affero General Public License v3.0
25.48k stars 6.1k forks source link

Google Play Services aren't used #8992

Closed floriangosse closed 4 years ago

floriangosse commented 5 years ago

Bug description

I'm running Signal on a Motorola Moto G (7) Play which has Google Play Services running. The problem is that Signal doesn't seems to use it because it shows me the notification "Background connection enabled".

I checked how long Signal was running in the background and it shows me that Signal was only running in foreground.

I've setup Signal by restoring a backup but I'm not sure if that is related.

Device info

Device: Motorola Moto G (7) Play Android version: 9.0.0 (Security Patch Level: 1 June 2019) Signal version: 4.45.2

greyson-signal commented 5 years ago

Did you install/register with Google Play Services disabled? Whatever the state is during registration is the state it'll stay. You can't register without play services and then turn them on later to start using them.

Also, how is Google Play Services setup? Are you using microg or something similar? Are you running lineageOS, or a stock ROM?

Also, please post a debug log (Settings > Advanced > Submit debug log). Thanks!

floriangosse commented 5 years ago

I'm using Stock version provided by Motorola. I haven't changed anything on this system.

Here is the debug log: https://debuglogs.org/7ef0cb3f17b8e0946d6745056364fb3eb1e8815932f694f0efd0c775dc63c4bb

I found this line in it:

08-22 10:57:12.321 31302 31337 D IncomingMessageObserver: Network requirement: true, app visible: false, gcm disabled: true

What me confuses me is gcm disabled: true. Because the Google Play Services are running.

ahstro commented 5 years ago

Are push notifications working in general? You can test it with something like Push Notification Tester.

stub42 commented 5 years ago

I had these symptoms. I believe Google Play Services was lacking permissions. Granting permissions to Google Play Services and rebooting did not fix my issue. Reinstalling Signal after that did fix my issue.

floriangosse commented 5 years ago

Are push notifications working in general? You can test it with something like Push Notification Tester.

Push notification work fine for other applications.

My feeling is that I have to reinstall Signal like @stub42 did.

But I think reinstalling is a bad user experience especially for users who are not tech related.

mudeth commented 4 years ago

I have the same issue on an Asus Zenfone 6, Android 9, stock ROM, September security update.

https://debuglogs.org/ab743ad5c11e261b244a84f2ec36fa6dd3234f3247aa4acd0062e5c92d950bbc

Steps I have tried (all failed):

Push notification tester linked to by @ahstro detected GP services and notification worked (tried with 1 second delay).

Unfamiliar with github etiquette, so please educate me if I'm hijacking/diluting the thread.

astatine commented 4 years ago

I have the same issue on my Android One phone (Make and Model: Xiaomi Mi A2) which definitely has Google Play Services with all permissions granted. My device is on the November Security Patch. All other push notifications work fine; I have even tested with the Push Notifications Tester app.

Signal was working fine until I factory-reset my phone and installed all my apps again (because I had to send my phone to get serviced for a hardware issue). I restored Signal messages from backup when I saw the persistent 'background connection enabled' notification. I thought it had something to do with the restored messages, so I even tried with a clean Signal install to no avail.

Debug logs Let me know if you need any more information.

astatine commented 4 years ago

@greyson-signal tagging you so this doesn't slip through the cracks. This is now happening on every phone I install Signal to, including a Samsung Galaxy M30s and Xiaomi Redmi 7A.

EDIT: ~v4.51.6 installs and runs without the annoying 'Background connection enabled' persistent notification on my Mi A2 and Xiaomi Redmi 7A.~ I'll check on the M30s when I get my hands on it next.

EDIT2: Well, looks like I spoke too soon. The 'background connection enabled' persistent notification is back on my Mi A2.

frumble commented 4 years ago

All I can add here is that it has occurred to me on a new Stock ROM Galaxy S9+ on which I set Signal as SMS app right out of system settings before I followed the regular Signal number registration process. After that, the persistent notification told me it is using background services to function. Did clear the app data and reinstalled the app, the problem was then gone afterwards a regular Signal registration as the first step.

forabi commented 4 years ago

I'm affected with this issue too. Phone is ASUS ROG II (WW, Android 9). No other apps complain about missing Play Services. I do have MicroG installed though.

KylePiira commented 4 years ago

I'm also having this problem on a Samsung Galaxy S8 running stock firmware with Google Play Services.

https://debuglogs.org/2e49967ffb408b7fb1c9ab23b69531009f1693df93f250b0dffac435a0f0ebea

ragnese commented 4 years ago

I bet the issue is here: https://github.com/signalapp/Signal-Android/blob/master/src/org/thoughtcrime/securesms/util/PlayServicesUtil.java#L35

That switch statement might need to be more clever about what to do with each code. For example, "SERVICE_MISSING_PERMISSION" might return when I disable Camera permission from Play Services. But Signal shouldn't care about that. https://developers.google.com/android/reference/com/google/android/gms/common/ConnectionResult.html#SERVICE_MISSING_PERMISSION

Same thing with the SIGNIN* results. Do we need to be signed in to Google for Signal to do its thing?

There are a whole bunch of possible results and not all of them should make Signal fallback, by my amateur understanding of things.

https://developers.google.com/android/reference/com/google/android/gms/common/ConnectionResult.html

guimspace commented 4 years ago

https://debuglogs.org/dbdc13c3f3e0efc9b817bb37870e75e6d2452686cb05c9f7bfd78f787d6c87bb

Edit: I've just installed it, and it is working fine now - detected Play Services.

maggu2810 commented 4 years ago

I was hit by this issue now, too. I was running the stock rom on my Pixel XL. I created a local backup and after that I installed LineageOS. I also installed the gapps. Notifications are working for other apps and also the notification test using the linked app above succeeded. I installed signal again amd restored the backup. After that I registered my phone number by call because SMS does not work on my mobile network provider. Now I get the websocket notification about background data usage.

What needs to be done to convince signal to use GCM or give more details why it thinks it is not working?

argonym commented 4 years ago

Could check how other Android OSS apps do the Play Services detection.

maggu2810 commented 4 years ago

I realized that on my system a token has been available, so I wonder why it has not been used.

For me it has been enough to set the option "pref_gcm_disabled" to "false" (in "/data/data/org.thoughtcrime.securesms/shared_prefs/org.thoughtcrime.securesms_preferences.xml").

After that it uses GCM as expected and my battery life is much better now.

I assume there is something wrong in the token handling in the Android app. If a token is available, what's the reason to not use it? I assume if some Play Service is not available, also the token should be missing.

slvchv commented 4 years ago

I have the same problem. It happened recently. Started showing the permanent notification "background connection enabled". Before that everything was fine, I was getting notifications from Signal and I didn't have this issue. Now, I am getting notifications just fine, but the permanent "background connection enabled" is annoying. Here is my log:

https://debuglogs.org/e7bf0d440107dd795b0f2f6e48163471ae25a32c474c44c1827f2f9c8fe482ed

Interesting fact: I was having notification issues with Viber ever since I got this phone. Missed notifications all the time. Tried contacting their support but they were not helpful. This was the reason I installed Signal actually.

I don't have any problems with other notifications. Instagram, Messenger, Twitter all work fine. Even WhatsApp (which I no longer use).

I was on the "beta" channel of Google Play Services. I thought that was the problem. Left the Beta channel, reset the Google Play Services app, installed the non-beta version, reinstalled and re-registered with Signal to no avail.

I am using stock Android 9, Samsung Galaxy A10. Never did any changes to the firmware or ever rooted the device.

schneekluth commented 4 years ago

I realized that on my system a token has been available, so I wonder why it has not been used.

For me it has been enough to set the option "pref_gcm_disabled" to "false" (in "/data/data/org.thoughtcrime.securesms/shared_prefs/org.thoughtcrime.securesms_preferences.xml").

After that it uses GCM as expected and my battery life is much better now.

I assume there is something wrong in the token handling in the Android app. If a token is available, what's the reason to not use it? I assume if some Play Service is not available, also the token should be missing.

These steps solved it for me on my Oneplus 7T / Android 10.

frumble commented 4 years ago

I don’t have this file on a Galaxy S9+. ~/data is empty, but in ~/Android/data/org.thoughtcrime.securesms are just the folders "cache" and "files", both empty and there aren’t any hidden files.

schneekluth commented 4 years ago

You need a rooted device or should use adb. You need to look at /data/data/... but you are looking in path ~/data/...

frumble commented 4 years ago

Ah, got confused by ~/data and /sdcard, Android’s file hierarchy is a mess. OK, tried adb pull but just get permission errors. "adb root" tells me: "adbd cannot run as root in production builds", where can I get the right one? I’m currently using the Arch package "android-tools" but there isn’t an obvious AUR package for root maneuvers. Tried this with an unrooted and a rooted device.

schneekluth commented 4 years ago

Actually I just did this on my phone without adb. Just get a file explorer e.g. MixPlorer, grant root permissions to it and edit the file on the phone. Good Luck

frumble commented 4 years ago

@schneekluth Of course it works with root with a graphical file manager but my mother’s phone, which is still affected by this bug, isn’t rooted, you see?

schneekluth commented 4 years ago

Ah, sorry.

issteve commented 4 years ago

Same problem here after I wanted to use a backup from another device.

Second install with importing a previous backup leads to: "This device does not support play services. Tap to disable system battery optimizations that prevent signal from retrieving messages while inactive." Even with properly functioning google play services.

So first I installed and setup Signal without any issue on my brand new unmodified Motorola one vision with Android One 10. Everything worked like expected. Then I recognized I couldn't just import my backup from my old device (Moto Z Play android 8), I have to place it in a certain folder and reinstall Signal again. So I deinstalled Signal, placed my backup in Signal/Backups and installed Signal again. The Backup got recognized, passphrase correct, all messages imported, some options with every right granted but at the end the message: "This device does not support play services ("Google-Play-Dienste"). Tap to disable system battery optimizations that prevent signal from retrieving messages while inactive." I didn't change anything but installing with a backup. Couldn't manage to get the app recognize the play services even with deinstalling, clearing caches, reboots and so on.

Another try without the backup finally ended with the same issue NOT recognizing the play services like above.

Don't know how to go the adb-way mentioned above without a step by step guide. :-( Anyone willing to help with this?

So no Signal on my new phone? Do I have to stick with my old one? Thanks for your help!

maggu2810 commented 4 years ago

@issteve For the solution I used you need root access to your phone. It would be really great if -- as long as the root cause is not fixed -- the android signal app would provide some experimental options in the app settings. That way you could change the property without requiring root.

issteve commented 4 years ago

@maggu2810 Yes, you are right, this would be a great idea! (I definitely won't root my new phone just to be able to use signal with the Google Play Services.)

Meanwhile the situation got mysteriously even worse.

I reconnected the Signal App on my old phone (without doing any other change to this phone) and have the same problem there now too! So all I did was switching the connection on again and register it again. I did not even use any other app or change any other setting in the mean time. Everything was fine before I stopped the Signal registration and is now weird with just registering it again...

(((Btw. I was thinking what I probably did differently than "the average person"

Debug log (relevant to me looks something between 2020-04-17 18:43 to 18:45 when "gcm disabled" switched (after years) wrong from false to true): https://debuglogs.org/019576a9e7452bc87cad6413959573aaa97d3a3d45d0ce2a201fb926df028f6a

Maybe: 2020-04-17 18:44:05.312 MESZ I TextSecurePreferences: Setting push registered: false 2020-04-17 18:44:05.365 MESZ W PushChallengeRequest: Push challenge not requested, as no FCM token was present ???)))

issteve commented 4 years ago

@greyson-signal Excuse me...

Did you install/register with Google Play Services disabled? Whatever the state is during registration is the state it'll stay. You can't register without play services and then turn them on later to start using them.

...does this mean, once signal switched to assuming (wrongly) there are no play services, simple reregistering could maybe help? Or does it have to be a new install? Or does nothing help as soon as it switched away from the play services?

Thank you for your time and effort!

maggu2810 commented 4 years ago

I also used the "by call" verification as I cannot receive SMS, too.

WRT to my comment above about an UI setting to change the property. Changing the property directly does not make sense (IMHO). But perhaps a button to retrigger the GCM check? Perhaps with a debug log that can be submitted if something goes wrong.

issteve commented 4 years ago

My guess now after further testing: it's related to the verification by call, cause I did investigate a little bit more by changing only the registration method (and phone number): I did reset Google Play services and restarted and reinstalled Signal with no better effect

=> I just deregistered the number in the settings and left the program, but than

Switched it again (without reinstalling or any other changement) but verification by call: same problem switched it again with typing in the verification code (without by call): problem solved

https://debuglogs.org/723dfe4e698d1c9a966ef4f4c199e4ad57feb5416a193a3b93fc086244882163

shows (wrong detection):

2020-04-19 15:48:05.549 MESZ D RegistrationCodeRequest: SMS Verification requested for +**********35 captcha null
2020-04-19 15:48:05.550 MESZ I TextSecurePreferences: Setting push registered: false
2020-04-19 15:48:05.577 MESZ W PushChallengeRequest: Push challenge not requested, as no FCM token was present
[...]
2020-04-19 15:48:55.912 MESZ D IncomingMessageObserver: Network requirement: true, app visible: false, gcm disabled: true

AND shows (right detection):

2020-04-19 15:50:12.290 MESZ D RegistrationCodeRequest: SMS Verification requested for +*********86 captcha null
2020-04-19 15:50:12.290 MESZ I TextSecurePreferences: Setting push registered: false
2020-04-19 15:50:12.314 MESZ I PushChallengeRequest: Requesting a push challenge
2020-04-19 15:50:12.315 MESZ D PushServiceSocket: Push service URL: https://textsecure-service.whispersystems.org
2020-04-19 15:50:12.315 MESZ D PushServiceSocket: Opening URL: https://textsecure-service.whispersystems.org/v1/accounts/fcm/preauth/ceB1P1A8IEo:APA91bGNz5TLWe287m8T9QBrIsGKr_ufmtzCMN6gjE8CLMvzI7TbCkGtnbUh7jXEYPlDg706w_Xr899fwVUvheNdHEj8SK6PZG6LuqaUvtoEPh1b3TwH4SCLqvXehCJQgOGVCl34bNq0/+*********86
2020-04-19 15:50:12.917 MESZ I FcmService: FCM message... Delay: 1102
2020-04-19 15:50:12.918 MESZ D FcmService: Got a push challenge "a6db6da23f1045027088d43500740d2f"
2020-04-19 15:50:12.918 MESZ I PushChallengeRequest: Received a push challenge "a6db6da23f1045027088d43500740d2f" in 603 ms
2020-04-19 15:50:12.918 MESZ D PushServiceSocket: Push service URL: https://textsecure-service.whispersystems.org
2020-04-19 15:50:12.918 MESZ D PushServiceSocket: Opening URL: https://textsecure-service.whispersystems.org/v1/accounts/sms/code/+*********86?client=android-ng&challenge=a6db6da23f1045027088d43500740d2f
[...]
2020-04-19 15:51:16.835 MESZ D IncomingMessageObserver: Network requirement: true, app visible: false, gcm disabled: false
issteve commented 4 years ago

...and by taking a first look at the code I found in: https://github.com/signalapp/Signal-Android/blob/master/app/src/main/java/org/thoughtcrime/securesms/registration/service/RegistrationCodeRequest.java Starting line 122

    /**
     * Device is requesting a phone call.
     *
     * Neither FCM or SMS retrieval is relevant in this mode.
     */
    PHONE_CALL(false, false);

Does this mean FCM could be classified as relevant again (what it obviously is ;-) ) there and could be switched on if a verification by call is used at this place (again)? Maybe just with placing PHONE_CALL(true,false); at this place (please)? Thank you for your consideration...

P.S. In anyway you can see with this bug report FCM is relevant for requesting verification by call. ;-)

It could be something like:

/**
     * Device is requesting a phone call.
     *
     * FCM could be relevant but SMS retrieval is not relevant in this mode.
     */
    PHONE_CALL(true, false);

See: https://github.com/signalapp/Signal-Android/pull/9550

Sorry, as I can't test it without having it integrated in an App from the play store, I'm not able to do the pull request by myself. Anyway I'm willing to test it on three different devices as soon it's available to me.

issteve commented 4 years ago

@johanw666 : I hope I'm not annoying you now, but I think you really brought me on the right track. As you wrote, the code checking if FCM is possible should have nothing to do with the registration method. But it looks like it wrongly does here and causing this bug with just one "false" instead of "true" in line 127... (see above) Could you probably do the required pull request? This would be really helpful... Thank you!

mudeth commented 4 years ago

FIX (bug bypass): Anyone who is subscribed to this thread, please do try what @issteve referenced.

I cleared signal storage and re-registered using SMS OTP. The last few times I did the sms network was congested and I opted for call. This time the play services error did not appear!

maggu2810 commented 4 years ago

I need to migrate my Signal app to another phone. Registration need to be done by voice call (no SMS possible).

@mudeth Which app to use to test the fix? The apk on the Signal webpage or the Play Store beta release?

issteve commented 4 years ago

@maggu2810 : I'm sorry I have to tell you I didn't hear anything back yet from anyone familiar with doing final pull requests like @greyson-signal or @johanw666 . So it looks like the probably fix I suggested - even it would be only the change of one word - is still just lying around here and AFAIK not (yet) merged from any developer into any app.

mudeth commented 4 years ago

@mudeth Which app to use to test the fix? The apk on the Signal webpage or the Play Store beta release?

I used the play store apk (think I've been on the beta for a while now).

I need to migrate my Signal app to another phone. Registration need to be done by voice call (no SMS possible).

You could try temporarily installing the SIM in a device that supports SMS, activate it on your new device and manually type the SMS in maybe?

maggu2810 commented 4 years ago

Sorry, I understand the comment wrong. My understand has been that we should try a potential fix that has been merged upstream.

@mudeth If the fix has not been merged, it does not matter which app to use.

The problem is that my provider of my mobile phone number does not support / deliver SMS.

As I do not want to root my new phone in the first days and activation by voice call does not seem to get fixed, I don't know what to do now...

maggu2810 commented 4 years ago

If I build the Android app myself (with the potential fix) myself,

mudeth commented 4 years ago

@mudeth If the fix has not been merged, it does not matter which app to use.

Yes, that's correct. I just replied with which version was working for me.

If I build the Android app myself (with the potential fix) myself,

I've never built for Android myself and I have zero experience, so take this with a grain of salt, but I would definitely give it a shot at least! Build Instructions are available here.

maggu2810 commented 4 years ago

Seems to work for me for the moment. I restored from backup and did the verification per voice call. After all has been done, I reboot the phone.

After the restart I did not open the app but asked a friend to send a message. A notification has been shown.

Hopefully the app does not decide to set the gcm disabled option to true again after a while.

greyson-signal commented 4 years ago

I've put a "bandaid" in 4.59.2 (currently in beta) to check for play services at app start and get you hooked up to FCM if you have it. Still looking at addressing the root cause.

maggu2810 commented 4 years ago

Great and please excuse the follow question but I cannot found it myself. Where can I download the "current" beta in that case 4.59.2.

In am already in the beta channel on Google Play but it shows me "4.58.5". Also https://signal.org/android/apk/ shows me "4.58.5".

Found it on apkmirror. As long as the signature fits, I assume it is okay to take it from there. But I wonder why the signal webpage does not contain the up-to-date one.

maggu2810 commented 4 years ago

FYI

greyson-signal commented 4 years ago

restart phone start signal no message that google play services are missing no websocket background service notification is shown

That was the "bandaid" :) We sort of "heal" your play services state at app start. As I said, still working on fixing the underlying problem.

vanMacG commented 4 years ago

I'm afraid I stumbled across a side effect of that bandaid... I have lineage with mircoG, so no real FCM/GCM. As the instructions in #8513 said, I disabled microG, installed Signal, registered and got the notfication that the websocket-service will be used. Everything works normal and I get notifications on new messages. But after activating microG again, websocket-notification brakes. Here is the full log: debuglogs.org

As I can see it starts with websocket and gcm disabled 05-07 12:46:29.647 2192 2215 D IncomingMessageObserver: Network requirement: true, app visible: false, gcm disabled: true but then "detects" GCM (aka microG) 05-07 12:46:29.801 2192 2192 I ApplicationContext: Play Services are newly-available. Updating to use FCM. and tries to switch 05-07 12:46:30.124 2192 2254 I FcmRefreshJob: Reregistering FCM... which finally fails 05-07 12:46:32.292 2192 2254 W FcmRefreshJob: GCM reregistration failed after retry attempt exhaustion! In ther end, websocket is disabled and gcm back in control 05-07 12:47:30.420 2192 2215 D IncomingMessageObserver: Network requirement: true, app visible: false, gcm disabled: false --> I don't get notifications on new messages anymore :(

I used Signal with websocket and microG for some months and it worked when it was disabled during registration. But the update yesterday to 4.59.8 seems to have it broken...

breversa commented 4 years ago

Same here on LineageOS 16/MicroG 0.2.10 : before Signal 4.59.8, everything worked fine (and Signal was registered with GCM via MicroG), but since Signal 4.59.8, I don't receive the messages until I open the app.

greyson-signal commented 4 years ago

At some point, I kind of just feel like if you're going to install something that fakes google play services, then you're going to run into problems when that fake doesn't work. I don't know exactly what the solution is for you.

breversa commented 4 years ago

Yes, I understand your feeling. I actually don't require GCM for Signal ; it's just that MicroG happened to be active (I need it for other purposes) when I installed Signal, and now it doesn't work as it used to.

Is there a way to make Signal stop rely on GCM ? Without reinstalling as that'd mean losing years of conversations ?

maggu2810 commented 4 years ago

Without reinstalling as that'd mean losing years of conversations ?

If you create a local backup, you can remove and reinstall the app and restore from backup. So, no conversation is lost.

vanMacG commented 4 years ago

@greyson-signal : Well, I can assume you that I didn't install microG just to fool you as a developer and make your life harder. And sorry it does it anyway! It's because we are trying to maximise our privacy and still are able to use apps. I feel your concerns about this fakes and that it's not your job to determine how's the functionallity of the fake.

But I don't want to argue about the motivations, I will try to propose a solution. I don't want to patronise you, this is just a idea from my side: I understand that you want the easiest solution for the majority of users, which are using play services. These people shouldn't see options, checkboxes or anything, just use their GCM. For the few people like me, the registration process acted like a "switch" like you wrote:

Did you install/register with Google Play Services disabled? Whatever the state is during registration is the state it'll stay.

Now this switch doesn't function anymore because on every startup the state gets detected. What would help us would be to have this switch back. It can be hidden in some sub-categories in the settings, hopefully the normal user won't find it, but people knowing what they want, can do it. Or another proposal: During the registration process, when the search for GCM was negative, there is already a warning-message. Something like "no play services found, only go on when you use a custom rom or know what you do". Maybe there could be an additional checkbox like "diable GCM forever" which is the switch for not trying the "bandaid" at start.

I don't know if this fits in with your agenda, but I think it would help some users (like me).