dev-experiment-uri-exits-the-app.md (4286B)
1 <!-- 2 This file is part of GNU Taler 3 (C) 2026 Taler Systems S.A. 4 5 GNU Taler is free software; you can redistribute it and/or modify it under the 6 terms of the GNU General Public License as published by the Free Software 7 Foundation; either version 3, or (at your option) any later version. 8 9 GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY 10 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 11 A PARTICULAR PURPOSE. See the GNU General Public License for more details. 12 13 You should have received a copy of the GNU General Public License along with 14 GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 15 --> 16 17 # An unknown `dev-experiment` URI closes the wallet, and its error is never shown 18 19 Found by the `uri_dev_experiment` scenario. 20 21 **Severity: low** — `taler://dev-experiment/` is only accepted in developer 22 mode. What makes it worth fixing is the shape of the failure: the error is 23 collected into a variable that nothing will ever display, and the user is 24 dropped onto the Android home screen. 25 26 ## What happens 27 28 Sharing `taler+http://dev-experiment/nonexistent` into the wallet: 29 30 * wallet-core answers with `WALLET_UNEXPECTED_EXCEPTION` (7001): 31 `unexpected exception (message: dev-experiment id not understood nonexistent)` 32 * the wallet **leaves the foreground**: the next screen is the launcher, not 33 the wallet. This happens when the URI arrives while the wallet is closed — 34 scanning a QR code or following a link, which is the ordinary case. With the 35 wallet already open the screen pops back to the main screen instead, so the 36 error is merely invisible rather than disruptive. 37 38 The simulator recorded the screen after the URI as 39 `['At a glance', 'Sat, Oct 17', 'Gmail', 'Photos', 'YouTube', …]` — the 40 emulator's home screen. 41 42 An empty id (`taler+http://dev-experiment/`) behaves differently and correctly: 43 the wallet stays open on the main screen. 44 45 ## Reproduce by hand 46 47 1. Install a debug build and enable **Developer mode**. 48 2. Close the wallet (swipe it away, or 49 `adb shell am force-stop net.taler.wallet.fdroid.debug`) — the URI has to 50 arrive while it is not running. 51 3. Run `adb logcat | grep applyDevExperiment` in a terminal. 52 4. Share the URI into the wallet, e.g. 53 54 ```bash 55 adb shell am start -a android.intent.action.SEND -t text/plain \ 56 -n net.taler.wallet.fdroid.debug/net.taler.wallet.main.MainActivity \ 57 --es android.intent.extra.TEXT 'taler+http://dev-experiment/nonexistent' 58 ``` 59 60 (A QR code with the same text, scanned from the wallet, does the same.) 61 5. The wallet opens, closes again and the home screen appears. The log shows 62 the 7001 error; nothing is shown in the app. 63 64 ## Reproduce with the simulator 65 66 ```bash 67 ssh root@tripwire.taler.net 68 cd /opt/taler-sim/driver 69 python3 ../findings/repro_dev_experiment_uri_exits_app.py 70 ``` 71 72 ## Why 73 74 `wallet/src/main/java/net/taler/wallet/HandleUriScreen.kt:128`: 75 76 ```kotlin 77 action.startsWith("dev-experiment/", ignoreCase = true) -> { 78 model.applyDevExperiment(u2) { error -> 79 errorInfo = error 80 } 81 onNavigateBack() 82 } 83 ``` 84 85 `applyDevExperiment` is asynchronous, and `onNavigateBack()` runs immediately, 86 without waiting for it. Two consequences: 87 88 * the error callback assigns to `errorInfo` after the screen that would render 89 it has already been popped, so the message is lost; 90 * when the URI arrived from outside (a share or a scan), there is nothing 91 behind this screen, so popping it finishes the activity and the user lands 92 on the home screen. 93 94 Every other branch in the same `when` navigates *forward* to a screen that 95 reports its own outcome; this is the only one that pops first. 96 97 ## Suggested fix 98 99 Navigate back only on success, and let the error render: 100 101 ```kotlin 102 action.startsWith("dev-experiment/", ignoreCase = true) -> { 103 model.applyDevExperiment(u2) { error -> 104 errorInfo = error // stays on screen, shows the sheet 105 } 106 // onNavigateBack() only once applyDevExperiment reports success 107 } 108 ``` 109 110 Separately, "dev-experiment id not understood" is a user-supplied value being 111 rejected, so wallet-core returning `WALLET_UNEXPECTED_EXCEPTION` for it is 112 arguably wrong as well; a dedicated code would let the app say what happened.