diff options
Diffstat (limited to 'core/java/android/content/ClipData.java')
| -rw-r--r-- | core/java/android/content/ClipData.java | 91 |
1 files changed, 10 insertions, 81 deletions
diff --git a/core/java/android/content/ClipData.java b/core/java/android/content/ClipData.java index 5c6728348893..234216539e97 100644 --- a/core/java/android/content/ClipData.java +++ b/core/java/android/content/ClipData.java @@ -27,7 +27,6 @@ import android.graphics.Bitmap; import android.net.Uri; import android.os.Build; import android.os.Parcel; -import android.os.ParcelFileDescriptor; import android.os.Parcelable; import android.os.StrictMode; import android.text.Html; @@ -171,11 +170,6 @@ public class ClipData implements Parcelable { static final String[] MIMETYPES_TEXT_INTENT = new String[] { ClipDescription.MIMETYPE_TEXT_INTENT }; - // Constants used in {@link #writeHtmlTextToParcel}. - static final int PARCEL_MAX_SIZE_BYTES = 800 * 1024; - static final int PARCEL_TYPE_STRING = 0; - static final int PARCEL_TYPE_PFD = 1; - final ClipDescription mClipDescription; final Bitmap mIcon; @@ -231,8 +225,7 @@ public class ClipData implements Parcelable { * with an alternative HTML formatted representation. You <em>must</em> * supply a plain text representation in addition to HTML text; coercion * will not be done from HTML formatted text into plain text. - * <p class="note"><strong>Note:</strong> It is strongly recommended to - * use content: URI for sharing large clip data. Starting on API 30, + * <p><strong>Warning:</strong> Use content: URI for sharing large clip data. * ClipData.Item doesn't accept an HTML text if it's larger than 800KB. * </p> */ @@ -682,7 +675,7 @@ public class ClipData implements Parcelable { } /** @hide */ - public void writeToProto(ProtoOutputStream proto, long fieldId) { + public void dumpDebug(ProtoOutputStream proto, long fieldId) { final long token = proto.start(fieldId); if (mHtmlText != null) { @@ -692,7 +685,7 @@ public class ClipData implements Parcelable { } else if (mUri != null) { proto.write(ClipDataProto.Item.URI, mUri.toString()); } else if (mIntent != null) { - mIntent.writeToProto(proto, ClipDataProto.Item.INTENT, true, true, true, true); + mIntent.dumpDebug(proto, ClipDataProto.Item.INTENT, true, true, true, true); } else { proto.write(ClipDataProto.Item.NOTHING, true); } @@ -892,12 +885,6 @@ public class ClipData implements Parcelable { mItems.add(item); } - /** @removed use #addItem(ContentResolver, Item) instead */ - @Deprecated - public void addItem(Item item, ContentResolver resolver) { - addItem(resolver, item); - } - /** * Add a new Item to the overall ClipData container. * <p> Unlike {@link #addItem(Item)}, this method will update the list of available MIME types @@ -1075,19 +1062,18 @@ public class ClipData implements Parcelable { if (!first) { b.append(' '); } - mItems.get(0).toShortString(b); - if (mItems.size() > 1) { - b.append(" ..."); + for (int i=0; i<mItems.size(); i++) { + b.append("{...}"); } } } /** @hide */ - public void writeToProto(ProtoOutputStream proto, long fieldId) { + public void dumpDebug(ProtoOutputStream proto, long fieldId) { final long token = proto.start(fieldId); if (mClipDescription != null) { - mClipDescription.writeToProto(proto, ClipDataProto.DESCRIPTION); + mClipDescription.dumpDebug(proto, ClipDataProto.DESCRIPTION); } if (mIcon != null) { final long iToken = proto.start(ClipDataProto.ICON); @@ -1096,7 +1082,7 @@ public class ClipData implements Parcelable { proto.end(iToken); } for (int i = 0; i < mItems.size(); i++) { - mItems.get(i).writeToProto(proto, ClipDataProto.ITEMS); + mItems.get(i).dumpDebug(proto, ClipDataProto.ITEMS); } proto.end(token); @@ -1142,7 +1128,7 @@ public class ClipData implements Parcelable { for (int i=0; i<N; i++) { Item item = mItems.get(i); TextUtils.writeToParcel(item.mText, dest, flags); - writeHtmlTextToParcel(item.mHtmlText, dest, flags); + dest.writeString8(item.mHtmlText); if (item.mIntent != null) { dest.writeInt(1); item.mIntent.writeToParcel(dest, flags); @@ -1169,7 +1155,7 @@ public class ClipData implements Parcelable { final int N = in.readInt(); for (int i=0; i<N; i++) { CharSequence text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); - String htmlText = readHtmlTextFromParcel(in); + String htmlText = in.readString8(); Intent intent = in.readInt() != 0 ? Intent.CREATOR.createFromParcel(in) : null; Uri uri = in.readInt() != 0 ? Uri.CREATOR.createFromParcel(in) : null; mItems.add(new Item(text, htmlText, intent, uri)); @@ -1189,61 +1175,4 @@ public class ClipData implements Parcelable { return new ClipData[size]; } }; - - /** - * Helper function for writing an HTML text into a parcel. - * If the text size is larger than 400KB, it writes the text to a file descriptor to prevent the - * parcel from exceeding 800KB binder size limit. {@link android.os.Binder#checkParcel()} - * Otherwise, it directly writes the text into the parcel. - * Note: This function is a workaround for existing applications that still use HTML for sharing - * large clip data. We will ask application developers to use content: URI instead and remove - * this function in API 30. - */ - private static void writeHtmlTextToParcel(String text, Parcel dest, int flags) { - byte[] textData = (text != null) ? text.getBytes() : new byte[0]; - if (textData.length > PARCEL_MAX_SIZE_BYTES / 2 - && Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) { - try { - ParcelFileDescriptor pfd = ParcelFileDescriptor.fromData(textData, null); - dest.writeInt(PARCEL_TYPE_PFD); - dest.writeParcelable(pfd, flags); - } catch (IOException e) { - throw new IllegalStateException( - "Error creating the shared memory area: " + e.toString()); - } - } else { - dest.writeInt(PARCEL_TYPE_STRING); - dest.writeString(text); - } - } - - /** - * Reads a text written by writeHtmlTextToParcel. - */ - private static String readHtmlTextFromParcel(Parcel in) { - if (in.readInt() == PARCEL_TYPE_STRING) { - return in.readString(); - } - ParcelFileDescriptor pfd = - in.readParcelable(ParcelFileDescriptor.class.getClassLoader()); - if (pfd == null) { - throw new IllegalStateException("Error reading ParcelFileDescriptor from Parcel"); - } - FileInputStream fis = new ParcelFileDescriptor.AutoCloseInputStream(pfd); - InputStreamReader reader = new InputStreamReader(fis); - StringBuilder builder = new StringBuilder(); - char[] buffer = new char[4096]; - int numRead; - try { - while ((numRead = reader.read(buffer)) != -1) { - builder.append(buffer, 0, numRead); - } - return builder.toString(); - } catch (IOException e) { - throw new IllegalStateException( - "Error reading data from ParcelFileDescriptor: " + e.toString()); - } finally { - IoUtils.closeQuietly(fis); - } - } } |
