Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.provider; |
| 18 | |
Jeff Sharkey | 6398343 | 2013-08-21 11:33:50 -0700 | [diff] [blame] | 19 | import static android.net.TrafficStats.KB_IN_BYTES; |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 20 | import static android.system.OsConstants.SEEK_SET; |
Julian Mancini | b650515 | 2017-06-27 13:29:09 -0700 | [diff] [blame] | 21 | |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 22 | import static com.android.internal.util.Preconditions.checkArgument; |
| 23 | import static com.android.internal.util.Preconditions.checkCollectionElementsNotNull; |
| 24 | import static com.android.internal.util.Preconditions.checkCollectionNotEmpty; |
| 25 | |
Steve McKay | 323ee3e | 2015-09-25 16:02:56 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 27 | import android.content.ContentProviderClient; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 28 | import android.content.ContentResolver; |
Jeff Sharkey | ee2f7df | 2013-09-26 11:32:30 -0700 | [diff] [blame] | 29 | import android.content.Context; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 30 | import android.content.Intent; |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 31 | import android.content.IntentSender; |
Jeff Sharkey | d2e1e81 | 2013-10-09 13:31:13 -0700 | [diff] [blame] | 32 | import android.content.pm.ResolveInfo; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 33 | import android.content.res.AssetFileDescriptor; |
Jeff Sharkey | 20d96d8 | 2013-07-30 17:08:39 -0700 | [diff] [blame] | 34 | import android.database.Cursor; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 35 | import android.graphics.Bitmap; |
| 36 | import android.graphics.BitmapFactory; |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 37 | import android.graphics.Matrix; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 38 | import android.graphics.Point; |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 39 | import android.media.ExifInterface; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 40 | import android.net.Uri; |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 43 | import android.os.CancellationSignal; |
Jeff Sharkey | 3381931 | 2013-10-29 11:56:37 -0700 | [diff] [blame] | 44 | import android.os.OperationCanceledException; |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 45 | import android.os.Parcel; |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 46 | import android.os.ParcelFileDescriptor; |
Jeff Sharkey | 67f9d50 | 2017-08-05 13:49:13 -0600 | [diff] [blame] | 47 | import android.os.ParcelFileDescriptor.OnCloseListener; |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 48 | import android.os.Parcelable; |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 49 | import android.os.ParcelableException; |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 50 | import android.os.RemoteException; |
Felipe Leme | 04a5d40 | 2016-02-08 16:44:06 -0800 | [diff] [blame] | 51 | import android.os.storage.StorageVolume; |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 52 | import android.system.ErrnoException; |
| 53 | import android.system.Os; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 54 | import android.util.Log; |
| 55 | |
| 56 | import libcore.io.IoUtils; |
| 57 | |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 58 | import java.io.BufferedInputStream; |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 59 | import java.io.File; |
Jeff Sharkey | 9d0843d | 2013-05-07 12:41:33 -0700 | [diff] [blame] | 60 | import java.io.FileDescriptor; |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 61 | import java.io.FileInputStream; |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 62 | import java.io.FileNotFoundException; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 63 | import java.io.IOException; |
Jeff Sharkey | dc2963a | 2013-08-02 15:55:26 -0700 | [diff] [blame] | 64 | import java.util.List; |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 65 | import java.util.Objects; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 68 | * Defines the contract between a documents provider and the platform. |
| 69 | * <p> |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 70 | * To create a document provider, extend {@link DocumentsProvider}, which |
| 71 | * provides a foundational implementation of this contract. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 72 | * <p> |
| 73 | * All client apps must hold a valid URI permission grant to access documents, |
| 74 | * typically issued when a user makes a selection through |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 75 | * {@link Intent#ACTION_OPEN_DOCUMENT}, {@link Intent#ACTION_CREATE_DOCUMENT}, |
Felipe Leme | 04a5d40 | 2016-02-08 16:44:06 -0800 | [diff] [blame] | 76 | * {@link Intent#ACTION_OPEN_DOCUMENT_TREE}, or |
| 77 | * {@link StorageVolume#createAccessIntent(String) StorageVolume.createAccessIntent}. |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 78 | * |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 79 | * @see DocumentsProvider |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 80 | */ |
| 81 | public final class DocumentsContract { |
Steve McKay | d3afdee | 2015-11-19 17:27:12 -0800 | [diff] [blame] | 82 | private static final String TAG = "DocumentsContract"; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 83 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 84 | // content://com.example/root/ |
| 85 | // content://com.example/root/sdcard/ |
| 86 | // content://com.example/root/sdcard/recent/ |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 87 | // content://com.example/root/sdcard/search/?query=pony |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 88 | // content://com.example/document/12/ |
| 89 | // content://com.example/document/12/children/ |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 90 | // content://com.example/tree/12/document/24/ |
| 91 | // content://com.example/tree/12/document/24/children/ |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 92 | |
| 93 | private DocumentsContract() { |
| 94 | } |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 95 | |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 96 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 97 | * Intent action used to identify {@link DocumentsProvider} instances. This |
| 98 | * is used in the {@code <intent-filter>} of a {@code <provider>}. |
Jeff Sharkey | 85f5f81 | 2013-10-07 10:16:12 -0700 | [diff] [blame] | 99 | */ |
| 100 | public static final String PROVIDER_INTERFACE = "android.content.action.DOCUMENTS_PROVIDER"; |
| 101 | |
Jeff Sharkey | 5b83f85 | 2013-08-14 18:29:19 -0700 | [diff] [blame] | 102 | /** {@hide} */ |
Jeff Sharkey | 15be836 | 2013-10-09 13:52:17 -0700 | [diff] [blame] | 103 | public static final String EXTRA_PACKAGE_NAME = "android.content.extra.PACKAGE_NAME"; |
| 104 | |
Jeff Sharkey | 96c6205 | 2013-10-25 16:30:54 -0700 | [diff] [blame] | 105 | /** {@hide} */ |
Aga Wronska | 1719b35 | 2016-03-21 11:28:03 -0700 | [diff] [blame] | 106 | public static final String EXTRA_SHOW_ADVANCED = "android.content.extra.SHOW_ADVANCED"; |
| 107 | |
| 108 | /** {@hide} */ |
Tomasz Mikolajewski | 74fe181 | 2015-06-12 17:13:26 -0700 | [diff] [blame] | 109 | public static final String EXTRA_TARGET_URI = "android.content.extra.TARGET_URI"; |
| 110 | |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 111 | /** |
Garfield Tan | b44ae61 | 2016-11-07 16:46:37 -0800 | [diff] [blame] | 112 | * Sets the desired initial location visible to user when file chooser is shown. |
| 113 | * |
| 114 | * <p>Applicable to {@link Intent} with actions: |
| 115 | * <ul> |
| 116 | * <li>{@link Intent#ACTION_OPEN_DOCUMENT}</li> |
| 117 | * <li>{@link Intent#ACTION_CREATE_DOCUMENT}</li> |
| 118 | * <li>{@link Intent#ACTION_OPEN_DOCUMENT_TREE}</li> |
| 119 | * </ul> |
| 120 | * |
| 121 | * <p>Location should specify a document URI or a tree URI with document ID. If |
| 122 | * this URI identifies a non-directory, document navigator will attempt to use the parent |
| 123 | * of the document as the initial location. |
Garfield Tan | 40d7b35 | 2017-03-02 15:30:30 -0800 | [diff] [blame] | 124 | * |
| 125 | * <p>The initial location is system specific if this extra is missing or document navigator |
| 126 | * failed to locate the desired initial location. |
Garfield Tan | b44ae61 | 2016-11-07 16:46:37 -0800 | [diff] [blame] | 127 | */ |
| 128 | public static final String EXTRA_INITIAL_URI = "android.provider.extra.INITIAL_URI"; |
| 129 | |
| 130 | /** |
Ben Kwa | 7779740 | 2015-05-29 15:40:31 -0700 | [diff] [blame] | 131 | * Set this in a DocumentsUI intent to cause a package's own roots to be |
| 132 | * excluded from the roots list. |
| 133 | */ |
| 134 | public static final String EXTRA_EXCLUDE_SELF = "android.provider.extra.EXCLUDE_SELF"; |
| 135 | |
| 136 | /** |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 137 | * Included in {@link AssetFileDescriptor#getExtras()} when returned |
| 138 | * thumbnail should be rotated. |
| 139 | * |
| 140 | * @see MediaStore.Images.ImageColumns#ORIENTATION |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 141 | */ |
Tomasz Mikolajewski | 5f53f65 | 2016-03-31 09:34:51 +0900 | [diff] [blame] | 142 | public static final String EXTRA_ORIENTATION = "android.provider.extra.ORIENTATION"; |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 143 | |
Tomasz Mikolajewski | 0e591f9 | 2015-06-12 16:22:17 -0700 | [diff] [blame] | 144 | /** |
| 145 | * Overrides the default prompt text in DocumentsUI when set in an intent. |
| 146 | */ |
| 147 | public static final String EXTRA_PROMPT = "android.provider.extra.PROMPT"; |
| 148 | |
Ben Lin | bd036d8 | 2016-12-15 15:41:08 -0800 | [diff] [blame] | 149 | /** |
| 150 | * Action of intent issued by DocumentsUI when user wishes to open/configure/manage a particular |
| 151 | * document in the provider application. |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 152 | * |
Ben Lin | bd036d8 | 2016-12-15 15:41:08 -0800 | [diff] [blame] | 153 | * <p>When issued, the intent will include the URI of the document as the intent data. |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 154 | * |
Ben Lin | bd036d8 | 2016-12-15 15:41:08 -0800 | [diff] [blame] | 155 | * <p>A provider wishing to provide support for this action should do two things. |
| 156 | * <li>Add an {@code <intent-filter>} matching this action. |
| 157 | * <li>When supplying information in {@link DocumentsProvider#queryChildDocuments}, include |
| 158 | * {@link Document#FLAG_SUPPORTS_SETTINGS} in the flags for each document that supports |
| 159 | * settings. |
| 160 | * |
| 161 | * @see DocumentsContact#Document#FLAG_SUPPORTS_SETTINGS |
| 162 | */ |
| 163 | public static final String |
| 164 | ACTION_DOCUMENT_SETTINGS = "android.provider.action.DOCUMENT_SETTINGS"; |
| 165 | |
Jeff Sharkey | 15be836 | 2013-10-09 13:52:17 -0700 | [diff] [blame] | 166 | /** {@hide} */ |
Jeff Sharkey | a61dc8e | 2013-09-05 17:14:14 -0700 | [diff] [blame] | 167 | public static final String ACTION_MANAGE_DOCUMENT = "android.provider.action.MANAGE_DOCUMENT"; |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 168 | |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 169 | /** {@hide} */ |
Jeff Sharkey | 1407d4c | 2015-04-12 21:52:24 -0700 | [diff] [blame] | 170 | public static final String |
| 171 | ACTION_DOCUMENT_ROOT_SETTINGS = "android.provider.action.DOCUMENT_ROOT_SETTINGS"; |
Jeff Sharkey | 59d577a | 2015-04-11 21:27:21 -0700 | [diff] [blame] | 172 | |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 173 | /** |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 174 | * Buffer is large enough to rewind past any EXIF headers. |
| 175 | */ |
| 176 | private static final int THUMBNAIL_BUFFER_SIZE = (int) (128 * KB_IN_BYTES); |
| 177 | |
Jeff Sharkey | cc2ae6b4 | 2015-09-29 13:04:46 -0700 | [diff] [blame] | 178 | /** {@hide} */ |
Garfield Tan | 92b96ba | 2016-11-01 14:33:48 -0700 | [diff] [blame] | 179 | public static final String EXTERNAL_STORAGE_PROVIDER_AUTHORITY = |
| 180 | "com.android.externalstorage.documents"; |
| 181 | |
| 182 | /** {@hide} */ |
Jeff Sharkey | cc2ae6b4 | 2015-09-29 13:04:46 -0700 | [diff] [blame] | 183 | public static final String PACKAGE_DOCUMENTS_UI = "com.android.documentsui"; |
| 184 | |
Julian Mancini | b650515 | 2017-06-27 13:29:09 -0700 | [diff] [blame] | 185 | /** {@hide} */ |
| 186 | public static final String METADATA_TYPES = "android:documentMetadataType"; |
| 187 | |
| 188 | /** {@hide} */ |
| 189 | public static final String METADATA_EXIF = "android:documentExif"; |
| 190 | |
| 191 | /** {@hide} */ |
| 192 | public static final String EXTRA_METADATA_TAGS = "android:documentMetadataTags"; |
| 193 | |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 194 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 195 | * Constants related to a document, including {@link Cursor} column names |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 196 | * and flags. |
| 197 | * <p> |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 198 | * A document can be either an openable stream (with a specific MIME type), |
| 199 | * or a directory containing additional documents (with the |
| 200 | * {@link #MIME_TYPE_DIR} MIME type). A directory represents the top of a |
| 201 | * subtree containing zero or more documents, which can recursively contain |
| 202 | * even more documents and directories. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 203 | * <p> |
| 204 | * All columns are <em>read-only</em> to client applications. |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 205 | */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 206 | public final static class Document { |
| 207 | private Document() { |
Jeff Sharkey | a5599ef | 2013-08-15 16:17:41 -0700 | [diff] [blame] | 208 | } |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 209 | |
Jeff Sharkey | a5599ef | 2013-08-15 16:17:41 -0700 | [diff] [blame] | 210 | /** |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 211 | * Unique ID of a document. This ID is both provided by and interpreted |
| 212 | * by a {@link DocumentsProvider}, and should be treated as an opaque |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 213 | * value by client applications. This column is required. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 214 | * <p> |
| 215 | * Each document must have a unique ID within a provider, but that |
| 216 | * single document may be included as a child of multiple directories. |
| 217 | * <p> |
| 218 | * A provider must always return durable IDs, since they will be used to |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 219 | * issue long-term URI permission grants when an application interacts |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 220 | * with {@link Intent#ACTION_OPEN_DOCUMENT} and |
| 221 | * {@link Intent#ACTION_CREATE_DOCUMENT}. |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 222 | * <p> |
| 223 | * Type: STRING |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 224 | */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 225 | public static final String COLUMN_DOCUMENT_ID = "document_id"; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 226 | |
| 227 | /** |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 228 | * Concrete MIME type of a document. For example, "image/png" or |
| 229 | * "application/pdf" for openable files. A document can also be a |
| 230 | * directory containing additional documents, which is represented with |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 231 | * the {@link #MIME_TYPE_DIR} MIME type. This column is required. |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 232 | * <p> |
| 233 | * Type: STRING |
| 234 | * |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 235 | * @see #MIME_TYPE_DIR |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 236 | */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 237 | public static final String COLUMN_MIME_TYPE = "mime_type"; |
| 238 | |
| 239 | /** |
| 240 | * Display name of a document, used as the primary title displayed to a |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 241 | * user. This column is required. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 242 | * <p> |
| 243 | * Type: STRING |
| 244 | */ |
| 245 | public static final String COLUMN_DISPLAY_NAME = OpenableColumns.DISPLAY_NAME; |
| 246 | |
| 247 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 248 | * Summary of a document, which may be shown to a user. This column is |
| 249 | * optional, and may be {@code null}. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 250 | * <p> |
| 251 | * Type: STRING |
| 252 | */ |
| 253 | public static final String COLUMN_SUMMARY = "summary"; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 254 | |
| 255 | /** |
| 256 | * Timestamp when a document was last modified, in milliseconds since |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 257 | * January 1, 1970 00:00:00.0 UTC. This column is required, and may be |
| 258 | * {@code null} if unknown. A {@link DocumentsProvider} can update this |
| 259 | * field using events from {@link OnCloseListener} or other reliable |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 260 | * {@link ParcelFileDescriptor} transports. |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 261 | * <p> |
| 262 | * Type: INTEGER (long) |
| 263 | * |
| 264 | * @see System#currentTimeMillis() |
| 265 | */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 266 | public static final String COLUMN_LAST_MODIFIED = "last_modified"; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 267 | |
| 268 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 269 | * Specific icon resource ID for a document. This column is optional, |
| 270 | * and may be {@code null} to use a platform-provided default icon based |
| 271 | * on {@link #COLUMN_MIME_TYPE}. |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 272 | * <p> |
| 273 | * Type: INTEGER (int) |
| 274 | */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 275 | public static final String COLUMN_ICON = "icon"; |
Jeff Sharkey | 6651669 | 2013-08-06 11:26:10 -0700 | [diff] [blame] | 276 | |
| 277 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 278 | * Flags that apply to a document. This column is required. |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 279 | * <p> |
| 280 | * Type: INTEGER (int) |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 281 | * |
| 282 | * @see #FLAG_SUPPORTS_WRITE |
| 283 | * @see #FLAG_SUPPORTS_DELETE |
| 284 | * @see #FLAG_SUPPORTS_THUMBNAIL |
| 285 | * @see #FLAG_DIR_PREFERS_GRID |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 286 | * @see #FLAG_DIR_PREFERS_LAST_MODIFIED |
Tomasz Mikolajewski | a8057a9 | 2015-11-16 11:41:28 +0900 | [diff] [blame] | 287 | * @see #FLAG_VIRTUAL_DOCUMENT |
Tomasz Mikolajewski | cbcd394 | 2016-01-28 12:39:25 +0900 | [diff] [blame] | 288 | * @see #FLAG_SUPPORTS_COPY |
| 289 | * @see #FLAG_SUPPORTS_MOVE |
| 290 | * @see #FLAG_SUPPORTS_REMOVE |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 291 | */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 292 | public static final String COLUMN_FLAGS = "flags"; |
| 293 | |
| 294 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 295 | * Size of a document, in bytes, or {@code null} if unknown. This column |
| 296 | * is required. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 297 | * <p> |
| 298 | * Type: INTEGER (long) |
| 299 | */ |
| 300 | public static final String COLUMN_SIZE = OpenableColumns.SIZE; |
| 301 | |
| 302 | /** |
| 303 | * MIME type of a document which is a directory that may contain |
| 304 | * additional documents. |
| 305 | * |
| 306 | * @see #COLUMN_MIME_TYPE |
| 307 | */ |
| 308 | public static final String MIME_TYPE_DIR = "vnd.android.document/directory"; |
| 309 | |
| 310 | /** |
| 311 | * Flag indicating that a document can be represented as a thumbnail. |
| 312 | * |
| 313 | * @see #COLUMN_FLAGS |
| 314 | * @see DocumentsContract#getDocumentThumbnail(ContentResolver, Uri, |
| 315 | * Point, CancellationSignal) |
| 316 | * @see DocumentsProvider#openDocumentThumbnail(String, Point, |
| 317 | * android.os.CancellationSignal) |
| 318 | */ |
| 319 | public static final int FLAG_SUPPORTS_THUMBNAIL = 1; |
| 320 | |
| 321 | /** |
| 322 | * Flag indicating that a document supports writing. |
| 323 | * <p> |
| 324 | * When a document is opened with {@link Intent#ACTION_OPEN_DOCUMENT}, |
| 325 | * the calling application is granted both |
| 326 | * {@link Intent#FLAG_GRANT_READ_URI_PERMISSION} and |
| 327 | * {@link Intent#FLAG_GRANT_WRITE_URI_PERMISSION}. However, the actual |
| 328 | * writability of a document may change over time, for example due to |
| 329 | * remote access changes. This flag indicates that a document client can |
| 330 | * expect {@link ContentResolver#openOutputStream(Uri)} to succeed. |
Steve McKay | 83df8c0 | 2015-09-16 15:07:31 -0700 | [diff] [blame] | 331 | * |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 332 | * @see #COLUMN_FLAGS |
| 333 | */ |
| 334 | public static final int FLAG_SUPPORTS_WRITE = 1 << 1; |
| 335 | |
| 336 | /** |
| 337 | * Flag indicating that a document is deletable. |
| 338 | * |
| 339 | * @see #COLUMN_FLAGS |
| 340 | * @see DocumentsContract#deleteDocument(ContentResolver, Uri) |
| 341 | * @see DocumentsProvider#deleteDocument(String) |
| 342 | */ |
| 343 | public static final int FLAG_SUPPORTS_DELETE = 1 << 2; |
| 344 | |
| 345 | /** |
| 346 | * Flag indicating that a document is a directory that supports creation |
| 347 | * of new files within it. Only valid when {@link #COLUMN_MIME_TYPE} is |
| 348 | * {@link #MIME_TYPE_DIR}. |
| 349 | * |
| 350 | * @see #COLUMN_FLAGS |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 351 | * @see DocumentsProvider#createDocument(String, String, String) |
| 352 | */ |
| 353 | public static final int FLAG_DIR_SUPPORTS_CREATE = 1 << 3; |
| 354 | |
| 355 | /** |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 356 | * Flag indicating that a directory prefers its contents be shown in a |
| 357 | * larger format grid. Usually suitable when a directory contains mostly |
| 358 | * pictures. Only valid when {@link #COLUMN_MIME_TYPE} is |
| 359 | * {@link #MIME_TYPE_DIR}. |
| 360 | * |
| 361 | * @see #COLUMN_FLAGS |
| 362 | */ |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 363 | public static final int FLAG_DIR_PREFERS_GRID = 1 << 4; |
Jeff Sharkey | d182bb6 | 2013-09-07 14:45:03 -0700 | [diff] [blame] | 364 | |
| 365 | /** |
| 366 | * Flag indicating that a directory prefers its contents be sorted by |
| 367 | * {@link #COLUMN_LAST_MODIFIED}. Only valid when |
| 368 | * {@link #COLUMN_MIME_TYPE} is {@link #MIME_TYPE_DIR}. |
| 369 | * |
| 370 | * @see #COLUMN_FLAGS |
| 371 | */ |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 372 | public static final int FLAG_DIR_PREFERS_LAST_MODIFIED = 1 << 5; |
Jeff Sharkey | f6db154 | 2013-09-13 13:42:19 -0700 | [diff] [blame] | 373 | |
| 374 | /** |
Jeff Sharkey | b7e1255 | 2014-05-21 22:22:03 -0700 | [diff] [blame] | 375 | * Flag indicating that a document can be renamed. |
| 376 | * |
| 377 | * @see #COLUMN_FLAGS |
Tomasz Mikolajewski | 90a7533 | 2016-07-13 10:14:59 +0900 | [diff] [blame] | 378 | * @see DocumentsContract#renameDocument(ContentResolver, Uri, |
Jeff Sharkey | b7e1255 | 2014-05-21 22:22:03 -0700 | [diff] [blame] | 379 | * String) |
| 380 | * @see DocumentsProvider#renameDocument(String, String) |
| 381 | */ |
| 382 | public static final int FLAG_SUPPORTS_RENAME = 1 << 6; |
| 383 | |
| 384 | /** |
Tomasz Mikolajewski | 74fe181 | 2015-06-12 17:13:26 -0700 | [diff] [blame] | 385 | * Flag indicating that a document can be copied to another location |
| 386 | * within the same document provider. |
| 387 | * |
| 388 | * @see #COLUMN_FLAGS |
Tomasz Mikolajewski | 90a7533 | 2016-07-13 10:14:59 +0900 | [diff] [blame] | 389 | * @see DocumentsContract#copyDocument(ContentResolver, Uri, Uri) |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 390 | * @see DocumentsProvider#copyDocument(String, String) |
Tomasz Mikolajewski | 74fe181 | 2015-06-12 17:13:26 -0700 | [diff] [blame] | 391 | */ |
| 392 | public static final int FLAG_SUPPORTS_COPY = 1 << 7; |
| 393 | |
| 394 | /** |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 395 | * Flag indicating that a document can be moved to another location |
| 396 | * within the same document provider. |
| 397 | * |
| 398 | * @see #COLUMN_FLAGS |
Tomasz Mikolajewski | 90a7533 | 2016-07-13 10:14:59 +0900 | [diff] [blame] | 399 | * @see DocumentsContract#moveDocument(ContentResolver, Uri, Uri, Uri) |
Tomasz Mikolajewski | d46ecbc | 2016-01-25 14:26:54 +0900 | [diff] [blame] | 400 | * @see DocumentsProvider#moveDocument(String, String, String) |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 401 | */ |
| 402 | public static final int FLAG_SUPPORTS_MOVE = 1 << 8; |
| 403 | |
| 404 | /** |
Tomasz Mikolajewski | a8057a9 | 2015-11-16 11:41:28 +0900 | [diff] [blame] | 405 | * Flag indicating that a document is virtual, and doesn't have byte |
| 406 | * representation in the MIME type specified as {@link #COLUMN_MIME_TYPE}. |
| 407 | * |
Tomasz Mikolajewski | 099f951 | 2016-12-09 10:19:46 +0900 | [diff] [blame] | 408 | * <p><em>Virtual documents must have at least one alternative streamable |
| 409 | * format via {@link DocumentsProvider#openTypedDocument}</em> |
| 410 | * |
Tomasz Mikolajewski | a8057a9 | 2015-11-16 11:41:28 +0900 | [diff] [blame] | 411 | * @see #COLUMN_FLAGS |
| 412 | * @see #COLUMN_MIME_TYPE |
| 413 | * @see DocumentsProvider#openTypedDocument(String, String, Bundle, |
| 414 | * android.os.CancellationSignal) |
Tomasz Mikolajewski | d99964f | 2016-02-15 11:16:32 +0900 | [diff] [blame] | 415 | * @see DocumentsProvider#getDocumentStreamTypes(String, String) |
Tomasz Mikolajewski | a8057a9 | 2015-11-16 11:41:28 +0900 | [diff] [blame] | 416 | */ |
Tomasz Mikolajewski | 7539565 | 2016-01-07 07:19:22 +0000 | [diff] [blame] | 417 | public static final int FLAG_VIRTUAL_DOCUMENT = 1 << 9; |
Tomasz Mikolajewski | a8057a9 | 2015-11-16 11:41:28 +0900 | [diff] [blame] | 418 | |
| 419 | /** |
Tomasz Mikolajewski | 9b055e1 | 2016-02-01 13:01:34 +0900 | [diff] [blame] | 420 | * Flag indicating that a document can be removed from a parent. |
| 421 | * |
| 422 | * @see #COLUMN_FLAGS |
Tomasz Mikolajewski | 90a7533 | 2016-07-13 10:14:59 +0900 | [diff] [blame] | 423 | * @see DocumentsContract#removeDocument(ContentResolver, Uri, Uri) |
Tomasz Mikolajewski | 9b055e1 | 2016-02-01 13:01:34 +0900 | [diff] [blame] | 424 | * @see DocumentsProvider#removeDocument(String, String) |
| 425 | */ |
| 426 | public static final int FLAG_SUPPORTS_REMOVE = 1 << 10; |
| 427 | |
| 428 | /** |
Ben Lin | bd036d8 | 2016-12-15 15:41:08 -0800 | [diff] [blame] | 429 | * Flag indicating that a document has settings that can be configured by user. |
| 430 | * |
| 431 | * @see #COLUMN_FLAGS |
| 432 | * @see #ACTION_DOCUMENT_SETTINGS |
| 433 | */ |
| 434 | public static final int FLAG_SUPPORTS_SETTINGS = 1 << 11; |
| 435 | |
| 436 | /** |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 437 | * Flag indicating that a Web link can be obtained for the document. |
| 438 | * |
| 439 | * @see #COLUMN_FLAGS |
| 440 | * @see DocumentsContract#createWebLinkIntent(PackageManager, Uri, Bundle) |
| 441 | */ |
| 442 | public static final int FLAG_WEB_LINKABLE = 1 << 12; |
| 443 | |
| 444 | /** |
Steve McKay | 168e464 | 2016-03-14 13:02:56 -0700 | [diff] [blame] | 445 | * Flag indicating that a document is not complete, likely its |
| 446 | * contents are being downloaded. Partial files cannot be opened, |
| 447 | * copied, moved in the UI. But they can be deleted and retried |
| 448 | * if they represent a failed download. |
| 449 | * |
| 450 | * @see #COLUMN_FLAGS |
| 451 | * @hide |
| 452 | */ |
| 453 | public static final int FLAG_PARTIAL = 1 << 16; |
Julian Mancini | b650515 | 2017-06-27 13:29:09 -0700 | [diff] [blame] | 454 | |
| 455 | /** |
| 456 | * Flag indicating that a document has available metadata that can be read |
| 457 | * using DocumentsContract#getDocumentMetadata |
| 458 | * @hide |
| 459 | */ |
| 460 | public static final int FLAG_SUPPORTS_METADATA = 1 << 17; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 463 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 464 | * Constants related to a root of documents, including {@link Cursor} column |
| 465 | * names and flags. A root is the start of a tree of documents, such as a |
| 466 | * physical storage device, or an account. Each root starts at the directory |
| 467 | * referenced by {@link Root#COLUMN_DOCUMENT_ID}, which can recursively |
| 468 | * contain both documents and directories. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 469 | * <p> |
| 470 | * All columns are <em>read-only</em> to client applications. |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 471 | */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 472 | public final static class Root { |
| 473 | private Root() { |
| 474 | } |
| 475 | |
Jeff Sharkey | a5599ef | 2013-08-15 16:17:41 -0700 | [diff] [blame] | 476 | /** |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 477 | * Unique ID of a root. This ID is both provided by and interpreted by a |
| 478 | * {@link DocumentsProvider}, and should be treated as an opaque value |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 479 | * by client applications. This column is required. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 480 | * <p> |
| 481 | * Type: STRING |
| 482 | */ |
| 483 | public static final String COLUMN_ROOT_ID = "root_id"; |
| 484 | |
| 485 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 486 | * Flags that apply to a root. This column is required. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 487 | * <p> |
| 488 | * Type: INTEGER (int) |
| 489 | * |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 490 | * @see #FLAG_LOCAL_ONLY |
| 491 | * @see #FLAG_SUPPORTS_CREATE |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 492 | * @see #FLAG_SUPPORTS_RECENTS |
| 493 | * @see #FLAG_SUPPORTS_SEARCH |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 494 | */ |
| 495 | public static final String COLUMN_FLAGS = "flags"; |
| 496 | |
| 497 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 498 | * Icon resource ID for a root. This column is required. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 499 | * <p> |
| 500 | * Type: INTEGER (int) |
| 501 | */ |
| 502 | public static final String COLUMN_ICON = "icon"; |
| 503 | |
| 504 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 505 | * Title for a root, which will be shown to a user. This column is |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 506 | * required. For a single storage service surfacing multiple accounts as |
| 507 | * different roots, this title should be the name of the service. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 508 | * <p> |
| 509 | * Type: STRING |
| 510 | */ |
| 511 | public static final String COLUMN_TITLE = "title"; |
| 512 | |
| 513 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 514 | * Summary for this root, which may be shown to a user. This column is |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 515 | * optional, and may be {@code null}. For a single storage service |
| 516 | * surfacing multiple accounts as different roots, this summary should |
| 517 | * be the name of the account. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 518 | * <p> |
| 519 | * Type: STRING |
| 520 | */ |
| 521 | public static final String COLUMN_SUMMARY = "summary"; |
| 522 | |
| 523 | /** |
| 524 | * Document which is a directory that represents the top directory of |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 525 | * this root. This column is required. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 526 | * <p> |
| 527 | * Type: STRING |
| 528 | * |
| 529 | * @see Document#COLUMN_DOCUMENT_ID |
| 530 | */ |
| 531 | public static final String COLUMN_DOCUMENT_ID = "document_id"; |
| 532 | |
| 533 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 534 | * Number of bytes available in this root. This column is optional, and |
| 535 | * may be {@code null} if unknown or unbounded. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 536 | * <p> |
| 537 | * Type: INTEGER (long) |
| 538 | */ |
| 539 | public static final String COLUMN_AVAILABLE_BYTES = "available_bytes"; |
| 540 | |
| 541 | /** |
Tomasz Mikolajewski | 3f78e17 | 2015-06-25 16:17:26 +0900 | [diff] [blame] | 542 | * Capacity of a root in bytes. This column is optional, and may be |
| 543 | * {@code null} if unknown or unbounded. |
Tomasz Mikolajewski | 3f78e17 | 2015-06-25 16:17:26 +0900 | [diff] [blame] | 544 | * <p> |
| 545 | * Type: INTEGER (long) |
| 546 | */ |
| 547 | public static final String COLUMN_CAPACITY_BYTES = "capacity_bytes"; |
| 548 | |
| 549 | /** |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 550 | * MIME types supported by this root. This column is optional, and if |
| 551 | * {@code null} the root is assumed to support all MIME types. Multiple |
| 552 | * MIME types can be separated by a newline. For example, a root |
| 553 | * supporting audio might return "audio/*\napplication/x-flac". |
Jeff Sharkey | 923396b | 2013-09-05 13:55:35 -0700 | [diff] [blame] | 554 | * <p> |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 555 | * Type: STRING |
Jeff Sharkey | 923396b | 2013-09-05 13:55:35 -0700 | [diff] [blame] | 556 | */ |
| 557 | public static final String COLUMN_MIME_TYPES = "mime_types"; |
| 558 | |
Garfield Tan | a7e852e | 2017-02-21 12:34:08 -0800 | [diff] [blame] | 559 | /** |
| 560 | * MIME type for a root. |
| 561 | */ |
Jeff Sharkey | a61dc8e | 2013-09-05 17:14:14 -0700 | [diff] [blame] | 562 | public static final String MIME_TYPE_ITEM = "vnd.android.document/root"; |
| 563 | |
Jeff Sharkey | 923396b | 2013-09-05 13:55:35 -0700 | [diff] [blame] | 564 | /** |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 565 | * Flag indicating that at least one directory under this root supports |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 566 | * creating content. Roots with this flag will be shown when an |
| 567 | * application interacts with {@link Intent#ACTION_CREATE_DOCUMENT}. |
Jeff Sharkey | 20d96d8 | 2013-07-30 17:08:39 -0700 | [diff] [blame] | 568 | * |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 569 | * @see #COLUMN_FLAGS |
Jeff Sharkey | 20d96d8 | 2013-07-30 17:08:39 -0700 | [diff] [blame] | 570 | */ |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 571 | public static final int FLAG_SUPPORTS_CREATE = 1; |
Jeff Sharkey | 20d96d8 | 2013-07-30 17:08:39 -0700 | [diff] [blame] | 572 | |
| 573 | /** |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 574 | * Flag indicating that this root offers content that is strictly local |
| 575 | * on the device. That is, no network requests are made for the content. |
| 576 | * |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 577 | * @see #COLUMN_FLAGS |
| 578 | * @see Intent#EXTRA_LOCAL_ONLY |
Jeff Sharkey | 20d96d8 | 2013-07-30 17:08:39 -0700 | [diff] [blame] | 579 | */ |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 580 | public static final int FLAG_LOCAL_ONLY = 1 << 1; |
| 581 | |
Jeff Sharkey | 20d96d8 | 2013-07-30 17:08:39 -0700 | [diff] [blame] | 582 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 583 | * Flag indicating that this root can be queried to provide recently |
| 584 | * modified documents. |
Jeff Sharkey | 251097b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 585 | * |
| 586 | * @see #COLUMN_FLAGS |
| 587 | * @see DocumentsContract#buildRecentDocumentsUri(String, String) |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 588 | * @see DocumentsProvider#queryRecentDocuments(String, String[]) |
Jeff Sharkey | 251097b | 2013-09-02 15:07:28 -0700 | [diff] [blame] | 589 | */ |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 590 | public static final int FLAG_SUPPORTS_RECENTS = 1 << 2; |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 591 | |
| 592 | /** |
| 593 | * Flag indicating that this root supports search. |
| 594 | * |
| 595 | * @see #COLUMN_FLAGS |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 596 | * @see DocumentsContract#buildSearchDocumentsUri(String, String, |
| 597 | * String) |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 598 | * @see DocumentsProvider#querySearchDocuments(String, String, |
| 599 | * String[]) |
| 600 | */ |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 601 | public static final int FLAG_SUPPORTS_SEARCH = 1 << 3; |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 602 | |
| 603 | /** |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 604 | * Flag indicating that this root supports testing parent child |
| 605 | * relationships. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 606 | * |
| 607 | * @see #COLUMN_FLAGS |
| 608 | * @see DocumentsProvider#isChildDocument(String, String) |
| 609 | */ |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 610 | public static final int FLAG_SUPPORTS_IS_CHILD = 1 << 4; |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 611 | |
| 612 | /** |
Garfield Tan | 8787703 | 2017-03-22 12:01:14 -0700 | [diff] [blame] | 613 | * Flag indicating that this root can be ejected. |
| 614 | * |
| 615 | * @see #COLUMN_FLAGS |
| 616 | * @see DocumentsContract#ejectRoot(ContentResolver, Uri) |
| 617 | * @see DocumentsProvider#ejectRoot(String) |
| 618 | */ |
| 619 | public static final int FLAG_SUPPORTS_EJECT = 1 << 5; |
| 620 | |
| 621 | /** |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 622 | * Flag indicating that this root is currently empty. This may be used |
| 623 | * to hide the root when opening documents, but the root will still be |
| 624 | * shown when creating documents and {@link #FLAG_SUPPORTS_CREATE} is |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 625 | * also set. If the value of this flag changes, such as when a root |
| 626 | * becomes non-empty, you must send a content changed notification for |
| 627 | * {@link DocumentsContract#buildRootsUri(String)}. |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 628 | * |
| 629 | * @see #COLUMN_FLAGS |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 630 | * @see ContentResolver#notifyChange(Uri, |
| 631 | * android.database.ContentObserver, boolean) |
| 632 | * @hide |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 633 | */ |
Jeff Sharkey | 6efba22 | 2013-09-27 16:44:11 -0700 | [diff] [blame] | 634 | public static final int FLAG_EMPTY = 1 << 16; |
| 635 | |
| 636 | /** |
Aga Wronska | 1719b35 | 2016-03-21 11:28:03 -0700 | [diff] [blame] | 637 | * Flag indicating that this root should only be visible to advanced |
| 638 | * users. |
| 639 | * |
| 640 | * @see #COLUMN_FLAGS |
| 641 | * @hide |
| 642 | */ |
| 643 | public static final int FLAG_ADVANCED = 1 << 17; |
| 644 | |
| 645 | /** |
Jeff Sharkey | 1407d4c | 2015-04-12 21:52:24 -0700 | [diff] [blame] | 646 | * Flag indicating that this root has settings. |
| 647 | * |
| 648 | * @see #COLUMN_FLAGS |
| 649 | * @see DocumentsContract#ACTION_DOCUMENT_ROOT_SETTINGS |
| 650 | * @hide |
| 651 | */ |
Aga Wronska | 1719b35 | 2016-03-21 11:28:03 -0700 | [diff] [blame] | 652 | public static final int FLAG_HAS_SETTINGS = 1 << 18; |
Steve McKay | ba23e54 | 2016-03-02 15:15:00 -0800 | [diff] [blame] | 653 | |
| 654 | /** |
| 655 | * Flag indicating that this root is on removable SD card storage. |
| 656 | * |
| 657 | * @see #COLUMN_FLAGS |
| 658 | * @hide |
| 659 | */ |
Aga Wronska | 1719b35 | 2016-03-21 11:28:03 -0700 | [diff] [blame] | 660 | public static final int FLAG_REMOVABLE_SD = 1 << 19; |
Steve McKay | ba23e54 | 2016-03-02 15:15:00 -0800 | [diff] [blame] | 661 | |
| 662 | /** |
| 663 | * Flag indicating that this root is on removable USB storage. |
| 664 | * |
| 665 | * @see #COLUMN_FLAGS |
| 666 | * @hide |
| 667 | */ |
Aga Wronska | 1719b35 | 2016-03-21 11:28:03 -0700 | [diff] [blame] | 668 | public static final int FLAG_REMOVABLE_USB = 1 << 20; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 669 | } |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 670 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 671 | /** |
| 672 | * Optional boolean flag included in a directory {@link Cursor#getExtras()} |
| 673 | * indicating that a document provider is still loading data. For example, a |
| 674 | * provider has returned some results, but is still waiting on an |
| 675 | * outstanding network request. The provider must send a content changed |
| 676 | * notification when loading is finished. |
| 677 | * |
| 678 | * @see ContentResolver#notifyChange(Uri, android.database.ContentObserver, |
| 679 | * boolean) |
| 680 | */ |
| 681 | public static final String EXTRA_LOADING = "loading"; |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 682 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 683 | /** |
| 684 | * Optional string included in a directory {@link Cursor#getExtras()} |
| 685 | * providing an informational message that should be shown to a user. For |
| 686 | * example, a provider may wish to indicate that not all documents are |
| 687 | * available. |
| 688 | */ |
| 689 | public static final String EXTRA_INFO = "info"; |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 690 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 691 | /** |
| 692 | * Optional string included in a directory {@link Cursor#getExtras()} |
| 693 | * providing an error message that should be shown to a user. For example, a |
| 694 | * provider may wish to indicate that a network error occurred. The user may |
| 695 | * choose to retry, resulting in a new query. |
| 696 | */ |
| 697 | public static final String EXTRA_ERROR = "error"; |
| 698 | |
Steve McKay | d3afdee | 2015-11-19 17:27:12 -0800 | [diff] [blame] | 699 | /** |
| 700 | * Optional result (I'm thinking boolean) answer to a question. |
| 701 | * {@hide} |
| 702 | */ |
| 703 | public static final String EXTRA_RESULT = "result"; |
| 704 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 705 | /** {@hide} */ |
| 706 | public static final String METHOD_CREATE_DOCUMENT = "android:createDocument"; |
| 707 | /** {@hide} */ |
Jeff Sharkey | b7e1255 | 2014-05-21 22:22:03 -0700 | [diff] [blame] | 708 | public static final String METHOD_RENAME_DOCUMENT = "android:renameDocument"; |
| 709 | /** {@hide} */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 710 | public static final String METHOD_DELETE_DOCUMENT = "android:deleteDocument"; |
Tomasz Mikolajewski | 74fe181 | 2015-06-12 17:13:26 -0700 | [diff] [blame] | 711 | /** {@hide} */ |
| 712 | public static final String METHOD_COPY_DOCUMENT = "android:copyDocument"; |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 713 | /** {@hide} */ |
| 714 | public static final String METHOD_MOVE_DOCUMENT = "android:moveDocument"; |
Steve McKay | d3afdee | 2015-11-19 17:27:12 -0800 | [diff] [blame] | 715 | /** {@hide} */ |
| 716 | public static final String METHOD_IS_CHILD_DOCUMENT = "android:isChildDocument"; |
Tomasz Mikolajewski | cbcd394 | 2016-01-28 12:39:25 +0900 | [diff] [blame] | 717 | /** {@hide} */ |
| 718 | public static final String METHOD_REMOVE_DOCUMENT = "android:removeDocument"; |
Ben Lin | e7822fb | 2016-06-24 15:21:08 -0700 | [diff] [blame] | 719 | /** {@hide} */ |
| 720 | public static final String METHOD_EJECT_ROOT = "android:ejectRoot"; |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 721 | /** {@hide} */ |
Garfield Tan | 3f6b68a | 2016-11-01 14:13:38 -0700 | [diff] [blame] | 722 | public static final String METHOD_FIND_DOCUMENT_PATH = "android:findDocumentPath"; |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 723 | /** {@hide} */ |
| 724 | public static final String METHOD_CREATE_WEB_LINK_INTENT = "android:createWebLinkIntent"; |
Julian Mancini | b650515 | 2017-06-27 13:29:09 -0700 | [diff] [blame] | 725 | /** {@hide} */ |
| 726 | public static final String METHOD_GET_DOCUMENT_METADATA = "android:getDocumentMetadata"; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 727 | |
| 728 | /** {@hide} */ |
Tomasz Mikolajewski | d46ecbc | 2016-01-25 14:26:54 +0900 | [diff] [blame] | 729 | public static final String EXTRA_PARENT_URI = "parentUri"; |
| 730 | /** {@hide} */ |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 731 | public static final String EXTRA_URI = "uri"; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 732 | |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 733 | /** |
| 734 | * @see #createWebLinkIntent(ContentResolver, Uri, Bundle) |
| 735 | * {@hide} |
| 736 | */ |
| 737 | public static final String EXTRA_OPTIONS = "options"; |
| 738 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 739 | private static final String PATH_ROOT = "root"; |
| 740 | private static final String PATH_RECENT = "recent"; |
| 741 | private static final String PATH_DOCUMENT = "document"; |
| 742 | private static final String PATH_CHILDREN = "children"; |
| 743 | private static final String PATH_SEARCH = "search"; |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 744 | private static final String PATH_TREE = "tree"; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 745 | |
| 746 | private static final String PARAM_QUERY = "query"; |
Jeff Sharkey | 4ec9739 | 2013-09-10 12:04:26 -0700 | [diff] [blame] | 747 | private static final String PARAM_MANAGE = "manage"; |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 748 | |
| 749 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 750 | * Build URI representing the roots of a document provider. When queried, a |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 751 | * provider will return one or more rows with columns defined by |
| 752 | * {@link Root}. |
| 753 | * |
| 754 | * @see DocumentsProvider#queryRoots(String[]) |
| 755 | */ |
| 756 | public static Uri buildRootsUri(String authority) { |
| 757 | return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) |
| 758 | .authority(authority).appendPath(PATH_ROOT).build(); |
| 759 | } |
| 760 | |
| 761 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 762 | * Build URI representing the given {@link Root#COLUMN_ROOT_ID} in a |
Jeff Sharkey | a61dc8e | 2013-09-05 17:14:14 -0700 | [diff] [blame] | 763 | * document provider. |
| 764 | * |
| 765 | * @see #getRootId(Uri) |
| 766 | */ |
| 767 | public static Uri buildRootUri(String authority, String rootId) { |
| 768 | return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) |
| 769 | .authority(authority).appendPath(PATH_ROOT).appendPath(rootId).build(); |
| 770 | } |
| 771 | |
| 772 | /** |
Steve McKay | b67bfbf | 2015-12-08 17:02:03 -0800 | [diff] [blame] | 773 | * Builds URI for user home directory on external (local) storage. |
| 774 | * {@hide} |
| 775 | */ |
| 776 | public static Uri buildHomeUri() { |
| 777 | // TODO: Avoid this type of interpackage copying. Added here to avoid |
| 778 | // direct coupling, but not ideal. |
Garfield Tan | 92b96ba | 2016-11-01 14:33:48 -0700 | [diff] [blame] | 779 | return DocumentsContract.buildRootUri(EXTERNAL_STORAGE_PROVIDER_AUTHORITY, "home"); |
Steve McKay | b67bfbf | 2015-12-08 17:02:03 -0800 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 783 | * Build URI representing the recently modified documents of a specific root |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 784 | * in a document provider. When queried, a provider will return zero or more |
| 785 | * rows with columns defined by {@link Document}. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 786 | * |
| 787 | * @see DocumentsProvider#queryRecentDocuments(String, String[]) |
| 788 | * @see #getRootId(Uri) |
| 789 | */ |
| 790 | public static Uri buildRecentDocumentsUri(String authority, String rootId) { |
| 791 | return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) |
| 792 | .authority(authority).appendPath(PATH_ROOT).appendPath(rootId) |
| 793 | .appendPath(PATH_RECENT).build(); |
| 794 | } |
| 795 | |
| 796 | /** |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 797 | * Build URI representing access to descendant documents of the given |
| 798 | * {@link Document#COLUMN_DOCUMENT_ID}. |
| 799 | * |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 800 | * @see #getTreeDocumentId(Uri) |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 801 | */ |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 802 | public static Uri buildTreeDocumentUri(String authority, String documentId) { |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 803 | return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(authority) |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 804 | .appendPath(PATH_TREE).appendPath(documentId).build(); |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 805 | } |
| 806 | |
| 807 | /** |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 808 | * Build URI representing the target {@link Document#COLUMN_DOCUMENT_ID} in |
| 809 | * a document provider. When queried, a provider will return a single row |
| 810 | * with columns defined by {@link Document}. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 811 | * |
| 812 | * @see DocumentsProvider#queryDocument(String, String[]) |
| 813 | * @see #getDocumentId(Uri) |
| 814 | */ |
| 815 | public static Uri buildDocumentUri(String authority, String documentId) { |
| 816 | return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) |
| 817 | .authority(authority).appendPath(PATH_DOCUMENT).appendPath(documentId).build(); |
| 818 | } |
| 819 | |
| 820 | /** |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 821 | * Build URI representing the target {@link Document#COLUMN_DOCUMENT_ID} in |
| 822 | * a document provider. When queried, a provider will return a single row |
| 823 | * with columns defined by {@link Document}. |
| 824 | * <p> |
| 825 | * However, instead of directly accessing the target document, the returned |
| 826 | * URI will leverage access granted through a subtree URI, typically |
| 827 | * returned by {@link Intent#ACTION_OPEN_DOCUMENT_TREE}. The target document |
| 828 | * must be a descendant (child, grandchild, etc) of the subtree. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 829 | * <p> |
| 830 | * This is typically used to access documents under a user-selected |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 831 | * directory tree, since it doesn't require the user to separately confirm |
| 832 | * each new document access. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 833 | * |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 834 | * @param treeUri the subtree to leverage to gain access to the target |
| 835 | * document. The target directory must be a descendant of this |
| 836 | * subtree. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 837 | * @param documentId the target document, which the caller may not have |
| 838 | * direct access to. |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 839 | * @see Intent#ACTION_OPEN_DOCUMENT_TREE |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 840 | * @see DocumentsProvider#isChildDocument(String, String) |
| 841 | * @see #buildDocumentUri(String, String) |
| 842 | */ |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 843 | public static Uri buildDocumentUriUsingTree(Uri treeUri, String documentId) { |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 844 | return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 845 | .authority(treeUri.getAuthority()).appendPath(PATH_TREE) |
| 846 | .appendPath(getTreeDocumentId(treeUri)).appendPath(PATH_DOCUMENT) |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 847 | .appendPath(documentId).build(); |
| 848 | } |
| 849 | |
| 850 | /** {@hide} */ |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 851 | public static Uri buildDocumentUriMaybeUsingTree(Uri baseUri, String documentId) { |
| 852 | if (isTreeUri(baseUri)) { |
| 853 | return buildDocumentUriUsingTree(baseUri, documentId); |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 854 | } else { |
| 855 | return buildDocumentUri(baseUri.getAuthority(), documentId); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /** |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 860 | * Build URI representing the children of the target directory in a document |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 861 | * provider. When queried, a provider will return zero or more rows with |
| 862 | * columns defined by {@link Document}. |
| 863 | * |
| 864 | * @param parentDocumentId the document to return children for, which must |
| 865 | * be a directory with MIME type of |
| 866 | * {@link Document#MIME_TYPE_DIR}. |
| 867 | * @see DocumentsProvider#queryChildDocuments(String, String[], String) |
| 868 | * @see #getDocumentId(Uri) |
| 869 | */ |
| 870 | public static Uri buildChildDocumentsUri(String authority, String parentDocumentId) { |
| 871 | return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(authority) |
| 872 | .appendPath(PATH_DOCUMENT).appendPath(parentDocumentId).appendPath(PATH_CHILDREN) |
| 873 | .build(); |
| 874 | } |
| 875 | |
| 876 | /** |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 877 | * Build URI representing the children of the target directory in a document |
| 878 | * provider. When queried, a provider will return zero or more rows with |
| 879 | * columns defined by {@link Document}. |
| 880 | * <p> |
| 881 | * However, instead of directly accessing the target directory, the returned |
| 882 | * URI will leverage access granted through a subtree URI, typically |
| 883 | * returned by {@link Intent#ACTION_OPEN_DOCUMENT_TREE}. The target |
| 884 | * directory must be a descendant (child, grandchild, etc) of the subtree. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 885 | * <p> |
| 886 | * This is typically used to access documents under a user-selected |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 887 | * directory tree, since it doesn't require the user to separately confirm |
| 888 | * each new document access. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 889 | * |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 890 | * @param treeUri the subtree to leverage to gain access to the target |
| 891 | * document. The target directory must be a descendant of this |
| 892 | * subtree. |
| 893 | * @param parentDocumentId the document to return children for, which the |
| 894 | * caller may not have direct access to, and which must be a |
| 895 | * directory with MIME type of {@link Document#MIME_TYPE_DIR}. |
| 896 | * @see Intent#ACTION_OPEN_DOCUMENT_TREE |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 897 | * @see DocumentsProvider#isChildDocument(String, String) |
| 898 | * @see #buildChildDocumentsUri(String, String) |
| 899 | */ |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 900 | public static Uri buildChildDocumentsUriUsingTree(Uri treeUri, String parentDocumentId) { |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 901 | return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT) |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 902 | .authority(treeUri.getAuthority()).appendPath(PATH_TREE) |
| 903 | .appendPath(getTreeDocumentId(treeUri)).appendPath(PATH_DOCUMENT) |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 904 | .appendPath(parentDocumentId).appendPath(PATH_CHILDREN).build(); |
| 905 | } |
| 906 | |
| 907 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 908 | * Build URI representing a search for matching documents under a specific |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 909 | * root in a document provider. When queried, a provider will return zero or |
| 910 | * more rows with columns defined by {@link Document}. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 911 | * |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 912 | * @see DocumentsProvider#querySearchDocuments(String, String, String[]) |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 913 | * @see #getRootId(Uri) |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 914 | * @see #getSearchDocumentsQuery(Uri) |
| 915 | */ |
| 916 | public static Uri buildSearchDocumentsUri( |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 917 | String authority, String rootId, String query) { |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 918 | return new Uri.Builder().scheme(ContentResolver.SCHEME_CONTENT).authority(authority) |
Jeff Sharkey | 3e1189b | 2013-09-12 21:59:06 -0700 | [diff] [blame] | 919 | .appendPath(PATH_ROOT).appendPath(rootId).appendPath(PATH_SEARCH) |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 920 | .appendQueryParameter(PARAM_QUERY, query).build(); |
| 921 | } |
| 922 | |
| 923 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 924 | * Test if the given URI represents a {@link Document} backed by a |
Jeff Sharkey | ee2f7df | 2013-09-26 11:32:30 -0700 | [diff] [blame] | 925 | * {@link DocumentsProvider}. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 926 | * |
| 927 | * @see #buildDocumentUri(String, String) |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 928 | * @see #buildDocumentUriUsingTree(Uri, String) |
Jeff Sharkey | ee2f7df | 2013-09-26 11:32:30 -0700 | [diff] [blame] | 929 | */ |
Steve McKay | 323ee3e | 2015-09-25 16:02:56 -0700 | [diff] [blame] | 930 | public static boolean isDocumentUri(Context context, @Nullable Uri uri) { |
| 931 | if (isContentUri(uri) && isDocumentsProvider(context, uri.getAuthority())) { |
| 932 | final List<String> paths = uri.getPathSegments(); |
| 933 | if (paths.size() == 2) { |
| 934 | return PATH_DOCUMENT.equals(paths.get(0)); |
| 935 | } else if (paths.size() == 4) { |
| 936 | return PATH_TREE.equals(paths.get(0)) && PATH_DOCUMENT.equals(paths.get(2)); |
| 937 | } |
Jeff Sharkey | ee2f7df | 2013-09-26 11:32:30 -0700 | [diff] [blame] | 938 | } |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 939 | return false; |
| 940 | } |
Jeff Sharkey | ee2f7df | 2013-09-26 11:32:30 -0700 | [diff] [blame] | 941 | |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 942 | /** {@hide} */ |
Steve McKay | 323ee3e | 2015-09-25 16:02:56 -0700 | [diff] [blame] | 943 | public static boolean isRootUri(Context context, @Nullable Uri uri) { |
| 944 | if (isContentUri(uri) && isDocumentsProvider(context, uri.getAuthority())) { |
| 945 | final List<String> paths = uri.getPathSegments(); |
| 946 | return (paths.size() == 2 && PATH_ROOT.equals(paths.get(0))); |
| 947 | } |
| 948 | return false; |
| 949 | } |
| 950 | |
| 951 | /** {@hide} */ |
| 952 | public static boolean isContentUri(@Nullable Uri uri) { |
| 953 | return uri != null && ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()); |
| 954 | } |
| 955 | |
Tomasz Mikolajewski | 7db9c81 | 2016-01-28 09:50:01 +0900 | [diff] [blame] | 956 | /** |
| 957 | * Test if the given URI represents a {@link Document} tree. |
| 958 | * |
| 959 | * @see #buildTreeDocumentUri(String, String) |
Tomasz Mikolajewski | 90a7533 | 2016-07-13 10:14:59 +0900 | [diff] [blame] | 960 | * @see #getTreeDocumentId(Uri) |
Tomasz Mikolajewski | 7db9c81 | 2016-01-28 09:50:01 +0900 | [diff] [blame] | 961 | */ |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 962 | public static boolean isTreeUri(Uri uri) { |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 963 | final List<String> paths = uri.getPathSegments(); |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 964 | return (paths.size() >= 2 && PATH_TREE.equals(paths.get(0))); |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | private static boolean isDocumentsProvider(Context context, String authority) { |
Jeff Sharkey | d2e1e81 | 2013-10-09 13:31:13 -0700 | [diff] [blame] | 968 | final Intent intent = new Intent(PROVIDER_INTERFACE); |
| 969 | final List<ResolveInfo> infos = context.getPackageManager() |
| 970 | .queryIntentContentProviders(intent, 0); |
| 971 | for (ResolveInfo info : infos) { |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 972 | if (authority.equals(info.providerInfo.authority)) { |
Jeff Sharkey | d2e1e81 | 2013-10-09 13:31:13 -0700 | [diff] [blame] | 973 | return true; |
| 974 | } |
Jeff Sharkey | ee2f7df | 2013-09-26 11:32:30 -0700 | [diff] [blame] | 975 | } |
| 976 | return false; |
| 977 | } |
| 978 | |
| 979 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 980 | * Extract the {@link Root#COLUMN_ROOT_ID} from the given URI. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 981 | */ |
| 982 | public static String getRootId(Uri rootUri) { |
| 983 | final List<String> paths = rootUri.getPathSegments(); |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 984 | if (paths.size() >= 2 && PATH_ROOT.equals(paths.get(0))) { |
| 985 | return paths.get(1); |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 986 | } |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 987 | throw new IllegalArgumentException("Invalid URI: " + rootUri); |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 988 | } |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 989 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 990 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 991 | * Extract the {@link Document#COLUMN_DOCUMENT_ID} from the given URI. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 992 | * |
| 993 | * @see #isDocumentUri(Context, Uri) |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 994 | */ |
| 995 | public static String getDocumentId(Uri documentUri) { |
| 996 | final List<String> paths = documentUri.getPathSegments(); |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 997 | if (paths.size() >= 2 && PATH_DOCUMENT.equals(paths.get(0))) { |
| 998 | return paths.get(1); |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 999 | } |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 1000 | if (paths.size() >= 4 && PATH_TREE.equals(paths.get(0)) |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 1001 | && PATH_DOCUMENT.equals(paths.get(2))) { |
| 1002 | return paths.get(3); |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1003 | } |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 1004 | throw new IllegalArgumentException("Invalid URI: " + documentUri); |
| 1005 | } |
| 1006 | |
| 1007 | /** |
| 1008 | * Extract the via {@link Document#COLUMN_DOCUMENT_ID} from the given URI. |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 1009 | */ |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 1010 | public static String getTreeDocumentId(Uri documentUri) { |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 1011 | final List<String> paths = documentUri.getPathSegments(); |
Jeff Sharkey | b9fbb72 | 2014-06-04 16:42:47 -0700 | [diff] [blame] | 1012 | if (paths.size() >= 2 && PATH_TREE.equals(paths.get(0))) { |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 1013 | return paths.get(1); |
| 1014 | } |
| 1015 | throw new IllegalArgumentException("Invalid URI: " + documentUri); |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1016 | } |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1017 | |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1018 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 1019 | * Extract the search query from a URI built by |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1020 | * {@link #buildSearchDocumentsUri(String, String, String)}. |
| 1021 | */ |
| 1022 | public static String getSearchDocumentsQuery(Uri searchDocumentsUri) { |
| 1023 | return searchDocumentsUri.getQueryParameter(PARAM_QUERY); |
Jeff Sharkey | 20d96d8 | 2013-07-30 17:08:39 -0700 | [diff] [blame] | 1024 | } |
| 1025 | |
Jeff Sharkey | 4ec9739 | 2013-09-10 12:04:26 -0700 | [diff] [blame] | 1026 | /** {@hide} */ |
| 1027 | public static Uri setManageMode(Uri uri) { |
| 1028 | return uri.buildUpon().appendQueryParameter(PARAM_MANAGE, "true").build(); |
| 1029 | } |
| 1030 | |
| 1031 | /** {@hide} */ |
| 1032 | public static boolean isManageMode(Uri uri) { |
| 1033 | return uri.getBooleanQueryParameter(PARAM_MANAGE, false); |
| 1034 | } |
| 1035 | |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1036 | /** |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 1037 | * Return thumbnail representing the document at the given URI. Callers are |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1038 | * responsible for their own in-memory caching. |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1039 | * |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1040 | * @param documentUri document to return thumbnail for, which must have |
| 1041 | * {@link Document#FLAG_SUPPORTS_THUMBNAIL} set. |
| 1042 | * @param size optimal thumbnail size desired. A provider may return a |
| 1043 | * thumbnail of a different size, but never more than double the |
| 1044 | * requested size. |
Jeff Sharkey | e8c00d8 | 2013-10-15 15:46:10 -0700 | [diff] [blame] | 1045 | * @param signal signal used to indicate if caller is no longer interested |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1046 | * in the thumbnail. |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1047 | * @return decoded thumbnail, or {@code null} if problem was encountered. |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1048 | * @see DocumentsProvider#openDocumentThumbnail(String, Point, |
| 1049 | * android.os.CancellationSignal) |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1050 | */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1051 | public static Bitmap getDocumentThumbnail( |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1052 | ContentResolver resolver, Uri documentUri, Point size, CancellationSignal signal) |
| 1053 | throws FileNotFoundException { |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1054 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1055 | documentUri.getAuthority()); |
| 1056 | try { |
| 1057 | return getDocumentThumbnail(client, documentUri, size, signal); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1058 | } catch (Exception e) { |
Jeff Sharkey | 3381931 | 2013-10-29 11:56:37 -0700 | [diff] [blame] | 1059 | if (!(e instanceof OperationCanceledException)) { |
| 1060 | Log.w(TAG, "Failed to load thumbnail for " + documentUri + ": " + e); |
| 1061 | } |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1062 | rethrowIfNecessary(resolver, e); |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1063 | return null; |
| 1064 | } finally { |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1065 | ContentProviderClient.releaseQuietly(client); |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1066 | } |
| 1067 | } |
| 1068 | |
| 1069 | /** {@hide} */ |
| 1070 | public static Bitmap getDocumentThumbnail( |
| 1071 | ContentProviderClient client, Uri documentUri, Point size, CancellationSignal signal) |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1072 | throws RemoteException, IOException { |
Jeff Sharkey | 6398343 | 2013-08-21 11:33:50 -0700 | [diff] [blame] | 1073 | final Bundle openOpts = new Bundle(); |
Jeff Sharkey | 5b836f2 | 2014-08-27 14:46:32 -0700 | [diff] [blame] | 1074 | openOpts.putParcelable(ContentResolver.EXTRA_SIZE, size); |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1075 | |
Jeff Sharkey | 9d0843d | 2013-05-07 12:41:33 -0700 | [diff] [blame] | 1076 | AssetFileDescriptor afd = null; |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 1077 | Bitmap bitmap = null; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1078 | try { |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1079 | afd = client.openTypedAssetFileDescriptor(documentUri, "image/*", openOpts, signal); |
Jeff Sharkey | 9d0843d | 2013-05-07 12:41:33 -0700 | [diff] [blame] | 1080 | |
| 1081 | final FileDescriptor fd = afd.getFileDescriptor(); |
Jeff Sharkey | 6398343 | 2013-08-21 11:33:50 -0700 | [diff] [blame] | 1082 | final long offset = afd.getStartOffset(); |
Jeff Sharkey | 9d0843d | 2013-05-07 12:41:33 -0700 | [diff] [blame] | 1083 | |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1084 | // Try seeking on the returned FD, since it gives us the most |
| 1085 | // optimal decode path; otherwise fall back to buffering. |
| 1086 | BufferedInputStream is = null; |
| 1087 | try { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 1088 | Os.lseek(fd, offset, SEEK_SET); |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1089 | } catch (ErrnoException e) { |
| 1090 | is = new BufferedInputStream(new FileInputStream(fd), THUMBNAIL_BUFFER_SIZE); |
| 1091 | is.mark(THUMBNAIL_BUFFER_SIZE); |
Jeff Sharkey | 6398343 | 2013-08-21 11:33:50 -0700 | [diff] [blame] | 1092 | } |
Jeff Sharkey | 9d0843d | 2013-05-07 12:41:33 -0700 | [diff] [blame] | 1093 | |
Jeff Sharkey | 6398343 | 2013-08-21 11:33:50 -0700 | [diff] [blame] | 1094 | // We requested a rough thumbnail size, but the remote size may have |
| 1095 | // returned something giant, so defensively scale down as needed. |
| 1096 | final BitmapFactory.Options opts = new BitmapFactory.Options(); |
| 1097 | opts.inJustDecodeBounds = true; |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1098 | if (is != null) { |
| 1099 | BitmapFactory.decodeStream(is, null, opts); |
Jeff Sharkey | 6398343 | 2013-08-21 11:33:50 -0700 | [diff] [blame] | 1100 | } else { |
| 1101 | BitmapFactory.decodeFileDescriptor(fd, null, opts); |
| 1102 | } |
Jeff Sharkey | 9d0843d | 2013-05-07 12:41:33 -0700 | [diff] [blame] | 1103 | |
Jeff Sharkey | 6398343 | 2013-08-21 11:33:50 -0700 | [diff] [blame] | 1104 | final int widthSample = opts.outWidth / size.x; |
| 1105 | final int heightSample = opts.outHeight / size.y; |
| 1106 | |
| 1107 | opts.inJustDecodeBounds = false; |
| 1108 | opts.inSampleSize = Math.min(widthSample, heightSample); |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1109 | if (is != null) { |
| 1110 | is.reset(); |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 1111 | bitmap = BitmapFactory.decodeStream(is, null, opts); |
Jeff Sharkey | 6398343 | 2013-08-21 11:33:50 -0700 | [diff] [blame] | 1112 | } else { |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1113 | try { |
Elliott Hughes | 34385d3 | 2014-04-28 11:11:32 -0700 | [diff] [blame] | 1114 | Os.lseek(fd, offset, SEEK_SET); |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1115 | } catch (ErrnoException e) { |
| 1116 | e.rethrowAsIOException(); |
| 1117 | } |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 1118 | bitmap = BitmapFactory.decodeFileDescriptor(fd, null, opts); |
| 1119 | } |
| 1120 | |
| 1121 | // Transform the bitmap if requested. We use a side-channel to |
| 1122 | // communicate the orientation, since EXIF thumbnails don't contain |
| 1123 | // the rotation flags of the original image. |
| 1124 | final Bundle extras = afd.getExtras(); |
| 1125 | final int orientation = (extras != null) ? extras.getInt(EXTRA_ORIENTATION, 0) : 0; |
| 1126 | if (orientation != 0) { |
| 1127 | final int width = bitmap.getWidth(); |
| 1128 | final int height = bitmap.getHeight(); |
| 1129 | |
| 1130 | final Matrix m = new Matrix(); |
| 1131 | m.setRotate(orientation, width / 2, height / 2); |
| 1132 | bitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, m, false); |
Jeff Sharkey | 6398343 | 2013-08-21 11:33:50 -0700 | [diff] [blame] | 1133 | } |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1134 | } finally { |
Jeff Sharkey | 9d0843d | 2013-05-07 12:41:33 -0700 | [diff] [blame] | 1135 | IoUtils.closeQuietly(afd); |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1136 | } |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 1137 | |
| 1138 | return bitmap; |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Jeff Sharkey | 5b83f85 | 2013-08-14 18:29:19 -0700 | [diff] [blame] | 1141 | /** |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1142 | * Create a new document with given MIME type and display name. |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1143 | * |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1144 | * @param parentDocumentUri directory with {@link Document#FLAG_DIR_SUPPORTS_CREATE} |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1145 | * @param mimeType MIME type of new document |
| 1146 | * @param displayName name of new document |
| 1147 | * @return newly created document, or {@code null} if failed |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1148 | */ |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1149 | public static Uri createDocument(ContentResolver resolver, Uri parentDocumentUri, |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1150 | String mimeType, String displayName) throws FileNotFoundException { |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1151 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1152 | parentDocumentUri.getAuthority()); |
| 1153 | try { |
| 1154 | return createDocument(client, parentDocumentUri, mimeType, displayName); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1155 | } catch (Exception e) { |
| 1156 | Log.w(TAG, "Failed to create document", e); |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1157 | rethrowIfNecessary(resolver, e); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1158 | return null; |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1159 | } finally { |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1160 | ContentProviderClient.releaseQuietly(client); |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1161 | } |
| 1162 | } |
| 1163 | |
| 1164 | /** {@hide} */ |
| 1165 | public static Uri createDocument(ContentProviderClient client, Uri parentDocumentUri, |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1166 | String mimeType, String displayName) throws RemoteException { |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1167 | final Bundle in = new Bundle(); |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 1168 | in.putParcelable(DocumentsContract.EXTRA_URI, parentDocumentUri); |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1169 | in.putString(Document.COLUMN_MIME_TYPE, mimeType); |
| 1170 | in.putString(Document.COLUMN_DISPLAY_NAME, displayName); |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1171 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1172 | final Bundle out = client.call(METHOD_CREATE_DOCUMENT, null, in); |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 1173 | return out.getParcelable(DocumentsContract.EXTRA_URI); |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1174 | } |
Jeff Sharkey | 5b83f85 | 2013-08-14 18:29:19 -0700 | [diff] [blame] | 1175 | |
Steve McKay | d3afdee | 2015-11-19 17:27:12 -0800 | [diff] [blame] | 1176 | /** {@hide} */ |
| 1177 | public static boolean isChildDocument(ContentProviderClient client, Uri parentDocumentUri, |
| 1178 | Uri childDocumentUri) throws RemoteException { |
| 1179 | |
| 1180 | final Bundle in = new Bundle(); |
| 1181 | in.putParcelable(DocumentsContract.EXTRA_URI, parentDocumentUri); |
| 1182 | in.putParcelable(DocumentsContract.EXTRA_TARGET_URI, childDocumentUri); |
| 1183 | |
| 1184 | final Bundle out = client.call(METHOD_IS_CHILD_DOCUMENT, null, in); |
| 1185 | if (out == null) { |
| 1186 | throw new RemoteException("Failed to get a reponse from isChildDocument query."); |
| 1187 | } |
| 1188 | if (!out.containsKey(DocumentsContract.EXTRA_RESULT)) { |
| 1189 | throw new RemoteException("Response did not include result field.."); |
| 1190 | } |
| 1191 | return out.getBoolean(DocumentsContract.EXTRA_RESULT); |
| 1192 | } |
| 1193 | |
Jeff Sharkey | 5b83f85 | 2013-08-14 18:29:19 -0700 | [diff] [blame] | 1194 | /** |
Jeff Sharkey | b7e1255 | 2014-05-21 22:22:03 -0700 | [diff] [blame] | 1195 | * Change the display name of an existing document. |
| 1196 | * <p> |
| 1197 | * If the underlying provider needs to create a new |
| 1198 | * {@link Document#COLUMN_DOCUMENT_ID} to represent the updated display |
| 1199 | * name, that new document is returned and the original document is no |
| 1200 | * longer valid. Otherwise, the original document is returned. |
| 1201 | * |
| 1202 | * @param documentUri document with {@link Document#FLAG_SUPPORTS_RENAME} |
| 1203 | * @param displayName updated name for document |
| 1204 | * @return the existing or new document after the rename, or {@code null} if |
| 1205 | * failed. |
| 1206 | */ |
| 1207 | public static Uri renameDocument(ContentResolver resolver, Uri documentUri, |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1208 | String displayName) throws FileNotFoundException { |
Jeff Sharkey | b7e1255 | 2014-05-21 22:22:03 -0700 | [diff] [blame] | 1209 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1210 | documentUri.getAuthority()); |
| 1211 | try { |
| 1212 | return renameDocument(client, documentUri, displayName); |
| 1213 | } catch (Exception e) { |
| 1214 | Log.w(TAG, "Failed to rename document", e); |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1215 | rethrowIfNecessary(resolver, e); |
Jeff Sharkey | b7e1255 | 2014-05-21 22:22:03 -0700 | [diff] [blame] | 1216 | return null; |
| 1217 | } finally { |
| 1218 | ContentProviderClient.releaseQuietly(client); |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | /** {@hide} */ |
| 1223 | public static Uri renameDocument(ContentProviderClient client, Uri documentUri, |
| 1224 | String displayName) throws RemoteException { |
| 1225 | final Bundle in = new Bundle(); |
| 1226 | in.putParcelable(DocumentsContract.EXTRA_URI, documentUri); |
| 1227 | in.putString(Document.COLUMN_DISPLAY_NAME, displayName); |
| 1228 | |
| 1229 | final Bundle out = client.call(METHOD_RENAME_DOCUMENT, null, in); |
| 1230 | final Uri outUri = out.getParcelable(DocumentsContract.EXTRA_URI); |
| 1231 | return (outUri != null) ? outUri : documentUri; |
| 1232 | } |
| 1233 | |
| 1234 | /** |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1235 | * Delete the given document. |
| 1236 | * |
Jeff Sharkey | ae9b51b | 2013-08-31 15:02:20 -0700 | [diff] [blame] | 1237 | * @param documentUri document with {@link Document#FLAG_SUPPORTS_DELETE} |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1238 | * @return if the document was deleted successfully. |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1239 | */ |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1240 | public static boolean deleteDocument(ContentResolver resolver, Uri documentUri) |
| 1241 | throws FileNotFoundException { |
Jeff Sharkey | de2b22f | 2013-09-11 17:33:06 -0700 | [diff] [blame] | 1242 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1243 | documentUri.getAuthority()); |
| 1244 | try { |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1245 | deleteDocument(client, documentUri); |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1246 | return true; |
| 1247 | } catch (Exception e) { |
| 1248 | Log.w(TAG, "Failed to delete document", e); |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1249 | rethrowIfNecessary(resolver, e); |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1250 | return false; |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1251 | } finally { |
| 1252 | ContentProviderClient.releaseQuietly(client); |
Jeff Sharkey | aeb16e2 | 2013-08-27 18:26:48 -0700 | [diff] [blame] | 1253 | } |
Jeff Sharkey | 5b83f85 | 2013-08-14 18:29:19 -0700 | [diff] [blame] | 1254 | } |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1255 | |
| 1256 | /** {@hide} */ |
| 1257 | public static void deleteDocument(ContentProviderClient client, Uri documentUri) |
| 1258 | throws RemoteException { |
| 1259 | final Bundle in = new Bundle(); |
Jeff Sharkey | 21de56a | 2014-04-05 19:05:24 -0700 | [diff] [blame] | 1260 | in.putParcelable(DocumentsContract.EXTRA_URI, documentUri); |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 1261 | |
| 1262 | client.call(METHOD_DELETE_DOCUMENT, null, in); |
| 1263 | } |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 1264 | |
| 1265 | /** |
Tomasz Mikolajewski | 74fe181 | 2015-06-12 17:13:26 -0700 | [diff] [blame] | 1266 | * Copies the given document. |
| 1267 | * |
| 1268 | * @param sourceDocumentUri document with {@link Document#FLAG_SUPPORTS_COPY} |
| 1269 | * @param targetParentDocumentUri document which will become a parent of the source |
| 1270 | * document's copy. |
| 1271 | * @return the copied document, or {@code null} if failed. |
Tomasz Mikolajewski | 74fe181 | 2015-06-12 17:13:26 -0700 | [diff] [blame] | 1272 | */ |
| 1273 | public static Uri copyDocument(ContentResolver resolver, Uri sourceDocumentUri, |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1274 | Uri targetParentDocumentUri) throws FileNotFoundException { |
Tomasz Mikolajewski | 74fe181 | 2015-06-12 17:13:26 -0700 | [diff] [blame] | 1275 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1276 | sourceDocumentUri.getAuthority()); |
| 1277 | try { |
| 1278 | return copyDocument(client, sourceDocumentUri, targetParentDocumentUri); |
| 1279 | } catch (Exception e) { |
| 1280 | Log.w(TAG, "Failed to copy document", e); |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1281 | rethrowIfNecessary(resolver, e); |
Tomasz Mikolajewski | 74fe181 | 2015-06-12 17:13:26 -0700 | [diff] [blame] | 1282 | return null; |
| 1283 | } finally { |
| 1284 | ContentProviderClient.releaseQuietly(client); |
| 1285 | } |
| 1286 | } |
| 1287 | |
| 1288 | /** {@hide} */ |
| 1289 | public static Uri copyDocument(ContentProviderClient client, Uri sourceDocumentUri, |
| 1290 | Uri targetParentDocumentUri) throws RemoteException { |
| 1291 | final Bundle in = new Bundle(); |
| 1292 | in.putParcelable(DocumentsContract.EXTRA_URI, sourceDocumentUri); |
| 1293 | in.putParcelable(DocumentsContract.EXTRA_TARGET_URI, targetParentDocumentUri); |
| 1294 | |
| 1295 | final Bundle out = client.call(METHOD_COPY_DOCUMENT, null, in); |
| 1296 | return out.getParcelable(DocumentsContract.EXTRA_URI); |
| 1297 | } |
| 1298 | |
| 1299 | /** |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 1300 | * Moves the given document under a new parent. |
| 1301 | * |
| 1302 | * @param sourceDocumentUri document with {@link Document#FLAG_SUPPORTS_MOVE} |
Tomasz Mikolajewski | d46ecbc | 2016-01-25 14:26:54 +0900 | [diff] [blame] | 1303 | * @param sourceParentDocumentUri parent document of the document to move. |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 1304 | * @param targetParentDocumentUri document which will become a new parent of the source |
| 1305 | * document. |
| 1306 | * @return the moved document, or {@code null} if failed. |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 1307 | */ |
| 1308 | public static Uri moveDocument(ContentResolver resolver, Uri sourceDocumentUri, |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1309 | Uri sourceParentDocumentUri, Uri targetParentDocumentUri) throws FileNotFoundException { |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 1310 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1311 | sourceDocumentUri.getAuthority()); |
| 1312 | try { |
Tomasz Mikolajewski | dcb4efe | 2016-02-10 19:14:49 +0900 | [diff] [blame] | 1313 | return moveDocument(client, sourceDocumentUri, sourceParentDocumentUri, |
Tomasz Mikolajewski | d46ecbc | 2016-01-25 14:26:54 +0900 | [diff] [blame] | 1314 | targetParentDocumentUri); |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 1315 | } catch (Exception e) { |
| 1316 | Log.w(TAG, "Failed to move document", e); |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1317 | rethrowIfNecessary(resolver, e); |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 1318 | return null; |
| 1319 | } finally { |
| 1320 | ContentProviderClient.releaseQuietly(client); |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | /** {@hide} */ |
| 1325 | public static Uri moveDocument(ContentProviderClient client, Uri sourceDocumentUri, |
Tomasz Mikolajewski | d46ecbc | 2016-01-25 14:26:54 +0900 | [diff] [blame] | 1326 | Uri sourceParentDocumentUri, Uri targetParentDocumentUri) throws RemoteException { |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 1327 | final Bundle in = new Bundle(); |
| 1328 | in.putParcelable(DocumentsContract.EXTRA_URI, sourceDocumentUri); |
Tomasz Mikolajewski | d46ecbc | 2016-01-25 14:26:54 +0900 | [diff] [blame] | 1329 | in.putParcelable(DocumentsContract.EXTRA_PARENT_URI, sourceParentDocumentUri); |
Tomasz Mikolajewski | a375a99 | 2015-06-25 15:39:27 +0900 | [diff] [blame] | 1330 | in.putParcelable(DocumentsContract.EXTRA_TARGET_URI, targetParentDocumentUri); |
| 1331 | |
| 1332 | final Bundle out = client.call(METHOD_MOVE_DOCUMENT, null, in); |
| 1333 | return out.getParcelable(DocumentsContract.EXTRA_URI); |
| 1334 | } |
| 1335 | |
| 1336 | /** |
Tomasz Mikolajewski | cbcd394 | 2016-01-28 12:39:25 +0900 | [diff] [blame] | 1337 | * Removes the given document from a parent directory. |
| 1338 | * |
| 1339 | * <p>In contrast to {@link #deleteDocument} it requires specifying the parent. |
| 1340 | * This method is especially useful if the document can be in multiple parents. |
| 1341 | * |
| 1342 | * @param documentUri document with {@link Document#FLAG_SUPPORTS_REMOVE} |
| 1343 | * @param parentDocumentUri parent document of the document to remove. |
| 1344 | * @return true if the document was removed successfully. |
| 1345 | */ |
| 1346 | public static boolean removeDocument(ContentResolver resolver, Uri documentUri, |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1347 | Uri parentDocumentUri) throws FileNotFoundException { |
Tomasz Mikolajewski | cbcd394 | 2016-01-28 12:39:25 +0900 | [diff] [blame] | 1348 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1349 | documentUri.getAuthority()); |
| 1350 | try { |
| 1351 | removeDocument(client, documentUri, parentDocumentUri); |
| 1352 | return true; |
| 1353 | } catch (Exception e) { |
| 1354 | Log.w(TAG, "Failed to remove document", e); |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1355 | rethrowIfNecessary(resolver, e); |
Tomasz Mikolajewski | cbcd394 | 2016-01-28 12:39:25 +0900 | [diff] [blame] | 1356 | return false; |
| 1357 | } finally { |
| 1358 | ContentProviderClient.releaseQuietly(client); |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | /** {@hide} */ |
| 1363 | public static void removeDocument(ContentProviderClient client, Uri documentUri, |
| 1364 | Uri parentDocumentUri) throws RemoteException { |
| 1365 | final Bundle in = new Bundle(); |
| 1366 | in.putParcelable(DocumentsContract.EXTRA_URI, documentUri); |
| 1367 | in.putParcelable(DocumentsContract.EXTRA_PARENT_URI, parentDocumentUri); |
| 1368 | |
| 1369 | client.call(METHOD_REMOVE_DOCUMENT, null, in); |
| 1370 | } |
| 1371 | |
Garfield Tan | 8787703 | 2017-03-22 12:01:14 -0700 | [diff] [blame] | 1372 | /** |
| 1373 | * Ejects the given root. It throws {@link IllegalStateException} when ejection failed. |
| 1374 | * |
| 1375 | * @param rootUri root with {@link Root#FLAG_SUPPORTS_EJECT} to be ejected |
| 1376 | */ |
| 1377 | public static void ejectRoot(ContentResolver resolver, Uri rootUri) { |
Ben Lin | e7822fb | 2016-06-24 15:21:08 -0700 | [diff] [blame] | 1378 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1379 | rootUri.getAuthority()); |
| 1380 | try { |
Garfield Tan | 8787703 | 2017-03-22 12:01:14 -0700 | [diff] [blame] | 1381 | ejectRoot(client, rootUri); |
| 1382 | } catch (RemoteException e) { |
| 1383 | e.rethrowAsRuntimeException(); |
Ben Lin | e7822fb | 2016-06-24 15:21:08 -0700 | [diff] [blame] | 1384 | } finally { |
| 1385 | ContentProviderClient.releaseQuietly(client); |
| 1386 | } |
| 1387 | } |
| 1388 | |
| 1389 | /** {@hide} */ |
Garfield Tan | 8787703 | 2017-03-22 12:01:14 -0700 | [diff] [blame] | 1390 | public static void ejectRoot(ContentProviderClient client, Uri rootUri) |
Ben Lin | e7822fb | 2016-06-24 15:21:08 -0700 | [diff] [blame] | 1391 | throws RemoteException { |
| 1392 | final Bundle in = new Bundle(); |
| 1393 | in.putParcelable(DocumentsContract.EXTRA_URI, rootUri); |
| 1394 | |
Garfield Tan | 8787703 | 2017-03-22 12:01:14 -0700 | [diff] [blame] | 1395 | client.call(METHOD_EJECT_ROOT, null, in); |
Ben Lin | e7822fb | 2016-06-24 15:21:08 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
Tomasz Mikolajewski | cbcd394 | 2016-01-28 12:39:25 +0900 | [diff] [blame] | 1398 | /** |
Julian Mancini | b650515 | 2017-06-27 13:29:09 -0700 | [diff] [blame] | 1399 | * Returns metadata associated with the document. The type of metadata returned |
| 1400 | * is specific to the document type. For example image files will largely return EXIF |
| 1401 | * metadata. |
| 1402 | * |
| 1403 | * <p>The returned {@link Bundle} will contain zero or more entries. |
| 1404 | * <p>Each entry represents a specific type of metadata. |
| 1405 | * |
| 1406 | * <p>if tags == null, then a list of default tags will be used. |
| 1407 | * |
| 1408 | * @param documentUri a Document URI |
| 1409 | * @param tags an array of keys to choose which data are added to the Bundle. If the Document |
| 1410 | * is a JPG or ExifInterface compatible, send keys from {@link ExifInterface}. |
| 1411 | * If tags are null, a set of default tags will be used. If the tags don't |
| 1412 | * match with any relevant data, they will not be added to the Bundle. |
| 1413 | * @return a Bundle of Bundles. If metadata exists within the Bundle, there will also |
| 1414 | * be a String under DocumentsContract.METADATA_TYPES that will return a String[] of the |
| 1415 | * types of metadata gathered. |
| 1416 | * |
| 1417 | * <pre><code> |
| 1418 | * Bundle metadata = DocumentsContract.getDocumentMetadata(resolver, imageDocUri, tags); |
| 1419 | * int imageLength = metadata.getInt(ExifInterface.TAG_IMAGE_LENGTH); |
| 1420 | * </code></pre> |
| 1421 | * |
| 1422 | * {@hide} |
| 1423 | */ |
| 1424 | public static Bundle getDocumentMetadata(ContentResolver resolver, Uri documentUri, |
| 1425 | @Nullable String[] tags) |
| 1426 | throws FileNotFoundException { |
| 1427 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1428 | documentUri.getAuthority()); |
| 1429 | |
| 1430 | try { |
| 1431 | return getDocumentMetadata(client, documentUri, tags); |
| 1432 | } catch (Exception e) { |
| 1433 | Log.w(TAG, "Failed to get document metadata"); |
| 1434 | rethrowIfNecessary(resolver, e); |
| 1435 | return null; |
| 1436 | } finally { |
| 1437 | ContentProviderClient.releaseQuietly(client); |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | /** |
| 1442 | * Returns metadata associated with the document. The type of metadata returned |
| 1443 | * is specific to the document type. For example image files will largely return EXIF |
| 1444 | * metadata. |
| 1445 | * |
| 1446 | * <p>The returned {@link Bundle} will contain zero or more entries. |
| 1447 | * <p>Each entry represents a specific type of metadata. |
| 1448 | * |
| 1449 | * <p>if tags == null, then a list of default tags will be used. |
| 1450 | * |
| 1451 | * @param documentUri a Document URI |
| 1452 | * @param tags an array of keys to choose which data are added to the Bundle. If the Document |
| 1453 | * is a JPG or ExifInterface compatible, send keys from {@link ExifInterface}. |
| 1454 | * If tags are null, a set of default tags will be used. If the tags don't |
| 1455 | * match with any relevant data, they will not be added to the Bundle. |
| 1456 | * @return a Bundle of Bundles. If metadata exists within the Bundle, there will also |
| 1457 | * be a String under DocumentsContract.METADATA_TYPES that will return a String[] of the |
| 1458 | * types of metadata gathered. |
| 1459 | * |
| 1460 | * <pre><code> |
| 1461 | * Bundle metadata = DocumentsContract.getDocumentMetadata(client, imageDocUri, tags); |
| 1462 | * int imageLength = metadata.getInt(ExifInterface.TAG_IMAGE_LENGTH); |
| 1463 | * </code></pre> |
| 1464 | * |
| 1465 | * {@hide} |
| 1466 | */ |
| 1467 | public static Bundle getDocumentMetadata(ContentProviderClient client, |
| 1468 | Uri documentUri, @Nullable String[] tags) throws RemoteException { |
| 1469 | final Bundle in = new Bundle(); |
| 1470 | in.putParcelable(EXTRA_URI, documentUri); |
| 1471 | in.putStringArray(EXTRA_METADATA_TAGS, tags); |
| 1472 | |
| 1473 | final Bundle out = client.call(METHOD_GET_DOCUMENT_METADATA, null, in); |
| 1474 | |
| 1475 | if (out == null) { |
| 1476 | throw new RemoteException("Failed to get a response from getDocumentMetadata"); |
| 1477 | } |
| 1478 | return out; |
| 1479 | } |
| 1480 | |
| 1481 | /** |
Garfield Tan | b690b4d | 2017-03-01 16:05:23 -0800 | [diff] [blame] | 1482 | * Finds the canonical path from the top of the document tree. |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1483 | * |
Garfield Tan | b690b4d | 2017-03-01 16:05:23 -0800 | [diff] [blame] | 1484 | * The {@link Path#getPath()} of the return value contains the document ID |
| 1485 | * of all documents along the path from the top the document tree to the |
| 1486 | * requested document, both inclusive. |
| 1487 | * |
| 1488 | * The {@link Path#getRootId()} of the return value returns {@code null}. |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1489 | * |
| 1490 | * @param treeUri treeUri of the document which path is requested. |
Garfield Tan | b690b4d | 2017-03-01 16:05:23 -0800 | [diff] [blame] | 1491 | * @return the path of the document, or {@code null} if failed. |
Garfield Tan | 3f6b68a | 2016-11-01 14:13:38 -0700 | [diff] [blame] | 1492 | * @see DocumentsProvider#findDocumentPath(String, String) |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1493 | */ |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1494 | public static Path findDocumentPath(ContentResolver resolver, Uri treeUri) |
| 1495 | throws FileNotFoundException { |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1496 | checkArgument(isTreeUri(treeUri), treeUri + " is not a tree uri."); |
| 1497 | |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1498 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1499 | treeUri.getAuthority()); |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1500 | try { |
Garfield Tan | b690b4d | 2017-03-01 16:05:23 -0800 | [diff] [blame] | 1501 | return findDocumentPath(client, treeUri); |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1502 | } catch (Exception e) { |
| 1503 | Log.w(TAG, "Failed to find path", e); |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1504 | rethrowIfNecessary(resolver, e); |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1505 | return null; |
| 1506 | } finally { |
| 1507 | ContentProviderClient.releaseQuietly(client); |
| 1508 | } |
| 1509 | } |
| 1510 | |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1511 | /** |
Garfield Tan | b690b4d | 2017-03-01 16:05:23 -0800 | [diff] [blame] | 1512 | * Finds the canonical path. If uri is a document uri returns path from a root and |
| 1513 | * its associated root id. If uri is a tree uri returns the path from the top of |
| 1514 | * the tree. The {@link Path#getPath()} of the return value contains document ID |
| 1515 | * starts from the top of the tree or the root document to the requested document, |
| 1516 | * both inclusive. |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1517 | * |
Garfield Tan | b690b4d | 2017-03-01 16:05:23 -0800 | [diff] [blame] | 1518 | * Callers can expect the root ID returned from multiple calls to this method is |
| 1519 | * consistent. |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1520 | * |
| 1521 | * @param uri uri of the document which path is requested. It can be either a |
| 1522 | * plain document uri or a tree uri. |
| 1523 | * @return the path of the document. |
Garfield Tan | 3f6b68a | 2016-11-01 14:13:38 -0700 | [diff] [blame] | 1524 | * @see DocumentsProvider#findDocumentPath(String, String) |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1525 | * |
| 1526 | * {@hide} |
| 1527 | */ |
Garfield Tan | 0b3cf66 | 2016-10-31 12:59:45 -0700 | [diff] [blame] | 1528 | public static Path findDocumentPath(ContentProviderClient client, Uri uri) |
| 1529 | throws RemoteException { |
| 1530 | |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1531 | final Bundle in = new Bundle(); |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1532 | in.putParcelable(DocumentsContract.EXTRA_URI, uri); |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1533 | |
Garfield Tan | 3f6b68a | 2016-11-01 14:13:38 -0700 | [diff] [blame] | 1534 | final Bundle out = client.call(METHOD_FIND_DOCUMENT_PATH, null, in); |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1535 | |
| 1536 | return out.getParcelable(DocumentsContract.EXTRA_RESULT); |
| 1537 | } |
| 1538 | |
| 1539 | /** |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 1540 | * Creates an intent for obtaining a web link for the specified document. |
| 1541 | * |
| 1542 | * <p>Note, that due to internal limitations, if there is already a web link |
| 1543 | * intent created for the specified document but with different options, |
| 1544 | * then it may be overriden. |
| 1545 | * |
| 1546 | * <p>Providers are required to show confirmation UI for all new permissions granted |
| 1547 | * for the linked document. |
| 1548 | * |
Tomasz Mikolajewski | 463b686 | 2017-03-22 17:34:05 +0900 | [diff] [blame] | 1549 | * <p>If list of recipients is known, then it should be passed in options as |
| 1550 | * {@link Intent#EXTRA_EMAIL} as a list of email addresses. Note, that |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 1551 | * this is just a hint for the provider, which can ignore the list. In either |
| 1552 | * case the provider is required to show a UI for letting the user confirm |
| 1553 | * any new permission grants. |
| 1554 | * |
Tomasz Mikolajewski | 463b686 | 2017-03-22 17:34:05 +0900 | [diff] [blame] | 1555 | * <p>Note, that the entire <code>options</code> bundle will be sent to the provider |
| 1556 | * backing the passed <code>uri</code>. Make sure that you trust the provider |
| 1557 | * before passing any sensitive information. |
Tomasz Mikolajewski | f1d5540 | 2017-03-03 15:09:40 +0900 | [diff] [blame] | 1558 | * |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 1559 | * <p>Since this API may show a UI, it cannot be called from background. |
| 1560 | * |
| 1561 | * <p>In order to obtain the Web Link use code like this: |
| 1562 | * <pre><code> |
| 1563 | * void onSomethingHappened() { |
| 1564 | * IntentSender sender = DocumentsContract.createWebLinkIntent(<i>...</i>); |
| 1565 | * if (sender != null) { |
| 1566 | * startIntentSenderForResult( |
Tomasz Mikolajewski | f1d5540 | 2017-03-03 15:09:40 +0900 | [diff] [blame] | 1567 | * sender, |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 1568 | * WEB_LINK_REQUEST_CODE, |
| 1569 | * null, 0, 0, 0, null); |
| 1570 | * } |
| 1571 | * } |
| 1572 | * |
| 1573 | * <i>(...)</i> |
| 1574 | * |
| 1575 | * void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 1576 | * if (requestCode == WEB_LINK_REQUEST_CODE && resultCode == RESULT_OK) { |
| 1577 | * Uri weblinkUri = data.getData(); |
| 1578 | * <i>...</i> |
| 1579 | * } |
| 1580 | * } |
| 1581 | * </code></pre> |
| 1582 | * |
| 1583 | * @param uri uri for the document to create a link to. |
| 1584 | * @param options Extra information for generating the link. |
| 1585 | * @return an intent sender to obtain the web link, or null if the document |
| 1586 | * is not linkable, or creating the intent sender failed. |
| 1587 | * @see DocumentsProvider#createWebLinkIntent(String, Bundle) |
| 1588 | * @see Intent#EXTRA_EMAIL |
| 1589 | */ |
| 1590 | public static IntentSender createWebLinkIntent(ContentResolver resolver, Uri uri, |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1591 | Bundle options) throws FileNotFoundException { |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 1592 | final ContentProviderClient client = resolver.acquireUnstableContentProviderClient( |
| 1593 | uri.getAuthority()); |
| 1594 | try { |
| 1595 | return createWebLinkIntent(client, uri, options); |
| 1596 | } catch (Exception e) { |
| 1597 | Log.w(TAG, "Failed to create a web link intent", e); |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1598 | rethrowIfNecessary(resolver, e); |
Tomasz Mikolajewski | cf31656 | 2016-10-24 15:17:01 +0900 | [diff] [blame] | 1599 | return null; |
| 1600 | } finally { |
| 1601 | ContentProviderClient.releaseQuietly(client); |
| 1602 | } |
| 1603 | } |
| 1604 | |
| 1605 | /** |
| 1606 | * {@hide} |
| 1607 | */ |
| 1608 | public static IntentSender createWebLinkIntent(ContentProviderClient client, Uri uri, |
| 1609 | Bundle options) throws RemoteException { |
| 1610 | final Bundle in = new Bundle(); |
| 1611 | in.putParcelable(DocumentsContract.EXTRA_URI, uri); |
| 1612 | |
| 1613 | // Options may be provider specific, so put them in a separate bundle to |
| 1614 | // avoid overriding the Uri. |
| 1615 | if (options != null) { |
| 1616 | in.putBundle(EXTRA_OPTIONS, options); |
| 1617 | } |
| 1618 | |
| 1619 | final Bundle out = client.call(METHOD_CREATE_WEB_LINK_INTENT, null, in); |
| 1620 | return out.getParcelable(DocumentsContract.EXTRA_RESULT); |
| 1621 | } |
| 1622 | |
| 1623 | /** |
Jeff Sharkey | c1c8f3f | 2013-10-14 14:57:33 -0700 | [diff] [blame] | 1624 | * Open the given image for thumbnail purposes, using any embedded EXIF |
| 1625 | * thumbnail if available, and providing orientation hints from the parent |
| 1626 | * image. |
| 1627 | * |
| 1628 | * @hide |
| 1629 | */ |
| 1630 | public static AssetFileDescriptor openImageThumbnail(File file) throws FileNotFoundException { |
| 1631 | final ParcelFileDescriptor pfd = ParcelFileDescriptor.open( |
| 1632 | file, ParcelFileDescriptor.MODE_READ_ONLY); |
| 1633 | Bundle extras = null; |
| 1634 | |
| 1635 | try { |
| 1636 | final ExifInterface exif = new ExifInterface(file.getAbsolutePath()); |
| 1637 | |
| 1638 | switch (exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1)) { |
| 1639 | case ExifInterface.ORIENTATION_ROTATE_90: |
| 1640 | extras = new Bundle(1); |
| 1641 | extras.putInt(EXTRA_ORIENTATION, 90); |
| 1642 | break; |
| 1643 | case ExifInterface.ORIENTATION_ROTATE_180: |
| 1644 | extras = new Bundle(1); |
| 1645 | extras.putInt(EXTRA_ORIENTATION, 180); |
| 1646 | break; |
| 1647 | case ExifInterface.ORIENTATION_ROTATE_270: |
| 1648 | extras = new Bundle(1); |
| 1649 | extras.putInt(EXTRA_ORIENTATION, 270); |
| 1650 | break; |
| 1651 | } |
| 1652 | |
| 1653 | final long[] thumb = exif.getThumbnailRange(); |
| 1654 | if (thumb != null) { |
| 1655 | return new AssetFileDescriptor(pfd, thumb[0], thumb[1], extras); |
| 1656 | } |
| 1657 | } catch (IOException e) { |
| 1658 | } |
| 1659 | |
| 1660 | return new AssetFileDescriptor(pfd, 0, AssetFileDescriptor.UNKNOWN_LENGTH, extras); |
| 1661 | } |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1662 | |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1663 | private static void rethrowIfNecessary(ContentResolver resolver, Exception e) |
| 1664 | throws FileNotFoundException { |
| 1665 | // We only want to throw applications targetting O and above |
| 1666 | if (resolver.getTargetSdkVersion() >= Build.VERSION_CODES.O) { |
| 1667 | if (e instanceof ParcelableException) { |
| 1668 | ((ParcelableException) e).maybeRethrow(FileNotFoundException.class); |
Ben Lin | 227e6e8 | 2017-03-13 15:36:13 -0700 | [diff] [blame] | 1669 | } else if (e instanceof RemoteException) { |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 1670 | ((RemoteException) e).rethrowAsRuntimeException(); |
| 1671 | } else if (e instanceof RuntimeException) { |
| 1672 | throw (RuntimeException) e; |
| 1673 | } |
| 1674 | } |
| 1675 | } |
| 1676 | |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1677 | /** |
Garfield Tan | 0b3cf66 | 2016-10-31 12:59:45 -0700 | [diff] [blame] | 1678 | * Holds a path from a document to a particular document under it. It |
| 1679 | * may also contains the root ID where the path resides. |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1680 | */ |
| 1681 | public static final class Path implements Parcelable { |
| 1682 | |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1683 | private final @Nullable String mRootId; |
| 1684 | private final List<String> mPath; |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1685 | |
| 1686 | /** |
| 1687 | * Creates a Path. |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1688 | * |
| 1689 | * @param rootId the ID of the root. May be null. |
Garfield Tan | 0b3cf66 | 2016-10-31 12:59:45 -0700 | [diff] [blame] | 1690 | * @param path the list of document ID from the parent document at |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1691 | * position 0 to the child document. |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1692 | */ |
Garfield Tan | 5f21480 | 2016-10-26 14:52:46 -0700 | [diff] [blame] | 1693 | public Path(@Nullable String rootId, List<String> path) { |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1694 | checkCollectionNotEmpty(path, "path"); |
| 1695 | checkCollectionElementsNotNull(path, "path"); |
| 1696 | |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1697 | mRootId = rootId; |
| 1698 | mPath = path; |
| 1699 | } |
| 1700 | |
Garfield Tan | 06940e1 | 2016-10-07 16:03:17 -0700 | [diff] [blame] | 1701 | /** |
| 1702 | * Returns the root id or null if the calling package doesn't have |
| 1703 | * permission to access root information. |
| 1704 | */ |
| 1705 | public @Nullable String getRootId() { |
| 1706 | return mRootId; |
| 1707 | } |
| 1708 | |
| 1709 | /** |
| 1710 | * Returns the path. The path is trimmed to the top of tree if |
| 1711 | * calling package doesn't have permission to access those |
| 1712 | * documents. |
| 1713 | */ |
| 1714 | public List<String> getPath() { |
| 1715 | return mPath; |
| 1716 | } |
| 1717 | |
| 1718 | @Override |
| 1719 | public boolean equals(Object o) { |
| 1720 | if (this == o) { |
| 1721 | return true; |
| 1722 | } |
| 1723 | if (o == null || !(o instanceof Path)) { |
| 1724 | return false; |
| 1725 | } |
| 1726 | Path path = (Path) o; |
| 1727 | return Objects.equals(mRootId, path.mRootId) && |
| 1728 | Objects.equals(mPath, path.mPath); |
| 1729 | } |
| 1730 | |
| 1731 | @Override |
| 1732 | public int hashCode() { |
| 1733 | return Objects.hash(mRootId, mPath); |
| 1734 | } |
| 1735 | |
| 1736 | @Override |
| 1737 | public String toString() { |
| 1738 | return new StringBuilder() |
| 1739 | .append("DocumentsContract.Path{") |
| 1740 | .append("rootId=") |
| 1741 | .append(mRootId) |
| 1742 | .append(", path=") |
| 1743 | .append(mPath) |
| 1744 | .append("}") |
| 1745 | .toString(); |
| 1746 | } |
| 1747 | |
Garfield Tan | aba97f3 | 2016-10-06 17:34:19 +0000 | [diff] [blame] | 1748 | @Override |
| 1749 | public void writeToParcel(Parcel dest, int flags) { |
| 1750 | dest.writeString(mRootId); |
| 1751 | dest.writeStringList(mPath); |
| 1752 | } |
| 1753 | |
| 1754 | @Override |
| 1755 | public int describeContents() { |
| 1756 | return 0; |
| 1757 | } |
| 1758 | |
| 1759 | public static final Creator<Path> CREATOR = new Creator<Path>() { |
| 1760 | @Override |
| 1761 | public Path createFromParcel(Parcel in) { |
| 1762 | final String rootId = in.readString(); |
| 1763 | final List<String> path = in.createStringArrayList(); |
| 1764 | return new Path(rootId, path); |
| 1765 | } |
| 1766 | |
| 1767 | @Override |
| 1768 | public Path[] newArray(int size) { |
| 1769 | return new Path[size]; |
| 1770 | } |
| 1771 | }; |
| 1772 | } |
Jeff Sharkey | 9ecfee0 | 2013-04-19 14:05:03 -0700 | [diff] [blame] | 1773 | } |