diff options
author | Dianne Hackborn <hackbod@google.com> | 2013-09-06 16:17:22 -0700 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2013-09-06 16:39:59 -0700 |
commit | 38ed2a471a2291383821fb187bfa18450f0581c2 (patch) | |
tree | 31a7ac96e520056689aa78c91c2bb244233305a8 /core/java/android/content/ContentResolver.java | |
parent | c8fb093a8970b78084f2b4505fc283ac9e24317b (diff) | |
download | frameworks_base-38ed2a471a2291383821fb187bfa18450f0581c2.zip frameworks_base-38ed2a471a2291383821fb187bfa18450f0581c2.tar.gz frameworks_base-38ed2a471a2291383821fb187bfa18450f0581c2.tar.bz2 |
Work on issue #10130785: Restore silence and vibrate settings...
...in settings > sound
Add a new ContentProvider API to canonicalize URIs, so they can
be transported across backup/restore.
Change-Id: Ie5af3662f6822a32310e49c7f1e1ff084986c56e
Diffstat (limited to 'core/java/android/content/ContentResolver.java')
-rw-r--r-- | core/java/android/content/ContentResolver.java | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/core/java/android/content/ContentResolver.java b/core/java/android/content/ContentResolver.java index 8a5a56c..9f462aa 100644 --- a/core/java/android/content/ContentResolver.java +++ b/core/java/android/content/ContentResolver.java @@ -497,6 +497,86 @@ public abstract class ContentResolver { } /** + * Transform the given <var>url</var> to a canonical representation of + * its referenced resource, which can be used across devices, persisted, + * backed up and restored, etc. The returned Uri is still a fully capable + * Uri for use with its content provider, allowing you to do all of the + * same content provider operations as with the original Uri -- + * {@link #query}, {@link #openInputStream(android.net.Uri)}, etc. The + * only difference in behavior between the original and new Uris is that + * the content provider may need to do some additional work at each call + * using it to resolve it to the correct resource, especially if the + * canonical Uri has been moved to a different environment. + * + * <p>If you are moving a canonical Uri between environments, you should + * perform another call to {@link #canonicalize} with that original Uri to + * re-canonicalize it for the current environment. Alternatively, you may + * want to use {@link #uncanonicalize} to transform it to a non-canonical + * Uri that works only in the current environment but potentially more + * efficiently than the canonical representation.</p> + * + * @param url The {@link Uri} that is to be transformed to a canonical + * representation. Like all resolver calls, the input can be either + * a non-canonical or canonical Uri. + * + * @return Returns the official canonical representation of <var>url</var>, + * or null if the content provider does not support a canonical representation + * of the given Uri. Many providers may not support canonicalization of some + * or all of their Uris. + * + * @see #uncanonicalize + */ + public final Uri canonicalize(Uri url) { + IContentProvider provider = acquireProvider(url); + if (provider == null) { + return null; + } + + try { + return provider.canonicalize(mPackageName, url); + } catch (RemoteException e) { + // Arbitrary and not worth documenting, as Activity + // Manager will kill this process shortly anyway. + return null; + } finally { + releaseProvider(provider); + } + } + + /** + * Given a canonical Uri previously generated by {@link #canonicalize}, convert + * it to its local non-canonical form. This can be useful in some cases where + * you know that you will only be using the Uri in the current environment and + * want to avoid any possible overhead when using it with the content + * provider. + * + * @param url The canonical {@link Uri} that is to be convered back to its + * non-canonical form. + * + * @return Returns the non-canonical representation of <var>url</var>. This + * function never returns null; if there is no conversion to be done, it returns + * the same Uri that was provided. + * + * @see #canonicalize + */ + public final Uri uncanonicalize(Uri url) { + IContentProvider provider = acquireProvider(url); + if (provider == null) { + return null; + } + + try { + return provider.uncanonicalize(mPackageName, url); + } catch (RemoteException e) { + // Arbitrary and not worth documenting, as Activity + // Manager will kill this process shortly anyway. + return null; + } finally { + releaseProvider(provider); + } + } + + /** * Open a stream on to the content associated with a content URI. If there * is no data associated with the URI, FileNotFoundException is thrown. * |