1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
|
# Compose UI overhaul, step 4: Entry editor. Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Replace the legacy `PasswordCreationActivity`, its generator dialogs, the manual OTP dialog and `SelectFolderActivity` with Compose: an editor destination (`EditRoute`) in `MainActivity`, opened from the list's create sheet and from the entry view's edit action; a generator bottom sheet with random and diceware tabs; OTP from QR (camera or image) and manual; a folder picker dialog shared by the editor and the list's move action. The autofill save flow hosts the same editor. Every save-path check of 0.1.2 stays.
**Architecture:** `EditRoute(dir, name?)` gets an `EditorViewModel` per back stack entry. The form (`EditorForm`: name, folder, password, username, extra) lives in Compose state in that ViewModel only. A new entry starts empty in the list's folder. An edit copies its plaintext once from the `EntryViewModel` of the `EntryRoute` below it on the back stack (`nav.getBackStackEntry<EntryRoute>()`), so plaintext never travels in a route or saved state and no second passphrase prompt is needed. Pure logic (form to pass file, validation, target file, overwrite check, atomic write, OTP URI, generator options) sits in `EditorModel.kt` with unit tests. Saving runs in `activity.lifecycleScope`, like the list's store operations: the ViewModel encrypts (CryptoRepository, unchanged) and writes off the main thread, the destination commits (`commitChange` needs the activity). `FLAG_SECURE` moves out of the destinations into a counted hold in `MainActivity` (`SecureWindow`), so entry and editor can overlap during a transition without clearing it. `AutofillSaveActivity` sets `FLAG_SECURE` for its window and shows `EditorDestination` directly. The legacy editor, its dialogs and layouts, the folder picker activity and fragment, and the now unused `flowbinding` and `swiperefreshlayout` dependencies are deleted.
**Tech Stack:** Kotlin 2.4.21, Compose BOM 2024.09.03 (foundation 1.7.3: `KeyboardOptions(autoCorrectEnabled = ...)`; Material 3 1.3.0: `ModalBottomSheet(properties = ModalBottomSheetProperties(securePolicy = ...))`, `PrimaryTabRow`, `Tab`), navigation-compose 2.8.9 (`getBackStackEntry<T>()`, `popBackStack<T>(inclusive)`), `hilt-navigation-compose` 1.2.0 (`hiltViewModel(viewModelStoreOwner)`), zxing-android-embedded (unchanged), passgen modules (unchanged), kotlin-result 2.0.0. No new dependencies.
Spec: `docs/superpowers/specs/2026-11-02-compose-ui-overhaul-design.md`. Earlier plans: `2026-11-02-compose-foundation.md`, `2026-11-02-compose-list.md`, `2026-11-02-compose-entry.md` (same folder).
## Decisions taken in this plan
- **How plaintext reaches the editor: the entry view's ViewModel.** The `EditRoute` composable looks up the `EntryRoute` back stack entry below it and reads `hiltViewModel<EntryViewModel>(that entry).entry`, then the editor copies it into its own ViewModel once (`EditorViewModel.start`, a no-op afterwards). Rejected: nav arguments or saved state (plaintext in a Bundle, forbidden); re-decrypting in the editor (a second passphrase prompt, or a silent dependency on the cache); an activity-scoped holder (outlives the entry). Consequences, all safe: after process death the restored `EditRoute` finds no plaintext and closes, so the entry view asks for the passphrase again (`ponytail:` marked). The entry's auto-close timer may drop its copy while the editor is open; the editor already has its own, and cancelling returns to an entry that then closes itself, as the old decrypt activity did.
- **Routes and returns.** `EditRoute(dir, name = null)`: `dir` relative to the store root, `name` the entry's file name without `.gpg` (null for a new entry). From the list: `EditRoute(path)`. From the entry view: `EditRoute(folder, name)`. After save: pop to the topmost `ListRoute` (it re-reads the store on resume); with none below (entry opened from a shortcut) the list root replaces the stack, as step 3 decided. After cancel (close icon or system back): pop, back to the list or the entry view. Both go through one guarded path: only the editor on top acts, nothing happens while a save runs, the keyboard is hidden and focus cleared first.
- **Folder picker: a dialog, not a destination.** `FolderPicker` (breadcrumbs plus subfolder rows with counts, New folder, Select, Cancel) returns its pick through a callback into the caller's own state, so there is no result channel across back stack entries. It shows no secrets; its window inherits `FLAG_SECURE` from the editor below. It replaces `SelectFolderActivity` for the editor and the list's move action. "New folder" creates a folder inside the folder shown and opens it, through the list's own `FolderNameDialog` and `folderNameError` (blank, already a file or folder, outside the store by path components), shared rather than copied (maintainer decision 2).
- **Autofill save hosts the Compose editor.** `AutofillSaveActivity` stays an activity (the autofill service starts it) but now calls `setContent { EditorDestination(...) }` with the form prefilled from its intent, instead of starting `PasswordCreationActivity` for a result. It sets `FLAG_SECURE`, uses `NoActionBarThemeM3` and `configChanges="orientation|screenSize"`. After saving it records the autofill match and, for "generate password", returns the fill dataset, exactly as before. This is what lets the legacy editor and its dialogs go in this step (open question 1).
- **FLAG_SECURE is counted.** `MainActivity.holdSecure()` / `releaseSecure()` and a private top-level `SecureWindow(activity)` composable (a `DisposableEffect`) wrap the entry and editor destinations in the `NavHost`. The flag goes on with the first hold and off with the last release, so entry to editor and back never clears it while either is composed. The `EntryDestination`'s own add/clear pair and its `ponytail:` note are removed. The generator sheet and the manual OTP dialog set `SecureFlagPolicy.SecureOn` explicitly; the picker inherits.
- **Save path, every 0.1.2 check kept, three old gaps closed.** In order: `formError` (empty name, `/` in the name, empty password and extra: same messages); `isInsideRepository` on the target (component-wise since 0.1.2), now checked before anything is created (the old editor created the folder first, so a crafted autofill folder name such as `site/../../x` could create directories outside the store); recipients from the nearest `.gpg-id` (`getPGPIdentifiers`, same snackbars for short or invalid IDs); refusal to overwrite another entry, now also when an edit only moves to another folder (the old check missed that case and overwrote silently); encryption to every recipient, refused when a key is missing (`CryptoRepository.encrypt`, untouched): nothing is written and nothing committed, the folder is not even created; the write goes through a temporary file moved over the target, so a failed write cannot truncate the existing entry; on rename or move the old file is deleted, now also for a move without rename (the old editor left a copy), and its autofill matches and recently-used time follow it; then `git add` and commit with the old messages.
- **Generator sheet.** One `ModalBottomSheet`, tabs Random and Diceware, the first tab chosen by the existing "Password generator" setting (`PREF_KEY_PWGEN_TYPE`, default diceware). Options, preference files and keys are the old ones (`PasswordGenerator` file for random, `pwgen` for diceware), so stored choices carry over. Every change regenerates (as the old dialogs did), Generate rolls again, Use fills the password. Errors show in the sheet instead of a toast. Generation runs off the main thread (the diceware word list is read on first use). Lengths are capped by the fields (3 digits, 2 for diceware words), `ponytail:` marked.
- **OTP.** "OTP from QR" opens a small menu: "Scan QR code" (zxing `CaptureActivity`, unchanged, only when the device has a camera) and "Choose an image" (decoded off the main thread). "Manual OTP" opens a dialog with secret and account; spaces in the secret are dropped. The resulting URI line is appended to the extra content on its own line. Both actions hide once the extra content holds a TOTP secret, as before.
- **Username always shown; "Encrypt username" switch dropped.** The spec puts a username field on the editor; the switch only moved text between the name and username fields for the file-based layout (open question 3).
- **"Save and copy" kept, in the overflow.** It now copies only after a successful save, through `copyPasswordToClipboard` (sensitive flag and clear timer). The spec's top bar has Save only (open question 4).
- **"No keys imported" prompt not ported to the editor.** The entry view still has it, and the editor can only edit an entry the entry view decrypted. A new entry on a store without keys fails at encryption with the 0.1.2 refusal ("Could not encrypt the password, nothing was saved: ...").
- **Keyboard types.** Password and extra content use `KeyboardType.Password` (multi-line for the extras), keeping the old `textVisiblePassword` intent that keyboards do not learn them; Compose has no visible-password type, and the text stays visible unless masked by the reveal toggle. Name and username turn autocorrect off.
- **Password visibility** starts from the "Show the password" setting, as in the entry view.
- **Commit failures are not surfaced**, exactly like the list's move and delete (`commitChange` result ignored); a theme or locale change in the middle of a save cancels before the commit, and the next commit picks the file up. `ponytail:` marked.
## Feature parity
### `PasswordCreationActivity`
| Behavior today | Decision |
|---|---|
| `FLAG_SECURE` on the whole activity (`BasePGPActivity`) | Port: counted hold while the editor is composed; `AutofillSaveActivity` sets it for its window |
| Title "New password" / "Edit password", up arrow cancels | Port: "New entry" / "Edit entry" (the app's word), close icon and system back through one guarded close path |
| Name field, focused on a new entry | Port (focus only on first show, not after recreation) |
| Directory field: hidden for new entries from the list, editable text for edits and autofill, created with `createDirectories` before any check | Changed: breadcrumb chips plus "Change" (picker) everywhere; the folder is created when the file is written, after the inside-repository check |
| Username field shown only for the encrypted-username layout or when prefilled | Changed: always shown (spec) |
| "Encrypt username" switch (file-based layout, new entries) | Drop: both fields are always visible (open question 3) |
| Password field, visible while typing, masked when prefilled or generated, toggle | Port: reveal toggle, initial state from "Show the password", monospace |
| "Generate" button opens the classic or diceware dialog per setting | Port: generator icon in the password field opens the sheet; the setting picks the first tab |
| Extra content, multi-line, `textVisiblePassword` | Port: multi-line, `KeyboardType.Password` |
| "Add OTP" hidden once the extras hold a TOTP secret | Port (both OTP actions) |
| OTP: scan QR (camera only), choose an image, enter manually; manual only without a camera | Port: "OTP from QR" menu (scan with a camera, image always), "Manual OTP" dialog |
| OTP import snackbars (success, failure, no image selected) | Port |
| Save | Port: top bar |
| Save and Copy (copied before encrypting, even when the save then failed) | Port in the overflow; copies only after a successful save (open question 4) |
| `requireKeysExist` "No keys imported" dialog with import | Drop: see decisions; a save without the recipient key is refused and writes nothing |
| Validation: empty name, `/` in the name, empty password and extra content | Port (`formError`, same strings) |
| Recipients from the nearest `.gpg-id`, snackbars for short or invalid IDs | Port (`getPGPIdentifiers`) |
| Encrypt to every recipient, refuse when a key is missing (0.1.2) | Port unchanged (`CryptoRepository.encrypt`) |
| Encrypt in memory before writing; nothing written or committed on failure (0.1.2) | Port; the target folder is now also left uncreated |
| Duplicate check for new entries and renames | Port and fix: also for a move to another folder |
| `isInsideRepository` on the target (after creating the folder) | Port, checked first |
| File written in place | Changed: temporary file moved over the target |
| Rename deletes the old file when the name changed | Port and fix: also when only the folder changed |
| Old file not deletable: dialog, no commit, editor closes | Changed: long snackbar, the new file is committed and the editor closes |
| Recently-used time carried over on rename | Port (`moveHistory`, shared with the list's folder rename) |
| Autofill matches of a renamed entry | New: updated like the list's move does (the old editor lost them) |
| Write error: dialog, editor closes | Changed: dialog, the editor stays open with its content |
| Commit "Add generated password for ..." / "Edit password for ..." | Port (named after the new location) |
| Result extras for the caller (created file, name, long name; password and username when generated) | Port as `SaveResult.Saved` for autofill; `MainActivity` returns to the list |
| Rotation recreates the activity; the fields' text went into the saved instance state | Changed: no recreation (`configChanges`), form in ViewModel memory only, never in saved state |
### Generator dialogs
| Behavior today | Decision |
|---|---|
| Random: numerals, symbols, uppercase, lowercase, pronounceable, ambiguous, length; `PasswordGenerator` preferences | Port, same keys and defaults (length 20; 16 when the field is empty) |
| Diceware: word count, separator; `pwgen` preferences | Port, same keys and defaults (5 words, `-`) |
| Regenerate on every change, "Generate", OK, Cancel | Port: regenerate on change, "Generate", "Use", dismiss cancels |
| Generator errors as a toast | Changed: shown in the sheet |
| Monospace preview | Port |
| Generation on the main thread | Changed: off the main thread |
| Dialog window inherits the secure flag | Changed: `SecureOn` explicitly |
### OTP import
| Behavior today | Decision |
|---|---|
| Manual dialog: secret, account; `otpauth://totp?secret=...&issuer=...`; a blank secret appended an empty string | Port: OK disabled while the secret is blank; spaces dropped; issuer percent-encoded |
| zxing `CaptureActivity` launched for a result | Keep as is |
| QR image decoded on the main thread | Port, off the main thread |
### Folder picker (`SelectFolderActivity`, `SelectFolderFragment`)
| Behavior today | Decision |
|---|---|
| Separate activity with a RecyclerView of folders (hidden ones per "Show hidden contents", never `.git`), fast scroller, Select menu item, up arrow | Replace: `FolderPicker` dialog with breadcrumbs (jump up), folder rows with counts, Select, Cancel; same hidden filter; no fast scroller |
| No way to create a folder (the old edit screen took a typed path instead) | New: "New folder" in the picker, the list's dialog and checks |
| Used by the list's move action | Port: the list's move uses `FolderPicker` |
### Deleted in this step (Task 7)
`PasswordCreationActivity.kt`, `EditPasswordScreen.kt` (upstream WIP), `PasswordGeneratorDialogFragment.kt`, `DicewarePasswordGeneratorDialogFragment.kt`, `OtpImportDialogFragment.kt`, `SelectFolderActivity.kt`, `SelectFolderFragment.kt`, `PasswordItemRecyclerAdapter.kt`, layouts `password_creation_activity.xml`, `fragment_pwgen.xml`, `fragment_pwgen_diceware.xml`, `fragment_manual_otp_entry.xml`, `select_folder_layout.xml`, `password_recycler_view.xml`, `password_row_layout.xml`, menus `pgp_handler_new_password.xml`, `pgp_handler_select_folder.xml`, drawables `ic_save_24dp.xml`, `ic_save_copy_24dp.xml`, ui:compose `PasswordField.kt` (`PasswordField`, `CopyButton`: only `EditPasswordScreen` used them), the `flowbinding` and `swiperefreshlayout` dependencies (only the deleted dialogs and `password_recycler_view.xml` used them), the two manifest entries and the two baseline issues in the deleted dialogs.
**What remains of `BasePGPActivity`** (for `AutofillDecryptActivity` until step 7): the class with `requireKeysExist`, the injected `settings`, `repository`, `dispatcherProvider` and `FLAG_SECURE` in `onCreate`; the companion's `EXTRA_FILE_PATH` (`LaunchActivity`, `MainActivity`), `getRelativePath`, `getParentPath`, `getLongName` (`PasswordItem`, `StoreActions`, entry and autofill); the `copyTextToClipboard`, `copyPasswordToClipboard` and `getPGPIdentifiers` extensions. Removed: `repoPath`, `fullPath`, `EXTRA_REPO_PATH` (only the editor used them).
**Kept for later steps:** `PasswordDialog` and `dialog_password_entry.xml` (`AutofillDecryptActivity`, step 7); ui:compose `PasswordItem.kt` and `APSAppBar.kt` (unrelated to the editor; `PGPKeyListActivity` uses `APSAppBar`, steps 5 and 8); `recyclerview`, `recyclerview-selection`, `fastscroll`, `SearchableRepositoryAdapter`, `password_row_background.xml` (autofill filter and git log, steps 6 to 8).
## Lessons from steps 2 and 3, designed in
- `MainActivity` keeps `configChanges="orientation|screenSize"`; `AutofillSaveActivity` gets the same for the same reason (a save running in `lifecycleScope` must survive rotation).
- Slack compose-lint: no composable members on activities (`SecureWindow` is a private top-level function taking the activity); every public composable has `modifier: Modifier = Modifier` as its first optional parameter; no collection parameters (the picker reads its own rows, kept as `ImmutableList`); `EditorViewModel` is a default parameter of `EditorDestination` and only method references and values are passed down.
- Accessibility: every `IconButton` has a content description (close, more options, show or hide password, generate); the editor has no FAB.
- Compose 1.7 focus and keyboard: the editor requests focus only on its first showing per ViewModel (name for a new entry, username for an autofill prefill, nothing for an edit); the guarded close path hides the keyboard and clears focus before leaving, so neither the entry view nor the list comes back with a stray keyboard (the list's own return handling from step 2 still applies).
- Dialogs and sheets are composed only while shown, so each opening starts fresh; the passphrase-style `remember`, never `rememberSaveable`, holds the manual OTP secret and the generated preview.
- Double submit: `EditorViewModel.save` sets `saving` before its first suspension (`lifecycleScope` runs on `Main.immediate`), Save is disabled while it is set, and it stays set after a success; the list's picker ignores a second Select.
- Off the main thread: encryption (CryptoRepository), the overwrite check, the write and delete, subfolder listing, QR decoding, password generation. The `.gpg-id` read stays on the main thread inside `getPGPIdentifiers` (it shows snackbars), as in the entry view.
- One ViewModel per back stack entry (`hiltViewModel()` in the destination).
**Conventions for every task**
- New files get this header:
```kotlin
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
* SPDX-License-Identifier: GPL-3.0-only
*/
```
- Commits are GPG-signed (default config, never disable). End each message with
`Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>`.
- No em dashes in docs, comments or commit messages.
- Before each commit run `./gradlew spotlessApply`, then the step's checks.
- Work on the `compose` branch.
---
### Task 1: Editor model and folder listing (TDD)
**Files:**
- Create: `app/src/main/java/app/passwordstore/ui/editor/EditorModel.kt`
- Test: `app/src/test/java/app/passwordstore/ui/editor/EditorModelTest.kt`
- Modify: `app/src/main/java/app/passwordstore/ui/list/ListModel.kt`
- Modify: `app/src/test/java/app/passwordstore/ui/list/ListModelTest.kt`
- [ ] **Step 1: Failing tests for the editor model**
`app/src/test/java/app/passwordstore/ui/editor/EditorModelTest.kt`:
```kotlin
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.editor
import app.passwordstore.R
import app.passwordstore.data.passfile.PasswordEntry
import app.passwordstore.passgen.random.PasswordOption
import app.passwordstore.util.time.UserClock
import app.passwordstore.util.totp.UriTotpFinder
import java.io.File
import java.nio.file.Files
import kotlin.test.AfterTest
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertFalse
import kotlin.test.assertNull
import kotlin.test.assertTrue
class EditorModelTest {
private val root = Files.createTempDirectory("aps").toFile()
@AfterTest
fun cleanUp() {
root.deleteRecursively()
}
private fun entry(content: String) =
PasswordEntry(UserClock(), UriTotpFinder(), content.encodeToByteArray())
@Test
fun editingWithoutChangesKeepsThePassFile() {
val files =
listOf(
"hunter2\nusername: alice\nurl: https://example.org\n",
"s3cret\notpauth://totp/example.com:carol?secret=JBSWY3DPEHPK3PXP&issuer=example.com\n",
)
for (content in files) assertEquals(content, passContent(editorForm(entry(content), "", "x")))
}
@Test
fun formFromAnEntrySplitsItsFields() {
val form =
editorForm(entry("hunter2\nusername: alice\nurl: https://example.org\n"), "work", "mail")
assertEquals(EditorForm("mail", "work", "hunter2", "alice", "url: https://example.org\n"), form)
}
@Test
fun newEntryContent() {
assertEquals(
"pw\nusername: bob\nnote: x",
passContent(EditorForm(name = "n", password = "pw", username = "bob", extra = "note: x")),
)
assertEquals("pw\n", passContent(EditorForm(name = "n", password = "pw")))
}
@Test
fun formErrors() {
assertEquals(R.string.file_toast_text, formError(EditorForm(name = " ", password = "pw")))
assertEquals(
R.string.invalid_filename_text,
formError(EditorForm(name = "a/b", password = "pw")),
)
assertEquals(R.string.empty_toast_text, formError(EditorForm(name = "a", username = "bob")))
assertNull(formError(EditorForm(name = "a", extra = "note")))
assertNull(formError(EditorForm(name = "a", password = "pw")))
}
@Test
fun entryFileTrimsTheNameAndUsesTheFolder() {
assertEquals(File(root, "work/mail.gpg"), entryFile(root, EditorForm(name = " mail ", dir = "work")))
assertEquals(File(root, "mail.gpg"), entryFile(root, EditorForm(name = "mail")))
}
@Test
fun overwritesOnlyAnotherFile() {
val taken = File(root, "a.gpg").apply { writeText("x") }
assertFalse(overwrites(File(root, "work/b.gpg"), null))
assertTrue(overwrites(taken, null))
assertFalse(overwrites(taken, taken))
assertTrue(overwrites(taken, File(root, "work/b.gpg")))
}
@Test
fun writeEntryCreatesTheFolderAndReplacesTheFile() {
val target = File(root, "new/dir/a.gpg")
writeEntry(target, byteArrayOf(1))
writeEntry(target, byteArrayOf(2, 3))
assertContentEquals(byteArrayOf(2, 3), target.readBytes())
assertEquals(listOf("a.gpg"), target.parentFile!!.list()!!.toList())
}
@Test
fun linesGoOnTheirOwnLine() {
assertEquals("otpauth://x", withLine("", "otpauth://x"))
assertEquals("a\notpauth://x", withLine("a", "otpauth://x"))
assertEquals("a\notpauth://x", withLine("a\n", "otpauth://x"))
}
@Test
fun manualTotpUriIsReadBackByTheParser() {
val uri = totpUri(" JBSW Y3DP EHPK 3PXP ", "Example Co")!!
assertEquals("JBSWY3DPEHPK3PXP", UriTotpFinder().findSecret(uri))
assertEquals("Example Co", UriTotpFinder().findIssuer(uri))
assertTrue(entry("PLACEHOLDER\n$uri").hasTotp())
assertEquals("otpauth://totp?secret=JBSWY3DPEHPK3PXP", totpUri("JBSWY3DPEHPK3PXP", " "))
assertNull(totpUri(" ", "Example Co"))
}
@Test
fun randomOptionsFollowTheCheckboxes() {
assertEquals(listOf(PasswordOption.FullyRandom), RandomSpec().options())
assertEquals(
listOf(
PasswordOption.NoDigits,
PasswordOption.AtLeastOneSymbol,
PasswordOption.NoUppercaseLetters,
PasswordOption.NoLowercaseLetters,
PasswordOption.NoAmbiguousCharacters,
),
RandomSpec(
numerals = false,
symbols = true,
uppercase = false,
lowercase = false,
ambiguous = false,
pronounceable = true,
)
.options(),
)
}
@Test
fun randomPasswordOrWhyNot() {
assertEquals(20, randomPassword(RandomSpec()).value.length)
assertEquals(
R.string.pwgen_no_chars_error,
randomPassword(RandomSpec(numerals = false, uppercase = false, lowercase = false)).error,
)
assertEquals(
R.string.pwgen_length_too_short_error,
randomPassword(RandomSpec(length = 2)).error,
)
}
}
```
Run: `./gradlew :app:testDebugUnitTest --tests app.passwordstore.ui.editor.EditorModelTest`
Expected: compilation FAILS with `Unresolved reference 'EditorForm'` (and the other new names).
- [ ] **Step 2: The editor model**
`app/src/main/java/app/passwordstore/ui/editor/EditorModel.kt`:
```kotlin
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.editor
import androidx.annotation.StringRes
import androidx.compose.runtime.Immutable
import app.passwordstore.R
import app.passwordstore.data.passfile.PasswordEntry
import app.passwordstore.passgen.random.MaxIterationsExceededException
import app.passwordstore.passgen.random.NoCharactersIncludedException
import app.passwordstore.passgen.random.PasswordGenerator
import app.passwordstore.passgen.random.PasswordLengthTooShortException
import app.passwordstore.passgen.random.PasswordOption
import com.github.michaelbull.result.Result
import com.github.michaelbull.result.mapError
import com.github.michaelbull.result.runCatching
import java.io.File
import java.io.IOException
import java.net.URLEncoder
import java.nio.file.Files
import java.nio.file.StandardCopyOption
/**
* What the editor edits. [dir] is the folder relative to the store root ("" is the root), [name]
* the file name without `.gpg`. Plaintext: held in memory only, never in saved state or a route.
*/
@Immutable
data class EditorForm(
val name: String = "",
val dir: String = "",
val password: String = "",
val username: String = "",
val extra: String = "",
)
/** The form for [entry], stored as [name] in [dir], split as the old editor split it. */
fun editorForm(entry: PasswordEntry, dir: String, name: String): EditorForm =
EditorForm(
name = name,
dir = dir,
password = entry.password.orEmpty(),
username = entry.username.orEmpty(),
extra = entry.extraContentWithoutUsername,
)
/** The pass file, as the old editor wrote it: password, `username: ...` when set, the extras. */
fun passContent(form: EditorForm): String {
val username = if (form.username.isEmpty()) "" else "\nusername: ${form.username}"
return "${form.password}$username\n${form.extra}"
}
/** Why [form] cannot be saved, as a string resource, or null when it can. */
@StringRes
fun formError(form: EditorForm): Int? =
when {
form.name.isBlank() -> R.string.file_toast_text
'/' in form.name -> R.string.invalid_filename_text
form.password.isEmpty() && form.extra.isEmpty() -> R.string.empty_toast_text
else -> null
}
/** Where [form] is saved in the store at [root]. */
fun entryFile(root: File, form: EditorForm): File =
File(File(root, form.dir), "${form.name.trim()}.gpg")
/** True when saving to [target] would replace a file other than the [original] being edited. */
fun overwrites(target: File, original: File?): Boolean =
target.exists() && target.canonicalPath != original?.canonicalPath
/**
* Writes [bytes] to [target], creating its folder, through a temporary file moved over it, so a
* failed write never truncates an existing entry.
*/
fun writeEntry(target: File, bytes: ByteArray) {
val dir = target.parentFile ?: throw IOException("No folder for $target")
dir.mkdirs()
val temp = File(dir, ".${target.name}.tmp")
try {
temp.writeBytes(bytes)
Files.move(
temp.toPath(),
target.toPath(),
StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.ATOMIC_MOVE,
)
} finally {
temp.delete()
}
}
/** [extra] with [line] added on a line of its own. */
fun withLine(extra: String, line: String): String =
if (extra.isEmpty() || extra.endsWith('\n')) "$extra$line" else "$extra\n$line"
/**
* An `otpauth://totp` URI, as the old manual OTP dialog built it, for a typed [secret] (spaces
* dropped: authenticators show it in groups) and an optional [issuer]; null for a blank secret.
*/
fun totpUri(secret: String, issuer: String): String? {
val key = secret.filterNot(Char::isWhitespace)
if (key.isEmpty()) return null
fun encode(s: String) = URLEncoder.encode(s, "UTF-8").replace("+", "%20")
val tail = if (issuer.isBlank()) "" else "&issuer=${encode(issuer.trim())}"
return "otpauth://totp?secret=${encode(key)}$tail"
}
/** The random generator's options, as its checkboxes show them; defaults are the old dialog's. */
@Immutable
data class RandomSpec(
val numerals: Boolean = true,
val symbols: Boolean = false,
val uppercase: Boolean = true,
val lowercase: Boolean = true,
val ambiguous: Boolean = true,
val pronounceable: Boolean = false,
val length: Int = 20,
)
/** The generator's options for this spec, negated where the generator asks what to leave out. */
fun RandomSpec.options(): List<PasswordOption> =
listOfNotNull(
PasswordOption.NoDigits.takeUnless { numerals },
PasswordOption.AtLeastOneSymbol.takeIf { symbols },
PasswordOption.NoUppercaseLetters.takeUnless { uppercase },
PasswordOption.NoLowercaseLetters.takeUnless { lowercase },
PasswordOption.NoAmbiguousCharacters.takeUnless { ambiguous },
PasswordOption.FullyRandom.takeUnless { pronounceable },
)
/** A random password for [spec], or the string resource saying why there is none. */
fun randomPassword(spec: RandomSpec): Result<String, Int> =
runCatching { PasswordGenerator.generate(spec.options(), spec.length) }
.mapError { e ->
when (e) {
is MaxIterationsExceededException -> R.string.pwgen_max_iterations_exceeded
is NoCharactersIncludedException -> R.string.pwgen_no_chars_error
is PasswordLengthTooShortException -> R.string.pwgen_length_too_short_error
else -> R.string.pwgen_some_error_occurred
}
}
/** The diceware generator's options; defaults are the old dialog's. */
@Immutable data class DicewareSpec(val words: Int = 5, val separator: Char = '-')
```
Run: `./gradlew :app:testDebugUnitTest --tests app.passwordstore.ui.editor.EditorModelTest`
Expected: `BUILD SUCCESSFUL`, 11 tests pass. If `manualTotpUriIsReadBackByTheParser` fails on the
issuer, the parser (`com.eygraber.uri.Uri`) decodes differently from `URLEncoder`: compare with
`UriTotpFinderTest` and adjust `encode` only, never the test's expectations.
- [ ] **Step 3: Failing test for the picker's folder listing**
In `app/src/test/java/app/passwordstore/ui/list/ListModelTest.kt`, add inside the class, after
the last test:
```kotlin
@Test
fun pickerOffersFoldersByName() {
folder("b")
folder("A")
folder(".hidden")
folder(".git")
file("c.gpg")
assertEquals(listOf("A", "b"), subfolders(root, showHidden = false).map { it.name })
assertEquals(listOf(".hidden", "A", "b"), subfolders(root, showHidden = true).map { it.name })
assertEquals(emptyList<File>(), subfolders(File(root, "missing"), showHidden = false))
}
```
Run: `./gradlew :app:testDebugUnitTest --tests app.passwordstore.ui.list.ListModelTest`
Expected: compilation FAILS with `Unresolved reference 'subfolders'`.
- [ ] **Step 4: The folder listing**
In `app/src/main/java/app/passwordstore/ui/list/ListModel.kt`, add after `childCount`:
```kotlin
/**
* Folders directly inside [dir] that the folder picker offers, by name: never `.git`, other hidden
* folders only with "Show hidden contents" ([showHidden]), as the list filters them.
*/
fun subfolders(dir: File, showHidden: Boolean): List<File> =
dir
.listFiles { f -> f.isDirectory && !f.name.startsWith(".git") && (showHidden || !f.isHidden) }
.orEmpty()
.sortedBy { it.name.lowercase() }
```
Run: `./gradlew :app:testDebugUnitTest --tests app.passwordstore.ui.list.ListModelTest`
Expected: `BUILD SUCCESSFUL`.
- [ ] **Step 5: Checks and commit**
Run: `./gradlew spotlessApply && CI=1 ./gradlew :app:assembleDebug :app:testDebugUnitTest`
Expected: `BUILD SUCCESSFUL`.
```bash
git add app/src/main/java/app/passwordstore/ui/editor/EditorModel.kt \
app/src/test/java/app/passwordstore/ui/editor/EditorModelTest.kt \
app/src/main/java/app/passwordstore/ui/list/ListModel.kt \
app/src/test/java/app/passwordstore/ui/list/ListModelTest.kt
git commit -m "feat(app): add the editor model and the picker's folder listing
Pure functions for the Compose editor: the form and the pass file it
writes, validation, the target file, the overwrite check, an atomic
write, OTP URI building and the random generator's options. The folder
picker lists subfolders with the list's hidden filter.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>"
```
---
### Task 2: Folder picker dialog; the list's move uses it
**Files:**
- Create: `app/src/main/java/app/passwordstore/ui/list/FolderPicker.kt`
- Modify: `app/src/main/java/app/passwordstore/ui/list/ListDestination.kt`
- Modify: `app/src/main/res/values/strings.xml`
- Modify: `app/src/main/res/values-it/strings.xml`
`SelectFolderActivity` stays compiled but unused until Task 7.
- [ ] **Step 1: The picker**
`app/src/main/java/app/passwordstore/ui/list/FolderPicker.kt`:
```kotlin
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.list
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.produceState
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import app.passwordstore.R
import app.passwordstore.ui.compose.BreadcrumbBar
import app.passwordstore.ui.compose.FolderRow
import app.passwordstore.ui.compose.crumbsFor
import app.passwordstore.ui.compose.theme.SpacingMedium
import app.passwordstore.util.extensions.sharedPrefs
import app.passwordstore.util.settings.PreferenceKeys
import java.io.File
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
/**
* Picks a folder of the store at [root], starting at [start] (relative to the root, "" is the
* root): breadcrumbs jump up, rows open subfolders, "New folder" creates one inside the folder
* shown (the list's validation) and opens it, Select reports the folder shown, relative to the
* root. Used by the list's move action and by the editor. Shows no secrets; its window inherits
* FLAG_SECURE from the screen below.
*/
@Composable
fun FolderPicker(
root: File,
start: String,
onPick: (relativePath: String) -> Unit,
onDismiss: () -> Unit,
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
var path by rememberSaveable { mutableStateOf(start) }
var naming by rememberSaveable { mutableStateOf(false) }
val showHidden = remember {
context.sharedPrefs.getBoolean(PreferenceKeys.SHOW_HIDDEN_CONTENTS, false)
}
val rows by
produceState<ImmutableList<ListRow>>(persistentListOf(), path, naming) {
val dir = File(root, path)
value = withContext(Dispatchers.IO) { listRows(subfolders(dir, showHidden), dir).folders }
}
if (naming) {
// The list's own dialog and checks: blank, already a file or folder, outside the store
// (component-wise isInsideRepository).
val dir = File(root, path)
FolderNameDialog(
title = stringResource(R.string.title_create_folder),
message = null,
confirm = stringResource(R.string.button_create),
validate = { folderNameError(it, File(dir, it)) },
onConfirm = { name ->
val folder = File(dir, name).canonicalFile
folder.mkdirs()
naming = false
path = folder.relativeTo(root.canonicalFile).path
},
onDismiss = { naming = false },
)
}
AlertDialog(
onDismissRequest = onDismiss,
modifier = modifier,
title = { Text(stringResource(R.string.folder_picker_title)) },
text = {
Column {
BreadcrumbBar(
crumbsFor(path),
stringResource(R.string.list_store_root),
onCrumbClick = { path = it },
modifier = Modifier.fillMaxWidth().padding(bottom = SpacingMedium),
)
// ponytail: a plain scrolling column, fine for the folders of one level; a LazyColumn
// if a store ever has thousands of subfolders in one folder.
Column(Modifier.heightIn(max = 360.dp).verticalScroll(rememberScrollState())) {
rows.forEach { row ->
key(row.path) {
FolderRow(
name = row.label,
count = row.count,
onClick = { path = File(row.path).relativeTo(root).path },
)
}
}
}
}
},
confirmButton = {
TextButton(onClick = { onPick(path) }) { Text(stringResource(R.string.crypto_select)) }
},
dismissButton = {
Row {
TextButton(onClick = { naming = true }) {
Text(stringResource(R.string.folder_picker_new))
}
TextButton(onClick = onDismiss) { Text(stringResource(R.string.dialog_cancel)) }
}
},
)
}
```
`mkdirs` runs on the main thread, as the list's own "Create folder" does: one directory, no
listing. An empty folder is not tracked by git, so nothing is committed until an entry lands in
it, exactly as with the list's "Create folder".
- [ ] **Step 2: Share the list's folder name dialog**
In `app/src/main/java/app/passwordstore/ui/list/ListDestination.kt`, replace
```kotlin
/** Asks for a folder name; [validate] returns an error string resource or null. */
@Composable
private fun FolderNameDialog(
```
with
```kotlin
/**
* Asks for a folder name; [validate] returns an error string resource or null. Shared with the
* folder picker's "New folder".
*/
@Composable
internal fun FolderNameDialog(
```
(`internal`, not public: Slack's `ComposeModifierMissing` checks public composables only, and the
dialog has no layout to modify. If lint still flags it, add `modifier: Modifier = Modifier` after
`onDismiss` and pass it to its `AlertDialog`.)
- [ ] **Step 3: Strings**
In `app/src/main/res/values/strings.xml`, before `</resources>`, add:
```xml
<!-- Compose folder picker -->
<string name="folder_picker_title">Choose a folder</string>
<string name="folder_picker_new">New folder</string>
```
In `app/src/main/res/values-it/strings.xml`, before `</resources>`, add:
```xml
<!-- Compose folder picker -->
<string name="folder_picker_title">Scegli una cartella</string>
<string name="folder_picker_new">Nuova cartella</string>
```
- [ ] **Step 4: The list's move uses the picker**
In `app/src/main/java/app/passwordstore/ui/list/ListDestination.kt`:
Delete these imports:
```kotlin
import android.app.Activity
import android.content.Intent
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
```
and
```kotlin
import app.passwordstore.ui.folderselect.SelectFolderActivity
```
In `enum class ListDialog`, replace
```kotlin
Delete,
```
with
```kotlin
Delete,
Move,
```
Delete the whole `moveLauncher` block:
```kotlin
val moveLauncher =
rememberLauncherForActivityResult(StartActivityForResult()) { result ->
val data = result.data
val target = data?.getStringExtra("SELECTED_FOLDER_PATH")?.let(::File)
val files = data?.getStringArrayExtra("Files")?.map(::File)
if (result.resultCode == Activity.RESULT_OK && target?.isDirectory == true && files != null) {
selected = emptyList()
activity.lifecycleScope.launch {
activity.moveItems(files, target)
refresh()
}
}
}
```
Replace
```kotlin
onMove = {
moveLauncher.launch(
Intent(activity, SelectFolderActivity::class.java)
.putExtra("Files", selected.toTypedArray())
)
},
```
with
```kotlin
onMove = { dialog = ListDialog.Move },
```
In the `when (dialog)` block, after the `ListDialog.Delete -> Prompt(...)` case (before
`ListDialog.Clone ->`), add:
```kotlin
ListDialog.Move ->
FolderPicker(
root = root,
start = path,
onPick = { target ->
// One move per pick: a double tap on Select must not move twice.
if (dialog == ListDialog.Move) {
val files = selected.map(::File)
dialog = ListDialog.None
selected = emptyList()
activity.lifecycleScope.launch {
activity.moveItems(files, File(root, target))
refresh()
}
}
},
onDismiss = { dialog = ListDialog.None },
)
```
In the KDoc of `ListDestination`, replace
```kotlin
* The list at [path] (relative to the store root): wires [ListScreen] to the [viewModel], the
* legacy activities and the store operations. [onOpenFolder] takes a path relative to the root,
* [onOpenEntry] an entry file.
```
with
```kotlin
* The list at [path] (relative to the store root): wires [ListScreen] to the [viewModel], the
* folder picker, the legacy activities and the store operations. [onOpenFolder] takes a path
* relative to the root, [onOpenEntry] an entry file.
```
- [ ] **Step 5: Checks and commit**
Run: `./gradlew spotlessApply && CI=1 ./gradlew :app:assembleDebug :app:testDebugUnitTest :app:lintDebug`
Expected: `BUILD SUCCESSFUL`. (Full move and "New folder" check on the emulator in Task 8,
step 9.)
```bash
git add app/src/main/java/app/passwordstore/ui/list/FolderPicker.kt \
app/src/main/java/app/passwordstore/ui/list/ListDestination.kt \
app/src/main/res/values/strings.xml app/src/main/res/values-it/strings.xml
git commit -m "feat(app): add the Compose folder picker for moves
A dialog with breadcrumbs, subfolder rows and New folder replaces the
legacy folder picker activity for the list's move action; the editor will
share it. New folder reuses the list's name dialog and checks. A second
tap on Select no longer moves twice.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>"
```
---
### Task 3: Editor ViewModel
**Files:**
- Create: `app/src/main/java/app/passwordstore/ui/editor/EditorViewModel.kt`
- Modify: `app/src/main/java/app/passwordstore/ui/list/StoreActions.kt`
- Modify: `app/src/main/java/app/passwordstore/injection/pwgen/DicewareModule.kt`
- [ ] **Step 1: Shared recently-used move in StoreActions**
In `app/src/main/java/app/passwordstore/ui/list/StoreActions.kt`, replace `renameFolder`:
```kotlin
/** Renames the folder [from] to [to], keeps its recently-used time, then commits. */
suspend fun BaseGitActivity.renameFolder(from: File, to: File) {
if (!moveFile(from, to)) return
val history = getSharedPreferences(HISTORY, Context.MODE_PRIVATE)
val time = history.getString(from.absolutePath.base64())
if (time != null)
history.edit {
remove(from.absolutePath.base64())
putString(to.absolutePath.base64(), time)
}
commitChange(getString(R.string.git_commit_move_text, from.name, to.name))
}
```
with
```kotlin
/** Renames the folder [from] to [to], keeps its recently-used time, then commits. */
suspend fun BaseGitActivity.renameFolder(from: File, to: File) {
if (!moveFile(from, to)) return
moveHistory(from, to)
commitChange(getString(R.string.git_commit_move_text, from.name, to.name))
}
/** Carries the "recently used" time of [from] over to [to]. */
fun Context.moveHistory(from: File, to: File) {
val history = getSharedPreferences(HISTORY, Context.MODE_PRIVATE)
val time = history.getString(from.absolutePath.base64()) ?: return
history.edit {
remove(from.absolutePath.base64())
putString(to.absolutePath.base64(), time)
}
}
```
- [ ] **Step 2: Diceware generator for ViewModels**
In `app/src/main/java/app/passwordstore/injection/pwgen/DicewareModule.kt`, add the import
```kotlin
import dagger.hilt.android.components.ViewModelComponent
```
and replace
```kotlin
@InstallIn(FragmentComponent::class)
```
with
```kotlin
@InstallIn(FragmentComponent::class, ViewModelComponent::class)
```
(`FragmentComponent` goes with the legacy dialog in Task 7.)
- [ ] **Step 3: The ViewModel**
`app/src/main/java/app/passwordstore/ui/editor/EditorViewModel.kt`:
```kotlin
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.editor
import android.content.Context
import android.content.SharedPreferences
import android.graphics.Bitmap
import android.graphics.ImageDecoder
import android.net.Uri
import android.os.Build
import android.provider.MediaStore
import androidx.annotation.StringRes
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.core.content.edit
import androidx.lifecycle.ViewModel
import app.passwordstore.R
import app.passwordstore.crypto.PGPIdentifier
import app.passwordstore.data.crypto.CryptoRepository
import app.passwordstore.data.passfile.PasswordEntry
import app.passwordstore.injection.prefs.PasswordGeneratorPreferences
import app.passwordstore.passgen.diceware.DicewarePassphraseGenerator
import app.passwordstore.passgen.random.PasswordOption
import app.passwordstore.ui.list.moveHistory
import app.passwordstore.util.autofill.AutofillMatcher
import app.passwordstore.util.coroutines.DispatcherProvider
import app.passwordstore.util.extensions.getString
import app.passwordstore.util.settings.PreferenceKeys
import com.github.michaelbull.result.Result
import com.github.michaelbull.result.get
import com.github.michaelbull.result.runCatching
import com.google.zxing.BinaryBitmap
import com.google.zxing.RGBLuminanceSource
import com.google.zxing.common.HybridBinarizer
import com.google.zxing.qrcode.QRCodeReader
import dagger.hilt.android.lifecycle.HiltViewModel
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.IOException
import javax.inject.Inject
import kotlinx.coroutines.withContext
import logcat.LogPriority.ERROR
import logcat.asLog
import logcat.logcat
/** What a save did. */
sealed interface SaveResult {
/**
* Written to [file] from [form]. [staleOriginal] is the old file of a rename or move, left
* behind because it could not be deleted.
*/
data class Saved(val file: File, val form: EditorForm, val staleOriginal: File?) : SaveResult
/** Nothing was written; [message] (a string resource, formatted with [arg]) says why. */
data class Failed(@StringRes val message: Int, val arg: String = "") : SaveResult
}
/**
* The editor's state and work: the [form] (plaintext, in memory only: never in saved state, reset
* when this ViewModel is cleared), the generators and their stored options, QR decoding, and the
* save (encrypt, write, replace the original). Holds no Context; calls take one and use the
* application context.
*/
@HiltViewModel
class EditorViewModel
@Inject
constructor(
private val repository: CryptoRepository,
private val entryFactory: PasswordEntry.Factory,
private val diceware: dagger.Lazy<DicewarePassphraseGenerator>,
@PasswordGeneratorPreferences private val pwgenPrefs: SharedPreferences,
private val dispatcherProvider: DispatcherProvider,
) : ViewModel() {
/** The fields being edited. */
var form by mutableStateOf(EditorForm())
/** Set while a save runs, and after one succeeded (the editor is leaving): saves and closes wait. */
var saving by mutableStateOf(false)
private set
/** Whether [start] filled the form. */
var started = false
private set
/** Fills the form the first time only and returns true then; a recreated activity keeps edits. */
fun start(initial: EditorForm): Boolean {
if (started) return false
started = true
form = initial
return true
}
/** True when [extra] already holds a TOTP secret (the OTP actions hide), as the old editor did. */
fun hasOtp(extra: String): Boolean =
entryFactory.create("PLACEHOLDER\n$extra".encodeToByteArray()).hasTotp()
/** The random generator's options as the old dialog stored them. */
fun randomSpec(context: Context): RandomSpec {
val prefs = context.randomPrefs()
return RandomSpec(
numerals = !prefs.getBoolean(PasswordOption.NoDigits.key, false),
symbols = prefs.getBoolean(PasswordOption.AtLeastOneSymbol.key, false),
uppercase = !prefs.getBoolean(PasswordOption.NoUppercaseLetters.key, false),
lowercase = !prefs.getBoolean(PasswordOption.NoLowercaseLetters.key, false),
ambiguous = !prefs.getBoolean(PasswordOption.NoAmbiguousCharacters.key, false),
pronounceable = !prefs.getBoolean(PasswordOption.FullyRandom.key, true),
length = prefs.getInt(PreferenceKeys.LENGTH, 20),
)
}
/** Stores [spec], as the old dialog did on every generation, then generates off the main thread. */
suspend fun generateRandom(spec: RandomSpec, context: Context): Result<String, Int> {
val options = spec.options()
context.randomPrefs().edit {
PasswordOption.entries.forEach { putBoolean(it.key, it in options) }
putInt(PreferenceKeys.LENGTH, spec.length)
}
return withContext(dispatcherProvider.default()) { randomPassword(spec) }
}
/** The diceware generator's options as the old dialog stored them. */
fun dicewareSpec(): DicewareSpec =
DicewareSpec(
words = pwgenPrefs.getInt(PreferenceKeys.DICEWARE_LENGTH, 5),
separator = pwgenPrefs.getString(PreferenceKeys.DICEWARE_SEPARATOR)?.firstOrNull() ?: '-',
)
/** Stores [spec] and generates a passphrase; the word list is read on first use, off main. */
suspend fun generateDiceware(spec: DicewareSpec): String {
pwgenPrefs.edit {
putInt(PreferenceKeys.DICEWARE_LENGTH, spec.words)
putString(PreferenceKeys.DICEWARE_SEPARATOR, spec.separator.toString())
}
return withContext(dispatcherProvider.io()) {
diceware.get().generatePassphrase(spec.words, spec.separator)
}
}
/** The text of the QR code in the image at [uri], or null when it has none. Off main. */
suspend fun readQr(uri: Uri, context: Context): String? {
val resolver = context.applicationContext.contentResolver
return withContext(dispatcherProvider.io()) {
runCatching {
val bitmap =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
ImageDecoder.decodeBitmap(ImageDecoder.createSource(resolver, uri))
.copy(Bitmap.Config.ARGB_8888, false)
} else {
@Suppress("DEPRECATION") MediaStore.Images.Media.getBitmap(resolver, uri)
}
val pixels = IntArray(bitmap.width * bitmap.height)
bitmap.getPixels(pixels, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height)
val source = RGBLuminanceSource(bitmap.width, bitmap.height, pixels)
QRCodeReader().decode(BinaryBitmap(HybridBinarizer(source))).text
}
.get()
}
}
/**
* Encrypts the form to [ids] and writes it to [target], replacing [original] when the entry was
* renamed or moved. Nothing is written (not even the folder) when [target] would replace another
* entry or when encryption fails; a recipient whose key is missing fails it (see
* CryptoRepository.encrypt). The caller checked [formError] and that [target] is inside the
* store. Returns null when a save already ran or is running.
*/
suspend fun save(
ids: List<PGPIdentifier>,
target: File,
original: File?,
context: Context,
): SaveResult? {
if (saving) return null
saving = true
var result: SaveResult? = null
try {
result = write(ids, target, original, context.applicationContext)
} finally {
// Stays set after a success (the editor is leaving); cleared on failure or cancellation.
if (result !is SaveResult.Saved) saving = false
}
return result
}
override fun onCleared() {
form = EditorForm()
}
private suspend fun write(
ids: List<PGPIdentifier>,
target: File,
original: File?,
app: Context,
): SaveResult {
val form = form
if (withContext(dispatcherProvider.io()) { overwrites(target, original) })
return SaveResult.Failed(R.string.password_creation_duplicate_error)
val out = ByteArrayOutputStream()
val encrypted = repository.encrypt(ids, passContent(form).byteInputStream(), out)
if (!encrypted.isOk) {
logcat(ERROR) { encrypted.error.asLog() }
return SaveResult.Failed(
R.string.password_creation_encrypt_fail_message,
encrypted.error.message.orEmpty(),
)
}
return withContext(dispatcherProvider.io()) {
try {
writeEntry(target, out.toByteArray())
} catch (e: IOException) {
logcat(ERROR) { e.asLog() }
return@withContext SaveResult.Failed(R.string.password_creation_file_write_fail_message)
}
var stale: File? = null
if (original != null && original.canonicalPath != target.canonicalPath) {
if (original.delete() || !original.exists()) {
AutofillMatcher.updateMatches(app, moveFromTo = mapOf(original to target))
app.moveHistory(original, target)
} else {
stale = original
}
}
SaveResult.Saved(target, form, stale)
}
}
private fun Context.randomPrefs(): SharedPreferences =
getSharedPreferences(RANDOM_PREFS, Context.MODE_PRIVATE)
private companion object {
/** The old random generator dialog's preferences file. */
const val RANDOM_PREFS = "PasswordGenerator"
}
}
```
- [ ] **Step 4: Checks and commit**
Run: `./gradlew spotlessApply && CI=1 ./gradlew :app:assembleDebug :app:testDebugUnitTest :app:lintDebug`
Expected: `BUILD SUCCESSFUL` (Hilt generates the ViewModel factory; nothing uses it yet). If Hilt
reports a missing binding for `PasswordEntry.Factory` in `ViewModelComponent`, check that
`TotpModule` still lists `ViewModelComponent` (added in step 3).
```bash
git add app/src/main/java/app/passwordstore/ui/editor/EditorViewModel.kt \
app/src/main/java/app/passwordstore/ui/list/StoreActions.kt \
app/src/main/java/app/passwordstore/injection/pwgen/DicewareModule.kt
git commit -m "feat(app): add the editor ViewModel
Holds the form in memory only, generates passwords with the stored
generator options, decodes QR images and saves off the main thread:
nothing is written when the target would replace another entry or when
encryption fails, the file is written through a temporary file, and a
renamed or moved entry takes its autofill matches and recently-used time
along.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>"
```
---
### Task 4: Editor screen, generator sheet, OTP dialog and strings
**Files:**
- Create: `app/src/main/java/app/passwordstore/ui/editor/EditorScreen.kt`
- Create: `app/src/main/java/app/passwordstore/ui/editor/GeneratorSheet.kt`
- Modify: `app/src/main/res/values/strings.xml`
- Modify: `app/src/main/res/values-it/strings.xml`
- [ ] **Step 1: Strings**
In `app/src/main/res/values/strings.xml`, before `</resources>`, add:
```xml
<!-- Compose editor -->
<string name="editor_new_title">New entry</string>
<string name="editor_edit_title">Edit entry</string>
<string name="editor_close">Close</string>
<string name="editor_folder">Folder</string>
<string name="editor_change_folder">Change</string>
<string name="editor_otp_qr">OTP from QR</string>
<string name="editor_otp_manual">Manual OTP</string>
<string name="generator_random">Random</string>
<string name="generator_diceware" translatable="false">Diceware</string>
<string name="generator_use">Use</string>
```
In `app/src/main/res/values-it/strings.xml`, before `</resources>`, add:
```xml
<!-- Compose editor -->
<string name="editor_new_title">Nuova voce</string>
<string name="editor_edit_title">Modifica voce</string>
<string name="editor_close">Chiudi</string>
<string name="editor_folder">Cartella</string>
<string name="editor_change_folder">Cambia</string>
<string name="editor_otp_qr">OTP da QR</string>
<string name="editor_otp_manual">OTP manuale</string>
<string name="generator_random">Casuale</string>
<string name="generator_use">Usa</string>
```
(`generator_diceware` is not translatable, so it must not appear in `values-it`: lint's
`ExtraTranslation` would fail. Everything else reuses existing translated strings.)
- [ ] **Step 2: The screen and the OTP dialog**
`app/src/main/java/app/passwordstore/ui/editor/EditorScreen.kt`:
```kotlin
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.editor
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Close
import androidx.compose.material.icons.filled.MoreVert
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.DropdownMenu
import androidx.compose.material3.DropdownMenuItem
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.LocalTextStyle
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.window.DialogProperties
import androidx.compose.ui.window.SecureFlagPolicy
import app.passwordstore.R
import app.passwordstore.ui.compose.BreadcrumbBar
import app.passwordstore.ui.compose.R as composeR
import app.passwordstore.ui.compose.crumbsFor
import app.passwordstore.ui.compose.theme.SpacingLarge
import app.passwordstore.ui.compose.theme.SpacingMedium
/** Which field takes focus when the editor first opens. */
enum class EditorFocus {
None,
Name,
Username,
}
/**
* The editor: name, folder (breadcrumbs; they and "Change" open the picker), password with reveal
* and generator, username, free-text extra content (the pass format as text) and the OTP actions,
* shown while the extras hold no TOTP secret ([showOtpActions]). [onScanQr] is null on a device
* without a camera. Only the reveal toggle and the menus keep state here.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EditorScreen(
form: EditorForm,
editing: Boolean,
saving: Boolean,
showOtpActions: Boolean,
initiallyRevealed: Boolean,
focus: EditorFocus,
onFormChange: (EditorForm) -> Unit,
onClose: () -> Unit,
onSave: (copy: Boolean) -> Unit,
onChangeFolder: () -> Unit,
onGenerate: () -> Unit,
onScanQr: (() -> Unit)?,
onQrImage: () -> Unit,
onManualOtp: () -> Unit,
modifier: Modifier = Modifier,
) {
var revealed by remember { mutableStateOf(initiallyRevealed) }
var menu by remember { mutableStateOf(false) }
var qrMenu by remember { mutableStateOf(false) }
val nameFocus = remember { FocusRequester() }
val usernameFocus = remember { FocusRequester() }
LaunchedEffect(Unit) {
when (focus) {
EditorFocus.Name -> nameFocus.requestFocus()
EditorFocus.Username -> usernameFocus.requestFocus()
EditorFocus.None -> Unit
}
}
val field = Modifier.fillMaxWidth().padding(horizontal = SpacingLarge)
Scaffold(
modifier = modifier,
topBar = {
TopAppBar(
title = {
Text(
stringResource(if (editing) R.string.editor_edit_title else R.string.editor_new_title)
)
},
navigationIcon = {
IconButton(onClick = onClose) {
Icon(Icons.Filled.Close, stringResource(R.string.editor_close))
}
},
actions = {
TextButton(onClick = { onSave(false) }, enabled = !saving) {
Text(stringResource(R.string.crypto_save))
}
Box {
IconButton(onClick = { menu = true }) {
Icon(Icons.Filled.MoreVert, stringResource(R.string.list_more_options))
}
DropdownMenu(expanded = menu, onDismissRequest = { menu = false }) {
DropdownMenuItem(
text = { Text(stringResource(R.string.crypto_save_and_copy)) },
onClick = {
menu = false
onSave(true)
},
enabled = !saving,
)
}
}
},
)
},
) { padding ->
Column(
Modifier.padding(padding)
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(bottom = SpacingLarge),
verticalArrangement = Arrangement.spacedBy(SpacingMedium),
) {
OutlinedTextField(
value = form.name,
onValueChange = { onFormChange(form.copy(name = it)) },
modifier = field.focusRequester(nameFocus),
label = { Text(stringResource(R.string.crypto_name_hint)) },
singleLine = true,
keyboardOptions = KeyboardOptions(autoCorrectEnabled = false, imeAction = ImeAction.Next),
)
Text(
stringResource(R.string.editor_folder),
field,
style = MaterialTheme.typography.labelMedium,
color = MaterialTheme.colorScheme.onSurfaceVariant,
)
Row(verticalAlignment = Alignment.CenterVertically) {
BreadcrumbBar(
crumbsFor(form.dir),
stringResource(R.string.list_store_root),
onCrumbClick = { onChangeFolder() },
modifier = Modifier.weight(1f),
)
TextButton(onClick = onChangeFolder, modifier = Modifier.padding(end = SpacingMedium)) {
Text(stringResource(R.string.editor_change_folder))
}
}
OutlinedTextField(
value = form.password,
onValueChange = { onFormChange(form.copy(password = it)) },
modifier = field,
label = { Text(stringResource(R.string.crypto_pass_label)) },
singleLine = true,
textStyle = LocalTextStyle.current.copy(fontFamily = FontFamily.Monospace),
visualTransformation =
if (revealed) VisualTransformation.None else PasswordVisualTransformation(),
keyboardOptions =
KeyboardOptions(
autoCorrectEnabled = false,
keyboardType = KeyboardType.Password,
imeAction = ImeAction.Next,
),
trailingIcon = {
Row {
IconButton(onClick = { revealed = !revealed }) {
Icon(
painterResource(
if (revealed) composeR.drawable.baseline_visibility_off_24
else composeR.drawable.baseline_visibility_24
),
contentDescription =
stringResource(
if (revealed) R.string.entry_hide_password else R.string.entry_show_password
),
)
}
IconButton(onClick = onGenerate) {
Icon(
painterResource(R.drawable.ic_password_24px),
contentDescription = stringResource(R.string.pwgen_title),
)
}
}
},
)
OutlinedTextField(
value = form.username,
onValueChange = { onFormChange(form.copy(username = it)) },
modifier = field.focusRequester(usernameFocus),
label = { Text(stringResource(R.string.crypto_username_hint)) },
singleLine = true,
keyboardOptions = KeyboardOptions(autoCorrectEnabled = false, imeAction = ImeAction.Next),
)
OutlinedTextField(
value = form.extra,
onValueChange = { onFormChange(form.copy(extra = it)) },
modifier = field,
label = { Text(stringResource(R.string.crypto_extra_label)) },
minLines = 3,
// A password keyboard does not learn what is typed, as the old textVisiblePassword.
keyboardOptions =
KeyboardOptions(autoCorrectEnabled = false, keyboardType = KeyboardType.Password),
)
if (showOtpActions)
Row(field, horizontalArrangement = Arrangement.spacedBy(SpacingMedium)) {
Box {
OutlinedButton(onClick = { qrMenu = true }) {
Icon(painterResource(R.drawable.ic_qr_code_scanner), contentDescription = null)
Text(stringResource(R.string.editor_otp_qr), Modifier.padding(start = SpacingMedium))
}
DropdownMenu(expanded = qrMenu, onDismissRequest = { qrMenu = false }) {
if (onScanQr != null)
DropdownMenuItem(
text = { Text(stringResource(R.string.otp_import_qr_code)) },
onClick = {
qrMenu = false
onScanQr()
},
)
DropdownMenuItem(
text = { Text(stringResource(R.string.otp_import_from_file)) },
onClick = {
qrMenu = false
onQrImage()
},
)
}
}
OutlinedButton(onClick = onManualOtp) {
Text(stringResource(R.string.editor_otp_manual))
}
}
}
}
}
/**
* Asks for a TOTP secret and an optional account (the URI's issuer), as the old manual OTP dialog
* did. Both live in [remember] only, and the window is FLAG_SECURE.
*/
@Composable
fun OtpDialog(
onAdd: (secret: String, account: String) -> Unit,
onDismiss: () -> Unit,
modifier: Modifier = Modifier,
) {
var secret by remember { mutableStateOf("") }
var account by remember { mutableStateOf("") }
val focus = remember { FocusRequester() }
AlertDialog(
onDismissRequest = onDismiss,
modifier = modifier,
properties = DialogProperties(securePolicy = SecureFlagPolicy.SecureOn),
title = { Text(stringResource(R.string.add_otp)) },
text = {
Column {
OutlinedTextField(
value = secret,
onValueChange = { secret = it },
modifier = Modifier.focusRequester(focus),
label = { Text(stringResource(R.string.otp_import_manual_hint_secret)) },
singleLine = true,
keyboardOptions =
KeyboardOptions(
autoCorrectEnabled = false,
keyboardType = KeyboardType.Password,
imeAction = ImeAction.Next,
),
)
OutlinedTextField(
value = account,
onValueChange = { account = it },
label = { Text(stringResource(R.string.otp_import_manual_hint_account)) },
singleLine = true,
keyboardOptions = KeyboardOptions(autoCorrectEnabled = false),
)
}
LaunchedEffect(Unit) { focus.requestFocus() }
},
confirmButton = {
TextButton(onClick = { onAdd(secret, account) }, enabled = secret.isNotBlank()) {
Text(stringResource(R.string.dialog_ok))
}
},
dismissButton = {
TextButton(onClick = onDismiss) { Text(stringResource(R.string.dialog_cancel)) }
},
)
}
```
- [ ] **Step 3: The generator sheet**
`app/src/main/java/app/passwordstore/ui/editor/GeneratorSheet.kt`:
```kotlin
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.editor
import androidx.annotation.StringRes
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.Button
import androidx.compose.material3.Checkbox
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.ModalBottomSheetProperties
import androidx.compose.material3.OutlinedTextField
import androidx.compose.material3.PrimaryTabRow
import androidx.compose.material3.Tab
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.window.SecureFlagPolicy
import app.passwordstore.R
import app.passwordstore.passgen.random.PasswordGenerator
import app.passwordstore.ui.compose.theme.SpacingLarge
import app.passwordstore.ui.compose.theme.SpacingMedium
import app.passwordstore.ui.compose.theme.SpacingSmall
import com.github.michaelbull.result.Result
private const val RANDOM_TAB = 0
private const val DICEWARE_TAB = 1
/**
* The password generator as a bottom sheet: a random tab and a diceware tab with the old dialogs'
* options, starting from [random] and [diceware]. [classicFirst] opens the random tab (the
* "Password generator" setting). Every change generates again; [onUse] takes the password shown.
* The password lives in [remember] only, and the sheet's window is FLAG_SECURE.
*/
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun GeneratorSheet(
classicFirst: Boolean,
random: RandomSpec,
diceware: DicewareSpec,
onRandom: suspend (RandomSpec) -> Result<String, Int>,
onDiceware: suspend (DicewareSpec) -> String,
onUse: (String) -> Unit,
onDismiss: () -> Unit,
modifier: Modifier = Modifier,
) {
var tab by remember { mutableIntStateOf(if (classicFirst) RANDOM_TAB else DICEWARE_TAB) }
var randomSpec by remember { mutableStateOf(random) }
var dicewareSpec by remember { mutableStateOf(diceware) }
var length by remember { mutableStateOf(random.length.toString()) }
var words by remember { mutableStateOf(diceware.words.toString()) }
var separator by remember { mutableStateOf(diceware.separator.toString()) }
var rolls by remember { mutableIntStateOf(0) }
var password by remember { mutableStateOf("") }
var problem by remember { mutableStateOf<Int?>(null) }
LaunchedEffect(tab, randomSpec, dicewareSpec, rolls) {
if (tab == RANDOM_TAB) {
val result = onRandom(randomSpec)
password = if (result.isOk) result.value else ""
problem = if (result.isOk) null else result.error
} else {
password = onDiceware(dicewareSpec)
problem = null
}
}
ModalBottomSheet(
onDismissRequest = onDismiss,
modifier = modifier,
properties = ModalBottomSheetProperties(securePolicy = SecureFlagPolicy.SecureOn),
) {
PrimaryTabRow(selectedTabIndex = tab) {
Tab(
selected = tab == RANDOM_TAB,
onClick = { tab = RANDOM_TAB },
text = { Text(stringResource(R.string.generator_random)) },
)
Tab(
selected = tab == DICEWARE_TAB,
onClick = { tab = DICEWARE_TAB },
text = { Text(stringResource(R.string.generator_diceware)) },
)
}
Column(
Modifier.verticalScroll(rememberScrollState()).padding(SpacingLarge),
verticalArrangement = Arrangement.spacedBy(SpacingSmall),
) {
val shown = problem
Text(
if (shown == null) password else stringResource(shown),
style = MaterialTheme.typography.titleMedium.copy(fontFamily = FontFamily.Monospace),
color =
if (shown == null) MaterialTheme.colorScheme.onSurface
else MaterialTheme.colorScheme.error,
)
if (tab == RANDOM_TAB) {
CheckRow(R.string.pwgen_numerals, randomSpec.numerals) {
randomSpec = randomSpec.copy(numerals = it)
}
CheckRow(R.string.pwgen_symbols, randomSpec.symbols) {
randomSpec = randomSpec.copy(symbols = it)
}
CheckRow(R.string.pwgen_uppercase, randomSpec.uppercase) {
randomSpec = randomSpec.copy(uppercase = it)
}
CheckRow(R.string.pwgen_lowercase, randomSpec.lowercase) {
randomSpec = randomSpec.copy(lowercase = it)
}
CheckRow(R.string.pwgen_pronounceable, randomSpec.pronounceable) {
randomSpec = randomSpec.copy(pronounceable = it)
}
CheckRow(R.string.pwgen_ambiguous, randomSpec.ambiguous) {
randomSpec = randomSpec.copy(ambiguous = it)
}
OutlinedTextField(
value = length,
onValueChange = { text ->
// ponytail: at most 999 characters; the generator has no upper bound of its own.
val digits = text.filter(Char::isDigit).take(3)
length = digits
randomSpec =
randomSpec.copy(length = digits.toIntOrNull() ?: PasswordGenerator.DEFAULT_LENGTH)
},
label = { Text(stringResource(R.string.pwgen_length)) },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
)
} else {
OutlinedTextField(
value = words,
onValueChange = { text ->
// ponytail: at most 99 words.
val digits = text.filter(Char::isDigit).take(2)
words = digits
dicewareSpec =
dicewareSpec.copy(words = digits.toIntOrNull()?.takeIf { it > 0 } ?: 5)
},
label = { Text(stringResource(R.string.pwgen_length)) },
singleLine = true,
keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Number),
)
OutlinedTextField(
value = separator,
onValueChange = { text ->
separator = text.take(1)
dicewareSpec = dicewareSpec.copy(separator = separator.firstOrNull() ?: '-')
},
label = { Text(stringResource(R.string.pwgen_separator)) },
singleLine = true,
)
}
Row(
Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(SpacingMedium, Alignment.End),
) {
TextButton(onClick = { rolls++ }) { Text(stringResource(R.string.pwgen_generate)) }
Button(
onClick = { onUse(password) },
enabled = password.isNotEmpty() && problem == null,
) {
Text(stringResource(R.string.generator_use))
}
}
}
}
}
@Composable
private fun CheckRow(@StringRes label: Int, checked: Boolean, onChange: (Boolean) -> Unit) {
Row(
Modifier.fillMaxWidth()
.toggleable(value = checked, role = Role.Checkbox, onValueChange = onChange),
verticalAlignment = Alignment.CenterVertically,
) {
Checkbox(checked = checked, onCheckedChange = null)
Text(stringResource(label), Modifier.padding(start = SpacingMedium))
}
}
```
- [ ] **Step 4: Checks and commit**
Run: `./gradlew spotlessApply && CI=1 ./gradlew :app:assembleDebug :app:lintDebug`
Expected: `BUILD SUCCESSFUL`. If `composeR` does not resolve, check the ui:compose namespace in
`ui/compose/build.gradle.kts` (`app.passwordstore.ui.compose`). If lint flags `PrimaryTabRow` or
`ModalBottomSheetProperties` as experimental beyond the existing `@OptIn`, add
`ExperimentalMaterial3Api` to that `@OptIn` only.
```bash
git add app/src/main/java/app/passwordstore/ui/editor/EditorScreen.kt \
app/src/main/java/app/passwordstore/ui/editor/GeneratorSheet.kt \
app/src/main/res/values/strings.xml app/src/main/res/values-it/strings.xml
git commit -m "feat(app): add the Compose editor screen and generator sheet
Stateless editor: name, folder breadcrumbs with Change, password with
reveal and generator, username, extra content and the OTP actions. The
generator sheet has random and diceware tabs with the old options; the
manual OTP dialog and the sheet are FLAG_SECURE.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>"
```
---
### Task 5: Editor destination and navigation
After this task the list and the entry view open the Compose editor. `PasswordCreationActivity`
is still started by `AutofillSaveActivity` (Task 6).
**Files:**
- Create: `app/src/main/java/app/passwordstore/ui/editor/EditorDestination.kt`
- Modify (replace whole file): `app/src/main/java/app/passwordstore/ui/main/MainActivity.kt`
- Modify: `app/src/main/java/app/passwordstore/ui/entry/EntryDestination.kt`
- Modify: `app/src/main/java/app/passwordstore/ui/list/ListDestination.kt`
- [ ] **Step 1: The destination**
`app/src/main/java/app/passwordstore/ui/editor/EditorDestination.kt`:
```kotlin
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.editor
import android.app.Activity
import android.content.pm.PackageManager
import androidx.activity.compose.BackHandler
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts.GetContent
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
import androidx.compose.foundation.layout.Box
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.res.stringResource
import androidx.fragment.app.FragmentActivity
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.lifecycleScope
import app.passwordstore.R
import app.passwordstore.data.repo.PasswordRepository
import app.passwordstore.ui.crypto.copyPasswordToClipboard
import app.passwordstore.ui.crypto.getPGPIdentifiers
import app.passwordstore.ui.list.FolderPicker
import app.passwordstore.util.extensions.commitChange
import app.passwordstore.util.extensions.getString
import app.passwordstore.util.extensions.isInsideRepository
import app.passwordstore.util.extensions.sharedPrefs
import app.passwordstore.util.extensions.snackbar
import app.passwordstore.util.settings.PreferenceKeys
import com.google.android.material.snackbar.Snackbar
import com.google.zxing.integration.android.IntentIntegrator
import java.io.File
import kotlinx.coroutines.launch
/**
* The editor: wires [EditorScreen] to the [viewModel], the generator sheet, the folder picker, OTP
* import and the save path (checks, recipients from `.gpg-id`, encryption, write, git commit).
* [initial] fills the form the first time; null means the entry to edit is no longer in memory
* (process death) and the editor closes. [original] is the file being edited, null for a new
* entry. [generate] opens the generator at once (autofill's "generate password"). [onClose]
* leaves without saving; [onSaved] runs after the commit.
*/
@Composable
fun EditorDestination(
activity: FragmentActivity,
initial: EditorForm?,
original: File?,
onClose: () -> Unit,
onSaved: (SaveResult.Saved) -> Unit,
modifier: Modifier = Modifier,
generate: Boolean = false,
viewModel: EditorViewModel = hiltViewModel(),
) {
val root = PasswordRepository.getRepositoryDirectory()
// ponytail: filled once per ViewModel, so a recreated activity keeps the edits; an edit restored
// after process death has nothing to fill from (the entry view's plaintext is gone) and closes,
// back to the entry view's passphrase prompt.
val first = remember { initial != null && viewModel.start(initial) }
val lost = !viewModel.started
LaunchedEffect(lost) { if (lost) onClose() }
if (lost) return
val keyboard = LocalSoftwareKeyboardController.current
val focusManager = LocalFocusManager.current
val scope = rememberCoroutineScope()
var sheet by rememberSaveable { mutableStateOf(first && generate) }
var picker by rememberSaveable { mutableStateOf(false) }
var otp by rememberSaveable { mutableStateOf(false) }
var failure by remember { mutableStateOf<String?>(null) }
val form = viewModel.form
val hasOtp = remember(form.extra) { viewModel.hasOtp(form.extra) }
val hasCamera = remember {
activity.packageManager.hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY)
}
val showPassword = remember {
activity.sharedPrefs.getBoolean(PreferenceKeys.SHOW_PASSWORD, true)
}
val classicFirst = remember {
activity.sharedPrefs.getString(PreferenceKeys.PREF_KEY_PWGEN_TYPE) == "classic"
}
fun say(message: Int) {
activity.snackbar(message = activity.getString(message))
}
fun addLine(line: String) {
viewModel.form = viewModel.form.copy(extra = withLine(viewModel.form.extra, line))
}
// The one way out without saving: only while no save runs, keyboard and focus dropped first.
fun close() {
if (viewModel.saving) return
keyboard?.hide()
focusManager.clearFocus()
onClose()
}
fun save(copy: Boolean) {
if (viewModel.saving) return
val current = viewModel.form
val target = entryFile(root, current)
val problem =
formError(current)
?: R.string.message_error_destination_outside_repo.takeUnless {
target.isInsideRepository()
}
if (problem != null) return say(problem)
// Recipients from the nearest .gpg-id, as pass does; null: an invalid ID, already reported.
val ids = activity.getPGPIdentifiers(current.dir) ?: return
activity.lifecycleScope.launch {
when (val result = viewModel.save(ids, target, original, activity)) {
null -> Unit
is SaveResult.Failed -> failure = activity.getString(result.message, result.arg)
is SaveResult.Saved -> {
if (copy) activity.copyPasswordToClipboard(result.form.password)
result.staleOriginal?.let {
activity.snackbar(
message =
activity.getString(
R.string.password_creation_file_delete_fail_message,
it.nameWithoutExtension,
),
length = Snackbar.LENGTH_LONG,
)
}
// ponytail: commit failures are not shown, as for the list's move and delete; a theme
// or locale change in the middle of a save cancels before this commit, and the next
// commit picks the file up.
activity.commitChange(
activity.getString(
if (original != null) R.string.git_commit_edit_text
else R.string.git_commit_add_text,
target.relativeTo(root).path.removeSuffix(".gpg"),
)
)
keyboard?.hide()
focusManager.clearFocus()
onSaved(result)
}
}
}
}
BackHandler(onBack = ::close)
val scan =
rememberLauncherForActivityResult(StartActivityForResult()) { result ->
val text = IntentIntegrator.parseActivityResult(result.resultCode, result.data)?.contents
if (result.resultCode == Activity.RESULT_OK && text != null) {
addLine("$text\n")
say(R.string.otp_import_success)
} else {
say(R.string.otp_import_failure_generic)
}
}
val image =
rememberLauncherForActivityResult(GetContent()) { uri ->
if (uri == null) {
say(R.string.otp_import_failure_no_selection)
} else {
scope.launch {
val text = viewModel.readQr(uri, activity)
if (text != null) {
addLine(text)
say(R.string.otp_import_success)
} else {
say(R.string.otp_import_failure_generic)
}
}
}
}
Box(modifier) {
EditorScreen(
form = form,
editing = original != null,
saving = viewModel.saving,
showOtpActions = !hasOtp,
initiallyRevealed = showPassword,
focus =
when {
!first -> EditorFocus.None
form.name.isEmpty() -> EditorFocus.Name
original == null -> EditorFocus.Username
else -> EditorFocus.None
},
onFormChange = { viewModel.form = it },
onClose = ::close,
onSave = ::save,
onChangeFolder = { picker = true },
onGenerate = { sheet = true },
onScanQr =
if (hasCamera) {
{
scan.launch(
IntentIntegrator(activity)
.setOrientationLocked(false)
.setBeepEnabled(false)
.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE)
.createScanIntent()
)
}
} else null,
onQrImage = { image.launch("image/*") },
onManualOtp = { otp = true },
)
if (sheet)
GeneratorSheet(
classicFirst = classicFirst,
random = viewModel.randomSpec(activity),
diceware = viewModel.dicewareSpec(),
onRandom = { spec -> viewModel.generateRandom(spec, activity) },
onDiceware = viewModel::generateDiceware,
onUse = { password ->
viewModel.form = viewModel.form.copy(password = password)
sheet = false
},
onDismiss = { sheet = false },
)
if (picker)
FolderPicker(
root = root,
start = form.dir,
onPick = { dir ->
viewModel.form = viewModel.form.copy(dir = dir)
picker = false
},
onDismiss = { picker = false },
)
if (otp)
OtpDialog(
onAdd = { secret, account ->
totpUri(secret, account)?.let(::addLine)
otp = false
},
onDismiss = { otp = false },
)
failure?.let { message ->
AlertDialog(
onDismissRequest = { failure = null },
title = { Text(stringResource(R.string.password_creation_file_fail_title)) },
text = { Text(message) },
confirmButton = {
TextButton(onClick = { failure = null }) { Text(stringResource(R.string.dialog_ok)) }
},
)
}
}
}
```
- [ ] **Step 2: MainActivity**
Replace `app/src/main/java/app/passwordstore/ui/main/MainActivity.kt` with:
```kotlin
/*
* Copyright (C) 2026 Danilo M. <danix@danix.xyz>
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.main
import android.os.Bundle
import android.view.WindowManager
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import androidx.navigation.toRoute
import app.passwordstore.data.password.PasswordItem
import app.passwordstore.data.repo.PasswordRepository
import app.passwordstore.ui.compose.theme.APSTheme
import app.passwordstore.ui.crypto.BasePGPActivity
import app.passwordstore.ui.editor.EditorDestination
import app.passwordstore.ui.editor.EditorForm
import app.passwordstore.ui.editor.editorForm
import app.passwordstore.ui.entry.EntryDestination
import app.passwordstore.ui.entry.EntryViewModel
import app.passwordstore.ui.git.base.BaseGitActivity
import app.passwordstore.ui.list.ListDestination
import app.passwordstore.ui.list.folderMoves
import app.passwordstore.ui.onboarding.activity.OnboardingActivity
import app.passwordstore.ui.settings.SettingsActivity
import app.passwordstore.util.extensions.launchActivity
import app.passwordstore.util.extensions.sharedPrefs
import app.passwordstore.util.settings.AuthMode
import app.passwordstore.util.settings.PreferenceKeys
import app.passwordstore.util.shortcuts.ShortcutHandler
import com.github.michaelbull.result.onFailure
import dagger.hilt.android.AndroidEntryPoint
import java.io.File
import javax.inject.Inject
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.serialization.Serializable
/**
* The password list of the folder at [path], relative to the store root ("" is the root). The back
* stack holds one entry per folder level.
*/
@Serializable data class ListRoute(val path: String = "")
/**
* One entry, by absolute path. Paths from [LaunchActivity] passed [LaunchActivity.isFileInRepo];
* the entry destination checks again before decrypting.
*/
@Serializable data class EntryRoute(val filePath: String)
/**
* The editor: a new entry in [dir] (relative to the store root, "" is the root), or the entry
* [name] (file name without `.gpg`) there. An edit takes its plaintext from the entry view below
* it on the back stack, never from the route.
*/
@Serializable data class EditRoute(val dir: String, val name: String? = null)
/**
* Single-activity host for the Compose UI. Not exported: it is only started by [LaunchActivity],
* after its biometric gate and path check. Extends [BaseGitActivity] (an AppCompatActivity, so also
* the FragmentActivity BiometricPrompt needs) because the git operations require one; it hosts no
* fragments.
*/
@AndroidEntryPoint
class MainActivity : BaseGitActivity() {
@Inject lateinit var shortcutHandler: ShortcutHandler
/** Composed destinations that show secrets; FLAG_SECURE is on while this is above zero. */
private var secureHolds = 0
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val filePath = intent.getStringExtra(BasePGPActivity.EXTRA_FILE_PATH)
val start: Any = if (filePath != null) EntryRoute(filePath) else ListRoute()
setContent {
APSTheme {
val nav = rememberNavController()
NavHost(nav, startDestination = start) {
composable<ListRoute> { entry ->
val path = entry.toRoute<ListRoute>().path
ListDestination(
activity = this@MainActivity,
path = path,
onOpenFolder = { target ->
// Only the folder on top may move the stack: a double tap must not push twice.
if (nav.currentBackStackEntry?.id == entry.id) {
val (pops, pushes) = folderMoves(path, target)
repeat(pops) { nav.popBackStack() }
pushes.forEach { nav.navigate(ListRoute(it)) }
}
},
onOpenEntry = { file ->
if (nav.currentBackStackEntry?.id == entry.id) {
addShortcut(file)
nav.navigate(EntryRoute(file.absolutePath))
}
},
onNewEntry = {
if (nav.currentBackStackEntry?.id == entry.id) nav.navigate(EditRoute(path))
},
)
}
composable<EntryRoute> { entry ->
val file = File(entry.toRoute<EntryRoute>().filePath)
SecureWindow(this@MainActivity)
EntryDestination(
activity = this@MainActivity,
file = file,
onClose = {
// Only the entry on top closes: the auto-close timer can race a back press.
if (nav.currentBackStackEntry?.id == entry.id) {
if (nav.previousBackStackEntry == null) finish() else nav.popBackStack()
}
},
onEdit = {
if (nav.currentBackStackEntry?.id == entry.id) {
val root = PasswordRepository.getRepositoryDirectory().canonicalFile
val dir = file.canonicalFile.parentFile?.relativeTo(root)?.path.orEmpty()
nav.navigate(EditRoute(dir, file.nameWithoutExtension))
}
},
)
}
composable<EditRoute> { entry ->
val route = entry.toRoute<EditRoute>()
val name = route.name
// An edit reads the decrypted entry from the entry view below it. After process
// death that ViewModel is new and empty, and the editor closes.
val decrypted =
if (name == null) null
else
remember(entry) { runCatching { nav.getBackStackEntry<EntryRoute>() }.getOrNull() }
?.let { hiltViewModel<EntryViewModel>(it).entry }
SecureWindow(this@MainActivity)
EditorDestination(
activity = this@MainActivity,
initial =
if (name == null) EditorForm(dir = route.dir)
else decrypted?.let { editorForm(it, route.dir, name) },
original =
name?.let { File(File(PasswordRepository.getRepositoryDirectory(), route.dir), "$it.gpg") },
onClose = {
if (nav.currentBackStackEntry?.id == entry.id) nav.popBackStack()
},
onSaved = {
// Back to the list, which re-reads the store on resume. An entry opened from a
// shortcut has no list below it: the list root replaces the stack.
if (nav.currentBackStackEntry?.id == entry.id) {
if (!nav.popBackStack<ListRoute>(inclusive = false))
nav.navigate(ListRoute()) { popUpTo<EntryRoute> { inclusive = true } }
}
},
)
}
}
}
}
}
/** Counts a destination that shows secrets; the first one turns FLAG_SECURE on. */
fun holdSecure() {
if (secureHolds++ == 0) window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
/** Ends a [holdSecure]; FLAG_SECURE goes off when no secret-showing destination is left. */
fun releaseSecure() {
if (--secureHolds == 0) window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE)
}
/** Re-reads the store; starts onboarding and returns false when there is none yet. */
fun checkStore(): Boolean {
PasswordRepository.initialize()
if (sharedPrefs.getBoolean(PreferenceKeys.REPOSITORY_INITIALIZED, false)) return true
launchActivity(OnboardingActivity::class.java)
return false
}
/** Git actions offered in the list's menu, chosen as the old list chose its menu. */
fun gitOps(): ImmutableList<GitOp> =
when {
gitSettings.authMode == AuthMode.None -> persistentListOf(GitOp.PULL)
PasswordRepository.isGitRepo() -> persistentListOf(GitOp.SYNC, GitOp.PULL, GitOp.PUSH)
else -> persistentListOf()
}
/** Runs [op]; failures show the usual git error dialog. */
suspend fun runGit(op: GitOp) {
launchGitOperation(op).onFailure { promptOnErrorHandler(it) }
}
/** Adds [file] to the launcher's dynamic shortcuts, as opening it from the list always did. */
fun addShortcut(file: File) {
val item = entryItem(file)
shortcutHandler.addDynamicShortcut(item, item.createAuthEnabledIntent(this))
}
fun pinEntry(file: File) {
val item = entryItem(file)
shortcutHandler.addPinnedShortcut(item, item.createAuthEnabledIntent(this))
}
fun openSettings() {
launchActivity(SettingsActivity::class.java)
}
private fun entryItem(file: File) =
PasswordItem.newPassword(file.name, file, PasswordRepository.getRepositoryDirectory())
}
/**
* FLAG_SECURE while composed. Counted in [MainActivity], because in a transition (entry view to
* editor and back) the entering destination is composed before the leaving one is disposed.
*/
@Composable
private fun SecureWindow(activity: MainActivity) {
DisposableEffect(activity) {
activity.holdSecure()
onDispose { activity.releaseSecure() }
}
}
```
(`createEntry` is gone: the list navigates to `EditRoute` itself.)
- [ ] **Step 3: EntryDestination opens the Compose editor**
In `app/src/main/java/app/passwordstore/ui/entry/EntryDestination.kt`:
Delete these imports:
```kotlin
import android.view.WindowManager
```
```kotlin
import androidx.compose.runtime.DisposableEffect
```
```kotlin
import app.passwordstore.data.passfile.PasswordEntry
```
```kotlin
import app.passwordstore.ui.crypto.BasePGPActivity
```
```kotlin
import app.passwordstore.ui.crypto.PasswordCreationActivity
```
Replace the KDoc and signature start:
```kotlin
/**
* One entry: wires [EntryScreen] to the [viewModel], the biometric and passphrase prompts, the
* clipboard and the legacy editor. [onClose] leaves the destination; [onSaved] runs after the
* editor saved the entry (the host returns to the list).
*/
@Composable
fun EntryDestination(
activity: MainActivity,
file: File,
onClose: () -> Unit,
onSaved: () -> Unit,
```
with
```kotlin
/**
* One entry: wires [EntryScreen] to the [viewModel], the biometric and passphrase prompts and the
* clipboard. [onClose] leaves the destination; [onEdit] opens the editor on the decrypted entry.
* The host keeps FLAG_SECURE on while this is composed.
*/
@Composable
fun EntryDestination(
activity: MainActivity,
file: File,
onClose: () -> Unit,
onEdit: () -> Unit,
```
Delete:
```kotlin
// Secrets stay out of screenshots and recents while this destination is composed.
// ponytail: plain add/clear, fine while no other secret-showing destination can overlap this
// one in a transition; count in MainActivity once the editor (step 4) becomes a destination.
DisposableEffect(Unit) {
activity.window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
onDispose { activity.window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE) }
}
```
Replace
```kotlin
// ponytail: after process death during key import or the editor, the unlock flow can start
```
with
```kotlin
// ponytail: after process death during key import, the unlock flow can start
```
Delete:
```kotlin
val editor =
rememberLauncherForActivityResult(StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) onSaved()
}
```
Replace
```kotlin
onEdit = { entry?.let { editor.launch(editIntent(activity, file, root, it)) } },
```
with
```kotlin
onEdit = { if (entry != null) onEdit() },
```
Delete the whole `editIntent` function with its KDoc:
```kotlin
/** The legacy editor, filled exactly as the old decrypt screen filled it. */
private fun editIntent(activity: Activity, file: File, root: File, entry: PasswordEntry): Intent =
Intent(activity, PasswordCreationActivity::class.java)
.setAction(Intent.ACTION_VIEW)
.putExtra(BasePGPActivity.EXTRA_FILE_PATH, getParentPath(file.absolutePath, root.absolutePath))
.putExtra(BasePGPActivity.EXTRA_REPO_PATH, root.absolutePath)
.putExtra(PasswordCreationActivity.EXTRA_FILE_NAME, file.nameWithoutExtension)
.putExtra(PasswordCreationActivity.EXTRA_USERNAME, entry.username)
.putExtra(PasswordCreationActivity.EXTRA_PASSWORD, entry.password)
.putExtra(PasswordCreationActivity.EXTRA_EXTRA_CONTENT, entry.extraContentWithoutUsername)
.putExtra(PasswordCreationActivity.EXTRA_EDITING, true)
```
(`Activity`, `Intent`, the result launcher imports and `getParentPath` stay: the key import
launcher, the share intent and `unlock()` use them.)
- [ ] **Step 4: The list opens the editor**
In `app/src/main/java/app/passwordstore/ui/list/ListDestination.kt`, replace
```kotlin
* The list at [path] (relative to the store root): wires [ListScreen] to the [viewModel], the
* folder picker, the legacy activities and the store operations. [onOpenFolder] takes a path
* relative to the root, [onOpenEntry] an entry file.
*/
@Composable
fun ListDestination(
activity: MainActivity,
path: String,
onOpenFolder: (relativePath: String) -> Unit,
onOpenEntry: (File) -> Unit,
```
with
```kotlin
* The list at [path] (relative to the store root): wires [ListScreen] to the [viewModel], the
* folder picker, the legacy activities and the store operations. [onOpenFolder] takes a path
* relative to the root, [onOpenEntry] an entry file; [onNewEntry] opens the editor in this folder.
*/
@Composable
fun ListDestination(
activity: MainActivity,
path: String,
onOpenFolder: (relativePath: String) -> Unit,
onOpenEntry: (File) -> Unit,
onNewEntry: () -> Unit,
```
and replace
```kotlin
ifInitialized { activity.createEntry(dir) }
```
with
```kotlin
ifInitialized(onNewEntry)
```
- [ ] **Step 5: Build and smoke check**
Run: `./gradlew spotlessApply && CI=1 ./gradlew :app:assembleDebug :app:testDebugUnitTest :app:lintDebug`
Expected: `BUILD SUCCESSFUL`. If `popBackStack<ListRoute>(inclusive = false)` does not resolve,
use `nav.popBackStack(ListRoute::class, inclusive = false)`. If Slack lint's
`ComposeViewModelInjection` flags the `hiltViewModel<EntryViewModel>(it)` call in the `NavHost`
builder, move the lookup into a private top-level `@Composable fun editedEntry(nav:
NavHostController, entry: NavBackStackEntry): PasswordEntry?` in `MainActivity.kt` with a
`@Suppress("ComposeViewModelInjection")` and a one-line reason (it reads another destination's
ViewModel, it does not own one).
With the emulator from Task 8 running and the store cloned (`export ANDROID_SERIAL=emulator-5554`
first; a phone may be connected), `./gradlew :app:installDebug`, open the app, tap "New entry",
"Create new password": the Compose editor opens (`adb exec-out uiautomator dump /dev/tty | grep -o
'text="Save"'`); the close icon returns to the list. Full checks are in Task 8.
- [ ] **Step 6: Commit**
```bash
git add app/src/main/java/app/passwordstore/ui/editor/EditorDestination.kt \
app/src/main/java/app/passwordstore/ui/main/MainActivity.kt \
app/src/main/java/app/passwordstore/ui/entry/EntryDestination.kt \
app/src/main/java/app/passwordstore/ui/list/ListDestination.kt
git commit -m "feat(app): open the Compose editor from the list and entry view
EditRoute replaces the legacy editor for new entries and edits. An edit
copies its plaintext from the entry view's ViewModel below it, never
through the route or saved state. Saving returns to the list, closing
returns to where the editor was opened. FLAG_SECURE is now counted in
MainActivity, so moving between the entry view and the editor never
clears it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>"
```
---
### Task 6: Autofill save hosts the Compose editor
**Files:**
- Modify (replace whole file): `app/src/main/java/app/passwordstore/ui/autofill/AutofillSaveActivity.kt`
- Modify: `app/src/main/AndroidManifest.xml`
- [ ] **Step 1: The activity**
Replace `app/src/main/java/app/passwordstore/ui/autofill/AutofillSaveActivity.kt` with:
```kotlin
/*
* Copyright © 2014-2024 The Android Password Store Authors. All Rights Reserved.
* SPDX-License-Identifier: GPL-3.0-only
*/
package app.passwordstore.ui.autofill
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.content.IntentSender
import android.os.Bundle
import android.view.WindowManager
import android.view.autofill.AutofillManager
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import app.passwordstore.ui.compose.theme.APSTheme
import app.passwordstore.ui.editor.EditorDestination
import app.passwordstore.ui.editor.EditorForm
import app.passwordstore.ui.editor.SaveResult
import app.passwordstore.util.autofill.AutofillMatcher
import app.passwordstore.util.autofill.AutofillPreferences
import app.passwordstore.util.autofill.AutofillResponseBuilder
import app.passwordstore.util.extensions.unsafeLazy
import com.github.androidpasswordstore.autofillparser.AutofillAction
import com.github.androidpasswordstore.autofillparser.Credentials
import com.github.androidpasswordstore.autofillparser.FormOrigin
import dagger.hilt.android.AndroidEntryPoint
import logcat.LogPriority.ERROR
import logcat.logcat
/**
* Saves credentials the autofill service caught (or generates a password for a form) in the
* Compose editor, prefilled from the form's origin, then records the autofill match and, for a
* generated password, fills it in.
*/
@AndroidEntryPoint
class AutofillSaveActivity : AppCompatActivity() {
companion object {
private const val EXTRA_FOLDER_NAME = "app.passwordstore.autofill.oreo.ui.EXTRA_FOLDER_NAME"
private const val EXTRA_PASSWORD = "app.passwordstore.autofill.oreo.ui.EXTRA_PASSWORD"
private const val EXTRA_NAME = "app.passwordstore.autofill.oreo.ui.EXTRA_NAME"
private const val EXTRA_SHOULD_MATCH_APP =
"app.passwordstore.autofill.oreo.ui.EXTRA_SHOULD_MATCH_APP"
private const val EXTRA_SHOULD_MATCH_WEB =
"app.passwordstore.autofill.oreo.ui.EXTRA_SHOULD_MATCH_WEB"
private const val EXTRA_GENERATE_PASSWORD =
"app.passwordstore.autofill.oreo.ui.EXTRA_GENERATE_PASSWORD"
private var saveRequestCode = 1
fun makeSaveIntentSender(
context: Context,
credentials: Credentials?,
formOrigin: FormOrigin,
): IntentSender {
val identifier = formOrigin.getPrettyIdentifier(context, untrusted = false)
// Prevent directory traversals
val sanitizedIdentifier =
identifier.replace('\\', '_').replace('/', '_').trimStart('.').takeUnless { it.isBlank() }
?: formOrigin.identifier
val directoryStructure = AutofillPreferences.directoryStructure(context)
val folderName =
directoryStructure.getSaveFolderName(
sanitizedIdentifier = sanitizedIdentifier,
username = credentials?.username,
)
val fileName =
directoryStructure.getSaveFileName(
username = credentials?.username,
identifier = identifier,
)
val intent =
Intent(context, AutofillSaveActivity::class.java).apply {
putExtras(
bundleOf(
EXTRA_FOLDER_NAME to folderName,
EXTRA_NAME to fileName,
EXTRA_PASSWORD to credentials?.password,
EXTRA_SHOULD_MATCH_APP to
formOrigin.identifier.takeIf { formOrigin is FormOrigin.App },
EXTRA_SHOULD_MATCH_WEB to
formOrigin.identifier.takeIf { formOrigin is FormOrigin.Web },
EXTRA_GENERATE_PASSWORD to (credentials == null),
)
)
}
return PendingIntent.getActivity(
context,
saveRequestCode++,
intent,
PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
.intentSender
}
}
private val formOrigin by unsafeLazy {
val shouldMatchApp: String? = intent.getStringExtra(EXTRA_SHOULD_MATCH_APP)
val shouldMatchWeb: String? = intent.getStringExtra(EXTRA_SHOULD_MATCH_WEB)
if (shouldMatchApp != null && shouldMatchWeb == null) {
FormOrigin.App(shouldMatchApp)
} else if (shouldMatchApp == null && shouldMatchWeb != null) {
FormOrigin.Web(shouldMatchWeb)
} else {
null
}
}
private val generate by unsafeLazy { intent.getBooleanExtra(EXTRA_GENERATE_PASSWORD, false) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// The whole window is the editor: keep it out of screenshots and recents.
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE)
val initial =
EditorForm(
name = intent.getStringExtra(EXTRA_NAME).orEmpty(),
dir = intent.getStringExtra(EXTRA_FOLDER_NAME).orEmpty().trim('/'),
password = intent.getStringExtra(EXTRA_PASSWORD).orEmpty(),
)
setContent {
APSTheme {
EditorDestination(
activity = this,
initial = initial,
original = null,
onClose = {
setResult(RESULT_CANCELED)
finish()
},
onSaved = ::finishSaved,
generate = generate,
)
}
}
}
/** Records the autofill match and, for a generated password, returns it to fill the form. */
private fun finishSaved(saved: SaveResult.Saved) {
formOrigin?.let { AutofillMatcher.addMatchFor(this, it, saved.file) }
val resultIntent =
if (generate) {
val clientState =
intent?.getBundleExtra(AutofillManager.EXTRA_CLIENT_STATE)
?: run {
logcat(ERROR) { "AutofillSaveActivity started without EXTRA_CLIENT_STATE" }
finish()
return
}
val username =
saved.form.username.ifEmpty { null }
?: AutofillPreferences.directoryStructure(this).getUsernameFor(saved.file)
val credentials = Credentials(username, saved.form.password, null)
val fillInDataset =
AutofillResponseBuilder.makeFillInDataset(
this,
credentials,
clientState,
AutofillAction.Generate,
)
Intent().putExtra(AutofillManager.EXTRA_AUTHENTICATION_RESULT, fillInDataset)
} else {
// The password came from the form: there is nothing to fill.
Intent()
}
setResult(RESULT_OK, resultIntent)
finish()
}
}
```
- [ ] **Step 2: Manifest**
In `app/src/main/AndroidManifest.xml`, replace
```xml
<activity
android:name=".ui.autofill.AutofillSaveActivity"
android:exported="false"
android:theme="@style/NoBackgroundThemeM3" />
```
with
```xml
<!-- ponytail: rotation must not cancel a save running in lifecycleScope, as in MainActivity. -->
<activity
android:name=".ui.autofill.AutofillSaveActivity"
android:configChanges="orientation|screenSize"
android:exported="false"
android:theme="@style/NoActionBarThemeM3"
android:windowSoftInputMode="adjustResize" />
```
(The old transparent theme hid a trampoline that started the editor; the activity now is the
editor.)
- [ ] **Step 3: Checks and commit**
Run: `./gradlew spotlessApply && CI=1 ./gradlew :app:assembleDebug :app:testDebugUnitTest :app:lintDebug`
Expected: `BUILD SUCCESSFUL`. `grep -rn PasswordCreationActivity app/src/main/java` now lists only
`PasswordCreationActivity.kt` and the three legacy dialogs.
```bash
git add app/src/main/java/app/passwordstore/ui/autofill/AutofillSaveActivity.kt \
app/src/main/AndroidManifest.xml
git commit -m "feat(app): host the Compose editor in the autofill save flow
AutofillSaveActivity shows the editor itself, prefilled from the form
and FLAG_SECURE, instead of starting the legacy editor for a result. The
autofill match and the generated-password fill work as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>"
```
---
### Task 7: Remove the legacy editor, generators and folder picker
**Files:**
- Delete: the files listed in "Deleted in this step" above
- Modify: `app/src/main/AndroidManifest.xml`
- Modify: `app/src/main/java/app/passwordstore/ui/crypto/BasePGPActivity.kt`
- Modify: `app/src/main/java/app/passwordstore/injection/pwgen/DicewareModule.kt`
- Modify: `app/build.gradle.kts`, `gradle/libs.versions.toml`
- Modify: `app/lint-baseline.xml`
- Modify: `docs/superpowers/specs/2026-11-02-compose-ui-overhaul-design.md`
- [ ] **Step 1: Delete the files**
```bash
git rm app/src/main/java/app/passwordstore/ui/crypto/PasswordCreationActivity.kt \
app/src/main/java/app/passwordstore/ui/crypto/EditPasswordScreen.kt \
app/src/main/java/app/passwordstore/ui/dialogs/PasswordGeneratorDialogFragment.kt \
app/src/main/java/app/passwordstore/ui/dialogs/DicewarePasswordGeneratorDialogFragment.kt \
app/src/main/java/app/passwordstore/ui/dialogs/OtpImportDialogFragment.kt \
app/src/main/java/app/passwordstore/ui/folderselect/SelectFolderActivity.kt \
app/src/main/java/app/passwordstore/ui/folderselect/SelectFolderFragment.kt \
app/src/main/java/app/passwordstore/ui/adapters/PasswordItemRecyclerAdapter.kt \
app/src/main/res/layout/password_creation_activity.xml \
app/src/main/res/layout/fragment_pwgen.xml \
app/src/main/res/layout/fragment_pwgen_diceware.xml \
app/src/main/res/layout/fragment_manual_otp_entry.xml \
app/src/main/res/layout/select_folder_layout.xml \
app/src/main/res/layout/password_recycler_view.xml \
app/src/main/res/layout/password_row_layout.xml \
app/src/main/res/menu/pgp_handler_new_password.xml \
app/src/main/res/menu/pgp_handler_select_folder.xml \
app/src/main/res/drawable/ic_save_24dp.xml \
app/src/main/res/drawable/ic_save_copy_24dp.xml \
ui/compose/src/main/kotlin/app/passwordstore/ui/compose/PasswordField.kt
```
- [ ] **Step 2: Manifest**
In `app/src/main/AndroidManifest.xml`, delete
```xml
<activity
android:name=".ui.crypto.PasswordCreationActivity"
android:exported="false"
android:label="@string/new_password_title"
android:windowSoftInputMode="adjustResize" />
```
and
```xml
<activity
android:name=".ui.folderselect.SelectFolderActivity"
android:exported="false" />
```
- [ ] **Step 3: BasePGPActivity**
In `app/src/main/java/app/passwordstore/ui/crypto/BasePGPActivity.kt`, delete
```kotlin
/** Full path to the repository */
val repoPath by unsafeLazy { intent.getStringExtra("REPO_PATH")!! }
/** Full path to the password file being worked on */
val fullPath by unsafeLazy { intent.getStringExtra("FILE_PATH")!! }
```
the line
```kotlin
const val EXTRA_REPO_PATH = "REPO_PATH"
```
and the import
```kotlin
import app.passwordstore.util.extensions.unsafeLazy
```
- [ ] **Step 4: Diceware only for ViewModels**
In `app/src/main/java/app/passwordstore/injection/pwgen/DicewareModule.kt`, replace
```kotlin
@InstallIn(FragmentComponent::class, ViewModelComponent::class)
```
with
```kotlin
@InstallIn(ViewModelComponent::class)
```
and delete the import `import dagger.hilt.android.components.FragmentComponent`.
- [ ] **Step 5: Unused dependencies**
In `app/build.gradle.kts`, delete the lines
```kotlin
implementation(libs.androidx.swiperefreshlayout)
```
```kotlin
implementation(libs.thirdparty.flowbinding.android)
```
In `gradle/libs.versions.toml`, delete the lines
```toml
flowbinding = "1.2.0"
```
```toml
androidx-swiperefreshlayout = "androidx.swiperefreshlayout:swiperefreshlayout:1.2.0"
```
```toml
thirdparty-flowbinding-android = { module = "io.github.reactivecircus.flowbinding:flowbinding-android", version.ref = "flowbinding" }
```
- [ ] **Step 6: Lint baseline**
`app/lint-baseline.xml` has two `SetTextI18n` issues located in the deleted generator dialogs.
Remove both `<issue>` blocks:
```bash
perl -0pi -e 's/\n <issue\n id="SetTextI18n"\n(?:(?!<\/issue>).)*?GeneratorDialogFragment\.kt(?:(?!<\/issue>).)*?<\/issue>\n//gs' app/lint-baseline.xml
grep -c GeneratorDialogFragment app/lint-baseline.xml
```
Expected: `0`, and `git diff app/lint-baseline.xml` shows exactly two removed `<issue>` blocks.
- [ ] **Step 7: Nothing refers to the removed code**
```bash
grep -rnwE 'PasswordCreationActivity|PasswordGeneratorDialogFragment|DicewarePasswordGeneratorDialogFragment|OtpImportDialogFragment|SelectFolderActivity|SelectFolderFragment|PasswordItemRecyclerAdapter|EditPasswordScreen|CopyButton|EXTRA_REPO_PATH|repoPath|fullPath|flowbinding|swiperefreshlayout' app/src ui/compose/src app/build.gradle.kts gradle/libs.versions.toml
grep -rnE 'PasswordCreationActivityBinding|FragmentPwgen|FragmentManualOtpEntryBinding|SelectFolderLayoutBinding|PasswordRecyclerViewBinding|R\.menu\.pgp_handler_(new_password|select_folder)|ic_save(_copy)?_24dp|ui\.compose\.PasswordField' app/src ui/compose/src
```
Expected: no output from either.
- [ ] **Step 8: The spec**
In `docs/superpowers/specs/2026-11-02-compose-ui-overhaul-design.md`, section "Editor", replace
```
- "OTP from QR" and "OTP manual" actions.
```
with
```
- "OTP from QR" (camera or image) and "OTP manual" actions.
- "Save and copy" in the overflow. Saving returns to the list; closing returns to where the
editor was opened. The folder picker is a dialog, shared with the list's move action. The
autofill save flow (`AutofillSaveActivity`) hosts the same editor.
```
and in section "Security", replace
```
- `FLAG_SECURE` is set on the window while the entry view or editor destination is shown and
cleared when leaving it, so secrets stay out of screenshots and recents.
```
with
```
- `FLAG_SECURE` is set on the window while the entry view or editor destination is shown and
cleared when leaving it, so secrets stay out of screenshots and recents. It is counted, so
moving between the two never clears it.
```
- [ ] **Step 9: Full local check**
Run:
```bash
./gradlew spotlessApply
CI=1 ./gradlew spotlessCheck test -PslimTests :app:assembleDebug :app:assembleRelease \
lint metalavaCheckCompatibilityRelease
```
Expected: `BUILD SUCCESSFUL`. If lint reports unused resources, they were used only by the
deleted files (likely candidates: `new_password_title`, `directory_hint`, `path_toast_text`,
`crypto_encrypt_username_label`, `pwd_generate_button`, `otp_import_manual_entry`,
`pwgen_include`, `select_folder`-style strings, `password_row_background` only if
`oreo_autofill_filter_row.xml` no longer uses it): confirm with `grep -rn` that nothing else uses
them, then delete them from every `values*/strings.xml` (a string left only in a translation is an
`ExtraTranslation` error) or from `res/drawable`, and re-run. If lint reports an issue in a file
from Tasks 1 to 6, fix it there and include it in this commit.
- [ ] **Step 10: Commit**
```bash
git add -A app/src/main app/build.gradle.kts gradle/libs.versions.toml app/lint-baseline.xml \
ui/compose/src docs/superpowers/specs/2026-11-02-compose-ui-overhaul-design.md
git commit -m "refactor(app): remove the legacy editor, generators and folder picker
The Compose editor, generator sheet, OTP dialog and folder picker
replace PasswordCreationActivity, the generator and manual OTP dialog
fragments, SelectFolderActivity with its fragment and adapter, their
layouts and menus, and upstream's unused EditPasswordScreen with the
PasswordField it used. flowbinding and swiperefreshlayout had no other
users. BasePGPActivity keeps what autofill decryption still needs.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>"
```
---
### Task 8: Emulator check and push
No real store or keys: the e2e environment from AGENTS.md only. A physical phone may be
connected over USB: every `adb` and Gradle install command in this task targets the emulator
through `ANDROID_SERIAL`; never touch the phone. The PIN `1234` below is the emulator's own test
PIN, never the owner's.
- [ ] **Step 1: Server, emulator, unlock, clean install**
```bash
export ANDROID_SERIAL=emulator-5554
scripts/e2e-env.sh up
$ANDROID_HOME/emulator/emulator -avd aps-test -no-window -no-audio -no-boot-anim \
-no-snapshot-save -gpu swiftshader_indirect &
adb wait-for-device
until [ "$(adb shell getprop sys.boot_completed | tr -d '\r')" = 1 ]; do sleep 2; done
adb shell input keyevent KEYCODE_WAKEUP; adb shell input keyevent 82
adb shell input text 1234; adb shell input keyevent 66
for s in animator_duration_scale transition_animation_scale window_animation_scale; do
adb shell settings put global $s 0; done
adb shell settings put secure autofill_service null
adb uninstall xyz.danix.hardenedpass.debug || true
./gradlew :app:installDebug
adb shell pm grant xyz.danix.hardenedpass.debug android.permission.CAMERA
scripts/e2e-env.sh push-keys
OUT=$(mktemp -d)
```
(`ANDROID_HOME` is the `sdk.dir` from `local.properties`. `push-keys` only after the unlock.
`installDebug` and `adb` both honor `ANDROID_SERIAL`. The uninstall also avoids a signature
mismatch between checkouts, see AGENTS.md. The camera grant keeps zxing's permission prompt out
of step 6; if `pm grant` says the permission is not requested, drop it and answer the prompt.)
Helpers for this shell. `center`, `tap` and `field` take an optional match index (1 = first);
in the editor the text fields are, in order, 1 name, 2 password, 3 username, 4 extra content.
`cmd clipboard` is not available on this image: clipboard checks paste into the list's search
field (keycode 279) instead.
```bash
ui() { adb exec-out uiautomator dump /dev/tty; }
center() { local b; b=$(ui | grep -o "<node [^>]*$1[^>]*>" | sed -n "${2:-1}p" | grep -o 'bounds="[^"]*"' | grep -oE '[0-9]+' | tr '\n' ' '); [ -n "$b" ] || { echo "not found: $1" >&2; return 1; }; set -- $b; echo "$(( ($1 + $3) / 2 )) $(( ($2 + $4) / 2 ))"; }
tap() { local c; c=$(center "$1" "$2") && adb shell input tap $c; sleep 1; }
hold() { local c; c=$(center "$1") && set -- $c && adb shell input swipe $1 $2 $1 $2 900; sleep 1; }
field() { tap 'class="android.widget.EditText"' "$1"; adb shell input keycombination 113 29; adb shell input keyevent 67; adb shell input text "$2"; }
value() { ui | grep -o '<node [^>]*class="android.widget.EditText"[^>]*>' | sed -n "${1}p" | grep -o ' text="[^"]*"' | cut -d'"' -f2; }
seen() { ui | grep -q "$1" && echo "ok: $1" || echo "MISSING: $1"; }
top() { adb shell dumpsys activity activities | grep topResumedActivity; }
open() { adb shell am start -n xyz.danix.hardenedpass.debug/app.passwordstore.ui.main.LaunchActivity; sleep 3; }
secure() { adb shell dumpsys window windows | awk -v a="${1:-ui[.]main[.]MainActivity}" '/Window #/{w=($0 ~ a)} w && /fl=/{print (/SECURE/ ? "secure" : "not secure"); w=0}'; }
pass() { tap 'class="android.widget.EditText"'; adb shell input text "$1"; tap 'text="OK"'; sleep 2; }
store() { adb shell run-as xyz.danix.hardenedpass.debug ls -a "files/store/$1"; }
srv() { docker exec -u git aps-e2e-git git -C /srv/git/store.git "$@"; }
reveal() { srv show "master:$1.gpg" > "$OUT/x.gpg"; GNUPGHOME=.e2e/gnupg gpg -q --batch --pinentry-mode loopback --passphrase test -d "$OUT/x.gpg"; }
```
- [ ] **Step 2: Onboarding and clone**
`open`, then go through onboarding: "Let's Go", "Clone Remote Repo", Repository URL
`ssh://git@10.0.2.2:2222/srv/git/store.git`, authentication mode "SSH key" (the toggle may need a
second tap before it shows as selected), Save; import the SSH key `aps-e2e-ssh-key` from Download
when asked, accept the host key, then "Select key" and import `aps-e2e-pgp-key.asc` from Download.
Expected afterwards: `top` shows `MainActivity`; `seen 'text="example.org"'` prints `ok`;
`secure` prints `not secure`.
- [ ] **Step 3: New entry in the root, random generator, Save and copy**
```bash
tap 'text="New entry"'; tap 'text="Create new password"'
top; seen 'text="Save"'; seen 'text="New entry"'; secure
adb shell input text site.example.net # the name field has focus
tap 'content-desc="Generate Password"'; tap 'text="Random"'
seen 'text="Numerals"'; seen 'text="Pronounceable"'; seen 'text="Ambiguous"'
tap 'text="Pronounceable"' # an option change regenerates
adb exec-out screencap -p > "$OUT/sheet.png"
tap 'text="Use"'
PW=$(value 2); echo "${#PW} $PW"
field 3 erin
tap 'content-desc="More options"'; tap 'text="Save and Copy"'
sleep 3; top; seen 'text="site.example.net"'; secure
tap 'text="Search"'; adb shell input keyevent 279; seen "text=\"$PW\""
adb shell input keyevent 4; adb shell input keyevent 4
```
Expected: the editor is a `MainActivity` destination (no `PasswordCreationActivity`), `secure`;
the sheet shows the random options; `$OUT/sheet.png` is black (open it); the password field holds
a 20-character password (`20 ...`); after saving, the list shows `site.example.net`, the window is
`not secure`, and the paste puts the same password in the search field (copied with the clear
timer).
- [ ] **Step 4: New entry in a subfolder, diceware generator**
```bash
tap 'text="work"'; tap 'text="New entry"'; tap 'text="Create new password"'
seen 'text="work"' # folder crumb
adb shell input text vpn
tap 'content-desc="Generate Password"'; tap 'text="Diceware"'
seen 'text="Separator"'
field 2 _ # in the sheet: 1 words, 2 separator
ui | grep -o 'text="[^"]*_[^"]*"'
tap 'text="Use"'; DW=$(value 2); echo "$DW"
tap 'text="Save"'; sleep 3; seen 'text="vpn"'; secure
```
Expected: the editor shows the `work` crumb; the sheet's preview turns into five words joined by
`_`; the password field holds it; `vpn` is listed in `work`; `not secure`.
- [ ] **Step 5: Edit: rename, move with the picker, new password; cancel back to the entry**
```bash
adb shell input keyevent 4 # root
tap 'text="example.org"'; pass test; seen 'text="hunter2"'; secure
tap 'content-desc="Edit password"'
seen 'text="Edit entry"'; seen 'text="example.org"'; seen 'text="hunter2"'; seen 'text="alice"'
seen 'url: https://example.org'; secure
tap 'content-desc="Close"'; seen 'text="hunter2"'; secure # cancel: back on the entry view
tap 'content-desc="Edit password"'
field 1 example-login
tap 'text="Change"'; seen 'text="Choose a folder"'; top
tap 'text="work"'; tap 'text="Select"'; seen 'text="work"'
field 2 n3w-pass
tap 'text="Save"'; sleep 3
top; seen 'text="otp"'; seen 'text="example.org"'; secure
store; store work
tap 'text="work"'; tap 'text="example-login"'; pass test
seen 'text="n3w-pass"'; seen 'text="alice"'; seen 'text="https://example.org"'
adb shell input keyevent 4
```
Expected: the editor opens filled in and `secure`; Close returns to the decrypted entry view, still
`secure` (entry to editor to entry never cleared the flag); the picker is a dialog over
`MainActivity`; after Save the root list is back (`ok: text="otp"`), `MISSING:
text="example.org"`, `not secure`; `store` lists no `example.org.gpg` at the root and `store work`
lists `example-login.gpg`; the moved entry decrypts with the new password, its username and url.
- [ ] **Step 6: OTP from QR (menu only) and manual OTP**
```bash
tap 'text="vpn"'; pass test; tap 'content-desc="Edit password"'
tap 'text="OTP from QR"'; seen 'text="Scan QR code"'; seen 'text="Choose an image"'
tap 'text="Choose an image"'; sleep 2; top
adb shell input keyevent 4; sleep 1; seen 'text="No image file was selected"'
tap 'text="OTP from QR"'; tap 'text="Scan QR code"'; sleep 3; top
adb shell input keyevent 4; sleep 1; seen 'text="Failed to import TOTP configuration"'
tap 'text="Manual OTP"'; seen 'text="Add OTP"'
adb shell input text JBSWY3DPEHPK3PXP # the secret field has focus
tap 'class="android.widget.EditText"' 2; adb shell input text example.net
tap 'text="OK"'
seen 'otpauth://totp?secret=JBSWY3DPEHPK3PXP&issuer=example.net'; seen 'text="Manual OTP"'
tap 'text="Save"'; sleep 3; seen 'text="vpn"'
```
Expected: the QR menu offers both sources; "Choose an image" opens the system picker
(`com.android.documentsui` or `com.google.android.documentsui` on top) and backing out shows the
"no image" snackbar; "Scan QR code" opens zxing's `CaptureActivity`, backing out shows the failure
snackbar. QR decoding itself cannot be exercised on the emulator (no QR in front of its virtual
camera, no QR image on the device); the maintainer checks it on the phone. The manual dialog adds
the URI line to the extra content and both OTP actions disappear (`MISSING: text="Manual OTP"`).
The OTP entry view never goes idle, so its code is checked on the server in step 11, not here.
- [ ] **Step 7: Missing recipient refusal (0.1.2)**
```bash
FPR=$(cat .e2e/seed/.gpg-id)
printf '%s\nMissing Key <missing@example.org>\n' "$FPR" | adb exec-in "run-as xyz.danix.hardenedpass.debug sh -c 'mkdir -p files/store/missing && cat > files/store/missing/.gpg-id'"
adb shell input keyevent 4; sleep 1 # root, re-read on resume
tap 'text="missing"'; tap 'text="New entry"'; tap 'text="Create new password"'
adb shell input text nope; field 2 x
tap 'text="Save"'; sleep 2
seen 'text="Error"'; ui | grep -o 'nothing was saved[^"]*'
tap 'text="OK"'; seen 'text="nope"'
tap 'content-desc="Close"'; sleep 1; seen 'text="nope"'
store missing
adb shell run-as xyz.danix.hardenedpass.debug rm -r files/store/missing
adb shell input keyevent 4
```
Expected: saving shows the "Error" dialog with "Could not encrypt the password, nothing was saved:
No key found with id: ..." naming the missing recipient; OK leaves the editor open with its
content; Close returns to the folder without a `nope` entry; `store missing` lists only `.`, `..`
and `.gpg-id` (no file, not even an empty one). The folder is removed again before the sync.
- [ ] **Step 8: Cancel paths and rotation mid-edit**
```bash
tap 'text="New entry"'; tap 'text="Create new password"'
adb shell input text cancel-test; tap 'content-desc="Close"'; sleep 1
seen 'text="cancel-test"'; secure
tap 'text="New entry"'; tap 'text="Create new password"'
adb shell input text rot-test; field 2 abc123; field 4 line1
adb shell settings put system accelerometer_rotation 0; adb shell settings put system user_rotation 1; sleep 2
seen 'text="rot-test"'; seen 'text="abc123"'; seen 'text="line1"'; secure
adb shell settings put system user_rotation 0; sleep 2; seen 'text="rot-test"'
for i in 1 2; do ui | grep -q 'text="Save"' && adb shell input keyevent 4; sleep 1; done
seen 'text="rot-test"'; secure; store
```
Expected: Close discards (`MISSING: text="cancel-test"`, `not secure`); after rotation the editor
still shows all three values and is `secure`; system back (after the keyboard, if it was up)
discards too (`MISSING: text="rot-test"`, `not secure`), and `store` lists neither file.
- [ ] **Step 9: List move with the new picker**
```bash
hold 'text="site.example.net"'; tap 'content-desc="Move"'
seen 'text="Choose a folder"'; top
tap 'text="work"'; tap 'content-desc="Password store"' # into a folder, back to the root
tap 'text="New folder"'; seen 'text="Create folder"'
tap 'text="Create"'; seen 'Category name can' # blank
adb shell input text work; tap 'text="Create"'; seen 'text="A folder by that name already exists"'
field 1 ../outside; tap 'text="Create"'; seen 'text="Destination must be within the repository"'
field 1 archive; tap 'text="Create"'; seen 'text="archive"'; seen 'text="Choose a folder"'
store; store archive; adb shell run-as xyz.danix.hardenedpass.debug ls files
tap 'content-desc="Password store"'
tap 'text="otp"'; tap 'text="Select"'; sleep 2
seen 'text="site.example.net"'; seen 'text="archive"'
tap 'text="otp"'; seen 'text="site.example.net"'
adb shell input keyevent 4
```
Expected: the picker is a dialog over `MainActivity` (no `SelectFolderActivity`), its breadcrumbs
jump back to the root. "New folder" opens the list's "Create folder" dialog over the picker and
refuses, with the list's messages, a blank name, an existing folder (`work` at the root) and a
name that resolves outside the store (`../outside`); `archive` is created and the picker shows it
(crumb `archive`, still the picker); `store` lists `archive`, `store archive` lists only `.` and
`..`, and `ls files` shows no `outside` next to `store`. Back at the root crumb, Select on `otp` moves
the entry: gone from the root (`MISSING: text="site.example.net"`), `archive` listed in the
root, the entry listed in `otp`. (`archive` stays empty, so git never sees it and step 11's
server tree is unchanged.)
- [ ] **Step 10: Autofill save flow (if `adb root` works on this image)**
```bash
if adb root | grep -q 'cannot run as root'; then echo "skip: no adb root"; else
adb wait-for-device; sleep 2
adb shell am start -n xyz.danix.hardenedpass.debug/app.passwordstore.ui.autofill.AutofillSaveActivity \
--es app.passwordstore.autofill.oreo.ui.EXTRA_FOLDER_NAME example.net \
--es app.passwordstore.autofill.oreo.ui.EXTRA_NAME dave \
--es app.passwordstore.autofill.oreo.ui.EXTRA_PASSWORD from-the-form \
--es app.passwordstore.autofill.oreo.ui.EXTRA_SHOULD_MATCH_WEB example.net
sleep 3; top; seen 'text="dave"'; seen 'text="from-the-form"'; seen 'text="example.net"'
secure 'AutofillSaveActivity'
tap 'text="Save"'; sleep 3; top
adb shell am start -n xyz.danix.hardenedpass.debug/app.passwordstore.ui.autofill.AutofillSaveActivity \
--es app.passwordstore.autofill.oreo.ui.EXTRA_FOLDER_NAME example.net \
--es app.passwordstore.autofill.oreo.ui.EXTRA_NAME frank \
--ez app.passwordstore.autofill.oreo.ui.EXTRA_GENERATE_PASSWORD true
sleep 3; seen 'text="Use"'; tap 'text="Use"'; tap 'text="Save"'; sleep 3; top
adb unroot; adb wait-for-device; sleep 2
fi
open; tap 'text="example.net"'; seen 'text="dave"'; seen 'text="frank"'; adb shell input keyevent 4
```
Expected (with root): `AutofillSaveActivity` on top showing the editor prefilled with `dave`,
`from-the-form` and the `example.net` crumb, `secure`; Save finishes it. The second start opens
with the generator sheet already up; Use and Save finish it (no autofill client state from the
shell, so it only logs that and closes; the file is still saved and committed). The list then
shows `example.net` with `dave` and `frank`. Without root, the step prints `skip` and the list
check is skipped too. Either way the real flow is the maintainer's check, not part of this run
(maintainer decision 1): on the tablet with Firefox, submit a login form and save it from the
autofill prompt, then use "Generate password" on a sign-up form; both open this editor, save,
and the generated password is filled in. Record the result in the session handoff.
- [ ] **Step 11: Sync, and what the server got**
```bash
adb shell input swipe 540 700 540 1800 400; sleep 8
srv log --format=%s
srv ls-tree -r --name-only master
reveal otp/site.example.net; echo ---
reveal work/example-login; echo ---
reveal work/vpn; echo ---
python3 -c 'import hmac,hashlib,struct,time,base64;k=base64.b32decode("JBSWY3DPEHPK3PXP");h=hmac.new(k,struct.pack(">Q",int(time.time())//30),hashlib.sha1).digest();o=h[-1]&15;print("%06d"%((struct.unpack(">I",h[o:o+4])[0]&0x7fffffff)%1000000))'
```
Expected: no error dialog. The log shows, above `Initial test store`: `Add generated password
for site.example.net using HardenedPass.`, `Add generated password for work/vpn using
HardenedPass.`, `Edit password for work/example-login using HardenedPass.`, `Edit password for
work/vpn using HardenedPass.`, `Rename site.example.net to otp/site.example.net.` (plus the two
`example.net/...` additions when step 10 ran). The tree has no `example.org.gpg`, no
`missing/`, no `rot-test.gpg` or `cancel-test.gpg`, no `.tmp` file. Decrypted:
`otp/site.example.net` is `$PW`, then `username: erin`; `work/example-login` is `n3w-pass`,
`username: alice`, `url: https://example.org`; `work/vpn` is `$DW` then
`otpauth://totp?secret=JBSWY3DPEHPK3PXP&issuer=example.net`. (The Python line prints the current
code for that secret, for a by-eye comparison if wanted: open `work/vpn` and take an emulator
console screenshot, as in step 3's plan.)
- [ ] **Step 12: Tear down and push**
```bash
adb shell settings put system user_rotation 0; adb shell settings put system accelerometer_rotation 1
adb uninstall xyz.danix.hardenedpass.debug
adb shell rm -f /sdcard/Download/aps-e2e-ssh-key /sdcard/Download/aps-e2e-pgp-key.asc
adb emu kill
scripts/e2e-env.sh down
unset ANDROID_SERIAL
rm -rf "$OUT"
git push
```
Expected: push succeeds to every `origin` push URL.
---
## Self-review notes
- **Spec coverage for step 4:** `EditRoute` is a Compose destination in `MainActivity`, opened from
the create sheet in the current folder and from the entry view's edit action (Task 5); after save
the list, after cancel back where it came from (Task 5, checked in Task 8 steps 3, 5, 8). Top bar
close, title, Save; name; folder chips with Change opening the picker; password with reveal and
generator; generator bottom sheet with random and diceware tabs and the old options; username;
free-text extras; OTP from QR and manual (Tasks 4, 5). Strings in `values/` and `values-it/`
("voce" for entry; Tasks 2, 4). Folder picker shared with the list's move (Tasks 2, 5; checked
in steps 5 and 9, "New folder" with its refusals in step 9). `FLAG_SECURE` counted across entry and editor, explicit on the sheet and the
OTP dialog, on for the autofill editor (Tasks 4 to 6; steps 3, 5, 8, 10). Plaintext only in
ViewModel memory; edits copy it from the entry view's ViewModel (Tasks 3, 5). Save path keeps
every check and closes three gaps (Task 3; steps 5, 7, 11). Autofill save keeps working, now on
the Compose editor (Task 6; step 10 and the maintainer's device check). Deletions and what is
left of `BasePGPActivity` (Task 7). TDD for the pure logic (Task 1). Full local CI (Task 7).
Emulator check of every scenario asked for (Task 8).
- **Parity summary:** ported: secure window, titles, name focus, password reveal and monospace,
generators with all options and stored preferences, OTP scan, image and manual import with
snackbars, OTP actions hidden when a secret exists, validation messages, `.gpg-id` recipients,
missing-key refusal, nothing written on failed encryption, duplicate check, inside-repository
check, rename with recently-used time, commit messages, autofill result. Changed: folder chips
and picker instead of a path field, username always shown, password visibility from the setting,
Save and copy in the overflow and only after success, generator errors in the sheet, write
errors keep the editor open, an undeletable old file is a snackbar, rotation keeps the form in
memory instead of saved state. Fixed: overwrite on a move, copy left behind on a move, folder
created before the inside check, failed write truncating an entry, autofill matches lost on
rename. Dropped: "Encrypt username" switch, the editor's "No keys imported" prompt.
- **Deliberate shortcuts (`ponytail:`):** an edit restored after process death closes (Task 5);
commit failures not shown and a mid-save theme change committing later (Task 5); the picker's
plain scrolling column (Task 2); generator length caps (Task 4); `AutofillSaveActivity`'s
`configChanges` (Task 6).
- **Type and name consistency:** `EditorForm`, `editorForm`, `passContent`, `formError`,
`entryFile`, `overwrites`, `writeEntry`, `withLine`, `totpUri`, `RandomSpec.options`,
`randomPassword`, `DicewareSpec` (Task 1) are used with the same signatures in Tasks 3 and 5;
`SaveResult.Saved(file, form, staleOriginal)` in Tasks 3, 5, 6; `EditorViewModel.start`,
`started`, `saving`, `hasOtp`, `randomSpec`, `generateRandom`, `dicewareSpec`,
`generateDiceware`, `readQr`, `save` (Task 3) match their calls in Task 5; `FolderPicker(root,
start, onPick, onDismiss)` in Tasks 2 and 5, `FolderNameDialog` and `folderNameError` shared by
the list and the picker; `ListDestination(..., onNewEntry)` and
`EntryDestination(..., onEdit)` match `MainActivity` (Task 5).
## Maintainer decisions (2026-11-03)
1. Autofill save moves to the Compose editor in this step (Task 6 as planned). The tablet and
Firefox check of the real autofill save and generate flows is the maintainer's; Task 8, step 10
says so.
2. The folder picker gets a "New folder" action: it creates a folder inside the folder the picker
shows, with the list's validation (blank, inside the repository by path components, already
exists), then shows it so Select picks it. The list's `FolderNameDialog` (now `internal`) and
`folderNameError` are reused, not duplicated. New string `folder_picker_new` in `values/` and
`values-it/`. Applied in Task 2, checked in Task 8, step 9.
3. "Encrypt username" switch: dropped, as planned.
4. "Save and copy": kept in the overflow menu, copies only after a successful save, as planned.
|