1 /* 2 * Copyright (C) 2009 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; 18 19 import android.content.ContentResolver; 20 import android.content.ContentValues; 21 import android.net.Uri; 22 import android.os.Environment; 23 import android.provider.MediaStore; 24 import android.provider.MediaStore.Audio.Media; 25 26 import junit.framework.Assert; 27 28 /** 29 * This class contains fake data and convenient methods for testing: 30 * {@link MediaStore.Audio.Media} 31 * {@link MediaStore.Audio.Genres} 32 * {@link MediaStore.Audio.Genres.Members} 33 * {@link MediaStore.Audio.Playlists} 34 * {@link MediaStore.Audio.Playlists.Members} 35 * {@link MediaStore.Audio.Albums} 36 * {@link MediaStore.Audio.Artists} 37 * {@link MediaStore.Audio.Artists.Albums} 38 * 39 * @see MediaStore_Audio_MediaTest 40 * @see MediaStore_Audio_GenresTest 41 * @see MediaStore_Audio_Genres_MembersTest 42 * @see MediaStore_Audio_PlaylistsTest 43 * @see MediaStore_Audio_Playlists_MembersTest 44 * @see MediaStore_Audio_ArtistsTest 45 * @see MediaStore_Audio_Artists_AlbumsTest 46 * @see MediaStore_Audio_AlbumsTest 47 */ 48 public class MediaStoreAudioTestHelper { 49 public static abstract class MockAudioMediaInfo { getContentValues(boolean isInternal)50 public abstract ContentValues getContentValues(boolean isInternal); 51 insertToInternal(ContentResolver contentResolver)52 public Uri insertToInternal(ContentResolver contentResolver) { 53 Uri uri = contentResolver.insert(Media.INTERNAL_CONTENT_URI, getContentValues(true)); 54 Assert.assertNotNull(uri); 55 return uri; 56 } 57 insertToExternal(ContentResolver contentResolver)58 public Uri insertToExternal(ContentResolver contentResolver) { 59 Uri uri = contentResolver.insert(Media.EXTERNAL_CONTENT_URI, getContentValues(false)); 60 Assert.assertNotNull(uri); 61 return uri; 62 } 63 delete(ContentResolver contentResolver, Uri uri)64 public int delete(ContentResolver contentResolver, Uri uri) { 65 return contentResolver.delete(uri, null, null); 66 } 67 } 68 69 public static class Audio1 extends MockAudioMediaInfo { Audio1()70 private Audio1() { 71 } 72 73 private static Audio1 sInstance = new Audio1(); 74 getInstance()75 public static Audio1 getInstance() { 76 return sInstance; 77 } 78 79 public static final int IS_RINGTONE = 0; 80 81 public static final int IS_NOTIFICATION = 0; 82 83 public static final int IS_ALARM = 0; 84 85 public static final int IS_MUSIC = 1; 86 87 public static final int IS_DRM = 0; 88 89 public static final int YEAR = 1992; 90 91 public static final int TRACK = 1; 92 93 public static final int DURATION = 340000; 94 95 public static final String COMPOSER = "Bruce Swedien"; 96 97 public static final String ARTIST = "Michael Jackson"; 98 99 public static final String ALBUM = "Dangerous"; 100 101 public static final String TITLE = "Jam"; 102 103 public static final int SIZE = 2737870; 104 105 public static final String MIME_TYPE = "audio/x-mpeg"; 106 107 public static final String DISPLAY_NAME = "Jam -Michael Jackson"; 108 109 public static final String INTERNAL_DATA = 110 "/data/data/com.android.cts.provider/files/Jam.mp3"; 111 112 public static final String FILE_NAME = "Jam.mp3"; 113 114 public static final String EXTERNAL_DATA = Environment.getExternalStorageDirectory() + 115 "/" + FILE_NAME; 116 117 public static final long DATE_MODIFIED = System.currentTimeMillis() / 1000; 118 119 public static final String GENRE = "POP"; 120 @Override getContentValues(boolean isInternal)121 public ContentValues getContentValues(boolean isInternal) { 122 ContentValues values = new ContentValues(); 123 values.put(Media.DATA, isInternal ? INTERNAL_DATA : EXTERNAL_DATA); 124 values.put(Media.DATE_MODIFIED, DATE_MODIFIED); 125 values.put(Media.DISPLAY_NAME, DISPLAY_NAME); 126 values.put(Media.MIME_TYPE, MIME_TYPE); 127 values.put(Media.SIZE, SIZE); 128 values.put(Media.TITLE, TITLE); 129 values.put(Media.ALBUM, ALBUM); 130 values.put(Media.ARTIST, ARTIST); 131 values.put(Media.COMPOSER, COMPOSER); 132 values.put(Media.DURATION, DURATION); 133 values.put(Media.TRACK, TRACK); 134 values.put(Media.YEAR, YEAR); 135 values.put(Media.IS_MUSIC, IS_MUSIC); 136 values.put(Media.IS_ALARM, IS_ALARM); 137 values.put(Media.IS_NOTIFICATION, IS_NOTIFICATION); 138 values.put(Media.IS_RINGTONE, IS_RINGTONE); 139 values.put(Media.IS_DRM, IS_DRM); 140 141 return values; 142 } 143 } 144 145 public static class Audio2 extends MockAudioMediaInfo { Audio2()146 private Audio2() { 147 } 148 149 private static Audio2 sInstance = new Audio2(); 150 getInstance()151 public static Audio2 getInstance() { 152 return sInstance; 153 } 154 155 public static final int IS_RINGTONE = 1; 156 157 public static final int IS_NOTIFICATION = 0; 158 159 public static final int IS_ALARM = 0; 160 161 public static final int IS_MUSIC = 0; 162 163 public static final int IS_DRM = 0; 164 165 public static final int YEAR = 1992; 166 167 public static final int TRACK = 1001; 168 169 public static final int DURATION = 338000; 170 171 public static final String COMPOSER = "Bruce Swedien"; 172 173 public static final String ARTIST = 174 "Michael Jackson - Live And Dangerous - National Stadium Bucharest"; 175 176 public static final String ALBUM = 177 "Michael Jackson - Live And Dangerous - National Stadium Bucharest"; 178 179 public static final String TITLE = "Jam"; 180 181 public static final int SIZE = 2737321; 182 183 public static final String MIME_TYPE = "audio/x-mpeg"; 184 185 public static final String DISPLAY_NAME = "Jam(Live)-Michael Jackson"; 186 187 public static final String FILE_NAME = "Jam_live.mp3"; 188 189 public static final String EXTERNAL_DATA = 190 Environment.getExternalStorageDirectory().getPath() + "/" + FILE_NAME; 191 192 public static final String INTERNAL_DATA = 193 "/data/data/com.android.cts.provider/files/Jam_live.mp3"; 194 195 196 197 public static final long DATE_MODIFIED = System.currentTimeMillis(); 198 199 @Override getContentValues(boolean isInternal)200 public ContentValues getContentValues(boolean isInternal) { 201 ContentValues values = new ContentValues(); 202 values.put(Media.DATA, isInternal ? INTERNAL_DATA : EXTERNAL_DATA); 203 values.put(Media.DATE_MODIFIED, DATE_MODIFIED); 204 values.put(Media.DISPLAY_NAME, DISPLAY_NAME); 205 values.put(Media.MIME_TYPE, MIME_TYPE); 206 values.put(Media.SIZE, SIZE); 207 values.put(Media.TITLE, TITLE); 208 values.put(Media.ALBUM, ALBUM); 209 values.put(Media.ARTIST, ARTIST); 210 values.put(Media.COMPOSER, COMPOSER); 211 values.put(Media.DURATION, DURATION); 212 values.put(Media.TRACK, TRACK); 213 values.put(Media.YEAR, YEAR); 214 values.put(Media.IS_MUSIC, IS_MUSIC); 215 values.put(Media.IS_ALARM, IS_ALARM); 216 values.put(Media.IS_NOTIFICATION, IS_NOTIFICATION); 217 values.put(Media.IS_RINGTONE, IS_RINGTONE); 218 values.put(Media.IS_DRM, IS_DRM); 219 220 return values; 221 } 222 } 223 224 public static class Audio3 extends Audio1 { Audio3()225 private Audio3() { 226 } 227 228 private static Audio3 sInstance = new Audio3(); 229 getInstance()230 public static Audio3 getInstance() { 231 return sInstance; 232 } 233 234 @Override getContentValues(boolean isInternal)235 public ContentValues getContentValues(boolean isInternal) { 236 ContentValues values = super.getContentValues(isInternal); 237 values.put(Media.DATA, values.getAsString(Media.DATA) + "_3"); 238 return values; 239 } 240 } 241 242 public static class Audio4 extends Audio1 { Audio4()243 private Audio4() { 244 } 245 246 private static Audio4 sInstance = new Audio4(); 247 getInstance()248 public static Audio4 getInstance() { 249 return sInstance; 250 } 251 252 @Override getContentValues(boolean isInternal)253 public ContentValues getContentValues(boolean isInternal) { 254 ContentValues values = super.getContentValues(isInternal); 255 values.put(Media.DATA, values.getAsString(Media.DATA) + "_4"); 256 return values; 257 } 258 } 259 260 public static class Audio5 extends Audio1 { Audio5()261 private Audio5() { 262 } 263 264 private static Audio5 sInstance = new Audio5(); 265 getInstance()266 public static Audio5 getInstance() { 267 return sInstance; 268 } 269 270 @Override getContentValues(boolean isInternal)271 public ContentValues getContentValues(boolean isInternal) { 272 ContentValues values = super.getContentValues(isInternal); 273 values.put(Media.DATA, values.getAsString(Media.DATA) + "_5"); 274 return values; 275 } 276 } 277 278 // These constants are not part of the public API 279 public static final String EXTERNAL_VOLUME_NAME = "external"; 280 public static final String INTERNAL_VOLUME_NAME = "internal"; 281 } 282