signalapp / Signal-Android

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

Self-compiled app doesn't register with Firebase #13451

Closed farewelltospring closed 6 months ago

farewelltospring commented 6 months ago

Bug description

After setting up Signal (registering or restoring from a backup) after compiling the app from source, Signal prompts the user to "optimize for missing Play Services" in order to retrieve messages while inactive.

Steps to reproduce

Actual result: Observe notice: "Optimize for missing Play Services / This device does not support Play services. Tap to disable system battery optimizations that prevent Signal from retrieving messages while inactive." plus the "background connection enabled" notification. Expected result: No notice, no websocket connection.

Screenshots

n/a

Device info

Device: Sony Xperia 5iii Android version: 13 Signal version: 7.0.2

Link to debug log

https://debuglogs.org/android/7.0.2/89f9c73989f4e19a55e157f61cd5e3509631ddc4196c0e23402a6fc6abc8bce7

nicholas-signal commented 6 months ago

Our Firebase API tokens are matched to our signature. You must register your own Firebase API tokens paired to your signing key, and include them in your custom Signal build.

farewelltospring commented 6 months ago

Thanks for the pointer. Will I have to replace all of the values in app/src/main/res/values/firebase_messaging.xml with values from a firebase project I own (and have paired with my personal signing key)?

nicholas-signal commented 6 months ago

Correct: you will have to provide your own values for all Google/Firebase tokens.

farewelltospring commented 6 months ago

I recompiled with my own Firebase tokens. FCM is successfully registering and I no longer see the "background connection enabled" notification, but I'm not receiving any push notifications from Firebase (The onMessageReceived() log statement never appears in logcat).

After comparing logcat output between the Play Store apk and my local apk (both version 7.0.2), the Play Store apk receives notifications from Firebase correctly:

I ActivityManager: Start proc 14634:org.thoughtcrime.securesms/u0a288 for broadcast {org.thoughtcrime.securesms/com.google.firebase.iid.FirebaseInstanceIdReceiver}
I FcmReceiveService: onMessageReceived() ID: 0:1709617667738038%e3016397f9fd7ecd, Delay: -123 (Server offset: 0), Priority: 1, Original Priority: 1, Network: [isOnVpn: false, isMetered: false]
I ActivityManager: Background started FGS: Allowed [callingPackage: org.thoughtcrime.securesms; callingUid: 10288; uidState: SVC ; intent: Intent { cmp=org.thoughtcrime.securesms/.gcm.FcmFetchForegroundService }; code:PUSH_MESSAGING; tempAllowListReason:<broadcast:u0a127:com.google.android.c2dm.intent.RECEIVE,reason:high-prio FCM,reasonCode:PUSH_MESSAGING,duration:20000,callingUid:10127>; targetSdkVersion:33; callerTargetSdkVersion:33; startForegroundCount:0; bindFromPackage:null]

Whereas my local apk has nothing.

Is it possible that the Signal-Server isn't sending messages correctly? I looked at the code a bit and IIUC, what happens is:

  1. Client registers with Signal-Server
  2. Client registers with Firebase
  3. Client sends FIS token to Signal-Server
  4. Signal-Server stores FIS token verbatim in Redis
  5. When Signal-Server needs to send a message to Client, Signal-Server pulls that stored FIS token and sends the message and the token to Firebase
  6. Firebase decodes the token and sends the message to the Client

If so, then I don't know what's broken, because this process sounds like it should be agnostic to the specific Firebase instance. Regardless, something is broken, because I'm not receiving push notifications even though I'm doing things right.

valldrac commented 6 months ago

I recompiled with my own Firebase tokens.

Don't change all the values in firebase_messaging.xml or it won't work. Just update:

farewelltospring commented 6 months ago

Thanks valldrac, worked like a charm. :D