Loading core/java/android/preference/RingtonePreference.java +30 −2 Original line number Diff line number Diff line /* * Copyright (C) 2007 The Android Open Source Project * Copyright (C) 2007, 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -49,6 +49,7 @@ public class RingtonePreference extends Preference implements private boolean mShowSilent; private int mRequestCode; private int mSubscriptionID = 0; /* Sub-1 by default */ public RingtonePreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); Loading Loading @@ -92,6 +93,28 @@ public class RingtonePreference extends Preference implements mRingtoneType = type; } /** * 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. * Loading Loading @@ -158,9 +181,14 @@ public class RingtonePreference extends Preference implements ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault); if (mShowDefault) { 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())); } } ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, mShowSilent); ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, mRingtoneType); Loading core/java/android/provider/Settings.java +58 −1 Original line number Diff line number Diff line /* * Copyright (c) 2013 The Linux Foundation. All rights reserved. * Copyright (c) 2013, 2014 The Linux Foundation. All rights reserved. * Not a Contribution. * Copyright (C) 2006 The Android Open Source Project * Loading Loading @@ -2001,6 +2001,30 @@ public final class Settings { */ public static final String RINGTONE = "ringtone"; /** * 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. Loading @@ -2011,6 +2035,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. * Loading media/java/android/media/Ringtone.java +12 −6 Original line number Diff line number Diff line /* * Copyright (C) 2006 The Android Open Source Project * Copyright (C) 2006, 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -115,8 +115,14 @@ public class Ringtone { if (Settings.AUTHORITY.equals(authority)) { if (followSettingsUri) { Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context, 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); title = context .getString(com.android.internal.R.string.ringtone_default_with_actual, Loading Loading @@ -279,9 +285,9 @@ public class Ringtone { private boolean playFallbackRingtone() { if (mAudioManager.getStreamVolume(mStreamType) != 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( Loading media/java/android/media/RingtoneManager.java +106 −3 Original line number Diff line number Diff line /* * Copyright (C) 2007 The Android Open Source Project * Copyright (C) 2007, 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -669,7 +669,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; Loading Loading @@ -701,4 +703,105 @@ public class RingtoneManager { } } /** * 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); } } Loading
core/java/android/preference/RingtonePreference.java +30 −2 Original line number Diff line number Diff line /* * Copyright (C) 2007 The Android Open Source Project * Copyright (C) 2007, 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -49,6 +49,7 @@ public class RingtonePreference extends Preference implements private boolean mShowSilent; private int mRequestCode; private int mSubscriptionID = 0; /* Sub-1 by default */ public RingtonePreference(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); Loading Loading @@ -92,6 +93,28 @@ public class RingtonePreference extends Preference implements mRingtoneType = type; } /** * 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. * Loading Loading @@ -158,9 +181,14 @@ public class RingtonePreference extends Preference implements ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT, mShowDefault); if (mShowDefault) { 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())); } } ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_SHOW_SILENT, mShowSilent); ringtonePickerIntent.putExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, mRingtoneType); Loading
core/java/android/provider/Settings.java +58 −1 Original line number Diff line number Diff line /* * Copyright (c) 2013 The Linux Foundation. All rights reserved. * Copyright (c) 2013, 2014 The Linux Foundation. All rights reserved. * Not a Contribution. * Copyright (C) 2006 The Android Open Source Project * Loading Loading @@ -2001,6 +2001,30 @@ public final class Settings { */ public static final String RINGTONE = "ringtone"; /** * 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. Loading @@ -2011,6 +2035,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. * Loading
media/java/android/media/Ringtone.java +12 −6 Original line number Diff line number Diff line /* * Copyright (C) 2006 The Android Open Source Project * Copyright (C) 2006, 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -115,8 +115,14 @@ public class Ringtone { if (Settings.AUTHORITY.equals(authority)) { if (followSettingsUri) { Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context, 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); title = context .getString(com.android.internal.R.string.ringtone_default_with_actual, Loading Loading @@ -279,9 +285,9 @@ public class Ringtone { private boolean playFallbackRingtone() { if (mAudioManager.getStreamVolume(mStreamType) != 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( Loading
media/java/android/media/RingtoneManager.java +106 −3 Original line number Diff line number Diff line /* * Copyright (C) 2007 The Android Open Source Project * Copyright (C) 2007, 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. Loading Loading @@ -669,7 +669,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; Loading Loading @@ -701,4 +703,105 @@ public class RingtoneManager { } } /** * 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); } }