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
|
/*
* Copyright (C) 2020 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.window;
import static android.app.Instrumentation.DEBUG_START_ACTIVITY;
import static android.app.TaskInfo.SELF_MOVABLE_UNSET;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.window.TaskFragmentOperation.OP_TYPE_CLEAR_ADJACENT_TASK_FRAGMENTS;
import static android.window.TaskFragmentOperation.OP_TYPE_CREATE_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_DELETE_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_COMPANION_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT;
import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SuppressLint;
import android.annotation.TestApi;
import android.app.Instrumentation;
import android.app.PendingIntent;
import android.app.TaskInfo.SelfMovable;
import android.app.WindowConfiguration;
import android.app.WindowConfiguration.WindowingMode;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ShortcutInfo;
import android.content.res.Configuration;
import android.graphics.Insets;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.ArrayMap;
import android.util.Log;
import android.view.InsetsFrameProvider;
import android.view.InsetsSource;
import android.view.SurfaceControl;
import android.view.WindowInsets;
import android.view.WindowInsets.Type.InsetsType;
import com.android.window.flags.Flags;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
/**
* Represents a collection of operations on some WindowContainers that should be applied all at
* once.
*
* @hide
*/
@TestApi
public final class WindowContainerTransaction implements Parcelable {
private final ArrayMap<IBinder, Change> mChanges = new ArrayMap<>();
// Flat list because re-order operations are order-dependent
private final ArrayList<HierarchyOp> mHierarchyOps = new ArrayList<>();
@Nullable
private IBinder mErrorCallbackToken;
@Nullable
private ITaskFragmentOrganizer mTaskFragmentOrganizer;
public WindowContainerTransaction() {}
private WindowContainerTransaction(@NonNull Parcel in) {
in.readMap(mChanges, null /* loader */);
in.readTypedList(mHierarchyOps, HierarchyOp.CREATOR);
mErrorCallbackToken = in.readStrongBinder();
mTaskFragmentOrganizer = ITaskFragmentOrganizer.Stub.asInterface(in.readStrongBinder());
}
@NonNull
private Change getOrCreateChange(IBinder token) {
Change out = mChanges.get(token);
if (out == null) {
out = new Change();
mChanges.put(token, out);
}
return out;
}
/**
* Clear the transaction object.
* This is equivalent to a new empty {@link WindowContainerTransaction} in content.
*
* @hide
*/
public void clear() {
mChanges.clear();
mHierarchyOps.clear();
mErrorCallbackToken = null;
mTaskFragmentOrganizer = null;
}
/*
* ===========================================================================================
* Window container properties
* ===========================================================================================
*/
/**
* Resize a container.
*/
@NonNull
public WindowContainerTransaction setBounds(
@NonNull WindowContainerToken container, @NonNull Rect bounds) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mConfiguration.windowConfiguration.setBounds(bounds);
chg.mConfigSetMask |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
chg.mWindowSetMask |= WindowConfiguration.WINDOW_CONFIG_BOUNDS;
return this;
}
/**
* Resize a container's app bounds. This is the bounds used to report appWidth/Height to an
* app's DisplayInfo. It is derived by subtracting the overlapping portion of the navbar from
* the full bounds.
*/
@NonNull
public WindowContainerTransaction setAppBounds(
@NonNull WindowContainerToken container, @NonNull Rect appBounds) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mConfiguration.windowConfiguration.setAppBounds(appBounds);
chg.mConfigSetMask |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
chg.mWindowSetMask |= WindowConfiguration.WINDOW_CONFIG_APP_BOUNDS;
return this;
}
/**
* Resize a container's configuration size. The configuration size is what gets reported to the
* app via screenWidth/HeightDp and influences which resources get loaded. This size is
* derived by subtracting the overlapping portions of both the statusbar and the navbar from
* the full bounds.
*/
@NonNull
public WindowContainerTransaction setScreenSizeDp(
@NonNull WindowContainerToken container, int w, int h) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mConfiguration.screenWidthDp = w;
chg.mConfiguration.screenHeightDp = h;
chg.mConfigSetMask |= ActivityInfo.CONFIG_SCREEN_SIZE;
return this;
}
/**
* Sets the densityDpi value in the configuration for the given container.
* @hide
*/
@NonNull
public WindowContainerTransaction setDensityDpi(@NonNull WindowContainerToken container,
int densityDpi) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mConfiguration.densityDpi = densityDpi;
chg.mConfigSetMask |= ActivityInfo.CONFIG_DENSITY;
return this;
}
/**
* Send a SurfaceControl transaction to the server, which the server will apply in sync with
* the next bounds change. As this uses deferred transaction and not BLAST it is only
* able to sync with a single window, and the first visible window in this hierarchy of type
* BASE_APPLICATION to resize will be used. If there are bound changes included in this
* WindowContainer transaction (from setBounds or scheduleFinishEnterPip), the SurfaceControl
* transaction will be synced with those bounds. If there are no changes, then
* the SurfaceControl transaction will be synced with the next bounds change. This means
* that you can call this, apply the WindowContainer transaction, and then later call
* dismissPip() to achieve synchronization.
*/
@NonNull
public WindowContainerTransaction setBoundsChangeTransaction(
@NonNull WindowContainerToken container, @NonNull SurfaceControl.Transaction t) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mBoundsChangeTransaction = t;
chg.mChangeMask |= Change.CHANGE_BOUNDS_TRANSACTION;
return this;
}
/**
* Set the windowing mode of children of a given root task, without changing
* the windowing mode of the Task itself. This can be used during transitions
* for example to make the activity render it's fullscreen configuration
* while the Task is still in PIP, so you can complete the animation.
*
* TODO(b/134365562): Can be removed once TaskOrg drives full-screen
*/
@NonNull
public WindowContainerTransaction setActivityWindowingMode(
@NonNull WindowContainerToken container, @WindowingMode int windowingMode) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mActivityWindowingMode = windowingMode;
return this;
}
/**
* Sets the windowing mode of the given container.
*/
@NonNull
public WindowContainerTransaction setWindowingMode(
@NonNull WindowContainerToken container, @WindowingMode int windowingMode) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mWindowingMode = windowingMode;
return this;
}
/**
* Sets whether the container should launch next as Bubble
* @hide
*/
@NonNull
public WindowContainerTransaction setLaunchNextToBubble(
@NonNull WindowContainerToken container, boolean launchNextToBubble) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mLaunchNextToBubble = launchNextToBubble;
chg.mChangeMask |= Change.CHANGE_LAUNCH_NEXT_TO_BUBBLE;
return this;
}
/**
* Sets whether a container or any of its children can be focusable. When {@code false}, no
* child can be focused; however, when {@code true}, it is still possible for children to be
* non-focusable due to WM policy.
*/
@NonNull
public WindowContainerTransaction setFocusable(
@NonNull WindowContainerToken container, boolean focusable) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mFocusable = focusable;
chg.mChangeMask |= Change.CHANGE_FOCUSABLE;
return this;
}
/**
* Sets whether the IME insets should be excluded by {@link com.android.server.wm.InsetsPolicy}.
* @hide
*/
@SuppressLint("UnflaggedApi")
@NonNull
public WindowContainerTransaction setExcludeImeInsets(
@NonNull WindowContainerToken container, boolean exclude) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_SET_EXCLUDE_INSETS_TYPES)
.setContainer(container.asBinder())
.setExcludeInsetsTypes(exclude ? WindowInsets.Type.ime() : 0)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Sets the forcibly showing and hiding types of system bars of the display.
* @hide
*/
@NonNull
public WindowContainerTransaction setSystemBarVisibilityOverride(
@NonNull WindowContainerToken display,
@NonNull IBinder caller,
@InsetsType int forciblyShowingInsetsTypes,
@InsetsType int forciblyHidingInsetsTypes) {
final int forciblyShowingAndHidingTypes =
forciblyShowingInsetsTypes & forciblyHidingInsetsTypes;
if (forciblyShowingAndHidingTypes != 0) {
throw new IllegalArgumentException(
WindowInsets.Type.toString(forciblyShowingAndHidingTypes)
+ " cannot be forcibly shown and hidden at the same time.");
}
final HierarchyOp hierarchyOp = new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_SET_SYSTEM_BAR_VISIBILITY_OVERRIDE)
.setContainer(display.asBinder())
.setCaller(caller)
.setSystemBarVisibilityOverride(
forciblyShowingInsetsTypes, forciblyHidingInsetsTypes)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Sets whether a container or its children should be hidden. When {@code false}, the existing
* visibility of the container applies, but when {@code true} the container will be forced
* to be hidden.
*/
@NonNull
public WindowContainerTransaction setHidden(
@NonNull WindowContainerToken container, boolean hidden) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mHidden = hidden;
chg.mChangeMask |= Change.CHANGE_HIDDEN;
return this;
}
/**
* Set the smallestScreenWidth of a container.
*/
@NonNull
public WindowContainerTransaction setSmallestScreenWidthDp(
@NonNull WindowContainerToken container, int widthDp) {
final Change cfg = getOrCreateChange(container.asBinder());
cfg.mConfiguration.smallestScreenWidthDp = widthDp;
cfg.mConfigSetMask |= ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
return this;
}
/**
* Sets whether a container should ignore the orientation request from apps and windows below
* it. It currently only applies to {@link com.android.server.wm.DisplayArea}. When
* {@code false}, it may rotate based on the orientation request; When {@code true}, it can
* never specify orientation, but shows the fixed-orientation apps below it in the letterbox.
* @hide
*/
@NonNull
public WindowContainerTransaction setIgnoreOrientationRequest(
@NonNull WindowContainerToken container, boolean ignoreOrientationRequest) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mIgnoreOrientationRequest = ignoreOrientationRequest;
chg.mChangeMask |= Change.CHANGE_IGNORE_ORIENTATION_REQUEST;
return this;
}
/**
* Sets whether a task should be translucent. When {@code false}, the existing translucent of
* the task applies, but when {@code true} the task will be forced to be translucent.
* @hide
*/
@NonNull
public WindowContainerTransaction setForceTranslucent(
@NonNull WindowContainerToken container, boolean forceTranslucent) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mForceTranslucent = forceTranslucent;
chg.mChangeMask |= Change.CHANGE_FORCE_TRANSLUCENT;
return this;
}
/**
* Resizes a container by providing a bounds in its parent coordinate.
* This is only used by {@link TaskFragmentOrganizer}.
*/
@NonNull
public WindowContainerTransaction setRelativeBounds(
@NonNull WindowContainerToken container, @NonNull Rect relBounds) {
final Change chg = getOrCreateChange(container.asBinder());
if (chg.mRelativeBounds == null) {
chg.mRelativeBounds = new Rect();
}
chg.mRelativeBounds.set(relBounds);
chg.mChangeMask |= Change.CHANGE_RELATIVE_BOUNDS;
// Bounds will be overridden.
chg.mConfigSetMask |= ActivityInfo.CONFIG_WINDOW_CONFIGURATION;
chg.mWindowSetMask |= WindowConfiguration.WINDOW_CONFIG_BOUNDS;
return this;
}
/**
* Sets whether a container is being drag-resized.
* When {@code true}, the client will reuse a single (larger) surface size to avoid
* continuous allocations on every size change.
*
* @param container WindowContainerToken of the task that changed its drag resizing state
* @hide
*/
@NonNull
public WindowContainerTransaction setDragResizing(@NonNull WindowContainerToken container,
boolean dragResizing) {
final Change change = getOrCreateChange(container.asBinder());
change.mChangeMask |= Change.CHANGE_DRAG_RESIZING;
change.mDragResizing = dragResizing;
return this;
}
/**
* Sets/removes the always on top flag for this {@code windowContainer}. See
* {@link com.android.server.wm.ConfigurationContainer#setAlwaysOnTop(boolean)}.
* Please note that this method is only intended to be used for a
* {@link com.android.server.wm.Task} or {@link com.android.server.wm.DisplayArea}.
*
* <p>
* Setting always on top to {@code True} will also make the {@code windowContainer} to move
* to the top.
* </p>
* <p>
* Setting always on top to {@code False} will make this {@code windowContainer} to move
* below the other always on top sibling containers.
* </p>
*
* @param windowContainer the container which the flag need to be updated for.
* @param alwaysOnTop denotes whether or not always on top flag should be set.
* @hide
*/
@NonNull
public WindowContainerTransaction setAlwaysOnTop(
@NonNull WindowContainerToken windowContainer, boolean alwaysOnTop) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP)
.setContainer(windowContainer.asBinder())
.setAlwaysOnTop(alwaysOnTop)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Sets/removes the reparent leaf task flag for this {@code windowContainer}.
* When this is set, the server side will try to reparent the leaf task to task display area
* if there is an existing activity in history during the activity launch. This operation only
* support on the organized root task.
* @hide
*/
@NonNull
public WindowContainerTransaction setReparentLeafTaskIfRelaunch(
@NonNull WindowContainerToken windowContainer, boolean reparentLeafTaskIfRelaunch) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH)
.setContainer(windowContainer.asBinder())
.setReparentLeafTaskIfRelaunch(reparentLeafTaskIfRelaunch)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Defers client-facing configuration changes for activities in `container` until the end of
* the transition animation. The configuration will still be applied to the WMCore hierarchy
* at the normal time (beginning); so, special consideration must be made for this in the
* animation.
*
* @param container WindowContainerToken who's children should defer config notification.
* @hide
*/
@NonNull
public WindowContainerTransaction deferConfigToTransitionEnd(
@NonNull WindowContainerToken container) {
final Change change = getOrCreateChange(container.asBinder());
change.mConfigAtTransitionEnd = true;
return this;
}
/**
* Sets the task as trimmable or not. This can be used to prevent the task from being trimmed by
* recents. This attribute is set to true on task creation by default.
*
* @param isTrimmableFromRecents When {@code true}, task is set as trimmable from recents.
* @hide
*/
@NonNull
public WindowContainerTransaction setTaskTrimmableFromRecents(
@NonNull WindowContainerToken container,
boolean isTrimmableFromRecents) {
mHierarchyOps.add(
HierarchyOp.createForSetTaskTrimmableFromRecents(container.asBinder(),
isTrimmableFromRecents));
return this;
}
/**
* Sets a given safe region {@code Rect} on the {@code container}. Set {@code null} to reset
* safe region bounds. When a safe region is set on a WindowContainer, the activities which
* need to be within a safe region will be letterboxed within the set safe region bounds.
* <p>Note that if the position of the WindowContainer changes, the caller needs to update the
* safe region bounds.
*
* @param container The window container that the safe region bounds are set on
* @param safeRegionBounds The rect for the safe region bounds which are absolute in nature.
* @hide
*/
@NonNull
@FlaggedApi(Flags.FLAG_SAFE_REGION_LETTERBOXING)
public WindowContainerTransaction setSafeRegionBounds(
@NonNull WindowContainerToken container,
@Nullable Rect safeRegionBounds) {
mHierarchyOps.add(
HierarchyOp.createForSetSafeRegionBounds(container.asBinder(), safeRegionBounds));
return this;
}
/**
* Sets whether the task should be forcibly excluded from Recents.
*
* @param container The window container of the task that the exclusion state is set on.
* @param forceExcluded {@code true} to force exclude the task, {@code false} otherwise.
* @throws IllegalStateException if the flag {@link Flags#FLAG_EXCLUDE_TASK_FROM_RECENTS} is
* not enabled.
* @hide
*/
@NonNull
public WindowContainerTransaction setTaskForceExcludedFromRecents(
@NonNull WindowContainerToken container, boolean forceExcluded) {
if (!Flags.excludeTaskFromRecents()) {
throw new IllegalStateException(
"Flag " + Flags.FLAG_EXCLUDE_TASK_FROM_RECENTS + " is not enabled");
}
final Change chg = getOrCreateChange(container.asBinder());
chg.mChangeMask |= Change.CHANGE_FORCE_EXCLUDED_FROM_RECENTS;
chg.mForceExcludedFromRecents = forceExcluded;
return this;
}
/**
* Sets whether the given container can be repositioned by {@link
* android.app.ActivityManager.AppTask#moveTaskTo}.
* Note that there are additional permission checks for the caller of {@link
* android.app.ActivityManager.AppTask#moveTaskTo}.
*
* @param container The window container of the task that the self-movable state is set on.
* @param selfMovable {@link android.app.TaskInfo#SELF_MOVABLE_ALLOWED} or {@link
* android.app.TaskInfo#SELF_MOVABLE_DENIED} to set the task as self-movable or not, {@link
* android.app.TaskInfo#SELF_MOVABLE_DEFAULT} to let the WM Core decide.
* @hide
*/
@NonNull
public WindowContainerTransaction setSelfMovable(
@NonNull WindowContainerToken container, @SelfMovable int selfMovable) {
final Change change = getOrCreateChange(container.asBinder());
change.mSelfMovable = selfMovable;
return this;
}
/**
* Sets whether the given container is able to contain self-movable tasks. A display is
* considered able to contain self-movable tasks as long as there is one child window container
* that is able to contain self-movable tasks.
*
* <p>Initially after each boot-up no window containers can contain self-movable tasks.
*
* <p>The container must be either a TaskDisplayArea or a root Task for this setting to have
* effect.
*
* @param container The window container whose ability to contain self-movable tasks is set on.
* @param isTaskMoveAllowed {@code true} to allow containing self-movable tasks, {@code
* false} otherwise.
* @hide
*/
@NonNull
public WindowContainerTransaction setIsTaskMoveAllowed(
@NonNull WindowContainerToken container, boolean isTaskMoveAllowed) {
final Change change = getOrCreateChange(container.asBinder());
change.mChangeMask |= Change.CHANGE_IS_TASK_MOVE_ALLOWED;
change.mIsTaskMoveAllowed = isTaskMoveAllowed;
return this;
}
/**
* Sets whether back press should be intercepted for the root activity of the given task
* container. If true, then
* {@link TaskOrganizer#onBackPressedOnTaskRoot(ActivityManager.RunningTaskInfo)} will be
* called.
*
* @param container The window container of the task that the intercept-back state is set on.
* @param interceptBackPressed {@code true} to allow back to be intercepted for the root
* activity of the task, {@code false} otherwise.
* @hide
*/
@NonNull
public WindowContainerTransaction setInterceptBackPressedOnTaskRoot(
@NonNull WindowContainerToken container,
boolean interceptBackPressed) {
final Change change = getOrCreateChange(container.asBinder());
change.mChangeMask |= Change.CHANGE_INTERCEPT_BACK_PRESSED;
change.mInterceptBackPressed = interceptBackPressed;
return this;
}
/*
* ===========================================================================================
* Hierarchy updates (create/destroy/reorder/reparent containers)
* ===========================================================================================
*/
/**
* Reorders a container within its parent.
*
* @param onTop When {@code true}, the child goes to the top of parent; otherwise it goes to
* the bottom.
*/
@NonNull
public WindowContainerTransaction reorder(@NonNull WindowContainerToken child, boolean onTop) {
return reorder(child, onTop, false /* includingParents */);
}
/**
* Reorders a container within its parent with an option to reorder all the parents in the
* hierarchy above among their respective siblings.
*
* @param onTop When {@code true}, the child goes to the top of parent; otherwise it goes to
* the bottom.
* @param includingParents When {@code true}, all the parents in the hierarchy above are also
* reordered among their respective siblings.
* @hide
*/
@NonNull
public WindowContainerTransaction reorder(@NonNull WindowContainerToken child, boolean onTop,
boolean includingParents) {
mHierarchyOps.add(HierarchyOp.createForReorder(child.asBinder(), onTop, includingParents));
return this;
}
/**
* Reparents a container into another one. The effect of a {@code null} parent can vary. For
* example, reparenting a stack to {@code null} will reparent it to its display.
*
* @param onTop When {@code true}, the child goes to the top of parent; otherwise it goes to
* the bottom.
*/
@NonNull
public WindowContainerTransaction reparent(@NonNull WindowContainerToken child,
@Nullable WindowContainerToken parent, boolean onTop) {
mHierarchyOps.add(HierarchyOp.createForReparent(child.asBinder(),
parent == null ? null : parent.asBinder(),
onTop));
return this;
}
/**
* Reparent's all children tasks or the top task of {@param currentParent} in the specified
* {@param windowingMode} and {@param activityType} to {@param newParent} in their current
* z-order.
*
* @param currentParent of the tasks to perform the operation no.
* {@code null} will perform the operation on the display.
* @param newParent for the tasks. {@code null} will perform the operation on the display.
* @param windowingModes of the tasks to reparent.
* @param activityTypes of the tasks to reparent.
* @param onTop When {@code true}, the child goes to the top of parent; otherwise it goes to
* the bottom.
* @param reparentTopOnly When {@code true}, only reparent the top task which fit windowingModes
* and activityTypes.
* @hide
*/
@NonNull
public WindowContainerTransaction reparentTasks(@Nullable WindowContainerToken currentParent,
@Nullable WindowContainerToken newParent, @Nullable int[] windowingModes,
@Nullable int[] activityTypes, boolean onTop, boolean reparentTopOnly) {
mHierarchyOps.add(HierarchyOp.createForChildrenTasksReparent(
currentParent != null ? currentParent.asBinder() : null,
newParent != null ? newParent.asBinder() : null,
windowingModes,
activityTypes,
onTop,
reparentTopOnly));
return this;
}
/**
* Reparent's all children tasks of {@param currentParent} in the specified
* {@param windowingMode} and {@param activityType} to {@param newParent} in their current
* z-order.
*
* @param currentParent of the tasks to perform the operation no.
* {@code null} will perform the operation on the display.
* @param newParent for the tasks. {@code null} will perform the operation on the display.
* @param windowingModes of the tasks to reparent. {@code null} ignore this attribute when
* perform the operation.
* @param activityTypes of the tasks to reparent. {@code null} ignore this attribute when
* perform the operation.
* @param onTop When {@code true}, the child goes to the top of parent; otherwise it goes to
* the bottom.
*/
@NonNull
public WindowContainerTransaction reparentTasks(@Nullable WindowContainerToken currentParent,
@Nullable WindowContainerToken newParent, @Nullable int[] windowingModes,
@Nullable int[] activityTypes, boolean onTop) {
return reparentTasks(currentParent, newParent, windowingModes, activityTypes, onTop,
false /* reparentTopOnly */);
}
/**
* Finds and removes a task and its children using its container token. The task is removed
* from recents.
*
* <p>If the task is a root task, its leaves are removed but the root task is not. Use
* {@link #removeRootTask(WindowContainerToken)} to remove the root task.
*
* @param containerToken ContainerToken of Task to be removed
*/
@NonNull
public WindowContainerTransaction removeTask(@NonNull WindowContainerToken containerToken) {
mHierarchyOps.add(HierarchyOp.createForRemoveTask(containerToken.asBinder()));
return this;
}
/**
* Finds and removes a root task created by an organizer and its leaves using its container
* token.
*
* @param containerToken ContainerToken of the root task to be removed
* @hide
*/
@NonNull
public WindowContainerTransaction removeRootTask(@NonNull WindowContainerToken containerToken) {
mHierarchyOps.add(HierarchyOp.createForRemoveRootTask(containerToken.asBinder()));
return this;
}
/**
* If `container` was brought to front as a transient-launch (eg. recents), this will reorder
* the container back to where it was prior to the transient-launch. This way if a transient
* launch is "aborted", the z-ordering of containers in WM should be restored to before the
* launch.
* @hide
*/
@NonNull
public WindowContainerTransaction restoreTransientOrder(
@NonNull WindowContainerToken container) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_RESTORE_TRANSIENT_ORDER)
.setContainer(container.asBinder())
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Restore the back navigation target from visible to invisible for canceling gesture animation.
* @hide
*/
@NonNull
public WindowContainerTransaction restoreBackNavi() {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_RESTORE_BACK_NAVIGATION)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/*
* ===========================================================================================
* Activity launch
* ===========================================================================================
*/
/**
* Starts a task by id. The task is expected to already exist (eg. as a recent task).
* @param taskId Id of task to start.
* @param options bundle containing ActivityOptions for the task's top activity.
* @hide
*/
@NonNull
public WindowContainerTransaction startTask(int taskId, @Nullable Bundle options) {
if (DEBUG_START_ACTIVITY) {
Log.d(Instrumentation.TAG, "WCT.startTask: taskId=" + taskId
+ " options=" + options, new Throwable());
}
mHierarchyOps.add(HierarchyOp.createForTaskLaunch(taskId, options));
return this;
}
/**
* Sends a pending intent in sync.
* @param sender The PendingIntent sender.
* @param fillInIntent The fillIn intent to patch over the sender's base intent.
* @param options bundle containing ActivityOptions for the task's top activity.
* @hide
*/
@NonNull
public WindowContainerTransaction sendPendingIntent(@Nullable PendingIntent sender,
@Nullable Intent fillInIntent, @Nullable Bundle options) {
if (DEBUG_START_ACTIVITY) {
Log.d(Instrumentation.TAG, "WCT.sendPendingIntent: sender="
+ (sender != null ? sender.getIntent() : "null")
+ " fillInIntent=" + fillInIntent + " options=" + options, new Throwable());
}
mHierarchyOps.add(new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_PENDING_INTENT)
.setLaunchOptions(options)
.setPendingIntent(sender)
.setActivityIntent(fillInIntent)
.build());
return this;
}
/**
* Starts activity(s) from a shortcut.
* @param callingPackage The package launching the shortcut.
* @param shortcutInfo Information about the shortcut to start
* @param options bundle containing ActivityOptions for the task's top activity.
* @hide
*/
@NonNull
public WindowContainerTransaction startShortcut(@NonNull String callingPackage,
@NonNull ShortcutInfo shortcutInfo, @Nullable Bundle options) {
if (DEBUG_START_ACTIVITY) {
Log.d(Instrumentation.TAG, "WCT.startShortcut: shortcutInfo=" + shortcutInfo
+ " options=" + options, new Throwable());
}
mHierarchyOps.add(HierarchyOp.createForStartShortcut(
callingPackage, shortcutInfo, options));
return this;
}
/**
* Sets whether a container should be the launch root for the specified windowing mode and
* activity type. This currently only applies to Task containers created by organizer.
*/
@NonNull
public WindowContainerTransaction setLaunchRoot(@NonNull WindowContainerToken container,
@Nullable int[] windowingModes, @Nullable int[] activityTypes) {
mHierarchyOps.add(HierarchyOp.createForSetLaunchRoot(
container.asBinder(),
windowingModes,
activityTypes));
return this;
}
/*
* ===========================================================================================
* Multitasking
* ===========================================================================================
*/
/**
* Sets two containers adjacent to each other. Containers below two visible adjacent roots will
* be made invisible. This currently only applies to TaskFragment containers created by
* organizer.
* @param root1 the first root.
* @param root2 the second root.
* @deprecated replace with {@link #setAdjacentRootSet}
*/
@SuppressWarnings("UnflaggedApi") // @TestApi without associated feature.
@Deprecated
@NonNull
public WindowContainerTransaction setAdjacentRoots(
@NonNull WindowContainerToken root1, @NonNull WindowContainerToken root2) {
return setAdjacentRootSet(root1, root2);
}
/**
* Sets multiple containers adjacent to each other. Containers below the visible adjacent roots
* will be made invisible. This currently only applies to Task containers created by organizer.
*
* <p>To remove one container from the adjacent roots, one can call {@link #clearAdjacentRoots}
* with the target container.
* To remove all containers from the adjacent roots, one much call {@link #clearAdjacentRoots}
* on each container if there were more than two containers in the set.
*
* <p>For non-Task TaskFragment, use {@link #setAdjacentTaskFragments} instead.
*
* @param roots the Tasks that should be adjacent to each other.
* @throws IllegalArgumentException if roots have size < 2.
* @hide // TODO(b/373709676) Rename to setAdjacentRoots and update CTS in 25Q4.
*/
@NonNull
public WindowContainerTransaction setAdjacentRootSet(@NonNull WindowContainerToken... roots) {
if (roots.length < 2) {
throw new IllegalArgumentException("setAdjacentRootSet must have size >= 2");
}
final IBinder[] rootTokens = new IBinder[roots.length];
for (int i = 0; i < roots.length; i++) {
rootTokens[i] = roots[i].asBinder();
}
mHierarchyOps.add(
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS)
.setContainers(rootTokens)
.build());
return this;
}
/**
* Clears container adjacent.
* If {@link #setAdjacentRootSet} is called with more than 2 roots, calling this will only
* remove the given root from the adjacent set. The rest of roots will stay adjacent to each
* other.
*
* @param root the root container to clear the adjacent roots for.
* @hide
*/
@NonNull
public WindowContainerTransaction clearAdjacentRoots(@NonNull WindowContainerToken root) {
mHierarchyOps.add(HierarchyOp.createForClearAdjacentRoots(root.asBinder()));
return this;
}
/**
* Sets the container as launch adjacent flag root. Task starting with
* {@link Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT} will be launching to.
*/
@NonNull
public WindowContainerTransaction setLaunchAdjacentFlagRoot(
@NonNull WindowContainerToken container) {
mHierarchyOps.add(HierarchyOp.createForSetLaunchAdjacentFlagRoot(container.asBinder(),
false /* clearRoot */));
return this;
}
/**
* Clears launch adjacent flag root for the display area of passing container.
*/
@NonNull
public WindowContainerTransaction clearLaunchAdjacentFlagRoot(
@NonNull WindowContainerToken container) {
mHierarchyOps.add(HierarchyOp.createForSetLaunchAdjacentFlagRoot(container.asBinder(),
true /* clearRoot */));
return this;
}
/**
* Disables or enables activities to be started in adjacent tasks (see
* {@link Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT}) for the specified root of any child tasks.
* This differs from {@link #setLaunchAdjacentFlagRoot(WindowContainerToken)} which controls the
* preferred launch-adjacent target and allows for selectively setting which root tasks can
* support launch-adjacent.
* @hide
*/
@NonNull
public WindowContainerTransaction setDisableLaunchAdjacent(
@NonNull WindowContainerToken container, boolean disabled) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mChangeMask |= Change.CHANGE_DISABLE_LAUNCH_ADJACENT;
chg.mDisableLaunchAdjacent = disabled;
return this;
}
/*
* ===========================================================================================
* PIP
* ===========================================================================================
*/
/**
* Moves the PiP activity of a parent task to a pinned root task.
* @param parentToken the parent task of the PiP activity
* @param bounds the entry bounds
* @hide
*/
@NonNull
public WindowContainerTransaction movePipActivityToPinnedRootTask(
@NonNull WindowContainerToken parentToken, @NonNull Rect bounds) {
mHierarchyOps.add(new HierarchyOp
.Builder(HierarchyOp.HIERARCHY_OP_TYPE_MOVE_PIP_ACTIVITY_TO_PINNED_TASK)
.setContainer(parentToken.asBinder())
.setBounds(bounds)
.build());
return this;
}
// TODO(b/365884835): Remove this method and the assertion in
// TaskFragmentOrganizerPolicyTest#testApplyChange_unsupportedChangeMask_throwException.
/**
* Notify {@link com.android.server.wm.PinnedTaskController} that the picture-in-picture task
* has finished the enter animation with the given bounds.
*/
@NonNull
public WindowContainerTransaction scheduleFinishEnterPip(
@NonNull WindowContainerToken container, @NonNull Rect bounds) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mChangeMask |= Change.CHANGE_PIP_CALLBACK;
return this;
}
/**
* Used in conjunction with a shell-transition call (usually finishTransition). This is
* basically a message to the transition system that a particular task should NOT go into
* PIP even though it normally would. This is to deal with some edge-case situations where
* Recents will "commit" the transition to go home, but then not actually go-home.
* @hide
*/
@NonNull
public WindowContainerTransaction setDoNotPip(@NonNull WindowContainerToken container) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mChangeMask |= Change.CHANGE_FORCE_NO_PIP;
return this;
}
/**
* Sets whether a Task or any of its children can enter picture-in-picture.
* When {@code false}, the container and its children won't be able to enter PiP.
*
* <p>Note: this is different from {@link #setDoNotPip}, which is to temporarily disable PiP
* during finishTransition.
* @hide
*/
@NonNull
public WindowContainerTransaction setDisablePip(
@NonNull WindowContainerToken container, boolean disablePip) {
final Change chg = getOrCreateChange(container.asBinder());
chg.mChangeMask |= Change.CHANGE_DISABLE_PIP;
chg.mDisablePip = disablePip;
return this;
}
/*
* ===========================================================================================
* Insets
* ===========================================================================================
*/
/**
* Adds a given {@code Rect} as an insets source frame on the {@code receiver}.
*
* @param receiver The window container that the insets source is added to.
* @param owner The owner of the insets source. An insets source can only be modified by its
* owner.
* @param index An owner might add multiple insets sources with the same type.
* This identifies them.
* @param type The {@link InsetsType} of the insets source.
* @param frame The rectangle area of the insets source.
* @param boundingRects The bounding rects within this inset, relative to the |frame|.
* @hide
*/
@NonNull
public WindowContainerTransaction addInsetsSource(
@NonNull WindowContainerToken receiver,
@Nullable IBinder owner, int index, @InsetsType int type, @Nullable Rect frame,
@Nullable Rect[] boundingRects, @InsetsSource.Flags int flags) {
return addInsetsSource(receiver, owner, new InsetsFrameProvider(owner, index, type)
.setSource(InsetsFrameProvider.SOURCE_ARBITRARY_RECTANGLE)
.setArbitraryRectangle(frame)
.setBoundingRects(boundingRects)
.setFlags(flags));
}
/**
* Adds a given {@code Insets} attached to the {@code receiver}'s bounds.
*
* @param receiver The window container that the insets source is attached to.
* @param owner The owner of the insets source. An insets source can only be modified by
* its owner.
* @param index An owner might add multiple insets sources with the same type.
* This identifies them.
* @param type The {@link InsetsType} of the insets source.
* @param insets The size of the insets on each side of the edges.
* @param boundingRects The bounding rects within this inset, relative to the |frame|.
* @hide
*/
@NonNull
public WindowContainerTransaction addInsetsSource(
@NonNull WindowContainerToken receiver,
@Nullable IBinder owner, int index, @InsetsType int type, @NonNull Insets insets,
@Nullable Rect[] boundingRects, @InsetsSource.Flags int flags) {
return addInsetsSource(receiver, owner, new InsetsFrameProvider(owner, index, type)
.setSource(InsetsFrameProvider.SOURCE_ATTACHED_CONTAINER_BOUNDS)
.setInsetsSize(insets)
.setBoundingRects(boundingRects)
.setFlags(flags));
}
@NonNull
private WindowContainerTransaction addInsetsSource(
@NonNull WindowContainerToken receiver, IBinder owner, InsetsFrameProvider provider) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_ADD_INSETS_FRAME_PROVIDER)
.setContainer(receiver.asBinder())
.setInsetsFrameProvider(provider)
.setCaller(owner)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Removes the insets source from the {@code receiver}.
*
* @param receiver The window container that the insets source was added to.
* @param owner The owner of the insets source. An insets source can only be modified by its
* owner.
* @param index An owner might add multiple insets sources with the same type.
* This identifies them.
* @param type The {@link InsetsType} of the insets source.
* @hide
*/
@NonNull
public WindowContainerTransaction removeInsetsSource(@NonNull WindowContainerToken receiver,
@Nullable IBinder owner, int index, @InsetsType int type) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_REMOVE_INSETS_FRAME_PROVIDER)
.setContainer(receiver.asBinder())
.setInsetsFrameProvider(new InsetsFrameProvider(owner, index, type))
.setCaller(owner)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/*
* ===========================================================================================
* Keyguard
* ===========================================================================================
*/
/**
* Adds a {@link KeyguardState} to apply to the given displays.
*
* @hide
*/
@NonNull
public WindowContainerTransaction addKeyguardState(@NonNull KeyguardState keyguardState) {
Objects.requireNonNull(keyguardState);
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE)
.setKeyguardState(keyguardState)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/*
* ===========================================================================================
* Task fragments
* ===========================================================================================
*/
/**
* Sets the {@link TaskFragmentOrganizer} that applies this {@link WindowContainerTransaction}.
* When this is set, the server side will not check for the permission of
* {@link android.Manifest.permission#MANAGE_ACTIVITY_TASKS}, but will ensure this WCT only
* contains operations that are allowed for this organizer, such as modifying TaskFragments that
* are organized by this organizer.
* @hide
*/
@NonNull
public WindowContainerTransaction setTaskFragmentOrganizer(
@NonNull ITaskFragmentOrganizer organizer) {
mTaskFragmentOrganizer = organizer;
return this;
}
/**
* When this {@link WindowContainerTransaction} failed to finish on the server side, it will
* trigger callback with this {@param errorCallbackToken}.
* @param errorCallbackToken client provided token that will be passed back as parameter in
* the callback if there is an error on the server side.
* @see com.android.server.wm.TaskFragmentOrganizerController#onTaskFragmentError
*/
@NonNull
public WindowContainerTransaction setErrorCallbackToken(@NonNull IBinder errorCallbackToken) {
if (mErrorCallbackToken != null) {
throw new IllegalStateException("Can't set multiple error token for one transaction.");
}
mErrorCallbackToken = errorCallbackToken;
return this;
}
/**
* Creates a new TaskFragment with the given options.
* @param taskFragmentCreationParams the options used to create the TaskFragment.
*/
@NonNull
public WindowContainerTransaction createTaskFragment(
@NonNull TaskFragmentCreationParams taskFragmentCreationParams) {
final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
OP_TYPE_CREATE_TASK_FRAGMENT)
.setTaskFragmentCreationParams(taskFragmentCreationParams)
.build();
return addTaskFragmentOperation(taskFragmentCreationParams.getFragmentToken(), operation);
}
/**
* Deletes an existing TaskFragment. Any remaining activities below it will be destroyed.
* @param fragmentToken client assigned unique token to create TaskFragment with specified in
* {@link TaskFragmentCreationParams#getFragmentToken()}.
*/
@NonNull
public WindowContainerTransaction deleteTaskFragment(@NonNull IBinder fragmentToken) {
final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
OP_TYPE_DELETE_TASK_FRAGMENT)
.build();
return addTaskFragmentOperation(fragmentToken, operation);
}
/**
* Starts an activity in the TaskFragment.
* @param fragmentToken client assigned unique token to create TaskFragment with specified in
* {@link TaskFragmentCreationParams#getFragmentToken()}.
* @param callerToken the activity token that initialized the activity launch.
* @param activityIntent intent to start the activity.
* @param activityOptions ActivityOptions to start the activity with.
* @see android.content.Context#startActivity(Intent, Bundle).
*/
@NonNull
public WindowContainerTransaction startActivityInTaskFragment(
@NonNull IBinder fragmentToken, @NonNull IBinder callerToken,
@NonNull Intent activityIntent, @Nullable Bundle activityOptions) {
final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT)
.setActivityToken(callerToken)
.setActivityIntent(activityIntent)
.setBundle(activityOptions)
.build();
return addTaskFragmentOperation(fragmentToken, operation);
}
/**
* Moves an activity into the TaskFragment.
* @param fragmentToken client assigned unique token to create TaskFragment with specified in
* {@link TaskFragmentCreationParams#getFragmentToken()}.
* @param activityToken activity to be reparented.
*/
@NonNull
public WindowContainerTransaction reparentActivityToTaskFragment(
@NonNull IBinder fragmentToken, @NonNull IBinder activityToken) {
final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT)
.setActivityToken(activityToken)
.build();
return addTaskFragmentOperation(fragmentToken, operation);
}
/**
* Sets to TaskFragments adjacent to each other. Containers below two visible adjacent
* TaskFragments will be made invisible. This is similar to
* {@link #setAdjacentRootSet(WindowContainerToken...)}, but can be used with
* fragmentTokens when that TaskFragments haven't been created (but will be created in the same
* {@link WindowContainerTransaction}).
* @param fragmentToken1 client assigned unique token to create TaskFragment with specified
* in {@link TaskFragmentCreationParams#getFragmentToken()}.
* @param fragmentToken2 client assigned unique token to create TaskFragment with specified
* in {@link TaskFragmentCreationParams#getFragmentToken()}.
*/
@NonNull
public WindowContainerTransaction setAdjacentTaskFragments(
@NonNull IBinder fragmentToken1, @NonNull IBinder fragmentToken2,
@Nullable TaskFragmentAdjacentParams params) {
final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS)
.setSecondaryFragmentToken(fragmentToken2)
.setBundle(params != null ? params.toBundle() : null)
.build();
return addTaskFragmentOperation(fragmentToken1, operation);
}
/**
* Clears the adjacent TaskFragments relationship that is previously set through
* {@link #setAdjacentTaskFragments}. Clear operation on one TaskFragment will also clear its
* current adjacent TaskFragment's.
* @param fragmentToken client assigned unique token to create TaskFragment with specified
* in {@link TaskFragmentCreationParams#getFragmentToken()}.
*/
@NonNull
public WindowContainerTransaction clearAdjacentTaskFragments(@NonNull IBinder fragmentToken) {
final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
OP_TYPE_CLEAR_ADJACENT_TASK_FRAGMENTS)
.build();
return addTaskFragmentOperation(fragmentToken, operation);
}
/**
* Requests focus on the top running Activity in the given TaskFragment. This will only take
* effect if there is no focus, or if the current focus is in the same Task as the requested
* TaskFragment.
* @param fragmentToken client assigned unique token to create TaskFragment with specified in
* {@link TaskFragmentCreationParams#getFragmentToken()}.
*/
@NonNull
public WindowContainerTransaction requestFocusOnTaskFragment(@NonNull IBinder fragmentToken) {
final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT)
.build();
return addTaskFragmentOperation(fragmentToken, operation);
}
/**
* Finishes the Activity.
* Comparing to directly calling {@link android.app.Activity#finish()}, calling this can make
* sure the finishing happens in the same transaction with other operations.
* @param activityToken activity to be finished.
*/
@NonNull
public WindowContainerTransaction finishActivity(@NonNull IBinder activityToken) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_FINISH_ACTIVITY)
.setContainer(activityToken)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Sets the TaskFragment {@code fragmentToken} to have a companion TaskFragment
* {@code companionFragmentToken}.
* This indicates that the organizer will remove the TaskFragment when the companion
* TaskFragment is removed.
*
* @param fragmentToken client assigned unique token to create TaskFragment with specified
* in {@link TaskFragmentCreationParams#getFragmentToken()}.
* @param companionFragmentToken client assigned unique token to create TaskFragment with
* specified in
* {@link TaskFragmentCreationParams#getFragmentToken()}.
* If it is {@code null}, the transaction will reset the companion
* TaskFragment.
* @hide
*/
@NonNull
public WindowContainerTransaction setCompanionTaskFragment(@NonNull IBinder fragmentToken,
@Nullable IBinder companionFragmentToken) {
final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
OP_TYPE_SET_COMPANION_TASK_FRAGMENT)
.setSecondaryFragmentToken(companionFragmentToken)
.build();
return addTaskFragmentOperation(fragmentToken, operation);
}
/**
* Adds a {@link TaskFragmentOperation} to apply to the given TaskFragment.
*
* @param fragmentToken client assigned unique token to create TaskFragment with specified in
* {@link TaskFragmentCreationParams#getFragmentToken()}.
* @param taskFragmentOperation the {@link TaskFragmentOperation} to apply to the given
* TaskFragment.
* @hide
*/
@NonNull
public WindowContainerTransaction addTaskFragmentOperation(@NonNull IBinder fragmentToken,
@NonNull TaskFragmentOperation taskFragmentOperation) {
Objects.requireNonNull(fragmentToken);
Objects.requireNonNull(taskFragmentOperation);
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_ADD_TASK_FRAGMENT_OPERATION)
.setContainer(fragmentToken)
.setTaskFragmentOperation(taskFragmentOperation)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Adds a hierarchy op for app compat reachability.
*
* @param container The token for the container Task
* @param taskId The id of the current task
* @hide
*/
public WindowContainerTransaction setReachabilityOffset(
@NonNull WindowContainerToken container, int taskId, int x, int y) {
mHierarchyOps.add(HierarchyOp.createForReachability(container.asBinder(), taskId, x, y));
return this;
}
/**
* Merges another WCT into this one.
* @param transfer When true, this will transfer everything from other potentially leaving
* other in an unusable state. When false, other is left alone, but
* SurfaceFlinger Transactions will not be merged.
* @hide
*/
public void merge(@NonNull WindowContainerTransaction other, boolean transfer) {
for (int i = 0, n = other.mChanges.size(); i < n; ++i) {
final IBinder key = other.mChanges.keyAt(i);
Change existing = mChanges.get(key);
if (existing == null) {
existing = new Change();
mChanges.put(key, existing);
}
existing.merge(other.mChanges.valueAt(i), transfer);
}
for (int i = 0, n = other.mHierarchyOps.size(); i < n; ++i) {
final HierarchyOp otherHierarchyOp = other.mHierarchyOps.get(i);
mHierarchyOps.add(transfer ? otherHierarchyOp : new HierarchyOp(otherHierarchyOp));
}
if (mErrorCallbackToken != null && other.mErrorCallbackToken != null && mErrorCallbackToken
!= other.mErrorCallbackToken) {
throw new IllegalArgumentException("Can't merge two WCTs with different error token");
}
final IBinder taskFragmentOrganizerAsBinder = mTaskFragmentOrganizer != null
? mTaskFragmentOrganizer.asBinder()
: null;
final IBinder otherTaskFragmentOrganizerAsBinder = other.mTaskFragmentOrganizer != null
? other.mTaskFragmentOrganizer.asBinder()
: null;
if (!Objects.equals(taskFragmentOrganizerAsBinder, otherTaskFragmentOrganizerAsBinder)) {
throw new IllegalArgumentException(
"Can't merge two WCTs from different TaskFragmentOrganizers");
}
mErrorCallbackToken = mErrorCallbackToken != null
? mErrorCallbackToken
: other.mErrorCallbackToken;
}
/** @hide */
public boolean isEmpty() {
return mChanges.isEmpty() && mHierarchyOps.isEmpty();
}
/** @hide */
@NonNull
public Map<IBinder, Change> getChanges() {
return mChanges;
}
/** @hide */
@NonNull
public List<HierarchyOp> getHierarchyOps() {
return mHierarchyOps;
}
/** @hide */
@Nullable
public IBinder getErrorCallbackToken() {
return mErrorCallbackToken;
}
/** @hide */
@Nullable
public ITaskFragmentOrganizer getTaskFragmentOrganizer() {
return mTaskFragmentOrganizer;
}
@Override
@NonNull
public String toString() {
return "WindowContainerTransaction {"
+ " changes= " + mChanges
+ " hops= " + mHierarchyOps
+ " errorCallbackToken=" + mErrorCallbackToken
+ " taskFragmentOrganizer=" + mTaskFragmentOrganizer
+ " }";
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeMap(mChanges);
dest.writeTypedList(mHierarchyOps);
dest.writeStrongBinder(mErrorCallbackToken);
dest.writeStrongInterface(mTaskFragmentOrganizer);
}
@Override
public int describeContents() {
return 0;
}
@NonNull
public static final Creator<WindowContainerTransaction> CREATOR =
new Creator<>() {
@Override
public WindowContainerTransaction createFromParcel(@NonNull Parcel in) {
return new WindowContainerTransaction(in);
}
@Override
public WindowContainerTransaction[] newArray(int size) {
return new WindowContainerTransaction[size];
}
};
/**
* Holds changes on a single WindowContainer including Configuration changes.
* @hide
*/
public static class Change implements Parcelable {
public static final int CHANGE_FOCUSABLE = 1;
public static final int CHANGE_BOUNDS_TRANSACTION = 1 << 1;
public static final int CHANGE_PIP_CALLBACK = 1 << 2;
public static final int CHANGE_HIDDEN = 1 << 3;
public static final int CHANGE_IGNORE_ORIENTATION_REQUEST = 1 << 4;
public static final int CHANGE_FORCE_NO_PIP = 1 << 5;
public static final int CHANGE_FORCE_TRANSLUCENT = 1 << 6;
public static final int CHANGE_DRAG_RESIZING = 1 << 7;
public static final int CHANGE_RELATIVE_BOUNDS = 1 << 8;
public static final int CHANGE_FORCE_EXCLUDED_FROM_RECENTS = 1 << 9;
public static final int CHANGE_LAUNCH_NEXT_TO_BUBBLE = 1 << 10;
public static final int CHANGE_DISABLE_PIP = 1 << 11;
public static final int CHANGE_DISABLE_LAUNCH_ADJACENT = 1 << 12;
public static final int CHANGE_IS_TASK_MOVE_ALLOWED = 1 << 13;
public static final int CHANGE_INTERCEPT_BACK_PRESSED = 1 << 14;
@IntDef(flag = true, prefix = { "CHANGE_" }, value = {
CHANGE_FOCUSABLE,
CHANGE_BOUNDS_TRANSACTION,
CHANGE_PIP_CALLBACK,
CHANGE_HIDDEN,
CHANGE_IGNORE_ORIENTATION_REQUEST,
CHANGE_FORCE_NO_PIP,
CHANGE_FORCE_TRANSLUCENT,
CHANGE_DRAG_RESIZING,
CHANGE_RELATIVE_BOUNDS,
CHANGE_FORCE_EXCLUDED_FROM_RECENTS,
CHANGE_LAUNCH_NEXT_TO_BUBBLE,
CHANGE_DISABLE_PIP,
CHANGE_DISABLE_LAUNCH_ADJACENT,
CHANGE_IS_TASK_MOVE_ALLOWED,
CHANGE_INTERCEPT_BACK_PRESSED
})
@Retention(RetentionPolicy.SOURCE)
public @interface ChangeMask {}
private final Configuration mConfiguration = new Configuration();
private boolean mFocusable = true;
private boolean mHidden = false;
private boolean mIgnoreOrientationRequest = false;
private boolean mForceTranslucent = false;
private boolean mDragResizing = false;
private boolean mForceExcludedFromRecents = false;
private boolean mDisablePip = false;
private boolean mDisableLaunchAdjacent = false;
private boolean mIsTaskMoveAllowed = false;
private boolean mInterceptBackPressed = false;
private @ChangeMask int mChangeMask = 0;
private @ActivityInfo.Config int mConfigSetMask = 0;
private @WindowConfiguration.WindowConfig int mWindowSetMask = 0;
private SurfaceControl.Transaction mBoundsChangeTransaction = null;
@Nullable
private Rect mRelativeBounds = null;
private boolean mConfigAtTransitionEnd = false;
private int mActivityWindowingMode = -1;
private int mWindowingMode = -1;
private @SelfMovable int mSelfMovable = SELF_MOVABLE_UNSET;
private boolean mLaunchNextToBubble = false;
private Change() {}
private Change(@NonNull Parcel in) {
mConfiguration.readFromParcel(in);
mFocusable = in.readBoolean();
mHidden = in.readBoolean();
mIgnoreOrientationRequest = in.readBoolean();
mForceTranslucent = in.readBoolean();
mDragResizing = in.readBoolean();
mForceExcludedFromRecents = in.readBoolean();
mLaunchNextToBubble = in.readBoolean();
mDisablePip = in.readBoolean();
mDisableLaunchAdjacent = in.readBoolean();
mIsTaskMoveAllowed = in.readBoolean();
mInterceptBackPressed = in.readBoolean();
mChangeMask = in.readInt();
mConfigSetMask = in.readInt();
mWindowSetMask = in.readInt();
if ((mChangeMask & Change.CHANGE_BOUNDS_TRANSACTION) != 0) {
mBoundsChangeTransaction =
SurfaceControl.Transaction.CREATOR.createFromParcel(in);
}
if ((mChangeMask & Change.CHANGE_RELATIVE_BOUNDS) != 0) {
mRelativeBounds = new Rect();
mRelativeBounds.readFromParcel(in);
}
mConfigAtTransitionEnd = in.readBoolean();
mWindowingMode = in.readInt();
mActivityWindowingMode = in.readInt();
mSelfMovable = in.readInt();
}
/**
* @param transfer When true, this will transfer other into this leaving other in an
* undefined state. Use this if you don't intend to use other. When false,
* SurfaceFlinger Transactions will not merge.
*/
public void merge(@NonNull Change other, boolean transfer) {
mConfiguration.setTo(other.mConfiguration, other.mConfigSetMask, other.mWindowSetMask);
mConfigSetMask |= other.mConfigSetMask;
mWindowSetMask |= other.mWindowSetMask;
if ((other.mChangeMask & CHANGE_FOCUSABLE) != 0) {
mFocusable = other.mFocusable;
}
if (transfer && (other.mChangeMask & CHANGE_BOUNDS_TRANSACTION) != 0) {
mBoundsChangeTransaction = other.mBoundsChangeTransaction;
other.mBoundsChangeTransaction = null;
}
if ((other.mChangeMask & CHANGE_HIDDEN) != 0) {
mHidden = other.mHidden;
}
if ((other.mChangeMask & CHANGE_IGNORE_ORIENTATION_REQUEST) != 0) {
mIgnoreOrientationRequest = other.mIgnoreOrientationRequest;
}
if ((other.mChangeMask & CHANGE_FORCE_TRANSLUCENT) != 0) {
mForceTranslucent = other.mForceTranslucent;
}
if ((other.mChangeMask & CHANGE_DRAG_RESIZING) != 0) {
mDragResizing = other.mDragResizing;
}
if ((other.mChangeMask & CHANGE_FORCE_EXCLUDED_FROM_RECENTS) != 0) {
mForceExcludedFromRecents = other.mForceExcludedFromRecents;
}
if ((other.mChangeMask & CHANGE_LAUNCH_NEXT_TO_BUBBLE) != 0) {
mLaunchNextToBubble = other.mLaunchNextToBubble;
}
if ((other.mChangeMask & CHANGE_DISABLE_PIP) != 0) {
mDisablePip = other.mDisablePip;
}
if ((other.mChangeMask & CHANGE_DISABLE_LAUNCH_ADJACENT) != 0) {
mDisableLaunchAdjacent = other.mDisableLaunchAdjacent;
}
if ((other.mChangeMask & CHANGE_IS_TASK_MOVE_ALLOWED) != 0) {
mIsTaskMoveAllowed = other.mIsTaskMoveAllowed;
}
if ((other.mChangeMask & CHANGE_INTERCEPT_BACK_PRESSED) != 0) {
mInterceptBackPressed = other.mInterceptBackPressed;
}
mChangeMask |= other.mChangeMask;
if (other.mActivityWindowingMode >= WINDOWING_MODE_UNDEFINED) {
mActivityWindowingMode = other.mActivityWindowingMode;
}
if (other.mWindowingMode >= WINDOWING_MODE_UNDEFINED) {
mWindowingMode = other.mWindowingMode;
}
if (other.mSelfMovable != SELF_MOVABLE_UNSET) {
mSelfMovable = other.mSelfMovable;
}
if (other.mRelativeBounds != null) {
mRelativeBounds = transfer
? other.mRelativeBounds
: new Rect(other.mRelativeBounds);
}
mConfigAtTransitionEnd = mConfigAtTransitionEnd
|| other.mConfigAtTransitionEnd;
}
public int getWindowingMode() {
return mWindowingMode;
}
public int getActivityWindowingMode() {
return mActivityWindowingMode;
}
@NonNull
public Configuration getConfiguration() {
return mConfiguration;
}
/** Gets the requested mLaunchNextToBubble state */
public boolean getLaunchNextToBubble() {
if ((mChangeMask & CHANGE_LAUNCH_NEXT_TO_BUBBLE) == 0) {
throw new RuntimeException(
"mLaunchNextToBubble not set. check CHANGE_LAUNCH_NEXT_TO_BUBBLE first");
}
return mLaunchNextToBubble;
}
/** Gets the requested focusable state */
public boolean getFocusable() {
if ((mChangeMask & CHANGE_FOCUSABLE) == 0) {
throw new RuntimeException("Focusable not set. check CHANGE_FOCUSABLE first");
}
return mFocusable;
}
/** Gets the requested hidden state */
public boolean getHidden() {
if ((mChangeMask & CHANGE_HIDDEN) == 0) {
throw new RuntimeException("Hidden not set. check CHANGE_HIDDEN first");
}
return mHidden;
}
/** Gets the requested state of whether to ignore orientation request. */
public boolean getIgnoreOrientationRequest() {
if ((mChangeMask & CHANGE_IGNORE_ORIENTATION_REQUEST) == 0) {
throw new RuntimeException("IgnoreOrientationRequest not set. "
+ "Check CHANGE_IGNORE_ORIENTATION_REQUEST first");
}
return mIgnoreOrientationRequest;
}
/** Gets the requested force translucent state. */
public boolean getForceTranslucent() {
if ((mChangeMask & CHANGE_FORCE_TRANSLUCENT) == 0) {
throw new RuntimeException("Force translucent not set. "
+ "Check CHANGE_FORCE_TRANSLUCENT first");
}
return mForceTranslucent;
}
/** Gets the requested drag resizing state. */
public boolean getDragResizing() {
if ((mChangeMask & CHANGE_DRAG_RESIZING) == 0) {
throw new RuntimeException("Drag resizing not set. "
+ "Check CHANGE_DRAG_RESIZING first");
}
return mDragResizing;
}
/** Gets whether the task is force excluded from recents. */
public boolean getForceExcludedFromRecents() {
if (!Flags.excludeTaskFromRecents()) {
throw new IllegalStateException(
"Flag " + Flags.FLAG_EXCLUDE_TASK_FROM_RECENTS + " is not enabled");
}
return mForceExcludedFromRecents;
}
/** Gets whether the task is disabled to enter picture-in-picture. */
public boolean getDisablePip() {
return mDisablePip;
}
/**
* Gets whether activities are disabled to be started in adjacent tasks for the specified
* root of any child tasks .
*/
public boolean getDisableLaunchAdjacent() {
return mDisableLaunchAdjacent;
}
/** Gets the intercept-back-pressed state. */
public boolean getInterceptBackPressed() {
if ((mChangeMask & CHANGE_INTERCEPT_BACK_PRESSED) == 0) {
throw new RuntimeException("Intercept back pressed not set. "
+ "Check CHANGE_INTERCEPT_BACK_PRESSED first");
}
return mInterceptBackPressed;
}
/** Gets whether the config should be sent to the client at the end of the transition. */
public boolean getConfigAtTransitionEnd() {
return mConfigAtTransitionEnd;
}
/**
* Gets whether the given container can be repositioned by {@link
* android.app.ActivityManager.AppTask#moveTaskTo}.
*/
public @SelfMovable int getSelfMovable() {
return mSelfMovable;
}
/**
* Gets whether the given container is able to contain self-movable tasks. A display
* is considered able to contain self-movable tasks as long as there is one child window
* container that is able to contain self-movable tasks.
*/
public boolean getIsTaskMoveAllowed() {
return mIsTaskMoveAllowed;
}
@ChangeMask
public int getChangeMask() {
return mChangeMask;
}
@ActivityInfo.Config
public int getConfigSetMask() {
return mConfigSetMask;
}
@WindowConfiguration.WindowConfig
public int getWindowSetMask() {
return mWindowSetMask;
}
@Nullable
public SurfaceControl.Transaction getBoundsChangeTransaction() {
return mBoundsChangeTransaction;
}
@Nullable
public Rect getRelativeBounds() {
return mRelativeBounds;
}
@Override
public String toString() {
final boolean changesBounds =
(mConfigSetMask & ActivityInfo.CONFIG_WINDOW_CONFIGURATION) != 0
&& ((mWindowSetMask & WindowConfiguration.WINDOW_CONFIG_BOUNDS)
!= 0);
final boolean changesAppBounds =
(mConfigSetMask & ActivityInfo.CONFIG_WINDOW_CONFIGURATION) != 0
&& ((mWindowSetMask & WindowConfiguration.WINDOW_CONFIG_APP_BOUNDS)
!= 0);
final boolean changesSs = (mConfigSetMask & ActivityInfo.CONFIG_SCREEN_SIZE) != 0;
final boolean changesSss =
(mConfigSetMask & ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE) != 0;
final var sb = new StringBuilder();
sb.append('{');
if (changesBounds) {
sb.append("bounds:").append(mConfiguration.windowConfiguration.getBounds())
.append(",");
}
if (changesAppBounds) {
sb.append("appbounds:").append(mConfiguration.windowConfiguration.getAppBounds())
.append(",");
}
if (changesSss) {
sb.append("ssw:").append(mConfiguration.smallestScreenWidthDp).append(",");
}
if (changesSs) {
sb.append("sw/h:").append(mConfiguration.screenWidthDp).append("x")
.append(mConfiguration.screenHeightDp).append(",");
}
if ((mChangeMask & CHANGE_FOCUSABLE) != 0) {
sb.append("focusable:").append(mFocusable).append(",");
}
if ((mChangeMask & CHANGE_FORCE_TRANSLUCENT) != 0) {
sb.append("forceTranslucent:").append(mForceTranslucent).append(",");
}
if ((mChangeMask & CHANGE_HIDDEN) != 0) {
sb.append("hidden:").append(mHidden).append(",");
}
if ((mChangeMask & CHANGE_DRAG_RESIZING) != 0) {
sb.append("dragResizing:").append(mDragResizing).append(",");
}
if ((mChangeMask & CHANGE_FORCE_EXCLUDED_FROM_RECENTS) != 0) {
sb.append("forceExcludedFromRecents:").append(mForceExcludedFromRecents)
.append(",");
}
if ((mChangeMask & CHANGE_DISABLE_PIP) != 0) {
sb.append("disablePip:").append(mDisablePip).append(",");
}
if ((mChangeMask & CHANGE_DISABLE_LAUNCH_ADJACENT) != 0) {
sb.append("disableLaunchAdjacent:").append(mDisableLaunchAdjacent).append(",");
}
if ((mChangeMask & CHANGE_IS_TASK_MOVE_ALLOWED) != 0) {
sb.append("isTaskMoveAllowed:").append(mIsTaskMoveAllowed).append(",");
}
if ((mChangeMask & CHANGE_INTERCEPT_BACK_PRESSED) != 0) {
sb.append("interceptBack:" + mInterceptBackPressed + ",");
}
if (mBoundsChangeTransaction != null) {
sb.append("hasBoundsTransaction,");
}
if ((mChangeMask & CHANGE_IGNORE_ORIENTATION_REQUEST) != 0) {
sb.append("ignoreOrientationRequest:").append(mIgnoreOrientationRequest)
.append(",");
}
if ((mChangeMask & CHANGE_RELATIVE_BOUNDS) != 0) {
sb.append("relativeBounds:").append(mRelativeBounds).append(",");
}
if ((mChangeMask & CHANGE_LAUNCH_NEXT_TO_BUBBLE) != 0) {
sb.append("launchNextToBubble:").append(mLaunchNextToBubble).append(",");
}
if (mConfigAtTransitionEnd) {
sb.append("configAtTransitionEnd").append(",");
}
sb.append("}");
return sb.toString();
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
mConfiguration.writeToParcel(dest, flags);
dest.writeBoolean(mFocusable);
dest.writeBoolean(mHidden);
dest.writeBoolean(mIgnoreOrientationRequest);
dest.writeBoolean(mForceTranslucent);
dest.writeBoolean(mDragResizing);
dest.writeBoolean(mForceExcludedFromRecents);
dest.writeBoolean(mLaunchNextToBubble);
dest.writeBoolean(mDisablePip);
dest.writeBoolean(mDisableLaunchAdjacent);
dest.writeBoolean(mIsTaskMoveAllowed);
dest.writeBoolean(mInterceptBackPressed);
dest.writeInt(mChangeMask);
dest.writeInt(mConfigSetMask);
dest.writeInt(mWindowSetMask);
if (mBoundsChangeTransaction != null) {
mBoundsChangeTransaction.writeToParcel(dest, flags);
}
if (mRelativeBounds != null) {
mRelativeBounds.writeToParcel(dest, flags);
}
dest.writeBoolean(mConfigAtTransitionEnd);
dest.writeInt(mWindowingMode);
dest.writeInt(mActivityWindowingMode);
dest.writeInt(mSelfMovable);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<Change> CREATOR = new Creator<>() {
@Override
public Change createFromParcel(@NonNull Parcel in) {
return new Change(in);
}
@Override
public Change[] newArray(int size) {
return new Change[size];
}
};
}
/**
* Holds information about a reparent/reorder operation in the hierarchy. This is separate from
* Changes because they must be executed in the same order that they are added.
* @see com.android.server.wm.WindowOrganizerController#applyHierarchyOp
* @hide
*/
public static final class HierarchyOp implements Parcelable {
public static final int HIERARCHY_OP_TYPE_REPARENT = 0;
public static final int HIERARCHY_OP_TYPE_REORDER = 1;
public static final int HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT = 2;
public static final int HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT = 3;
public static final int HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS = 4;
public static final int HIERARCHY_OP_TYPE_LAUNCH_TASK = 5;
public static final int HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT = 6;
public static final int HIERARCHY_OP_TYPE_PENDING_INTENT = 7;
public static final int HIERARCHY_OP_TYPE_START_SHORTCUT = 8;
public static final int HIERARCHY_OP_TYPE_RESTORE_TRANSIENT_ORDER = 9;
public static final int HIERARCHY_OP_TYPE_ADD_INSETS_FRAME_PROVIDER = 10;
public static final int HIERARCHY_OP_TYPE_REMOVE_INSETS_FRAME_PROVIDER = 11;
public static final int HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP = 12;
public static final int HIERARCHY_OP_TYPE_REMOVE_TASK = 13;
public static final int HIERARCHY_OP_TYPE_FINISH_ACTIVITY = 14;
public static final int HIERARCHY_OP_TYPE_CLEAR_ADJACENT_ROOTS = 15;
public static final int HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH = 16;
public static final int HIERARCHY_OP_TYPE_ADD_TASK_FRAGMENT_OPERATION = 17;
public static final int HIERARCHY_OP_TYPE_MOVE_PIP_ACTIVITY_TO_PINNED_TASK = 18;
public static final int HIERARCHY_OP_TYPE_SET_IS_TRIMMABLE = 19;
public static final int HIERARCHY_OP_TYPE_RESTORE_BACK_NAVIGATION = 20;
public static final int HIERARCHY_OP_TYPE_SET_EXCLUDE_INSETS_TYPES = 21;
public static final int HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE = 22;
public static final int HIERARCHY_OP_TYPE_REMOVE_ROOT_TASK = 23;
public static final int HIERARCHY_OP_TYPE_APP_COMPAT_REACHABILITY = 24;
public static final int HIERARCHY_OP_TYPE_SET_SAFE_REGION_BOUNDS = 25;
public static final int HIERARCHY_OP_TYPE_SET_SYSTEM_BAR_VISIBILITY_OVERRIDE = 26;
@IntDef(prefix = {"HIERARCHY_OP_TYPE_"}, value = {
HIERARCHY_OP_TYPE_REPARENT,
HIERARCHY_OP_TYPE_REORDER,
HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT,
HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT,
HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS,
HIERARCHY_OP_TYPE_LAUNCH_TASK,
HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT,
HIERARCHY_OP_TYPE_PENDING_INTENT,
HIERARCHY_OP_TYPE_START_SHORTCUT,
HIERARCHY_OP_TYPE_RESTORE_TRANSIENT_ORDER,
HIERARCHY_OP_TYPE_ADD_INSETS_FRAME_PROVIDER,
HIERARCHY_OP_TYPE_REMOVE_INSETS_FRAME_PROVIDER,
HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP,
HIERARCHY_OP_TYPE_REMOVE_TASK,
HIERARCHY_OP_TYPE_FINISH_ACTIVITY,
HIERARCHY_OP_TYPE_CLEAR_ADJACENT_ROOTS,
HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH,
HIERARCHY_OP_TYPE_ADD_TASK_FRAGMENT_OPERATION,
HIERARCHY_OP_TYPE_MOVE_PIP_ACTIVITY_TO_PINNED_TASK,
HIERARCHY_OP_TYPE_SET_IS_TRIMMABLE,
HIERARCHY_OP_TYPE_RESTORE_BACK_NAVIGATION,
HIERARCHY_OP_TYPE_SET_EXCLUDE_INSETS_TYPES,
HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE,
HIERARCHY_OP_TYPE_REMOVE_ROOT_TASK,
HIERARCHY_OP_TYPE_APP_COMPAT_REACHABILITY,
HIERARCHY_OP_TYPE_SET_SAFE_REGION_BOUNDS,
HIERARCHY_OP_TYPE_SET_SYSTEM_BAR_VISIBILITY_OVERRIDE,
})
@Retention(RetentionPolicy.SOURCE)
public @interface HierarchyOpType {
}
// The following key(s) are for use with mLaunchOptions:
// When launching a task (eg. from recents), this is the taskId to be launched.
public static final String LAUNCH_KEY_TASK_ID = "android:transaction.hop.taskId";
// When starting from a shortcut, this contains the calling package.
public static final String LAUNCH_KEY_SHORTCUT_CALLING_PACKAGE =
"android:transaction.hop.shortcut_calling_package";
// The following keys are used to define the reachability direction after a double tap.
public static final String REACHABILITY_EVENT_X = "android:transaction.reachability_x";
public static final String REACHABILITY_EVENT_Y = "android:transaction.reachability_y";
@HierarchyOpType
private final int mType;
// Container we are performing the operation on.
@Nullable
private IBinder mContainer;
@Nullable
private IBinder[] mContainers;
// If this is same as mContainer, then only change position, don't reparent.
@Nullable
private IBinder mReparent;
@Nullable
private InsetsFrameProvider mInsetsFrameProvider;
@Nullable
private IBinder mCaller;
// Moves/reparents to top of parent when {@code true}, otherwise moves/reparents to bottom.
private boolean mToTop;
private boolean mReparentTopOnly;
@Nullable
private int[] mWindowingModes;
@Nullable
private int[] mActivityTypes;
@Nullable
private Bundle mLaunchOptions;
@Nullable
private Bundle mAppCompatOptions;
@Nullable
private Intent mActivityIntent;
/** Used as options for {@link #addTaskFragmentOperation}. */
@Nullable
private TaskFragmentOperation mTaskFragmentOperation;
@Nullable
private KeyguardState mKeyguardState;
@Nullable
private PendingIntent mPendingIntent;
@Nullable
private ShortcutInfo mShortcutInfo;
@Nullable
private Rect mBounds;
private boolean mIncludingParents;
private boolean mAlwaysOnTop;
private boolean mReparentLeafTaskIfRelaunch;
private boolean mIsTrimmableFromRecents;
private @InsetsType int mExcludeInsetsTypes;
private @InsetsType int mForciblyShowingInsetsTypes;
private @InsetsType int mForciblyHidingInsetsTypes;
@Nullable
private Rect mSafeRegionBounds;
/** Creates a hierarchy operation for reparenting a container within the hierarchy. */
@NonNull
public static HierarchyOp createForReparent(
@NonNull IBinder container, @Nullable IBinder reparent, boolean toTop) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_REPARENT)
.setContainer(container)
.setReparentContainer(reparent)
.setToTop(toTop)
.build();
}
/**
* Creates a a hierarchy op for the reorder operation.
*
* @param container which needs to be reordered
* @param toTop if true, the container reorders
* @param includingParents if true, all the parents in the hierarchy above are also
* reordered among their respective siblings
* @return
*/
@NonNull
public static HierarchyOp createForReorder(@NonNull IBinder container, boolean toTop,
boolean includingParents) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_REORDER)
.setContainer(container)
.setReparentContainer(container)
.setToTop(toTop)
.setIncludingParents(includingParents)
.build();
}
/** Creates a hierarchy op for reparenting child tasks from one container to another. */
@NonNull
public static HierarchyOp createForChildrenTasksReparent(@Nullable IBinder currentParent,
@Nullable IBinder newParent, @Nullable int[] windowingModes,
@Nullable int[] activityTypes, boolean onTop, boolean reparentTopOnly) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT)
.setContainer(currentParent)
.setReparentContainer(newParent)
.setWindowingModes(windowingModes)
.setActivityTypes(activityTypes)
.setToTop(onTop)
.setReparentTopOnly(reparentTopOnly)
.build();
}
/** Creates a hierarchy op for setting the launch root for tasks. */
@NonNull
public static HierarchyOp createForSetLaunchRoot(@Nullable IBinder container,
@Nullable int[] windowingModes, @Nullable int[] activityTypes) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT)
.setContainer(container)
.setWindowingModes(windowingModes)
.setActivityTypes(activityTypes)
.build();
}
/** Creates a hierarchy op for setting adjacent root tasks. */
@NonNull
public static HierarchyOp createForAdjacentRoots(
@Nullable IBinder root1, @Nullable IBinder root2) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS)
.setContainer(root1)
.setReparentContainer(root2)
.build();
}
/** Creates a hierarchy op for launching a task. */
@NonNull
public static HierarchyOp createForTaskLaunch(int taskId, @Nullable Bundle options) {
final Bundle fullOptions = options == null ? new Bundle() : options;
fullOptions.putInt(LAUNCH_KEY_TASK_ID, taskId);
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_LAUNCH_TASK)
.setToTop(true)
.setLaunchOptions(fullOptions)
.build();
}
/** Creates a hierarchy op for starting a shortcut. */
@NonNull
public static HierarchyOp createForStartShortcut(@NonNull String callingPackage,
@NonNull ShortcutInfo shortcutInfo, @Nullable Bundle options) {
final Bundle fullOptions = options == null ? new Bundle() : options;
fullOptions.putString(LAUNCH_KEY_SHORTCUT_CALLING_PACKAGE, callingPackage);
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_START_SHORTCUT)
.setShortcutInfo(shortcutInfo)
.setLaunchOptions(fullOptions)
.build();
}
/** Creates a hierarchy op for setting launch adjacent flag root. */
@NonNull
public static HierarchyOp createForSetLaunchAdjacentFlagRoot(@Nullable IBinder container,
boolean clearRoot) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT)
.setContainer(container)
.setToTop(clearRoot)
.build();
}
/** Creates a hierarchy op for deleting a task **/
@NonNull
public static HierarchyOp createForRemoveTask(@NonNull IBinder container) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_REMOVE_TASK)
.setContainer(container)
.build();
}
/**
* Creates a hierarchy op for deleting a root task
*
* @hide
**/
@NonNull
public static HierarchyOp createForRemoveRootTask(@NonNull IBinder container) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_REMOVE_ROOT_TASK)
.setContainer(container)
.build();
}
/** Creates a hierarchy op for clearing adjacent root tasks. */
@NonNull
public static HierarchyOp createForClearAdjacentRoots(@NonNull IBinder root) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_CLEAR_ADJACENT_ROOTS)
.setContainer(root)
.build();
}
/** Create a hierarchy op for app compat reachability. */
@NonNull
public static HierarchyOp createForReachability(IBinder container, int taskId, int x,
int y) {
final Bundle appCompatOptions = new Bundle();
appCompatOptions.putInt(LAUNCH_KEY_TASK_ID, taskId);
appCompatOptions.putInt(REACHABILITY_EVENT_X, x);
appCompatOptions.putInt(REACHABILITY_EVENT_Y, y);
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_APP_COMPAT_REACHABILITY)
.setAppCompatOptions(appCompatOptions)
.setContainer(container)
.build();
}
/** Create a hierarchy op for setting a task non-trimmable by recents. */
@NonNull
@FlaggedApi(Flags.FLAG_ENABLE_DESKTOP_WINDOWING_WALLPAPER_ACTIVITY)
public static HierarchyOp createForSetTaskTrimmableFromRecents(@NonNull IBinder container,
boolean isTrimmableFromRecents) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_IS_TRIMMABLE)
.setContainer(container)
.setIsTrimmableFromRecents(isTrimmableFromRecents)
.build();
}
/** Creates a hierarchy op for setting the safe region bounds. */
@NonNull
@FlaggedApi(Flags.FLAG_SAFE_REGION_LETTERBOXING)
public static HierarchyOp createForSetSafeRegionBounds(@NonNull IBinder container,
@Nullable Rect safeRegionBounds) {
return new Builder(HIERARCHY_OP_TYPE_SET_SAFE_REGION_BOUNDS)
.setContainer(container)
.setSafeRegionBounds(safeRegionBounds)
.build();
}
/** Only creates through {@link Builder}. */
private HierarchyOp(@HierarchyOpType int type) {
mType = type;
}
public HierarchyOp(@NonNull HierarchyOp copy) {
mType = copy.mType;
mContainer = copy.mContainer;
mContainers = copy.mContainers;
mBounds = copy.mBounds;
mIncludingParents = copy.mIncludingParents;
mReparent = copy.mReparent;
mInsetsFrameProvider = copy.mInsetsFrameProvider;
mCaller = copy.mCaller;
mToTop = copy.mToTop;
mReparentTopOnly = copy.mReparentTopOnly;
mWindowingModes = copy.mWindowingModes;
mActivityTypes = copy.mActivityTypes;
mLaunchOptions = copy.mLaunchOptions;
mAppCompatOptions = copy.mAppCompatOptions;
mActivityIntent = copy.mActivityIntent;
mTaskFragmentOperation = copy.mTaskFragmentOperation;
mKeyguardState = copy.mKeyguardState;
mPendingIntent = copy.mPendingIntent;
mShortcutInfo = copy.mShortcutInfo;
mAlwaysOnTop = copy.mAlwaysOnTop;
mReparentLeafTaskIfRelaunch = copy.mReparentLeafTaskIfRelaunch;
mIsTrimmableFromRecents = copy.mIsTrimmableFromRecents;
mExcludeInsetsTypes = copy.mExcludeInsetsTypes;
mForciblyShowingInsetsTypes = copy.mForciblyShowingInsetsTypes;
mForciblyHidingInsetsTypes = copy.mForciblyHidingInsetsTypes;
mSafeRegionBounds = copy.mSafeRegionBounds;
}
private HierarchyOp(@NonNull Parcel in) {
mType = in.readInt();
mContainer = in.readStrongBinder();
mContainers = in.createBinderArray();
mBounds = in.readTypedObject(Rect.CREATOR);
mIncludingParents = in.readBoolean();
mReparent = in.readStrongBinder();
mInsetsFrameProvider = in.readTypedObject(InsetsFrameProvider.CREATOR);
mCaller = in.readStrongBinder();
mToTop = in.readBoolean();
mReparentTopOnly = in.readBoolean();
mWindowingModes = in.createIntArray();
mActivityTypes = in.createIntArray();
mLaunchOptions = in.readBundle();
mAppCompatOptions = in.readBundle(getClass().getClassLoader());
mActivityIntent = in.readTypedObject(Intent.CREATOR);
mTaskFragmentOperation = in.readTypedObject(TaskFragmentOperation.CREATOR);
mKeyguardState = in.readTypedObject(KeyguardState.CREATOR);
mPendingIntent = in.readTypedObject(PendingIntent.CREATOR);
mShortcutInfo = in.readTypedObject(ShortcutInfo.CREATOR);
mAlwaysOnTop = in.readBoolean();
mReparentLeafTaskIfRelaunch = in.readBoolean();
mIsTrimmableFromRecents = in.readBoolean();
mExcludeInsetsTypes = in.readInt();
mForciblyShowingInsetsTypes = in.readInt();
mForciblyHidingInsetsTypes = in.readInt();
mSafeRegionBounds = in.readTypedObject(Rect.CREATOR);
}
@HierarchyOpType
public int getType() {
return mType;
}
public boolean isReparent() {
return mType == HIERARCHY_OP_TYPE_REPARENT;
}
@Nullable
public IBinder getNewParent() {
return mReparent;
}
@Nullable
public InsetsFrameProvider getInsetsFrameProvider() {
return mInsetsFrameProvider;
}
@Nullable
public IBinder getCaller() {
return mCaller;
}
@NonNull
public IBinder getContainer() {
return mContainer;
}
@NonNull
public IBinder[] getContainers() {
return mContainers;
}
public boolean getToTop() {
return mToTop;
}
public boolean getReparentTopOnly() {
return mReparentTopOnly;
}
@Nullable
public int[] getWindowingModes() {
return mWindowingModes;
}
@Nullable
public int[] getActivityTypes() {
return mActivityTypes;
}
@Nullable
public Bundle getLaunchOptions() {
return mLaunchOptions;
}
@Nullable
public Bundle getAppCompatOptions() {
return mAppCompatOptions;
}
@Nullable
public Intent getActivityIntent() {
return mActivityIntent;
}
public boolean isAlwaysOnTop() {
return mAlwaysOnTop;
}
public boolean isReparentLeafTaskIfRelaunch() {
return mReparentLeafTaskIfRelaunch;
}
@Nullable
public TaskFragmentOperation getTaskFragmentOperation() {
return mTaskFragmentOperation;
}
@Nullable
public KeyguardState getKeyguardState() {
return mKeyguardState;
}
@Nullable
public PendingIntent getPendingIntent() {
return mPendingIntent;
}
@Nullable
public ShortcutInfo getShortcutInfo() {
return mShortcutInfo;
}
@NonNull
public Rect getBounds() {
return mBounds;
}
/** Denotes whether the parents should also be included in the op. */
public boolean includingParents() {
return mIncludingParents;
}
/** Denotes whether the task can be trimmable from recents */
public boolean isTrimmableFromRecents() {
return mIsTrimmableFromRecents;
}
public @InsetsType int getExcludeInsetsTypes() {
return mExcludeInsetsTypes;
}
public @InsetsType int getForciblyShowingInsetsTypes() {
return mForciblyShowingInsetsTypes;
}
public @InsetsType int getForciblyHidingInsetsTypes() {
return mForciblyHidingInsetsTypes;
}
/** Denotes the safe region bounds */
@Nullable
public Rect getSafeRegionBounds() {
return mSafeRegionBounds;
}
/** Gets a string representation of a hierarchy-op type. */
public static String hopToString(@HierarchyOpType int type) {
switch (type) {
case HIERARCHY_OP_TYPE_REPARENT: return "reparent";
case HIERARCHY_OP_TYPE_REORDER: return "reorder";
case HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT: return "childrenTasksReparent";
case HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT: return "setLaunchRoot";
case HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS: return "setAdjacentRoots";
case HIERARCHY_OP_TYPE_LAUNCH_TASK: return "launchTask";
case HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT: return "setAdjacentFlagRoot";
case HIERARCHY_OP_TYPE_PENDING_INTENT: return "pendingIntent";
case HIERARCHY_OP_TYPE_START_SHORTCUT: return "startShortcut";
case HIERARCHY_OP_TYPE_RESTORE_TRANSIENT_ORDER: return "restoreTransientOrder";
case HIERARCHY_OP_TYPE_ADD_INSETS_FRAME_PROVIDER: return "addInsetsFrameProvider";
case HIERARCHY_OP_TYPE_REMOVE_INSETS_FRAME_PROVIDER:
return "removeInsetsFrameProvider";
case HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP: return "setAlwaysOnTop";
case HIERARCHY_OP_TYPE_REMOVE_TASK: return "removeTask";
case HIERARCHY_OP_TYPE_REMOVE_ROOT_TASK: return "removeRootTask";
case HIERARCHY_OP_TYPE_FINISH_ACTIVITY: return "finishActivity";
case HIERARCHY_OP_TYPE_CLEAR_ADJACENT_ROOTS: return "clearAdjacentRoots";
case HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH:
return "setReparentLeafTaskIfRelaunch";
case HIERARCHY_OP_TYPE_ADD_TASK_FRAGMENT_OPERATION:
return "addTaskFragmentOperation";
case HIERARCHY_OP_TYPE_MOVE_PIP_ACTIVITY_TO_PINNED_TASK:
return "movePipActivityToPinnedTask";
case HIERARCHY_OP_TYPE_SET_IS_TRIMMABLE: return "setIsTrimmable";
case HIERARCHY_OP_TYPE_RESTORE_BACK_NAVIGATION: return "restoreBackNav";
case HIERARCHY_OP_TYPE_SET_EXCLUDE_INSETS_TYPES: return "setExcludeInsetsTypes";
case HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE: return "setKeyguardState";
case HIERARCHY_OP_TYPE_SET_SAFE_REGION_BOUNDS: return "setSafeRegionBounds";
case HIERARCHY_OP_TYPE_SET_SYSTEM_BAR_VISIBILITY_OVERRIDE:
return "setSystemBarVisibilityOverride";
default: return "HOP(" + type + ")";
}
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("{").append(hopToString(mType)).append(": ");
switch (mType) {
case HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT:
sb.append("from=").append(mContainer).append(" to=").append(mReparent)
.append(" mToTop=").append(mToTop)
.append(" mReparentTopOnly=").append(mReparentTopOnly)
.append(" mWindowingMode=").append(Arrays.toString(mWindowingModes))
.append(" mActivityType=").append(Arrays.toString(mActivityTypes));
break;
case HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT:
sb.append("container=").append(mContainer)
.append(" mWindowingMode=").append(Arrays.toString(mWindowingModes))
.append(" mActivityType=").append(Arrays.toString(mActivityTypes));
break;
case HIERARCHY_OP_TYPE_REPARENT:
sb.append(mContainer).append(" to ").append(mToTop ? "top of " : "bottom of ")
.append(mReparent);
break;
case HIERARCHY_OP_TYPE_REORDER:
sb.append(mContainer).append(" to ").append(mToTop ? "top" : "bottom");
break;
case HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS:
for (IBinder container : mContainers) {
if (container == mContainers[0]) {
sb.append("adjacentRoots=").append(container);
} else {
sb.append(", ").append(container);
}
}
break;
case HIERARCHY_OP_TYPE_LAUNCH_TASK:
sb.append(mLaunchOptions);
break;
case HIERARCHY_OP_TYPE_APP_COMPAT_REACHABILITY:
sb.append(mAppCompatOptions);
break;
case HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT:
sb.append("container=").append(mContainer).append(" clearRoot=").append(mToTop);
break;
case HIERARCHY_OP_TYPE_START_SHORTCUT:
sb.append("options=").append(mLaunchOptions)
.append(" info=").append(mShortcutInfo);
break;
case HIERARCHY_OP_TYPE_PENDING_INTENT:
sb.append("options=").append(mLaunchOptions);
break;
case HIERARCHY_OP_TYPE_ADD_INSETS_FRAME_PROVIDER:
case HIERARCHY_OP_TYPE_REMOVE_INSETS_FRAME_PROVIDER:
sb.append("container=").append(mContainer)
.append(" provider=").append(mInsetsFrameProvider)
.append(" caller=").append(mCaller);
break;
case HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP:
sb.append("container=").append(mContainer)
.append(" alwaysOnTop=").append(mAlwaysOnTop);
break;
case HIERARCHY_OP_TYPE_REMOVE_TASK:
sb.append("task=").append(mContainer);
break;
case HIERARCHY_OP_TYPE_REMOVE_ROOT_TASK:
sb.append("rootTask=").append(mContainer);
break;
case HIERARCHY_OP_TYPE_FINISH_ACTIVITY:
sb.append("activity=").append(mContainer);
break;
case HIERARCHY_OP_TYPE_CLEAR_ADJACENT_ROOTS:
sb.append("container=").append(mContainer);
break;
case HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH:
sb.append("container= ").append(mContainer)
.append(" reparentLeafTaskIfRelaunch= ")
.append(mReparentLeafTaskIfRelaunch);
break;
case HIERARCHY_OP_TYPE_ADD_TASK_FRAGMENT_OPERATION:
sb.append("fragmentToken= ").append(mContainer)
.append(" operation= ").append(mTaskFragmentOperation);
break;
case HIERARCHY_OP_TYPE_SET_EXCLUDE_INSETS_TYPES:
sb.append("container= ").append(mContainer)
.append(" mExcludeInsetsTypes= ")
.append(WindowInsets.Type.toString(mExcludeInsetsTypes));
break;
case HIERARCHY_OP_TYPE_SET_KEYGUARD_STATE:
sb.append("KeyguardState= ").append(mKeyguardState);
break;
case HIERARCHY_OP_TYPE_SET_IS_TRIMMABLE:
sb.append("container= ").append(mContainer)
.append(" isTrimmable= ")
.append(mIsTrimmableFromRecents);
break;
case HIERARCHY_OP_TYPE_SET_SAFE_REGION_BOUNDS:
sb.append("container= ").append(mContainer)
.append(" safeRegionBounds= ")
.append(mSafeRegionBounds);
break;
case HIERARCHY_OP_TYPE_SET_SYSTEM_BAR_VISIBILITY_OVERRIDE:
sb.append(" container=").append(mContainer)
.append(" caller=").append(mCaller)
.append(" mForciblyShowingInsetsTypes=")
.append(WindowInsets.Type.toString(mForciblyShowingInsetsTypes))
.append(" mForciblyHidingInsetsTypes=")
.append(WindowInsets.Type.toString(mForciblyHidingInsetsTypes));
break;
default:
sb.append("container=").append(mContainer)
.append(" reparent=").append(mReparent)
.append(" mToTop=").append(mToTop)
.append(" mWindowingMode=").append(Arrays.toString(mWindowingModes))
.append(" mActivityType=").append(Arrays.toString(mActivityTypes));
}
return sb.append("}").toString();
}
@Override
public void writeToParcel(@NonNull Parcel dest, int flags) {
dest.writeInt(mType);
dest.writeStrongBinder(mContainer);
dest.writeBinderArray(mContainers);
dest.writeTypedObject(mBounds, flags);
dest.writeBoolean(mIncludingParents);
dest.writeStrongBinder(mReparent);
dest.writeTypedObject(mInsetsFrameProvider, flags);
dest.writeStrongBinder(mCaller);
dest.writeBoolean(mToTop);
dest.writeBoolean(mReparentTopOnly);
dest.writeIntArray(mWindowingModes);
dest.writeIntArray(mActivityTypes);
dest.writeBundle(mLaunchOptions);
dest.writeBundle(mAppCompatOptions);
dest.writeTypedObject(mActivityIntent, flags);
dest.writeTypedObject(mTaskFragmentOperation, flags);
dest.writeTypedObject(mKeyguardState, flags);
dest.writeTypedObject(mPendingIntent, flags);
dest.writeTypedObject(mShortcutInfo, flags);
dest.writeBoolean(mAlwaysOnTop);
dest.writeBoolean(mReparentLeafTaskIfRelaunch);
dest.writeBoolean(mIsTrimmableFromRecents);
dest.writeInt(mExcludeInsetsTypes);
dest.writeInt(mForciblyShowingInsetsTypes);
dest.writeInt(mForciblyHidingInsetsTypes);
dest.writeTypedObject(mSafeRegionBounds, flags);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<HierarchyOp> CREATOR = new Creator<>() {
@Override
public HierarchyOp createFromParcel(@NonNull Parcel in) {
return new HierarchyOp(in);
}
@Override
public HierarchyOp[] newArray(int size) {
return new HierarchyOp[size];
}
};
private static class Builder {
@HierarchyOpType
private final int mType;
@Nullable
private IBinder mContainer;
@Nullable
private IBinder[] mContainers;
@Nullable
private IBinder mReparent;
@Nullable
private InsetsFrameProvider mInsetsFrameProvider;
@Nullable
private IBinder mCaller;
private boolean mToTop;
private boolean mReparentTopOnly;
@Nullable
private int[] mWindowingModes;
@Nullable
private int[] mActivityTypes;
@Nullable
private Bundle mLaunchOptions;
@Nullable
private Bundle mAppCompatOptions;
@Nullable
private Intent mActivityIntent;
@Nullable
private TaskFragmentOperation mTaskFragmentOperation;
@Nullable
private KeyguardState mKeyguardState;
@Nullable
private PendingIntent mPendingIntent;
@Nullable
private ShortcutInfo mShortcutInfo;
@Nullable
private Rect mBounds;
private boolean mIncludingParents;
private boolean mAlwaysOnTop;
private boolean mReparentLeafTaskIfRelaunch;
private boolean mIsTrimmableFromRecents;
private @InsetsType int mExcludeInsetsTypes;
private @InsetsType int mForciblyShowingInsetsTypes;
private @InsetsType int mForciblyHidingInsetsTypes;
@Nullable
private Rect mSafeRegionBounds;
Builder(@HierarchyOpType int type) {
mType = type;
}
Builder setContainer(@Nullable IBinder container) {
mContainer = container;
return this;
}
Builder setContainers(@Nullable IBinder[] containers) {
mContainers = containers;
return this;
}
Builder setReparentContainer(@Nullable IBinder reparentContainer) {
mReparent = reparentContainer;
return this;
}
Builder setInsetsFrameProvider(InsetsFrameProvider provider) {
mInsetsFrameProvider = provider;
return this;
}
Builder setCaller(@Nullable IBinder caller) {
mCaller = caller;
return this;
}
Builder setToTop(boolean toTop) {
mToTop = toTop;
return this;
}
Builder setReparentTopOnly(boolean reparentTopOnly) {
mReparentTopOnly = reparentTopOnly;
return this;
}
Builder setWindowingModes(@Nullable int[] windowingModes) {
mWindowingModes = windowingModes;
return this;
}
Builder setActivityTypes(@Nullable int[] activityTypes) {
mActivityTypes = activityTypes;
return this;
}
Builder setLaunchOptions(@Nullable Bundle launchOptions) {
mLaunchOptions = launchOptions;
return this;
}
Builder setAppCompatOptions(@Nullable Bundle appCompatOptions) {
mAppCompatOptions = appCompatOptions;
return this;
}
Builder setActivityIntent(@Nullable Intent activityIntent) {
mActivityIntent = activityIntent;
return this;
}
Builder setPendingIntent(@Nullable PendingIntent sender) {
mPendingIntent = sender;
return this;
}
Builder setAlwaysOnTop(boolean alwaysOnTop) {
mAlwaysOnTop = alwaysOnTop;
return this;
}
Builder setTaskFragmentOperation(
@Nullable TaskFragmentOperation taskFragmentOperation) {
mTaskFragmentOperation = taskFragmentOperation;
return this;
}
Builder setKeyguardState(
@Nullable KeyguardState keyguardState) {
mKeyguardState = keyguardState;
return this;
}
Builder setReparentLeafTaskIfRelaunch(boolean reparentLeafTaskIfRelaunch) {
mReparentLeafTaskIfRelaunch = reparentLeafTaskIfRelaunch;
return this;
}
Builder setShortcutInfo(@Nullable ShortcutInfo shortcutInfo) {
mShortcutInfo = shortcutInfo;
return this;
}
Builder setBounds(@NonNull Rect bounds) {
mBounds = bounds;
return this;
}
Builder setIncludingParents(boolean value) {
mIncludingParents = value;
return this;
}
Builder setIsTrimmableFromRecents(boolean isTrimmableFromRecents) {
mIsTrimmableFromRecents = isTrimmableFromRecents;
return this;
}
Builder setExcludeInsetsTypes(@InsetsType int excludeInsetsTypes) {
mExcludeInsetsTypes = excludeInsetsTypes;
return this;
}
Builder setSystemBarVisibilityOverride(
@InsetsType int forciblyShowingInsetsTypes,
@InsetsType int forciblyHidingInsetsTypes) {
mForciblyShowingInsetsTypes = forciblyShowingInsetsTypes;
mForciblyHidingInsetsTypes = forciblyHidingInsetsTypes;
return this;
}
Builder setSafeRegionBounds(Rect safeRegionBounds) {
mSafeRegionBounds = safeRegionBounds;
return this;
}
@NonNull
HierarchyOp build() {
final HierarchyOp hierarchyOp = new HierarchyOp(mType);
hierarchyOp.mContainer = mContainer;
hierarchyOp.mContainers = mContainers;
hierarchyOp.mReparent = mReparent;
hierarchyOp.mWindowingModes = mWindowingModes != null
? Arrays.copyOf(mWindowingModes, mWindowingModes.length)
: null;
hierarchyOp.mActivityTypes = mActivityTypes != null
? Arrays.copyOf(mActivityTypes, mActivityTypes.length)
: null;
hierarchyOp.mInsetsFrameProvider = mInsetsFrameProvider;
hierarchyOp.mCaller = mCaller;
hierarchyOp.mToTop = mToTop;
hierarchyOp.mReparentTopOnly = mReparentTopOnly;
hierarchyOp.mLaunchOptions = mLaunchOptions;
hierarchyOp.mAppCompatOptions = mAppCompatOptions;
hierarchyOp.mActivityIntent = mActivityIntent;
hierarchyOp.mPendingIntent = mPendingIntent;
hierarchyOp.mAlwaysOnTop = mAlwaysOnTop;
hierarchyOp.mTaskFragmentOperation = mTaskFragmentOperation;
hierarchyOp.mKeyguardState = mKeyguardState;
hierarchyOp.mShortcutInfo = mShortcutInfo;
hierarchyOp.mBounds = mBounds;
hierarchyOp.mIncludingParents = mIncludingParents;
hierarchyOp.mReparentLeafTaskIfRelaunch = mReparentLeafTaskIfRelaunch;
hierarchyOp.mIsTrimmableFromRecents = mIsTrimmableFromRecents;
hierarchyOp.mExcludeInsetsTypes = mExcludeInsetsTypes;
hierarchyOp.mForciblyShowingInsetsTypes = mForciblyShowingInsetsTypes;
hierarchyOp.mForciblyHidingInsetsTypes = mForciblyHidingInsetsTypes;
hierarchyOp.mSafeRegionBounds = mSafeRegionBounds;
return hierarchyOp;
}
}
}
/**
* Helper class for building an options Bundle that can be used to set adjacent rules of
* TaskFragments.
*/
public static class TaskFragmentAdjacentParams {
private static final String DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL =
"android:transaction.adjacent.option.delay_primary_removal";
private static final String DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL =
"android:transaction.adjacent.option.delay_secondary_removal";
private boolean mDelayPrimaryLastActivityRemoval;
private boolean mDelaySecondaryLastActivityRemoval;
public TaskFragmentAdjacentParams() {
}
public TaskFragmentAdjacentParams(@NonNull Bundle bundle) {
mDelayPrimaryLastActivityRemoval = bundle.getBoolean(
DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL);
mDelaySecondaryLastActivityRemoval = bundle.getBoolean(
DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL);
}
/** @see #shouldDelayPrimaryLastActivityRemoval() */
public void setShouldDelayPrimaryLastActivityRemoval(boolean delay) {
mDelayPrimaryLastActivityRemoval = delay;
}
/** @see #shouldDelaySecondaryLastActivityRemoval() */
public void setShouldDelaySecondaryLastActivityRemoval(boolean delay) {
mDelaySecondaryLastActivityRemoval = delay;
}
/**
* Whether to delay the last activity of the primary adjacent TaskFragment being immediately
* removed while finishing.
* <p>
* It is usually set to {@code true} to give organizer an opportunity to perform other
* actions or animations. An example is to finish together with the adjacent TaskFragment.
* </p>
*/
public boolean shouldDelayPrimaryLastActivityRemoval() {
return mDelayPrimaryLastActivityRemoval;
}
/**
* Similar to {@link #shouldDelayPrimaryLastActivityRemoval()}, but for the secondary
* TaskFragment.
*/
public boolean shouldDelaySecondaryLastActivityRemoval() {
return mDelaySecondaryLastActivityRemoval;
}
@NonNull
Bundle toBundle() {
final Bundle b = new Bundle();
b.putBoolean(DELAY_PRIMARY_LAST_ACTIVITY_REMOVAL, mDelayPrimaryLastActivityRemoval);
b.putBoolean(DELAY_SECONDARY_LAST_ACTIVITY_REMOVAL, mDelaySecondaryLastActivityRemoval);
return b;
}
}
}
|