diff options
-rw-r--r-- | core/java/android/preference/RingtonePreference.java | 30 | ||||
-rw-r--r-- | core/java/android/provider/Settings.java | 57 | ||||
-rw-r--r-- | media/java/android/media/Ringtone.java | 16 | ||||
-rw-r--r-- | media/java/android/media/RingtoneManager.java | 107 |
4 files changed, 202 insertions, 8 deletions
diff --git a/core/java/android/preference/RingtonePreference.java b/core/java/android/preference/RingtonePreference.java index 81c0595..dd260e0 100644 --- a/core/java/android/preference/RingtonePreference.java +++ b/core/java/android/preference/RingtonePreference.java @@ -51,6 +51,7 @@ public class RingtonePreference extends Preference implements private int mDialogStyle; private int mRequestCode; + private int mSubscriptionID = 0; /* Sub-1 by default */ public RingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); @@ -101,6 +102,28 @@ public class RingtonePreference extends Preference implements } /** + * Returns the subscription ID. + * + * @return The current subscription ID. + * @see #setSubId(int) + * @hide + */ + public int getSubId() { + return mSubscriptionID; + } + + /** + * Sets the subscription ID. + * + * @param subId subscription ID. + * @see #getSubId(int) + * @hide + */ + public void setSubId(int subId) { + mSubscriptionID = subId; + } + + /** * Returns whether to a show an item for the default sound/ringtone. * * @return Whether to show an item for the default sound/ringtone. @@ -187,8 +210,13 @@ public class RingtonePreference extends Preference implements ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault); if (mShowDefault) { - ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, + if (getRingtoneType() == RingtoneManager.TYPE_RINGTONE) { + ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, + RingtoneManager.getDefaultRingtoneUriBySubId(getSubId())); + } else { + ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DEFAULT_URI, RingtoneManager.getDefaultUri(getRingtoneType())); + } } if (mDialogStyle != 0) { ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_DIALOG_THEME, diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 28e04e8..a738b83 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -2780,6 +2780,30 @@ public final class Settings { private static final Validator RINGTONE_VALIDATOR = sUriValidator; /** + * Persistent store for the SIM-2 ringtone URI. + * <p> + * If you need to play SIM-2 ringtone at any given time, it is recommended + * you give {@link #DEFAULT_RINGTONE_URI_2} to the media player. It will resolve + * to the set default ringtone at the time of playing. + * + * @see #DEFAULT_RINGTONE_URI_2 + * @hide + */ + public static final String RINGTONE_2 = "ringtone_2"; + + /** + * Persistent store for the SIM-3 ringtone URI. + * <p> + * If you need to play SIM-3 ringtone at any given time, it is recommended + * you give {@link #DEFAULT_RINGTONE_URI_3} to the media player. It will resolve + * to the set default ringtone at the time of playing. + * + * @see #DEFAULT_RINGTONE_URI_3 + * @hide + */ + public static final String RINGTONE_3 = "ringtone_3"; + + /** * A {@link Uri} that will point to the current default ringtone at any * given time. * <p> @@ -2790,6 +2814,39 @@ public final class Settings { public static final Uri DEFAULT_RINGTONE_URI = getUriFor(RINGTONE); /** + * A {@link Uri} that will point to the current SIM-2 ringtone at any + * given time. + * <p> + * If the current default ringtone is in the DRM provider and the caller + * does not have permission, the exception will be a + * FileNotFoundException. + * + * @hide + */ + public static final Uri DEFAULT_RINGTONE_URI_2 = getUriFor(RINGTONE_2); + + /** + * A {@link Uri} that will point to the current SIM-3 ringtone at any + * given time. + * <p> + * If the current default ringtone is in the DRM provider and the caller + * does not have permission, the exception will be a + * FileNotFoundException. + * + * @hide + */ + public static final Uri DEFAULT_RINGTONE_URI_3 = getUriFor(RINGTONE_3); + + /** + * Maximum number of ringtones supported. + * <p> + * Maximum number of ringtones supported by settings. Increment this + * if a new URI needs to be added for ringtone. + * @hide + */ + public static final int MAX_NUM_RINGTONES = 3; + + /** * Persistent store for the system-wide default notification sound. * * @see #RINGTONE 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); + } } |