Merge "Add the test for the new api canManageMedia" into sc-dev
diff --git a/tests/tests/provider/src/android/provider/cts/media/MediaStoreTest.java b/tests/tests/provider/src/android/provider/cts/media/MediaStoreTest.java
index 1e9ac55..949b691 100644
--- a/tests/tests/provider/src/android/provider/cts/media/MediaStoreTest.java
+++ b/tests/tests/provider/src/android/provider/cts/media/MediaStoreTest.java
@@ -26,6 +26,7 @@
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import android.Manifest;
import android.app.AppOpsManager;
import android.content.ContentResolver;
import android.content.Context;
@@ -264,7 +265,25 @@
.isFalse();
}
- public void setAppOpsModeForUid(int uid, int mode, @NonNull String... ops) {
+ @Test
+ public void testCanManageMedia() throws Exception {
+ final String opString = AppOpsManager.permissionToOp(Manifest.permission.MANAGE_MEDIA);
+
+ // no access
+ assertThat(MediaStore.canManageMedia(getContext())).isFalse();
+ try {
+ // grant access
+ setAppOpsModeForUid(Process.myUid(), AppOpsManager.MODE_ALLOWED, opString);
+
+ assertThat(MediaStore.canManageMedia(getContext())).isTrue();
+ } finally {
+ setAppOpsModeForUid(Process.myUid(), AppOpsManager.MODE_ERRORED, opString);
+ }
+ // no access
+ assertThat(MediaStore.canManageMedia(getContext())).isFalse();
+ }
+
+ private void setAppOpsModeForUid(int uid, int mode, @NonNull String... ops) {
getInstrumentation().getUiAutomation().adoptShellPermissionIdentity(null);
try {
for (String op : ops) {