1 /* 2 * Copyright (C) 2015 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 18 package android.permission2.cts; 19 20 import android.content.ContentValues; 21 import android.platform.test.annotations.AppModeFull; 22 import android.provider.ContactsContract; 23 import android.test.AndroidTestCase; 24 import android.test.suitebuilder.annotation.SmallTest; 25 26 /** 27 * Verify that deprecated contacts permissions are not enforced. 28 */ 29 @AppModeFull(reason = "Instant apps cannot get the READ_CONTACTS/WRITE_CONTACTS permissions") 30 public class ContactsProviderTest extends AndroidTestCase { 31 32 /** 33 * Verifies that query(ContactsContract.Contacts.CONTENT_URI) only requires 34 * permission {@link android.Manifest.permission#READ_CONTACTS}. 35 */ 36 @SmallTest 37 public void testQueryContacts() { 38 getContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, 39 null, null, null, null); 40 } 41 42 /** 43 * Verifies that insert(ContactsContract.Contacts.CONTENT_URI) only requires 44 * permission {@link android.Manifest.permission#WRITE_CONTACTS}. 45 */ 46 @SmallTest 47 public void testInsertContacts() { 48 try { 49 getContext().getContentResolver().insert(ContactsContract.Contacts.CONTENT_URI, 50 new ContentValues()); 51 } catch (SecurityException e) { 52 fail("insert(ContactsContract.Contacts.CONTENT_URI) threw SecurityException"); 53 } catch (UnsupportedOperationException e) { 54 // It is okay for this fail in this manner. 55 } 56 } 57 58 /** 59 * Verifies that query(ContactsContract.Profile.CONTENT_URI) only requires 60 * permission {@link android.Manifest.permission#READ_CONTACTS}. 61 */ 62 @SmallTest 63 public void testQueryProfile() { 64 getContext().getContentResolver().query(ContactsContract.Profile.CONTENT_URI, 65 null, null, null, null); 66 } 67 68 /** 69 * Verifies that insert(ContactsContract.Profile.CONTENT_URI) only requires 70 * permission {@link android.Manifest.permission#WRITE_CONTACTS}. The provider won't 71 * actually let us execute this. But at least it shouldn't throw a security exception. 72 */ 73 @SmallTest 74 public void testInsertProfile() { 75 try { 76 getContext().getContentResolver().insert(ContactsContract.Profile.CONTENT_URI, 77 new ContentValues(0)); 78 } catch (SecurityException e) { 79 fail("insert(ContactsContract.Profile.CONTENT_URI) threw SecurityException"); 80 } catch (UnsupportedOperationException e) { 81 // It is okay for this fail in this manner. 82 } 83 } 84 85 /** 86 * Verifies that update(ContactsContract.Profile.CONTENT_URI) only requires 87 * permission {@link android.Manifest.permission#WRITE_CONTACTS}. 88 */ 89 @SmallTest 90 public void testUpdateProfile() { 91 getContext().getContentResolver().update(ContactsContract.Profile.CONTENT_URI, 92 new ContentValues(0), null, null); 93 } 94 } 95