[DESCRIPTION]
KK版本不需要patch,直接支持双卡铃声设置;
L版本需要合入双卡铃声patch,由我司提供;
但sim1和sim2的默认铃声都是一样的,如何分开设置sim1,sim2的默认铃声?
[SOLUTION]
1,
KK版本:alps\build\target\product\core.mk
L版本:alps\build\target\product\full_base.mk: 设置系统属性“ro.config.ringtone_sim2”(原来的ro.config.ringtone给卡1用): PRODUCT_PROPERTY_OVERRIDES := \ ro.config.notification_sound=Proxima.ogg \ ro.config.alarm_alert=Alarm_Classic.ogg \ ro.config.ringtone=Backroad.ogg\
ro.config.ringtone_sim2=Carina.ogg
2,frameworks/base/core/java/android/provider/Settings.java中: 添加卡2的铃声属性字段RINGTONE_SIM2,这个值与前面在core.mk中定义的属性的最后一个字段相同,如您定义为“ro.config.ringtone_sim2”, 则RINGTONE_SIM2为“RINGTONE_SIM2 = "ringtone_sim2",假设您定义的属性为“ro.config.ringtone_sim_id_2” 则对应的RINGTONE_SIM2="ringtone_sim_id_2",参考标有//add this line为添加的部分: public static final String RINGTONE = "ringtone"; public static final String RINGTONE_SIM2 = "ringtone_sim2";//add this line public static final Uri DEFAULT_RINGTONE_URI = getUriFor(RINGTONE); public static final Uri DEFAULT_RINGTONE_SIM2_URI = getUriFor(RINGTONE_SIM2);//add this line
3,alps\frameworks\base\media\java\android\media\RintoneManager.java: 1),添加SIM2的type,参考//add this line为添加的部分: public static final int TYPE_VIDEO_CALL = 8; public static final int TYPE_SIP_CALL = 16; public static final int TYPE_RINGTONE_SIM2 = 32;//add this line public static final String KEY_DEFAULT_RINGTONE_SIM2 = "mtk_audioprofile_default_ringtone_sim2";//add this line
2) 返回获取的sim2的uri,参考//add this line为添加的部分: public static Uri getDefaultRingtoneUri(Context context, int type) { ... switch (type) { case TYPE_RINGTONE: uriString = Settings.System.getString(resolver, KEY_DEFAULT_RINGTONE); break; case TYPE_RINGTONE_SIM2://add this line uriString = Settings.System.getString(resolver, KEY_DEFAULT_RINGTONE_SIM2);//add this line break;//add this line 4,alps\frameworks\base\media\java\android\media\MediaScanner.java中: 1),添加读取到的卡2 的默认铃声相关定义: private String mDefaultRingtoneSim2Filename; private boolean mDefaultRingtoneSim2Set; private static final String RINGTONE_SIM2_SET = "ringtone_sim2_set";
2),将core.mk中定义的sim2 铃声的名字读出来,参考//add this line为添加的部分: private void setDefaultRingtoneFileNames() { mDefaultRingtoneFilename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.RINGTONE); mDefaultRingtoneSim2Filename = SystemProperties.get(DEFAULT_RINGTONE_PROPERTY_PREFIX + Settings.System.RINGTONE_SIM2);//add this line ... } 3),添加isSim2Ringtone来区别设置的是sim1还是sim2,然后将扫描到的文件名和上面读到的sim2默认铃声文件名对比,如果是sim2 的ringtone,则设置sim2默认值。参考注有"//add this line"或" //start modify"和"//end modify"包含的地方(这里极易合入错误,注意原来的if(ringtone&& ……)是被替换修改的,要删掉): private Uri endFile(FileEntry entry, boolean ringtones, boolean notifications, boolean alarms, boolean music, boolean podcasts){ boolean isSim2Ringtone = false; //add this line ..... if (notifications &&((mWasEmptyPriorToScan && !mDefaultNotificationSet) || doesSettingEmpty(NOTIFICATION_SET))) { .... //start modify } 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. Xlog.v(TAG, "endFile: needToSetRingtone=true."); } else if(TextUtils.isEmpty(mDefaultRingtoneSim2Filename) || doesPathHaveFilename(entry.mPath, mDefaultRingtoneSim2Filename)) { needToSetSettings = true; isSim2Ringtone = true; Xlog.v(TAG, "endFile: needToSetRingtone=true.sim2 default ringtone"); } //end modify } else if (alarms && ((mWasEmptyPriorToScan && !mDefaultAlarmSet) || doesSettingEmpty(ALARM_SET))) { ... } ... if(needToSetSettings) { if (notifications && doesSettingEmpty(NOTIFICATION_SET)) { ..... //start modify } 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); Xlog.v(TAG, "endFile: set ringtone. uri=" + tableUri + ", rowId=" + rowId); } else { setSettingIfNotSet(SSettings.System.RINGTONE_SIM2, tableUri, rowId); setProfileSettings(RingtoneManager.TYPE_RINGTONE_SIM2, tableUri, rowId); mDefaultRingtoneSim2Set = true; setSettingFlag(RINGTONE_SIM2_SET); Xlog.v(TAG, "endFile: set sim2 ringtone. uri=" + tableUri + ", rowId=" + rowId); } //end modify }else if (alarms && doesSettingEmpty(ALARM_SET)) { .... }
4),添加设置sim2铃声,参考//start modify 和//end modify的地方:
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);
//start modify } else if(type ==RingtoneManager.TYPE_RINGTONE_SIM2){ setSettingIfNotSet(RingtoneManager.KEY_DEFAULT_RINGTONE_SIM2, uri, rowId); //end modify } 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
L版本:alps\frameworks\base\services\core\java\com\mediatek\audioprofile\AudioProfileService.java:
KK版本: alps\mediatek\frameworks\base\media\audio\java\com\mediatek\audioprofile\AudioProfileService.java:
1)定义给sim2 ringtone用的index,同时修改ringtone type的个数,由原来的4改成5,参考注有“//modify this line”和“//add this line”的地方
// mDefaultRingtone index
private static final int DEFAULT_RINGTONE_TYPE_CONUT = 5;//modify this line
private static final int DEFAULT_RINGER_INDEX = ProfileSettings.ringer_stream.ordinal();
private static final int DEFAULT_NOTIFICATION_INDEX = ProfileSettings.notification_stream.ordinal();
private static final int DEFAULT_VIDEOCALL_INDEX = ProfileSettings.videocall_Stream.ordinal();
private static final int DEFAULT_SIPCALL_INDEX = ProfileSettings.sipcall_Stream.ordinal();
private static final int DEFAULT_RINGER_SIM2_INDEX = ProfileSettings.ringer_sim2_stream.ordinal();//add this line
2)情景模式读铃声默认值时,添加读取sim2的默认值,参考//start modify和//end modify之间的修改:
private void readDefaultRingtones() {
....
// mDefaultRingtone[3] sip ringtone
uriString = Settings.System.getString(mContentResolver, AudioProfileManager.KEY_DEFAULT_SIP_CALL);
uri = (uriString == null ? null : Uri.parse(uriString));
mDefaultRingtone.set(DEFAULT_SIPCALL_INDEX, uri);
//start modify // 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); //end modify 3)
L版本:import android.telephony.SubscriptionManager;
KK版本:import android.provider.Telephony.SIMInfo;
private void readPersistedSettings(String profileKey, long simId) {
...
//start modify Uri voiceCallUri;
L版本: int slotId = SubscriptionManager.getSlotId(simId);//add this line
KK版本:
int slotId = SIMInfo.getSlotById(mContext, (int)simId);//add this line if(slotId ==1){ voiceCallUri = getPersistedValue(name, initValues,mDefaultRingtone.get(DEFAULT_RINGER_SIM2_INDEX));}else{ voiceCallUri = getPersistedValue(name, initValues,mDefaultRingtone.get(DEFAULT_RINGER_INDEX)); } //end modify name = AudioProfileManager.getStreamUriKey(profileKey, AudioProfileManager.TYPE_NOTIFICATION);
Uri notificationUri = getPersistedValue(name, initValues,
mDefaultRingtone.get(DEFAULT_NOTIFICATION_INDEX));
...
}
4)
public void reset() {
Log.d(TAG, "reset start!");
mResetFlag = true;
String generalKey = mPredefinedKeys.get(Scenario.GENERAL.ordinal());
boolean isGeneralActive = isActiveProfile(generalKey);
synchronized (mActiveProfileKey) {
// Second restore other three predefine profile to default and delete custom
// profile if exist.
List<String> allKeys = new ArrayList<String>();
allKeys.addAll(mKeys);
allKeys.remove(generalKey);
for (String profileKey : allKeys) {
...
}
//start modify
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];
uriString = Settings.System.getString(mContentResolver, AudioProfileManager.KEY_DEFAULT_RINGTONE_SIM2);
uri = (uriString == null ? null : Uri.parse(uriString));
persistRingtoneUriToDatabase(generalKey, AudioProfileManager.TYPE_RINGTONE, subId, uri);
persistRingtoneUriToDatabase(outdoorKey, AudioProfileManager.TYPE_RINGTONE, subId, uri);
}
//end modify
Log.d(TAG, "reset end!");
}
mResetFlag = false;
}
6,alps\mediatek\frameworks\base\media\audio\java\com\mediatek\audioprofile\AudioProfileManager.java:
1)
public static final String KEY_DEFAULT_RINGTONE_SIM2 = "mtk_audioprofile_default_ringtone_sim2";//add this line
2) public enum ProfileSettings {
ringer_stream, notification_stream, videocall_Stream, sipcall_Stream,
ringer_sim2_stream, //add this line
ringer_volume, notification_volume, alarm_volume,
vibration_enabled, dtmftone_enabled, soundeffect_enbled, hapticfeedback_enabled,
lockscreensound_enabled
}
7. 若为L版本和JB版本,则请跳过步骤7,直接看步骤8。若为KK版本,则请看完本步7. 由于KK版本中删除了个别接口,目前的做法是恢复JB版本的接口。 对于KK版本设置卡1卡2的默认铃声,请继续做如下修改: 1)、在frameworks\opt\telephony\src\java\android\provider\Telephony.java中添加SIMInfo.getSlotById()方法: /** * @param ctx * @param SIMId * @return the slot of the SIM Card, -1 indicate that the SIM card is missing */ public static int getSlotById(Context ctx, long SIMId) { logd("[getSlotById]"); try { Class clz = Class.forName("com.mediatek.telephony.SimInfoManagerAdp"); Method method = clz.getMethod("getSlotByIdAdp", Context.class, long.class); if (method != null) { Integer slot = (Integer)method.invoke(null, ctx, SIMId); return slot.intValue(); } } catch (Exception e) { logd("createInstance:got exception for getSlotByIdAdp"); e.printStackTrace(); } return -1; } 2)、在mediatek\frameworks\base\telephony\java\com\mediatek\telephony\SimInfoManagerAdp.java中添加getSlotByIdAdp()的方法: public static int getSlotByIdAdp(Context ctx, long simId) { logd("[getSlotByIdAdp]"); return SimInfoManager.getSlotById(ctx, simId); } 3)、在mediatek\frameworks\base\telephony\java\com\mediatek\telephony\SimInfoManager.java中添加getSlotById()的方法: /** * Given an index, return the slot which the SIM is currently inserted * @param ctx * @param simInfoId the unique SimInfoRecord index in database * @return the slot which the SIM card currently inserted, -1 indicate SIM card missing */ public static int getSlotById(Context ctx, long simInfoId) { logd("[getSlotById]+ simInfoId:" + simInfoId); if (simInfoId <= 0 ) { logd("[getSlotById]- simInfoId <= 0"); return SLOT_NONE; } Cursor cursor = ctx.getContentResolver().query(ContentUris.withAppendedId(CONTENT_URI, simInfoId), new String[]{SLOT}, null, null, null); try { if (cursor != null) { if (cursor.moveToFirst()) { int slot = cursor.getInt(0); logd("[getSlotById]- sim in slot:" + slot); return slot; } } } finally { if (cursor != null) { cursor.close(); } } logd("[getSlotById]- fail, return -1"); return SLOT_NONE; }
8、若为L版本,则需看本步骤。若为其他版本,直接看步骤9
修改alps/packages/services/telecomm/src/com/android/server/telecom/Ringer.java private void startRingingOrCallWaiting() { ... AudioManager audioManager = (AudioManager) mContext.getSystemService(Context.AUDIO_SERVICE); if (audioManager.getStreamVolume(AudioManager.STREAM_RING) > 0) { Log.v(this, "startRingingOrCallWaiting"); mCallAudioManager.setIsRinging(true); //add begin if (SystemProperties.get("ro.mtk_multisim_ringtone").equals("1")) { PhoneAccountHandle phoneAccountHandle = foregroundCall.getTargetPhoneAccount(); Log.v(this, "phoneAccountHandle = " + phoneAccountHandle); long subId = SubscriptionManager.INVALID_SUB_ID; if(phoneAccountHandle != null) { String mId = phoneAccountHandle.getId(); Log.v(this, "phoneAccountHandle id = " + mId); if(mId != null) { subId = new Long(mId).longValue(); } } AudioProfileManager audioProfileMgr = (AudioProfileManager)mContext.getSystemService(Context.AUDIO_PROFILE_SERVICE); Uri ringtoneUri = audioProfileMgr.getRingtoneUri(audioProfileMgr.getActiveProfileKey(), AudioProfileManager.TYPE_RINGTONE, subId); if(-1==RingtoneManager.validRingtoneUri(mContext, ringtoneUri)){ ringtoneUri = null; } Log.d(this, "subscriber id: "+subId+" ringtoneUri: "+ringtoneUri); Uri contactRingtoneUri = foregroundCall.getRingtone(); mRingtonePlayer.play(contactRingtoneUri == null ? ringtoneUri : contactRingtoneUri); } else { //add end // Because we wait until a contact info query to complete before processing a // call (for the purposes of direct-to-voicemail), the information about custom // ringtones should be available by the time this code executes. We can safely // request the custom ringtone from the call and expect it to be current. mRingtonePlayer.play(foregroundCall.getRingtone());
9. 请修改后,执行如下命令: make update-api 这时候,L版本最终可能会报错,Context.java文件,将报错的@link和@see都删除,然后out下ITelephonyEx.java报出的@return 错误也删掉,以保证update-api通过。 然后,再完整编译整个project。