Fix the complie error of network migration

1. Fix the error in import part
2. Remove broken code and add TODO

Future CL will fix TODO and add tests

Bug: 114749736
Test: Build
Change-Id: I4fda0708959e299015ecb10ac17c9c2dadc6f852
This commit is contained in:
jackqdyulei
2018-10-03 16:34:57 -07:00
parent bff33e170c
commit 38f872fa1f
20 changed files with 565 additions and 287 deletions

View File

@@ -137,7 +137,12 @@
<!-- Whether or not TopLevelSettings should force rounded icon for injected tiles --> <!-- Whether or not TopLevelSettings should force rounded icon for injected tiles -->
<bool name="config_force_rounded_icon_TopLevelSettings">true</bool> <bool name="config_force_rounded_icon_TopLevelSettings">true</bool>
<!-- TODO(b/114749736): migrate override for config value --> <!-- TODO(b/115429501): move those 3 configs to framework-->
<!-- Show enabled lte option for lte device --> <!-- Show enabled lte option for lte device -->
<bool name="config_enabled_lte" translatable="false">false</bool> <bool name="config_enabled_lte" translatable="false">false</bool>
<!-- Show enabled tdscdma option for device -->
<bool name="config_support_tdscdma" translatable="false">false</bool>
<!-- Show enabled tdscdma option for device when connect roaming network -->
<string-array name="config_support_tdscdma_roaming_on_networks"
translatable="false"></string-array>
</resources> </resources>

View File

@@ -10186,23 +10186,10 @@
<!-- Configuration setting for world mode Format is <true;GID if any to be checked> [CHAR LIMIT=NONE] --> <!-- Configuration setting for world mode Format is <true;GID if any to be checked> [CHAR LIMIT=NONE] -->
<string translatable="false" name="config_world_mode"/> <string translatable="false" name="config_world_mode"/>
<!-- Available networks screen, text when no networks connected [CHAR LIMIT=NONE] -->
<string name="network_disconnected">Disconnected</string>
<!-- Available networks screen, text when network connected [CHAR LIMIT=NONE] -->
<string name="network_connected">Connected</string>
<!-- Available networks screen, text when a network is connecting [CHAR LIMIT=NONE] -->
<string name="network_connecting">Connecting\u2026</string>
<!-- Available networks screen, text when a network cannot be connected [CHAR LIMIT=NONE] -->
<string name="network_could_not_connect">Couldnt connect</string>
<!-- Available networks screen title/heading [CHAR LIMIT=NONE] --> <!-- Available networks screen title/heading [CHAR LIMIT=NONE] -->
<string name="label_available">Available networks</string> <string name="label_available">Available networks</string>
<!-- Mobile network settings screen, toast when searching for available networks [CHAR LIMIT=NONE] --> <!-- Mobile network settings screen, toast when searching for available networks [CHAR LIMIT=NONE] -->
<string name="load_networks_progress">Searching\u2026</string> <string name="load_networks_progress">Searching\u2026</string>
<!-- Available networks screen, text when no networks are found [CHAR LIMIT=NONE] -->
<string name="empty_networks_list">No networks found.</string>
<!-- Available networks screen, toast when an error is encountered when searching for networks [CHAR LIMIT=NONE] -->
<string name="network_query_error">Couldn\u2019t find networks. Try again.</string>
<!-- Available networks screen, toast when registering on a specific network [CHAR LIMIT=NONE] --> <!-- Available networks screen, toast when registering on a specific network [CHAR LIMIT=NONE] -->
<string name="register_on_network">Registering on <xliff:g id="network" example="Verizon">%s</xliff:g>\u2026</string> <string name="register_on_network">Registering on <xliff:g id="network" example="Verizon">%s</xliff:g>\u2026</string>
<!-- Available networks screen, toast when SIM card isn't allowed on a network [CHAR LIMIT=NONE] --> <!-- Available networks screen, toast when SIM card isn't allowed on a network [CHAR LIMIT=NONE] -->
@@ -10215,8 +10202,6 @@
<!-- Available networks screen, name of switch button for whether to select network automatically [CHAR LIMIT=NONE] --> <!-- Available networks screen, name of switch button for whether to select network automatically [CHAR LIMIT=NONE] -->
<string name="select_automatically">Automatically select network</string> <string name="select_automatically">Automatically select network</string>
<!-- Available networks screen, name of button when user wants to select network manually [CHAR LIMIT=NONE] -->
<string name="choose_network_title">Choose network</string>
<!-- A menu item in "Mobile network settings" that allows the user to update the phone <!-- A menu item in "Mobile network settings" that allows the user to update the phone
with mobile operator specific settings. [CHAR LIMIT=25] --> with mobile operator specific settings. [CHAR LIMIT=25] -->
<string name="carrier_settings_title">Carrier settings</string> <string name="carrier_settings_title">Carrier settings</string>
@@ -10259,4 +10244,16 @@
<string name="cdma_subscription_summary">Change between RUIM/SIM and NV</string> <string name="cdma_subscription_summary">Change between RUIM/SIM and NV</string>
<!-- Dialog title for CDMA subscription [CHAR LIMIT=30] --> <!-- Dialog title for CDMA subscription [CHAR LIMIT=30] -->
<string name="cdma_subscription_dialogtitle">subscription</string> <string name="cdma_subscription_dialogtitle">subscription</string>
<!-- Mobile network settings screen, Advanced button to show more items when clicked [CHAR LIMIT=50] -->
<string name="advanced_options_title">Advanced</string>
<!-- Title to register automatically [CHAR LIMIT=NONE] -->
<string name="register_automatically">Automatic registration\u2026</string>
<!-- Mobile network settings screen, dialog message title when user selects the Data roaming check box [CHAR LIMIT=120] -->
<string name="roaming_alert_title">Allow data roaming?</string>
<!-- Mobile network settings screen, message asking the user to check their pricing with their Carrier, when enabling Data roaming. [CHAR LIMIT=NONE] -->
<string name="roaming_check_price_warning">Check with your network provider for pricing.</string>
<!-- Available networks screen, summary when button disallowed due to permanent automatic mode [CHAR LIMIT=NONE] -->
<string name="manual_mode_disallowed_summary">Unavailable when connected to <xliff:g id="carrier" example="verizon">%1$s</xliff:g></string>
</resources> </resources>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project <!--
Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@@ -16,7 +17,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.android.phone.CdmaSystemSelectListPreference <com.android.settings.mobilenetwork.CdmaSystemSelectListPreference
android:key="cdma_system_select_key" android:key="cdma_system_select_key"
android:title="@string/cdma_system_select_title" android:title="@string/cdma_system_select_title"
android:summary="@string/cdma_system_select_summary" android:summary="@string/cdma_system_select_summary"
@@ -24,7 +25,7 @@
android:entryValues="@array/cdma_system_select_values" android:entryValues="@array/cdma_system_select_values"
android:dialogTitle="@string/cdma_system_select_dialogtitle" /> android:dialogTitle="@string/cdma_system_select_dialogtitle" />
<com.android.phone.CdmaSubscriptionListPreference <com.android.settings.mobilenetwork.CdmaSubscriptionListPreference
android:key="cdma_subscription_key" android:key="cdma_subscription_key"
android:title="@string/cdma_subscription_title" android:title="@string/cdma_subscription_title"
android:summary="@string/cdma_subscription_summary" android:summary="@string/cdma_subscription_summary"
@@ -37,7 +38,7 @@
<PreferenceCategory <PreferenceCategory
android:key="category_cdma_apn_key"> android:key="category_cdma_apn_key">
<!-- The launching Intent will be defined thru code as we need to pass some Extra --> <!-- The launching Intent will be defined thru code as we need to pass some Extra -->
<com.android.phone.RestrictedPreference <com.android.settingslib.RestrictedPreference
android:key="button_cdma_apn_key" android:key="button_cdma_apn_key"
android:title="@string/apn_settings" android:title="@string/apn_settings"
android:persistent="false"/> android:persistent="false"/>
@@ -46,9 +47,7 @@
<Preference <Preference
android:key="carrier_settings_key" android:key="carrier_settings_key"
android:title="@string/carrier_settings_title"> android:title="@string/carrier_settings_title">
<intent android:action="android.intent.action.MAIN" <!-- b/114749736, create a preference controller to build intent -->
android:targetPackage="@string/carrier_settings"
android:targetClass="@string/carrier_settings_menu" />
</Preference> </Preference>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2008 The Android Open Source Project <!--
Copyright (C) 2008 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@@ -16,7 +17,7 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<com.android.phone.NetworkOperators <com.android.settings.mobilenetwork.NetworkOperators
android:key="network_operators_category_key" android:key="network_operators_category_key"
android:title="@string/network_operator_category" android:title="@string/network_operator_category"
android:persistent="false"> android:persistent="false">
@@ -26,7 +27,7 @@
android:title="@string/select_automatically" android:title="@string/select_automatically"
android:persistent="false"/> android:persistent="false"/>
<com.android.phone.NetworkSelectListPreference <com.android.settings.mobilenetwork.NetworkSelectListPreference
android:key="button_network_select_key" android:key="button_network_select_key"
android:title="@string/network_select_title" android:title="@string/network_select_title"
android:persistent="false"/> android:persistent="false"/>
@@ -35,7 +36,7 @@
android:key="button_choose_network_key" android:key="button_choose_network_key"
android:title="@string/choose_network_title" android:title="@string/choose_network_title"
android:fragment="com.android.phone.NetworkSelectSetting" /> android:fragment="com.android.phone.NetworkSelectSetting" />
</com.android.phone.NetworkOperators> </com.android.settings.mobilenetwork.NetworkOperators>
<!--We want separate APN setting from reset of settings because--> <!--We want separate APN setting from reset of settings because-->
<!--we want user to change it with caution.--> <!--we want user to change it with caution.-->
@@ -43,7 +44,7 @@
android:key="category_gsm_apn_key" android:key="category_gsm_apn_key"
android:layout="@layout/preference_category_no_label"> android:layout="@layout/preference_category_no_label">
<com.android.phone.RestrictedPreference <com.android.settingslib.RestrictedPreference
android:key="button_gsm_apn_key" android:key="button_gsm_apn_key"
android:title="@string/apn_settings" android:title="@string/apn_settings"
android:persistent="false" /> android:persistent="false" />
@@ -52,9 +53,7 @@
<PreferenceScreen <PreferenceScreen
android:key="carrier_settings_key" android:key="carrier_settings_key"
android:title="@string/carrier_settings_title"> android:title="@string/carrier_settings_title">
<intent android:action="android.intent.action.MAIN" <!-- b/114749736, create a preference controller to build intent -->
android:targetPackage="@string/carrier_settings"
android:targetClass="@string/carrier_settings_menu" />
</PreferenceScreen> </PreferenceScreen>
</PreferenceScreen> </PreferenceScreen>

