Merge "[Settings] Refactor Wifi Calling description text" am: 078f873ccc am: 54e4845d54
Original change: https://android-review.googlesource.com/c/platform/packages/apps/Settings/+/1904791
Change-Id: Icba1cb39911ec1e06b3952117e95ccf03630aeae
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index b9d62f3..201762b 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1421,6 +1421,23 @@
</activity>
<activity
+ android:name="Settings$WifiScanningSettingsActivity"
+ android:label="@string/location_scanning_wifi_always_scanning_title"
+ android:icon="@drawable/ic_homepage_location"
+ android:exported="true"
+ android:permission="android.permission.CHANGE_WIFI_STATE"
+ android:configChanges="orientation|keyboardHidden|screenSize">
+ <intent-filter android:priority="1">
+ <action android:name="android.settings.WIFI_SCANNING_SETTINGS" />
+ <category android:name="android.intent.category.DEFAULT" />
+ </intent-filter>
+ <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
+ android:value="com.android.settings.location.WifiScanningFragment" />
+ <meta-data android:name="com.android.settings.PRIMARY_PROFILE_CONTROLLED"
+ android:value="true" />
+ </activity>
+
+ <activity
android:name=".Settings$SecurityDashboardActivity"
android:label="@string/security_settings_title"
android:icon="@drawable/ic_homepage_security"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f6b0895..e01b309 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4823,7 +4823,7 @@
<!-- Manage applications, individual application screen, confirmation dialog title. Displays when user selects to "Clear data". -->
<string name="clear_data_dlg_title">Delete app data?</string>
<!-- Manage applications, individual application screen, confirmation dialog message. Displays when user selects to "Clear data". It warns the user of the consequences of clearing the data for an app. -->
- <string name="clear_data_dlg_text">All this app\u2019s data will be deleted permanently. This includes all files, settings, accounts, databases, etc.</string>
+ <string name="clear_data_dlg_text">This app\u2019s data will be permanently deleted. This includes files, settings, databases, and other app data.</string>
<!-- Manage applications, individual application screen, confirmation dialog button. Displays when user selects to "Clear data". Goes through with the clearing of the data. -->
<string name="dlg_ok">OK</string>
<!-- Manage applications, individual application screen, confirmation dialog button. Displays when user selects to "Clear data". -->
@@ -6337,8 +6337,8 @@
<string name="power_wifi">Wi\u2011Fi</string>
<!-- Label for power consumed by Bluetooth -->
<string name="power_bluetooth">Bluetooth</string>
- <!-- Label for power consumed by Mobile network idle -->
- <string name="power_cell">Mobile network standby</string>
+ <!-- Label for power consumed by Mobile network -->
+ <string name="power_cell">Mobile network</string>
<!-- Label for power consumed by Calling -->
<string name="power_phone">Voice calls</string>
<!-- Label for power consumed when Idle -->
@@ -13410,6 +13410,9 @@
<string name="default_active_sim_sms">SMS</string>
<!-- Provider Model: summary of default mobile data. [CHAR LIMIT=50] -->
<string name="default_active_sim_mobile_data">mobile data</string>
+ <!-- Provider Model: Message to describe "Wi-Fi scan always available feature" when Wi-Fi is off and Wi-Fi
+ scanning is on. To mark a link to bring the user to "scanning settings" screen. [CHAR LIMIT=NONE]-->
+ <string name="wifi_scan_notify_message">To improve device experience, apps and services can still scan for Wi\u2011Fi networks at any time, even when Wi\u2011Fi is off. This can be used, for example, to improve location-based features and services. You can change this in Wi\u2011Fi scanning settings. <annotation id="link">Change</annotation></string>
<!-- Summary text separator for preferences including a short description
(eg. "Connected / 5G"). [CHAR LIMIT=50] -->
diff --git a/res/xml/network_provider_settings.xml b/res/xml/network_provider_settings.xml
index 9cab924..2d211b5 100644
--- a/res/xml/network_provider_settings.xml
+++ b/res/xml/network_provider_settings.xml
@@ -81,4 +81,10 @@
<com.android.settings.datausage.DataUsagePreference
android:key="non_carrier_data_usage"
android:title="@string/non_carrier_data_usage"/>
+
+ <com.android.settingslib.widget.FooterPreference
+ android:key="wifi_status_message_footer"
+ android:selectable="false"
+ settings:allowDividerAbove="false"
+ settings:searchable="false"/>
</PreferenceScreen>
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index cb2cde4..da988f8 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -166,6 +166,7 @@
public static class AppUsageAccessSettingsActivity extends SettingsActivity { /* empty */ }
public static class LocationSettingsActivity extends SettingsActivity { /* empty */ }
public static class ScanningSettingsActivity extends SettingsActivity { /* empty */ }
+ public static class WifiScanningSettingsActivity extends SettingsActivity { /* empty */ }
public static class PrivacyDashboardActivity extends SettingsActivity { /* empty */ }
public static class PrivacySettingsActivity extends SettingsActivity { /* empty */ }
public static class FactoryResetActivity extends SettingsActivity {
diff --git a/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
index 8509ca0..bcd47bc 100644
--- a/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/AdvancedConnectedDeviceDashboardFragment.java
@@ -26,6 +26,7 @@
import com.android.settings.nfc.AndroidBeamPreferenceController;
import com.android.settings.print.PrintSettingPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.uwb.UwbPreferenceController;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
@@ -43,6 +44,7 @@
private static final String TAG = "AdvancedConnectedDeviceFrag";
static final String KEY_BLUETOOTH = "bluetooth_settings";
+ static final String KEY_UWB = "uwb_settings";
@Override
public int getMetricsCategory() {
@@ -65,6 +67,15 @@
}
@Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+ UwbPreferenceController uwbPreferenceController = use(UwbPreferenceController.class);
+ if (uwbPreferenceController != null && getSettingsLifecycle() != null) {
+ getSettingsLifecycle().addObserver(uwbPreferenceController);
+ }
+ }
+
+ @Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildControllers(context, getSettingsLifecycle());
}
diff --git a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
index ce980e0..c8eb488 100644
--- a/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
+++ b/src/com/android/settings/connecteddevice/ConnectedDeviceDashboardFragment.java
@@ -19,12 +19,15 @@
import android.content.Context;
import android.net.Uri;
import android.provider.DeviceConfig;
+import android.text.TextUtils;
+import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.core.SettingsUIDeviceConfig;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.password.PasswordUtils;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.slices.SlicePreferenceController;
import com.android.settingslib.search.SearchIndexable;
@@ -33,6 +36,9 @@
public class ConnectedDeviceDashboardFragment extends DashboardFragment {
private static final String TAG = "ConnectedDeviceFrag";
+ private static final String SETTINGS_PACKAGE_NAME = "com.android.settings";
+ private static final String SYSTEMUI_PACKAGE_NAME = "com.android.systemui";
+ private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@VisibleForTesting
static final String KEY_CONNECTED_DEVICES = "connected_device_list";
@@ -64,12 +70,20 @@
super.onAttach(context);
final boolean nearbyEnabled = DeviceConfig.getBoolean(DeviceConfig.NAMESPACE_SETTINGS_UI,
SettingsUIDeviceConfig.BT_NEAR_BY_SUGGESTION_ENABLED, true);
+ String callingAppPackageName = PasswordUtils.getCallingAppPackageName(
+ getActivity().getActivityToken());
+ if (DEBUG) {
+ Log.d(TAG, "onAttach() calling package name is : " + callingAppPackageName);
+ }
use(AvailableMediaDeviceGroupController.class).init(this);
use(ConnectedDeviceGroupController.class).init(this);
use(PreviouslyConnectedDevicePreferenceController.class).init(this);
use(SlicePreferenceController.class).setSliceUri(nearbyEnabled
? Uri.parse(getString(R.string.config_nearby_devices_slice_uri))
: null);
+ use(DiscoverableFooterPreferenceController.class).setAlwaysDiscoverable(
+ TextUtils.equals(SETTINGS_PACKAGE_NAME, callingAppPackageName)
+ || TextUtils.equals(SYSTEMUI_PACKAGE_NAME, callingAppPackageName));
}
/**
diff --git a/src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceController.java b/src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceController.java
index 91368bf..5df31bc 100644
--- a/src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceController.java
+++ b/src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceController.java
@@ -52,6 +52,7 @@
private BluetoothAdapter mBluetoothAdapter;
private AlwaysDiscoverable mAlwaysDiscoverable;
private FooterPreference mPreference;
+ private boolean mIsAlwaysDiscoverable;
public DiscoverableFooterPreferenceController(Context context, String key) {
super(context, key);
@@ -84,7 +85,9 @@
}
mContext.registerReceiver(mBluetoothChangedReceiver,
new IntentFilter(BluetoothAdapter.ACTION_STATE_CHANGED));
- mAlwaysDiscoverable.start();
+ if (mIsAlwaysDiscoverable) {
+ mAlwaysDiscoverable.start();
+ }
updateFooterPreferenceTitle(mBluetoothAdapter.getState());
}
@@ -94,7 +97,19 @@
return;
}
mContext.unregisterReceiver(mBluetoothChangedReceiver);
- mAlwaysDiscoverable.stop();
+ if (mIsAlwaysDiscoverable) {
+ mAlwaysDiscoverable.stop();
+ }
+ }
+
+ /**
+ * Set whether the device can be discovered. By default the value will be {@code false}.
+ *
+ * @param isAlwaysDiscoverable {@code true} if the device can be discovered,
+ * otherwise {@code false}
+ */
+ public void setAlwaysDiscoverable(boolean isAlwaysDiscoverable) {
+ mIsAlwaysDiscoverable = isAlwaysDiscoverable;
}
private void updateFooterPreferenceTitle(int bluetoothState) {
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 6d7626c..70852fe 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -113,6 +113,7 @@
import com.android.settings.localepicker.LocaleListEditor;
import com.android.settings.location.LocationServices;
import com.android.settings.location.LocationSettings;
+import com.android.settings.location.WifiScanningFragment;
import com.android.settings.network.MobileNetworkListFragment;
import com.android.settings.network.NetworkDashboardFragment;
import com.android.settings.network.NetworkProviderSettings;
@@ -202,6 +203,7 @@
ProcessStatsUi.class.getName(),
NotificationStation.class.getName(),
LocationSettings.class.getName(),
+ WifiScanningFragment.class.getName(),
PrivacyDashboardFragment.class.getName(),
LocationServices.class.getName(),
SecuritySettings.class.getName(),
diff --git a/src/com/android/settings/network/EraseEuiccDataDialogFragment.java b/src/com/android/settings/network/EraseEuiccDataDialogFragment.java
index 819d3b1..2c3847c 100644
--- a/src/com/android/settings/network/EraseEuiccDataDialogFragment.java
+++ b/src/com/android/settings/network/EraseEuiccDataDialogFragment.java
@@ -19,6 +19,7 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.settings.SettingsEnums;
+import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -75,23 +76,24 @@
}
if (which == DialogInterface.BUTTON_POSITIVE) {
- if (ConfirmationSimDeletionPredicate.getSingleton().test(getContext())) {
+ Context context = getContext();
+ if (ConfirmationSimDeletionPredicate.getSingleton().test(context)) {
// Create a "verify it's you" verification over keyguard
// when "erase" button been pressed.
// This might protect from erasing by some automation process.
- WifiDppUtils.showLockScreen(getContext(), () -> runAsyncWipe());
+ WifiDppUtils.showLockScreen(context, () -> runAsyncWipe(context));
} else {
- runAsyncWipe();
+ runAsyncWipe(context);
}
}
}
- private void runAsyncWipe() {
+ private void runAsyncWipe(Context context) {
AsyncTask.execute(new Runnable() {
@Override
public void run() {
RecoverySystem.wipeEuiccData(
- getContext(), PACKAGE_NAME_EUICC_DATA_MANAGEMENT_CALLBACK);
+ context, PACKAGE_NAME_EUICC_DATA_MANAGEMENT_CALLBACK);
}
});
}
diff --git a/src/com/android/settings/network/NetworkProviderSettings.java b/src/com/android/settings/network/NetworkProviderSettings.java
index 88211ad..fccd874 100644
--- a/src/com/android/settings/network/NetworkProviderSettings.java
+++ b/src/com/android/settings/network/NetworkProviderSettings.java
@@ -27,6 +27,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
+import android.location.LocationManager;
import android.net.NetworkTemplate;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
@@ -61,7 +62,9 @@
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.datausage.DataUsagePreference;
import com.android.settings.datausage.DataUsageUtils;
+import com.android.settings.location.WifiScanningFragment;
import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.utils.AnnotationSpan;
import com.android.settings.wifi.AddNetworkFragment;
import com.android.settings.wifi.AddWifiNetworkPreference;
import com.android.settings.wifi.ConfigureWifiEntryFragment;
@@ -79,6 +82,7 @@
import com.android.settingslib.search.Indexable;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.utils.ThreadUtils;
+import com.android.settingslib.widget.FooterPreference;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.wifi.LongPressWifiEntryPreference;
import com.android.settingslib.wifi.WifiSavedConfigUtils;
@@ -132,6 +136,7 @@
@VisibleForTesting
static final String PREF_KEY_DATA_USAGE = "non_carrier_data_usage";
private static final String PREF_KEY_RESET_INTERNET = "resetting_your_internet";
+ private static final String PREF_KEY_WIFI_STATUS_MESSAGE = "wifi_status_message_footer";
private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
@@ -231,6 +236,8 @@
LayoutPreference mResetInternetPreference;
@VisibleForTesting
ConnectedEthernetNetworkController mConnectedEthernetNetworkController;
+ @VisibleForTesting
+ FooterPreference mWifiStatusMessagePreference;
/**
* Mobile networks list for provider model
@@ -305,6 +312,7 @@
addNetworkMobileProviderController();
addConnectedEthernetNetworkController();
addWifiSwitchPreferenceController();
+ mWifiStatusMessagePreference = findPreference(PREF_KEY_WIFI_STATUS_MESSAGE);
}
private void updateAirplaneModeMsgPreference(boolean visible) {
@@ -717,6 +725,7 @@
switch (wifiState) {
case WifiManager.WIFI_STATE_ENABLED:
+ setWifiScanMessage(/* isWifiEnabled */ true);
updateWifiEntryPreferences();
break;
@@ -732,6 +741,7 @@
break;
case WifiManager.WIFI_STATE_DISABLED:
+ setWifiScanMessage(/* isWifiEnabled */ false);
removeConnectedWifiEntryPreference();
removeWifiEntryPreference();
setAdditionalSettingsSummaries();
@@ -741,6 +751,37 @@
}
}
+ @VisibleForTesting
+ void setWifiScanMessage(boolean isWifiEnabled) {
+ final Context context = getContext();
+ if (context == null) {
+ return;
+ }
+
+ final LocationManager locationManager = context.getSystemService(LocationManager.class);
+ if (isWifiEnabled || !locationManager.isLocationEnabled()
+ || !mWifiManager.isScanAlwaysAvailable()) {
+ mWifiStatusMessagePreference.setVisible(false);
+ return;
+ }
+ if (TextUtils.isEmpty(mWifiStatusMessagePreference.getTitle())) {
+ AnnotationSpan.LinkInfo info = new AnnotationSpan.LinkInfo(
+ AnnotationSpan.LinkInfo.DEFAULT_ANNOTATION,
+ v -> launchWifiScanningFragment());
+ CharSequence text = AnnotationSpan.linkify(
+ context.getText(R.string.wifi_scan_notify_message), info);
+ mWifiStatusMessagePreference.setTitle(text);
+ }
+ mWifiStatusMessagePreference.setVisible(true);
+ }
+
+ private void launchWifiScanningFragment() {
+ new SubSettingLauncher(getContext())
+ .setDestination(WifiScanningFragment.class.getName())
+ .setSourceMetricsCategory(SettingsEnums.SETTINGS_NETWORK_CATEGORY)
+ .launch();
+ }
+
@Override
public void onWifiEntriesChanged() {
if (mIsWifiEntryListStale) {
diff --git a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
index 8e65605..5f20894 100644
--- a/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
+++ b/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragment.java
@@ -25,7 +25,6 @@
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle;
-import android.telephony.ServiceState;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -52,7 +51,6 @@
import com.google.common.collect.ImmutableMap;
-import java.util.Arrays;
import java.util.List;
import java.util.Map;
@@ -180,8 +178,7 @@
final TextView operatorName = view.findViewById(R.id.operator_name_value);
mTelephonyManager = mTelephonyManager.createForSubscriptionId(mSubId);
- final ServiceState serviceState = mTelephonyManager.getServiceState();
- operatorName.setText(serviceState == null ? "" : serviceState.getOperatorAlphaLong());
+ operatorName.setText(info.getCarrierName());
final TextView phoneTitle = view.findViewById(R.id.number_label);
phoneTitle.setVisibility(info.isOpportunistic() ? View.GONE : View.VISIBLE);
diff --git a/src/com/android/settings/security/InstallCaCertificateWarning.java b/src/com/android/settings/security/InstallCaCertificateWarning.java
index 3854875..139bc1c 100644
--- a/src/com/android/settings/security/InstallCaCertificateWarning.java
+++ b/src/com/android/settings/security/InstallCaCertificateWarning.java
@@ -16,6 +16,8 @@
package com.android.settings.security;
+import static android.view.WindowManager.LayoutParams.SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS;
+
import android.annotation.Nullable;
import android.app.Activity;
import android.content.Intent;
@@ -45,6 +47,8 @@
setTheme(SetupWizardUtils.getTheme(this, getIntent()));
ThemeHelper.trySetDynamicColor(this);
setContentView(R.layout.ca_certificate_warning_dialog);
+ getWindow().addSystemFlags(SYSTEM_FLAG_HIDE_NON_SYSTEM_OVERLAY_WINDOWS);
+
final GlifLayout layout = findViewById(R.id.setup_wizard_layout);
layout.setHeaderText(R.string.ca_certificate_warning_title);
@@ -57,6 +61,7 @@
.setTheme(R.style.SudGlifButton_Secondary)
.build()
);
+ mixin.getSecondaryButtonView().setFilterTouchesWhenObscured(true);
mixin.setPrimaryButton(
new FooterButton.Builder(this)
@@ -66,6 +71,7 @@
.setTheme(R.style.SudGlifButton_Primary)
.build()
);
+ mixin.getPrimaryButtonView().setFilterTouchesWhenObscured(true);
}
private View.OnClickListener installCaCertificate() {
diff --git a/src/com/android/settings/uwb/UwbPreferenceController.java b/src/com/android/settings/uwb/UwbPreferenceController.java
index 877c9f2..8b330a9 100644
--- a/src/com/android/settings/uwb/UwbPreferenceController.java
+++ b/src/com/android/settings/uwb/UwbPreferenceController.java
@@ -24,6 +24,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
+import android.os.Handler;
import android.provider.Settings;
import android.uwb.UwbManager;
import android.uwb.UwbManager.AdapterStateCallback;
@@ -52,11 +53,13 @@
@VisibleForTesting
private final BroadcastReceiver mAirplaneModeChangedReceiver;
private final Executor mExecutor;
+ private final Handler mHandler;
private Preference mPreference;
public UwbPreferenceController(Context context, String key) {
super(context, key);
mExecutor = Executors.newSingleThreadExecutor();
+ mHandler = new Handler(context.getMainLooper());
if (isUwbSupportedOnDevice()) {
mUwbManager = context.getSystemService(UwbManager.class);
}
@@ -65,6 +68,8 @@
mAirplaneModeChangedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
+ mAirplaneModeOn = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.AIRPLANE_MODE_ON, 0) == 1;
updateState(mPreference);
}
};
@@ -114,6 +119,8 @@
@Override
public void onStateChanged(int state, int reason) {
+ Runnable runnable = () -> updateState(mPreference);
+ mHandler.post(runnable);
}
/** Called when activity starts being displayed to user. */
diff --git a/tests/robotests/src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceControllerTest.java
index 065b924..6510f19 100644
--- a/tests/robotests/src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/connecteddevice/DiscoverableFooterPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -104,7 +105,8 @@
}
@Test
- public void onStart_shouldRegisterBluetoothChanged() {
+ public void onStart_setAlwaysDiscoverableAsTrue_shouldRegisterBluetoothChanged() {
+ mDiscoverableFooterPreferenceController.setAlwaysDiscoverable(true);
mDiscoverableFooterPreferenceController.onStart();
assertThat(getRegisteredBroadcastReceivers()).contains(mBluetoothChangedReceiver);
@@ -112,7 +114,8 @@
}
@Test
- public void onStop_shouldUnregisterBluetoothChanged() {
+ public void onStop_setAlwaysDiscoverableAsTrue_shouldUnregisterBluetoothChanged() {
+ mDiscoverableFooterPreferenceController.setAlwaysDiscoverable(true);
mDiscoverableFooterPreferenceController.onStart();
mDiscoverableFooterPreferenceController.onStop();
@@ -121,6 +124,25 @@
}
@Test
+ public void onStart_setAlwaysDiscoverableAsFalse_shouldNotRegisterBluetoothChanged() {
+ mDiscoverableFooterPreferenceController.setAlwaysDiscoverable(false);
+ mDiscoverableFooterPreferenceController.onStart();
+
+ assertThat(getRegisteredBroadcastReceivers()).contains(mBluetoothChangedReceiver);
+ verify(mAlwaysDiscoverable, never()).start();
+ }
+
+ @Test
+ public void onStop_setAlwaysDiscoverableAsFalse_shouldNotUnregisterBluetoothChanged() {
+ mDiscoverableFooterPreferenceController.setAlwaysDiscoverable(false);
+ mDiscoverableFooterPreferenceController.onStart();
+ mDiscoverableFooterPreferenceController.onStop();
+
+ assertThat(getRegisteredBroadcastReceivers()).doesNotContain(mBluetoothChangedReceiver);
+ verify(mAlwaysDiscoverable, never()).stop();
+ }
+
+ @Test
public void onBluetoothStateChanged_bluetoothOn_updateTitle() {
BluetoothAdapter.getDefaultAdapter().setName(DEVICE_NAME);
sendBluetoothStateChangedIntent(BluetoothAdapter.STATE_ON);
diff --git a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
index 19b044b..be8bf3a 100644
--- a/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
+++ b/tests/robotests/src/com/android/settings/network/NetworkProviderSettingsTest.java
@@ -38,6 +38,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
+import android.location.LocationManager;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
@@ -67,6 +68,7 @@
import com.android.settings.wifi.ConnectedWifiEntryPreference;
import com.android.settings.wifi.WifiConfigController2;
import com.android.settings.wifi.WifiDialog2;
+import com.android.settingslib.widget.FooterPreference;
import com.android.settingslib.widget.LayoutPreference;
import com.android.settingslib.wifi.LongPressWifiEntryPreference;
import com.android.wifitrackerlib.WifiEntry;
@@ -97,6 +99,8 @@
@Mock
private UserManager mUserManager;
@Mock
+ private LocationManager mLocationManager;
+ @Mock
private AirplaneModeEnabler mAirplaneModeEnabler;
@Mock
private DataUsagePreference mDataUsagePreference;
@@ -132,6 +136,7 @@
doReturn(mPowerManager).when(mContext).getSystemService(PowerManager.class);
doReturn(mWifiManager).when(mContext).getSystemService(WifiManager.class);
doReturn(mUserManager).when(mContext).getSystemService(Context.USER_SERVICE);
+ doReturn(mLocationManager).when(mContext).getSystemService(LocationManager.class);
when(mUserManager.hasBaseUserRestriction(any(), any())).thenReturn(true);
doReturn(mContext).when(mPreferenceManager).getContext();
mNetworkProviderSettings.mAddWifiNetworkPreference = new AddWifiNetworkPreference(mContext);
@@ -144,6 +149,7 @@
mNetworkProviderSettings.mAirplaneModeMsgPreference = mAirplaneModeMsgPreference;
mNetworkProviderSettings.mAirplaneModeEnabler = mAirplaneModeEnabler;
mNetworkProviderSettings.mInternetUpdater = mInternetUpdater;
+ mNetworkProviderSettings.mWifiStatusMessagePreference = new FooterPreference(mContext);
doReturn(NetworkProviderSettings.PREF_KEY_CONNECTED_ACCESS_POINTS)
.when(mConnectedWifiEntryPreferenceCategory).getKey();
mNetworkProviderSettings.mConnectedWifiEntryPreferenceCategory =
@@ -532,6 +538,57 @@
}
@Test
+ public void setWifiScanMessage_wifiOnScanOn_footerIsInvisible() {
+ when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
+
+ mNetworkProviderSettings.setWifiScanMessage(/* isWifiEnabled */ true);
+
+ assertThat(mNetworkProviderSettings.mWifiStatusMessagePreference.isVisible()).isFalse();
+ }
+
+ @Test
+ public void setWifiScanMessage_wifiOffLocationOnScanOn_footerIsVisible() {
+ when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
+ when(mLocationManager.isLocationEnabled()).thenReturn(true);
+
+ mNetworkProviderSettings.setWifiScanMessage(/* isWifiEnabled */ false);
+
+ assertThat(mNetworkProviderSettings.mWifiStatusMessagePreference.isVisible()).isTrue();
+ assertThat(mNetworkProviderSettings.mWifiStatusMessagePreference.getTitle().length())
+ .isNotEqualTo(0);
+ }
+
+ @Test
+ public void setWifiScanMessage_wifiOffLocationOnScanOff_footerIsInvisible() {
+ when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
+ when(mLocationManager.isLocationEnabled()).thenReturn(true);
+
+ mNetworkProviderSettings.setWifiScanMessage(/* isWifiEnabled */ false);
+
+ assertThat(mNetworkProviderSettings.mWifiStatusMessagePreference.isVisible()).isFalse();
+ }
+
+ @Test
+ public void setWifiScanMessage_wifiOffLocationOffScanOn_footerIsInvisible() {
+ when(mWifiManager.isScanAlwaysAvailable()).thenReturn(true);
+ when(mLocationManager.isLocationEnabled()).thenReturn(false);
+
+ mNetworkProviderSettings.setWifiScanMessage(/* isWifiEnabled */ false);
+
+ assertThat(mNetworkProviderSettings.mWifiStatusMessagePreference.isVisible()).isFalse();
+ }
+
+ @Test
+ public void setWifiScanMessage_wifiOffLocationOffScanOff_footerIsInvisible() {
+ when(mWifiManager.isScanAlwaysAvailable()).thenReturn(false);
+ when(mLocationManager.isLocationEnabled()).thenReturn(false);
+
+ mNetworkProviderSettings.setWifiScanMessage(/* isWifiEnabled */ false);
+
+ assertThat(mNetworkProviderSettings.mWifiStatusMessagePreference.isVisible()).isFalse();
+ }
+
+ @Test
@Config(shadows = ShadowPreferenceFragmentCompat.class)
public void onStop_shouldRemoveCallbacks() {
View fragmentView = mock(View.class);
diff --git a/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
index 70b0598..ea440c7 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/RenameMobileNetworkDialogFragmentTest.java
@@ -31,7 +31,6 @@
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
-import android.telephony.ServiceState;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
@@ -73,8 +72,6 @@
@Mock
private TelephonyManager mTelephonyMgr;
@Mock
- private ServiceState mServiceState;
- @Mock
private SubscriptionManager mSubscriptionMgr;
@Mock
private SubscriptionInfo mSubscriptionInfo;
@@ -95,11 +92,9 @@
stm.setTelephonyManagerForSubscriptionId(mSubscriptionId, mTelephonyMgr);
when(mTelephonyMgr.createForSubscriptionId(anyInt())).thenReturn(mTelephonyMgr);
- when(mTelephonyMgr.getServiceState()).thenReturn(mServiceState);
- when(mServiceState.getOperatorAlphaLong()).thenReturn("fake carrier name");
-
when(mSubscriptionInfo.getSubscriptionId()).thenReturn(mSubscriptionId);
when(mSubscriptionInfo.getDisplayName()).thenReturn("test");
+ when(mSubscriptionInfo.getCarrierName()).thenReturn("fake carrier name");
when(mSubscriptionMgr.setDisplayName(any(), anyInt(), anyInt())).thenReturn(0);
mActivity = spy(Robolectric.buildActivity(FragmentActivity.class).setup().get());