Android8.1 源码修改之插入SIM卡默认启用Volte功能
程序员文章站
2022-05-03 23:06:34
前言 公用电话产品,插入SIM卡后要求自动打开Volte功能,即插即用,用完拔卡就走 实现 第一步 开关对应的代码 通过打印日志和全局查找,源码位置 vendor/mediatek/proprietary/packages/services/Telephony/src/com/android/pho ......
前言
公用电话产品,插入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()打开