diff options
Diffstat (limited to 'android/app/src/main/java')
| -rw-r--r-- | android/app/src/main/java/io/coinos/app/PushReceiver.java | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/android/app/src/main/java/io/coinos/app/PushReceiver.java b/android/app/src/main/java/io/coinos/app/PushReceiver.java index ce3e3f0..b14de53 100644 --- a/android/app/src/main/java/io/coinos/app/PushReceiver.java +++ b/android/app/src/main/java/io/coinos/app/PushReceiver.java @@ -49,14 +49,7 @@ public class PushReceiver extends BroadcastReceiver { case Push.ACTION_MESSAGE: { byte[] bytes = intent.getByteArrayExtra(Push.EXTRA_BYTES_MESSAGE); String body = bytes != null ? new String(bytes) : intent.getStringExtra(Push.EXTRA_MESSAGE); - // On the WebView build the wallet lives in THIS app's storage, so it - // can be woken and told to deal with whatever arrived. On the TWA - // build the wallet is Chrome's and out of reach, so the notification - // is the whole of what we can do. - boolean woke = Wake.start(context, body); - // A payment or a message is news whether or not we handled it; a - // wallet-connect request is not, unless nobody is going to answer it. - if (!woke || !isSilent(body)) notify(context, body); + onPush(context, body); Push.ack(context, intent.getStringExtra(Push.EXTRA_ID)); break; } @@ -65,8 +58,23 @@ public class PushReceiver extends BroadcastReceiver { } } + /** + * A push, however it came (a UnifiedPush distributor, or Firebase in the + * fcm build — FcmService): the same JSON either way. + */ + static void onPush(Context context, String body) { + // On the WebView build the wallet lives in THIS app's storage, so it + // can be woken and told to deal with whatever arrived. On the TWA + // build the wallet is Chrome's and out of reach, so the notification + // is the whole of what we can do. + boolean woke = Wake.start(context, body); + // A payment or a message is news whether or not we handled it; a + // wallet-connect request is not, unless nobody is going to answer it. + if (!woke || !isSilent(body)) notify(context, body); + } + /** Requests the woken wallet answers by itself need no notification. */ - private boolean isSilent(String payload) { + private static boolean isSilent(String payload) { try { JSONObject j = new JSONObject(payload == null ? "{}" : payload); String reason = j.optString("reason", j.optString("type", "")); @@ -79,7 +87,7 @@ public class PushReceiver extends BroadcastReceiver { * describes; anything we don't recognise still gets a notification, because * silence is the one answer that's always wrong here. */ - private void notify(Context c, String payload) { + private static void notify(Context c, String payload) { String title = c.getString(R.string.app_name); String text = c.getString(R.string.push_generic); String deepLink = null; |
