适用于Android L及之后的版本
1. alps/build/target/product/core_base.mk
添加SIM2 的系统属性ro.config.ringtone_sim2
并置默认来电铃声(ro.config.ringtone
是给SIM1 用):
PRODUCT_PROPERTY_OVERRIDES += \
ro.config.ringtone=Broken_Chord.ogg \
ro.config.ringtone_sim2=Decorative_Pattern.ogg
2. alps/frameworks/base/core/java/android/provider/Settings.java
添加卡2 的铃声属性字段RINGTONE_SIM2
,这个值与前面在common.mk 中定义的属性的
最后一个字段相同, 如果定义为ro.config.ringtone_sim2
, 则RINGTONE_SIM2
为
RINGTONE_SIM2 = "ringtone_sim2"
。
public static final String RINGTONE = "ringtone";
public static final Uri DEFAULT_RINGTONE_URI = getUriFor(RINGTONE);
// bailu modify start
public static final String RINGTONE_SIM2 = "ringtone_sim2";
public static final Uri DEFAULT_RINGTONE_SIM2_URI = getUriFor(RINGTONE_SIM2);
// bailu modify end
3. alps/frameworks/base/media/java/android/media/RingtoneManager.java
public static final int TYPE_RINGTONE = 1;
public static final int TYPE_NOTIFICATION = 2;
public static final int TYPE_ALARM = 4;
public static final int TYPE_VIDEO_CALL = 8;
public static final int TYPE_SIP_CALL = 16;
// bailu modify start
public static final int TYPE_RINGTONE_SIM2 = 32;
public static final String KEY_DEFAULT_RINGTONE_SIM2 = "mtk_audioprofile_default_ringtone_sim2";
// bailu modify end
public static Uri getDefaultRingtoneUri(Context context, int type) {
...
switch (type) {
case TYPE_RINGTONE:
uriString = Settings.System.getString(resolver, KEY_DEFAULT_RINGTONE);
break;
// bailu modify start
case TYPE_RINGTONE_SIM2:
uriString = Settings.System.getString(resolver, KEY_DEFAULT_RINGTONE_SIM2);
break;
// bailu modify end
4. alps/frameworks/base/media/java/android/media/MediaScanner.java
// bailu modify start
private String mDefaultRingtoneSim2Filename;
private boolean mDefaultRingtoneSim2Set;
private static final String RINGTONE_SIM2_SET = "ringtone_sim2_set";
// bailu modify end
core_base.mk
中定义的sim2 铃声的名字读出来: private void setDefaultRingtoneFileNames() {
mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
+ Settings.System.RINGTONE);
// bailu modify start
mDefaultRingtoneSim2Filename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX
+ Settings.System.RINGTONE_SIM2);
// bailu modify end
...
}
private Uri endFile(FileEntry entry, boolean ringtones, boolean notifications,
boolean alarms, boolean music, boolean podcasts)
throws RemoteException {
// bailu modify start
boolean isSim2Ringtone = false;
// bailu modify end
...
if (notifications && ((mWasEmptyPriorToScan && !mDefaultNotificationSet) ||
doesSettingEmpty(NOTIFICATION_SET))) {
...
// bailu modify start
} else if (ringtones && ((mWasEmptyPriorToScan && (!mDefaultRingtoneSet||!mDefaultRingtoneSim2Set)) ||
doesSettingEmpty(RINGTONE_SET)||doesSettingEmpty(RINGTONE_SIM2_SET))) {
if (TextUtils.isEmpty(mDefaultRingtoneFilename) ||
doesPathHaveFilename(entry.mPath, mDefaultRingtoneFilename)) {
needToSetSettings = true;
/// M: Adds log to debug setting ringtones.
Log.v(TAG, "endFile: needToSetRingtone=true.");
} else if(TextUtils.isEmpty(mDefaultRingtoneSim2Filename) ||
doesPathHaveFilename(entry.mPath, mDefaultRingtoneSim2Filename)) {
needToSetSettings = true;
isSim2Ringtone = true;
Log.v(TAG, "endFile: needToSetRingtone=true.sim2 default ringtone");
}
// bailu modify end
} else if (alarms && ((mWasEmptyPriorToScan && !mDefaultAlarmSet) ||
doesSettingEmpty(ALARM_SET))) {
...
}
...
///M: Set ringtone if it wasn't set before. @{
if(needToSetSettings) {
if (notifications && doesSettingEmpty(NOTIFICATION_SET)) {
...
// bailu modify start
} else if (ringtones && (doesSettingEmpty(RINGTONE_SET)||doesSettingEmpty(RINGTONE_SIM2_SET))) {
if (!isSim2Ringtone) {
setSettingIfNotSet(Settings.System.RINGTONE, tableUri, rowId);
setSettingIfNotSet(Settings.System.VIDEO_CALL, tableUri, rowId);
setSettingIfNotSet(Settings.System.SIP_CALL, tableUri, rowId);
setProfileSettings(RingtoneManager.TYPE_RINGTONE, tableUri, rowId);
setProfileSettings(RingtoneManager.TYPE_VIDEO_CALL, tableUri, rowId);
setProfileSettings(RingtoneManager.TYPE_SIP_CALL, tableUri, rowId);
mDefaultRingtoneSet = true;
setSettingFlag(RINGTONE_SET);
Log.v(TAG, "endFile: set ringtone. uri=" + tableUri + ", rowId=" + rowId);
} else {
setSettingIfNotSet(Settings.System.RINGTONE_SIM2, tableUri, rowId);
setProfileSettings(RingtoneManager.TYPE_RINGTONE_SIM2, tableUri, rowId);
mDefaultRingtoneSim2Set = true;
setSettingFlag(RINGTONE_SIM2_SET);
Log.v(TAG, "endFile: set sim2 ringtone. uri=" + tableUri + ", rowId=" + rowId);
}
// bailu modify end
} else if (alarms && doesSettingEmpty(ALARM_SET)) {
...
}
private void setProfileSettings(int type, Uri uri, long rowId) {
if (type == RingtoneManager.TYPE_NOTIFICATION) {
setSettingIfNotSet(RingtoneManager.KEY_DEFAULT_NOTIFICATION, uri, rowId);
} else if (type == RingtoneManager.TYPE_RINGTONE) {
setSettingIfNotSet(RingtoneManager.KEY_DEFAULT_RINGTONE, uri, rowId);
// bailu modify start
} else if (type == RingtoneManager.TYPE_RINGTONE_SIM2) {
setSettingIfNotSet(RingtoneManager.KEY_DEFAULT_RINGTONE_SIM2, uri, rowId);
// bailu modify end
} else if (type == RingtoneManager.TYPE_VIDEO_CALL) {
setSettingIfNotSet(RingtoneManager.KEY_DEFAULT_VIDEO_CALL, uri, rowId);
} else if (type == RingtoneManager.TYPE_SIP_CALL) {
setSettingIfNotSet(RingtoneManager.KEY_DEFAULT_SIP_CALL, uri, rowId);
} else if (type == RingtoneManager.TYPE_ALARM) {
setSettingIfNotSet(RingtoneManager.KEY_DEFAULT_ALARM, uri, rowId);
}
}
5. alps/frameworks/base/media/java/com/mediatek/audioprofile/AudioProfileManager.java
// mDefaultRingtone index
/// bailu modify start
private static final int DEFAULT_RINGTONE_TYPE_CONUT = 5;
private static final int DEFAULT_RINGER_SIM2_INDEX = ProfileSettings.ringer_sim2_stream.ordinal();
// bailu modify end
private void readDefaultRingtones() {
...
// mDefaultRingtone[3] sip ringtone
uriString = Settings.System.getStringForUser(mContentResolver,
AudioProfileManager.KEY_DEFAULT_SIP_CALL,mUserId);
uri = (uriString == null ? null : Uri.parse(uriString));
mDefaultRingtone.set(DEFAULT_SIPCALL_INDEX, uri);
/// bailu modify start
// mDefaultRingtone[4] vioce ringtone sim2
uriString = Settings.System.getString(mContentResolver, AudioProfileManager.KEY_DEFAULT_RINGTONE_SIM2);
uri = (uriString == null ? null : Uri.parse(uriString));
mDefaultRingtone.set(DEFAULT_RINGER_SIM2_INDEX , uri);
// bailu modify end
private void readPersistedSettings(String profileKey, long simId) {
...
name = AudioProfileManager.getStreamUriKey(profileKey,
AudioProfileManager.TYPE_RINGTONE, simId);
/// bailu modify start
Uri voiceCallUri;
int slotId = SubscriptionManager.getSlotId(Integer.parseInt(String.valueOf(simId)));
if (slotId == 1) {
voiceCallUri = getPersistedValue(name, initValues,mDefaultRingtone.get(DEFAULT_RINGER_SIM2_INDEX));
} else {
voiceCallUri = getPersistedValue(name, initValues,mDefaultRingtone.get(DEFAULT_RINGER_INDEX));
}
// bailu modify end
name = AudioProfileManager.getStreamUriKey(profileKey,
AudioProfileManager.TYPE_NOTIFICATION);
...
}
public void reset() {
...
if(SystemProperties.get("ro.mtk_multisim_ringtone").equals("1")){
String outdoorKey = mPredefinedKeys.get(Scenario.OUTDOOR.ordinal());
long subId=SubscriptionManager.getSubId(0)[0];
String uriString =
Settings.System.getString(mContentResolver,
AudioProfileManager.KEY_DEFAULT_RINGTONE);
Uri uri = (uriString == null ? null : Uri.parse(uriString));
persistRingtoneUriToDatabase(generalKey, AudioProfileManager.TYPE_RINGTONE, subId,
uri);
persistRingtoneUriToDatabase(outdoorKey, AudioProfileManager.TYPE_RINGTONE, subId,
uri);
subId=SubscriptionManager.getSubId(1)[0];
// bailu modify start
uriString = Settings.System.getString(mContentResolver,
AudioProfileManager.KEY_DEFAULT_RINGTONE_SIM2);
// bailu modify end
uri = (uriString == null ? null : Uri.parse(uriString));
persistRingtoneUriToDatabase(generalKey, AudioProfileManager.TYPE_RINGTONE, subId,
uri);
persistRingtoneUriToDatabase(outdoorKey, AudioProfileManager.TYPE_RINGTONE, subId,
uri);
}
...
}
6. alps/frameworks/base/media/java/com/mediatek/audioprofile/AudioProfileManager.java
public static final String KEY_DEFAULT_RINGTONE_SIM2 = "mtk_audioprofile_default_ringtone_sim2";
ringer_sim2_stream
public enum ProfileSettings {
ringer_stream, notification_stream, videocall_Stream, sipcall_Stream, ringer_sim2_stream, // bailu modify
ringer_volume, notification_volume, alarm_volume,
vibration_enabled, dtmftone_enabled, soundeffect_enbled, hapticfeedback_enabled,
lockscreensound_enabled
}