您好,登錄后才能下訂單哦!
這篇文章主要介紹Android8.1源碼修改之插入SIM卡默認啟用Volte功能的示例分析,文中介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們一定要看完!
前言
公用電話產品,插入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功能的示例分析”這篇文章的所有內容,感謝各位的閱讀!希望分享的內容對大家有幫助,更多相關知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。