Loading core/java/android/provider/Settings.java +16 −0 Original line number Diff line number Diff line Loading @@ -2306,6 +2306,22 @@ public final class Settings { */ public static final String ALARM_ALERT = "alarm_alert"; /** * Persistent store for the system-wide default mms notification sound. * * @see #DEFAULT_MMS_NOTIFICATION_URI * @hide */ public static final String MMS_NOTIFICATION_SOUND = "mms_notification"; /** * A {@link Uri} that will point to the current default mms notification * sound at any given time. * * @hide */ public static final Uri DEFAULT_MMS_NOTIFICATION_URI = getUriFor(MMS_NOTIFICATION_SOUND); /** * A {@link Uri} that will point to the current default alarm alert at * any given time. Loading core/res/res/values/customize.xml +22 −0 Original line number Diff line number Diff line Loading @@ -40,4 +40,26 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <!-- custom date format or not --> <bool name="def_custom_dateformat">false</bool> <!-- custom system sound or not --> <bool name="def_custom_sys_sound">false</bool> <!-- Default ringtone for SIM1,the value is ringtone file name. --> <string name="def_custom_sys_ringtone"></string> <!-- Default ringtone for SIM2,the value is ringtone file name. --> <string name="def_custom_sys_ringtone2"></string> <!-- Default ringtone for SIM3,the value is ringtone file name. --> <string name="def_custom_sys_ringtone3"></string> <!-- Default ringtone for system notification,the value is ringtone file name. --> <string name="def_custom_sys_notification"></string> <!-- Default ringtone for mms,the value is ringtone file name. --> <string name="def_custom_sys_mms"></string> <!-- Default ringtone for alarm,the value is ringtone file name. --> <string name="def_custom_sys_alarm"></string> </resources> core/res/res/values/symbols.xml +7 −0 Original line number Diff line number Diff line Loading @@ -249,6 +249,7 @@ <java-symbol type="attr" name="accessibilityFocusedDrawable"/> <java-symbol type="bool" name="def_custom_dateformat" /> <java-symbol type="bool" name="def_custom_sys_sound" /> <java-symbol type="bool" name="action_bar_embed_tabs" /> <java-symbol type="bool" name="action_bar_embed_tabs_pre_jb" /> <java-symbol type="bool" name="action_bar_expanded_action_views_exclusive" /> Loading Loading @@ -457,6 +458,12 @@ <java-symbol type="string" name="def_wifi_wifihotspot_ssid" /> <java-symbol type="string" name="def_wifi_wifihotspot_pass" /> <java-symbol type="string" name="def_wifi_direct_name" /> <java-symbol type="string" name="def_custom_sys_ringtone" /> <java-symbol type="string" name="def_custom_sys_ringtone2" /> <java-symbol type="string" name="def_custom_sys_ringtone3" /> <java-symbol type="string" name="def_custom_sys_notification" /> <java-symbol type="string" name="def_custom_sys_mms" /> <java-symbol type="string" name="def_custom_sys_alarm" /> <java-symbol type="string" name="CfMmi" /> <java-symbol type="string" name="ClipMmi" /> <java-symbol type="string" name="ClirMmi" /> Loading media/java/android/media/MediaScanner.java +94 −22 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Locale; import com.android.internal.R; /** * Internal service helper that no-one should use directly. * Loading Loading @@ -336,8 +338,14 @@ public class MediaScanner private boolean mDefaultAlarmSet; /** The filename for the default sound for the ringer ringtone. */ private String mDefaultRingtoneFilename; /** The filename for the default sound for the ringer ringtone 2. */ private String mDefaultRingtone2Filename; /** The filename for the default sound for the ringer ringtone 3. */ private String mDefaultRingtone3Filename; /** The filename for the default sound for the notification ringtone. */ private String mDefaultNotificationFilename; /** The filename for the default sound for the mms notification ringtone. */ private String mDefaultMmsNotificationFilename; /** The filename for the default sound for the alarm ringtone. */ private String mDefaultAlarmAlertFilename; /** Loading Loading @@ -402,7 +410,14 @@ public class MediaScanner //mClient.testGenreNameConverter(); } private boolean isSoundCustomized() { return mContext.getResources().getBoolean(R.bool.def_custom_sys_sound); } private void setDefaultRingtoneFileNames() { if (isSoundCustomized()) { setCustomizedRingtoneFileNames(); } else { mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.RINGTONE); mDefaultNotificationFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX Loading @@ -410,6 +425,54 @@ public class MediaScanner mDefaultAlarmAlertFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.ALARM_ALERT); } } private void setCustomizedRingtoneFileNames() { if (!TextUtils .isEmpty(mContext.getResources().getString(R.string.def_custom_sys_ringtone))) { mDefaultRingtoneFilename = mContext.getResources().getString( R.string.def_custom_sys_ringtone); } else { mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.RINGTONE); } mDefaultRingtone2Filename = mContext.getResources().getString( R.string.def_custom_sys_ringtone2); if (mDefaultRingtone2Filename == null || TextUtils.isEmpty(mDefaultRingtone2Filename)) { mDefaultRingtone2Filename = mDefaultRingtoneFilename; } mDefaultRingtone3Filename = mContext.getResources().getString( R.string.def_custom_sys_ringtone3); if (mDefaultRingtone3Filename == null || TextUtils.isEmpty(mDefaultRingtone3Filename)) { mDefaultRingtone3Filename = mDefaultRingtoneFilename; } if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_notification))) { mDefaultNotificationFilename = mContext.getResources().getString( R.string.def_custom_sys_notification); } else { mDefaultNotificationFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.NOTIFICATION_SOUND); } mDefaultMmsNotificationFilename = mContext.getResources().getString( R.string.def_custom_sys_mms); if (mDefaultMmsNotificationFilename == null || TextUtils.isEmpty(mDefaultMmsNotificationFilename.trim())) { mDefaultMmsNotificationFilename = mDefaultNotificationFilename; } if (!TextUtils.isEmpty(mContext.getResources().getString(R.string.def_custom_sys_alarm))) { mDefaultAlarmAlertFilename = mContext.getResources().getString( R.string.def_custom_sys_alarm); } else { mDefaultAlarmAlertFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.ALARM_ALERT); } } private final MyMediaScannerClient mClient = new MyMediaScannerClient(); Loading Loading @@ -938,22 +1001,9 @@ public class MediaScanner // notifications, ringtones, and alarms, because the rowId of the inserted file is // needed. if (mWasEmptyPriorToScan) { if (notifications && !mDefaultNotificationSet) { if (TextUtils.isEmpty(mDefaultNotificationFilename) || doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename)) { needToSetSettings = true; } } else if (ringtones && !mDefaultRingtoneSet) { if (TextUtils.isEmpty(mDefaultRingtoneFilename) || doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) { needToSetSettings = true; } } else if (alarms && !mDefaultAlarmSet) { if (TextUtils.isEmpty(mDefaultAlarmAlertFilename) || doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename)) { needToSetSettings = true; } } needToSetSettings = needToSetSettingsForNotification(entry) || needToSetSettingsForRingtone(entry) || needToSetSettingsForAlarm(entry); } // New file, insert it. Loading Loading @@ -1003,6 +1053,10 @@ public class MediaScanner if(needToSetSettings) { if (notifications) { setSettingIfNotSet(Settings.System.NOTIFICATION_SOUND, tableUri, rowId); if (isSoundCustomized()) { setSettingIfNotSet(Settings.System.MMS_NOTIFICATION_SOUND, tableUri, rowId); } mDefaultNotificationSet = true; } else if (ringtones) { // memorize default system ringtone persistently Loading @@ -1026,6 +1080,24 @@ public class MediaScanner return result; } private boolean needToSetSettingsForNotification(FileEntry entry) { return TextUtils.isEmpty(mDefaultNotificationFilename) || doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename) || doesPathHaveFilename(entry.mPath, mDefaultMmsNotificationFilename); } private boolean needToSetSettingsForRingtone(FileEntry entry) { return TextUtils.isEmpty(mDefaultRingtoneFilename) || doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename) || doesPathHaveFilename(entry.mPath, mDefaultRingtone2Filename) || doesPathHaveFilename(entry.mPath, mDefaultRingtone3Filename); } private boolean needToSetSettingsForAlarm(FileEntry entry) { return TextUtils.isEmpty(mDefaultAlarmAlertFilename) || doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename); } private boolean doesPathHaveFilename(String path, String filename) { int pathFilenameStart = path.lastIndexOf(File.separatorChar) + 1; int filenameLength = filename.length(); Loading media/java/android/media/Ringtone.java +114 −0 Original line number Diff line number Diff line /* * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); Loading @@ -17,6 +20,7 @@ package android.media; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; import android.content.res.AssetFileDescriptor; import android.content.res.Resources.NotFoundException; Loading @@ -24,12 +28,16 @@ import android.database.Cursor; import android.net.Uri; import android.os.Binder; import android.os.RemoteException; import android.os.SystemProperties; import android.provider.MediaStore; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; import java.io.IOException; import com.android.internal.R; /** * Ringtone provides a quick method for playing a ringtone, notification, or * other similar types of sounds. Loading @@ -43,6 +51,8 @@ public class Ringtone { private static final String TAG = "Ringtone"; private static final boolean LOGD = true; private static final String DEFAULT_RINGTONE_PROPERTY_PREFIX_RO = "ro.config."; private static final String[] MEDIA_COLUMNS = new String[] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA, Loading Loading @@ -210,6 +220,12 @@ public class Ringtone { // TODO: detect READ_EXTERNAL and specific content provider case, instead of relying on throwing if (isSoundCustomized()) { // instead of restore to default ringtone. restoreRingtoneIfNotExist(Settings.System.RINGTONE); restoreRingtoneIfNotExist(Settings.System.RINGTONE_2); } // try opening uri locally before delegating to remote player mLocalPlayer = new MediaPlayer(); try { Loading Loading @@ -357,4 +373,102 @@ public class Ringtone { void setTitle(String title) { mTitle = title; } private boolean isSoundCustomized() { return mContext.getResources().getBoolean(R.bool.def_custom_sys_sound); } private String getDefaultRingtoneFileName(String settingName) { String defaultRingtoneFilenameGet = SystemProperties .get(DEFAULT_RINGTONE_PROPERTY_PREFIX_RO + settingName); if (Settings.System.RINGTONE.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_ringtone))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_ringtone); } } else if (Settings.System.RINGTONE_2.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_ringtone2))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_ringtone2); } }if (Settings.System.RINGTONE_3.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_ringtone3))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_ringtone3); } } else if (Settings.System.NOTIFICATION_SOUND.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_notification))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_notification); } } else if (Settings.System.MMS_NOTIFICATION_SOUND.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources(). getString(R.string.def_custom_sys_mms))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_mms); } } else if (Settings.System.ALARM_ALERT.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources() .getString(R.string.def_custom_sys_alarm))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_alarm); } } return defaultRingtoneFilenameGet; } /** * When playing ringtone or in Phone ringtone interface, check the * corresponding file get from media with the uri get from setting. If the * file is not exist, restore to default ringtone. */ private void restoreRingtoneIfNotExist(String settingName) { String ringtoneUri = Settings.System.getString(mContext.getContentResolver(), settingName); if (ringtoneUri == null) { return; } ContentResolver res = mContext.getContentResolver(); Cursor c = null; try { c = mContext.getContentResolver().query(Uri.parse(ringtoneUri), new String[] { MediaStore.Audio.Media.TITLE }, null, null, null); // Check whether the corresponding file of Uri is exist. if (!hasData(c)) { c = res.acquireProvider("media").query( null, MediaStore.Audio.Media.INTERNAL_CONTENT_URI, new String[] { "_id" }, MediaStore.Audio.AudioColumns.IS_RINGTONE + "=1 and " + MediaStore.Audio.Media.DISPLAY_NAME + "=?", new String[] { getDefaultRingtoneFileName(settingName) }, null, null); // Set the setting to the Uri of default ringtone. if (hasData(c) && c.moveToFirst()) { int rowId = c.getInt(0); Settings.System.putString( mContext.getContentResolver(), settingName, ContentUris.withAppendedId(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, rowId).toString()); } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in restoreRingtoneIfNotExist()", e); } finally { if (c != null) { c.close(); } } } private boolean hasData(Cursor c) { return c != null && c.getCount() > 0; } } Loading
core/java/android/provider/Settings.java +16 −0 Original line number Diff line number Diff line Loading @@ -2306,6 +2306,22 @@ public final class Settings { */ public static final String ALARM_ALERT = "alarm_alert"; /** * Persistent store for the system-wide default mms notification sound. * * @see #DEFAULT_MMS_NOTIFICATION_URI * @hide */ public static final String MMS_NOTIFICATION_SOUND = "mms_notification"; /** * A {@link Uri} that will point to the current default mms notification * sound at any given time. * * @hide */ public static final Uri DEFAULT_MMS_NOTIFICATION_URI = getUriFor(MMS_NOTIFICATION_SOUND); /** * A {@link Uri} that will point to the current default alarm alert at * any given time. Loading
core/res/res/values/customize.xml +22 −0 Original line number Diff line number Diff line Loading @@ -40,4 +40,26 @@ IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <!-- custom date format or not --> <bool name="def_custom_dateformat">false</bool> <!-- custom system sound or not --> <bool name="def_custom_sys_sound">false</bool> <!-- Default ringtone for SIM1,the value is ringtone file name. --> <string name="def_custom_sys_ringtone"></string> <!-- Default ringtone for SIM2,the value is ringtone file name. --> <string name="def_custom_sys_ringtone2"></string> <!-- Default ringtone for SIM3,the value is ringtone file name. --> <string name="def_custom_sys_ringtone3"></string> <!-- Default ringtone for system notification,the value is ringtone file name. --> <string name="def_custom_sys_notification"></string> <!-- Default ringtone for mms,the value is ringtone file name. --> <string name="def_custom_sys_mms"></string> <!-- Default ringtone for alarm,the value is ringtone file name. --> <string name="def_custom_sys_alarm"></string> </resources>
core/res/res/values/symbols.xml +7 −0 Original line number Diff line number Diff line Loading @@ -249,6 +249,7 @@ <java-symbol type="attr" name="accessibilityFocusedDrawable"/> <java-symbol type="bool" name="def_custom_dateformat" /> <java-symbol type="bool" name="def_custom_sys_sound" /> <java-symbol type="bool" name="action_bar_embed_tabs" /> <java-symbol type="bool" name="action_bar_embed_tabs_pre_jb" /> <java-symbol type="bool" name="action_bar_expanded_action_views_exclusive" /> Loading Loading @@ -457,6 +458,12 @@ <java-symbol type="string" name="def_wifi_wifihotspot_ssid" /> <java-symbol type="string" name="def_wifi_wifihotspot_pass" /> <java-symbol type="string" name="def_wifi_direct_name" /> <java-symbol type="string" name="def_custom_sys_ringtone" /> <java-symbol type="string" name="def_custom_sys_ringtone2" /> <java-symbol type="string" name="def_custom_sys_ringtone3" /> <java-symbol type="string" name="def_custom_sys_notification" /> <java-symbol type="string" name="def_custom_sys_mms" /> <java-symbol type="string" name="def_custom_sys_alarm" /> <java-symbol type="string" name="CfMmi" /> <java-symbol type="string" name="ClipMmi" /> <java-symbol type="string" name="ClirMmi" /> Loading
media/java/android/media/MediaScanner.java +94 −22 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ import java.util.HashSet; import java.util.Iterator; import java.util.Locale; import com.android.internal.R; /** * Internal service helper that no-one should use directly. * Loading Loading @@ -336,8 +338,14 @@ public class MediaScanner private boolean mDefaultAlarmSet; /** The filename for the default sound for the ringer ringtone. */ private String mDefaultRingtoneFilename; /** The filename for the default sound for the ringer ringtone 2. */ private String mDefaultRingtone2Filename; /** The filename for the default sound for the ringer ringtone 3. */ private String mDefaultRingtone3Filename; /** The filename for the default sound for the notification ringtone. */ private String mDefaultNotificationFilename; /** The filename for the default sound for the mms notification ringtone. */ private String mDefaultMmsNotificationFilename; /** The filename for the default sound for the alarm ringtone. */ private String mDefaultAlarmAlertFilename; /** Loading Loading @@ -402,7 +410,14 @@ public class MediaScanner //mClient.testGenreNameConverter(); } private boolean isSoundCustomized() { return mContext.getResources().getBoolean(R.bool.def_custom_sys_sound); } private void setDefaultRingtoneFileNames() { if (isSoundCustomized()) { setCustomizedRingtoneFileNames(); } else { mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.RINGTONE); mDefaultNotificationFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX Loading @@ -410,6 +425,54 @@ public class MediaScanner mDefaultAlarmAlertFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.ALARM_ALERT); } } private void setCustomizedRingtoneFileNames() { if (!TextUtils .isEmpty(mContext.getResources().getString(R.string.def_custom_sys_ringtone))) { mDefaultRingtoneFilename = mContext.getResources().getString( R.string.def_custom_sys_ringtone); } else { mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.RINGTONE); } mDefaultRingtone2Filename = mContext.getResources().getString( R.string.def_custom_sys_ringtone2); if (mDefaultRingtone2Filename == null || TextUtils.isEmpty(mDefaultRingtone2Filename)) { mDefaultRingtone2Filename = mDefaultRingtoneFilename; } mDefaultRingtone3Filename = mContext.getResources().getString( R.string.def_custom_sys_ringtone3); if (mDefaultRingtone3Filename == null || TextUtils.isEmpty(mDefaultRingtone3Filename)) { mDefaultRingtone3Filename = mDefaultRingtoneFilename; } if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_notification))) { mDefaultNotificationFilename = mContext.getResources().getString( R.string.def_custom_sys_notification); } else { mDefaultNotificationFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.NOTIFICATION_SOUND); } mDefaultMmsNotificationFilename = mContext.getResources().getString( R.string.def_custom_sys_mms); if (mDefaultMmsNotificationFilename == null || TextUtils.isEmpty(mDefaultMmsNotificationFilename.trim())) { mDefaultMmsNotificationFilename = mDefaultNotificationFilename; } if (!TextUtils.isEmpty(mContext.getResources().getString(R.string.def_custom_sys_alarm))) { mDefaultAlarmAlertFilename = mContext.getResources().getString( R.string.def_custom_sys_alarm); } else { mDefaultAlarmAlertFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.ALARM_ALERT); } } private final MyMediaScannerClient mClient = new MyMediaScannerClient(); Loading Loading @@ -938,22 +1001,9 @@ public class MediaScanner // notifications, ringtones, and alarms, because the rowId of the inserted file is // needed. if (mWasEmptyPriorToScan) { if (notifications && !mDefaultNotificationSet) { if (TextUtils.isEmpty(mDefaultNotificationFilename) || doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename)) { needToSetSettings = true; } } else if (ringtones && !mDefaultRingtoneSet) { if (TextUtils.isEmpty(mDefaultRingtoneFilename) || doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) { needToSetSettings = true; } } else if (alarms && !mDefaultAlarmSet) { if (TextUtils.isEmpty(mDefaultAlarmAlertFilename) || doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename)) { needToSetSettings = true; } } needToSetSettings = needToSetSettingsForNotification(entry) || needToSetSettingsForRingtone(entry) || needToSetSettingsForAlarm(entry); } // New file, insert it. Loading Loading @@ -1003,6 +1053,10 @@ public class MediaScanner if(needToSetSettings) { if (notifications) { setSettingIfNotSet(Settings.System.NOTIFICATION_SOUND, tableUri, rowId); if (isSoundCustomized()) { setSettingIfNotSet(Settings.System.MMS_NOTIFICATION_SOUND, tableUri, rowId); } mDefaultNotificationSet = true; } else if (ringtones) { // memorize default system ringtone persistently Loading @@ -1026,6 +1080,24 @@ public class MediaScanner return result; } private boolean needToSetSettingsForNotification(FileEntry entry) { return TextUtils.isEmpty(mDefaultNotificationFilename) || doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename) || doesPathHaveFilename(entry.mPath, mDefaultMmsNotificationFilename); } private boolean needToSetSettingsForRingtone(FileEntry entry) { return TextUtils.isEmpty(mDefaultRingtoneFilename) || doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename) || doesPathHaveFilename(entry.mPath, mDefaultRingtone2Filename) || doesPathHaveFilename(entry.mPath, mDefaultRingtone3Filename); } private boolean needToSetSettingsForAlarm(FileEntry entry) { return TextUtils.isEmpty(mDefaultAlarmAlertFilename) || doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename); } private boolean doesPathHaveFilename(String path, String filename) { int pathFilenameStart = path.lastIndexOf(File.separatorChar) + 1; int filenameLength = filename.length(); Loading
media/java/android/media/Ringtone.java +114 −0 Original line number Diff line number Diff line /* * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved. * Not a Contribution. * * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); Loading @@ -17,6 +20,7 @@ package android.media; import android.content.ContentResolver; import android.content.ContentUris; import android.content.Context; import android.content.res.AssetFileDescriptor; import android.content.res.Resources.NotFoundException; Loading @@ -24,12 +28,16 @@ import android.database.Cursor; import android.net.Uri; import android.os.Binder; import android.os.RemoteException; import android.os.SystemProperties; import android.provider.MediaStore; import android.provider.Settings; import android.text.TextUtils; import android.util.Log; import java.io.IOException; import com.android.internal.R; /** * Ringtone provides a quick method for playing a ringtone, notification, or * other similar types of sounds. Loading @@ -43,6 +51,8 @@ public class Ringtone { private static final String TAG = "Ringtone"; private static final boolean LOGD = true; private static final String DEFAULT_RINGTONE_PROPERTY_PREFIX_RO = "ro.config."; private static final String[] MEDIA_COLUMNS = new String[] { MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA, Loading Loading @@ -210,6 +220,12 @@ public class Ringtone { // TODO: detect READ_EXTERNAL and specific content provider case, instead of relying on throwing if (isSoundCustomized()) { // instead of restore to default ringtone. restoreRingtoneIfNotExist(Settings.System.RINGTONE); restoreRingtoneIfNotExist(Settings.System.RINGTONE_2); } // try opening uri locally before delegating to remote player mLocalPlayer = new MediaPlayer(); try { Loading Loading @@ -357,4 +373,102 @@ public class Ringtone { void setTitle(String title) { mTitle = title; } private boolean isSoundCustomized() { return mContext.getResources().getBoolean(R.bool.def_custom_sys_sound); } private String getDefaultRingtoneFileName(String settingName) { String defaultRingtoneFilenameGet = SystemProperties .get(DEFAULT_RINGTONE_PROPERTY_PREFIX_RO + settingName); if (Settings.System.RINGTONE.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_ringtone))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_ringtone); } } else if (Settings.System.RINGTONE_2.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_ringtone2))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_ringtone2); } }if (Settings.System.RINGTONE_3.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_ringtone3))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_ringtone3); } } else if (Settings.System.NOTIFICATION_SOUND.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources().getString( R.string.def_custom_sys_notification))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_notification); } } else if (Settings.System.MMS_NOTIFICATION_SOUND.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources(). getString(R.string.def_custom_sys_mms))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_mms); } } else if (Settings.System.ALARM_ALERT.equals(settingName)) { if (!TextUtils.isEmpty(mContext.getResources() .getString(R.string.def_custom_sys_alarm))) { defaultRingtoneFilenameGet = mContext.getResources().getString( R.string.def_custom_sys_alarm); } } return defaultRingtoneFilenameGet; } /** * When playing ringtone or in Phone ringtone interface, check the * corresponding file get from media with the uri get from setting. If the * file is not exist, restore to default ringtone. */ private void restoreRingtoneIfNotExist(String settingName) { String ringtoneUri = Settings.System.getString(mContext.getContentResolver(), settingName); if (ringtoneUri == null) { return; } ContentResolver res = mContext.getContentResolver(); Cursor c = null; try { c = mContext.getContentResolver().query(Uri.parse(ringtoneUri), new String[] { MediaStore.Audio.Media.TITLE }, null, null, null); // Check whether the corresponding file of Uri is exist. if (!hasData(c)) { c = res.acquireProvider("media").query( null, MediaStore.Audio.Media.INTERNAL_CONTENT_URI, new String[] { "_id" }, MediaStore.Audio.AudioColumns.IS_RINGTONE + "=1 and " + MediaStore.Audio.Media.DISPLAY_NAME + "=?", new String[] { getDefaultRingtoneFileName(settingName) }, null, null); // Set the setting to the Uri of default ringtone. if (hasData(c) && c.moveToFirst()) { int rowId = c.getInt(0); Settings.System.putString( mContext.getContentResolver(), settingName, ContentUris.withAppendedId(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, rowId).toString()); } } } catch (RemoteException e) { Log.e(TAG, "RemoteException in restoreRingtoneIfNotExist()", e); } finally { if (c != null) { c.close(); } } } private boolean hasData(Cursor c) { return c != null && c.getCount() > 0; } }