Skip to content

Commit e606329

Browse files
Dave SantoroAndroid (Google) Code Review
authored andcommitted
Merge "Add hidden API for pre-authorizing URIs." into ics-mr0
2 parents bcfe415 + e43185e commit e606329

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed

core/java/android/provider/ContactsContract.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,59 @@ public final class ContactsContract {
186186
*/
187187
public static final String DEFERRED_SNIPPETING_QUERY = "deferred_snippeting_query";
188188

189+
/**
190+
* <p>
191+
* API for obtaining a pre-authorized version of a URI that normally requires special
192+
* permission (beyond READ_CONTACTS) to read. The caller obtaining the pre-authorized URI
193+
* must already have the necessary permissions to access the URI; otherwise a
194+
* {@link SecurityException} will be thrown.
195+
* </p>
196+
* <p>
197+
* The authorized URI returned in the bundle contains an expiring token that allows the
198+
* caller to execute the query without having the special permissions that would normally
199+
* be required.
200+
* </p>
201+
* <p>
202+
* This API does not access disk, and should be safe to invoke from the UI thread.
203+
* </p>
204+
* <p>
205+
* Example usage:
206+
* <pre>
207+
* Uri profileUri = ContactsContract.Profile.CONTENT_VCARD_URI;
208+
* Bundle uriBundle = new Bundle();
209+
* uriBundle.putParcelable(ContactsContract.Authorization.KEY_URI_TO_AUTHORIZE, uri);
210+
* Bundle authResponse = getContext().getContentResolver().call(
211+
* ContactsContract.AUTHORITY_URI,
212+
* ContactsContract.Authorization.AUTHORIZATION_METHOD,
213+
* null, // String arg, not used.
214+
* uriBundle);
215+
* if (authResponse != null) {
216+
* Uri preauthorizedProfileUri = (Uri) authResponse.getParcelable(
217+
* ContactsContract.Authorization.KEY_AUTHORIZED_URI);
218+
* // This pre-authorized URI can be queried by a caller without READ_PROFILE
219+
* // permission.
220+
* }
221+
* </pre>
222+
* </p>
223+
* @hide
224+
*/
225+
public static final class Authorization {
226+
/**
227+
* The method to invoke to create a pre-authorized URI out of the input argument.
228+
*/
229+
public static final String AUTHORIZATION_METHOD = "authorize";
230+
231+
/**
232+
* The key to set in the outbound Bundle with the URI that should be authorized.
233+
*/
234+
public static final String KEY_URI_TO_AUTHORIZE = "uri_to_authorize";
235+
236+
/**
237+
* The key to retrieve from the returned Bundle to obtain the pre-authorized URI.
238+
*/
239+
public static final String KEY_AUTHORIZED_URI = "authorized_uri";
240+
}
241+
189242
/**
190243
* @hide
191244
*/

core/java/android/provider/Settings.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4052,6 +4052,14 @@ public static final String getBluetoothInputDevicePriorityKey(String address) {
40524052
/** Timeout for package verification. {@hide} */
40534053
public static final String PACKAGE_VERIFIER_TIMEOUT = "verifier_timeout";
40544054

4055+
/**
4056+
* Duration in milliseconds before pre-authorized URIs for the contacts
4057+
* provider should expire.
4058+
* @hide
4059+
*/
4060+
public static final String CONTACTS_PREAUTH_URI_EXPIRATION =
4061+
"contacts_preauth_uri_expiration";
4062+
40554063
/**
40564064
* This are the settings to be backed up.
40574065
*

0 commit comments

Comments
 (0)