summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2014-11-12 12:16:57 -0800
committerGerrit Code Review <gerrit@cyanogenmod.org>2016-05-14 15:58:49 -0700
commit58ae12f7a030a62e77dd4f541e985ed49ec717cc (patch)
treebf6870b5fd851bcf1a761bce7bd9251a3e551efc /media
parent2d7713afa5f5d34d107b88a15ac52fd8bb20afe3 (diff)
downloadframeworks_base-58ae12f7a030a62e77dd4f541e985ed49ec717cc.zip
frameworks_base-58ae12f7a030a62e77dd4f541e985ed49ec717cc.tar.gz
frameworks_base-58ae12f7a030a62e77dd4f541e985ed49ec717cc.tar.bz2
MediaScanner: Add support for default ringtones per sim
Ticket: CYNGNOS-314, CYNGNOS-2654 Change-Id: I1ed112a38d2b3676e31a78eb70ea0e16a3957b02
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/MediaScanner.java79
1 files changed, 66 insertions, 13 deletions
diff --git a/media/java/android/media/MediaScanner.java b/media/java/android/media/MediaScanner.java
index da1484c..9264bc0 100644
--- a/media/java/android/media/MediaScanner.java
+++ b/media/java/android/media/MediaScanner.java
@@ -48,6 +48,7 @@ import android.sax.ElementListener;
import android.sax.RootElement;
import android.system.ErrnoException;
import android.system.Os;
+import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.util.Log;
import android.util.Xml;
@@ -329,23 +330,26 @@ public class MediaScanner
// old thumbnail files
private int mOriginalCount;
/** Whether the scanner has set a default sound for the ringer ringtone. */
- private boolean mDefaultRingtoneSet;
+ private boolean[] mDefaultRingtonesSet;
/** Whether the scanner has set a default sound for the notification ringtone. */
private boolean mDefaultNotificationSet;
/** Whether the scanner has set a default sound for the alarm ringtone. */
private boolean mDefaultAlarmSet;
- /** The filename for the default sound for the ringer ringtone. */
- private String mDefaultRingtoneFilename;
+ /** The filenames for the default sound for the ringer ringtone. */
+ private String[] mDefaultRingtoneFilenames;
/** The filename for the default sound for the notification ringtone. */
private String mDefaultNotificationFilename;
/** The filename for the default sound for the alarm ringtone. */
private String mDefaultAlarmAlertFilename;
+ /** The number of phones in the system */
+ private int mPhoneCount = -1;
/**
* The prefix for system properties that define the default sound for
* ringtones. Concatenate the name of the setting from Settings
* to get the full system property.
*/
private static final String DEFAULT_RINGTONE_PROPERTY_PREFIX = "ro.config.";
+ private static final int DEFAULT_SIM_INDEX = 0;
// set to true if file path comparisons should be case insensitive.
// this should be set when scanning files on a case insensitive file system.
@@ -408,8 +412,21 @@ public class MediaScanner
}
private void setDefaultRingtoneFileNames() {
- mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
+ String defaultAllSimRingtone = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
+ Settings.System.RINGTONE);
+
+ mPhoneCount = TelephonyManager.getDefault().getPhoneCount();
+ mDefaultRingtoneFilenames = new String[mPhoneCount];
+ mDefaultRingtonesSet = new boolean[mPhoneCount];
+
+ mDefaultRingtoneFilenames[DEFAULT_SIM_INDEX] = defaultAllSimRingtone;
+
+ for (int i = (DEFAULT_SIM_INDEX + 1); i < mPhoneCount; i++) {
+ String defaultIterSimRingtone = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
+ + Settings.System.RINGTONE + "_" + (i + 1), defaultAllSimRingtone);
+ mDefaultRingtoneFilenames[i] = defaultIterSimRingtone;
+ }
+
mDefaultNotificationFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
+ Settings.System.NOTIFICATION_SOUND);
mDefaultAlarmAlertFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
@@ -550,8 +567,9 @@ public class MediaScanner
if (entry.mPath != null &&
((!mDefaultNotificationSet &&
doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename))
- || (!mDefaultRingtoneSet &&
- doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename))
+ || (mPhoneCount > 0 && !mDefaultRingtonesSet[(mPhoneCount-1)] &&
+ doesPathHaveFilename(entry.mPath,
+ mDefaultRingtoneFilenames[(mPhoneCount-1)]))
|| (!mDefaultAlarmSet &&
doesPathHaveFilename(entry.mPath, mDefaultAlarmAlertFilename)))) {
Log.w(TAG, "forcing rescan of " + entry.mPath +
@@ -953,10 +971,14 @@ public class MediaScanner
doesPathHaveFilename(entry.mPath, mDefaultNotificationFilename)) {
needToSetSettings = true;
}
- } else if (ringtones && !mDefaultRingtoneSet) {
- if (TextUtils.isEmpty(mDefaultRingtoneFilename) ||
- doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) {
- needToSetSettings = true;
+ } else if (ringtones && !ringtoneDefaultsSet()) {
+ for (int i = 0; i < mPhoneCount; i++) {
+ // Check if ringtone matches default ringtone
+ if (TextUtils.isEmpty(mDefaultRingtoneFilenames[i]) ||
+ doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilenames[i])) {
+ needToSetSettings = true;
+ break;
+ }
}
} else if (alarms && !mDefaultAlarmSet) {
if (TextUtils.isEmpty(mDefaultAlarmAlertFilename) ||
@@ -1025,8 +1047,27 @@ public class MediaScanner
setSettingIfNotSet(Settings.System.NOTIFICATION_SOUND, tableUri, rowId);
mDefaultNotificationSet = true;
} else if (ringtones) {
- setSettingIfNotSet(Settings.System.RINGTONE, tableUri, rowId);
- mDefaultRingtoneSet = true;
+ String uri = null;
+ for (int i = 0; i < mPhoneCount; i++) {
+ if (mDefaultRingtonesSet[i]) {
+ continue;
+ }
+ // Check if ringtone matches default ringtone
+ if (!TextUtils.isEmpty(mDefaultRingtoneFilenames[i]) &&
+ !doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilenames[i])) {
+ continue;
+ }
+ if (i == DEFAULT_SIM_INDEX) {
+ uri = Settings.System.RINGTONE;
+ } else {
+ uri = Settings.System.RINGTONE + "_" + (i + 1);
+ }
+
+ // Set default ringtone
+ setSettingIfNotSet(uri, tableUri, rowId);
+
+ mDefaultRingtonesSet[i] = true;
+ }
} else if (alarms) {
setSettingIfNotSet(Settings.System.ALARM_ALERT, tableUri, rowId);
mDefaultAlarmSet = true;
@@ -1036,6 +1077,15 @@ public class MediaScanner
return result;
}
+ private boolean ringtoneDefaultsSet() {
+ for (boolean defaultSet : mDefaultRingtonesSet) {
+ if (!defaultSet) {
+ return false;
+ }
+ }
+ return true;
+ }
+
private boolean doesPathHaveFilename(String path, String filename) {
int pathFilenameStart = path.lastIndexOf(File.separatorChar) + 1;
int filenameLength = filename.length();
@@ -1118,7 +1168,10 @@ public class MediaScanner
selectionArgs = new String[] { "" };
}
- mDefaultRingtoneSet = wasSettingAlreadySet(Settings.System.RINGTONE);
+ mDefaultRingtonesSet[0] = wasSettingAlreadySet(Settings.System.RINGTONE);
+ for (int i=1; i< mPhoneCount; i++) {
+ mDefaultRingtonesSet[i] = wasSettingAlreadySet(Settings.System.RINGTONE + "_" + i);
+ }
mDefaultNotificationSet = wasSettingAlreadySet(Settings.System.NOTIFICATION_SOUND);
mDefaultAlarmSet = wasSettingAlreadySet(Settings.System.ALARM_ALERT);