From eb91bd8fe34e01cef6e7a746c3ee677dff91316d Mon Sep 17 00:00:00 2001 From: Karthik Reddy Katta Date: Thu, 6 Mar 2014 16:27:57 +0530 Subject: Ringtone: Add support for selection of phone ringtone for SIM-2. -Issue: "The process android.process.media has stopped" pop up is displayed when ringtone for SIM-2 is selected. -Rootcause: There is no type and URI defined for SIM-2 ringtone in the RingtoneManager. This is leading to SQl exception when executing a selection query. -Fix: Add URIs for the SIM-2 and SIM-3 ringtones. Define interfaces to return them to app side based on subscription ID. TICKET: CYNGNOS-1589 CRs-Fixed: 612945 Change-Id: If68c2d008dd86d2b55d3fb7f5667bbadc238d0b3 --- media/java/android/media/Ringtone.java | 16 ++-- media/java/android/media/RingtoneManager.java | 107 +++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 7 deletions(-) (limited to 'media') diff --git a/media/java/android/media/Ringtone.java b/media/java/android/media/Ringtone.java index c2bcd93..2f96d1f 100644 --- a/media/java/android/media/Ringtone.java +++ b/media/java/android/media/Ringtone.java @@ -214,8 +214,14 @@ public class Ringtone { if (Settings.AUTHORITY.equals(authority)) { if (followSettingsUri) { - Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context, - RingtoneManager.getDefaultType(uri)); + Uri actualUri; + if (RingtoneManager.getDefaultType(uri) == RingtoneManager.TYPE_RINGTONE) { + actualUri = RingtoneManager.getActualRingtoneUriBySubId(context, + RingtoneManager.getDefaultRingtoneSubIdByUri(uri)); + } else { + actualUri = RingtoneManager.getActualDefaultRingtoneUri(context, + RingtoneManager.getDefaultType(uri)); + } String actualTitle = getTitle( context, actualUri, false /*followSettingsUri*/, allowRemote); title = context @@ -412,9 +418,9 @@ public class Ringtone { private boolean playFallbackRingtone() { if (mAudioManager.getStreamVolume(AudioAttributes.toLegacyStreamType(mAudioAttributes)) != 0) { - int ringtoneType = RingtoneManager.getDefaultType(mUri); - if (ringtoneType == -1 || - RingtoneManager.getActualDefaultRingtoneUri(mContext, ringtoneType) != null) { + int subId = RingtoneManager.getDefaultRingtoneSubIdByUri(mUri); + if (subId != -1 && + RingtoneManager.getActualRingtoneUriBySubId(mContext, subId) != null) { // Default ringtone, try fallback ringtone. try { AssetFileDescriptor afd = mContext.getResources().openRawResourceFd( diff --git a/media/java/android/media/RingtoneManager.java b/media/java/android/media/RingtoneManager.java index 01cae5c..fe4c91b 100644 --- a/media/java/android/media/RingtoneManager.java +++ b/media/java/android/media/RingtoneManager.java @@ -700,7 +700,9 @@ public class RingtoneManager { public static int getDefaultType(Uri defaultRingtoneUri) { if (defaultRingtoneUri == null) { return -1; - } else if (defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI)) { + } else if (defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI) || + defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI_2) || + defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI_3)) { return TYPE_RINGTONE; } else if (defaultRingtoneUri.equals(Settings.System.DEFAULT_NOTIFICATION_URI)) { return TYPE_NOTIFICATION; @@ -731,5 +733,106 @@ public class RingtoneManager { return null; } } - + + /** + * Returns the subscription ID of {@link Uri}. + * + * @param defaultRingtoneUri The default {@link Uri}. For example, + * {@link System#DEFAULT_RINGTONE_URI}, + * {@link System#DEFAULT_RINGTONE_URI_2}, or + * {@link System#DEFAULT_RINGTONE_URI_3}. + * @return The Subscription ID of the defaultRingtoneUri, or -1. + * @hide + */ + public static int getDefaultRingtoneSubIdByUri(Uri defaultRingtoneUri) { + if (defaultRingtoneUri == null) { + return -1; + } + /** + * URI is encoded as below: + * DEFAULT_RINGTONE_URI: content://settings/system/ringtone + * DEFAULT_RINGTONE_URI_2: content://settings/system/ringtone_2 + * DEFAULT_RINGTONE_URI_3: content://settings/system/ringtone_3 + */ + if (defaultRingtoneUri.equals(Settings.System.DEFAULT_RINGTONE_URI)) { + return 0; /* Sub-1 */ + } + final String uriString = defaultRingtoneUri.toString(); + int parsedSubId = -1; + if (uriString.startsWith(Settings.System.DEFAULT_RINGTONE_URI.toString())) { + parsedSubId = Integer.parseInt(uriString.substring(uriString.lastIndexOf("_") + 1)); + if ((parsedSubId > 0 && parsedSubId <= Settings.System.MAX_NUM_RINGTONES)) { + return parsedSubId - 1; + } + } + return -1; + } + + /** + * Gets the actual default sound's {@link Uri}. This will give the actual + * sound {@link Uri}, instead of using this, most clients can use + * {@link System#DEFAULT_RINGTONE_URI}. + * + * @param subId The Subscription ID. + * @return A {@link Uri} pointing to the default sound for the sound type. + * @hide + */ + public static Uri getDefaultRingtoneUriBySubId(int subId) { + if (!(subId >= 0 && subId < Settings.System.MAX_NUM_RINGTONES)) { + return null; + } + if (subId == 0) { + return Settings.System.DEFAULT_RINGTONE_URI; + } else { + final String uriString = + Settings.System.DEFAULT_RINGTONE_URI.toString() + "_" + (subId + 1); + return Uri.parse(uriString); + } + } + + /** + * Gets the current default sound's {@link Uri}. This will give the actual + * sound {@link Uri}, instead of using this, most clients can use + * {@link System#DEFAULT_RINGTONE_URI}. + * + * @param context A context used for querying. + * @param subId The Subscription ID. + * @return A {@link Uri} pointing to the default sound for the sound type. + * @hide + */ + public static Uri getActualRingtoneUriBySubId(Context context, int subId) { + if (!(subId >= 0 && subId < Settings.System.MAX_NUM_RINGTONES)) { + return null; + } + String setting; + if (subId == 0) { + setting = Settings.System.RINGTONE; + } else { + setting = Settings.System.RINGTONE + "_" + (subId + 1); + } + final String uriString = Settings.System.getString(context.getContentResolver(), setting); + return uriString != null ? Uri.parse(uriString) : null; + } + + /** + * Sets the {@link Uri} of the default sound for a given sound type. + * + * @param context A context used for querying. + * @param subId The Subscription ID. + * @param ringtoneUri A {@link Uri} pointing to the default sound to set. + * @hide + */ + public static void setActualRingtoneUriBySubId(Context context, int subId, Uri ringtoneUri) { + if (!(subId >= 0 && subId < Settings.System.MAX_NUM_RINGTONES)) { + return; + } + String setting; + if (subId == 0) { + setting = Settings.System.RINGTONE; + } else { + setting = Settings.System.RINGTONE + "_" + (subId + 1); + } + Settings.System.putString(context.getContentResolver(), setting, + ringtoneUri != null ? ringtoneUri.toString() : null); + } } -- cgit v1.1