Fix SecurityException when trying to retrieve ringtone title

Use RingtoneManager.getRingtone instead of accessing MediaProvider
directly

Bug: 22430897

Change-Id: Ib7ec053b5b92ed3d1b77ef63ab339c9b8c4da87f
diff --git a/src/com/android/phone/common/util/SettingsUtil.java b/src/com/android/phone/common/util/SettingsUtil.java
index e473947..c297e1e 100644
--- a/src/com/android/phone/common/util/SettingsUtil.java
+++ b/src/com/android/phone/common/util/SettingsUtil.java
@@ -20,6 +20,7 @@
 import android.content.SharedPreferences;
 import android.database.Cursor;
 import android.database.sqlite.SQLiteException;
+import android.media.Ringtone;
 import android.media.RingtoneManager;
 import android.net.Uri;
 import android.os.Handler;
@@ -82,17 +83,16 @@
             summary = context.getString(R.string.ringtone_silent);
         } else {
             // Fetch the ringtone title from the media provider
-            try {
-                Cursor cursor = context.getContentResolver().query(ringtoneUri,
-                        new String[] { MediaStore.Audio.Media.TITLE }, null, null, null);
-                if (cursor != null) {
-                    if (cursor.moveToFirst()) {
-                        summary = cursor.getString(0);
+            final Ringtone ringtone = RingtoneManager.getRingtone(context, ringtoneUri);
+            if (ringtone != null) {
+                try {
+                    final String title = ringtone.getTitle(context);
+                    if (!TextUtils.isEmpty(title)) {
+                        summary = title;
                     }
-                    cursor.close();
+                } catch (SQLiteException sqle) {
+                    // Unknown title for the ringtone
                 }
-            } catch (SQLiteException sqle) {
-                // Unknown title for the ringtone
             }
         }
         if (defaultRingtone) {