这篇文章主要介绍Android8.1源码修改之插入SIM卡默认启用Volte功能的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
创新互联公司主要从事成都网站设计、做网站、成都外贸网站建设公司、网页设计、企业做网站、公司建网站等业务。立足成都服务禹州,十余年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:13518219792
前言
公用电话产品,插入SIM卡后要求自动打开Volte功能,即插即用,用完拔卡就走
实现
第一步 开关对应的代码
通过打印日志和全局查找,源码位置 vendor/mediatek/proprietary/packages/services/Telephony/src/com/android/phone/MobileNetworkSettings.java 04-15 08:15:29.238 1191-1191/com.android.phone I/NetworkSettings: isUpdateTabsNeeded:- DO_NOTHING newSil.size()=1 mActiveSubInfos.size()=1 04-15 08:15:29.240 1191-1191/com.android.phone D/NetworkSettings: initializeSubscriptions: DO_NOTHING 04-15 08:15:29.240 1191-1191/com.android.phone D/NetworkSettings: convertTabToSlot: info size=1 currentTab=0 slotId=0 04-15 08:15:29.246 1191-1191/com.android.phone I/NetworkSettings: updatePhone:- slotId=0 sir={id=1, iccId=89861114706315182802 simSlotIndex=0 displayName=中国电信 carrierName=中国电信 nameSource=0 iconTint=-16746133 dataRoaming=0 iconBitmap=android.graphics.Bitmap@ca496f0 mcc 460 mnc 11 isEmbedded false accessRules null} 04-15 08:15:29.246 1191-1191/com.android.phone D/NetworkSettings: updateBody: isLteOnCdma=true phoneSubId=1 04-15 08:15:29.253 1191-1191/com.android.phone D/NetworkSettings: phoneType == PhoneConstants.PHONE_TYPE_CDMA or is CT VOLTE... 04-15 08:15:29.266 1191-1191/com.android.phone D/NetworkSettings: isWorldMode=false 04-15 08:15:29.267 1191-1191/com.android.phone D/NetworkSettings: isWorldMode=false 04-15 08:15:29.267 1191-1191/com.android.phone D/NetworkSettings: settingsNetworkMode: 10 04-15 08:15:29.285 1191-1191/com.android.phone D/NetworkSettings: [addEnhanced4GLteSwitchPreference] volteEnabled :true 04-15 08:15:29.285 1191-1191/com.android.phone D/NetworkSettings: [addEnhanced4GLteSwitchPreference] Remove mButton4glte! 04-15 08:15:29.285 1191-1191/com.android.phone D/NetworkSettings: [addEnhanced4GLteSwitchPreference] ss :false 04-15 08:15:29.307 1191-1191/com.android.phone D/DefaultMobileNetworkSettingsExt: customizeEnhanced4GLteSwitchPreference 04-15 08:15:29.320 1191-1191/com.android.phone D/NetworkSettings: CdmaNetworkSettings destroy com.android.phone.MobileNetworkSettings@99b81a5 04-15 08:15:29.320 1191-1191/com.android.phone D/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
修改如下
private BroadcastReceiver mReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { Log.d(TAG, "onReceive, action = " + intent.getAction()); updateState(); // cczheng add when recive SIM_STATE_CHANGED default open volte if (TelephonyIntents.ACTION_SIM_STATE_CHANGED.equals(intent.getAction())) { updateVolteState(); } }; }; //cczheng add check volte is open, and defalut open volte private void updateVolteState(){ Log.e(TAG, "updateVolteState...."); int subId = getListenSubId(); Log.i(TAG, "isValidSubscriptionId=="+SubscriptionManager.isValidSubscriptionId(subId)); Log.i(TAG, "isCtVolteEnabled=="+TelephonyUtilsEx.isCtVolteEnabled()); if (SubscriptionManager.isValidSubscriptionId(subId) && TelephonyUtilsEx.isCtVolteEnabled()) { boolean volteOn = MtkImsManager.isEnhanced4gLteModeSettingEnabledByUser(mContext, SubscriptionManager.getPhoneId(subId)); boolean isEnable4gOn = isEnable4gOn(subId); Log.i(TAG, "isEnable4gOn=="+isEnable4gOn); Log.i(TAG, "volteOn=="+volteOn); int phoneId = SubscriptionManager.getPhoneId(subId); Log.e(TAG, "phoneId = " + phoneId + " subId="+subId); if (!volteOn) { MtkImsManager.setEnhanced4gLteModeSetting(mContext, true, phoneId); } } } private boolean isLteNetwork(int subId) { boolean isLte = false; int networkType = TelephonyManager.NETWORK_TYPE_UNKNOWN; final int dataNetworkType = TelephonyManager.getDefault().getDataNetworkType(subId); final int voiceNetworkType = TelephonyManager.getDefault().getVoiceNetworkType(subId); Log.d(TAG, "dataNetworkType = " + dataNetworkType + ", voiceNetworkType = " + voiceNetworkType); if (TelephonyManager.NETWORK_TYPE_UNKNOWN != dataNetworkType) { networkType = dataNetworkType; } else if (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); return isLte; }
至此,搞定,简单说下上面的代码,当收到SIM状态改变的广播,检查卡的subId是否是有效的(subId>0),卡片是否支持Volte功能,同时满足则获取当前Volte是否已启用,未启用则调用MtkImsManager.setEnhanced4gLteModeSetting()
打开
以上是“Android8.1源码修改之插入SIM卡默认启用Volte功能的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!