Merge "Fix WifiDetailPreferenceControllerTest failure" into qt-dev
diff --git a/res/drawable/ic_face_enroll_introduction_detail.xml b/res/drawable/ic_face_enroll_introduction_detail.xml
index 7159148..386f8c7 100644
--- a/res/drawable/ic_face_enroll_introduction_detail.xml
+++ b/res/drawable/ic_face_enroll_introduction_detail.xml
@@ -14,7 +14,6 @@
~ See the License for the specific language governing permissions and
~ limitations under the License
-->
-
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
@@ -23,8 +22,13 @@
android:viewportHeight="24">
<path
- android:pathData="M0 0h24v24H0V0z" />
+ android:pathData="M0,0h24v24H0V0z" />
+ <path
+ android:pathData="M0,0h24v24H0V0z" />
<path
android:fillColor="#000000"
- android:pathData="M11 15h2v2h-2zm0-8h2v6h-2zm0.99-5C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2zM12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8z" />
+ android:pathData="M12,2L3.82,5.64v5.45c0,5.05,3.49,9.76,8.18,10.91c4.69-1.15,8.18-5.86,8.18-10.91V5.64L12,2z M18.18,11.09 c0,1.55-0.41,3.05-1.1,4.38C15.77,14.5,13.4,14,12,14s-3.77,0.5-5.08,1.47c-0.69-1.33-1.1-2.83-1.1-4.38V6.94L12,4.19l6.18,2.75 V11.09z" />
+ <path
+ android:fillColor="#000000"
+ android:pathData="M 12 7.5 C 13.6568542495 7.5 15 8.84314575051 15 10.5 C 15 12.1568542495 13.6568542495 13.5 12 13.5 C 10.3431457505 13.5 9 12.1568542495 9 10.5 C 9 8.84314575051 10.3431457505 7.5 12 7.5 Z" />
</vector>
\ No newline at end of file
diff --git a/res/layout/face_enroll_introduction.xml b/res/layout/face_enroll_introduction.xml
index 900f378..5107bd8 100644
--- a/res/layout/face_enroll_introduction.xml
+++ b/res/layout/face_enroll_introduction.xml
@@ -45,14 +45,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content" />
- <Space
- android:layout_width="0dp"
- android:layout_height="0dp"
- android:layout_weight="1"/>
-
<FrameLayout
android:layout_width="match_parent"
- android:layout_height="wrap_content">
+ android:layout_height="wrap_content"
+ android:layout_marginVertical="48dp">
<com.google.android.setupdesign.view.IllustrationVideoView
android:id="@+id/illustration_normal"
@@ -71,18 +67,12 @@
</FrameLayout>
- <Space
- android:layout_width="0dp"
- android:layout_height="0dp"
- android:layout_weight="1"/>
-
<!-- Contains the buttons and extra information text at the bottom -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
- android:layout_gravity="center_horizontal|bottom"
- android:layout_marginTop="24dp">
+ android:layout_gravity="center_horizontal|bottom">
<FrameLayout
android:layout_width="match_parent"
@@ -110,7 +100,8 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingStart="16dp"
- android:paddingEnd="16dp">
+ android:paddingEnd="16dp"
+ android:layout_marginTop="24dp">
<ImageView
android:layout_width="wrap_content"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index d5b0ae6..08d5634 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2243,7 +2243,7 @@
<string name="wifi_carrier_content">Connect via <xliff:g id="name">%1$s</xliff:g></string>
<string name="wifi_scan_always_turnon_message">To improve location accuracy and for other purposes, <xliff:g id="app_name">%1$s</xliff:g> wants to turn on network scanning, even when Wi-Fi is off.\n\nAllow this for all apps that want to scan?</string>
- <!-- Message to inform user, an unknown app want to enable network scanning. [CHAR LIMIT=200] -->
+ <!-- Message to inform user, an unknown app want to enable network scanning. [CHAR LIMIT=250] -->
<string name="wifi_scan_always_turn_on_message_unknown">To improve location accuracy and for other purposes, an unknown app wants to turn on network scanning, even when Wi\u2011Fi is off.\n\nAllow this for all apps that want to scan?</string>
<!-- Message informing the user how to turn off [CHAR LIMIT=200] -->
<string name="wifi_scan_always_turnoff_message">To turn this off, go to Advanced in the overflow menu.</string>
@@ -2308,12 +2308,12 @@
<item quantity="one">1 network</item>
<item quantity="other">%d networks</item>
</plurals>
- <!-- Wi-Fi settings screen, Saved passpoint networks summary. This shows below the "Saved networks" item and indicates the number of passpoint networks a user has saved. [CHAR LIMIT=30] -->
+ <!-- Wi-Fi settings screen, Saved networks summary. This shows below the "Saved networks" item and indicates the number of passpoint networks a user has saved. [CHAR LIMIT=30] -->
<plurals name="wifi_saved_passpoint_access_points_summary">
<item quantity="one">1 subscription</item>
<item quantity="other">%d subscriptions</item>
</plurals>
- <!-- Wi-Fi settings screen, Saved passpoint networks summary. This shows below the "Saved networks" item and indicates number of whole kinds networks, if there are both normal saved networks and saved passpoint networks. The number will be at least 2. [CHAR LIMIT=60] -->
+ <!-- Wi-Fi settings screen, Saved networks summary. This shows below the "Saved networks" item and indicates number of whole kinds networks, if there are both normal saved networks and saved passpoint networks. The number will be at least 2. [CHAR LIMIT=60] -->
<plurals name="wifi_saved_all_access_points_summary">
<item quantity="other">%d networks & subscriptions</item>
</plurals>
@@ -6994,6 +6994,10 @@
<string name="preferred_network_type_title">Preferred network type</string>
<!-- Preferred network type summary. [CHAR LIMIT=100] -->
<string name="preferred_network_type_summary">LTE (recommended)</string>
+ <!-- Title of multimedia messaging service settings. [CHAR LIMIT=50] -->
+ <string name="mms_message_title">MMS messages</string>
+ <!-- Summary of multimedia messaging service settings. [CHAR LIMIT=100] -->
+ <string name="mms_message_summary">Send & receive when mobile data is off</string>
<!-- Work SIM title. [CHAR LIMIT=50] -->
<string name="work_sim_title">Work SIM</string>
diff --git a/res/xml/adaptive_sleep_detail.xml b/res/xml/adaptive_sleep_detail.xml
index cada2e8..2fa511b 100644
--- a/res/xml/adaptive_sleep_detail.xml
+++ b/res/xml/adaptive_sleep_detail.xml
@@ -21,7 +21,6 @@
android:key="adaptive_sleep_detail"
android:title="@string/adaptive_sleep_title">
- <!-- TODO(111939367): add correct animation -->
<com.android.settings.widget.VideoPreference
android:key="adaptive_sleep_video"
android:title="@string/summary_placeholder"
diff --git a/res/xml/mobile_network_settings_v2.xml b/res/xml/mobile_network_settings_v2.xml
index e7cc1dc..6682437 100644
--- a/res/xml/mobile_network_settings_v2.xml
+++ b/res/xml/mobile_network_settings_v2.xml
@@ -74,6 +74,12 @@
settings:controller="com.android.settings.datausage.BillingCyclePreferenceController" />
<SwitchPreference
+ android:key="mms_message"
+ android:title="@string/mms_message_title"
+ android:summary="@string/mms_message_summary"
+ settings:controller="com.android.settings.network.telephony.MmsMessagePreferenceController" />
+
+ <SwitchPreference
android:key="enhanced_4g_lte"
android:title="@string/enhanced_4g_lte_mode_title"
android:persistent="false"
diff --git a/src/com/android/settings/core/FeatureFlags.java b/src/com/android/settings/core/FeatureFlags.java
index 9c00831..fee9c42 100644
--- a/src/com/android/settings/core/FeatureFlags.java
+++ b/src/com/android/settings/core/FeatureFlags.java
@@ -25,7 +25,6 @@
public static final String HEARING_AID_SETTINGS = "settings_bluetooth_hearing_aid";
public static final String MOBILE_NETWORK_V2 = "settings_mobile_network_v2";
public static final String NETWORK_INTERNET_V2 = "settings_network_and_internet_v2";
- public static final String SLICE_INJECTION = "settings_slice_injection";
public static final String WIFI_DETAILS_DATAUSAGE_HEADER =
"settings_wifi_details_datausage_header";
}
diff --git a/src/com/android/settings/gestures/GesturePreferenceController.java b/src/com/android/settings/gestures/GesturePreferenceController.java
index 97de95d..d7b386a 100644
--- a/src/com/android/settings/gestures/GesturePreferenceController.java
+++ b/src/com/android/settings/gestures/GesturePreferenceController.java
@@ -23,6 +23,7 @@
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
+import com.android.settings.R;
import com.android.settings.core.TogglePreferenceController;
import com.android.settings.widget.VideoPreference;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -64,6 +65,12 @@
}
@Override
+ public CharSequence getSummary() {
+ return mContext.getText(
+ isChecked() ? R.string.gesture_setting_on : R.string.gesture_setting_off);
+ }
+
+ @Override
public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState != null) {
mVideoPaused = savedInstanceState.getBoolean(KEY_VIDEO_PAUSED, false);
diff --git a/src/com/android/settings/media/MediaOutputIndicatorSlice.java b/src/com/android/settings/media/MediaOutputIndicatorSlice.java
index 0023e3f..fe59d75 100644
--- a/src/com/android/settings/media/MediaOutputIndicatorSlice.java
+++ b/src/com/android/settings/media/MediaOutputIndicatorSlice.java
@@ -114,29 +114,29 @@
private boolean isVisible() {
// To decide Slice's visibility.
// return true if device is connected or previously connected, false for other cases.
- return !CollectionUtils.isEmpty(getConnectableA2dpDevices())
- || !CollectionUtils.isEmpty(getConnectableHearingAidDevices());
+ return !CollectionUtils.isEmpty(getConnectedA2dpDevices())
+ || !CollectionUtils.isEmpty(getConnectedHearingAidDevices());
}
- private List<BluetoothDevice> getConnectableA2dpDevices() {
- // Get A2dp devices on all states
- // (STATE_DISCONNECTED, STATE_CONNECTING, STATE_CONNECTED, STATE_DISCONNECTING)
+ private List<BluetoothDevice> getConnectedA2dpDevices() {
+ // Get A2dp devices on states
+ // (STATE_CONNECTING, STATE_CONNECTED, STATE_DISCONNECTING)
final A2dpProfile a2dpProfile = mProfileManager.getA2dpProfile();
if (a2dpProfile == null) {
return new ArrayList<>();
}
- return a2dpProfile.getConnectableDevices();
+ return a2dpProfile.getConnectedDevices();
}
- private List<BluetoothDevice> getConnectableHearingAidDevices() {
- // Get hearing aid profile devices on all states
- // (STATE_DISCONNECTED, STATE_CONNECTING, STATE_CONNECTED, STATE_DISCONNECTING)
+ private List<BluetoothDevice> getConnectedHearingAidDevices() {
+ // Get hearing aid profile devices on states
+ // (STATE_CONNECTING, STATE_CONNECTED, STATE_DISCONNECTING)
final HearingAidProfile hapProfile = mProfileManager.getHearingAidProfile();
if (hapProfile == null) {
return new ArrayList<>();
}
- return hapProfile.getConnectableDevices();
+ return hapProfile.getConnectedDevices();
}
private CharSequence findActiveDeviceName() {
diff --git a/src/com/android/settings/network/MobileDataContentObserver.java b/src/com/android/settings/network/MobileDataContentObserver.java
new file mode 100644
index 0000000..b8a1c8c
--- /dev/null
+++ b/src/com/android/settings/network/MobileDataContentObserver.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network;
+
+import android.content.Context;
+import android.database.ContentObserver;
+import android.net.Uri;
+import android.os.Handler;
+import android.provider.Settings;
+import android.telephony.TelephonyManager;
+
+/**
+ * {@link ContentObserver} to listen to update of mobile data change
+ */
+public class MobileDataContentObserver extends ContentObserver {
+ private OnMobileDataChangedListener mListener;
+
+ public MobileDataContentObserver(Handler handler) {
+ super(handler);
+ }
+
+ public static Uri getObservableUri(int subId) {
+ Uri uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA);
+ if (TelephonyManager.getDefault().getSimCount() != 1) {
+ uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA + subId);
+ }
+ return uri;
+ }
+
+ public void setOnMobileDataChangedListener(OnMobileDataChangedListener lsn) {
+ mListener = lsn;
+ }
+
+ @Override
+ public void onChange(boolean selfChange) {
+ super.onChange(selfChange);
+ if (mListener != null) {
+ mListener.onMobileDataChanged();
+ }
+ }
+
+ public void register(Context context, int subId) {
+ final Uri uri = getObservableUri(subId);
+ context.getContentResolver().registerContentObserver(uri, false, this);
+
+ }
+
+ public void unRegister(Context context) {
+ context.getContentResolver().unregisterContentObserver(this);
+ }
+
+ /**
+ * Listener for update of mobile data(ON vs OFF)
+ */
+ public interface OnMobileDataChangedListener {
+ void onMobileDataChanged();
+ }
+}
diff --git a/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
new file mode 100644
index 0000000..b8d2081
--- /dev/null
+++ b/src/com/android/settings/network/telephony/MmsMessagePreferenceController.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import android.content.Context;
+import android.os.Handler;
+import android.os.Looper;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.telephony.data.ApnSetting;
+import android.util.Log;
+
+import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
+import androidx.preference.SwitchPreference;
+
+import com.android.settings.network.MobileDataContentObserver;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnStart;
+import com.android.settingslib.core.lifecycle.events.OnStop;
+
+/**
+ * Preference controller for "Mobile data"
+ */
+public class MmsMessagePreferenceController extends TelephonyTogglePreferenceController implements
+ LifecycleObserver, OnStart, OnStop {
+ private TelephonyManager mTelephonyManager;
+ private SubscriptionManager mSubscriptionManager;
+ private MobileDataContentObserver mMobileDataContentObserver;
+ private SwitchPreference mPreference;
+
+ public MmsMessagePreferenceController(Context context, String key) {
+ super(context, key);
+ mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
+ mMobileDataContentObserver = new MobileDataContentObserver(
+ new Handler(Looper.getMainLooper()));
+ mMobileDataContentObserver.setOnMobileDataChangedListener(()->updateState(mPreference));
+ }
+
+ @Override
+ public int getAvailabilityStatus(int subId) {
+ final TelephonyManager telephonyManager = TelephonyManager
+ .from(mContext).createForSubscriptionId(subId);
+ return (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID
+ && !telephonyManager.isDataEnabled()
+ && telephonyManager.isApnMetered(ApnSetting.TYPE_MMS))
+ ? AVAILABLE
+ : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public void onStart() {
+ if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ mMobileDataContentObserver.register(mContext, mSubId);
+ }
+ }
+
+ @Override
+ public void onStop() {
+ if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ mMobileDataContentObserver.unRegister(mContext);
+ }
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ preference.setVisible(isAvailable());
+ ((SwitchPreference) preference).setChecked(isChecked());
+ }
+
+ public void init(int subId) {
+ mSubId = subId;
+ mTelephonyManager = TelephonyManager.from(mContext).createForSubscriptionId(mSubId);
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ return mSubscriptionManager.setAlwaysAllowMmsData(mSubId, isChecked);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mTelephonyManager.isDataEnabledForApn(ApnSetting.TYPE_MMS);
+ }
+}
diff --git a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
index de54879..a0e50fc 100644
--- a/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
+++ b/src/com/android/settings/network/telephony/MobileDataPreferenceController.java
@@ -27,6 +27,7 @@
import android.telephony.TelephonyManager;
import android.text.TextUtils;
+import com.android.settings.network.MobileDataContentObserver;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
@@ -48,7 +49,7 @@
private SwitchPreference mPreference;
private TelephonyManager mTelephonyManager;
private SubscriptionManager mSubscriptionManager;
- private DataContentObserver mDataContentObserver;
+ private MobileDataContentObserver mDataContentObserver;
private FragmentManager mFragmentManager;
@VisibleForTesting
int mDialogType;
@@ -58,7 +59,8 @@
public MobileDataPreferenceController(Context context, String key) {
super(context, key);
mSubscriptionManager = context.getSystemService(SubscriptionManager.class);
- mDataContentObserver = new DataContentObserver(new Handler(Looper.getMainLooper()));
+ mDataContentObserver = new MobileDataContentObserver(new Handler(Looper.getMainLooper()));
+ mDataContentObserver.setOnMobileDataChangedListener(()-> updateState(mPreference));
}
@Override
@@ -129,14 +131,6 @@
return info != null && info.isOpportunistic();
}
- public static Uri getObservableUri(int subId) {
- Uri uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA);
- if (TelephonyManager.getDefault().getSimCount() != 1) {
- uri = Settings.Global.getUriFor(Settings.Global.MOBILE_DATA + subId);
- }
- return uri;
- }
-
public void init(FragmentManager fragmentManager, int subId) {
mFragmentManager = fragmentManager;
mSubId = subId;
@@ -170,30 +164,4 @@
mSubId);
dialogFragment.show(mFragmentManager, DIALOG_TAG);
}
-
- /**
- * Listener that listens mobile data state change.
- */
- public class DataContentObserver extends ContentObserver {
-
- public DataContentObserver(Handler handler) {
- super(handler);
- }
-
- @Override
- public void onChange(boolean selfChange) {
- super.onChange(selfChange);
- updateState(mPreference);
- }
-
- public void register(Context context, int subId) {
- final Uri uri = getObservableUri(subId);
- context.getContentResolver().registerContentObserver(uri, false, this);
-
- }
-
- public void unRegister(Context context) {
- context.getContentResolver().unregisterContentObserver(this);
- }
- }
}
diff --git a/src/com/android/settings/network/telephony/MobileDataSlice.java b/src/com/android/settings/network/telephony/MobileDataSlice.java
index 28cb11e..bf9fc04 100644
--- a/src/com/android/settings/network/telephony/MobileDataSlice.java
+++ b/src/com/android/settings/network/telephony/MobileDataSlice.java
@@ -39,6 +39,7 @@
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.network.AirplaneModePreferenceController;
+import com.android.settings.network.MobileDataContentObserver;
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.slices.CustomSliceable;
import com.android.settings.slices.SliceBackgroundWorker;
@@ -267,7 +268,7 @@
}
public void register(Context context, int subId) {
- final Uri uri = MobileDataPreferenceController.getObservableUri(subId);
+ final Uri uri = MobileDataContentObserver.getObservableUri(subId);
context.getContentResolver().registerContentObserver(uri, false, this);
}
diff --git a/src/com/android/settings/network/telephony/MobileNetworkSettings.java b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
index 3578792..db99258 100644
--- a/src/com/android/settings/network/telephony/MobileNetworkSettings.java
+++ b/src/com/android/settings/network/telephony/MobileNetworkSettings.java
@@ -136,6 +136,7 @@
use(MobileNetworkSwitchController.class).init(getLifecycle(), mSubId);
use(CarrierSettingsVersionPreferenceController.class).init(mSubId);
use(BillingCyclePreferenceController.class).init(mSubId);
+ use(MmsMessagePreferenceController.class).init(mSubId);
}
use(MobileDataPreferenceController.class).init(getFragmentManager(), mSubId);
use(RoamingPreferenceController.class).init(getFragmentManager(), mSubId);
diff --git a/src/com/android/settings/sim/CallsSimListDialogFragment.java b/src/com/android/settings/sim/CallsSimListDialogFragment.java
index bb5a003..7d3de44 100644
--- a/src/com/android/settings/sim/CallsSimListDialogFragment.java
+++ b/src/com/android/settings/sim/CallsSimListDialogFragment.java
@@ -16,6 +16,7 @@
package com.android.settings.sim;
+import android.app.settings.SettingsEnums;
import android.content.Context;
import android.telecom.PhoneAccount;
import android.telecom.PhoneAccountHandle;
@@ -56,4 +57,9 @@
}
return result;
}
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.DIALOG_CALL_SIM_LIST;
+ }
}
diff --git a/src/com/android/settings/sim/PreferredSimDialogFragment.java b/src/com/android/settings/sim/PreferredSimDialogFragment.java
index 5b81e62..29f4c65 100644
--- a/src/com/android/settings/sim/PreferredSimDialogFragment.java
+++ b/src/com/android/settings/sim/PreferredSimDialogFragment.java
@@ -18,6 +18,7 @@
import android.app.Activity;
import android.app.Dialog;
+import android.app.settings.SettingsEnums;
import android.content.DialogInterface;
import android.os.Bundle;
import android.telephony.SubscriptionInfo;
@@ -98,4 +99,9 @@
protected SubscriptionManager getSubscriptionManager() {
return getContext().getSystemService(SubscriptionManager.class);
}
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.DIALOG_PREFERRED_SIM_PICKER;
+ }
}
diff --git a/src/com/android/settings/sim/SimDialogFragment.java b/src/com/android/settings/sim/SimDialogFragment.java
index 10815fd..de991ec 100644
--- a/src/com/android/settings/sim/SimDialogFragment.java
+++ b/src/com/android/settings/sim/SimDialogFragment.java
@@ -20,10 +20,11 @@
import android.os.Bundle;
import androidx.annotation.NonNull;
-import androidx.fragment.app.DialogFragment;
+
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
/** Common functionality for showing a dialog in SimDialogActivity. */
-public abstract class SimDialogFragment extends DialogFragment {
+public abstract class SimDialogFragment extends InstrumentedDialogFragment {
private static final String TAG = "SimDialogFragment";
private static final String KEY_TITLE_ID = "title_id";
diff --git a/src/com/android/settings/sim/SimListDialogFragment.java b/src/com/android/settings/sim/SimListDialogFragment.java
index f78c4e7..1802d65 100644
--- a/src/com/android/settings/sim/SimListDialogFragment.java
+++ b/src/com/android/settings/sim/SimListDialogFragment.java
@@ -17,6 +17,7 @@
package com.android.settings.sim;
import android.app.Dialog;
+import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
@@ -50,7 +51,7 @@
protected SelectSubscriptionAdapter mAdapter;
@VisibleForTesting
- List<SubscriptionInfo> mSubscriptions;
+ List<SubscriptionInfo> mSubscriptions;
public static SimListDialogFragment newInstance(int dialogType, int titleResId,
boolean includeAskEveryTime) {
@@ -122,6 +123,11 @@
builder.setAdapter(mAdapter, this);
}
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.DIALOG_SIM_LIST;
+ }
+
private static class SelectSubscriptionAdapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mInflater;
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 56e4c30..4d3f230 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -469,13 +469,12 @@
return;
}
- // "forget" for normal saved network. And "disconnect" for ephemeral network because we
- // could only disconnect it and put it in blacklists so it won't be used again.
- if (mSelectedAccessPoint.isEphemeral()) {
- menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */,
- R.string.wifi_disconnect_button_text);
- } else if (mSelectedAccessPoint.isSaved()) {
- menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */, R.string.forget);
+ // "forget" for normal saved network. And "disconnect" for ephemeral network because it
+ // could only be disconnected and be put in blacklists so it won't be used again.
+ if (mSelectedAccessPoint.isSaved() || mSelectedAccessPoint.isEphemeral()) {
+ final int stringId = mSelectedAccessPoint.isEphemeral() ?
+ R.string.wifi_disconnect_button_text : R.string.forget;
+ menu.add(Menu.NONE, MENU_ID_FORGET, 0 /* order */, stringId);
}
if (mSelectedAccessPoint.isSaved() && !mSelectedAccessPoint.isActive()) {
diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
index ae96ed3..eaf3678 100644
--- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
+++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
@@ -146,7 +146,8 @@
private static final long TIMEOUT = Duration.ofSeconds(10).toMillis();
// Be static to avoid too much object not be reset.
- private static CountDownTimer mTimer;
+ @VisibleForTesting
+ static CountDownTimer mTimer;
private AccessPoint mAccessPoint;
private final ConnectivityManager mConnectivityManager;
@@ -256,20 +257,15 @@
@Override
public void onLost(Network network) {
- final boolean lostCurrentNetwork = network.equals(mNetwork);
- if (lostCurrentNetwork) {
- // Should update as disconnect but not exit. Except for ephemeral network which
- // should not show on saved network list.
- if (!mIsEphemeral) {
- return;
- }
-
+ // Ephemeral network not a saved network, leave detail page once disconnected
+ if (mIsEphemeral && network.equals(mNetwork)) {
exitActivity();
}
}
};
- private final WifiTracker.WifiListener mWifiListener = new WifiTracker.WifiListener() {
+ @VisibleForTesting
+ final WifiTracker.WifiListener mWifiListener = new WifiTracker.WifiListener() {
/** Called when the state of Wifi has changed. */
public void onWifiStateChanged(int state) {
Log.d(TAG, "onWifiStateChanged(" + state + ")");
@@ -284,16 +280,7 @@
/** Called when the connection state of wifi has changed. */
public void onConnectedChanged() {
- updateAccessPointFromScannedList();
- if (mConnected != mAccessPoint.isActive()) {
- Log.d(TAG, "Connection state changed!");
- mConnected = mAccessPoint.isActive();
- if (mAccessPoint.isActive()) {
- updateConnectingState(STATE_CONNECTED);
- } else {
- updateConnectingState(STATE_DISCONNECTED);
- }
- }
+ refreshPage();
}
/**
@@ -516,42 +503,41 @@
refreshMacAddress();
}
- private boolean updateAccessPoint() {
+ @VisibleForTesting
+ boolean updateAccessPoint() {
boolean changed = false;
- if (mWifiTracker != null) {
- // remember mIsOutOfRange as old before updated
- boolean oldState = mIsOutOfRange;
- updateAccessPointFromScannedList();
- // refresh UI if signal level changed for disconnect network.
- changed = mRssiSignalLevel != mAccessPoint.getLevel();
- changed |= oldState != mIsOutOfRange;
- }
+ // remember mIsOutOfRange as old before updated
+ boolean oldState = mIsOutOfRange;
+ updateAccessPointFromScannedList();
if (mAccessPoint.isActive()) {
- // Sometimes {@link WifiManager#getCurrentNetwork()} return null after connected,
- // refresh it if needed.
- if (mNetwork == null) {
- updateNetworkInfo();
- }
+ updateNetworkInfo();
mNetworkInfo = mConnectivityManager.getNetworkInfo(mNetwork);
mWifiInfo = mWifiManager.getConnectionInfo();
if (mNetwork == null || mNetworkInfo == null || mWifiInfo == null) {
- // Once connected, can't get mNetworkInfo immediately, return false and wait for
- // next time to update UI.
+ // Once connected, can't get mNetwork immediately, return false and wait for
+ // next time to update UI. also reset {@code mIsOutOfRange}
+ mIsOutOfRange = oldState;
return false;
}
-
changed |= mAccessPoint.update(mWifiConfig, mWifiInfo, mNetworkInfo);
- // If feature for saved network not enabled, always return true.
- return mWifiTracker == null || changed;
+ }
+
+ // signal level changed
+ changed |= mRssiSignalLevel != mAccessPoint.getLevel();
+ // In/Out of range changed
+ changed |= oldState != mIsOutOfRange;
+ // connect state changed
+ if (mConnected != mAccessPoint.isActive()) {
+ mConnected = mAccessPoint.isActive();
+ changed = true;
+ updateConnectingState(mAccessPoint.isActive() ? STATE_CONNECTED : STATE_DISCONNECTED);
}
return changed;
}
private void updateAccessPointFromScannedList() {
- if (mWifiTracker == null) return;
-
mIsOutOfRange = true;
for (AccessPoint ap : mWifiTracker.getAccessPoints()) {
@@ -967,7 +953,8 @@
return FeatureFlagUtils.isEnabled(context, FeatureFlags.WIFI_DETAILS_DATAUSAGE_HEADER);
}
- private void connectNetwork() {
+ @VisibleForTesting
+ void connectNetwork() {
final Activity activity = mFragment.getActivity();
// error handling, connected/saved network should have mWifiConfig.
if (mWifiConfig == null) {
@@ -1045,7 +1032,6 @@
mAccessPoint.getTitle()),
Toast.LENGTH_SHORT).show();
- updateNetworkInfo();
refreshPage();
} else if (state == STATE_NOT_IN_RANGE) {
Log.d(TAG, "AP not in range");
@@ -1084,7 +1070,11 @@
.setButton3Enabled(false);
break;
case STATE_CONNECTED:
- mButtonsPref.setButton3Visible(false);
+ // init button state and set as invisible
+ mButtonsPref.setButton3Text(R.string.wifi_connect)
+ .setButton3Icon(R.drawable.ic_settings_wireless)
+ .setButton3Enabled(true)
+ .setButton3Visible(false);
break;
case STATE_DISCONNECTED:
case STATE_NOT_IN_RANGE:
diff --git a/tests/robotests/assets/grandfather_slice_controller_not_in_xml b/tests/robotests/assets/grandfather_slice_controller_not_in_xml
index d2274e6..4bc4339 100644
--- a/tests/robotests/assets/grandfather_slice_controller_not_in_xml
+++ b/tests/robotests/assets/grandfather_slice_controller_not_in_xml
@@ -2,3 +2,4 @@
com.android.settings.testutils.FakeSliderController
com.android.settings.core.TogglePreferenceControllerTest$FakeToggle
com.android.settings.accessibility.AccessibilitySlicePreferenceController
+com.android.settings.network.telephony.MmsMessagePreferenceController
diff --git a/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java b/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java
index 5fdadb4..ccc8cbd 100644
--- a/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java
+++ b/tests/robotests/src/com/android/settings/core/codeinspection/CodeInspectionTest.java
@@ -24,12 +24,11 @@
import com.android.settings.slices.SliceControllerInXmlCodeInspector;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
import java.util.List;
-import org.robolectric.RobolectricTestRunner;
/**
* Test suite that scans all classes in app package, and performs different types of code inspection
@@ -47,7 +46,6 @@
}
@Test
- @Ignore("b/130897640")
public void runInstrumentableFragmentCodeInspection() {
new InstrumentableFragmentCodeInspector(mClasses).run();
}
diff --git a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
index b39f77e..1ba1dc9 100644
--- a/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
+++ b/tests/robotests/src/com/android/settings/media/MediaOutputIndicatorSliceTest.java
@@ -106,9 +106,9 @@
}
@Test
- public void getSlice_noConnectableDevice_returnNull() {
+ public void getSlice_noConnectedDevice_returnNull() {
mDevicesList.clear();
- when(mA2dpProfile.getConnectableDevices()).thenReturn(mDevicesList);
+ when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
assertThat(mMediaOutputIndicatorSlice.getSlice()).isNull();
}
@@ -116,7 +116,7 @@
@Test
public void getSlice_noActiveDevice_verifyDefaultName() {
mDevicesList.add(mA2dpDevice);
- when(mA2dpProfile.getConnectableDevices()).thenReturn(mDevicesList);
+ when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
when(mA2dpProfile.getActiveDevice()).thenReturn(null);
// Verify slice title and subtitle
@@ -130,7 +130,7 @@
@Test
public void getSlice_A2dpDeviceActive_verifyName() {
mDevicesList.add(mA2dpDevice);
- when(mA2dpProfile.getConnectableDevices()).thenReturn(mDevicesList);
+ when(mA2dpProfile.getConnectedDevices()).thenReturn(mDevicesList);
when(mA2dpProfile.getActiveDevice()).thenReturn(mA2dpDevice);
final Slice mediaSlice = mMediaOutputIndicatorSlice.getSlice();
@@ -142,7 +142,7 @@
@Test
public void getSlice_HADeviceActive_verifyName() {
mDevicesList.add(mHapDevice);
- when(mHearingAidProfile.getConnectableDevices()).thenReturn(mDevicesList);
+ when(mHearingAidProfile.getConnectedDevices()).thenReturn(mDevicesList);
when(mHearingAidProfile.getActiveDevices()).thenReturn(mDevicesList);
// Verify slice title and subtitle
diff --git a/tests/robotests/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
new file mode 100644
index 0000000..0263fe9
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/network/telephony/MmsMessagePreferenceControllerTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.network.telephony;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_UNAVAILABLE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.telephony.SubscriptionManager;
+import android.telephony.TelephonyManager;
+import android.telephony.data.ApnSetting;
+
+import androidx.preference.SwitchPreference;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowSubscriptionManager;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(shadows = ShadowSubscriptionManager.class)
+public class MmsMessagePreferenceControllerTest {
+ private static final int SUB_ID = 2;
+
+ @Mock
+ private TelephonyManager mTelephonyManager;
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
+
+ private MmsMessagePreferenceController mController;
+ private SwitchPreference mPreference;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
+ when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
+ when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
+ when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
+
+ mPreference = new SwitchPreference(mContext);
+ mController = new MmsMessagePreferenceController(mContext, "mms_message");
+ ShadowSubscriptionManager.setDefaultDataSubscriptionId(SUB_ID);
+ mController.init(SUB_ID);
+ mPreference.setKey(mController.getPreferenceKey());
+ }
+
+ @Test
+ public void getAvailabilityStatus_invalidSubscription_returnUnavailable() {
+ mController.init(SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_mobileDataOn_returnUnavailable() {
+ when(mTelephonyManager.isDataEnabled()).thenReturn(true);
+
+ assertThat(mController.getAvailabilityStatus(SUB_ID)).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_meteredOff_returnUnavailable() {
+ when(mTelephonyManager.isApnMetered(ApnSetting.TYPE_MMS)).thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus(SUB_ID)).isEqualTo(CONDITIONALLY_UNAVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_mobileDataOffWithValidSubId_returnAvailable() {
+ mController.init(SUB_ID);
+ when(mTelephonyManager.isDataEnabled()).thenReturn(false);
+ when(mTelephonyManager.isApnMetered(ApnSetting.TYPE_MMS)).thenReturn(true);
+
+ assertThat(mController.getAvailabilityStatus(SUB_ID)).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void isChecked_returnDataFromTelephonyManager() {
+ when(mTelephonyManager.isDataEnabledForApn(ApnSetting.TYPE_MMS)).thenReturn(false);
+ assertThat(mController.isChecked()).isFalse();
+
+ when(mTelephonyManager.isDataEnabledForApn(ApnSetting.TYPE_MMS)).thenReturn(true);
+ assertThat(mController.isChecked()).isTrue();
+ }
+
+ @Test
+ public void setChecked_setDataIntoSubscriptionManager() {
+ mController.setChecked(true);
+ verify(mSubscriptionManager).setAlwaysAllowMmsData(SUB_ID, true);
+
+ mController.setChecked(false);
+ verify(mSubscriptionManager).setAlwaysAllowMmsData(SUB_ID, false);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
index de23f18..904fdd8 100644
--- a/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiDetailPreferenceControllerTest.java
@@ -35,6 +35,7 @@
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
+import android.content.res.Resources;
import android.content.pm.PackageManager;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
@@ -95,6 +96,7 @@
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowToast;
import java.net.Inet4Address;
import java.net.InetAddress;
@@ -1311,6 +1313,406 @@
}
@Test
+ public void testConnectButton_shouldInvisibleForConnectNetwork() {
+ setUpForConnectedNetwork();
+
+ displayAndResume();
+
+ verify(mockButtonsPref, times(1)).setButton3Visible(false);
+ }
+
+ @Test
+ public void testConnectButton_shouldVisibleForDisconnectNetwork() {
+ setUpForDisconnectedNetwork();
+
+ displayAndResume();
+
+ verify(mockButtonsPref, times(1)).setButton3Visible(true);
+ verify(mockButtonsPref, times(1)).setButton3Text(R.string.wifi_connect);
+ }
+
+ private void setUpForToast() {
+ Resources res = mContext.getResources();
+ when(mockActivity.getResources()).thenReturn(res);
+ }
+
+ @Test
+ public void testConnectButton_clickConnect_displayAsSuccess() {
+ setUpForDisconnectedNetwork();
+ when(mockWifiManager.isWifiEnabled()).thenReturn(true);
+ InOrder inOrder = inOrder(mockButtonsPref);
+ String label = "title";
+ when(mockAccessPoint.getTitle()).thenReturn(label);
+ setUpForToast();
+
+ displayAndResume();
+
+ // check connect button exist
+ verifyConnectBtnSetUpAsVisible(inOrder);
+
+ // click connect button
+ mController.connectNetwork();
+
+ // check display button as connecting
+ verify(mockWifiManager, times(1)).connect(anyInt(), any(WifiManager.ActionListener.class));
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+
+ // update as connected
+ when(mockAccessPoint.isActive()).thenReturn(true);
+ mController.updateAccessPoint();
+
+ // check connect button invisible, be init as default state and toast success message
+ verifyConnectBtnBeInitAsDefault(inOrder);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Visible(false);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_connected_to_message, label));
+ }
+
+ @Test
+ public void testConnectButton_clickConnectButFailed_displayFailMessage() {
+ setUpForDisconnectedNetwork();
+ ArgumentCaptor<WifiManager.ActionListener> connectListenerCaptor =
+ ArgumentCaptor.forClass(WifiManager.ActionListener.class);
+ when(mockWifiManager.isWifiEnabled()).thenReturn(true);
+ InOrder inOrder = inOrder(mockButtonsPref);
+ setUpForToast();
+
+ displayAndResume();
+
+ // check connect button exist
+ verifyConnectBtnSetUpAsVisible(inOrder);
+
+ // click connect button
+ mController.connectNetwork();
+
+ // check display button as connecting
+ verify(mockWifiManager, times(1)).connect(anyInt(), connectListenerCaptor.capture());
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+
+ // update as failed
+ connectListenerCaptor.getValue().onFailure(-1);
+
+ // check connect button visible, be init as default and toast failed message
+ verifyConnectBtnBeInitAsDefault(inOrder);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Visible(true);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_failed_connect_message));
+ }
+
+ private void verifyConnectBtnSetUpAsVisible(InOrder inOrder) {
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Text(R.string.wifi_connect);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Icon(R.drawable.ic_settings_wireless);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Visible(true);
+ }
+
+ private void verifyConnectBtnSetUpAsConnecting(InOrder inOrder) {
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Text(R.string.wifi_connecting);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Enabled(false);
+ }
+
+ private void verifyConnectBtnBeInitAsDefault(InOrder inOrder) {
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Text(R.string.wifi_connect);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Icon(R.drawable.ic_settings_wireless);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Enabled(true);
+ }
+
+ @Test
+ public void testConnectButton_clickConnectButTimeout_displayFailMessage() {
+ setUpForDisconnectedNetwork();
+ when(mockWifiManager.isWifiEnabled()).thenReturn(true);
+ InOrder inOrder = inOrder(mockButtonsPref);
+ setUpForToast();
+
+ displayAndResume();
+
+ // check connect button exist
+ verifyConnectBtnSetUpAsVisible(inOrder);
+
+ // click connect button
+ mController.connectNetwork();
+
+ // check display button as connecting
+ verify(mockWifiManager, times(1)).connect(anyInt(), any(WifiManager.ActionListener.class));
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+
+ // update as failed
+ mController.mTimer.onFinish();
+
+ // check connect button visible, be init as default and toast failed message
+ verifyConnectBtnBeInitAsDefault(inOrder);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Visible(true);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_failed_connect_message));
+ }
+
+ @Test
+ public void testConnectButton_clickConnectButTimeout_displayNotInRangeMessage() {
+ setUpForNotInRangeNetwork();
+ when(mockWifiManager.isWifiEnabled()).thenReturn(true);
+ InOrder inOrder = inOrder(mockButtonsPref);
+ setUpForToast();
+
+ displayAndResume();
+
+ // check connect button exist
+ verifyConnectBtnSetUpAsVisible(inOrder);
+
+ // click connect button
+ mController.connectNetwork();
+
+ // check display button as connecting
+ verify(mockWifiManager, times(1)).connect(anyInt(), any(WifiManager.ActionListener.class));
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+
+ // update as failed
+ mController.mTimer.onFinish();
+
+ // check connect button visible, be init as default and toast failed message
+ verifyConnectBtnBeInitAsDefault(inOrder);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Visible(true);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_not_in_range_message));
+ }
+
+ @Test
+ public void testConnectButton_clickConnectWhenWiFiDisabled_displaySuccessMessage() {
+ setUpForDisconnectedNetwork();
+ when(mockWifiManager.isWifiEnabled()).thenReturn(false); // wifi disabled
+ InOrder inOrder = inOrder(mockButtonsPref);
+ String label = "title";
+ when(mockAccessPoint.getTitle()).thenReturn(label);
+ setUpForToast();
+
+ displayAndResume();
+
+ // check connect button exist
+ verifyConnectBtnSetUpAsVisible(inOrder);
+
+ // click connect button
+ mController.connectNetwork();
+
+ // check turn on Wi-Fi, display button as connecting and toast turn on Wi-Fi message
+ verify(mockWifiManager, times(1)).setWifiEnabled(true);
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_turned_on_message));
+
+ // notify Wi-Fi enabled
+ mController.mWifiListener.onWifiStateChanged(WifiManager.WIFI_STATE_ENABLED);
+
+ // check had connect network and icon display as expected
+ verify(mockWifiManager, times(1)).connect(anyInt(), any(WifiManager.ActionListener.class));
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+
+ // update as connected
+ when(mockAccessPoint.isActive()).thenReturn(true);
+ mController.updateAccessPoint();
+
+ // check connect button invisible, be init as default state and toast success message
+ verifyConnectBtnBeInitAsDefault(inOrder);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Visible(false);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_connected_to_message, label));
+ }
+
+ @Test
+ public void testConnectButton_clickConnectWhenWiFiDisabled_failedToConnectWiFi() {
+ setUpForDisconnectedNetwork();
+ when(mockWifiManager.isWifiEnabled()).thenReturn(false); // wifi disabled
+ InOrder inOrder = inOrder(mockButtonsPref);
+ setUpForToast();
+
+ displayAndResume();
+
+ // check connect button exist
+ verifyConnectBtnSetUpAsVisible(inOrder);
+
+ // click connect button
+ mController.connectNetwork();
+
+ // check turn on Wi-Fi, display button as connecting and toast turn on Wi-Fi message
+ verify(mockWifiManager, times(1)).setWifiEnabled(true);
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_turned_on_message));
+
+ // notify Wi-Fi enabled
+ mController.mWifiListener.onWifiStateChanged(WifiManager.WIFI_STATE_ENABLED);
+
+ // check had connect network and icon display as expected
+ verify(mockWifiManager, times(1)).connect(anyInt(), any(WifiManager.ActionListener.class));
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+
+ // update as failed
+ mController.mTimer.onFinish();
+
+ // check connect button visible, be init as default and toast failed message
+ verifyConnectBtnBeInitAsDefault(inOrder);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Visible(true);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_failed_connect_message));
+ }
+
+ @Test
+ public void
+ testConnectButton_clickConnectWhenWiFiDisabled_failedToConnectWifiBecauseNotInRange() {
+ setUpForNotInRangeNetwork();
+ when(mockWifiManager.isWifiEnabled()).thenReturn(false); // wifi disabled
+ InOrder inOrder = inOrder(mockButtonsPref);
+ setUpForToast();
+
+ displayAndResume();
+
+ // check connect button exist
+ verifyConnectBtnSetUpAsVisible(inOrder);
+
+ // click connect button
+ mController.connectNetwork();
+
+ // check turn on Wi-Fi, display button as connecting and toast turn on Wi-Fi message
+ verify(mockWifiManager, times(1)).setWifiEnabled(true);
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_turned_on_message));
+
+ // notify Wi-Fi enabled
+ mController.mWifiListener.onWifiStateChanged(WifiManager.WIFI_STATE_ENABLED);
+
+ // check had connect network and icon display as expected
+ verify(mockWifiManager, times(1)).connect(anyInt(), any(WifiManager.ActionListener.class));
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+
+ // update as failed
+ mController.mTimer.onFinish();
+
+ // check connect button visible, be init as default and toast failed message
+ verifyConnectBtnBeInitAsDefault(inOrder);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Visible(true);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_not_in_range_message));
+ }
+
+ @Test
+ public void testConnectButton_clickConnectWhenWiFiDisabled_failedToEnableWifi() {
+ setUpForDisconnectedNetwork();
+ when(mockWifiManager.isWifiEnabled()).thenReturn(false); // wifi disabled
+ InOrder inOrder = inOrder(mockButtonsPref);
+ setUpForToast();
+
+ displayAndResume();
+
+ // check connect button exist
+ verifyConnectBtnSetUpAsVisible(inOrder);
+
+ // click connect button
+ mController.connectNetwork();
+
+ // check turn on Wi-Fi, display button as connecting and toast turn on Wi-Fi message
+ verify(mockWifiManager, times(1)).setWifiEnabled(true);
+ verifyConnectBtnSetUpAsConnecting(inOrder);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_turned_on_message));
+
+ // notify turn on Wi-Fi failed
+ mController.mTimer.onFinish();
+
+ // check connect button visible, be init as default and toast failed message
+ verifyConnectBtnBeInitAsDefault(inOrder);
+ inOrder.verify(mockButtonsPref, times(1)).setButton3Visible(true);
+ assertThat(ShadowToast.getTextOfLatestToast()).isEqualTo(
+ mContext.getString(R.string.wifi_failed_connect_message));
+ }
+
+ @Test
+ public void updateAccessPoint_returnFalseForNothingChanged() {
+ setUpForDisconnectedNetwork();
+
+ displayAndResume();
+ boolean changed = mController.updateAccessPoint();
+
+ assertThat(changed).isFalse();
+ }
+
+ @Test
+ public void updateAccessPoint_returnTrueForSignalLevelChanged() {
+ setUpForDisconnectedNetwork();
+
+ displayAndResume();
+
+ // Level changed
+ when(mockAccessPoint.getLevel()).thenReturn(LEVEL + 1);
+ boolean changed = mController.updateAccessPoint();
+
+ assertThat(changed).isTrue();
+ }
+
+ @Test
+ public void updateAccessPoint_returnTrueForChangeAsNotInRange() {
+ setUpForDisconnectedNetwork();
+
+ displayAndResume();
+
+ // change as not in range
+ when(mockAccessPoint.matches(any(WifiConfiguration.class))).thenReturn(false);
+ boolean changed = mController.updateAccessPoint();
+
+ assertThat(changed).isTrue();
+ }
+
+ @Test
+ public void updateAccessPoint_returnTrueForChangeAsInRange() {
+ setUpForNotInRangeNetwork();
+
+ displayAndResume();
+
+ // change as in range
+ when(mockAccessPoint.matches(any(WifiConfiguration.class))).thenReturn(true);
+ boolean changed = mController.updateAccessPoint();
+
+ assertThat(changed).isTrue();
+ }
+
+ @Test
+ public void updateAccessPoint_returnTrueForChangeAsConnected() {
+ setUpForDisconnectedNetwork();
+
+ displayAndResume();
+
+ // change as connected
+ when(mockAccessPoint.isActive()).thenReturn(true);
+ boolean changed = mController.updateAccessPoint();
+
+ assertThat(changed).isTrue();
+ }
+
+ @Test
+ public void updateAccessPoint_returnTrueForChangeAsDisconnected() {
+ setUpForConnectedNetwork();
+
+ displayAndResume();
+
+ // change as disconnected
+ when(mockAccessPoint.isActive()).thenReturn(false);
+ boolean changed = mController.updateAccessPoint();
+
+ assertThat(changed).isTrue();
+ }
+
+ @Test
+ public void updateAccessPoint_returnTrueForAccessPointUpdated() {
+ setUpForConnectedNetwork();
+
+ displayAndResume();
+
+ // change as disconnected
+ when(mockAccessPoint.update(mockWifiConfig, mockWifiInfo, mockNetworkInfo))
+ .thenReturn(true);
+ boolean changed = mController.updateAccessPoint();
+
+ assertThat(changed).isTrue();
+ }
+
+ @Test
public void testRefreshRssiViews_shouldNotUpdateIfLevelIsSameForConnectedNetwork() {
setUpForConnectedNetwork();
displayAndResume();