Android8.1 源碼修改之插入SIM卡默認啓用Volte功能

前言

公用電話產品,插入SIM卡後要求自動打開Volte功能,即插即用,用完拔卡就走java

實現

第一步 開關對應的代碼

經過打印日誌和全局查找,源碼位置 vendor/mediatek/proprietary/packages/services/Telephony/src/com/android/phone/MobileNetworkSettings.javaandroid

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的打開、關閉ide

詳細的分析流程,請看這篇this

第二步 插卡後調用開關的代碼

經過插卡後分析日誌發現打印 android.intent.action.SIM_STATE_CHANGED, 字面意思Sim卡狀態改變通知, 全局查找到,.net

源碼位置 vendor\mediatek\proprietary\packages\services\Telephony\src\com\mediatek\settings\cdma\CdmaVolteServiceChecker.java日誌

修改以下code

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()打開blog

相關文章
相關標籤/搜索