Add TestApi interfaces for window organizers

Enables testing the API surfaces from CTS.

Bug: 149338177
Test: they pass!
Change-Id: I7e1f2852585a10c20d299bd87e9a87f828d06d6a
diff --git a/core/java/android/window/WindowOrganizer.java b/core/java/android/window/WindowOrganizer.java
index 5590e72..4578271 100644
--- a/core/java/android/window/WindowOrganizer.java
+++ b/core/java/android/window/WindowOrganizer.java
@@ -16,29 +16,32 @@
 
 package android.window;
 
+import android.annotation.NonNull;
 import android.annotation.RequiresPermission;
-import android.app.ActivityManager;
+import android.annotation.TestApi;
 import android.app.ActivityTaskManager;
 import android.os.RemoteException;
 import android.util.Singleton;
 
-import java.util.List;
-
 /**
- * Class for organizing specific types of windows like Tasks and DisplayAreas
+ * Base class for organizing specific types of windows like Tasks and DisplayAreas
  *
  * @hide
  */
+@TestApi
 public class WindowOrganizer {
 
     /**
      * Apply multiple WindowContainer operations at once.
      * @param t The transaction to apply.
-     * @hide
      */
     @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-    public static void applyTransaction(WindowContainerTransaction t) throws RemoteException {
-        getWindowOrganizerController().applyTransaction(t);
+    public static void applyTransaction(@NonNull WindowContainerTransaction t) {
+        try {
+            getWindowOrganizerController().applyTransaction(t);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
     }
 
     /**
@@ -49,17 +52,19 @@
      *        WindowContainer transaction will be passed to this callback when ready.
      * @return An ID for the sync operation which will later be passed to transactionReady callback.
      *         This lets the caller differentiate overlapping sync operations.
-     * @hide
      */
     @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-    public static int applySyncTransaction(WindowContainerTransaction t,
-            IWindowContainerTransactionCallback callback) throws RemoteException {
-        return getWindowOrganizerController().applySyncTransaction(t, callback);
+    public int applySyncTransaction(@NonNull WindowContainerTransaction t,
+            @NonNull WindowContainerTransactionCallback callback) {
+        try {
+            return getWindowOrganizerController().applySyncTransaction(t, callback.mInterface);
+        } catch (RemoteException e) {
+            throw e.rethrowFromSystemServer();
+        }
     }
 
-    /** @hide */
     @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-    private static IWindowOrganizerController getWindowOrganizerController() {
+    static IWindowOrganizerController getWindowOrganizerController() {
         return IWindowOrganizerControllerSingleton.get();
     }
 
@@ -74,138 +79,4 @@
                     }
                 }
             };
-
-    public static class TaskOrganizer {
-
-        /**
-         * Register a TaskOrganizer to manage tasks as they enter the given windowing mode.
-         * If there was already a TaskOrganizer for this windowing mode it will be evicted
-         * and receive taskVanished callbacks in the process.
-         */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static void registerOrganizer(ITaskOrganizer organizer, int windowingMode)
-                throws RemoteException {
-            getController().registerTaskOrganizer(organizer, windowingMode);
-        }
-
-        /** Unregisters a previously registered task organizer. */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static void unregisterOrganizer(ITaskOrganizer organizer) throws RemoteException {
-            getController().unregisterTaskOrganizer(organizer);
-        }
-
-        /** Creates a persistent root task in WM for a particular windowing-mode. */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static ActivityManager.RunningTaskInfo createRootTask(
-                int displayId, int windowingMode) throws RemoteException {
-            return getController().createRootTask(displayId, windowingMode);
-        }
-
-        /** Deletes a persistent root task in WM */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static boolean deleteRootTask(IWindowContainer task) throws RemoteException {
-            return getController().deleteRootTask(task);
-        }
-
-        /** Gets direct child tasks (ordered from top-to-bottom) */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static List<ActivityManager.RunningTaskInfo> getChildTasks(IWindowContainer parent,
-                int[] activityTypes) throws RemoteException {
-            return getController().getChildTasks(parent, activityTypes);
-        }
-
-        /** Gets all root tasks on a display (ordered from top-to-bottom) */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static List<ActivityManager.RunningTaskInfo> getRootTasks(
-                int displayId, int[] activityTypes) throws RemoteException {
-            return getController().getRootTasks(displayId, activityTypes);
-        }
-
-        /** Get the root task which contains the current ime target */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static IWindowContainer getImeTarget(int display) throws RemoteException {
-            return getController().getImeTarget(display);
-        }
-
-        /**
-         * Set's the root task to launch new tasks into on a display. {@code null} means no launch
-         * root and thus new tasks just end up directly on the display.
-         */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static void setLaunchRoot(int displayId, IWindowContainer root)
-                throws RemoteException {
-            getController().setLaunchRoot(displayId, root);
-        }
-
-        /**
-         * Requests that the given task organizer is notified when back is pressed on the root
-         * activity of one of its controlled tasks.
-         */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static void setInterceptBackPressedOnTaskRoot(ITaskOrganizer organizer,
-                boolean interceptBackPressed) throws RemoteException {
-            getController().setInterceptBackPressedOnTaskRoot(organizer, interceptBackPressed);
-        }
-
-        private static ITaskOrganizerController getController() {
-            return ITaskOrganizerControllerSingleton.get();
-        }
-
-        private static final Singleton<ITaskOrganizerController> ITaskOrganizerControllerSingleton =
-                new Singleton<ITaskOrganizerController>() {
-                    @Override
-                    protected ITaskOrganizerController create() {
-                        try {
-                            return getWindowOrganizerController().getTaskOrganizerController();
-                        } catch (RemoteException e) {
-                            return null;
-                        }
-                    }
-                };
-    }
-
-    /** Class for organizing display areas. */
-    public static class DisplayAreaOrganizer {
-
-        public static final int FEATURE_UNDEFINED = -1;
-        public static final int FEATURE_SYSTEM_FIRST = 0;
-        // The Root display area on a display
-        public static final int FEATURE_ROOT = FEATURE_SYSTEM_FIRST;
-        // Display area hosting the task container.
-        public static final int FEATURE_TASK_CONTAINER = FEATURE_SYSTEM_FIRST + 1;
-        // Display area hosting non-activity window tokens.
-        public static final int FEATURE_WINDOW_TOKENS = FEATURE_SYSTEM_FIRST + 2;
-
-        public static final int FEATURE_SYSTEM_LAST = 10_000;
-
-        // Vendor specific display area definition can start with this value.
-        public static final int FEATURE_VENDOR_FIRST = FEATURE_SYSTEM_LAST + 1;
-
-        /** @hide */
-        @RequiresPermission(android.Manifest.permission.MANAGE_ACTIVITY_STACKS)
-        public static void registerOrganizer(
-                IDisplayAreaOrganizer organizer, int displayAreaFeature) throws RemoteException {
-            getController().registerOrganizer(organizer, displayAreaFeature);
-        }
-
-        /** @hide */
-        private static IDisplayAreaOrganizerController getController() {
-            return IDisplayAreaOrganizerControllerSingleton.get();
-        }
-
-        private static final Singleton<IDisplayAreaOrganizerController>
-                IDisplayAreaOrganizerControllerSingleton =
-                new Singleton<IDisplayAreaOrganizerController>() {
-                    @Override
-                    protected IDisplayAreaOrganizerController create() {
-                        try {
-                            return getWindowOrganizerController()
-                                    .getDisplayAreaOrganizerController();
-                        } catch (RemoteException e) {
-                            return null;
-                        }
-                    }
-                };
-
-    }
 }