Android8.1 源码修改之插入SIM卡默认启用Volte功能
前言
公用电话产品,插入SIM卡后要求自动打开Volte功能,即插即用,用完拔卡就走
实现
第一步开关对应的代码
通过打印日志和全局查找,源码位置vendor/mediatek/proprietary/packages/services/Telephony/src/com/android/phone/MobileNetworkSettings.java 04-1508:15:29.2381191-1191/com.android.phoneI/NetworkSettings:isUpdateTabsNeeded:-DO_NOTHINGnewSil.size()=1mActiveSubInfos.size()=1 04-1508:15:29.2401191-1191/com.android.phoneD/NetworkSettings:initializeSubscriptions:DO_NOTHING 04-1508:15:29.2401191-1191/com.android.phoneD/NetworkSettings:convertTabToSlot:infosize=1currentTab=0slotId=0 04-1508:15:29.2461191-1191/com.android.phoneI/NetworkSettings:updatePhone:-slotId=0sir={id=1,iccId=89861114706315182802simSlotIndex=0displayName=中国电信carrierName=中国电信nameSource=0iconTint=-16746133dataRoaming=0iconBitmap=android.graphics.Bitmap@ca496f0mcc460mnc11isEmbeddedfalseaccessRulesnull} 04-1508:15:29.2461191-1191/com.android.phoneD/NetworkSettings:updateBody:isLteOnCdma=truephoneSubId=1 04-1508:15:29.2531191-1191/com.android.phoneD/NetworkSettings:phoneType==PhoneConstants.PHONE_TYPE_CDMAorisCTVOLTE... 04-1508:15:29.2661191-1191/com.android.phoneD/NetworkSettings:isWorldMode=false 04-1508:15:29.2671191-1191/com.android.phoneD/NetworkSettings:isWorldMode=false 04-1508:15:29.2671191-1191/com.android.phoneD/NetworkSettings:settingsNetworkMode:10 04-1508:15:29.2851191-1191/com.android.phoneD/NetworkSettings:[addEnhanced4GLteSwitchPreference]volteEnabled:true 04-1508:15:29.2851191-1191/com.android.phoneD/NetworkSettings:[addEnhanced4GLteSwitchPreference]RemovemButton4glte! 04-1508:15:29.2851191-1191/com.android.phoneD/NetworkSettings:[addEnhanced4GLteSwitchPreference]ss:false 04-1508:15:29.3071191-1191/com.android.phoneD/DefaultMobileNetworkSettingsExt:customizeEnhanced4GLteSwitchPreference 04-1508:15:29.3201191-1191/com.android.phoneD/NetworkSettings:CdmaNetworkSettingsdestroycom.android.phone.MobileNetworkSettings@99b81a5 04-1508:15:29.3201191-1191/com.android.phoneD/CdmaNetworkSettings:onDestroy
通过MtkImsManager.setEnhanced4gLteModeSetting(this,enhanced4gModePref.isChecked(),phoneId);这行代码来实现volte的打开、关闭
第二步插卡后调用开关的代码
通过插卡后分析日志发现打印android.intent.action.SIM_STATE_CHANGED,字面意思Sim卡状态改变通知,全局查找到,
源码位置
vendor\mediatek\proprietary\packages\services\Telephony\src\com\mediatek\settings\cdma\CdmaVolteServiceChecker.java
修改如下
privateBroadcastReceivermReceiver=newBroadcastReceiver(){ @Override publicvoidonReceive(Contextcontext,Intentintent){ Log.d(TAG,"onReceive,action="+intent.getAction()); updateState(); //cczhengaddwhenreciveSIM_STATE_CHANGEDdefaultopenvolte if(TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())){ updateVolteState(); } }; }; //cczhengaddcheckvolteisopen,anddefalutopenvolte privatevoidupdateVolteState(){ Log.e(TAG,"updateVolteState...."); intsubId=getListenSubId(); Log.i(TAG,"isValidSubscriptionId=="+SubscriptionManager.isValidSubscriptionId(subId)); Log.i(TAG,"isCtVolteEnabled=="+TelephonyUtilsEx.isCtVolteEnabled()); if(SubscriptionManager.isValidSubscriptionId(subId)&&TelephonyUtilsEx.isCtVolteEnabled()){ booleanvolteOn=MtkImsManager.isEnhanced4gLteModeSettingEnabledByUser(mContext, SubscriptionManager.getPhoneId(subId)); booleanisEnable4gOn=isEnable4gOn(subId); Log.i(TAG,"isEnable4gOn=="+isEnable4gOn); Log.i(TAG,"volteOn=="+volteOn); intphoneId=SubscriptionManager.getPhoneId(subId); Log.e(TAG,"phoneId="+phoneId+"subId="+subId); if(!volteOn){ MtkImsManager.setEnhanced4gLteModeSetting(mContext,true,phoneId); } } } privatebooleanisLteNetwork(intsubId){ booleanisLte=false; intnetworkType=TelephonyManager.NETWORK_TYPE_UNKNOWN; finalintdataNetworkType=TelephonyManager.getDefault().getDataNetworkType(subId); finalintvoiceNetworkType=TelephonyManager.getDefault().getVoiceNetworkType(subId); Log.d(TAG,"dataNetworkType="+dataNetworkType +",voiceNetworkType="+voiceNetworkType); if(TelephonyManager.NETWORK_TYPE_UNKNOWN!=dataNetworkType){ networkType=dataNetworkType; }elseif(TelephonyManager.NETWORK_TYPE_UNKNOWN!=voiceNetworkType){ networkType=voiceNetworkType; } if((networkType==TelephonyManager.NETWORK_TYPE_LTE) ||(networkType==TelephonyManager.NETWORK_TYPE_LTE_CA)){ isLte=true; } Log.d(TAG,"isLte="+isLte); returnisLte; }
至此,搞定,简单说下上面的代码,当收到SIM状态改变的广播,检查卡的subId是否是有效的(subId>0),卡片是否支持Volte功能,同时满足则获取当前Volte是否已启用,未启用则调用MtkImsManager.setEnhanced4gLteModeSetting()打开
总结
以上所述是小编给大家介绍的Android8.1源码修改之插入SIM卡默认启用Volte功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!