Initial layout of selection toolbar.

The initial selection toolbar related architecture. Render service
part and the implementation will be revised in the follow up changes.

Bug: 190030331
Bug: 205822301
Test: manual. Can boot to home and get manager successfully.
Ignore-AOSP-First: new file for T

Change-Id: Iab5d5f2e5e48e6258a63fb0c479194c958ea61e8
diff --git a/services/Android.bp b/services/Android.bp
index dcbcff0..c830c22 100644
--- a/services/Android.bp
+++ b/services/Android.bp
@@ -90,6 +90,7 @@
         ":services.profcollect-sources",
         ":services.restrictions-sources",
         ":services.searchui-sources",
+        ":services.selectiontoolbar-sources",
         ":services.smartspace-sources",
         ":services.speech-sources",
         ":services.startop.iorap-sources",
@@ -144,6 +145,7 @@
         "services.profcollect",
         "services.restrictions",
         "services.searchui",
+        "services.selectiontoolbar",
         "services.smartspace",
         "services.speech",
         "services.startop",
diff --git a/services/java/com/android/server/SystemServer.java b/services/java/com/android/server/SystemServer.java
index a72cf3a..45d9626 100644
--- a/services/java/com/android/server/SystemServer.java
+++ b/services/java/com/android/server/SystemServer.java
@@ -332,6 +332,8 @@
             "com.android.server.contentcapture.ContentCaptureManagerService";
     private static final String TRANSLATION_MANAGER_SERVICE_CLASS =
             "com.android.server.translation.TranslationManagerService";
+    private static final String SELECTION_TOOLBAR_MANAGER_SERVICE_CLASS =
+            "com.android.server.selectiontoolbar.SelectionToolbarManagerService";
     private static final String MUSIC_RECOGNITION_MANAGER_SERVICE_CLASS =
             "com.android.server.musicrecognition.MusicRecognitionManagerService";
     private static final String SYSTEM_CAPTIONS_MANAGER_SERVICE_CLASS =
@@ -2592,6 +2594,11 @@
             Slog.d(TAG, "TranslationService not defined by OEM");
         }
 
+        // Selection toolbar service
+        t.traceBegin("StartSelectionToolbarManagerService");
+        mSystemServiceManager.startService(SELECTION_TOOLBAR_MANAGER_SERVICE_CLASS);
+        t.traceEnd();
+
         // NOTE: ClipboardService depends on ContentCapture and Autofill
         t.traceBegin("StartClipboardService");
         mSystemServiceManager.startService(ClipboardService.class);
