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
|
/*
* 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 android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.app.PendingIntent;
import android.app.WindowConfiguration;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ShortcutInfo;
import android.content.res.Configuration;
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.view.InsetsState;
import android.view.SurfaceControl;
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(Parcel in) {
in.readMap(mChanges, null /* loader */);
in.readTypedList(mHierarchyOps, HierarchyOp.CREATOR);
mErrorCallbackToken = in.readStrongBinder();
mTaskFragmentOrganizer = ITaskFragmentOrganizer.Stub.asInterface(in.readStrongBinder());
}
private Change getOrCreateChange(IBinder token) {
Change out = mChanges.get(token);
if (out == null) {
out = new Change();
mChanges.put(token, out);
}
return out;
}
/**
* Resize a container.
*/
@NonNull
public WindowContainerTransaction setBounds(
@NonNull WindowContainerToken container,@NonNull Rect bounds) {
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) {
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) {
Change chg = getOrCreateChange(container.asBinder());
chg.mConfiguration.screenWidthDp = w;
chg.mConfiguration.screenHeightDp = h;
chg.mConfigSetMask |= ActivityInfo.CONFIG_SCREEN_SIZE;
return this;
}
/**
* 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) {
Change chg = getOrCreateChange(container.asBinder());
chg.mPinnedBounds = new Rect(bounds);
chg.mChangeMask |= Change.CHANGE_PIP_CALLBACK;
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) {
Change chg = getOrCreateChange(container.asBinder());
chg.mBoundsChangeTransaction = t;
chg.mChangeMask |= Change.CHANGE_BOUNDS_TRANSACTION;
return this;
}
/**
* Like {@link #setBoundsChangeTransaction} but instead queues up a setPosition/WindowCrop
* on a container's surface control. This is useful when a boundsChangeTransaction needs to be
* queued up on a Task that won't be organized until the end of this window-container
* transaction.
*
* This requires that, at the end of this transaction, `task` will be organized; otherwise
* the server will throw an IllegalArgumentException.
*
* WARNING: Use this carefully. Whatever is set here should match the expected bounds after
* the transaction completes since it will likely be replaced by it. This call is
* intended to pre-emptively set bounds on a surface in sync with a buffer when
* otherwise the new bounds and the new buffer would update on different frames.
*
* TODO(b/134365562): remove once TaskOrg drives full-screen or BLAST is enabled.
*
* @hide
*/
@NonNull
public WindowContainerTransaction setBoundsChangeTransaction(
@NonNull WindowContainerToken task, @NonNull Rect surfaceBounds) {
Change chg = getOrCreateChange(task.asBinder());
if (chg.mBoundsChangeSurfaceBounds == null) {
chg.mBoundsChangeSurfaceBounds = new Rect();
}
chg.mBoundsChangeSurfaceBounds.set(surfaceBounds);
chg.mChangeMask |= Change.CHANGE_BOUNDS_TRANSACTION_RECT;
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, int windowingMode) {
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, int windowingMode) {
Change chg = getOrCreateChange(container.asBinder());
chg.mWindowingMode = windowingMode;
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) {
Change chg = getOrCreateChange(container.asBinder());
chg.mFocusable = focusable;
chg.mChangeMask |= Change.CHANGE_FOCUSABLE;
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) {
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) {
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) {
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) {
Change chg = getOrCreateChange(container.asBinder());
chg.mForceTranslucent = forceTranslucent;
chg.mChangeMask |= Change.CHANGE_FORCE_TRANSLUCENT;
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) {
Change chg = getOrCreateChange(container.asBinder());
chg.mChangeMask |= Change.CHANGE_FORCE_NO_PIP;
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;
}
/**
* 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) {
mHierarchyOps.add(HierarchyOp.createForReorder(child.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 */);
}
/**
* 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;
}
/**
* Sets to 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.
*/
@NonNull
public WindowContainerTransaction setAdjacentRoots(
@NonNull WindowContainerToken root1, @NonNull WindowContainerToken root2) {
mHierarchyOps.add(HierarchyOp.createForAdjacentRoots(
root1.asBinder(),
root2.asBinder()));
return this;
}
/**
* This is temp function for compatible with old cts tests suite and it equal to
* {@link #setAdjacentRoots(WindowContainerToken, WindowContainerToken).
* @deprecated should use {@link #setAdjacentRoots(WindowContainerToken, WindowContainerToken)}
*/
@Deprecated
@NonNull
public WindowContainerTransaction setAdjacentRoots(
@NonNull WindowContainerToken root1, @NonNull WindowContainerToken root2,
boolean moveTogether) {
return setAdjacentRoots(root1, root2);
}
/**
* Sets the container as launch adjacent flag root. Task starting with
* {@link 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;
}
/**
* 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) {
mHierarchyOps.add(HierarchyOp.createForTaskLaunch(taskId, options));
return this;
}
/**
* Finds and removes a task and its children using its container token. The task is removed
* from recents.
* @param containerToken ContainerToken of Task to be removed
*/
@NonNull
public WindowContainerTransaction removeTask(@NonNull WindowContainerToken containerToken) {
mHierarchyOps.add(HierarchyOp.createForRemoveTask(containerToken.asBinder()));
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;
}
/**
* Sends a pending intent in sync.
* @param sender The PendingIntent sender.
* @param intent 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(PendingIntent sender, Intent intent,
@Nullable Bundle options) {
mHierarchyOps.add(new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_PENDING_INTENT)
.setLaunchOptions(options)
.setPendingIntent(sender)
.setActivityIntent(intent)
.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) {
mHierarchyOps.add(HierarchyOp.createForStartShortcut(
callingPackage, shortcutInfo, options));
return this;
}
/**
* Creates a new TaskFragment with the given options.
* @param taskFragmentOptions the options used to create the TaskFragment.
*/
@NonNull
public WindowContainerTransaction createTaskFragment(
@NonNull TaskFragmentCreationParams taskFragmentOptions) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_CREATE_TASK_FRAGMENT)
.setTaskFragmentCreationOptions(taskFragmentOptions)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Deletes an existing TaskFragment. Any remaining activities below it will be destroyed.
* @param taskFragment the TaskFragment to be removed.
*/
@NonNull
public WindowContainerTransaction deleteTaskFragment(
@NonNull WindowContainerToken taskFragment) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_DELETE_TASK_FRAGMENT)
.setContainer(taskFragment.asBinder())
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* 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 HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT)
.setContainer(fragmentToken)
.setReparentContainer(callerToken)
.setActivityIntent(activityIntent)
.setLaunchOptions(activityOptions)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* 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 HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT)
.setReparentContainer(fragmentToken)
.setContainer(activityToken)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Reparents all children of one TaskFragment to another.
* @param oldParent children of this TaskFragment will be reparented.
* @param newParent the new parent TaskFragment to move the children to. If {@code null}, the
* children will be moved to the leaf Task.
*/
@NonNull
public WindowContainerTransaction reparentChildren(
@NonNull WindowContainerToken oldParent,
@Nullable WindowContainerToken newParent) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_REPARENT_CHILDREN)
.setContainer(oldParent.asBinder())
.setReparentContainer(newParent != null ? newParent.asBinder() : null)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Sets to TaskFragments adjacent to each other. Containers below two visible adjacent
* TaskFragments will be made invisible. This is similar to
* {@link #setAdjacentRoots(WindowContainerToken, WindowContainerToken)}, but can be used with
* fragmentTokens when that TaskFragments haven't been created (but will be created in the same
* {@link WindowContainerTransaction}).
* To reset it, pass {@code null} for {@code fragmentToken2}.
* @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()}. If it is
* {@code null}, the transaction will reset the adjacent TaskFragment.
*/
@NonNull
public WindowContainerTransaction setAdjacentTaskFragments(
@NonNull IBinder fragmentToken1, @Nullable IBinder fragmentToken2,
@Nullable TaskFragmentAdjacentParams params) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS)
.setContainer(fragmentToken1)
.setReparentContainer(fragmentToken2)
.setLaunchOptions(params != null ? params.toBundle() : null)
.build();
mHierarchyOps.add(hierarchyOp);
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;
}
/**
* Adds a given {@code Rect} as a rect insets provider on the {@code receiverWindowContainer}.
* This will trigger a change of insets for all the children in the subtree of
* {@code receiverWindowContainer}.
*
* @param receiverWindowContainer the window container which the insets provider need to be
* added to
* @param insetsProviderFrame the frame that will be added as Insets provider
* @param insetsTypes types of insets the rect provides
* @hide
*/
@NonNull
public WindowContainerTransaction addRectInsetsProvider(
@NonNull WindowContainerToken receiverWindowContainer,
@NonNull Rect insetsProviderFrame,
@InsetsState.InternalInsetsType int[] insetsTypes) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER)
.setContainer(receiverWindowContainer.asBinder())
.setInsetsProviderFrame(insetsProviderFrame)
.setInsetsTypes(insetsTypes)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Removes the insets provider for the given types from the
* {@code receiverWindowContainer}. This will trigger a change of insets for all the children
* in the subtree of {@code receiverWindowContainer}.
*
* @param receiverWindowContainer the window container which the insets-override-provider has
* to be removed from
* @param insetsTypes types of insets that have to be removed
* @hide
*/
@NonNull
public WindowContainerTransaction removeInsetsProvider(
@NonNull WindowContainerToken receiverWindowContainer,
@InsetsState.InternalInsetsType int[] insetsTypes) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER)
.setContainer(receiverWindowContainer.asBinder())
.setInsetsTypes(insetsTypes)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* 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 HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT)
.setContainer(fragmentToken)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* 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 container} to have a companion TaskFragment {@code companion}.
* This indicates that the organizer will remove the TaskFragment when the companion
* TaskFragment is removed.
*
* @param container the TaskFragment container
* @param companion the companion TaskFragment. If it is {@code null}, the transaction will
* reset the companion TaskFragment.
* @hide
*/
@NonNull
public WindowContainerTransaction setCompanionTaskFragment(@NonNull IBinder container,
@Nullable IBinder companion) {
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_SET_COMPANION_TASK_FRAGMENT)
.setContainer(container)
.setReparentContainer(companion)
.build();
mHierarchyOps.add(hierarchyOp);
return this;
}
/**
* Sets the {@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
* TaskFramgent.
* @hide
*/
@NonNull
public WindowContainerTransaction setTaskFragmentOperation(@NonNull IBinder fragmentToken,
@NonNull TaskFragmentOperation taskFragmentOperation) {
Objects.requireNonNull(fragmentToken);
Objects.requireNonNull(taskFragmentOperation);
final HierarchyOp hierarchyOp =
new HierarchyOp.Builder(
HierarchyOp.HIERARCHY_OP_TYPE_SET_TASK_FRAGMENT_OPERATION)
.setContainer(fragmentToken)
.setTaskFragmentOperation(taskFragmentOperation)
.build();
mHierarchyOps.add(hierarchyOp);
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.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;
}
/**
* 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 ITaskFragmentOrganizer#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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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(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) {
mHierarchyOps.add(transfer ? other.mHierarchyOps.get(i)
: new HierarchyOp(other.mHierarchyOps.get(i)));
}
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 */
public Map<IBinder, Change> getChanges() {
return mChanges;
}
/** @hide */
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<WindowContainerTransaction>() {
@Override
public WindowContainerTransaction createFromParcel(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_BOUNDS_TRANSACTION_RECT = 1 << 4;
public static final int CHANGE_IGNORE_ORIENTATION_REQUEST = 1 << 5;
public static final int CHANGE_FORCE_NO_PIP = 1 << 6;
public static final int CHANGE_FORCE_TRANSLUCENT = 1 << 7;
public static final int CHANGE_DRAG_RESIZING = 1 << 8;
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 int mChangeMask = 0;
private @ActivityInfo.Config int mConfigSetMask = 0;
private @WindowConfiguration.WindowConfig int mWindowSetMask = 0;
private Rect mPinnedBounds = null;
private SurfaceControl.Transaction mBoundsChangeTransaction = null;
private Rect mBoundsChangeSurfaceBounds = null;
private int mActivityWindowingMode = -1;
private int mWindowingMode = -1;
public Change() {}
protected Change(Parcel in) {
mConfiguration.readFromParcel(in);
mFocusable = in.readBoolean();
mHidden = in.readBoolean();
mIgnoreOrientationRequest = in.readBoolean();
mForceTranslucent = in.readBoolean();
mDragResizing = in.readBoolean();
mChangeMask = in.readInt();
mConfigSetMask = in.readInt();
mWindowSetMask = in.readInt();
if ((mChangeMask & Change.CHANGE_PIP_CALLBACK) != 0) {
mPinnedBounds = new Rect();
mPinnedBounds.readFromParcel(in);
}
if ((mChangeMask & Change.CHANGE_BOUNDS_TRANSACTION) != 0) {
mBoundsChangeTransaction =
SurfaceControl.Transaction.CREATOR.createFromParcel(in);
}
if ((mChangeMask & Change.CHANGE_BOUNDS_TRANSACTION_RECT) != 0) {
mBoundsChangeSurfaceBounds = new Rect();
mBoundsChangeSurfaceBounds.readFromParcel(in);
}
mWindowingMode = in.readInt();
mActivityWindowingMode = 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(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_PIP_CALLBACK) != 0) {
mPinnedBounds = transfer ? other.mPinnedBounds : new Rect(other.mPinnedBounds);
}
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;
}
mChangeMask |= other.mChangeMask;
if (other.mActivityWindowingMode >= 0) {
mActivityWindowingMode = other.mActivityWindowingMode;
}
if (other.mWindowingMode >= 0) {
mWindowingMode = other.mWindowingMode;
}
if (other.mBoundsChangeSurfaceBounds != null) {
mBoundsChangeSurfaceBounds = transfer ? other.mBoundsChangeSurfaceBounds
: new Rect(other.mBoundsChangeSurfaceBounds);
}
}
public int getWindowingMode() {
return mWindowingMode;
}
public int getActivityWindowingMode() {
return mActivityWindowingMode;
}
public Configuration getConfiguration() {
return mConfiguration;
}
/** 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;
}
public int getChangeMask() {
return mChangeMask;
}
@ActivityInfo.Config
public int getConfigSetMask() {
return mConfigSetMask;
}
@WindowConfiguration.WindowConfig
public int getWindowSetMask() {
return mWindowSetMask;
}
/**
* Returns the bounds to be used for scheduling the enter pip callback
* or null if no callback is to be scheduled.
*/
public Rect getEnterPipBounds() {
return mPinnedBounds;
}
public SurfaceControl.Transaction getBoundsChangeTransaction() {
return mBoundsChangeTransaction;
}
public Rect getBoundsChangeSurfaceBounds() {
return mBoundsChangeSurfaceBounds;
}
@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;
StringBuilder sb = new StringBuilder();
sb.append('{');
if (changesBounds) {
sb.append("bounds:" + mConfiguration.windowConfiguration.getBounds() + ",");
}
if (changesAppBounds) {
sb.append("appbounds:" + mConfiguration.windowConfiguration.getAppBounds() + ",");
}
if (changesSss) {
sb.append("ssw:" + mConfiguration.smallestScreenWidthDp + ",");
}
if (changesSs) {
sb.append("sw/h:" + mConfiguration.screenWidthDp + "x"
+ mConfiguration.screenHeightDp + ",");
}
if ((mChangeMask & CHANGE_FOCUSABLE) != 0) {
sb.append("focusable:" + mFocusable + ",");
}
if ((mChangeMask & CHANGE_DRAG_RESIZING) != 0) {
sb.append("dragResizing:" + mDragResizing + ",");
}
if (mBoundsChangeTransaction != null) {
sb.append("hasBoundsTransaction,");
}
if ((mChangeMask & CHANGE_IGNORE_ORIENTATION_REQUEST) != 0) {
sb.append("ignoreOrientationRequest:" + mIgnoreOrientationRequest + ",");
}
sb.append("}");
return sb.toString();
}
@Override
public void writeToParcel(Parcel dest, int flags) {
mConfiguration.writeToParcel(dest, flags);
dest.writeBoolean(mFocusable);
dest.writeBoolean(mHidden);
dest.writeBoolean(mIgnoreOrientationRequest);
dest.writeBoolean(mForceTranslucent);
dest.writeBoolean(mDragResizing);
dest.writeInt(mChangeMask);
dest.writeInt(mConfigSetMask);
dest.writeInt(mWindowSetMask);
if (mPinnedBounds != null) {
mPinnedBounds.writeToParcel(dest, flags);
}
if (mBoundsChangeTransaction != null) {
mBoundsChangeTransaction.writeToParcel(dest, flags);
}
if (mBoundsChangeSurfaceBounds != null) {
mBoundsChangeSurfaceBounds.writeToParcel(dest, flags);
}
dest.writeInt(mWindowingMode);
dest.writeInt(mActivityWindowingMode);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<Change> CREATOR = new Creator<Change>() {
@Override
public Change createFromParcel(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.
* @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_CREATE_TASK_FRAGMENT = 7;
public static final int HIERARCHY_OP_TYPE_DELETE_TASK_FRAGMENT = 8;
public static final int HIERARCHY_OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT = 9;
public static final int HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT = 10;
public static final int HIERARCHY_OP_TYPE_REPARENT_CHILDREN = 11;
public static final int HIERARCHY_OP_TYPE_PENDING_INTENT = 12;
public static final int HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS = 13;
public static final int HIERARCHY_OP_TYPE_START_SHORTCUT = 14;
public static final int HIERARCHY_OP_TYPE_RESTORE_TRANSIENT_ORDER = 15;
public static final int HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER = 16;
public static final int HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER = 17;
public static final int HIERARCHY_OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT = 18;
public static final int HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP = 19;
public static final int HIERARCHY_OP_TYPE_REMOVE_TASK = 20;
public static final int HIERARCHY_OP_TYPE_FINISH_ACTIVITY = 21;
public static final int HIERARCHY_OP_TYPE_SET_COMPANION_TASK_FRAGMENT = 22;
public static final int HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH = 23;
public static final int HIERARCHY_OP_TYPE_SET_TASK_FRAGMENT_OPERATION = 24;
// 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";
private final int mType;
// Container we are performing the operation on.
@Nullable
private IBinder mContainer;
// If this is same as mContainer, then only change position, don't reparent.
@Nullable
private IBinder mReparent;
private @InsetsState.InternalInsetsType int[] mInsetsTypes;
private Rect mInsetsProviderFrame;
// 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 Intent mActivityIntent;
/** Used as options for {@link #createTaskFragment}. */
@Nullable
private TaskFragmentCreationParams mTaskFragmentCreationOptions;
/** Used as options for {@link #setTaskFragmentOperation}. */
@Nullable
private TaskFragmentOperation mTaskFragmentOperation;
@Nullable
private PendingIntent mPendingIntent;
@Nullable
private ShortcutInfo mShortcutInfo;
private boolean mAlwaysOnTop;
private boolean mReparentLeafTaskIfRelaunch;
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();
}
public static HierarchyOp createForReorder(@NonNull IBinder container, boolean toTop) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_REORDER)
.setContainer(container)
.setReparentContainer(container)
.setToTop(toTop)
.build();
}
public static HierarchyOp createForChildrenTasksReparent(IBinder currentParent,
IBinder newParent, int[] windowingModes, 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();
}
public static HierarchyOp createForSetLaunchRoot(IBinder container,
int[] windowingModes, int[] activityTypes) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT)
.setContainer(container)
.setWindowingModes(windowingModes)
.setActivityTypes(activityTypes)
.build();
}
/** Create a hierarchy op for setting adjacent root tasks. */
public static HierarchyOp createForAdjacentRoots(IBinder root1, IBinder root2) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS)
.setContainer(root1)
.setReparentContainer(root2)
.build();
}
/** Create a hierarchy op for launching a task. */
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();
}
/** Create a hierarchy op for starting a shortcut. */
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();
}
/** Create a hierarchy op for setting launch adjacent flag root. */
public static HierarchyOp createForSetLaunchAdjacentFlagRoot(IBinder container,
boolean clearRoot) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT)
.setContainer(container)
.setToTop(clearRoot)
.build();
}
/** create a hierarchy op for deleting a task **/
public static HierarchyOp createForRemoveTask(@NonNull IBinder container) {
return new HierarchyOp.Builder(HIERARCHY_OP_TYPE_REMOVE_TASK)
.setContainer(container)
.build();
}
/** Only creates through {@link Builder}. */
private HierarchyOp(int type) {
mType = type;
}
public HierarchyOp(@NonNull HierarchyOp copy) {
mType = copy.mType;
mContainer = copy.mContainer;
mReparent = copy.mReparent;
mInsetsTypes = copy.mInsetsTypes;
mInsetsProviderFrame = copy.mInsetsProviderFrame;
mToTop = copy.mToTop;
mReparentTopOnly = copy.mReparentTopOnly;
mWindowingModes = copy.mWindowingModes;
mActivityTypes = copy.mActivityTypes;
mLaunchOptions = copy.mLaunchOptions;
mActivityIntent = copy.mActivityIntent;
mTaskFragmentCreationOptions = copy.mTaskFragmentCreationOptions;
mTaskFragmentOperation = copy.mTaskFragmentOperation;
mPendingIntent = copy.mPendingIntent;
mShortcutInfo = copy.mShortcutInfo;
mAlwaysOnTop = copy.mAlwaysOnTop;
mReparentLeafTaskIfRelaunch = copy.mReparentLeafTaskIfRelaunch;
}
protected HierarchyOp(Parcel in) {
mType = in.readInt();
mContainer = in.readStrongBinder();
mReparent = in.readStrongBinder();
mInsetsTypes = in.createIntArray();
if (in.readInt() != 0) {
mInsetsProviderFrame = Rect.CREATOR.createFromParcel(in);
} else {
mInsetsProviderFrame = null;
}
mToTop = in.readBoolean();
mReparentTopOnly = in.readBoolean();
mWindowingModes = in.createIntArray();
mActivityTypes = in.createIntArray();
mLaunchOptions = in.readBundle();
mActivityIntent = in.readTypedObject(Intent.CREATOR);
mTaskFragmentCreationOptions = in.readTypedObject(TaskFragmentCreationParams.CREATOR);
mTaskFragmentOperation = in.readTypedObject(TaskFragmentOperation.CREATOR);
mPendingIntent = in.readTypedObject(PendingIntent.CREATOR);
mShortcutInfo = in.readTypedObject(ShortcutInfo.CREATOR);
mAlwaysOnTop = in.readBoolean();
mReparentLeafTaskIfRelaunch = in.readBoolean();
}
public int getType() {
return mType;
}
public boolean isReparent() {
return mType == HIERARCHY_OP_TYPE_REPARENT;
}
@Nullable
public IBinder getNewParent() {
return mReparent;
}
@Nullable
public @InsetsState.InternalInsetsType int[] getInsetsTypes() {
return mInsetsTypes;
}
public Rect getInsetsProviderFrame() {
return mInsetsProviderFrame;
}
@NonNull
public IBinder getContainer() {
return mContainer;
}
@NonNull
public IBinder getAdjacentRoot() {
return mReparent;
}
@NonNull
public IBinder getCompanionContainer() {
return mReparent;
}
@NonNull
public IBinder getCallingActivity() {
return mReparent;
}
public boolean getToTop() {
return mToTop;
}
public boolean getReparentTopOnly() {
return mReparentTopOnly;
}
public int[] getWindowingModes() {
return mWindowingModes;
}
public int[] getActivityTypes() {
return mActivityTypes;
}
@Nullable
public Bundle getLaunchOptions() {
return mLaunchOptions;
}
@Nullable
public Intent getActivityIntent() {
return mActivityIntent;
}
public boolean isAlwaysOnTop() {
return mAlwaysOnTop;
}
public boolean isReparentLeafTaskIfRelaunch() {
return mReparentLeafTaskIfRelaunch;
}
@Nullable
public TaskFragmentCreationParams getTaskFragmentCreationOptions() {
return mTaskFragmentCreationOptions;
}
@Nullable
public TaskFragmentOperation getTaskFragmentOperation() {
return mTaskFragmentOperation;
}
@Nullable
public PendingIntent getPendingIntent() {
return mPendingIntent;
}
@Nullable
public ShortcutInfo getShortcutInfo() {
return mShortcutInfo;
}
@Override
public String toString() {
switch (mType) {
case HIERARCHY_OP_TYPE_CHILDREN_TASKS_REPARENT:
return "{ChildrenTasksReparent: from=" + mContainer + " to=" + mReparent
+ " mToTop=" + mToTop + " mReparentTopOnly=" + mReparentTopOnly
+ " mWindowingMode=" + Arrays.toString(mWindowingModes)
+ " mActivityType=" + Arrays.toString(mActivityTypes) + "}";
case HIERARCHY_OP_TYPE_SET_LAUNCH_ROOT:
return "{SetLaunchRoot: container=" + mContainer
+ " mWindowingMode=" + Arrays.toString(mWindowingModes)
+ " mActivityType=" + Arrays.toString(mActivityTypes) + "}";
case HIERARCHY_OP_TYPE_REPARENT:
return "{reparent: " + mContainer + " to " + (mToTop ? "top of " : "bottom of ")
+ mReparent + "}";
case HIERARCHY_OP_TYPE_REORDER:
return "{reorder: " + mContainer + " to " + (mToTop ? "top" : "bottom") + "}";
case HIERARCHY_OP_TYPE_SET_ADJACENT_ROOTS:
return "{SetAdjacentRoot: container=" + mContainer
+ " adjacentRoot=" + mReparent + "}";
case HIERARCHY_OP_TYPE_LAUNCH_TASK:
return "{LaunchTask: " + mLaunchOptions + "}";
case HIERARCHY_OP_TYPE_SET_LAUNCH_ADJACENT_FLAG_ROOT:
return "{SetAdjacentFlagRoot: container=" + mContainer + " clearRoot=" + mToTop
+ "}";
case HIERARCHY_OP_TYPE_CREATE_TASK_FRAGMENT:
return "{CreateTaskFragment: options=" + mTaskFragmentCreationOptions + "}";
case HIERARCHY_OP_TYPE_DELETE_TASK_FRAGMENT:
return "{DeleteTaskFragment: taskFragment=" + mContainer + "}";
case HIERARCHY_OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT:
return "{StartActivityInTaskFragment: fragmentToken=" + mContainer + " intent="
+ mActivityIntent + " options=" + mLaunchOptions + "}";
case HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT:
return "{ReparentActivityToTaskFragment: fragmentToken=" + mReparent
+ " activity=" + mContainer + "}";
case HIERARCHY_OP_TYPE_REPARENT_CHILDREN:
return "{ReparentChildren: oldParent=" + mContainer + " newParent=" + mReparent
+ "}";
case HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS:
return "{SetAdjacentTaskFragments: container=" + mContainer
+ " adjacentContainer=" + mReparent + "}";
case HIERARCHY_OP_TYPE_START_SHORTCUT:
return "{StartShortcut: options=" + mLaunchOptions + " info=" + mShortcutInfo
+ "}";
case HIERARCHY_OP_TYPE_ADD_RECT_INSETS_PROVIDER:
return "{addRectInsetsProvider: container=" + mContainer
+ " insetsProvidingFrame=" + mInsetsProviderFrame
+ " insetsType=" + Arrays.toString(mInsetsTypes) + "}";
case HIERARCHY_OP_TYPE_REMOVE_INSETS_PROVIDER:
return "{removeLocalInsetsProvider: container=" + mContainer
+ " insetsType=" + Arrays.toString(mInsetsTypes) + "}";
case HIERARCHY_OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT:
return "{requestFocusOnTaskFragment: container=" + mContainer + "}";
case HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP:
return "{setAlwaysOnTop: container=" + mContainer
+ " alwaysOnTop=" + mAlwaysOnTop + "}";
case HIERARCHY_OP_TYPE_REMOVE_TASK:
return "{RemoveTask: task=" + mContainer + "}";
case HIERARCHY_OP_TYPE_FINISH_ACTIVITY:
return "{finishActivity: activity=" + mContainer + "}";
case HIERARCHY_OP_TYPE_SET_COMPANION_TASK_FRAGMENT:
return "{setCompanionTaskFragment: container = " + mContainer + " companion = "
+ mReparent + "}";
case HIERARCHY_OP_TYPE_SET_REPARENT_LEAF_TASK_IF_RELAUNCH:
return "{setReparentLeafTaskIfRelaunch: container= " + mContainer
+ " reparentLeafTaskIfRelaunch= " + mReparentLeafTaskIfRelaunch + "}";
case HIERARCHY_OP_TYPE_SET_TASK_FRAGMENT_OPERATION:
return "{setTaskFragmentOperation: fragmentToken= " + mContainer
+ " operation= " + mTaskFragmentOperation + "}";
default:
return "{mType=" + mType + " container=" + mContainer + " reparent=" + mReparent
+ " mToTop=" + mToTop
+ " mWindowingMode=" + Arrays.toString(mWindowingModes)
+ " mActivityType=" + Arrays.toString(mActivityTypes) + "}";
}
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(mType);
dest.writeStrongBinder(mContainer);
dest.writeStrongBinder(mReparent);
dest.writeIntArray(mInsetsTypes);
if (mInsetsProviderFrame != null) {
dest.writeInt(1);
mInsetsProviderFrame.writeToParcel(dest, 0);
} else {
dest.writeInt(0);
}
dest.writeBoolean(mToTop);
dest.writeBoolean(mReparentTopOnly);
dest.writeIntArray(mWindowingModes);
dest.writeIntArray(mActivityTypes);
dest.writeBundle(mLaunchOptions);
dest.writeTypedObject(mActivityIntent, flags);
dest.writeTypedObject(mTaskFragmentCreationOptions, flags);
dest.writeTypedObject(mTaskFragmentOperation, flags);
dest.writeTypedObject(mPendingIntent, flags);
dest.writeTypedObject(mShortcutInfo, flags);
dest.writeBoolean(mAlwaysOnTop);
dest.writeBoolean(mReparentLeafTaskIfRelaunch);
}
@Override
public int describeContents() {
return 0;
}
public static final Creator<HierarchyOp> CREATOR = new Creator<HierarchyOp>() {
@Override
public HierarchyOp createFromParcel(Parcel in) {
return new HierarchyOp(in);
}
@Override
public HierarchyOp[] newArray(int size) {
return new HierarchyOp[size];
}
};
private static class Builder {
private final int mType;
@Nullable
private IBinder mContainer;
@Nullable
private IBinder mReparent;
private int[] mInsetsTypes;
private Rect mInsetsProviderFrame;
private boolean mToTop;
private boolean mReparentTopOnly;
@Nullable
private int[] mWindowingModes;
@Nullable
private int[] mActivityTypes;
@Nullable
private Bundle mLaunchOptions;
@Nullable
private Intent mActivityIntent;
@Nullable
private TaskFragmentCreationParams mTaskFragmentCreationOptions;
@Nullable
private TaskFragmentOperation mTaskFragmentOperation;
@Nullable
private PendingIntent mPendingIntent;
@Nullable
private ShortcutInfo mShortcutInfo;
private boolean mAlwaysOnTop;
private boolean mReparentLeafTaskIfRelaunch;
Builder(int type) {
mType = type;
}
Builder setContainer(@Nullable IBinder container) {
mContainer = container;
return this;
}
Builder setReparentContainer(@Nullable IBinder reparentContainer) {
mReparent = reparentContainer;
return this;
}
Builder setInsetsTypes(int[] insetsTypes) {
mInsetsTypes = insetsTypes;
return this;
}
Builder setInsetsProviderFrame(Rect insetsProviderFrame) {
mInsetsProviderFrame = insetsProviderFrame;
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 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 setTaskFragmentCreationOptions(
@Nullable TaskFragmentCreationParams taskFragmentCreationOptions) {
mTaskFragmentCreationOptions = taskFragmentCreationOptions;
return this;
}
Builder setTaskFragmentOperation(
@Nullable TaskFragmentOperation taskFragmentOperation) {
mTaskFragmentOperation = taskFragmentOperation;
return this;
}
Builder setReparentLeafTaskIfRelaunch(boolean reparentLeafTaskIfRelaunch) {
mReparentLeafTaskIfRelaunch = reparentLeafTaskIfRelaunch;
return this;
}
Builder setShortcutInfo(@Nullable ShortcutInfo shortcutInfo) {
mShortcutInfo = shortcutInfo;
return this;
}
HierarchyOp build() {
final HierarchyOp hierarchyOp = new HierarchyOp(mType);
hierarchyOp.mContainer = mContainer;
hierarchyOp.mReparent = mReparent;
hierarchyOp.mWindowingModes = mWindowingModes != null
? Arrays.copyOf(mWindowingModes, mWindowingModes.length)
: null;
hierarchyOp.mActivityTypes = mActivityTypes != null
? Arrays.copyOf(mActivityTypes, mActivityTypes.length)
: null;
hierarchyOp.mInsetsTypes = mInsetsTypes;
hierarchyOp.mInsetsProviderFrame = mInsetsProviderFrame;
hierarchyOp.mToTop = mToTop;
hierarchyOp.mReparentTopOnly = mReparentTopOnly;
hierarchyOp.mLaunchOptions = mLaunchOptions;
hierarchyOp.mActivityIntent = mActivityIntent;
hierarchyOp.mPendingIntent = mPendingIntent;
hierarchyOp.mAlwaysOnTop = mAlwaysOnTop;
hierarchyOp.mTaskFragmentCreationOptions = mTaskFragmentCreationOptions;
hierarchyOp.mTaskFragmentOperation = mTaskFragmentOperation;
hierarchyOp.mShortcutInfo = mShortcutInfo;
hierarchyOp.mReparentLeafTaskIfRelaunch = mReparentLeafTaskIfRelaunch;
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;
}
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;
}
}
}
|