Bug 776223 - Don't paste null text to Android's clipboard. r=blassey
authorChris Peterson <cpeterson@mozilla.com>
Fri, 17 May 2013 17:16:38 -0700
changeset 143935 501ef1098f55c35061d29ab9f44a18b00bfcbbb9
parent 143934 a45a64281b4b4bf3f8f4a1d911a6af3967c0dc1a
child 143936 a827f9fead79e80e19ae4c573d63231116d5fc19
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersblassey
bugs776223
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 776223 - Don't paste null text to Android's clipboard. r=blassey
mobile/android/base/GeckoAppShell.java
--- a/mobile/android/base/GeckoAppShell.java
+++ b/mobile/android/base/GeckoAppShell.java
@@ -1167,17 +1167,16 @@ public class GeckoAppShell
         intent.setData(pruned);
 
         return intent;
     }
 
     /* On some devices, access to the clipboard service needs to happen
      * on a thread with a looper, so this function requires a looper is
      * present on the thread. */
-    @SuppressWarnings("deprecation")
     private static String getClipboardTextImpl() {
         Context context = GeckoApp.mAppContext;
         if (android.os.Build.VERSION.SDK_INT >= 11) {
             android.content.ClipboardManager cm = (android.content.ClipboardManager)context.getSystemService(Context.CLIPBOARD_SERVICE);
             if (cm.hasPrimaryClip()) {
                 ClipData clip = cm.getPrimaryClip();
                 if (clip != null) {
                     ClipData.Item item = clip.getItemAt(0);
@@ -1215,20 +1214,23 @@ public class GeckoAppShell
         });
         try {
             return sClipboardQueue.take();
         } catch (InterruptedException ie) {
             return "";
         }
     }
 
-    static void setClipboardText(final String text) {
+    static void setClipboardText(String copiedText) {
+        // Copy an empty string instead of null to avoid clipboard crashes.
+        // AndroidBridge::EmptyClipboard() passes null to clear the clipboard's current contents.
+        final String text = (copiedText != null) ? copiedText : "";
+
         ThreadUtils.postToBackgroundThread(new Runnable() {
             @Override
-            @SuppressWarnings("deprecation")
             public void run() {
                 Context context = GeckoApp.mAppContext;
                 if (android.os.Build.VERSION.SDK_INT >= 11) {
                     android.content.ClipboardManager cm = (android.content.ClipboardManager)
                         context.getSystemService(Context.CLIPBOARD_SERVICE);
                     cm.setPrimaryClip(ClipData.newPlainText("Text", text));
                 } else {
                     android.text.ClipboardManager cm = (android.text.ClipboardManager)