Add ClipboardManager stub
This creates a stub for ClipboardManager that can be accessed from the
BridgeContext.
Bug: 153131457
Test: N/A
Change-Id: Ia1cd1034492a11d526a5a98016827dd97702e8aa
(cherry picked from commit 6e1a0e25c2c19720d5f7c33ee3ea6cf25a17064b)
diff --git a/bridge/src/android/content/ClipboardManager.java b/bridge/src/android/content/ClipboardManager.java
new file mode 100644
index 0000000..f833175
--- /dev/null
+++ b/bridge/src/android/content/ClipboardManager.java
@@ -0,0 +1,127 @@
+/*
+ * 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.content;
+
+import android.annotation.NonNull;
+import android.annotation.Nullable;
+import android.os.Handler;
+
+public class ClipboardManager extends android.text.ClipboardManager {
+
+ /**
+ * Defines a listener callback that is invoked when the primary clip on the clipboard changes.
+ * Objects that want to register a listener call
+ * {@link android.content.ClipboardManager#addPrimaryClipChangedListener(OnPrimaryClipChangedListener)
+ * addPrimaryClipChangedListener()} with an
+ * object that implements OnPrimaryClipChangedListener.
+ *
+ */
+ public interface OnPrimaryClipChangedListener {
+
+ /**
+ * Callback that is invoked by {@link android.content.ClipboardManager} when the primary
+ * clip changes.
+ */
+ void onPrimaryClipChanged();
+ }
+
+ /** {@hide} */
+ public ClipboardManager(Context context, Handler handler) { }
+
+ /**
+ * Sets the current primary clip on the clipboard. This is the clip that
+ * is involved in normal cut and paste operations.
+ *
+ * @param clip The clipped data item to set.
+ * @see #getPrimaryClip()
+ * @see #clearPrimaryClip()
+ */
+ public void setPrimaryClip(@NonNull ClipData clip) { }
+
+ /**
+ * Clears any current primary clip on the clipboard.
+ *
+ * @see #setPrimaryClip(ClipData)
+ */
+ public void clearPrimaryClip() { }
+
+ /**
+ * Returns the current primary clip on the clipboard.
+ *
+ * <em>If the application is not the default IME or does not have input focus this return
+ * {@code null}.</em>
+ *
+ * @see #setPrimaryClip(ClipData)
+ */
+ public @Nullable ClipData getPrimaryClip() {
+ return null;
+ }
+
+ /**
+ * Returns a description of the current primary clip on the clipboard
+ * but not a copy of its data.
+ *
+ * <em>If the application is not the default IME or does not have input focus this return
+ * {@code null}.</em>
+ *
+ * @see #setPrimaryClip(ClipData)
+ */
+ public @Nullable ClipDescription getPrimaryClipDescription() {
+ return null;
+ }
+
+ /**
+ * Returns true if there is currently a primary clip on the clipboard.
+ *
+ * <em>If the application is not the default IME or the does not have input focus this will
+ * return {@code false}.</em>
+ */
+ public boolean hasPrimaryClip() {
+ return false;
+ }
+
+ public void addPrimaryClipChangedListener(OnPrimaryClipChangedListener what) { }
+
+ public void removePrimaryClipChangedListener(OnPrimaryClipChangedListener what) { }
+
+ /**
+ * @deprecated Use {@link #getPrimaryClip()} instead. This retrieves
+ * the primary clip and tries to coerce it to a string.
+ */
+ @Deprecated
+ public CharSequence getText() {
+ return null;
+ }
+
+ /**
+ * @deprecated Use {@link #setPrimaryClip(ClipData)} instead. This
+ * creates a ClippedItem holding the given text and sets it as the
+ * primary clip. It has no label or icon.
+ */
+ @Deprecated
+ public void setText(CharSequence text) { }
+
+ /**
+ * @deprecated Use {@link #hasPrimaryClip()} instead.
+ */
+ @Deprecated
+ public boolean hasText() {
+ return false;
+ }
+
+ void reportPrimaryClipChanged() { }
+}
diff --git a/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index 09a1d23..a2538c2 100644
--- a/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -43,6 +43,7 @@
import android.annotation.Nullable;
import android.app.SystemServiceRegistry;
import android.content.BroadcastReceiver;
+import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
@@ -164,6 +165,7 @@
private final WindowManager mWindowManager;
private final DisplayManager mDisplayManager;
private final AutofillManager mAutofillManager;
+ private final ClipboardManager mClipboardManager;
private final HashMap<View, Integer> mScrollYPos = new HashMap<>();
private final HashMap<View, Integer> mScrollXPos = new HashMap<>();
@@ -250,6 +252,7 @@
mWindowManager = new WindowManagerImpl(this, mMetrics);
mDisplayManager = new DisplayManager(this);
mAutofillManager = new AutofillManager(this, new Default());
+ mClipboardManager = new ClipboardManager(this, null);
if (mLayoutlibCallback.isResourceNamespacingRequired()) {
if (mLayoutlibCallback.hasAndroidXAppCompat()) {
@@ -630,6 +633,9 @@
case AUTOFILL_MANAGER_SERVICE:
return mAutofillManager;
+ case CLIPBOARD_SERVICE:
+ return mClipboardManager;
+
case AUDIO_SERVICE:
case TEXT_CLASSIFICATION_SERVICE:
case CONTENT_CAPTURE_MANAGER_SERVICE: