The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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.content; |
| 18 | |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 19 | import android.accounts.Account; |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 20 | import android.annotation.IntDef; |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 21 | import android.annotation.NonNull; |
Scott Kennedy | 9f78f65 | 2015-03-01 15:29:25 -0800 | [diff] [blame] | 22 | import android.annotation.Nullable; |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 23 | import android.annotation.RequiresPermission; |
Ivan Chiang | fd3415c | 2018-12-07 18:22:50 +0800 | [diff] [blame] | 24 | import android.annotation.SystemApi; |
Jeff Sharkey | a73b8fd | 2016-01-06 17:02:08 -0700 | [diff] [blame] | 25 | import android.annotation.TestApi; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 26 | import android.annotation.UnsupportedAppUsage; |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 27 | import android.annotation.UserIdInt; |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 28 | import android.app.ActivityManager; |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 29 | import android.app.ActivityThread; |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 30 | import android.app.AppGlobals; |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 31 | import android.app.UriGrantsManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.content.pm.PackageManager.NameNotFoundException; |
| 33 | import android.content.res.AssetFileDescriptor; |
| 34 | import android.content.res.Resources; |
| 35 | import android.database.ContentObserver; |
Jeff Brown | 825c513 | 2011-10-12 16:11:30 -0700 | [diff] [blame] | 36 | import android.database.CrossProcessCursorWrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.database.Cursor; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.database.IContentObserver; |
Jeff Sharkey | 4e5efa3 | 2018-10-04 19:21:53 -0600 | [diff] [blame] | 39 | import android.graphics.Bitmap; |
Jeff Sharkey | 4e5efa3 | 2018-10-04 19:21:53 -0600 | [diff] [blame] | 40 | import android.graphics.ImageDecoder; |
| 41 | import android.graphics.ImageDecoder.ImageInfo; |
| 42 | import android.graphics.ImageDecoder.Source; |
Jeff Sharkey | 5b836f2 | 2014-08-27 14:46:32 -0700 | [diff] [blame] | 43 | import android.graphics.Point; |
Daniel Nishi | c29d2b0 | 2016-06-30 12:20:41 -0700 | [diff] [blame] | 44 | import android.graphics.drawable.Drawable; |
Jeff Sharkey | 806bece | 2019-02-19 14:42:55 -0700 | [diff] [blame] | 45 | import android.graphics.drawable.Icon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | import android.net.Uri; |
| 47 | import android.os.Bundle; |
Jeff Brown | a7771df | 2012-05-07 20:06:46 -0700 | [diff] [blame] | 48 | import android.os.CancellationSignal; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 49 | import android.os.DeadObjectException; |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 50 | import android.os.IBinder; |
Jeff Brown | a7771df | 2012-05-07 20:06:46 -0700 | [diff] [blame] | 51 | import android.os.ICancellationSignal; |
| 52 | import android.os.OperationCanceledException; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | import android.os.ParcelFileDescriptor; |
| 54 | import android.os.RemoteException; |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 55 | import android.os.ServiceManager; |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 56 | import android.os.SystemClock; |
Dianne Hackborn | 5e03e2c | 2012-09-06 14:21:19 -0700 | [diff] [blame] | 57 | import android.os.UserHandle; |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 58 | import android.os.storage.StorageManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | import android.text.TextUtils; |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 60 | import android.util.EventLog; |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 61 | import android.util.Log; |
Jeff Sharkey | 4e5efa3 | 2018-10-04 19:21:53 -0600 | [diff] [blame] | 62 | import android.util.Size; |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 63 | |
Daniel Nishi | c29d2b0 | 2016-06-30 12:20:41 -0700 | [diff] [blame] | 64 | import com.android.internal.util.MimeIconUtils; |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 65 | import com.android.internal.util.Preconditions; |
| 66 | |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 67 | import dalvik.system.CloseGuard; |
| 68 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | import java.io.File; |
| 70 | import java.io.FileInputStream; |
| 71 | import java.io.FileNotFoundException; |
| 72 | import java.io.IOException; |
| 73 | import java.io.InputStream; |
| 74 | import java.io.OutputStream; |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 75 | import java.lang.annotation.Retention; |
| 76 | import java.lang.annotation.RetentionPolicy; |
Gilles Debunne | 03f0292 | 2010-06-09 14:11:45 -0700 | [diff] [blame] | 77 | import java.util.ArrayList; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | import java.util.List; |
Jeff Sharkey | 4e5efa3 | 2018-10-04 19:21:53 -0600 | [diff] [blame] | 79 | import java.util.Objects; |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 80 | import java.util.Random; |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 81 | import java.util.concurrent.atomic.AtomicBoolean; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | /** |
| 84 | * This class provides applications access to the content model. |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 85 | * |
| 86 | * <div class="special reference"> |
| 87 | * <h3>Developer Guides</h3> |
| 88 | * <p>For more information about using a ContentResolver with content providers, read the |
| 89 | * <a href="{@docRoot}guide/topics/providers/content-providers.html">Content Providers</a> |
| 90 | * developer guide.</p> |
Ng Zhi An | b837d0b | 2019-01-24 21:39:24 -0800 | [diff] [blame] | 91 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 93 | public abstract class ContentResolver implements ContentInterface { |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 94 | /** |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 95 | * Enables logic that supports deprecation of {@code _data} columns, |
| 96 | * typically by replacing values with fake paths that the OS then offers to |
| 97 | * redirect to {@link #openFileDescriptor(Uri, String)}, which developers |
| 98 | * should be using directly. |
| 99 | * |
| 100 | * @hide |
| 101 | */ |
Jeff Sharkey | 10ec9d8 | 2018-11-28 14:52:45 -0700 | [diff] [blame] | 102 | public static final boolean DEPRECATE_DATA_COLUMNS = StorageManager.hasIsolatedStorage(); |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Special filesystem path prefix which indicates that a path should be |
| 106 | * treated as a {@code content://} {@link Uri} when |
| 107 | * {@link #DEPRECATE_DATA_COLUMNS} is enabled. |
| 108 | * <p> |
| 109 | * The remainder of the path after this prefix is a |
| 110 | * {@link Uri#getSchemeSpecificPart()} value, which includes authority, path |
| 111 | * segments, and query parameters. |
| 112 | * |
| 113 | * @hide |
| 114 | */ |
| 115 | public static final String DEPRECATE_DATA_PREFIX = "/mnt/content/"; |
| 116 | |
| 117 | /** |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 118 | * @deprecated instead use |
| 119 | * {@link #requestSync(android.accounts.Account, String, android.os.Bundle)} |
| 120 | */ |
Fred Quintana | 4a6679b | 2009-08-17 13:05:39 -0700 | [diff] [blame] | 121 | @Deprecated |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 122 | public static final String SYNC_EXTRAS_ACCOUNT = "account"; |
Georgi Nikolov | b339557 | 2013-06-18 18:27:31 -0700 | [diff] [blame] | 123 | |
| 124 | /** |
| 125 | * If this extra is set to true, the sync request will be scheduled |
| 126 | * at the front of the sync request queue and without any delay |
| 127 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | public static final String SYNC_EXTRAS_EXPEDITED = "expedited"; |
Georgi Nikolov | b339557 | 2013-06-18 18:27:31 -0700 | [diff] [blame] | 129 | |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 130 | /** |
Shreyas Basarge | 8c834c0 | 2016-01-07 13:53:16 +0000 | [diff] [blame] | 131 | * If this extra is set to true, the sync request will be scheduled |
| 132 | * only when the device is plugged in. This is equivalent to calling |
| 133 | * setRequiresCharging(true) on {@link SyncRequest}. |
| 134 | */ |
| 135 | public static final String SYNC_EXTRAS_REQUIRE_CHARGING = "require_charging"; |
| 136 | |
| 137 | /** |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 138 | * @deprecated instead use |
| 139 | * {@link #SYNC_EXTRAS_MANUAL} |
| 140 | */ |
Fred Quintana | 4a6679b | 2009-08-17 13:05:39 -0700 | [diff] [blame] | 141 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | public static final String SYNC_EXTRAS_FORCE = "force"; |
Fred Quintana | 53bd252 | 2010-02-05 15:28:12 -0800 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * If this extra is set to true then the sync settings (like getSyncAutomatically()) |
| 146 | * are ignored by the sync scheduler. |
| 147 | */ |
| 148 | public static final String SYNC_EXTRAS_IGNORE_SETTINGS = "ignore_settings"; |
| 149 | |
| 150 | /** |
| 151 | * If this extra is set to true then any backoffs for the initial attempt (e.g. due to retries) |
| 152 | * are ignored by the sync scheduler. If this request fails and gets rescheduled then the |
| 153 | * retries will still honor the backoff. |
| 154 | */ |
| 155 | public static final String SYNC_EXTRAS_IGNORE_BACKOFF = "ignore_backoff"; |
| 156 | |
| 157 | /** |
| 158 | * If this extra is set to true then the request will not be retried if it fails. |
| 159 | */ |
| 160 | public static final String SYNC_EXTRAS_DO_NOT_RETRY = "do_not_retry"; |
| 161 | |
| 162 | /** |
| 163 | * Setting this extra is the equivalent of setting both {@link #SYNC_EXTRAS_IGNORE_SETTINGS} |
| 164 | * and {@link #SYNC_EXTRAS_IGNORE_BACKOFF} |
| 165 | */ |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 166 | public static final String SYNC_EXTRAS_MANUAL = "force"; |
Fred Quintana | 53bd252 | 2010-02-05 15:28:12 -0800 | [diff] [blame] | 167 | |
Georgi Nikolov | b339557 | 2013-06-18 18:27:31 -0700 | [diff] [blame] | 168 | /** |
| 169 | * Indicates that this sync is intended to only upload local changes to the server. |
| 170 | * For example, this will be set to true if the sync is initiated by a call to |
| 171 | * {@link ContentResolver#notifyChange(android.net.Uri, android.database.ContentObserver, boolean)} |
| 172 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 173 | public static final String SYNC_EXTRAS_UPLOAD = "upload"; |
Georgi Nikolov | b339557 | 2013-06-18 18:27:31 -0700 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * Indicates that the sync adapter should proceed with the delete operations, |
| 177 | * even if it determines that there are too many. |
| 178 | * See {@link SyncResult#tooManyDeletions} |
| 179 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | public static final String SYNC_EXTRAS_OVERRIDE_TOO_MANY_DELETIONS = "deletions_override"; |
Georgi Nikolov | b339557 | 2013-06-18 18:27:31 -0700 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * Indicates that the sync adapter should not proceed with the delete operations, |
| 184 | * if it determines that there are too many. |
| 185 | * See {@link SyncResult#tooManyDeletions} |
| 186 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | public static final String SYNC_EXTRAS_DISCARD_LOCAL_DELETIONS = "discard_deletions"; |
| 188 | |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 189 | /* Extensions to API. TODO: Not clear if we will keep these as public flags. */ |
| 190 | /** {@hide} User-specified flag for expected upload size. */ |
| 191 | public static final String SYNC_EXTRAS_EXPECTED_UPLOAD = "expected_upload"; |
| 192 | |
| 193 | /** {@hide} User-specified flag for expected download size. */ |
| 194 | public static final String SYNC_EXTRAS_EXPECTED_DOWNLOAD = "expected_download"; |
| 195 | |
| 196 | /** {@hide} Priority of this sync with respect to other syncs scheduled for this application. */ |
| 197 | public static final String SYNC_EXTRAS_PRIORITY = "sync_priority"; |
| 198 | |
| 199 | /** {@hide} Flag to allow sync to occur on metered network. */ |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 200 | public static final String SYNC_EXTRAS_DISALLOW_METERED = "allow_metered"; |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 201 | |
Fred Quintana | 4a6679b | 2009-08-17 13:05:39 -0700 | [diff] [blame] | 202 | /** |
Makoto Onuki | 75ad249 | 2018-03-28 14:42:42 -0700 | [diff] [blame] | 203 | * {@hide} Integer extra containing a SyncExemption flag. |
Makoto Onuki | 61283ec | 2018-01-31 17:22:36 -0800 | [diff] [blame] | 204 | * |
| 205 | * Only the system and the shell user can set it. |
| 206 | * |
| 207 | * This extra is "virtual". Once passed to the system server, it'll be removed from the bundle. |
| 208 | */ |
Makoto Onuki | 75ad249 | 2018-03-28 14:42:42 -0700 | [diff] [blame] | 209 | public static final String SYNC_VIRTUAL_EXTRAS_EXEMPTION_FLAG = "v_exemption"; |
Makoto Onuki | 61283ec | 2018-01-31 17:22:36 -0800 | [diff] [blame] | 210 | |
| 211 | /** |
Fred Quintana | 4a6679b | 2009-08-17 13:05:39 -0700 | [diff] [blame] | 212 | * Set by the SyncManager to request that the SyncAdapter initialize itself for |
| 213 | * the given account/authority pair. One required initialization step is to |
| 214 | * ensure that {@link #setIsSyncable(android.accounts.Account, String, int)} has been |
| 215 | * called with a >= 0 value. When this flag is set the SyncAdapter does not need to |
| 216 | * do a full sync, though it is allowed to do so. |
| 217 | */ |
| 218 | public static final String SYNC_EXTRAS_INITIALIZE = "initialize"; |
| 219 | |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 220 | /** @hide */ |
| 221 | public static final Intent ACTION_SYNC_CONN_STATUS_CHANGED = |
| 222 | new Intent("com.android.sync.SYNC_CONN_STATUS_CHANGED"); |
| 223 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | public static final String SCHEME_CONTENT = "content"; |
| 225 | public static final String SCHEME_ANDROID_RESOURCE = "android.resource"; |
| 226 | public static final String SCHEME_FILE = "file"; |
| 227 | |
| 228 | /** |
Jeff Sharkey | 5b836f2 | 2014-08-27 14:46:32 -0700 | [diff] [blame] | 229 | * An extra {@link Point} describing the optimal size for a requested image |
| 230 | * resource, in pixels. If a provider has multiple sizes of the image, it |
| 231 | * should return the image closest to this size. |
| 232 | * |
| 233 | * @see #openTypedAssetFileDescriptor(Uri, String, Bundle) |
| 234 | * @see #openTypedAssetFileDescriptor(Uri, String, Bundle, |
| 235 | * CancellationSignal) |
| 236 | */ |
| 237 | public static final String EXTRA_SIZE = "android.content.extra.SIZE"; |
| 238 | |
| 239 | /** |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 240 | * An extra boolean describing whether a particular provider supports refresh |
| 241 | * or not. If a provider supports refresh, it should include this key in its |
| 242 | * returned Cursor as part of its query call. |
| 243 | * |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 244 | */ |
| 245 | public static final String EXTRA_REFRESH_SUPPORTED = "android.content.extra.REFRESH_SUPPORTED"; |
| 246 | |
| 247 | /** |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 248 | * Key for an SQL style selection string that may be present in the query Bundle argument |
| 249 | * passed to {@link ContentProvider#query(Uri, String[], Bundle, CancellationSignal)} |
| 250 | * when called by a legacy client. |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 251 | * |
| 252 | * <p>Clients should never include user supplied values directly in the selection string, |
| 253 | * as this presents an avenue for SQL injection attacks. In lieu of this, a client |
| 254 | * should use standard placeholder notation to represent values in a selection string, |
| 255 | * then supply a corresponding value in {@value #QUERY_ARG_SQL_SELECTION_ARGS}. |
| 256 | * |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 257 | * <p><b>Apps targeting {@link android.os.Build.VERSION_CODES#O} or higher are strongly |
| 258 | * encourage to use structured query arguments in lieu of opaque SQL query clauses.</b> |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 259 | * |
| 260 | * @see #QUERY_ARG_SORT_COLUMNS |
| 261 | * @see #QUERY_ARG_SORT_DIRECTION |
| 262 | * @see #QUERY_ARG_SORT_COLLATION |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 263 | */ |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 264 | public static final String QUERY_ARG_SQL_SELECTION = "android:query-arg-sql-selection"; |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 265 | |
| 266 | /** |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 267 | * Key for SQL selection string arguments list. |
| 268 | * |
| 269 | * <p>Clients should never include user supplied values directly in the selection string, |
| 270 | * as this presents an avenue for SQL injection attacks. In lieu of this, a client |
| 271 | * should use standard placeholder notation to represent values in a selection string, |
| 272 | * then supply a corresponding value in {@value #QUERY_ARG_SQL_SELECTION_ARGS}. |
| 273 | * |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 274 | * <p><b>Apps targeting {@link android.os.Build.VERSION_CODES#O} or higher are strongly |
| 275 | * encourage to use structured query arguments in lieu of opaque SQL query clauses.</b> |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 276 | * |
| 277 | * @see #QUERY_ARG_SORT_COLUMNS |
| 278 | * @see #QUERY_ARG_SORT_DIRECTION |
| 279 | * @see #QUERY_ARG_SORT_COLLATION |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 280 | */ |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 281 | public static final String QUERY_ARG_SQL_SELECTION_ARGS = |
| 282 | "android:query-arg-sql-selection-args"; |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 283 | |
| 284 | /** |
| 285 | * Key for an SQL style sort string that may be present in the query Bundle argument |
| 286 | * passed to {@link ContentProvider#query(Uri, String[], Bundle, CancellationSignal)} |
| 287 | * when called by a legacy client. |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 288 | * |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 289 | * <p><b>Apps targeting {@link android.os.Build.VERSION_CODES#O} or higher are strongly |
| 290 | * encourage to use structured query arguments in lieu of opaque SQL query clauses.</b> |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 291 | * |
| 292 | * @see #QUERY_ARG_SORT_COLUMNS |
| 293 | * @see #QUERY_ARG_SORT_DIRECTION |
| 294 | * @see #QUERY_ARG_SORT_COLLATION |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 295 | */ |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 296 | public static final String QUERY_ARG_SQL_SORT_ORDER = "android:query-arg-sql-sort-order"; |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 297 | |
Jeff Sharkey | 6adc98c | 2018-07-12 19:47:49 -0600 | [diff] [blame] | 298 | /** {@hide} */ |
| 299 | public static final String QUERY_ARG_SQL_GROUP_BY = "android:query-arg-sql-group-by"; |
| 300 | /** {@hide} */ |
| 301 | public static final String QUERY_ARG_SQL_HAVING = "android:query-arg-sql-having"; |
| 302 | /** {@hide} */ |
| 303 | public static final String QUERY_ARG_SQL_LIMIT = "android:query-arg-sql-limit"; |
| 304 | |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 305 | /** |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 306 | * Specifies the list of columns against which to sort results. When first column values |
| 307 | * are identical, records are then sorted based on second column values, and so on. |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 308 | * |
| 309 | * <p>Columns present in this list must also be included in the projection |
| 310 | * supplied to {@link ContentResolver#query(Uri, String[], Bundle, CancellationSignal)}. |
| 311 | * |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 312 | * <p>Apps targeting {@link android.os.Build.VERSION_CODES#O} or higher: |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 313 | * |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 314 | * <li>{@link ContentProvider} implementations: When preparing data in |
| 315 | * {@link ContentProvider#query(Uri, String[], Bundle, CancellationSignal)}, if sort columns |
| 316 | * is reflected in the returned Cursor, it is strongly recommended that |
| 317 | * {@link #QUERY_ARG_SORT_COLUMNS} then be included in the array of honored arguments |
| 318 | * reflected in {@link Cursor} extras {@link Bundle} under {@link #EXTRA_HONORED_ARGS}. |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 319 | * |
| 320 | * <li>When querying a provider, where no QUERY_ARG_SQL* otherwise exists in the |
| 321 | * arguments {@link Bundle}, the Content framework will attempt to synthesize |
| 322 | * an QUERY_ARG_SQL* argument using the corresponding QUERY_ARG_SORT* values. |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 323 | */ |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 324 | public static final String QUERY_ARG_SORT_COLUMNS = "android:query-arg-sort-columns"; |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 325 | |
| 326 | /** |
| 327 | * Specifies desired sort order. When unspecified a provider may provide a default |
| 328 | * sort direction, or choose to return unsorted results. |
| 329 | * |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 330 | * <p>Apps targeting {@link android.os.Build.VERSION_CODES#O} or higher: |
| 331 | * |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 332 | * <li>{@link ContentProvider} implementations: When preparing data in |
| 333 | * {@link ContentProvider#query(Uri, String[], Bundle, CancellationSignal)}, if sort direction |
| 334 | * is reflected in the returned Cursor, it is strongly recommended that |
| 335 | * {@link #QUERY_ARG_SORT_DIRECTION} then be included in the array of honored arguments |
| 336 | * reflected in {@link Cursor} extras {@link Bundle} under {@link #EXTRA_HONORED_ARGS}. |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 337 | * |
| 338 | * <li>When querying a provider, where no QUERY_ARG_SQL* otherwise exists in the |
| 339 | * arguments {@link Bundle}, the Content framework will attempt to synthesize |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 340 | * a QUERY_ARG_SQL* argument using the corresponding QUERY_ARG_SORT* values. |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 341 | * |
| 342 | * @see #QUERY_SORT_DIRECTION_ASCENDING |
| 343 | * @see #QUERY_SORT_DIRECTION_DESCENDING |
| 344 | */ |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 345 | public static final String QUERY_ARG_SORT_DIRECTION = "android:query-arg-sort-direction"; |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 346 | |
| 347 | /** |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 348 | * Allows client to specify a hint to the provider declaring which collation |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 349 | * to use when sorting text values. |
| 350 | * |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 351 | * <p>Providers may support custom collators. When specifying a custom collator |
| 352 | * the value is determined by the Provider. |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 353 | * |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 354 | * <li>{@link ContentProvider} implementations: When preparing data in |
| 355 | * {@link ContentProvider#query(Uri, String[], Bundle, CancellationSignal)}, if sort collation |
| 356 | * is reflected in the returned Cursor, it is strongly recommended that |
| 357 | * {@link #QUERY_ARG_SORT_COLLATION} then be included in the array of honored arguments |
| 358 | * reflected in {@link Cursor} extras {@link Bundle} under {@link #EXTRA_HONORED_ARGS}. |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 359 | * |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 360 | * <li>When querying a provider, where no QUERY_ARG_SQL* otherwise exists in the |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 361 | * arguments {@link Bundle}, the Content framework will attempt to synthesize |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 362 | * a QUERY_ARG_SQL* argument using the corresponding QUERY_ARG_SORT* values. |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 363 | * |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 364 | * @see java.text.Collator#PRIMARY |
| 365 | * @see java.text.Collator#SECONDARY |
| 366 | * @see java.text.Collator#TERTIARY |
| 367 | * @see java.text.Collator#IDENTICAL |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 368 | */ |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 369 | public static final String QUERY_ARG_SORT_COLLATION = "android:query-arg-sort-collation"; |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 370 | |
Steve McKay | 415f41b | 2017-02-01 13:38:25 -0800 | [diff] [blame] | 371 | /** |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 372 | * Allows provider to report back to client which query keys are honored in a Cursor. |
Steve McKay | 415f41b | 2017-02-01 13:38:25 -0800 | [diff] [blame] | 373 | * |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 374 | * <p>Key identifying a {@code String[]} containing all QUERY_ARG_SORT* arguments |
Steve McKay | 415f41b | 2017-02-01 13:38:25 -0800 | [diff] [blame] | 375 | * honored by the provider. Include this in {@link Cursor} extras {@link Bundle} |
| 376 | * when any QUERY_ARG_SORT* value was honored during the preparation of the |
| 377 | * results {@link Cursor}. |
| 378 | * |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 379 | * <p>If present, ALL honored arguments are enumerated in this extra’s payload. |
| 380 | * |
| 381 | * @see #QUERY_ARG_SORT_COLUMNS |
| 382 | * @see #QUERY_ARG_SORT_DIRECTION |
| 383 | * @see #QUERY_ARG_SORT_COLLATION |
Steve McKay | 415f41b | 2017-02-01 13:38:25 -0800 | [diff] [blame] | 384 | */ |
| 385 | public static final String EXTRA_HONORED_ARGS = "android.content.extra.HONORED_ARGS"; |
| 386 | |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 387 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 388 | @IntDef(flag = false, prefix = { "QUERY_SORT_DIRECTION_" }, value = { |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 389 | QUERY_SORT_DIRECTION_ASCENDING, |
| 390 | QUERY_SORT_DIRECTION_DESCENDING |
| 391 | }) |
| 392 | @Retention(RetentionPolicy.SOURCE) |
| 393 | public @interface SortDirection {} |
| 394 | public static final int QUERY_SORT_DIRECTION_ASCENDING = 0; |
| 395 | public static final int QUERY_SORT_DIRECTION_DESCENDING = 1; |
| 396 | |
| 397 | /** |
| 398 | * @see {@link java.text.Collector} for details on respective collation strength. |
| 399 | * @hide |
| 400 | */ |
| 401 | @IntDef(flag = false, value = { |
| 402 | java.text.Collator.PRIMARY, |
| 403 | java.text.Collator.SECONDARY, |
| 404 | java.text.Collator.TERTIARY, |
| 405 | java.text.Collator.IDENTICAL |
| 406 | }) |
| 407 | @Retention(RetentionPolicy.SOURCE) |
| 408 | public @interface QueryCollator {} |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 409 | |
| 410 | /** |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 411 | * Specifies the offset row index within a Cursor. |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 412 | */ |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 413 | public static final String QUERY_ARG_OFFSET = "android:query-arg-offset"; |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 414 | |
| 415 | /** |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 416 | * Specifies the max number of rows to include in a Cursor. |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 417 | */ |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 418 | public static final String QUERY_ARG_LIMIT = "android:query-arg-limit"; |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 419 | |
| 420 | /** |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 421 | * Added to {@link Cursor} extras {@link Bundle} to indicate total row count of |
| 422 | * recordset when paging is supported. Providers must include this when |
Steve McKay | 415f41b | 2017-02-01 13:38:25 -0800 | [diff] [blame] | 423 | * implementing paging support. |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 424 | * |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 425 | * <p>A provider may return -1 that row count of the recordset is unknown. |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 426 | * |
| 427 | * <p>Providers having returned -1 in a previous query are recommended to |
| 428 | * send content change notification once (if) full recordset size becomes |
| 429 | * known. |
| 430 | */ |
Steve McKay | d74a3bd | 2017-04-24 12:07:53 -0700 | [diff] [blame] | 431 | public static final String EXTRA_TOTAL_COUNT = "android.content.extra.TOTAL_COUNT"; |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 432 | |
| 433 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 434 | * This is the Android platform's base MIME type for a content: URI |
| 435 | * containing a Cursor of a single item. Applications should use this |
| 436 | * as the base type along with their own sub-type of their content: URIs |
| 437 | * that represent a particular item. For example, hypothetical IMAP email |
| 438 | * client may have a URI |
| 439 | * <code>content://com.company.provider.imap/inbox/1</code> for a particular |
| 440 | * message in the inbox, whose MIME type would be reported as |
| 441 | * <code>CURSOR_ITEM_BASE_TYPE + "/vnd.company.imap-msg"</code> |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 442 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | * <p>Compare with {@link #CURSOR_DIR_BASE_TYPE}. |
| 444 | */ |
| 445 | public static final String CURSOR_ITEM_BASE_TYPE = "vnd.android.cursor.item"; |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 446 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 447 | /** |
| 448 | * This is the Android platform's base MIME type for a content: URI |
| 449 | * containing a Cursor of zero or more items. Applications should use this |
| 450 | * as the base type along with their own sub-type of their content: URIs |
| 451 | * that represent a directory of items. For example, hypothetical IMAP email |
| 452 | * client may have a URI |
| 453 | * <code>content://com.company.provider.imap/inbox</code> for all of the |
| 454 | * messages in its inbox, whose MIME type would be reported as |
| 455 | * <code>CURSOR_DIR_BASE_TYPE + "/vnd.company.imap-msg"</code> |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 456 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 457 | * <p>Note how the base MIME type varies between this and |
| 458 | * {@link #CURSOR_ITEM_BASE_TYPE} depending on whether there is |
| 459 | * one single item or multiple items in the data set, while the sub-type |
| 460 | * remains the same because in either case the data structure contained |
| 461 | * in the cursor is the same. |
| 462 | */ |
| 463 | public static final String CURSOR_DIR_BASE_TYPE = "vnd.android.cursor.dir"; |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 464 | |
Matt Casey | bd7bcf0 | 2014-02-05 15:51:39 -0800 | [diff] [blame] | 465 | /** |
| 466 | * This is the Android platform's generic MIME type to match any MIME |
| 467 | * type of the form "{@link #CURSOR_ITEM_BASE_TYPE}/{@code SUB_TYPE}". |
| 468 | * {@code SUB_TYPE} is the sub-type of the application-dependent |
| 469 | * content, e.g., "audio", "video", "playlist". |
| 470 | */ |
| 471 | public static final String ANY_CURSOR_ITEM_TYPE = "vnd.android.cursor.item/*"; |
| 472 | |
Jeff Sharkey | 91e3cd4 | 2018-08-27 18:03:33 -0600 | [diff] [blame] | 473 | /** |
| 474 | * Default MIME type for files whose type is otherwise unknown. |
| 475 | * @hide |
| 476 | */ |
| 477 | public static final String MIME_TYPE_DEFAULT = "application/octet-stream"; |
| 478 | |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 479 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 480 | @UnsupportedAppUsage |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 481 | public static final int SYNC_ERROR_SYNC_ALREADY_IN_PROGRESS = 1; |
| 482 | /** @hide */ |
| 483 | public static final int SYNC_ERROR_AUTHENTICATION = 2; |
| 484 | /** @hide */ |
| 485 | public static final int SYNC_ERROR_IO = 3; |
| 486 | /** @hide */ |
| 487 | public static final int SYNC_ERROR_PARSE = 4; |
| 488 | /** @hide */ |
| 489 | public static final int SYNC_ERROR_CONFLICT = 5; |
| 490 | /** @hide */ |
| 491 | public static final int SYNC_ERROR_TOO_MANY_DELETIONS = 6; |
| 492 | /** @hide */ |
| 493 | public static final int SYNC_ERROR_TOO_MANY_RETRIES = 7; |
| 494 | /** @hide */ |
| 495 | public static final int SYNC_ERROR_INTERNAL = 8; |
| 496 | |
Alon Albert | 57286f9 | 2012-10-09 14:21:38 -0700 | [diff] [blame] | 497 | private static final String[] SYNC_ERROR_NAMES = new String[] { |
| 498 | "already-in-progress", |
| 499 | "authentication-error", |
| 500 | "io-error", |
| 501 | "parse-error", |
| 502 | "conflict", |
| 503 | "too-many-deletions", |
| 504 | "too-many-retries", |
| 505 | "internal-error", |
| 506 | }; |
| 507 | |
| 508 | /** @hide */ |
Jeff Sharkey | 7a96c39 | 2012-11-15 14:01:46 -0800 | [diff] [blame] | 509 | public static String syncErrorToString(int error) { |
Alon Albert | 57286f9 | 2012-10-09 14:21:38 -0700 | [diff] [blame] | 510 | if (error < 1 || error > SYNC_ERROR_NAMES.length) { |
| 511 | return String.valueOf(error); |
| 512 | } |
| 513 | return SYNC_ERROR_NAMES[error - 1]; |
| 514 | } |
| 515 | |
Alon Albert | 5c113fa | 2013-02-07 08:07:32 -0800 | [diff] [blame] | 516 | /** @hide */ |
| 517 | public static int syncErrorStringToInt(String error) { |
| 518 | for (int i = 0, n = SYNC_ERROR_NAMES.length; i < n; i++) { |
| 519 | if (SYNC_ERROR_NAMES[i].equals(error)) { |
| 520 | return i + 1; |
| 521 | } |
| 522 | } |
| 523 | if (error != null) { |
| 524 | try { |
| 525 | return Integer.parseInt(error); |
| 526 | } catch (NumberFormatException e) { |
| 527 | Log.d(TAG, "error parsing sync error: " + error); |
| 528 | } |
| 529 | } |
| 530 | return 0; |
| 531 | } |
| 532 | |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 533 | public static final int SYNC_OBSERVER_TYPE_SETTINGS = 1<<0; |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 534 | public static final int SYNC_OBSERVER_TYPE_PENDING = 1<<1; |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 535 | public static final int SYNC_OBSERVER_TYPE_ACTIVE = 1<<2; |
| 536 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 537 | @UnsupportedAppUsage |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 538 | public static final int SYNC_OBSERVER_TYPE_STATUS = 1<<3; |
| 539 | /** @hide */ |
| 540 | public static final int SYNC_OBSERVER_TYPE_ALL = 0x7fffffff; |
| 541 | |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 542 | /** @hide */ |
Jeff Sharkey | ce8db99 | 2017-12-13 20:05:05 -0700 | [diff] [blame] | 543 | @IntDef(flag = true, prefix = { "NOTIFY_" }, value = { |
| 544 | NOTIFY_SYNC_TO_NETWORK, |
| 545 | NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS |
| 546 | }) |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 547 | @Retention(RetentionPolicy.SOURCE) |
| 548 | public @interface NotifyFlags {} |
| 549 | |
| 550 | /** |
| 551 | * Flag for {@link #notifyChange(Uri, ContentObserver, int)}: attempt to sync the change |
| 552 | * to the network. |
| 553 | */ |
| 554 | public static final int NOTIFY_SYNC_TO_NETWORK = 1<<0; |
| 555 | |
| 556 | /** |
| 557 | * Flag for {@link #notifyChange(Uri, ContentObserver, int)}: if set, this notification |
| 558 | * will be skipped if it is being delivered to the root URI of a ContentObserver that is |
| 559 | * using "notify for descendants." The purpose of this is to allow the provide to send |
| 560 | * a general notification of "something under X" changed that observers of that specific |
| 561 | * URI can receive, while also sending a specific URI under X. It would use this flag |
| 562 | * when sending the former, so that observers of "X and descendants" only see the latter. |
| 563 | */ |
| 564 | public static final int NOTIFY_SKIP_NOTIFY_FOR_DESCENDANTS = 1<<1; |
| 565 | |
Makoto Onuki | 75ad249 | 2018-03-28 14:42:42 -0700 | [diff] [blame] | 566 | /** |
| 567 | * No exception, throttled by app standby normally. |
| 568 | * @hide |
| 569 | */ |
| 570 | public static final int SYNC_EXEMPTION_NONE = 0; |
| 571 | |
| 572 | /** |
Makoto Onuki | d5f25d2 | 2018-05-22 16:02:17 -0700 | [diff] [blame] | 573 | * Exemption given to a sync request made by a foreground app (including |
| 574 | * PROCESS_STATE_IMPORTANT_FOREGROUND). |
Makoto Onuki | 75ad249 | 2018-03-28 14:42:42 -0700 | [diff] [blame] | 575 | * |
Makoto Onuki | d5f25d2 | 2018-05-22 16:02:17 -0700 | [diff] [blame] | 576 | * At the schedule time, we promote the sync adapter app for a higher bucket: |
| 577 | * - If the device is not dozing (so the sync will start right away) |
| 578 | * promote to ACTIVE for 1 hour. |
| 579 | * - If the device is dozing (so the sync *won't* start right away), |
| 580 | * promote to WORKING_SET for 4 hours, so it'll get a higher chance to be started once the |
| 581 | * device comes out of doze. |
| 582 | * - When the sync actually starts, we promote the sync adapter app to ACTIVE for 10 minutes, |
| 583 | * so it can schedule and start more syncs without getting throttled, even when the first |
| 584 | * operation was canceled and now we're retrying. |
| 585 | * |
| 586 | * |
Makoto Onuki | 75ad249 | 2018-03-28 14:42:42 -0700 | [diff] [blame] | 587 | * @hide |
| 588 | */ |
Makoto Onuki | d5f25d2 | 2018-05-22 16:02:17 -0700 | [diff] [blame] | 589 | public static final int SYNC_EXEMPTION_PROMOTE_BUCKET = 1; |
Makoto Onuki | 75ad249 | 2018-03-28 14:42:42 -0700 | [diff] [blame] | 590 | |
| 591 | /** |
Makoto Onuki | d5f25d2 | 2018-05-22 16:02:17 -0700 | [diff] [blame] | 592 | * In addition to {@link #SYNC_EXEMPTION_PROMOTE_BUCKET}, we put the sync adapter app in the |
Makoto Onuki | 75ad249 | 2018-03-28 14:42:42 -0700 | [diff] [blame] | 593 | * temp whitelist for 10 minutes, so that even RARE apps can run syncs right away. |
| 594 | * @hide |
| 595 | */ |
Makoto Onuki | d5f25d2 | 2018-05-22 16:02:17 -0700 | [diff] [blame] | 596 | public static final int SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP = 2; |
Makoto Onuki | 75ad249 | 2018-03-28 14:42:42 -0700 | [diff] [blame] | 597 | |
| 598 | /** @hide */ |
| 599 | @IntDef(flag = false, prefix = { "SYNC_EXEMPTION_" }, value = { |
| 600 | SYNC_EXEMPTION_NONE, |
Makoto Onuki | d5f25d2 | 2018-05-22 16:02:17 -0700 | [diff] [blame] | 601 | SYNC_EXEMPTION_PROMOTE_BUCKET, |
| 602 | SYNC_EXEMPTION_PROMOTE_BUCKET_WITH_TEMP, |
Makoto Onuki | 75ad249 | 2018-03-28 14:42:42 -0700 | [diff] [blame] | 603 | }) |
| 604 | @Retention(RetentionPolicy.SOURCE) |
| 605 | public @interface SyncExemption {} |
| 606 | |
Brad Fitzpatrick | 2588096 | 2010-02-22 15:17:49 -0800 | [diff] [blame] | 607 | // Always log queries which take 500ms+; shorter queries are |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 608 | // sampled accordingly. |
Jeff Sharkey | 2b4d22c | 2013-04-26 10:52:00 -0700 | [diff] [blame] | 609 | private static final boolean ENABLE_CONTENT_SAMPLE = false; |
Brad Fitzpatrick | 2588096 | 2010-02-22 15:17:49 -0800 | [diff] [blame] | 610 | private static final int SLOW_THRESHOLD_MILLIS = 500; |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 611 | private final Random mRandom = new Random(); // guarded by itself |
| 612 | |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 613 | public ContentResolver(@Nullable Context context) { |
| 614 | this(context, null); |
| 615 | } |
| 616 | |
| 617 | /** {@hide} */ |
| 618 | public ContentResolver(@Nullable Context context, @Nullable ContentInterface wrapped) { |
Jeff Sharkey | 66a017b | 2013-01-17 18:18:22 -0800 | [diff] [blame] | 619 | mContext = context != null ? context : ActivityThread.currentApplication(); |
Dianne Hackborn | 95d7853 | 2013-09-11 09:51:14 -0700 | [diff] [blame] | 620 | mPackageName = mContext.getOpPackageName(); |
Jeff Sharkey | 4b2e87f | 2017-04-26 00:36:02 +0000 | [diff] [blame] | 621 | mTargetSdkVersion = mContext.getApplicationInfo().targetSdkVersion; |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 622 | mWrapped = wrapped; |
| 623 | } |
| 624 | |
| 625 | /** {@hide} */ |
Jeff Sharkey | ba4acd5 | 2019-03-05 19:46:54 -0700 | [diff] [blame] | 626 | public static @NonNull ContentResolver wrap(@NonNull ContentInterface wrapped) { |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 627 | Preconditions.checkNotNull(wrapped); |
| 628 | |
| 629 | return new ContentResolver(null, wrapped) { |
| 630 | @Override |
| 631 | public void unstableProviderDied(IContentProvider icp) { |
| 632 | throw new UnsupportedOperationException(); |
| 633 | } |
| 634 | @Override |
| 635 | public boolean releaseUnstableProvider(IContentProvider icp) { |
| 636 | throw new UnsupportedOperationException(); |
| 637 | } |
| 638 | @Override |
| 639 | public boolean releaseProvider(IContentProvider icp) { |
| 640 | throw new UnsupportedOperationException(); |
| 641 | } |
| 642 | @Override |
| 643 | protected IContentProvider acquireUnstableProvider(Context c, String name) { |
| 644 | throw new UnsupportedOperationException(); |
| 645 | } |
| 646 | @Override |
| 647 | protected IContentProvider acquireProvider(Context c, String name) { |
| 648 | throw new UnsupportedOperationException(); |
| 649 | } |
| 650 | }; |
| 651 | } |
| 652 | |
| 653 | /** |
| 654 | * Create a {@link ContentResolver} instance that redirects all its methods |
| 655 | * to the given {@link ContentProvider}. |
| 656 | */ |
Jeff Sharkey | ba4acd5 | 2019-03-05 19:46:54 -0700 | [diff] [blame] | 657 | public static @NonNull ContentResolver wrap(@NonNull ContentProvider wrapped) { |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 658 | return wrap((ContentInterface) wrapped); |
| 659 | } |
| 660 | |
| 661 | /** |
| 662 | * Create a {@link ContentResolver} instance that redirects all its methods |
| 663 | * to the given {@link ContentProviderClient}. |
| 664 | */ |
Jeff Sharkey | ba4acd5 | 2019-03-05 19:46:54 -0700 | [diff] [blame] | 665 | public static @NonNull ContentResolver wrap(@NonNull ContentProviderClient wrapped) { |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 666 | return wrap((ContentInterface) wrapped); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 670 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | protected abstract IContentProvider acquireProvider(Context c, String name); |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 672 | |
| 673 | /** |
| 674 | * Providing a default implementation of this, to avoid having to change a |
| 675 | * lot of other things, but implementations of ContentResolver should |
| 676 | * implement it. |
| 677 | * |
| 678 | * @hide |
| 679 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 680 | @UnsupportedAppUsage |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 681 | protected IContentProvider acquireExistingProvider(Context c, String name) { |
| 682 | return acquireProvider(c, name); |
| 683 | } |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 684 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 686 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 687 | public abstract boolean releaseProvider(IContentProvider icp); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 688 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 689 | @UnsupportedAppUsage |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 690 | protected abstract IContentProvider acquireUnstableProvider(Context c, String name); |
| 691 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 692 | @UnsupportedAppUsage |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 693 | public abstract boolean releaseUnstableProvider(IContentProvider icp); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 694 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 695 | @UnsupportedAppUsage |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 696 | public abstract void unstableProviderDied(IContentProvider icp); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 697 | |
Jeff Sharkey | 7aa7601 | 2013-09-30 14:26:27 -0700 | [diff] [blame] | 698 | /** @hide */ |
| 699 | public void appNotRespondingViaProvider(IContentProvider icp) { |
| 700 | throw new UnsupportedOperationException("appNotRespondingViaProvider"); |
| 701 | } |
| 702 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | /** |
| 704 | * Return the MIME type of the given content URL. |
| 705 | * |
| 706 | * @param url A Uri identifying content (either a list or specific type), |
| 707 | * using the content:// scheme. |
| 708 | * @return A MIME type for the content, or null if the URL is invalid or the type is unknown |
| 709 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 710 | @Override |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 711 | public final @Nullable String getType(@NonNull Uri url) { |
| 712 | Preconditions.checkNotNull(url, "url"); |
| 713 | |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 714 | try { |
| 715 | if (mWrapped != null) return mWrapped.getType(url); |
| 716 | } catch (RemoteException e) { |
| 717 | return null; |
| 718 | } |
| 719 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 720 | // XXX would like to have an acquireExistingUnstableProvider for this. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 721 | IContentProvider provider = acquireExistingProvider(url); |
| 722 | if (provider != null) { |
| 723 | try { |
| 724 | return provider.getType(url); |
| 725 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 726 | // Arbitrary and not worth documenting, as Activity |
| 727 | // Manager will kill this process shortly anyway. |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 728 | return null; |
| 729 | } catch (java.lang.Exception e) { |
Ola Olsson | 145e6c4 | 2010-12-20 16:45:35 +0100 | [diff] [blame] | 730 | Log.w(TAG, "Failed to get type for: " + url + " (" + e.getMessage() + ")"); |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 731 | return null; |
| 732 | } finally { |
| 733 | releaseProvider(provider); |
| 734 | } |
| 735 | } |
| 736 | |
| 737 | if (!SCHEME_CONTENT.equals(url.getScheme())) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | return null; |
| 739 | } |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 740 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | try { |
Sudheer Shanka | dc589ac | 2016-11-10 15:30:17 -0800 | [diff] [blame] | 742 | String type = ActivityManager.getService().getProviderMimeType( |
Nicolas Prevot | 1dddc7f | 2014-07-07 17:44:58 +0100 | [diff] [blame] | 743 | ContentProvider.getUriWithoutUserId(url), resolveUserId(url)); |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 744 | return type; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 745 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 746 | throw e.rethrowFromSystemServer(); |
Ola Olsson | 145e6c4 | 2010-12-20 16:45:35 +0100 | [diff] [blame] | 747 | } catch (java.lang.Exception e) { |
| 748 | Log.w(TAG, "Failed to get type for: " + url + " (" + e.getMessage() + ")"); |
| 749 | return null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 750 | } |
| 751 | } |
| 752 | |
| 753 | /** |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 754 | * Query for the possible MIME types for the representations the given |
| 755 | * content URL can be returned when opened as as stream with |
| 756 | * {@link #openTypedAssetFileDescriptor}. Note that the types here are |
| 757 | * not necessarily a superset of the type returned by {@link #getType} -- |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 758 | * many content providers cannot return a raw stream for the structured |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 759 | * data that they contain. |
| 760 | * |
| 761 | * @param url A Uri identifying content (either a list or specific type), |
| 762 | * using the content:// scheme. |
| 763 | * @param mimeTypeFilter The desired MIME type. This may be a pattern, |
John Spurlock | 3390018 | 2014-01-02 11:04:18 -0500 | [diff] [blame] | 764 | * such as */*, to query for all available MIME types that match the |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 765 | * pattern. |
Dianne Hackborn | acb69bb | 2012-04-13 15:36:06 -0700 | [diff] [blame] | 766 | * @return Returns an array of MIME type strings for all available |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 767 | * data streams that match the given mimeTypeFilter. If there are none, |
| 768 | * null is returned. |
| 769 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 770 | @Override |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 771 | public @Nullable String[] getStreamTypes(@NonNull Uri url, @NonNull String mimeTypeFilter) { |
| 772 | Preconditions.checkNotNull(url, "url"); |
| 773 | Preconditions.checkNotNull(mimeTypeFilter, "mimeTypeFilter"); |
| 774 | |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 775 | try { |
| 776 | if (mWrapped != null) return mWrapped.getStreamTypes(url, mimeTypeFilter); |
| 777 | } catch (RemoteException e) { |
| 778 | return null; |
| 779 | } |
| 780 | |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 781 | IContentProvider provider = acquireProvider(url); |
| 782 | if (provider == null) { |
| 783 | return null; |
| 784 | } |
Dianne Hackborn | 64bbbb4 | 2010-09-27 20:25:20 -0700 | [diff] [blame] | 785 | |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 786 | try { |
| 787 | return provider.getStreamTypes(url, mimeTypeFilter); |
| 788 | } catch (RemoteException e) { |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 789 | // Arbitrary and not worth documenting, as Activity |
| 790 | // Manager will kill this process shortly anyway. |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 791 | return null; |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 792 | } finally { |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 793 | releaseProvider(provider); |
| 794 | } |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 798 | * Query the given URI, returning a {@link Cursor} over the result set. |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 799 | * <p> |
| 800 | * For best performance, the caller should follow these guidelines: |
| 801 | * <ul> |
| 802 | * <li>Provide an explicit projection, to prevent |
| 803 | * reading data from storage that aren't going to be used.</li> |
| 804 | * <li>Use question mark parameter markers such as 'phone=?' instead of |
| 805 | * explicit values in the {@code selection} parameter, so that queries |
| 806 | * that differ only by those values will be recognized as the same |
| 807 | * for caching purposes.</li> |
| 808 | * </ul> |
| 809 | * </p> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 810 | * |
| 811 | * @param uri The URI, using the content:// scheme, for the content to |
| 812 | * retrieve. |
| 813 | * @param projection A list of which columns to return. Passing null will |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 814 | * return all columns, which is inefficient. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | * @param selection A filter declaring which rows to return, formatted as an |
| 816 | * SQL WHERE clause (excluding the WHERE itself). Passing null will |
| 817 | * return all rows for the given URI. |
| 818 | * @param selectionArgs You may include ?s in selection, which will be |
| 819 | * replaced by the values from selectionArgs, in the order that they |
| 820 | * appear in the selection. The values will be bound as Strings. |
| 821 | * @param sortOrder How to order the rows, formatted as an SQL ORDER BY |
| 822 | * clause (excluding the ORDER BY itself). Passing null will use the |
| 823 | * default sort order, which may be unordered. |
| 824 | * @return A Cursor object, which is positioned before the first entry, or null |
| 825 | * @see Cursor |
| 826 | */ |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 827 | public final @Nullable Cursor query(@RequiresPermission.Read @NonNull Uri uri, |
| 828 | @Nullable String[] projection, @Nullable String selection, |
| 829 | @Nullable String[] selectionArgs, @Nullable String sortOrder) { |
Jeff Brown | 75ea64f | 2012-01-25 19:37:13 -0800 | [diff] [blame] | 830 | return query(uri, projection, selection, selectionArgs, sortOrder, null); |
| 831 | } |
| 832 | |
| 833 | /** |
Jeff Brown | c64ff37 | 2013-10-09 18:50:56 -0700 | [diff] [blame] | 834 | * Query the given URI, returning a {@link Cursor} over the result set |
| 835 | * with optional support for cancellation. |
Jeff Brown | 75ea64f | 2012-01-25 19:37:13 -0800 | [diff] [blame] | 836 | * <p> |
| 837 | * For best performance, the caller should follow these guidelines: |
| 838 | * <ul> |
| 839 | * <li>Provide an explicit projection, to prevent |
| 840 | * reading data from storage that aren't going to be used.</li> |
| 841 | * <li>Use question mark parameter markers such as 'phone=?' instead of |
| 842 | * explicit values in the {@code selection} parameter, so that queries |
| 843 | * that differ only by those values will be recognized as the same |
| 844 | * for caching purposes.</li> |
| 845 | * </ul> |
| 846 | * </p> |
| 847 | * |
| 848 | * @param uri The URI, using the content:// scheme, for the content to |
| 849 | * retrieve. |
| 850 | * @param projection A list of which columns to return. Passing null will |
| 851 | * return all columns, which is inefficient. |
| 852 | * @param selection A filter declaring which rows to return, formatted as an |
| 853 | * SQL WHERE clause (excluding the WHERE itself). Passing null will |
| 854 | * return all rows for the given URI. |
| 855 | * @param selectionArgs You may include ?s in selection, which will be |
| 856 | * replaced by the values from selectionArgs, in the order that they |
| 857 | * appear in the selection. The values will be bound as Strings. |
| 858 | * @param sortOrder How to order the rows, formatted as an SQL ORDER BY |
| 859 | * clause (excluding the ORDER BY itself). Passing null will use the |
| 860 | * default sort order, which may be unordered. |
Jeff Brown | 4c1241d | 2012-02-02 17:05:00 -0800 | [diff] [blame] | 861 | * @param cancellationSignal A signal to cancel the operation in progress, or null if none. |
Jeff Brown | 75ea64f | 2012-01-25 19:37:13 -0800 | [diff] [blame] | 862 | * If the operation is canceled, then {@link OperationCanceledException} will be thrown |
| 863 | * when the query is executed. |
| 864 | * @return A Cursor object, which is positioned before the first entry, or null |
| 865 | * @see Cursor |
| 866 | */ |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 867 | public final @Nullable Cursor query(@RequiresPermission.Read @NonNull Uri uri, |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 868 | @Nullable String[] projection, @Nullable String selection, |
| 869 | @Nullable String[] selectionArgs, @Nullable String sortOrder, |
| 870 | @Nullable CancellationSignal cancellationSignal) { |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 871 | Bundle queryArgs = createSqlQueryBundle(selection, selectionArgs, sortOrder); |
| 872 | return query(uri, projection, queryArgs, cancellationSignal); |
| 873 | } |
| 874 | |
| 875 | /** |
| 876 | * Query the given URI, returning a {@link Cursor} over the result set |
| 877 | * with support for cancellation. |
| 878 | * |
| 879 | * <p>For best performance, the caller should follow these guidelines: |
| 880 | * |
| 881 | * <li>Provide an explicit projection, to prevent reading data from storage |
| 882 | * that aren't going to be used. |
| 883 | * |
Steve McKay | 415f41b | 2017-02-01 13:38:25 -0800 | [diff] [blame] | 884 | * Provider must identify which QUERY_ARG_SORT* arguments were honored during |
| 885 | * the preparation of the result set by including the respective argument keys |
| 886 | * in the {@link Cursor} extras {@link Bundle}. See {@link #EXTRA_HONORED_ARGS} |
| 887 | * for details. |
| 888 | * |
Aurimas Liutikas | 7f69533 | 2018-05-31 21:07:32 -0700 | [diff] [blame] | 889 | * @see #QUERY_ARG_SORT_COLUMNS |
| 890 | * @see #QUERY_ARG_SORT_DIRECTION |
| 891 | * @see #QUERY_ARG_SORT_COLLATION |
Steve McKay | 415f41b | 2017-02-01 13:38:25 -0800 | [diff] [blame] | 892 | * |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 893 | * @param uri The URI, using the content:// scheme, for the content to |
| 894 | * retrieve. |
| 895 | * @param projection A list of which columns to return. Passing null will |
| 896 | * return all columns, which is inefficient. |
| 897 | * @param queryArgs A Bundle containing any arguments to the query. |
| 898 | * @param cancellationSignal A signal to cancel the operation in progress, or null if none. |
| 899 | * If the operation is canceled, then {@link OperationCanceledException} will be thrown |
| 900 | * when the query is executed. |
| 901 | * @return A Cursor object, which is positioned before the first entry, or null |
| 902 | * @see Cursor |
| 903 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 904 | @Override |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 905 | public final @Nullable Cursor query(final @RequiresPermission.Read @NonNull Uri uri, |
| 906 | @Nullable String[] projection, @Nullable Bundle queryArgs, |
| 907 | @Nullable CancellationSignal cancellationSignal) { |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 908 | Preconditions.checkNotNull(uri, "uri"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 909 | |
| 910 | try { |
| 911 | if (mWrapped != null) { |
| 912 | return mWrapped.query(uri, projection, queryArgs, cancellationSignal); |
| 913 | } |
| 914 | } catch (RemoteException e) { |
| 915 | return null; |
| 916 | } |
| 917 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 918 | IContentProvider unstableProvider = acquireUnstableProvider(uri); |
| 919 | if (unstableProvider == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | return null; |
| 921 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 922 | IContentProvider stableProvider = null; |
Jeff Brown | c21b5a0 | 2013-01-07 17:15:12 -0800 | [diff] [blame] | 923 | Cursor qCursor = null; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 924 | try { |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 925 | long startTime = SystemClock.uptimeMillis(); |
Jeff Brown | 75ea64f | 2012-01-25 19:37:13 -0800 | [diff] [blame] | 926 | |
Jeff Brown | 4c1241d | 2012-02-02 17:05:00 -0800 | [diff] [blame] | 927 | ICancellationSignal remoteCancellationSignal = null; |
| 928 | if (cancellationSignal != null) { |
| 929 | cancellationSignal.throwIfCanceled(); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 930 | remoteCancellationSignal = unstableProvider.createCancellationSignal(); |
Jeff Brown | 4c1241d | 2012-02-02 17:05:00 -0800 | [diff] [blame] | 931 | cancellationSignal.setRemote(remoteCancellationSignal); |
Jeff Brown | 75ea64f | 2012-01-25 19:37:13 -0800 | [diff] [blame] | 932 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 933 | try { |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 934 | qCursor = unstableProvider.query(mPackageName, uri, projection, |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 935 | queryArgs, remoteCancellationSignal); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 936 | } catch (DeadObjectException e) { |
| 937 | // The remote process has died... but we only hold an unstable |
| 938 | // reference though, so we might recover!!! Let's try!!!! |
| 939 | // This is exciting!!1!!1!!!!1 |
| 940 | unstableProviderDied(unstableProvider); |
| 941 | stableProvider = acquireProvider(uri); |
| 942 | if (stableProvider == null) { |
| 943 | return null; |
| 944 | } |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 945 | qCursor = stableProvider.query( |
| 946 | mPackageName, uri, projection, queryArgs, remoteCancellationSignal); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 947 | } |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 948 | if (qCursor == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 949 | return null; |
| 950 | } |
Jeff Brown | c21b5a0 | 2013-01-07 17:15:12 -0800 | [diff] [blame] | 951 | |
| 952 | // Force query execution. Might fail and throw a runtime exception here. |
Vasu Nori | 020e534 | 2010-04-28 14:22:38 -0700 | [diff] [blame] | 953 | qCursor.getCount(); |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 954 | long durationMillis = SystemClock.uptimeMillis() - startTime; |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 955 | maybeLogQueryToEventLog(durationMillis, uri, projection, queryArgs); |
Jeff Brown | c21b5a0 | 2013-01-07 17:15:12 -0800 | [diff] [blame] | 956 | |
| 957 | // Wrap the cursor object into CursorWrapperInner object. |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 958 | final IContentProvider provider = (stableProvider != null) ? stableProvider |
| 959 | : acquireProvider(uri); |
| 960 | final CursorWrapperInner wrapper = new CursorWrapperInner(qCursor, provider); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 961 | stableProvider = null; |
Jeff Brown | c21b5a0 | 2013-01-07 17:15:12 -0800 | [diff] [blame] | 962 | qCursor = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 963 | return wrapper; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 964 | } catch (RemoteException e) { |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 965 | // Arbitrary and not worth documenting, as Activity |
| 966 | // Manager will kill this process shortly anyway. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | return null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 968 | } finally { |
Jeff Brown | c21b5a0 | 2013-01-07 17:15:12 -0800 | [diff] [blame] | 969 | if (qCursor != null) { |
| 970 | qCursor.close(); |
| 971 | } |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 972 | if (cancellationSignal != null) { |
| 973 | cancellationSignal.setRemote(null); |
| 974 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 975 | if (unstableProvider != null) { |
| 976 | releaseUnstableProvider(unstableProvider); |
| 977 | } |
| 978 | if (stableProvider != null) { |
| 979 | releaseProvider(stableProvider); |
| 980 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | } |
| 982 | } |
| 983 | |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 984 | /** |
Dianne Hackborn | 38ed2a4 | 2013-09-06 16:17:22 -0700 | [diff] [blame] | 985 | * Transform the given <var>url</var> to a canonical representation of |
| 986 | * its referenced resource, which can be used across devices, persisted, |
| 987 | * backed up and restored, etc. The returned Uri is still a fully capable |
| 988 | * Uri for use with its content provider, allowing you to do all of the |
| 989 | * same content provider operations as with the original Uri -- |
| 990 | * {@link #query}, {@link #openInputStream(android.net.Uri)}, etc. The |
| 991 | * only difference in behavior between the original and new Uris is that |
| 992 | * the content provider may need to do some additional work at each call |
| 993 | * using it to resolve it to the correct resource, especially if the |
| 994 | * canonical Uri has been moved to a different environment. |
| 995 | * |
| 996 | * <p>If you are moving a canonical Uri between environments, you should |
| 997 | * perform another call to {@link #canonicalize} with that original Uri to |
| 998 | * re-canonicalize it for the current environment. Alternatively, you may |
| 999 | * want to use {@link #uncanonicalize} to transform it to a non-canonical |
| 1000 | * Uri that works only in the current environment but potentially more |
| 1001 | * efficiently than the canonical representation.</p> |
| 1002 | * |
| 1003 | * @param url The {@link Uri} that is to be transformed to a canonical |
| 1004 | * representation. Like all resolver calls, the input can be either |
| 1005 | * a non-canonical or canonical Uri. |
| 1006 | * |
| 1007 | * @return Returns the official canonical representation of <var>url</var>, |
| 1008 | * or null if the content provider does not support a canonical representation |
| 1009 | * of the given Uri. Many providers may not support canonicalization of some |
| 1010 | * or all of their Uris. |
| 1011 | * |
| 1012 | * @see #uncanonicalize |
| 1013 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1014 | @Override |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1015 | public final @Nullable Uri canonicalize(@NonNull Uri url) { |
| 1016 | Preconditions.checkNotNull(url, "url"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1017 | |
| 1018 | try { |
| 1019 | if (mWrapped != null) return mWrapped.canonicalize(url); |
| 1020 | } catch (RemoteException e) { |
| 1021 | return null; |
| 1022 | } |
| 1023 | |
Dianne Hackborn | 38ed2a4 | 2013-09-06 16:17:22 -0700 | [diff] [blame] | 1024 | IContentProvider provider = acquireProvider(url); |
| 1025 | if (provider == null) { |
| 1026 | return null; |
| 1027 | } |
| 1028 | |
| 1029 | try { |
| 1030 | return provider.canonicalize(mPackageName, url); |
| 1031 | } catch (RemoteException e) { |
| 1032 | // Arbitrary and not worth documenting, as Activity |
| 1033 | // Manager will kill this process shortly anyway. |
| 1034 | return null; |
| 1035 | } finally { |
| 1036 | releaseProvider(provider); |
| 1037 | } |
| 1038 | } |
| 1039 | |
| 1040 | /** |
| 1041 | * Given a canonical Uri previously generated by {@link #canonicalize}, convert |
| 1042 | * it to its local non-canonical form. This can be useful in some cases where |
| 1043 | * you know that you will only be using the Uri in the current environment and |
| 1044 | * want to avoid any possible overhead when using it with the content |
Dianne Hackborn | b3ac67a | 2013-09-11 11:02:24 -0700 | [diff] [blame] | 1045 | * provider or want to verify that the referenced data exists at all in the |
| 1046 | * new environment. |
Dianne Hackborn | 38ed2a4 | 2013-09-06 16:17:22 -0700 | [diff] [blame] | 1047 | * |
| 1048 | * @param url The canonical {@link Uri} that is to be convered back to its |
| 1049 | * non-canonical form. |
| 1050 | * |
Dianne Hackborn | b3ac67a | 2013-09-11 11:02:24 -0700 | [diff] [blame] | 1051 | * @return Returns the non-canonical representation of <var>url</var>. This will |
| 1052 | * return null if data identified by the canonical Uri can not be found in |
| 1053 | * the current environment; callers must always check for null and deal with |
| 1054 | * that by appropriately falling back to an alternative. |
Dianne Hackborn | 38ed2a4 | 2013-09-06 16:17:22 -0700 | [diff] [blame] | 1055 | * |
| 1056 | * @see #canonicalize |
| 1057 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1058 | @Override |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1059 | public final @Nullable Uri uncanonicalize(@NonNull Uri url) { |
| 1060 | Preconditions.checkNotNull(url, "url"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1061 | |
| 1062 | try { |
| 1063 | if (mWrapped != null) return mWrapped.uncanonicalize(url); |
| 1064 | } catch (RemoteException e) { |
| 1065 | return null; |
| 1066 | } |
| 1067 | |
Dianne Hackborn | 38ed2a4 | 2013-09-06 16:17:22 -0700 | [diff] [blame] | 1068 | IContentProvider provider = acquireProvider(url); |
| 1069 | if (provider == null) { |
| 1070 | return null; |
| 1071 | } |
| 1072 | |
| 1073 | try { |
| 1074 | return provider.uncanonicalize(mPackageName, url); |
| 1075 | } catch (RemoteException e) { |
| 1076 | // Arbitrary and not worth documenting, as Activity |
| 1077 | // Manager will kill this process shortly anyway. |
| 1078 | return null; |
| 1079 | } finally { |
| 1080 | releaseProvider(provider); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | /** |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 1085 | * This allows clients to request an explicit refresh of content identified by {@code uri}. |
| 1086 | * <p> |
| 1087 | * Client code should only invoke this method when there is a strong indication (such as a user |
| 1088 | * initiated pull to refresh gesture) that the content is stale. |
| 1089 | * <p> |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 1090 | * |
Ben Lin | 2b64a88 | 2016-11-11 15:24:58 -0800 | [diff] [blame] | 1091 | * @param url The Uri identifying the data to refresh. |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 1092 | * @param args Additional options from the client. The definitions of these are specific to the |
| 1093 | * content provider being called. |
| 1094 | * @param cancellationSignal A signal to cancel the operation in progress, or {@code null} if |
| 1095 | * none. For example, if you called refresh on a particular uri, you should call |
| 1096 | * {@link CancellationSignal#throwIfCanceled()} to check whether the client has |
| 1097 | * canceled the refresh request. |
| 1098 | * @return true if the provider actually tried refreshing. |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 1099 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1100 | @Override |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 1101 | public final boolean refresh(@NonNull Uri url, @Nullable Bundle args, |
| 1102 | @Nullable CancellationSignal cancellationSignal) { |
| 1103 | Preconditions.checkNotNull(url, "url"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1104 | |
| 1105 | try { |
| 1106 | if (mWrapped != null) return mWrapped.refresh(url, args, cancellationSignal); |
| 1107 | } catch (RemoteException e) { |
| 1108 | return false; |
| 1109 | } |
| 1110 | |
Ben Lin | 1cf454f | 2016-11-10 13:50:54 -0800 | [diff] [blame] | 1111 | IContentProvider provider = acquireProvider(url); |
| 1112 | if (provider == null) { |
| 1113 | return false; |
| 1114 | } |
| 1115 | |
| 1116 | try { |
| 1117 | ICancellationSignal remoteCancellationSignal = null; |
| 1118 | if (cancellationSignal != null) { |
| 1119 | cancellationSignal.throwIfCanceled(); |
| 1120 | remoteCancellationSignal = provider.createCancellationSignal(); |
| 1121 | cancellationSignal.setRemote(remoteCancellationSignal); |
| 1122 | } |
| 1123 | return provider.refresh(mPackageName, url, args, remoteCancellationSignal); |
| 1124 | } catch (RemoteException e) { |
| 1125 | // Arbitrary and not worth documenting, as Activity |
| 1126 | // Manager will kill this process shortly anyway. |
| 1127 | return false; |
| 1128 | } finally { |
| 1129 | releaseProvider(provider); |
| 1130 | } |
| 1131 | } |
| 1132 | |
| 1133 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1134 | * Open a stream on to the content associated with a content URI. If there |
| 1135 | * is no data associated with the URI, FileNotFoundException is thrown. |
| 1136 | * |
| 1137 | * <h5>Accepts the following URI schemes:</h5> |
| 1138 | * <ul> |
| 1139 | * <li>content ({@link #SCHEME_CONTENT})</li> |
| 1140 | * <li>android.resource ({@link #SCHEME_ANDROID_RESOURCE})</li> |
| 1141 | * <li>file ({@link #SCHEME_FILE})</li> |
| 1142 | * </ul> |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 1143 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1144 | * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information |
| 1145 | * on these schemes. |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 1146 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1147 | * @param uri The desired URI. |
| 1148 | * @return InputStream |
| 1149 | * @throws FileNotFoundException if the provided URI could not be opened. |
| 1150 | * @see #openAssetFileDescriptor(Uri, String) |
| 1151 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1152 | public final @Nullable InputStream openInputStream(@NonNull Uri uri) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1153 | throws FileNotFoundException { |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1154 | Preconditions.checkNotNull(uri, "uri"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1155 | String scheme = uri.getScheme(); |
| 1156 | if (SCHEME_ANDROID_RESOURCE.equals(scheme)) { |
| 1157 | // Note: left here to avoid breaking compatibility. May be removed |
| 1158 | // with sufficient testing. |
| 1159 | OpenResourceIdResult r = getResourceId(uri); |
| 1160 | try { |
| 1161 | InputStream stream = r.r.openRawResource(r.id); |
| 1162 | return stream; |
| 1163 | } catch (Resources.NotFoundException ex) { |
| 1164 | throw new FileNotFoundException("Resource does not exist: " + uri); |
| 1165 | } |
| 1166 | } else if (SCHEME_FILE.equals(scheme)) { |
| 1167 | // Note: left here to avoid breaking compatibility. May be removed |
| 1168 | // with sufficient testing. |
| 1169 | return new FileInputStream(uri.getPath()); |
| 1170 | } else { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1171 | AssetFileDescriptor fd = openAssetFileDescriptor(uri, "r", null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1172 | try { |
| 1173 | return fd != null ? fd.createInputStream() : null; |
| 1174 | } catch (IOException e) { |
| 1175 | throw new FileNotFoundException("Unable to create stream"); |
| 1176 | } |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | /** |
| 1181 | * Synonym for {@link #openOutputStream(Uri, String) |
| 1182 | * openOutputStream(uri, "w")}. |
| 1183 | * @throws FileNotFoundException if the provided URI could not be opened. |
| 1184 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1185 | public final @Nullable OutputStream openOutputStream(@NonNull Uri uri) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1186 | throws FileNotFoundException { |
| 1187 | return openOutputStream(uri, "w"); |
| 1188 | } |
| 1189 | |
| 1190 | /** |
| 1191 | * Open a stream on to the content associated with a content URI. If there |
| 1192 | * is no data associated with the URI, FileNotFoundException is thrown. |
| 1193 | * |
| 1194 | * <h5>Accepts the following URI schemes:</h5> |
| 1195 | * <ul> |
| 1196 | * <li>content ({@link #SCHEME_CONTENT})</li> |
| 1197 | * <li>file ({@link #SCHEME_FILE})</li> |
| 1198 | * </ul> |
| 1199 | * |
| 1200 | * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information |
| 1201 | * on these schemes. |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 1202 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1203 | * @param uri The desired URI. |
| 1204 | * @param mode May be "w", "wa", "rw", or "rwt". |
| 1205 | * @return OutputStream |
| 1206 | * @throws FileNotFoundException if the provided URI could not be opened. |
| 1207 | * @see #openAssetFileDescriptor(Uri, String) |
| 1208 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1209 | public final @Nullable OutputStream openOutputStream(@NonNull Uri uri, @NonNull String mode) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1210 | throws FileNotFoundException { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1211 | AssetFileDescriptor fd = openAssetFileDescriptor(uri, mode, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1212 | try { |
| 1213 | return fd != null ? fd.createOutputStream() : null; |
| 1214 | } catch (IOException e) { |
| 1215 | throw new FileNotFoundException("Unable to create stream"); |
| 1216 | } |
| 1217 | } |
| 1218 | |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1219 | @Override |
| 1220 | public final @Nullable ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode, |
| 1221 | @Nullable CancellationSignal signal) throws FileNotFoundException { |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1222 | try { |
| 1223 | if (mWrapped != null) return mWrapped.openFile(uri, mode, signal); |
| 1224 | } catch (RemoteException e) { |
| 1225 | return null; |
| 1226 | } |
| 1227 | |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1228 | return openFileDescriptor(uri, mode, signal); |
| 1229 | } |
| 1230 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1231 | /** |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1232 | * Open a raw file descriptor to access data under a URI. This |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | * is like {@link #openAssetFileDescriptor(Uri, String)}, but uses the |
| 1234 | * underlying {@link ContentProvider#openFile} |
| 1235 | * ContentProvider.openFile()} method, so will <em>not</em> work with |
| 1236 | * providers that return sub-sections of files. If at all possible, |
| 1237 | * you should use {@link #openAssetFileDescriptor(Uri, String)}. You |
| 1238 | * will receive a FileNotFoundException exception if the provider returns a |
| 1239 | * sub-section of a file. |
| 1240 | * |
| 1241 | * <h5>Accepts the following URI schemes:</h5> |
| 1242 | * <ul> |
| 1243 | * <li>content ({@link #SCHEME_CONTENT})</li> |
| 1244 | * <li>file ({@link #SCHEME_FILE})</li> |
| 1245 | * </ul> |
| 1246 | * |
| 1247 | * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information |
| 1248 | * on these schemes. |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1249 | * <p> |
| 1250 | * If opening with the exclusive "r" or "w" modes, the returned |
| 1251 | * ParcelFileDescriptor could be a pipe or socket pair to enable streaming |
| 1252 | * of data. Opening with the "rw" mode implies a file on disk that supports |
| 1253 | * seeking. If possible, always use an exclusive mode to give the underlying |
| 1254 | * {@link ContentProvider} the most flexibility. |
| 1255 | * <p> |
| 1256 | * If you are writing a file, and need to communicate an error to the |
| 1257 | * provider, use {@link ParcelFileDescriptor#closeWithError(String)}. |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 1258 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1259 | * @param uri The desired URI to open. |
| 1260 | * @param mode The file mode to use, as per {@link ContentProvider#openFile |
| 1261 | * ContentProvider.openFile}. |
| 1262 | * @return Returns a new ParcelFileDescriptor pointing to the file. You |
| 1263 | * own this descriptor and are responsible for closing it when done. |
Yury Zhauniarovich | f9c5176 | 2012-05-12 18:39:25 +0200 | [diff] [blame] | 1264 | * @throws FileNotFoundException Throws FileNotFoundException if no |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1265 | * file exists under the URI or the mode is invalid. |
| 1266 | * @see #openAssetFileDescriptor(Uri, String) |
| 1267 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1268 | public final @Nullable ParcelFileDescriptor openFileDescriptor(@NonNull Uri uri, |
| 1269 | @NonNull String mode) throws FileNotFoundException { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1270 | return openFileDescriptor(uri, mode, null); |
| 1271 | } |
| 1272 | |
| 1273 | /** |
| 1274 | * Open a raw file descriptor to access data under a URI. This |
| 1275 | * is like {@link #openAssetFileDescriptor(Uri, String)}, but uses the |
| 1276 | * underlying {@link ContentProvider#openFile} |
| 1277 | * ContentProvider.openFile()} method, so will <em>not</em> work with |
| 1278 | * providers that return sub-sections of files. If at all possible, |
| 1279 | * you should use {@link #openAssetFileDescriptor(Uri, String)}. You |
| 1280 | * will receive a FileNotFoundException exception if the provider returns a |
| 1281 | * sub-section of a file. |
| 1282 | * |
| 1283 | * <h5>Accepts the following URI schemes:</h5> |
| 1284 | * <ul> |
| 1285 | * <li>content ({@link #SCHEME_CONTENT})</li> |
| 1286 | * <li>file ({@link #SCHEME_FILE})</li> |
| 1287 | * </ul> |
| 1288 | * |
| 1289 | * <p>See {@link #openAssetFileDescriptor(Uri, String)} for more information |
| 1290 | * on these schemes. |
| 1291 | * <p> |
| 1292 | * If opening with the exclusive "r" or "w" modes, the returned |
| 1293 | * ParcelFileDescriptor could be a pipe or socket pair to enable streaming |
| 1294 | * of data. Opening with the "rw" mode implies a file on disk that supports |
| 1295 | * seeking. If possible, always use an exclusive mode to give the underlying |
| 1296 | * {@link ContentProvider} the most flexibility. |
| 1297 | * <p> |
| 1298 | * If you are writing a file, and need to communicate an error to the |
| 1299 | * provider, use {@link ParcelFileDescriptor#closeWithError(String)}. |
| 1300 | * |
| 1301 | * @param uri The desired URI to open. |
| 1302 | * @param mode The file mode to use, as per {@link ContentProvider#openFile |
| 1303 | * ContentProvider.openFile}. |
Ying Wang | 9436631 | 2013-08-23 22:20:03 -0700 | [diff] [blame] | 1304 | * @param cancellationSignal A signal to cancel the operation in progress, |
| 1305 | * or null if none. If the operation is canceled, then |
| 1306 | * {@link OperationCanceledException} will be thrown. |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1307 | * @return Returns a new ParcelFileDescriptor pointing to the file. You |
| 1308 | * own this descriptor and are responsible for closing it when done. |
| 1309 | * @throws FileNotFoundException Throws FileNotFoundException if no |
| 1310 | * file exists under the URI or the mode is invalid. |
| 1311 | * @see #openAssetFileDescriptor(Uri, String) |
| 1312 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1313 | public final @Nullable ParcelFileDescriptor openFileDescriptor(@NonNull Uri uri, |
| 1314 | @NonNull String mode, @Nullable CancellationSignal cancellationSignal) |
| 1315 | throws FileNotFoundException { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1316 | AssetFileDescriptor afd = openAssetFileDescriptor(uri, mode, cancellationSignal); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1317 | if (afd == null) { |
| 1318 | return null; |
| 1319 | } |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 1320 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1321 | if (afd.getDeclaredLength() < 0) { |
| 1322 | // This is a full file! |
| 1323 | return afd.getParcelFileDescriptor(); |
| 1324 | } |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 1325 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1326 | // Client can't handle a sub-section of a file, so close what |
| 1327 | // we got and bail with an exception. |
| 1328 | try { |
| 1329 | afd.close(); |
| 1330 | } catch (IOException e) { |
| 1331 | } |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 1332 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1333 | throw new FileNotFoundException("Not a whole file"); |
| 1334 | } |
| 1335 | |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1336 | @Override |
| 1337 | public final @Nullable AssetFileDescriptor openAssetFile(@NonNull Uri uri, @NonNull String mode, |
| 1338 | @Nullable CancellationSignal signal) throws FileNotFoundException { |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1339 | try { |
| 1340 | if (mWrapped != null) return mWrapped.openAssetFile(uri, mode, signal); |
| 1341 | } catch (RemoteException e) { |
| 1342 | return null; |
| 1343 | } |
| 1344 | |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1345 | return openAssetFileDescriptor(uri, mode, signal); |
| 1346 | } |
| 1347 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1348 | /** |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1349 | * Open a raw file descriptor to access data under a URI. This |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1350 | * interacts with the underlying {@link ContentProvider#openAssetFile} |
Gilles Debunne | 03f0292 | 2010-06-09 14:11:45 -0700 | [diff] [blame] | 1351 | * method of the provider associated with the given URI, to retrieve any file stored there. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1352 | * |
| 1353 | * <h5>Accepts the following URI schemes:</h5> |
| 1354 | * <ul> |
| 1355 | * <li>content ({@link #SCHEME_CONTENT})</li> |
| 1356 | * <li>android.resource ({@link #SCHEME_ANDROID_RESOURCE})</li> |
| 1357 | * <li>file ({@link #SCHEME_FILE})</li> |
| 1358 | * </ul> |
| 1359 | * <h5>The android.resource ({@link #SCHEME_ANDROID_RESOURCE}) Scheme</h5> |
| 1360 | * <p> |
| 1361 | * A Uri object can be used to reference a resource in an APK file. The |
| 1362 | * Uri should be one of the following formats: |
| 1363 | * <ul> |
| 1364 | * <li><code>android.resource://package_name/id_number</code><br/> |
| 1365 | * <code>package_name</code> is your package name as listed in your AndroidManifest.xml. |
| 1366 | * For example <code>com.example.myapp</code><br/> |
| 1367 | * <code>id_number</code> is the int form of the ID.<br/> |
| 1368 | * The easiest way to construct this form is |
| 1369 | * <pre>Uri uri = Uri.parse("android.resource://com.example.myapp/" + R.raw.my_resource");</pre> |
| 1370 | * </li> |
| 1371 | * <li><code>android.resource://package_name/type/name</code><br/> |
| 1372 | * <code>package_name</code> is your package name as listed in your AndroidManifest.xml. |
| 1373 | * For example <code>com.example.myapp</code><br/> |
| 1374 | * <code>type</code> is the string form of the resource type. For example, <code>raw</code> |
| 1375 | * or <code>drawable</code>. |
| 1376 | * <code>name</code> is the string form of the resource name. That is, whatever the file |
| 1377 | * name was in your res directory, without the type extension. |
| 1378 | * The easiest way to construct this form is |
| 1379 | * <pre>Uri uri = Uri.parse("android.resource://com.example.myapp/raw/my_resource");</pre> |
| 1380 | * </li> |
| 1381 | * </ul> |
| 1382 | * |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1383 | * <p>Note that if this function is called for read-only input (mode is "r") |
| 1384 | * on a content: URI, it will instead call {@link #openTypedAssetFileDescriptor} |
John Spurlock | 3390018 | 2014-01-02 11:04:18 -0500 | [diff] [blame] | 1385 | * for you with a MIME type of "*/*". This allows such callers to benefit |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1386 | * from any built-in data conversion that a provider implements. |
| 1387 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1388 | * @param uri The desired URI to open. |
| 1389 | * @param mode The file mode to use, as per {@link ContentProvider#openAssetFile |
| 1390 | * ContentProvider.openAssetFile}. |
| 1391 | * @return Returns a new ParcelFileDescriptor pointing to the file. You |
| 1392 | * own this descriptor and are responsible for closing it when done. |
| 1393 | * @throws FileNotFoundException Throws FileNotFoundException of no |
| 1394 | * file exists under the URI or the mode is invalid. |
| 1395 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1396 | public final @Nullable AssetFileDescriptor openAssetFileDescriptor(@NonNull Uri uri, |
| 1397 | @NonNull String mode) throws FileNotFoundException { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1398 | return openAssetFileDescriptor(uri, mode, null); |
| 1399 | } |
| 1400 | |
| 1401 | /** |
| 1402 | * Open a raw file descriptor to access data under a URI. This |
| 1403 | * interacts with the underlying {@link ContentProvider#openAssetFile} |
| 1404 | * method of the provider associated with the given URI, to retrieve any file stored there. |
| 1405 | * |
| 1406 | * <h5>Accepts the following URI schemes:</h5> |
| 1407 | * <ul> |
| 1408 | * <li>content ({@link #SCHEME_CONTENT})</li> |
| 1409 | * <li>android.resource ({@link #SCHEME_ANDROID_RESOURCE})</li> |
| 1410 | * <li>file ({@link #SCHEME_FILE})</li> |
| 1411 | * </ul> |
| 1412 | * <h5>The android.resource ({@link #SCHEME_ANDROID_RESOURCE}) Scheme</h5> |
| 1413 | * <p> |
| 1414 | * A Uri object can be used to reference a resource in an APK file. The |
| 1415 | * Uri should be one of the following formats: |
| 1416 | * <ul> |
| 1417 | * <li><code>android.resource://package_name/id_number</code><br/> |
| 1418 | * <code>package_name</code> is your package name as listed in your AndroidManifest.xml. |
| 1419 | * For example <code>com.example.myapp</code><br/> |
| 1420 | * <code>id_number</code> is the int form of the ID.<br/> |
| 1421 | * The easiest way to construct this form is |
| 1422 | * <pre>Uri uri = Uri.parse("android.resource://com.example.myapp/" + R.raw.my_resource");</pre> |
| 1423 | * </li> |
| 1424 | * <li><code>android.resource://package_name/type/name</code><br/> |
| 1425 | * <code>package_name</code> is your package name as listed in your AndroidManifest.xml. |
| 1426 | * For example <code>com.example.myapp</code><br/> |
| 1427 | * <code>type</code> is the string form of the resource type. For example, <code>raw</code> |
| 1428 | * or <code>drawable</code>. |
| 1429 | * <code>name</code> is the string form of the resource name. That is, whatever the file |
| 1430 | * name was in your res directory, without the type extension. |
| 1431 | * The easiest way to construct this form is |
| 1432 | * <pre>Uri uri = Uri.parse("android.resource://com.example.myapp/raw/my_resource");</pre> |
| 1433 | * </li> |
| 1434 | * </ul> |
| 1435 | * |
| 1436 | * <p>Note that if this function is called for read-only input (mode is "r") |
| 1437 | * on a content: URI, it will instead call {@link #openTypedAssetFileDescriptor} |
John Spurlock | 3390018 | 2014-01-02 11:04:18 -0500 | [diff] [blame] | 1438 | * for you with a MIME type of "*/*". This allows such callers to benefit |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1439 | * from any built-in data conversion that a provider implements. |
| 1440 | * |
| 1441 | * @param uri The desired URI to open. |
| 1442 | * @param mode The file mode to use, as per {@link ContentProvider#openAssetFile |
| 1443 | * ContentProvider.openAssetFile}. |
Ying Wang | 9436631 | 2013-08-23 22:20:03 -0700 | [diff] [blame] | 1444 | * @param cancellationSignal A signal to cancel the operation in progress, or null if |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1445 | * none. If the operation is canceled, then |
| 1446 | * {@link OperationCanceledException} will be thrown. |
| 1447 | * @return Returns a new ParcelFileDescriptor pointing to the file. You |
| 1448 | * own this descriptor and are responsible for closing it when done. |
| 1449 | * @throws FileNotFoundException Throws FileNotFoundException of no |
| 1450 | * file exists under the URI or the mode is invalid. |
| 1451 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1452 | public final @Nullable AssetFileDescriptor openAssetFileDescriptor(@NonNull Uri uri, |
| 1453 | @NonNull String mode, @Nullable CancellationSignal cancellationSignal) |
| 1454 | throws FileNotFoundException { |
| 1455 | Preconditions.checkNotNull(uri, "uri"); |
| 1456 | Preconditions.checkNotNull(mode, "mode"); |
| 1457 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1458 | String scheme = uri.getScheme(); |
| 1459 | if (SCHEME_ANDROID_RESOURCE.equals(scheme)) { |
| 1460 | if (!"r".equals(mode)) { |
| 1461 | throw new FileNotFoundException("Can't write resources: " + uri); |
| 1462 | } |
| 1463 | OpenResourceIdResult r = getResourceId(uri); |
| 1464 | try { |
| 1465 | return r.r.openRawResourceFd(r.id); |
| 1466 | } catch (Resources.NotFoundException ex) { |
| 1467 | throw new FileNotFoundException("Resource does not exist: " + uri); |
| 1468 | } |
| 1469 | } else if (SCHEME_FILE.equals(scheme)) { |
| 1470 | ParcelFileDescriptor pfd = ParcelFileDescriptor.open( |
Adam Lesinski | eb8c3f9 | 2013-09-20 14:08:25 -0700 | [diff] [blame] | 1471 | new File(uri.getPath()), ParcelFileDescriptor.parseMode(mode)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1472 | return new AssetFileDescriptor(pfd, 0, -1); |
| 1473 | } else { |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1474 | if ("r".equals(mode)) { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1475 | return openTypedAssetFileDescriptor(uri, "*/*", null, cancellationSignal); |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1476 | } else { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1477 | IContentProvider unstableProvider = acquireUnstableProvider(uri); |
| 1478 | if (unstableProvider == null) { |
| 1479 | throw new FileNotFoundException("No content provider: " + uri); |
| 1480 | } |
| 1481 | IContentProvider stableProvider = null; |
| 1482 | AssetFileDescriptor fd = null; |
| 1483 | |
| 1484 | try { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1485 | ICancellationSignal remoteCancellationSignal = null; |
| 1486 | if (cancellationSignal != null) { |
| 1487 | cancellationSignal.throwIfCanceled(); |
| 1488 | remoteCancellationSignal = unstableProvider.createCancellationSignal(); |
| 1489 | cancellationSignal.setRemote(remoteCancellationSignal); |
| 1490 | } |
| 1491 | |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1492 | try { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1493 | fd = unstableProvider.openAssetFile( |
| 1494 | mPackageName, uri, mode, remoteCancellationSignal); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1495 | if (fd == null) { |
| 1496 | // The provider will be released by the finally{} clause |
| 1497 | return null; |
| 1498 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1499 | } catch (DeadObjectException e) { |
| 1500 | // The remote process has died... but we only hold an unstable |
| 1501 | // reference though, so we might recover!!! Let's try!!!! |
| 1502 | // This is exciting!!1!!1!!!!1 |
| 1503 | unstableProviderDied(unstableProvider); |
| 1504 | stableProvider = acquireProvider(uri); |
| 1505 | if (stableProvider == null) { |
| 1506 | throw new FileNotFoundException("No content provider: " + uri); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1507 | } |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1508 | fd = stableProvider.openAssetFile( |
| 1509 | mPackageName, uri, mode, remoteCancellationSignal); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1510 | if (fd == null) { |
| 1511 | // The provider will be released by the finally{} clause |
| 1512 | return null; |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1513 | } |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1514 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1515 | |
| 1516 | if (stableProvider == null) { |
| 1517 | stableProvider = acquireProvider(uri); |
| 1518 | } |
| 1519 | releaseUnstableProvider(unstableProvider); |
Koji Fukui | f783c02 | 2014-02-07 15:01:36 +0900 | [diff] [blame] | 1520 | unstableProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1521 | ParcelFileDescriptor pfd = new ParcelFileDescriptorInner( |
| 1522 | fd.getParcelFileDescriptor(), stableProvider); |
| 1523 | |
| 1524 | // Success! Don't release the provider when exiting, let |
| 1525 | // ParcelFileDescriptorInner do that when it is closed. |
| 1526 | stableProvider = null; |
| 1527 | |
| 1528 | return new AssetFileDescriptor(pfd, fd.getStartOffset(), |
| 1529 | fd.getDeclaredLength()); |
| 1530 | |
| 1531 | } catch (RemoteException e) { |
| 1532 | // Whatever, whatever, we'll go away. |
| 1533 | throw new FileNotFoundException( |
| 1534 | "Failed opening content provider: " + uri); |
| 1535 | } catch (FileNotFoundException e) { |
| 1536 | throw e; |
| 1537 | } finally { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1538 | if (cancellationSignal != null) { |
| 1539 | cancellationSignal.setRemote(null); |
| 1540 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1541 | if (stableProvider != null) { |
| 1542 | releaseProvider(stableProvider); |
| 1543 | } |
| 1544 | if (unstableProvider != null) { |
| 1545 | releaseUnstableProvider(unstableProvider); |
| 1546 | } |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | } |
| 1550 | } |
| 1551 | |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1552 | @Override |
| 1553 | public final @Nullable AssetFileDescriptor openTypedAssetFile(@NonNull Uri uri, |
| 1554 | @NonNull String mimeTypeFilter, @Nullable Bundle opts, |
| 1555 | @Nullable CancellationSignal signal) throws FileNotFoundException { |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1556 | try { |
| 1557 | if (mWrapped != null) { |
| 1558 | return mWrapped.openTypedAssetFile(uri, mimeTypeFilter, opts, signal); |
| 1559 | } |
| 1560 | } catch (RemoteException e) { |
| 1561 | return null; |
| 1562 | } |
| 1563 | |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1564 | return openTypedAssetFileDescriptor(uri, mimeTypeFilter, opts, signal); |
| 1565 | } |
| 1566 | |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1567 | /** |
| 1568 | * Open a raw file descriptor to access (potentially type transformed) |
| 1569 | * data from a "content:" URI. This interacts with the underlying |
| 1570 | * {@link ContentProvider#openTypedAssetFile} method of the provider |
| 1571 | * associated with the given URI, to retrieve retrieve any appropriate |
| 1572 | * data stream for the data stored there. |
| 1573 | * |
| 1574 | * <p>Unlike {@link #openAssetFileDescriptor}, this function only works |
| 1575 | * with "content:" URIs, because content providers are the only facility |
| 1576 | * with an associated MIME type to ensure that the returned data stream |
| 1577 | * is of the desired type. |
| 1578 | * |
| 1579 | * <p>All text/* streams are encoded in UTF-8. |
| 1580 | * |
| 1581 | * @param uri The desired URI to open. |
| 1582 | * @param mimeType The desired MIME type of the returned data. This can |
John Spurlock | 3390018 | 2014-01-02 11:04:18 -0500 | [diff] [blame] | 1583 | * be a pattern such as */*, which will allow the content provider to |
Dianne Hackborn | 23fdaf6 | 2010-08-06 12:16:55 -0700 | [diff] [blame] | 1584 | * select a type, though there is no way for you to determine what type |
| 1585 | * it is returning. |
| 1586 | * @param opts Additional provider-dependent options. |
| 1587 | * @return Returns a new ParcelFileDescriptor from which you can read the |
| 1588 | * data stream from the provider. Note that this may be a pipe, meaning |
| 1589 | * you can't seek in it. The only seek you should do is if the |
| 1590 | * AssetFileDescriptor contains an offset, to move to that offset before |
| 1591 | * reading. You own this descriptor and are responsible for closing it when done. |
| 1592 | * @throws FileNotFoundException Throws FileNotFoundException of no |
| 1593 | * data of the desired type exists under the URI. |
| 1594 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1595 | public final @Nullable AssetFileDescriptor openTypedAssetFileDescriptor(@NonNull Uri uri, |
| 1596 | @NonNull String mimeType, @Nullable Bundle opts) throws FileNotFoundException { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1597 | return openTypedAssetFileDescriptor(uri, mimeType, opts, null); |
| 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * Open a raw file descriptor to access (potentially type transformed) |
| 1602 | * data from a "content:" URI. This interacts with the underlying |
| 1603 | * {@link ContentProvider#openTypedAssetFile} method of the provider |
| 1604 | * associated with the given URI, to retrieve retrieve any appropriate |
| 1605 | * data stream for the data stored there. |
| 1606 | * |
| 1607 | * <p>Unlike {@link #openAssetFileDescriptor}, this function only works |
| 1608 | * with "content:" URIs, because content providers are the only facility |
| 1609 | * with an associated MIME type to ensure that the returned data stream |
| 1610 | * is of the desired type. |
| 1611 | * |
| 1612 | * <p>All text/* streams are encoded in UTF-8. |
| 1613 | * |
| 1614 | * @param uri The desired URI to open. |
| 1615 | * @param mimeType The desired MIME type of the returned data. This can |
John Spurlock | 3390018 | 2014-01-02 11:04:18 -0500 | [diff] [blame] | 1616 | * be a pattern such as */*, which will allow the content provider to |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1617 | * select a type, though there is no way for you to determine what type |
| 1618 | * it is returning. |
| 1619 | * @param opts Additional provider-dependent options. |
Ying Wang | 9436631 | 2013-08-23 22:20:03 -0700 | [diff] [blame] | 1620 | * @param cancellationSignal A signal to cancel the operation in progress, |
| 1621 | * or null if none. If the operation is canceled, then |
| 1622 | * {@link OperationCanceledException} will be thrown. |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1623 | * @return Returns a new ParcelFileDescriptor from which you can read the |
| 1624 | * data stream from the provider. Note that this may be a pipe, meaning |
| 1625 | * you can't seek in it. The only seek you should do is if the |
| 1626 | * AssetFileDescriptor contains an offset, to move to that offset before |
| 1627 | * reading. You own this descriptor and are responsible for closing it when done. |
| 1628 | * @throws FileNotFoundException Throws FileNotFoundException of no |
| 1629 | * data of the desired type exists under the URI. |
| 1630 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1631 | public final @Nullable AssetFileDescriptor openTypedAssetFileDescriptor(@NonNull Uri uri, |
| 1632 | @NonNull String mimeType, @Nullable Bundle opts, |
| 1633 | @Nullable CancellationSignal cancellationSignal) throws FileNotFoundException { |
| 1634 | Preconditions.checkNotNull(uri, "uri"); |
| 1635 | Preconditions.checkNotNull(mimeType, "mimeType"); |
| 1636 | |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1637 | IContentProvider unstableProvider = acquireUnstableProvider(uri); |
| 1638 | if (unstableProvider == null) { |
| 1639 | throw new FileNotFoundException("No content provider: " + uri); |
| 1640 | } |
| 1641 | IContentProvider stableProvider = null; |
| 1642 | AssetFileDescriptor fd = null; |
| 1643 | |
| 1644 | try { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1645 | ICancellationSignal remoteCancellationSignal = null; |
| 1646 | if (cancellationSignal != null) { |
| 1647 | cancellationSignal.throwIfCanceled(); |
| 1648 | remoteCancellationSignal = unstableProvider.createCancellationSignal(); |
| 1649 | cancellationSignal.setRemote(remoteCancellationSignal); |
| 1650 | } |
| 1651 | |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1652 | try { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1653 | fd = unstableProvider.openTypedAssetFile( |
| 1654 | mPackageName, uri, mimeType, opts, remoteCancellationSignal); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1655 | if (fd == null) { |
| 1656 | // The provider will be released by the finally{} clause |
| 1657 | return null; |
| 1658 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1659 | } catch (DeadObjectException e) { |
| 1660 | // The remote process has died... but we only hold an unstable |
| 1661 | // reference though, so we might recover!!! Let's try!!!! |
| 1662 | // This is exciting!!1!!1!!!!1 |
| 1663 | unstableProviderDied(unstableProvider); |
| 1664 | stableProvider = acquireProvider(uri); |
| 1665 | if (stableProvider == null) { |
| 1666 | throw new FileNotFoundException("No content provider: " + uri); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1667 | } |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1668 | fd = stableProvider.openTypedAssetFile( |
| 1669 | mPackageName, uri, mimeType, opts, remoteCancellationSignal); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1670 | if (fd == null) { |
| 1671 | // The provider will be released by the finally{} clause |
| 1672 | return null; |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 1673 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1674 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1675 | |
| 1676 | if (stableProvider == null) { |
| 1677 | stableProvider = acquireProvider(uri); |
| 1678 | } |
| 1679 | releaseUnstableProvider(unstableProvider); |
Koji Fukui | f783c02 | 2014-02-07 15:01:36 +0900 | [diff] [blame] | 1680 | unstableProvider = null; |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1681 | ParcelFileDescriptor pfd = new ParcelFileDescriptorInner( |
| 1682 | fd.getParcelFileDescriptor(), stableProvider); |
| 1683 | |
| 1684 | // Success! Don't release the provider when exiting, let |
| 1685 | // ParcelFileDescriptorInner do that when it is closed. |
| 1686 | stableProvider = null; |
| 1687 | |
| 1688 | return new AssetFileDescriptor(pfd, fd.getStartOffset(), |
| 1689 | fd.getDeclaredLength()); |
| 1690 | |
| 1691 | } catch (RemoteException e) { |
| 1692 | // Whatever, whatever, we'll go away. |
| 1693 | throw new FileNotFoundException( |
| 1694 | "Failed opening content provider: " + uri); |
| 1695 | } catch (FileNotFoundException e) { |
| 1696 | throw e; |
| 1697 | } finally { |
Jeff Sharkey | bd3b902 | 2013-08-20 15:20:04 -0700 | [diff] [blame] | 1698 | if (cancellationSignal != null) { |
| 1699 | cancellationSignal.setRemote(null); |
| 1700 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 1701 | if (stableProvider != null) { |
| 1702 | releaseProvider(stableProvider); |
| 1703 | } |
| 1704 | if (unstableProvider != null) { |
| 1705 | releaseUnstableProvider(unstableProvider); |
| 1706 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1707 | } |
| 1708 | } |
| 1709 | |
Bjorn Bringert | 4c87a3f | 2009-09-16 15:59:37 +0100 | [diff] [blame] | 1710 | /** |
| 1711 | * A resource identified by the {@link Resources} that contains it, and a resource id. |
| 1712 | * |
| 1713 | * @hide |
| 1714 | */ |
| 1715 | public class OpenResourceIdResult { |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1716 | @UnsupportedAppUsage |
Bjorn Bringert | 4c87a3f | 2009-09-16 15:59:37 +0100 | [diff] [blame] | 1717 | public Resources r; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1718 | @UnsupportedAppUsage |
Bjorn Bringert | 4c87a3f | 2009-09-16 15:59:37 +0100 | [diff] [blame] | 1719 | public int id; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1720 | } |
Bjorn Bringert | 4c87a3f | 2009-09-16 15:59:37 +0100 | [diff] [blame] | 1721 | |
| 1722 | /** |
| 1723 | * Resolves an android.resource URI to a {@link Resources} and a resource id. |
| 1724 | * |
| 1725 | * @hide |
| 1726 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 1727 | @UnsupportedAppUsage |
Bjorn Bringert | 4c87a3f | 2009-09-16 15:59:37 +0100 | [diff] [blame] | 1728 | public OpenResourceIdResult getResourceId(Uri uri) throws FileNotFoundException { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1729 | String authority = uri.getAuthority(); |
| 1730 | Resources r; |
| 1731 | if (TextUtils.isEmpty(authority)) { |
| 1732 | throw new FileNotFoundException("No authority: " + uri); |
| 1733 | } else { |
| 1734 | try { |
| 1735 | r = mContext.getPackageManager().getResourcesForApplication(authority); |
| 1736 | } catch (NameNotFoundException ex) { |
| 1737 | throw new FileNotFoundException("No package found for authority: " + uri); |
| 1738 | } |
| 1739 | } |
| 1740 | List<String> path = uri.getPathSegments(); |
| 1741 | if (path == null) { |
| 1742 | throw new FileNotFoundException("No path: " + uri); |
| 1743 | } |
| 1744 | int len = path.size(); |
| 1745 | int id; |
| 1746 | if (len == 1) { |
| 1747 | try { |
| 1748 | id = Integer.parseInt(path.get(0)); |
| 1749 | } catch (NumberFormatException e) { |
| 1750 | throw new FileNotFoundException("Single path segment is not a resource ID: " + uri); |
| 1751 | } |
| 1752 | } else if (len == 2) { |
| 1753 | id = r.getIdentifier(path.get(1), path.get(0), authority); |
| 1754 | } else { |
| 1755 | throw new FileNotFoundException("More than two path segments: " + uri); |
| 1756 | } |
| 1757 | if (id == 0) { |
| 1758 | throw new FileNotFoundException("No resource found for: " + uri); |
| 1759 | } |
| 1760 | OpenResourceIdResult res = new OpenResourceIdResult(); |
| 1761 | res.r = r; |
| 1762 | res.id = id; |
| 1763 | return res; |
| 1764 | } |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 1765 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1766 | /** |
| 1767 | * Inserts a row into a table at the given URL. |
| 1768 | * |
| 1769 | * If the content provider supports transactions the insertion will be atomic. |
| 1770 | * |
| 1771 | * @param url The URL of the table to insert into. |
| 1772 | * @param values The initial values for the newly inserted row. The key is the column name for |
| 1773 | * the field. Passing an empty ContentValues will create an empty row. |
| 1774 | * @return the URL of the newly created row. |
| 1775 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1776 | @Override |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 1777 | public final @Nullable Uri insert(@RequiresPermission.Write @NonNull Uri url, |
| 1778 | @Nullable ContentValues values) { |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1779 | Preconditions.checkNotNull(url, "url"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1780 | |
| 1781 | try { |
| 1782 | if (mWrapped != null) return mWrapped.insert(url, values); |
| 1783 | } catch (RemoteException e) { |
| 1784 | return null; |
| 1785 | } |
| 1786 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | IContentProvider provider = acquireProvider(url); |
| 1788 | if (provider == null) { |
| 1789 | throw new IllegalArgumentException("Unknown URL " + url); |
| 1790 | } |
| 1791 | try { |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 1792 | long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1793 | Uri createdRow = provider.insert(mPackageName, url, values); |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 1794 | long durationMillis = SystemClock.uptimeMillis() - startTime; |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 1795 | maybeLogUpdateToEventLog(durationMillis, url, "insert", null /* where */); |
| 1796 | return createdRow; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1797 | } catch (RemoteException e) { |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 1798 | // Arbitrary and not worth documenting, as Activity |
| 1799 | // Manager will kill this process shortly anyway. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1800 | return null; |
| 1801 | } finally { |
| 1802 | releaseProvider(provider); |
| 1803 | } |
| 1804 | } |
| 1805 | |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 1806 | /** |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 1807 | * Applies each of the {@link ContentProviderOperation} objects and returns an array |
| 1808 | * of their results. Passes through OperationApplicationException, which may be thrown |
| 1809 | * by the call to {@link ContentProviderOperation#apply}. |
| 1810 | * If all the applications succeed then a {@link ContentProviderResult} array with the |
| 1811 | * same number of elements as the operations will be returned. It is implementation-specific |
| 1812 | * how many, if any, operations will have been successfully applied if a call to |
| 1813 | * apply results in a {@link OperationApplicationException}. |
| 1814 | * @param authority the authority of the ContentProvider to which this batch should be applied |
| 1815 | * @param operations the operations to apply |
| 1816 | * @return the results of the applications |
| 1817 | * @throws OperationApplicationException thrown if an application fails. |
| 1818 | * See {@link ContentProviderOperation#apply} for more information. |
| 1819 | * @throws RemoteException thrown if a RemoteException is encountered while attempting |
| 1820 | * to communicate with a remote provider. |
| 1821 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1822 | @Override |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1823 | public @NonNull ContentProviderResult[] applyBatch(@NonNull String authority, |
| 1824 | @NonNull ArrayList<ContentProviderOperation> operations) |
| 1825 | throws RemoteException, OperationApplicationException { |
| 1826 | Preconditions.checkNotNull(authority, "authority"); |
| 1827 | Preconditions.checkNotNull(operations, "operations"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1828 | |
| 1829 | try { |
| 1830 | if (mWrapped != null) return mWrapped.applyBatch(authority, operations); |
| 1831 | } catch (RemoteException e) { |
| 1832 | return null; |
| 1833 | } |
| 1834 | |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 1835 | ContentProviderClient provider = acquireContentProviderClient(authority); |
Fred Quintana | 6a8d533 | 2009-05-07 17:35:38 -0700 | [diff] [blame] | 1836 | if (provider == null) { |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 1837 | throw new IllegalArgumentException("Unknown authority " + authority); |
Fred Quintana | 6a8d533 | 2009-05-07 17:35:38 -0700 | [diff] [blame] | 1838 | } |
| 1839 | try { |
Fred Quintana | 8943737 | 2009-05-15 15:10:40 -0700 | [diff] [blame] | 1840 | return provider.applyBatch(operations); |
Fred Quintana | 6a8d533 | 2009-05-07 17:35:38 -0700 | [diff] [blame] | 1841 | } finally { |
| 1842 | provider.release(); |
| 1843 | } |
| 1844 | } |
| 1845 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1846 | /** |
| 1847 | * Inserts multiple rows into a table at the given URL. |
| 1848 | * |
| 1849 | * This function make no guarantees about the atomicity of the insertions. |
| 1850 | * |
| 1851 | * @param url The URL of the table to insert into. |
| 1852 | * @param values The initial values for the newly inserted rows. The key is the column name for |
| 1853 | * the field. Passing null will create an empty row. |
| 1854 | * @return the number of newly created rows. |
| 1855 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1856 | @Override |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 1857 | public final int bulkInsert(@RequiresPermission.Write @NonNull Uri url, |
| 1858 | @NonNull ContentValues[] values) { |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1859 | Preconditions.checkNotNull(url, "url"); |
| 1860 | Preconditions.checkNotNull(values, "values"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1861 | |
| 1862 | try { |
| 1863 | if (mWrapped != null) return mWrapped.bulkInsert(url, values); |
| 1864 | } catch (RemoteException e) { |
| 1865 | return 0; |
| 1866 | } |
| 1867 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1868 | IContentProvider provider = acquireProvider(url); |
| 1869 | if (provider == null) { |
| 1870 | throw new IllegalArgumentException("Unknown URL " + url); |
| 1871 | } |
| 1872 | try { |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 1873 | long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1874 | int rowsCreated = provider.bulkInsert(mPackageName, url, values); |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 1875 | long durationMillis = SystemClock.uptimeMillis() - startTime; |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 1876 | maybeLogUpdateToEventLog(durationMillis, url, "bulkinsert", null /* where */); |
| 1877 | return rowsCreated; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1878 | } catch (RemoteException e) { |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 1879 | // Arbitrary and not worth documenting, as Activity |
| 1880 | // Manager will kill this process shortly anyway. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1881 | return 0; |
| 1882 | } finally { |
| 1883 | releaseProvider(provider); |
| 1884 | } |
| 1885 | } |
| 1886 | |
| 1887 | /** |
| 1888 | * Deletes row(s) specified by a content URI. |
| 1889 | * |
| 1890 | * If the content provider supports transactions, the deletion will be atomic. |
| 1891 | * |
| 1892 | * @param url The URL of the row to delete. |
| 1893 | * @param where A filter to apply to rows before deleting, formatted as an SQL WHERE clause |
| 1894 | (excluding the WHERE itself). |
| 1895 | * @return The number of rows deleted. |
| 1896 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1897 | @Override |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 1898 | public final int delete(@RequiresPermission.Write @NonNull Uri url, @Nullable String where, |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1899 | @Nullable String[] selectionArgs) { |
| 1900 | Preconditions.checkNotNull(url, "url"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1901 | |
| 1902 | try { |
| 1903 | if (mWrapped != null) return mWrapped.delete(url, where, selectionArgs); |
| 1904 | } catch (RemoteException e) { |
| 1905 | return 0; |
| 1906 | } |
| 1907 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1908 | IContentProvider provider = acquireProvider(url); |
| 1909 | if (provider == null) { |
| 1910 | throw new IllegalArgumentException("Unknown URL " + url); |
| 1911 | } |
| 1912 | try { |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 1913 | long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1914 | int rowsDeleted = provider.delete(mPackageName, url, where, selectionArgs); |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 1915 | long durationMillis = SystemClock.uptimeMillis() - startTime; |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 1916 | maybeLogUpdateToEventLog(durationMillis, url, "delete", where); |
| 1917 | return rowsDeleted; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1918 | } catch (RemoteException e) { |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 1919 | // Arbitrary and not worth documenting, as Activity |
| 1920 | // Manager will kill this process shortly anyway. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1921 | return -1; |
| 1922 | } finally { |
| 1923 | releaseProvider(provider); |
| 1924 | } |
| 1925 | } |
| 1926 | |
| 1927 | /** |
| 1928 | * Update row(s) in a content URI. |
| 1929 | * |
| 1930 | * If the content provider supports transactions the update will be atomic. |
| 1931 | * |
| 1932 | * @param uri The URI to modify. |
| 1933 | * @param values The new field values. The key is the column name for the field. |
| 1934 | A null value will remove an existing field value. |
Omari Stephens | d2a2daa | 2010-03-10 18:53:54 -0800 | [diff] [blame] | 1935 | * @param where A filter to apply to rows before updating, formatted as an SQL WHERE clause |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1936 | (excluding the WHERE itself). |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 1937 | * @return the number of rows updated. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1938 | * @throws NullPointerException if uri or values are null |
| 1939 | */ |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1940 | @Override |
Tor Norbye | 788fc2b | 2015-07-05 16:10:42 -0700 | [diff] [blame] | 1941 | public final int update(@RequiresPermission.Write @NonNull Uri uri, |
| 1942 | @Nullable ContentValues values, @Nullable String where, |
| 1943 | @Nullable String[] selectionArgs) { |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1944 | Preconditions.checkNotNull(uri, "uri"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1945 | |
| 1946 | try { |
| 1947 | if (mWrapped != null) return mWrapped.update(uri, values, where, selectionArgs); |
| 1948 | } catch (RemoteException e) { |
| 1949 | return 0; |
| 1950 | } |
| 1951 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1952 | IContentProvider provider = acquireProvider(uri); |
| 1953 | if (provider == null) { |
| 1954 | throw new IllegalArgumentException("Unknown URI " + uri); |
| 1955 | } |
| 1956 | try { |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 1957 | long startTime = SystemClock.uptimeMillis(); |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 1958 | int rowsUpdated = provider.update(mPackageName, uri, values, where, selectionArgs); |
Brad Fitzpatrick | d72f718 | 2010-02-11 17:07:51 -0800 | [diff] [blame] | 1959 | long durationMillis = SystemClock.uptimeMillis() - startTime; |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 1960 | maybeLogUpdateToEventLog(durationMillis, uri, "update", where); |
| 1961 | return rowsUpdated; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1962 | } catch (RemoteException e) { |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 1963 | // Arbitrary and not worth documenting, as Activity |
| 1964 | // Manager will kill this process shortly anyway. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1965 | return -1; |
| 1966 | } finally { |
| 1967 | releaseProvider(provider); |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | /** |
Ken Wakasa | f76a50c | 2012-03-09 19:56:35 +0900 | [diff] [blame] | 1972 | * Call a provider-defined method. This can be used to implement |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 1973 | * read or write interfaces which are cheaper than using a Cursor and/or |
| 1974 | * do not fit into the traditional table model. |
| 1975 | * |
| 1976 | * @param method provider-defined method name to call. Opaque to |
| 1977 | * framework, but must be non-null. |
| 1978 | * @param arg provider-defined String argument. May be null. |
| 1979 | * @param extras provider-defined Bundle argument. May be null. |
| 1980 | * @return a result Bundle, possibly null. Will be null if the ContentProvider |
| 1981 | * does not implement call. |
| 1982 | * @throws NullPointerException if uri or method is null |
| 1983 | * @throws IllegalArgumentException if uri is not known |
| 1984 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1985 | public final @Nullable Bundle call(@NonNull Uri uri, @NonNull String method, |
| 1986 | @Nullable String arg, @Nullable Bundle extras) { |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 1987 | return call(uri.getAuthority(), method, arg, extras); |
| 1988 | } |
| 1989 | |
| 1990 | @Override |
| 1991 | public final @Nullable Bundle call(@NonNull String authority, @NonNull String method, |
| 1992 | @Nullable String arg, @Nullable Bundle extras) { |
| 1993 | Preconditions.checkNotNull(authority, "authority"); |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 1994 | Preconditions.checkNotNull(method, "method"); |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 1995 | |
| 1996 | try { |
| 1997 | if (mWrapped != null) return mWrapped.call(authority, method, arg, extras); |
| 1998 | } catch (RemoteException e) { |
| 1999 | return null; |
| 2000 | } |
| 2001 | |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 2002 | IContentProvider provider = acquireProvider(authority); |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 2003 | if (provider == null) { |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 2004 | throw new IllegalArgumentException("Unknown authority " + authority); |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 2005 | } |
| 2006 | try { |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 2007 | final Bundle res = provider.call(mPackageName, authority, method, arg, extras); |
Jeff Sharkey | a04c7a7 | 2016-03-18 12:20:36 -0600 | [diff] [blame] | 2008 | Bundle.setDefusable(res, true); |
| 2009 | return res; |
Brad Fitzpatrick | 534c84c | 2011-01-12 14:06:30 -0800 | [diff] [blame] | 2010 | } catch (RemoteException e) { |
| 2011 | // Arbitrary and not worth documenting, as Activity |
| 2012 | // Manager will kill this process shortly anyway. |
| 2013 | return null; |
| 2014 | } finally { |
| 2015 | releaseProvider(provider); |
| 2016 | } |
| 2017 | } |
| 2018 | |
| 2019 | /** |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 2020 | * Returns the content provider for the given content URI. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2021 | * |
| 2022 | * @param uri The URI to a content provider |
| 2023 | * @return The ContentProvider for the given URI, or null if no content provider is found. |
| 2024 | * @hide |
| 2025 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 2026 | @UnsupportedAppUsage |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 2027 | public final IContentProvider acquireProvider(Uri uri) { |
Jason Monk | d18651f | 2017-10-05 14:18:49 -0400 | [diff] [blame] | 2028 | if (!SCHEME_CONTENT.equals(uri.getScheme())) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2029 | return null; |
| 2030 | } |
Yury Zhauniarovich | f9c5176 | 2012-05-12 18:39:25 +0200 | [diff] [blame] | 2031 | final String auth = uri.getAuthority(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2032 | if (auth != null) { |
Yury Zhauniarovich | f9c5176 | 2012-05-12 18:39:25 +0200 | [diff] [blame] | 2033 | return acquireProvider(mContext, auth); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2034 | } |
| 2035 | return null; |
| 2036 | } |
| 2037 | |
| 2038 | /** |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 2039 | * Returns the content provider for the given content URI if the process |
| 2040 | * already has a reference on it. |
| 2041 | * |
| 2042 | * @param uri The URI to a content provider |
| 2043 | * @return The ContentProvider for the given URI, or null if no content provider is found. |
| 2044 | * @hide |
| 2045 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 2046 | @UnsupportedAppUsage |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 2047 | public final IContentProvider acquireExistingProvider(Uri uri) { |
| 2048 | if (!SCHEME_CONTENT.equals(uri.getScheme())) { |
| 2049 | return null; |
| 2050 | } |
Yury Zhauniarovich | f9c5176 | 2012-05-12 18:39:25 +0200 | [diff] [blame] | 2051 | final String auth = uri.getAuthority(); |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 2052 | if (auth != null) { |
Yury Zhauniarovich | f9c5176 | 2012-05-12 18:39:25 +0200 | [diff] [blame] | 2053 | return acquireExistingProvider(mContext, auth); |
Dianne Hackborn | cca1f0e | 2010-09-26 18:34:53 -0700 | [diff] [blame] | 2054 | } |
| 2055 | return null; |
| 2056 | } |
| 2057 | |
| 2058 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2059 | * @hide |
| 2060 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 2061 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2062 | public final IContentProvider acquireProvider(String name) { |
Brad Fitzpatrick | 1877d01 | 2010-03-04 17:48:13 -0800 | [diff] [blame] | 2063 | if (name == null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2064 | return null; |
| 2065 | } |
| 2066 | return acquireProvider(mContext, name); |
| 2067 | } |
| 2068 | |
| 2069 | /** |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 2070 | * Returns the content provider for the given content URI. |
| 2071 | * |
| 2072 | * @param uri The URI to a content provider |
| 2073 | * @return The ContentProvider for the given URI, or null if no content provider is found. |
| 2074 | * @hide |
| 2075 | */ |
| 2076 | public final IContentProvider acquireUnstableProvider(Uri uri) { |
| 2077 | if (!SCHEME_CONTENT.equals(uri.getScheme())) { |
| 2078 | return null; |
| 2079 | } |
| 2080 | String auth = uri.getAuthority(); |
| 2081 | if (auth != null) { |
| 2082 | return acquireUnstableProvider(mContext, uri.getAuthority()); |
| 2083 | } |
| 2084 | return null; |
| 2085 | } |
| 2086 | |
| 2087 | /** |
| 2088 | * @hide |
| 2089 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 2090 | @UnsupportedAppUsage |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 2091 | public final IContentProvider acquireUnstableProvider(String name) { |
| 2092 | if (name == null) { |
| 2093 | return null; |
| 2094 | } |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 2095 | return acquireUnstableProvider(mContext, name); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 2096 | } |
| 2097 | |
| 2098 | /** |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2099 | * Returns a {@link ContentProviderClient} that is associated with the {@link ContentProvider} |
| 2100 | * that services the content at uri, starting the provider if necessary. Returns |
| 2101 | * null if there is no provider associated wih the uri. The caller must indicate that they are |
| 2102 | * done with the provider by calling {@link ContentProviderClient#release} which will allow |
kopriva | 219f7dc | 2018-10-09 13:42:28 -0700 | [diff] [blame] | 2103 | * the system to release the provider if it determines that there is no other reason for |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2104 | * keeping it active. |
| 2105 | * @param uri specifies which provider should be acquired |
| 2106 | * @return a {@link ContentProviderClient} that is associated with the {@link ContentProvider} |
| 2107 | * that services the content at uri or null if there isn't one. |
| 2108 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2109 | public final @Nullable ContentProviderClient acquireContentProviderClient(@NonNull Uri uri) { |
| 2110 | Preconditions.checkNotNull(uri, "uri"); |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2111 | IContentProvider provider = acquireProvider(uri); |
| 2112 | if (provider != null) { |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 2113 | return new ContentProviderClient(this, provider, uri.getAuthority(), true); |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2114 | } |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2115 | return null; |
| 2116 | } |
| 2117 | |
| 2118 | /** |
| 2119 | * Returns a {@link ContentProviderClient} that is associated with the {@link ContentProvider} |
| 2120 | * with the authority of name, starting the provider if necessary. Returns |
| 2121 | * null if there is no provider associated wih the uri. The caller must indicate that they are |
| 2122 | * done with the provider by calling {@link ContentProviderClient#release} which will allow |
kopriva | 219f7dc | 2018-10-09 13:42:28 -0700 | [diff] [blame] | 2123 | * the system to release the provider if it determines that there is no other reason for |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2124 | * keeping it active. |
| 2125 | * @param name specifies which provider should be acquired |
| 2126 | * @return a {@link ContentProviderClient} that is associated with the {@link ContentProvider} |
| 2127 | * with the authority of name or null if there isn't one. |
| 2128 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2129 | public final @Nullable ContentProviderClient acquireContentProviderClient( |
| 2130 | @NonNull String name) { |
| 2131 | Preconditions.checkNotNull(name, "name"); |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2132 | IContentProvider provider = acquireProvider(name); |
| 2133 | if (provider != null) { |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 2134 | return new ContentProviderClient(this, provider, name, true); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 2135 | } |
| 2136 | |
| 2137 | return null; |
| 2138 | } |
| 2139 | |
| 2140 | /** |
| 2141 | * Like {@link #acquireContentProviderClient(Uri)}, but for use when you do |
| 2142 | * not trust the stability of the target content provider. This turns off |
| 2143 | * the mechanism in the platform clean up processes that are dependent on |
| 2144 | * a content provider if that content provider's process goes away. Normally |
| 2145 | * you can safely assume that once you have acquired a provider, you can freely |
| 2146 | * use it as needed and it won't disappear, even if your process is in the |
| 2147 | * background. If using this method, you need to take care to deal with any |
| 2148 | * failures when communicating with the provider, and be sure to close it |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 2149 | * so that it can be re-opened later. In particular, catching a |
| 2150 | * {@link android.os.DeadObjectException} from the calls there will let you |
| 2151 | * know that the content provider has gone away; at that point the current |
| 2152 | * ContentProviderClient object is invalid, and you should release it. You |
| 2153 | * can acquire a new one if you would like to try to restart the provider |
| 2154 | * and perform new operations on it. |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 2155 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2156 | public final @Nullable ContentProviderClient acquireUnstableContentProviderClient( |
| 2157 | @NonNull Uri uri) { |
| 2158 | Preconditions.checkNotNull(uri, "uri"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 2159 | IContentProvider provider = acquireUnstableProvider(uri); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 2160 | if (provider != null) { |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 2161 | return new ContentProviderClient(this, provider, uri.getAuthority(), false); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | return null; |
| 2165 | } |
| 2166 | |
| 2167 | /** |
| 2168 | * Like {@link #acquireContentProviderClient(String)}, but for use when you do |
| 2169 | * not trust the stability of the target content provider. This turns off |
| 2170 | * the mechanism in the platform clean up processes that are dependent on |
| 2171 | * a content provider if that content provider's process goes away. Normally |
| 2172 | * you can safely assume that once you have acquired a provider, you can freely |
| 2173 | * use it as needed and it won't disappear, even if your process is in the |
| 2174 | * background. If using this method, you need to take care to deal with any |
| 2175 | * failures when communicating with the provider, and be sure to close it |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 2176 | * so that it can be re-opened later. In particular, catching a |
| 2177 | * {@link android.os.DeadObjectException} from the calls there will let you |
| 2178 | * know that the content provider has gone away; at that point the current |
| 2179 | * ContentProviderClient object is invalid, and you should release it. You |
| 2180 | * can acquire a new one if you would like to try to restart the provider |
| 2181 | * and perform new operations on it. |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 2182 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2183 | public final @Nullable ContentProviderClient acquireUnstableContentProviderClient( |
| 2184 | @NonNull String name) { |
| 2185 | Preconditions.checkNotNull(name, "name"); |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 2186 | IContentProvider provider = acquireUnstableProvider(name); |
Dianne Hackborn | 652b6d1 | 2012-05-09 18:18:40 -0700 | [diff] [blame] | 2187 | if (provider != null) { |
Jeff Sharkey | 633a13e | 2018-12-07 12:00:45 -0700 | [diff] [blame] | 2188 | return new ContentProviderClient(this, provider, name, false); |
Fred Quintana | 718d8a2 | 2009-04-29 17:53:20 -0700 | [diff] [blame] | 2189 | } |
| 2190 | |
| 2191 | return null; |
| 2192 | } |
| 2193 | |
| 2194 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2195 | * Register an observer class that gets callbacks when data identified by a |
| 2196 | * given content URI changes. |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 2197 | * <p> |
| 2198 | * Starting in {@link android.os.Build.VERSION_CODES#O}, all content |
| 2199 | * notifications must be backed by a valid {@link ContentProvider}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2200 | * |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 2201 | * @param uri The URI to watch for changes. This can be a specific row URI, |
| 2202 | * or a base URI for a whole class of content. |
| 2203 | * @param notifyForDescendants When false, the observer will be notified |
| 2204 | * whenever a change occurs to the exact URI specified by |
| 2205 | * <code>uri</code> or to one of the URI's ancestors in the path |
| 2206 | * hierarchy. When true, the observer will also be notified |
| 2207 | * whenever a change occurs to the URI's descendants in the path |
| 2208 | * hierarchy. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2209 | * @param observer The object that receives callbacks when changes occur. |
| 2210 | * @see #unregisterContentObserver |
| 2211 | */ |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 2212 | public final void registerContentObserver(@NonNull Uri uri, boolean notifyForDescendants, |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2213 | @NonNull ContentObserver observer) { |
| 2214 | Preconditions.checkNotNull(uri, "uri"); |
| 2215 | Preconditions.checkNotNull(observer, "observer"); |
Benjamin Franz | adea191 | 2015-06-19 16:03:38 +0100 | [diff] [blame] | 2216 | registerContentObserver( |
| 2217 | ContentProvider.getUriWithoutUserId(uri), |
Dianne Hackborn | 1a30bd9 | 2016-01-11 11:05:00 -0800 | [diff] [blame] | 2218 | notifyForDescendants, |
Benjamin Franz | adea191 | 2015-06-19 16:03:38 +0100 | [diff] [blame] | 2219 | observer, |
Sudheer Shanka | b4e2ddd | 2017-02-03 15:15:57 -0800 | [diff] [blame] | 2220 | ContentProvider.getUserIdFromUri(uri, mContext.getUserId())); |
Christopher Tate | 16aa973 | 2012-09-17 16:23:44 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | /** @hide - designated user version */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 2224 | @UnsupportedAppUsage |
Christopher Tate | 16aa973 | 2012-09-17 16:23:44 -0700 | [diff] [blame] | 2225 | public final void registerContentObserver(Uri uri, boolean notifyForDescendents, |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2226 | ContentObserver observer, @UserIdInt int userHandle) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2227 | try { |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 2228 | getContentService().registerContentObserver(uri, notifyForDescendents, |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 2229 | observer.getContentObserver(), userHandle, mTargetSdkVersion); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2230 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2231 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2232 | } |
| 2233 | } |
| 2234 | |
| 2235 | /** |
| 2236 | * Unregisters a change observer. |
| 2237 | * |
| 2238 | * @param observer The previously registered observer that is no longer needed. |
| 2239 | * @see #registerContentObserver |
| 2240 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2241 | public final void unregisterContentObserver(@NonNull ContentObserver observer) { |
| 2242 | Preconditions.checkNotNull(observer, "observer"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2243 | try { |
| 2244 | IContentObserver contentObserver = observer.releaseContentObserver(); |
| 2245 | if (contentObserver != null) { |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 2246 | getContentService().unregisterContentObserver( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2247 | contentObserver); |
| 2248 | } |
| 2249 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2250 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2251 | } |
| 2252 | } |
| 2253 | |
| 2254 | /** |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 2255 | * Notify registered observers that a row was updated and attempt to sync |
| 2256 | * changes to the network. |
| 2257 | * <p> |
| 2258 | * To observe events sent through this call, use |
| 2259 | * {@link #registerContentObserver(Uri, boolean, ContentObserver)}. |
| 2260 | * <p> |
| 2261 | * Starting in {@link android.os.Build.VERSION_CODES#O}, all content |
| 2262 | * notifications must be backed by a valid {@link ContentProvider}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2263 | * |
Jeff Brown | 86de059 | 2012-01-23 13:01:18 -0800 | [diff] [blame] | 2264 | * @param uri The uri of the content that was changed. |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 2265 | * @param observer The observer that originated the change, may be |
| 2266 | * <code>null</null>. The observer that originated the change |
| 2267 | * will only receive the notification if it has requested to |
| 2268 | * receive self-change notifications by implementing |
| 2269 | * {@link ContentObserver#deliverSelfNotifications()} to return |
| 2270 | * true. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2271 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2272 | public void notifyChange(@NonNull Uri uri, @Nullable ContentObserver observer) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2273 | notifyChange(uri, observer, true /* sync to network */); |
| 2274 | } |
| 2275 | |
| 2276 | /** |
| 2277 | * Notify registered observers that a row was updated. |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 2278 | * <p> |
| 2279 | * To observe events sent through this call, use |
| 2280 | * {@link #registerContentObserver(Uri, boolean, ContentObserver)}. |
| 2281 | * <p> |
| 2282 | * If syncToNetwork is true, this will attempt to schedule a local sync |
| 2283 | * using the sync adapter that's registered for the authority of the |
| 2284 | * provided uri. No account will be passed to the sync adapter, so all |
| 2285 | * matching accounts will be synchronized. |
| 2286 | * <p> |
| 2287 | * Starting in {@link android.os.Build.VERSION_CODES#O}, all content |
| 2288 | * notifications must be backed by a valid {@link ContentProvider}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2289 | * |
Jeff Brown | 86de059 | 2012-01-23 13:01:18 -0800 | [diff] [blame] | 2290 | * @param uri The uri of the content that was changed. |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 2291 | * @param observer The observer that originated the change, may be |
| 2292 | * <code>null</null>. The observer that originated the change |
| 2293 | * will only receive the notification if it has requested to |
| 2294 | * receive self-change notifications by implementing |
| 2295 | * {@link ContentObserver#deliverSelfNotifications()} to return |
| 2296 | * true. |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 2297 | * @param syncToNetwork If true, same as {@link #NOTIFY_SYNC_TO_NETWORK}. |
Steve Pomeroy | d7a1aad | 2012-01-18 16:15:59 -0500 | [diff] [blame] | 2298 | * @see #requestSync(android.accounts.Account, String, android.os.Bundle) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2299 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2300 | public void notifyChange(@NonNull Uri uri, @Nullable ContentObserver observer, |
| 2301 | boolean syncToNetwork) { |
| 2302 | Preconditions.checkNotNull(uri, "uri"); |
Benjamin Franz | adea191 | 2015-06-19 16:03:38 +0100 | [diff] [blame] | 2303 | notifyChange( |
| 2304 | ContentProvider.getUriWithoutUserId(uri), |
| 2305 | observer, |
| 2306 | syncToNetwork, |
Sudheer Shanka | b4e2ddd | 2017-02-03 15:15:57 -0800 | [diff] [blame] | 2307 | ContentProvider.getUserIdFromUri(uri, mContext.getUserId())); |
Christopher Tate | 16aa973 | 2012-09-17 16:23:44 -0700 | [diff] [blame] | 2308 | } |
| 2309 | |
| 2310 | /** |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 2311 | * Notify registered observers that a row was updated. |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 2312 | * <p> |
| 2313 | * To observe events sent through this call, use |
| 2314 | * {@link #registerContentObserver(Uri, boolean, ContentObserver)}. |
| 2315 | * <p> |
| 2316 | * If syncToNetwork is true, this will attempt to schedule a local sync |
| 2317 | * using the sync adapter that's registered for the authority of the |
| 2318 | * provided uri. No account will be passed to the sync adapter, so all |
| 2319 | * matching accounts will be synchronized. |
| 2320 | * <p> |
| 2321 | * Starting in {@link android.os.Build.VERSION_CODES#O}, all content |
| 2322 | * notifications must be backed by a valid {@link ContentProvider}. |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 2323 | * |
| 2324 | * @param uri The uri of the content that was changed. |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 2325 | * @param observer The observer that originated the change, may be |
| 2326 | * <code>null</null>. The observer that originated the change |
| 2327 | * will only receive the notification if it has requested to |
| 2328 | * receive self-change notifications by implementing |
| 2329 | * {@link ContentObserver#deliverSelfNotifications()} to return |
| 2330 | * true. |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 2331 | * @param flags Additional flags: {@link #NOTIFY_SYNC_TO_NETWORK}. |
| 2332 | * @see #requestSync(android.accounts.Account, String, android.os.Bundle) |
| 2333 | */ |
| 2334 | public void notifyChange(@NonNull Uri uri, @Nullable ContentObserver observer, |
| 2335 | @NotifyFlags int flags) { |
| 2336 | Preconditions.checkNotNull(uri, "uri"); |
| 2337 | notifyChange( |
| 2338 | ContentProvider.getUriWithoutUserId(uri), |
| 2339 | observer, |
| 2340 | flags, |
Sudheer Shanka | b4e2ddd | 2017-02-03 15:15:57 -0800 | [diff] [blame] | 2341 | ContentProvider.getUserIdFromUri(uri, mContext.getUserId())); |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 2342 | } |
| 2343 | |
| 2344 | /** |
Christopher Tate | 16aa973 | 2012-09-17 16:23:44 -0700 | [diff] [blame] | 2345 | * Notify registered observers within the designated user(s) that a row was updated. |
| 2346 | * |
| 2347 | * @hide |
| 2348 | */ |
Dianne Hackborn | e761777 | 2016-04-27 17:03:52 -0700 | [diff] [blame] | 2349 | public void notifyChange(@NonNull Uri uri, ContentObserver observer, boolean syncToNetwork, |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2350 | @UserIdInt int userHandle) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2351 | try { |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 2352 | getContentService().notifyChange( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2353 | uri, observer == null ? null : observer.getContentObserver(), |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 2354 | observer != null && observer.deliverSelfNotifications(), |
| 2355 | syncToNetwork ? NOTIFY_SYNC_TO_NETWORK : 0, |
Makoto Onuki | e183a40 | 2018-08-29 11:46:41 -0700 | [diff] [blame] | 2356 | userHandle, mTargetSdkVersion, mContext.getPackageName()); |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 2357 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2358 | throw e.rethrowFromSystemServer(); |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 2359 | } |
| 2360 | } |
| 2361 | |
| 2362 | /** |
| 2363 | * Notify registered observers within the designated user(s) that a row was updated. |
| 2364 | * |
| 2365 | * @hide |
| 2366 | */ |
Dianne Hackborn | e761777 | 2016-04-27 17:03:52 -0700 | [diff] [blame] | 2367 | public void notifyChange(@NonNull Uri uri, ContentObserver observer, @NotifyFlags int flags, |
Dianne Hackborn | 141f11c | 2016-04-05 15:46:12 -0700 | [diff] [blame] | 2368 | @UserIdInt int userHandle) { |
| 2369 | try { |
| 2370 | getContentService().notifyChange( |
| 2371 | uri, observer == null ? null : observer.getContentObserver(), |
| 2372 | observer != null && observer.deliverSelfNotifications(), flags, |
Makoto Onuki | e183a40 | 2018-08-29 11:46:41 -0700 | [diff] [blame] | 2373 | userHandle, mTargetSdkVersion, mContext.getPackageName()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2374 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2375 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2376 | } |
| 2377 | } |
| 2378 | |
| 2379 | /** |
Jeff Sharkey | adef88a | 2013-10-15 13:54:44 -0700 | [diff] [blame] | 2380 | * Take a persistable URI permission grant that has been offered. Once |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 2381 | * taken, the permission grant will be remembered across device reboots. |
Jeff Sharkey | adef88a | 2013-10-15 13:54:44 -0700 | [diff] [blame] | 2382 | * Only URI permissions granted with |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 2383 | * {@link Intent#FLAG_GRANT_PERSISTABLE_URI_PERMISSION} can be persisted. If |
| 2384 | * the grant has already been persisted, taking it again will touch |
| 2385 | * {@link UriPermission#getPersistedTime()}. |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 2386 | * |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 2387 | * @see #getPersistedUriPermissions() |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 2388 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2389 | public void takePersistableUriPermission(@NonNull Uri uri, |
| 2390 | @Intent.AccessUriMode int modeFlags) { |
| 2391 | Preconditions.checkNotNull(uri, "uri"); |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 2392 | try { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 2393 | UriGrantsManager.getService().takePersistableUriPermission( |
Felipe Leme | 988234a | 2018-02-14 12:00:29 -0800 | [diff] [blame] | 2394 | ContentProvider.getUriWithoutUserId(uri), modeFlags, /* toPackage= */ null, |
| 2395 | resolveUserId(uri)); |
| 2396 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2397 | throw e.rethrowFromSystemServer(); |
Felipe Leme | 988234a | 2018-02-14 12:00:29 -0800 | [diff] [blame] | 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | /** |
| 2402 | * @hide |
| 2403 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 2404 | @UnsupportedAppUsage |
Felipe Leme | 988234a | 2018-02-14 12:00:29 -0800 | [diff] [blame] | 2405 | public void takePersistableUriPermission(@NonNull String toPackage, @NonNull Uri uri, |
| 2406 | @Intent.AccessUriMode int modeFlags) { |
| 2407 | Preconditions.checkNotNull(toPackage, "toPackage"); |
| 2408 | Preconditions.checkNotNull(uri, "uri"); |
| 2409 | try { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 2410 | UriGrantsManager.getService().takePersistableUriPermission( |
Felipe Leme | 988234a | 2018-02-14 12:00:29 -0800 | [diff] [blame] | 2411 | ContentProvider.getUriWithoutUserId(uri), modeFlags, toPackage, |
| 2412 | resolveUserId(uri)); |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 2413 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2414 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 2415 | } |
| 2416 | } |
| 2417 | |
| 2418 | /** |
Jeff Sharkey | adef88a | 2013-10-15 13:54:44 -0700 | [diff] [blame] | 2419 | * Relinquish a persisted URI permission grant. The URI must have been |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 2420 | * previously made persistent with |
| 2421 | * {@link #takePersistableUriPermission(Uri, int)}. Any non-persistent |
| 2422 | * grants to the calling package will remain intact. |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 2423 | * |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 2424 | * @see #getPersistedUriPermissions() |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 2425 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2426 | public void releasePersistableUriPermission(@NonNull Uri uri, |
| 2427 | @Intent.AccessUriMode int modeFlags) { |
| 2428 | Preconditions.checkNotNull(uri, "uri"); |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 2429 | try { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 2430 | UriGrantsManager.getService().releasePersistableUriPermission( |
Felipe Leme | 988234a | 2018-02-14 12:00:29 -0800 | [diff] [blame] | 2431 | ContentProvider.getUriWithoutUserId(uri), modeFlags, /* toPackage= */ null, |
| 2432 | resolveUserId(uri)); |
| 2433 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2434 | throw e.rethrowFromSystemServer(); |
Felipe Leme | 988234a | 2018-02-14 12:00:29 -0800 | [diff] [blame] | 2435 | } |
| 2436 | } |
| 2437 | |
| 2438 | /** |
Jeff Sharkey | adef88a | 2013-10-15 13:54:44 -0700 | [diff] [blame] | 2439 | * Return list of all URI permission grants that have been persisted by the |
Jeff Sharkey | bcaac0a | 2013-10-09 14:21:08 -0700 | [diff] [blame] | 2440 | * calling app. That is, the returned permissions have been granted |
| 2441 | * <em>to</em> the calling app. Only persistable grants taken with |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 2442 | * {@link #takePersistableUriPermission(Uri, int)} are returned. |
Fyodor Kupolov | 9bbaacf | 2016-06-20 14:03:44 -0700 | [diff] [blame] | 2443 | * <p>Note: Some of the returned URIs may not be usable until after the user is unlocked. |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 2444 | * |
| 2445 | * @see #takePersistableUriPermission(Uri, int) |
| 2446 | * @see #releasePersistableUriPermission(Uri, int) |
| 2447 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2448 | public @NonNull List<UriPermission> getPersistedUriPermissions() { |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 2449 | try { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 2450 | return UriGrantsManager.getService() |
Jeff Sharkey | bcaac0a | 2013-10-09 14:21:08 -0700 | [diff] [blame] | 2451 | .getPersistedUriPermissions(mPackageName, true).getList(); |
| 2452 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2453 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | bcaac0a | 2013-10-09 14:21:08 -0700 | [diff] [blame] | 2454 | } |
| 2455 | } |
| 2456 | |
| 2457 | /** |
Jeff Sharkey | adef88a | 2013-10-15 13:54:44 -0700 | [diff] [blame] | 2458 | * Return list of all persisted URI permission grants that are hosted by the |
Jeff Sharkey | bcaac0a | 2013-10-09 14:21:08 -0700 | [diff] [blame] | 2459 | * calling app. That is, the returned permissions have been granted |
| 2460 | * <em>from</em> the calling app. Only grants taken with |
| 2461 | * {@link #takePersistableUriPermission(Uri, int)} are returned. |
Fyodor Kupolov | 9bbaacf | 2016-06-20 14:03:44 -0700 | [diff] [blame] | 2462 | * <p>Note: Some of the returned URIs may not be usable until after the user is unlocked. |
Jeff Sharkey | bcaac0a | 2013-10-09 14:21:08 -0700 | [diff] [blame] | 2463 | */ |
Jeff Sharkey | 673db44 | 2015-06-11 19:30:57 -0700 | [diff] [blame] | 2464 | public @NonNull List<UriPermission> getOutgoingPersistedUriPermissions() { |
Jeff Sharkey | bcaac0a | 2013-10-09 14:21:08 -0700 | [diff] [blame] | 2465 | try { |
Wale Ogunwale | 6d50dcc | 2018-07-21 23:00:40 -0700 | [diff] [blame] | 2466 | return UriGrantsManager.getService() |
Jeff Sharkey | bcaac0a | 2013-10-09 14:21:08 -0700 | [diff] [blame] | 2467 | .getPersistedUriPermissions(mPackageName, false).getList(); |
Jeff Sharkey | e66c177 | 2013-09-20 14:30:59 -0700 | [diff] [blame] | 2468 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2469 | throw e.rethrowFromSystemServer(); |
Jeff Sharkey | 08da7a1 | 2013-08-11 20:53:18 -0700 | [diff] [blame] | 2470 | } |
| 2471 | } |
| 2472 | |
| 2473 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2474 | * Start an asynchronous sync operation. If you want to monitor the progress |
| 2475 | * of the sync you may register a SyncObserver. Only values of the following |
| 2476 | * types may be used in the extras bundle: |
| 2477 | * <ul> |
| 2478 | * <li>Integer</li> |
| 2479 | * <li>Long</li> |
| 2480 | * <li>Boolean</li> |
| 2481 | * <li>Float</li> |
| 2482 | * <li>Double</li> |
| 2483 | * <li>String</li> |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 2484 | * <li>Account</li> |
| 2485 | * <li>null</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2486 | * </ul> |
| 2487 | * |
| 2488 | * @param uri the uri of the provider to sync or null to sync all providers. |
| 2489 | * @param extras any extras to pass to the SyncAdapter. |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2490 | * @deprecated instead use |
| 2491 | * {@link #requestSync(android.accounts.Account, String, android.os.Bundle)} |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2492 | */ |
Dianne Hackborn | 4a51c20 | 2009-08-21 15:14:02 -0700 | [diff] [blame] | 2493 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2494 | public void startSync(Uri uri, Bundle extras) { |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2495 | Account account = null; |
| 2496 | if (extras != null) { |
| 2497 | String accountName = extras.getString(SYNC_EXTRAS_ACCOUNT); |
| 2498 | if (!TextUtils.isEmpty(accountName)) { |
Svet Ganov | f6d424f1 | 2016-09-20 20:18:53 -0700 | [diff] [blame] | 2499 | // TODO: No references to Google in AOSP |
Costin Manolache | 3348f14 | 2009-09-29 18:58:36 -0700 | [diff] [blame] | 2500 | account = new Account(accountName, "com.google"); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2501 | } |
| 2502 | extras.remove(SYNC_EXTRAS_ACCOUNT); |
| 2503 | } |
| 2504 | requestSync(account, uri != null ? uri.getAuthority() : null, extras); |
| 2505 | } |
| 2506 | |
| 2507 | /** |
| 2508 | * Start an asynchronous sync operation. If you want to monitor the progress |
| 2509 | * of the sync you may register a SyncObserver. Only values of the following |
| 2510 | * types may be used in the extras bundle: |
| 2511 | * <ul> |
| 2512 | * <li>Integer</li> |
| 2513 | * <li>Long</li> |
| 2514 | * <li>Boolean</li> |
| 2515 | * <li>Float</li> |
| 2516 | * <li>Double</li> |
| 2517 | * <li>String</li> |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 2518 | * <li>Account</li> |
| 2519 | * <li>null</li> |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2520 | * </ul> |
| 2521 | * |
| 2522 | * @param account which account should be synced |
| 2523 | * @param authority which authority should be synced |
| 2524 | * @param extras any extras to pass to the SyncAdapter. |
| 2525 | */ |
| 2526 | public static void requestSync(Account account, String authority, Bundle extras) { |
Alexandra Gherghina | 03e1e83 | 2014-09-10 16:06:10 +0100 | [diff] [blame] | 2527 | requestSyncAsUser(account, authority, UserHandle.myUserId(), extras); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2528 | } |
| 2529 | |
| 2530 | /** |
| 2531 | * @see #requestSync(Account, String, Bundle) |
| 2532 | * @hide |
| 2533 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2534 | public static void requestSyncAsUser(Account account, String authority, @UserIdInt int userId, |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2535 | Bundle extras) { |
Matthew Williams | d8abd6a | 2013-09-09 14:35:27 -0700 | [diff] [blame] | 2536 | if (extras == null) { |
| 2537 | throw new IllegalArgumentException("Must specify extras."); |
| 2538 | } |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 2539 | SyncRequest request = |
| 2540 | new SyncRequest.Builder() |
| 2541 | .setSyncAdapter(account, authority) |
| 2542 | .setExtras(extras) |
Nick Kralevich | 69002ae | 2013-10-19 08:43:08 -0700 | [diff] [blame] | 2543 | .syncOnce() // Immediate sync. |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 2544 | .build(); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2545 | try { |
Makoto Onuki | e183a40 | 2018-08-29 11:46:41 -0700 | [diff] [blame] | 2546 | // Note ActivityThread.currentPackageName() may not be accurate in a shared process |
| 2547 | // case, but it's only for debugging. |
| 2548 | getContentService().syncAsUser(request, userId, ActivityThread.currentPackageName()); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2549 | } catch(RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2550 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2551 | } |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 2552 | } |
| 2553 | |
| 2554 | /** |
| 2555 | * Register a sync with the SyncManager. These requests are built using the |
| 2556 | * {@link SyncRequest.Builder}. |
| 2557 | */ |
| 2558 | public static void requestSync(SyncRequest request) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2559 | try { |
Makoto Onuki | e183a40 | 2018-08-29 11:46:41 -0700 | [diff] [blame] | 2560 | // Note ActivityThread.currentPackageName() may not be accurate in a shared process |
| 2561 | // case, but it's only for debugging. |
| 2562 | getContentService().sync(request, ActivityThread.currentPackageName()); |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 2563 | } catch(RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2564 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2565 | } |
| 2566 | } |
| 2567 | |
| 2568 | /** |
| 2569 | * Check that only values of the following types are in the Bundle: |
| 2570 | * <ul> |
| 2571 | * <li>Integer</li> |
| 2572 | * <li>Long</li> |
| 2573 | * <li>Boolean</li> |
| 2574 | * <li>Float</li> |
| 2575 | * <li>Double</li> |
| 2576 | * <li>String</li> |
Fred Quintana | d9d2f11 | 2009-04-23 13:36:27 -0700 | [diff] [blame] | 2577 | * <li>Account</li> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2578 | * <li>null</li> |
| 2579 | * </ul> |
| 2580 | * @param extras the Bundle to check |
| 2581 | */ |
| 2582 | public static void validateSyncExtrasBundle(Bundle extras) { |
| 2583 | try { |
| 2584 | for (String key : extras.keySet()) { |
| 2585 | Object value = extras.get(key); |
| 2586 | if (value == null) continue; |
| 2587 | if (value instanceof Long) continue; |
| 2588 | if (value instanceof Integer) continue; |
| 2589 | if (value instanceof Boolean) continue; |
| 2590 | if (value instanceof Float) continue; |
| 2591 | if (value instanceof Double) continue; |
| 2592 | if (value instanceof String) continue; |
Fred Quintana | d9d2f11 | 2009-04-23 13:36:27 -0700 | [diff] [blame] | 2593 | if (value instanceof Account) continue; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2594 | throw new IllegalArgumentException("unexpected value type: " |
| 2595 | + value.getClass().getName()); |
| 2596 | } |
| 2597 | } catch (IllegalArgumentException e) { |
| 2598 | throw e; |
| 2599 | } catch (RuntimeException exc) { |
| 2600 | throw new IllegalArgumentException("error unparceling Bundle", exc); |
| 2601 | } |
| 2602 | } |
| 2603 | |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2604 | /** |
| 2605 | * Cancel any active or pending syncs that match the Uri. If the uri is null then |
| 2606 | * all syncs will be canceled. |
| 2607 | * |
| 2608 | * @param uri the uri of the provider to sync or null to sync all providers. |
| 2609 | * @deprecated instead use {@link #cancelSync(android.accounts.Account, String)} |
| 2610 | */ |
Dianne Hackborn | 4a51c20 | 2009-08-21 15:14:02 -0700 | [diff] [blame] | 2611 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2612 | public void cancelSync(Uri uri) { |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2613 | cancelSync(null /* all accounts */, uri != null ? uri.getAuthority() : null); |
| 2614 | } |
| 2615 | |
| 2616 | /** |
| 2617 | * Cancel any active or pending syncs that match account and authority. The account and |
| 2618 | * authority can each independently be set to null, which means that syncs with any account |
| 2619 | * or authority, respectively, will match. |
| 2620 | * |
| 2621 | * @param account filters the syncs that match by this account |
| 2622 | * @param authority filters the syncs that match by this authority |
| 2623 | */ |
| 2624 | public static void cancelSync(Account account, String authority) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2625 | try { |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2626 | getContentService().cancelSync(account, authority, null); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2627 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2628 | throw e.rethrowFromSystemServer(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2629 | } |
| 2630 | } |
| 2631 | |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2632 | /** |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2633 | * @see #cancelSync(Account, String) |
| 2634 | * @hide |
| 2635 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2636 | public static void cancelSyncAsUser(Account account, String authority, @UserIdInt int userId) { |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2637 | try { |
| 2638 | getContentService().cancelSyncAsUser(account, authority, null, userId); |
| 2639 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2640 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2641 | } |
| 2642 | } |
| 2643 | |
| 2644 | /** |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2645 | * Get information about the SyncAdapters that are known to the system. |
| 2646 | * @return an array of SyncAdapters that have registered with the system |
| 2647 | */ |
| 2648 | public static SyncAdapterType[] getSyncAdapterTypes() { |
| 2649 | try { |
| 2650 | return getContentService().getSyncAdapterTypes(); |
| 2651 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2652 | throw e.rethrowFromSystemServer(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2653 | } |
| 2654 | } |
| 2655 | |
| 2656 | /** |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2657 | * @see #getSyncAdapterTypes() |
| 2658 | * @hide |
| 2659 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2660 | public static SyncAdapterType[] getSyncAdapterTypesAsUser(@UserIdInt int userId) { |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2661 | try { |
| 2662 | return getContentService().getSyncAdapterTypesAsUser(userId); |
| 2663 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2664 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2665 | } |
| 2666 | } |
| 2667 | |
| 2668 | /** |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 2669 | * @hide |
| 2670 | * Returns the package names of syncadapters that match a given user and authority. |
| 2671 | */ |
Jeff Sharkey | a73b8fd | 2016-01-06 17:02:08 -0700 | [diff] [blame] | 2672 | @TestApi |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 2673 | public static String[] getSyncAdapterPackagesForAuthorityAsUser(String authority, |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2674 | @UserIdInt int userId) { |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 2675 | try { |
| 2676 | return getContentService().getSyncAdapterPackagesForAuthorityAsUser(authority, userId); |
| 2677 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2678 | throw e.rethrowFromSystemServer(); |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 2679 | } |
Amith Yamasani | 37a40c2 | 2015-06-17 13:25:42 -0700 | [diff] [blame] | 2680 | } |
| 2681 | |
| 2682 | /** |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2683 | * Check if the provider should be synced when a network tickle is received |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2684 | * <p>This method requires the caller to hold the permission |
| 2685 | * {@link android.Manifest.permission#READ_SYNC_SETTINGS}. |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2686 | * |
| 2687 | * @param account the account whose setting we are querying |
| 2688 | * @param authority the provider whose setting we are querying |
| 2689 | * @return true if the provider should be synced when a network tickle is received |
| 2690 | */ |
| 2691 | public static boolean getSyncAutomatically(Account account, String authority) { |
| 2692 | try { |
| 2693 | return getContentService().getSyncAutomatically(account, authority); |
| 2694 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2695 | throw e.rethrowFromSystemServer(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2696 | } |
| 2697 | } |
| 2698 | |
| 2699 | /** |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2700 | * @see #getSyncAutomatically(Account, String) |
| 2701 | * @hide |
| 2702 | */ |
| 2703 | public static boolean getSyncAutomaticallyAsUser(Account account, String authority, |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2704 | @UserIdInt int userId) { |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2705 | try { |
| 2706 | return getContentService().getSyncAutomaticallyAsUser(account, authority, userId); |
| 2707 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2708 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | /** |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2713 | * Set whether or not the provider is synced when it receives a network tickle. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2714 | * <p>This method requires the caller to hold the permission |
| 2715 | * {@link android.Manifest.permission#WRITE_SYNC_SETTINGS}. |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2716 | * |
| 2717 | * @param account the account whose setting we are querying |
| 2718 | * @param authority the provider whose behavior is being controlled |
| 2719 | * @param sync true if the provider should be synced when tickles are received for it |
| 2720 | */ |
| 2721 | public static void setSyncAutomatically(Account account, String authority, boolean sync) { |
Alexandra Gherghina | 03e1e83 | 2014-09-10 16:06:10 +0100 | [diff] [blame] | 2722 | setSyncAutomaticallyAsUser(account, authority, sync, UserHandle.myUserId()); |
Alexandra Gherghina | cb22807 | 2014-07-01 15:14:11 +0100 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | /** |
| 2726 | * @see #setSyncAutomatically(Account, String, boolean) |
| 2727 | * @hide |
| 2728 | */ |
| 2729 | public static void setSyncAutomaticallyAsUser(Account account, String authority, boolean sync, |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2730 | @UserIdInt int userId) { |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2731 | try { |
Alexandra Gherghina | cb22807 | 2014-07-01 15:14:11 +0100 | [diff] [blame] | 2732 | getContentService().setSyncAutomaticallyAsUser(account, authority, sync, userId); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2733 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2734 | throw e.rethrowFromSystemServer(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2735 | } |
| 2736 | } |
| 2737 | |
| 2738 | /** |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2739 | * Specifies that a sync should be requested with the specified the account, authority, |
| 2740 | * and extras at the given frequency. If there is already another periodic sync scheduled |
| 2741 | * with the account, authority and extras then a new periodic sync won't be added, instead |
| 2742 | * the frequency of the previous one will be updated. |
| 2743 | * <p> |
| 2744 | * These periodic syncs honor the "syncAutomatically" and "masterSyncAutomatically" settings. |
| 2745 | * Although these sync are scheduled at the specified frequency, it may take longer for it to |
| 2746 | * actually be started if other syncs are ahead of it in the sync operation queue. This means |
| 2747 | * that the actual start time may drift. |
Fred Quintana | 53bd252 | 2010-02-05 15:28:12 -0800 | [diff] [blame] | 2748 | * <p> |
| 2749 | * Periodic syncs are not allowed to have any of {@link #SYNC_EXTRAS_DO_NOT_RETRY}, |
| 2750 | * {@link #SYNC_EXTRAS_IGNORE_BACKOFF}, {@link #SYNC_EXTRAS_IGNORE_SETTINGS}, |
| 2751 | * {@link #SYNC_EXTRAS_INITIALIZE}, {@link #SYNC_EXTRAS_FORCE}, |
| 2752 | * {@link #SYNC_EXTRAS_EXPEDITED}, {@link #SYNC_EXTRAS_MANUAL} set to true. |
| 2753 | * If any are supplied then an {@link IllegalArgumentException} will be thrown. |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2754 | * |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2755 | * <p>This method requires the caller to hold the permission |
| 2756 | * {@link android.Manifest.permission#WRITE_SYNC_SETTINGS}. |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2757 | * <p>The bundle for a periodic sync can be queried by applications with the correct |
| 2758 | * permissions using |
| 2759 | * {@link ContentResolver#getPeriodicSyncs(Account account, String provider)}, so no |
| 2760 | * sensitive data should be transferred here. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2761 | * |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2762 | * @param account the account to specify in the sync |
| 2763 | * @param authority the provider to specify in the sync request |
| 2764 | * @param extras extra parameters to go along with the sync request |
Liefu Liu | 5c0d7b3 | 2018-03-21 10:25:49 -0700 | [diff] [blame] | 2765 | * @param pollFrequency how frequently the sync should be performed, in seconds. |
| 2766 | * On Android API level 24 and above, a minmam interval of 15 minutes is enforced. |
| 2767 | * On previous versions, the minimum interval is 1 hour. |
Fred Quintana | 53bd252 | 2010-02-05 15:28:12 -0800 | [diff] [blame] | 2768 | * @throws IllegalArgumentException if an illegal extra was set or if any of the parameters |
| 2769 | * are null. |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2770 | */ |
| 2771 | public static void addPeriodicSync(Account account, String authority, Bundle extras, |
| 2772 | long pollFrequency) { |
| 2773 | validateSyncExtrasBundle(extras); |
Makoto Onuki | 61283ec | 2018-01-31 17:22:36 -0800 | [diff] [blame] | 2774 | if (invalidPeriodicExtras(extras)) { |
Fred Quintana | 53bd252 | 2010-02-05 15:28:12 -0800 | [diff] [blame] | 2775 | throw new IllegalArgumentException("illegal extras were set"); |
| 2776 | } |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2777 | try { |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 2778 | getContentService().addPeriodicSync(account, authority, extras, pollFrequency); |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2779 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2780 | throw e.rethrowFromSystemServer(); |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | |
| 2784 | /** |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2785 | * {@hide} |
| 2786 | * Helper function to throw an <code>IllegalArgumentException</code> if any illegal |
| 2787 | * extras were set for a periodic sync. |
| 2788 | * |
| 2789 | * @param extras bundle to validate. |
| 2790 | */ |
| 2791 | public static boolean invalidPeriodicExtras(Bundle extras) { |
| 2792 | if (extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false) |
| 2793 | || extras.getBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, false) |
| 2794 | || extras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_BACKOFF, false) |
| 2795 | || extras.getBoolean(ContentResolver.SYNC_EXTRAS_IGNORE_SETTINGS, false) |
| 2796 | || extras.getBoolean(ContentResolver.SYNC_EXTRAS_INITIALIZE, false) |
| 2797 | || extras.getBoolean(ContentResolver.SYNC_EXTRAS_FORCE, false) |
| 2798 | || extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false)) { |
| 2799 | return true; |
| 2800 | } |
| 2801 | return false; |
| 2802 | } |
| 2803 | |
| 2804 | /** |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2805 | * Remove a periodic sync. Has no affect if account, authority and extras don't match |
| 2806 | * an existing periodic sync. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2807 | * <p>This method requires the caller to hold the permission |
| 2808 | * {@link android.Manifest.permission#WRITE_SYNC_SETTINGS}. |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2809 | * |
| 2810 | * @param account the account of the periodic sync to remove |
| 2811 | * @param authority the provider of the periodic sync to remove |
| 2812 | * @param extras the extras of the periodic sync to remove |
| 2813 | */ |
| 2814 | public static void removePeriodicSync(Account account, String authority, Bundle extras) { |
| 2815 | validateSyncExtrasBundle(extras); |
| 2816 | try { |
| 2817 | getContentService().removePeriodicSync(account, authority, extras); |
| 2818 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2819 | throw e.rethrowFromSystemServer(); |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2820 | } |
| 2821 | } |
| 2822 | |
| 2823 | /** |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2824 | * Remove the specified sync. This will cancel any pending or active syncs. If the request is |
| 2825 | * for a periodic sync, this call will remove any future occurrences. |
Matthew Williams | 5a9decd | 2014-06-04 09:25:11 -0700 | [diff] [blame] | 2826 | * <p> |
| 2827 | * If a periodic sync is specified, the caller must hold the permission |
| 2828 | * {@link android.Manifest.permission#WRITE_SYNC_SETTINGS}. |
| 2829 | *</p> |
| 2830 | * It is possible to cancel a sync using a SyncRequest object that is not the same object |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2831 | * with which you requested the sync. Do so by building a SyncRequest with the same |
Matthew Williams | 5a9decd | 2014-06-04 09:25:11 -0700 | [diff] [blame] | 2832 | * adapter, frequency, <b>and</b> extras bundle. |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 2833 | * |
| 2834 | * @param request SyncRequest object containing information about sync to cancel. |
| 2835 | */ |
| 2836 | public static void cancelSync(SyncRequest request) { |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2837 | if (request == null) { |
| 2838 | throw new IllegalArgumentException("request cannot be null"); |
| 2839 | } |
| 2840 | try { |
| 2841 | getContentService().cancelRequest(request); |
| 2842 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2843 | throw e.rethrowFromSystemServer(); |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2844 | } |
Matthew Williams | fa77418 | 2013-06-18 15:44:11 -0700 | [diff] [blame] | 2845 | } |
| 2846 | |
| 2847 | /** |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2848 | * Get the list of information about the periodic syncs for the given account and authority. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2849 | * <p>This method requires the caller to hold the permission |
| 2850 | * {@link android.Manifest.permission#READ_SYNC_SETTINGS}. |
Fred Quintana | c5d1c6d | 2010-01-27 12:17:49 -0800 | [diff] [blame] | 2851 | * |
| 2852 | * @param account the account whose periodic syncs we are querying |
| 2853 | * @param authority the provider whose periodic syncs we are querying |
| 2854 | * @return a list of PeriodicSync objects. This list may be empty but will never be null. |
| 2855 | */ |
| 2856 | public static List<PeriodicSync> getPeriodicSyncs(Account account, String authority) { |
| 2857 | try { |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2858 | return getContentService().getPeriodicSyncs(account, authority, null); |
| 2859 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2860 | throw e.rethrowFromSystemServer(); |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2861 | } |
| 2862 | } |
| 2863 | |
| 2864 | /** |
Fred Quintana | 5e787c4 | 2009-08-16 23:13:53 -0700 | [diff] [blame] | 2865 | * Check if this account/provider is syncable. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2866 | * <p>This method requires the caller to hold the permission |
| 2867 | * {@link android.Manifest.permission#READ_SYNC_SETTINGS}. |
Fred Quintana | 5e787c4 | 2009-08-16 23:13:53 -0700 | [diff] [blame] | 2868 | * @return >0 if it is syncable, 0 if not, and <0 if the state isn't known yet. |
| 2869 | */ |
Jim Miller | 20ea6ce | 2009-08-17 15:47:14 -0700 | [diff] [blame] | 2870 | public static int getIsSyncable(Account account, String authority) { |
Fred Quintana | 5e787c4 | 2009-08-16 23:13:53 -0700 | [diff] [blame] | 2871 | try { |
| 2872 | return getContentService().getIsSyncable(account, authority); |
| 2873 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2874 | throw e.rethrowFromSystemServer(); |
Fred Quintana | 5e787c4 | 2009-08-16 23:13:53 -0700 | [diff] [blame] | 2875 | } |
| 2876 | } |
| 2877 | |
| 2878 | /** |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2879 | * @see #getIsSyncable(Account, String) |
| 2880 | * @hide |
| 2881 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2882 | public static int getIsSyncableAsUser(Account account, String authority, |
| 2883 | @UserIdInt int userId) { |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2884 | try { |
| 2885 | return getContentService().getIsSyncableAsUser(account, authority, userId); |
| 2886 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2887 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2888 | } |
| 2889 | } |
| 2890 | |
| 2891 | /** |
Fred Quintana | 5e787c4 | 2009-08-16 23:13:53 -0700 | [diff] [blame] | 2892 | * Set whether this account/provider is syncable. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2893 | * <p>This method requires the caller to hold the permission |
| 2894 | * {@link android.Manifest.permission#WRITE_SYNC_SETTINGS}. |
Fred Quintana | 718671b | 2009-08-17 14:08:37 -0700 | [diff] [blame] | 2895 | * @param syncable >0 denotes syncable, 0 means not syncable, <0 means unknown |
Fred Quintana | 5e787c4 | 2009-08-16 23:13:53 -0700 | [diff] [blame] | 2896 | */ |
Jim Miller | 20ea6ce | 2009-08-17 15:47:14 -0700 | [diff] [blame] | 2897 | public static void setIsSyncable(Account account, String authority, int syncable) { |
Fred Quintana | 5e787c4 | 2009-08-16 23:13:53 -0700 | [diff] [blame] | 2898 | try { |
| 2899 | getContentService().setIsSyncable(account, authority, syncable); |
| 2900 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2901 | throw e.rethrowFromSystemServer(); |
Fred Quintana | 5e787c4 | 2009-08-16 23:13:53 -0700 | [diff] [blame] | 2902 | } |
| 2903 | } |
| 2904 | |
| 2905 | /** |
Ruslan Tkhakokhov | 1951303 | 2019-02-05 11:06:21 +0000 | [diff] [blame] | 2906 | * @see #setIsSyncable(Account, String, int) |
| 2907 | * @hide |
| 2908 | */ |
| 2909 | public static void setIsSyncableAsUser(Account account, String authority, int syncable, |
| 2910 | int userId) { |
| 2911 | try { |
| 2912 | getContentService().setIsSyncableAsUser(account, authority, syncable, userId); |
| 2913 | } catch (RemoteException e) { |
| 2914 | throw e.rethrowFromSystemServer(); |
| 2915 | } |
| 2916 | } |
| 2917 | |
| 2918 | /** |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2919 | * Gets the master auto-sync setting that applies to all the providers and accounts. |
| 2920 | * If this is false then the per-provider auto-sync setting is ignored. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2921 | * <p>This method requires the caller to hold the permission |
| 2922 | * {@link android.Manifest.permission#READ_SYNC_SETTINGS}. |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2923 | * |
| 2924 | * @return the master auto-sync setting that applies to all the providers and accounts |
| 2925 | */ |
| 2926 | public static boolean getMasterSyncAutomatically() { |
| 2927 | try { |
| 2928 | return getContentService().getMasterSyncAutomatically(); |
| 2929 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2930 | throw e.rethrowFromSystemServer(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2931 | } |
| 2932 | } |
| 2933 | |
| 2934 | /** |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2935 | * @see #getMasterSyncAutomatically() |
| 2936 | * @hide |
| 2937 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2938 | public static boolean getMasterSyncAutomaticallyAsUser(@UserIdInt int userId) { |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2939 | try { |
| 2940 | return getContentService().getMasterSyncAutomaticallyAsUser(userId); |
| 2941 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2942 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 2943 | } |
| 2944 | } |
| 2945 | |
| 2946 | /** |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2947 | * Sets the master auto-sync setting that applies to all the providers and accounts. |
| 2948 | * If this is false then the per-provider auto-sync setting is ignored. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2949 | * <p>This method requires the caller to hold the permission |
| 2950 | * {@link android.Manifest.permission#WRITE_SYNC_SETTINGS}. |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2951 | * |
| 2952 | * @param sync the master auto-sync setting that applies to all the providers and accounts |
| 2953 | */ |
| 2954 | public static void setMasterSyncAutomatically(boolean sync) { |
Alexandra Gherghina | 03e1e83 | 2014-09-10 16:06:10 +0100 | [diff] [blame] | 2955 | setMasterSyncAutomaticallyAsUser(sync, UserHandle.myUserId()); |
Alexandra Gherghina | 0e9ac20 | 2014-07-15 23:11:48 +0100 | [diff] [blame] | 2956 | } |
| 2957 | |
| 2958 | /** |
| 2959 | * @see #setMasterSyncAutomatically(boolean) |
| 2960 | * @hide |
| 2961 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 2962 | public static void setMasterSyncAutomaticallyAsUser(boolean sync, @UserIdInt int userId) { |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2963 | try { |
Alexandra Gherghina | 0e9ac20 | 2014-07-15 23:11:48 +0100 | [diff] [blame] | 2964 | getContentService().setMasterSyncAutomaticallyAsUser(sync, userId); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2965 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2966 | throw e.rethrowFromSystemServer(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2967 | } |
| 2968 | } |
| 2969 | |
| 2970 | /** |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2971 | * Returns true if there is currently a sync operation for the given account or authority |
| 2972 | * actively being processed. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2973 | * <p>This method requires the caller to hold the permission |
| 2974 | * {@link android.Manifest.permission#READ_SYNC_STATS}. |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2975 | * @param account the account whose setting we are querying |
| 2976 | * @param authority the provider whose behavior is being queried |
| 2977 | * @return true if a sync is active for the given account or authority. |
| 2978 | */ |
| 2979 | public static boolean isSyncActive(Account account, String authority) { |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2980 | if (account == null) { |
| 2981 | throw new IllegalArgumentException("account must not be null"); |
| 2982 | } |
| 2983 | if (authority == null) { |
| 2984 | throw new IllegalArgumentException("authority must not be null"); |
| 2985 | } |
| 2986 | |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2987 | try { |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2988 | return getContentService().isSyncActive(account, authority, null); |
| 2989 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 2990 | throw e.rethrowFromSystemServer(); |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 2991 | } |
| 2992 | } |
| 2993 | |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 2994 | /** |
Fred Quintana | c6a6955 | 2010-09-27 17:05:04 -0700 | [diff] [blame] | 2995 | * If a sync is active returns the information about it, otherwise returns null. |
| 2996 | * <p> |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 2997 | * This method requires the caller to hold the permission |
| 2998 | * {@link android.Manifest.permission#READ_SYNC_STATS}. |
| 2999 | * <p> |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 3000 | * @return the SyncInfo for the currently active sync or null if one is not active. |
Fred Quintana | c6a6955 | 2010-09-27 17:05:04 -0700 | [diff] [blame] | 3001 | * @deprecated |
| 3002 | * Since multiple concurrent syncs are now supported you should use |
| 3003 | * {@link #getCurrentSyncs()} to get the accurate list of current syncs. |
| 3004 | * This method returns the first item from the list of current syncs |
| 3005 | * or null if there are none. |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3006 | */ |
Fred Quintana | c6a6955 | 2010-09-27 17:05:04 -0700 | [diff] [blame] | 3007 | @Deprecated |
Fred Quintana | d5e4fdc | 2010-03-30 15:16:21 -0700 | [diff] [blame] | 3008 | public static SyncInfo getCurrentSync() { |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3009 | try { |
Fred Quintana | c6a6955 | 2010-09-27 17:05:04 -0700 | [diff] [blame] | 3010 | final List<SyncInfo> syncs = getContentService().getCurrentSyncs(); |
| 3011 | if (syncs.isEmpty()) { |
| 3012 | return null; |
| 3013 | } |
| 3014 | return syncs.get(0); |
| 3015 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 3016 | throw e.rethrowFromSystemServer(); |
Fred Quintana | c6a6955 | 2010-09-27 17:05:04 -0700 | [diff] [blame] | 3017 | } |
| 3018 | } |
| 3019 | |
| 3020 | /** |
| 3021 | * Returns a list with information about all the active syncs. This list will be empty |
| 3022 | * if there are no active syncs. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 3023 | * <p> |
| 3024 | * This method requires the caller to hold the permission |
| 3025 | * {@link android.Manifest.permission#READ_SYNC_STATS}. |
| 3026 | * <p> |
Fred Quintana | c6a6955 | 2010-09-27 17:05:04 -0700 | [diff] [blame] | 3027 | * @return a List of SyncInfo objects for the currently active syncs. |
| 3028 | */ |
| 3029 | public static List<SyncInfo> getCurrentSyncs() { |
| 3030 | try { |
| 3031 | return getContentService().getCurrentSyncs(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3032 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 3033 | throw e.rethrowFromSystemServer(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3034 | } |
| 3035 | } |
| 3036 | |
| 3037 | /** |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 3038 | * @see #getCurrentSyncs() |
| 3039 | * @hide |
| 3040 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 3041 | public static List<SyncInfo> getCurrentSyncsAsUser(@UserIdInt int userId) { |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 3042 | try { |
| 3043 | return getContentService().getCurrentSyncsAsUser(userId); |
| 3044 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 3045 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 3046 | } |
| 3047 | } |
| 3048 | |
| 3049 | /** |
Fred Quintana | 4a6679b | 2009-08-17 13:05:39 -0700 | [diff] [blame] | 3050 | * Returns the status that matches the authority. |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3051 | * @param account the account whose setting we are querying |
| 3052 | * @param authority the provider whose behavior is being queried |
| 3053 | * @return the SyncStatusInfo for the authority, or null if none exists |
| 3054 | * @hide |
| 3055 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 3056 | @UnsupportedAppUsage |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3057 | public static SyncStatusInfo getSyncStatus(Account account, String authority) { |
| 3058 | try { |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 3059 | return getContentService().getSyncStatus(account, authority, null); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3060 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 3061 | throw e.rethrowFromSystemServer(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3062 | } |
| 3063 | } |
| 3064 | |
| 3065 | /** |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 3066 | * @see #getSyncStatus(Account, String) |
| 3067 | * @hide |
| 3068 | */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 3069 | @UnsupportedAppUsage |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 3070 | public static SyncStatusInfo getSyncStatusAsUser(Account account, String authority, |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 3071 | @UserIdInt int userId) { |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 3072 | try { |
| 3073 | return getContentService().getSyncStatusAsUser(account, authority, null, userId); |
| 3074 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 3075 | throw e.rethrowFromSystemServer(); |
Alexandra Gherghina | 0363c3e | 2014-06-23 13:34:59 +0100 | [diff] [blame] | 3076 | } |
| 3077 | } |
| 3078 | |
| 3079 | /** |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3080 | * Return true if the pending status is true of any matching authorities. |
Nicolas Falliere | 9530e3a | 2012-06-18 17:21:06 -0700 | [diff] [blame] | 3081 | * <p>This method requires the caller to hold the permission |
| 3082 | * {@link android.Manifest.permission#READ_SYNC_STATS}. |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3083 | * @param account the account whose setting we are querying |
| 3084 | * @param authority the provider whose behavior is being queried |
| 3085 | * @return true if there is a pending sync with the matching account and authority |
| 3086 | */ |
| 3087 | public static boolean isSyncPending(Account account, String authority) { |
Alexandra Gherghina | 03e1e83 | 2014-09-10 16:06:10 +0100 | [diff] [blame] | 3088 | return isSyncPendingAsUser(account, authority, UserHandle.myUserId()); |
Alexandra Gherghina | cb22807 | 2014-07-01 15:14:11 +0100 | [diff] [blame] | 3089 | } |
| 3090 | |
| 3091 | /** |
| 3092 | * @see #requestSync(Account, String, Bundle) |
| 3093 | * @hide |
| 3094 | */ |
Jeff Sharkey | 8588bc1 | 2016-01-06 16:47:42 -0700 | [diff] [blame] | 3095 | public static boolean isSyncPendingAsUser(Account account, String authority, |
| 3096 | @UserIdInt int userId) { |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3097 | try { |
Alexandra Gherghina | cb22807 | 2014-07-01 15:14:11 +0100 | [diff] [blame] | 3098 | return getContentService().isSyncPendingAsUser(account, authority, null, userId); |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 3099 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 3100 | throw e.rethrowFromSystemServer(); |
Matthew Williams | 56dbf8f | 2013-07-26 12:56:39 -0700 | [diff] [blame] | 3101 | } |
| 3102 | } |
| 3103 | |
Fred Quintana | 1b487ec | 2010-02-26 10:57:55 -0800 | [diff] [blame] | 3104 | /** |
| 3105 | * Request notifications when the different aspects of the SyncManager change. The |
| 3106 | * different items that can be requested are: |
| 3107 | * <ul> |
| 3108 | * <li> {@link #SYNC_OBSERVER_TYPE_PENDING} |
| 3109 | * <li> {@link #SYNC_OBSERVER_TYPE_ACTIVE} |
| 3110 | * <li> {@link #SYNC_OBSERVER_TYPE_SETTINGS} |
| 3111 | * </ul> |
| 3112 | * The caller can set one or more of the status types in the mask for any |
| 3113 | * given listener registration. |
| 3114 | * @param mask the status change types that will cause the callback to be invoked |
| 3115 | * @param callback observer to be invoked when the status changes |
| 3116 | * @return a handle that can be used to remove the listener at a later time |
| 3117 | */ |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3118 | public static Object addStatusChangeListener(int mask, final SyncStatusObserver callback) { |
Fred Quintana | 1b487ec | 2010-02-26 10:57:55 -0800 | [diff] [blame] | 3119 | if (callback == null) { |
| 3120 | throw new IllegalArgumentException("you passed in a null callback"); |
| 3121 | } |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3122 | try { |
| 3123 | ISyncStatusObserver.Stub observer = new ISyncStatusObserver.Stub() { |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 3124 | @Override |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3125 | public void onStatusChanged(int which) throws RemoteException { |
| 3126 | callback.onStatusChanged(which); |
| 3127 | } |
| 3128 | }; |
| 3129 | getContentService().addStatusChangeListener(mask, observer); |
| 3130 | return observer; |
| 3131 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 3132 | throw e.rethrowFromSystemServer(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3133 | } |
| 3134 | } |
| 3135 | |
Fred Quintana | 1b487ec | 2010-02-26 10:57:55 -0800 | [diff] [blame] | 3136 | /** |
| 3137 | * Remove a previously registered status change listener. |
| 3138 | * @param handle the handle that was returned by {@link #addStatusChangeListener} |
| 3139 | */ |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3140 | public static void removeStatusChangeListener(Object handle) { |
Fred Quintana | 1b487ec | 2010-02-26 10:57:55 -0800 | [diff] [blame] | 3141 | if (handle == null) { |
| 3142 | throw new IllegalArgumentException("you passed in a null handle"); |
| 3143 | } |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3144 | try { |
| 3145 | getContentService().removeStatusChangeListener((ISyncStatusObserver.Stub) handle); |
| 3146 | } catch (RemoteException e) { |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 3147 | throw e.rethrowFromSystemServer(); |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3148 | } |
| 3149 | } |
| 3150 | |
Ivan Chiang | fd3415c | 2018-12-07 18:22:50 +0800 | [diff] [blame] | 3151 | /** |
Jeff Sharkey | b91eaa5 | 2019-02-19 11:09:13 -0700 | [diff] [blame] | 3152 | * Store the given {@link Bundle} as a long-lived cached object within the |
| 3153 | * system. This can be useful to avoid expensive re-parsing when apps are |
| 3154 | * restarted multiple times on low-RAM devices. |
| 3155 | * <p> |
| 3156 | * The {@link Bundle} is automatically invalidated when a |
| 3157 | * {@link #notifyChange(Uri, ContentObserver)} event applies to the key. |
Ivan Chiang | fd3415c | 2018-12-07 18:22:50 +0800 | [diff] [blame] | 3158 | * |
Jeff Sharkey | b91eaa5 | 2019-02-19 11:09:13 -0700 | [diff] [blame] | 3159 | * @hide |
Ivan Chiang | fd3415c | 2018-12-07 18:22:50 +0800 | [diff] [blame] | 3160 | */ |
Ivan Chiang | 5922ce2 | 2019-02-13 11:42:42 +0800 | [diff] [blame] | 3161 | @SystemApi |
Ivan Chiang | a46ade3 | 2019-02-25 11:30:34 +0800 | [diff] [blame] | 3162 | @RequiresPermission(android.Manifest.permission.CACHE_CONTENT) |
Jeff Sharkey | b91eaa5 | 2019-02-19 11:09:13 -0700 | [diff] [blame] | 3163 | public void putCache(@NonNull Uri key, @Nullable Bundle value) { |
Jeff Sharkey | 8731408 | 2016-03-11 17:25:11 -0700 | [diff] [blame] | 3164 | try { |
| 3165 | getContentService().putCache(mContext.getPackageName(), key, value, |
| 3166 | mContext.getUserId()); |
| 3167 | } catch (RemoteException e) { |
| 3168 | throw e.rethrowFromSystemServer(); |
| 3169 | } |
| 3170 | } |
| 3171 | |
Ivan Chiang | fd3415c | 2018-12-07 18:22:50 +0800 | [diff] [blame] | 3172 | /** |
Jeff Sharkey | b91eaa5 | 2019-02-19 11:09:13 -0700 | [diff] [blame] | 3173 | * Retrieve the last {@link Bundle} stored as a long-lived cached object |
| 3174 | * within the system. |
Ivan Chiang | fd3415c | 2018-12-07 18:22:50 +0800 | [diff] [blame] | 3175 | * |
Jeff Sharkey | b91eaa5 | 2019-02-19 11:09:13 -0700 | [diff] [blame] | 3176 | * @return {@code null} if no cached object has been stored, or if the |
| 3177 | * stored object has been invalidated due to a |
| 3178 | * {@link #notifyChange(Uri, ContentObserver)} event. |
| 3179 | * @hide |
Ivan Chiang | fd3415c | 2018-12-07 18:22:50 +0800 | [diff] [blame] | 3180 | */ |
Ivan Chiang | 5922ce2 | 2019-02-13 11:42:42 +0800 | [diff] [blame] | 3181 | @SystemApi |
Ivan Chiang | a46ade3 | 2019-02-25 11:30:34 +0800 | [diff] [blame] | 3182 | @RequiresPermission(android.Manifest.permission.CACHE_CONTENT) |
Jeff Sharkey | b91eaa5 | 2019-02-19 11:09:13 -0700 | [diff] [blame] | 3183 | public @Nullable Bundle getCache(@NonNull Uri key) { |
Jeff Sharkey | 8731408 | 2016-03-11 17:25:11 -0700 | [diff] [blame] | 3184 | try { |
| 3185 | final Bundle bundle = getContentService().getCache(mContext.getPackageName(), key, |
| 3186 | mContext.getUserId()); |
| 3187 | if (bundle != null) bundle.setClassLoader(mContext.getClassLoader()); |
| 3188 | return bundle; |
| 3189 | } catch (RemoteException e) { |
| 3190 | throw e.rethrowFromSystemServer(); |
| 3191 | } |
| 3192 | } |
| 3193 | |
Ben Lin | 8ea8200 | 2017-03-08 17:30:16 -0800 | [diff] [blame] | 3194 | /** {@hide} */ |
| 3195 | public int getTargetSdkVersion() { |
| 3196 | return mTargetSdkVersion; |
| 3197 | } |
| 3198 | |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 3199 | /** |
| 3200 | * Returns sampling percentage for a given duration. |
| 3201 | * |
| 3202 | * Always returns at least 1%. |
| 3203 | */ |
| 3204 | private int samplePercentForDuration(long durationMillis) { |
| 3205 | if (durationMillis >= SLOW_THRESHOLD_MILLIS) { |
| 3206 | return 100; |
| 3207 | } |
| 3208 | return (int) (100 * durationMillis / SLOW_THRESHOLD_MILLIS) + 1; |
| 3209 | } |
| 3210 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 3211 | private void maybeLogQueryToEventLog( |
| 3212 | long durationMillis, Uri uri, String[] projection, @Nullable Bundle queryArgs) { |
Jeff Sharkey | 2b4d22c | 2013-04-26 10:52:00 -0700 | [diff] [blame] | 3213 | if (!ENABLE_CONTENT_SAMPLE) return; |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 3214 | int samplePercent = samplePercentForDuration(durationMillis); |
| 3215 | if (samplePercent < 100) { |
| 3216 | synchronized (mRandom) { |
| 3217 | if (mRandom.nextInt(100) >= samplePercent) { |
| 3218 | return; |
| 3219 | } |
| 3220 | } |
| 3221 | } |
| 3222 | |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 3223 | // Ensure a non-null bundle. |
| 3224 | queryArgs = (queryArgs != null) ? queryArgs : Bundle.EMPTY; |
| 3225 | |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 3226 | StringBuilder projectionBuffer = new StringBuilder(100); |
| 3227 | if (projection != null) { |
| 3228 | for (int i = 0; i < projection.length; ++i) { |
| 3229 | // Note: not using a comma delimiter here, as the |
| 3230 | // multiple arguments to EventLog.writeEvent later |
| 3231 | // stringify with a comma delimiter, which would make |
| 3232 | // parsing uglier later. |
| 3233 | if (i != 0) projectionBuffer.append('/'); |
| 3234 | projectionBuffer.append(projection[i]); |
| 3235 | } |
| 3236 | } |
| 3237 | |
| 3238 | // ActivityThread.currentPackageName() only returns non-null if the |
| 3239 | // current thread is an application main thread. This parameter tells |
| 3240 | // us whether an event loop is blocked, and if so, which app it is. |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3241 | String blockingPackage = AppGlobals.getInitialPackage(); |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 3242 | |
| 3243 | EventLog.writeEvent( |
Brad Fitzpatrick | a8fbedb | 2010-04-08 14:08:54 -0700 | [diff] [blame] | 3244 | EventLogTags.CONTENT_QUERY_SAMPLE, |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 3245 | uri.toString(), |
| 3246 | projectionBuffer.toString(), |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 3247 | queryArgs.getString(QUERY_ARG_SQL_SELECTION, ""), |
| 3248 | queryArgs.getString(QUERY_ARG_SQL_SORT_ORDER, ""), |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 3249 | durationMillis, |
| 3250 | blockingPackage != null ? blockingPackage : "", |
| 3251 | samplePercent); |
| 3252 | } |
| 3253 | |
| 3254 | private void maybeLogUpdateToEventLog( |
| 3255 | long durationMillis, Uri uri, String operation, String selection) { |
Jeff Sharkey | 2b4d22c | 2013-04-26 10:52:00 -0700 | [diff] [blame] | 3256 | if (!ENABLE_CONTENT_SAMPLE) return; |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 3257 | int samplePercent = samplePercentForDuration(durationMillis); |
| 3258 | if (samplePercent < 100) { |
| 3259 | synchronized (mRandom) { |
| 3260 | if (mRandom.nextInt(100) >= samplePercent) { |
| 3261 | return; |
| 3262 | } |
| 3263 | } |
| 3264 | } |
Dianne Hackborn | 01e4cfc | 2010-06-24 15:07:24 -0700 | [diff] [blame] | 3265 | String blockingPackage = AppGlobals.getInitialPackage(); |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 3266 | EventLog.writeEvent( |
Brad Fitzpatrick | a8fbedb | 2010-04-08 14:08:54 -0700 | [diff] [blame] | 3267 | EventLogTags.CONTENT_UPDATE_SAMPLE, |
Brad Fitzpatrick | a63730d | 2010-02-07 22:25:34 -0800 | [diff] [blame] | 3268 | uri.toString(), |
| 3269 | operation, |
| 3270 | selection != null ? selection : "", |
| 3271 | durationMillis, |
| 3272 | blockingPackage != null ? blockingPackage : "", |
| 3273 | samplePercent); |
| 3274 | } |
Fred Quintana | ac9385e | 2009-06-22 18:00:59 -0700 | [diff] [blame] | 3275 | |
Jeff Brown | 825c513 | 2011-10-12 16:11:30 -0700 | [diff] [blame] | 3276 | private final class CursorWrapperInner extends CrossProcessCursorWrapper { |
Gilles Debunne | 03f0292 | 2010-06-09 14:11:45 -0700 | [diff] [blame] | 3277 | private final IContentProvider mContentProvider; |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3278 | private final AtomicBoolean mProviderReleased = new AtomicBoolean(); |
Jeff Brown | baaf8c3 | 2011-10-09 14:07:00 -0700 | [diff] [blame] | 3279 | |
| 3280 | private final CloseGuard mCloseGuard = CloseGuard.get(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3281 | |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3282 | CursorWrapperInner(Cursor cursor, IContentProvider contentProvider) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3283 | super(cursor); |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3284 | mContentProvider = contentProvider; |
Jeff Brown | baaf8c3 | 2011-10-09 14:07:00 -0700 | [diff] [blame] | 3285 | mCloseGuard.open("close"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3286 | } |
| 3287 | |
| 3288 | @Override |
| 3289 | public void close() { |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3290 | mCloseGuard.close(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3291 | super.close(); |
Jeff Brown | baaf8c3 | 2011-10-09 14:07:00 -0700 | [diff] [blame] | 3292 | |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3293 | if (mProviderReleased.compareAndSet(false, true)) { |
| 3294 | ContentResolver.this.releaseProvider(mContentProvider); |
Jeff Brown | baaf8c3 | 2011-10-09 14:07:00 -0700 | [diff] [blame] | 3295 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3296 | } |
| 3297 | |
| 3298 | @Override |
| 3299 | protected void finalize() throws Throwable { |
| 3300 | try { |
Narayan Kamath | 492e9e8 | 2017-03-22 14:28:08 +0000 | [diff] [blame] | 3301 | if (mCloseGuard != null) { |
| 3302 | mCloseGuard.warnIfOpen(); |
| 3303 | } |
| 3304 | |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3305 | close(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3306 | } finally { |
| 3307 | super.finalize(); |
| 3308 | } |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | private final class ParcelFileDescriptorInner extends ParcelFileDescriptor { |
Gilles Debunne | 03f0292 | 2010-06-09 14:11:45 -0700 | [diff] [blame] | 3313 | private final IContentProvider mContentProvider; |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3314 | private final AtomicBoolean mProviderReleased = new AtomicBoolean(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3315 | |
| 3316 | ParcelFileDescriptorInner(ParcelFileDescriptor pfd, IContentProvider icp) { |
| 3317 | super(pfd); |
| 3318 | mContentProvider = icp; |
| 3319 | } |
| 3320 | |
| 3321 | @Override |
Amith Yamasani | 487c11a | 2013-09-18 09:16:15 -0700 | [diff] [blame] | 3322 | public void releaseResources() { |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3323 | if (mProviderReleased.compareAndSet(false, true)) { |
Dianne Hackborn | 6ae8d18 | 2012-05-23 13:12:42 -0700 | [diff] [blame] | 3324 | ContentResolver.this.releaseProvider(mContentProvider); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3325 | } |
| 3326 | } |
| 3327 | } |
| 3328 | |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 3329 | /** @hide */ |
| 3330 | public static final String CONTENT_SERVICE_NAME = "content"; |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 3331 | |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 3332 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 3333 | @UnsupportedAppUsage |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 3334 | public static IContentService getContentService() { |
| 3335 | if (sContentService != null) { |
| 3336 | return sContentService; |
| 3337 | } |
| 3338 | IBinder b = ServiceManager.getService(CONTENT_SERVICE_NAME); |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 3339 | sContentService = IContentService.Stub.asInterface(b); |
Dianne Hackborn | 231cc60 | 2009-04-27 17:10:36 -0700 | [diff] [blame] | 3340 | return sContentService; |
| 3341 | } |
Tom O'Neill | 0ba1cb0 | 2010-01-08 12:53:50 -0800 | [diff] [blame] | 3342 | |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 3343 | /** @hide */ |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 3344 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 3345 | public String getPackageName() { |
| 3346 | return mPackageName; |
| 3347 | } |
| 3348 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 3349 | @UnsupportedAppUsage |
Jeff Sharkey | c907d21 | 2018-04-09 09:56:42 -0600 | [diff] [blame] | 3350 | private static volatile IContentService sContentService; |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 3351 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3352 | private final Context mContext; |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3353 | |
Mathew Inwood | 5c0d354 | 2018-08-14 13:54:31 +0100 | [diff] [blame] | 3354 | @UnsupportedAppUsage |
Dianne Hackborn | 35654b6 | 2013-01-14 17:38:02 -0800 | [diff] [blame] | 3355 | final String mPackageName; |
Jeff Sharkey | 912e80d | 2017-02-24 11:00:55 -0700 | [diff] [blame] | 3356 | final int mTargetSdkVersion; |
Jeff Sharkey | a13887f | 2019-02-15 15:53:35 -0700 | [diff] [blame] | 3357 | final ContentInterface mWrapped; |
Jeff Sharkey | 60cfad8 | 2016-01-05 17:30:57 -0700 | [diff] [blame] | 3358 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3359 | private static final String TAG = "ContentResolver"; |
Nicolas Prevot | d85fc72 | 2014-04-16 19:52:08 +0100 | [diff] [blame] | 3360 | |
| 3361 | /** @hide */ |
| 3362 | public int resolveUserId(Uri uri) { |
| 3363 | return ContentProvider.getUserIdFromUri(uri, mContext.getUserId()); |
| 3364 | } |
Daniel Nishi | c29d2b0 | 2016-06-30 12:20:41 -0700 | [diff] [blame] | 3365 | |
| 3366 | /** @hide */ |
Jeff Sharkey | ad357d1 | 2018-02-02 13:25:31 -0700 | [diff] [blame] | 3367 | public int getUserId() { |
| 3368 | return mContext.getUserId(); |
| 3369 | } |
| 3370 | |
Jeff Sharkey | 806bece | 2019-02-19 14:42:55 -0700 | [diff] [blame] | 3371 | /** {@hide} */ |
| 3372 | @Deprecated |
Daniel Nishi | c29d2b0 | 2016-06-30 12:20:41 -0700 | [diff] [blame] | 3373 | public Drawable getTypeDrawable(String mimeType) { |
Jeff Sharkey | 806bece | 2019-02-19 14:42:55 -0700 | [diff] [blame] | 3374 | return getTypeInfo(mimeType).getIcon().loadDrawable(mContext); |
| 3375 | } |
| 3376 | |
| 3377 | /** |
| 3378 | * Return a detailed description of the given MIME type, including an icon |
| 3379 | * and label that describe the type. |
| 3380 | * |
| 3381 | * @param mimeType Valid, concrete MIME type. |
| 3382 | */ |
| 3383 | public final @NonNull TypeInfo getTypeInfo(@NonNull String mimeType) { |
| 3384 | Objects.requireNonNull(mimeType); |
| 3385 | return MimeIconUtils.getTypeInfo(mimeType); |
| 3386 | } |
| 3387 | |
| 3388 | /** |
| 3389 | * Detailed description of a specific MIME type, including an icon and label |
| 3390 | * that describe the type. |
| 3391 | */ |
| 3392 | public static final class TypeInfo { |
| 3393 | private final Icon mIcon; |
| 3394 | private final CharSequence mLabel; |
| 3395 | private final CharSequence mContentDescription; |
| 3396 | |
| 3397 | /** {@hide} */ |
| 3398 | public TypeInfo(@NonNull Icon icon, @NonNull CharSequence label, |
| 3399 | @NonNull CharSequence contentDescription) { |
| 3400 | mIcon = Objects.requireNonNull(icon); |
| 3401 | mLabel = Objects.requireNonNull(label); |
| 3402 | mContentDescription = Objects.requireNonNull(contentDescription); |
| 3403 | } |
| 3404 | |
| 3405 | /** |
| 3406 | * Return a visual representation of this MIME type. This can be styled |
| 3407 | * using {@link Icon#setTint(int)} to match surrounding UI. |
| 3408 | * |
| 3409 | * @see Icon#loadDrawable(Context) |
| 3410 | * @see android.widget.ImageView#setImageDrawable(Drawable) |
| 3411 | */ |
| 3412 | public @NonNull Icon getIcon() { |
| 3413 | return mIcon; |
| 3414 | } |
| 3415 | |
| 3416 | /** |
| 3417 | * Return a textual representation of this MIME type. |
| 3418 | * |
| 3419 | * @see android.widget.TextView#setText(CharSequence) |
| 3420 | */ |
| 3421 | public @NonNull CharSequence getLabel() { |
| 3422 | return mLabel; |
| 3423 | } |
| 3424 | |
| 3425 | /** |
| 3426 | * Return a content description for this MIME type. |
| 3427 | * |
| 3428 | * @see android.view.View#setContentDescription(CharSequence) |
| 3429 | */ |
| 3430 | public @NonNull CharSequence getContentDescription() { |
| 3431 | return mContentDescription; |
| 3432 | } |
Daniel Nishi | c29d2b0 | 2016-06-30 12:20:41 -0700 | [diff] [blame] | 3433 | } |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 3434 | |
| 3435 | /** |
| 3436 | * @hide |
| 3437 | */ |
| 3438 | public static @Nullable Bundle createSqlQueryBundle( |
| 3439 | @Nullable String selection, |
| 3440 | @Nullable String[] selectionArgs, |
| 3441 | @Nullable String sortOrder) { |
| 3442 | |
| 3443 | if (selection == null && selectionArgs == null && sortOrder == null) { |
| 3444 | return null; |
| 3445 | } |
| 3446 | |
| 3447 | Bundle queryArgs = new Bundle(); |
| 3448 | if (selection != null) { |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 3449 | queryArgs.putString(QUERY_ARG_SQL_SELECTION, selection); |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 3450 | } |
| 3451 | if (selectionArgs != null) { |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 3452 | queryArgs.putStringArray(QUERY_ARG_SQL_SELECTION_ARGS, selectionArgs); |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 3453 | } |
| 3454 | if (sortOrder != null) { |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 3455 | queryArgs.putString(QUERY_ARG_SQL_SORT_ORDER, sortOrder); |
Steve McKay | ea93fe7 | 2016-12-02 11:35:35 -0800 | [diff] [blame] | 3456 | } |
| 3457 | return queryArgs; |
| 3458 | } |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 3459 | |
| 3460 | /** |
| 3461 | * Returns structured sort args formatted as an SQL sort clause. |
| 3462 | * |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 3463 | * NOTE: Collator clauses are suitable for use with non text fields. We might |
| 3464 | * choose to omit any collation clause since we don't know the underlying |
| 3465 | * type of data to be collated. Imperical testing shows that sqlite3 doesn't |
| 3466 | * appear to care much about the presence of collate clauses in queries |
| 3467 | * when ordering by numeric fields. For this reason we include collate |
| 3468 | * clause unilaterally when {@link #QUERY_ARG_SORT_COLLATION} is present |
| 3469 | * in query args bundle. |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 3470 | * |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 3471 | * TODO: Would be nice to explicitly validate that colums referenced in |
| 3472 | * {@link #QUERY_ARG_SORT_COLUMNS} are present in the associated projection. |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 3473 | * |
| 3474 | * @hide |
| 3475 | */ |
| 3476 | public static String createSqlSortClause(Bundle queryArgs) { |
| 3477 | String[] columns = queryArgs.getStringArray(QUERY_ARG_SORT_COLUMNS); |
| 3478 | if (columns == null || columns.length == 0) { |
| 3479 | throw new IllegalArgumentException("Can't create sort clause without columns."); |
| 3480 | } |
| 3481 | |
| 3482 | String query = TextUtils.join(", ", columns); |
| 3483 | |
Steve McKay | d7ece9f | 2017-01-12 16:59:59 -0800 | [diff] [blame] | 3484 | // Interpret PRIMARY and SECONDARY collation strength as no-case collation based |
| 3485 | // on their javadoc descriptions. |
| 3486 | int collation = queryArgs.getInt( |
| 3487 | ContentResolver.QUERY_ARG_SORT_COLLATION, java.text.Collator.IDENTICAL); |
| 3488 | if (collation == java.text.Collator.PRIMARY || collation == java.text.Collator.SECONDARY) { |
| 3489 | query += " COLLATE NOCASE"; |
| 3490 | } |
| 3491 | |
Steve McKay | 415f41b | 2017-02-01 13:38:25 -0800 | [diff] [blame] | 3492 | int sortDir = queryArgs.getInt(QUERY_ARG_SORT_DIRECTION, Integer.MIN_VALUE); |
| 3493 | if (sortDir != Integer.MIN_VALUE) { |
| 3494 | switch (sortDir) { |
| 3495 | case QUERY_SORT_DIRECTION_ASCENDING: |
| 3496 | query += " ASC"; |
| 3497 | break; |
| 3498 | case QUERY_SORT_DIRECTION_DESCENDING: |
| 3499 | query += " DESC"; |
| 3500 | break; |
| 3501 | default: |
| 3502 | throw new IllegalArgumentException("Unsupported sort direction value." |
| 3503 | + " See ContentResolver documentation for details."); |
| 3504 | } |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 3505 | } |
Steve McKay | 29c3f68 | 2016-12-16 14:52:59 -0800 | [diff] [blame] | 3506 | return query; |
| 3507 | } |
Jeff Sharkey | 4e5efa3 | 2018-10-04 19:21:53 -0600 | [diff] [blame] | 3508 | |
| 3509 | /** |
| 3510 | * Convenience method that efficiently loads a visual thumbnail for the |
| 3511 | * given {@link Uri}. Internally calls |
| 3512 | * {@link ContentProvider#openTypedAssetFile} on the remote provider, but |
| 3513 | * also defensively resizes any returned content to match the requested |
| 3514 | * target size. |
| 3515 | * |
| 3516 | * @param uri The item that should be visualized as a thumbnail. |
| 3517 | * @param size The target area on the screen where this thumbnail will be |
| 3518 | * shown. This is passed to the provider as {@link #EXTRA_SIZE} |
| 3519 | * to help it avoid downloading or generating heavy resources. |
| 3520 | * @param signal A signal to cancel the operation in progress. |
| 3521 | * @return Valid {@link Bitmap} which is a visual thumbnail. |
| 3522 | * @throws IOException If any trouble was encountered while generating or |
| 3523 | * loading the thumbnail, or if |
| 3524 | * {@link CancellationSignal#cancel()} was invoked. |
| 3525 | */ |
| 3526 | public @NonNull Bitmap loadThumbnail(@NonNull Uri uri, @NonNull Size size, |
| 3527 | @Nullable CancellationSignal signal) throws IOException { |
| 3528 | Objects.requireNonNull(uri); |
| 3529 | Objects.requireNonNull(size); |
| 3530 | |
| 3531 | try (ContentProviderClient client = acquireContentProviderClient(uri)) { |
Leon Scroggins III | 19ff0c5 | 2018-11-19 10:00:51 -0500 | [diff] [blame] | 3532 | return loadThumbnail(client, uri, size, signal, ImageDecoder.ALLOCATOR_SOFTWARE); |
Jeff Sharkey | 4e5efa3 | 2018-10-04 19:21:53 -0600 | [diff] [blame] | 3533 | } |
| 3534 | } |
| 3535 | |
| 3536 | /** {@hide} */ |
Jeff Sharkey | e770d22 | 2018-12-07 15:15:59 -0700 | [diff] [blame] | 3537 | public static Bitmap loadThumbnail(@NonNull ContentInterface content, @NonNull Uri uri, |
Jeff Sharkey | 4e5efa3 | 2018-10-04 19:21:53 -0600 | [diff] [blame] | 3538 | @NonNull Size size, @Nullable CancellationSignal signal, int allocator) |
| 3539 | throws IOException { |
Jeff Sharkey | e770d22 | 2018-12-07 15:15:59 -0700 | [diff] [blame] | 3540 | Objects.requireNonNull(content); |
Jeff Sharkey | 4e5efa3 | 2018-10-04 19:21:53 -0600 | [diff] [blame] | 3541 | Objects.requireNonNull(uri); |
| 3542 | Objects.requireNonNull(size); |
| 3543 | |
| 3544 | // Convert to Point, since that's what the API is defined as |
| 3545 | final Bundle opts = new Bundle(); |
| 3546 | opts.putParcelable(EXTRA_SIZE, Point.convert(size)); |
| 3547 | |
| 3548 | return ImageDecoder.decodeBitmap(ImageDecoder.createSource(() -> { |
Jeff Sharkey | e770d22 | 2018-12-07 15:15:59 -0700 | [diff] [blame] | 3549 | return content.openTypedAssetFile(uri, "image/*", opts, signal); |
Jeff Sharkey | 4e5efa3 | 2018-10-04 19:21:53 -0600 | [diff] [blame] | 3550 | }), (ImageDecoder decoder, ImageInfo info, Source source) -> { |
| 3551 | decoder.setAllocator(allocator); |
| 3552 | |
| 3553 | // One last-ditch check to see if we've been canceled. |
| 3554 | if (signal != null) signal.throwIfCanceled(); |
| 3555 | |
| 3556 | // We requested a rough thumbnail size, but the remote size may have |
| 3557 | // returned something giant, so defensively scale down as needed. |
| 3558 | final int widthSample = info.getSize().getWidth() / size.getWidth(); |
| 3559 | final int heightSample = info.getSize().getHeight() / size.getHeight(); |
| 3560 | final int sample = Math.min(widthSample, heightSample); |
| 3561 | if (sample > 1) { |
| 3562 | decoder.setTargetSampleSize(sample); |
| 3563 | } |
| 3564 | }); |
| 3565 | } |
Makoto Onuki | ee93ad2 | 2018-10-18 16:24:13 -0700 | [diff] [blame] | 3566 | |
| 3567 | /** {@hide} */ |
| 3568 | public static void onDbCorruption(String tag, String message, Throwable stacktrace) { |
| 3569 | try { |
| 3570 | getContentService().onDbCorruption(tag, message, Log.getStackTraceString(stacktrace)); |
| 3571 | } catch (RemoteException e) { |
| 3572 | e.rethrowFromSystemServer(); |
| 3573 | } |
| 3574 | } |
Jeff Sharkey | bc2ae00 | 2018-07-31 10:45:37 -0600 | [diff] [blame] | 3575 | |
| 3576 | /** {@hide} */ |
| 3577 | public static Uri translateDeprecatedDataPath(String path) { |
| 3578 | final String ssp = "//" + path.substring(DEPRECATE_DATA_PREFIX.length()); |
| 3579 | return Uri.parse(new Uri.Builder().scheme(SCHEME_CONTENT) |
| 3580 | .encodedOpaquePart(ssp).build().toString()); |
| 3581 | } |
| 3582 | |
| 3583 | /** {@hide} */ |
| 3584 | public static String translateDeprecatedDataPath(Uri uri) { |
| 3585 | return DEPRECATE_DATA_PREFIX + uri.getEncodedSchemeSpecificPart().substring(2); |
| 3586 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3587 | } |