Update profile api am: 4f872ae7fc am: c9f417823f
Change-Id: I3d158f5b4439e4fe0692b9ba337c2dcbf49009c3
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 5ffbf9f..d64e27c 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -135,11 +135,6 @@
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
- <intent-filter android:priority="100">
- <action android:name="android.settings.LOCATION_SCANNING_SETTINGS" />
- <category android:name="android.intent.category.DEFAULT"/>
- </intent-filter>
-
<intent-filter android:priority="1">
<action android:name="android.settings.APPLICATION_SETTINGS" />
<action android:name="android.settings.MANAGE_APPLICATIONS_SETTINGS" />
diff --git a/res/layout/date_picker.xml b/res/layout/date_picker.xml
index 93529b9..960ae65 100644
--- a/res/layout/date_picker.xml
+++ b/res/layout/date_picker.xml
@@ -29,6 +29,7 @@
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:datePickerMode="spinner"
+ android:calendarViewShown="false"
android:scaleX="1.6"
android:scaleY="1.6"/>
diff --git a/res/values/preference_keys.xml b/res/values/preference_keys.xml
index 8d97e87..491a562 100644
--- a/res/values/preference_keys.xml
+++ b/res/values/preference_keys.xml
@@ -283,10 +283,6 @@
</string>
<string name="pk_location_app_permissions" translatable="false">location_app_permissions
</string>
- <string name="pk_location_scanning" translatable="false">location_scanning</string>
- <string name="pk_location_scanning_wifi" translatable="false">location_scanning_wifi</string>
- <string name="pk_location_scanning_bluetooth" translatable="false">location_scanning_bluetooth
- </string>
<string name="pk_location_services" translatable="false">location_services</string>
<string name="pk_location_footer" translatable="false">location_footer</string>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a081584..1feb990 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -732,21 +732,9 @@
<string name="location_settings_recent_requests_empty_message">No recent location requests</string>
<!-- Title of Location App-level Permissions setting [CHAR LIMIT=60] -->
<string name="location_settings_app_permissions_title">App-level permissions</string>
- <!-- Title of Location Scanning setting [CHAR LIMIT=60] -->
- <string name="location_settings_scanning_title">Scanning</string>
<!-- Title of Location Services category [CHAR LIMIT=60] -->
<string name="location_settings_services_title">Location Services</string>
- <!-- Location Scanning --><skip/>
- <!-- Title of Wi-Fi scanning preference [CHAR LIMIT=60] -->
- <string name="location_settings_wifi_scanning_title">Wi\u2011Fi scanning</string>
- <!-- Summary of Wi-Fi scanning preference [CHAR LIMIT=240] -->
- <string name="location_settings_wifi_scanning_summary">Allow apps and services to 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.</string>
- <!-- Title of Bluetooth scanning preference [CHAT LIMIT=60]-->
- <string name="location_settings_bluetooth_scanning_title">Bluetooth scanning</string>
- <!-- Summary of Bluetooth scanning preference [CHAR LIMIT=240] -->
- <string name="location_settings_bluetooth_scanning_summary">Allow apps and services to scan for nearby devices at any time, even when Bluetooth is off. This can be used, for example, to improve location-based features and services.</string>
-
<!-- System --><skip/>
<!-- Main setting menu item to go into system settings -->
<string name="system_setting_title">System</string>
@@ -1435,7 +1423,7 @@
<string name="suggestion_dismiss_button">DISMISS</string>
<!-- Warn user that the action they are trying to perform is blocked while the car is in motion [CHAR LIMIT=60] -->
- <string name="restricted_while_driving">Feature not available while driving.</string>
+ <string name="restricted_while_driving">Feature not available while driving</string>
<!-- Warn user that adding a user is blocked while the car is in motion [CHAR LIMIT=60] -->
- <string name="add_user_restricted_while_driving">Can\'t add user while driving.</string>
+ <string name="add_user_restricted_while_driving">Can\'t add user while driving</string>
</resources>
diff --git a/res/xml/location_scanning_fragment.xml b/res/xml/location_scanning_fragment.xml
deleted file mode 100644
index f71f246..0000000
--- a/res/xml/location_scanning_fragment.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright 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.
--->
-
-<PreferenceScreen
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto"
- android:title="@string/location_settings_scanning_title">
- <SwitchPreference
- android:key="@string/pk_location_scanning_wifi"
- android:summary="@string/location_settings_wifi_scanning_summary"
- android:title="@string/location_settings_wifi_scanning_title"
- settings:controller="com.android.car.settings.location.WifiScanningPreferenceController"/>
- <SwitchPreference
- android:key="@string/pk_location_scanning_bluetooth"
- android:summary="@string/location_settings_bluetooth_scanning_summary"
- android:title="@string/location_settings_bluetooth_scanning_title"
- settings:controller="com.android.car.settings.location.BluetoothScanningPreferenceController"/>
-</PreferenceScreen>
diff --git a/res/xml/location_settings_fragment.xml b/res/xml/location_settings_fragment.xml
index 4f1b57c..3f3d121 100644
--- a/res/xml/location_settings_fragment.xml
+++ b/res/xml/location_settings_fragment.xml
@@ -33,11 +33,6 @@
android:value="android.permission-group.LOCATION"/>
</intent>
</Preference>
- <Preference
- android:fragment="com.android.car.settings.location.LocationScanningFragment"
- android:key="@string/pk_location_scanning"
- android:title="@string/location_settings_scanning_title"
- settings:controller="com.android.car.settings.location.LocationScanningPreferenceController"/>
<PreferenceCategory
android:key="@string/pk_location_services"
android:title="@string/location_settings_services_title"
diff --git a/src/com/android/car/settings/FallbackHome.java b/src/com/android/car/settings/FallbackHome.java
index 2804333..c7067e9 100644
--- a/src/com/android/car/settings/FallbackHome.java
+++ b/src/com/android/car/settings/FallbackHome.java
@@ -16,13 +16,14 @@
package com.android.car.settings;
+import static android.car.settings.CarSettings.Global.ENABLE_USER_SWITCH_DEVELOPER_MESSAGE;
+
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ResolveInfo;
-import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -82,8 +83,8 @@
} else {
flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
- // TODO: read from developer settings instead, so it can be used on user builds
- showInfo = Build.IS_DEBUGGABLE;
+ showInfo = "true".equals(Settings.Global.getString(getContentResolver(),
+ ENABLE_USER_SWITCH_DEVELOPER_MESSAGE));
}
if (showInfo) {
diff --git a/src/com/android/car/settings/common/FragmentResolver.java b/src/com/android/car/settings/common/FragmentResolver.java
index 8e29f2d..594d94f 100644
--- a/src/com/android/car/settings/common/FragmentResolver.java
+++ b/src/com/android/car/settings/common/FragmentResolver.java
@@ -42,7 +42,6 @@
import com.android.car.settings.home.HomepageFragment;
import com.android.car.settings.inputmethod.KeyboardFragment;
import com.android.car.settings.language.LanguagePickerFragment;
-import com.android.car.settings.location.LocationScanningFragment;
import com.android.car.settings.network.MobileNetworkFragment;
import com.android.car.settings.network.NetworkAndInternetFragment;
import com.android.car.settings.quicksettings.QuickSettingFragment;
@@ -116,9 +115,6 @@
case Settings.ACTION_BLUETOOTH_SETTINGS:
return new BluetoothSettingsFragment();
- case Settings.ACTION_LOCATION_SCANNING_SETTINGS:
- return new LocationScanningFragment();
-
case Settings.ACTION_APPLICATION_SETTINGS:
case Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS:
case Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS:
diff --git a/src/com/android/car/settings/location/BluetoothScanningPreferenceController.java b/src/com/android/car/settings/location/BluetoothScanningPreferenceController.java
deleted file mode 100644
index 1427bfd..0000000
--- a/src/com/android/car/settings/location/BluetoothScanningPreferenceController.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.settings.location;
-
-import android.car.drivingstate.CarUxRestrictions;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.provider.Settings;
-
-import androidx.preference.TwoStatePreference;
-
-import com.android.car.settings.common.FragmentController;
-import com.android.car.settings.common.PreferenceController;
-
-/**
- * Handles Bluetooth location scanning settings.
- */
-public class BluetoothScanningPreferenceController extends
- PreferenceController<TwoStatePreference> {
-
- public BluetoothScanningPreferenceController(Context context, String preferenceKey,
- FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
- super(context, preferenceKey, fragmentController, uxRestrictions);
- }
-
- @Override
- protected Class<TwoStatePreference> getPreferenceType() {
- return TwoStatePreference.class;
- }
-
- @Override
- protected int getAvailabilityStatus() {
- return getContext().getPackageManager().hasSystemFeature(
- PackageManager.FEATURE_BLUETOOTH_LE) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
- }
-
- @Override
- protected void updateState(TwoStatePreference preference) {
- preference.setChecked(Settings.Global.getInt(getContext().getContentResolver(),
- Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0) == 1);
- }
-
- @Override
- protected boolean handlePreferenceChanged(TwoStatePreference preference, Object newValue) {
- boolean isBluetoothScanningEnabled = (boolean) newValue;
- Settings.Global.putInt(getContext().getContentResolver(),
- Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, isBluetoothScanningEnabled ? 1 : 0);
- return true;
- }
-}
diff --git a/src/com/android/car/settings/location/LocationScanningFragment.java b/src/com/android/car/settings/location/LocationScanningFragment.java
deleted file mode 100644
index 7b7fa5d..0000000
--- a/src/com/android/car/settings/location/LocationScanningFragment.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.settings.location;
-
-import androidx.annotation.XmlRes;
-
-import com.android.car.settings.R;
-import com.android.car.settings.common.SettingsFragment;
-
-/**
- * Fragment that hosts Location Scanning settings.
- */
-public class LocationScanningFragment extends SettingsFragment {
-
- @Override
- @XmlRes
- protected int getPreferenceScreenResId() {
- return R.xml.location_scanning_fragment;
- }
-}
diff --git a/src/com/android/car/settings/location/LocationScanningPreferenceController.java b/src/com/android/car/settings/location/LocationScanningPreferenceController.java
deleted file mode 100644
index 9b7a259..0000000
--- a/src/com/android/car/settings/location/LocationScanningPreferenceController.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.settings.location;
-
-import android.car.drivingstate.CarUxRestrictions;
-import android.content.Context;
-import android.content.pm.PackageManager;
-
-import androidx.preference.Preference;
-
-import com.android.car.settings.common.FragmentController;
-import com.android.car.settings.common.PreferenceController;
-
-/**
- * Hides the Scanning entry if neither Wi-Fi nor Bluetooth are supported.
- */
-public class LocationScanningPreferenceController extends PreferenceController<Preference> {
-
- public LocationScanningPreferenceController(Context context, String preferenceKey,
- FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
- super(context, preferenceKey, fragmentController, uxRestrictions);
- }
-
- @Override
- protected Class<Preference> getPreferenceType() {
- return Preference.class;
- }
-
- @Override
- public int getAvailabilityStatus() {
- PackageManager packageManager = getContext().getPackageManager();
- return (packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI)
- || packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE))
- ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
- }
-}
diff --git a/src/com/android/car/settings/location/WifiScanningPreferenceController.java b/src/com/android/car/settings/location/WifiScanningPreferenceController.java
deleted file mode 100644
index 6a8031a..0000000
--- a/src/com/android/car/settings/location/WifiScanningPreferenceController.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.settings.location;
-
-import android.car.drivingstate.CarUxRestrictions;
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.provider.Settings;
-
-import androidx.preference.TwoStatePreference;
-
-import com.android.car.settings.common.FragmentController;
-import com.android.car.settings.common.PreferenceController;
-
-/**
- * Handles Wi-Fi location scanning settings.
- */
-public class WifiScanningPreferenceController extends PreferenceController<TwoStatePreference> {
-
- public WifiScanningPreferenceController(Context context, String preferenceKey,
- FragmentController fragmentController, CarUxRestrictions uxRestrictions) {
- super(context, preferenceKey, fragmentController, uxRestrictions);
- }
-
- @Override
- protected Class<TwoStatePreference> getPreferenceType() {
- return TwoStatePreference.class;
- }
-
- @Override
- protected int getAvailabilityStatus() {
- return getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_WIFI)
- ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
- }
-
- @Override
- protected void updateState(TwoStatePreference preference) {
- preference.setChecked(Settings.Global.getInt(getContext().getContentResolver(),
- Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0) == 1);
- }
-
- @Override
- protected boolean handlePreferenceChanged(TwoStatePreference preference, Object newValue) {
- boolean isWifiScanningEnabled = (boolean) newValue;
- Settings.Global.putInt(getContext().getContentResolver(),
- Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, isWifiScanningEnabled ? 1 : 0);
- return true;
- }
-}
diff --git a/tests/robotests/src/com/android/car/settings/bluetooth/BluetoothSettingsFragmentTest.java b/tests/robotests/src/com/android/car/settings/bluetooth/BluetoothSettingsFragmentTest.java
index 1438d87..fd19141 100644
--- a/tests/robotests/src/com/android/car/settings/bluetooth/BluetoothSettingsFragmentTest.java
+++ b/tests/robotests/src/com/android/car/settings/bluetooth/BluetoothSettingsFragmentTest.java
@@ -48,6 +48,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
@@ -237,6 +238,8 @@
Intent intent = new Intent(BluetoothAdapter.ACTION_STATE_CHANGED);
intent.putExtra(BluetoothAdapter.EXTRA_STATE, state);
mContext.sendBroadcast(intent);
+
+ Robolectric.flushForegroundThreadScheduler();
}
private MenuItem findSwitch(Activity activity) {
diff --git a/tests/robotests/src/com/android/car/settings/location/BluetoothScanningPreferenceControllerTest.java b/tests/robotests/src/com/android/car/settings/location/BluetoothScanningPreferenceControllerTest.java
deleted file mode 100644
index abb822b..0000000
--- a/tests/robotests/src/com/android/car/settings/location/BluetoothScanningPreferenceControllerTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.car.settings.location;
-
-import static com.android.car.settings.common.PreferenceController.AVAILABLE;
-import static com.android.car.settings.common.PreferenceController.UNSUPPORTED_ON_DEVICE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.provider.Settings;
-
-import androidx.lifecycle.Lifecycle;
-import androidx.preference.SwitchPreference;
-
-import com.android.car.settings.CarSettingsRobolectricTestRunner;
-import com.android.car.settings.common.PreferenceControllerTestHelper;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
-
-@RunWith(CarSettingsRobolectricTestRunner.class)
-public class BluetoothScanningPreferenceControllerTest {
-
- private Context mContext;
- private SwitchPreference mPreference;
- private BluetoothScanningPreferenceController mController;
-
- @Before
- public void setUp() {
- mContext = RuntimeEnvironment.application;
- mPreference = new SwitchPreference(mContext);
- PreferenceControllerTestHelper<BluetoothScanningPreferenceController> controllerHelper =
- new PreferenceControllerTestHelper<>(mContext,
- BluetoothScanningPreferenceController.class, mPreference);
- mController = controllerHelper.getController();
- Shadows.shadowOf(mContext.getPackageManager()).setSystemFeature(
- PackageManager.FEATURE_BLUETOOTH_LE, /* supported= */ true);
- controllerHelper.sendLifecycleEvent(Lifecycle.Event.ON_CREATE);
- }
-
- @Test
- public void getAvailabilityStatus_hasBluetoothFeature_available() {
- Shadows.shadowOf(mContext.getPackageManager()).setSystemFeature(
- PackageManager.FEATURE_BLUETOOTH_LE, /* supported= */ true);
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_noBluetoothFeature_unsupported() {
- Shadows.shadowOf(mContext.getPackageManager()).setSystemFeature(
- PackageManager.FEATURE_BLUETOOTH_LE, /* supported= */ false);
- assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
- }
-
- @Test
- public void refreshUi_bluetoothScanningEnabled_shouldCheckPreference() {
- mPreference.setChecked(false);
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1);
- mController.refreshUi();
-
- assertThat(mPreference.isChecked()).isTrue();
- }
-
- @Test
- public void refreshUi_bluetoothScanningDisabled_shouldUncheckPreference() {
- mPreference.setChecked(true);
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0);
- mController.refreshUi();
-
- assertThat(mPreference.isChecked()).isFalse();
- }
-
- @Test
- public void handlePreferenceChanged_preferenceChecked_shouldEnableBluetoothScanning() {
- mPreference.callChangeListener(true);
-
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 0)).isEqualTo(1);
- }
-
- @Test
- public void handlePreferenceChanged_preferenceUnchecked_shouldDisableBluetoothScanning() {
- mPreference.callChangeListener(false);
-
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.BLE_SCAN_ALWAYS_AVAILABLE, 1)).isEqualTo(0);
- }
-}
diff --git a/tests/robotests/src/com/android/car/settings/location/LocationScanningPreferenceControllerTest.java b/tests/robotests/src/com/android/car/settings/location/LocationScanningPreferenceControllerTest.java
deleted file mode 100644
index 15a9716..0000000
--- a/tests/robotests/src/com/android/car/settings/location/LocationScanningPreferenceControllerTest.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.car.settings.location;
-
-import static com.android.car.settings.common.PreferenceController.AVAILABLE;
-import static com.android.car.settings.common.PreferenceController.UNSUPPORTED_ON_DEVICE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-
-import androidx.lifecycle.Lifecycle;
-import androidx.preference.Preference;
-
-import com.android.car.settings.CarSettingsRobolectricTestRunner;
-import com.android.car.settings.common.PreferenceControllerTestHelper;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
-import org.robolectric.shadows.ShadowPackageManager;
-
-@RunWith(CarSettingsRobolectricTestRunner.class)
-public class LocationScanningPreferenceControllerTest {
-
- private ShadowPackageManager mShadowPackageManager;
- private LocationScanningPreferenceController mController;
-
- @Before
- public void setUp() {
- Context context = RuntimeEnvironment.application;
- PreferenceControllerTestHelper<LocationScanningPreferenceController> controllerHelper =
- new PreferenceControllerTestHelper<>(context,
- LocationScanningPreferenceController.class, new Preference(context));
- mController = controllerHelper.getController();
- controllerHelper.sendLifecycleEvent(Lifecycle.Event.ON_CREATE);
- mShadowPackageManager = Shadows.shadowOf(context.getPackageManager());
- }
-
- @Test
- public void getAvailabilityStatus_available_wifiOrBluetooth() {
- mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_WIFI, /* supported= */ true);
- mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE,
- /* supported= */ false);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
-
- mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_WIFI, /* supported= */ false);
- mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE,
- /* supported= */ true);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_notAvailable_noWifiNoBluetooth() {
- mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_WIFI, /* supported= */ false);
- mShadowPackageManager.setSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE,
- /* supported= */ false);
-
- assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
- }
-}
diff --git a/tests/robotests/src/com/android/car/settings/location/WifiScanningPreferenceControllerTest.java b/tests/robotests/src/com/android/car/settings/location/WifiScanningPreferenceControllerTest.java
deleted file mode 100644
index b97887d..0000000
--- a/tests/robotests/src/com/android/car/settings/location/WifiScanningPreferenceControllerTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.car.settings.location;
-
-import static com.android.car.settings.common.PreferenceController.AVAILABLE;
-import static com.android.car.settings.common.PreferenceController.UNSUPPORTED_ON_DEVICE;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.provider.Settings;
-
-import androidx.lifecycle.Lifecycle;
-import androidx.preference.SwitchPreference;
-
-import com.android.car.settings.CarSettingsRobolectricTestRunner;
-import com.android.car.settings.common.PreferenceControllerTestHelper;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.RuntimeEnvironment;
-import org.robolectric.Shadows;
-
-@RunWith(CarSettingsRobolectricTestRunner.class)
-public class WifiScanningPreferenceControllerTest {
-
- private Context mContext;
- private SwitchPreference mPreference;
- private WifiScanningPreferenceController mController;
-
- @Before
- public void setUp() {
- mContext = RuntimeEnvironment.application;
- mPreference = new SwitchPreference(mContext);
- PreferenceControllerTestHelper<WifiScanningPreferenceController> controllerHelper =
- new PreferenceControllerTestHelper<>(mContext,
- WifiScanningPreferenceController.class, mPreference);
- mController = controllerHelper.getController();
- Shadows.shadowOf(mContext.getPackageManager()).setSystemFeature(
- PackageManager.FEATURE_WIFI, /* supported= */ true);
- controllerHelper.sendLifecycleEvent(Lifecycle.Event.ON_CREATE);
- }
-
- @Test
- public void getAvailabilityStatus_hasWifiFeature_available() {
- Shadows.shadowOf(mContext.getPackageManager()).setSystemFeature(
- PackageManager.FEATURE_WIFI, /* supported= */ true);
- assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
- }
-
- @Test
- public void getAvailabilityStatus_noWifiFeature_unsupported() {
- Shadows.shadowOf(mContext.getPackageManager()).setSystemFeature(
- PackageManager.FEATURE_WIFI, /* supported= */ false);
- assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
- }
-
- @Test
- public void refreshUi_wifiScanningEnabled_shouldCheckPreference() {
- mPreference.setChecked(false);
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1);
- mController.refreshUi();
-
- assertThat(mPreference.isChecked()).isTrue();
- }
-
- @Test
- public void refreshUi_wifiScanningDisabled_shouldUncheckPreference() {
- mPreference.setChecked(true);
- Settings.Global.putInt(mContext.getContentResolver(),
- Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0);
- mController.refreshUi();
-
- assertThat(mPreference.isChecked()).isFalse();
- }
-
- @Test
- public void handlePreferenceChanged_preferenceChecked_shouldEnableWifiScanning() {
- mPreference.callChangeListener(true);
-
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 0)).isEqualTo(1);
- }
-
- @Test
- public void handlePreferenceChanged_preferenceUnchecked_shouldDisableWifiScanning() {
- mPreference.callChangeListener(false);
-
- assertThat(Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.WIFI_SCAN_ALWAYS_AVAILABLE, 1)).isEqualTo(0);
- }
-}
diff --git a/tests/robotests/src/com/android/car/settings/wifi/AddWifiFragmentTest.java b/tests/robotests/src/com/android/car/settings/wifi/AddWifiFragmentTest.java
index a0bc881..7ea6296 100644
--- a/tests/robotests/src/com/android/car/settings/wifi/AddWifiFragmentTest.java
+++ b/tests/robotests/src/com/android/car/settings/wifi/AddWifiFragmentTest.java
@@ -36,6 +36,7 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@@ -122,6 +123,8 @@
intent.putExtra(NetworkNamePreferenceController.KEY_NETWORK_NAME, networkName);
mLocalBroadcastManager.sendBroadcastSync(intent);
+ Robolectric.flushForegroundThreadScheduler();
+
assertThat(getAddWifiButton().isEnabled()).isTrue();
}
diff --git a/tests/robotests/src/com/android/car/settings/wifi/WifiTetherFragmentTest.java b/tests/robotests/src/com/android/car/settings/wifi/WifiTetherFragmentTest.java
index ed3e706..bbe5cf6 100644
--- a/tests/robotests/src/com/android/car/settings/wifi/WifiTetherFragmentTest.java
+++ b/tests/robotests/src/com/android/car/settings/wifi/WifiTetherFragmentTest.java
@@ -40,6 +40,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import org.robolectric.shadow.api.Shadow;
@@ -122,9 +123,7 @@
ShadowCarWifiManager.setInstance(mCarWifiManager);
mFragmentController.setup();
- Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
- intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_ENABLING);
- mContext.sendBroadcast(intent);
+ sendStateChangedIntent(WifiManager.WIFI_AP_STATE_ENABLING);
assertThat(findSwitch(mFragment.requireActivity()).isEnabled()).isFalse();
}
@@ -135,9 +134,7 @@
ShadowCarWifiManager.setInstance(mCarWifiManager);
mFragmentController.setup();
- Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
- intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_ENABLED);
- mContext.sendBroadcast(intent);
+ sendStateChangedIntent(WifiManager.WIFI_AP_STATE_ENABLED);
assertThat(findSwitch(mFragment.requireActivity()).isEnabled()).isTrue();
assertThat(findSwitch(mFragment.requireActivity()).isChecked()).isTrue();
@@ -149,9 +146,7 @@
ShadowCarWifiManager.setInstance(mCarWifiManager);
mFragmentController.setup();
- Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
- intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_DISABLED);
- mContext.sendBroadcast(intent);
+ sendStateChangedIntent(WifiManager.WIFI_AP_STATE_DISABLED);
assertThat(findSwitch(mFragment.requireActivity()).isEnabled()).isTrue();
assertThat(findSwitch(mFragment.requireActivity()).isChecked()).isFalse();
@@ -163,18 +158,22 @@
ShadowCarWifiManager.setInstance(mCarWifiManager);
mFragmentController.setup();
- Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
- intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_ENABLING);
- mContext.sendBroadcast(intent);
+ sendStateChangedIntent(WifiManager.WIFI_AP_STATE_ENABLING);
- Intent intent2 = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
- intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, WifiManager.WIFI_AP_STATE_FAILED);
- mContext.sendBroadcast(intent2);
+ sendStateChangedIntent(WifiManager.WIFI_AP_STATE_FAILED);
assertThat(findSwitch(mFragment.requireActivity()).isEnabled()).isTrue();
assertThat(findSwitch(mFragment.requireActivity()).isChecked()).isFalse();
}
+ private void sendStateChangedIntent(int state) {
+ Intent intent = new Intent(WifiManager.WIFI_AP_STATE_CHANGED_ACTION);
+ intent.putExtra(WifiManager.EXTRA_WIFI_AP_STATE, state);
+ mContext.sendBroadcast(intent);
+
+ Robolectric.flushForegroundThreadScheduler();
+ }
+
private MenuItem findSwitch(Activity activity) {
Toolbar toolbar = activity.requireViewById(R.id.toolbar);
return toolbar.getMenuItems().get(0);