2727import android .os .RemoteException ;
2828import android .provider .MediaStore ;
2929import android .provider .Settings ;
30+ import android .provider .MediaStore .MediaColumns ;
3031import android .util .Log ;
3132
3233import java .io .IOException ;
@@ -50,6 +51,8 @@ public class Ringtone {
5051 MediaStore .Audio .Media .DATA ,
5152 MediaStore .Audio .Media .TITLE
5253 };
54+ /** Selection that limits query results to just audio files */
55+ private static final String MEDIA_SELECTION = MediaColumns .MIME_TYPE + " LIKE 'audio/%'" ;
5356
5457 // keep references on active Ringtones until stopped or completion listener called.
5558 private static final ArrayList <Ringtone > sActiveRingtones = new ArrayList <Ringtone >();
@@ -193,11 +196,14 @@ private void applyPlaybackProperties_sync() {
193196 */
194197 public String getTitle (Context context ) {
195198 if (mTitle != null ) return mTitle ;
196- return mTitle = getTitle (context , mUri , true );
199+ return mTitle = getTitle (context , mUri , true /*followSettingsUri*/ , mAllowRemote );
197200 }
198201
199- private static String getTitle (Context context , Uri uri , boolean followSettingsUri ) {
200- Cursor cursor = null ;
202+ /**
203+ * @hide
204+ */
205+ public static String getTitle (
206+ Context context , Uri uri , boolean followSettingsUri , boolean allowRemote ) {
201207 ContentResolver res = context .getContentResolver ();
202208
203209 String title = null ;
@@ -209,31 +215,45 @@ private static String getTitle(Context context, Uri uri, boolean followSettingsU
209215 if (followSettingsUri ) {
210216 Uri actualUri = RingtoneManager .getActualDefaultRingtoneUri (context ,
211217 RingtoneManager .getDefaultType (uri ));
212- String actualTitle = getTitle (context , actualUri , false );
218+ String actualTitle = getTitle (
219+ context , actualUri , false /*followSettingsUri*/ , allowRemote );
213220 title = context
214221 .getString (com .android .internal .R .string .ringtone_default_with_actual ,
215222 actualTitle );
216223 }
217224 } else {
225+ Cursor cursor = null ;
218226 try {
219227 if (MediaStore .AUTHORITY .equals (authority )) {
220- cursor = res .query (uri , MEDIA_COLUMNS , null , null , null );
228+ final String mediaSelection = allowRemote ? null : MEDIA_SELECTION ;
229+ cursor = res .query (uri , MEDIA_COLUMNS , mediaSelection , null , null );
230+ if (cursor != null && cursor .getCount () == 1 ) {
231+ cursor .moveToFirst ();
232+ return cursor .getString (2 );
233+ }
234+ // missing cursor is handled below
221235 }
222236 } catch (SecurityException e ) {
223- // missing cursor is handled below
224- }
225-
226- try {
227- if (cursor != null && cursor .getCount () == 1 ) {
228- cursor .moveToFirst ();
229- return cursor .getString (2 );
230- } else {
231- title = uri .getLastPathSegment ();
237+ IRingtonePlayer mRemotePlayer = null ;
238+ if (allowRemote ) {
239+ AudioManager audioManager =
240+ (AudioManager ) context .getSystemService (Context .AUDIO_SERVICE );
241+ mRemotePlayer = audioManager .getRingtonePlayer ();
242+ }
243+ if (mRemotePlayer != null ) {
244+ try {
245+ title = mRemotePlayer .getTitle (uri );
246+ } catch (RemoteException re ) {
247+ }
232248 }
233249 } finally {
234250 if (cursor != null ) {
235251 cursor .close ();
236252 }
253+ cursor = null ;
254+ }
255+ if (title == null ) {
256+ title = uri .getLastPathSegment ();
237257 }
238258 }
239259 }
0 commit comments