Merge "Use RingtonePlayer to get ringtone title" into mnc-dev
This commit is contained in:
@@ -33,4 +33,7 @@ interface IRingtonePlayer {
|
|||||||
/** Used for Notification sound playback. */
|
/** Used for Notification sound playback. */
|
||||||
void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa);
|
void playAsync(in Uri uri, in UserHandle user, boolean looping, in AudioAttributes aa);
|
||||||
void stopAsync();
|
void stopAsync();
|
||||||
|
|
||||||
|
/** Return the title of the media. */
|
||||||
|
String getTitle(in Uri uri);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ import android.os.Binder;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
|
import android.provider.MediaStore.MediaColumns;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -50,6 +51,8 @@ public class Ringtone {
|
|||||||
MediaStore.Audio.Media.DATA,
|
MediaStore.Audio.Media.DATA,
|
||||||
MediaStore.Audio.Media.TITLE
|
MediaStore.Audio.Media.TITLE
|
||||||
};
|
};
|
||||||
|
/** Selection that limits query results to just audio files */
|
||||||
|
private static final String MEDIA_SELECTION = MediaColumns.MIME_TYPE + " LIKE 'audio/%'";
|
||||||
|
|
||||||
// keep references on active Ringtones until stopped or completion listener called.
|
// keep references on active Ringtones until stopped or completion listener called.
|
||||||
private static final ArrayList<Ringtone> sActiveRingtones = new ArrayList<Ringtone>();
|
private static final ArrayList<Ringtone> sActiveRingtones = new ArrayList<Ringtone>();
|
||||||
@@ -193,11 +196,14 @@ public class Ringtone {
|
|||||||
*/
|
*/
|
||||||
public String getTitle(Context context) {
|
public String getTitle(Context context) {
|
||||||
if (mTitle != null) return mTitle;
|
if (mTitle != null) return mTitle;
|
||||||
return mTitle = getTitle(context, mUri, true);
|
return mTitle = getTitle(context, mUri, true /*followSettingsUri*/, mAllowRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getTitle(Context context, Uri uri, boolean followSettingsUri) {
|
/**
|
||||||
Cursor cursor = null;
|
* @hide
|
||||||
|
*/
|
||||||
|
public static String getTitle(
|
||||||
|
Context context, Uri uri, boolean followSettingsUri, boolean allowRemote) {
|
||||||
ContentResolver res = context.getContentResolver();
|
ContentResolver res = context.getContentResolver();
|
||||||
|
|
||||||
String title = null;
|
String title = null;
|
||||||
@@ -209,31 +215,45 @@ public class Ringtone {
|
|||||||
if (followSettingsUri) {
|
if (followSettingsUri) {
|
||||||
Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context,
|
Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context,
|
||||||
RingtoneManager.getDefaultType(uri));
|
RingtoneManager.getDefaultType(uri));
|
||||||
String actualTitle = getTitle(context, actualUri, false);
|
String actualTitle = getTitle(
|
||||||
|
context, actualUri, false /*followSettingsUri*/, allowRemote);
|
||||||
title = context
|
title = context
|
||||||
.getString(com.android.internal.R.string.ringtone_default_with_actual,
|
.getString(com.android.internal.R.string.ringtone_default_with_actual,
|
||||||
actualTitle);
|
actualTitle);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Cursor cursor = null;
|
||||||
try {
|
try {
|
||||||
if (MediaStore.AUTHORITY.equals(authority)) {
|
if (MediaStore.AUTHORITY.equals(authority)) {
|
||||||
cursor = res.query(uri, MEDIA_COLUMNS, null, null, null);
|
final String mediaSelection = allowRemote ? null : MEDIA_SELECTION;
|
||||||
}
|
cursor = res.query(uri, MEDIA_COLUMNS, mediaSelection, null, null);
|
||||||
} catch (SecurityException e) {
|
|
||||||
// missing cursor is handled below
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
if (cursor != null && cursor.getCount() == 1) {
|
if (cursor != null && cursor.getCount() == 1) {
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
return cursor.getString(2);
|
return cursor.getString(2);
|
||||||
} else {
|
}
|
||||||
title = uri.getLastPathSegment();
|
// missing cursor is handled below
|
||||||
|
}
|
||||||
|
} catch (SecurityException e) {
|
||||||
|
IRingtonePlayer mRemotePlayer = null;
|
||||||
|
if (allowRemote) {
|
||||||
|
AudioManager audioManager =
|
||||||
|
(AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||||
|
mRemotePlayer = audioManager.getRingtonePlayer();
|
||||||
|
}
|
||||||
|
if (mRemotePlayer != null) {
|
||||||
|
try {
|
||||||
|
title = mRemotePlayer.getTitle(uri);
|
||||||
|
} catch (RemoteException re) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (cursor != null) {
|
if (cursor != null) {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
|
cursor = null;
|
||||||
|
}
|
||||||
|
if (title == null) {
|
||||||
|
title = uri.getLastPathSegment();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -171,6 +171,13 @@ public class RingtonePlayer extends SystemUI {
|
|||||||
}
|
}
|
||||||
mAsyncPlayer.stop();
|
mAsyncPlayer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTitle(Uri uri) {
|
||||||
|
final UserHandle user = Binder.getCallingUserHandle();
|
||||||
|
return Ringtone.getTitle(getContextForUser(user), uri,
|
||||||
|
false /*followSettingsUri*/, false /*allowRemote*/);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private Context getContextForUser(UserHandle user) {
|
private Context getContextForUser(UserHandle user) {
|
||||||
|
|||||||
Reference in New Issue
Block a user