Commit ef703ce
feat(auth): add API key settings screen (#156)
* feat(auth): add API key settings screen and config manager
Implements the Android-side UI for API authentication, now that
aw-server-rust#608 landed and embedded config loads from app data dir.
- ConfigManager.kt: reads/writes [auth].api_key in config.toml stored at
context.filesDir; uses UUID-based key generation; pure string TOML
manipulation, no extra library dependency
- AuthSettingsActivity.kt: shows current API key, copy-to-clipboard,
regenerate, and enable/disable toggle; prompts user to restart app
after changes (server rereads config at startup)
- activity_auth_settings.xml: layout for the settings screen
- AndroidManifest.xml: registers AuthSettingsActivity
- MainActivity.kt: wires the previously-stub settings button to open
AuthSettingsActivity instead of a Snackbar
- ConfigManagerTest.kt: 11 JVM unit tests covering parse/write logic
including roundtrips and the [auth]-without-key edge case
Closes #145 (partial — "Open in browser" URL
token passing and server restart API are follow-up work)
* fix(auth): address Greptile review findings
- ConfigManager.writeApiKey: scope api_key detection to [auth] section
only, preventing cross-section corruption when other TOML sections
also contain an api_key field
- AuthSettingsActivity: show btnCopy immediately after enable via switch
or regenerate button (was permanently hidden after toggle)
- AuthSettingsActivity: guard switch.isChecked setter with isUpdatingSwitch
flag to prevent double-toast when regenerating key
- Layout: replace deprecated Switch with SwitchMaterial
- ConfigManagerTest: add cross-section api_key isolation regression test
* fix(auth): fully scope writeApiKey operations to [auth] section
The previous fix scoped the apiKeyLinePresent check but still ran
replaceFirst on the full file content, which would still clobber an
api_key field in an earlier TOML section. Now: extract the [auth]
section, perform all string operations within it, then substitute the
modified section back into the full content. Test helper mirrors the fix.
* fix(auth): suppress clipboard preview for API key on Android 13+
Set ClipDescription.EXTRA_IS_SENSITIVE so the system does not show a
plaintext preview toast of the API key when copying on Android 13+.
* fix(auth): use atomic write for config.toml via temp-file rename
* fix(ci): fallback versionCode for fork PRs
* fix(ci): upgrade artifact actions to v4
* fix(ci): use modern Android SDK tools path
* fix(ci): skip signed artifacts on fork PRs
* fix(auth): propagate API key write failures
* fix(ci): repair Linux emulator startup
* fix(ci): handle emulator without kvm acceleration
* fix(ci): make E2E screenshot best effort
* fix(auth): insert API key in newline-less auth section
* ci: re-trigger Test job (stuck pending for 14h)
* fix(ci): remove jniLibs dependency from Test job
Unit tests (./gradlew test) run on the JVM and don't require native
.so files. The jniLibs cache restore was failing because the cache was
saved by a ubicloud runner but the Test job runs on a GitHub-hosted
runner (different cache backend). Remove NDK setup and jniLibs cache
restore from the Test job, and drop the needs:[build-rust] dependency
since there are no longer any shared artifacts.
* fix(ci): restore NDK in Test job — required at Gradle config time
* fix(auth): move ConfigManager I/O off UI thread; fix spurious toast
- Add kotlinx-coroutines-android + lifecycle-runtime-ktx deps
- Wrap all ConfigManager calls in lifecycleScope.launch { withContext(Dispatchers.IO) }
so file reads/writes never block the main thread
- Rename refreshUI() → scheduleRefreshUI() (coroutine launcher) +
applyAuthToUI(auth) (pure UI update) to make the async boundary explicit
- Fix spurious 'Setting saved' toast: only show when the switch ON branch
actually wrote a new key; suppress when auth was already enabled
---------
Co-authored-by: TimeToBuildBob <bob@gptme.org>1 parent 00b06c4 commit ef703ce
8 files changed
Lines changed: 583 additions & 44 deletions
File tree
- .github/workflows
- mobile
- src
- main
- java/net/activitywatch/android
- res/layout
- test/java/net/activitywatch/android
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
99 | 99 | | |
100 | 100 | | |
101 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
102 | 119 | | |
103 | 120 | | |
104 | 121 | | |
| 122 | + | |
105 | 123 | | |
106 | 124 | | |
107 | 125 | | |
108 | 126 | | |
109 | 127 | | |
110 | 128 | | |
| 129 | + | |
111 | 130 | | |
| 131 | + | |
112 | 132 | | |
113 | 133 | | |
114 | 134 | | |
| |||
121 | 141 | | |
122 | 142 | | |
123 | 143 | | |
| 144 | + | |
124 | 145 | | |
125 | 146 | | |
126 | 147 | | |
127 | 148 | | |
128 | 149 | | |
129 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
130 | 156 | | |
131 | 157 | | |
132 | 158 | | |
| |||
136 | 162 | | |
137 | 163 | | |
138 | 164 | | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
139 | 168 | | |
140 | 169 | | |
141 | 170 | | |
| |||
222 | 251 | | |
223 | 252 | | |
224 | 253 | | |
225 | | - | |
| 254 | + | |
226 | 255 | | |
227 | | - | |
| 256 | + | |
228 | 257 | | |
229 | 258 | | |
230 | 259 | | |
231 | 260 | | |
232 | 261 | | |
233 | | - | |
234 | 262 | | |
235 | 263 | | |
236 | 264 | | |
| |||
239 | 267 | | |
240 | 268 | | |
241 | 269 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | 270 | | |
247 | 271 | | |
248 | 272 | | |
249 | 273 | | |
250 | 274 | | |
251 | | - | |
| 275 | + | |
252 | 276 | | |
253 | 277 | | |
254 | 278 | | |
255 | 279 | | |
256 | 280 | | |
257 | 281 | | |
258 | | - | |
259 | 282 | | |
260 | 283 | | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | 284 | | |
277 | 285 | | |
278 | 286 | | |
| |||
328 | 336 | | |
329 | 337 | | |
330 | 338 | | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
331 | 342 | | |
332 | 343 | | |
333 | 344 | | |
334 | 345 | | |
335 | | - | |
336 | | - | |
| 346 | + | |
| 347 | + | |
337 | 348 | | |
338 | 349 | | |
339 | | - | |
| 350 | + | |
340 | 351 | | |
341 | 352 | | |
342 | 353 | | |
| |||
369 | 380 | | |
370 | 381 | | |
371 | 382 | | |
372 | | - | |
373 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
374 | 391 | | |
375 | 392 | | |
376 | 393 | | |
377 | 394 | | |
378 | 395 | | |
379 | | - | |
380 | 396 | | |
381 | 397 | | |
382 | 398 | | |
| |||
422 | 438 | | |
423 | 439 | | |
424 | 440 | | |
425 | | - | |
426 | | - | |
427 | 441 | | |
428 | 442 | | |
429 | 443 | | |
| |||
449 | 463 | | |
450 | 464 | | |
451 | 465 | | |
452 | | - | |
| 466 | + | |
453 | 467 | | |
454 | | - | |
455 | | - | |
| 468 | + | |
| 469 | + | |
456 | 470 | | |
457 | 471 | | |
458 | 472 | | |
459 | 473 | | |
460 | | - | |
| 474 | + | |
461 | 475 | | |
462 | 476 | | |
463 | 477 | | |
| |||
473 | 487 | | |
474 | 488 | | |
475 | 489 | | |
476 | | - | |
| 490 | + | |
477 | 491 | | |
478 | 492 | | |
479 | 493 | | |
| |||
500 | 514 | | |
501 | 515 | | |
502 | 516 | | |
503 | | - | |
| 517 | + | |
504 | 518 | | |
505 | | - | |
| 519 | + | |
506 | 520 | | |
| 521 | + | |
507 | 522 | | |
508 | 523 | | |
509 | 524 | | |
| |||
556 | 571 | | |
557 | 572 | | |
558 | 573 | | |
559 | | - | |
| 574 | + | |
560 | 575 | | |
561 | | - | |
| 576 | + | |
562 | 577 | | |
| 578 | + | |
563 | 579 | | |
564 | 580 | | |
565 | 581 | | |
| |||
581 | 597 | | |
582 | 598 | | |
583 | 599 | | |
584 | | - | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
| 81 | + | |
| 82 | + | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
| |||
0 commit comments