1 /* 2 * Copyright (C) 2013 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 package android.provider.cts.media; 18 19 import static android.provider.cts.media.MediaStoreTest.TAG; 20 21 import static org.junit.Assert.assertNotNull; 22 import static org.junit.Assert.assertTrue; 23 24 import android.content.Intent; 25 import android.content.pm.ResolveInfo; 26 import android.net.Uri; 27 import android.os.Build; 28 import android.provider.MediaStore; 29 import android.util.Log; 30 31 import androidx.test.InstrumentationRegistry; 32 import androidx.test.filters.SdkSuppress; 33 34 import org.junit.Before; 35 import org.junit.Test; 36 import org.junit.runner.RunWith; 37 import org.junit.runners.Parameterized; 38 import org.junit.runners.Parameterized.Parameter; 39 import org.junit.runners.Parameterized.Parameters; 40 41 import java.util.List; 42 43 /** 44 * Tests to verify that common actions on {@link MediaStore} content are 45 * available. 46 */ 47 @SdkSuppress(minSdkVersion = Build.VERSION_CODES.R) 48 @RunWith(Parameterized.class) 49 public class MediaStoreIntentsTest { 50 private Uri mExternalAudio; 51 private Uri mExternalVideo; 52 private Uri mExternalImages; 53 54 @Parameter(0) 55 public String mVolumeName; 56 57 @Parameters data()58 public static Iterable<? extends Object> data() { 59 return MediaProviderTestUtils.getSharedVolumeNames(); 60 } 61 62 @Before setUp()63 public void setUp() throws Exception { 64 Log.d(TAG, "Using volume " + mVolumeName); 65 mExternalAudio = MediaStore.Audio.Media.getContentUri(mVolumeName); 66 mExternalVideo = MediaStore.Video.Media.getContentUri(mVolumeName); 67 mExternalImages = MediaStore.Images.Media.getContentUri(mVolumeName); 68 } 69 assertCanBeHandled(Intent intent)70 public void assertCanBeHandled(Intent intent) { 71 List<ResolveInfo> resolveInfoList = InstrumentationRegistry.getTargetContext() 72 .getPackageManager().queryIntentActivities(intent, 0); 73 assertNotNull("Missing ResolveInfo", resolveInfoList); 74 assertTrue("No ResolveInfo found for " + intent.toString(), 75 resolveInfoList.size() > 0); 76 } 77 78 @Test testPickImageDir()79 public void testPickImageDir() { 80 Intent intent = new Intent(Intent.ACTION_PICK); 81 intent.setData(mExternalImages); 82 assertCanBeHandled(intent); 83 } 84 85 @Test testPickVideoDir()86 public void testPickVideoDir() { 87 Intent intent = new Intent(Intent.ACTION_PICK); 88 intent.setData(mExternalVideo); 89 assertCanBeHandled(intent); 90 } 91 92 @Test testPickAudioDir()93 public void testPickAudioDir() { 94 Intent intent = new Intent(Intent.ACTION_PICK); 95 intent.setData(mExternalAudio); 96 assertCanBeHandled(intent); 97 } 98 99 @Test testViewImageDir()100 public void testViewImageDir() { 101 Intent intent = new Intent(Intent.ACTION_VIEW); 102 intent.setData(mExternalImages); 103 assertCanBeHandled(intent); 104 } 105 106 @Test testViewVideoDir()107 public void testViewVideoDir() { 108 Intent intent = new Intent(Intent.ACTION_VIEW); 109 intent.setData(mExternalVideo); 110 assertCanBeHandled(intent); 111 } 112 113 @Test testViewImageFile()114 public void testViewImageFile() { 115 final String[] schemes = new String[] { 116 "file", "http", "https", "content" }; 117 final String[] mimes = new String[] { 118 "image/bmp", "image/jpeg", "image/png", "image/gif", "image/webp", 119 "image/x-adobe-dng", "image/x-canon-cr2", "image/x-nikon-nef", "image/x-nikon-nrw", 120 "image/x-sony-arw", "image/x-panasonic-rw2", "image/x-olympus-orf", 121 "image/x-fuji-raf", "image/x-pentax-pef", "image/x-samsung-srw" }; 122 123 for (String scheme : schemes) { 124 for (String mime : mimes) { 125 Intent intent = new Intent(Intent.ACTION_VIEW); 126 final Uri uri = new Uri.Builder().scheme(scheme) 127 .authority("example.com").path("image").build(); 128 intent.setDataAndType(uri, mime); 129 assertCanBeHandled(intent); 130 } 131 } 132 } 133 134 @Test testViewVideoFile()135 public void testViewVideoFile() { 136 final String[] schemes = new String[] { 137 "file", "http", "https", "content" }; 138 final String[] mimes = new String[] { 139 "video/mpeg4", "video/mp4", "video/3gp", "video/3gpp", "video/3gpp2", 140 "video/webm" }; 141 142 for (String scheme : schemes) { 143 for (String mime : mimes) { 144 Intent intent = new Intent(Intent.ACTION_VIEW); 145 final Uri uri = new Uri.Builder().scheme(scheme) 146 .authority("example.com").path("video").build(); 147 intent.setDataAndType(uri, mime); 148 assertCanBeHandled(intent); 149 } 150 } 151 } 152 153 @Test testViewAudioFile()154 public void testViewAudioFile() { 155 final String[] schemes = new String[] { 156 "file", "http", "content" }; 157 final String[] mimes = new String[] { 158 "audio/mpeg", "audio/mp4", "audio/ogg", "audio/webm", "application/ogg", 159 "application/x-ogg" }; 160 161 for (String scheme : schemes) { 162 for (String mime : mimes) { 163 Intent intent = new Intent(Intent.ACTION_VIEW); 164 final Uri uri = new Uri.Builder().scheme(scheme) 165 .authority("example.com").path("audio").build(); 166 intent.setDataAndType(uri, mime); 167 assertCanBeHandled(intent); 168 } 169 } 170 } 171 } 172