diff --git a/services/selectiontoolbar/Android.bp b/services/selectiontoolbar/Android.bp
new file mode 100644
index 0000000..cc6405f
--- /dev/null
+++ b/services/selectiontoolbar/Android.bp
@@ -0,0 +1,22 @@
+package {
+    // See: http://go/android-license-faq
+    // A large-scale-change added 'default_applicable_licenses' to import
+    // all of the 'license_kinds' from "frameworks_base_license"
+    // to get the below license kinds:
+    //   SPDX-license-identifier-Apache-2.0
+    default_applicable_licenses: ["frameworks_base_license"],
+}
+
+filegroup {
+    name: "services.selectiontoolbar-sources",
+    srcs: ["java/**/*.java"],
+    path: "java",
+    visibility: ["//frameworks/base/services"],
+}
+
+java_library_static {
+    name: "services.selectiontoolbar",
+    defaults: ["platform_service_defaults"],
+    srcs: [":services.selectiontoolbar-sources"],
+    libs: ["services.core"],
+}
diff --git a/services/selectiontoolbar/OWNERS b/services/selectiontoolbar/OWNERS
new file mode 100644
index 0000000..ed9425c
--- /dev/null
+++ b/services/selectiontoolbar/OWNERS
@@ -0,0 +1 @@
+include /core/java/android/view/selectiontoolbar/OWNERS
diff --git a/services/selectiontoolbar/java/com/android/server/selectiontoolbar/SelectionToolbarManagerService.java b/services/selectiontoolbar/java/com/android/server/selectiontoolbar/SelectionToolbarManagerService.java
new file mode 100644
index 0000000..3bdf55c
--- /dev/null
+++ b/services/selectiontoolbar/java/com/android/server/selectiontoolbar/SelectionToolbarManagerService.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2021 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 com.android.server.selectiontoolbar;
+
+import android.content.Context;
+import android.util.Slog;
+import android.view.selectiontoolbar.ISelectionToolbarCallback;
+import android.view.selectiontoolbar.ISelectionToolbarManager;
+import android.view.selectiontoolbar.ShowInfo;
+
+import com.android.internal.util.DumpUtils;
+import com.android.server.infra.AbstractMasterSystemService;
+
+import java.io.FileDescriptor;
+import java.io.PrintWriter;
+
+/**
+ * Entry point service for selection toolbar management.
+ */
+public final class SelectionToolbarManagerService extends
+        AbstractMasterSystemService<SelectionToolbarManagerService,
+                SelectionToolbarManagerServiceImpl> {
+
+    private static final String TAG = "SelectionToolbarManagerService";
+
+    @Override
+    public void onStart() {
+        publishBinderService(Context.SELECTION_TOOLBAR_SERVICE,
+                new SelectionToolbarManagerService.SelectionToolbarManagerServiceStub());
+    }
+
+    public SelectionToolbarManagerService(Context context) {
+        super(context, new SelectionToolbarServiceNameResolver(), /* disallowProperty= */
+                null, PACKAGE_UPDATE_POLICY_REFRESH_EAGER);
+    }
+
+    @Override
+    protected SelectionToolbarManagerServiceImpl newServiceLocked(int resolvedUserId,
+            boolean disabled) {
+        return new SelectionToolbarManagerServiceImpl(this, mLock, resolvedUserId);
+    }
+
+    final class SelectionToolbarManagerServiceStub extends ISelectionToolbarManager.Stub {
+
+        @Override
+        public void showToolbar(ShowInfo showInfo, ISelectionToolbarCallback callback, int userId) {
+            synchronized (mLock) {
+                SelectionToolbarManagerServiceImpl service = getServiceForUserLocked(userId);
+                if (service != null) {
+                    service.showToolbar(showInfo, callback);
+                } else {
+                    Slog.v(TAG, "showToolbar(): no service for " + userId);
+                }
+            }
+        }
+
+        @Override
+        public void hideToolbar(long widgetToken, int userId) {
+            synchronized (mLock) {
+                SelectionToolbarManagerServiceImpl service = getServiceForUserLocked(userId);
+                if (service != null) {
+                    service.hideToolbar(widgetToken);
+                } else {
+                    Slog.v(TAG, "hideToolbar(): no service for " + userId);
+                }
+            }
+        }
+
+        @Override
+        public void dismissToolbar(long widgetToken, int userId) {
+            synchronized (mLock) {
+                SelectionToolbarManagerServiceImpl service = getServiceForUserLocked(userId);
+                if (service != null) {
+                    service.dismissToolbar(widgetToken);
+                } else {
+                    Slog.v(TAG, "dismissToolbar(): no service for " + userId);
+                }
+            }
+        }
+
+        @Override
+        public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
+            if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) return;
+
+            synchronized (mLock) {
+                dumpLocked("", pw);
+            }
+        }
+    }
+}
diff --git a/services/selectiontoolbar/java/com/android/server/selectiontoolbar/SelectionToolbarManagerServiceImpl.java b/services/selectiontoolbar/java/com/android/server/selectiontoolbar/SelectionToolbarManagerServiceImpl.java
new file mode 100644
index 0000000..94bf712
--- /dev/null
+++ b/services/selectiontoolbar/java/com/android/server/selectiontoolbar/SelectionToolbarManagerServiceImpl.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2021 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 com.android.server.selectiontoolbar;
+
+import android.annotation.NonNull;
+import android.view.selectiontoolbar.ISelectionToolbarCallback;
+import android.view.selectiontoolbar.ShowInfo;
+
+import com.android.server.infra.AbstractPerUserSystemService;
+
+final class SelectionToolbarManagerServiceImpl extends
+        AbstractPerUserSystemService<SelectionToolbarManagerServiceImpl,
+                SelectionToolbarManagerService> {
+
+    private static final String TAG = "SelectionToolbarManagerServiceImpl";
+
+    protected SelectionToolbarManagerServiceImpl(@NonNull SelectionToolbarManagerService master,
+            @NonNull Object lock, int userId) {
+        super(master, lock, userId);
+    }
+
+    void showToolbar(ShowInfo showInfo, ISelectionToolbarCallback callback) {
+        // TODO: add implementation to bind service
+    }
+
+    void hideToolbar(long widgetToken) {
+        // TODO: add implementation to bind service
+    }
+
+    void dismissToolbar(long widgetToken) {
+        // TODO: add implementation to bind service
+    }
+}
diff --git a/services/selectiontoolbar/java/com/android/server/selectiontoolbar/SelectionToolbarServiceNameResolver.java b/services/selectiontoolbar/java/com/android/server/selectiontoolbar/SelectionToolbarServiceNameResolver.java
new file mode 100644
index 0000000..1d4c94d
--- /dev/null
+++ b/services/selectiontoolbar/java/com/android/server/selectiontoolbar/SelectionToolbarServiceNameResolver.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2021 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 com.android.server.selectiontoolbar;
+
+import com.android.server.infra.ServiceNameResolver;
+
+import java.io.PrintWriter;
+
+final class SelectionToolbarServiceNameResolver implements ServiceNameResolver {
+
+    // TODO: move to SysUi or ExtServices
+    private static final String SELECTION_TOOLBAR_SERVICE_NAME =
+            "android/com.android.server.selectiontoolbar.DefaultSelectionToolbarRenderService";
+
+    @Override
+    public String getDefaultServiceName(int userId) {
+        return SELECTION_TOOLBAR_SERVICE_NAME;
+    }
+
+    @Override
+    public void dumpShort(PrintWriter pw) {
+        pw.print("service="); pw.print(SELECTION_TOOLBAR_SERVICE_NAME);
+    }
+
+    @Override
+    public void dumpShort(PrintWriter pw, int userId) {
+        pw.print("defaultService="); pw.print(getDefaultServiceName(userId));
+    }
+}