Merge "Handle the IllegalStateException"
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 6724ff5..a5586f7 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -3009,6 +3009,7 @@
android:theme="@style/Theme.BottomDialog"
android:excludeFromRecents="true"
android:launchMode="singleTop"
+ android:taskAffinity=".panel.SettingsPanelActivity"
android:exported="true">
<intent-filter>
<action android:name="android.settings.panel.action.INTERNET_CONNECTIVITY" />
diff --git a/res/layout-land/panel_layout.xml b/res/layout-land/panel_layout.xml
index 3975bfe..049fd0b 100644
--- a/res/layout-land/panel_layout.xml
+++ b/res/layout-land/panel_layout.xml
@@ -20,7 +20,7 @@
android:orientation="vertical">
<TextView
- android:id="@+id/title"
+ android:id="@+id/panel_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
diff --git a/res/layout/dialog_firmware_version.xml b/res/layout/dialog_firmware_version.xml
deleted file mode 100644
index 1d5f531..0000000
--- a/res/layout/dialog_firmware_version.xml
+++ /dev/null
@@ -1,103 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2017 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<ScrollView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:padding="@dimen/sim_content_padding">
-
- <TextView
- style="@style/device_info_dialog_label"
- android:id="@+id/firmware_version_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/firmware_version"/>
- <TextView
- style="@style/device_info_dialog_value"
- android:id="@+id/firmware_version_value"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
-
- <TextView
- style="@style/device_info_dialog_label"
- android:id="@+id/security_patch_level_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/security_patch"/>
- <TextView
- style="@style/device_info_dialog_value"
- android:id="@+id/security_patch_level_value"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?android:attr/selectableItemBackground"
- android:textColor="?android:attr/colorAccent"/>
-
- <TextView
- style="@style/device_info_dialog_label"
- android:id="@+id/module_version_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/module_version"/>
- <TextView
- style="@style/device_info_dialog_value"
- android:id="@+id/module_version_value"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
-
- <TextView
- style="@style/device_info_dialog_label"
- android:id="@+id/baseband_version_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/baseband_version"/>
- <TextView
- style="@style/device_info_dialog_value"
- android:id="@+id/baseband_version_value"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
-
- <TextView
- style="@style/device_info_dialog_label"
- android:id="@+id/kernel_version_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/kernel_version"/>
- <TextView
- style="@style/device_info_dialog_value"
- android:id="@+id/kernel_version_value"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
-
- <TextView
- style="@style/device_info_dialog_label"
- android:id="@+id/build_number_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/build_number"/>
- <TextView
- style="@style/device_info_dialog_value"
- android:id="@+id/build_number_value"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"/>
-
- </LinearLayout>
-</ScrollView>
diff --git a/res/layout/dialog_hardware_info.xml b/res/layout/dialog_hardware_info.xml
deleted file mode 100644
index 7ea4783..0000000
--- a/res/layout/dialog_hardware_info.xml
+++ /dev/null
@@ -1,65 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2017 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
- -->
-
-<ScrollView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:padding="24dp">
-
- <TextView
- style="@style/device_info_dialog_label"
- android:id="@+id/model_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/model_info" />
- <TextView
- style="@style/device_info_dialog_value"
- android:id="@+id/model_value"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
-
- <TextView
- style="@style/device_info_dialog_label"
- android:id="@+id/serial_number_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/status_serial_number" />
- <TextView
- style="@style/device_info_dialog_value"
- android:id="@+id/serial_number_value"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
-
- <TextView
- style="@style/device_info_dialog_label"
- android:id="@+id/hardware_rev_label"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/hardware_revision" />
- <TextView
- style="@style/device_info_dialog_value"
- android:id="@+id/hardware_rev_value"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
-
- </LinearLayout>
-</ScrollView>
\ No newline at end of file
diff --git a/res/layout/settings_panel.xml b/res/layout/settings_panel.xml
index aec898c..3405ef0 100644
--- a/res/layout/settings_panel.xml
+++ b/res/layout/settings_panel.xml
@@ -16,4 +16,5 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_content"
android:layout_height="match_parent"
- android:layout_width="match_parent"/>
\ No newline at end of file
+ android:layout_width="match_parent"
+ android:animateLayoutChanges="true"/>
\ No newline at end of file
diff --git a/res/layout/wifi_button_preference_widget.xml b/res/layout/wifi_button_preference_widget.xml
index 55078c2..1ecb98c 100644
--- a/res/layout/wifi_button_preference_widget.xml
+++ b/res/layout/wifi_button_preference_widget.xml
@@ -19,6 +19,8 @@
android:id="@+id/button_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:minWidth="@dimen/min_tap_target_size"
+ android:minHeight="@dimen/min_tap_target_size"
android:layout_gravity="center"
android:background="@null"
android:visibility="gone"
diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index 8ee2fba..1ae3bf5 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -65,9 +65,10 @@
android:id="@+id/ssid_scanner_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:minWidth="@dimen/min_tap_target_size"
+ android:minHeight="@dimen/min_tap_target_size"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
- android:layout_margin="5dp"
android:background="@null"
android:src="@drawable/ic_scan_24dp"
android:contentDescription="@string/wifi_add_network" />
@@ -300,9 +301,10 @@
android:id="@+id/password_scanner_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
+ android:minWidth="@dimen/min_tap_target_size"
+ android:minHeight="@dimen/min_tap_target_size"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
- android:layout_margin="5dp"
android:background="@null"
android:src="@drawable/ic_scan_24dp"
android:contentDescription="@string/wifi_add_network" />
diff --git a/res/layout/wifi_network_details_two_buttons_panel.xml b/res/layout/wifi_network_details_two_buttons_panel.xml
index 57f76b5..6c51d11 100644
--- a/res/layout/wifi_network_details_two_buttons_panel.xml
+++ b/res/layout/wifi_network_details_two_buttons_panel.xml
@@ -27,7 +27,6 @@
android:paddingStart="8dp"
android:paddingEnd="8dp">
<Button
- style="@android:style/@Widget.Material.Button.Colored"
android:id="@+id/forget_button"
android:text="@string/forget"
android:layout_width="0dp"
diff --git a/res/values/strings.xml b/res/values/strings.xml
index f581121..90b72e1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -2153,6 +2153,10 @@
<string name="wifi_dpp_could_not_add_device">Couldn\u2019t add device</string>
<!-- Title for the fragment to show that device found but naming known [CHAR LIMIT=50] -->
<string name="wifi_dpp_device_found">Device found</string>
+ <!-- Hint for Wi-Fi DPP handshake running [CHAR LIMIT=NONE] -->
+ <string name="wifi_dpp_sharing_wifi_with_this_device">Sharing Wi\u2011Fi with this device\u2026</string>
+ <!-- Hint for Wi-Fi DPP handshake running [CHAR LIMIT=NONE] -->
+ <string name="wifi_dpp_connecting">Connecting\u2026</string>
<!-- Label for the try again button [CHAR LIMIT=20]-->
<string name="retry">Retry</string>
<!-- Label for the check box to share a network with other users on the same device -->
@@ -2927,8 +2931,6 @@
<!-- About phone screen, status item label [CHAR LIMIT=40] -->
<string name="firmware_version">Android version</string>
- <!-- About phone screen, dialog title for showing device software information such as android version, security patch level, etc [CHAR LIMIT=60] -->
- <string name="firmware_title">Android</string>
<!-- About phone screen, status item label [CHAR LIMIT=60] -->
<string name="security_patch">Android security patch level</string>
<!-- About phone screen, status item label [CHAR LIMIT=40] -->
@@ -3625,7 +3627,7 @@
<string name="master_clear_final_button_text">Erase everything</string>
<!-- Master clear failed message -->
<string name="master_clear_failed">No reset was performed because the System Clear service isn\u2019t available.</string>
- <!-- Master clear confirmation screen title [CHAR LIMIT=30] -->
+ <!-- Master clear confirmation screen title [CHAR LIMIT=33] -->
<string name="master_clear_confirm_title">Erase all data?</string>
<!-- Error message for users that aren't allowed to factory reset [CHAR LIMIT=none] -->
<string name="master_clear_not_available">Factory reset is not available for this user</string>
diff --git a/res/xml/firmware_version.xml b/res/xml/firmware_version.xml
new file mode 100644
index 0000000..2914ef1
--- /dev/null
+++ b/res/xml/firmware_version.xml
@@ -0,0 +1,73 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="firmware_version_screen"
+ android:title="@string/firmware_version"
+ settings:keywords="@string/keywords_android_version">
+
+ <!-- Android version -->
+ <Preference
+ android:key="os_firmware_version"
+ android:title="@string/firmware_version"
+ android:summary="@string/summary_placeholder"
+ settings:enableCopying="true"
+ settings:allowDynamicSummaryInSlice="true"
+ settings:controller="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionDetailPreferenceController"/>
+
+ <!-- Security patch -->
+ <Preference
+ android:key="security_key"
+ android:title="@string/security_patch"
+ settings:enableCopying="true"
+ settings:controller="com.android.settings.deviceinfo.firmwareversion.SecurityPatchLevelPreferenceController"/>
+
+ <!-- Mainline module version -->
+ <Preference
+ android:key="module_version"
+ android:title="@string/module_version"
+ android:summary="@string/summary_placeholder"
+ settings:enableCopying="true"
+ settings:controller="com.android.settings.deviceinfo.firmwareversion.MainlineModuleVersionPreferenceController"/>
+
+ <!-- Baseband -->
+ <Preference
+ android:key="base_band"
+ android:title="@string/baseband_version"
+ android:summary="@string/summary_placeholder"
+ settings:enableCopying="true"
+ settings:controller="com.android.settings.deviceinfo.firmwareversion.BasebandVersionPreferenceController"/>
+
+ <!-- Kernel -->
+ <Preference
+ android:key="kernel_version"
+ android:title="@string/kernel_version"
+ android:summary="@string/summary_placeholder"
+ settings:enableCopying="true"
+ settings:controller="com.android.settings.deviceinfo.firmwareversion.KernelVersionPreferenceController"/>
+
+ <!-- Build -->
+ <Preference
+ android:key="os_build_number"
+ android:title="@string/build_number"
+ android:summary="@string/summary_placeholder"
+ settings:enableCopying="true"
+ settings:controller="com.android.settings.deviceinfo.firmwareversion.SimpleBuildNumberPreferenceController"/>
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/hardware_info.xml b/res/xml/hardware_info.xml
new file mode 100644
index 0000000..2e35101
--- /dev/null
+++ b/res/xml/hardware_info.xml
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ 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.
+ -->
+
+<PreferenceScreen
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:settings="http://schemas.android.com/apk/res-auto"
+ android:key="hardware_info_screen"
+ android:title="@string/hardware_info"
+ settings:keywords="@string/keywords_model_and_hardware">
+
+ <!-- Model -->
+ <Preference
+ android:key="hardware_info_device_model"
+ android:title="@string/model_info"
+ android:summary="@string/summary_placeholder"
+ settings:allowDynamicSummaryInSlice="true"
+ settings:controller="com.android.settings.deviceinfo.hardwareinfo.DeviceModelPreferenceController"
+ settings:enableCopying="true"/>
+
+ <!-- SerialNumber -->
+ <Preference
+ android:key="hardware_info_device_serial"
+ android:title="@string/status_serial_number"
+ android:summary="@string/summary_placeholder"
+ settings:allowDynamicSummaryInSlice="true"
+ settings:controller="com.android.settings.deviceinfo.hardwareinfo.SerialNumberPreferenceController"
+ settings:enableCopying="true"/>
+
+ <!-- Hardware revision -->
+ <Preference
+ android:key="hardware_info_device_revision"
+ android:title="@string/hardware_revision"
+ android:summary="@string/summary_placeholder"
+ settings:allowDynamicSummaryInSlice="true"
+ settings:controller="com.android.settings.deviceinfo.hardwareinfo.HardwareRevisionPreferenceController"
+ settings:enableCopying="true"/>
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/my_device_info.xml b/res/xml/my_device_info.xml
index 6323a14..83bf5c4 100644
--- a/res/xml/my_device_info.xml
+++ b/res/xml/my_device_info.xml
@@ -105,7 +105,8 @@
settings:keywords="@string/keywords_model_and_hardware"
android:summary="@string/summary_placeholder"
settings:allowDynamicSummaryInSlice="true"
- settings:controller="com.android.settings.deviceinfo.DeviceModelPreferenceController"/>
+ android:fragment="com.android.settings.deviceinfo.hardwareinfo.HardwareInfoFragment"
+ settings:controller="com.android.settings.deviceinfo.HardwareInfoPreferenceController"/>
<!-- IMEI -->
<Preference
@@ -121,11 +122,10 @@
android:key="firmware_version"
android:order="32"
android:title="@string/firmware_version"
- settings:keywords="@string/keywords_android_version"
android:summary="@string/summary_placeholder"
settings:allowDynamicSummaryInSlice="true"
- settings:controller=
- "com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController"/>
+ android:fragment="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings"
+ settings:controller="com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController"/>
<!--IP address -->
<Preference
diff --git a/src/com/android/settings/applications/RecentAppsPreferenceController.java b/src/com/android/settings/applications/RecentAppsPreferenceController.java
index fe52a8b..838d758 100644
--- a/src/com/android/settings/applications/RecentAppsPreferenceController.java
+++ b/src/com/android/settings/applications/RecentAppsPreferenceController.java
@@ -82,6 +82,8 @@
Preference mAllAppPref;
@VisibleForTesting
Preference mDivider;
+ @VisibleForTesting
+ boolean mIsFirstLaunch;
private final PackageManager mPm;
private final UsageStatsManager mUsageStatsManager;
@@ -93,6 +95,7 @@
private Fragment mHost;
private Calendar mCal;
private List<UsageStats> mStats;
+ private List<UsageStats> mRecentApps;
private boolean mHasRecentApps;
static {
@@ -115,6 +118,9 @@
mIconDrawableFactory = IconDrawableFactory.newInstance(mContext);
mPowerManager = mContext.getSystemService(PowerManager.class);
mUsageStatsManager = mContext.getSystemService(UsageStatsManager.class);
+ mRecentApps = new ArrayList<>();
+ mIsFirstLaunch = true;
+ reloadData();
}
public void setFragment(Fragment fragment) {
@@ -123,8 +129,7 @@
@Override
public int getAvailabilityStatus() {
- reloadData();
- return getDisplayableRecentAppList().isEmpty() ? AVAILABLE_UNSEARCHABLE : AVAILABLE;
+ return mRecentApps.isEmpty() ? AVAILABLE_UNSEARCHABLE : AVAILABLE;
}
@Override
@@ -152,7 +157,11 @@
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- refreshUi();
+ // In order to improve launch time, we don't load data again at first launch.
+ if (!mIsFirstLaunch) {
+ reloadData();
+ refreshUi();
+ }
// Show total number of installed apps as See all's summary.
new InstalledAppCounter(mContext, InstalledAppCounter.IGNORE_INSTALL_REASON,
mContext.getPackageManager()) {
@@ -167,6 +176,7 @@
}
}
}.execute();
+ mIsFirstLaunch = false;
}
@Override
@@ -177,11 +187,9 @@
@VisibleForTesting
void refreshUi() {
- reloadData();
- final List<UsageStats> recentApps = getDisplayableRecentAppList();
- if (recentApps != null && !recentApps.isEmpty()) {
+ if (mRecentApps != null && !mRecentApps.isEmpty()) {
mHasRecentApps = true;
- displayRecentApps(recentApps);
+ displayRecentApps();
} else {
mHasRecentApps = false;
displayOnlyAppInfo();
@@ -197,6 +205,8 @@
: mUsageStatsManager.queryUsageStats(
UsageStatsManager.INTERVAL_BEST, mCal.getTimeInMillis(),
System.currentTimeMillis());
+
+ updateDisplayableRecentAppList();
}
private void displayOnlyAppInfo() {
@@ -206,10 +216,10 @@
mRecentAppsPreference.setVisible(false);
}
- private void displayRecentApps(List<UsageStats> recentApps) {
+ private void displayRecentApps() {
int showAppsCount = 0;
- for (UsageStats stat : recentApps) {
+ for (UsageStats stat : mRecentApps) {
final AppEntityInfo appEntityInfoInfo = createAppEntity(stat);
if (appEntityInfoInfo != null) {
mAppEntitiesController.setAppEntity(showAppsCount++, appEntityInfoInfo);
@@ -246,8 +256,8 @@
.build();
}
- private List<UsageStats> getDisplayableRecentAppList() {
- final List<UsageStats> recentApps = new ArrayList<>();
+ private void updateDisplayableRecentAppList() {
+ mRecentApps.clear();
final Map<String, UsageStats> map = new ArrayMap<>();
final int statCount = mStats.size();
for (int i = 0; i < statCount; i++) {
@@ -273,13 +283,12 @@
if (appEntry == null) {
continue;
}
- recentApps.add(stat);
+ mRecentApps.add(stat);
count++;
if (count >= AppEntitiesHeaderController.MAXIMUM_APPS) {
break;
}
}
- return recentApps;
}
diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItem.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItem.java
index 305281c..370a4df 100644
--- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItem.java
+++ b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItem.java
@@ -30,6 +30,7 @@
private static final String TAG = "DeviceAdminListItem";
+ private final UserHandle mUserHandle;
private final String mKey;
private final DeviceAdminInfo mInfo;
private final CharSequence mName;
@@ -39,7 +40,8 @@
public DeviceAdminListItem(Context context, DeviceAdminInfo info) {
mInfo = info;
- mKey = mInfo.getComponent().flattenToString();
+ mUserHandle = new UserHandle(getUserIdFromDeviceAdminInfo(mInfo));
+ mKey = mUserHandle.getIdentifier() + "@" + mInfo.getComponent().flattenToString();
mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
final PackageManager pm = context.getPackageManager();
mName = mInfo.loadLabel(pm);
@@ -48,8 +50,7 @@
} catch (Resources.NotFoundException exception) {
Log.w(TAG, "Setting description to null because can't find resource: " + mKey);
}
- mIcon = pm.getUserBadgedIcon(mInfo.loadIcon(pm),
- new UserHandle(DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo)));
+ mIcon = pm.getUserBadgedIcon(mInfo.loadIcon(pm), mUserHandle);
}
@Override
@@ -70,8 +71,7 @@
}
public boolean isActive() {
- return mDPM.isAdminActiveAsUser(mInfo.getComponent(),
- DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo));
+ return mDPM.isAdminActiveAsUser(mInfo.getComponent(), getUserIdFromDeviceAdminInfo(mInfo));
}
public Drawable getIcon() {
@@ -79,16 +79,25 @@
}
public boolean isEnabled() {
- return !mDPM.isRemovingAdmin(mInfo.getComponent(),
- DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo));
+ return !mDPM.isRemovingAdmin(mInfo.getComponent(), getUserIdFromDeviceAdminInfo(mInfo));
}
public UserHandle getUser() {
- return new UserHandle(DeviceAdminUtils.getUserIdFromDeviceAdminInfo(mInfo));
+ return new UserHandle(getUserIdFromDeviceAdminInfo(mInfo));
}
public Intent getLaunchIntent(Context context) {
return new Intent(context, DeviceAdminAdd.class)
.putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, mInfo.getComponent());
}
+
+ /**
+ * Extracts the user id from a device admin info object.
+ *
+ * @param adminInfo the device administrator info.
+ * @return identifier of the user associated with the device admin.
+ */
+ private static int getUserIdFromDeviceAdminInfo(DeviceAdminInfo adminInfo) {
+ return UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid);
+ }
}
diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListPreferenceController.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListPreferenceController.java
index 319d62f..7b139d9 100644
--- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListPreferenceController.java
+++ b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListPreferenceController.java
@@ -53,6 +53,9 @@
import com.android.settingslib.widget.FooterPreference;
import com.android.settingslib.widget.FooterPreferenceMixinCompat;
+import org.xmlpull.v1.XmlPullParserException;
+
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@@ -249,8 +252,7 @@
Log.w(TAG, "Unable to load component: " + activeAdmin);
continue;
}
- final DeviceAdminInfo deviceAdminInfo = DeviceAdminUtils.createDeviceAdminInfo(
- mContext, ai);
+ final DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(mContext, ai);
if (deviceAdminInfo == null) {
continue;
}
@@ -286,7 +288,7 @@
&& alreadyAddedComponents.contains(riComponentName)) {
continue;
}
- DeviceAdminInfo deviceAdminInfo = DeviceAdminUtils.createDeviceAdminInfo(
+ DeviceAdminInfo deviceAdminInfo = createDeviceAdminInfo(
mContext, resolveInfo.activityInfo);
// add only visible ones (note: active admins are added regardless of visibility)
if (deviceAdminInfo != null && deviceAdminInfo.isVisible()) {
@@ -297,4 +299,20 @@
}
}
}
+
+ /**
+ * Creates a device admin info object for the resolved intent that points to the component of
+ * the device admin.
+ *
+ * @param ai ActivityInfo for the admin component.
+ * @return new {@link DeviceAdminInfo} object or null if there was an error.
+ */
+ private static DeviceAdminInfo createDeviceAdminInfo(Context context, ActivityInfo ai) {
+ try {
+ return new DeviceAdminInfo(context, ai);
+ } catch (XmlPullParserException | IOException e) {
+ Log.w(TAG, "Skipping " + ai, e);
+ }
+ return null;
+ }
}
diff --git a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminUtils.java b/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminUtils.java
deleted file mode 100644
index 13d9d20..0000000
--- a/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminUtils.java
+++ /dev/null
@@ -1,58 +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.settings.applications.specialaccess.deviceadmin;
-
-import android.app.admin.DeviceAdminInfo;
-import android.content.Context;
-import android.content.pm.ActivityInfo;
-import android.os.UserHandle;
-import android.util.Log;
-
-import org.xmlpull.v1.XmlPullParserException;
-
-import java.io.IOException;
-
-public class DeviceAdminUtils {
-
- private static final String TAG = "DeviceAdminUtils";
-
- /**
- * Creates a device admin info object for the resolved intent that points to the component of
- * the device admin.
- *
- * @param ai ActivityInfo for the admin component.
- * @return new {@link DeviceAdminInfo} object or null if there was an error.
- */
- public static DeviceAdminInfo createDeviceAdminInfo(Context context, ActivityInfo ai) {
- try {
- return new DeviceAdminInfo(context, ai);
- } catch (XmlPullParserException | IOException e) {
- Log.w(TAG, "Skipping " + ai, e);
- }
- return null;
- }
-
- /**
- * Extracts the user id from a device admin info object.
- *
- * @param adminInfo the device administrator info.
- * @return identifier of the user associated with the device admin.
- */
- public static int getUserIdFromDeviceAdminInfo(DeviceAdminInfo adminInfo) {
- return UserHandle.getUserId(adminInfo.getActivityInfo().applicationInfo.uid);
- }
-}
diff --git a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
index 34a758b..64c9866 100644
--- a/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
+++ b/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderController.java
@@ -16,6 +16,7 @@
package com.android.settings.bluetooth;
+import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.Bitmap;
@@ -23,6 +24,8 @@
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.net.Uri;
+import android.os.Handler;
+import android.os.Looper;
import android.provider.MediaStore;
import android.util.Log;
import android.view.View;
@@ -59,9 +62,25 @@
@VisibleForTesting
final Map<String, Bitmap> mIconCache;
private CachedBluetoothDevice mCachedDevice;
+ @VisibleForTesting
+ BluetoothAdapter mBluetoothAdapter;
+ @VisibleForTesting
+ Handler mHandler = new Handler(Looper.getMainLooper());
+ @VisibleForTesting
+ final BluetoothAdapter.MetadataListener mMetadataListener =
+ new BluetoothAdapter.MetadataListener() {
+ @Override
+ public void onMetadataChanged(BluetoothDevice device, int key, String value) {
+ super.onMetadataChanged(device, key, value);
+ Log.i(TAG, String.format("Metadata updated in Device %s: %d = %s.", device, key,
+ value));
+ refresh();
+ }
+ };
public AdvancedBluetoothDetailsHeaderController(Context context, String prefKey) {
super(context, prefKey);
+ mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
mIconCache = new HashMap<>();
}
@@ -84,11 +103,14 @@
@Override
public void onStart() {
mCachedDevice.registerCallback(this::onDeviceAttributesChanged);
+ mBluetoothAdapter.registerMetadataListener(mCachedDevice.getDevice(), mMetadataListener,
+ mHandler);
}
@Override
public void onStop() {
mCachedDevice.unregisterCallback(this::onDeviceAttributesChanged);
+ mBluetoothAdapter.unregisterMetadataListener(mCachedDevice.getDevice());
// Destroy icon bitmap associated with this header
for (Bitmap bitmap : mIconCache.values()) {
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 60655fe..5e32e71 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -49,9 +49,9 @@
import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureDetails;
import com.android.settings.applications.specialaccess.pictureinpicture.PictureInPictureSettings;
import com.android.settings.applications.specialaccess.vrlistener.VrListenerSettings;
-import com.android.settings.backup.UserBackupSettingsActivity;
import com.android.settings.backup.PrivacySettings;
import com.android.settings.backup.ToggleBackupSettingFragment;
+import com.android.settings.backup.UserBackupSettingsActivity;
import com.android.settings.biometrics.face.FaceSettings;
import com.android.settings.bluetooth.BluetoothDeviceDetailsFragment;
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
@@ -68,6 +68,7 @@
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageSettings;
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
+import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionSettings;
import com.android.settings.display.NightDisplaySettings;
import com.android.settings.dream.DreamSettings;
import com.android.settings.enterprise.EnterprisePrivacySettings;
@@ -166,6 +167,7 @@
DisplaySettings.class.getName(),
MyDeviceInfoFragment.class.getName(),
ManageApplications.class.getName(),
+ FirmwareVersionSettings.class.getName(),
ManageAssist.class.getName(),
ProcessStatsUi.class.getName(),
NotificationStation.class.getName(),
diff --git a/src/com/android/settings/development/FileEncryptionPreferenceController.java b/src/com/android/settings/development/FileEncryptionPreferenceController.java
index 8aadfb9..82a58ba 100644
--- a/src/com/android/settings/development/FileEncryptionPreferenceController.java
+++ b/src/com/android/settings/development/FileEncryptionPreferenceController.java
@@ -63,7 +63,8 @@
@Override
public void updateState(Preference preference) {
- if (!TextUtils.equals("file", CryptoProperties.type().orElse("none"))) {
+ if (CryptoProperties.type().orElse(CryptoProperties.type_values.NONE) !=
+ CryptoProperties.type_values.FILE) {
return;
}
diff --git a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
index ec0ab36..f13af94 100644
--- a/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/BuildNumberPreferenceController.java
@@ -42,7 +42,6 @@
import com.android.settings.core.InstrumentedPreferenceFragment;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.password.ChooseLockSettingsHelper;
-import com.android.settings.slices.Copyable;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
@@ -50,7 +49,7 @@
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.development.DevelopmentSettingsEnabler;
-public class BuildNumberPreferenceController extends BasePreferenceController implements Copyable,
+public class BuildNumberPreferenceController extends BasePreferenceController implements
LifecycleObserver, OnStart {
static final int TAPS_TO_BE_A_DEVELOPER = 7;
@@ -109,6 +108,11 @@
}
@Override
+ public boolean isCopyableSlice() {
+ return true;
+ }
+
+ @Override
public void copy() {
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
CLIPBOARD_SERVICE);
diff --git a/src/com/android/settings/deviceinfo/HardwareInfoDialogFragment.java b/src/com/android/settings/deviceinfo/HardwareInfoDialogFragment.java
deleted file mode 100644
index 34a7143..0000000
--- a/src/com/android/settings/deviceinfo/HardwareInfoDialogFragment.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo;
-
-import android.app.Dialog;
-import android.app.settings.SettingsEnums;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.SystemProperties;
-import android.text.TextUtils;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.TextView;
-
-import androidx.annotation.VisibleForTesting;
-import androidx.appcompat.app.AlertDialog;
-
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-
-public class HardwareInfoDialogFragment extends InstrumentedDialogFragment {
-
- public static final String TAG = "HardwareInfo";
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.DIALOG_SETTINGS_HARDWARE_INFO;
- }
-
- public static HardwareInfoDialogFragment newInstance() {
- final HardwareInfoDialogFragment fragment = new HardwareInfoDialogFragment();
- return fragment;
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
- .setTitle(R.string.hardware_info)
- .setPositiveButton(android.R.string.ok, null);
- final View content = LayoutInflater.from(builder.getContext())
- .inflate(R.layout.dialog_hardware_info, null /* parent */);
- // Model
- setText(content, R.id.model_label, R.id.model_value,
- DeviceModelPreferenceController.getDeviceModel());
-
- // Serial number
- setText(content, R.id.serial_number_label, R.id.serial_number_value, getSerialNumber());
-
- // Hardware rev
- setText(content, R.id.hardware_rev_label, R.id.hardware_rev_value,
- SystemProperties.get("ro.boot.hardware.revision"));
-
- return builder.setView(content).create();
- }
-
- @VisibleForTesting
- void setText(View content, int labelViewId, int valueViewId, String value) {
- if (content == null) {
- return;
- }
- final View labelView = content.findViewById(labelViewId);
- final TextView valueView = content.findViewById(valueViewId);
- if (!TextUtils.isEmpty(value)) {
- labelView.setVisibility(View.VISIBLE);
- valueView.setVisibility(View.VISIBLE);
- valueView.setText(value);
- } else {
- labelView.setVisibility(View.GONE);
- valueView.setVisibility(View.GONE);
- }
- }
-
- @VisibleForTesting
- String getSerialNumber() {
- return Build.getSerial();
- }
-}
diff --git a/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java b/src/com/android/settings/deviceinfo/HardwareInfoPreferenceController.java
similarity index 71%
rename from src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java
rename to src/com/android/settings/deviceinfo/HardwareInfoPreferenceController.java
index 2797153..29f1391 100644
--- a/src/com/android/settings/deviceinfo/DeviceModelPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/HardwareInfoPreferenceController.java
@@ -17,11 +17,8 @@
import android.content.Context;
import android.os.Build;
-import android.text.TextUtils;
import android.util.Log;
-import androidx.fragment.app.Fragment;
-import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
@@ -31,21 +28,14 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
-public class DeviceModelPreferenceController extends BasePreferenceController {
-
+public class HardwareInfoPreferenceController extends BasePreferenceController {
private static final String TAG = "DeviceModelPrefCtrl";
- private Fragment mHost;
-
- public DeviceModelPreferenceController(Context context, String key) {
+ public HardwareInfoPreferenceController(Context context, String key) {
super(context, key);
}
- public void setHost(Fragment fragment) {
- mHost = fragment;
- }
-
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
@@ -54,7 +44,7 @@
@Override
public int getAvailabilityStatus() {
return mContext.getResources().getBoolean(R.bool.config_show_device_model)
- ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ ? AVAILABLE_UNSEARCHABLE : UNSUPPORTED_ON_DEVICE;
}
@Override
@@ -62,21 +52,6 @@
return mContext.getResources().getString(R.string.model_summary, getDeviceModel());
}
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
- return false;
- }
- final HardwareInfoDialogFragment fragment = HardwareInfoDialogFragment.newInstance();
- fragment.show(mHost.getFragmentManager(), HardwareInfoDialogFragment.TAG);
- return true;
- }
-
- @Override
- public boolean isSliceable() {
- return true;
- }
-
public static String getDeviceModel() {
FutureTask<String> msvSuffixTask = new FutureTask<>(() -> DeviceInfoUtils.getMsvSuffix());
diff --git a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
index 598dfb1..3767860 100644
--- a/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/PhoneNumberPreferenceController.java
@@ -35,14 +35,12 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.slices.Copyable;
import com.android.settingslib.DeviceInfoUtils;
import java.util.ArrayList;
import java.util.List;
-public class PhoneNumberPreferenceController extends BasePreferenceController implements
- Copyable {
+public class PhoneNumberPreferenceController extends BasePreferenceController {
private final static String KEY_PHONE_NUMBER = "phone_number";
@@ -99,6 +97,11 @@
}
@Override
+ public boolean isCopyableSlice() {
+ return true;
+ }
+
+ @Override
public void copy() {
final ClipboardManager clipboard = (ClipboardManager) mContext.getSystemService(
CLIPBOARD_SERVICE);
diff --git a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
index 0116c42..e6afb7b 100644
--- a/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
+++ b/src/com/android/settings/deviceinfo/aboutphone/MyDeviceInfoFragment.java
@@ -31,7 +31,6 @@
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.deviceinfo.BluetoothAddressPreferenceController;
import com.android.settings.deviceinfo.BuildNumberPreferenceController;
-import com.android.settings.deviceinfo.DeviceModelPreferenceController;
import com.android.settings.deviceinfo.DeviceNamePreferenceController;
import com.android.settings.deviceinfo.FccEquipmentIdPreferenceController;
import com.android.settings.deviceinfo.FeedbackPreferenceController;
@@ -41,7 +40,6 @@
import com.android.settings.deviceinfo.SafetyInfoPreferenceController;
import com.android.settings.deviceinfo.UptimePreferenceController;
import com.android.settings.deviceinfo.WifiMacAddressPreferenceController;
-import com.android.settings.deviceinfo.firmwareversion.FirmwareVersionPreferenceController;
import com.android.settings.deviceinfo.imei.ImeiInfoPreferenceController;
import com.android.settings.deviceinfo.simstatus.SimStatusPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -77,8 +75,6 @@
@Override
public void onAttach(Context context) {
super.onAttach(context);
- use(FirmwareVersionPreferenceController.class).setHost(this /* parent */);
- use(DeviceModelPreferenceController.class).setHost(this /* parent */);
use(ImeiInfoPreferenceController.class).setHost(this /* parent */);
use(DeviceNamePreferenceController.class).setHost(this /* parent */);
mBuildNumberPreferenceController = use(BuildNumberPreferenceController.class);
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionDialogController.java b/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionDialogController.java
deleted file mode 100644
index 0e36d85..0000000
--- a/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionDialogController.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo.firmwareversion;
-
-import android.content.Context;
-import android.os.SystemProperties;
-
-import androidx.annotation.VisibleForTesting;
-
-import com.android.settings.R;
-import com.android.settings.Utils;
-
-public class BasebandVersionDialogController {
-
- @VisibleForTesting
- static final int BASEBAND_VERSION_LABEL_ID = R.id.baseband_version_label;
- @VisibleForTesting
- static final int BASEBAND_VERSION_VALUE_ID = R.id.baseband_version_value;
- @VisibleForTesting
- static final String BASEBAND_PROPERTY = "gsm.version.baseband";
-
- private final FirmwareVersionDialogFragment mDialog;
-
- public BasebandVersionDialogController(FirmwareVersionDialogFragment dialog) {
- mDialog = dialog;
- }
-
- /**
- * Updates the baseband version field of the dialog.
- */
- public void initialize() {
- final Context context = mDialog.getContext();
- if (Utils.isWifiOnly(context)) {
- mDialog.removeSettingFromScreen(BASEBAND_VERSION_LABEL_ID);
- mDialog.removeSettingFromScreen(BASEBAND_VERSION_VALUE_ID);
- return;
- }
-
- mDialog.setText(BASEBAND_VERSION_VALUE_ID, SystemProperties.get(BASEBAND_PROPERTY,
- context.getString(R.string.device_info_default)));
- }
-}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceController.java
new file mode 100644
index 0000000..dd3d560
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceController.java
@@ -0,0 +1,47 @@
+/*
+ * 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.deviceinfo.firmwareversion;
+
+import android.content.Context;
+import android.os.SystemProperties;
+
+import androidx.annotation.VisibleForTesting;
+
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.core.BasePreferenceController;
+
+public class BasebandVersionPreferenceController extends BasePreferenceController {
+
+ @VisibleForTesting
+ static final String BASEBAND_PROPERTY = "gsm.version.baseband";
+
+ public BasebandVersionPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return !Utils.isWifiOnly(mContext) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return SystemProperties.get(BASEBAND_PROPERTY,
+ mContext.getString(R.string.device_info_default));
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/BuildNumberDialogController.java b/src/com/android/settings/deviceinfo/firmwareversion/BuildNumberDialogController.java
deleted file mode 100644
index ba4eb7a..0000000
--- a/src/com/android/settings/deviceinfo/firmwareversion/BuildNumberDialogController.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo.firmwareversion;
-
-import android.os.Build;
-import android.text.BidiFormatter;
-
-import androidx.annotation.VisibleForTesting;
-
-import com.android.settings.R;
-
-public class BuildNumberDialogController {
-
- @VisibleForTesting
- static final int BUILD_NUMBER_VALUE_ID = R.id.build_number_value;
-
- private final FirmwareVersionDialogFragment mDialog;
-
- public BuildNumberDialogController(FirmwareVersionDialogFragment dialog) {
- mDialog = dialog;
- }
-
- /**
- * Updates the build number to the dialog.
- */
- public void initialize() {
- mDialog.setText(BUILD_NUMBER_VALUE_ID,
- BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY));
- }
-}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogController.java b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceController.java
similarity index 72%
rename from src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogController.java
rename to src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceController.java
index 8c29f7b..9f3d6e5 100644
--- a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogController.java
+++ b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceController.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * 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.
@@ -22,42 +22,60 @@
import android.os.SystemClock;
import android.os.UserHandle;
import android.os.UserManager;
+import android.text.TextUtils;
import android.util.Log;
-import android.view.View;
import androidx.annotation.VisibleForTesting;
+import androidx.preference.Preference;
import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.slices.Sliceable;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
-public class FirmwareVersionDialogController implements View.OnClickListener {
+public class FirmwareVersionDetailPreferenceController extends BasePreferenceController {
private static final String TAG = "firmwareDialogCtrl";
private static final int DELAY_TIMER_MILLIS = 500;
private static final int ACTIVITY_TRIGGER_COUNT = 3;
- @VisibleForTesting
- static final int FIRMWARE_VERSION_VALUE_ID = R.id.firmware_version_value;
- @VisibleForTesting
- static final int FIRMWARE_VERSION_LABEL_ID = R.id.firmware_version_label;
-
- private final FirmwareVersionDialogFragment mDialog;
- private final Context mContext;
private final UserManager mUserManager;
private final long[] mHits = new long[ACTIVITY_TRIGGER_COUNT];
private RestrictedLockUtils.EnforcedAdmin mFunDisallowedAdmin;
private boolean mFunDisallowedBySystem;
- public FirmwareVersionDialogController(FirmwareVersionDialogFragment dialog) {
- mDialog = dialog;
- mContext = dialog.getContext();
+ public FirmwareVersionDetailPreferenceController(Context context, String key) {
+ super(context, key);
mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);
+ initializeAdminPermissions();
}
@Override
- public void onClick(View v) {
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public boolean isSliceable() {
+ return true;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return Build.VERSION.RELEASE;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
+ return false;
+ }
+ if (Utils.isMonkeyRunning()) {
+ return false;
+ }
arrayCopy();
mHits[mHits.length - 1] = SystemClock.uptimeMillis();
if (mHits[0] >= (SystemClock.uptimeMillis() - DELAY_TIMER_MILLIS)) {
@@ -67,7 +85,7 @@
mFunDisallowedAdmin);
}
Log.d(TAG, "Sorry, no fun for you!");
- return;
+ return true;
}
final Intent intent = new Intent(Intent.ACTION_MAIN)
@@ -79,21 +97,7 @@
Log.e(TAG, "Unable to start activity " + intent.toString());
}
}
- }
-
- /**
- * Populates the Android version field in the dialog and registers click listeners.
- */
- public void initialize() {
- initializeAdminPermissions();
- registerClickListeners();
-
- mDialog.setText(FIRMWARE_VERSION_VALUE_ID, Build.VERSION.RELEASE);
- }
-
- private void registerClickListeners() {
- mDialog.registerClickListener(FIRMWARE_VERSION_LABEL_ID, this /* listener */);
- mDialog.registerClickListener(FIRMWARE_VERSION_VALUE_ID, this /* listener */);
+ return true;
}
/**
@@ -111,4 +115,10 @@
mFunDisallowedBySystem = RestrictedLockUtilsInternal.hasBaseUserRestriction(
mContext, UserManager.DISALLOW_FUN, UserHandle.myUserId());
}
+
+ @Override
+ public void copy() {
+ Sliceable.setCopyContent(mContext, getSummary(),
+ mContext.getText(R.string.firmware_version));
+ }
}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogFragment.java b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogFragment.java
deleted file mode 100644
index 2093c3e..0000000
--- a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogFragment.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo.firmwareversion;
-
-import android.app.Dialog;
-import android.app.settings.SettingsEnums;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.TextView;
-
-import androidx.appcompat.app.AlertDialog;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
-
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-
-public class FirmwareVersionDialogFragment extends InstrumentedDialogFragment {
-
- private static final String TAG = "firmwareVersionDialog";
-
- private View mRootView;
-
- public static void show(Fragment host) {
- final FragmentManager manager = host.getChildFragmentManager();
- if (manager.findFragmentByTag(TAG) == null) {
- final FirmwareVersionDialogFragment dialog = new FirmwareVersionDialogFragment();
- dialog.show(manager, TAG);
- }
- }
-
- @Override
- public int getMetricsCategory() {
- return SettingsEnums.DIALOG_FIRMWARE_VERSION;
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
- .setTitle(R.string.firmware_title)
- .setPositiveButton(android.R.string.ok, null /* listener */);
-
- mRootView = LayoutInflater.from(getActivity()).inflate(
- R.layout.dialog_firmware_version, null /* parent */);
-
- initializeControllers();
-
- return builder.setView(mRootView).create();
- }
-
- public void setText(int viewId, CharSequence text) {
- final TextView view = mRootView.findViewById(viewId);
- if (view != null) {
- view.setText(text);
- }
- }
-
- public void removeSettingFromScreen(int viewId) {
- final View view = mRootView.findViewById(viewId);
- if (view != null) {
- view.setVisibility(View.GONE);
- }
- }
-
- public void registerClickListener(int viewId, View.OnClickListener listener) {
- final View view = mRootView.findViewById(viewId);
- if (view != null) {
- view.setOnClickListener(listener);
- }
- }
-
- private void initializeControllers() {
- new FirmwareVersionDialogController(this).initialize();
- new SecurityPatchLevelDialogController(this).initialize();
- new BasebandVersionDialogController(this).initialize();
- new KernelVersionDialogController(this).initialize();
- new BuildNumberDialogController(this).initialize();
- new ModuleVersionDialogController(this).initialize();
- }
-}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceController.java
index b7b67b7..41d9566 100644
--- a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceController.java
@@ -18,56 +18,22 @@
import android.content.Context;
import android.os.Build;
-import android.text.TextUtils;
-import androidx.fragment.app.Fragment;
-import androidx.preference.Preference;
-
-import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.slices.Copyable;
-public class FirmwareVersionPreferenceController extends BasePreferenceController implements
- Copyable {
-
- private Fragment mFragment;
+public class FirmwareVersionPreferenceController extends BasePreferenceController {
public FirmwareVersionPreferenceController(Context context, String key) {
super(context, key);
}
- public void setHost(Fragment fragment) {
- mFragment = fragment;
- }
-
@Override
public int getAvailabilityStatus() {
- return AVAILABLE;
+ return AVAILABLE_UNSEARCHABLE;
}
@Override
public CharSequence getSummary() {
return Build.VERSION.RELEASE;
}
-
- @Override
- public boolean handlePreferenceTreeClick(Preference preference) {
- if (!TextUtils.equals(preference.getKey(), mPreferenceKey)) {
- return false;
- }
-
- FirmwareVersionDialogFragment.show(mFragment);
- return true;
- }
-
- @Override
- public boolean isSliceable() {
- return true;
- }
-
- @Override
- public void copy() {
- Copyable.setCopyContent(mContext, getSummary(),
- mContext.getText(R.string.firmware_version));
- }
}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionSettings.java b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionSettings.java
new file mode 100644
index 0000000..90c3b56
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionSettings.java
@@ -0,0 +1,64 @@
+/*
+ * 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.deviceinfo.firmwareversion;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@SearchIndexable
+public class FirmwareVersionSettings extends DashboardFragment {
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.firmware_version;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return "FirmwareVersionSettings";
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.DIALOG_FIRMWARE_VERSION;
+ }
+
+ public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.firmware_version;
+ result.add(sir);
+ return result;
+ }
+
+ };
+}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionDialogController.java b/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionDialogController.java
deleted file mode 100644
index 0d816d5..0000000
--- a/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionDialogController.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo.firmwareversion;
-
-import androidx.annotation.VisibleForTesting;
-
-import com.android.settings.R;
-import com.android.settingslib.DeviceInfoUtils;
-
-public class KernelVersionDialogController {
-
- @VisibleForTesting
- static int KERNEL_VERSION_VALUE_ID = R.id.kernel_version_value;
-
- private final FirmwareVersionDialogFragment mDialog;
-
- public KernelVersionDialogController(FirmwareVersionDialogFragment dialog) {
- mDialog = dialog;
- }
-
- /**
- * Updates kernel version to the dialog.
- */
- public void initialize() {
- mDialog.setText(KERNEL_VERSION_VALUE_ID,
- DeviceInfoUtils.getFormattedKernelVersion(mDialog.getContext()));
- }
-}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceController.java
new file mode 100644
index 0000000..0500c893
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceController.java
@@ -0,0 +1,39 @@
+/*
+ * 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.deviceinfo.firmwareversion;
+
+import android.content.Context;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.DeviceInfoUtils;
+
+public class KernelVersionPreferenceController extends BasePreferenceController {
+
+ public KernelVersionPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return DeviceInfoUtils.getFormattedKernelVersion(mContext);
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceController.java
new file mode 100644
index 0000000..e2f4fae
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceController.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.deviceinfo.firmwareversion;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.text.TextUtils;
+import android.util.FeatureFlagUtils;
+import android.util.Log;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.FeatureFlags;
+
+public class MainlineModuleVersionPreferenceController extends BasePreferenceController {
+
+ private static final String TAG = "MainlineModuleControl";
+
+ private final PackageManager mPackageManager;
+
+ private String mModuleVersion;
+
+ public MainlineModuleVersionPreferenceController(Context context, String key) {
+ super(context, key);
+ mPackageManager = mContext.getPackageManager();
+ initModules();
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (!FeatureFlagUtils.isEnabled(mContext, FeatureFlags.MAINLINE_MODULE)) {
+ return UNSUPPORTED_ON_DEVICE;
+ }
+ return !TextUtils.isEmpty(mModuleVersion) ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ private void initModules() {
+ if (!FeatureFlagUtils.isEnabled(mContext, FeatureFlags.MAINLINE_MODULE)) {
+ return;
+ }
+ final String moduleProvider = mContext.getString(
+ com.android.internal.R.string.config_defaultModuleMetadataProvider);
+ if (!TextUtils.isEmpty(moduleProvider)) {
+ try {
+ mModuleVersion =
+ mPackageManager.getPackageInfo(moduleProvider, 0 /* flags */).versionName;
+ return;
+ } catch (PackageManager.NameNotFoundException e) {
+ Log.e(TAG, "Failed to get mainline version.", e);
+ mModuleVersion = null;
+ }
+ }
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return mModuleVersion;
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogController.java b/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogController.java
deleted file mode 100644
index 0dc953d..0000000
--- a/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogController.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * 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.deviceinfo.firmwareversion;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.text.TextUtils;
-import android.util.FeatureFlagUtils;
-import android.util.Log;
-
-import com.android.settings.R;
-import com.android.settings.core.FeatureFlags;
-
-import androidx.annotation.VisibleForTesting;
-
-public class ModuleVersionDialogController {
-
- private static final String TAG = "MainlineModuleControl";
-
- @VisibleForTesting
- static final int MODULE_VERSION_LABEL_ID = R.id.module_version_label;
- @VisibleForTesting
- static final int MODULE_VERSION_VALUE_ID = R.id.module_version_value;
-
- private final FirmwareVersionDialogFragment mDialog;
- private final Context mContext;
- private final PackageManager mPackageManager;
-
- public ModuleVersionDialogController(FirmwareVersionDialogFragment dialog) {
- mDialog = dialog;
- mContext = mDialog.getContext();
- mPackageManager = mContext.getPackageManager();
- }
-
- /**
- * Updates the mainline module version field of the dialog.
- */
- public void initialize() {
- if (!FeatureFlagUtils.isEnabled(mContext, FeatureFlags.MAINLINE_MODULE)) {
- mDialog.removeSettingFromScreen(MODULE_VERSION_LABEL_ID);
- mDialog.removeSettingFromScreen(MODULE_VERSION_VALUE_ID);
- return;
- }
- final String moduleProvider = mContext.getString(
- com.android.internal.R.string.config_defaultModuleMetadataProvider);
- if (!TextUtils.isEmpty(moduleProvider)) {
- try {
- mDialog.setText(MODULE_VERSION_VALUE_ID,
- mPackageManager.getPackageInfo(moduleProvider, 0 /* flags */).versionName);
- return;
- } catch (PackageManager.NameNotFoundException e) {
- Log.e(TAG, "Failed to get mainline version.", e);
- }
- }
- mDialog.removeSettingFromScreen(MODULE_VERSION_LABEL_ID);
- mDialog.removeSettingFromScreen(MODULE_VERSION_VALUE_ID);
- }
-}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelDialogController.java b/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelDialogController.java
deleted file mode 100644
index 9037fe7..0000000
--- a/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelDialogController.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo.firmwareversion;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.net.Uri;
-import android.text.TextUtils;
-import android.util.Log;
-import android.view.View;
-
-import androidx.annotation.VisibleForTesting;
-
-import com.android.settings.R;
-import com.android.settingslib.DeviceInfoUtils;
-
-public class SecurityPatchLevelDialogController implements View.OnClickListener {
-
- private static final String TAG = "SecurityPatchCtrl";
- private static final Uri INTENT_URI_DATA = Uri.parse(
- "https://source.android.com/security/bulletin/");
-
- @VisibleForTesting
- static final int SECURITY_PATCH_VALUE_ID = R.id.security_patch_level_value;
- @VisibleForTesting
- static final int SECURITY_PATCH_LABEL_ID = R.id.security_patch_level_label;
-
- private final FirmwareVersionDialogFragment mDialog;
- private final Context mContext;
- private final PackageManager mPackageManager;
- private final String mCurrentPatch;
-
- public SecurityPatchLevelDialogController(FirmwareVersionDialogFragment dialog) {
- mDialog = dialog;
- mContext = dialog.getContext();
- mPackageManager = mContext.getPackageManager();
- mCurrentPatch = DeviceInfoUtils.getSecurityPatch();
- }
-
- @Override
- public void onClick(View v) {
- final Intent intent = new Intent();
- intent.setAction(Intent.ACTION_VIEW);
- intent.setData(INTENT_URI_DATA);
- if (mPackageManager.queryIntentActivities(intent, 0).isEmpty()) {
- // Don't send out the intent to stop crash
- Log.w(TAG, "Stop click action on " + SECURITY_PATCH_VALUE_ID + ": "
- + "queryIntentActivities() returns empty");
- return;
- }
-
- mContext.startActivity(intent);
- }
-
- /**
- * Populates the security patch level field in the dialog and registers click listeners.
- */
- public void initialize() {
- if (TextUtils.isEmpty(mCurrentPatch)) {
- mDialog.removeSettingFromScreen(SECURITY_PATCH_LABEL_ID);
- mDialog.removeSettingFromScreen(SECURITY_PATCH_VALUE_ID);
- return;
- }
- registerListeners();
- mDialog.setText(SECURITY_PATCH_VALUE_ID, mCurrentPatch);
- }
-
- private void registerListeners() {
- mDialog.registerClickListener(SECURITY_PATCH_LABEL_ID, this /* listener */);
- mDialog.registerClickListener(SECURITY_PATCH_VALUE_ID, this /* listener */);
- }
-}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelPreferenceController.java
new file mode 100644
index 0000000..1df78a8
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelPreferenceController.java
@@ -0,0 +1,75 @@
+/*
+ * 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.deviceinfo.firmwareversion;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.net.Uri;
+import android.text.TextUtils;
+import android.util.Log;
+
+import androidx.preference.Preference;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.DeviceInfoUtils;
+
+public class SecurityPatchLevelPreferenceController extends BasePreferenceController {
+
+ private static final String TAG = "SecurityPatchCtrl";
+ private static final Uri INTENT_URI_DATA = Uri.parse(
+ "https://source.android.com/security/bulletin/");
+
+ private final PackageManager mPackageManager;
+ private final String mCurrentPatch;
+
+ public SecurityPatchLevelPreferenceController(Context context, String key) {
+ super(context, key);
+ mPackageManager = mContext.getPackageManager();
+ mCurrentPatch = DeviceInfoUtils.getSecurityPatch();
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return !TextUtils.isEmpty(mCurrentPatch)
+ ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return mCurrentPatch;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
+ return false;
+ }
+
+ final Intent intent = new Intent();
+ intent.setAction(Intent.ACTION_VIEW);
+ intent.setData(INTENT_URI_DATA);
+ if (mPackageManager.queryIntentActivities(intent, 0).isEmpty()) {
+ // Don't send out the intent to stop crash
+ Log.w(TAG, "queryIntentActivities() returns empty");
+ return true;
+ }
+
+ mContext.startActivity(intent);
+ return true;
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/firmwareversion/SimpleBuildNumberPreferenceController.java b/src/com/android/settings/deviceinfo/firmwareversion/SimpleBuildNumberPreferenceController.java
new file mode 100644
index 0000000..c7d4459
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/firmwareversion/SimpleBuildNumberPreferenceController.java
@@ -0,0 +1,41 @@
+/*
+ * 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.deviceinfo.firmwareversion;
+
+import android.content.Context;
+import android.os.Build;
+import android.text.BidiFormatter;
+
+import com.android.settings.core.BasePreferenceController;
+
+public class SimpleBuildNumberPreferenceController extends BasePreferenceController {
+
+ public SimpleBuildNumberPreferenceController(Context context,
+ String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY);
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceController.java
new file mode 100644
index 0000000..42c7b01
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceController.java
@@ -0,0 +1,42 @@
+/*
+ * 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.deviceinfo.hardwareinfo;
+
+import android.content.Context;
+
+import com.android.settings.deviceinfo.HardwareInfoPreferenceController;
+
+public class DeviceModelPreferenceController extends HardwareInfoPreferenceController {
+
+ public DeviceModelPreferenceController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ final int availability = super.getAvailabilityStatus();
+ if (availability == AVAILABLE_UNSEARCHABLE) {
+ return AVAILABLE;
+ }
+ return availability;
+ }
+
+ @Override
+ public boolean isSliceable() {
+ return true;
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFragment.java b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFragment.java
new file mode 100644
index 0000000..40e73ef
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoFragment.java
@@ -0,0 +1,71 @@
+/*
+ * 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.deviceinfo.hardwareinfo;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.provider.SearchIndexableResource;
+
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settings.search.Indexable;
+import com.android.settingslib.search.SearchIndexable;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+@SearchIndexable
+public class HardwareInfoFragment extends DashboardFragment {
+
+ public static final String TAG = "HardwareInfo";
+
+ @Override
+ public int getMetricsCategory() {
+ return SettingsEnums.DIALOG_SETTINGS_HARDWARE_INFO;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.hardware_info;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
+ boolean enabled) {
+ final ArrayList<SearchIndexableResource> result = new ArrayList<>();
+
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.hardware_info;
+ result.add(sir);
+ return result;
+ }
+
+ @Override
+ protected boolean isPageSearchEnabled(Context context) {
+ return context.getResources().getBoolean(R.bool.config_show_device_model);
+ }
+ };
+}
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java
new file mode 100644
index 0000000..ec0cdb2
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/HardwareRevisionPreferenceController.java
@@ -0,0 +1,46 @@
+/*
+ * 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.deviceinfo.hardwareinfo;
+
+import android.content.Context;
+import android.os.SystemProperties;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+
+public class HardwareRevisionPreferenceController extends BasePreferenceController {
+
+ public HardwareRevisionPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_device_model)
+ ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean isSliceable() {
+ return true;
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return SystemProperties.get("ro.boot.hardware.revision");
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java b/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java
new file mode 100644
index 0000000..01cd5f3
--- /dev/null
+++ b/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceController.java
@@ -0,0 +1,58 @@
+/*
+ * 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.deviceinfo.hardwareinfo;
+
+import android.content.Context;
+import android.os.Build;
+
+import com.android.settings.R;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.slices.Sliceable;
+
+public class SerialNumberPreferenceController extends BasePreferenceController {
+
+ public SerialNumberPreferenceController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return mContext.getResources().getBoolean(R.bool.config_show_device_model)
+ ? AVAILABLE : UNSUPPORTED_ON_DEVICE;
+ }
+
+ @Override
+ public boolean isSliceable() {
+ return true;
+ }
+
+ @Override
+ public boolean isCopyableSlice() {
+ return true;
+ }
+
+ @Override
+ public void copy() {
+ Sliceable.setCopyContent(mContext, getSummary(),
+ mContext.getText(R.string.status_serial_number));
+ }
+
+ @Override
+ public CharSequence getSummary() {
+ return Build.getSerial();
+ }
+}
diff --git a/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java
index 96ff83c..77d975e 100644
--- a/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/imei/ImeiInfoPreferenceController.java
@@ -29,7 +29,7 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.slices.Copyable;
+import com.android.settings.slices.Sliceable;
import com.android.settingslib.Utils;
import java.util.ArrayList;
@@ -38,7 +38,7 @@
/**
* Controller that manages preference for single and multi sim devices.
*/
-public class ImeiInfoPreferenceController extends BasePreferenceController implements Copyable {
+public class ImeiInfoPreferenceController extends BasePreferenceController {
private final boolean mIsMultiSim;
private final TelephonyManager mTelephonyManager;
@@ -106,8 +106,13 @@
}
@Override
+ public boolean isCopyableSlice() {
+ return true;
+ }
+
+ @Override
public void copy() {
- Copyable.setCopyContent(mContext, getSummary(), mContext.getText(R.string.status_imei));
+ Sliceable.setCopyContent(mContext, getSummary(), mContext.getText(R.string.status_imei));
}
private void updatePreference(Preference preference, int simSlot) {
diff --git a/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java b/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
index a0449f2..153aa40 100644
--- a/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
+++ b/src/com/android/settings/fuelgauge/batterytip/StatsManagerConfig.java
@@ -65,6 +65,11 @@
AnomalyType.EXCESSIVE_CRASH_RATE,
AnomalyType.EXCESSIVE_CRASH_LOOPING,
AnomalyType.NUMBER_OF_OPEN_FILES,
+ AnomalyType.EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_CONTACT_ACCESS,
+ AnomalyType.EXCESSIVE_AUDIO_IN_BACKGROUND,
+ AnomalyType.EXCESSIVE_CRASH_ANR_IN_BACKGROUND,
+ AnomalyType.BATTERY_DRAIN_FROM_UNUSED_APP,
})
public @interface AnomalyType {
/**
@@ -218,6 +223,42 @@
* The application crashed because no more file descriptors were available.
*/
int NUMBER_OF_OPEN_FILES = 26;
+
+ /**
+ * The application used an excessive amount of CPU while in a
+ * background process state.
+ */
+ int EXCESSIVE_CPU_USAGE_IN_BACKGROUND = 27;
+
+ /**
+ * The application kept the camera open for an excessive amount
+ * of time while in a bckground process state.
+ */
+ int EXCESSIVE_CAMERA_USAGE_IN_BACKGROUND = 28;
+
+ /**
+ * The application has accessed the contacts content provider an
+ * excessive amount.
+ */
+ int EXCESSIVE_CONTACT_ACCESS = 29;
+
+ /**
+ * The application has played too much audio while in a background
+ * process state.
+ */
+ int EXCESSIVE_AUDIO_IN_BACKGROUND = 30;
+
+ /**
+ * The application has crashed or ANRed too many times while in a
+ * background process state.
+ */
+ int EXCESSIVE_CRASH_ANR_IN_BACKGROUND = 31;
+
+ /**
+ * An application which has not been used by the user recently
+ * was detected to cause an excessive amount of battery drain.
+ */
+ int BATTERY_DRAIN_FROM_UNUSED_APP = 32;
}
}
diff --git a/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java b/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java
index 35ff2ec..e21bb75 100644
--- a/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java
+++ b/src/com/android/settings/gestures/PreventRingingSwitchPreferenceController.java
@@ -61,6 +61,17 @@
LayoutPreference pref = screen.findPreference(getPreferenceKey());
if (pref != null) {
mSettingObserver = new SettingObserver(pref);
+ pref.setOnPreferenceClickListener(preference -> {
+ int preventRinging = Settings.Secure.getInt(mContext.getContentResolver(),
+ Settings.Secure.VOLUME_HUSH_GESTURE,
+ Settings.Secure.VOLUME_HUSH_VIBRATE);
+ boolean isChecked = preventRinging != Settings.Secure.VOLUME_HUSH_OFF;
+ Settings.Secure.putInt(mContext.getContentResolver(),
+ Settings.Secure.VOLUME_HUSH_GESTURE, isChecked
+ ? Settings.Secure.VOLUME_HUSH_OFF
+ : Settings.Secure.VOLUME_HUSH_VIBRATE);
+ return true;
+ });
mSwitch = pref.findViewById(R.id.switch_bar);
if (mSwitch != null) {
mSwitch.addOnSwitchChangeListener(this);
diff --git a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
index 42e18ed..d6ea6ca 100644
--- a/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
+++ b/src/com/android/settings/homepage/contextualcards/ContextualCardLoader.java
@@ -23,6 +23,7 @@
import android.content.Context;
import android.database.ContentObserver;
import android.database.Cursor;
+import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.text.format.DateUtils;
diff --git a/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java b/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java
index e278baa..48a9aa5 100644
--- a/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/deviceinfo/DeviceInfoSlice.java
@@ -36,7 +36,7 @@
import com.android.settings.R;
import com.android.settings.SubSettings;
import com.android.settings.Utils;
-import com.android.settings.deviceinfo.DeviceModelPreferenceController;
+import com.android.settings.deviceinfo.HardwareInfoPreferenceController;
import com.android.settings.deviceinfo.aboutphone.MyDeviceInfoFragment;
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.slices.CustomSliceable;
@@ -107,7 +107,7 @@
}
private CharSequence getDeviceModel() {
- return DeviceModelPreferenceController.getDeviceModel();
+ return HardwareInfoPreferenceController.getDeviceModel();
}
@VisibleForTesting
diff --git a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java b/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
index 5b5d474..9b912a8 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/BatteryFixSlice.java
@@ -80,7 +80,7 @@
public Slice getSlice() {
final ListBuilder sliceBuilder =
new ListBuilder(mContext, BATTERY_FIX_SLICE_URI, ListBuilder.INFINITY)
- .setAccentColor(-1);
+ .setAccentColor(COLOR_NOT_TINTED);
// TipType.SUMMARY is battery good
if (UNIMPORTANT_BATTERY_TIPS.contains(readBatteryTipAvailabilityCache(mContext))) {
diff --git a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
index 0152614..ae8b80a 100644
--- a/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
+++ b/src/com/android/settings/homepage/contextualcards/slices/NotificationChannelSlice.java
@@ -142,7 +142,8 @@
@Override
public Slice getSlice() {
final ListBuilder listBuilder =
- new ListBuilder(mContext, getUri(), ListBuilder.INFINITY).setAccentColor(-1);
+ new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
+ .setAccentColor(COLOR_NOT_TINTED);
/**
* Get package which is satisfied with:
* 1. Recently installed.
diff --git a/src/com/android/settings/nfc/NfcPreferenceController.java b/src/com/android/settings/nfc/NfcPreferenceController.java
index 04f288d..2ca3b23 100644
--- a/src/com/android/settings/nfc/NfcPreferenceController.java
+++ b/src/com/android/settings/nfc/NfcPreferenceController.java
@@ -15,20 +15,26 @@
*/
package com.android.settings.nfc;
+import android.content.BroadcastReceiver;
import android.content.Context;
+import android.content.Intent;
import android.content.IntentFilter;
+import android.net.Uri;
import android.nfc.NfcAdapter;
import android.provider.Settings;
-
+import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.slices.SliceBackgroundWorker;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnPause;
import com.android.settingslib.core.lifecycle.events.OnResume;
+import java.io.IOException;
+
public class NfcPreferenceController extends TogglePreferenceController
implements LifecycleObserver, OnResume, OnPause {
@@ -51,8 +57,7 @@
return;
}
- final SwitchPreference switchPreference =
- (SwitchPreference) screen.findPreference(getPreferenceKey());
+ final SwitchPreference switchPreference = screen.findPreference(getPreferenceKey());
mNfcEnabler = new NfcEnabler(mContext, switchPreference);
@@ -87,14 +92,6 @@
}
@Override
- public IntentFilter getIntentFilter() {
- final IntentFilter filter = new IntentFilter();
- filter.addAction(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
- filter.addAction(NfcAdapter.EXTRA_ADAPTER_STATE);
- return filter;
- }
-
- @Override
public boolean hasAsyncUpdate() {
return true;
}
@@ -105,6 +102,11 @@
}
@Override
+ public Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
+ return NfcSliceWorker.class;
+ }
+
+ @Override
public void onResume() {
if (mAirplaneModeObserver != null) {
mAirplaneModeObserver.register();
@@ -135,4 +137,77 @@
Settings.Global.AIRPLANE_MODE_TOGGLEABLE_RADIOS);
return toggleable != null && toggleable.contains(Settings.Global.RADIO_NFC);
}
+
+ /**
+ * Listener for background changes to NFC.
+ *
+ * <p>
+ * Listen to broadcasts from {@link NfcAdapter}. The worker will call notify changed on the
+ * NFC Slice only when the following extras are present in the broadcast:
+ * <ul>
+ * <li>{@link NfcAdapter#STATE_ON}</li>
+ * <li>{@link NfcAdapter#STATE_OFF}</li>
+ * </ul>
+ */
+ public static class NfcSliceWorker extends SliceBackgroundWorker<Void> {
+
+ private static final String TAG = "NfcSliceWorker";
+
+ private static final IntentFilter NFC_FILTER =
+ new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+
+ private NfcUpdateReceiver mUpdateObserver;
+
+ public NfcSliceWorker(Context context, Uri uri) {
+ super(context, uri);
+ mUpdateObserver = new NfcUpdateReceiver(this);
+ }
+
+ @Override
+ protected void onSlicePinned() {
+ getContext().registerReceiver(mUpdateObserver, NFC_FILTER);
+ }
+
+ @Override
+ protected void onSliceUnpinned() {
+ getContext().unregisterReceiver(mUpdateObserver);
+ }
+
+ @Override
+ public void close() throws IOException {
+ mUpdateObserver = null;
+ }
+
+ public void updateSlice() {
+ notifySliceChange();
+ }
+
+ public class NfcUpdateReceiver extends BroadcastReceiver {
+
+ private final int NO_EXTRA = -1;
+
+ private final NfcSliceWorker mSliceBackgroundWorker;
+
+ public NfcUpdateReceiver(NfcSliceWorker sliceWorker) {
+ mSliceBackgroundWorker = sliceWorker;
+ }
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ final int nfcStateExtra = intent.getIntExtra(NfcAdapter.EXTRA_ADAPTER_STATE,
+ NO_EXTRA);
+
+ // Do nothing if state change is empty, or an intermediate step.
+ if ( (nfcStateExtra == NO_EXTRA)
+ || (nfcStateExtra == NfcAdapter.STATE_TURNING_ON)
+ || (nfcStateExtra == NfcAdapter.STATE_TURNING_OFF)) {
+ Log.d(TAG, "Transitional update, dropping broadcast");
+ return;
+ }
+
+ Log.d(TAG, "Nfc broadcast received, updating Slice.");
+ mSliceBackgroundWorker.updateSlice();
+ }
+ }
+ }
}
diff --git a/src/com/android/settings/notification/NotificationAssistantPreferenceController.java b/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
index 5c591b8..66f27fe 100644
--- a/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
+++ b/src/com/android/settings/notification/NotificationAssistantPreferenceController.java
@@ -16,18 +16,46 @@
package com.android.settings.notification;
+import android.content.ComponentName;
import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.UserHandle;
import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.applications.DefaultAppInfo;
+import com.android.settingslib.widget.CandidateInfo;
+
+import com.google.common.annotations.VisibleForTesting;
public class NotificationAssistantPreferenceController extends BasePreferenceController {
+ @VisibleForTesting
+ protected NotificationBackend mNotificationBackend;
+ private PackageManager mPackageManager;
+
public NotificationAssistantPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
+ mNotificationBackend = new NotificationBackend();
+ mPackageManager = mContext.getPackageManager();
}
@Override
public int getAvailabilityStatus() {
return BasePreferenceController.AVAILABLE;
}
+
+ @Override
+ public CharSequence getSummary() {
+ CandidateInfo appSelected = new NotificationAssistantPicker.CandidateNone(mContext);
+ ComponentName assistant = mNotificationBackend.getAllowedNotificationAssistant();
+ if (assistant != null) {
+ appSelected = createCandidateInfo(assistant);
+ }
+ return appSelected.loadLabel();
+ }
+
+ @VisibleForTesting
+ protected CandidateInfo createCandidateInfo(ComponentName cn) {
+ return new DefaultAppInfo(mContext, mPackageManager, UserHandle.myUserId(), cn);
+ }
}
diff --git a/src/com/android/settings/password/ChooseLockGeneric.java b/src/com/android/settings/password/ChooseLockGeneric.java
index cae7d33..cf62112 100644
--- a/src/com/android/settings/password/ChooseLockGeneric.java
+++ b/src/com/android/settings/password/ChooseLockGeneric.java
@@ -238,8 +238,8 @@
UserManager.get(getActivity()),
getArguments(),
getActivity().getIntent().getExtras()).getIdentifier();
- mController =
- new ChooseLockGenericController(getContext(), mUserId, mRequestedMinComplexity);
+ mController = new ChooseLockGenericController(
+ getContext(), mUserId, mRequestedMinComplexity, mLockPatternUtils);
if (ACTION_SET_NEW_PASSWORD.equals(chooseLockAction)
&& UserManager.get(getActivity()).isManagedProfile(mUserId)
&& mLockPatternUtils.isSeparateProfileChallengeEnabled(mUserId)) {
diff --git a/src/com/android/settings/password/ChooseLockGenericController.java b/src/com/android/settings/password/ChooseLockGenericController.java
index 91ca957..62a0063 100644
--- a/src/com/android/settings/password/ChooseLockGenericController.java
+++ b/src/com/android/settings/password/ChooseLockGenericController.java
@@ -27,6 +27,7 @@
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
+import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import java.util.ArrayList;
@@ -43,12 +44,14 @@
@PasswordComplexity private final int mRequestedMinComplexity;
private ManagedLockPasswordProvider mManagedPasswordProvider;
private DevicePolicyManager mDpm;
+ private final LockPatternUtils mLockPatternUtils;
public ChooseLockGenericController(Context context, int userId) {
this(
context,
userId,
- PASSWORD_COMPLEXITY_NONE);
+ PASSWORD_COMPLEXITY_NONE,
+ new LockPatternUtils(context));
}
/**
@@ -56,13 +59,14 @@
* when determining the available screen lock types
*/
public ChooseLockGenericController(Context context, int userId,
- @PasswordComplexity int requestedMinComplexity) {
+ @PasswordComplexity int requestedMinComplexity, LockPatternUtils lockPatternUtils) {
this(
context,
userId,
requestedMinComplexity,
context.getSystemService(DevicePolicyManager.class),
- ManagedLockPasswordProvider.get(context, userId));
+ ManagedLockPasswordProvider.get(context, userId),
+ lockPatternUtils);
}
@VisibleForTesting
@@ -71,12 +75,14 @@
int userId,
@PasswordComplexity int requestedMinComplexity,
DevicePolicyManager dpm,
- ManagedLockPasswordProvider managedLockPasswordProvider) {
+ ManagedLockPasswordProvider managedLockPasswordProvider,
+ LockPatternUtils lockPatternUtils) {
mContext = context;
mUserId = userId;
mRequestedMinComplexity = requestedMinComplexity;
mManagedPasswordProvider = managedLockPasswordProvider;
mDpm = dpm;
+ mLockPatternUtils = lockPatternUtils;
}
/**
@@ -105,6 +111,12 @@
&& !managedProfile; // Swipe doesn't make sense for profiles.
case MANAGED:
return mManagedPasswordProvider.isManagedPasswordChoosable();
+ case PIN:
+ case PATTERN:
+ case PASSWORD:
+ // Hide the secure lock screen options if the device doesn't support the secure lock
+ // screen feature.
+ return mLockPatternUtils.hasSecureLockScreen();
}
return true;
}
diff --git a/src/com/android/settings/slices/Copyable.java b/src/com/android/settings/slices/Copyable.java
deleted file mode 100644
index a480063..0000000
--- a/src/com/android/settings/slices/Copyable.java
+++ /dev/null
@@ -1,51 +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.settings.slices;
-
-import static android.content.Context.CLIPBOARD_SERVICE;
-
-import android.content.ClipData;
-import android.content.ClipboardManager;
-import android.content.Context;
-import android.widget.Toast;
-
-import com.android.settings.R;
-
-/**
- * Provide the copy ability for preference controller to copy the data to the clipboard.
- */
-public interface Copyable {
- /**
- * Copy the key slice information to the clipboard.
- * It is highly recommended to show the toast to notify users when implemented this function.
- */
- void copy();
-
- /**
- * Set the copy content to the clipboard and show the toast.
- */
- static void setCopyContent(Context context, CharSequence copyContent,
- CharSequence messageTitle) {
- final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(
- CLIPBOARD_SERVICE);
- final ClipData clip = ClipData.newPlainText("text", copyContent);
- clipboard.setPrimaryClip(clip);
-
- final String toast = context.getString(R.string.copyable_slice_toast, messageTitle);
- Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
- }
-}
diff --git a/src/com/android/settings/slices/CustomSliceable.java b/src/com/android/settings/slices/CustomSliceable.java
index d32e266..0b97bed 100644
--- a/src/com/android/settings/slices/CustomSliceable.java
+++ b/src/com/android/settings/slices/CustomSliceable.java
@@ -55,6 +55,11 @@
public interface CustomSliceable extends Sliceable {
/**
+ * The color representing not to be tinted for the slice.
+ */
+ int COLOR_NOT_TINTED = -1;
+
+ /**
* @return an complete instance of the {@link Slice}.
*/
Slice getSlice();
@@ -79,18 +84,6 @@
Intent getIntent();
/**
- * Settings Slices which require background work, such as updating lists should implement a
- * {@link SliceBackgroundWorker} and return it here. An example of background work is updating
- * a list of Wifi networks available in the area.
- *
- * @return a {@link Class<? extends SliceBackgroundWorker>} to perform background work for the
- * slice.
- */
- default Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
- return null;
- }
-
- /**
* Standardize the intents returned to indicate actions by the Slice.
* <p>
* The {@link PendingIntent} is linked to {@link SliceBroadcastReceiver} where the Intent
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index 5c662e5..397b2fc 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -153,7 +153,7 @@
if (filter != null) {
registerIntentToUri(filter, sliceUri);
}
- ThreadUtils.postOnMainThread(() -> startBackgroundWorker(sliceable));
+ ThreadUtils.postOnMainThread(() -> startBackgroundWorker(sliceable, sliceUri));
return;
}
@@ -326,20 +326,19 @@
}
}
- private void startBackgroundWorker(CustomSliceable sliceable) {
+ private void startBackgroundWorker(Sliceable sliceable, Uri uri) {
final Class workerClass = sliceable.getBackgroundWorkerClass();
if (workerClass == null) {
return;
}
- final Uri uri = sliceable.getUri();
if (mPinnedWorkers.containsKey(uri)) {
return;
}
Log.d(TAG, "Starting background worker for: " + uri);
final SliceBackgroundWorker worker = SliceBackgroundWorker.getInstance(
- getContext(), sliceable);
+ getContext(), sliceable, uri);
mPinnedWorkers.put(uri, worker);
worker.onSlicePinned();
}
@@ -397,6 +396,8 @@
registerIntentToUri(filter, uri);
}
+ ThreadUtils.postOnMainThread(() -> startBackgroundWorker(controller, uri));
+
final List<Uri> pinnedSlices = getContext().getSystemService(
SliceManager.class).getPinnedSlices();
if (pinnedSlices.contains(uri)) {
diff --git a/src/com/android/settings/slices/SliceBackgroundWorker.java b/src/com/android/settings/slices/SliceBackgroundWorker.java
index 995394e..559aa71 100644
--- a/src/com/android/settings/slices/SliceBackgroundWorker.java
+++ b/src/com/android/settings/slices/SliceBackgroundWorker.java
@@ -80,13 +80,12 @@
* Returns the singleton instance of the {@link SliceBackgroundWorker} for specified {@link
* CustomSliceable}
*/
- static SliceBackgroundWorker getInstance(Context context, CustomSliceable sliceable) {
- final Uri uri = sliceable.getUri();
+ static SliceBackgroundWorker getInstance(Context context, Sliceable sliceable, Uri uri) {
SliceBackgroundWorker worker = getInstance(uri);
if (worker == null) {
final Class<? extends SliceBackgroundWorker> workerClass =
sliceable.getBackgroundWorkerClass();
- worker = createInstance(context, uri, workerClass);
+ worker = createInstance(context.getApplicationContext(), uri, workerClass);
LIVE_WORKERS.put(uri, worker);
}
return worker;
diff --git a/src/com/android/settings/slices/SliceBroadcastReceiver.java b/src/com/android/settings/slices/SliceBroadcastReceiver.java
index 061cf18..b2ea583 100644
--- a/src/com/android/settings/slices/SliceBroadcastReceiver.java
+++ b/src/com/android/settings/slices/SliceBroadcastReceiver.java
@@ -184,7 +184,7 @@
final BasePreferenceController controller = getPreferenceController(context, key);
- if (!(controller instanceof Copyable)) {
+ if (!(controller instanceof Sliceable)) {
throw new IllegalArgumentException(
"Copyable action passed for a non-copyable key:" + key);
}
@@ -197,7 +197,7 @@
return;
}
- ((Copyable) controller).copy();
+ controller.copy();
}
/**
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
index 8f85431..c3869a6 100644
--- a/src/com/android/settings/slices/SliceBuilderUtils.java
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -93,7 +93,7 @@
return buildUnavailableSlice(context, sliceData);
}
- if (controller instanceof Copyable) {
+ if (controller.isCopyableSlice()) {
return buildCopyableSlice(context, sliceData, controller);
}
diff --git a/src/com/android/settings/slices/Sliceable.java b/src/com/android/settings/slices/Sliceable.java
index ddec2e1..c1661f8 100644
--- a/src/com/android/settings/slices/Sliceable.java
+++ b/src/com/android/settings/slices/Sliceable.java
@@ -16,7 +16,15 @@
package com.android.settings.slices;
+import static android.content.Context.CLIPBOARD_SERVICE;
+
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
import android.content.IntentFilter;
+import android.widget.Toast;
+
+import com.android.settings.R;
/**
* A collection of API making a PreferenceController "sliceable"
@@ -55,4 +63,44 @@
default boolean hasAsyncUpdate() {
return false;
}
+
+ /**
+ * Copy the key slice information to the clipboard.
+ * It is highly recommended to show the toast to notify users when implemented this function.
+ */
+ default void copy() {
+ }
+
+ /**
+ * Whether or not it's a copyable slice.
+ */
+ default boolean isCopyableSlice() {
+ return false;
+ }
+
+ /**
+ * Set the copy content to the clipboard and show the toast.
+ */
+ static void setCopyContent(Context context, CharSequence copyContent,
+ CharSequence messageTitle) {
+ final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(
+ CLIPBOARD_SERVICE);
+ final ClipData clip = ClipData.newPlainText("text", copyContent);
+ clipboard.setPrimaryClip(clip);
+
+ final String toast = context.getString(R.string.copyable_slice_toast, messageTitle);
+ Toast.makeText(context, toast, Toast.LENGTH_SHORT).show();
+ }
+
+ /**
+ * Settings Slices which require background work, such as updating lists should implement a
+ * {@link SliceBackgroundWorker} and return it here. An example of background work is updating
+ * a list of Wifi networks available in the area.
+ *
+ * @return a {@link Class<? extends SliceBackgroundWorker>} to perform background work for the
+ * slice.
+ */
+ default Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
+ return null;
+ }
}
diff --git a/src/com/android/settings/wifi/AddNetworkFragment.java b/src/com/android/settings/wifi/AddNetworkFragment.java
index 651b25f..81b6c85 100644
--- a/src/com/android/settings/wifi/AddNetworkFragment.java
+++ b/src/com/android/settings/wifi/AddNetworkFragment.java
@@ -19,12 +19,14 @@
import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.Intent;
+import android.net.wifi.WifiConfiguration;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageButton;
+import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
@@ -40,7 +42,10 @@
final static int SUBMIT_BUTTON_ID = android.R.id.button1;
@VisibleForTesting
final static int CANCEL_BUTTON_ID = android.R.id.button2;
- final static int SCANNER_BUTTON_ID = R.id.ssid_scanner_button;
+ final static int SSID_SCANNER_BUTTON_ID = R.id.ssid_scanner_button;
+ final static int PASSWORD_SCANNER_BUTTON_ID = R.id.password_scanner_button;
+
+ private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
private WifiConfigController mUIController;
private Button mSubmitBtn;
@@ -68,10 +73,12 @@
mSubmitBtn = rootView.findViewById(SUBMIT_BUTTON_ID);
mCancelBtn = rootView.findViewById(CANCEL_BUTTON_ID);
- final ImageButton scannerButton = rootView.findViewById(SCANNER_BUTTON_ID);
+ final ImageButton ssidScannerButton = rootView.findViewById(SSID_SCANNER_BUTTON_ID);
+ final ImageButton passwordScannerButton = rootView.findViewById(PASSWORD_SCANNER_BUTTON_ID);
mSubmitBtn.setOnClickListener(this);
mCancelBtn.setOnClickListener(this);
- scannerButton.setOnClickListener(this);
+ ssidScannerButton.setOnClickListener(this);
+ passwordScannerButton.setOnClickListener(this);
mUIController = new WifiConfigController(this, rootView, null, getMode());
return rootView;
@@ -85,6 +92,8 @@
@Override
public void onClick(View view) {
+ String ssid = null;
+
switch (view.getId()) {
case SUBMIT_BUTTON_ID:
handleSubmitAction();
@@ -92,15 +101,34 @@
case CANCEL_BUTTON_ID:
handleCancelAction();
break;
- case SCANNER_BUTTON_ID:
+ case SSID_SCANNER_BUTTON_ID:
+ final TextView ssidEditText = getView().findViewById(R.id.ssid);
+ ssid = ssidEditText.getText().toString();
+ // No break and flows to case PASSWORD_SCANNER_BUTTON_ID
+ case PASSWORD_SCANNER_BUTTON_ID:
// Launch QR code scanner to join a network.
- getContext().startActivity(
- WifiDppUtils.getEnrolleeQrCodeScannerIntent(/* ssid */ null));
+ startActivityForResult(WifiDppUtils.getEnrolleeQrCodeScannerIntent(ssid),
+ REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER);
break;
}
}
@Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ if (requestCode == REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER) {
+ if (resultCode != Activity.RESULT_OK) {
+ return;
+ }
+
+ final WifiConfiguration config = data.getParcelableExtra(
+ WifiDialogActivity.KEY_WIFI_CONFIGURATION);
+ successfullyFinish(config);
+ }
+ }
+
+ @Override
public int getMode() {
return WifiConfigUiBase.MODE_CONNECT;
}
@@ -158,9 +186,13 @@
@VisibleForTesting
void handleSubmitAction() {
+ successfullyFinish(mUIController.getConfig());
+ }
+
+ private void successfullyFinish(WifiConfiguration config) {
final Intent intent = new Intent();
final Activity activity = getActivity();
- intent.putExtra(WIFI_CONFIG_KEY, mUIController.getConfig());
+ intent.putExtra(WIFI_CONFIG_KEY, config);
activity.setResult(Activity.RESULT_OK, intent);
activity.finish();
}
diff --git a/src/com/android/settings/wifi/WifiDialog.java b/src/com/android/settings/wifi/WifiDialog.java
index 7d5f3b3..fbea824 100644
--- a/src/com/android/settings/wifi/WifiDialog.java
+++ b/src/com/android/settings/wifi/WifiDialog.java
@@ -18,15 +18,16 @@
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
+import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import com.android.settings.R;
-import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.android.settingslib.wifi.AccessPoint;
@@ -40,6 +41,9 @@
default void onSubmit(WifiDialog dialog) {
}
+
+ default void onScan(WifiDialog dialog, String ssid) {
+ }
}
private static final int BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE;
@@ -80,18 +84,6 @@
@Override
protected void onCreate(Bundle savedInstanceState) {
mView = getLayoutInflater().inflate(R.layout.wifi_dialog, /* root */ null);
- final ImageButton scannerButton = mView.findViewById(R.id.password_scanner_button);
- if (scannerButton != null) {
- scannerButton.setOnClickListener((View v) -> {
- String ssid = null;
- if (mAccessPoint != null) {
- ssid = mAccessPoint.getSsidStr();
- }
- // Launch QR code scanner to join a network.
- getContext().startActivity(
- WifiDppUtils.getEnrolleeQrCodeScannerIntent(ssid));
- });
- }
setView(mView);
mController = new WifiConfigController(this, mView, mAccessPoint, mMode);
super.onCreate(savedInstanceState);
@@ -109,6 +101,35 @@
}
}
+ @Override
+ protected void onStart() {
+ View.OnClickListener onClickScannerButtonListener = v -> {
+ if (mListener == null) {
+ return;
+ }
+
+ String ssid = null;
+ if (mAccessPoint == null) {
+ final TextView ssidEditText = findViewById(R.id.ssid);
+ ssid = ssidEditText.getText().toString();
+ } else {
+ ssid = mAccessPoint.getSsidStr();
+ }
+ mListener.onScan(/* WifiDialog */ this, ssid);
+ };
+
+ final ImageButton ssidScannerButton = findViewById(R.id.ssid_scanner_button);
+ ssidScannerButton.setOnClickListener(onClickScannerButtonListener);
+
+ final ImageButton passwordScannerButton = findViewById(R.id.password_scanner_button);
+ passwordScannerButton.setOnClickListener(onClickScannerButtonListener);
+
+ if (mHideSubmitButton) {
+ ssidScannerButton.setVisibility(View.GONE);
+ passwordScannerButton.setVisibility(View.GONE);
+ }
+ }
+
public void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
mController.updatePassword();
diff --git a/src/com/android/settings/wifi/WifiDialogActivity.java b/src/com/android/settings/wifi/WifiDialogActivity.java
index c32bcf3..35de66e 100644
--- a/src/com/android/settings/wifi/WifiDialogActivity.java
+++ b/src/com/android/settings/wifi/WifiDialogActivity.java
@@ -29,6 +29,7 @@
import androidx.annotation.VisibleForTesting;
import com.android.settings.SetupWizardUtils;
+import com.android.settings.wifi.dpp.WifiDppUtils;
import com.android.settingslib.wifi.AccessPoint;
import com.google.android.setupcompat.util.WizardManagerHelper;
@@ -49,10 +50,13 @@
@VisibleForTesting
static final String KEY_CONNECT_FOR_CALLER = "connect_for_caller";
- private static final String KEY_WIFI_CONFIGURATION = "wifi_configuration";
+ public static final String KEY_WIFI_CONFIGURATION = "wifi_configuration";
+
private static final int RESULT_CONNECTED = RESULT_FIRST_USER;
private static final int RESULT_FORGET = RESULT_FIRST_USER + 1;
+ private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
+
private WifiDialog mDialog;
@Override
@@ -162,4 +166,25 @@
mDialog = null;
finish();
}
+
+ @Override
+ public void onScan(WifiDialog dialog, String ssid) {
+ // Launch QR code scanner to join a network.
+ startActivityForResult(WifiDppUtils.getEnrolleeQrCodeScannerIntent(ssid),
+ REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER);
+ }
+
+ @Override
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ if (requestCode == REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER) {
+ if (resultCode != RESULT_OK) {
+ return;
+ }
+
+ setResult(RESULT_CONNECTED, data);
+ finish();
+ }
+ }
}
diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java
index 4ca9f86..27c495e 100644
--- a/src/com/android/settings/wifi/WifiSettings.java
+++ b/src/com/android/settings/wifi/WifiSettings.java
@@ -117,6 +117,8 @@
private static final String PREF_KEY_SAVED_NETWORKS = "saved_networks";
private static final String PREF_KEY_STATUS_MESSAGE = "wifi_status_message";
+ private static final int REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER = 0;
+
private static boolean isVerboseLoggingEnabled() {
return WifiTracker.sVerboseLogging || Log.isLoggable(TAG, Log.VERBOSE);
}
@@ -427,10 +429,17 @@
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
- // Only handle request comes from AddNetworkFragment
if (requestCode == ADD_NETWORK_REQUEST) {
handleAddNetworkRequest(resultCode, data);
return;
+ } else if (requestCode == REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER) {
+ if (resultCode == Activity.RESULT_OK) {
+ if (mDialog != null) {
+ mDialog.dismiss();
+ }
+ mWifiTracker.resumeScanning();
+ }
+ return;
}
final boolean formerlyRestricted = mIsRestricted;
@@ -1065,6 +1074,13 @@
}
}
+ @Override
+ public void onScan(WifiDialog dialog, String ssid) {
+ // Launch QR code scanner to join a network.
+ startActivityForResult(WifiDppUtils.getEnrolleeQrCodeScannerIntent(ssid),
+ REQUEST_CODE_WIFI_DPP_ENROLLEE_QR_CODE_SCANNER);
+ }
+
/* package */ void submit(WifiConfigController configController) {
final WifiConfiguration config = configController.getConfig();
diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
index 671624e..53b1530 100644
--- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
+++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java
@@ -371,9 +371,6 @@
// Update whether the forget button should be displayed.
mButtonsPref.setButton1Visible(canForgetNetwork());
-
- // TODO(b/124700405): Check if showing share button is fine to added for saved network
- mButtonsPref.setButton3Visible(false);
}
private void updateLiveNetworkInfo() {
diff --git a/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
index 97b2ebe..9e731ba 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppAddDeviceFragment.java
@@ -172,6 +172,9 @@
mLatestStatusCode = code;
}
+ if (isGoingInitiator()) {
+ mSummary.setText(R.string.wifi_dpp_sharing_wifi_with_this_device);
+ }
mProgressBar.setVisibility(isGoingInitiator() ? View.VISIBLE : View.INVISIBLE);
mButtonRight.setVisibility(isGoingInitiator() ? View.INVISIBLE : View.VISIBLE);
}
@@ -255,7 +258,7 @@
mTitle.setText(information);
}
- mSummary.setText(getString(R.string.wifi_dpp_add_device_to_wifi, getSsid()));
+ updateSummary();
mWifiApPictureView = view.findViewById(R.id.wifi_ap_picture_view);
mChooseDifferentNetwork = view.findViewById(R.id.choose_different_network);
@@ -273,6 +276,7 @@
mProgressBar.setVisibility(View.VISIBLE);
mButtonRight.setVisibility(View.INVISIBLE);
startWifiDppConfiguratorInitiator();
+ updateSummary();
});
if (savedInstanceState != null) {
@@ -342,4 +346,12 @@
return model.isGoingInitiator();
}
+
+ private void updateSummary() {
+ if (isGoingInitiator()) {
+ mSummary.setText(R.string.wifi_dpp_sharing_wifi_with_this_device);
+ } else {
+ mSummary.setText(getString(R.string.wifi_dpp_add_device_to_wifi, getSsid()));
+ }
+ }
}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
index e664a05..a19069b 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppQrCodeScannerFragment.java
@@ -31,7 +31,6 @@
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
-import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.util.Size;
@@ -48,6 +47,7 @@
import androidx.lifecycle.ViewModelProviders;
import com.android.settings.R;
+import com.android.settings.wifi.WifiDialogActivity;
import com.android.settings.wifi.qrcode.QrCamera;
import com.android.settings.wifi.qrcode.QrDecorateView;
@@ -77,6 +77,7 @@
// Key for Bundle usage
private static final String KEY_IS_CONFIGURATOR_MODE = "key_is_configurator_mode";
private static final String KEY_LATEST_ERROR_CODE = "key_latest_error_code";
+ private static final String KEY_WIFI_CONFIGURATION = "key_wifi_configuration";
private ProgressBar mProgressBar;
private QrCamera mCamera;
@@ -93,6 +94,9 @@
/** QR code data scanned by camera */
private WifiQrCode mWifiQrCode;
+ /** The WifiConfiguration connecting for enrollee usage */
+ private WifiConfiguration mWifiConfiguration;
+
private int mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_FAILURE_NONE;
@Override
@@ -102,6 +106,7 @@
if (savedInstanceState != null) {
mIsConfiguratorMode = savedInstanceState.getBoolean(KEY_IS_CONFIGURATOR_MODE);
mLatestStatusCode = savedInstanceState.getInt(KEY_LATEST_ERROR_CODE);
+ mWifiConfiguration = savedInstanceState.getParcelable(KEY_WIFI_CONFIGURATION);
}
final WifiDppInitiatorViewModel model =
@@ -224,13 +229,7 @@
} else {
mTitle.setText(R.string.wifi_dpp_scan_qr_code);
- String description;
- if (TextUtils.isEmpty(mSsid)) {
- description = getString(R.string.wifi_dpp_scan_qr_code_join_unknown_network, mSsid);
- } else {
- description = getString(R.string.wifi_dpp_scan_qr_code_join_network, mSsid);
- }
- mSummary.setText(description);
+ updateEnrolleeSummary();
}
mErrorMessage = view.findViewById(R.id.error_message);
@@ -410,6 +409,7 @@
if (!mIsConfiguratorMode) {
mProgressBar.setVisibility(View.VISIBLE);
startWifiDppEnrolleeInitiator((WifiQrCode)msg.obj);
+ updateEnrolleeSummary();
}
break;
@@ -417,6 +417,7 @@
mErrorMessage.setVisibility(View.INVISIBLE);
final WifiNetworkConfig wifiNetworkConfig = (WifiNetworkConfig)msg.obj;
+ mWifiConfiguration = wifiNetworkConfig.getWifiConfigurationOrNull();
wifiNetworkConfig.connect(getContext(),
/* listener */ WifiDppQrCodeScannerFragment.this);
break;
@@ -431,6 +432,7 @@
public void onSaveInstanceState(Bundle outState) {
outState.putBoolean(KEY_IS_CONFIGURATOR_MODE, mIsConfiguratorMode);
outState.putInt(KEY_LATEST_ERROR_CODE, mLatestStatusCode);
+ outState.putParcelable(KEY_WIFI_CONFIGURATION, mWifiConfiguration);
super.onSaveInstanceState(outState);
}
@@ -446,6 +448,7 @@
for (WifiConfiguration wifiConfig : wifiConfigs) {
if (wifiConfig.networkId == newNetworkId) {
mLatestStatusCode = WifiDppUtils.EASY_CONNECT_EVENT_SUCCESS;
+ mWifiConfiguration = wifiConfig;
wifiManager.connect(wifiConfig, WifiDppQrCodeScannerFragment.this);
return;
}
@@ -453,6 +456,7 @@
Log.e(TAG, "Invalid networkId " + newNetworkId);
mLatestStatusCode = EasyConnectStatusCallback.EASY_CONNECT_EVENT_FAILURE_GENERIC;
+ updateEnrolleeSummary();
mProgressBar.setVisibility(View.INVISIBLE);
showErrorMessage(getString(R.string.wifi_dpp_check_connection_try_again));
restartCamera();
@@ -520,6 +524,7 @@
}
mLatestStatusCode = code;
+ updateEnrolleeSummary();
mProgressBar.setVisibility(View.INVISIBLE);
restartCamera();
}
@@ -539,9 +544,11 @@
@Override
public void onSuccess() {
- startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
+ final Intent resultIntent = new Intent();
+ resultIntent.putExtra(WifiDialogActivity.KEY_WIFI_CONFIGURATION, mWifiConfiguration);
+
final Activity hostActivity = getActivity();
- hostActivity.setResult(Activity.RESULT_OK);
+ hostActivity.setResult(Activity.RESULT_OK, resultIntent);
hostActivity.finish();
}
@@ -578,4 +585,18 @@
mCamera.start(surfaceTexture);
}
+
+ private void updateEnrolleeSummary() {
+ if (isGoingInitiator()) {
+ mSummary.setText(R.string.wifi_dpp_connecting);
+ } else {
+ String description;
+ if (TextUtils.isEmpty(mSsid)) {
+ description = getString(R.string.wifi_dpp_scan_qr_code_join_unknown_network, mSsid);
+ } else {
+ description = getString(R.string.wifi_dpp_scan_qr_code_join_network, mSsid);
+ }
+ mSummary.setText(description);
+ }
+ }
}
diff --git a/src/com/android/settings/wifi/dpp/WifiDppUtils.java b/src/com/android/settings/wifi/dpp/WifiDppUtils.java
index 24cd1d7..6c991cf 100644
--- a/src/com/android/settings/wifi/dpp/WifiDppUtils.java
+++ b/src/com/android/settings/wifi/dpp/WifiDppUtils.java
@@ -95,6 +95,11 @@
/**
* Returns an intent to launch QR code scanner for Wi-Fi DPP enrollee.
*
+ * After enrollee success, the callee activity will return connecting WifiConfiguration by
+ * putExtra {@code WifiDialogActivity.KEY_WIFI_CONFIGURATION} for
+ * {@code Activity#setResult(int resultCode, Intent data)}. The calling object should check
+ * if it's available before using it.
+ *
* @param ssid The data corresponding to {@code WifiConfiguration} SSID
* @return Intent for launching QR code scanner
*/
diff --git a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
index 979e602..6135cba 100644
--- a/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
+++ b/src/com/android/settings/wifi/dpp/WifiNetworkConfig.java
@@ -228,7 +228,7 @@
/**
* This is a simplified method from {@code WifiConfigController.getConfig()}
*/
- private WifiConfiguration getWifiConfigurationOrNull() {
+ WifiConfiguration getWifiConfigurationOrNull() {
if (!isValidConfig(this)) {
return null;
}
diff --git a/src/com/android/settings/wifi/slice/ContextualWifiSlice.java b/src/com/android/settings/wifi/slice/ContextualWifiSlice.java
index 5761ae5..fa8c267 100644
--- a/src/com/android/settings/wifi/slice/ContextualWifiSlice.java
+++ b/src/com/android/settings/wifi/slice/ContextualWifiSlice.java
@@ -16,26 +16,17 @@
package com.android.settings.wifi.slice;
-import android.annotation.ColorInt;
import android.content.Context;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
-import android.graphics.drawable.Drawable;
-import android.net.NetworkInfo.State;
import android.net.Uri;
import android.net.wifi.WifiSsid;
import android.text.TextUtils;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
-import androidx.core.graphics.drawable.IconCompat;
import androidx.slice.Slice;
-import com.android.settings.R;
-import com.android.settings.Utils;
import com.android.settings.slices.CustomSliceRegistry;
import com.android.settings.slices.CustomSliceable;
-import com.android.settingslib.wifi.AccessPoint;
/**
* {@link CustomSliceable} for Wi-Fi, used by contextual homepage.
@@ -65,36 +56,6 @@
// keep showing this card to keep UI stable, even if wifi connects to a network later.
mPreviouslyDisplayed = true;
- // Reload theme for switching dark mode on/off
- mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
-
return super.getSlice();
}
-
- @Override
- protected IconCompat getAccessPointLevelIcon(AccessPoint accessPoint) {
- final Drawable d = mContext.getDrawable(
- com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
-
- @ColorInt int color;
- if (accessPoint.isActive()) {
- final State state = accessPoint.getNetworkInfo().getState();
- if (state == State.CONNECTED) {
- color = Utils.getColorAccentDefaultColor(mContext);
- } else { // connecting
- color = Utils.getDisabled(mContext, Utils.getColorAttrDefaultColor(mContext,
- android.R.attr.colorControlNormal));
- }
- } else {
- color = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal);
- }
-
- d.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
- return Utils.createIconWithDrawable(d);
- }
-
- @Override
- protected int getSliceAccentColor() {
- return -1;
- }
}
diff --git a/src/com/android/settings/wifi/slice/WifiSlice.java b/src/com/android/settings/wifi/slice/WifiSlice.java
index b4b94e1..679ab8b 100644
--- a/src/com/android/settings/wifi/slice/WifiSlice.java
+++ b/src/com/android/settings/wifi/slice/WifiSlice.java
@@ -26,12 +26,21 @@
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
+import android.graphics.Color;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffColorFilter;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
+import android.net.NetworkInfo;
import android.net.Uri;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.net.wifi.WifiSsid;
import android.os.Bundle;
+import android.text.Spannable;
+import android.text.SpannableString;
import android.text.TextUtils;
+import android.text.style.ForegroundColorSpan;
import androidx.annotation.VisibleForTesting;
import androidx.core.graphics.drawable.IconCompat;
@@ -79,13 +88,15 @@
@Override
public Slice getSlice() {
+ // Reload theme for switching dark mode on/off
+ mContext.getTheme().applyStyle(R.style.Theme_Settings_Home, true /* force */);
+
final boolean isWifiEnabled = isWifiEnabled();
final IconCompat icon = IconCompat.createWithResource(mContext,
R.drawable.ic_settings_wireless);
final String title = mContext.getString(R.string.wifi_settings);
final CharSequence summary = getSummary();
- @ColorInt final int color = getSliceAccentColor();
final PendingIntent toggleAction = getBroadcastIntent(mContext);
final PendingIntent primaryAction = getPrimaryAction();
final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon,
@@ -94,7 +105,7 @@
null /* actionTitle */, isWifiEnabled);
final ListBuilder listBuilder = new ListBuilder(mContext, getUri(), ListBuilder.INFINITY)
- .setAccentColor(color)
+ .setAccentColor(COLOR_NOT_TINTED)
.addRow(new ListBuilder.RowBuilder()
.setTitle(title)
.setSubtitle(summary)
@@ -118,8 +129,7 @@
if (i < apCount) {
listBuilder.addRow(getAccessPointRow(results.get(i)));
} else if (needLoadingRow) {
- listBuilder.addRow(new ListBuilder.RowBuilder()
- .setTitle(mContext.getText(R.string.wifi_empty_list_wifi_on)));
+ listBuilder.addRow(getLoadingRow());
needLoadingRow = false;
} else {
listBuilder.addRow(new ListBuilder.RowBuilder()
@@ -130,11 +140,11 @@
}
private ListBuilder.RowBuilder getAccessPointRow(AccessPoint accessPoint) {
- final CharSequence title = accessPoint.getConfigName();
+ final CharSequence title = getAccessPointName(accessPoint);
final IconCompat levelIcon = getAccessPointLevelIcon(accessPoint);
final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder()
.setTitleItem(levelIcon, ListBuilder.ICON_IMAGE)
- .setTitle(title)
+ .setSubtitle(title)
.setPrimaryAction(SliceAction.create(
getAccessPointAction(accessPoint), levelIcon, ListBuilder.ICON_IMAGE,
title));
@@ -146,14 +156,35 @@
return rowBuilder;
}
- protected IconCompat getAccessPointLevelIcon(AccessPoint accessPoint) {
- return IconCompat.createWithResource(mContext,
- com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
+ private CharSequence getAccessPointName(AccessPoint accessPoint) {
+ final CharSequence name = accessPoint.getConfigName();
+ final Spannable span = new SpannableString(name);
+ @ColorInt final int color = Utils.getColorAttrDefaultColor(mContext,
+ android.R.attr.textColorPrimary);
+ span.setSpan(new ForegroundColorSpan(color), 0, name.length(),
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+ return span;
}
- @ColorInt
- protected int getSliceAccentColor() {
- return Utils.getColorAccentDefaultColor(mContext);
+ private IconCompat getAccessPointLevelIcon(AccessPoint accessPoint) {
+ final Drawable d = mContext.getDrawable(
+ com.android.settingslib.Utils.getWifiIconResource(accessPoint.getLevel()));
+
+ @ColorInt int color;
+ if (accessPoint.isActive()) {
+ final NetworkInfo.State state = accessPoint.getNetworkInfo().getState();
+ if (state == NetworkInfo.State.CONNECTED) {
+ color = Utils.getColorAccentDefaultColor(mContext);
+ } else { // connecting
+ color = Utils.getDisabled(mContext, Utils.getColorAttrDefaultColor(mContext,
+ android.R.attr.colorControlNormal));
+ }
+ } else {
+ color = Utils.getColorAttrDefaultColor(mContext, android.R.attr.colorControlNormal);
+ }
+
+ d.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
+ return Utils.createIconWithDrawable(d);
}
private IconCompat getEndIcon(AccessPoint accessPoint) {
@@ -190,6 +221,18 @@
intent, 0 /* flags */);
}
+ private ListBuilder.RowBuilder getLoadingRow() {
+ final CharSequence title = mContext.getText(R.string.wifi_empty_list_wifi_on);
+
+ // for aligning to the Wi-Fi AP's name
+ final IconCompat emptyIcon = Utils.createIconWithDrawable(
+ new ColorDrawable(Color.TRANSPARENT));
+
+ return new ListBuilder.RowBuilder()
+ .setTitleItem(emptyIcon, ListBuilder.ICON_IMAGE)
+ .setSubtitle(title);
+ }
+
/**
* Update the current wifi status to the boolean value keyed by
* {@link android.app.slice.Slice#EXTRA_TOGGLE_STATE} on {@param intent}.
diff --git a/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
index 1411bc0..e2a1657 100644
--- a/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/RecentAppsPreferenceControllerTest.java
@@ -25,9 +25,9 @@
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -146,6 +146,7 @@
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
+ mController.reloadData();
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@@ -157,13 +158,17 @@
}
@Test
- public void displayPreferenceAndUpdateState_shouldRefreshUi() {
- doNothing().when(mController).refreshUi();
-
+ public void displayPreference_shouldNotReloadData() {
mController.displayPreference(mScreen);
- mController.updateState(mScreen);
- verify(mController, times(2)).refreshUi();
+ verify(mController, never()).reloadData();
+ }
+
+ @Test
+ public void displayPreference_shouldRefreshUi() {
+ mController.displayPreference(mScreen);
+
+ verify(mController).refreshUi();
}
@Test
@@ -174,6 +179,25 @@
}
@Test
+ public void updateState_firstLaunch_shouldNotReloadData() {
+ mController.mIsFirstLaunch = true;
+
+ mController.updateState(mRecentAppsPreference);
+
+ verify(mController, never()).reloadData();
+ }
+
+ @Test
+ public void updateState_afterFirstLaunch_shouldReloadDataAndRefreshUi() {
+ mController.mIsFirstLaunch = false;
+
+ mController.updateState(mRecentAppsPreference);
+
+ verify(mController).reloadData();
+ verify(mController).refreshUi();
+ }
+
+ @Test
public void updateState_threeValidRecentOpenAppsSet_setAppEntityThreeTime() {
final List<UsageStats> stats = new ArrayList<>();
final UsageStats stat1 = new UsageStats();
@@ -203,6 +227,7 @@
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
+ mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -243,6 +268,7 @@
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
+ mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -274,6 +300,7 @@
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
+ mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -314,6 +341,7 @@
// Make sure stat2 is considered an instant app.
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
(InstantAppDataProvider) (ApplicationInfo info) -> info == stat2Entry.info);
+ mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -389,6 +417,7 @@
.thenReturn(new ResolveInfo());
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
+ mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
diff --git a/tests/robotests/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItemTest.java b/tests/robotests/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItemTest.java
index 17703e3..7392fb1 100644
--- a/tests/robotests/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItemTest.java
+++ b/tests/robotests/src/com/android/settings/applications/specialaccess/deviceadmin/DeviceAdminListItemTest.java
@@ -67,7 +67,7 @@
DeviceAdminListItem item = new DeviceAdminListItem(mContext, mDeviceAdminInfo);
- assertThat(item.getKey()).isEqualTo(cn.flattenToShortString());
+ assertThat(item.getKey()).isEqualTo("0@" + cn.flattenToShortString());
assertThat(item.getName()).isEqualTo(label);
assertThat(item.getDescription()).isEqualTo(description);
}
diff --git a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
index 53fac3c..139ef41 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/AdvancedBluetoothDetailsHeaderControllerTest.java
@@ -21,6 +21,7 @@
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.graphics.Bitmap;
@@ -65,6 +66,8 @@
private ImageView mImageView;
@Mock
private CachedBluetoothDevice mCachedDevice;
+ @Mock
+ private BluetoothAdapter mBluetoothAdapter;
private AdvancedBluetoothDetailsHeaderController mController;
private LayoutPreference mLayoutPreference;
@@ -78,6 +81,7 @@
mLayoutPreference = new LayoutPreference(mContext,
LayoutInflater.from(mContext).inflate(R.layout.advanced_bt_entity_header, null));
mController.mLayoutPreference = mLayoutPreference;
+ mController.mBluetoothAdapter = mBluetoothAdapter;
when(mCachedDevice.getDevice()).thenReturn(mBluetoothDevice);
}
@@ -159,6 +163,21 @@
verify(mImageView).setImageBitmap(mBitmap);
}
+ @Test
+ public void onStart_registerCallback() {
+ mController.onStart();
+
+ verify(mBluetoothAdapter).registerMetadataListener(mBluetoothDevice,
+ mController.mMetadataListener, mController.mHandler);
+ }
+
+ @Test
+ public void onStop_unregisterCallback() {
+ mController.onStop();
+
+ verify(mBluetoothAdapter).unregisterMetadataListener(mBluetoothDevice);
+ }
+
private void assertBatteryLevel(LinearLayout linearLayout, int batteryLevel) {
final TextView textView = linearLayout.findViewById(R.id.bt_battery_summary);
assertThat(textView.getText().toString()).isEqualTo(
diff --git a/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java
index 61e650f..0784a61 100644
--- a/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/FileEncryptionPreferenceControllerTest.java
@@ -92,7 +92,7 @@
ReflectionHelpers.setField(mController, "mStorageManager", mStorageManager);
when(mStorageManager.isConvertibleToFBE()).thenReturn(true);
mController.displayPreference(mPreferenceScreen);
- CryptoProperties.type("foobar");
+ CryptoProperties.type(CryptoProperties.type_values.NONE);
mController.updateState(mPreference);
@@ -106,7 +106,7 @@
ReflectionHelpers.setField(mController, "mStorageManager", mStorageManager);
when(mStorageManager.isConvertibleToFBE()).thenReturn(true);
mController.displayPreference(mPreferenceScreen);
- CryptoProperties.type("file");
+ CryptoProperties.type(CryptoProperties.type_values.FILE);
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.java b/tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.java
deleted file mode 100644
index 29d9a7c..0000000
--- a/tests/robotests/src/com/android/settings/deviceinfo/HardwareInfoDialogFragmentTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyString;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.doReturn;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-
-import android.os.SystemProperties;
-import android.view.View;
-
-import androidx.fragment.app.FragmentActivity;
-
-import com.android.settings.R;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.robolectric.Robolectric;
-import org.robolectric.RobolectricTestRunner;
-
-@RunWith(RobolectricTestRunner.class)
-public class HardwareInfoDialogFragmentTest {
-
- private FragmentActivity mActivity;
-
- @Before
- public void setUp() {
- mActivity = Robolectric.setupActivity(FragmentActivity.class);
- }
-
- @Test
- public void display_shouldShowHardwareRevision() {
- final String TEST_HARDWARE_REV = "123";
- SystemProperties.set("ro.boot.hardware.revision", TEST_HARDWARE_REV);
-
- final HardwareInfoDialogFragment fragment = spy(HardwareInfoDialogFragment.newInstance());
- doReturn("").when(fragment).getSerialNumber();
- fragment.show(mActivity.getSupportFragmentManager(), HardwareInfoDialogFragment.TAG);
-
- verify(fragment).setText(
- any(View.class), eq(R.id.model_label), eq(R.id.model_value),
- anyString());
-
- verify(fragment).setText(
- any(View.class), eq(R.id.hardware_rev_label), eq(R.id.hardware_rev_value),
- anyString());
- }
-}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceControllerTest.java
similarity index 60%
rename from tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionDialogControllerTest.java
rename to tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceControllerTest.java
index 0f56164..5f4848f 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BasebandVersionPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * 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.
@@ -16,15 +16,12 @@
package com.android.settings.deviceinfo.firmwareversion;
-import static com.android.settings.deviceinfo.firmwareversion.BasebandVersionDialogController
- .BASEBAND_PROPERTY;
-import static com.android.settings.deviceinfo.firmwareversion.BasebandVersionDialogController
- .BASEBAND_VERSION_LABEL_ID;
-import static com.android.settings.deviceinfo.firmwareversion.BasebandVersionDialogController
- .BASEBAND_VERSION_VALUE_ID;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+import static com.android.settings.deviceinfo.firmwareversion.BasebandVersionPreferenceController.BASEBAND_PROPERTY;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
+import static com.google.common.truth.Truth.assertThat;
+
import static org.robolectric.shadow.api.Shadow.extract;
import android.content.Context;
@@ -36,7 +33,6 @@
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;
@@ -44,44 +40,35 @@
@RunWith(RobolectricTestRunner.class)
@Config(shadows = ShadowConnectivityManager.class)
-public class BasebandVersionDialogControllerTest {
-
- @Mock
- private FirmwareVersionDialogFragment mDialog;
+public class BasebandVersionPreferenceControllerTest {
private Context mContext;
- private BasebandVersionDialogController mController;
+ private BasebandVersionPreferenceController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- when(mDialog.getContext()).thenReturn(mContext);
- mController = new BasebandVersionDialogController(mDialog);
+ mController = new BasebandVersionPreferenceController(mContext, "key");
}
@Test
- public void initialize_wifiOnly_shouldRemoveSettingFromDialog() {
- ShadowConnectivityManager connectivityManager =
+ public void getAvailability_wifiOnly_unavailable() {
+ final ShadowConnectivityManager connectivityManager =
extract(mContext.getSystemService(ConnectivityManager.class));
connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, false);
- mController.initialize();
-
- verify(mDialog).removeSettingFromScreen(BASEBAND_VERSION_LABEL_ID);
- verify(mDialog).removeSettingFromScreen(BASEBAND_VERSION_VALUE_ID);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
@Test
- public void initialize_hasMobile_shouldSetDialogTextToBasebandVersion() {
+ public void getAvailability_hasMobile_available() {
final String text = "test";
SystemProperties.set(BASEBAND_PROPERTY, text);
ShadowConnectivityManager connectivityManager =
extract(mContext.getSystemService(ConnectivityManager.class));
connectivityManager.setNetworkSupported(ConnectivityManager.TYPE_MOBILE, true);
- mController.initialize();
-
- verify(mDialog).setText(BASEBAND_VERSION_VALUE_ID, text);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BuildNumberDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BuildNumberDialogControllerTest.java
deleted file mode 100644
index a1e8813..0000000
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/BuildNumberDialogControllerTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo.firmwareversion;
-
-import static com.android.settings.deviceinfo.firmwareversion.BuildNumberDialogController
- .BUILD_NUMBER_VALUE_ID;
-
-import static org.mockito.Mockito.verify;
-
-import android.os.Build;
-import android.text.BidiFormatter;
-
-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;
-
-@RunWith(RobolectricTestRunner.class)
-public class BuildNumberDialogControllerTest {
-
- @Mock
- private FirmwareVersionDialogFragment mDialog;
-
- private BuildNumberDialogController mController;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- mController = new BuildNumberDialogController(mDialog);
- }
-
- @Test
- public void initialize_shouldUpdateBuildNumberToDialog() {
- mController.initialize();
-
- verify(mDialog)
- .setText(BUILD_NUMBER_VALUE_ID, BidiFormatter.getInstance().unicodeWrap(Build.DISPLAY));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceControllerTest.java
similarity index 64%
rename from tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogControllerTest.java
rename to tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceControllerTest.java
index 0c57941..adfff25 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionDetailPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * 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.
@@ -16,13 +16,9 @@
package com.android.settings.deviceinfo.firmwareversion;
-import static com.android.settings.deviceinfo.firmwareversion.FirmwareVersionDialogController
- .FIRMWARE_VERSION_LABEL_ID;
-import static com.android.settings.deviceinfo.firmwareversion.FirmwareVersionDialogController
- .FIRMWARE_VERSION_VALUE_ID;
+import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
@@ -32,7 +28,8 @@
import android.content.Context;
import android.os.Build;
import android.os.UserManager;
-import android.view.View;
+
+import androidx.preference.Preference;
import org.junit.Before;
import org.junit.Test;
@@ -44,36 +41,30 @@
import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
-public class FirmwareVersionDialogControllerTest {
+public class FirmwareVersionDetailPreferenceControllerTest {
@Mock
private UserManager mUserManager;
- @Mock
- private FirmwareVersionDialogFragment mDialog;
- @Mock
- private View mView;
+ private Preference mPreference;
private Context mContext;
- private FirmwareVersionDialogController mController;
+ private FirmwareVersionDetailPreferenceController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
- when(mDialog.getContext()).thenReturn(mContext);
- mController = spy(new FirmwareVersionDialogController(mDialog));
+ mController = spy(new TestController(mContext, "key"));
+
ReflectionHelpers.setField(mController, "mUserManager", mUserManager);
- doNothing().when(mController).arrayCopy();
- doNothing().when(mController).initializeAdminPermissions();
+
+ mPreference = new Preference(mContext);
+ mPreference.setKey(mController.getPreferenceKey());
}
@Test
- public void initialize_shouldRegisterListenersAndSetBuildVersion() {
- mController.initialize();
-
- verify(mDialog).registerClickListener(eq(FIRMWARE_VERSION_VALUE_ID), any());
- verify(mDialog).registerClickListener(eq(FIRMWARE_VERSION_LABEL_ID), any());
- verify(mDialog).setText(FIRMWARE_VERSION_VALUE_ID, Build.VERSION.RELEASE);
+ public void getSummary_shouldGetBuildVersion() {
+ assertThat(mController.getSummary()).isEqualTo(Build.VERSION.RELEASE);
}
@Test
@@ -82,7 +73,7 @@
hits[0] = Long.MAX_VALUE;
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_FUN)).thenReturn(true);
- mController.onClick(mView);
+ mController.handlePreferenceTreeClick(mPreference);
verify(mContext, never()).startActivity(any());
}
@@ -93,8 +84,19 @@
hits[0] = Long.MAX_VALUE;
when(mUserManager.hasUserRestriction(UserManager.DISALLOW_FUN)).thenReturn(false);
- mController.onClick(mView);
+ mController.handlePreferenceTreeClick(mPreference);
verify(mContext).startActivity(any());
}
+
+ private static class TestController extends FirmwareVersionDetailPreferenceController {
+
+ public TestController(Context context, String key) {
+ super(context, key);
+ }
+
+ @Override
+ void initializeAdminPermissions() {
+ }
+ }
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerTest.java
index 0c74525..77ae4e2 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/FirmwareVersionPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * 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.
@@ -16,42 +16,29 @@
package com.android.settings.deviceinfo.firmwareversion;
-import static android.content.Context.CLIPBOARD_SERVICE;
-
import static com.google.common.truth.Truth.assertThat;
-import android.content.ClipboardManager;
import android.content.Context;
import android.os.Build;
-import androidx.fragment.app.Fragment;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.core.BasePreferenceController;
-import org.junit.After;
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.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-import org.robolectric.annotation.Resetter;
@RunWith(RobolectricTestRunner.class)
public class FirmwareVersionPreferenceControllerTest {
private static final String KEY = "firmware_version";
- @Mock
- private Fragment mFragment;
-
private Preference mPreference;
private PreferenceScreen mScreen;
private FirmwareVersionPreferenceController mController;
@@ -62,22 +49,16 @@
final Context context = RuntimeEnvironment.application;
final PreferenceManager preferenceManager = new PreferenceManager(context);
mController = new FirmwareVersionPreferenceController(context, KEY);
- mController.setHost(mFragment);
mPreference = new Preference(context);
mPreference.setKey(KEY);
mScreen = preferenceManager.createPreferenceScreen(context);
mScreen.addPreference(mPreference);
}
- @After
- public void tearDown() {
- ShadowFirmwareVersionDialogFragment.reset();
- }
-
@Test
public void firmwareVersion_shouldAlwaysBeShown() {
- assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.AVAILABLE);
+ assertThat(mController.getAvailabilityStatus())
+ .isEqualTo(BasePreferenceController.AVAILABLE_UNSEARCHABLE);
}
@Test
@@ -86,55 +67,4 @@
assertThat(mPreference.getSummary()).isEqualTo(Build.VERSION.RELEASE);
}
-
- @Test
- @Config(shadows = ShadowFirmwareVersionDialogFragment.class)
- public void handlePreferenceTreeClick_samePreferenceKey_shouldStartDialogFragment() {
- final boolean result = mController.handlePreferenceTreeClick(mPreference);
-
- assertThat(ShadowFirmwareVersionDialogFragment.isShowing).isTrue();
- assertThat(result).isTrue();
- }
-
- @Test
- public void handlePreferenceTreeClick_unknownPreferenceKey_shouldDoNothingAndReturnFalse() {
- mPreference.setKey("foobar");
-
- final boolean result = mController.handlePreferenceTreeClick(mPreference);
-
- assertThat(ShadowFirmwareVersionDialogFragment.isShowing).isFalse();
- assertThat(result).isFalse();
- }
-
- @Test
- public void isSliceable_shouldBeTrue() {
- assertThat(mController.isSliceable()).isTrue();
- }
-
- @Test
- public void copy_shouldCopyVersionNumberToClipboard() {
- mController.copy();
-
- final Context context = RuntimeEnvironment.application;
- final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(
- CLIPBOARD_SERVICE);
- final CharSequence data = clipboard.getPrimaryClip().getItemAt(0).getText();
- assertThat(data.toString()).isEqualTo(Build.VERSION.RELEASE);
- }
-
- @Implements(FirmwareVersionDialogFragment.class)
- public static class ShadowFirmwareVersionDialogFragment {
-
- private static boolean isShowing = false;
-
- @Implementation
- public static void show(Fragment fragemnt) {
- isShowing = true;
- }
-
- @Resetter
- public static void reset() {
- isShowing = false;
- }
- }
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionDialogControllerTest.java
deleted file mode 100644
index 52af280..0000000
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionDialogControllerTest.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.deviceinfo.firmwareversion;
-
-import static com.android.settings.deviceinfo.firmwareversion.KernelVersionDialogController
- .KERNEL_VERSION_VALUE_ID;
-
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-
-import com.android.settingslib.DeviceInfoUtils;
-
-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;
-
-@RunWith(RobolectricTestRunner.class)
-public class KernelVersionDialogControllerTest {
-
- @Mock
- private FirmwareVersionDialogFragment mDialog;
-
- private Context mContext;
- private KernelVersionDialogController mController;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- mContext = RuntimeEnvironment.application;
- when(mDialog.getContext()).thenReturn(mContext);
- mController = new KernelVersionDialogController(mDialog);
- }
-
- @Test
- public void initialize_shouldUpdateKernelVersionToDialog() {
- mController.initialize();
-
- verify(mDialog)
- .setText(KERNEL_VERSION_VALUE_ID, DeviceInfoUtils.getFormattedKernelVersion(mContext));
- }
-}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceControllerTest.java
new file mode 100644
index 0000000..9ee0bb3
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/KernelVersionPreferenceControllerTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.deviceinfo.firmwareversion;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import com.android.settingslib.DeviceInfoUtils;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class KernelVersionPreferenceControllerTest {
+
+
+ private Context mContext;
+ private KernelVersionPreferenceController mController;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new KernelVersionPreferenceController(mContext, "key");
+ }
+
+ @Test
+ public void getSummary_shouldGetKernalVersion() {
+ assertThat(mController.getSummary()).isEqualTo(
+ DeviceInfoUtils.getFormattedKernelVersion(mContext));
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java
new file mode 100644
index 0000000..2761b2f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/MainlineModuleVersionPreferenceControllerTest.java
@@ -0,0 +1,116 @@
+/*
+ * 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.deviceinfo.firmwareversion;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.anyInt;
+import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageInfo;
+import android.content.pm.PackageManager;
+import android.util.FeatureFlagUtils;
+
+import com.android.settings.core.FeatureFlags;
+
+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;
+
+@RunWith(RobolectricTestRunner.class)
+public class MainlineModuleVersionPreferenceControllerTest {
+
+ @Mock
+ private PackageManager mPackageManager;
+
+ private Context mContext;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, true);
+ }
+
+ @Test
+ public void getAvailabilityStatus_featureDisabled_unavailable() {
+ FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, false);
+
+ final MainlineModuleVersionPreferenceController controller =
+ new MainlineModuleVersionPreferenceController(mContext, "key");
+
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noMainlineModuleProvider_unavailable() {
+ when(mContext.getString(
+ com.android.internal.R.string.config_defaultModuleMetadataProvider)).thenReturn(
+ null);
+
+ final MainlineModuleVersionPreferenceController controller =
+ new MainlineModuleVersionPreferenceController(mContext, "key");
+
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noMainlineModulePackageInfo_unavailable() throws Exception {
+
+ final String provider = "test.provider";
+ when(mContext.getString(
+ com.android.internal.R.string.config_defaultModuleMetadataProvider))
+ .thenReturn(provider);
+ when(mPackageManager.getPackageInfo(eq(provider), anyInt()))
+ .thenThrow(new PackageManager.NameNotFoundException());
+
+ final MainlineModuleVersionPreferenceController controller =
+ new MainlineModuleVersionPreferenceController(mContext, "key");
+
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_hasMainlineModulePackageInfo_available() throws Exception {
+ final String provider = "test.provider";
+ final String version = "test version 123";
+ final PackageInfo info = new PackageInfo();
+ info.versionName = version;
+ when(mContext.getString(
+ com.android.internal.R.string.config_defaultModuleMetadataProvider))
+ .thenReturn(provider);
+ when(mPackageManager.getPackageInfo(eq(provider), anyInt())).thenReturn(info);
+
+ final MainlineModuleVersionPreferenceController controller =
+ new MainlineModuleVersionPreferenceController(mContext, "key");
+
+ assertThat(controller.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogControllerTest.java
deleted file mode 100644
index b84ea99..0000000
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/ModuleVersionDialogControllerTest.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.deviceinfo.firmwareversion;
-
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.util.FeatureFlagUtils;
-
-import com.android.settings.core.FeatureFlags;
-
-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;
-
-@RunWith(RobolectricTestRunner.class)
-public class ModuleVersionDialogControllerTest {
-
- @Mock
- private FirmwareVersionDialogFragment mDialog;
- @Mock
- private PackageManager mPackageManager;
-
- private Context mContext;
- private ModuleVersionDialogController mController;
-
- @Before
- public void setup() {
- MockitoAnnotations.initMocks(this);
- mContext = spy(RuntimeEnvironment.application);
- when(mDialog.getContext()).thenReturn(mContext);
- when(mContext.getPackageManager()).thenReturn(mPackageManager);
- mController = new ModuleVersionDialogController(mDialog);
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, true);
- }
-
- @Test
- public void initialize_featureDisabled_shouldRemoveSettingFromDialog() {
- FeatureFlagUtils.setEnabled(mContext, FeatureFlags.MAINLINE_MODULE, false);
-
- mController.initialize();
-
- verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_LABEL_ID);
- verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_VALUE_ID);
- }
-
- @Test
- public void initialize_noMainlineModuleProvider_shouldRemoveSettingFromDialog() {
- when(mContext.getString(
- com.android.internal.R.string.config_defaultModuleMetadataProvider)).thenReturn(null);
-
- mController.initialize();
-
- verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_LABEL_ID);
- verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_VALUE_ID);
- }
-
- @Test
- public void initialize_noMainlineModulePackageInfo_shouldRemoveSettingFromDialog()
- throws PackageManager.NameNotFoundException {
- final String provider = "test.provider";
- when(mContext.getString(
- com.android.internal.R.string.config_defaultModuleMetadataProvider))
- .thenReturn(provider);
- when(mPackageManager.getPackageInfo(eq(provider), anyInt()))
- .thenThrow(new PackageManager.NameNotFoundException());
-
- mController.initialize();
-
- verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_LABEL_ID);
- verify(mDialog).removeSettingFromScreen(mController.MODULE_VERSION_VALUE_ID);
- }
-
- @Test
- public void initialize_hasMainlineModulePackageInfo_shouldshouldSetDialogTextToMainlineVersion()
- throws PackageManager.NameNotFoundException {
- final String provider = "test.provider";
- final String version = "test version 123";
- final PackageInfo info = new PackageInfo();
- info.versionName = version;
- when(mContext.getString(
- com.android.internal.R.string.config_defaultModuleMetadataProvider))
- .thenReturn(provider);
- when(mPackageManager.getPackageInfo(eq(provider), anyInt())).thenReturn(info);
-
- mController.initialize();
-
- verify(mDialog).setText(mController.MODULE_VERSION_VALUE_ID, version);
- }
-
-}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelDialogControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelPreferenceControllerTest.java
similarity index 62%
rename from tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelDialogControllerTest.java
rename to tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelPreferenceControllerTest.java
index 8c334cc..ccc91e6 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelDialogControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/firmwareversion/SecurityPatchLevelPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * 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.
@@ -16,14 +16,13 @@
package com.android.settings.deviceinfo.firmwareversion;
-import static com.android.settings.deviceinfo.firmwareversion.SecurityPatchLevelDialogController
- .SECURITY_PATCH_LABEL_ID;
-import static com.android.settings.deviceinfo.firmwareversion.SecurityPatchLevelDialogController
- .SECURITY_PATCH_VALUE_ID;
+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.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
-import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -33,7 +32,8 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
-import android.view.View;
+
+import androidx.preference.Preference;
import org.junit.Before;
import org.junit.Test;
@@ -47,55 +47,47 @@
import java.util.Collections;
@RunWith(RobolectricTestRunner.class)
-public class SecurityPatchLevelDialogControllerTest {
+public class SecurityPatchLevelPreferenceControllerTest {
@Mock
private PackageManager mPackageManager;
- @Mock
- private FirmwareVersionDialogFragment mDialog;
- @Mock
- private View mView;
private Context mContext;
- private SecurityPatchLevelDialogController mController;
+ private SecurityPatchLevelPreferenceController mController;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = spy(Robolectric.setupActivity(Activity.class));
- when(mDialog.getContext()).thenReturn(mContext);
}
@Test
- public void initialize_noPatchInfo_shouldRemoveSettingFromDialog() {
+ public void getAvailabilityStatus_noPatchInfo_unavailable() {
ReflectionHelpers.setStaticField(Build.VERSION.class, "SECURITY_PATCH", "");
- mController = new SecurityPatchLevelDialogController(mDialog);
+ mController = new SecurityPatchLevelPreferenceController(mContext, "key");
- mController.initialize();
-
- verify(mDialog).removeSettingFromScreen(SECURITY_PATCH_VALUE_ID);
- verify(mDialog).removeSettingFromScreen(SECURITY_PATCH_LABEL_ID);
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(CONDITIONALLY_UNAVAILABLE);
}
@Test
- public void initialize_patchInfoAvailable_shouldRegisterListeners() {
+ public void getAvailabilityStatus_hasPatchInfo_available() {
ReflectionHelpers.setStaticField(Build.VERSION.class, "SECURITY_PATCH", "foobar");
- mController = new SecurityPatchLevelDialogController(mDialog);
+ mController = new SecurityPatchLevelPreferenceController(mContext, "key");
- mController.initialize();
-
- verify(mDialog).registerClickListener(eq(SECURITY_PATCH_LABEL_ID), any());
- verify(mDialog).registerClickListener(eq(SECURITY_PATCH_VALUE_ID), any());
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@Test
public void onClick_noActivityIntent_shouldDoNothing() {
when(mPackageManager.queryIntentActivities(any(), anyInt()))
.thenReturn(Collections.emptyList());
- mController = new SecurityPatchLevelDialogController(mDialog);
+ mController = new SecurityPatchLevelPreferenceController(mContext, "key");
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
- mController.onClick(mView);
+ final Preference pref = new Preference(mContext);
+ pref.setKey(mController.getPreferenceKey());
+
+ mController.handlePreferenceTreeClick(pref);
verify(mContext, never()).startActivity(any());
}
@@ -104,10 +96,14 @@
public void onClick_activityIntentFound_shouldStartActivity() {
when(mPackageManager.queryIntentActivities(any(), anyInt()))
.thenReturn(Collections.singletonList(null));
- mController = new SecurityPatchLevelDialogController(mDialog);
+
+ mController = new SecurityPatchLevelPreferenceController(mContext, "key");
ReflectionHelpers.setField(mController, "mPackageManager", mPackageManager);
- mController.onClick(mView);
+ final Preference pref = new Preference(mContext);
+ pref.setKey(mController.getPreferenceKey());
+
+ mController.handlePreferenceTreeClick(pref);
verify(mContext).startActivity(any());
}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceControllerTest.java
new file mode 100644
index 0000000..1204c44
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/DeviceModelPreferenceControllerTest.java
@@ -0,0 +1,64 @@
+/*
+ * 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.deviceinfo.hardwareinfo;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import com.android.settings.core.BasePreferenceController;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(RobolectricTestRunner.class)
+public class DeviceModelPreferenceControllerTest {
+
+ private Context mContext;
+ private DeviceModelPreferenceController mController;
+
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mController = new DeviceModelPreferenceController(mContext, "test_key");
+ }
+
+ @Test
+ public void getAvailabilityStatus_configAllowed_available() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.AVAILABLE);
+ }
+
+ @Test
+ @Config(qualifiers = "mcc999")
+ public void getAvailabilityStatus_configDisallowed_unavailable() {
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(
+ BasePreferenceController.UNSUPPORTED_ON_DEVICE);
+ }
+
+ @Test
+ public void isAlwaysSliceable() {
+ assertThat(mController.isSliceable()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoPreferenceControllerTest.java
similarity index 64%
rename from tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java
rename to tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoPreferenceControllerTest.java
index 6418cf8..413c492 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/DeviceModelPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/HardwareInfoPreferenceControllerTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2017 The Android Open Source Project
+ * 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.
@@ -13,56 +13,44 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.android.settings.deviceinfo;
+package com.android.settings.deviceinfo.hardwareinfo;
import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.eq;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
import android.content.Context;
import android.os.Build;
-import androidx.fragment.app.Fragment;
-import androidx.fragment.app.FragmentManager;
-import androidx.fragment.app.FragmentTransaction;
import androidx.preference.Preference;
import androidx.preference.PreferenceManager;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
+import com.android.settings.deviceinfo.HardwareInfoPreferenceController;
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;
@RunWith(RobolectricTestRunner.class)
-public class DeviceModelPreferenceControllerTest {
+public class HardwareInfoPreferenceControllerTest {
private final String KEY = "device_model";
- @Mock
- private Fragment mFragment;
private Preference mPreference;
private PreferenceScreen mPreferenceScreen;
private Context mContext;
- private DeviceModelPreferenceController mController;
+ private HardwareInfoPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mController = new DeviceModelPreferenceController(mContext, KEY);
- mController.setHost(mFragment);
+ mController = new HardwareInfoPreferenceController(mContext, KEY);
mPreference = new Preference(mContext);
mPreference.setKey(KEY);
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
@@ -73,7 +61,7 @@
@Test
public void isAvailable_returnTrueIfVisible() {
assertThat(mController.getAvailabilityStatus()).isEqualTo(
- BasePreferenceController.AVAILABLE);
+ BasePreferenceController.AVAILABLE_UNSEARCHABLE);
}
@Test
@@ -90,22 +78,6 @@
assertThat(containBuildModel(mPreference.getSummary())).isTrue();
}
- @Test
- public void clickPreference_shouldLaunchHardwareInfoDialog() {
- FragmentManager fragmentManager = mock(FragmentManager.class);
- when(mFragment.getFragmentManager()).thenReturn(fragmentManager);
- when(fragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
-
- assertThat(mController.handlePreferenceTreeClick(mPreference)).isTrue();
- verify(fragmentManager.beginTransaction())
- .add(any(HardwareInfoDialogFragment.class), eq(HardwareInfoDialogFragment.TAG));
- }
-
- @Test
- public void isSliceable_shouldBeTrue() {
- assertThat(mController.isSliceable()).isTrue();
- }
-
private boolean containBuildModel(CharSequence result) {
final String oracle = mContext.getResources().getString(R.string.model_summary,
Build.MODEL);
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceControllerTest.java
new file mode 100644
index 0000000..c2ae4af
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/deviceinfo/hardwareinfo/SerialNumberPreferenceControllerTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.deviceinfo.hardwareinfo;
+
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ClipData;
+import android.content.ClipboardManager;
+import android.content.Context;
+import android.os.Build;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class SerialNumberPreferenceControllerTest {
+
+ private Context mContext;
+ private SerialNumberPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mController = new SerialNumberPreferenceController(mContext, "test");
+ }
+
+ @Test
+ public void isCopyableSlice() {
+ assertThat(mController.isSliceable()).isTrue();
+ assertThat(mController.isCopyableSlice()).isTrue();
+ }
+
+ @Test
+ public void copy_shouldPutSerialNumberToClipBoard() {
+ mController.copy();
+
+ final ClipboardManager clipboardManager = mContext.getSystemService(ClipboardManager.class);
+ final ClipData data = clipboardManager.getPrimaryClip();
+
+ assertThat(data.getItemAt(0).getText().toString()).contains(Build.getSerial());
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java
index 5f221f5..85eeacc 100644
--- a/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/PreventRingingSwitchPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -29,8 +30,10 @@
import android.provider.Settings;
import androidx.preference.Preference;
+import androidx.preference.PreferenceScreen;
import com.android.settings.widget.SwitchBar;
+import com.android.settingslib.widget.LayoutPreference;
import org.junit.Before;
import org.junit.Test;
@@ -95,4 +98,16 @@
mController.updateState(mPreference);
verify(mController.mSwitch, times(1)).setChecked(true);
}
+
+ @Test
+ public void testPreferenceClickListenerAttached() {
+ PreferenceScreen preferenceScreen = mock(PreferenceScreen.class);
+ LayoutPreference mLayoutPreference = mock(LayoutPreference.class);
+ when(preferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+ mLayoutPreference);
+ mController.displayPreference(preferenceScreen);
+
+ verify(mLayoutPreference, times(1))
+ .setOnPreferenceClickListener(any());
+ }
}
diff --git a/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
index 8883ddf..e3672c9 100644
--- a/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/nfc/NfcPreferenceControllerTest.java
@@ -19,10 +19,13 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.content.Intent;
+import android.net.Uri;
import android.nfc.NfcAdapter;
import android.nfc.NfcManager;
import android.os.UserManager;
@@ -31,6 +34,10 @@
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
+import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker;
+import com.android.settings.nfc.NfcPreferenceController.NfcSliceWorker.NfcUpdateReceiver;
+import com.android.settings.slices.SliceBuilderUtils;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -246,4 +253,67 @@
assertThat(mNfcController.mAirplaneModeObserver).isNull();
}
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_noExtra_sliceDoesntUpdate() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker, times(0)).updateSlice();
+ }
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_turningOn_sliceDoesntUpdate() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+ triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_TURNING_ON);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker, times(0)).updateSlice();
+ }
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_turningOff_sliceDoesntUpdate() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+ triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_TURNING_OFF);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker, times(0)).updateSlice();
+ }
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_nfcOn_sliceUpdates() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+ triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_ON);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker).updateSlice();
+ }
+
+ @Test
+ public void ncfSliceWorker_nfcBroadcast_nfcOff_sliceUpdates() {
+ final NfcSliceWorker worker = spy(new NfcSliceWorker(mContext, getDummyUri()));
+ final NfcUpdateReceiver receiver = worker.new NfcUpdateReceiver(worker);
+ final Intent triggerIntent = new Intent(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
+ triggerIntent.putExtra(NfcAdapter.EXTRA_ADAPTER_STATE, NfcAdapter.STATE_OFF);
+
+ receiver.onReceive(mContext, triggerIntent);
+
+ verify(worker).updateSlice();
+ }
+
+ private Uri getDummyUri() {
+ return SliceBuilderUtils.getUri("action/nfc", false);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
new file mode 100644
index 0000000..b2f65e0
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/notification/NotificationAssistantPreferenceControllerTest.java
@@ -0,0 +1,100 @@
+/*
+ * 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.notification;
+
+import static junit.framework.TestCase.assertEquals;
+
+import static org.mockito.Mockito.when;
+
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.graphics.drawable.Drawable;
+import android.os.Debug;
+
+import com.android.settingslib.widget.CandidateInfo;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Answers;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+@RunWith(RobolectricTestRunner.class)
+public class NotificationAssistantPreferenceControllerTest {
+
+ private static final String KEY = "TEST_KEY";
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock
+ private NotificationBackend mBackend;
+ private NotificationAssistantPreferenceController mPreferenceController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mPreferenceController = new TestPreferenceController(mContext, mBackend);
+ }
+
+ @Test
+ public void testGetSummary_noAssistant() {
+ when(mBackend.getAllowedNotificationAssistant()).thenReturn(null);
+ CharSequence noneLabel = new NotificationAssistantPicker.CandidateNone(mContext)
+ .loadLabel();
+ assertEquals(noneLabel, mPreferenceController.getSummary());
+ }
+
+ @Test
+ public void testGetSummary_TestAssistant() {
+ String testName = "test_pkg/test_cls";
+ when(mBackend.getAllowedNotificationAssistant()).thenReturn(
+ ComponentName.unflattenFromString(testName));
+ assertEquals(testName, mPreferenceController.getSummary());
+ }
+
+ private final class TestPreferenceController extends NotificationAssistantPreferenceController {
+
+ private TestPreferenceController(Context context, NotificationBackend backend) {
+ super(context, KEY);
+ mNotificationBackend = backend;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY;
+ }
+
+ @Override
+ protected CandidateInfo createCandidateInfo(ComponentName cn) {
+ return new CandidateInfo(true) {
+ @Override
+ public CharSequence loadLabel() { return cn.flattenToString(); }
+
+ @Override
+ public Drawable loadIcon() { return null; }
+
+ @Override
+ public String getKey() { return null; }
+ };
+ }
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
index 2b7bdeb..4adc01b 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockGenericControllerTest.java
@@ -34,6 +34,7 @@
import android.app.admin.DevicePolicyManager.PasswordComplexity;
import android.content.ComponentName;
+import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.testutils.shadow.SettingsShadowResources;
@@ -61,10 +62,14 @@
@Mock
private DevicePolicyManager mDevicePolicyManager;
+ @Mock
+ private LockPatternUtils mLockPatternUtils;
+
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ when(mLockPatternUtils.hasSecureLockScreen()).thenReturn(true);
mController = createController(PASSWORD_COMPLEXITY_NONE);
SettingsShadowResources.overrideResource(R.bool.config_hide_none_security_option, false);
SettingsShadowResources.overrideResource(R.bool.config_hide_swipe_security_option, false);
@@ -266,6 +271,7 @@
0 /* userId */,
minPasswordComplexity,
mDevicePolicyManager,
- mManagedLockPasswordProvider);
+ mManagedLockPasswordProvider,
+ mLockPatternUtils);
}
}
diff --git a/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java b/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java
index 195c82d..9e8644f 100644
--- a/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/password/ChooseLockTypeDialogFragmentTest.java
@@ -33,6 +33,7 @@
import com.android.settings.R;
import com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
+import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
import org.junit.Before;
import org.junit.Test;
@@ -43,7 +44,7 @@
import org.robolectric.shadows.androidx.fragment.FragmentController;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = ShadowAlertDialogCompat.class)
+@Config(shadows = {ShadowAlertDialogCompat.class, ShadowLockPatternUtils.class})
public class ChooseLockTypeDialogFragmentTest {
private Context mContext;
diff --git a/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java b/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
index e0c6ded..aeb16e6 100644
--- a/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
@@ -34,6 +34,7 @@
import com.android.settings.password.SetupChooseLockPassword.SetupChooseLockPasswordFragment;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
+import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.android.settings.widget.ScrollToParentEditText;
@@ -57,7 +58,13 @@
import java.util.List;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {SettingsShadowResources.class, ShadowUtils.class, ShadowAlertDialogCompat.class})
+@Config(
+ shadows = {
+ SettingsShadowResources.class,
+ ShadowLockPatternUtils.class,
+ ShadowUtils.class,
+ ShadowAlertDialogCompat.class
+ })
public class SetupChooseLockPasswordTest {
@Before
diff --git a/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java
index 430c535..4852546 100644
--- a/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetupChooseLockPatternTest.java
@@ -38,6 +38,7 @@
import com.android.settings.password.ChooseLockPattern.ChooseLockPatternFragment;
import com.android.settings.password.ChooseLockPattern.IntentBuilder;
import com.android.settings.testutils.shadow.ShadowAlertDialogCompat;
+import com.android.settings.testutils.shadow.ShadowLockPatternUtils;
import com.android.settings.testutils.shadow.ShadowUtils;
import com.google.android.setupcompat.PartnerCustomizationLayout;
@@ -57,7 +58,7 @@
import java.util.Arrays;
@RunWith(RobolectricTestRunner.class)
-@Config(shadows = {ShadowUtils.class, ShadowAlertDialogCompat.class})
+@Config(shadows = {ShadowUtils.class, ShadowAlertDialogCompat.class, ShadowLockPatternUtils.class})
public class SetupChooseLockPatternTest {
private SetupChooseLockPattern mActivity;
diff --git a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
index 726e4bd..a693f34 100644
--- a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
+++ b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
@@ -64,6 +64,7 @@
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@@ -184,6 +185,20 @@
}
@Test
+ public void loadSlice_registersBackgroundListener() {
+ insertSpecialCase(KEY);
+ final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false);
+
+ mProvider.loadSlice(uri);
+
+ Robolectric.flushForegroundThreadScheduler();
+ Robolectric.flushBackgroundThreadScheduler();
+
+ assertThat(mProvider.mPinnedWorkers.get(uri).getClass())
+ .isEqualTo(FakeToggleController.TestWorker.class);
+ }
+
+ @Test
public void testLoadSlice_doesNotCacheWithoutPin() {
insertSpecialCase(KEY);
final Uri uri = SliceBuilderUtils.getUri(INTENT_PATH, false);
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeCopyableController.java b/tests/robotests/src/com/android/settings/testutils/FakeCopyableController.java
index 31e955c..e51a249 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeCopyableController.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeCopyableController.java
@@ -19,9 +19,8 @@
import android.content.Context;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.slices.Copyable;
-public class FakeCopyableController extends BasePreferenceController implements Copyable {
+public class FakeCopyableController extends BasePreferenceController {
public FakeCopyableController(Context context, String preferenceKey) {
super(context, preferenceKey);
@@ -38,6 +37,7 @@
}
@Override
- public void copy() {
+ public boolean isCopyableSlice() {
+ return true;
}
}
diff --git a/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java b/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java
index d1677cd..e785487 100644
--- a/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java
+++ b/tests/robotests/src/com/android/settings/testutils/FakeToggleController.java
@@ -19,10 +19,14 @@
import android.content.Context;
import android.content.IntentFilter;
+import android.net.Uri;
import android.net.wifi.WifiManager;
import android.provider.Settings;
import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.slices.SliceBackgroundWorker;
+
+import java.io.IOException;
public class FakeToggleController extends TogglePreferenceController {
@@ -71,6 +75,11 @@
}
@Override
+ public Class<? extends SliceBackgroundWorker> getBackgroundWorkerClass() {
+ return TestWorker.class;
+ }
+
+ @Override
public boolean hasAsyncUpdate() {
return mIsAsyncUpdate;
}
@@ -78,4 +87,23 @@
public void setAsyncUpdate(boolean isAsyncUpdate) {
mIsAsyncUpdate = isAsyncUpdate;
}
+
+ public static class TestWorker extends SliceBackgroundWorker<Void> {
+
+ public TestWorker(Context context, Uri uri) {
+ super(context, uri);
+ }
+
+ @Override
+ protected void onSlicePinned() {
+ }
+
+ @Override
+ protected void onSliceUnpinned() {
+ }
+
+ @Override
+ public void close() throws IOException {
+ }
+ }
}
diff --git a/tests/robotests/src/com/android/settings/testutils/SliceTester.java b/tests/robotests/src/com/android/settings/testutils/SliceTester.java
index 17edb6e..d84d42c 100644
--- a/tests/robotests/src/com/android/settings/testutils/SliceTester.java
+++ b/tests/robotests/src/com/android/settings/testutils/SliceTester.java
@@ -238,22 +238,38 @@
* @param title Title for asserting.
*/
public static void assertAnySliceItemContainsTitle(List<SliceItem> sliceItems, String title) {
- boolean hasTitle = false;
+ assertThat(hasText(sliceItems, title, HINT_TITLE)).isTrue();
+ }
+
+ /**
+ * Assert any slice item contains subtitle.
+ *
+ * @param sliceItems All slice items of a Slice.
+ * @param subtitle Subtitle for asserting.
+ */
+ public static void assertAnySliceItemContainsSubtitle(List<SliceItem> sliceItems,
+ String subtitle) {
+ // Subtitle has no hints
+ assertThat(hasText(sliceItems, subtitle, null /* hints */)).isTrue();
+ }
+
+ private static boolean hasText(List<SliceItem> sliceItems, String text, String hints) {
+ boolean hasText = false;
for (SliceItem item : sliceItems) {
- List<SliceItem> titleItems = SliceQuery.findAll(item, FORMAT_TEXT, HINT_TITLE,
+ List<SliceItem> textItems = SliceQuery.findAll(item, FORMAT_TEXT, hints,
null /* non-hints */);
- if (titleItems == null) {
+ if (textItems == null) {
continue;
}
- for (SliceItem subTitleItem : titleItems) {
- if (TextUtils.equals(subTitleItem.getText(), title)) {
- hasTitle = true;
+ for (SliceItem textItem : textItems) {
+ if (TextUtils.equals(textItem.getText(), text)) {
+ hasText = true;
break;
}
}
}
- assertThat(hasTitle).isTrue();
+ return hasText;
}
private static void assertKeywords(SliceMetadata metadata, SliceData data) {
diff --git a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java
index 7ce098d..f287085 100644
--- a/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java
+++ b/tests/robotests/src/com/android/settings/testutils/shadow/ShadowLockPatternUtils.java
@@ -32,6 +32,11 @@
private static boolean sDeviceEncryptionEnabled;
@Implementation
+ protected boolean hasSecureLockScreen() {
+ return true;
+ }
+
+ @Implementation
protected boolean isSecure(int id) {
return true;
}
diff --git a/tests/robotests/src/com/android/settings/wifi/slice/WifiSliceTest.java b/tests/robotests/src/com/android/settings/wifi/slice/WifiSliceTest.java
index dd99e55..6af8f80 100644
--- a/tests/robotests/src/com/android/settings/wifi/slice/WifiSliceTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/slice/WifiSliceTest.java
@@ -118,7 +118,7 @@
// All AP rows + title row
assertThat(rows).isEqualTo(DEFAULT_EXPANDED_ROW_COUNT + 1);
// Has scanning text
- SliceTester.assertAnySliceItemContainsTitle(sliceItems,
+ SliceTester.assertAnySliceItemContainsSubtitle(sliceItems,
mContext.getString(R.string.wifi_empty_list_wifi_on));
}
diff --git a/tests/unit/src/com/android/settings/DisplaySettingsTest.java b/tests/unit/src/com/android/settings/DisplaySettingsTest.java
deleted file mode 100644
index cc9cd81..0000000
--- a/tests/unit/src/com/android/settings/DisplaySettingsTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License
- */
-
-package com.android.settings;
-
-import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.action.ViewActions.click;
-import static androidx.test.espresso.matcher.ViewMatchers.withText;
-
-import android.app.Instrumentation;
-import android.content.Context;
-import android.content.Intent;
-import android.support.test.uiautomator.UiDevice;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class DisplaySettingsTest {
-
- private Instrumentation mInstrumentation;
- private Context mContext;
- private UiDevice mDevice;
-
- @Before
- public void setUp() {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
- mContext = mInstrumentation.getTargetContext();
- mDevice = UiDevice.getInstance(mInstrumentation);
- }
-
- @Test
- public void launchBrightnessLevel_shouldNotCrash() {
- mInstrumentation.startActivitySync(
- new Intent(mContext, DisplaySettings.class));
- onView(withText(mContext.getString(R.string.brightness))).perform(click());
- // should not crash
- mDevice.pressBack(); // dismiss the brightness dialog
- }
-}
diff --git a/tests/unit/src/com/android/settings/EncryptionInterstitialTest.java b/tests/unit/src/com/android/settings/EncryptionInterstitialTest.java
deleted file mode 100644
index 503a78c..0000000
--- a/tests/unit/src/com/android/settings/EncryptionInterstitialTest.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings;
-
-import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.action.ViewActions.click;
-import static androidx.test.espresso.matcher.ViewMatchers.withId;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import android.app.Activity;
-import android.app.Instrumentation;
-import android.app.Instrumentation.ActivityMonitor;
-import android.app.Instrumentation.ActivityResult;
-import android.content.Context;
-import android.content.Intent;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.MediumTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import com.google.android.setupcompat.PartnerCustomizationLayout;
-import com.google.android.setupcompat.template.FooterBarMixin;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@MediumTest
-public class EncryptionInterstitialTest {
-
- private Instrumentation mInstrumentation;
- private Context mContext;
- private TestActivityMonitor mActivityMonitor;
-
- @Before
- public void setUp() {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
- mContext = mInstrumentation.getTargetContext();
- mActivityMonitor = new TestActivityMonitor();
- mInstrumentation.addMonitor(mActivityMonitor);
- }
-
- @After
- public void tearDown() {
- mInstrumentation.removeMonitor(mActivityMonitor);
- }
-
- @Test
- public void clickYes_shouldRequirePassword() {
- final Activity activity = mInstrumentation.startActivitySync(
- new Intent(mContext, EncryptionInterstitial.class)
- .putExtra("extra_unlock_method_intent", new Intent("test.unlock.intent")));
- final PartnerCustomizationLayout layout = activity.findViewById(R.id.setup_wizard_layout);
- layout.getMixin(FooterBarMixin.class).getPrimaryButtonView().performClick();
-
- mActivityMonitor.waitForActivityWithTimeout(1000);
- assertEquals(1, mActivityMonitor.getHits());
-
- assertTrue(mActivityMonitor.mMatchedIntent.getBooleanExtra(
- EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, false));
- }
-
- @Test
- public void clickNo_shouldNotRequirePassword() {
- final Activity activity = mInstrumentation.startActivitySync(
- new Intent(mContext, EncryptionInterstitial.class)
- .putExtra("extra_unlock_method_intent", new Intent("test.unlock.intent")));
- final PartnerCustomizationLayout layout = activity.findViewById(R.id.setup_wizard_layout);
- layout.getMixin(FooterBarMixin.class).getSecondaryButtonView().performClick();
-
- mActivityMonitor.waitForActivityWithTimeout(1000);
- assertEquals(1, mActivityMonitor.getHits());
-
- assertFalse(mActivityMonitor.mMatchedIntent.getBooleanExtra(
- EncryptionInterstitial.EXTRA_REQUIRE_PASSWORD, true));
- }
-
- private static class TestActivityMonitor extends ActivityMonitor {
-
- Intent mMatchedIntent = null;
-
- @Override
- public ActivityResult onStartActivity(Intent intent) {
- if ("test.unlock.intent".equals(intent.getAction())) {
- mMatchedIntent = intent;
- return new ActivityResult(Activity.RESULT_OK, null);
- }
- return null;
- }
- }
-}
diff --git a/tests/unit/src/com/android/settings/ManagedAccessSettingsLowRamTest.java b/tests/unit/src/com/android/settings/ManagedAccessSettingsLowRamTest.java
deleted file mode 100644
index 426b8a4..0000000
--- a/tests/unit/src/com/android/settings/ManagedAccessSettingsLowRamTest.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings;
-
-import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.action.ViewActions.click;
-import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
-import static androidx.test.espresso.assertion.ViewAssertions.matches;
-import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static androidx.test.espresso.matcher.ViewMatchers.withText;
-
-import android.app.ActivityManager;
-import android.app.Instrumentation;
-import android.content.Context;
-import android.content.Intent;
-import android.provider.Settings;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class ManagedAccessSettingsLowRamTest {
-
- private Instrumentation mInstrumentation;
- private Context mTargetContext;
-
- @Before
- public void setUp() {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
- mTargetContext = mInstrumentation.getTargetContext();
- }
-
- @Test
- public void testManagedAccessOptionsVisibility() throws Exception {
- mInstrumentation.startActivitySync(new Intent(mTargetContext,
- com.android.settings.Settings.AppAndNotificationDashboardActivity.class));
- onView(withText(mTargetContext.getString(R.string.expand_button_title))).perform(click());
- onView(withText(mTargetContext.getString(R.string.special_access))).perform(click());
-
- String[] managedServiceLabels = new String[] {"Do Not Disturb access",
- "VR helper services", "Notification access", "Picture-in-picture"};
- for (String label : managedServiceLabels) {
- if (ActivityManager.isLowRamDeviceStatic()) {
- onView(withText(label)).check(doesNotExist());
- } else {
- onView(withText(label)).check(matches(isDisplayed()));
- }
- }
- }
-
- @Test
- public void launchNotificationSetting_onlyWorksIfNotLowRam() {
- final Intent intent = new Intent(Settings.ACTION_NOTIFICATION_LISTENER_SETTINGS);
-
- mInstrumentation.startActivitySync(intent);
-
- final String label = "This feature is not available on this device";
- if (ActivityManager.isLowRamDeviceStatic()) {
- onView(withText(label)).check(matches(isDisplayed()));
- } else {
- onView(withText(label)).check(doesNotExist());
- }
- }
-
- @Test
- public void launchDndSetting_onlyWorksIfNotLowRam() {
- final Intent intent = new Intent(Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
-
- mInstrumentation.startActivitySync(intent);
-
- final String label = "This feature is not available on this device";
- if (ActivityManager.isLowRamDeviceStatic()) {
- onView(withText(label)).check(matches(isDisplayed()));
- } else {
- onView(withText(label)).check(doesNotExist());
- }
- }
-
- @Test
- public void launchVrSetting_onlyWorksIfNotLowRam() {
- final Intent intent = new Intent(Settings.ACTION_VR_LISTENER_SETTINGS);
-
- mInstrumentation.startActivitySync(intent);
-
- final String label = "This feature is not available on this device";
- if (ActivityManager.isLowRamDeviceStatic()) {
- onView(withText(label)).check(matches(isDisplayed()));
- } else {
- onView(withText(label)).check(doesNotExist());
- }
- }
-
- @Test
- public void launchPictureInPictureSetting_onlyWorksIfNotLowRam() {
- final Intent intent = new Intent(Settings.ACTION_PICTURE_IN_PICTURE_SETTINGS);
-
- mInstrumentation.startActivitySync(intent);
-
- final String label = "This feature is not available on this device";
- if (ActivityManager.isLowRamDeviceStatic()) {
- onView(withText(label)).check(matches(isDisplayed()));
- } else {
- onView(withText(label)).check(doesNotExist());
- }
- }
-}
diff --git a/tests/unit/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java b/tests/unit/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java
index 48f9f5d..1701ddf 100644
--- a/tests/unit/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java
+++ b/tests/unit/src/com/android/settings/RegulatoryInfoDisplayActivityTest.java
@@ -16,12 +16,6 @@
package com.android.settings;
-import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.assertion.ViewAssertions.matches;
-import static androidx.test.espresso.matcher.RootMatchers.isDialog;
-import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static androidx.test.espresso.matcher.ViewMatchers.withId;
-
import static junit.framework.Assert.fail;
import android.app.Instrumentation;
@@ -29,8 +23,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.ResolveInfo;
-import android.graphics.Bitmap;
-import android.util.Log;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -40,10 +32,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-
@RunWith(AndroidJUnit4.class)
@SmallTest
public class RegulatoryInfoDisplayActivityTest {
@@ -82,73 +70,4 @@
return;
}
}
-
- @Test
- public void launchRegulatoryInfo_shouldNotCrash() {
- final Context context = mInstrumentation.getTargetContext();
- final boolean hasRegulatoryInfo = context.getResources()
- .getBoolean(R.bool.config_show_regulatory_info);
-
- if (!hasRegulatoryInfo) {
- return;
- }
- // Launch intent
- mInstrumentation.startActivitySync(mRegulatoryInfoIntent);
-
- onView(withId(R.id.regulatoryInfo))
- .inRoot(isDialog())
- .check(matches(isDisplayed()));
- }
-
- @Test
- public void launchRegulatoryInfo_withInfoImage_shouldDisplay() throws IOException {
- // TODO: Remove "setenforce 0" when selinux rules is updated to give read permission for
- // regulatory info.
- mUiAutomation.executeShellCommand("setenforce 0");
-
- final boolean tempFileCreated = ensureRegulatoryInfoImageExists();
- try {
- final Context context = mInstrumentation.getTargetContext();
- final boolean hasRegulatoryInfo = context.getResources()
- .getBoolean(R.bool.config_show_regulatory_info);
-
- if (!hasRegulatoryInfo) {
- return;
- }
- // Launch intent
- mInstrumentation.startActivitySync(mRegulatoryInfoIntent);
-
- onView(withId(R.id.regulatoryInfo))
- .inRoot(isDialog())
- .check(matches(isDisplayed()));
- } finally {
- if (tempFileCreated) {
- final String filename =
- RegulatoryInfoDisplayActivity.getRegulatoryInfoImageFileName();
- new File(filename).delete();
- Log.d(TAG, "Deleting temp file " + filename);
- }
- }
- }
-
- /**
- * Ensures regulatory label image exists on disk.
- *
- * @return true if a test image is created.
- */
- private boolean ensureRegulatoryInfoImageExists() throws IOException {
- final String filename = RegulatoryInfoDisplayActivity.getRegulatoryInfoImageFileName();
- if (new File(filename).exists()) {
- return false;
- }
- Log.d(TAG, "Creating temp file " + filename);
- final Bitmap bitmap = Bitmap.createBitmap(400 /* width */, 400 /* height */,
- Bitmap.Config.ARGB_8888);
- final FileOutputStream out = new FileOutputStream(filename);
- bitmap.compress(Bitmap.CompressFormat.PNG, 100 /* quality */, out);
- out.close();
- return true;
- }
-
-
}
diff --git a/tests/unit/src/com/android/settings/SettingsHookTests.java b/tests/unit/src/com/android/settings/SettingsHookTests.java
deleted file mode 100644
index ee0bbb6..0000000
--- a/tests/unit/src/com/android/settings/SettingsHookTests.java
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
- * Copyright (C) 2010 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;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.test.ActivityInstrumentationTestCase2;
-
-import java.util.List;
-
-/**
- * Tests for the Settings operator/manufacturer hook.
- *
- * Running all tests:
- *
- * make SettingsTests
- * adb push SettingsTests.apk /system/app/SettingsTests.apk
- * adb shell am instrument \
- * -w com.android.settings.tests/android.test.InstrumentationTestRunner
- */
-public class SettingsHookTests extends ActivityInstrumentationTestCase2<Settings> {
-
- private static final String PACKAGE_NAME = "com.android.settings.tests.unit";
-
- private static final String KEY_SETTINGS_ROOT = "parent";
- private static final String KEY_SETTINGS_OPERATOR = "operator_settings";
- private static final String KEY_SETTINGS_MANUFACTURER = "manufacturer_settings";
-
- private static final String INTENT_OPERATOR_HOOK = "com.android.settings.OPERATOR_APPLICATION_SETTING";
- private static final String INTENT_MANUFACTURER_HOOK = "com.android.settings.MANUFACTURER_APPLICATION_SETTING";
-
- private Settings mSettings;
-
- public SettingsHookTests() {
- super("com.android.settings", Settings.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mSettings = getActivity();
- }
-
- /**
- * Test that the operator/manufacturer settings hook test application is
- * available and that it's installed in the device's system image.
- */
- public void testSettingsHookTestAppAvailable() throws Exception {
- Context context = mSettings.getApplicationContext();
- PackageManager pm = context.getPackageManager();
- ApplicationInfo applicationInfo = pm.getApplicationInfo(PACKAGE_NAME, 0);
- assertTrue((applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
- }
-
- /**
- * Test that the operator test activity has registered an intent-filter for
- * an action named 'android.settings.OPERATOR_APPLICATION_SETTING'.
- */
- public void testOperatorIntentFilter() {
- boolean result = false;
- Context context = mSettings.getApplicationContext();
- PackageManager pm = context.getPackageManager();
- Intent intent = new Intent(INTENT_OPERATOR_HOOK);
- List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
- for (ResolveInfo resolveInfo : list) {
- if (resolveInfo.activityInfo.packageName.equals(PACKAGE_NAME)) {
- result = true;
- }
- }
- assertTrue("Intent-filter not found", result);
- }
-
- /**
- * Test that the manufacturer test activity has registered an intent-filter
- * for an action named 'android.settings.MANUFACTURER_APPLICATION_SETTING'.
- */
- public void testManufacturerIntentFilter() {
- boolean result = false;
- Context context = mSettings.getApplicationContext();
- PackageManager pm = context.getPackageManager();
- Intent intent = new Intent(INTENT_MANUFACTURER_HOOK);
- List<ResolveInfo> list = pm.queryIntentActivities(intent, 0);
- for (ResolveInfo resolveInfo : list) {
- if (resolveInfo.activityInfo.packageName.equals(PACKAGE_NAME)) {
- result = true;
- }
- }
- assertTrue("Intent-filter not found", result);
- }
-
- /**
- * Test that the operator preference is available in the Settings
- * application.
- */
- public void testOperatorPreferenceAvailable() {
-// TODO: fix this test case to work with fragments
-// PreferenceGroup root = (PreferenceGroup)mSettings.findPreference(KEY_SETTINGS_ROOT);
-// Preference operatorPreference = root.findPreference(KEY_SETTINGS_OPERATOR);
-// assertNotNull(operatorPreference);
- }
-
- /**
- * Test that the manufacturer preference is available in the Settings
- * application.
- */
- public void testManufacturerPreferenceAvailable() {
-// TODO: fix this test case to work with fragments
-// PreferenceGroup root = (PreferenceGroup)mSettings.findPreference(KEY_SETTINGS_ROOT);
-// Preference manufacturerHook = root.findPreference(KEY_SETTINGS_MANUFACTURER);
-// assertNotNull(manufacturerHook);
- }
-
-}
diff --git a/tests/unit/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java b/tests/unit/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java
index f8d06a8..0c27379 100644
--- a/tests/unit/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java
+++ b/tests/unit/src/com/android/settings/accessibility/AccessibilityShortcutPreferenceFragmentTest.java
@@ -30,6 +30,7 @@
import android.app.Instrumentation;
import android.os.Bundle;
+
import android.provider.Settings;
import android.widget.CompoundButton;
@@ -64,14 +65,6 @@
}
@Test
- public void lockScreenPreference_defaultBeforeDialogShown_isOff() {
- setDialogShown(false);
- setOnLockscreen(null);
- startFragment();
- assertLockscreenSwitchIsCheckedIs(false);
- }
-
- @Test
public void lockScreenPreference_setOnBeforeDialogShown_isOn() {
setDialogShown(false);
setOnLockscreen(true);
@@ -87,14 +80,6 @@
assertLockscreenSwitchIsCheckedIs(true);
}
- @Test
- public void lockScreenPreference_setOffAfterDialogShown_isOn() {
- setDialogShown(true);
- setOnLockscreen(false);
- startFragment();
- assertLockscreenSwitchIsCheckedIs(false);
- }
-
private void startFragment() {
mInstrumentation.runOnMainSync(() -> {
new SubSettingLauncher(mActivity)
diff --git a/tests/unit/src/com/android/settings/applications/DefaultAppSettingsTest.java b/tests/unit/src/com/android/settings/applications/DefaultAppSettingsTest.java
deleted file mode 100644
index 1dd899e..0000000
--- a/tests/unit/src/com/android/settings/applications/DefaultAppSettingsTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.applications;
-
-import android.content.Context;
-import android.content.Intent;
-import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.UiObject;
-import android.support.test.uiautomator.UiSelector;
-import android.test.InstrumentationTestCase;
-import android.widget.TextView;
-
-import androidx.test.filters.SmallTest;
-
-import com.android.settings.R;
-
-import org.junit.Test;
-
-/**
- * Test for Advanced App preferences.
- */
-@SmallTest
-public class DefaultAppSettingsTest extends InstrumentationTestCase {
-
- private UiDevice mDevice;
- private Context mTargetContext;
- private String mTargetPackage;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mDevice = UiDevice.getInstance(getInstrumentation());
- mTargetContext = getInstrumentation().getTargetContext();
- mTargetPackage = mTargetContext.getPackageName();
- }
-
- @Test
- public void testSelectDefaultHome_shouldLaunchHomePicker() throws Exception {
- launchDefaultApps();
- final String titleHomeApp = mTargetContext.getResources().getString(R.string.home_app);
- mDevice.findObject(new UiSelector().text(titleHomeApp)).click();
- final UiObject actionBar = mDevice.findObject(new UiSelector().resourceId(
- "com.android.settings:id/action_bar"));
- final UiObject title = actionBar.getChild(
- new UiSelector().className(TextView.class.getName()));
- assertEquals(titleHomeApp, title.getText());
- }
-
- private void launchDefaultApps() throws Exception {
- final Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
- .addCategory(Intent.CATEGORY_LAUNCHER)
- .setPackage(mTargetPackage)
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- getInstrumentation().getContext().startActivity(settingsIntent);
- final String titleApps = mTargetContext.getResources().getString(
- R.string.app_and_notification_dashboard_title);
- mDevice.findObject(new UiSelector().text(titleApps)).click();
- final String titleAdvance = mTargetContext.getResources().getString(
- R.string.advanced_section_header);
- mDevice.findObject(new UiSelector().text(titleAdvance)).click();
- final String titleDefaultApps = mTargetContext.getResources().getString(
- R.string.app_default_dashboard_title);
- mDevice.findObject(new UiSelector().text(titleDefaultApps)).click();
- }
-
-}
diff --git a/tests/unit/src/com/android/settings/applications/ManageApplicationsLaunchTest.java b/tests/unit/src/com/android/settings/applications/ManageApplicationsLaunchTest.java
deleted file mode 100644
index c98a43d..0000000
--- a/tests/unit/src/com/android/settings/applications/ManageApplicationsLaunchTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.applications;
-
-import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.assertion.ViewAssertions.matches;
-import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
-import static androidx.test.espresso.matcher.ViewMatchers.withText;
-
-import static org.hamcrest.Matchers.allOf;
-
-import android.app.Instrumentation;
-import android.content.Intent;
-import android.provider.Settings;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class ManageApplicationsLaunchTest {
-
- private Instrumentation mInstrumentation;
-
- @Before
- public void setUp() {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
- }
-
- @Test
- public void launchAppsSettings_shouldShowAppList() throws Exception {
- final Intent appsSettingsIntent = new
- Intent(Settings.ACTION_MANAGE_APPLICATIONS_SETTINGS);
-
- mInstrumentation.startActivitySync(appsSettingsIntent);
-
- onView(allOf(withText("Calculator"))).check(matches(isDisplayed()));
- }
-}
diff --git a/tests/unit/src/com/android/settings/applications/SpecialAppAccessSettingsTest.java b/tests/unit/src/com/android/settings/applications/SpecialAppAccessSettingsTest.java
deleted file mode 100644
index 4738d59..0000000
--- a/tests/unit/src/com/android/settings/applications/SpecialAppAccessSettingsTest.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.applications;
-
-import android.content.Context;
-import android.content.Intent;
-import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.UiObject;
-import android.support.test.uiautomator.UiObjectNotFoundException;
-import android.support.test.uiautomator.UiScrollable;
-import android.support.test.uiautomator.UiSelector;
-import android.test.InstrumentationTestCase;
-import android.widget.TextView;
-
-import androidx.test.filters.SmallTest;
-
-import com.android.settings.R;
-
-import org.junit.Test;
-
-/**
- * Test for Special App Access preferences.
- */
-@SmallTest
-public class SpecialAppAccessSettingsTest extends InstrumentationTestCase {
-
- private UiDevice mDevice;
- private Context mTargetContext;
- private String mTargetPackage;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mDevice = UiDevice.getInstance(getInstrumentation());
- mTargetContext = getInstrumentation().getTargetContext();
- mTargetPackage = mTargetContext.getPackageName();
- }
-
- @Test
- public void testSelectPictureInPicture_shouldNotCrash() throws Exception {
- launchSpecialApps();
- final String titlePictureInPictureApp =
- mTargetContext.getResources().getString(R.string.picture_in_picture_title);
-
- // select Picture-in-Picture
- mDevice.findObject(new UiSelector().text(titlePictureInPictureApp)).click();
-
- // Picture-in-picture settings page should launch and no crash
- final UiObject actionBar = mDevice.findObject(new UiSelector().resourceId(
- "com.android.settings:id/action_bar"));
- final UiObject title = actionBar.getChild(
- new UiSelector().className(TextView.class.getName()));
- assertEquals(titlePictureInPictureApp, title.getText());
- }
-
- private void launchSpecialApps() throws Exception {
- final Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
- .addCategory(Intent.CATEGORY_LAUNCHER)
- .setPackage(mTargetPackage)
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- getInstrumentation().getContext().startActivity(settingsIntent);
- final String titleApps = mTargetContext.getResources().getString(
- R.string.app_and_notification_dashboard_title);
- mDevice.findObject(new UiSelector().text(titleApps)).click();
- final String titleAdvance = mTargetContext.getResources().getString(
- R.string.advanced_section_header);
- mDevice.findObject(new UiSelector().text(titleAdvance)).click();
- final String titleSpecialApps = mTargetContext.getResources().getString(
- R.string.special_access);
-
- try {
- // scollbar may or may not be present, depending on how many recents app are there. If
- // the page is scrollable, scroll to the bottom to show the special app access settings.
- final UiScrollable settings = new UiScrollable(
- new UiSelector().packageName(mTargetContext.getPackageName()).scrollable(true));
- settings.scrollTextIntoView(titleSpecialApps);
- } catch (UiObjectNotFoundException e) {
- // ignore
- }
-
- mDevice.findObject(new UiSelector().text(titleSpecialApps)).click();
- }
-
-}
diff --git a/tests/unit/src/com/android/settings/backup/BackupIntentTest.java b/tests/unit/src/com/android/settings/backup/BackupIntentTest.java
index 0115c56..54e7451 100644
--- a/tests/unit/src/com/android/settings/backup/BackupIntentTest.java
+++ b/tests/unit/src/com/android/settings/backup/BackupIntentTest.java
@@ -39,7 +39,7 @@
public class BackupIntentTest {
private static final String INTENT_PRIVACY_SETTINGS = "android.settings.PRIVACY_SETTINGS";
private static final String BACKUP_SETTINGS_ACTIVITY =
- "com.android.settings.backup.UserBackupSettingsActivity";
+ "com.android.settings.Settings$PrivacyDashboardActivity";
private Context mContext;
diff --git a/tests/unit/src/com/android/settings/bluetooth/BluetoothDeviceDetailsRotationTest.java b/tests/unit/src/com/android/settings/bluetooth/BluetoothDeviceDetailsRotationTest.java
deleted file mode 100644
index aec6dd2..0000000
--- a/tests/unit/src/com/android/settings/bluetooth/BluetoothDeviceDetailsRotationTest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.bluetooth;
-
-import static org.mockito.Mockito.when;
-
-import android.app.Instrumentation;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.RemoteException;
-import android.support.test.uiautomator.UiDevice;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import com.android.settings.SettingsActivity;
-import com.android.settings.core.SubSettingLauncher;
-import com.android.settingslib.bluetooth.CachedBluetoothDevice;
-import com.android.settingslib.bluetooth.LocalBluetoothManager;
-import com.android.settingslib.core.instrumentation.Instrumentable;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Answers;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class BluetoothDeviceDetailsRotationTest {
- private Context mContext;
- private UiDevice mUiDevice;
- private Instrumentation mInstrumentation;
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private CachedBluetoothDevice mCachedDevice;
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- private LocalBluetoothManager mBluetoothManager;
-
- private String mDeviceAddress;
-
- @Before
- public void setUp() throws Exception {
- MockitoAnnotations.initMocks(this);
- mContext = InstrumentationRegistry.getTargetContext();
- mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
-
- mDeviceAddress = "AA:BB:CC:DD:EE:FF";
- when(mCachedDevice.getAddress()).thenReturn(mDeviceAddress);
- when(mCachedDevice.getName()).thenReturn("Mock Device");
-
- BluetoothDeviceDetailsFragment.sTestDataFactory =
- new BluetoothDeviceDetailsFragment.TestDataFactory() {
- @Override
- public CachedBluetoothDevice getDevice(String deviceAddress) {
- return mCachedDevice;
- }
-
- @Override
- public LocalBluetoothManager getManager(Context context) {
- return mBluetoothManager;
- }
- };
- }
-
- @Test
- public void rotation() {
- Intent intent = new Intent("android.settings.BLUETOOTH_SETTINGS");
- SettingsActivity activity = (SettingsActivity) mInstrumentation.startActivitySync(intent);
- Bundle args = new Bundle(1);
- args.putString(BluetoothDeviceDetailsFragment.KEY_DEVICE_ADDRESS, mDeviceAddress);
- new SubSettingLauncher(activity)
- .setDestination(BluetoothDeviceDetailsFragment.class.getName())
- .setTitleText("test")
- .setArguments(args)
- .setSourceMetricsCategory(Instrumentable.METRICS_CATEGORY_UNKNOWN)
- .launch();
- try {
- mUiDevice.setOrientationLeft();
- mUiDevice.setOrientationNatural();
- mUiDevice.setOrientationRight();
- mUiDevice.setOrientationNatural();
- } catch (RemoteException e) {
- throw new RuntimeException(e);
- }
- }
-}
\ No newline at end of file
diff --git a/tests/unit/src/com/android/settings/bluetooth/DevicePickerActivityTest.java b/tests/unit/src/com/android/settings/bluetooth/DevicePickerActivityTest.java
deleted file mode 100644
index e531e0a..0000000
--- a/tests/unit/src/com/android/settings/bluetooth/DevicePickerActivityTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.bluetooth;
-
-import android.app.Instrumentation;
-import android.content.Intent;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class DevicePickerActivityTest {
-
- private Instrumentation mInstrumentation;
-
- @Before
- public void setUp() throws Exception {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
- }
-
- @Test
- public void startActivityNoCrash() {
- mInstrumentation.startActivitySync(
- new Intent("android.bluetooth.devicepicker.action.LAUNCH"));
- // No crash
- }
-}
diff --git a/tests/unit/src/com/android/settings/connecteddevice/ConnectedDeviceActivityTest.java b/tests/unit/src/com/android/settings/connecteddevice/ConnectedDeviceActivityTest.java
deleted file mode 100644
index 2957c4c..0000000
--- a/tests/unit/src/com/android/settings/connecteddevice/ConnectedDeviceActivityTest.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.connecteddevice;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.app.Instrumentation;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.text.TextUtils;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import java.util.List;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class ConnectedDeviceActivityTest {
- private static final String INTENT_ACTION = "android.intent.action.MAIN";
- private static final String CONNECTED_DEVICE_TITLE = "Connected devices";
-
- private Instrumentation mInstrumentation;
-
- @Before
- public void setUp() throws Exception {
- mInstrumentation = InstrumentationRegistry.getInstrumentation();
- }
-
- @Test
- public void queryConnectedDeviceActivity_onlyOneResponse() {
- final PackageManager packageManager = mInstrumentation.getContext().getPackageManager();
- final Intent intent = new Intent(INTENT_ACTION);
-
- int count = 0;
- final List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(intent,
- PackageManager.GET_META_DATA);
- for (ResolveInfo info : resolveInfoList) {
- if (TextUtils.equals(info.activityInfo.loadLabel(packageManager).toString(),
- CONNECTED_DEVICE_TITLE)) {
- count++;
- }
- }
-
- assertThat(count).isEqualTo(1);
- }
-
-}
diff --git a/tests/unit/src/com/android/settings/dashboard/PreferenceThemeTest.java b/tests/unit/src/com/android/settings/dashboard/PreferenceThemeTest.java
index 18a5e70..0ae5597 100644
--- a/tests/unit/src/com/android/settings/dashboard/PreferenceThemeTest.java
+++ b/tests/unit/src/com/android/settings/dashboard/PreferenceThemeTest.java
@@ -18,13 +18,9 @@
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
-import static androidx.test.espresso.assertion.ViewAssertions.matches;
-import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed;
import static androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
-import static com.android.settings.dashboard.FirstIdViewMatcher.withFirstId;
-
import static org.hamcrest.Matchers.allOf;
import android.app.Instrumentation;
@@ -58,12 +54,6 @@
}
@Test
- public void startPhoneStatus_preferenceIconSpaceReserved() throws InterruptedException {
- launchPhoneStatus();
- onView(withFirstId(R.id.icon_frame)).check(matches(isDisplayed()));
- }
-
- @Test
public void startSetupWizardLockScreen_preferenceIconSpaceNotReserved() {
launchSetupWizardLockScreen();
// Icons should not be shown, and the frame should not occupy extra space.
@@ -72,14 +62,6 @@
onView(withId(R.id.icon_container)).check(doesNotExist());
}
- private void launchPhoneStatus() {
- final Intent settingsIntent = new Intent("android.settings.DEVICE_INFO_SETTINGS")
- .addCategory(Intent.CATEGORY_DEFAULT)
- .setPackage(mTargetPackage)
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- InstrumentationRegistry.getInstrumentation().startActivitySync(settingsIntent);
- }
-
private void launchSetupWizardLockScreen() {
final Intent settingsIntent = new Intent("com.android.settings.SETUP_LOCK_SCREEN")
.addCategory(Intent.CATEGORY_DEFAULT)
diff --git a/tests/unit/src/com/android/settings/datausage/MobileDataUsageActivityTest.java b/tests/unit/src/com/android/settings/datausage/MobileDataUsageActivityTest.java
deleted file mode 100644
index 066d199..0000000
--- a/tests/unit/src/com/android/settings/datausage/MobileDataUsageActivityTest.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings;
-
-import static junit.framework.Assert.assertEquals;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.net.NetworkTemplate;
-import android.telephony.SubscriptionManager;
-import android.telephony.TelephonyManager;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class MobileDataUsageActivityTest {
- private static final String TAG = "MobileDataUsageTest";
- @Test
- public void test_mobileDataUsageIntent() {
- final Context context = InstrumentationRegistry.getTargetContext();
- final PackageManager packageManager = context.getPackageManager();
- final int subId = SubscriptionManager.getDefaultSubscriptionId();
- final NetworkTemplate template = getNetworkTemplate(context, subId);
-
- Intent intent = new Intent(android.provider.Settings.ACTION_MOBILE_DATA_USAGE);
- intent.putExtra(android.provider.Settings.EXTRA_NETWORK_TEMPLATE, template);
- intent.putExtra(android.provider.Settings.EXTRA_SUB_ID, subId);
-
- assertEquals(packageManager.queryIntentActivities(intent, 0).size(), 1);
-
- context.startActivity(intent);
- // Should exit gracefully without crashing.
- }
-
- private NetworkTemplate getNetworkTemplate(Context context, int subId) {
- TelephonyManager tm = (TelephonyManager) context
- .getSystemService(Context.TELEPHONY_SERVICE);
- NetworkTemplate mobileAll = NetworkTemplate.buildTemplateMobileAll(
- tm.getSubscriberId(subId));
- return NetworkTemplate.normalize(mobileAll,
- tm.getMergedSubscriberIds());
- }
-}
diff --git a/tests/unit/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java b/tests/unit/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java
index 2659529..a04c08d 100644
--- a/tests/unit/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java
+++ b/tests/unit/src/com/android/settings/datetime/timezone/model/TimeZoneDataTest.java
@@ -56,9 +56,6 @@
*/
assertThat(mTimeZoneData.lookupCountryCodesForZoneId("Europe/Simferopol").isEmpty())
.isTrue();
- // Metlakatla has the same time as Anchorage after 2015
- assertThat(mTimeZoneData.lookupCountryCodesForZoneId("America/Metlakatla").isEmpty())
- .isTrue();
assertThat(mTimeZoneData.lookupCountryCodesForZoneId("Europe/London").isEmpty())
.isFalse();
assertThat(mTimeZoneData.lookupCountryCodesForZoneId("America/Los_Angeles").isEmpty())
diff --git a/tests/unit/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java b/tests/unit/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
deleted file mode 100644
index a0053be..0000000
--- a/tests/unit/src/com/android/settings/deviceinfo/StorageDashboardFragmentTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.android.settings.deviceinfo;
-
-import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.action.ViewActions.click;
-import static androidx.test.espresso.intent.Intents.intended;
-import static androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra;
-import static androidx.test.espresso.matcher.ViewMatchers.withText;
-
-import static org.hamcrest.Matchers.containsString;
-import static org.hamcrest.Matchers.equalTo;
-
-import androidx.test.espresso.intent.rule.IntentsTestRule;
-import androidx.test.filters.SmallTest;
-
-import com.android.settings.R;
-import com.android.settings.Settings.StorageDashboardActivity;
-import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
-
-import org.junit.Rule;
-import org.junit.Test;
-
-@SmallTest
-public class StorageDashboardFragmentTest {
-
- public static final String EXTRA_KEY = ":settings:show_fragment";
-
- @Rule
- public IntentsTestRule<StorageDashboardActivity> mActivityRule =
- new IntentsTestRule<>(StorageDashboardActivity.class, true, true);
-
- @Test
- public void testStorageManagePreference_canClickTextView() throws InterruptedException {
- // Click on the actual textbox instead of just somewhere in the preference
- onView(withText(R.string.automatic_storage_manager_preference_title)).perform(click());
-
- // Check that it worked by seeing if we switched screens
- intended(hasExtra(equalTo(EXTRA_KEY),
- containsString(AutomaticStorageManagerSettings.class.getName())));
-
- }
-}
diff --git a/tests/unit/src/com/android/settings/dream/DreamSettingsLaunchTest.java b/tests/unit/src/com/android/settings/dream/DreamSettingsLaunchTest.java
deleted file mode 100644
index 6a2abd5..0000000
--- a/tests/unit/src/com/android/settings/dream/DreamSettingsLaunchTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.dream;
-
-import android.content.Context;
-import android.content.Intent;
-import android.provider.Settings;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class DreamSettingsLaunchTest {
-
- @Test
- public void launchFromIntent_doesNotCrash() {
- final Context context = InstrumentationRegistry.getTargetContext();
- Intent intent = new Intent(Settings.ACTION_DREAM_SETTINGS);
-
- context.startActivity(intent);
- }
-}
diff --git a/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java b/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java
index ede4631..19b1360 100644
--- a/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java
+++ b/tests/unit/src/com/android/settings/notification/AppNotificationSettingsTest.java
@@ -41,6 +41,7 @@
import android.content.Context;
import android.content.Intent;
import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry;
import androidx.test.espresso.intent.Intents;
@@ -55,7 +56,9 @@
@RunWith(AndroidJUnit4.class)
@SmallTest
public class AppNotificationSettingsTest {
+ private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
+ private UiDevice mUiDevice;
private Context mTargetContext;
private Instrumentation mInstrumentation;
@@ -68,9 +71,14 @@
private NotificationChannel mUngroupedChannel;
@Before
- public void setUp() {
+ public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
+
+ mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mUiDevice.wakeUp();
+ mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
+
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
mGroup1 = new NotificationChannelGroup(this.getClass().getName() + "1", "group1");
@@ -87,7 +95,8 @@
@Test
public void launchNotificationSetting_shouldNotHaveAppInfoLink() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
@@ -99,60 +108,38 @@
@Test
public void launchNotificationSetting_showGroupsWithMultipleChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mGroup1.getName().toString()))).check(
matches(isDisplayed()));
- try {
- onView(allOf(withText(mGroup1Channel1.getName().toString())))
- .check(matches(isDisplayed()));
- fail("Channel erroneously appearing");
- } catch (Exception e) {
- // expected
- }
- // links to group page
- Intents.init();
- onView(allOf(withText(mGroup1.getName().toString()))).perform(click());
- intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT,
- ChannelGroupNotificationSettings.class.getName())));
- Intents.release();
+ onView(allOf(withText(mGroup1Channel1.getName().toString()))).check(
+ matches(isDisplayed()));
+ onView(allOf(withText(mGroup1Channel2.getName().toString()))).check(
+ matches(isDisplayed()));
}
@Test
public void launchNotificationSetting_showUngroupedChannels() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mUngroupedChannel.getName().toString())))
.check(matches(isDisplayed()));
- // links directly to channel page
- Intents.init();
- onView(allOf(withText(mUngroupedChannel.getName().toString()))).perform(click());
- intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT, ChannelNotificationSettings.class.getName())));
- Intents.release();
}
@Test
public void launchNotificationSetting_showGroupsWithOneChannel() {
final Intent intent = new Intent(Settings.ACTION_APP_NOTIFICATION_SETTINGS)
- .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName());
+ .putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
+ onView(allOf(withText(mGroup2.getName().toString())))
+ .check(matches(isDisplayed()));
onView(allOf(withText(mGroup2Channel1.getName().toString())))
.check(matches(isDisplayed()));
- try {
- onView(allOf(withText(mGroup2.getName().toString()))).check(
- matches(isDisplayed()));
- fail("Group erroneously appearing");
- } catch (Exception e) {
- // expected
- }
-
- // links directly to channel page
- Intents.init();
- onView(allOf(withText(mGroup2Channel1.getName().toString()))).perform(click());
- intended(allOf(hasExtra(EXTRA_SHOW_FRAGMENT, ChannelNotificationSettings.class.getName())));
- Intents.release();
}
private NotificationChannel createChannel(NotificationChannelGroup group,
diff --git a/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java b/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java
index f7a5a82..9a3a994 100644
--- a/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java
+++ b/tests/unit/src/com/android/settings/notification/ChannelNotificationSettingsTest.java
@@ -36,6 +36,7 @@
import android.os.Process;
import android.os.ServiceManager;
import android.provider.Settings;
+import android.support.test.uiautomator.UiDevice;
import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
@@ -48,17 +49,23 @@
@RunWith(AndroidJUnit4.class)
@SmallTest
public class ChannelNotificationSettingsTest {
+ private static final String WM_DISMISS_KEYGUARD_COMMAND = "wm dismiss-keyguard";
+ private UiDevice mUiDevice;
private Context mTargetContext;
private Instrumentation mInstrumentation;
private NotificationChannel mNotificationChannel;
private NotificationManager mNm;
@Before
- public void setUp() {
+ public void setUp() throws Exception {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mTargetContext = mInstrumentation.getTargetContext();
+ mUiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
+ mUiDevice.wakeUp();
+ mUiDevice.executeShellCommand(WM_DISMISS_KEYGUARD_COMMAND);
+
mNm = (NotificationManager) mTargetContext.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationChannel = new NotificationChannel(this.getClass().getName(),
this.getClass().getName(), IMPORTANCE_MIN);
@@ -69,7 +76,8 @@
public void launchNotificationSetting_shouldNotCrash() {
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
- .putExtra(Settings.EXTRA_CHANNEL_ID, mNotificationChannel.getId());
+ .putExtra(Settings.EXTRA_CHANNEL_ID, mNotificationChannel.getId())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
onView(allOf(withText(mNotificationChannel.getName().toString()))).check(
@@ -90,12 +98,12 @@
final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
.putExtra(Settings.EXTRA_APP_PACKAGE, mTargetContext.getPackageName())
- .putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId());
+ .putExtra(Settings.EXTRA_CHANNEL_ID, blocked.getId())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mInstrumentation.startActivitySync(intent);
- onView(allOf(withText("Off"), isDisplayed())).check(matches(isDisplayed()));
- onView(allOf(withText("Android is blocking this category of notifications from"
- + " appearing on this device"))).check(matches(isDisplayed()));
+ onView(allOf(withText("At your request, Android is blocking this category of notifications"
+ + " from appearing on this device"))).check(matches(isDisplayed()));
try {
onView(allOf(withText("On the lock screen"))).check(matches(isDisplayed()));
diff --git a/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java b/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
index 2fe4074..4120a07 100644
--- a/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
+++ b/tests/unit/src/com/android/settings/notification/ZenModeSettingsIntegrationTest.java
@@ -37,27 +37,29 @@
@Test
public void testZenModeSettingsPreferences() {
launchZenSettings();
- onView(withText("Behavior")).check(matches(isDisplayed()));
- onView(withText("Turn on automatically")).check(matches(isDisplayed()));
+ onView(withText("Calls")).check(matches(isDisplayed()));
+ onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed()));
+ onView(withText("Restrict notifications")).check(matches(isDisplayed()));
+ onView(withText("Duration")).check(matches(isDisplayed()));
+ onView(withText("Schedules")).check(matches(isDisplayed()));
}
@Test
public void testZenModeBehaviorPreferences() {
launchZenBehaviorSettings();
- onView(withText("Alarms")).check(matches(isDisplayed()));
- onView(withText("Media and system feedback")).check(matches(isDisplayed()));
- onView(withText("Reminders")).check(matches(isDisplayed()));
- onView(withText("Events")).check(matches(isDisplayed()));
- onView(withText("Messages")).check(matches(isDisplayed()));
onView(withText("Calls")).check(matches(isDisplayed()));
- onView(withText("Repeat callers")).check(matches(isDisplayed()));
+ onView(withText("SMS, MMS, and messaging apps")).check(matches(isDisplayed()));
+ onView(withText("Restrict notifications")).check(matches(isDisplayed()));
+ onView(withText("Duration")).check(matches(isDisplayed()));
+ onView(withText("Schedules")).check(matches(isDisplayed()));
}
@Test
public void testZenModeAutomationPreferences() {
launchZenAutomationSettings();
- onView(withText("Weekend")).check(matches(isDisplayed()));
- onView(withText("Add rule")).check(matches(isDisplayed()));
+ onView(withText("Sleeping")).check(matches(isDisplayed()));
+ onView(withText("Event")).check(matches(isDisplayed()));
+ onView(withText("Add more")).check(matches(isDisplayed()));
}
private void launchZenSettings() {
diff --git a/tests/unit/src/com/android/settings/tests/DrawOverlayDetailsTest.java b/tests/unit/src/com/android/settings/tests/DrawOverlayDetailsTest.java
deleted file mode 100644
index d450bf0..0000000
--- a/tests/unit/src/com/android/settings/tests/DrawOverlayDetailsTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2016 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.tests;
-
-import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.Espresso.openActionBarOverflowOrOptionsMenu;
-import static androidx.test.espresso.action.ViewActions.click;
-import static androidx.test.espresso.assertion.ViewAssertions.matches;
-import static androidx.test.espresso.matcher.ViewMatchers.isEnabled;
-import static androidx.test.espresso.matcher.ViewMatchers.withText;
-
-import static org.hamcrest.core.IsNot.not;
-
-import android.app.Instrumentation;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.UiScrollable;
-import android.support.test.uiautomator.UiSelector;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import com.android.settings.R;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class DrawOverlayDetailsTest {
- private final static String PACKAGE_SYSTEM_UI = "com.android.systemui";
-
- @Test
- public void testSystemUiDrawOverlayDetails_Disabled() throws Exception{
- Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
- instrumentation.startActivitySync(new Intent(android.provider.Settings
- .ACTION_MANAGE_OVERLAY_PERMISSION));
-
- final Context targetContext = instrumentation.getTargetContext();
-
- final PackageManager packageManager = targetContext.getPackageManager();
- final String appName = (String) packageManager.getApplicationLabel(packageManager
- .getApplicationInfo(PACKAGE_SYSTEM_UI, PackageManager.GET_META_DATA));
-
- final UiDevice device = UiDevice.getInstance(instrumentation);
- device.waitForIdle();
-
- openActionBarOverflowOrOptionsMenu(targetContext);
- onView(withText(targetContext.getString(R.string.menu_show_system))).perform(click());
- device.waitForIdle();
-
- final UiScrollable settings = new UiScrollable(
- new UiSelector().packageName(targetContext.getPackageName()).scrollable(true));
- settings.scrollTextIntoView(appName);
- onView(withText(appName)).perform(click());
- onView(withText(targetContext.getString(R.string.permit_draw_overlay))).check(matches
- (not(isEnabled())));
- }
-
-}
diff --git a/tests/unit/src/com/android/settings/tests/KeepOnScreenTest.java b/tests/unit/src/com/android/settings/tests/KeepOnScreenTest.java
deleted file mode 100644
index b930ffb..0000000
--- a/tests/unit/src/com/android/settings/tests/KeepOnScreenTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright (C) 2016 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.tests;
-
-import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.action.ViewActions.click;
-import static androidx.test.espresso.matcher.ViewMatchers.withText;
-
-import static junit.framework.Assert.assertEquals;
-
-import android.app.Instrumentation;
-import android.content.Context;
-import android.content.Intent;
-import android.os.BatteryManager;
-import android.provider.Settings;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import com.android.settings.R;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class KeepOnScreenTest {
- private static int EXPECTED_FLAG = BatteryManager.BATTERY_PLUGGED_AC
- | BatteryManager.BATTERY_PLUGGED_USB | BatteryManager.BATTERY_PLUGGED_WIRELESS;
-
- @Test
- public void testStayAwake_turnOn_StayAwakeWhileWirelessCharging() throws Exception{
- Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
- instrumentation.startActivitySync(new Intent(android.provider.Settings
- .ACTION_APPLICATION_DEVELOPMENT_SETTINGS));
-
- final Context targetContext = instrumentation.getTargetContext();
- final int prevFlag = Settings.Global.getInt(targetContext.getContentResolver(), Settings
- .Global.STAY_ON_WHILE_PLUGGED_IN);
-
- // Turn on "Stay Awake" if needed
- if (prevFlag == 0) {
- onView(withText(R.string.keep_screen_on)).perform(click());
- }
-
- final int currentFlag = Settings.Global.getInt(targetContext.getContentResolver(), Settings
- .Global.STAY_ON_WHILE_PLUGGED_IN);
-
- assertEquals(EXPECTED_FLAG, currentFlag);
-
- // Since this app doesn't have permission(and shouldn't have) to change global setting, we
- // can only tearDown in this way
- if (prevFlag != currentFlag) {
- onView(withText(R.string.keep_screen_on)).perform(click());
- }
- }
-}
diff --git a/tests/unit/src/com/android/settings/tests/PrivateVolumeSettingsTest.java b/tests/unit/src/com/android/settings/tests/PrivateVolumeSettingsTest.java
deleted file mode 100644
index 2760a07..0000000
--- a/tests/unit/src/com/android/settings/tests/PrivateVolumeSettingsTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (C) 2016 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.tests;
-
-import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.assertion.ViewAssertions.doesNotExist;
-import static androidx.test.espresso.matcher.ViewMatchers.withText;
-
-import android.app.Instrumentation;
-import android.content.Intent;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class PrivateVolumeSettingsTest {
- @Test
- public void test_ManageStorageNotShown() {
- Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
- instrumentation.startActivitySync(
- new Intent(android.provider.Settings.ACTION_INTERNAL_STORAGE_SETTINGS));
- onView(withText(com.android.settings.R.string.storage_menu_manage)).check(doesNotExist());
- }
-}
\ No newline at end of file
diff --git a/tests/unit/src/com/android/settings/tests/SettingsRestoreAfterCloseTest.java b/tests/unit/src/com/android/settings/tests/SettingsRestoreAfterCloseTest.java
deleted file mode 100644
index 3c6caf7..0000000
--- a/tests/unit/src/com/android/settings/tests/SettingsRestoreAfterCloseTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (C) 2016 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.tests;
-
-import android.app.ActivityManager;
-import android.content.Context;
-import android.content.Intent;
-import android.provider.Settings;
-import android.support.test.uiautomator.By;
-import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.Until;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class SettingsRestoreAfterCloseTest {
- private static final String PACKAGE_SETTINGS = "com.android.settings";
- private static final int TIME_OUT = 2000;
-
- private boolean mAlwaysFinish;
-
- @Before
- public void setUp() throws Exception {
- // To make sure when we press home button, the activity will be destroyed by OS
- Context context = InstrumentationRegistry.getContext();
- mAlwaysFinish = Settings.Global.getInt(
- context.getContentResolver(), Settings.Global
- .ALWAYS_FINISH_ACTIVITIES, 0)
- != 0;
-
- ActivityManager.getService().setAlwaysFinish(true);
- }
-
- @After
- public void tearDown() throws Exception {
- ActivityManager.getService().setAlwaysFinish(mAlwaysFinish);
- }
-
- @Test
- public void testRtlStability_AppCloseAndReOpen_shouldNotCrash() throws Exception {
-
- final UiDevice uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation
- ());
- uiDevice.pressHome();
-
- // Open the settings app
- startSettingsMainActivity(uiDevice);
-
- // Press home button
- uiDevice.pressHome();
- final String launcherPackage = uiDevice.getLauncherPackageName();
- uiDevice.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), TIME_OUT);
-
- // Open the settings again
- startSettingsMainActivity(uiDevice);
- }
-
- private void startSettingsMainActivity(UiDevice uiDevice) {
- Context context = InstrumentationRegistry.getContext();
- context.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
- uiDevice.wait(Until.hasObject(By.pkg(PACKAGE_SETTINGS).depth(0)), TIME_OUT);
- }
-}
diff --git a/tests/unit/src/com/android/settings/users/UserSettingsTest.java b/tests/unit/src/com/android/settings/users/UserSettingsTest.java
deleted file mode 100644
index 93f62f3..0000000
--- a/tests/unit/src/com/android/settings/users/UserSettingsTest.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Copyright (C) 2016 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.users;
-
-import static com.google.common.truth.Truth.assertThat;
-
-import android.content.Context;
-import android.content.Intent;
-import android.support.test.uiautomator.UiDevice;
-import android.support.test.uiautomator.UiObject;
-import android.support.test.uiautomator.UiObjectNotFoundException;
-import android.support.test.uiautomator.UiScrollable;
-import android.support.test.uiautomator.UiSelector;
-
-import androidx.test.InstrumentationRegistry;
-import androidx.test.filters.SmallTest;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-@SmallTest
-public class UserSettingsTest {
-
- private static final String SYSTEM = "System";
- private static final String ADVANCED = "Advanced";
- private static final String USERS = "Multiple users";
- private static final String EMERGNENCY_INFO = "Emergency information";
- private static final String ADD_USERS_WHEN_LOCKED = "Add users";
- private static final String SWITCH_USER_BUTTON = "com.android.systemui:id/multi_user_switch";
- private static final String SETTINGS_BUTTON = "com.android.systemui:id/settings_button";
- private static final String PRIMARY_USER = "Owner";
- private static final String GUEST_USER = "Guest";
- private static final String ADD_GUEST = "Add guest";
- private static final String CONTINUE = "Yes, continue";
-
- private UiDevice mDevice;
- private Context mContext;
- private String mTargetPackage;
-
- @Before
- public void setUp() {
- mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
- mContext = InstrumentationRegistry.getTargetContext();
- mTargetPackage = mContext.getPackageName();
- }
-
- @Test
- public void testEmergencyInfoNotExists() throws Exception {
- launchUserSettings();
- UiObject emergencyInfoPreference =
- mDevice.findObject(new UiSelector().text(EMERGNENCY_INFO));
-
- assertThat(emergencyInfoPreference.exists()).isFalse();
- }
-
- @Test
- public void testAddUsersWhenLockedNotExists() throws Exception {
- launchUserSettings();
- UiObject addUsersPreference =
- mDevice.findObject(new UiSelector().text(ADD_USERS_WHEN_LOCKED));
- assertThat(addUsersPreference.exists()).isFalse();
- }
-
- @Test
- public void testUsersExistsOnSecondaryUser() throws Exception {
- // switch to guest user
- switchToOrCreateGuest();
- // launch settings (launch from intent doesn't work, hence launch from quick settings)
- mDevice.openQuickSettings();
- mDevice.findObject(new UiSelector().resourceId(SETTINGS_BUTTON)).click();
- // launch system settings and expand whole screen
- final UiScrollable settings = new UiScrollable(
- new UiSelector().packageName(mTargetPackage).scrollable(true));
- final String titleSystem = SYSTEM;
- settings.scrollTextIntoView(titleSystem);
- mDevice.findObject(new UiSelector().text(titleSystem)).click();
- mDevice.findObject(new UiSelector().text(ADVANCED)).click();
-
- final boolean hasUsersSettings = mDevice.findObject(new UiSelector().text(USERS)).exists();
-
- // switch back to primary user
- mDevice.openQuickSettings();
- mDevice.findObject(new UiSelector().resourceId(SWITCH_USER_BUTTON)).click();
- mDevice.findObject(new UiSelector().text(PRIMARY_USER)).click();
-
- assertThat(hasUsersSettings).isTrue();
- }
-
- private void launchSettings() {
- Intent settingsIntent = new Intent(Intent.ACTION_MAIN)
- .addCategory(Intent.CATEGORY_LAUNCHER)
- .setPackage(mTargetPackage)
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- mContext.startActivity(settingsIntent);
- }
-
- private void launchUserSettings() throws Exception {
- launchSettings();
- final UiScrollable settings = new UiScrollable(
- new UiSelector().packageName(mTargetPackage).scrollable(true));
- final String titleSystem = SYSTEM;
- settings.scrollTextIntoView(titleSystem);
- mDevice.findObject(new UiSelector().text(titleSystem)).click();
- mDevice.findObject(new UiSelector().text(ADVANCED)).click();
- mDevice.findObject(new UiSelector().text(USERS)).click();
- }
-
- private void switchToOrCreateGuest() throws UiObjectNotFoundException {
- mDevice.openQuickSettings();
- mDevice.findObject(new UiSelector().resourceId(SWITCH_USER_BUTTON)).click();
- // if no existing guest user, select "Add guest", otherwise select "Guest"
- final UiObject addGuest = mDevice.findObject(new UiSelector().text(ADD_GUEST));
- if (addGuest.exists()) {
- addGuest.click();
- mDevice.waitForIdle();
- mDevice.pressBack();
- } else {
- mDevice.findObject(new UiSelector().text(GUEST_USER)).click();
- mDevice.waitForIdle();
- mDevice.findObject(new UiSelector().text(CONTINUE)).click();
- mDevice.waitForIdle();
- }
- }
-}
diff --git a/tests/unit/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java b/tests/unit/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
index cb586e4..2de6611 100644
--- a/tests/unit/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
+++ b/tests/unit/src/com/android/settings/wifi/tether/WifiTetherSettingsTest.java
@@ -56,7 +56,8 @@
mTetherActivityIntent = new Intent()
.setClassName(mInstrumentation.getTargetContext().getPackageName(),
Settings.TetherSettingsActivity.class.getName())
- .setPackage(mInstrumentation.getTargetContext().getPackageName());
+ .setPackage(mInstrumentation.getTargetContext().getPackageName())
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
@After
@@ -69,7 +70,6 @@
launchWifiTetherActivity();
onView(withText("Hotspot name")).check(matches(isDisplayed()));
onView(withText("Hotspot password")).check(matches(isDisplayed()));
- onView(withText("AP Band")).check(matches(isDisplayed()));
}
private void launchWifiTetherActivity() {