1
0
forked from GRIN/grim

android: one-shot payment-requested notification (id=3)

Fire a separate high-importance system notification when an incoming
payment request (Invoice1 -> SurfaceRequest) is ingested over nostr,
mirroring the existing received-payment notification (id=2). Fail-open on
a missing JNI handle; fires once per not-yet-seen slate. No-op off Android.

Also add examples/tunnel_measure.rs, a dev harness for measuring the Nym
read tunnel (cold connect + warm per-fetch latency over the real transport).
This commit is contained in:
2ro
2026-07-02 22:19:23 -04:00
parent 23bb845689
commit 54344bd1d3
6 changed files with 219 additions and 0 deletions
@@ -27,6 +27,10 @@ public class BackgroundService extends Service {
// sync notification above.
private static final int PAYMENT_NOTIFICATION_ID = 2;
private static final String PAYMENT_CHANNEL_ID = "PaymentReceived";
// One-shot "payment requested" notification (someone asking us to pay them),
// separate from both the sync (id=1) and received-payment (id=2) notifications.
private static final int REQUEST_NOTIFICATION_ID = 3;
private static final String REQUEST_CHANNEL_ID = "PaymentRequested";
private NotificationCompat.Builder mNotificationBuilder;
private String mNotificationContentText = "";
@@ -228,6 +232,40 @@ public class BackgroundService extends Service {
}
}
// Show a one-shot "payment requested" notification (id=3), separate from both
// the persistent sync notification (id=1) and the received-payment one (id=2).
// Called from native code via MainActivity when a payment request (Invoice1)
// arrives over nostr, possibly while the app is backgrounded. Mirrors
// notifyPaymentReceived; strings are composed here Java-side.
public static void notifyPaymentRequested(Context context, String name, String amount) {
NotificationManager manager = context.getSystemService(NotificationManager.class);
if (manager == null) {
return;
}
// High-importance channel so the notification pops with sound + vibration.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(
REQUEST_CHANNEL_ID, "Payment requests", NotificationManager.IMPORTANCE_HIGH
);
manager.createNotificationChannel(channel);
}
Intent i = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_IMMUTABLE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, REQUEST_CHANNEL_ID)
.setContentTitle("Payment requested")
.setContentText(name + " requested " + amount + "")
.setSmallIcon(R.drawable.ic_stat_name)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setAutoCancel(true)
.setDefaults(NotificationCompat.DEFAULT_ALL)
.setContentIntent(pendingIntent);
try {
manager.notify(REQUEST_NOTIFICATION_ID, builder.build());
} catch (SecurityException e) {
// POST_NOTIFICATIONS not granted: skip the notification, never the request.
}
}
// Start the service.
public static void start(Context c) {
if (!isServiceRunning(c)) {
@@ -427,6 +427,12 @@ public class MainActivity extends GameActivity {
BackgroundService.notifyPaymentReceived(this, name, amount);
}
// Called from native code to show a "payment requested" notification
// (BackgroundService id=3) when a payment request arrives over nostr.
public void notifyPaymentRequested(String name, String amount) {
BackgroundService.notifyPaymentRequested(this, name, amount);
}
// Called from native code to set text into clipboard.
public void copyText(String data) {
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);