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 { 50 public abstract ContentValues getContentValues(boolean isInternal); 51 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 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 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 { 70 private Audio1() { 71 } 72 73 private static Audio1 sInstance = new Audio1(); 74 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 YEAR = 1992; 88 89 public static final int TRACK = 1; 90 91 public static final int DURATION = 340000; 92 93 public static final String COMPOSER = "Bruce Swedien"; 94 95 public static final String ARTIST = "Michael Jackson"; 96 97 public static final String ALBUM = "Dangerous"; 98 99 public static final String TITLE = "Jam"; 100 101 public static final int SIZE = 2737870; 102 103 public static final String MIME_TYPE = "audio/x-mpeg"; 104 105 public static final String DISPLAY_NAME = "Jam -Michael Jackson"; 106 107 public static final String INTERNAL_DATA = 108 "/data/data/com.android.cts.stub/files/Jam.mp3"; 109 110 public static final String FILE_NAME = "Jam.mp3"; 111 112 public static final String EXTERNAL_DATA = Environment.getExternalStorageDirectory() + 113 "/" + FILE_NAME; 114 115 public static final long DATE_MODIFIED = System.currentTimeMillis(); 116 117 public static final String GENRE = "POP"; 118 @Override 119 public ContentValues getContentValues(boolean isInternal) { 120 ContentValues values = new ContentValues(); 121 values.put(Media.DATA, isInternal ? INTERNAL_DATA : EXTERNAL_DATA); 122 values.put(Media.DATE_MODIFIED, DATE_MODIFIED); 123 values.put(Media.DISPLAY_NAME, DISPLAY_NAME); 124 values.put(Media.MIME_TYPE, MIME_TYPE); 125 values.put(Media.SIZE, SIZE); 126 values.put(Media.TITLE, TITLE); 127 values.put(Media.ALBUM, ALBUM); 128 values.put(Media.ARTIST, ARTIST); 129 values.put(Media.COMPOSER, COMPOSER); 130 values.put(Media.DURATION, DURATION); 131 values.put(Media.TRACK, TRACK); 132 values.put(Media.YEAR, YEAR); 133 values.put(Media.IS_MUSIC, IS_MUSIC); 134 values.put(Media.IS_ALARM, IS_ALARM); 135 values.put(Media.IS_NOTIFICATION, IS_NOTIFICATION); 136 values.put(Media.IS_RINGTONE, IS_RINGTONE); 137 138 return values; 139 } 140 } 141 142 public static class Audio2 extends MockAudioMediaInfo { 143 private Audio2() { 144 } 145 146 private static Audio2 sInstance = new Audio2(); 147 148 public static Audio2 getInstance() { 149 return sInstance; 150 } 151 152 public static final int IS_RINGTONE = 1; 153 154 public static final int IS_NOTIFICATION = 0; 155 156 public static final int IS_ALARM = 0; 157 158 public static final int IS_MUSIC = 0; 159 160 public static final int YEAR = 1992; 161 162 public static final int TRACK = 1001; 163 164 public static final int DURATION = 338000; 165 166 public static final String COMPOSER = "Bruce Swedien"; 167 168 public static final String ARTIST = 169 "Michael Jackson - Live And Dangerous - National Stadium Bucharest"; 170 171 public static final String ALBUM = 172 "Michael Jackson - Live And Dangerous - National Stadium Bucharest"; 173 174 public static final String TITLE = "Jam"; 175 176 public static final int SIZE = 2737321; 177 178 public static final String MIME_TYPE = "audio/x-mpeg"; 179 180 public static final String DISPLAY_NAME = "Jam(Live)-Michael Jackson"; 181 182 public static final String FILE_NAME = "Jam_live.mp3"; 183 184 public static final String EXTERNAL_DATA = 185 Environment.getExternalStorageDirectory().getPath() + "/" + FILE_NAME; 186 187 public static final String INTERNAL_DATA = 188 "/data/data/com.android.cts.stub/files/Jam_live.mp3"; 189 190 191 192 public static final long DATE_MODIFIED = System.currentTimeMillis(); 193 194 @Override 195 public ContentValues getContentValues(boolean isInternal) { 196 ContentValues values = new ContentValues(); 197 values.put(Media.DATA, isInternal ? INTERNAL_DATA : EXTERNAL_DATA); 198 values.put(Media.DATE_MODIFIED, DATE_MODIFIED); 199 values.put(Media.DISPLAY_NAME, DISPLAY_NAME); 200 values.put(Media.MIME_TYPE, MIME_TYPE); 201 values.put(Media.SIZE, SIZE); 202 values.put(Media.TITLE, TITLE); 203 values.put(Media.ALBUM, ALBUM); 204 values.put(Media.ARTIST, ARTIST); 205 values.put(Media.COMPOSER, COMPOSER); 206 values.put(Media.DURATION, DURATION); 207 values.put(Media.TRACK, TRACK); 208 values.put(Media.YEAR, YEAR); 209 values.put(Media.IS_MUSIC, IS_MUSIC); 210 values.put(Media.IS_ALARM, IS_ALARM); 211 values.put(Media.IS_NOTIFICATION, IS_NOTIFICATION); 212 values.put(Media.IS_RINGTONE, IS_RINGTONE); 213 214 return values; 215 } 216 } 217 218 // These constants are not part of the public API 219 public static final String EXTERNAL_VOLUME_NAME = "external"; 220 public static final String INTERNAL_VOLUME_NAME = "internal"; 221 } 222