View File

@@ -20,23 +20,23 @@
android:title="@string/cdma_lte_data_service"> android:title="@string/cdma_lte_data_service">
</PreferenceScreen> </PreferenceScreen>
<com.android.phone.MobileDataPreference <com.android.settings.mobilenetwork.MobileDataPreference
android:key="mobile_data_enable" android:key="mobile_data_enable"
android:title="@string/mobile_data_settings_title" android:title="@string/mobile_data_settings_title"
android:summary="@string/mobile_data_settings_summary"/> android:summary="@string/mobile_data_settings_summary"/>
<com.android.phone.RestrictedSwitchPreference <com.android.settingslib.RestrictedSwitchPreference
android:key="button_roaming_key" android:key="button_roaming_key"
android:title="@string/roaming" android:title="@string/roaming"
android:persistent="false" android:persistent="false"
android:summaryOn="@string/roaming_enable" android:summaryOn="@string/roaming_enable"
android:summaryOff="@string/roaming_disable"/> android:summaryOff="@string/roaming_disable"/>
<com.android.phone.DataUsagePreference <com.android.settings.mobilenetwork.DataUsagePreference
android:key="data_usage_summary" android:key="data_usage_summary"
android:title="@string/data_usage_title" /> android:title="@string/data_usage_title" />
<com.android.phone.AdvancedOptionsPreference <com.android.settings.mobilenetwork.AdvancedOptionsPreference
android:key="advanced_options"/> android:key="advanced_options"/>
<SwitchPreference <SwitchPreference

View File

@@ -16,27 +16,31 @@
package com.android.settings.mobilenetwork; package com.android.settings.mobilenetwork;
import android.content.Context; import android.content.Context;
import android.preference.Preference; import androidx.preference.Preference;
import androidx.preference.PreferenceViewHolder;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView; import android.widget.TextView;
import com.android.settings.R;
/** /**
* Customized preference class representing the "Advanced" button that expands to fields that * Customized preference class representing the "Advanced" button that expands to fields that
* are hidden by default. * are hidden by default.
*/ */
//TODO(b/114749736): Change it back to normal preference
public class AdvancedOptionsPreference extends Preference { public class AdvancedOptionsPreference extends Preference {
public AdvancedOptionsPreference(Context context, AttributeSet attrs) { public AdvancedOptionsPreference(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} }
@Override @Override
protected void onBindView(View view) { public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindView(view); super.onBindViewHolder(holder);
setIcon(R.drawable.ic_expand_more); setIcon(R.drawable.ic_expand_more);
setTitle(R.string.advanced_options_title); setTitle(R.string.advanced_options_title);
TextView summary = view.findViewById(android.R.id.summary); TextView summary = (TextView) holder.findViewById(android.R.id.summary);
summary.setMaxLines(1); summary.setMaxLines(1);
} }
} }

View File

