Updated CTS tests for Contacts permissions

We no longer use the profile permissions.

Bug: 21090207
Change-Id: I31e6ae7b0f49c3589071f6a95f8d69a9456c144d
diff --git a/tests/tests/permission/src/android/permission/cts/ContactsProviderTest.java b/tests/tests/permission/src/android/permission/cts/ContactsProviderTest.java
index 51e54df..d815a1d 100644
--- a/tests/tests/permission/src/android/permission/cts/ContactsProviderTest.java
+++ b/tests/tests/permission/src/android/permission/cts/ContactsProviderTest.java
@@ -16,12 +16,7 @@
 
 package android.permission.cts;
 
-import android.os.RemoteException;
-import android.content.ContentProviderClient;
-import android.content.ContentResolver;
 import android.content.ContentValues;
-import android.database.Cursor;
-import android.provider.Contacts;
 import android.provider.ContactsContract;
 import android.test.AndroidTestCase;
 import android.test.suitebuilder.annotation.SmallTest;
@@ -71,7 +66,7 @@
      * Verifies that query(ContactsContract.Profile.CONTENT_URI) requires
      * Permission.
      * <p>
-     * Requires Permission: {@link android.Manifest.permission#READ_PROFILE}.
+     * Requires Permission: {@link android.Manifest.permission#READ_CONTACTS}.
      */
     @SmallTest
     public void testQueryProfile() {
@@ -91,7 +86,7 @@
      * permission, but trying to do it without the permission should throw a
      * SecurityException anyway.
      * <p>
-     * Requires Permission: {@link android.Manifest.permission#WRITE_PROFILE}.
+     * Requires Permission: {@link android.Manifest.permission#WRITE_CONTACTS}.
      */
     @SmallTest
     public void testInsertProfile() {
@@ -109,7 +104,7 @@
      * Verifies that update(ContactsContract.Profile.CONTENT_URI) requires
      * Permission.
      * <p>
-     * Requires Permission: {@link android.Manifest.permission#WRITE_PROFILE}.
+     * Requires Permission: {@link android.Manifest.permission#WRITE_CONTACTS}.
      */
     @SmallTest
     public void testUpdateProfile() {
diff --git a/tests/tests/permission2/AndroidManifest.xml b/tests/tests/permission2/AndroidManifest.xml
index c0b78c4..984d124 100755
--- a/tests/tests/permission2/AndroidManifest.xml
+++ b/tests/tests/permission2/AndroidManifest.xml
@@ -45,6 +45,12 @@
     <!-- need app that has RECORD_AUDIO but not CAPTURE_AUDIO_OUTPUT -->
     <uses-permission android:name="android.permission.RECORD_AUDIO"/>
 
+    <!-- need app that has READ_CONTACTS but not READ_PROFILE -->
+    <uses-permission android:name="android.permission.READ_CONTACTS"/>
+
+    <!-- need app that has WRITE_CONTACTS but not WRITE_PROFILE -->
+    <uses-permission android:name="android.permission.WRITE_CONTACTS"/>
+
     <!-- need a permission that would ordinarily be granted, but has a maxSdkVersion that
          causes it to be withheld under the current API level -->
     <uses-permission
diff --git a/tests/tests/permission2/src/android/permission2/cts/ContactsProviderTest.java b/tests/tests/permission2/src/android/permission2/cts/ContactsProviderTest.java
new file mode 100644
index 0000000..5a04079
--- /dev/null
+++ b/tests/tests/permission2/src/android/permission2/cts/ContactsProviderTest.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package android.permission2.cts;
+
+import android.content.ContentValues;
+import android.provider.ContactsContract;
+import android.test.AndroidTestCase;
+import android.test.suitebuilder.annotation.SmallTest;
+
+/**
+ * Verify that deprecated contacts permissions are not enforced.
+ */
+public class ContactsProviderTest extends AndroidTestCase {
+
+    /**
+     * Verifies that query(ContactsContract.Contacts.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#READ_CONTACTS}.
+     */
+    @SmallTest
+    public void testQueryContacts() {
+        getContext().getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
+                null, null, null, null);
+    }
+
+    /**
+     * Verifies that insert(ContactsContract.Contacts.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#WRITE_CONTACTS}.
+     */
+    @SmallTest
+    public void testInsertContacts() {
+        try {
+            getContext().getContentResolver().insert(ContactsContract.Contacts.CONTENT_URI,
+                    new ContentValues());
+        } catch (SecurityException e) {
+            fail("insert(ContactsContract.Contacts.CONTENT_URI) threw SecurityException");
+        } catch (UnsupportedOperationException e) {
+            // It is okay for this fail in this manner.
+        }
+    }
+
+    /**
+     * Verifies that query(ContactsContract.Profile.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#READ_CONTACTS}.
+     */
+    @SmallTest
+    public void testQueryProfile() {
+        getContext().getContentResolver().query(ContactsContract.Profile.CONTENT_URI,
+                null, null, null, null);
+    }
+
+    /**
+     * Verifies that insert(ContactsContract.Profile.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#WRITE_CONTACTS}. The provider won't
+     * actually let us execute this. But at least it shouldn't throw a security exception.
+     */
+    @SmallTest
+    public void testInsertProfile() {
+     try {
+         getContext().getContentResolver().insert(ContactsContract.Profile.CONTENT_URI,
+                new ContentValues(0));
+        } catch (SecurityException e) {
+            fail("insert(ContactsContract.Profile.CONTENT_URI) threw SecurityException");
+        } catch (UnsupportedOperationException e) {
+            // It is okay for this fail in this manner.
+        }
+    }
+
+    /**
+     * Verifies that update(ContactsContract.Profile.CONTENT_URI) only requires
+     * permission {@link android.Manifest.permission#WRITE_CONTACTS}.
+     */
+    @SmallTest
+    public void testUpdateProfile() {
+        getContext().getContentResolver().update(ContactsContract.Profile.CONTENT_URI,
+                new ContentValues(0), null, null);
+    }
+}