Merge "Add flag to not connect in WifiDialogActivity"
diff --git a/res/layout/dialog_imei_info.xml b/res/layout/dialog_imei_info.xml
new file mode 100644
index 0000000..b19d336
--- /dev/null
+++ b/res/layout/dialog_imei_info.xml
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2017 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.
+ -->
+
+<ScrollView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <LinearLayout
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:padding="@dimen/sim_content_padding">
+
+ <!-- These items are only for CDMA phones -->
+ <LinearLayout
+ android:id="@+id/cdma_settings"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <TextView
+ style="@style/device_info_dialog_label"
+ android:id="@+id/min_number_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/status_min_number"/>
+ <TextView
+ style="@style/device_info_dialog_value"
+ android:id="@+id/min_number_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <TextView
+ style="@style/device_info_dialog_label"
+ android:id="@+id/prl_version_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/status_prl_version"/>
+ <TextView
+ style="@style/device_info_dialog_value"
+ android:id="@+id/prl_version_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <TextView
+ style="@style/device_info_dialog_label"
+ android:id="@+id/meid_number_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/status_meid_number"/>
+ <TextView
+ style="@style/device_info_dialog_value"
+ android:id="@+id/meid_number_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/gsm_settings"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
+ <TextView
+ style="@style/device_info_dialog_label"
+ android:id="@+id/imei_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/status_imei"/>
+ <TextView
+ style="@style/device_info_dialog_value"
+ android:id="@+id/imei_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+
+ <TextView
+ style="@style/device_info_dialog_label"
+ android:id="@+id/imei_sv_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/status_imei_sv"/>
+ <TextView
+ style="@style/device_info_dialog_value"
+ android:id="@+id/imei_sv_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+ </LinearLayout>
+
+ <TextView
+ style="@style/device_info_dialog_label"
+ android:id="@+id/icc_id_label"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/status_icc_id"/>
+ <TextView
+ style="@style/device_info_dialog_value"
+ android:id="@+id/icc_id_value"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"/>
+ </LinearLayout>
+</ScrollView>
\ No newline at end of file
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8b84849..b5108e6 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2661,6 +2661,10 @@
<string name="storage_settings_summary" product="nosdcard">Unmount USB storage, view available storage</string>
<!-- [CHAR LIMIT=100] Main settings screen item's summary for the SD card and storage settings -->
<string name="storage_settings_summary" product="default">Unmount SD card, view available storage</string>
+ <!-- About phone screen, title for IMEI for multi-sim devices -->
+ <string name="imei_multi_sim_slot_1">IMEI (sim slot 1)</string>
+ <!-- About phone screen, title for IMEI for multi-sim devices -->
+ <string name="imei_multi_sim_slot_2">IMEI (sim slot 2)</string>
<!-- Do not translate. About phone, status item title -->
<string name="status_imei">IMEI</string>
<!-- Do not translate. About phone, status item title -->
@@ -2677,6 +2681,10 @@
<string name="status_msid_number">MSID</string>
<!-- About phone, status item title. The phone PRL Version of the current device.-->
<string name="status_prl_version">PRL version</string>
+ <!-- About phone screen, title for MEID for multi-sim devices -->
+ <string name="meid_multi_sim_sim_slot_1">MEID (sim slot 1)</string>
+ <!-- About phone screen, title for MEID for multi-sim devices -->
+ <string name="meid_multi_sim_sim_slot_2">MEID (sim slot 2)</string>
<!-- About phone, status item title. The phone MEID number of the current LTE/CDMA device. [CHAR LIMIT=30] -->
<string name="status_meid_number">MEID</string>
<!-- About phone, status item title. The ICCID of the current LTE device. [CHAR LIMIT=30] -->
@@ -6555,6 +6563,7 @@
<string name="keywords_payment_settings">pay, tap, payments</string>
<string name="keywords_backup">backup, back up</string>
<string name="keywords_assist_gesture_launch">gesture</string>
+ <string name="keywords_imei_info">imei, meid</string>
<!-- NFC Wi-Fi pairing/setup strings-->
diff --git a/res/values/styles.xml b/res/values/styles.xml
index c9ef22c..8815bb3 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -478,4 +478,14 @@
<item name="android:textSize">@dimen/search_bar_text_size</item>
</style>
+ <style name="device_info_dialog_label">
+ <item name="android:textAppearance">@android:style/TextAppearance.Material.Body1</item>
+ <item name="android:textColor">?android:attr/textColorSecondary</item>
+ </style>
+
+ <style name="device_info_dialog_value">
+ <item name="android:textAppearance">@android:style/TextAppearance.Material.Body2</item>
+ <item name="android:paddingBottom">24dp</item>
+ </style>
+
</resources>
diff --git a/res/xml/color_mode_settings.xml b/res/xml/color_mode_settings.xml
new file mode 100644
index 0000000..b7f58d2
--- /dev/null
+++ b/res/xml/color_mode_settings.xml
@@ -0,0 +1,21 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2017 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:key="color_mode_settings_screen"
+ android:title="@string/color_mode_title" />
diff --git a/res/xml/device_info_settings_v2.xml b/res/xml/device_info_settings_v2.xml
index 0553f1e..794a12b 100644
--- a/res/xml/device_info_settings_v2.xml
+++ b/res/xml/device_info_settings_v2.xml
@@ -40,10 +40,18 @@
android:title="@string/hardware_info"
android:summary="@string/summary_placeholder"/>
- <!-- IMEI -->
+ <!-- IMEI Sim Slot 1 -->
<Preference
- android:key="imei_info"
+ android:key="imei_info_sim_slot_1"
android:title="@string/status_imei"
+ settings:keywords="@string/keywords_imei_info"
+ android:summary="@string/summary_placeholder"/>
+
+ <!-- IMEI Sim Slot 2 -->
+ <Preference
+ android:key="imei_info_sim_slot_2"
+ android:title="@string/imei_multi_sim_slot_2"
+ settings:keywords="@string/keywords_imei_info"
android:summary="@string/summary_placeholder"/>
<!-- Android version -->
diff --git a/src/com/android/settings/DeviceInfoSettings.java b/src/com/android/settings/DeviceInfoSettings.java
index 4479eaa..5a5bec0 100644
--- a/src/com/android/settings/DeviceInfoSettings.java
+++ b/src/com/android/settings/DeviceInfoSettings.java
@@ -32,6 +32,8 @@
import com.android.settings.deviceinfo.FccEquipmentIdPreferenceController;
import com.android.settings.deviceinfo.FeedbackPreferenceController;
import com.android.settings.deviceinfo.FirmwareVersionPreferenceController;
+import com.android.settings.deviceinfo.imei.ImeiInfoDualSimPreferenceController;
+import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceControllerV2;
import com.android.settings.deviceinfo.KernelVersionPreferenceController;
import com.android.settings.deviceinfo.ManualPreferenceController;
import com.android.settings.deviceinfo.RegulatoryInfoPreferenceController;
@@ -120,7 +122,6 @@
Activity activity, Fragment fragment, Lifecycle lifecycle) {
if (FeatureFlagUtils.isEnabled(DEVICE_INFO_V2_FEATURE_FLAG)) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
-
// Device name
// Phone number
@@ -129,7 +130,9 @@
controllers.add(new DeviceModelPreferenceController(context, fragment));
- // IMEI
+ controllers.add(new ImeiInfoPreferenceControllerV2(context, fragment));
+
+ controllers.add(new ImeiInfoDualSimPreferenceController(context, fragment));
// Android version
diff --git a/src/com/android/settings/deviceinfo/ImeiInfoPreferenceController.java b/src/com/android/settings/deviceinfo/ImeiInfoPreferenceController.java
index f564734..456dbfc 100644
--- a/src/com/android/settings/deviceinfo/ImeiInfoPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/ImeiInfoPreferenceController.java
@@ -19,8 +19,13 @@
import android.content.Context;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceControllerV2;
import com.android.settingslib.deviceinfo.AbstractSimStatusImeiInfoPreferenceController;
+/**
+ * deprecated in favour of {@link ImeiInfoPreferenceControllerV2}
+ */
+@Deprecated
public class ImeiInfoPreferenceController extends AbstractSimStatusImeiInfoPreferenceController
implements PreferenceControllerMixin {
diff --git a/src/com/android/settings/deviceinfo/ImeiInformation.java b/src/com/android/settings/deviceinfo/ImeiInformation.java
index 9d4602b..9f38f1b 100644
--- a/src/com/android/settings/deviceinfo/ImeiInformation.java
+++ b/src/com/android/settings/deviceinfo/ImeiInformation.java
@@ -22,7 +22,6 @@
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.text.Spannable;
-import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
@@ -34,7 +33,12 @@
import com.android.internal.telephony.PhoneFactory;
import com.android.settings.R;
import com.android.settings.SettingsPreferenceFragment;
+import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceControllerV2;
+/**
+ * deprecated in favor of {@link ImeiInfoPreferenceControllerV2}
+ */
+@Deprecated
public class ImeiInformation extends SettingsPreferenceFragment {
private static final String KEY_PRL_VERSION = "prl_version";
diff --git a/src/com/android/settings/deviceinfo/imei/AbstractImeiInfoPreferenceController.java b/src/com/android/settings/deviceinfo/imei/AbstractImeiInfoPreferenceController.java
new file mode 100644
index 0000000..a9871a0
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/imei/AbstractImeiInfoPreferenceController.java
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2017 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.deviceinfo.imei;
+
+import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.telephony.TelephonyManager;
+import android.text.TextUtils;
+
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.deviceinfo.AbstractSimStatusImeiInfoPreferenceController;
+
+/**
+ * Controller that manages preference for single and dual sim devices.
+ */
+public abstract class AbstractImeiInfoPreferenceController extends
+ AbstractSimStatusImeiInfoPreferenceController implements PreferenceControllerMixin {
+
+ protected final boolean mIsMultiSim;
+ protected final TelephonyManager mTelephonyManager;
+
+ private Preference mPreference;
+ private Fragment mFragment;
+
+ public AbstractImeiInfoPreferenceController(Context context, Fragment fragment) {
+ super(context);
+
+ mFragment = fragment;
+ mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
+ mIsMultiSim = mTelephonyManager.getPhoneCount() > 1;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ if (mPreference == null) {
+ return;
+ }
+ final int phoneType = mTelephonyManager.getPhoneType();
+ if (phoneType == PHONE_TYPE_CDMA) {
+ mPreference.setTitle(getTitleForCdmaPhone());
+ mPreference.setSummary(getMeid());
+ } else {
+ // GSM phone
+ mPreference.setTitle(getTitleForGsmPhone());
+ mPreference.setSummary(mTelephonyManager.getImei(getSimSlot()));
+ }
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
+ return false;
+ }
+
+ ImeiInfoDialogFragment.show(mFragment, getSimSlot(), mPreference.getTitle().toString());
+ return true;
+ }
+
+ /**
+ * @return The preference title for phones based on CDMA technology.
+ */
+ protected abstract String getTitleForCdmaPhone();
+
+ /**
+ * @return The preference title for phones based on GSM technology.
+ */
+ protected abstract String getTitleForGsmPhone();
+
+ /**
+ * @return The sim slot to retrieve IMEI/CDMA information about.
+ */
+ protected abstract int getSimSlot();
+
+ @VisibleForTesting
+ String getMeid() {
+ return mTelephonyManager.getMeid(getSimSlot());
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
new file mode 100644
index 0000000..542b630
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogController.java
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2017 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.deviceinfo.imei;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.support.annotation.NonNull;
+import android.support.annotation.VisibleForTesting;
+import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.text.Spannable;
+import android.text.SpannableStringBuilder;
+import android.text.Spanned;
+import android.text.TextUtils;
+import android.text.style.TtsSpan;
+
+import com.android.internal.telephony.PhoneConstants;
+import com.android.settings.R;
+
+import java.util.List;
+
+public class ImeiInfoDialogController {
+
+ @VisibleForTesting
+ static final int ID_PRL_VERSION_VALUE = R.id.prl_version_value;
+ private static final int ID_MIN_NUMBER_LABEL = R.id.min_number_label;
+ @VisibleForTesting
+ static final int ID_MIN_NUMBER_VALUE = R.id.min_number_value;
+ @VisibleForTesting
+ static final int ID_MEID_NUMBER_VALUE = R.id.meid_number_value;
+ @VisibleForTesting
+ static final int ID_ICC_ID_LABEL = R.id.icc_id_label;
+ @VisibleForTesting
+ static final int ID_ICC_ID_VALUE = R.id.icc_id_value;
+ @VisibleForTesting
+ static final int ID_IMEI_VALUE = R.id.imei_value;
+ @VisibleForTesting
+ static final int ID_IMEI_SV_VALUE = R.id.imei_sv_value;
+ @VisibleForTesting
+ static final int ID_CDMA_SETTINGS = R.id.cdma_settings;
+ @VisibleForTesting
+ static final int ID_GSM_SETTINGS = R.id.gsm_settings;
+
+ private static CharSequence getTextAsDigits(CharSequence text) {
+ if (TextUtils.isDigitsOnly(text)) {
+ final Spannable spannable = new SpannableStringBuilder(text);
+ final TtsSpan span = new TtsSpan.DigitsBuilder(text.toString()).build();
+ spannable.setSpan(span, 0, spannable.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ text = spannable;
+ }
+ return text;
+ }
+
+ private final ImeiInfoDialogFragment mDialog;
+ private final TelephonyManager mTelephonyManager;
+ private final SubscriptionInfo mSubscriptionInfo;
+ private final int mSlotId;
+
+ public ImeiInfoDialogController(@NonNull ImeiInfoDialogFragment dialog, int slotId) {
+ mDialog = dialog;
+ mSlotId = slotId;
+ final Context context = dialog.getContext();
+ mTelephonyManager = (TelephonyManager) context.getSystemService(
+ Context.TELEPHONY_SERVICE);
+ mSubscriptionInfo = getSubscriptionInfo(context, slotId);
+ }
+
+ /**
+ * Sets IMEI/MEID information based on whether the device is CDMA or GSM.
+ */
+ public void populateImeiInfo() {
+ if (mSubscriptionInfo == null) {
+ return;
+ }
+ if (mTelephonyManager.getPhoneType() == TelephonyManager.PHONE_TYPE_CDMA) {
+ updateDialogForCdmaPhone();
+ } else {
+ updateDialogForGsmPhone();
+ }
+ }
+
+ private void updateDialogForCdmaPhone() {
+ final Resources res = mDialog.getContext().getResources();
+ mDialog.setText(ID_MEID_NUMBER_VALUE, getMeid());
+ mDialog.setText(ID_MIN_NUMBER_VALUE,
+ mTelephonyManager.getCdmaMin(mSubscriptionInfo.getSubscriptionId()));
+
+ if (res.getBoolean(R.bool.config_msid_enable)) {
+ mDialog.setText(ID_MIN_NUMBER_LABEL,
+ res.getString(R.string.status_msid_number));
+ }
+
+ mDialog.setText(ID_PRL_VERSION_VALUE, getCdmaPrlVersion());
+
+ if (isCdmaLteEnabled()) {
+ // Show ICC ID and IMEI for LTE device
+ mDialog.setText(ID_ICC_ID_VALUE, mSubscriptionInfo.getIccId());
+ mDialog.setText(ID_IMEI_VALUE,
+ getTextAsDigits(mTelephonyManager.getImei(mSlotId)));
+ mDialog.setText(ID_IMEI_SV_VALUE,
+ getTextAsDigits(mTelephonyManager.getDeviceSoftwareVersion(mSlotId)));
+ } else {
+ // device is not GSM/UMTS, do not display GSM/UMTS features
+ mDialog.removeViewFromScreen(ID_GSM_SETTINGS);
+ mDialog.removeViewFromScreen(ID_ICC_ID_LABEL);
+ mDialog.removeViewFromScreen(ID_ICC_ID_VALUE);
+ }
+ }
+
+ private void updateDialogForGsmPhone() {
+ mDialog.setText(ID_IMEI_VALUE, getTextAsDigits(mTelephonyManager.getImei(mSlotId)));
+ mDialog.setText(ID_IMEI_SV_VALUE,
+ getTextAsDigits(mTelephonyManager.getDeviceSoftwareVersion(mSlotId)));
+ // device is not CDMA, do not display CDMA features
+ mDialog.removeViewFromScreen(ID_CDMA_SETTINGS);
+ mDialog.removeViewFromScreen(ID_ICC_ID_LABEL);
+ mDialog.removeViewFromScreen(ID_ICC_ID_VALUE);
+ }
+
+ private SubscriptionInfo getSubscriptionInfo(Context context, int slotId) {
+ final List<SubscriptionInfo> subscriptionInfoList = SubscriptionManager.from(context)
+ .getActiveSubscriptionInfoList();
+ if (subscriptionInfoList == null) {
+ return null;
+ }
+
+ return subscriptionInfoList.get(slotId);
+ }
+
+ @VisibleForTesting
+ String getCdmaPrlVersion() {
+ return mTelephonyManager.getCdmaPrlVersion();
+ }
+
+ @VisibleForTesting
+ boolean isCdmaLteEnabled() {
+ return mTelephonyManager.getLteOnCdmaMode(mSubscriptionInfo.getSubscriptionId())
+ == PhoneConstants.LTE_ON_CDMA_TRUE;
+ }
+
+ @VisibleForTesting
+ String getMeid() {
+ return mTelephonyManager.getMeid(mSlotId);
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogFragment.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogFragment.java
new file mode 100644
index 0000000..11e66f1
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogFragment.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 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.deviceinfo.imei;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.VisibleForTesting;
+import android.text.TextUtils;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.TextView;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+
+public class ImeiInfoDialogFragment extends InstrumentedDialogFragment {
+
+ @VisibleForTesting
+ static final String TAG = "ImeiInfoDialog";
+
+ private static final String SLOT_ID_BUNDLE_KEY = "arg_key_slot_id";
+ private static final String DIALOG_TITLE_BUNDLE_KEY = "arg_key_dialog_title";
+
+ private View mRootView;
+
+ public static void show(@NonNull Fragment host, int slotId, String dialogTitle) {
+ final FragmentManager manager = host.getChildFragmentManager();
+ if (manager.findFragmentByTag(TAG) == null) {
+ final Bundle bundle = new Bundle();
+ bundle.putInt(SLOT_ID_BUNDLE_KEY, slotId);
+ bundle.putString(DIALOG_TITLE_BUNDLE_KEY, dialogTitle);
+ final ImeiInfoDialogFragment dialog = new ImeiInfoDialogFragment();
+ dialog.setArguments(bundle);
+ dialog.show(manager, TAG);
+ }
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.DIALOG_IMEI_INFO;
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ final Bundle bundle = getArguments();
+ final int slotId = bundle.getInt(SLOT_ID_BUNDLE_KEY);
+ final String dialogTitle = bundle.getString(DIALOG_TITLE_BUNDLE_KEY);
+
+ final ImeiInfoDialogController controller = new ImeiInfoDialogController(this, slotId);
+ final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
+ .setTitle(dialogTitle)
+ .setPositiveButton(android.R.string.ok, null);
+ mRootView = LayoutInflater.from(builder.getContext())
+ .inflate(R.layout.dialog_imei_info, null /* parent */);
+ controller.populateImeiInfo();
+ return builder.setView(mRootView).create();
+ }
+
+ public void removeViewFromScreen(int viewId) {
+ final View view = mRootView.findViewById(viewId);
+ if (view != null) {
+ view.setVisibility(View.GONE);
+ }
+ }
+
+ public void setText(int viewId, CharSequence text) {
+ final TextView textView = mRootView.findViewById(viewId);
+ if (TextUtils.isEmpty(text)) {
+ text = getResources().getString(R.string.device_info_default);
+ }
+ if (textView != null) {
+ textView.setText(text);
+ }
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoDualSimPreferenceController.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoDualSimPreferenceController.java
new file mode 100644
index 0000000..61d99b9
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoDualSimPreferenceController.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2017 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.deviceinfo.imei;
+
+import android.app.Fragment;
+import android.content.Context;
+
+import com.android.settings.R;
+
+public class ImeiInfoDualSimPreferenceController extends AbstractImeiInfoPreferenceController {
+
+ private static final String KEY_IMEI_INFO_DUAL_SIM = "imei_info_sim_slot_2";
+ private static final int SIM_SLOT = 1;
+
+ public ImeiInfoDualSimPreferenceController(Context context, Fragment fragment) {
+ super(context, fragment);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return super.isAvailable() && mIsMultiSim;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_IMEI_INFO_DUAL_SIM;
+ }
+
+ @Override
+ protected String getTitleForCdmaPhone() {
+ return mContext.getResources().getString(R.string.meid_multi_sim_sim_slot_2);
+ }
+
+ @Override
+ protected String getTitleForGsmPhone() {
+ return mContext.getResources().getString(R.string.imei_multi_sim_slot_2);
+ }
+
+ @Override
+ protected int getSimSlot() {
+ return SIM_SLOT;
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2.java
new file mode 100644
index 0000000..74448bb
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2017 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.deviceinfo.imei;
+
+import android.app.Fragment;
+import android.content.Context;
+
+import com.android.settings.R;
+
+public class ImeiInfoPreferenceControllerV2 extends AbstractImeiInfoPreferenceController {
+
+ public static final int SIM_SLOT = 0;
+
+ private static final String KEY_IMEI_INFO = "imei_info_sim_slot_1";
+
+ public ImeiInfoPreferenceControllerV2(Context context, Fragment fragment) {
+ super(context, fragment);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_IMEI_INFO;
+ }
+
+ @Override
+ protected String getTitleForCdmaPhone() {
+ return mIsMultiSim ? mContext.getResources().getString(R.string.meid_multi_sim_sim_slot_1)
+ : mContext.getResources().getString(R.string.status_meid_number);
+ }
+
+ @Override
+ protected String getTitleForGsmPhone() {
+ return mIsMultiSim ? mContext.getResources().getString(R.string.imei_multi_sim_slot_1)
+ : mContext.getResources().getString(R.string.status_imei);
+ }
+
+ @Override
+ protected int getSimSlot() {
+ return SIM_SLOT;
+ }
+}
diff --git a/src/com/android/settings/display/ColorModePreferenceFragment.java b/src/com/android/settings/display/ColorModePreferenceFragment.java
index 07cf82e..9f18fd8 100644
--- a/src/com/android/settings/display/ColorModePreferenceFragment.java
+++ b/src/com/android/settings/display/ColorModePreferenceFragment.java
@@ -45,6 +45,11 @@
}
@Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.color_mode_settings;
+ }
+
+ @Override
protected List<? extends CandidateInfo> getCandidates() {
Context c = getContext();
return Arrays.asList(
diff --git a/src/com/android/settings/widget/RadioButtonPickerFragment.java b/src/com/android/settings/widget/RadioButtonPickerFragment.java
index 7489a77..c768909 100644
--- a/src/com/android/settings/widget/RadioButtonPickerFragment.java
+++ b/src/com/android/settings/widget/RadioButtonPickerFragment.java
@@ -83,6 +83,9 @@
}
@Override
+ protected abstract int getPreferenceScreenResId();
+
+ @Override
public void onRadioButtonClicked(RadioButtonPreference selected) {
final String selectedKey = selected.getKey();
onRadioButtonConfirmed(selectedKey);
diff --git a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragmentTest.java b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragmentTest.java
index 3621edd..42a6225 100644
--- a/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/applications/defaultapps/DefaultAppPickerFragmentTest.java
@@ -115,6 +115,11 @@
}
@Override
+ protected int getPreferenceScreenResId() {
+ return 0;
+ }
+
+ @Override
protected List<DefaultAppInfo> getCandidates() {
return new ArrayList<>();
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/AbstractImeiInfoPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/AbstractImeiInfoPreferenceControllerTest.java
new file mode 100644
index 0000000..51e6005
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/AbstractImeiInfoPreferenceControllerTest.java
@@ -0,0 +1,143 @@
+/*
+ * Copyright (C) 2017 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.deviceinfo.imei;
+
+import static android.telephony.TelephonyManager.PHONE_TYPE_CDMA;
+import static android.telephony.TelephonyManager.PHONE_TYPE_GSM;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Fragment;
+import android.app.FragmentManager;
+import android.content.Context;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.telephony.TelephonyManager;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class AbstractImeiInfoPreferenceControllerTest {
+
+ @Mock
+ private Preference mPreference;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private UserManager mUserManager;
+ @Mock
+ private Fragment mFragment;
+
+ private Context mContext;
+ private AbstractImeiInfoPreferenceControllerImpl mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
+ mController = new AbstractImeiInfoPreferenceControllerImpl(mContext, mFragment);
+ ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void displayPreference_cdmaPhone_shouldSetCdmaTitleAndMeid() {
+ mController = spy(mController);
+ final String meid = "125132215123";
+ when(mTelephonyManager.getPhoneType()).thenReturn(PHONE_TYPE_CDMA);
+ doReturn(meid).when(mController).getMeid();
+
+ mController.displayPreference(mScreen);
+
+ verify(mPreference).setTitle(mController.getTitleForCdmaPhone());
+ verify(mPreference).setSummary(meid);
+ }
+
+ @Test
+ public void displayPreference_gsmPhone_shouldSetGsmTitleAndImei() {
+ final String imei = "125132215123";
+ when(mTelephonyManager.getPhoneType()).thenReturn(PHONE_TYPE_GSM);
+ when(mTelephonyManager.getImei(anyInt())).thenReturn(imei);
+
+ mController.displayPreference(mScreen);
+
+ verify(mPreference).setTitle(mController.getTitleForGsmPhone());
+ verify(mPreference).setSummary(imei);
+ }
+
+ @Test
+ public void handlePreferenceTreeClick_shouldStartDialogFragment() {
+ when(mFragment.getChildFragmentManager()).thenReturn(
+ mock(FragmentManager.class, Answers.RETURNS_DEEP_STUBS));
+ when(mPreference.getTitle()).thenReturn("SomeTitle");
+ mController.displayPreference(mScreen);
+
+ mController.handlePreferenceTreeClick(mPreference);
+
+ verify(mFragment).getChildFragmentManager();
+ }
+
+ public class AbstractImeiInfoPreferenceControllerImpl extends
+ AbstractImeiInfoPreferenceController {
+
+ public AbstractImeiInfoPreferenceControllerImpl(Context context, Fragment fragment) {
+ super(context, fragment);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return "foobar";
+ }
+
+ @Override
+ protected String getTitleForCdmaPhone() {
+ return "foo";
+ }
+
+ @Override
+ protected String getTitleForGsmPhone() {
+ return "bar";
+ }
+
+ @Override
+ protected int getSimSlot() {
+ return 0;
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
new file mode 100644
index 0000000..bb4933b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDialogControllerTest.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (C) 2017 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.deviceinfo.imei;
+
+import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_CDMA_SETTINGS;
+import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_GSM_SETTINGS;
+import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_ICC_ID_LABEL;
+import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_ICC_ID_VALUE;
+import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_IMEI_SV_VALUE;
+import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_IMEI_VALUE;
+import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_MEID_NUMBER_VALUE;
+import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_MIN_NUMBER_VALUE;
+import static com.android.settings.deviceinfo.imei.ImeiInfoDialogController.ID_PRL_VERSION_VALUE;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.telephony.SubscriptionInfo;
+import android.telephony.TelephonyManager;
+
+import com.android.settings.TestConfig;
+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;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ImeiInfoDialogControllerTest {
+
+ private static final String PRL_VERSION = "some_prl_version";
+ private static final String MEID_NUMBER = "12871234124";
+ private static final String IMEI_NUMBER = "2341982751254";
+ private static final String MIN_NUMBER = "123417851315";
+ private static final String ICCID_NUMBER = "3845672472";
+ private static final String IMEI_SV_NUMBER = "12";
+
+ @Mock
+ private ImeiInfoDialogFragment mDialog;
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private SubscriptionInfo mSubscriptionInfo;
+
+ private Context mContext;
+ private ImeiInfoDialogController mController;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
+ when(mDialog.getContext()).thenReturn(mContext);
+ mController = spy(new ImeiInfoDialogController(mDialog, 0 /* phone id */));
+ ReflectionHelpers.setField(mController, "mSubscriptionInfo", mSubscriptionInfo);
+
+ doReturn(PRL_VERSION).when(mController).getCdmaPrlVersion();
+ doReturn(MEID_NUMBER).when(mController).getMeid();
+ when(mTelephonyManager.getCdmaMin(anyInt())).thenReturn(MIN_NUMBER);
+ when(mSubscriptionInfo.getIccId()).thenReturn(ICCID_NUMBER);
+ when(mTelephonyManager.getDeviceSoftwareVersion(anyInt())).thenReturn(IMEI_SV_NUMBER);
+ when(mTelephonyManager.getImei(anyInt())).thenReturn(IMEI_NUMBER);
+ }
+
+ @Test
+ public void populateImeiInfo_cdmaLteEnabled_shouldSetMeidAndImeiAndMin() {
+ doReturn(true).when(mController).isCdmaLteEnabled();
+ when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
+
+ mController.populateImeiInfo();
+
+ verify(mDialog).setText(ID_MEID_NUMBER_VALUE, MEID_NUMBER);
+ verify(mDialog).setText(ID_MIN_NUMBER_VALUE, MIN_NUMBER);
+ verify(mDialog).setText(ID_PRL_VERSION_VALUE, PRL_VERSION);
+ verify(mDialog).setText(ID_ICC_ID_VALUE, ICCID_NUMBER);
+ verify(mDialog).setText(eq(ID_IMEI_VALUE), any());
+ verify(mDialog).setText(eq(ID_IMEI_SV_VALUE), any());
+ }
+
+ @Test
+ public void populateImeiInfo_cdmaLteDisabled_shouldSetMeidAndMinAndRemoveGsmSettings() {
+ doReturn(false).when(mController).isCdmaLteEnabled();
+ when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_CDMA);
+
+ mController.populateImeiInfo();
+
+ verify(mDialog).setText(ID_MEID_NUMBER_VALUE, MEID_NUMBER);
+ verify(mDialog).setText(ID_MIN_NUMBER_VALUE, MIN_NUMBER);
+ verify(mDialog).setText(ID_PRL_VERSION_VALUE, PRL_VERSION);
+ verify(mDialog).removeViewFromScreen(ID_GSM_SETTINGS);
+ verify(mDialog).removeViewFromScreen(ID_ICC_ID_VALUE);
+ verify(mDialog).removeViewFromScreen(ID_ICC_ID_LABEL);
+ }
+
+ @Test
+ public void populateImeinfo_gsm_shouldSetImeiAndRemoveCdmaSettings() {
+ when(mTelephonyManager.getPhoneType()).thenReturn(TelephonyManager.PHONE_TYPE_GSM);
+
+ mController.populateImeiInfo();
+
+ verify(mDialog).setText(eq(ID_IMEI_VALUE), any());
+ verify(mDialog).setText(eq(ID_IMEI_SV_VALUE), any());
+ verify(mDialog).removeViewFromScreen(ID_CDMA_SETTINGS);
+ verify(mDialog).removeViewFromScreen(ID_ICC_ID_VALUE);
+ verify(mDialog).removeViewFromScreen(ID_ICC_ID_LABEL);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDualSimPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDualSimPreferenceControllerTest.java
new file mode 100644
index 0000000..ce99ee4
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoDualSimPreferenceControllerTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2017 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.deviceinfo.imei;
+
+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.when;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.telephony.TelephonyManager;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+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;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ImeiInfoDualSimPreferenceControllerTest {
+
+ @Mock
+ private Preference mPreference;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private UserManager mUserManager;
+ @Mock
+ private Fragment mFragment;
+
+ private Context mContext;
+ private ImeiInfoDualSimPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
+ mController = new ImeiInfoDualSimPreferenceController(mContext, mFragment);
+ ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void getTitleForCdmaPhone_shouldReturnCdmaMultiSimString() {
+ ReflectionHelpers.setField(mController, "mIsMultiSim", true);
+
+ assertThat(mController.getTitleForCdmaPhone()).isEqualTo(mContext.getResources().getString(
+ R.string.meid_multi_sim_sim_slot_2));
+ }
+
+ @Test
+ public void getTitleForGsmPhone_shouldReturnGsmMultiSimString() {
+ ReflectionHelpers.setField(mController, "mIsMultiSim", true);
+
+ assertThat(mController.getTitleForGsmPhone()).isEqualTo(mContext.getResources().getString(
+ R.string.imei_multi_sim_slot_2));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2Test.java b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2Test.java
new file mode 100644
index 0000000..233e27e
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceControllerV2Test.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright (C) 2017 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.deviceinfo.imei;
+
+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.when;
+
+import android.app.Fragment;
+import android.content.Context;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.telephony.TelephonyManager;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+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;
+import org.robolectric.annotation.Config;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class ImeiInfoPreferenceControllerV2Test {
+
+ @Mock
+ private Preference mPreference;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private UserManager mUserManager;
+ @Mock
+ private Fragment mFragment;
+
+ private Context mContext;
+ private ImeiInfoPreferenceControllerV2 mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mUserManager).when(mContext).getSystemService(UserManager.class);
+ mController = new ImeiInfoPreferenceControllerV2(mContext, mFragment);
+ ReflectionHelpers.setField(mController, "mTelephonyManager", mTelephonyManager);
+ when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
+ when(mPreference.getKey()).thenReturn(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void getTitleForCdmaPhone_noMultiSim_shouldReturnCdmaNoMultiSimString() {
+ ReflectionHelpers.setField(mController, "mIsMultiSim", false);
+
+ assertThat(mController.getTitleForCdmaPhone()).isEqualTo(mContext.getResources().getString(
+ R.string.status_meid_number));
+ }
+
+ @Test
+ public void getTitleForCdmaPhone_multiSim_shouldReturnCdmaMultiSimString() {
+ ReflectionHelpers.setField(mController, "mIsMultiSim", true);
+
+ assertThat(mController.getTitleForCdmaPhone()).isEqualTo(mContext.getResources().getString(
+ R.string.meid_multi_sim_sim_slot_1));
+ }
+
+ @Test
+ public void getTitleForGsmPhone_noMultiSim_shouldReturnGsmNoMultiSimString() {
+ ReflectionHelpers.setField(mController, "mIsMultiSim", false);
+
+ assertThat(mController.getTitleForGsmPhone()).isEqualTo(mContext.getResources().getString(
+ R.string.status_imei));
+ }
+
+ @Test
+ public void getTitleForGsmPhone_multiSim_shouldReturnGsmMultiSimString() {
+ ReflectionHelpers.setField(mController, "mIsMultiSim", true);
+
+ assertThat(mController.getTitleForGsmPhone()).isEqualTo(mContext.getResources().getString(
+ R.string.imei_multi_sim_slot_1));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
index 9ee79ff..fb9bb9f 100644
--- a/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/display/ColorModePreferenceFragmentTest.java
@@ -16,11 +16,18 @@
package com.android.settings.display;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.os.Bundle;
+
import com.android.internal.app.NightDisplayController;
import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
@@ -111,20 +118,31 @@
@Test
public void setKey_natural() {
mFragment.setDefaultKey(ColorModePreferenceFragment.KEY_COLOR_MODE_NATURAL);
- Mockito.verify(mController).setColorMode(NightDisplayController.COLOR_MODE_NATURAL);
+ verify(mController).setColorMode(NightDisplayController.COLOR_MODE_NATURAL);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void setKey_boosted() {
mFragment.setDefaultKey(ColorModePreferenceFragment.KEY_COLOR_MODE_BOOSTED);
- Mockito.verify(mController).setColorMode(NightDisplayController.COLOR_MODE_BOOSTED);
+ verify(mController).setColorMode(NightDisplayController.COLOR_MODE_BOOSTED);
}
@Config(shadows = {SettingsShadowSystemProperties.class})
@Test
public void setKey_saturated() {
mFragment.setDefaultKey(ColorModePreferenceFragment.KEY_COLOR_MODE_SATURATED);
- Mockito.verify(mController).setColorMode(NightDisplayController.COLOR_MODE_SATURATED);
+ verify(mController).setColorMode(NightDisplayController.COLOR_MODE_SATURATED);
}
+
+ @Test
+ public void onCreatePreferences_useNewTitle_shouldAddColorModePreferences() {
+ doNothing().when(mFragment).addPreferencesFromResource(anyInt());
+ doNothing().when(mFragment).updateCandidates();
+
+ mFragment.onCreatePreferences(Bundle.EMPTY, null /* rootKey */);
+
+ verify(mFragment).addPreferencesFromResource(R.xml.color_mode_settings);
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java b/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java
index 40d73eb..8ca68ae 100644
--- a/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/widget/RadioButtonPickerFragmentTest.java
@@ -114,6 +114,11 @@
}
@Override
+ protected int getPreferenceScreenResId() {
+ return 0;
+ }
+
+ @Override
protected List<DefaultAppInfo> getCandidates() {
return new ArrayList<>();
}