@@ -19,21 +19,22 @@ package com.android.settings.mobilenetwork;
import android.content.Intent; import android.content.Intent;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.os.SystemProperties; import android.os.SystemProperties;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.TextUtils; import android.text.TextUtils;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import com.android.internal.annotations.VisibleForTesting; import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.PhoneConstants;
import com.android.phone.MobileNetworkSettings; import com.android.settings.R;
import com.android.phone.RestrictedPreference;
import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedPreference;
/** /**
* List of Phone-specific settings screens. * List of Phone-specific settings screens.
@@ -54,11 +55,11 @@ public class CdmaOptions {
private static final String BUTTON_APN_EXPAND_KEY = "button_cdma_apn_key"; private static final String BUTTON_APN_EXPAND_KEY = "button_cdma_apn_key";
private static final String CATEGORY_APN_EXPAND_KEY = "category_cdma_apn_key"; private static final String CATEGORY_APN_EXPAND_KEY = "category_cdma_apn_key";
private PreferenceFragment mPrefFragment; private PreferenceFragmentCompat mPrefFragment;
private PreferenceScreen mPrefScreen; private PreferenceScreen mPrefScreen;
private int mSubId; private int mSubId;
public CdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, int subId) { public CdmaOptions(PreferenceFragmentCompat prefFragment, PreferenceScreen prefScreen, int subId) {
mPrefFragment = prefFragment; mPrefFragment = prefFragment;
mPrefScreen = prefScreen; mPrefScreen = prefScreen;
mPrefFragment.addPreferencesFromResource(R.xml.cdma_options); mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
@@ -99,7 +100,7 @@ public class CdmaOptions {
if (addAPNExpand) { if (addAPNExpand) {
log("update: addAPNExpand"); log("update: addAPNExpand");
mButtonAPNExpand.setDisabledByAdmin( mButtonAPNExpand.setDisabledByAdmin(
MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext()) MobileNetworkUtils.isDpcApnEnforced(mButtonAPNExpand.getContext())
? RestrictedLockUtilsInternal.getDeviceOwner( ? RestrictedLockUtilsInternal.getDeviceOwner(
mButtonAPNExpand.getContext()) mButtonAPNExpand.getContext())
: null); : null);

View File

@@ -18,7 +18,7 @@ package com.android.settings.mobilenetwork;
import android.content.Context; import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.preference.ListPreference; import androidx.preference.ListPreference;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.AttributeSet; import android.util.AttributeSet;
@@ -29,7 +29,7 @@ import com.android.settingslib.utils.ThreadUtils;
public class CdmaSubscriptionListPreference extends ListPreference { public class CdmaSubscriptionListPreference extends ListPreference {
private static final String LOG_TAG = "CdmaSubscriptionListPreference"; private static final String LOG_TAG = "CdmaSubListPref";
// Used for CDMA subscription mode // Used for CDMA subscription mode
private static final int CDMA_SUBSCRIPTION_RUIM_SIM = 0; private static final int CDMA_SUBSCRIPTION_RUIM_SIM = 0;
@@ -67,17 +67,13 @@ public class CdmaSubscriptionListPreference extends ListPreference {
mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(subId); mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(subId);
} }
@Override //TODO(b/114749736): move this logic to preference controller
protected void showDialog(Bundle state) { protected void showDialog(Bundle state) {
setCurrentCdmaSubscriptionModeValue(); setCurrentCdmaSubscriptionModeValue();
super.showDialog(state);
} }
@Override //TODO(b/114749736): move this logic to preference controller
protected void onDialogClosed(boolean positiveResult) { protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (!positiveResult) { if (!positiveResult) {
//The button was dismissed - no need to set new value //The button was dismissed - no need to set new value
return; return;

View File

@@ -20,7 +20,6 @@ import android.content.Context;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.preference.ListPreference;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.AttributeSet; import android.util.AttributeSet;
@@ -28,9 +27,11 @@ import android.util.Log;
import com.android.settingslib.utils.ThreadUtils; import com.android.settingslib.utils.ThreadUtils;
import androidx.preference.ListPreference;
public class CdmaSystemSelectListPreference extends ListPreference { public class CdmaSystemSelectListPreference extends ListPreference {
private static final String LOG_TAG = "CdmaRoamingListPreference"; private static final String LOG_TAG = "CdmaRoamingListPref";
private static final boolean DBG = false; private static final boolean DBG = false;
private TelephonyManager mTelephonyManager; private TelephonyManager mTelephonyManager;
@@ -57,17 +58,15 @@ public class CdmaSystemSelectListPreference extends ListPreference {
queryCdmaRoamingMode(); queryCdmaRoamingMode();
} }
@Override //TODO(b/114749736): Move this to preference controller
protected void showDialog(Bundle state) { protected void showDialog(Bundle state) {
if (!mTelephonyManager.getEmergencyCallbackMode()) { if (!mTelephonyManager.getEmergencyCallbackMode()) {
super.showDialog(state); // show Dialog
} }
} }
@Override //TODO(b/114749736): Move this to preference controller
protected void onDialogClosed(boolean positiveResult) { protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
if (positiveResult && (getValue() != null)) { if (positiveResult && (getValue() != null)) {
int buttonCdmaRoamingMode = Integer.parseInt(getValue()); int buttonCdmaRoamingMode = Integer.parseInt(getValue());
int settingsCdmaRoamingMode = Settings.Global.getInt( int settingsCdmaRoamingMode = Settings.Global.getInt(

View File

@@ -127,6 +127,35 @@ public final class CellInfoUtil {
return oi; return oi;
} }
/**
* Creates a CellInfo object from OperatorInfo. GsmCellInfo is used here only because
* operatorInfo does not contain technology type while CellInfo is an abstract object that
* requires to specify technology type. It doesn't matter which CellInfo type to use here, since
* we only want to wrap the operator info and PLMN to a CellInfo object.
*/
public static CellInfo convertOperatorInfoToCellInfo(OperatorInfo operatorInfo) {
String operatorNumeric = operatorInfo.getOperatorNumeric();
String mcc = null;
String mnc = null;
if (operatorNumeric != null && operatorNumeric.matches("^[0-9]{5,6}$")) {
mcc = operatorNumeric.substring(0, 3);
mnc = operatorNumeric.substring(3);
}
CellIdentityGsm cig = new CellIdentityGsm(
Integer.MAX_VALUE /* lac */,
Integer.MAX_VALUE /* cid */,
Integer.MAX_VALUE /* arfcn */,
Integer.MAX_VALUE /* bsic */,
mcc,
mnc,
operatorInfo.getOperatorAlphaLong(),
operatorInfo.getOperatorAlphaShort());
CellInfoGsm ci = new CellInfoGsm();
ci.setCellIdentity(cig);
return ci;
}
/** Checks whether the network operator is forbidden. */ /** Checks whether the network operator is forbidden. */
public static boolean isForbidden(CellInfo cellInfo, List<String> forbiddenPlmns) { public static boolean isForbidden(CellInfo cellInfo, List<String> forbiddenPlmns) {
String plmn = CellInfoUtil.getOperatorInfoFromCellInfo(cellInfo).getOperatorNumeric(); String plmn = CellInfoUtil.getOperatorInfoFromCellInfo(cellInfo).getOperatorNumeric();

View File

@@ -20,12 +20,13 @@ import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.NetworkTemplate; import android.net.NetworkTemplate;
import android.preference.Preference; import androidx.preference.Preference;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.util.AttributeSet; import android.util.AttributeSet;
import com.android.settings.R;
import com.android.settingslib.net.DataUsageController; import com.android.settingslib.net.DataUsageController;
/** /**

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2018 The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -19,22 +19,21 @@ package com.android.settings.mobilenetwork;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.provider.Settings; import android.provider.Settings;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.Phone; import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.PhoneConstants;
import com.android.phone.INetworkQueryService; import com.android.settings.R;
import com.android.phone.MobileNetworkSettings;
import com.android.phone.PhoneGlobals;
import com.android.phone.RestrictedPreference;
import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedPreference;
/** /**
* List of Network-specific settings screens. * List of Network-specific settings screens.
@@ -54,11 +53,11 @@ public class GsmUmtsOptions {
private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key"; private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_key";
public static final String EXTRA_SUB_ID = "sub_id"; public static final String EXTRA_SUB_ID = "sub_id";
private PreferenceFragment mPrefFragment; private PreferenceFragmentCompat mPrefFragment;
private PreferenceScreen mPrefScreen; private PreferenceScreen mPrefScreen;
public GsmUmtsOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, public GsmUmtsOptions(PreferenceFragmentCompat prefFragment, PreferenceScreen prefScreen,
final int subId, INetworkQueryService queryService) { final int subId) {
final Context context = prefFragment.getContext(); final Context context = prefFragment.getContext();
mPrefFragment = prefFragment; mPrefFragment = prefFragment;
mPrefScreen = prefScreen; mPrefScreen = prefScreen;
@@ -72,18 +71,19 @@ public class GsmUmtsOptions {
mNetworkOperator.initialize(); mNetworkOperator.initialize();
update(subId, queryService); update(subId);
} }
// Unlike mPrefFragment or mPrefScreen, subId or queryService may change during lifecycle of // Unlike mPrefFragment or mPrefScreen, subId may change during lifecycle of GsmUmtsOptions.
// GsmUmtsOptions. When that happens, we update GsmUmtsOptions with new parameters. // When that happens, we update GsmUmtsOptions with new parameters.
protected void update(final int subId, INetworkQueryService queryService) { protected void update(final int subId) {
boolean addAPNExpand = true; boolean addAPNExpand = true;
boolean addNetworkOperatorsCategory = true; boolean addNetworkOperatorsCategory = true;
boolean addCarrierSettings = true; boolean addCarrierSettings = true;
final TelephonyManager telephonyManager = TelephonyManager.from(mPrefFragment.getContext()) final TelephonyManager telephonyManager = TelephonyManager.from(mPrefFragment.getContext())
.createForSubscriptionId(subId); .createForSubscriptionId(subId);
Phone phone = PhoneGlobals.getPhone(subId); //TODO(b/115429509): Get phone from subId
Phone phone = null;
if (phone == null) return; if (phone == null) return;
if (telephonyManager.getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) { if (telephonyManager.getPhoneType() != PhoneConstants.PHONE_TYPE_GSM) {
log("Not a GSM phone"); log("Not a GSM phone");
@@ -128,7 +128,7 @@ public class GsmUmtsOptions {
if (addAPNExpand) { if (addAPNExpand) {
log("update: addAPNExpand"); log("update: addAPNExpand");
mButtonAPNExpand.setDisabledByAdmin( mButtonAPNExpand.setDisabledByAdmin(
MobileNetworkSettings.isDpcApnEnforced(mButtonAPNExpand.getContext()) MobileNetworkUtils.isDpcApnEnforced(mButtonAPNExpand.getContext())
? RestrictedLockUtilsInternal.getDeviceOwner( ? RestrictedLockUtilsInternal.getDeviceOwner(
mButtonAPNExpand.getContext()) mButtonAPNExpand.getContext())
: null); : null);
@@ -156,7 +156,7 @@ public class GsmUmtsOptions {
if (addNetworkOperatorsCategory) { if (addNetworkOperatorsCategory) {
mPrefScreen.addPreference(mNetworkOperator); mPrefScreen.addPreference(mNetworkOperator);
mNetworkOperator.update(subId, queryService); mNetworkOperator.update(subId);
} else { } else {
mPrefScreen.removePreference(mNetworkOperator); mPrefScreen.removePreference(mNetworkOperator);
} }
@@ -177,3 +177,4 @@ public class GsmUmtsOptions {
android.util.Log.d(LOG_TAG, s); android.util.Log.d(LOG_TAG, s);
} }
} }

View File

@@ -25,8 +25,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.preference.DialogPreference;
import android.preference.PreferenceScreen;
import android.provider.Settings.Global; import android.provider.Settings.Global;
import android.telephony.SubscriptionInfo; import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
@@ -36,8 +34,13 @@ import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.Checkable; import android.widget.Checkable;
import androidx.preference.DialogPreference;
import androidx.preference.PreferenceScreen;
import androidx.preference.PreferenceViewHolder;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import java.util.List; import java.util.List;
@@ -45,7 +48,8 @@ import java.util.List;
* Customized Preference to enable / disable mobile data. * Customized Preference to enable / disable mobile data.
* Basically copy of with com.android.settings.CellDataPreference. * Basically copy of with com.android.settings.CellDataPreference.
*/ */
public class MobileDataPreference extends DialogPreference { public class MobileDataPreference extends DialogPreference implements
DialogInterface.OnClickListener {
private static final boolean DBG = false; private static final boolean DBG = false;
private static final String TAG = "MobileDataPreference"; private static final String TAG = "MobileDataPreference";
@@ -92,8 +96,8 @@ public class MobileDataPreference extends DialogPreference {
} }
@Override @Override
protected void onAttachedToActivity() { public void onAttached() {
super.onAttachedToActivity(); super.onAttached();
mListener.setListener(true, mSubId, getContext()); mListener.setListener(true, mSubId, getContext());
} }
@@ -124,7 +128,7 @@ public class MobileDataPreference extends DialogPreference {
} }
@Override @Override
public void performClick(PreferenceScreen preferenceScreen) { public void performClick() {
if (!isEnabled() || !SubscriptionManager.isValidSubscriptionId(mSubId)) { if (!isEnabled() || !SubscriptionManager.isValidSubscriptionId(mSubId)) {
return; return;
} }
@@ -141,7 +145,7 @@ public class MobileDataPreference extends DialogPreference {
// disabling data; show confirmation dialog which eventually // disabling data; show confirmation dialog which eventually
// calls setMobileDataEnabled() once user confirms. // calls setMobileDataEnabled() once user confirms.
mMultiSimDialog = false; mMultiSimDialog = false;
super.performClick(preferenceScreen); super.performClick();
} else { } else {
// Don't show any dialog. // Don't show any dialog.
setMobileDataEnabled(false /* enabled */, false /* disableOtherSubscriptions */); setMobileDataEnabled(false /* enabled */, false /* disableOtherSubscriptions */);
@@ -151,7 +155,7 @@ public class MobileDataPreference extends DialogPreference {
// enabling data and setting to default; show confirmation dialog which eventually // enabling data and setting to default; show confirmation dialog which eventually
// calls setMobileDataEnabled() once user confirms. // calls setMobileDataEnabled() once user confirms.
mMultiSimDialog = true; mMultiSimDialog = true;
super.performClick(preferenceScreen); super.performClick();
} else { } else {
// Don't show any dialog. // Don't show any dialog.
setMobileDataEnabled(true /* enabled */, false /* disableOtherSubscriptions */); setMobileDataEnabled(true /* enabled */, false /* disableOtherSubscriptions */);
@@ -181,14 +185,14 @@ public class MobileDataPreference extends DialogPreference {
} }
@Override @Override
protected void onBindView(View view) { public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindView(view); super.onBindViewHolder(holder);
View checkableView = view.findViewById(com.android.internal.R.id.switch_widget); View checkableView = holder.findViewById(com.android.internal.R.id.switch_widget);
checkableView.setClickable(false); checkableView.setClickable(false);
((Checkable) checkableView).setChecked(mChecked); ((Checkable) checkableView).setChecked(mChecked);
} }
@Override //TODO(b/114749736): move it to preference controller
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) { protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
if (mMultiSimDialog) { if (mMultiSimDialog) {
showMultiSimDialog(builder); showMultiSimDialog(builder);
@@ -217,7 +221,7 @@ public class MobileDataPreference extends DialogPreference {
String.valueOf(currentSir != null ? currentSir.getDisplayName() : null), String.valueOf(currentSir != null ? currentSir.getDisplayName() : null),
previousName)); previousName));
builder.setPositiveButton(R.string.ok, this); builder.setPositiveButton(android.R.string.ok, this);
builder.setNegativeButton(R.string.cancel, null); builder.setNegativeButton(R.string.cancel, null);
} }

View File

@@ -19,8 +19,6 @@ package com.android.settings.mobilenetwork;
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI; import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
import android.app.ActionBar; import android.app.ActionBar;
import android.app.Activity;
import android.app.DialogFragment;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -36,12 +34,6 @@ import android.os.Message;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager; import android.os.UserManager;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.preference.SwitchPreference;
import android.provider.Settings; import android.provider.Settings;
import android.telecom.PhoneAccountHandle; import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager; import android.telecom.TelecomManager;
@@ -67,26 +59,29 @@ import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.telephony.Phone; import com.android.internal.telephony.Phone;
import com.android.internal.telephony.PhoneConstants; import com.android.internal.telephony.PhoneConstants;
import com.android.internal.telephony.TelephonyIntents; import com.android.internal.telephony.TelephonyIntents;
import com.android.phone.AdvancedOptionsPreference; import com.android.settings.R;
import com.android.phone.CdmaOptions; import com.android.settings.dashboard.DashboardFragment;
import com.android.phone.CdmaSystemSelectListPreference; import com.android.settings.search.BaseSearchIndexProvider;
import com.android.phone.DataUsagePreference; import com.android.settings.search.Indexable;
import com.android.phone.EmergencyCallbackModeExitDialog;
import com.android.phone.GsmUmtsOptions;
import com.android.phone.MobileDataPreference;
import com.android.phone.MobileNetworkSettings;
import com.android.phone.NetworkOperators;
import com.android.phone.NetworkSelectListPreference;
import com.android.phone.RestrictedSwitchPreference;
import com.android.phone.RoamingDialogFragment;
import com.android.settingslib.RestrictedLockUtilsInternal; import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.RestrictedSwitchPreference;
import com.android.settingslib.search.SearchIndexable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
public static class MobileNetworkFragment extends PreferenceFragment implements import androidx.fragment.app.FragmentActivity;
Preference.OnPreferenceChangeListener, com.android.phone.RoamingDialogFragment.RoamingDialogListener { import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class MobileNetworkFragment extends DashboardFragment implements
Preference.OnPreferenceChangeListener, RoamingDialogFragment.RoamingDialogListener {
// debug data // debug data
private static final String LOG_TAG = "NetworkSettings"; private static final String LOG_TAG = "NetworkSettings";
@@ -125,10 +120,14 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
private static final String BUTTON_GSM_APN_EXPAND_KEY = "button_gsm_apn_key"; private static final String BUTTON_GSM_APN_EXPAND_KEY = "button_gsm_apn_key";
private static final String BUTTON_CDMA_APN_EXPAND_KEY = "button_cdma_apn_key"; private static final String BUTTON_CDMA_APN_EXPAND_KEY = "button_cdma_apn_key";
private static final String EXTRA_EXIT_ECM_RESULT = "exit_ecm_result";
private static final String LEGACY_ACTION_CONFIGURE_PHONE_ACCOUNT =
"android.telecom.action.CONNECTION_SERVICE_CONFIGURE";
private final BroadcastReceiver private final BroadcastReceiver
mPhoneChangeReceiver = new MobileNetworkSettings.MobileNetworkFragment.PhoneChangeReceiver(); mPhoneChangeReceiver = new PhoneChangeReceiver();
private final ContentObserver private final ContentObserver
mDpcEnforcedContentObserver = new MobileNetworkSettings.MobileNetworkFragment.DpcApnEnforcedObserver(); mDpcEnforcedContentObserver = new DpcApnEnforcedObserver();
static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE; static final int preferredNetworkMode = Phone.PREFERRED_NT_MODE;
@@ -142,13 +141,17 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
//Intent extra to indicate expand all fields. //Intent extra to indicate expand all fields.
private static final String EXPAND_EXTRA = "expandable"; private static final String EXPAND_EXTRA = "expandable";
private enum TabState {
NO_TABS, UPDATE, DO_NOTHING
}
private SubscriptionManager mSubscriptionManager; private SubscriptionManager mSubscriptionManager;
private TelephonyManager mTelephonyManager; private TelephonyManager mTelephonyManager;
private CarrierConfigManager mCarrierConfigManager; private CarrierConfigManager mCarrierConfigManager;
private int mSubId; private int mSubId;
//UI objects //UI objects
private com.android.phone.AdvancedOptionsPreference mAdvancedOptions; private AdvancedOptionsPreference mAdvancedOptions;
private ListPreference mButtonPreferredNetworkMode; private ListPreference mButtonPreferredNetworkMode;
private ListPreference mButtonEnabledNetworks; private ListPreference mButtonEnabledNetworks;
private RestrictedSwitchPreference mButtonDataRoam; private RestrictedSwitchPreference mButtonDataRoam;
@@ -159,15 +162,15 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
private Preference mWiFiCallingPref; private Preference mWiFiCallingPref;
private SwitchPreference mVideoCallingPref; private SwitchPreference mVideoCallingPref;
private NetworkSelectListPreference mButtonNetworkSelect; private NetworkSelectListPreference mButtonNetworkSelect;
private com.android.phone.MobileDataPreference mMobileDataPref; private MobileDataPreference mMobileDataPref;
private com.android.phone.DataUsagePreference mDataUsagePref; private DataUsagePreference mDataUsagePref;
private static final String iface = "rmnet0"; //TODO: this will go away private static final String iface = "rmnet0"; //TODO: this will go away
private List<SubscriptionInfo> mActiveSubInfos; private List<SubscriptionInfo> mActiveSubInfos;
private UserManager mUm; private UserManager mUm;
private ImsManager mImsMgr; private ImsManager mImsMgr;
private MobileNetworkSettings.MobileNetworkFragment.MyHandler mHandler; private MyHandler mHandler;
private boolean mOkClicked; private boolean mOkClicked;
private boolean mExpandAdvancedFields; private boolean mExpandAdvancedFields;
@@ -175,8 +178,8 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
private TabHost mTabHost; private TabHost mTabHost;
//GsmUmts options and Cdma options //GsmUmts options and Cdma options
com.android.phone.GsmUmtsOptions mGsmUmtsOptions; GsmUmtsOptions mGsmUmtsOptions;
com.android.phone.CdmaOptions mCdmaOptions; CdmaOptions mCdmaOptions;
private Preference mClickedPreference; private Preference mClickedPreference;
private boolean mShow4GForLTE; private boolean mShow4GForLTE;
@@ -205,11 +208,11 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
* Listen to different subId if it's changed. * Listen to different subId if it's changed.
*/ */
protected void updateSubscriptionId(Integer subId) { protected void updateSubscriptionId(Integer subId) {
if (subId.equals(MobileNetworkSettings.MobileNetworkFragment.PhoneCallStateListener.this.mSubId)) { if (subId.equals(PhoneCallStateListener.this.mSubId)) {
return; return;
} }
MobileNetworkSettings.MobileNetworkFragment.PhoneCallStateListener.this.mSubId = subId; PhoneCallStateListener.this.mSubId = subId;
mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE); mTelephonyManager.listen(this, PhoneStateListener.LISTEN_NONE);
@@ -220,11 +223,24 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} }
} }
private final MobileNetworkSettings.MobileNetworkFragment.PhoneCallStateListener private final PhoneCallStateListener
mPhoneStateListener = new MobileNetworkSettings.MobileNetworkFragment.PhoneCallStateListener(); mPhoneStateListener = new PhoneCallStateListener();
//TODO(b/114749736): figure out a way to update this fragment from intent
public void onIntentUpdate(Intent intent) {
if (!mUnavailable) {
updateCurrentTab(intent);
}
}
@Override @Override
public void onPositiveButtonClick(DialogFragment dialog) { public int getMetricsCategory() {
//TODO(b/114749736): add metrics id for it
return 0;
}
@Override
public void onPositiveButtonClick(androidx.fragment.app.DialogFragment dialog) {
mTelephonyManager.setDataRoamingEnabled(true); mTelephonyManager.setDataRoamingEnabled(true);
mButtonDataRoam.setChecked(true); mButtonDataRoam.setChecked(true);
MetricsLogger.action(getContext(), MetricsLogger.action(getContext(),
@@ -232,28 +248,14 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
true); true);
} }
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
if (getListView() != null) {
getListView().setDivider(null);
}
}
public void onIntentUpdate(Intent intent) {
if (!mUnavailable) {
updateCurrentTab(intent);
}
}
/** /**
* Invoked on each preference click in this hierarchy, overrides * Invoked on each preference click in this hierarchy, overrides
* PreferenceActivity's implementation. Used to make sure we track the * PreferenceActivity's implementation. Used to make sure we track the
* preference click events. * preference click events.
*/ */
@Override @Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, public boolean onPreferenceTreeClick(Preference preference) {
Preference preference) { sendMetricsEventPreferenceClicked(getPreferenceScreen(), preference);
sendMetricsEventPreferenceClicked(preferenceScreen, preference);
/** TODO: Refactor and get rid of the if's using subclasses */ /** TODO: Refactor and get rid of the if's using subclasses */
if (preference.getKey().equals(BUTTON_4G_LTE_KEY)) { if (preference.getKey().equals(BUTTON_4G_LTE_KEY)) {
@@ -283,7 +285,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
return true; return true;
} else if (preference == mLteDataServicePref) { } else if (preference == mLteDataServicePref) {
String tmpl = android.provider.Settings.Global.getString( String tmpl = android.provider.Settings.Global.getString(
getActivity().getContentResolver(), getContext().getContentResolver(),
android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL); android.provider.Settings.Global.SETUP_PREPAID_DATA_SERVICE_URL);
if (!TextUtils.isEmpty(tmpl)) { if (!TextUtils.isEmpty(tmpl)) {
String imsi = mTelephonyManager.getSubscriberId(); String imsi = mTelephonyManager.getSubscriberId();
@@ -323,7 +325,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
// if the button is anything but the simple toggle preference, // if the button is anything but the simple toggle preference,
// we'll need to disable all preferences to reject all click // we'll need to disable all preferences to reject all click
// events until the sub-activity's UI comes up. // events until the sub-activity's UI comes up.
preferenceScreen.setEnabled(false); getPreferenceScreen().setEnabled(false);
// Let the intents be launched by the Preference manager // Let the intents be launched by the Preference manager
return false; return false;
} }
@@ -349,8 +351,8 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} }
private void initializeSubscriptions() { private void initializeSubscriptions() {
final Activity activity = getActivity(); final FragmentActivity activity = getActivity();
if (activity == null || activity.isDestroyed()) { if (activity == null) {
// Process preferences in activity only if its not destroyed // Process preferences in activity only if its not destroyed
return; return;
} }
@@ -360,7 +362,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
// Before updating the the active subscription list check // Before updating the the active subscription list check
// if tab updating is needed as the list is changing. // if tab updating is needed as the list is changing.
List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList(); List<SubscriptionInfo> sil = mSubscriptionManager.getActiveSubscriptionInfoList();
MobileNetworkSettings.TabState state = isUpdateTabsNeeded(sil); TabState state = isUpdateTabsNeeded(sil);
// Update to the active subscription list // Update to the active subscription list
mActiveSubInfos.clear(); mActiveSubInfos.clear();
@@ -430,19 +432,19 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
if (DBG) log("initializeSubscriptions:-"); if (DBG) log("initializeSubscriptions:-");
} }
private MobileNetworkSettings.TabState isUpdateTabsNeeded(List<SubscriptionInfo> newSil) { private TabState isUpdateTabsNeeded(List<SubscriptionInfo> newSil) {
MobileNetworkSettings.TabState state = MobileNetworkSettings.TabState.DO_NOTHING; TabState state = TabState.DO_NOTHING;
if (newSil == null) { if (newSil == null) {
if (mActiveSubInfos.size() >= TAB_THRESHOLD) { if (mActiveSubInfos.size() >= TAB_THRESHOLD) {
if (DBG) log("isUpdateTabsNeeded: NO_TABS, size unknown and was tabbed"); if (DBG) log("isUpdateTabsNeeded: NO_TABS, size unknown and was tabbed");
state = MobileNetworkSettings.TabState.NO_TABS; state = TabState.NO_TABS;
} }
} else if (newSil.size() < TAB_THRESHOLD && mActiveSubInfos.size() >= TAB_THRESHOLD) { } else if (newSil.size() < TAB_THRESHOLD && mActiveSubInfos.size() >= TAB_THRESHOLD) {
if (DBG) log("isUpdateTabsNeeded: NO_TABS, size went to small"); if (DBG) log("isUpdateTabsNeeded: NO_TABS, size went to small");
state = MobileNetworkSettings.TabState.NO_TABS; state = TabState.NO_TABS;
} else if (newSil.size() >= TAB_THRESHOLD && mActiveSubInfos.size() < TAB_THRESHOLD) { } else if (newSil.size() >= TAB_THRESHOLD && mActiveSubInfos.size() < TAB_THRESHOLD) {
if (DBG) log("isUpdateTabsNeeded: UPDATE, size changed"); if (DBG) log("isUpdateTabsNeeded: UPDATE, size changed");
state = MobileNetworkSettings.TabState.UPDATE; state = TabState.UPDATE;
} else if (newSil.size() >= TAB_THRESHOLD) { } else if (newSil.size() >= TAB_THRESHOLD) {
Iterator<SubscriptionInfo> siIterator = mActiveSubInfos.iterator(); Iterator<SubscriptionInfo> siIterator = mActiveSubInfos.iterator();
for(SubscriptionInfo newSi : newSil) { for(SubscriptionInfo newSi : newSil) {
@@ -450,7 +452,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
if (!newSi.getDisplayName().equals(curSi.getDisplayName())) { if (!newSi.getDisplayName().equals(curSi.getDisplayName())) {
if (DBG) log("isUpdateTabsNeeded: UPDATE, new name=" if (DBG) log("isUpdateTabsNeeded: UPDATE, new name="
+ newSi.getDisplayName()); + newSi.getDisplayName());
state = MobileNetworkSettings.TabState.UPDATE; state = TabState.UPDATE;
break; break;
} }
} }
@@ -530,28 +532,26 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
public void onCreate(Bundle icicle) { public void onCreate(Bundle icicle) {
Log.i(LOG_TAG, "onCreate:+"); Log.i(LOG_TAG, "onCreate:+");
super.onCreate(icicle); super.onCreate(icicle);
final Context context = getContext();
final Activity activity = getActivity(); if (context == null) {
if (activity == null || activity.isDestroyed()) {
Log.e(LOG_TAG, "onCreate:- with no valid activity."); Log.e(LOG_TAG, "onCreate:- with no valid activity.");
return; return;
} }
mHandler = new MobileNetworkSettings.MobileNetworkFragment.MyHandler(); mHandler = new MyHandler();
mUm = (UserManager) activity.getSystemService(Context.USER_SERVICE); mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
mSubscriptionManager = SubscriptionManager.from(activity); mSubscriptionManager = SubscriptionManager.from(context);
mTelephonyManager = (TelephonyManager) activity.getSystemService( mTelephonyManager = (TelephonyManager) context.getSystemService(
Context.TELEPHONY_SERVICE); Context.TELEPHONY_SERVICE);
mCarrierConfigManager = new CarrierConfigManager(getContext()); mCarrierConfigManager = new CarrierConfigManager(getContext());
if (icicle != null) { if (icicle != null) {
mExpandAdvancedFields = icicle.getBoolean(EXPAND_ADVANCED_FIELDS, false); mExpandAdvancedFields = icicle.getBoolean(EXPAND_ADVANCED_FIELDS, false);
} else if (getActivity().getIntent().getBooleanExtra(EXPAND_EXTRA, false)) { } else if (getIntent().getBooleanExtra(EXPAND_EXTRA, false)) {
mExpandAdvancedFields = true; mExpandAdvancedFields = true;
} }
addPreferencesFromResource(R.xml.network_setting_fragment);
mButton4glte = (SwitchPreference)findPreference(BUTTON_4G_LTE_KEY); mButton4glte = (SwitchPreference)findPreference(BUTTON_4G_LTE_KEY);
mButton4glte.setOnPreferenceChangeListener(this); mButton4glte.setOnPreferenceChangeListener(this);
@@ -562,7 +562,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
mDataUsagePref = (DataUsagePreference) findPreference(BUTTON_DATA_USAGE_KEY); mDataUsagePref = (DataUsagePreference) findPreference(BUTTON_DATA_USAGE_KEY);
try { try {
Context con = activity.createPackageContext("com.android.systemui", 0); Context con = context.createPackageContext("com.android.systemui", 0);
int id = con.getResources().getIdentifier("config_show4GForLTE", int id = con.getResources().getIdentifier("config_show4GForLTE",
"bool", "com.android.systemui"); "bool", "com.android.systemui");
mShow4GForLTE = con.getResources().getBoolean(id); mShow4GForLTE = con.getResources().getBoolean(id);
@@ -614,7 +614,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
if (mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS) if (mUm.hasUserRestriction(UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)
|| !mUm.isSystemUser()) { || !mUm.isSystemUser()) {
mUnavailable = true; mUnavailable = true;
getActivity().setContentView(R.layout.telephony_disallowed_preference_screen); //TODO(b/114749736): migrate telephony_disallowed_preference_screen.xml
} else { } else {
initializeSubscriptions(); initializeSubscriptions();
updateCurrentTab(getActivity().getIntent()); updateCurrentTab(getActivity().getIntent());
@@ -692,7 +692,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener); mSubscriptionManager.addOnSubscriptionsChangedListener(mOnSubscriptionsChangeListener);
final Context context = getActivity(); final Context context = getContext();
IntentFilter intentFilter = new IntentFilter( IntentFilter intentFilter = new IntentFilter(
TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED); TelephonyIntents.ACTION_RADIO_TECHNOLOGY_CHANGED);
context.registerReceiver(mPhoneChangeReceiver, intentFilter); context.registerReceiver(mPhoneChangeReceiver, intentFilter);
@@ -703,13 +703,23 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} }
@Override
protected int getPreferenceScreenResId() {
return R.xml.network_setting_fragment;
}
@Override
protected String getLogTag() {
return null;
}
private boolean hasActiveSubscriptions() { private boolean hasActiveSubscriptions() {
return mActiveSubInfos.size() > 0; return mActiveSubInfos.size() > 0;
} }
private void updateBodyBasicFields(Activity activity, PreferenceScreen prefSet, private void updateBodyBasicFields(FragmentActivity activity, PreferenceScreen prefSet,
int phoneSubId, boolean hasActiveSubscriptions) { int phoneSubId, boolean hasActiveSubscriptions) {
Context context = activity.getApplicationContext(); Context context = getContext();
ActionBar actionBar = activity.getActionBar(); ActionBar actionBar = activity.getActionBar();
if (actionBar != null) { if (actionBar != null) {
@@ -732,7 +742,6 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
// Initialize states of mButtonDataRoam. // Initialize states of mButtonDataRoam.
mButtonDataRoam.setChecked(mTelephonyManager.isDataRoamingEnabled()); mButtonDataRoam.setChecked(mTelephonyManager.isDataRoamingEnabled());
mButtonDataRoam.setDisabledByAdmin(false);
if (mButtonDataRoam.isEnabled()) { if (mButtonDataRoam.isEnabled()) {
if (RestrictedLockUtilsInternal.hasBaseUserRestriction(context, if (RestrictedLockUtilsInternal.hasBaseUserRestriction(context,
UserManager.DISALLOW_DATA_ROAMING, UserHandle.myUserId())) { UserManager.DISALLOW_DATA_ROAMING, UserHandle.myUserId())) {
@@ -746,11 +755,11 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} }
private void updateBody() { private void updateBody() {
final Activity activity = getActivity(); final FragmentActivity activity = getActivity();
final PreferenceScreen prefSet = getPreferenceScreen(); final PreferenceScreen prefSet = getPreferenceScreen();
final boolean hasActiveSubscriptions = hasActiveSubscriptions(); final boolean hasActiveSubscriptions = hasActiveSubscriptions();
if (activity == null || activity.isDestroyed()) { if (activity == null) {
Log.e(LOG_TAG, "updateBody with no valid activity."); Log.e(LOG_TAG, "updateBody with no valid activity.");
return; return;
} }
@@ -772,14 +781,14 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} }
} else { } else {
// Shows the "Carrier" preference that allows user to add a e-sim profile. // Shows the "Carrier" preference that allows user to add a e-sim profile.
if (showEuiccSettings(getContext())) { if (MobileNetworkUtils.showEuiccSettings(getContext())) {
mEuiccSettingsPref.setSummary(null /* summary */); mEuiccSettingsPref.setSummary(null /* summary */);
prefSet.addPreference(mEuiccSettingsPref); prefSet.addPreference(mEuiccSettingsPref);
} }
} }
} }
private void updateBodyAdvancedFields(Activity activity, PreferenceScreen prefSet, private void updateBodyAdvancedFields(FragmentActivity activity, PreferenceScreen prefSet,
int phoneSubId, boolean hasActiveSubscriptions) { int phoneSubId, boolean hasActiveSubscriptions) {
boolean isLteOnCdma = mTelephonyManager.getLteOnCdmaMode() boolean isLteOnCdma = mTelephonyManager.getLteOnCdmaMode()
== PhoneConstants.LTE_ON_CDMA_TRUE; == PhoneConstants.LTE_ON_CDMA_TRUE;
@@ -792,7 +801,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
prefSet.addPreference(mButtonEnabledNetworks); prefSet.addPreference(mButtonEnabledNetworks);
prefSet.addPreference(mButton4glte); prefSet.addPreference(mButton4glte);
if (showEuiccSettings(getActivity())) { if (MobileNetworkUtils.showEuiccSettings(getContext())) {
prefSet.addPreference(mEuiccSettingsPref); prefSet.addPreference(mEuiccSettingsPref);
String spn = mTelephonyManager.getSimOperatorName(); String spn = mTelephonyManager.getSimOperatorName();
if (TextUtils.isEmpty(spn)) { if (TextUtils.isEmpty(spn)) {
@@ -895,11 +904,11 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
UpdatePreferredNetworkModeSummary(settingsNetworkMode); UpdatePreferredNetworkModeSummary(settingsNetworkMode);
UpdateEnabledNetworksValueAndSummary(settingsNetworkMode); UpdateEnabledNetworksValueAndSummary(settingsNetworkMode);
// Display preferred network type based on what modem returns b/18676277 // Display preferred network type based on what modem returns b/18676277
new MobileNetworkSettings.SetPreferredNetworkAsyncTask( new SetPreferredNetworkAsyncTask(
mTelephonyManager, mTelephonyManager,
mSubId, mSubId,
settingsNetworkMode, settingsNetworkMode,
mHandler.obtainMessage(MobileNetworkSettings.MobileNetworkFragment.MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)) mHandler.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE))
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
/** /**
@@ -934,7 +943,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
if (ps != null) { if (ps != null) {
ps.setEnabled(hasActiveSubscriptions); ps.setEnabled(hasActiveSubscriptions);
} }
ps = findPreference(com.android.phone.NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY); ps = findPreference(NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY);
if (ps != null) { if (ps != null) {
ps.setEnabled(hasActiveSubscriptions); ps.setEnabled(hasActiveSubscriptions);
} }
@@ -950,7 +959,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
if (ps != null) { if (ps != null) {
ps.setEnabled(hasActiveSubscriptions); ps.setEnabled(hasActiveSubscriptions);
} }
ps = findPreference(com.android.phone.NetworkOperators.BUTTON_AUTO_SELECT_KEY); ps = findPreference(NetworkOperators.BUTTON_AUTO_SELECT_KEY);
if (ps != null) { if (ps != null) {
ps.setSummary(null); ps.setSummary(null);
if (mTelephonyManager.getServiceState().getRoaming()) { if (mTelephonyManager.getServiceState().getRoaming()) {
@@ -1143,11 +1152,11 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
buttonNetworkMode ); buttonNetworkMode );
//Set the modem network mode //Set the modem network mode
new MobileNetworkSettings.SetPreferredNetworkAsyncTask( new SetPreferredNetworkAsyncTask(
mTelephonyManager, mTelephonyManager,
mSubId, mSubId,
modemNetworkMode, modemNetworkMode,
mHandler.obtainMessage(MobileNetworkSettings.MobileNetworkFragment.MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)) mHandler.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE))
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
} else if (preference == mButtonEnabledNetworks) { } else if (preference == mButtonEnabledNetworks) {
@@ -1195,11 +1204,11 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId, android.provider.Settings.Global.PREFERRED_NETWORK_MODE + phoneSubId,
buttonNetworkMode ); buttonNetworkMode );
//Set the modem network mode //Set the modem network mode
new MobileNetworkSettings.SetPreferredNetworkAsyncTask( new SetPreferredNetworkAsyncTask(
mTelephonyManager, mTelephonyManager,
mSubId, mSubId,
modemNetworkMode, modemNetworkMode,
mHandler.obtainMessage(MobileNetworkSettings.MobileNetworkFragment.MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE)) mHandler.obtainMessage(MyHandler.MESSAGE_SET_PREFERRED_NETWORK_TYPE))
.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); .executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
} }
} else if (preference == mButton4glte) { } else if (preference == mButton4glte) {
@@ -1225,8 +1234,8 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
getMetricsEventCategory(getPreferenceScreen(), mButtonDataRoam)); getMetricsEventCategory(getPreferenceScreen(), mButtonDataRoam));
// First confirm with a warning dialog about charges // First confirm with a warning dialog about charges
mOkClicked = false; mOkClicked = false;
com.android.phone.RoamingDialogFragment RoamingDialogFragment
fragment = new com.android.phone.RoamingDialogFragment(); fragment = new RoamingDialogFragment();
Bundle b = new Bundle(); Bundle b = new Bundle();
b.putInt(RoamingDialogFragment.SUB_ID_KEY, mSubId); b.putInt(RoamingDialogFragment.SUB_ID_KEY, mSubId);
fragment.setArguments(b); fragment.setArguments(b);
@@ -1287,7 +1296,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} }
private void handleSetPreferredNetworkTypeResponse(Message msg) { private void handleSetPreferredNetworkTypeResponse(Message msg) {
final Activity activity = getActivity(); final FragmentActivity activity = getActivity();
if (activity == null || activity.isDestroyed()) { if (activity == null || activity.isDestroyed()) {
// Access preferences of activity only if it is not destroyed // Access preferences of activity only if it is not destroyed
// or if fragment is not attached to an activity. // or if fragment is not attached to an activity.
@@ -1589,7 +1598,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
switch(requestCode) { switch(requestCode) {
case REQUEST_CODE_EXIT_ECM: case REQUEST_CODE_EXIT_ECM:
Boolean isChoiceYes = data.getBooleanExtra( Boolean isChoiceYes = data.getBooleanExtra(
EmergencyCallbackModeExitDialog.EXTRA_EXIT_ECM_RESULT, false); EXTRA_EXIT_ECM_RESULT, false);
if (isChoiceYes) { if (isChoiceYes) {
// If the phone exits from ECM mode, show the CDMA Options // If the phone exits from ECM mode, show the CDMA Options
mCdmaOptions.showDialog(mClickedPreference); mCdmaOptions.showDialog(mClickedPreference);
@@ -1609,7 +1618,8 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} }
// Removes the preference if the wifi calling is disabled. // Removes the preference if the wifi calling is disabled.
if (!isWifiCallingEnabled(getContext(), SubscriptionManager.getPhoneId(mSubId))) { if (!MobileNetworkUtils.isWifiCallingEnabled(getContext(),
SubscriptionManager.getPhoneId(mSubId))) {
mCallingCategory.removePreference(mWiFiCallingPref); mCallingCategory.removePreference(mWiFiCallingPref);
return; return;
} }
@@ -1618,8 +1628,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
TelecomManager.from(getContext()).getSimCallManager(); TelecomManager.from(getContext()).getSimCallManager();
if (simCallManager != null) { if (simCallManager != null) {
Intent intent = MobileNetworkSettings.buildPhoneAccountConfigureIntent( Intent intent = buildPhoneAccountConfigureIntent(getContext(), simCallManager);
getContext(), simCallManager);
PackageManager pm = getContext().getPackageManager(); PackageManager pm = getContext().getPackageManager();
List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0); List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
mWiFiCallingPref.setTitle(resolutions.get(0).loadLabel(pm)); mWiFiCallingPref.setTitle(resolutions.get(0).loadLabel(pm));
@@ -1664,7 +1673,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
if ((mImsMgr == null if ((mImsMgr == null
|| !mImsMgr.isVolteEnabledByPlatform() || !mImsMgr.isVolteEnabledByPlatform()
|| !mImsMgr.isVolteProvisionedOnDevice() || !mImsMgr.isVolteProvisionedOnDevice()
|| !isImsServiceStateReady(mImsMgr) || !MobileNetworkUtils.isImsServiceStateReady(mImsMgr)
|| carrierConfig.getBoolean( || carrierConfig.getBoolean(
CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL))) { CarrierConfigManager.KEY_HIDE_ENHANCED_4G_LTE_BOOL))) {
getPreferenceScreen().removePreference(mButton4glte); getPreferenceScreen().removePreference(mButton4glte);
@@ -1687,7 +1696,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
if (mImsMgr != null if (mImsMgr != null
&& mImsMgr.isVtEnabledByPlatform() && mImsMgr.isVtEnabledByPlatform()
&& mImsMgr.isVtProvisionedOnDevice() && mImsMgr.isVtProvisionedOnDevice()
&& isImsServiceStateReady(mImsMgr) && MobileNetworkUtils.isImsServiceStateReady(mImsMgr)
&& (carrierConfig.getBoolean( && (carrierConfig.getBoolean(
CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS) CarrierConfigManager.KEY_IGNORE_DATA_ENABLED_CHANGED_FOR_VIDEO_CALLS)
|| mTelephonyManager.isDataEnabled())) { || mTelephonyManager.isDataEnabled())) {
@@ -1802,7 +1811,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
PreferenceCategory networkOperatorCategory = PreferenceCategory networkOperatorCategory =
(PreferenceCategory) prefSet.findPreference( (PreferenceCategory) prefSet.findPreference(
com.android.phone.NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY); NetworkOperators.CATEGORY_NETWORK_OPERATORS_KEY);
Preference carrierSettings = prefSet.findPreference(BUTTON_CARRIER_SETTINGS_KEY); Preference carrierSettings = prefSet.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
if (networkOperatorCategory != null) { if (networkOperatorCategory != null) {
if (enable) { if (enable) {
@@ -1822,7 +1831,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
return; return;
} }
updateCdmaOptions(this, prefSet, mSubId); updateCdmaOptions(this, prefSet, mSubId);
com.android.phone.CdmaSystemSelectListPreference systemSelect = CdmaSystemSelectListPreference systemSelect =
(CdmaSystemSelectListPreference)prefSet.findPreference (CdmaSystemSelectListPreference)prefSet.findPreference
(BUTTON_CDMA_SYSTEM_SELECT_KEY); (BUTTON_CDMA_SYSTEM_SELECT_KEY);
systemSelect.setSubscriptionId(mSubId); systemSelect.setSubscriptionId(mSubId);
@@ -1929,7 +1938,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} else if (preference == mVideoCallingPref) { } else if (preference == mVideoCallingPref) {
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_VIDEO_CALLING_TOGGLE; return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_VIDEO_CALLING_TOGGLE;
} else if (preference == preferenceScreen } else if (preference == preferenceScreen
.findPreference(com.android.phone.NetworkOperators.BUTTON_AUTO_SELECT_KEY)) { .findPreference(NetworkOperators.BUTTON_AUTO_SELECT_KEY)) {
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_AUTO_SELECT_NETWORK_TOGGLE; return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_AUTO_SELECT_NETWORK_TOGGLE;
} else if (preference == preferenceScreen } else if (preference == preferenceScreen
.findPreference(NetworkOperators.BUTTON_NETWORK_SELECT_KEY)) { .findPreference(NetworkOperators.BUTTON_NETWORK_SELECT_KEY)) {
@@ -1950,7 +1959,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} }
} }
private void updateGsmUmtsOptions(PreferenceFragment prefFragment, private void updateGsmUmtsOptions(PreferenceFragmentCompat prefFragment,
PreferenceScreen prefScreen, final int subId) { PreferenceScreen prefScreen, final int subId) {
// We don't want to re-create GsmUmtsOptions if already exists. Otherwise, the // We don't want to re-create GsmUmtsOptions if already exists. Otherwise, the
// preferences inside it will also be re-created which causes unexpected behavior. // preferences inside it will also be re-created which causes unexpected behavior.
@@ -1962,7 +1971,7 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
} }
} }
private void updateCdmaOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen, private void updateCdmaOptions(PreferenceFragmentCompat prefFragment, PreferenceScreen prefScreen,
int subId) { int subId) {
// We don't want to re-create CdmaOptions if already exists. Otherwise, the preferences // We don't want to re-create CdmaOptions if already exists. Otherwise, the preferences
// inside it will also be re-created which causes unexpected behavior. For example, // inside it will also be re-created which causes unexpected behavior. For example,
@@ -1973,9 +1982,57 @@ public static class MobileNetworkFragment extends PreferenceFragment implements
mCdmaOptions.updateSubscriptionId(subId); mCdmaOptions.updateSubscriptionId(subId);
} }
} }
}
private static final class SetPreferredNetworkAsyncTask extends AsyncTask<Void, Void, Boolean> { private static Intent buildPhoneAccountConfigureIntent(
Context context, PhoneAccountHandle accountHandle) {
Intent intent = buildConfigureIntent(
context, accountHandle, TelecomManager.ACTION_CONFIGURE_PHONE_ACCOUNT);
if (intent == null) {
// If the new configuration didn't work, try the old configuration intent.
intent = buildConfigureIntent(
context, accountHandle, LEGACY_ACTION_CONFIGURE_PHONE_ACCOUNT);
if (intent != null) {
Log.w(MobileNetworkFragment.LOG_TAG,
"Phone account using old configuration intent: " + accountHandle);
}
}
return intent;
}
private static Intent buildConfigureIntent(
Context context, PhoneAccountHandle accountHandle, String actionStr) {
if (accountHandle == null || accountHandle.getComponentName() == null
|| TextUtils.isEmpty(accountHandle.getComponentName().getPackageName())) {
return null;
}
// Build the settings intent.
Intent intent = new Intent(actionStr);
intent.setPackage(accountHandle.getComponentName().getPackageName());
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(TelecomManager.EXTRA_PHONE_ACCOUNT_HANDLE, accountHandle);
// Check to see that the phone account package can handle the setting intent.
PackageManager pm = context.getPackageManager();
List<ResolveInfo> resolutions = pm.queryIntentActivities(intent, 0);
if (resolutions.size() == 0) {
intent = null; // set no intent if the package cannot handle it.
}
return intent;
}
//TODO(b/114749736): update search provider
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {
@Override
protected boolean isPageSearchEnabled(Context context) {
return false;
}
};
private static final class SetPreferredNetworkAsyncTask extends AsyncTask<Void, Void, Boolean> {
private final TelephonyManager mTelephonyManager; private final TelephonyManager mTelephonyManager;
private final int mSubId; private final int mSubId;
@@ -2000,4 +2057,5 @@ private static final class SetPreferredNetworkAsyncTask extends AsyncTask<Void,
mCallback.obj = isSuccessed; mCallback.obj = isSuccessed;
mCallback.sendToTarget(); mCallback.sendToTarget();
} }
}
} }

View File

@@ -0,0 +1,173 @@
/*
* Copyright (C) 2018 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.
*/
package com.android.settings.mobilenetwork;
import static android.provider.Telephony.Carriers.ENFORCE_MANAGED_URI;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.os.PersistableBundle;
import android.os.SystemProperties;
import android.provider.Settings;
import android.telecom.PhoneAccountHandle;
import android.telecom.TelecomManager;
import android.telephony.TelephonyManager;
import android.telephony.euicc.EuiccManager;
import android.telephony.ims.feature.ImsFeature;
import android.text.TextUtils;
import android.util.Log;
import com.android.ims.ImsException;
import com.android.ims.ImsManager;
import java.util.Arrays;
import java.util.List;
public class MobileNetworkUtils {
private static final String TAG = "MobileNetworkUtils";
// CID of the device.
private static final String KEY_CID = "ro.boot.cid";
// CIDs of devices which should not show anything related to eSIM.
private static final String KEY_ESIM_CID_IGNORE = "ro.setupwizard.esim_cid_ignore";
// System Property which is used to decide whether the default eSIM UI will be shown,
// the default value is false.
private static final String KEY_ENABLE_ESIM_UI_BY_DEFAULT =
"esim.enable_esim_system_ui_by_default";
/**
* Returns if DPC APNs are enforced.
*/
public static boolean isDpcApnEnforced(Context context) {
try (Cursor enforceCursor = context.getContentResolver().query(ENFORCE_MANAGED_URI,
null, null, null, null)) {
if (enforceCursor == null || enforceCursor.getCount() != 1) {
return false;
}
enforceCursor.moveToFirst();
return enforceCursor.getInt(0) > 0;
}
}
/**
* Returns true if Wifi calling is enabled for at least one phone.
*/
public static boolean isWifiCallingEnabled(Context context) {
int phoneCount = TelephonyManager.from(context).getPhoneCount();
for (int i = 0; i < phoneCount; i++) {
if (isWifiCallingEnabled(context, i)) {
return true;
}
}
return false;
}
/**
* Returns true if Wifi calling is enabled for the specific phone with id {@code phoneId}.
*/
public static boolean isWifiCallingEnabled(Context context, int phoneId) {
final PhoneAccountHandle simCallManager =
TelecomManager.from(context).getSimCallManager();
boolean isWifiCallingEnabled;
if (simCallManager != null) {
//TODO(b/114749736): build intent to query wifi calling feature
final Intent intent = null;
PackageManager pm = context.getPackageManager();
isWifiCallingEnabled = intent != null
&& !pm.queryIntentActivities(intent, 0 /* flags */).isEmpty();
} else {
ImsManager imsMgr = ImsManager.getInstance(context, phoneId);
isWifiCallingEnabled = imsMgr != null
&& imsMgr.isWfcEnabledByPlatform()
&& imsMgr.isWfcProvisionedOnDevice()
&& isImsServiceStateReady(imsMgr);
}
return isWifiCallingEnabled;
}
public static boolean isImsServiceStateReady(ImsManager imsMgr) {
boolean isImsServiceStateReady = false;
try {
if (imsMgr != null && imsMgr.getImsServiceState() == ImsFeature.STATE_READY) {
isImsServiceStateReady = true;
}
} catch (ImsException ex) {
Log.e(TAG, "Exception when trying to get ImsServiceStatus: " + ex);
}
Log.d(TAG, "isImsServiceStateReady=" + isImsServiceStateReady);
return isImsServiceStateReady;
}
/**
* Whether to show the entry point to eUICC settings.
*
* <p>We show the entry point on any device which supports eUICC as long as either the eUICC
* was ever provisioned (that is, at least one profile was ever downloaded onto it), or if
* the user has enabled development mode.
*/
public static boolean showEuiccSettings(Context context) {
EuiccManager euiccManager =
(EuiccManager) context.getSystemService(Context.EUICC_SERVICE);
if (!euiccManager.isEnabled()) {
return false;
}
final ContentResolver cr = context.getContentResolver();
TelephonyManager tm =
(TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String currentCountry = tm.getNetworkCountryIso().toLowerCase();
String supportedCountries =
Settings.Global.getString(cr, Settings.Global.EUICC_SUPPORTED_COUNTRIES);
boolean inEsimSupportedCountries = false;
if (TextUtils.isEmpty(currentCountry)) {
inEsimSupportedCountries = true;
} else if (!TextUtils.isEmpty(supportedCountries)) {
List<String> supportedCountryList =
Arrays.asList(TextUtils.split(supportedCountries.toLowerCase(), ","));
if (supportedCountryList.contains(currentCountry)) {
inEsimSupportedCountries = true;
}
}
final boolean esimIgnoredDevice =
Arrays.asList(TextUtils.split(SystemProperties.get(KEY_ESIM_CID_IGNORE, ""), ","))
.contains(SystemProperties.get(KEY_CID, null));
final boolean enabledEsimUiByDefault =
SystemProperties.getBoolean(KEY_ENABLE_ESIM_UI_BY_DEFAULT, true);
final boolean euiccProvisioned =
Settings.Global.getInt(cr, Settings.Global.EUICC_PROVISIONED, 0) != 0;
final boolean inDeveloperMode =
Settings.Global.getInt(cr, Settings.Global.DEVELOPMENT_SETTINGS_ENABLED, 0) != 0;
return (inDeveloperMode || euiccProvisioned
|| (!esimIgnoredDevice && enabledEsimUiByDefault && inEsimSupportedCountries));
}
public static PersistableBundle getCarrierConfigBySubId(int mSubId) {
//TODO(b/114749736): get carrier config from subId
return new PersistableBundle();
}
}

View File

@@ -21,9 +21,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.TwoStatePreference;
import android.telephony.ServiceState; import android.telephony.ServiceState;
import android.telephony.SubscriptionManager; import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
@@ -31,9 +28,13 @@ import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.TwoStatePreference;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.phone.NetworkSelectSettingActivity; import com.android.settings.R;
import com.android.settingslib.utils.ThreadUtils; import com.android.settingslib.utils.ThreadUtils;
/** /**
@@ -273,7 +274,8 @@ public class NetworkOperators extends PreferenceCategory
* Open the Choose network page via {@alink NetworkSelectSettingActivity} * Open the Choose network page via {@alink NetworkSelectSettingActivity}
*/ */
public void openChooseNetworkPage() { public void openChooseNetworkPage() {
Intent intent = NetworkSelectSettingActivity.getIntent(getContext(), mSubId); //TODO(b/114749736): Build intent without calling static method
Intent intent = new Intent();
getContext().startActivity(intent); getContext().startActivity(intent);
} }

View File

@@ -27,7 +27,6 @@ import android.telephony.TelephonyScanManager;
import android.util.Log; import android.util.Log;
import com.android.internal.telephony.CellNetworkScanResult; import com.android.internal.telephony.CellNetworkScanResult;
import com.android.phone.CellInfoUtil;
import com.google.common.util.concurrent.FutureCallback; import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.Futures;

View File

@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.phone; package com.android.settings.mobilenetwork;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
@@ -24,8 +24,6 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.preference.ListPreference;
import android.preference.Preference;
import android.telephony.CellInfo; import android.telephony.CellInfo;
import android.telephony.CellInfoCdma; import android.telephony.CellInfoCdma;
import android.telephony.CellInfoGsm; import android.telephony.CellInfoGsm;
@@ -43,7 +41,7 @@ import android.widget.Toast;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.OperatorInfo; import com.android.internal.telephony.OperatorInfo;
import com.android.phone.NetworkScanHelper.NetworkScanCallback; import com.android.settings.R;
import com.android.settingslib.utils.ThreadUtils; import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList; import java.util.ArrayList;
@@ -52,6 +50,9 @@ import java.util.List;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
/** /**
* "Networks" preference in "Mobile network" settings UI for the Phone app. * "Networks" preference in "Mobile network" settings UI for the Phone app.
@@ -159,7 +160,8 @@ public class NetworkSelectListPreference extends ListPreference
} }
}; };
private final NetworkScanHelper.NetworkScanCallback mCallback = new NetworkScanCallback() { private final NetworkScanHelper.NetworkScanCallback mCallback =
new NetworkScanHelper.NetworkScanCallback() {
public void onResults(List<CellInfo> results) { public void onResults(List<CellInfo> results) {
if (DBG) logd("get scan results: " + results.toString()); if (DBG) logd("get scan results: " + results.toString());
Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_RESULTS, results); Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_RESULTS, results);
@@ -189,9 +191,8 @@ public class NetworkSelectListPreference extends ListPreference
mNetworkOperators.getNetworkSelectionMode(); mNetworkOperators.getNetworkSelectionMode();
} }
@Override //TODO(b/114749736): move this logic to preference controller
protected void onDialogClosed(boolean positiveResult) { protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
// If dismissed, we query NetworkSelectMode and update states of AutoSelect button. // If dismissed, we query NetworkSelectMode and update states of AutoSelect button.
if (!positiveResult) { if (!positiveResult) {
mNetworkOperators.getNetworkSelectionMode(); mNetworkOperators.getNetworkSelectionMode();

View File

@@ -31,6 +31,10 @@ import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
import android.view.View; import android.view.View;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.MetricsLogger; import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.OperatorInfo; import com.android.internal.telephony.OperatorInfo;
@@ -47,10 +51,6 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
/** /**
* "Choose network" settings UI for the Phone app. * "Choose network" settings UI for the Phone app.
*/ */

View File

@@ -17,9 +17,6 @@ package com.android.settings.mobilenetwork;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog; import android.app.Dialog;
import android.app.DialogFragment;
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener; import android.content.DialogInterface.OnClickListener;
@@ -27,11 +24,19 @@ import android.os.Bundle;
import android.os.PersistableBundle; import android.os.PersistableBundle;
import android.telephony.CarrierConfigManager; import android.telephony.CarrierConfigManager;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
/** /**
* A dialog fragment that asks the user if they are sure they want to turn on data roaming * A dialog fragment that asks the user if they are sure they want to turn on data roaming
* to avoid accidental charges. * to avoid accidental charges.
*/ */
public class RoamingDialogFragment extends DialogFragment implements OnClickListener { public class RoamingDialogFragment extends InstrumentedDialogFragment implements OnClickListener {
public static final String SUB_ID_KEY = "sub_id_key"; public static final String SUB_ID_KEY = "sub_id_key";
@@ -55,9 +60,8 @@ public class RoamingDialogFragment extends DialogFragment implements OnClickList
mSubId = args.getInt(SUB_ID_KEY); mSubId = args.getInt(SUB_ID_KEY);
mCarrierConfigManager = new CarrierConfigManager(context); mCarrierConfigManager = new CarrierConfigManager(context);
// Verify host activity implemented callback interface //TODO(b/114749736): set target fragment in host fragment
FragmentManager fragmentManager = getFragmentManager(); Fragment fragment = getTargetFragment();
Fragment fragment = fragmentManager.findFragmentById(R.id.network_setting_content);
try { try {
mListener = (RoamingDialogListener) fragment; mListener = (RoamingDialogListener) fragment;
} catch (ClassCastException e) { } catch (ClassCastException e) {
@@ -68,7 +72,7 @@ public class RoamingDialogFragment extends DialogFragment implements OnClickList
@Override @Override
public Dialog onCreateDialog(Bundle savedInstanceState) { public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
int title = R.string.roaming_alert_title; int title = R.string.roaming_alert_title;
PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId); PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
if (carrierConfig != null && carrierConfig.getBoolean( if (carrierConfig != null && carrierConfig.getBoolean(
@@ -83,6 +87,12 @@ public class RoamingDialogFragment extends DialogFragment implements OnClickList
return builder.create(); return builder.create();
} }
@Override
public int getMetricsCategory() {
//TODO(b/114749736): add category for roaming dialog
return 0;
}
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
// let the host know that the positive button has been clicked // let the host know that the positive button has been clicked