Merge "Do not show Provisioning items for IMS if it is not enabled."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index ef8b3c0..5c0256b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3341,6 +3341,17 @@
<service android:name=".fuelgauge.batterytip.AnomalyDetectionJobService"
android:permission="android.permission.BIND_JOB_SERVICE" />
+ <activity
+ android:name="Settings$WifiCallingDisclaimerActivity"
+ android:label="@string/wifi_calling_settings_title"
+ android:taskAffinity="com.android.settings">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.wifi.calling.WifiCallingDisclaimerFragment" />
+ </activity>
<!-- This is the longest AndroidManifest.xml ever. -->
</application>
</manifest>
diff --git a/res/layout/wfc_disclaimer_fragment.xml b/res/layout/wfc_disclaimer_fragment.xml
new file mode 100644
index 0000000..00baae5
--- /dev/null
+++ b/res/layout/wfc_disclaimer_fragment.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <TextView
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:layout_marginStart="16dp"
+ android:layout_marginBottom="20dp"
+ android:textAppearance="?android:attr/textAppearanceLarge"
+ android:text="@string/wfc_disclaimer_title_text" />
+
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="1dp"
+ android:background="?android:attr/listDivider" />
+
+ <androidx.recyclerview.widget.RecyclerView
+ android:id="@+id/disclaimer_item_list"
+ android:layout_width="match_parent"
+ android:layout_height="0dp"
+ android:layout_weight="1" />
+
+ <LinearLayout
+ android:orientation="horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content" >
+
+ <Button
+ android:id="@+id/disagree_button"
+ style="@style/DisclaimerNegativeButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:text="@string/wfc_disclaimer_disagree_text" />
+
+ <Space
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_weight="1" />
+
+ <Button
+ android:id="@+id/agree_button"
+ style="@style/DisclaimerPositiveButton"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:text="@string/wfc_disclaimer_agree_button_text" />
+ </LinearLayout>
+</LinearLayout>
diff --git a/res/layout/wfc_simple_disclaimer_item.xml b/res/layout/wfc_simple_disclaimer_item.xml
new file mode 100644
index 0000000..ee43182
--- /dev/null
+++ b/res/layout/wfc_simple_disclaimer_item.xml
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingTop="16dp"
+ android:paddingBottom="20dp"
+ android:paddingStart="16dp"
+ android:paddingEnd="16dp"
+ android:gravity="center_vertical">
+ <TextView
+ android:id="@+id/disclaimer_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="@android:style/TextAppearance.Material.Subhead" />
+ <TextView
+ android:id="@+id/disclaimer_desc"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="@android:style/TextAppearance.Material.Body1"
+ android:textColor="?android:attr/textColorSecondary"
+ android:layout_below="@id/disclaimer_title" />
+</RelativeLayout>
\ No newline at end of file
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index a3a9865..930e21e 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1165,4 +1165,17 @@
<item>0</item>
</string-array>
+ <!-- WiFi calling mode array -->
+ <string-array name="wifi_calling_mode_summaries" translatable="false">
+ <item>@string/wifi_calling_mode_wifi_preferred_summary</item>
+ <item>@string/wifi_calling_mode_cellular_preferred_summary</item>
+ <item>@string/wifi_calling_mode_wifi_only_summary</item>
+ </string-array>
+
+ <!-- WiFi calling mode array without wifi only mode -->
+ <string-array name="wifi_calling_mode_summaries_without_wifi_only" translatable="false">
+ <item>@string/wifi_calling_mode_wifi_preferred_summary</item>
+ <item>@string/wifi_calling_mode_cellular_preferred_summary</item>
+ </string-array>
+
</resources>
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index 33573ac..181af40 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -149,6 +149,11 @@
<attr name="aspectRatio" format="float" />
</declare-styleable>
+ <declare-styleable name="ListWithEntrySummaryPreference">
+ <!-- Summaries of entry -->
+ <attr name="entrySummaries" format="reference" />
+ </declare-styleable>
+
<!-- For UsageView -->
<declare-styleable name="UsageView">
<attr name="android:colorAccent" />
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 2c52c3a..ae12511 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -291,6 +291,15 @@
<dimen name="password_requirement_textsize">14sp</dimen>
+ <!-- Visible vertical space we want to show below password edittext field when ime is shown.
+ The unit is sp as it is related to the text size of password requirement item. -->
+ <dimen name="visible_vertical_space_below_password">20sp</dimen>
+
+ <!-- Select dialog -->
+ <dimen name="select_dialog_padding_start">20dp</dimen>
+ <dimen name="select_dialog_item_margin_start">12dp</dimen>
+ <dimen name="select_dialog_summary_padding_bottom">8dp</dimen>
+
<!-- Padding between the donut and the storage summary. -->
<dimen name="storage_summary_padding_end">16dp</dimen>
<!-- Text size of the big number in the donut. -->
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c55bcfc..8790dcb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2302,7 +2302,7 @@
<!-- Title of WFC preference item [CHAR LIMIT=30] -->
<string name="wifi_calling_mode_title">Calling preference</string>
<!-- Title of WFC preference selection dialog [CHAR LIMIT=30] -->
- <string name="wifi_calling_mode_dialog_title">Wi-Fi calling mode</string>
+ <string name="wifi_calling_mode_dialog_title">Calling preference</string>
<!-- Title of WFC roaming preference item [CHAR LIMIT=45] -->
<string name="wifi_calling_roaming_mode_title">Roaming preference</string>
<!-- Summary of WFC roaming preference item [CHAR LIMIT=NONE]-->
@@ -2310,9 +2310,9 @@
<!-- WFC mode dialog [CHAR LIMIT=45] -->
<string name="wifi_calling_roaming_mode_dialog_title">Roaming preference</string>
<string-array name="wifi_calling_mode_choices">
- <item>Wi-Fi preferred</item>
- <item>Mobile preferred</item>
- <item>Wi-Fi only</item>
+ <item>@*android:string/wfc_mode_wifi_preferred_summary</item>
+ <item>@*android:string/wfc_mode_cellular_preferred_summary</item>
+ <item>@*android:string/wfc_mode_wifi_only_summary</item>
</string-array>
<string-array name="wifi_calling_mode_choices_v2">
<item>Wi-Fi</item>
@@ -2325,8 +2325,8 @@
<item>"0"</item>
</string-array>
<string-array name="wifi_calling_mode_choices_without_wifi_only">
- <item>Wi-Fi preferred</item>
- <item>Mobile preferred</item>
+ <item>@*android:string/wfc_mode_wifi_preferred_summary</item>
+ <item>@*android:string/wfc_mode_cellular_preferred_summary</item>
</string-array>
<string-array name="wifi_calling_mode_choices_v2_without_wifi_only">
<item>Wi-Fi</item>
@@ -2336,6 +2336,14 @@
<item>"2"</item>
<item>"1"</item>
</string-array>
+
+ <!-- Summary of WFC preference item on the WFC preference selection dialog. [CHAR LIMIT=70]-->
+ <string name="wifi_calling_mode_wifi_preferred_summary">If Wi\u2011Fi is unavailable, use mobile network</string>
+ <!-- Summary of WFC preference item on the WFC preference selection dialog. [CHAR LIMIT=70]-->
+ <string name="wifi_calling_mode_cellular_preferred_summary">If mobile network is unavailable, use Wi\u2011Fi</string>
+ <!-- Summary of WFC preference item on the WFC preference selection dialog. [CHAR LIMIT=70]-->
+ <string name="wifi_calling_mode_wifi_only_summary">Call over Wi\u2011Fi. If Wi\u2011Fi is lost, call will end.</string>
+
<!-- Wi-Fi Calling settings. Text displayed when Wi-Fi Calling is off -->
<string name="wifi_calling_off_explanation">When Wi-Fi calling is on, your phone can route calls via Wi-Fi networks or your carrier\u2019s network, depending on your preference and which signal is stronger. Before turning on this feature, check with your carrier regarding fees and other details.<xliff:g id="additional_text" example="Learn More">%1$s</xliff:g></string>
<!-- Wi-Fi Calling settings. Additional text displayed when Wi-Fi Calling is off. Default empty. [CHAR LIMIT=NONE] -->
@@ -10080,4 +10088,13 @@
<!-- Title for Connected device shortcut [CHAR LIMIT=30] -->
<string name="devices_title">Devices</string>
+
+ <!-- Label for the title on wfc disclaimer fragment. [CHAR LIMIT=40] -->
+ <string name="wfc_disclaimer_title_text">Important information</string>
+
+ <!-- Label for the agree button on wfc disclaimer fragment. [CHAR LIMIT=30] -->
+ <string name="wfc_disclaimer_agree_button_text">CONTINUE</string>
+
+ <!-- Label for the disagree button on wfc disclaimer fragment. [CHAR LIMIT=30] -->
+ <string name="wfc_disclaimer_disagree_text">NO THANKS</string>
</resources>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index f82d0e5..e171713 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -506,4 +506,16 @@
<item name="android:paddingBottom">24dp</item>
</style>
+ <style name="DisclaimerPositiveButton" parent="@style/SuwGlifButton.Primary">
+ <item name="android:layout_margin">16dp</item>
+ <item name="android:paddingStart">8dp</item>
+ <item name="android:paddingEnd">8dp</item>
+ </style>
+
+ <style name="DisclaimerNegativeButton" parent="@style/SuwGlifButton.Secondary">
+ <item name="android:layout_margin">16dp</item>
+ <item name="android:paddingStart">8dp</item>
+ <item name="android:paddingEnd">8dp</item>
+ </style>
+
</resources>
diff --git a/res/xml/single_choice_list_item_2.xml b/res/xml/single_choice_list_item_2.xml
new file mode 100644
index 0000000..ca80f44
--- /dev/null
+++ b/res/xml/single_choice_list_item_2.xml
@@ -0,0 +1,58 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingStart="@dimen/select_dialog_padding_start"
+ android:paddingEnd="?android:attr/dialogPreferredPadding"
+ android:orientation="horizontal"
+ android:descendantFocusability="blocksDescendants">
+
+ <RadioButton
+ android:id="@+id/radio"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:clickable="false" />
+
+ <LinearLayout
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:orientation="vertical"
+ android:layout_marginStart="@dimen/select_dialog_item_margin_start"
+ android:layout_gravity="center_vertical">
+
+ <TextView
+ android:id="@+id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:textColor="?android:attr/textColorAlertDialogListItem"
+ android:ellipsize="marquee" />
+
+ <TextView
+ android:id="@+id/summary"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:paddingBottom="@dimen/select_dialog_summary_padding_bottom"
+ android:textAppearance="?android:attr/textAppearanceListItemSecondary"
+ android:textColor="?android:attr/textColorSecondary"
+ android:maxLines="10" />
+
+ </LinearLayout>
+</LinearLayout>
diff --git a/res/xml/wifi_calling_settings.xml b/res/xml/wifi_calling_settings.xml
index 0adb1e8..0276bdb 100644
--- a/res/xml/wifi_calling_settings.xml
+++ b/res/xml/wifi_calling_settings.xml
@@ -15,24 +15,27 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
android:key="wifi_calling_settings"
android:title="@string/wifi_calling_settings_title">
- <ListPreference
+ <com.android.settings.wifi.calling.ListWithEntrySummaryPreference
android:key="wifi_calling_mode"
android:title="@string/wifi_calling_mode_title"
android:summary="@string/wifi_calling_mode_title"
android:entries="@array/wifi_calling_mode_choices"
android:entryValues="@array/wifi_calling_mode_values"
- android:dialogTitle="@string/wifi_calling_mode_dialog_title" />
+ android:dialogTitle="@string/wifi_calling_mode_dialog_title"
+ settings:entrySummaries="@array/wifi_calling_mode_summaries" />
- <ListPreference
+ <com.android.settings.wifi.calling.ListWithEntrySummaryPreference
android:key="wifi_calling_roaming_mode"
android:title="@string/wifi_calling_roaming_mode_title"
android:summary="@string/wifi_calling_roaming_mode_summary"
android:entries="@array/wifi_calling_mode_choices_v2"
android:entryValues="@array/wifi_calling_mode_values"
- android:dialogTitle="@string/wifi_calling_roaming_mode_dialog_title" />
+ android:dialogTitle="@string/wifi_calling_roaming_mode_dialog_title"
+ settings:entrySummaries="@array/wifi_calling_mode_summaries" />
<Preference
android:key="emergency_address_key"
diff --git a/src/com/android/settings/ResetNetworkConfirm.java b/src/com/android/settings/ResetNetworkConfirm.java
index 99f2df6..950a0b0 100644
--- a/src/com/android/settings/ResetNetworkConfirm.java
+++ b/src/com/android/settings/ResetNetworkConfirm.java
@@ -154,20 +154,9 @@
SubscriptionManager.getPhoneId(mSubId)).factoryReset();
restoreDefaultApn(context);
esimFactoryReset(context, context.getPackageName());
- // There has been issues when Sms raw table somehow stores orphan
- // fragments. They lead to garbled message when new fragments come
- // in and combied with those stale ones. In case this happens again,
- // user can reset all network settings which will clean up this table.
- cleanUpSmsRawTable(context);
}
};
- private void cleanUpSmsRawTable(Context context) {
- ContentResolver resolver = context.getContentResolver();
- Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete");
- resolver.delete(uri, null, null);
- }
-
@VisibleForTesting
void esimFactoryReset(Context context, String packageName) {
if (mEraseEsim) {
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index cd5a908..903e49e 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -156,6 +156,7 @@
}
public static class WebViewAppPickerActivity extends SettingsActivity { /* empty */ }
public static class AdvancedConnectedDeviceActivity extends SettingsActivity { /* empty */ }
+ public static class WifiCallingDisclaimerActivity extends SettingsActivity { /* empty */ }
// Top level categories for new IA
public static class NetworkDashboardActivity extends SettingsActivity {}
diff --git a/src/com/android/settings/development/FileEncryptionPreferenceController.java b/src/com/android/settings/development/FileEncryptionPreferenceController.java
index 731f487..a988fdd 100644
--- a/src/com/android/settings/development/FileEncryptionPreferenceController.java
+++ b/src/com/android/settings/development/FileEncryptionPreferenceController.java
@@ -63,7 +63,8 @@
@Override
public void updateState(Preference preference) {
- if (!TextUtils.equals("file", CryptoProperties.type().orElse("none"))) {
+ if (CryptoProperties.type().orElse(CryptoProperties.type_values.NONE) !=
+ CryptoProperties.type_values.FILE) {
return;
}
diff --git a/src/com/android/settings/wifi/calling/DisclaimerItem.java b/src/com/android/settings/wifi/calling/DisclaimerItem.java
new file mode 100644
index 0000000..6fd8b70
--- /dev/null
+++ b/src/com/android/settings/wifi/calling/DisclaimerItem.java
@@ -0,0 +1,137 @@
+/*
+ * 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.wifi.calling;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.PersistableBundle;
+import android.telephony.CarrierConfigManager;
+import android.util.Log;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+/**
+ * Interface to control disclaimer item from {@link WifiCallingDisclaimerFragment}.
+ */
+@VisibleForTesting
+public abstract class DisclaimerItem {
+ private static final String SHARED_PREFERENCES_NAME = "wfc_disclaimer_prefs";
+
+ protected final Context mContext;
+ protected final int mSubId;
+ private final CarrierConfigManager mCarrierConfigManager;
+
+ DisclaimerItem(Context context, int subId) {
+ mContext = context;
+ mSubId = subId;
+ mCarrierConfigManager = mContext.getSystemService(CarrierConfigManager.class);
+ }
+
+ /**
+ * Called by the {@link WifiCallingDisclaimerFragment} when a user has clicked the agree button.
+ */
+ void onAgreed() {
+ setBooleanSharedPrefs(getPrefKey(), true);
+ }
+
+ /**
+ * Checks whether the disclaimer item need to be displayed or not.
+ *
+ * @return Returns {@code true} if disclaimer item need to be displayed,
+ * {@code false} if not displayed.
+ */
+ boolean shouldShow() {
+ if (getBooleanSharedPrefs(getPrefKey(), false)) {
+ logd("shouldShow: false due to a user has already agreed.");
+ return false;
+ }
+ logd("shouldShow: true");
+ return true;
+ }
+
+ /**
+ * Gets the configuration values for a particular sub id.
+ *
+ * @return The {@link PersistableBundle} instance containing the config value for a
+ * particular phone id, or default values.
+ */
+ protected PersistableBundle getCarrierConfig() {
+ PersistableBundle config = mCarrierConfigManager.getConfigForSubId(mSubId);
+ if (config != null) {
+ return config;
+ }
+ // Return static default defined in CarrierConfigManager.
+ return CarrierConfigManager.getDefaultConfig();
+ }
+
+ protected void logd(String msg) {
+ Log.d(getName(), "[" + mSubId + "] " + msg);
+ }
+
+ /**
+ * Gets a title id for disclaimer item.
+ *
+ * @return Title id for disclaimer item.
+ */
+ protected abstract int getTitleId();
+
+ /**
+ * Gets a message id for disclaimer item.
+ *
+ * @return Message id for disclaimer item.
+ */
+ protected abstract int getMessageId();
+
+ /**
+ * Gets a name of disclaimer item.
+ *
+ * @return Name of disclaimer item.
+ */
+ protected abstract String getName();
+
+ /**
+ * Gets a preference key to keep user's consent.
+ *
+ * @return Preference key to keep user's consent.
+ */
+ protected abstract String getPrefKey();
+
+ /**
+ * Gets the boolean value from shared preferences.
+ *
+ * @param key The key for the preference item.
+ * @param defValue Value to return if this preference does not exist.
+ * @return The boolean value of corresponding key, or defValue.
+ */
+ private boolean getBooleanSharedPrefs(String key, boolean defValue) {
+ SharedPreferences prefs = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME,
+ Context.MODE_PRIVATE);
+ return prefs.getBoolean(key + mSubId, defValue);
+ }
+
+ /**
+ * Sets the boolean value to shared preferences.
+ *
+ * @param key The key for the preference item.
+ * @param value The value to be set for shared preferences.
+ */
+ private void setBooleanSharedPrefs(String key, boolean value) {
+ SharedPreferences prefs = mContext.getSharedPreferences(SHARED_PREFERENCES_NAME,
+ Context.MODE_PRIVATE);
+ prefs.edit().putBoolean(key + mSubId, value).apply();
+ }
+}
diff --git a/src/com/android/settings/wifi/calling/DisclaimerItemFactory.java b/src/com/android/settings/wifi/calling/DisclaimerItemFactory.java
new file mode 100644
index 0000000..6d8dc8f
--- /dev/null
+++ b/src/com/android/settings/wifi/calling/DisclaimerItemFactory.java
@@ -0,0 +1,57 @@
+/*
+ * 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.wifi.calling;
+
+import android.content.Context;
+
+import com.android.internal.annotations.VisibleForTesting;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Factory class to create disclaimer items list.
+ */
+@VisibleForTesting
+public final class DisclaimerItemFactory {
+
+ /**
+ * Creates disclaimer items list.
+ *
+ * @param context The application context
+ * @param subId The subscription id.
+ * @return The {@link DisclaimerItem} list instance, if there are no items, return empty list.
+ */
+ public static List<DisclaimerItem> create(Context context, int subId) {
+ List<DisclaimerItem> itemList = getDisclaimerItemList(context, subId);
+ Iterator itr = itemList.iterator();
+ while (itr.hasNext()) {
+ DisclaimerItem item = (DisclaimerItem) itr.next();
+ if (!item.shouldShow()) {
+ itr.remove();
+ }
+ }
+ return itemList;
+ }
+
+ private static List<DisclaimerItem> getDisclaimerItemList(Context context, int subId) {
+ List<DisclaimerItem> itemList = new ArrayList<DisclaimerItem>();
+
+ return itemList;
+ }
+}
diff --git a/src/com/android/settings/wifi/calling/DisclaimerItemListAdapter.java b/src/com/android/settings/wifi/calling/DisclaimerItemListAdapter.java
new file mode 100644
index 0000000..4b5d19c
--- /dev/null
+++ b/src/com/android/settings/wifi/calling/DisclaimerItemListAdapter.java
@@ -0,0 +1,78 @@
+/*
+ * 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.wifi.calling;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.settings.R;
+
+import java.util.List;
+
+/**
+ * Adapter for disclaimer items list.
+ */
+public class DisclaimerItemListAdapter extends
+ RecyclerView.Adapter<DisclaimerItemListAdapter.DisclaimerItemViewHolder> {
+
+ private List<DisclaimerItem> mDisclaimerItemList;
+
+ public DisclaimerItemListAdapter(List<DisclaimerItem> list) {
+ mDisclaimerItemList = list;
+ }
+
+ @Override
+ public DisclaimerItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(
+ Context.LAYOUT_INFLATER_SERVICE);
+ View view = inflater.inflate(R.layout.wfc_simple_disclaimer_item, null, false);
+ return new DisclaimerItemViewHolder(view);
+ }
+
+ @Override
+ public void onBindViewHolder(DisclaimerItemViewHolder holder, int position) {
+ holder.titleView.setText(mDisclaimerItemList.get(position).getTitleId());
+ holder.descriptionView.setText(mDisclaimerItemList.get(position).getMessageId());
+ }
+
+ @Override
+ public int getItemCount() {
+ return mDisclaimerItemList.size();
+ }
+
+ public static class DisclaimerItemViewHolder extends RecyclerView.ViewHolder {
+ @VisibleForTesting
+ static final int ID_DISCLAIMER_ITEM_TITLE = R.id.disclaimer_title;
+ @VisibleForTesting
+ static final int ID_DISCLAIMER_ITEM_DESCRIPTION = R.id.disclaimer_desc;
+
+ public final TextView titleView;
+ public final TextView descriptionView;
+
+ public DisclaimerItemViewHolder(View itemView) {
+ super(itemView);
+ titleView = itemView.findViewById(ID_DISCLAIMER_ITEM_TITLE);
+ descriptionView = itemView.findViewById(ID_DISCLAIMER_ITEM_DESCRIPTION);
+ }
+ }
+}
diff --git a/src/com/android/settings/wifi/calling/ListWithEntrySummaryPreference.java b/src/com/android/settings/wifi/calling/ListWithEntrySummaryPreference.java
new file mode 100644
index 0000000..c24ff2b
--- /dev/null
+++ b/src/com/android/settings/wifi/calling/ListWithEntrySummaryPreference.java
@@ -0,0 +1,204 @@
+/*
+ * 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.wifi.calling;
+
+import android.app.AlertDialog.Builder;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.content.res.TypedArray;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.util.AttributeSet;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ListAdapter;
+import android.widget.RadioButton;
+import android.widget.TextView;
+
+import com.android.settings.CustomListPreference;
+import com.android.settings.R;
+
+/**
+ * ListPreference contain the entry summary.
+ */
+public class ListWithEntrySummaryPreference extends CustomListPreference {
+ private static final String LOG_TAG = "ListWithEntrySummaryPreference";
+ private final Context mContext;
+ private CharSequence[] mSummaries;
+
+ /**
+ * ListWithEntrySummaryPreference constructor.
+ *
+ * @param context The context of view.
+ * @param attrs The attributes of the XML tag that is inflating the linear layout.
+ */
+ public ListWithEntrySummaryPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ mContext = context;
+
+ TypedArray array = context.obtainStyledAttributes(attrs,
+ R.styleable.ListWithEntrySummaryPreference, 0, 0);
+ mSummaries = array.getTextArray(R.styleable.ListWithEntrySummaryPreference_entrySummaries);
+ array.recycle();
+ }
+
+ /**
+ * Sets the summaries of mode items to be shown in the mode select dialog.
+ *
+ * @param summariesResId The summaries of mode items.
+ */
+ public void setEntrySummaries(int summariesResId) {
+ mSummaries = getContext().getResources().getTextArray(summariesResId);
+ }
+
+ /**
+ * Sets the summaries of mode items to be shown in the mode select dialog.
+ *
+ * @param summaries The summaries of mode items.
+ */
+ public void setEntrySummaries(CharSequence[] summaries) {
+ mSummaries = summaries;
+ }
+
+ private CharSequence getEntrySummary(int index) {
+ if (mSummaries == null) {
+ Log.w(LOG_TAG, "getEntrySummary : mSummaries is null");
+ return "";
+ }
+ return mSummaries[index];
+ }
+
+ @Override
+ protected void onPrepareDialogBuilder(Builder builder,
+ DialogInterface.OnClickListener listener) {
+ ListAdapter la = (ListAdapter) new SelectorAdapter(mContext,
+ R.xml.single_choice_list_item_2, this);
+ builder.setSingleChoiceItems(la, findIndexOfValue(getValue()), listener);
+ super.onPrepareDialogBuilder(builder, listener);
+ }
+
+ private static class SelectorAdapter extends ArrayAdapter<CharSequence> {
+ private final Context mContext;
+ private ListWithEntrySummaryPreference mSelector;
+
+ /**
+ * SelectorAdapter constructor.
+ *
+ * @param context The current context.
+ * @param rowResourceId The resource id of the XML tag that is inflating the linear layout.
+ * @param listPreference The instance of ListWithEntrySummaryPreference.
+ */
+ public SelectorAdapter(Context context, int rowResourceId,
+ ListWithEntrySummaryPreference listPreference) {
+ super(context, rowResourceId, listPreference.getEntryValues());
+ mContext = context;
+ mSelector = listPreference;
+ }
+
+ @Override
+ public View getView(int position, View convertView, ViewGroup parent) {
+ LayoutInflater inflater = LayoutInflater.from(mContext);
+ View row = inflater.inflate(R.xml.single_choice_list_item_2, parent, false);
+
+ TextView title = (TextView) row.findViewById(R.id.title);
+ title.setText(mSelector.getEntries()[position]);
+
+ TextView summary = (TextView) row.findViewById(R.id.summary);
+ summary.setText(mSelector.getEntrySummary(position));
+
+ RadioButton rb = (RadioButton) row.findViewById(R.id.radio);
+ if (position == mSelector.findIndexOfValue(mSelector.getValue())) {
+ rb.setChecked(true);
+ }
+
+ return row;
+ }
+ }
+
+ @Override
+ protected Parcelable onSaveInstanceState() {
+ final Parcelable superState = super.onSaveInstanceState();
+
+ final SavedState myState = new SavedState(superState);
+ myState.mEntries = getEntries();
+ myState.mEntryValues = getEntryValues();
+ myState.mSummaries = mSummaries;
+ return myState;
+ }
+
+ @Override
+ protected void onRestoreInstanceState(Parcelable state) {
+ if (state == null || !state.getClass().equals(SavedState.class)) {
+ // Didn't save state for us in onSaveInstanceState
+ super.onRestoreInstanceState(state);
+ return;
+ }
+
+ SavedState myState = (SavedState) state;
+ super.onRestoreInstanceState(myState.getSuperState());
+ setEntries(myState.mEntries);
+ setEntryValues(myState.mEntryValues);
+ mSummaries = myState.mSummaries;
+ }
+
+ /**
+ * We save entries, entryValues and summaries into bundle.
+ * At onCreate of fragment, dialog will be restored if it was open. In this case,
+ * we need to restore entries, entryValues and summaries. Without those information,
+ * crash when entering multi window during wfc modes dialog shown.
+ */
+ private static class SavedState extends BaseSavedState {
+ private CharSequence[] mEntries;
+ private CharSequence[] mEntryValues;
+ private CharSequence[] mSummaries;
+
+ public SavedState(Parcel source) {
+ super(source);
+ mEntries = source.readCharSequenceArray();
+ mEntryValues = source.readCharSequenceArray();
+ mSummaries = source.readCharSequenceArray();
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ super.writeToParcel(dest, flags);
+ dest.writeCharSequenceArray(mEntries);
+ dest.writeCharSequenceArray(mEntryValues);
+ dest.writeCharSequenceArray(mSummaries);
+ }
+
+ public SavedState(Parcelable superState) {
+ super(superState);
+ }
+
+ public static final Parcelable.Creator<SavedState> CREATOR =
+ new Parcelable.Creator<SavedState>() {
+ @Override
+ public SavedState createFromParcel(Parcel in) {
+ return new SavedState(in);
+ }
+
+ @Override
+ public SavedState[] newArray(int size) {
+ return new SavedState[size];
+ }
+ };
+ }
+}
diff --git a/src/com/android/settings/wifi/calling/WifiCallingDisclaimerFragment.java b/src/com/android/settings/wifi/calling/WifiCallingDisclaimerFragment.java
new file mode 100644
index 0000000..7763226
--- /dev/null
+++ b/src/com/android/settings/wifi/calling/WifiCallingDisclaimerFragment.java
@@ -0,0 +1,148 @@
+/*
+ * 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.wifi.calling;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.telephony.SubscriptionManager;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+import androidx.recyclerview.widget.DividerItemDecoration;
+import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.RecyclerView.OnScrollListener;
+
+import com.android.internal.annotations.VisibleForTesting;
+import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.settings.R;
+import com.android.settings.core.InstrumentedFragment;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Fragment for displaying disclaimers for WFC.
+ */
+public class WifiCallingDisclaimerFragment extends InstrumentedFragment
+ implements View.OnClickListener {
+ private static final String TAG = "WifiCallingDisclaimerFragment";
+
+ private static final String STATE_IS_SCROLL_TO_BOTTOM = "state_is_scroll_to_bottom";
+
+ private List<DisclaimerItem> mDisclaimerItemList = new ArrayList<DisclaimerItem>();
+ private Button mAgreeButton;
+ private Button mDisagreeButton;
+ private boolean mScrollToBottom;
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsEvent.WIFI_CALLING;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ final Bundle args = getArguments();
+ final int subId = (args != null) ? args.getInt(WifiCallingSettingsForSub.EXTRA_SUB_ID)
+ : SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
+
+ mDisclaimerItemList = DisclaimerItemFactory.create(getActivity(), subId);
+ if (mDisclaimerItemList.isEmpty()) {
+ finish(Activity.RESULT_OK);
+ return;
+ }
+
+ if (savedInstanceState != null) {
+ mScrollToBottom = savedInstanceState.getBoolean(
+ STATE_IS_SCROLL_TO_BOTTOM, mScrollToBottom);
+ }
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ final View view = inflater.inflate(R.layout.wfc_disclaimer_fragment, container, false);
+
+ mAgreeButton = view.findViewById(R.id.agree_button);
+ mAgreeButton.setOnClickListener(this);
+ mDisagreeButton = view.findViewById(R.id.disagree_button);
+ mDisagreeButton.setOnClickListener(this);
+
+ final RecyclerView recyclerView = (RecyclerView) view.findViewById(
+ R.id.disclaimer_item_list);
+ recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
+ recyclerView.setAdapter(new DisclaimerItemListAdapter(mDisclaimerItemList));
+
+ RecyclerView.ItemDecoration itemDecoration =
+ new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL);
+ recyclerView.addItemDecoration(itemDecoration);
+
+ recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
+ @Override
+ public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
+ super.onScrolled(recyclerView, dx, dy);
+ if (!recyclerView.canScrollVertically(1 /* scrolling down */)) {
+ mScrollToBottom = true;
+ updateButtonState();
+ recyclerView.removeOnScrollListener(this);
+ }
+ }
+ });
+
+ return view;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+ updateButtonState();
+ }
+
+ @Override
+ public void onSaveInstanceState(Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putBoolean(STATE_IS_SCROLL_TO_BOTTOM, mScrollToBottom);
+ }
+
+ private void updateButtonState() {
+ mAgreeButton.setEnabled(mScrollToBottom);
+ }
+
+ @Override
+ public void onClick(View v) {
+ if (v == mAgreeButton) {
+ for (DisclaimerItem item : mDisclaimerItemList) {
+ item.onAgreed();
+ }
+ finish(Activity.RESULT_OK);
+ } else if (v == mDisagreeButton) {
+ finish(Activity.RESULT_CANCELED);
+ }
+ }
+
+ @VisibleForTesting
+ void finish(int result) {
+ Activity activity = getActivity();
+ activity.setResult(result, null);
+ activity.finish();
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
index e50cb95..34963e0 100644
--- a/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
+++ b/src/com/android/settings/wifi/calling/WifiCallingSettingsForSub.java
@@ -53,6 +53,7 @@
import com.android.settings.SettingsActivity;
import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
+import com.android.settings.core.SubSettingLauncher;
import com.android.settings.widget.SwitchBar;
/**
@@ -69,9 +70,13 @@
private static final String BUTTON_WFC_ROAMING_MODE = "wifi_calling_roaming_mode";
private static final String PREFERENCE_EMERGENCY_ADDRESS = "emergency_address_key";
- private static final int REQUEST_CHECK_WFC_EMERGENCY_ADDRESS = 1;
+ @VisibleForTesting
+ static final int REQUEST_CHECK_WFC_EMERGENCY_ADDRESS = 1;
+ @VisibleForTesting
+ static final int REQUEST_CHECK_WFC_DISCLAIMER = 2;
public static final String EXTRA_LAUNCH_CARRIER_APP = "EXTRA_LAUNCH_CARRIER_APP";
+ public static final String EXTRA_SUB_ID = "EXTRA_SUB_ID";
protected static final String FRAGMENT_BUNDLE_SUBID = "subId";
@@ -81,8 +86,8 @@
//UI objects
private SwitchBar mSwitchBar;
private Switch mSwitch;
- private ListPreference mButtonWfcMode;
- private ListPreference mButtonWfcRoamingMode;
+ private ListWithEntrySummaryPreference mButtonWfcMode;
+ private ListWithEntrySummaryPreference mButtonWfcRoamingMode;
private Preference mUpdateAddress;
private TextView mEmptyView;
@@ -176,7 +181,7 @@
mEmptyView = getView().findViewById(android.R.id.empty);
setEmptyView(mEmptyView);
- final Resources res = SubscriptionManager.getResourcesForSubId(getActivity(), mSubId);
+ final Resources res = getResourcesForSubId();
String emptyViewText = res.getString(R.string.wifi_calling_off_explanation,
res.getString(R.string.wifi_calling_off_explanation_2));
mEmptyView.setText(emptyViewText);
@@ -260,10 +265,11 @@
mImsManager = getImsManager();
- mButtonWfcMode = (ListPreference) findPreference(BUTTON_WFC_MODE);
+ mButtonWfcMode = (ListWithEntrySummaryPreference) findPreference(BUTTON_WFC_MODE);
mButtonWfcMode.setOnPreferenceChangeListener(this);
- mButtonWfcRoamingMode = (ListPreference) findPreference(BUTTON_WFC_ROAMING_MODE);
+ mButtonWfcRoamingMode = (ListWithEntrySummaryPreference) findPreference(
+ BUTTON_WFC_ROAMING_MODE);
mButtonWfcRoamingMode.setOnPreferenceChangeListener(this);
mUpdateAddress = (Preference) findPreference(PREFERENCE_EMERGENCY_ADDRESS);
@@ -324,10 +330,14 @@
if (!isWifiOnlySupported) {
mButtonWfcMode.setEntries(R.array.wifi_calling_mode_choices_without_wifi_only);
mButtonWfcMode.setEntryValues(R.array.wifi_calling_mode_values_without_wifi_only);
+ mButtonWfcMode.setEntrySummaries(R.array.wifi_calling_mode_summaries_without_wifi_only);
+
mButtonWfcRoamingMode.setEntries(
R.array.wifi_calling_mode_choices_v2_without_wifi_only);
mButtonWfcRoamingMode.setEntryValues(
R.array.wifi_calling_mode_values_without_wifi_only);
+ mButtonWfcRoamingMode.setEntrySummaries(
+ R.array.wifi_calling_mode_summaries_without_wifi_only);
}
@@ -415,14 +425,17 @@
return;
}
- // Call address management activity before turning on WFC
- Intent carrierAppIntent = getCarrierActivityIntent();
- if (carrierAppIntent != null) {
- carrierAppIntent.putExtra(EXTRA_LAUNCH_CARRIER_APP, LAUCH_APP_ACTIVATE);
- startActivityForResult(carrierAppIntent, REQUEST_CHECK_WFC_EMERGENCY_ADDRESS);
- } else {
- updateWfcMode(true);
- }
+ // Launch disclaimer fragment before turning on WFC
+ final Context context = getActivity();
+ final Bundle args = new Bundle();
+ args.putInt(EXTRA_SUB_ID, mSubId);
+ new SubSettingLauncher(context)
+ .setDestination(WifiCallingDisclaimerFragment.class.getName())
+ .setArguments(args)
+ .setTitle(R.string.wifi_calling_settings_title)
+ .setSourceMetricsCategory(getMetricsCategory())
+ .setResultListener(this, REQUEST_CHECK_WFC_DISCLAIMER)
+ .launch();
}
/*
@@ -475,12 +488,30 @@
final Context context = getActivity();
- if (requestCode == REQUEST_CHECK_WFC_EMERGENCY_ADDRESS) {
- Log.d(TAG, "WFC emergency address activity result = " + resultCode);
+ Log.d(TAG, "WFC activity request = " + requestCode + " result = " + resultCode);
- if (resultCode == Activity.RESULT_OK) {
- updateWfcMode(true);
- }
+ switch (requestCode) {
+ case REQUEST_CHECK_WFC_EMERGENCY_ADDRESS:
+ if (resultCode == Activity.RESULT_OK) {
+ updateWfcMode(true);
+ }
+ break;
+ case REQUEST_CHECK_WFC_DISCLAIMER:
+ if (resultCode == Activity.RESULT_OK) {
+ // Call address management activity before turning on WFC
+ Intent carrierAppIntent = getCarrierActivityIntent();
+ if (carrierAppIntent != null) {
+ carrierAppIntent.putExtra(EXTRA_LAUNCH_CARRIER_APP, LAUCH_APP_ACTIVATE);
+ startActivityForResult(carrierAppIntent,
+ REQUEST_CHECK_WFC_EMERGENCY_ADDRESS);
+ } else {
+ updateWfcMode(true);
+ }
+ }
+ break;
+ default:
+ Log.e(TAG, "Unexpected request: " + requestCode);
+ break;
}
}
@@ -567,4 +598,9 @@
}
return resId;
}
+
+ @VisibleForTesting
+ Resources getResourcesForSubId() {
+ return SubscriptionManager.getResourcesForSubId(getActivity(), mSubId, false);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java
index afd465a..fb5eaab 100644
--- a/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java
@@ -91,7 +91,7 @@
ReflectionHelpers.setField(mController, "mStorageManager", mStorageManager);
when(mStorageManager.isConvertibleToFBE()).thenReturn(true);
mController.displayPreference(mPreferenceScreen);
- CryptoProperties.type("foobar");
+ CryptoProperties.type(CryptoProperties.type_values.NONE);
mController.updateState(mPreference);
@@ -105,7 +105,7 @@
ReflectionHelpers.setField(mController, "mStorageManager", mStorageManager);
when(mStorageManager.isConvertibleToFBE()).thenReturn(true);
mController.displayPreference(mPreferenceScreen);
- CryptoProperties.type("file");
+ CryptoProperties.type(CryptoProperties.type_values.FILE);
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDisclaimerItemFactory.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDisclaimerItemFactory.java
new file mode 100644
index 0000000..c50d4f1
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowDisclaimerItemFactory.java
@@ -0,0 +1,41 @@
+/*
+ * 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.testutils.shadow;
+
+import android.content.Context;
+
+import com.android.settings.wifi.calling.DisclaimerItemFactory;
+import com.android.settings.wifi.calling.DisclaimerItem;
+
+import java.util.List;
+
+import org.robolectric.annotation.Implementation;
+import org.robolectric.annotation.Implements;
+
+@Implements(DisclaimerItemFactory.class)
+public final class ShadowDisclaimerItemFactory {
+ private static List<DisclaimerItem> sMockDisclaimerItemList;
+
+ public static void setDisclaimerItemList(List<DisclaimerItem> list) {
+ sMockDisclaimerItemList = list;
+ }
+
+ @Implementation
+ public static List<DisclaimerItem> create(Context context, int subId) {
+ return sMockDisclaimerItemList;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/DisclaimerItemListAdapterTest.java b/tests/robotests/src/com/android/settings/wifi/calling/DisclaimerItemListAdapterTest.java
new file mode 100644
index 0000000..5fc5441
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/calling/DisclaimerItemListAdapterTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.wifi.calling;
+
+import static com.android.settings.wifi.calling.DisclaimerItemListAdapter
+ .DisclaimerItemViewHolder.ID_DISCLAIMER_ITEM_TITLE;
+import static com.android.settings.wifi.calling.DisclaimerItemListAdapter
+ .DisclaimerItemViewHolder.ID_DISCLAIMER_ITEM_DESCRIPTION;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+public class DisclaimerItemListAdapterTest {
+
+ private static final int ITEM_POSITION = 0;
+ private static final int DISCLAIMER_TITLE_STRING_ID = 0;
+ private static final int DISCLAIMER_MESSAGE_STRING_ID = 1;
+
+ @Mock
+ private LayoutInflater mLayoutInflater;
+ @Mock
+ private TextView mTestView;
+ @Mock
+ private TextView mDescView;
+ @Mock
+ private View mView;
+ @Mock
+ private ViewGroup mViewGroup;
+ @Mock
+ private Context mContext;
+
+ private MockDisclaimerItem mDisclaimerItem;
+ private DisclaimerItemListAdapter mDisclaimerItemListAdapter;
+ private List<DisclaimerItem> mDisclaimerItemList = new ArrayList<>();
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mDisclaimerItem = spy(new MockDisclaimerItem(mContext, 0 /* subId */));
+ mDisclaimerItemList.add(mDisclaimerItem);
+
+ when(mLayoutInflater.inflate(anyInt(), anyObject(), anyBoolean())).thenReturn(mView);
+ when(mViewGroup.getContext()).thenReturn(mContext);
+ when(mViewGroup.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE)).thenReturn(
+ mLayoutInflater);
+ when(mView.findViewById(ID_DISCLAIMER_ITEM_TITLE)).thenReturn(mTestView);
+ when(mView.findViewById(ID_DISCLAIMER_ITEM_DESCRIPTION)).thenReturn(mDescView);
+ }
+
+ @Test
+ public void onBindViewHolder_haveItem_shouldSetText() {
+ final DisclaimerItemListAdapter.DisclaimerItemViewHolder viewHolder =
+ new DisclaimerItemListAdapter.DisclaimerItemViewHolder(mView);
+
+ mDisclaimerItemListAdapter = new DisclaimerItemListAdapter(mDisclaimerItemList);
+ mDisclaimerItemListAdapter.onCreateViewHolder(mViewGroup, 0 /* viewType */);
+ mDisclaimerItemListAdapter.onBindViewHolder(viewHolder, ITEM_POSITION);
+
+ // Check the text is set when the DisclaimerItem exists.
+ verify(viewHolder.titleView).setText(DISCLAIMER_TITLE_STRING_ID);
+ verify(viewHolder.descriptionView).setText(DISCLAIMER_MESSAGE_STRING_ID);
+ }
+
+ private class MockDisclaimerItem extends DisclaimerItem {
+ MockDisclaimerItem(Context context, int subId) {
+ super(context, subId);
+ }
+
+ @Override
+ protected int getTitleId() {
+ return DISCLAIMER_TITLE_STRING_ID;
+ }
+
+ @Override
+ protected int getMessageId() {
+ return DISCLAIMER_MESSAGE_STRING_ID;
+ }
+
+ @Override
+ protected String getName() {
+ return "MockDisclaimerItem";
+ }
+
+ @Override
+ protected String getPrefKey() {
+ return "mock_pref_key";
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/ListWithEntrySummaryPreferenceTest.java b/tests/robotests/src/com/android/settings/wifi/calling/ListWithEntrySummaryPreferenceTest.java
new file mode 100644
index 0000000..0cef231
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/calling/ListWithEntrySummaryPreferenceTest.java
@@ -0,0 +1,126 @@
+/*
+ * 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.wifi.calling;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.app.AlertDialog;
+import android.content.Context;
+import android.os.Parcelable;
+import android.widget.ListAdapter;
+import android.widget.TextView;
+
+import com.android.settings.R;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+import java.io.IOException;
+
+@RunWith(RobolectricTestRunner.class)
+public class ListWithEntrySummaryPreferenceTest {
+
+ private Context mContext;
+ private ListWithEntrySummaryPreference mPreference;
+
+ private CharSequence[] mDefaultEntries =
+ {"default_entry1", "default_entry2", "default_entry3"};
+ private CharSequence[] mDefaultEntryValues = {"0", "1", "2"};
+ private CharSequence[] mDefaultEntrySummaries =
+ {"default_summary1", "default_summary2", "default_summary3"};
+
+ private CharSequence[] mCustomEntries = {"custom_entry1", "custom_entry2"};
+ private CharSequence[] mCustomEntryValues = {"0", "1"};
+ private CharSequence[] mCustomEntrySummaries = {"custom_summary1", "custom_summary2"};
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mPreference = new ListWithEntrySummaryPreference(mContext, null);
+ mPreference.setEntries(mDefaultEntries);
+ mPreference.setEntryValues(mDefaultEntryValues);
+ mPreference.setEntrySummaries(mDefaultEntrySummaries);
+ }
+
+ @Test
+ public void initialize_defaultEntries_shouldDisplayDefalutEntries() {
+ AlertDialog dialog = showDialog(mPreference);
+ ListAdapter adapter = dialog.getListView().getAdapter();
+
+ int len = mDefaultEntries.length;
+ assertThat(adapter.getCount()).isEqualTo(len);
+ for (int i = 0; i < len; i++) {
+ TextView title = adapter.getView(i, null, null).findViewById(R.id.title);
+ TextView summary = adapter.getView(i, null, null).findViewById(R.id.summary);
+ assertThat(title.getText()).isEqualTo(mDefaultEntries[i]);
+ assertThat(summary.getText()).isEqualTo(mDefaultEntrySummaries[i]);
+ }
+ }
+
+ @Test
+ public void setEntries_customEntries_shouldUpdateEntries() {
+ mPreference.setEntries(mCustomEntries);
+ mPreference.setEntryValues(mCustomEntryValues);
+ mPreference.setEntrySummaries(mCustomEntrySummaries);
+
+ AlertDialog dialog = showDialog(mPreference);
+ ListAdapter adapter = dialog.getListView().getAdapter();
+
+ int len = mCustomEntries.length;
+ assertThat(adapter.getCount()).isEqualTo(len);
+ for (int i = 0; i < len; i++) {
+ TextView title = adapter.getView(i, null, null).findViewById(R.id.title);
+ TextView summary = adapter.getView(i, null, null).findViewById(R.id.summary);
+ assertThat(title.getText()).isEqualTo(mCustomEntries[i]);
+ assertThat(summary.getText()).isEqualTo(mCustomEntrySummaries[i]);
+ }
+ }
+
+ @Test
+ public void onSaveAndRestoreInstanceState_resumePreference_shouldNotChangeEntries() {
+ setEntries_customEntries_shouldUpdateEntries();
+
+ final Parcelable parcelable = mPreference.onSaveInstanceState();
+ ListWithEntrySummaryPreference preference
+ = new ListWithEntrySummaryPreference(mContext, null);
+ preference.setEntries(mDefaultEntries);
+ preference.setEntryValues(mDefaultEntryValues);
+ preference.setEntrySummaries(mDefaultEntrySummaries);
+ preference.onRestoreInstanceState(parcelable);
+
+ AlertDialog dialog = showDialog(preference);
+ ListAdapter adapter = dialog.getListView().getAdapter();
+
+ int len = mCustomEntries.length;
+ assertThat(adapter.getCount()).isEqualTo(len);
+ for (int i = 0; i < len; i++) {
+ TextView title = adapter.getView(i, null, null).findViewById(R.id.title);
+ TextView summary = adapter.getView(i, null, null).findViewById(R.id.summary);
+ assertThat(title.getText()).isEqualTo(mCustomEntries[i]);
+ assertThat(summary.getText()).isEqualTo(mCustomEntrySummaries[i]);
+ }
+ }
+
+ private AlertDialog showDialog(ListWithEntrySummaryPreference preference) {
+ AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
+ preference.onPrepareDialogBuilder(builder, null);
+ return builder.show();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingDisclaimerFragmentTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingDisclaimerFragmentTest.java
new file mode 100644
index 0000000..70c1d91
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingDisclaimerFragmentTest.java
@@ -0,0 +1,180 @@
+/*
+ * 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.wifi.calling;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.app.Activity;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.ViewGroup;
+import android.widget.Button;
+
+import androidx.recyclerview.widget.RecyclerView;
+import androidx.recyclerview.widget.RecyclerView.OnScrollListener;
+
+import com.android.settings.R;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.ShadowDisclaimerItemFactory;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Captor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.annotation.Config;
+import org.robolectric.Robolectric;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(shadows = ShadowDisclaimerItemFactory.class)
+public class WifiCallingDisclaimerFragmentTest {
+
+ @Mock
+ private Activity mActivity;
+ @Mock
+ private DisclaimerItem mDisclaimerItem;
+ @Mock
+ private LayoutInflater mLayoutInflater;
+ @Mock
+ private View mView;
+ @Mock
+ private ViewGroup mViewGroup;
+ @Mock
+ private Button mAgreeButton;
+ @Mock
+ private Button mDisagreeButton;
+ @Mock
+ private RecyclerView mRecyclerView;
+
+ @Captor
+ ArgumentCaptor<OnClickListener> mOnClickListenerCaptor;
+ @Captor
+ ArgumentCaptor<OnScrollListener> mOnScrollListenerCaptor;
+
+ private WifiCallingDisclaimerFragment mFragment;
+ private List<DisclaimerItem> mDisclaimerItemList = new ArrayList<>();
+ private List<DisclaimerItem> mEmptyDisclaimerItemList = new ArrayList<>();
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mActivity = Robolectric.setupActivity(Activity.class);
+ mFragment = spy(new WifiCallingDisclaimerFragment());
+
+ doReturn(mActivity).when(mFragment).getActivity();
+
+ when(mLayoutInflater.inflate(anyInt(), anyObject(), anyBoolean())).thenReturn(mView);
+ when(mView.findViewById(R.id.agree_button)).thenReturn(mAgreeButton);
+ when(mView.findViewById(R.id.disagree_button)).thenReturn(mDisagreeButton);
+ when(mView.findViewById(R.id.disclaimer_item_list)).thenReturn(mRecyclerView);
+ when(mView.getId()).thenReturn(R.id.agree_button);
+
+ mOnScrollListenerCaptor = ArgumentCaptor.forClass(OnScrollListener.class);
+ doNothing().when(mRecyclerView).addOnScrollListener(mOnScrollListenerCaptor.capture());
+ mOnClickListenerCaptor = ArgumentCaptor.forClass(OnClickListener.class);
+ doNothing().when(mAgreeButton).setOnClickListener(mOnClickListenerCaptor.capture());
+
+ mDisclaimerItemList.add(mDisclaimerItem);
+ }
+
+ @Test
+ public void onCreate_notHaveItem_shouldFinishFragment() {
+ ShadowDisclaimerItemFactory.setDisclaimerItemList(mEmptyDisclaimerItemList);
+
+ mFragment.onCreate(null /* savedInstanceState */);
+
+ // Check the fragment is finished when the DisclaimerItemList is empty.
+ verify(mFragment).finish(Activity.RESULT_OK);
+ }
+
+ @Test
+ public void onCreate_haveItem_shouldNotFinishFragment() {
+ ShadowDisclaimerItemFactory.setDisclaimerItemList(mDisclaimerItemList);
+
+ mFragment.onCreate(null /* savedInstanceState */);
+
+ // Check the fragment is not finished when the DisclaimerItemList is not empty.
+ verify(mFragment, never()).finish(Activity.RESULT_OK);
+ }
+
+ @Test
+ public void onScrolled_canNotScroll_shouldEnableAgreeButton() {
+ ShadowDisclaimerItemFactory.setDisclaimerItemList(mDisclaimerItemList);
+
+ when(mRecyclerView.canScrollVertically(1)).thenReturn(false);
+
+ mFragment.onCreate(null /* savedInstanceState */);
+ mFragment.onCreateView(mLayoutInflater, mViewGroup, null /* savedInstanceState */);
+
+ mOnScrollListenerCaptor.getValue().onScrolled(mRecyclerView, 0, 0);
+
+ // Check the agreeButton is enabled when the view is scrolled to the bottom end.
+ verify(mAgreeButton).setEnabled(true);
+ // Check the OnScrollListener is removed when the view is scrolled to the bottom end.
+ verify(mRecyclerView).removeOnScrollListener(any());
+ }
+
+ @Test
+ public void onScrolled_canScroll_shouldNotEnableAgreeButton() {
+ ShadowDisclaimerItemFactory.setDisclaimerItemList(mDisclaimerItemList);
+
+ when(mRecyclerView.canScrollVertically(1)).thenReturn(true);
+
+ mFragment.onCreate(null /* savedInstanceState */);
+ mFragment.onCreateView(mLayoutInflater, mViewGroup, null /* savedInstanceState */);
+
+ mOnScrollListenerCaptor.getValue().onScrolled(mRecyclerView, 0, 0);
+
+ // Check the agreeButton is not enabled when the view is not scrolled to the bottom end.
+ verify(mAgreeButton, never()).setEnabled(anyBoolean());
+ // Check the OnScrollListener is not removed when the view is not scrolled to
+ // the bottom end.
+ verify(mRecyclerView, never()).removeOnScrollListener(any());
+ }
+
+ @Test
+ public void onClick_agreeButton_shouldFinishFragment() {
+ ShadowDisclaimerItemFactory.setDisclaimerItemList(mDisclaimerItemList);
+
+ mFragment.onCreate(null /* savedInstanceState */);
+ mFragment.onCreateView(mLayoutInflater, mViewGroup, null /* savedInstanceState */);
+
+ mOnClickListenerCaptor.getValue().onClick(mAgreeButton);
+
+ // Check the onAgreed callback is called when "CONTINUE" button is clicked.
+ verify(mDisclaimerItem).onAgreed();
+ // Check the WFC disclaimer fragment is finished when "CONTINUE" button is clicked.
+ verify(mFragment).finish(Activity.RESULT_OK);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
index 2f2fa62..fbdc303 100644
--- a/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/calling/WifiCallingSettingsForSubTest.java
@@ -16,11 +16,14 @@
package com.android.settings.wifi.calling;
+import static com.android.settings.SettingsActivity.EXTRA_SHOW_FRAGMENT;
import static com.google.common.truth.Truth.assertThat;
+import static junit.framework.Assert.assertEquals;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
@@ -31,6 +34,8 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.app.Activity;
+import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -41,6 +46,7 @@
import android.widget.TextView;
import androidx.preference.ListPreference;
+import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.ims.ImsConfig;
@@ -49,7 +55,6 @@
import com.android.settings.R;
import com.android.settings.SettingsActivity;
import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.widget.SwitchBar;
import com.android.settings.widget.ToggleSwitch;
@@ -57,6 +62,7 @@
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.RobolectricTestRunner;
@@ -69,6 +75,8 @@
public class WifiCallingSettingsForSubTest {
private static final String BUTTON_WFC_MODE = "wifi_calling_mode";
private static final String BUTTON_WFC_ROAMING_MODE = "wifi_calling_roaming_mode";
+ private static final String TEST_EMERGENCY_ADDRESS_CARRIER_APP =
+ "com.android.settings/.wifi.calling.TestEmergencyAddressCarrierApp";
private TestFragment mFragment;
private Context mContext;
@@ -76,6 +84,7 @@
private final PersistableBundle mBundle = new PersistableBundle();
@Mock private static CarrierConfigManager sCarrierConfigManager;
+ @Mock private CarrierConfigManager mMockConfigManager;
@Mock private ImsManager mImsManager;
@Mock private PreferenceScreen mPreferenceScreen;
@Mock private SettingsActivity mActivity;
@@ -85,6 +94,7 @@
@Mock private ImsConfig mImsConfig;
@Mock private ListPreference mButtonWfcMode;
@Mock private ListPreference mButtonWfcRoamingMode;
+ @Mock private Preference mUpdateAddress;
@Before
public void setUp() throws NoSuchFieldException, ImsException {
@@ -125,6 +135,11 @@
doReturn(mBundle).when(sCarrierConfigManager).getConfigForSubId(anyInt());
setDefaultCarrierConfigValues();
+ doReturn(sCarrierConfigManager).when(mActivity).getSystemService(
+ CarrierConfigManager.class);
+ doReturn(mContext.getResources()).when(mFragment).getResourcesForSubId();
+ doNothing().when(mFragment).startActivityForResult(any(Intent.class), anyInt());
+
mFragment.onAttach(mContext);
mFragment.onCreate(null);
mFragment.onActivityCreated(null);
@@ -135,6 +150,9 @@
CarrierConfigManager.KEY_USE_WFC_HOME_NETWORK_MODE_IN_ROAMING_NETWORK_BOOL, false);
mBundle.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_MODE_BOOL, true);
mBundle.putBoolean(CarrierConfigManager.KEY_EDITABLE_WFC_ROAMING_MODE_BOOL, true);
+ mBundle.putString(
+ CarrierConfigManager.KEY_WFC_EMERGENCY_ADDRESS_CARRIER_APP_STRING,
+ TEST_EMERGENCY_ADDRESS_CARRIER_APP);
}
@Test
@@ -263,6 +281,61 @@
eq(true));
}
+ @Test
+ public void onSwitchChanged_enableSetting_shouldLaunchWfcDisclaimerFragment() {
+ ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+
+ mFragment.onSwitchChanged(null, true);
+
+ // Check the WFC disclaimer fragment is launched.
+ verify(mFragment).startActivityForResult(intentCaptor.capture(),
+ eq(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_DISCLAIMER));
+ Intent intent = intentCaptor.getValue();
+ assertThat(intent.getStringExtra(EXTRA_SHOW_FRAGMENT))
+ .isEqualTo(WifiCallingDisclaimerFragment.class.getName());
+ }
+
+ @Test
+ public void onActivityResult_finishWfcDisclaimerFragment_shouldLaunchCarrierActivity() {
+ ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+
+ // Emulate the WfcDisclaimerActivity finish.
+ mFragment.onActivityResult(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_DISCLAIMER,
+ Activity.RESULT_OK, null);
+
+ // Check the WFC emergency address activity is launched.
+ verify(mFragment).startActivityForResult(intentCaptor.capture(),
+ eq(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_EMERGENCY_ADDRESS));
+ Intent intent = intentCaptor.getValue();
+ assertEquals(intent.getComponent(), ComponentName.unflattenFromString(
+ TEST_EMERGENCY_ADDRESS_CARRIER_APP));
+ }
+
+ @Test
+ public void onActivityResult_finishCarrierActivity_shouldShowWfcPreference() {
+ ReflectionHelpers.setField(mFragment, "mButtonWfcMode", mButtonWfcMode);
+ ReflectionHelpers.setField(mFragment, "mButtonWfcRoamingMode", mButtonWfcRoamingMode);
+ ReflectionHelpers.setField(mFragment, "mUpdateAddress", mUpdateAddress);
+
+ mFragment.onActivityResult(WifiCallingSettingsForSub.REQUEST_CHECK_WFC_EMERGENCY_ADDRESS,
+ Activity.RESULT_OK, null);
+
+ // Check the WFC preferences is added.
+ verify(mPreferenceScreen).addPreference(mButtonWfcMode);
+ verify(mPreferenceScreen).addPreference(mButtonWfcRoamingMode);
+ verify(mPreferenceScreen).addPreference(mUpdateAddress);
+ // Check the WFC enable request.
+ verify(mImsManager).setWfcSetting(true);
+ }
+
+ @Test
+ public void onSwitchChanged_disableSetting_shouldNotLaunchWfcDisclaimerFragment() {
+ mFragment.onSwitchChanged(null, false);
+
+ // Check the WFC disclaimer fragment is not launched.
+ verify(mFragment, never()).startActivityForResult(any(Intent.class), anyInt());
+ }
+
protected static class TestFragment extends WifiCallingSettingsForSub {
@Override
protected Object getSystemService(final String name) {