概述
前言
公用电话产品,插入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卡状态改变通知, 全局查找到,
源码位置
vendormediatekproprietarypackagesservicesTelephonysrccommediateksettingscdmaCdmaVolteServiceChecker.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功能,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对靠谱客网站的支持!
如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!
最后
以上就是真实菠萝为你收集整理的Android8.1 源码修改之插入SIM卡默认启用Volte功能的全部内容,希望文章能够帮你解决Android8.1 源码修改之插入SIM卡默认启用Volte功能所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复