Implement launch bounds logic in Android (3/3)
This CL introduces persistence to launch bounds logic. It also wires up
the following state changes and persister:
1) freeform resizing;
2) windowing mode change;
3) display change;
4) task closing.
We may still need to persist immersive mode, but that needs further
discussion.
Changed launch bounds modifier a bit so that it won't launch tasks that
are completely out of the new display or conflict to existing tasks.
Bug: 113252871
Test: Manual tests on that freeform launch bounds are persisted across
reboots.
atest WmTests:LaunchParamsPersisterTests
atest WmTests:LaunchParamsControllerTests
atest WmTests:PersisterQueueTests
Change-Id: I20f3056735253c668c7f09c6eb5204e6a5990b1c
diff --git a/services/core/java/com/android/server/wm/PersisterQueue.java b/services/core/java/com/android/server/wm/PersisterQueue.java
index 1cfc7ac..a17ee65 100644
--- a/services/core/java/com/android/server/wm/PersisterQueue.java
+++ b/services/core/java/com/android/server/wm/PersisterQueue.java
@@ -130,6 +130,30 @@
return null;
}
+ /**
+ *
+ * @param item
+ * @param flush
+ * @param <T>
+ */
+ synchronized <T extends WriteQueueItem> void updateLastOrAddItem(T item, boolean flush) {
+ final T itemToUpdate = findLastItem(item::matches, (Class<T>) item.getClass());
+ if (itemToUpdate == null) {
+ addItem(item, flush);
+ } else {
+ itemToUpdate.updateFrom(item);
+ }
+
+ yieldIfQueueTooDeep();
+ }
+
+ /**
+ * Removes all items with which given predicate returns {@code true}.
+ *
+ * @param predicate the predicate
+ * @param clazz
+ * @param <T>
+ */
synchronized <T extends WriteQueueItem> void removeItems(Predicate<T> predicate,
Class<T> clazz) {
for (int i = mWriteQueue.size() - 1; i >= 0; --i) {
@@ -230,8 +254,14 @@
item.process();
}
- interface WriteQueueItem {
+ interface WriteQueueItem<T extends WriteQueueItem<T>> {
void process();
+
+ default void updateFrom(T item) {}
+
+ default boolean matches(T item) {
+ return false;
+ }
}
interface Listener {