平台
RK3399 + Android 8.1
问题:
设置 > 更多 > 移动网络 > 首选网络类型 选项中, 仅显示 3G和2G, 缺少LTE, 本身模块与SIM卡是支持LTE的.
相关代码:
|-- packages/services/Telephony/res/xml/network_setting_fragment.xml
<?xml version="1.0" encoding="utf-8"?> <!-- Copyright (C) 2008 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:title="@string/mobile_networks"> <PreferenceScreen android:key="cdma_lte_data_service_key" android:title="@string/cdma_lte_data_service"> </PreferenceScreen> <com.android.phone.MobileDataPreference android:key="mobile_data_enable" android:title="@string/mobile_data_settings_title" android:summary="@string/mobile_data_settings_summary"/> <com.android.phone.RestrictedSwitchPreference android:key="button_roaming_key" android:title="@string/roaming" android:persistent="false" android:summaryOn="@string/roaming_enable" android:summaryOff="@string/roaming_disable"/> <com.android.phone.DataUsagePreference android:key="data_usage_summary" android:title="@string/data_usage_title" /> <com.android.phone.AdvancedOptionsPreference android:key="advanced_options"/> <SwitchPreference android:key="enhanced_4g_lte" android:title="@string/enhanced_4g_lte_mode_title" android:persistent="false" android:summary="@string/enhanced_4g_lte_mode_summary"/> <!--网络类型列表项--> <ListPreference android:key="preferred_network_mode_key" android:title="@string/preferred_network_mode_title" android:summary="@string/preferred_network_mode_summary" android:entries="@array/preferred_network_mode_choices" android:entryValues="@array/preferred_network_mode_values" android:dialogTitle="@string/preferred_network_mode_dialogtitle" /> <ListPreference android:key="enabled_networks_key" android:title="@string/preferred_network_mode_title" android:summary="@string/preferred_network_mode_summary" android:entries="@array/enabled_networks_choices" android:entryValues="@array/enabled_networks_values" android:dialogTitle="@string/preferred_network_mode_dialogtitle" /> <Preference android:key="carrier_settings_euicc_key" android:title="@string/carrier_settings_euicc" /> <PreferenceCategory android:key="calling" android:title="@string/call_category"> <PreferenceScreen android:key="wifi_calling_key" android:title="@string/wifi_calling_settings_title"> <intent android:action="android.intent.action.MAIN" android:targetPackage="com.android.settings" android:targetClass="com.android.settings.Settings$WifiCallingSettingsActivity"> <extra android:name="show_drawer_menu" android:value="true" /> </intent> </PreferenceScreen> <SwitchPreference android:key="video_calling_key" android:title="@string/video_calling_settings_title" android:persistent="true"/> </PreferenceCategory> </PreferenceScreen>
|-- packages/services/Telephony/src/com/android/phone/MobileNetworkSettings.java
public class MobileNetworkSettings extends Activity { public static class MobileNetworkFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener, RoamingDialogFragment.RoamingDialogListener { private static final String BUTTON_PREFERED_NETWORK_MODE = "preferred_network_mode_key"; @Override public void onCreate(Bundle icicle) { Log.i(LOG_TAG, "onCreate:+"); super.onCreate(icicle); ... //添加设置项 addPreferencesFromResource(R.xml.network_setting_fragment); mButtonPreferredNetworkMode = (ListPreference) prefSet.findPreference( BUTTON_PREFERED_NETWORK_MODE); } private void updateBodyAdvancedFields(Activity activity, PreferenceScreen prefSet, int phoneSubId, boolean hasActiveSubscriptions) { boolean isLteOnCdma = mPhone.getLteOnCdmaMode() == PhoneConstants.LTE_ON_CDMA_TRUE; if (DBG) { log("updateBody: isLteOnCdma=" + isLteOnCdma + " phoneSubId=" + phoneSubId); } prefSet.addPreference(mButtonPreferredNetworkMode); prefSet.addPreference(mButtonEnabledNetworks); prefSet.addPreference(mButton4glte); if (showEuiccSettings(getActivity())) { prefSet.addPreference(mEuiccSettingsPref); String spn = mTelephonyManager.getSimOperatorName(); if (TextUtils.isEmpty(spn)) { mEuiccSettingsPref.setSummary(null); } else { mEuiccSettingsPref.setSummary(spn); } } int settingsNetworkMode = android.provider.Settings.Global.getInt( mPhone.getContext().getContentResolver(), android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, preferredNetworkMode); PersistableBundle carrierConfig = PhoneGlobals.getInstance().getCarrierConfigForSubId(mPhone.getSubId()); mIsGlobalCdma = isLteOnCdma && carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_CDMA_CHOICES_BOOL); if (carrierConfig.getBoolean( CarrierConfigManager.KEY_HIDE_CARRIER_NETWORK_SETTINGS_BOOL)) { prefSet.removePreference(mButtonPreferredNetworkMode); prefSet.removePreference(mButtonEnabledNetworks); prefSet.removePreference(mLteDataServicePref); } else if (carrierConfig.getBoolean(CarrierConfigManager .KEY_HIDE_PREFERRED_NETWORK_TYPE_BOOL) && !mPhone.getServiceState().getRoaming() && mPhone.getServiceState().getDataRegState() == ServiceState.STATE_IN_SERVICE) { prefSet.removePreference(mButtonPreferredNetworkMode); prefSet.removePreference(mButtonEnabledNetworks); final int phoneType = mPhone.getPhoneType(); if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { updateCdmaOptions(this, prefSet, mPhone); } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { updateGsmUmtsOptions(this, prefSet, phoneSubId, mNetworkQueryService); } else { throw new IllegalStateException("Unexpected phone type: " + phoneType); } // Since pref is being hidden from user, set network mode to default // in case it is currently something else. That is possible if user // changed the setting while roaming and is now back to home network. settingsNetworkMode = preferredNetworkMode; } else if (carrierConfig.getBoolean( CarrierConfigManager.KEY_WORLD_PHONE_BOOL) == true) { prefSet.removePreference(mButtonEnabledNetworks); // set the listener for the mButtonPreferredNetworkMode list preference so we can issue // change Preferred Network Mode. mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this); updateCdmaOptions(this, prefSet, mPhone); updateGsmUmtsOptions(this, prefSet, phoneSubId, mNetworkQueryService); } else { prefSet.removePreference(mButtonPreferredNetworkMode); final int phoneType = mPhone.getPhoneType(); if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) { int lteForced = android.provider.Settings.Global.getInt( mPhone.getContext().getContentResolver(), android.provider.Settings.Global.LTE_SERVICE_FORCED + mPhone.getSubId(), 0); if (isLteOnCdma) { if (lteForced == 0) { mButtonEnabledNetworks.setEntries( R.array.enabled_networks_cdma_choices); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_cdma_values); } else { switch (settingsNetworkMode) { case Phone.NT_MODE_CDMA: case Phone.NT_MODE_CDMA_NO_EVDO: case Phone.NT_MODE_EVDO_NO_CDMA: mButtonEnabledNetworks.setEntries( R.array.enabled_networks_cdma_no_lte_choices); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_cdma_no_lte_values); break; case Phone.NT_MODE_GLOBAL: case Phone.NT_MODE_LTE_CDMA_AND_EVDO: case Phone.NT_MODE_LTE_CDMA_EVDO_GSM_WCDMA: case Phone.NT_MODE_LTE_ONLY: mButtonEnabledNetworks.setEntries( R.array.enabled_networks_cdma_only_lte_choices); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_cdma_only_lte_values); break; default: mButtonEnabledNetworks.setEntries( R.array.enabled_networks_cdma_choices); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_cdma_values); break; } } } updateCdmaOptions(this, prefSet, mPhone); } else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) { if (isSupportTdscdma()) { mButtonEnabledNetworks.setEntries( R.array.enabled_networks_tdscdma_choices); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_tdscdma_values); } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL) && !getResources().getBoolean(R.bool.config_enabled_lte)) { mButtonEnabledNetworks.setEntries( R.array.enabled_networks_except_gsm_lte_choices); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_except_gsm_lte_values); } else if (!carrierConfig.getBoolean(CarrierConfigManager.KEY_PREFER_2G_BOOL)) { int select = (mShow4GForLTE == true) ? R.array.enabled_networks_except_gsm_4g_choices : R.array.enabled_networks_except_gsm_choices; mButtonEnabledNetworks.setEntries(select); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_except_gsm_values); } else if (!getResources().getBoolean(R.bool.config_enabled_lte)) { //运行此分支 mButtonEnabledNetworks.setEntries( R.array.enabled_networks_except_lte_choices); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_except_lte_values); } else if (mIsGlobalCdma) { mButtonEnabledNetworks.setEntries( R.array.enabled_networks_cdma_choices); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_cdma_values); } else { int select = (mShow4GForLTE == true) ? R.array.enabled_networks_4g_choices : R.array.enabled_networks_choices; mButtonEnabledNetworks.setEntries(select); mButtonEnabledNetworks.setEntryValues( R.array.enabled_networks_values); } updateGsmUmtsOptions(this, prefSet, phoneSubId, mNetworkQueryService); } else { throw new IllegalStateException("Unexpected phone type: " + phoneType); } if (isWorldMode()) { mButtonEnabledNetworks.setEntries( R.array.preferred_network_mode_choices_world_mode); mButtonEnabledNetworks.setEntryValues( R.array.preferred_network_mode_values_world_mode); } mButtonEnabledNetworks.setOnPreferenceChangeListener(this); if (DBG) log("settingsNetworkMode: " + settingsNetworkMode); }
|-- packages/services/Telephony/res/values/strings.xml
<string-array name="enabled_networks_except_lte_choices" translatable="false"> <item>@string/network_3G</item> <item>@string/network_2G</item> </string-array>
config_enabled_lte的值为:
|-- packages/services/Telephony/res/values/config.xml
<bool name="config_enabled_lte" translatable="false">false</bool>
在以往的代码(以下为RK3288 Android7.1)中, 此值为true:
|-- device/rockchip/common/overlay/packages/services/Telephony/res/values/config.xml
<bool name="config_enabled_lte" translatable="false">true</bool>
因此, 只需把 config_enabled_lte的值改为true即可显示出LTE.