* commit '22c3f90639fa8d74de68a63b0a13412740580845': Move ringtone redirection to MediaPlayer.
This commit is contained in:
@ -37,6 +37,7 @@ import android.os.Process;
|
|||||||
import android.os.PowerManager;
|
import android.os.PowerManager;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
|
import android.provider.Settings;
|
||||||
import android.system.ErrnoException;
|
import android.system.ErrnoException;
|
||||||
import android.system.OsConstants;
|
import android.system.OsConstants;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -969,10 +970,15 @@ public class MediaPlayer implements SubtitleController.Listener
|
|||||||
*/
|
*/
|
||||||
public void setDataSource(Context context, Uri uri, Map<String, String> headers)
|
public void setDataSource(Context context, Uri uri, Map<String, String> headers)
|
||||||
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
|
throws IOException, IllegalArgumentException, SecurityException, IllegalStateException {
|
||||||
String scheme = uri.getScheme();
|
final String scheme = uri.getScheme();
|
||||||
if(scheme == null || scheme.equals("file")) {
|
if (ContentResolver.SCHEME_FILE.equals(scheme)) {
|
||||||
setDataSource(uri.getPath());
|
setDataSource(uri.getPath());
|
||||||
return;
|
return;
|
||||||
|
} else if (ContentResolver.SCHEME_CONTENT.equals(scheme)
|
||||||
|
&& Settings.AUTHORITY.equals(uri.getAuthority())) {
|
||||||
|
// Redirect ringtones to go directly to underlying provider
|
||||||
|
uri = RingtoneManager.getActualDefaultRingtoneUri(context,
|
||||||
|
RingtoneManager.getDefaultType(uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetFileDescriptor fd = null;
|
AssetFileDescriptor fd = null;
|
||||||
|
@ -37,13 +37,11 @@ import android.content.Intent;
|
|||||||
import android.content.IntentFilter;
|
import android.content.IntentFilter;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.UserInfo;
|
import android.content.pm.UserInfo;
|
||||||
import android.content.res.AssetFileDescriptor;
|
|
||||||
import android.database.AbstractCursor;
|
import android.database.AbstractCursor;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
import android.database.sqlite.SQLiteException;
|
import android.database.sqlite.SQLiteException;
|
||||||
import android.database.sqlite.SQLiteQueryBuilder;
|
import android.database.sqlite.SQLiteQueryBuilder;
|
||||||
import android.media.RingtoneManager;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@ -54,7 +52,6 @@ import android.os.Process;
|
|||||||
import android.os.SystemProperties;
|
import android.os.SystemProperties;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
import android.os.UserManager;
|
import android.os.UserManager;
|
||||||
import android.provider.MediaStore;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.Secure;
|
import android.provider.Settings.Secure;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
@ -1228,77 +1225,8 @@ public class SettingsProvider extends ContentProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
|
||||||
|
throw new FileNotFoundException("Direct file access no longer supported; "
|
||||||
/*
|
+ "ringtone playback is available through android.media.Ringtone");
|
||||||
* When a client attempts to openFile the default ringtone or
|
|
||||||
* notification setting Uri, we will proxy the call to the current
|
|
||||||
* default ringtone's Uri (if it is in the media provider).
|
|
||||||
*/
|
|
||||||
int ringtoneType = RingtoneManager.getDefaultType(uri);
|
|
||||||
// Above call returns -1 if the Uri doesn't match a default type
|
|
||||||
if (ringtoneType != -1) {
|
|
||||||
Context context = getContext();
|
|
||||||
|
|
||||||
// Get the current value for the default sound
|
|
||||||
Uri soundUri = RingtoneManager.getActualDefaultRingtoneUri(context, ringtoneType);
|
|
||||||
|
|
||||||
if (soundUri != null) {
|
|
||||||
// Proxy the openFile call to media provider
|
|
||||||
String authority = soundUri.getAuthority();
|
|
||||||
if (authority.equals(MediaStore.AUTHORITY)) {
|
|
||||||
return context.getContentResolver().openFileDescriptor(soundUri, mode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.openFile(uri, mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AssetFileDescriptor openAssetFile(Uri uri, String mode) throws FileNotFoundException {
|
|
||||||
|
|
||||||
/*
|
|
||||||
* When a client attempts to openFile the default ringtone or
|
|
||||||
* notification setting Uri, we will proxy the call to the current
|
|
||||||
* default ringtone's Uri (if it is in the media provider).
|
|
||||||
*/
|
|
||||||
int ringtoneType = RingtoneManager.getDefaultType(uri);
|
|
||||||
// Above call returns -1 if the Uri doesn't match a default type
|
|
||||||
if (ringtoneType != -1) {
|
|
||||||
Context context = getContext();
|
|
||||||
|
|
||||||
// Get the current value for the default sound
|
|
||||||
Uri soundUri = RingtoneManager.getActualDefaultRingtoneUri(context, ringtoneType);
|
|
||||||
|
|
||||||
if (soundUri != null) {
|
|
||||||
// Proxy the openFile call to media provider
|
|
||||||
String authority = soundUri.getAuthority();
|
|
||||||
if (authority.equals(MediaStore.AUTHORITY)) {
|
|
||||||
ParcelFileDescriptor pfd = null;
|
|
||||||
try {
|
|
||||||
pfd = context.getContentResolver().openFileDescriptor(soundUri, mode);
|
|
||||||
return new AssetFileDescriptor(pfd, 0, -1);
|
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
// fall through and open the fallback ringtone below
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
return super.openAssetFile(soundUri, mode);
|
|
||||||
} catch (FileNotFoundException ex) {
|
|
||||||
// Since a non-null Uri was specified, but couldn't be opened,
|
|
||||||
// fall back to the built-in ringtone.
|
|
||||||
return context.getResources().openRawResourceFd(
|
|
||||||
com.android.internal.R.raw.fallbackring);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// no need to fall through and have openFile() try again, since we
|
|
||||||
// already know that will fail.
|
|
||||||
throw new FileNotFoundException(); // or return null ?
|
|
||||||
}
|
|
||||||
|
|
||||||
// Note that this will end up calling openFile() above.
|
|
||||||
return super.openAssetFile(uri, mode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user