Snap for 5075986 from 5b0c051dcd to qt-release
Change-Id: I7728cf3c77578e595b206bcd44eee7a731a29668
This commit is contained in:
28
res/drawable/ic_apps_filter_settings_24dp.xml
Normal file
28
res/drawable/ic_apps_filter_settings_24dp.xml
Normal file
@@ -0,0 +1,28 @@
|
||||
<!--
|
||||
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.
|
||||
-->
|
||||
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="?android:attr/colorAccent"
|
||||
android:pathData="M13.85,22.25h-3.7c-0.74,0 -1.36,-0.54 -1.45,-1.27l-0.27,-1.89c-0.27,-0.14 -0.53,-0.29 -0.79,-0.46l-1.8,0.72c-0.7,0.26 -1.47,-0.03 -1.81,-0.65L2.2,15.53c-0.35,-0.66 -0.2,-1.44 0.36,-1.88l1.53,-1.19c-0.01,-0.15 -0.02,-0.3 -0.02,-0.46c0,-0.15 0.01,-0.31 0.02,-0.46l-1.52,-1.19C1.98,9.9 1.83,9.09 2.2,8.47l1.85,-3.19c0.34,-0.62 1.11,-0.9 1.79,-0.63l1.81,0.73c0.26,-0.17 0.52,-0.32 0.78,-0.46l0.27,-1.91c0.09,-0.7 0.71,-1.25 1.44,-1.25h3.7c0.74,0 1.36,0.54 1.45,1.27l0.27,1.89c0.27,0.14 0.53,0.29 0.79,0.46l1.8,-0.72c0.71,-0.26 1.48,0.03 1.82,0.65l1.84,3.18c0.36,0.66 0.2,1.44 -0.36,1.88l-1.52,1.19c0.01,0.15 0.02,0.3 0.02,0.46s-0.01,0.31 -0.02,0.46l1.52,1.19c0.56,0.45 0.72,1.23 0.37,1.86l-1.86,3.22c-0.34,0.62 -1.11,0.9 -1.8,0.63l-1.8,-0.72c-0.26,0.17 -0.52,0.32 -0.78,0.46l-0.27,1.91C15.21,21.71 14.59,22.25 13.85,22.25zM13.32,20.72c0,0.01 0,0.01 0,0.02L13.32,20.72zM10.68,20.7l0,0.02C10.69,20.72 10.69,20.71 10.68,20.7zM10.62,20.25h2.76l0.37,-2.55l0.53,-0.22c0.44,-0.18 0.88,-0.44 1.34,-0.78l0.45,-0.34l2.38,0.96l1.38,-2.4l-2.03,-1.58l0.07,-0.56c0.03,-0.26 0.06,-0.51 0.06,-0.78c0,-0.27 -0.03,-0.53 -0.06,-0.78l-0.07,-0.56l2.03,-1.58l-1.39,-2.4l-2.39,0.96l-0.45,-0.35c-0.42,-0.32 -0.87,-0.58 -1.33,-0.77L13.75,6.3l-0.37,-2.55h-2.76L10.25,6.3L9.72,6.51C9.28,6.7 8.84,6.95 8.38,7.3L7.93,7.63L5.55,6.68L4.16,9.07l2.03,1.58l-0.07,0.56C6.09,11.47 6.06,11.74 6.06,12c0,0.26 0.02,0.53 0.06,0.78l0.07,0.56l-2.03,1.58l1.38,2.4l2.39,-0.96l0.45,0.35c0.43,0.33 0.86,0.58 1.33,0.77l0.53,0.22L10.62,20.25zM18.22,17.72c0,0.01 -0.01,0.02 -0.01,0.03L18.22,17.72zM5.77,17.71l0.01,0.02C5.78,17.72 5.77,17.71 5.77,17.71zM3.93,9.47L3.93,9.47C3.93,9.47 3.93,9.47 3.93,9.47zM18.22,6.27c0,0.01 0.01,0.02 0.01,0.02L18.22,6.27zM5.79,6.25L5.78,6.27C5.78,6.27 5.79,6.26 5.79,6.25zM13.31,3.28c0,0.01 0,0.01 0,0.02L13.31,3.28zM10.69,3.26l0,0.02C10.69,3.27 10.69,3.27 10.69,3.26z"/>
|
||||
<path
|
||||
android:fillColor="?android:attr/colorAccent"
|
||||
android:pathData="M12,12m-3.5,0a3.5,3.5 0,1 1,7 0a3.5,3.5 0,1 1,-7 0"/>
|
||||
</vector>
|
||||
@@ -37,7 +37,7 @@
|
||||
android:layout_toRightOf="@id/filter_spinner"
|
||||
android:contentDescription="@string/configure"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_settings_24dp"
|
||||
android:src="@drawable/ic_apps_filter_settings_24dp"
|
||||
android:visibility="gone"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2014 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.
|
||||
-->
|
||||
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@android:id/text1"
|
||||
style="?android:attr/spinnerItemStyle"
|
||||
android:singleLine="true"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingStart="0dp"
|
||||
android:ellipsize="marquee"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textAlignment="inherit" />
|
||||
@@ -14,21 +14,17 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
|
||||
android:orientation="horizontal">
|
||||
android:minHeight="?android:attr/listPreferredItemHeight">
|
||||
|
||||
<Spinner
|
||||
<com.android.settingslib.widget.settingsspinner.SettingsSpinner
|
||||
android:id="@+id/cycles_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:paddingLeft="0dp"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Subhead"
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_centerInParent="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
@@ -17,12 +17,9 @@
|
||||
<androidx.cardview.widget.CardView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
style="@style/SuggestionConditionStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:cardUseCompatPadding="true"
|
||||
app:cardElevation="@dimen/condition_card_elevation"
|
||||
app:cardCornerRadius="@dimen/suggestion_card_corner_radius">
|
||||
style="@style/ContextualCardStyle">
|
||||
|
||||
<include layout="@layout/condition_tile"/>
|
||||
|
||||
|
||||
@@ -20,12 +20,7 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/homepage_card_top_margin"
|
||||
android:layout_marginBottom="@dimen/homepage_card_bottom_margin"
|
||||
android:layout_marginStart="@dimen/homepage_card_side_margin"
|
||||
android:layout_marginEnd="@dimen/homepage_card_side_margin"
|
||||
app:cardCornerRadius="@dimen/homepage_card_corner_radius"
|
||||
app:cardElevation="@dimen/homepage_card_elevation">
|
||||
style="@style/ContextualCardStyle">
|
||||
|
||||
<androidx.slice.widget.SliceView
|
||||
android:id="@+id/slice_view"
|
||||
|
||||
@@ -24,11 +24,11 @@
|
||||
|
||||
<Toolbar
|
||||
android:id="@+id/action_bar"
|
||||
style="?android:attr/actionBarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:navigationContentDescription="@*android:string/action_bar_up_description"
|
||||
android:theme="?android:attr/actionBarTheme"
|
||||
style="?android:attr/actionBarStyle"/>
|
||||
android:theme="?android:attr/actionBarTheme"/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/main_content"
|
||||
|
||||
@@ -10259,6 +10259,9 @@
|
||||
<!-- 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>
|
||||
|
||||
<!-- Title for mobile data preference, to display the mobile data usage for each app. [CHAR LIMIT=NONE]-->
|
||||
<string name="mobile_data_usage_title">App data usage</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>
|
||||
|
||||
@@ -458,4 +458,13 @@
|
||||
<item name="android:paddingBottom">24dp</item>
|
||||
</style>
|
||||
|
||||
<style name="ContextualCardStyle">
|
||||
<item name="android:layout_marginTop">@dimen/homepage_card_top_margin</item>
|
||||
<item name="android:layout_marginBottom">@dimen/homepage_card_bottom_margin</item>
|
||||
<item name="android:layout_marginStart">@dimen/homepage_card_side_margin</item>
|
||||
<item name="android:layout_marginEnd">@dimen/homepage_card_side_margin</item>
|
||||
<item name="cardCornerRadius">@dimen/homepage_card_corner_radius</item>
|
||||
<item name="cardElevation">@dimen/homepage_card_elevation</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -183,7 +183,6 @@
|
||||
|
||||
<!-- Accessibility portion of Setup Wizard -->
|
||||
<style name="SetupWizardAccessibilityTheme" parent="Theme.SettingsBase">
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
<item name="android:colorPrimary">@color/material_grey_100</item>
|
||||
<item name="android:colorAccent">@color/material_blue_700</item>
|
||||
<item name="android:titleTextColor">@color/material_blue_700</item>
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?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">
|
||||
|
||||
<com.android.settings.network.telephony.CdmaSubscriptionListPreference
|
||||
android:key="cdma_subscription_key"
|
||||
android:title="@string/cdma_subscription_title"
|
||||
android:summary="@string/cdma_subscription_summary"
|
||||
android:entries="@array/cdma_subscription_choices"
|
||||
android:entryValues="@array/cdma_subscription_values"
|
||||
android:dialogTitle="@string/cdma_subscription_dialogtitle" />
|
||||
|
||||
<!--We want separate APN setting from reset of settings because-->
|
||||
<!--we want user to change it with caution.-->
|
||||
<PreferenceCategory
|
||||
android:key="category_cdma_apn_key">
|
||||
<!-- The launching Intent will be defined thru code as we need to pass some Extra -->
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="button_cdma_apn_key"
|
||||
android:title="@string/apn_settings"
|
||||
android:persistent="false"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<Preference
|
||||
android:key="carrier_settings_key"
|
||||
android:title="@string/carrier_settings_title">
|
||||
<!-- b/114749736, create a preference controller to build intent -->
|
||||
</Preference>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -27,7 +27,7 @@
|
||||
android:title="@string/select_automatically"
|
||||
android:persistent="false"/>
|
||||
|
||||
<com.android.settings.mobilenetwork.NetworkSelectListPreference
|
||||
<com.android.settings.network.telephony.NetworkSelectListPreference
|
||||
android:key="button_network_select_key"
|
||||
android:title="@string/network_select_title"
|
||||
android:persistent="false"/>
|
||||
|
||||
@@ -36,11 +36,14 @@
|
||||
android:title="@string/roaming"
|
||||
android:persistent="false"
|
||||
android:summaryOn="@string/roaming_enable"
|
||||
android:summaryOff="@string/roaming_disable"/>
|
||||
android:summaryOff="@string/roaming_disable"
|
||||
settings:userRestriction="no_data_roaming"
|
||||
settings:controller="com.android.settings.network.telephony.RoamingPreferenceController"/>
|
||||
|
||||
<com.android.settings.network.telephony.DataUsagePreference
|
||||
<Preference
|
||||
android:key="data_usage_summary"
|
||||
android:title="@string/data_usage_title" />
|
||||
android:title="@string/mobile_data_usage_title"
|
||||
settings:controller="com.android.settings.network.telephony.DataUsagePreferenceController"/>
|
||||
|
||||
<SwitchPreference
|
||||
android:key="enhanced_4g_lte"
|
||||
@@ -100,4 +103,29 @@
|
||||
android:dialogTitle="@string/cdma_system_select_dialogtitle"
|
||||
settings:controller="com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController"/>
|
||||
|
||||
<ListPreference
|
||||
android:key="cdma_subscription_key"
|
||||
android:title="@string/cdma_subscription_title"
|
||||
android:summary="@string/cdma_subscription_summary"
|
||||
android:entries="@array/cdma_subscription_choices"
|
||||
android:entryValues="@array/cdma_subscription_values"
|
||||
android:dialogTitle="@string/cdma_subscription_dialogtitle"
|
||||
settings:controller="com.android.settings.network.telephony.cdma.CdmaSubscriptionPreferenceController"/>
|
||||
|
||||
<!--We want separate APN setting from reset of settings because we want user to change it with caution-->
|
||||
<PreferenceCategory
|
||||
android:key="category_cdma_apn_key">
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="button_cdma_apn_key"
|
||||
android:title="@string/apn_settings"
|
||||
android:persistent="false"
|
||||
settings:controller="com.android.settings.network.telephony.cdma.CdmaApnPreferenceController"/>
|
||||
</PreferenceCategory>
|
||||
|
||||
<Preference
|
||||
android:key="carrier_settings_key"
|
||||
android:title="@string/carrier_settings_title"
|
||||
settings:controller="com.android.settings.network.telephony.CarrierPreferenceController">
|
||||
</Preference>
|
||||
|
||||
</PreferenceScreen>
|
||||
|
||||
@@ -113,7 +113,7 @@ public class ProxySelector extends InstrumentedFragment implements DialogCreatab
|
||||
if (mDialogFragment != null) {
|
||||
Log.e(TAG, "Old dialog fragment not null!");
|
||||
}
|
||||
mDialogFragment = new SettingsDialogFragment(this, dialogId);
|
||||
mDialogFragment = SettingsDialogFragment.newInstance(this, dialogId);
|
||||
mDialogFragment.show(getActivity().getSupportFragmentManager(), Integer.toString(dialogId));
|
||||
}
|
||||
|
||||
|
||||
@@ -454,7 +454,7 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
if (mDialogFragment != null) {
|
||||
Log.e(TAG, "Old dialog fragment not null!");
|
||||
}
|
||||
mDialogFragment = new SettingsDialogFragment(this, dialogId);
|
||||
mDialogFragment = SettingsDialogFragment.newInstance(this, dialogId);
|
||||
mDialogFragment.show(getChildFragmentManager(), Integer.toString(dialogId));
|
||||
}
|
||||
|
||||
@@ -541,22 +541,26 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
private DialogInterface.OnCancelListener mOnCancelListener;
|
||||
private DialogInterface.OnDismissListener mOnDismissListener;
|
||||
|
||||
public SettingsDialogFragment(DialogCreatable fragment, int dialogId) {
|
||||
super(fragment, dialogId);
|
||||
public static SettingsDialogFragment newInstance(DialogCreatable fragment, int dialogId) {
|
||||
if (!(fragment instanceof Fragment)) {
|
||||
throw new IllegalArgumentException("fragment argument must be an instance of "
|
||||
+ Fragment.class.getName());
|
||||
}
|
||||
mParentFragment = (Fragment) fragment;
|
||||
}
|
||||
|
||||
final SettingsDialogFragment settingsDialogFragment = new SettingsDialogFragment();
|
||||
settingsDialogFragment.setParentFragment(fragment);
|
||||
settingsDialogFragment.setDialogId(dialogId);
|
||||
|
||||
return settingsDialogFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMetricsCategory() {
|
||||
if (mDialogCreatable == null) {
|
||||
if (mParentFragment == null) {
|
||||
return Instrumentable.METRICS_CATEGORY_UNKNOWN;
|
||||
}
|
||||
final int metricsCategory = mDialogCreatable.getDialogMetricsCategory(mDialogId);
|
||||
final int metricsCategory =
|
||||
((DialogCreatable) mParentFragment).getDialogMetricsCategory(mDialogId);
|
||||
if (metricsCategory <= 0) {
|
||||
throw new IllegalStateException("Dialog must provide a metrics category");
|
||||
}
|
||||
@@ -639,6 +643,14 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setParentFragment(DialogCreatable fragment) {
|
||||
mParentFragment = (Fragment) fragment;
|
||||
}
|
||||
|
||||
private void setDialogId(int dialogId) {
|
||||
mDialogId = dialogId;
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean hasNextButton() {
|
||||
|
||||
@@ -144,7 +144,7 @@ public class AppDataUsage extends DataUsageBaseFragment implements OnPreferenceC
|
||||
mBackgroundUsage = findPreference(KEY_BACKGROUND_USAGE);
|
||||
|
||||
mCycle = (SpinnerPreference) findPreference(KEY_CYCLE);
|
||||
mCycleAdapter = new CycleAdapter(getContext(), mCycle, mCycleListener, false);
|
||||
mCycleAdapter = new CycleAdapter(getContext(), mCycle, mCycleListener);
|
||||
|
||||
if (mAppItem.key > 0) {
|
||||
if (mPackages.size() != 0) {
|
||||
|
||||
@@ -131,7 +131,7 @@ public class AppDataUsageV2 extends DataUsageBaseFragment implements OnPreferenc
|
||||
mBackgroundUsage = findPreference(KEY_BACKGROUND_USAGE);
|
||||
|
||||
mCycle = (SpinnerPreference) findPreference(KEY_CYCLE);
|
||||
mCycleAdapter = new CycleAdapter(getContext(), mCycle, mCycleListener, false);
|
||||
mCycleAdapter = new CycleAdapter(getContext(), mCycle, mCycleListener);
|
||||
|
||||
if (mAppItem.key > 0) {
|
||||
if (mPackages.size() != 0) {
|
||||
|
||||
@@ -20,28 +20,25 @@ import android.net.NetworkStatsHistory;
|
||||
import android.text.format.DateUtils;
|
||||
import android.util.Pair;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settingslib.net.ChartData;
|
||||
import com.android.settingslib.net.NetworkCycleData;
|
||||
import com.android.settingslib.widget.settingsspinner.SettingsSpinnerAdapter;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class CycleAdapter extends ArrayAdapter<CycleAdapter.CycleItem> {
|
||||
public class CycleAdapter extends SettingsSpinnerAdapter<CycleAdapter.CycleItem> {
|
||||
|
||||
private final SpinnerInterface mSpinner;
|
||||
private final AdapterView.OnItemSelectedListener mListener;
|
||||
|
||||
public CycleAdapter(Context context, SpinnerInterface spinner,
|
||||
AdapterView.OnItemSelectedListener listener, boolean isHeader) {
|
||||
super(context, isHeader ? R.layout.filter_spinner_item
|
||||
: R.layout.data_usage_cycle_item);
|
||||
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||
AdapterView.OnItemSelectedListener listener) {
|
||||
super(context);
|
||||
mSpinner = spinner;
|
||||
mListener = listener;
|
||||
mSpinner.setAdapter(this);
|
||||
@@ -159,7 +156,7 @@ public class CycleAdapter extends ArrayAdapter<CycleAdapter.CycleItem> {
|
||||
public boolean updateCycleList(List<? extends NetworkCycleData> cycleData) {
|
||||
// stash away currently selected cycle to try restoring below
|
||||
final CycleAdapter.CycleItem previousItem = (CycleAdapter.CycleItem)
|
||||
mSpinner.getSelectedItem();
|
||||
mSpinner.getSelectedItem();
|
||||
clear();
|
||||
|
||||
final Context context = getContext();
|
||||
@@ -223,8 +220,11 @@ public class CycleAdapter extends ArrayAdapter<CycleAdapter.CycleItem> {
|
||||
|
||||
public interface SpinnerInterface {
|
||||
void setAdapter(CycleAdapter cycleAdapter);
|
||||
|
||||
void setOnItemSelectedListener(AdapterView.OnItemSelectedListener listener);
|
||||
|
||||
Object getSelectedItem();
|
||||
|
||||
void setSelection(int position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -182,7 +182,7 @@ public class DataUsageList extends DataUsageBaseFragment {
|
||||
public void setSelection(int position) {
|
||||
mCycleSpinner.setSelection(position);
|
||||
}
|
||||
}, mCycleListener, true);
|
||||
}, mCycleListener);
|
||||
|
||||
mLoadingViewController = new LoadingViewController(
|
||||
getView().findViewById(R.id.loading_container), getListView());
|
||||
|
||||
@@ -175,7 +175,7 @@ public class DataUsageListV2 extends DataUsageBaseFragment {
|
||||
public void setSelection(int position) {
|
||||
mCycleSpinner.setSelection(position);
|
||||
}
|
||||
}, mCycleListener, true);
|
||||
}, mCycleListener);
|
||||
|
||||
mLoadingViewController = new LoadingViewController(
|
||||
getView().findViewById(R.id.loading_container), getListView());
|
||||
|
||||
@@ -18,12 +18,12 @@ import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Spinner;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceViewHolder;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.widget.settingsspinner.SettingsSpinner;
|
||||
|
||||
public class SpinnerPreference extends Preference implements CycleAdapter.SpinnerInterface {
|
||||
|
||||
@@ -63,7 +63,7 @@ public class SpinnerPreference extends Preference implements CycleAdapter.Spinne
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder holder) {
|
||||
super.onBindViewHolder(holder);
|
||||
Spinner spinner = (Spinner) holder.findViewById(R.id.cycles_spinner);
|
||||
SettingsSpinner spinner = (SettingsSpinner) holder.findViewById(R.id.cycles_spinner);
|
||||
spinner.setAdapter(mAdapter);
|
||||
spinner.setSelection(mPosition);
|
||||
spinner.setOnItemSelectedListener(mOnSelectedListener);
|
||||
|
||||
@@ -59,11 +59,15 @@ public class ActionDisabledByAdminDialog extends Activity
|
||||
}
|
||||
admin.component = intent.getParcelableExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN);
|
||||
|
||||
int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
if (userId == UserHandle.USER_NULL) {
|
||||
admin.user = null;
|
||||
if (intent.hasExtra(Intent.EXTRA_USER)) {
|
||||
admin.user = intent.getParcelableExtra(Intent.EXTRA_USER);
|
||||
} else {
|
||||
admin.user = UserHandle.of(userId);
|
||||
int userId = intent.getIntExtra(Intent.EXTRA_USER_ID, UserHandle.myUserId());
|
||||
if (userId == UserHandle.USER_NULL) {
|
||||
admin.user = null;
|
||||
} else {
|
||||
admin.user = UserHandle.of(userId);
|
||||
}
|
||||
}
|
||||
return admin;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.NetworkUtils;
|
||||
import android.provider.Settings;
|
||||
import android.system.Os;
|
||||
import android.text.Editable;
|
||||
@@ -72,8 +73,6 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
|
||||
PRIVATE_DNS_MAP.put(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME, R.id.private_dns_mode_provider);
|
||||
}
|
||||
|
||||
private static final int[] ADDRESS_FAMILIES = new int[] {AF_INET, AF_INET6};
|
||||
|
||||
@VisibleForTesting
|
||||
static final String MODE_KEY = Settings.Global.PRIVATE_DNS_MODE;
|
||||
@VisibleForTesting
|
||||
@@ -203,23 +202,6 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
|
||||
updateDialogInfo();
|
||||
}
|
||||
|
||||
private boolean isWeaklyValidatedHostname(String hostname) {
|
||||
// TODO(b/34953048): Use a validation method that permits more accurate,
|
||||
// but still inexpensive, checking of likely valid DNS hostnames.
|
||||
final String WEAK_HOSTNAME_REGEX = "^[a-zA-Z0-9_.-]+$";
|
||||
if (!hostname.matches(WEAK_HOSTNAME_REGEX)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int address_family : ADDRESS_FAMILIES) {
|
||||
if (Os.inet_pton(address_family, hostname) != null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private Button getSaveButton() {
|
||||
final AlertDialog dialog = (AlertDialog) getDialog();
|
||||
if (dialog == null) {
|
||||
@@ -236,7 +218,7 @@ public class PrivateDnsModeDialogPreference extends CustomDialogPreferenceCompat
|
||||
final Button saveButton = getSaveButton();
|
||||
if (saveButton != null) {
|
||||
saveButton.setEnabled(modeProvider
|
||||
? isWeaklyValidatedHostname(mEditText.getText().toString())
|
||||
? NetworkUtils.isWeaklyValidatedHostname(mEditText.getText().toString())
|
||||
: true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import android.net.Network;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
@@ -46,6 +48,8 @@ import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.util.List;
|
||||
@@ -136,6 +140,19 @@ public class PrivateDnsPreferenceController extends BasePreferenceController
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
//TODO(b/112982691): Add policy transparency explaining why this setting is disabled.
|
||||
preference.setEnabled(!isManagedByAdmin());
|
||||
}
|
||||
|
||||
private boolean isManagedByAdmin() {
|
||||
EnforcedAdmin enforcedAdmin = RestrictedLockUtilsInternal.checkIfRestrictionEnforced(
|
||||
mContext, UserManager.DISALLOW_CONFIG_PRIVATE_DNS, UserHandle.myUserId());
|
||||
return enforcedAdmin != null;
|
||||
}
|
||||
|
||||
private class PrivateDnsSettingsObserver extends ContentObserver {
|
||||
public PrivateDnsSettingsObserver(Handler h) {
|
||||
super(h);
|
||||
|
||||
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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.network.telephony;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
/**
|
||||
* Preference controller for "Carrier Settings"
|
||||
*/
|
||||
public class CarrierPreferenceController extends BasePreferenceController {
|
||||
|
||||
@VisibleForTesting
|
||||
CarrierConfigManager mCarrierConfigManager;
|
||||
private int mSubId;
|
||||
|
||||
public CarrierPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mCarrierConfigManager = new CarrierConfigManager(context);
|
||||
}
|
||||
|
||||
public void init(int subId) {
|
||||
mSubId = subId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
||||
|
||||
// Return available if it is in CDMA or GSM mode, and the flag is on
|
||||
return carrierConfig != null
|
||||
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL)
|
||||
&& (MobileNetworkUtils.isCdmaOptions(mContext, mSubId)
|
||||
|| MobileNetworkUtils.isGsmOptions(mContext, mSubId))
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (getPreferenceKey().equals(preference.getKey())) {
|
||||
//TODO(b/117651939): start carrier settings activity
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -16,25 +16,11 @@
|
||||
|
||||
package com.android.settings.network.telephony;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.PersistableBundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
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.logging.MetricsLogger;
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
/**
|
||||
* List of Phone-specific settings screens.
|
||||
@@ -42,137 +28,18 @@ import com.android.settingslib.RestrictedPreference;
|
||||
public class CdmaOptions {
|
||||
private static final String LOG_TAG = "CdmaOptions";
|
||||
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
private CdmaSubscriptionListPreference mButtonCdmaSubscription;
|
||||
private RestrictedPreference mButtonAPNExpand;
|
||||
private Preference mCategoryAPNExpand;
|
||||
private Preference mButtonCarrierSettings;
|
||||
|
||||
private static final String BUTTON_CDMA_SYSTEM_SELECT_KEY = "cdma_system_select_key";
|
||||
private static final String BUTTON_CDMA_SUBSCRIPTION_KEY = "cdma_subscription_key";
|
||||
private static final String BUTTON_CARRIER_SETTINGS_KEY = "carrier_settings_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 PreferenceFragmentCompat mPrefFragment;
|
||||
private PreferenceScreen mPrefScreen;
|
||||
private int mSubId;
|
||||
|
||||
public CdmaOptions(PreferenceFragmentCompat prefFragment, PreferenceScreen prefScreen, int subId) {
|
||||
public CdmaOptions(PreferenceFragmentCompat prefFragment, PreferenceScreen prefScreen,
|
||||
int subId) {
|
||||
mPrefFragment = prefFragment;
|
||||
mPrefScreen = prefScreen;
|
||||
mPrefFragment.addPreferencesFromResource(R.xml.cdma_options);
|
||||
mCarrierConfigManager = new CarrierConfigManager(prefFragment.getContext());
|
||||
|
||||
// Initialize preferences.
|
||||
mButtonCdmaSubscription = (CdmaSubscriptionListPreference) mPrefScreen
|
||||
.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY);
|
||||
mButtonCarrierSettings = mPrefScreen.findPreference(BUTTON_CARRIER_SETTINGS_KEY);
|
||||
mButtonAPNExpand = (RestrictedPreference) mPrefScreen.findPreference(BUTTON_APN_EXPAND_KEY);
|
||||
mCategoryAPNExpand = mPrefScreen.findPreference(CATEGORY_APN_EXPAND_KEY);
|
||||
|
||||
updateSubscriptionId(subId);
|
||||
}
|
||||
|
||||
protected void updateSubscriptionId(int subId) {
|
||||
mSubId = subId;
|
||||
int phoneType = TelephonyManager.from(mPrefFragment.getContext())
|
||||
.createForSubscriptionId(mSubId).getPhoneType();
|
||||
|
||||
PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
||||
// Some CDMA carriers want the APN settings.
|
||||
boolean addAPNExpand = shouldAddApnExpandPreference(phoneType, carrierConfig);
|
||||
boolean addCdmaSubscription =
|
||||
deviceSupportsNvAndRuim();
|
||||
// Read platform settings for carrier settings
|
||||
boolean addCarrierSettings =
|
||||
carrierConfig.getBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL);
|
||||
|
||||
// Making no assumptions of whether they are added or removed at this point.
|
||||
// Calling add or remove explicitly to make sure they are updated.
|
||||
|
||||
if (addAPNExpand) {
|
||||
log("update: addAPNExpand");
|
||||
mButtonAPNExpand.setDisabledByAdmin(
|
||||
MobileNetworkUtils.isDpcApnEnforced(mButtonAPNExpand.getContext())
|
||||
? RestrictedLockUtilsInternal.getDeviceOwner(
|
||||
mButtonAPNExpand.getContext())
|
||||
: null);
|
||||
mButtonAPNExpand.setOnPreferenceClickListener(
|
||||
new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
MetricsLogger.action(mButtonAPNExpand.getContext(),
|
||||
MetricsEvent.ACTION_MOBILE_NETWORK_APN_SETTINGS);
|
||||
// We need to build the Intent by hand as the Preference Framework
|
||||
// does not allow to add an Intent with some extras into a Preference
|
||||
// XML file
|
||||
final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
|
||||
// This will setup the Home and Search affordance
|
||||
intent.putExtra(":settings:show_fragment_as_subsetting", true);
|
||||
intent.putExtra("sub_id", mSubId);
|
||||
mPrefFragment.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
mPrefScreen.addPreference(mCategoryAPNExpand);
|
||||
} else {
|
||||
mPrefScreen.removePreference(mCategoryAPNExpand);
|
||||
}
|
||||
|
||||
if (addCdmaSubscription) {
|
||||
log("Both NV and Ruim supported, ENABLE subscription type selection");
|
||||
mPrefScreen.addPreference(mButtonCdmaSubscription);
|
||||
mButtonCdmaSubscription.setEnabled(true);
|
||||
} else {
|
||||
log("Both NV and Ruim NOT supported, REMOVE subscription type selection");
|
||||
mPrefScreen.removePreference(mButtonCdmaSubscription);
|
||||
}
|
||||
|
||||
if (addCarrierSettings) {
|
||||
mPrefScreen.addPreference(mButtonCarrierSettings);
|
||||
} else {
|
||||
mPrefScreen.removePreference(mButtonCarrierSettings);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether we should add the APN expandable preference based on the phone type and
|
||||
* carrier config
|
||||
*/
|
||||
@VisibleForTesting
|
||||
public static boolean shouldAddApnExpandPreference(int phoneType, PersistableBundle config) {
|
||||
return phoneType == PhoneConstants.PHONE_TYPE_CDMA
|
||||
&& config.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL);
|
||||
}
|
||||
|
||||
private boolean deviceSupportsNvAndRuim() {
|
||||
// retrieve the list of subscription types supported by device.
|
||||
String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
|
||||
boolean nvSupported = false;
|
||||
boolean ruimSupported = false;
|
||||
|
||||
log("deviceSupportsnvAnRum: prop=" + subscriptionsSupported);
|
||||
if (!TextUtils.isEmpty(subscriptionsSupported)) {
|
||||
// Searches through the comma-separated list for a match for "NV"
|
||||
// and "RUIM" to update nvSupported and ruimSupported.
|
||||
for (String subscriptionType : subscriptionsSupported.split(",")) {
|
||||
subscriptionType = subscriptionType.trim();
|
||||
if (subscriptionType.equalsIgnoreCase("NV")) {
|
||||
nvSupported = true;
|
||||
}
|
||||
if (subscriptionType.equalsIgnoreCase("RUIM")) {
|
||||
ruimSupported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log("deviceSupportsnvAnRum: nvSupported=" + nvSupported +
|
||||
" ruimSupported=" + ruimSupported);
|
||||
return (nvSupported && ruimSupported);
|
||||
}
|
||||
|
||||
public boolean preferenceTreeClick(Preference preference) {
|
||||
//TODO(b/114749736): handle it in preferenceController and remove this file
|
||||
if (preference.getKey().equals(BUTTON_CDMA_SYSTEM_SELECT_KEY)) {
|
||||
log("preferenceTreeClick: return BUTTON_CDMA_ROAMING_KEY true");
|
||||
return true;
|
||||
@@ -184,12 +51,6 @@ public class CdmaOptions {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showDialog(Preference preference) {
|
||||
if (preference.getKey().equals(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
|
||||
mButtonCdmaSubscription.showDialog(null);
|
||||
}
|
||||
}
|
||||
|
||||
protected void log(String s) {
|
||||
android.util.Log.d(LOG_TAG, s);
|
||||
}
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
/*
|
||||
* 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.network.telephony;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import androidx.preference.ListPreference;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.internal.telephony.Phone;
|
||||
import com.android.settingslib.utils.ThreadUtils;
|
||||
|
||||
public class CdmaSubscriptionListPreference extends ListPreference {
|
||||
|
||||
private static final String LOG_TAG = "CdmaSubListPref";
|
||||
|
||||
// Used for CDMA subscription mode
|
||||
private static final int CDMA_SUBSCRIPTION_RUIM_SIM = 0;
|
||||
private static final int CDMA_SUBSCRIPTION_NV = 1;
|
||||
|
||||
//preferredSubscriptionMode 0 - RUIM/SIM, preferred
|
||||
// 1 - NV
|
||||
static final int preferredSubscriptionMode = Phone.PREFERRED_CDMA_SUBSCRIPTION;
|
||||
|
||||
private TelephonyManager mTelephonyManager;
|
||||
|
||||
public CdmaSubscriptionListPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
|
||||
mTelephonyManager = TelephonyManager.from(context);
|
||||
setCurrentCdmaSubscriptionModeValue();
|
||||
}
|
||||
|
||||
private void setCurrentCdmaSubscriptionModeValue() {
|
||||
int cdmaSubscriptionMode = Settings.Global.getInt(getContext().getContentResolver(),
|
||||
Settings.Global.CDMA_SUBSCRIPTION_MODE, preferredSubscriptionMode);
|
||||
setValue(Integer.toString(cdmaSubscriptionMode));
|
||||
}
|
||||
|
||||
public CdmaSubscriptionListPreference(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the subscription id associated with this preference.
|
||||
*
|
||||
* @param subId the subscription id.
|
||||
*/
|
||||
public void setSubscriptionId(int subId) {
|
||||
mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(subId);
|
||||
}
|
||||
|
||||
//TODO(b/114749736): move this logic to preference controller
|
||||
protected void showDialog(Bundle state) {
|
||||
setCurrentCdmaSubscriptionModeValue();
|
||||
}
|
||||
|
||||
//TODO(b/114749736): move this logic to preference controller
|
||||
protected void onDialogClosed(boolean positiveResult) {
|
||||
if (!positiveResult) {
|
||||
//The button was dismissed - no need to set new value
|
||||
return;
|
||||
}
|
||||
|
||||
int buttonCdmaSubscriptionMode = Integer.parseInt(getValue());
|
||||
Log.d(LOG_TAG, "Setting new value " + buttonCdmaSubscriptionMode);
|
||||
int statusCdmaSubscriptionMode;
|
||||
switch(buttonCdmaSubscriptionMode) {
|
||||
case CDMA_SUBSCRIPTION_NV:
|
||||
statusCdmaSubscriptionMode = Phone.CDMA_SUBSCRIPTION_NV;
|
||||
break;
|
||||
case CDMA_SUBSCRIPTION_RUIM_SIM:
|
||||
statusCdmaSubscriptionMode = Phone.CDMA_SUBSCRIPTION_RUIM_SIM;
|
||||
break;
|
||||
default:
|
||||
statusCdmaSubscriptionMode = Phone.PREFERRED_CDMA_SUBSCRIPTION;
|
||||
}
|
||||
|
||||
// Set the CDMA subscription mode, when mode has been successfully changed, update the
|
||||
// mode to the global setting.
|
||||
ThreadUtils.postOnBackgroundThread(() -> {
|
||||
// The subscription mode selected by user.
|
||||
int cdmaSubscriptionMode = Integer.parseInt(getValue());
|
||||
|
||||
boolean isSuccessed = mTelephonyManager.setCdmaSubscriptionMode(
|
||||
statusCdmaSubscriptionMode);
|
||||
|
||||
// Update the global settings if successed.
|
||||
if (isSuccessed) {
|
||||
Settings.Global.putInt(getContext().getContentResolver(),
|
||||
Settings.Global.CDMA_SUBSCRIPTION_MODE,
|
||||
cdmaSubscriptionMode);
|
||||
} else {
|
||||
Log.e(LOG_TAG, "Setting Cdma subscription source failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/*
|
||||
* 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.network.telephony;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.NetworkTemplate;
|
||||
import androidx.preference.Preference;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.format.Formatter;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.net.DataUsageController;
|
||||
|
||||
/**
|
||||
* The preference that shows mobile data usage summary and
|
||||
* leads to mobile data usage list page.
|
||||
*/
|
||||
public class DataUsagePreference extends Preference {
|
||||
|
||||
private NetworkTemplate mTemplate;
|
||||
private int mSubId;
|
||||
|
||||
public DataUsagePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* After creating this preference, this functions needs to be called to
|
||||
* initialize which subID it connects to.
|
||||
*/
|
||||
public void initialize(int subId) {
|
||||
final Context context = getContext();
|
||||
mSubId = subId;
|
||||
mTemplate = getNetworkTemplate(context, subId);
|
||||
|
||||
DataUsageController controller = new DataUsageController(context);
|
||||
|
||||
DataUsageController.DataUsageInfo usageInfo = controller.getDataUsageInfo(mTemplate);
|
||||
setSummary(context.getString(R.string.data_usage_template,
|
||||
Formatter.formatFileSize(context, usageInfo.usageLevel), usageInfo.period));
|
||||
setIntent(getIntent());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Intent getIntent() {
|
||||
Intent intent = new Intent(Settings.ACTION_MOBILE_DATA_USAGE);
|
||||
|
||||
intent.putExtra(Settings.EXTRA_NETWORK_TEMPLATE, mTemplate);
|
||||
intent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
|
||||
|
||||
return intent;
|
||||
}
|
||||
|
||||
private NetworkTemplate getNetworkTemplate(Context context, int subId) {
|
||||
TelephonyManager tm = (TelephonyManager) context
|
||||
.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
NetworkTemplate mobileAll = NetworkTemplate.buildTemplateMobileAll(
|
||||
tm.getSubscriberId(subId));
|
||||
return NetworkTemplate.normalize(mobileAll,
|
||||
tm.getMergedSubscriberIds());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* 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.network.telephony;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.NetworkTemplate;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.text.format.Formatter;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settingslib.net.DataUsageController;
|
||||
|
||||
/**
|
||||
* Preference controller for "Data usage"
|
||||
*/
|
||||
public class DataUsagePreferenceController extends BasePreferenceController {
|
||||
|
||||
private NetworkTemplate mTemplate;
|
||||
private DataUsageController.DataUsageInfo mDataUsageInfo;
|
||||
private Intent mIntent;
|
||||
private int mSubId;
|
||||
|
||||
public DataUsagePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
? AVAILABLE
|
||||
: AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
mContext.startActivity(mIntent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final boolean enabled = mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID;
|
||||
preference.setEnabled(enabled);
|
||||
|
||||
if (enabled) {
|
||||
preference.setSummary(mContext.getString(R.string.data_usage_template,
|
||||
Formatter.formatFileSize(mContext, mDataUsageInfo.usageLevel),
|
||||
mDataUsageInfo.period));
|
||||
}
|
||||
}
|
||||
|
||||
public void init(int subId) {
|
||||
mSubId = subId;
|
||||
|
||||
if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
mTemplate = getNetworkTemplate(mContext, subId);
|
||||
|
||||
final DataUsageController controller = new DataUsageController(mContext);
|
||||
mDataUsageInfo = controller.getDataUsageInfo(mTemplate);
|
||||
|
||||
mIntent = new Intent(Settings.ACTION_MOBILE_DATA_USAGE);
|
||||
mIntent.putExtra(Settings.EXTRA_NETWORK_TEMPLATE, mTemplate);
|
||||
mIntent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
|
||||
}
|
||||
}
|
||||
|
||||
private NetworkTemplate getNetworkTemplate(Context context, int subId) {
|
||||
final TelephonyManager tm = TelephonyManager.from(context).createForSubscriptionId(subId);
|
||||
NetworkTemplate mobileAll = NetworkTemplate.buildTemplateMobileAll(tm.getSubscriberId());
|
||||
|
||||
return NetworkTemplate.normalize(mobileAll, tm.getMergedSubscriberIds());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -66,6 +66,8 @@ import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.internal.telephony.TelephonyIntents;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.dashboard.DashboardFragment;
|
||||
import com.android.settings.network.telephony.cdma.CdmaApnPreferenceController;
|
||||
import com.android.settings.network.telephony.cdma.CdmaSubscriptionPreferenceController;
|
||||
import com.android.settings.network.telephony.cdma.CdmaSystemSelectPreferenceController;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
@@ -79,7 +81,7 @@ import java.util.List;
|
||||
|
||||
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
|
||||
public class MobileNetworkFragment extends DashboardFragment implements
|
||||
Preference.OnPreferenceChangeListener, RoamingDialogFragment.RoamingDialogListener {
|
||||
Preference.OnPreferenceChangeListener {
|
||||
|
||||
// debug data
|
||||
private static final String LOG_TAG = "NetworkSettings";
|
||||
@@ -151,7 +153,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
//UI objects
|
||||
private ListPreference mButtonPreferredNetworkMode;
|
||||
private ListPreference mButtonEnabledNetworks;
|
||||
private RestrictedSwitchPreference mButtonDataRoam;
|
||||
private SwitchPreference mButton4glte;
|
||||
private Preference mLteDataServicePref;
|
||||
private Preference mEuiccSettingsPref;
|
||||
@@ -159,9 +160,9 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
private Preference mWiFiCallingPref;
|
||||
private SwitchPreference mVideoCallingPref;
|
||||
private NetworkSelectListPreference mButtonNetworkSelect;
|
||||
private DataUsagePreference mDataUsagePref;
|
||||
|
||||
private CdmaSystemSelectPreferenceController mCdmaSystemSelectPreferenceController;
|
||||
private CdmaSubscriptionPreferenceController mCdmaSubscriptionPreferenceController;
|
||||
|
||||
private static final String iface = "rmnet0"; //TODO: this will go away
|
||||
private List<SubscriptionInfo> mActiveSubInfos;
|
||||
@@ -226,15 +227,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPositiveButtonClick(androidx.fragment.app.DialogFragment dialog) {
|
||||
mTelephonyManager.setDataRoamingEnabled(true);
|
||||
mButtonDataRoam.setChecked(true);
|
||||
MetricsLogger.action(getContext(),
|
||||
getMetricsEventCategory(getPreferenceScreen(), mButtonDataRoam),
|
||||
true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoked on each preference click in this hierarchy, overrides
|
||||
* PreferenceActivity's implementation. Used to make sure we track the
|
||||
@@ -297,15 +289,11 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
preferredNetworkMode);
|
||||
mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode));
|
||||
return true;
|
||||
} else if (preference == mButtonDataRoam) {
|
||||
// Do not disable the preference screen if the user clicks Data roaming.
|
||||
return true;
|
||||
} else if (preference == mEuiccSettingsPref) {
|
||||
Intent intent = new Intent(EuiccManager.ACTION_MANAGE_EMBEDDED_SUBSCRIPTIONS);
|
||||
startActivity(intent);
|
||||
return true;
|
||||
} else if (preference == mWiFiCallingPref || preference == mVideoCallingPref
|
||||
|| preference == mDataUsagePref) {
|
||||
} else if (preference == mWiFiCallingPref || preference == mVideoCallingPref) {
|
||||
return false;
|
||||
} else {
|
||||
// if the button is anything but the simple toggle preference,
|
||||
@@ -397,9 +385,15 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
|
||||
use(RoamingPreferenceController.class).init(getFragmentManager(), mSubId);
|
||||
use(CdmaApnPreferenceController.class).init(mSubId);
|
||||
use(CarrierPreferenceController.class).init(mSubId);
|
||||
use(DataUsagePreferenceController.class).init(mSubId);
|
||||
|
||||
mCdmaSystemSelectPreferenceController = use(CdmaSystemSelectPreferenceController.class);
|
||||
mCdmaSystemSelectPreferenceController.init(getPreferenceManager(), mSubId);
|
||||
mCdmaSubscriptionPreferenceController = use(CdmaSubscriptionPreferenceController.class);
|
||||
mCdmaSubscriptionPreferenceController.init(getPreferenceManager(), mSubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -426,7 +420,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
mCallingCategory = (PreferenceCategory) findPreference(CATEGORY_CALLING_KEY);
|
||||
mWiFiCallingPref = findPreference(BUTTON_WIFI_CALLING_KEY);
|
||||
mVideoCallingPref = (SwitchPreference) findPreference(BUTTON_VIDEO_CALLING_KEY);
|
||||
mDataUsagePref = (DataUsagePreference) findPreference(BUTTON_DATA_USAGE_KEY);
|
||||
|
||||
try {
|
||||
Context con = context.createPackageContext("com.android.systemui", 0);
|
||||
@@ -441,13 +434,10 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
//get UI object references
|
||||
PreferenceScreen prefSet = getPreferenceScreen();
|
||||
|
||||
mButtonDataRoam = (RestrictedSwitchPreference) prefSet.findPreference(
|
||||
BUTTON_ROAMING_KEY);
|
||||
mButtonPreferredNetworkMode = (ListPreference) prefSet.findPreference(
|
||||
BUTTON_PREFERED_NETWORK_MODE);
|
||||
mButtonEnabledNetworks = (ListPreference) prefSet.findPreference(
|
||||
BUTTON_ENABLED_NETWORKS_KEY);
|
||||
mButtonDataRoam.setOnPreferenceChangeListener(this);
|
||||
|
||||
mLteDataServicePref = prefSet.findPreference(BUTTON_CDMA_LTE_DATA_SERVICE_KEY);
|
||||
|
||||
@@ -520,11 +510,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
// preferences.
|
||||
getPreferenceScreen().setEnabled(true);
|
||||
|
||||
// Set UI state in onResume because a user could go home, launch some
|
||||
// app to change this setting's backend, and re-launch this settings app
|
||||
// and the UI state would be inconsistent with actual state
|
||||
mButtonDataRoam.setChecked(mTelephonyManager.isDataRoamingEnabled());
|
||||
|
||||
if (getPreferenceScreen().findPreference(BUTTON_PREFERED_NETWORK_MODE) != null
|
||||
|| getPreferenceScreen().findPreference(BUTTON_ENABLED_NETWORKS_KEY) != null) {
|
||||
updatePreferredNetworkUIFromDb();
|
||||
@@ -574,29 +559,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
// android.R.id.home will be triggered in onOptionsItemSelected()
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
prefSet.addPreference(mButtonDataRoam);
|
||||
prefSet.addPreference(mDataUsagePref);
|
||||
|
||||
mButtonDataRoam.setEnabled(hasActiveSubscriptions);
|
||||
mDataUsagePref.setEnabled(hasActiveSubscriptions);
|
||||
|
||||
if (hasActiveSubscriptions) {
|
||||
// Customized preferences needs to be initialized with subId.
|
||||
mDataUsagePref.initialize(phoneSubId);
|
||||
|
||||
// Initialize states of mButtonDataRoam.
|
||||
mButtonDataRoam.setChecked(mTelephonyManager.isDataRoamingEnabled());
|
||||
if (mButtonDataRoam.isEnabled()) {
|
||||
if (RestrictedLockUtilsInternal.hasBaseUserRestriction(context,
|
||||
UserManager.DISALLOW_DATA_ROAMING, UserHandle.myUserId())) {
|
||||
mButtonDataRoam.setEnabled(false);
|
||||
} else {
|
||||
mButtonDataRoam.checkRestrictionAndSetDisabled(
|
||||
UserManager.DISALLOW_DATA_ROAMING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBody() {
|
||||
@@ -724,15 +686,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to extra preference changes that need as Metrics events logging.
|
||||
*/
|
||||
|
||||
if (prefSet.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY) != null) {
|
||||
prefSet.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)
|
||||
.setOnPreferenceChangeListener(this);
|
||||
}
|
||||
|
||||
// Get the networkMode from Settings.System and displays it
|
||||
mButtonEnabledNetworks.setValue(Integer.toString(settingsNetworkMode));
|
||||
mButtonPreferredNetworkMode.setValue(Integer.toString(settingsNetworkMode));
|
||||
@@ -1046,42 +999,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
boolean enhanced4gMode = !mButton4glte.isChecked();
|
||||
mButton4glte.setChecked(enhanced4gMode);
|
||||
mImsMgr.setEnhanced4gLteModeSetting(mButton4glte.isChecked());
|
||||
} else if (preference == mButtonDataRoam) {
|
||||
if (DBG) log("onPreferenceTreeClick: preference == mButtonDataRoam.");
|
||||
|
||||
//normally called on the toggle click
|
||||
if (!mButtonDataRoam.isChecked()) {
|
||||
PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(
|
||||
mSubId);
|
||||
if (carrierConfig != null && carrierConfig.getBoolean(
|
||||
CarrierConfigManager.KEY_DISABLE_CHARGE_INDICATION_BOOL)) {
|
||||
mTelephonyManager.setDataRoamingEnabled(true);
|
||||
MetricsLogger.action(getContext(),
|
||||
getMetricsEventCategory(getPreferenceScreen(), mButtonDataRoam),
|
||||
true);
|
||||
} else {
|
||||
// MetricsEvent with no value update.
|
||||
MetricsLogger.action(getContext(),
|
||||
getMetricsEventCategory(getPreferenceScreen(), mButtonDataRoam));
|
||||
// First confirm with a warning dialog about charges
|
||||
mOkClicked = false;
|
||||
RoamingDialogFragment
|
||||
fragment = new RoamingDialogFragment();
|
||||
Bundle b = new Bundle();
|
||||
b.putInt(RoamingDialogFragment.SUB_ID_KEY, mSubId);
|
||||
fragment.setArguments(b);
|
||||
fragment.setTargetFragment(this, 0 /* requestCode */);
|
||||
fragment.show(getFragmentManager(), ROAMING_TAG);
|
||||
// Don't update the toggle unless the confirm button is actually pressed.
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
mTelephonyManager.setDataRoamingEnabled(false);
|
||||
MetricsLogger.action(getContext(),
|
||||
getMetricsEventCategory(getPreferenceScreen(), mButtonDataRoam),
|
||||
false);
|
||||
return true;
|
||||
}
|
||||
} else if (preference == mVideoCallingPref) {
|
||||
// If mButton4glte is not checked, mVideoCallingPref should be disabled.
|
||||
// So it only makes sense to call phoneMgr.enableVideoCalling if it's checked.
|
||||
@@ -1093,9 +1010,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
mVideoCallingPref.setEnabled(false);
|
||||
return false;
|
||||
}
|
||||
} else if (preference == getPreferenceScreen()
|
||||
.findPreference(BUTTON_CDMA_SUBSCRIPTION_KEY)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
updateBody();
|
||||
@@ -1431,11 +1345,13 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
EXTRA_EXIT_ECM_RESULT, false);
|
||||
if (isChoiceYes) {
|
||||
// If the phone exits from ECM mode, show the CDMA Options
|
||||
if (TextUtils.equals(mClickedPreference.getKey(),
|
||||
final String key = mClickedPreference.getKey();
|
||||
if (TextUtils.equals(key,
|
||||
mCdmaSystemSelectPreferenceController.getPreferenceKey())) {
|
||||
mCdmaSystemSelectPreferenceController.showDialog();
|
||||
} else {
|
||||
mCdmaOptions.showDialog(mClickedPreference);
|
||||
} else if (TextUtils.equals(key,
|
||||
mCdmaSubscriptionPreferenceController.getPreferenceKey())) {
|
||||
mCdmaSubscriptionPreferenceController.showDialog();
|
||||
}
|
||||
} else {
|
||||
// do nothing
|
||||
@@ -1704,7 +1620,7 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
// For ListPreferences, we log it here without a value, only indicating it's clicked to
|
||||
// open the list dialog. When a value is chosen, another MetricsEvent is logged with
|
||||
// new value in onPreferenceChange.
|
||||
if (preference == mLteDataServicePref || preference == mDataUsagePref
|
||||
if (preference == mLteDataServicePref
|
||||
|| preference == mEuiccSettingsPref
|
||||
|| preference == mWiFiCallingPref || preference == mButtonPreferredNetworkMode
|
||||
|| preference == mButtonEnabledNetworks
|
||||
@@ -1743,10 +1659,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
|
||||
if (preference == null) {
|
||||
return MetricsProto.MetricsEvent.VIEW_UNKNOWN;
|
||||
} else if (preference == mButtonDataRoam) {
|
||||
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_DATA_ROAMING_TOGGLE;
|
||||
} else if (preference == mDataUsagePref) {
|
||||
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_DATA_USAGE;
|
||||
} else if (preference == mLteDataServicePref) {
|
||||
return MetricsProto.MetricsEvent.ACTION_MOBILE_NETWORK_SET_UP_DATA_SERVICE;
|
||||
} else if (preference == mButton4glte) {
|
||||
@@ -1802,8 +1714,6 @@ public class MobileNetworkFragment extends DashboardFragment implements
|
||||
// the open dialog gets dismissed or detached after pause / resume.
|
||||
if (mCdmaOptions == null) {
|
||||
mCdmaOptions = new CdmaOptions(prefFragment, prefScreen, subId);
|
||||
} else {
|
||||
mCdmaOptions.updateSubscriptionId(subId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -275,6 +275,20 @@ public class MobileNetworkUtils {
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isGsmOptions(Context context, int subId) {
|
||||
if (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
|
||||
return false;
|
||||
}
|
||||
final TelephonyManager telephonyManager = TelephonyManager.from(context)
|
||||
.createForSubscriptionId(subId);
|
||||
|
||||
if (telephonyManager.getPhoneType() == PhoneConstants.PHONE_TYPE_GSM) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return {@code true} if it is world mode, and we may show advanced options in telephony
|
||||
* settings
|
||||
|
||||
@@ -71,6 +71,7 @@ public class MobileSettingsActivity extends SettingsBaseActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.mobile_settings_container);
|
||||
setActionBar(findViewById(R.id.action_bar));
|
||||
mSubscriptionManager = getSystemService(SubscriptionManager.class);
|
||||
mSubscriptionInfos = mSubscriptionManager.getActiveSubscriptionInfoList();
|
||||
mCurSubscriptionId = savedInstanceState != null
|
||||
|
||||
@@ -23,11 +23,11 @@ import android.content.DialogInterface.OnClickListener;
|
||||
import android.os.Bundle;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
|
||||
@@ -42,15 +42,14 @@ public class RoamingDialogFragment extends InstrumentedDialogFragment implements
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
private int mSubId;
|
||||
|
||||
/**
|
||||
* The interface we expect a host activity to implement.
|
||||
*/
|
||||
public interface RoamingDialogListener {
|
||||
void onPositiveButtonClick(DialogFragment dialog);
|
||||
}
|
||||
public static RoamingDialogFragment newInstance(int subId) {
|
||||
final RoamingDialogFragment dialogFragment = new RoamingDialogFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(SUB_ID_KEY, subId);
|
||||
dialogFragment.setArguments(args);
|
||||
|
||||
// the host activity which implements the listening interface
|
||||
private RoamingDialogListener mListener;
|
||||
return dialogFragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
@@ -58,14 +57,6 @@ public class RoamingDialogFragment extends InstrumentedDialogFragment implements
|
||||
Bundle args = getArguments();
|
||||
mSubId = args.getInt(SUB_ID_KEY);
|
||||
mCarrierConfigManager = new CarrierConfigManager(context);
|
||||
|
||||
Fragment fragment = getTargetFragment();
|
||||
try {
|
||||
mListener = (RoamingDialogListener) fragment;
|
||||
} catch (ClassCastException e) {
|
||||
throw new ClassCastException(fragment.toString() +
|
||||
"must implement RoamingDialogListener");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,7 +86,8 @@ public class RoamingDialogFragment extends InstrumentedDialogFragment implements
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
// let the host know that the positive button has been clicked
|
||||
if (which == dialog.BUTTON_POSITIVE) {
|
||||
mListener.onPositiveButtonClick(this);
|
||||
TelephonyManager.from(getContext()).createForSubscriptionId(
|
||||
mSubId).setDataRoamingEnabled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
/*
|
||||
* 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.network.telephony;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.TogglePreferenceController;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/**
|
||||
* Preference controller for "Roaming"
|
||||
*/
|
||||
public class RoamingPreferenceController extends TogglePreferenceController implements
|
||||
LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
private static final String DIALOG_TAG = "MobileDataDialog";
|
||||
|
||||
private RestrictedSwitchPreference mSwitchPreference;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
private int mSubId;
|
||||
private DataContentObserver mDataContentObserver;
|
||||
@VisibleForTesting
|
||||
boolean mNeedDialog;
|
||||
@VisibleForTesting
|
||||
FragmentManager mFragmentManager;
|
||||
|
||||
public RoamingPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mCarrierConfigManager = context.getSystemService(CarrierConfigManager.class);
|
||||
mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mDataContentObserver.register(mContext, mSubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mDataContentObserver.unRegister(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mSwitchPreference = (RestrictedSwitchPreference) screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
|
||||
? AVAILABLE
|
||||
: AVAILABLE_UNSEARCHABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (TextUtils.equals(preference.getKey(), getPreferenceKey())) {
|
||||
if (mNeedDialog) {
|
||||
showDialog();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setChecked(boolean isChecked) {
|
||||
mNeedDialog = isDialogNeeded();
|
||||
|
||||
if (!mNeedDialog) {
|
||||
// Update data directly if we don't need dialog
|
||||
mTelephonyManager.setDataRoamingEnabled(isChecked);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final RestrictedSwitchPreference switchPreference = (RestrictedSwitchPreference) preference;
|
||||
switchPreference.setEnabled(mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
switchPreference.setChecked(isChecked());
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean isDialogNeeded() {
|
||||
final boolean isRoamingEnabled = mTelephonyManager.isDataRoamingEnabled();
|
||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(
|
||||
mSubId);
|
||||
|
||||
// Need dialog if we need to turn on roaming and the roaming charge indication is allowed
|
||||
if (!isRoamingEnabled && (carrierConfig == null || !carrierConfig.getBoolean(
|
||||
CarrierConfigManager.KEY_DISABLE_CHARGE_INDICATION_BOOL))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isChecked() {
|
||||
return mTelephonyManager.isDataRoamingEnabled();
|
||||
}
|
||||
|
||||
public void init(FragmentManager fragmentManager, int subId) {
|
||||
mFragmentManager = fragmentManager;
|
||||
mSubId = subId;
|
||||
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
|
||||
}
|
||||
|
||||
private void showDialog() {
|
||||
final RoamingDialogFragment dialogFragment = RoamingDialogFragment.newInstance(mSubId);
|
||||
|
||||
dialogFragment.show(mFragmentManager, DIALOG_TAG);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener that listens data roaming change
|
||||
*/
|
||||
public class DataContentObserver extends ContentObserver {
|
||||
|
||||
public DataContentObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
updateState(mSwitchPreference);
|
||||
}
|
||||
|
||||
public void register(Context context, int subId) {
|
||||
Uri uri = Settings.Global.getUriFor(Settings.Global.DATA_ROAMING);
|
||||
if (TelephonyManager.getDefault().getSimCount() != 1) {
|
||||
uri = Settings.Global.getUriFor(Settings.Global.DATA_ROAMING + subId);
|
||||
}
|
||||
context.getContentResolver().registerContentObserver(uri, false, this);
|
||||
|
||||
}
|
||||
|
||||
public void unRegister(Context context) {
|
||||
context.getContentResolver().unregisterContentObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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.network.telephony.cdma;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.network.ApnSettings;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settingslib.RestrictedLockUtilsInternal;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
/**
|
||||
* Preference controller for "CDMA Apn"
|
||||
*/
|
||||
public class CdmaApnPreferenceController extends CdmaBasePreferenceController {
|
||||
|
||||
private static final String CATEGORY_KEY = "category_cdma_apn_key";
|
||||
@VisibleForTesting
|
||||
CarrierConfigManager mCarrierConfigManager;
|
||||
|
||||
public CdmaApnPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mCarrierConfigManager = new CarrierConfigManager(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
final PersistableBundle carrierConfig = mCarrierConfigManager.getConfigForSubId(mSubId);
|
||||
|
||||
return carrierConfig != null
|
||||
&& carrierConfig.getBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL)
|
||||
&& MobileNetworkUtils.isCdmaOptions(mContext, mSubId)
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
if (isAvailable()) {
|
||||
((RestrictedPreference) mPreference).setDisabledByAdmin(
|
||||
MobileNetworkUtils.isDpcApnEnforced(mContext)
|
||||
? RestrictedLockUtilsInternal.getDeviceOwner(mContext)
|
||||
: null);
|
||||
} else {
|
||||
screen.findPreference(CATEGORY_KEY).setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
||||
if (getPreferenceKey().equals(preference.getKey())) {
|
||||
// This activity runs in phone process, we must use intent to start
|
||||
final Intent intent = new Intent(Settings.ACTION_APN_SETTINGS);
|
||||
// This will setup the Home and Search affordance
|
||||
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SUBSETTING, true);
|
||||
intent.putExtra(ApnSettings.SUB_ID, mSubId);
|
||||
mContext.startActivity(intent);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* 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.network.telephony.cdma;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/**
|
||||
* Preference controller related to CDMA category
|
||||
*/
|
||||
public abstract class CdmaBasePreferenceController extends BasePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop {
|
||||
|
||||
protected Preference mPreference;
|
||||
protected TelephonyManager mTelephonyManager;
|
||||
protected PreferenceManager mPreferenceManager;
|
||||
protected int mSubId;
|
||||
private DataContentObserver mDataContentObserver;
|
||||
|
||||
public CdmaBasePreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mDataContentObserver.register(mContext, mSubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mDataContentObserver.unRegister(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return MobileNetworkUtils.isCdmaOptions(mContext, mSubId)
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
public void init(PreferenceManager preferenceManager, int subId) {
|
||||
mPreferenceManager = preferenceManager;
|
||||
mSubId = subId;
|
||||
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
|
||||
}
|
||||
|
||||
public void init(int subId) {
|
||||
init(null, subId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener that listens to mobile data state change.
|
||||
*/
|
||||
public class DataContentObserver extends ContentObserver {
|
||||
|
||||
public DataContentObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
public void register(Context context, int subId) {
|
||||
final Uri uri = Settings.Global.getUriFor(
|
||||
Settings.Global.PREFERRED_NETWORK_MODE + subId);
|
||||
context.getContentResolver().registerContentObserver(uri, false, this);
|
||||
}
|
||||
|
||||
public void unRegister(Context context) {
|
||||
context.getContentResolver().unregisterContentObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* 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.network.telephony.cdma;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.android.internal.telephony.Phone;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
|
||||
/**
|
||||
* Preference controller for "CDMA subscription"
|
||||
*/
|
||||
public class CdmaSubscriptionPreferenceController extends CdmaBasePreferenceController
|
||||
implements ListPreference.OnPreferenceChangeListener {
|
||||
private static final String TYPE_NV = "NV";
|
||||
private static final String TYPE_RUIM = "RUIM";
|
||||
|
||||
@VisibleForTesting
|
||||
ListPreference mPreference;
|
||||
|
||||
public CdmaSubscriptionPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return MobileNetworkUtils.isCdmaOptions(mContext, mSubId) && deviceSupportsNvAndRuim()
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
final ListPreference listPreference = (ListPreference) preference;
|
||||
listPreference.setVisible(getAvailabilityStatus() == AVAILABLE);
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.CDMA_SUBSCRIPTION_MODE, Phone.PREFERRED_CDMA_SUBSCRIPTION);
|
||||
if (mode != Phone.CDMA_SUBSCRIPTION_UNKNOWN) {
|
||||
listPreference.setValue(Integer.toString(mode));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object object) {
|
||||
final int newMode = Integer.parseInt((String) object);
|
||||
//TODO(b/117611981): only set it in one place
|
||||
if (mTelephonyManager.setCdmaSubscriptionMode(newMode)) {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.CDMA_SUBSCRIPTION_MODE, newMode);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
final int mode = Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.CDMA_SUBSCRIPTION_MODE, Phone.PREFERRED_CDMA_SUBSCRIPTION);
|
||||
|
||||
mPreference.setValue(Integer.toString(mode));
|
||||
mPreferenceManager.showDialog(mPreference);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
boolean deviceSupportsNvAndRuim() {
|
||||
// retrieve the list of subscription types supported by device.
|
||||
final String subscriptionsSupported = SystemProperties.get("ril.subscription.types");
|
||||
boolean nvSupported = false;
|
||||
boolean ruimSupported = false;
|
||||
|
||||
if (!TextUtils.isEmpty(subscriptionsSupported)) {
|
||||
// Searches through the comma-separated list for a match for "NV"
|
||||
// and "RUIM" to update nvSupported and ruimSupported.
|
||||
for (String subscriptionType : subscriptionsSupported.split(",")) {
|
||||
subscriptionType = subscriptionType.trim();
|
||||
if (subscriptionType.equalsIgnoreCase(TYPE_NV)) {
|
||||
nvSupported = true;
|
||||
} else if (subscriptionType.equalsIgnoreCase(TYPE_RUIM)) {
|
||||
ruimSupported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (nvSupported && ruimSupported);
|
||||
}
|
||||
}
|
||||
@@ -17,64 +17,20 @@
|
||||
package com.android.settings.network.telephony.cdma;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.ContentObserver;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.network.telephony.MobileNetworkUtils;
|
||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
||||
|
||||
/**
|
||||
* Preference controller for "System Select"
|
||||
*/
|
||||
public class CdmaSystemSelectPreferenceController extends BasePreferenceController
|
||||
implements LifecycleObserver, OnStart, OnStop, ListPreference.OnPreferenceChangeListener {
|
||||
|
||||
@VisibleForTesting
|
||||
ListPreference mPreference;
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private PreferenceManager mPreferenceManager;
|
||||
private DataContentObserver mDataContentObserver;
|
||||
private int mSubId;
|
||||
public class CdmaSystemSelectPreferenceController extends CdmaBasePreferenceController
|
||||
implements ListPreference.OnPreferenceChangeListener {
|
||||
|
||||
public CdmaSystemSelectPreferenceController(Context context, String key) {
|
||||
super(context, key);
|
||||
mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
mDataContentObserver.register(mContext, mSubId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
mDataContentObserver.unRegister(mContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getAvailabilityStatus() {
|
||||
return MobileNetworkUtils.isCdmaOptions(mContext, mSubId)
|
||||
? AVAILABLE
|
||||
: CONDITIONALLY_UNAVAILABLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -106,12 +62,6 @@ public class CdmaSystemSelectPreferenceController extends BasePreferenceControll
|
||||
return false;
|
||||
}
|
||||
|
||||
public void init(PreferenceManager preferenceManager, int subId) {
|
||||
mPreferenceManager = preferenceManager;
|
||||
mSubId = subId;
|
||||
mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
|
||||
}
|
||||
|
||||
public void showDialog() {
|
||||
if (!mTelephonyManager.getEmergencyCallbackMode()) {
|
||||
mPreferenceManager.showDialog(mPreference);
|
||||
@@ -119,37 +69,13 @@ public class CdmaSystemSelectPreferenceController extends BasePreferenceControll
|
||||
}
|
||||
|
||||
private void resetCdmaRoamingModeToDefault() {
|
||||
final ListPreference listPreference = (ListPreference) mPreference;
|
||||
//set the mButtonCdmaRoam
|
||||
mPreference.setValue(Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_ANY));
|
||||
listPreference.setValue(Integer.toString(TelephonyManager.CDMA_ROAMING_MODE_ANY));
|
||||
//set the Settings.System
|
||||
Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.CDMA_ROAMING_MODE,
|
||||
TelephonyManager.CDMA_ROAMING_MODE_ANY);
|
||||
//Set the Status
|
||||
mTelephonyManager.setCdmaRoamingMode(TelephonyManager.CDMA_ROAMING_MODE_ANY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listener that listens mobile data state change.
|
||||
*/
|
||||
public class DataContentObserver extends ContentObserver {
|
||||
|
||||
public DataContentObserver(Handler handler) {
|
||||
super(handler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(boolean selfChange) {
|
||||
super.onChange(selfChange);
|
||||
updateState(mPreference);
|
||||
}
|
||||
|
||||
public void register(Context context, int subId) {
|
||||
Uri uri = Settings.Global.getUriFor(Settings.Global.PREFERRED_NETWORK_MODE + subId);
|
||||
context.getContentResolver().registerContentObserver(uri, false, this);
|
||||
}
|
||||
|
||||
public void unRegister(Context context) {
|
||||
context.getContentResolver().unregisterContentObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ public class SettingsDialogFragmentTest {
|
||||
public void testGetMetrics_shouldGetMetricFromDialogCreatable() {
|
||||
when(mDialogCreatable.getDialogMetricsCategory(DIALOG_ID)).thenReturn(1);
|
||||
|
||||
mDialogFragment =
|
||||
new SettingsPreferenceFragment.SettingsDialogFragment(mDialogCreatable, DIALOG_ID);
|
||||
mDialogFragment = SettingsPreferenceFragment.SettingsDialogFragment.newInstance(
|
||||
mDialogCreatable, DIALOG_ID);
|
||||
mDialogFragment.onAttach(RuntimeEnvironment.application);
|
||||
mDialogFragment.getMetricsCategory();
|
||||
|
||||
@@ -65,8 +65,8 @@ public class SettingsDialogFragmentTest {
|
||||
when(mDialogCreatable.getDialogMetricsCategory(DIALOG_ID)).thenReturn(-1);
|
||||
|
||||
try {
|
||||
mDialogFragment =
|
||||
new SettingsPreferenceFragment.SettingsDialogFragment(mDialogCreatable, DIALOG_ID);
|
||||
mDialogFragment = SettingsPreferenceFragment.SettingsDialogFragment.newInstance(
|
||||
mDialogCreatable, DIALOG_ID);
|
||||
mDialogFragment.onAttach(RuntimeEnvironment.application);
|
||||
fail("Should fail with IllegalStateException");
|
||||
} catch (IllegalStateException e) {
|
||||
|
||||
@@ -43,6 +43,7 @@ import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.withSettings;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
@@ -50,6 +51,8 @@ import android.net.ConnectivityManager.NetworkCallback;
|
||||
import android.net.LinkProperties;
|
||||
import android.net.Network;
|
||||
import android.os.Handler;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.Settings;
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
@@ -58,6 +61,8 @@ import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import org.junit.Before;
|
||||
@@ -79,6 +84,10 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(shadows = {
|
||||
ShadowUserManager.class,
|
||||
ShadowDevicePolicyManager.class
|
||||
})
|
||||
public class PrivateDnsPreferenceControllerTest {
|
||||
|
||||
private final static String HOSTNAME = "dns.example.com";
|
||||
@@ -108,6 +117,7 @@ public class PrivateDnsPreferenceControllerTest {
|
||||
private ShadowContentResolver mShadowContentResolver;
|
||||
private Lifecycle mLifecycle;
|
||||
private LifecycleOwner mLifecycleOwner;
|
||||
private ShadowUserManager mShadowUserManager;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -127,6 +137,8 @@ public class PrivateDnsPreferenceControllerTest {
|
||||
mLifecycleOwner = () -> mLifecycle;
|
||||
mLifecycle = new Lifecycle(mLifecycleOwner);
|
||||
mLifecycle.addObserver(mController);
|
||||
|
||||
mShadowUserManager = ShadowUserManager.getShadow();
|
||||
}
|
||||
|
||||
private void updateLinkProperties(LinkProperties lp) {
|
||||
@@ -264,6 +276,31 @@ public class PrivateDnsPreferenceControllerTest {
|
||||
verify(mPreference).setSummary(getResourceString(R.string.private_dns_mode_opportunistic));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEnabled_canBeDisabledByAdmin() {
|
||||
final int userId = UserHandle.myUserId();
|
||||
final List<UserManager.EnforcingUser> enforcingUsers = Collections.singletonList(
|
||||
new UserManager.EnforcingUser(userId,
|
||||
UserManager.RESTRICTION_SOURCE_DEVICE_OWNER)
|
||||
);
|
||||
mShadowUserManager.setUserRestrictionSources(
|
||||
UserManager.DISALLOW_CONFIG_PRIVATE_DNS,
|
||||
UserHandle.of(userId),
|
||||
enforcingUsers);
|
||||
|
||||
ShadowDevicePolicyManager.getShadow().setDeviceOwnerComponentOnAnyUser(
|
||||
new ComponentName("test", "test"));
|
||||
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setEnabled(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isEnabled_isEnabledByDefault() {
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setEnabled(true);
|
||||
}
|
||||
|
||||
private void setPrivateDnsMode(String mode) {
|
||||
Settings.Global.putString(mContentResolver, PRIVATE_DNS_MODE, mode);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.network.telephony;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class CarrierPreferenceControllerTest {
|
||||
private static final int SUB_ID = 2;
|
||||
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@Mock
|
||||
private TelephonyManager mInvalidTelephonyManager;
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
|
||||
private CarrierPreferenceController mController;
|
||||
private RestrictedPreference mPreference;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
|
||||
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
mPreference = new RestrictedPreference(mContext);
|
||||
mController = new CarrierPreferenceController(mContext, "mobile_data");
|
||||
mController.init(SUB_ID);
|
||||
mController.mCarrierConfigManager = mCarrierConfigManager;
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_cdmaWithFlagOff_returnUnavailable() {
|
||||
doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
||||
final PersistableBundle bundle = new PersistableBundle();
|
||||
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, false);
|
||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_cdmaWithFlagOnreturnAvailable() {
|
||||
doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
||||
final PersistableBundle bundle = new PersistableBundle();
|
||||
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, true);
|
||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_gsmWithFlagOnreturnAvailable() {
|
||||
doReturn(PhoneConstants.PHONE_TYPE_GSM).when(mTelephonyManager).getPhoneType();
|
||||
final PersistableBundle bundle = new PersistableBundle();
|
||||
bundle.putBoolean(CarrierConfigManager.KEY_CARRIER_SETTINGS_ENABLE_BOOL, true);
|
||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* 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.network.telephony;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class DataUsagePreferenceControllerTest {
|
||||
private static final int SUB_ID = 2;
|
||||
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
private DataUsagePreferenceController mController;
|
||||
private SwitchPreference mPreference;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
|
||||
mPreference = new SwitchPreference(mContext);
|
||||
mController = new DataUsagePreferenceController(mContext, "data_usage");
|
||||
mController.init(SUB_ID);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_validSubId_returnAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_invalidSubId_returnUnsearchable() {
|
||||
mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_needDialog_showDialog() {
|
||||
final ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mContext).startActivity(captor.capture());
|
||||
final Intent intent = captor.getValue();
|
||||
|
||||
assertThat(intent.getAction()).isEqualTo(Settings.ACTION_MOBILE_DATA_USAGE);
|
||||
assertThat(intent.getIntExtra(Settings.EXTRA_SUB_ID, 0)).isEqualTo(SUB_ID);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_invalidSubId_disabled() {
|
||||
mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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.network.telephony;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.PersistableBundle;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.RestrictedSwitchPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class RoamingPreferenceControllerTest {
|
||||
private static final int SUB_ID = 2;
|
||||
|
||||
@Mock
|
||||
private FragmentManager mFragmentManager;
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@Mock
|
||||
private TelephonyManager mInvalidTelephonyManager;
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private FragmentTransaction mFragmentTransaction;
|
||||
@Mock
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
|
||||
private RoamingPreferenceController mController;
|
||||
private RestrictedSwitchPreference mPreference;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
|
||||
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
||||
doReturn(mCarrierConfigManager).when(mContext).getSystemService(CarrierConfigManager.class);
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
doReturn(mFragmentTransaction).when(mFragmentManager).beginTransaction();
|
||||
|
||||
mPreference = new RestrictedSwitchPreference(mContext);
|
||||
mController = new RoamingPreferenceController(mContext, "roaming");
|
||||
mController.init(mFragmentManager, SUB_ID);
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_validSubId_returnAvailable() {
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_invalidSubId_returnUnsearchable() {
|
||||
mController.init(mFragmentManager, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(
|
||||
BasePreferenceController.AVAILABLE_UNSEARCHABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDialogNeeded_roamingDisabledWithoutFlag_returnTrue() {
|
||||
final PersistableBundle bundle = new PersistableBundle();
|
||||
bundle.putBoolean(CarrierConfigManager.KEY_DISABLE_CHARGE_INDICATION_BOOL, false);
|
||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
doReturn(false).when(mTelephonyManager).isDataRoamingEnabled();
|
||||
|
||||
assertThat(mController.isDialogNeeded()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isDialogNeeded_roamingEnabled_returnFalse() {
|
||||
doReturn(true).when(mTelephonyManager).isDataRoamingEnabled();
|
||||
|
||||
assertThat(mController.isDialogNeeded()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handlePreferenceTreeClick_needDialog_showDialog() {
|
||||
mController.mNeedDialog = true;
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mFragmentManager).beginTransaction();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_invalidSubId_disabled() {
|
||||
mController.init(mFragmentManager, SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_validSubId_enabled() {
|
||||
doReturn(true).when(mTelephonyManager).isDataRoamingEnabled();
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.isEnabled()).isTrue();
|
||||
assertThat(mPreference.isChecked()).isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* 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.network.telephony.cdma;
|
||||
|
||||
import static com.android.settings.core.BasePreferenceController.AVAILABLE;
|
||||
import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.PersistableBundle;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.CarrierConfigManager;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import com.android.internal.telephony.PhoneConstants;
|
||||
import com.android.settings.network.ApnSettings;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
import com.android.settingslib.RestrictedPreference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class CdmaApnPreferenceControllerTest {
|
||||
private static final int SUB_ID = 2;
|
||||
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@Mock
|
||||
private TelephonyManager mInvalidTelephonyManager;
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
@Mock
|
||||
private CarrierConfigManager mCarrierConfigManager;
|
||||
|
||||
private CdmaApnPreferenceController mController;
|
||||
private RestrictedPreference mPreference;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
|
||||
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
mPreference = new RestrictedPreference(mContext);
|
||||
mController = new CdmaApnPreferenceController(mContext, "mobile_data");
|
||||
mController.init(SUB_ID);
|
||||
mController.mPreference = mPreference;
|
||||
mController.mCarrierConfigManager = mCarrierConfigManager;
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_apnSettingsNotSupported_returnUnavailable() {
|
||||
doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
||||
final PersistableBundle bundle = new PersistableBundle();
|
||||
bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, false);
|
||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAvailabilityStatus_apnSettingsSupportedWithCDMA_returnAvailable() {
|
||||
doReturn(PhoneConstants.PHONE_TYPE_CDMA).when(mTelephonyManager).getPhoneType();
|
||||
final PersistableBundle bundle = new PersistableBundle();
|
||||
bundle.putBoolean(CarrierConfigManager.KEY_SHOW_APN_SETTING_CDMA_BOOL, true);
|
||||
doReturn(bundle).when(mCarrierConfigManager).getConfigForSubId(SUB_ID);
|
||||
|
||||
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handPreferenceTreeClick_fireIntent() {
|
||||
ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class);
|
||||
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
verify(mContext).startActivity(captor.capture());
|
||||
final Intent intent = captor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(Settings.ACTION_APN_SETTINGS);
|
||||
assertThat(intent.getIntExtra(ApnSettings.SUB_ID, 0)).isEqualTo(SUB_ID);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* 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.network.telephony.cdma;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.spy;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.SystemProperties;
|
||||
import android.provider.Settings;
|
||||
import android.telephony.SubscriptionManager;
|
||||
import android.telephony.TelephonyManager;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.android.internal.telephony.Phone;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
public class CdmaSubscriptionPreferenceControllerTest {
|
||||
private static final int SUB_ID = 2;
|
||||
|
||||
@Mock
|
||||
private PreferenceManager mPreferenceManager;
|
||||
@Mock
|
||||
private TelephonyManager mTelephonyManager;
|
||||
@Mock
|
||||
private TelephonyManager mInvalidTelephonyManager;
|
||||
@Mock
|
||||
private SubscriptionManager mSubscriptionManager;
|
||||
|
||||
private CdmaSubscriptionPreferenceController mController;
|
||||
private ListPreference mPreference;
|
||||
private Context mContext;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
|
||||
mContext = spy(RuntimeEnvironment.application);
|
||||
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
|
||||
doReturn(mSubscriptionManager).when(mContext).getSystemService(SubscriptionManager.class);
|
||||
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(SUB_ID);
|
||||
doReturn(mInvalidTelephonyManager).when(mTelephonyManager).createForSubscriptionId(
|
||||
SubscriptionManager.INVALID_SUBSCRIPTION_ID);
|
||||
|
||||
mPreference = new ListPreference(mContext);
|
||||
mController = new CdmaSubscriptionPreferenceController(mContext, "mobile_data");
|
||||
mController.init(mPreferenceManager, SUB_ID);
|
||||
mController.mPreference = mPreference;
|
||||
mPreference.setKey(mController.getPreferenceKey());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onPreferenceChange_selectNV_returnNVMode() {
|
||||
doReturn(true).when(mTelephonyManager).setCdmaSubscriptionMode(anyInt());
|
||||
|
||||
mController.onPreferenceChange(mPreference, Integer.toString(Phone.CDMA_SUBSCRIPTION_NV));
|
||||
|
||||
assertThat(Settings.Global.getInt(mContext.getContentResolver(),
|
||||
Settings.Global.CDMA_SUBSCRIPTION_MODE,
|
||||
Phone.CDMA_SUBSCRIPTION_RUIM_SIM)).isEqualTo(Phone.CDMA_SUBSCRIPTION_NV);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_stateRUIM_displayRUIM() {
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.CDMA_SUBSCRIPTION_MODE, Phone.CDMA_SUBSCRIPTION_NV);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
assertThat(mPreference.getValue()).isEqualTo(Integer.toString(Phone.CDMA_SUBSCRIPTION_NV));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void updateState_stateUnknown_doNothing() {
|
||||
mPreference.setValue(Integer.toString(Phone.CDMA_SUBSCRIPTION_NV));
|
||||
Settings.Global.putInt(mContext.getContentResolver(),
|
||||
Settings.Global.CDMA_SUBSCRIPTION_MODE, Phone.CDMA_SUBSCRIPTION_UNKNOWN);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
// Still NV mode
|
||||
assertThat(mPreference.getValue()).isEqualTo(Integer.toString(Phone.CDMA_SUBSCRIPTION_NV));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void deviceSupportsNvAndRuim() {
|
||||
SystemProperties.set("ril.subscription.types", "NV,RUIM");
|
||||
assertThat(mController.deviceSupportsNvAndRuim()).isTrue();
|
||||
|
||||
SystemProperties.set("ril.subscription.types", "");
|
||||
|
||||
assertThat(mController.deviceSupportsNvAndRuim()).isFalse();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user