Android 8.1 source code modification: insert SIM card to enable voltage function by default

Keywords: Android Java

Preface

For the public telephone product, after inserting the SIM card, it is required to turn on the voltage function automatically, plug and play, and leave after using the card

Realization

Code corresponding to the first step switch

Through printing logs and global search, the source location is vendor / MediaTek / proprietary / packages / services / telephone / 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=China Telecom carrierName=China Telecom 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

Through mtkimsmanager.setenhanced 4gltemodesetting (this, enhanced 4gmodepref. Ischecked(), phoneid); this line of code is used to open and close volte

For detailed analysis process, please see This article

The second step is to call the switch code after the card is inserted.

By analyzing the log after inserting the card, it is found that android.intent.action.Sim ﹣ state ﹣ changed is printed, which literally means the Sim card status change notice, which is found globally,

Source location vendor \ MediaTek \ proprietary \ packages \ services \ telephone \ SRC \ com \ MediaTek \ settings \ CDMA \ cdmavolteservicechecker.java

Revised as follows

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;
}

So far, it's done. Simply speaking, when receiving the broadcast of SIM status change, check whether the subId of the card is valid (subId > 0), whether the card supports the voltage function, and if it meets the requirements, obtain whether the current voltage is enabled, and if not, call MtkImsManager.setEnhanced4gLteModeSetting() to open it

Posted by henkealf on Mon, 11 Nov 2019 08:57:30 -0800