diff options
| author | Adam Soltys <[email protected]> | 2026-09-12 17:06:14 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2026-09-12 17:06:14 -0700 |
| commit | ce61a0f20a2c535e0c69f59836a17f31a3d88468 (patch) | |
| tree | bc80738e4181af5bb8b3ca0844a16d52766c415a /android/app/src/webview/java | |
| parent | 8fe3d0d28d5f15643c1737809c5f1773cb8f9f94 (diff) | |
| download | coinosv3-ce61a0f20a2c535e0c69f59836a17f31a3d88468.tar.gz coinosv3-ce61a0f20a2c535e0c69f59836a17f31a3d88468.zip | |
End to end over the real network, and the advice now fits the app it's in.
A push sent to ntfy.sh reached a killed app on a real phone:
17:02:21.259 ntfy.sh → the phone's ntfy → broadcast to io.coinos.webview
17:02:21.308 app process started (it had been killed)
17:02:21.458 wake: job started
17:02:22.926 wake: finishing (page said so) — 1.7s, and "You were paid"
One thing that took two goes: `adb shell am force-stop` marks a package
STOPPED, and Android delivers no broadcasts to a stopped package unless the
sender sets FLAG_INCLUDE_STOPPED_PACKAGES — which `am broadcast` does and a
real distributor rightly doesn't. The first attempt looked like a failure and
was a test artefact; `am kill`, which is what Android itself does to a
backgrounded app, delivers fine.
And the WebView build can now say something useful about push. It was
inheriting the browser's line — "your browser has no push service, try
Firefox" — which is nonsense inside a WebView that IS the app. It asks the
host what's actually there and says: install a push app like ntfy (nothing
installed), or wait a moment and reopen (a distributor that hasn't answered
yet). Payments and messages still arrive whenever coinos is open, which is
the part that matters most to someone reading an apology.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_019mrt228Upn9nNCwGixzSLx
Diffstat (limited to 'android/app/src/webview/java')
| -rw-r--r-- | android/app/src/webview/java/io/coinos/app/MainActivity.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/android/app/src/webview/java/io/coinos/app/MainActivity.java b/android/app/src/webview/java/io/coinos/app/MainActivity.java index 1c0c9d5..a7980c4 100644 --- a/android/app/src/webview/java/io/coinos/app/MainActivity.java +++ b/android/app/src/webview/java/io/coinos/app/MainActivity.java @@ -17,6 +17,8 @@ import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; +import java.util.List; + /** * The wallet, in a WebView this app owns. * @@ -108,10 +110,30 @@ public class MainActivity extends Activity { && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) { try { requestPermissions(new String[] { Manifest.permission.POST_NOTIFICATIONS }, REQ_PERMS); } catch (Exception ignored) {} } + // The page can ask where it's running and whether anything on this phone + // can deliver a push — the advice it gives is useless otherwise ("use + // Firefox" makes no sense inside a WebView that IS the app). + web.addJavascriptInterface(new Host(), "CoinosHost"); Push.register(this); web.loadUrl(urlFor(getIntent())); } + /** What the page is allowed to ask about its surroundings. */ + private class Host { + @android.webkit.JavascriptInterface + public String env() { + String dist = Push.distributor(MainActivity.this); + List<String> all = Push.distributors(MainActivity.this); + String endpoint = Push.endpoint(MainActivity.this); + return "{\"app\":\"graphene\",\"distributors\":" + all.size() + + ",\"distributor\":" + (dist == null ? "null" : "\"" + dist + "\"") + + ",\"endpoint\":" + (endpoint != null) + "}"; + } + /** The wake job's bridge has this too; here it's a no-op. */ + @android.webkit.JavascriptInterface + public void done() {} + } + /** A scheme intent (lightning:, bitcoin:, nostr:) rides in as ?u=, like the TWA's. */ private String urlFor(Intent intent) { StringBuilder url = new StringBuilder(BASE); |
