am 09c4eaf7: am 7f9e9012: Merge "RingtoneManager: query results depend on caller permission" into mnc-dev

* commit '09c4eaf71e6ec750db5b7d810bfa9643196ed968':
  RingtoneManager: query results depend on caller permission
This commit is contained in:
Jean-Michel Trivi
2015-07-24 03:08:09 +00:00
committed by Android Git Automerger

View File

@@ -23,9 +23,11 @@ import android.annotation.SdkConstant.SdkConstantType;
import android.app.Activity;
import android.content.ContentUris;
import android.content.Context;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.Environment;
import android.os.Process;
import android.provider.MediaStore;
import android.provider.Settings;
import android.provider.Settings.System;
@@ -359,7 +361,10 @@ public class RingtoneManager {
* If {@link RingtoneManager#RingtoneManager(Activity)} was not used, the
* caller should manage the returned cursor through its activity's life
* cycle to prevent leaking the cursor.
*
* <p>
* Note that the list of ringtones available will differ depending on whether the caller
* has the {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission.
*
* @return A {@link Cursor} of all the ringtones available.
* @see #ID_COLUMN_INDEX
* @see #TITLE_COLUMN_INDEX
@@ -455,8 +460,10 @@ public class RingtoneManager {
/**
* Returns a valid ringtone URI. No guarantees on which it returns. If it
* cannot find one, returns null.
*
* cannot find one, returns null. If it can only find one on external storage and the caller
* doesn't have the {@link android.Manifest.permission#READ_EXTERNAL_STORAGE} permission,
* returns null.
*
* @param context The context to use for querying.
* @return A ringtone URI, or null if one cannot be found.
*/
@@ -495,6 +502,12 @@ public class RingtoneManager {
}
private Cursor getMediaRingtones() {
if (PackageManager.PERMISSION_GRANTED != mContext.checkPermission(
android.Manifest.permission.READ_EXTERNAL_STORAGE,
Process.myPid(), Process.myUid())) {
Log.w(TAG, "No READ_EXTERNAL_STORAGE permission, ignoring ringtones on ext storage");
return null;
}
// Get the external media cursor. First check to see if it is mounted.
final String status = Environment.getExternalStorageState();