Merge "Remove support v1"
diff --git a/res/layout/choose_lock_password_footer.xml b/res/layout/choose_lock_password_footer.xml
index 41306e9..0b7791c 100644
--- a/res/layout/choose_lock_password_footer.xml
+++ b/res/layout/choose_lock_password_footer.xml
@@ -21,12 +21,13 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
- <!-- left : cancel -->
- <Button android:id="@+id/cancel_button"
+ <!-- left : skip -->
+ <Button android:id="@+id/skip_button"
style="@style/SuwGlifButton.Secondary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/lockpassword_cancel_label" />
+ android:text="@string/skip_label"
+ android:visibility="gone" />
<!-- left : clear -->
diff --git a/res/layout/choose_lock_pattern_common.xml b/res/layout/choose_lock_pattern_common.xml
index 949d130..6aee0f9 100644
--- a/res/layout/choose_lock_pattern_common.xml
+++ b/res/layout/choose_lock_pattern_common.xml
@@ -107,6 +107,14 @@
android:textSize="14sp"
android:visibility="gone"/>
+ <Button
+ android:id="@+id/screen_lock_options"
+ style="@style/SuwGlifButton.Tertiary"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/setup_lock_settings_options_button_label"
+ android:visibility="gone" />
+
</com.android.internal.widget.LinearLayoutWithDefaultTouchRecepient>
</com.android.setupwizardlib.GlifLayout>
diff --git a/res/layout/preference_category_no_title.xml b/res/layout/preference_category_no_title.xml
index 136ec6d..d4704bd 100644
--- a/res/layout/preference_category_no_title.xml
+++ b/res/layout/preference_category_no_title.xml
@@ -18,7 +18,7 @@
set height to 0. This will be used in preference category without title in order to remove
extra 32dp blank -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+android:id/title"
+ android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="0dp"
android:textAppearance="@android:style/TextAppearance.Material.Body2"
diff --git a/res/layout/preference_widget_master_checkbox.xml b/res/layout/preference_widget_master_checkbox.xml
new file mode 100644
index 0000000..e61839d
--- /dev/null
+++ b/res/layout/preference_widget_master_checkbox.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+ Copyright (C) 2018 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<CheckBox
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/checkboxWidget"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:gravity="center"
+ android:layout_marginStart="?android:attr/listPreferredItemPaddingEnd"
+ android:layout_marginEnd="?android:attr/listPreferredItemPaddingEnd"
+ android:clickable="false" />
diff --git a/res/layout/private_dns_mode_dialog.xml b/res/layout/private_dns_mode_dialog.xml
index 16152a4..652bc63 100644
--- a/res/layout/private_dns_mode_dialog.xml
+++ b/res/layout/private_dns_mode_dialog.xml
@@ -14,43 +14,56 @@
limitations under the License.
-->
-<RadioGroup
+<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/private_dns_radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:padding="8dip">
+ android:orientation="vertical"
+ android:padding="8dp">
- <RadioButton
- android:id="@+id/private_dns_mode_off"
- android:text="@string/private_dns_mode_off"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="8dip"/>
+ <RadioGroup
+ android:id="@+id/private_dns_radio_group"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content">
- <RadioButton
- android:id="@+id/private_dns_mode_opportunistic"
- android:text="@string/private_dns_mode_opportunistic"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="8dip"/>
+ <RadioButton
+ android:id="@+id/private_dns_mode_off"
+ android:text="@string/private_dns_mode_off"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"/>
- <RadioButton
- android:id="@+id/private_dns_mode_provider"
- android:text="@string/private_dns_mode_provider"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="8dip"/>
+ <RadioButton
+ android:id="@+id/private_dns_mode_opportunistic"
+ android:text="@string/private_dns_mode_opportunistic"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"/>
- <EditText
- android:id="@+id/private_dns_mode_provider_hostname"
- android:hint="@string/private_dns_mode_provider_hostname_hint"
- style="@android:style/Widget.CompoundButton.RadioButton"
- android:imeOptions="actionDone"
- android:inputType="textFilter|textUri"
+ <RadioButton
+ android:id="@+id/private_dns_mode_provider"
+ android:text="@string/private_dns_mode_provider"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="8dp"/>
+
+ <EditText
+ android:id="@+id/private_dns_mode_provider_hostname"
+ android:hint="@string/private_dns_mode_provider_hostname_hint"
+ style="@android:style/Widget.CompoundButton.RadioButton"
+ android:imeOptions="actionDone"
+ android:inputType="textFilter|textUri"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginStart="40dp"
+ android:layout_marginEnd="8dp"/>
+ </RadioGroup>
+
+ <TextView
+ android:id="@+id/private_dns_help_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
- android:layout_marginStart="40dip"
- android:layout_marginEnd="8dip"/>
-
-</RadioGroup>
+ android:layout_marginTop="16dp"
+ android:paddingStart="16dp"
+ android:textAppearance="?android:attr/textAppearanceSmall"/>
+</LinearLayout>
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index aa8a586..dbcfee1 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -309,6 +309,24 @@
<item>Never time out</item>
</string-array>
+ <!-- Bluetooth developer settings: Titles for maximum number of connected audio devices -->
+ <string-array name="bluetooth_max_connected_audio_devices">
+ <item>1 (Default)</item>
+ <item>2</item>
+ <item>3</item>
+ <item>4</item>
+ <item>5</item>
+ </string-array>
+
+ <!-- Bluetooth developer settings: Values for maximum number of connected audio devices -->
+ <string-array name="bluetooth_max_connected_audio_devices_values">
+ <item>1</item>
+ <item>2</item>
+ <item>3</item>
+ <item>4</item>
+ <item>5</item>
+ </string-array>
+
<!-- Match this with drawable.wifi_signal. --> <skip />
<!-- Wi-Fi settings. The signal strength a Wi-Fi network has. -->
<string-array name="wifi_signal">
diff --git a/res/values/bools.xml b/res/values/bools.xml
index 6df9d6c..687d5bd 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -80,4 +80,7 @@
<!-- Whether accessibility shortcut preference should be shown or not. -->
<bool name="config_show_accessibility_shortcut_preference">true</bool>
+
+ <!-- Whether assist_and_voice_input should be shown or not. -->
+ <bool name="config_show_assist_and_voice_input">true</bool>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 596ada8..74737ad 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -396,6 +396,11 @@
<!-- Summary for bluetooth item in connection detail page -->
<string name="bluetooth_pref_summary">Allow device to pair and connect to bluetooth devices</string>
+ <!-- Setting Checkbox title for disabling Bluetooth inband ringing in Development Settings -->
+ <string name="bluetooth_disable_inband_ringing">Disable in-band ringing</string>
+ <!-- Summary of checkbox for disabling Bluetooth inband ringing in Development Settings -->
+ <string name="bluetooth_disable_inband_ringing_summary">Don’t play custom phone ringtones on Bluetooth headsets</string>
+
<!-- Title for connected device group [CHAR LIMIT=none]-->
<string name="connected_device_connected_title">Currently connected</string>
<!-- Title for connected device group [CHAR LIMIT=none]-->
@@ -1624,6 +1629,11 @@
<!-- Bluetooth settings. Dock Setting Dialog - Remember setting and don't ask user again -->
<string name="bluetooth_dock_settings_remember">Remember settings</string>
+ <!-- Bluetooth developer settings: Maximum number of connected audio devices -->
+ <string name="bluetooth_max_connected_audio_devices_string">Maximum connected Bluetooth audio devices</string>
+ <!-- Bluetooth developer settings: Maximum number of connected audio devices -->
+ <string name="bluetooth_max_connected_audio_devices_dialog_title">Select maximum number of connected Bluetooth audio devices</string>
+
<!-- Wifi Display settings. The title of the screen. [CHAR LIMIT=40] -->
<string name="wifi_display_settings_title">Cast</string>
<!-- Wifi Display settings. The title of a menu item to enable wireless display [CHAR LIMIT=40] -->
@@ -2264,7 +2274,8 @@
<string name="emergency_address_title">Emergency Address</string>
<!-- Summary of Update Emergency Address preference, explaining usage of emergency address [CHAR LIMIT=NONE] -->
<string name="emergency_address_summary">Used as your location when you make an emergency call over Wi\u2011Fi</string>
-
+ <!-- Message of private dns that provides a help link. [CHAR LIMIT=NONE] -->
+ <string name="private_dns_help_message"><annotation id="url">Learn more</annotation> about Private DNS features</string>
<!-- Sound and alerts settings -->
<skip/>
@@ -6336,6 +6347,7 @@
<string name="help_url_icc_lock" translatable="false"></string>
<string name="help_uri_process_stats_summary" translatable="false"></string>
<string name="help_uri_process_stats_apps" translatable="false"></string>
+ <string name="help_uri_private_dns" translatable="false"></string>
<!-- User account title [CHAR LIMIT=30] -->
<string name="user_account_title">Account for content</string>
diff --git a/res/xml/development_settings.xml b/res/xml/development_settings.xml
index 60efcab..aad5d23 100644
--- a/res/xml/development_settings.xml
+++ b/res/xml/development_settings.xml
@@ -240,9 +240,9 @@
android:summary="@string/bluetooth_disable_absolute_volume_summary"/>
<SwitchPreference
- android:key="bluetooth_enable_inband_ringing"
- android:title="@string/bluetooth_enable_inband_ringing"
- android:summary="@string/bluetooth_enable_inband_ringing_summary"/>
+ android:key="bluetooth_disable_inband_ringing"
+ android:title="@string/bluetooth_disable_inband_ringing"
+ android:summary="@string/bluetooth_disable_inband_ringing_summary"/>
<ListPreference
android:key="bluetooth_select_avrcp_version"
@@ -286,6 +286,13 @@
android:entries="@array/bluetooth_a2dp_codec_ldac_playback_quality_titles"
android:entryValues="@array/bluetooth_a2dp_codec_ldac_playback_quality_values" />
+ <ListPreference
+ android:key="bluetooth_max_connected_audio_devices"
+ android:title="@string/bluetooth_max_connected_audio_devices_string"
+ android:dialogTitle="@string/bluetooth_max_connected_audio_devices_dialog_title"
+ android:entries="@array/bluetooth_max_connected_audio_devices"
+ android:entryValues="@array/bluetooth_max_connected_audio_devices_values" />
+
</PreferenceCategory>
<PreferenceCategory android:key="debug_input_category"
diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml
index 0aec18f..5d6c9e9 100644
--- a/res/xml/power_usage_summary.xml
+++ b/res/xml/power_usage_summary.xml
@@ -31,23 +31,7 @@
android:layout="@layout/preference_category_no_title"/>
<PreferenceCategory
- android:key="device_usage_list">
-
- <com.android.settings.fuelgauge.PowerGaugePreference
- android:key="last_full_charge"
- android:title="@string/battery_last_full_charge"
- android:selectable="false"/>
-
- <com.android.settings.fuelgauge.PowerGaugePreference
- android:key="screen_usage"
- android:title="@string/device_screen_usage"
- android:selectable="false"/>
-
- </PreferenceCategory>
-
- <PreferenceCategory
- android:key="power_management"
- android:title="@string/battery_power_management">
+ android:key="power_management">
<com.android.settings.widget.MasterSwitchPreference
android:fragment="com.android.settings.fuelgauge.BatterySaverSettings"
@@ -59,26 +43,20 @@
android:title="@string/battery_percentage"
android:summary="@string/battery_percentage_description"/>
- <!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
- <SwitchPreference
- android:key="auto_brightness_battery"
- android:title="@string/auto_brightness_title"
- android:summary="@string/auto_brightness_summary"
- settings:keywords="@string/keywords_display_auto_brightness"/>
+ </PreferenceCategory>
- <!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
- <com.android.settings.TimeoutListPreference
- android:key="screen_timeout_battery"
- android:title="@string/screen_timeout"
- android:summary="@string/screen_timeout_summary"
- android:entries="@array/screen_timeout_entries"
- android:entryValues="@array/screen_timeout_values"/>
+ <PreferenceCategory
+ android:key="device_usage_list">
- <!-- Cross-listed item, if you change this, also change it in display_settings.xml -->
- <Preference
- android:key="ambient_display_battery"
- android:title="@string/ambient_display_screen_title"
- android:fragment="com.android.settings.display.AmbientDisplaySettings" />
+ <com.android.settings.fuelgauge.PowerGaugePreference
+ android:key="last_full_charge"
+ android:title="@string/battery_last_full_charge"
+ android:selectable="false"/>
+
+ <com.android.settings.fuelgauge.PowerGaugePreference
+ android:key="screen_usage"
+ android:title="@string/device_screen_usage"
+ android:selectable="false"/>
</PreferenceCategory>
diff --git a/res/xml/security_settings_v2.xml b/res/xml/security_settings_v2.xml
index 30e829d..571e51f 100644
--- a/res/xml/security_settings_v2.xml
+++ b/res/xml/security_settings_v2.xml
@@ -24,89 +24,145 @@
<!-- security_settings_status.xml -->
<PreferenceCategory
+ android:order="-10"
android:key="security_status"
android:title="@string/security_status_title" />
- <!-- TODO Need security section -->
<PreferenceCategory
+ android:order="1"
+ android:key="dashboard_tile_placeholder" />
+
+ <!-- security section -->
+ <PreferenceCategory
+ android:order="10"
android:key="security_category"
android:title="@string/lock_settings_title">
- <!-- security_settings_chooser -->
<com.android.settings.widget.GearPreference
android:key="unlock_set_or_change"
android:title="@string/unlock_set_unlock_launch_picker_title"
android:summary="@string/unlock_set_unlock_mode_none"
settings:keywords="@string/keywords_lockscreen" />
- <Preference android:key="lockscreen_preferences"
- android:title="@string/lockscreen_settings_title"
- android:fragment="com.android.settings.security.LockscreenDashboardFragment"/>
+ <Preference
+ android:key="lockscreen_preferences"
+ android:title="@string/lockscreen_settings_title"
+ android:summary="@string/summary_placeholder"
+ android:fragment="com.android.settings.security.LockscreenDashboardFragment" />
+
+ <Preference
+ android:key="fingerprint_settings"
+ android:title="@string/security_settings_fingerprint_preference_title"
+ android:summary="@string/summary_placeholder" />
+
+ </PreferenceCategory>
+
+ <!-- work profile security section -->
+ <PreferenceCategory
+ android:order="20"
+ android:key="security_category_profile"
+ android:title="@string/lock_settings_profile_title">
+
+ <!-- security_settings_unification -->
+ <com.android.settingslib.RestrictedSwitchPreference
+ android:key="unification"
+ android:title="@string/lock_settings_profile_unification_title"
+ android:summary="@string/lock_settings_profile_unification_summary"
+ settings:keywords="@string/keywords_unification" />
+
+ <com.android.settingslib.RestrictedPreference
+ android:key="unlock_set_or_change_profile"
+ android:title="@string/unlock_set_unlock_launch_picker_title_profile"
+ android:summary="@string/unlock_set_unlock_mode_pattern"
+ settings:keywords="@string/keywords_lockscreen" />
+
+ <SwitchPreference
+ android:key="visiblepattern_profile"
+ android:summary="@string/summary_placeholder"
+ android:title="@string/lockpattern_settings_enable_visible_pattern_title_profile" />
+
+ <Preference
+ android:key="fingerprint_settings_profile"
+ android:title="@string/security_settings_fingerprint_preference_title"
+ android:summary="@string/summary_placeholder" />
</PreferenceCategory>
<!-- security_settings_misc.xml -->
<PreferenceCategory
+ android:order="30"
android:key="security_settings_misc_category"
android:title="@string/security_passwords_title">
<Preference
android:key="location"
android:title="@string/location_settings_title"
- android:fragment="com.android.settings.location.LocationSettings">
- </Preference>
+ android:summary="@string/summary_placeholder"
+ android:fragment="com.android.settings.location.LocationSettings" />
<SwitchPreference
android:key="show_password"
android:title="@string/show_password"
- android:summary="@string/show_password_summary"/>
+ android:summary="@string/show_password_summary" />
</PreferenceCategory>
<PreferenceCategory
+ android:order="40"
android:key="security_settings_device_admin_category">
- <Preference android:key="manage_device_admin"
- android:title="@string/manage_device_admin"
- android:persistent="false"
- android:fragment="com.android.settings.DeviceAdminSettings"/>
+ <Preference
+ android:key="manage_device_admin"
+ android:title="@string/manage_device_admin"
+ android:summary="@string/summary_placeholder"
+ android:fragment="com.android.settings.DeviceAdminSettings" />
- <Preference android:key="enterprise_privacy"
- android:title="@string/enterprise_privacy_settings"
- android:persistent="false"
- android:fragment="com.android.settings.enterprise.EnterprisePrivacySettings"/>
+ <Preference
+ android:key="enterprise_privacy"
+ android:title="@string/enterprise_privacy_settings"
+ android:summary="@string/summary_placeholder"
+ android:fragment="com.android.settings.enterprise.EnterprisePrivacySettings" />
</PreferenceCategory>
- <Preference android:key="sim_lock_settings"
- android:title="@string/sim_lock_settings_category">
+ <Preference
+ android:order="50"
+ android:key="sim_lock_settings"
+ android:title="@string/sim_lock_settings_category">
- <intent android:action="android.intent.action.MAIN"
- android:targetPackage="com.android.settings"
- android:targetClass="com.android.settings.Settings$IccLockSettingsActivity"/>
+ <intent
+ android:action="android.intent.action.MAIN"
+ android:targetPackage="com.android.settings"
+ android:targetClass="com.android.settings.Settings$IccLockSettingsActivity" />
</Preference>
<Preference
+ android:order="60"
android:key="encryption_and_credential"
android:title="@string/encryption_and_credential_settings_title"
android:summary="@string/encryption_and_credential_settings_summary"
- android:fragment="com.android.settings.security.EncryptionAndCredential"/>
-
- <Preference android:key="manage_trust_agents"
- android:title="@string/manage_trust_agents"
- android:persistent="false"
- android:fragment="com.android.settings.security.trustagent.TrustAgentSettings"/>
+ android:fragment="com.android.settings.security.EncryptionAndCredential" />
<Preference
+ android:order="70"
+ android:key="manage_trust_agents"
+ android:title="@string/manage_trust_agents"
+ android:summary="@string/summary_placeholder"
+ android:fragment="com.android.settings.security.trustagent.TrustAgentSettings" />
+
+ <Preference
+ android:order="80"
android:key="screen_pinning_settings"
android:title="@string/screen_pinning_title"
android:summary="@string/summary_placeholder"
- android:fragment="com.android.settings.security.ScreenPinningSettings"/>
+ android:fragment="com.android.settings.security.ScreenPinningSettings" />
- <Preference android:key="security_misc_usage_access"
- android:title="@string/usage_access_title"
- android:fragment="com.android.settings.applications.manageapplications.ManageApplications">
+ <Preference
+ android:order="90"
+ android:key="security_misc_usage_access"
+ android:title="@string/usage_access_title"
+ android:fragment="com.android.settings.applications.manageapplications.ManageApplications">
<extra
android:name="classname"
android:value="com.android.settings.Settings$UsageAccessSettingsActivity" />
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 6b0a5b8..cd64799 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -1222,7 +1222,7 @@
public static FingerprintManager getFingerprintManagerOrNull(Context context) {
if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)) {
- return context.getSystemService(FingerprintManager.class);
+ return (FingerprintManager) context.getSystemService(Context.FINGERPRINT_SERVICE);
} else {
return null;
}
diff --git a/src/com/android/settings/applications/AppPermissionsPreferenceController.java b/src/com/android/settings/applications/AppPermissionsPreferenceController.java
index c8ff381..6100123 100644
--- a/src/com/android/settings/applications/AppPermissionsPreferenceController.java
+++ b/src/com/android/settings/applications/AppPermissionsPreferenceController.java
@@ -75,7 +75,8 @@
The 3 permissions are the first three from the list which any app has granted:
Location, Microphone, Camera, Sms, Contacts, and Phone
*/
- private String getSummary() {
+ @Override
+ public String getSummary() {
final Set<String> permissions = getAllPermissionsInGroups();
Set<String> grantedPermissionGroups = getGrantedPermissionGroups(permissions);
CharSequence summary = null;
diff --git a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
index fa67ec8..873c98c 100644
--- a/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
+++ b/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBase.java
@@ -14,7 +14,6 @@
package com.android.settings.applications.appinfo;
-import android.app.slice.Slice;
import android.content.Context;
import android.os.Bundle;
import android.os.UserManager;
@@ -52,7 +51,13 @@
@Override
public void updateState(Preference preference) {
- preference.setSummary(isDefaultApp() ? R.string.yes : R.string.no);
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
+ int summaryResId = isDefaultApp() ? R.string.yes : R.string.no;
+ return mContext.getString(summaryResId);
}
@Override
@@ -69,12 +74,14 @@
/**
* Check whether the app has the default app capability
+ *
* @return true if the app has the default app capability
*/
protected abstract boolean hasAppCapability();
/**
* Check whether the app is the default app
+ *
* @return true if the app is the default app
*/
protected abstract boolean isDefaultApp();
diff --git a/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java b/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java
index 37a9edf..02f52b6 100644
--- a/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/DrawOverlayDetailPreferenceController.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.UserManager;
-import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import com.android.settings.SettingsPreferenceFragment;
@@ -61,9 +60,8 @@
return DrawOverlayDetails.class;
}
- @VisibleForTesting
- CharSequence getSummary() {
- return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry());
+ @Override
+ public String getSummary() {
+ return DrawOverlayDetails.getSummary(mContext, mParent.getAppEntry()).toString();
}
-
}
diff --git a/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java b/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java
index 2a88d2f..73e7675 100644
--- a/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java
+++ b/src/com/android/settings/applications/appinfo/WriteSystemSettingsPreferenceController.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.UserManager;
-import android.support.annotation.VisibleForTesting;
import android.support.v7.preference.Preference;
import com.android.settings.SettingsPreferenceFragment;
@@ -62,9 +61,9 @@
return WriteSettingsDetails.class;
}
- @VisibleForTesting
- CharSequence getSummary() {
- return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry());
- }
+ @Override
+ public String getSummary() {
+ return WriteSettingsDetails.getSummary(mContext, mParent.getAppEntry()).toString();
+ }
}
diff --git a/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java b/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
index cba08c8..f78548b 100644
--- a/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
+++ b/src/com/android/settings/applications/assist/DefaultAssistPreferenceController.java
@@ -26,6 +26,7 @@
import android.support.annotation.VisibleForTesting;
import com.android.internal.app.AssistUtils;
+import com.android.settings.R;
import com.android.settings.applications.defaultapps.DefaultAppInfo;
import com.android.settings.applications.defaultapps.DefaultAppPreferenceController;
@@ -73,7 +74,7 @@
@Override
public boolean isAvailable() {
- return true;
+ return mContext.getResources().getBoolean(R.bool.config_show_assist_and_voice_input);
}
@Override
diff --git a/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
index 7a7530c..dccc310 100644
--- a/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
+++ b/src/com/android/settings/backup/BackupSettingsActivityPreferenceController.java
@@ -23,8 +23,6 @@
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
public class BackupSettingsActivityPreferenceController extends BasePreferenceController {
private static final String TAG = "BackupSettingActivityPC";
@@ -49,10 +47,15 @@
@Override
public void updateState(Preference preference) {
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
final boolean backupEnabled = mBackupManager.isBackupEnabled();
- preference.setSummary(backupEnabled
- ? R.string.accessibility_feature_state_on
- : R.string.accessibility_feature_state_off);
+ return backupEnabled
+ ? mContext.getString(R.string.accessibility_feature_state_on)
+ : mContext.getString(R.string.accessibility_feature_state_off);
}
}
\ No newline at end of file
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
index 2d0ce60..bf13e07 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceController.java
@@ -109,7 +109,19 @@
@Override
public void updateState(Preference preference) {
- updateDeviceName(preference, mLocalAdapter.getName());
+ updateDeviceName(preference);
+ }
+
+ @Override
+ public String getSummary() {
+ String deviceName = getDeviceName();
+ if (TextUtils.isEmpty(deviceName)) {
+ return super.getSummary();
+ }
+
+ return TextUtils.expandTemplate(
+ mContext.getText(R.string.bluetooth_device_name_summary),
+ BidiFormatter.getInstance().unicodeWrap(deviceName)).toString();
}
/**
@@ -132,18 +144,14 @@
* Update device summary with {@code deviceName}, where {@code deviceName} has accent color
*
* @param preference to set the summary for
- * @param deviceName bluetooth device name to show in the summary
*/
- protected void updateDeviceName(final Preference preference, final String deviceName) {
- if (deviceName == null) {
- // TODO: show error message in preference subtitle
- return;
- }
- final CharSequence summary = TextUtils.expandTemplate(
- mContext.getText(R.string.bluetooth_device_name_summary),
- BidiFormatter.getInstance().unicodeWrap(deviceName));
+ protected void updateDeviceName(final Preference preference) {
preference.setSelectable(false);
- preference.setSummary(summary);
+ preference.setSummary(getSummary());
+ }
+
+ protected String getDeviceName() {
+ return mLocalAdapter.getName();
}
/**
@@ -158,7 +166,7 @@
if (TextUtils.equals(action, BluetoothAdapter.ACTION_LOCAL_NAME_CHANGED)) {
if (mPreference != null && mLocalAdapter != null && mLocalAdapter.isEnabled()) {
- updateDeviceName(mPreference, mLocalAdapter.getName());
+ updateDeviceName(mPreference);
}
}
}
diff --git a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
index 69eefcf..a12d1a8 100644
--- a/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceController.java
@@ -67,8 +67,13 @@
}
@Override
- protected void updateDeviceName(final Preference preference, final String deviceName) {
- preference.setSummary(deviceName);
+ protected void updateDeviceName(final Preference preference) {
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
+ return getDeviceName();
}
@Override
diff --git a/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java b/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java
index 3482ee2..8a59768 100644
--- a/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java
+++ b/src/com/android/settings/bluetooth/BluetoothSwitchPreferenceController.java
@@ -98,10 +98,11 @@
}
@Override
- public void setChecked(boolean isChecked) {
+ public boolean setChecked(boolean isChecked) {
if (mBluetoothAdapter != null) {
mBluetoothAdapter.setBluetoothEnabled(isChecked);
}
+ return true;
}
/**
diff --git a/src/com/android/settings/core/TogglePreferenceController.java b/src/com/android/settings/core/TogglePreferenceController.java
index febd7ad..5431f4d 100644
--- a/src/com/android/settings/core/TogglePreferenceController.java
+++ b/src/com/android/settings/core/TogglePreferenceController.java
@@ -40,8 +40,9 @@
* Set the Setting to {@param isChecked}
*
* @param isChecked Is {@true} when the setting should be enabled.
+ * @return {@true} if the underlying setting is updated.
*/
- public abstract void setChecked(boolean isChecked);
+ public abstract boolean setChecked(boolean isChecked);
@Override
public final void updateState(Preference preference) {
@@ -50,8 +51,6 @@
@Override
public final boolean onPreferenceChange(Preference preference, Object newValue) {
- boolean auto = (Boolean) newValue;
- setChecked(auto);
- return true;
+ return setChecked((Boolean) newValue);
}
}
\ No newline at end of file
diff --git a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
index 9ef38b8..048f6ed 100644
--- a/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
+++ b/src/com/android/settings/dashboard/DashboardFeatureProviderImpl.java
@@ -218,6 +218,10 @@
preference.setSummary(tile.summary);
} else if (tile.metaData != null
&& tile.metaData.containsKey(META_DATA_PREFERENCE_SUMMARY_URI)) {
+ // Set a placeholder summary before starting to fetch real summary, this is necessary
+ // to avoid preference height change.
+ preference.setSummary(R.string.summary_placeholder);
+
ThreadUtils.postOnBackgroundThread(() -> {
final Map<String, IContentProvider> providerMap = new ArrayMap<>();
final String uri = tile.metaData.getString(META_DATA_PREFERENCE_SUMMARY_URI);
diff --git a/src/com/android/settings/datausage/BillingCycleSettings.java b/src/com/android/settings/datausage/BillingCycleSettings.java
index fb8119c..34d18e9 100644
--- a/src/com/android/settings/datausage/BillingCycleSettings.java
+++ b/src/com/android/settings/datausage/BillingCycleSettings.java
@@ -24,8 +24,6 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
-import android.icu.text.MeasureFormat;
-import android.icu.util.MeasureUnit;
import android.net.NetworkPolicy;
import android.net.NetworkTemplate;
import android.os.Bundle;
@@ -36,7 +34,6 @@
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
-import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.Spinner;
@@ -256,17 +253,6 @@
: editor.getPolicyWarningBytes(template);
final long limitDisabled = isLimit ? LIMIT_DISABLED : WARNING_DISABLED;
- final MeasureFormat formatter = MeasureFormat.getInstance(
- getContext().getResources().getConfiguration().locale,
- MeasureFormat.FormatWidth.SHORT);
- final String[] unitNames = new String[] {
- formatter.getUnitDisplayName(MeasureUnit.MEGABYTE),
- formatter.getUnitDisplayName(MeasureUnit.GIGABYTE)
- };
- final ArrayAdapter<String> adapter = new ArrayAdapter<String>(
- getContext(), R.layout.data_usage_spinner_item, unitNames);
- type.setAdapter(adapter);
-
if (bytes > 1.5f * GB_IN_BYTES) {
final String bytesText = formatText(bytes / (float) GB_IN_BYTES);
bytesPicker.setText(bytesText);
diff --git a/src/com/android/settings/development/BluetoothInbandRingingPreferenceController.java b/src/com/android/settings/development/BluetoothInbandRingingPreferenceController.java
index db5a881..809db19 100644
--- a/src/com/android/settings/development/BluetoothInbandRingingPreferenceController.java
+++ b/src/com/android/settings/development/BluetoothInbandRingingPreferenceController.java
@@ -31,11 +31,11 @@
DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
PreferenceControllerMixin {
- private static final String BLUETOOTH_ENABLE_INBAND_RINGING_KEY =
- "bluetooth_enable_inband_ringing";
+ private static final String BLUETOOTH_DISABLE_INBAND_RINGING_KEY =
+ "bluetooth_disable_inband_ringing";
@VisibleForTesting
- static final String BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY =
- "persist.bluetooth.enableinbandringing";
+ static final String BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY =
+ "persist.bluetooth.disableinbandringing";
private SwitchPreference mPreference;
@@ -50,7 +50,7 @@
@Override
public String getPreferenceKey() {
- return BLUETOOTH_ENABLE_INBAND_RINGING_KEY;
+ return BLUETOOTH_DISABLE_INBAND_RINGING_KEY;
}
@Override
@@ -62,16 +62,16 @@
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
- final boolean isEnabled = (Boolean) newValue;
- SystemProperties.set(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY,
- isEnabled ? "true" : "false");
+ final boolean isChecked = (Boolean) newValue;
+ SystemProperties.set(BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY,
+ isChecked ? "true" : "false");
return true;
}
@Override
public void updateState(Preference preference) {
final boolean isEnabled = SystemProperties.getBoolean(
- BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, true /* default */);
+ BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY, false /* default */);
mPreference.setChecked(isEnabled);
}
@@ -83,9 +83,8 @@
@Override
protected void onDeveloperOptionsSwitchDisabled() {
mPreference.setEnabled(false);
- // the default setting for this preference is the enabled state
- mPreference.setChecked(true);
- SystemProperties.set(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, "true");
+ mPreference.setChecked(false);
+ SystemProperties.set(BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY, "false");
}
@VisibleForTesting
diff --git a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java
new file mode 100644
index 0000000..5512685
--- /dev/null
+++ b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java
@@ -0,0 +1,103 @@
+/*
+ * 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.development;
+
+import android.content.Context;
+import android.os.SystemProperties;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.ListPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+
+import com.android.settings.R;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.development.DeveloperOptionsPreferenceController;
+
+public class BluetoothMaxConnectedAudioDevicesPreferenceController extends
+ DeveloperOptionsPreferenceController implements Preference.OnPreferenceChangeListener,
+ PreferenceControllerMixin {
+
+ private static final String BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_KEY =
+ "bluetooth_max_connected_audio_devices";
+
+ @VisibleForTesting
+ static final String BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY =
+ "persist.bluetooth.maxconnectedaudiodevices";
+
+ private final String[] mListValues;
+ private final String[] mListSummaries;
+ private ListPreference mPreference;
+
+ public BluetoothMaxConnectedAudioDevicesPreferenceController(Context context) {
+ super(context);
+
+ mListValues = context.getResources()
+ .getStringArray(R.array.bluetooth_max_connected_audio_devices_values);
+ mListSummaries = context.getResources()
+ .getStringArray(R.array.bluetooth_max_connected_audio_devices);
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_KEY;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+
+ mPreference = (ListPreference) screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValue.toString());
+ updateState(preference);
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final String currentValue = SystemProperties.get(
+ BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
+ int index = 0; // Defaults to 1 device
+ for (int i = 0; i < mListValues.length; i++) {
+ if (TextUtils.equals(currentValue, mListValues[i])) {
+ index = i;
+ break;
+ }
+ }
+ mPreference.setValue(mListValues[index]);
+ mPreference.setSummary(mListSummaries[index]);
+ }
+
+ @Override
+ protected void onDeveloperOptionsSwitchEnabled() {
+ mPreference.setEnabled(true);
+ updateState(mPreference);
+ }
+
+ @Override
+ protected void onDeveloperOptionsSwitchDisabled() {
+ mPreference.setEnabled(false);
+ SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, mListValues[0]);
+ mPreference.setValue(mListValues[0]);
+ mPreference.setSummary(mListSummaries[0]);
+ }
+}
+
diff --git a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
index e736798..a404bc0 100644
--- a/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
+++ b/src/com/android/settings/development/DevelopmentSettingsDashboardFragment.java
@@ -417,6 +417,7 @@
bluetoothA2dpConfigStore));
controllers.add(new BluetoothAudioQualityPreferenceController(context, lifecycle,
bluetoothA2dpConfigStore));
+ controllers.add(new BluetoothMaxConnectedAudioDevicesPreferenceController(context));
controllers.add(new ShowTapsPreferenceController(context));
controllers.add(new PointerLocationPreferenceController(context));
controllers.add(new ShowSurfaceUpdatesPreferenceController(context));
diff --git a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
index 92c33d8..a061f82 100644
--- a/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
+++ b/src/com/android/settings/deviceinfo/SystemUpdatePreferenceController.java
@@ -78,8 +78,12 @@
@Override
public void updateState(Preference preference) {
- preference.setSummary(mContext.getString(R.string.about_summary,
- Build.VERSION.RELEASE));
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
+ return mContext.getString(R.string.about_summary, Build.VERSION.RELEASE);
}
/**
diff --git a/src/com/android/settings/display/AutoBrightnessPreferenceController.java b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
index d71a1f8..28f9260 100644
--- a/src/com/android/settings/display/AutoBrightnessPreferenceController.java
+++ b/src/com/android/settings/display/AutoBrightnessPreferenceController.java
@@ -45,9 +45,10 @@
}
@Override
- public void setChecked(boolean isChecked) {
+ public boolean setChecked(boolean isChecked) {
Settings.System.putInt(mContext.getContentResolver(), SYSTEM_KEY,
isChecked ? SCREEN_BRIGHTNESS_MODE_AUTOMATIC : DEFAULT_VALUE);
+ return true;
}
@Override
diff --git a/src/com/android/settings/fingerprint/FingerprintProfileStatusPreferenceController.java b/src/com/android/settings/fingerprint/FingerprintProfileStatusPreferenceController.java
new file mode 100644
index 0000000..68d2ade
--- /dev/null
+++ b/src/com/android/settings/fingerprint/FingerprintProfileStatusPreferenceController.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.fingerprint;
+
+import android.content.Context;
+import android.os.UserHandle;
+
+public class FingerprintProfileStatusPreferenceController
+ extends FingerprintStatusPreferenceController {
+
+ public static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings_profile";
+
+ public FingerprintProfileStatusPreferenceController(Context context) {
+ super(context, KEY_FINGERPRINT_SETTINGS);
+ }
+
+ @Override
+ protected boolean isUserSupported() {
+ return mProfileChallengeUserId != UserHandle.USER_NULL
+ && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId);
+ }
+
+ @Override
+ protected int getUserId() {
+ return mProfileChallengeUserId;
+ }
+}
diff --git a/src/com/android/settings/fingerprint/FingerprintSettings.java b/src/com/android/settings/fingerprint/FingerprintSettings.java
index ad7f83a..de7187c 100644
--- a/src/com/android/settings/fingerprint/FingerprintSettings.java
+++ b/src/com/android/settings/fingerprint/FingerprintSettings.java
@@ -25,12 +25,10 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.hardware.fingerprint.Fingerprint;
import android.hardware.fingerprint.FingerprintManager;
import android.os.Bundle;
-import android.os.CancellationSignal;
import android.os.Handler;
import android.os.UserHandle;
import android.os.UserManager;
@@ -41,12 +39,7 @@
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import android.support.v7.preference.PreferenceViewHolder;
-import android.text.Annotation;
-import android.text.SpannableString;
-import android.text.SpannableStringBuilder;
-import android.text.TextPaint;
import android.text.TextUtils;
-import android.text.style.URLSpan;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
@@ -61,6 +54,7 @@
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.password.ChooseLockGeneric;
import com.android.settings.password.ChooseLockSettingsHelper;
+import com.android.settings.utils.AnnotationSpan;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
@@ -103,6 +97,9 @@
private static final long LOCKOUT_DURATION = 30000; // time we have to wait for fp to reset, ms
+ public static final String ANNOTATION_URL = "url";
+ public static final String ANNOTATION_ADMIN_DETAILS = "admin_details";
+
public static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings";
@Override
@@ -162,6 +159,20 @@
private FingerprintRemoveSidecar mRemovalSidecar;
private HashMap<Integer, String> mFingerprintsRenaming;
+ final AnnotationSpan.LinkInfo mUrlLinkInfo = new AnnotationSpan.LinkInfo(
+ ANNOTATION_URL, (view) -> {
+ final Context context = view.getContext();
+ Intent intent = HelpUtils.getHelpIntent(context, getString(getHelpResource()),
+ context.getClass().getName());
+ if (intent != null) {
+ try {
+ view.startActivityForResult(intent, 0);
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, "Activity was not found for intent, " + intent.toString());
+ }
+ }
+ });
+
FingerprintAuthenticateSidecar.Listener mAuthenticateListener =
new FingerprintAuthenticateSidecar.Listener() {
@Override
@@ -346,10 +357,15 @@
final FooterPreference pref = mFooterPreferenceMixin.createFooterPreference();
final EnforcedAdmin admin = RestrictedLockUtils.checkIfKeyguardFeaturesDisabled(
activity, DevicePolicyManager.KEYGUARD_DISABLE_FINGERPRINT, mUserId);
- pref.setTitle(LearnMoreSpan.linkify(getText(admin != null
- ? R.string.security_settings_fingerprint_enroll_disclaimer_lockscreen_disabled
+ final AnnotationSpan.LinkInfo adminLinkInfo = new AnnotationSpan.LinkInfo(
+ ANNOTATION_ADMIN_DETAILS, (view) -> {
+ RestrictedLockUtils.sendShowAdminSupportDetailsIntent(activity, admin);
+ });
+ pref.setTitle(AnnotationSpan.linkify(getText(admin != null
+ ? R.string
+ .security_settings_fingerprint_enroll_disclaimer_lockscreen_disabled
: R.string.security_settings_fingerprint_enroll_disclaimer),
- getString(getHelpResource()), admin));
+ mUrlLinkInfo, adminLinkInfo));
}
protected void removeFingerprintPreference(int fingerprintId) {
@@ -906,74 +922,10 @@
}
}
- private static class LearnMoreSpan extends URLSpan {
- private static final String TAG = "LearnMoreSpan";
- private static final Typeface TYPEFACE_MEDIUM =
- Typeface.create("sans-serif-medium", Typeface.NORMAL);
-
- private static final String ANNOTATION_URL = "url";
- private static final String ANNOTATION_ADMIN_DETAILS = "admin_details";
-
- private EnforcedAdmin mEnforcedAdmin = null;
-
- private LearnMoreSpan(String url) {
- super(url);
- }
-
- private LearnMoreSpan(EnforcedAdmin admin) {
- super((String) null);
- mEnforcedAdmin = admin;
- }
-
- @Override
- public void onClick(View widget) {
- Context ctx = widget.getContext();
- if (mEnforcedAdmin != null) {
- RestrictedLockUtils.sendShowAdminSupportDetailsIntent(ctx, mEnforcedAdmin);
- } else {
- Intent intent = HelpUtils.getHelpIntent(ctx, getURL(), ctx.getClass().getName());
- if (intent == null) {
- Log.w(LearnMoreSpan.TAG, "Null help intent.");
- return;
- }
- try {
- widget.startActivityForResult(intent, 0);
- } catch (ActivityNotFoundException e) {
- Log.w(FingerprintSettingsFragment.TAG,
- "Actvity was not found for intent, " + intent.toString());
- }
- }
- }
-
- @Override
- public void updateDrawState(TextPaint ds) {
- super.updateDrawState(ds);
- ds.setUnderlineText(false);
- ds.setTypeface(TYPEFACE_MEDIUM);
- }
-
- public static CharSequence linkify(CharSequence rawText, String uri, EnforcedAdmin admin) {
- SpannableString msg = new SpannableString(rawText);
- Annotation[] spans = msg.getSpans(0, msg.length(), Annotation.class);
- SpannableStringBuilder builder = new SpannableStringBuilder(msg);
- for (Annotation annotation : spans) {
- final String key = annotation.getValue();
- int start = msg.getSpanStart(annotation);
- int end = msg.getSpanEnd(annotation);
- LearnMoreSpan link = null;
- if (ANNOTATION_URL.equals(key)) {
- link = new LearnMoreSpan(uri);
- } else if (ANNOTATION_ADMIN_DETAILS.equals(key)) {
- link = new LearnMoreSpan(admin);
- }
- if (link != null) {
- builder.setSpan(link, start, end, msg.getSpanFlags(link));
- }
- }
- return builder;
- }
- }
-
+ /**
+ * @deprecated in favor of new SecuritySettings.
+ */
+ @Deprecated
public static Preference getFingerprintPreferenceForUser(Context context, final int userId) {
final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(context);
if (fpm == null || !fpm.isHardwareDetected()) {
diff --git a/src/com/android/settings/fingerprint/FingerprintStatusPreferenceController.java b/src/com/android/settings/fingerprint/FingerprintStatusPreferenceController.java
new file mode 100644
index 0000000..19eb4bb
--- /dev/null
+++ b/src/com/android/settings/fingerprint/FingerprintStatusPreferenceController.java
@@ -0,0 +1,118 @@
+/*
+ * 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.fingerprint;
+
+import android.content.Context;
+import android.content.Intent;
+import android.hardware.fingerprint.Fingerprint;
+import android.hardware.fingerprint.FingerprintManager;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+
+import java.util.List;
+
+public class FingerprintStatusPreferenceController extends BasePreferenceController {
+
+ private static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings";
+
+ protected final FingerprintManager mFingerprintManager;
+ protected final UserManager mUm;
+ protected final LockPatternUtils mLockPatternUtils;
+
+ protected final int mUserId = UserHandle.myUserId();
+ protected final int mProfileChallengeUserId;
+
+ public FingerprintStatusPreferenceController(Context context) {
+ this(context, KEY_FINGERPRINT_SETTINGS);
+ }
+
+ public FingerprintStatusPreferenceController(Context context, String key) {
+ super(context, key);
+ mFingerprintManager = Utils.getFingerprintManagerOrNull(context);
+ mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ mLockPatternUtils = FeatureFactory.getFactory(context)
+ .getSecurityFeatureProvider()
+ .getLockPatternUtils(context);
+ mProfileChallengeUserId = Utils.getManagedProfileId(mUm, mUserId);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (mFingerprintManager == null || !mFingerprintManager.isHardwareDetected()) {
+ return DISABLED_UNSUPPORTED;
+ }
+ if (isUserSupported()) {
+ return AVAILABLE;
+ } else {
+ return DISABLED_FOR_USER;
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ if (!isAvailable()) {
+ if (preference != null) {
+ preference.setVisible(false);
+ }
+ return;
+ } else {
+ preference.setVisible(true);
+ }
+ final int userId = getUserId();
+ final List<Fingerprint> items = mFingerprintManager.getEnrolledFingerprints(userId);
+ final int fingerprintCount = items != null ? items.size() : 0;
+ final String clazz;
+ if (fingerprintCount > 0) {
+ preference.setSummary(mContext.getResources().getQuantityString(
+ R.plurals.security_settings_fingerprint_preference_summary,
+ fingerprintCount, fingerprintCount));
+ clazz = FingerprintSettings.class.getName();
+ } else {
+ preference.setSummary(
+ R.string.security_settings_fingerprint_preference_summary_none);
+ clazz = FingerprintEnrollIntroduction.class.getName();
+ }
+ preference.setOnPreferenceClickListener(target -> {
+ final Context context = target.getContext();
+ final UserManager userManager = UserManager.get(context);
+ if (Utils.startQuietModeDialogIfNecessary(context, userManager,
+ userId)) {
+ return false;
+ }
+ Intent intent = new Intent();
+ intent.setClassName("com.android.settings", clazz);
+ intent.putExtra(Intent.EXTRA_USER_ID, userId);
+ context.startActivity(intent);
+ return true;
+ });
+ }
+
+ protected int getUserId() {
+ return mUserId;
+ }
+
+ protected boolean isUserSupported() {
+ return true;
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index a5b6c08..0315f03 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -84,10 +84,6 @@
private static final String KEY_SCREEN_USAGE = "screen_usage";
private static final String KEY_TIME_SINCE_LAST_FULL_CHARGE = "last_full_charge";
-
- private static final String KEY_AUTO_BRIGHTNESS = "auto_brightness_battery";
- private static final String KEY_SCREEN_TIMEOUT = "screen_timeout_battery";
- private static final String KEY_AMBIENT_DISPLAY = "ambient_display_battery";
private static final String KEY_BATTERY_SAVER_SUMMARY = "battery_saver_summary";
@VisibleForTesting
@@ -272,14 +268,9 @@
mBatteryTipPreferenceController = new BatteryTipPreferenceController(context,
KEY_BATTERY_TIP, this);
controllers.add(mBatteryTipPreferenceController);
- controllers.add(new AutoBrightnessPreferenceController(context, KEY_AUTO_BRIGHTNESS));
- controllers.add(new TimeoutPreferenceController(context, KEY_SCREEN_TIMEOUT));
controllers.add(new BatterySaverController(context, getLifecycle()));
controllers.add(new BatteryPercentagePreferenceController(context));
- controllers.add(new AmbientDisplayPreferenceController(
- context,
- new AmbientDisplayConfiguration(context),
- KEY_AMBIENT_DISPLAY));
+
return controllers;
}
@@ -544,10 +535,6 @@
public List<String> getNonIndexableKeys(Context context) {
List<String> niks = super.getNonIndexableKeys(context);
niks.add(KEY_BATTERY_SAVER_SUMMARY);
- // Duplicates in display
- niks.add(KEY_AUTO_BRIGHTNESS);
- niks.add(KEY_SCREEN_TIMEOUT);
- niks.add(KEY_AMBIENT_DISPLAY);
return niks;
}
};
diff --git a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
index 819b128..8b2fcc0 100644
--- a/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
+++ b/src/com/android/settings/gestures/GesturesSettingPreferenceController.java
@@ -24,7 +24,6 @@
import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.AbstractPreferenceController;
@@ -58,25 +57,28 @@
@Override
public void updateState(Preference preference) {
+ preference.setSummary(getSummary());
+ }
+
+ @Override
+ public String getSummary() {
if (!mFeatureProvider.isSensorAvailable(mContext)) {
- preference.setSummary("");
- return;
+ return "";
}
final ContentResolver contentResolver = mContext.getContentResolver();
final boolean assistGestureEnabled = Settings.Secure.getInt(
contentResolver, Settings.Secure.ASSIST_GESTURE_ENABLED, 1) != 0;
final boolean assistGestureSilenceEnabled = Settings.Secure.getInt(
contentResolver, Settings.Secure.ASSIST_GESTURE_SILENCE_ALERTS_ENABLED, 1) != 0;
- final String summary;
+
if (mFeatureProvider.isSupported(mContext) && assistGestureEnabled) {
- summary = mContext.getString(
+ return mContext.getString(
R.string.language_input_gesture_summary_on_with_assist);
- } else if (assistGestureSilenceEnabled) {
- summary = mContext.getString(
- R.string.language_input_gesture_summary_on_non_assist);
- } else {
- summary = mContext.getString(R.string.language_input_gesture_summary_off);
}
- preference.setSummary(summary);
+ if (assistGestureSilenceEnabled) {
+ return mContext.getString(
+ R.string.language_input_gesture_summary_on_non_assist);
+ }
+ return mContext.getString(R.string.language_input_gesture_summary_off);
}
}
\ No newline at end of file
diff --git a/src/com/android/settings/network/PrivateDnsModeDialogFragment.java b/src/com/android/settings/network/PrivateDnsModeDialogFragment.java
index 5704fb9..8b7ccce 100644
--- a/src/com/android/settings/network/PrivateDnsModeDialogFragment.java
+++ b/src/com/android/settings/network/PrivateDnsModeDialogFragment.java
@@ -22,22 +22,30 @@
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.FragmentManager;
+import android.content.ActivityNotFoundException;
import android.content.ContentResolver;
import android.content.Context;
import android.content.DialogInterface;
+import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.support.annotation.VisibleForTesting;
import android.text.Editable;
import android.text.TextWatcher;
+import android.text.method.LinkMovementMethod;
+import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
+import android.widget.TextView;
+import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settings.utils.AnnotationSpan;
+import com.android.settingslib.HelpUtils;
import java.util.HashMap;
import java.util.Map;
@@ -48,6 +56,8 @@
public class PrivateDnsModeDialogFragment extends InstrumentedDialogFragment implements
DialogInterface.OnClickListener, RadioGroup.OnCheckedChangeListener, TextWatcher {
+ public static final String ANNOTATION_URL = "url";
+
private static final String TAG = "PrivateDnsModeDialogFragment";
// DNS_MODE -> RadioButton id
private static final Map<String, Integer> PRIVATE_DNS_MAP;
@@ -73,6 +83,21 @@
@VisibleForTesting
String mMode;
+ private final AnnotationSpan.LinkInfo mUrlLinkInfo = new AnnotationSpan.LinkInfo(
+ ANNOTATION_URL, (widget) -> {
+ final Context context = widget.getContext();
+ final Intent intent = HelpUtils.getHelpIntent(context,
+ getString(R.string.help_uri_private_dns),
+ context.getClass().getName());
+ if (intent != null) {
+ try {
+ widget.startActivityForResult(intent, 0);
+ } catch (ActivityNotFoundException e) {
+ Log.w(TAG, "Activity was not found for intent, " + intent.toString());
+ }
+ }
+ });
+
public static void show(FragmentManager fragmentManager) {
if (fragmentManager.findFragmentByTag(TAG) == null) {
final PrivateDnsModeDialogFragment fragment = new PrivateDnsModeDialogFragment();
@@ -112,25 +137,30 @@
mRadioGroup.setOnCheckedChangeListener(this);
mRadioGroup.check(PRIVATE_DNS_MAP.getOrDefault(mMode, R.id.private_dns_mode_opportunistic));
+ final TextView helpTextView = view.findViewById(R.id.private_dns_help_info);
+ helpTextView.setMovementMethod(LinkMovementMethod.getInstance());
+ helpTextView.setText(AnnotationSpan.linkify(
+ context.getText(R.string.private_dns_help_message), mUrlLinkInfo));
+
return view;
}
@Override
public void onClick(DialogInterface dialog, int which) {
- //TODO(b/34953048): add metric action
if (mMode.equals(PRIVATE_DNS_MODE_PROVIDER_HOSTNAME)) {
// Only clickable if hostname is valid, so we could save it safely
Settings.Global.putString(getContext().getContentResolver(), HOSTNAME_KEY,
mEditText.getText().toString());
}
+ mMetricsFeatureProvider.action(getContext(),
+ MetricsProto.MetricsEvent.ACTION_PRIVATE_DNS_MODE, mMode);
Settings.Global.putString(getContext().getContentResolver(), MODE_KEY, mMode);
}
@Override
public int getMetricsCategory() {
- //TODO(b/68030013): add metric id
- return 0;
+ return MetricsProto.MetricsEvent.DIALOG_PRIVATE_DNS;
}
@Override
diff --git a/src/com/android/settings/notification/HeaderPreferenceController.java b/src/com/android/settings/notification/HeaderPreferenceController.java
index 3d51b25..5ec60c2 100644
--- a/src/com/android/settings/notification/HeaderPreferenceController.java
+++ b/src/com/android/settings/notification/HeaderPreferenceController.java
@@ -77,7 +77,8 @@
: mAppRow.label;
}
- CharSequence getSummary() {
+ @Override
+ public String getSummary() {
if (mChannel != null) {
if (mChannelGroup != null && mChannelGroup.getGroup() != null
&& !TextUtils.isEmpty(mChannelGroup.getGroup().getName())) {
@@ -87,12 +88,12 @@
summary.append(bidi.unicodeWrap(mContext.getText(
R.string.notification_header_divider_symbol_with_spaces)));
summary.append(bidi.unicodeWrap(mChannelGroup.getGroup().getName().toString()));
- return summary;
+ return summary.toString();
} else {
- return mAppRow.label;
+ return mAppRow.label.toString();
}
} else if (mChannelGroup != null && mChannelGroup.getGroup() != null) {
- return mAppRow.label;
+ return mAppRow.label.toString();
} else {
return "";
}
diff --git a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java
index dd7b0fb..d56febb 100644
--- a/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java
+++ b/src/com/android/settings/notification/LockScreenNotificationPreferenceController.java
@@ -36,6 +36,7 @@
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
@@ -78,7 +79,9 @@
mProfileChallengeUserId = Utils.getManagedProfileId(
UserManager.get(context), UserHandle.myUserId());
- final LockPatternUtils utils = new LockPatternUtils(context);
+ final LockPatternUtils utils = FeatureFactory.getFactory(context)
+ .getSecurityFeatureProvider()
+ .getLockPatternUtils(context);
mSecure = utils.isSecure(UserHandle.myUserId());
mSecureProfile = (mProfileChallengeUserId != UserHandle.USER_NULL)
&& (utils.isSecure(mProfileChallengeUserId)
@@ -278,10 +281,14 @@
}
}
- public int getSummaryResource() {
- final boolean enabled = getLockscreenNotificationsEnabled(UserHandle.myUserId());
- final boolean allowPrivate = !mSecure
- || getLockscreenAllowPrivateNotifications(UserHandle.myUserId());
+ public static int getSummaryResource(Context context) {
+ final boolean enabled = getLockscreenNotificationsEnabled(context, UserHandle.myUserId());
+ final boolean secure = FeatureFactory.getFactory(context)
+ .getSecurityFeatureProvider()
+ .getLockPatternUtils(context)
+ .isSecure(UserHandle.myUserId());
+ final boolean allowPrivate = !secure
+ || getLockscreenAllowPrivateNotifications(context, UserHandle.myUserId());
return !enabled ? R.string.lock_screen_notifications_summary_disable :
allowPrivate ? R.string.lock_screen_notifications_summary_show :
R.string.lock_screen_notifications_summary_hide;
@@ -291,7 +298,7 @@
if (mLockscreen == null) {
return;
}
- mLockscreenSelectedValue = getSummaryResource();
+ mLockscreenSelectedValue = getSummaryResource(mContext);
mLockscreen.setSummary("%s");
mLockscreen.setValue(Integer.toString(mLockscreenSelectedValue));
}
@@ -303,9 +310,9 @@
if (mLockscreenProfile == null) {
return;
}
- final boolean enabled = getLockscreenNotificationsEnabled(mProfileChallengeUserId);
+ final boolean enabled = getLockscreenNotificationsEnabled(mContext,mProfileChallengeUserId);
final boolean allowPrivate = !mSecureProfile
- || getLockscreenAllowPrivateNotifications(mProfileChallengeUserId);
+ || getLockscreenAllowPrivateNotifications(mContext, mProfileChallengeUserId);
mLockscreenProfile.setSummary("%s");
mLockscreenSelectedValueProfile = !enabled
? R.string.lock_screen_notifications_summary_disable_profile
@@ -314,13 +321,13 @@
mLockscreenProfile.setValue(Integer.toString(mLockscreenSelectedValueProfile));
}
- private boolean getLockscreenNotificationsEnabled(int userId) {
- return Settings.Secure.getIntForUser(mContext.getContentResolver(),
+ private static boolean getLockscreenNotificationsEnabled(Context context, int userId) {
+ return Settings.Secure.getIntForUser(context.getContentResolver(),
Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0, userId) != 0;
}
- private boolean getLockscreenAllowPrivateNotifications(int userId) {
- return Settings.Secure.getIntForUser(mContext.getContentResolver(),
+ private static boolean getLockscreenAllowPrivateNotifications(Context context, int userId) {
+ return Settings.Secure.getIntForUser(context.getContentResolver(),
Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 0, userId) != 0;
}
diff --git a/src/com/android/settings/password/ChooseLockPassword.java b/src/com/android/settings/password/ChooseLockPassword.java
index 4e54f3c..11efec3 100644
--- a/src/com/android/settings/password/ChooseLockPassword.java
+++ b/src/com/android/settings/password/ChooseLockPassword.java
@@ -210,7 +210,7 @@
private String mFirstPin;
private RecyclerView mPasswordRestrictionView;
protected boolean mIsAlphaMode;
- protected Button mCancelButton;
+ protected Button mSkipButton;
private Button mClearButton;
private Button mNextButton;
private TextView mMessage;
@@ -377,8 +377,8 @@
ViewGroup container = view.findViewById(R.id.password_container);
container.setOpticalInsets(Insets.NONE);
- mCancelButton = (Button) view.findViewById(R.id.cancel_button);
- mCancelButton.setOnClickListener(this);
+ mSkipButton = (Button) view.findViewById(R.id.skip_button);
+ mSkipButton.setOnClickListener(this);
mNextButton = (Button) view.findViewById(R.id.next_button);
mNextButton.setOnClickListener(this);
mClearButton = view.findViewById(R.id.clear_button);
@@ -774,10 +774,6 @@
handleNext();
break;
- case R.id.cancel_button:
- getActivity().finish();
- break;
-
case R.id.clear_button:
mPasswordEntry.setText("");
break;
@@ -901,7 +897,6 @@
}
mClearButton.setVisibility(toVisibility(mUiStage != Stage.Introduction));
- mCancelButton.setVisibility(toVisibility(mUiStage == Stage.Introduction));
setNextText(mUiStage.buttonText);
mPasswordEntryInputDisabler.setInputEnabled(canInput);
diff --git a/src/com/android/settings/password/ChooseLockPattern.java b/src/com/android/settings/password/ChooseLockPattern.java
index 7cd9db8..746a977 100644
--- a/src/com/android/settings/password/ChooseLockPattern.java
+++ b/src/com/android/settings/password/ChooseLockPattern.java
@@ -290,8 +290,6 @@
* The states of the left footer button.
*/
enum LeftButtonMode {
- Cancel(R.string.cancel, true),
- CancelDisabled(R.string.cancel, false),
Retry(R.string.lockpattern_retry_button_text, true),
RetryDisabled(R.string.lockpattern_retry_button_text, false),
Gone(ID_EMPTY_MESSAGE, false);
@@ -342,7 +340,7 @@
R.string.lock_settings_picker_fingerprint_added_security_message,
R.string.lockpassword_choose_your_pattern_message,
R.string.lockpattern_recording_intro_header,
- LeftButtonMode.Cancel, RightButtonMode.ContinueDisabled,
+ LeftButtonMode.Gone, RightButtonMode.ContinueDisabled,
ID_EMPTY_MESSAGE, true),
HelpScreen(
ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_settings_help_how_to_record,
@@ -360,15 +358,15 @@
LeftButtonMode.Retry, RightButtonMode.Continue, ID_EMPTY_MESSAGE, false),
NeedToConfirm(
ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_need_to_confirm,
- LeftButtonMode.Cancel, RightButtonMode.ConfirmDisabled,
+ LeftButtonMode.Gone, RightButtonMode.ConfirmDisabled,
ID_EMPTY_MESSAGE, true),
ConfirmWrong(
ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_need_to_unlock_wrong,
- LeftButtonMode.Cancel, RightButtonMode.ConfirmDisabled,
+ LeftButtonMode.Gone, RightButtonMode.ConfirmDisabled,
ID_EMPTY_MESSAGE, true),
ChoiceConfirmed(
ID_EMPTY_MESSAGE, ID_EMPTY_MESSAGE, R.string.lockpattern_pattern_confirmed_header,
- LeftButtonMode.Cancel, RightButtonMode.Confirm, ID_EMPTY_MESSAGE, false);
+ LeftButtonMode.Gone, RightButtonMode.Confirm, ID_EMPTY_MESSAGE, false);
/**
@@ -413,7 +411,7 @@
private ChooseLockSettingsHelper mChooseLockSettingsHelper;
private SaveAndFinishWorker mSaveAndFinishWorker;
- private int mUserId;
+ protected int mUserId;
private boolean mForFingerprint;
private static final String KEY_UI_STAGE = "uiStage";
@@ -558,8 +556,6 @@
mChosenPattern = null;
mLockPatternView.clearPattern();
updateStage(Stage.Introduction);
- } else if (mUiStage.leftMode == LeftButtonMode.Cancel) {
- getActivity().finish();
} else {
throw new IllegalStateException("left footer button pressed, but stage of " +
mUiStage + " doesn't make sense");
diff --git a/src/com/android/settings/password/ChooseLockTypeDialogFragment.java b/src/com/android/settings/password/ChooseLockTypeDialogFragment.java
index 13dc996..6a66ffb 100644
--- a/src/com/android/settings/password/ChooseLockTypeDialogFragment.java
+++ b/src/com/android/settings/password/ChooseLockTypeDialogFragment.java
@@ -16,6 +16,7 @@
package com.android.settings.password;
+import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
@@ -24,6 +25,7 @@
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
+import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
@@ -33,8 +35,11 @@
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
+import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
+import com.android.setupwizardlib.util.WizardManagerHelper;
import java.util.List;
@@ -60,6 +65,36 @@
public interface OnLockTypeSelectedListener {
void onLockTypeSelected(ScreenLockType lock);
+
+ default void startChooseLockActivity(ScreenLockType selectedLockType, Activity activity) {
+ Intent activityIntent = activity.getIntent();
+ Intent intent = new Intent(activity, SetupChooseLockGeneric.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
+
+ // Copy the original extras into the new intent
+ if (activityIntent.hasExtra(
+ ChooseLockGenericFragment.EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS)) {
+ intent.putExtras(activityIntent.getBundleExtra(
+ ChooseLockGenericFragment.EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS));
+ }
+ intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, selectedLockType.defaultQuality);
+
+ // Propagate the fingerprint challenge
+ intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE,
+ activityIntent.getBooleanExtra(
+ ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE, false));
+ intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE,
+ activityIntent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0));
+
+ // The user is already given the choice of the what screen lock to set up. No need to
+ // show this button again.
+ intent.putExtra(ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
+
+ WizardManagerHelper.copyWizardManagerExtras(activityIntent, intent);
+
+ activity.startActivity(intent);
+ activity.finish();
+ }
}
@Override
diff --git a/src/com/android/settings/password/SetupChooseLockPassword.java b/src/com/android/settings/password/SetupChooseLockPassword.java
index 79cfef3..5c70736 100644
--- a/src/com/android/settings/password/SetupChooseLockPassword.java
+++ b/src/com/android/settings/password/SetupChooseLockPassword.java
@@ -28,13 +28,9 @@
import android.widget.Button;
import android.widget.LinearLayout;
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.SetupRedactionInterstitial;
-import com.android.settings.password.ChooseLockGeneric.ChooseLockGenericFragment;
import com.android.settings.password.ChooseLockTypeDialogFragment.OnLockTypeSelectedListener;
-import com.android.setupwizardlib.util.WizardManagerHelper;
/**
* Setup Wizard's version of ChooseLockPassword screen. It inherits the logic and basic structure
@@ -75,9 +71,6 @@
public static class SetupChooseLockPasswordFragment extends ChooseLockPasswordFragment
implements OnLockTypeSelectedListener {
- @VisibleForTesting
- static final int REQUEST_SCREEN_LOCK_OPTIONS = 1;
-
@Nullable
private Button mOptionsButton;
@@ -90,8 +83,7 @@
boolean anyOptionsShown = chooseLockGenericController.getVisibleScreenLockTypes(
DevicePolicyManager.PASSWORD_QUALITY_SOMETHING, false).size() > 0;
boolean showOptionsButton = activity.getIntent().getBooleanExtra(
- ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
-
+ ChooseLockGeneric.ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
if (!anyOptionsShown) {
Log.w(TAG, "Visible screen lock types is empty!");
}
@@ -107,9 +99,10 @@
public void onClick(View v) {
switch (v.getId()) {
case R.id.screen_lock_options:
- launchChooseLockGeneric();
+ ChooseLockTypeDialogFragment.newInstance(mUserId)
+ .show(getChildFragmentManager(), null);
break;
- case R.id.cancel_button:
+ case R.id.skip_button:
SetupSkipDialog dialog = SetupSkipDialog.newInstance(
getActivity().getIntent()
.getBooleanExtra(SetupSkipDialog.EXTRA_FRP_SUPPORTED, false));
@@ -120,11 +113,6 @@
}
}
- private void launchChooseLockGeneric() {
- ChooseLockTypeDialogFragment.newInstance(mUserId)
- .show(getChildFragmentManager(), null);
- }
-
@Override
protected Intent getRedactionInterstitialIntent(Context context) {
// Setup wizard's redaction interstitial is deferred to optional step. Enable that
@@ -137,57 +125,16 @@
public void onLockTypeSelected(ScreenLockType lock) {
ScreenLockType currentLockType = mIsAlphaMode ?
ScreenLockType.PASSWORD : ScreenLockType.PIN;
- if (currentLockType.equals(lock)) {
- // ignore same lock type.
+ if (lock == currentLockType) {
return;
}
- Intent activityIntent = getActivity().getIntent();
- Intent intent = new Intent(getContext(), SetupChooseLockGeneric.class);
-
- // Copy the original extras into the new intent
- if (activityIntent
- .hasExtra(ChooseLockGenericFragment.EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS)) {
- intent.putExtras(activityIntent.getBundleExtra(
- ChooseLockGenericFragment.EXTRA_CHOOSE_LOCK_GENERIC_EXTRAS));
- }
- intent.putExtra(LockPatternUtils.PASSWORD_TYPE_KEY, lock.defaultQuality);
-
- // Propagate the fingerprint challenge
- intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE,
- activityIntent.getBooleanExtra(ChooseLockSettingsHelper.EXTRA_KEY_HAS_CHALLENGE,
- false));
- intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE,
- activityIntent.getLongExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE, 0));
-
- // The user is already given the choice of the what screen lock to set up. No need to
- // show this button again.
- intent.putExtra(ChooseLockGenericFragment.EXTRA_SHOW_OPTIONS_BUTTON, false);
-
- WizardManagerHelper.copyWizardManagerExtras(activityIntent, intent);
-
- startActivityForResult(intent, REQUEST_SCREEN_LOCK_OPTIONS);
- }
-
- @Override
- public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == REQUEST_SCREEN_LOCK_OPTIONS) {
- if (resultCode != Activity.RESULT_CANCELED) {
- Activity activity = getActivity();
- activity.setResult(resultCode, data);
- activity.finish();
- }
- }
+ startChooseLockActivity(lock, getActivity());
}
@Override
protected void updateUi() {
super.updateUi();
- if (mForFingerprint) {
- mCancelButton.setVisibility(View.GONE);
- } else {
- mCancelButton.setText(R.string.skip_label);
- }
+ mSkipButton.setVisibility(mForFingerprint ? View.GONE : View.VISIBLE);
if (mOptionsButton != null) {
mOptionsButton.setVisibility(
diff --git a/src/com/android/settings/password/SetupChooseLockPattern.java b/src/com/android/settings/password/SetupChooseLockPattern.java
index b1e3d0d..b1c9fac 100644
--- a/src/com/android/settings/password/SetupChooseLockPattern.java
+++ b/src/com/android/settings/password/SetupChooseLockPattern.java
@@ -19,7 +19,11 @@
import android.app.Fragment;
import android.content.Context;
import android.content.Intent;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import com.android.settings.R;
import com.android.settings.SetupRedactionInterstitial;
/**
@@ -46,7 +50,26 @@
return SetupChooseLockPatternFragment.class;
}
- public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment {
+ public static class SetupChooseLockPatternFragment extends ChooseLockPatternFragment
+ implements ChooseLockTypeDialogFragment.OnLockTypeSelectedListener {
+
+ @Override
+ public void onViewCreated(View view, Bundle savedInstanceState) {
+ super.onViewCreated(view, savedInstanceState);
+ Button optionsButton = (Button) view.findViewById(R.id.screen_lock_options);
+ optionsButton.setVisibility(View.VISIBLE);
+ optionsButton.setOnClickListener((btn) ->
+ ChooseLockTypeDialogFragment.newInstance(mUserId)
+ .show(getChildFragmentManager(), null));
+ }
+
+ @Override
+ public void onLockTypeSelected(ScreenLockType lock) {
+ if (ScreenLockType.PATTERN == lock) {
+ return;
+ }
+ startChooseLockActivity(lock, getActivity());
+ }
@Override
protected Intent getRedactionInterstitialIntent(Context context) {
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index c4e178f..0207c94 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -75,7 +75,7 @@
import com.android.settings.security.EncryptionAndCredential;
import com.android.settings.security.LockscreenDashboardFragment;
import com.android.settings.security.ScreenPinningSettings;
-import com.android.settings.security.SecuritySettings;
+import com.android.settings.security.SecuritySettingsV2;
import com.android.settings.security.screenlock.ScreenLockSettings;
import com.android.settings.sim.SimSettings;
import com.android.settings.support.SupportDashboardActivity;
@@ -135,7 +135,7 @@
addIndex(LocationSettings.class);
addIndex(LocationMode.class);
addIndex(ScanningSettings.class);
- addIndex(SecuritySettings.class);
+ addIndex(SecuritySettingsV2.class);
addIndex(ScreenLockSettings.class);
addIndex(EncryptionAndCredential.class);
addIndex(ScreenPinningSettings.class);
@@ -179,5 +179,7 @@
private SearchIndexableResources() {
}
- public static Collection<Class> providerValues() { return sProviders;}
+ public static Collection<Class> providerValues() {
+ return sProviders;
+ }
}
\ No newline at end of file
diff --git a/src/com/android/settings/security/ChangeProfileScreenLockPreferenceController.java b/src/com/android/settings/security/ChangeProfileScreenLockPreferenceController.java
new file mode 100644
index 0000000..9a33ec3
--- /dev/null
+++ b/src/com/android/settings/security/ChangeProfileScreenLockPreferenceController.java
@@ -0,0 +1,101 @@
+/*
+ * 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.security;
+
+import static com.android.settings.security
+ .SecuritySettingsV2.SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.support.v7.preference.Preference;
+import android.text.TextUtils;
+
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.password.ChooseLockGeneric;
+
+public class ChangeProfileScreenLockPreferenceController extends
+ ChangeScreenLockPreferenceController {
+
+ private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile";
+
+ public ChangeProfileScreenLockPreferenceController(Context context,
+ SecuritySettingsV2 host) {
+ super(context, host);
+ }
+
+ public boolean isAvailable() {
+ if (mProfileChallengeUserId == UserHandle.USER_NULL ||
+ !mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
+ return false;
+ }
+ if (!mLockPatternUtils.isSecure(mProfileChallengeUserId)) {
+ return true;
+ }
+ switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)) {
+ case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
+ case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
+ case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
+ case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_UNLOCK_SET_OR_CHANGE_PROFILE;
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
+ return false;
+ }
+ if (Utils.startQuietModeDialogIfNecessary(mContext, mUm, mProfileChallengeUserId)) {
+ return false;
+ }
+ final Bundle extras = new Bundle();
+ extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId);
+ mHost.startFragment(mHost, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
+ R.string.lock_settings_picker_title_profile,
+ SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE, extras);
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ updateSummary(preference, mProfileChallengeUserId);
+
+ if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
+ final String summary = mContext.getString(
+ R.string.lock_settings_profile_unified_summary);
+ mPreference.setSummary(summary);
+ mPreference.setEnabled(false);
+ } else {
+ // PO may disallow to change profile password, and the profile's password is
+ // separated from screen lock password. Disable profile specific "Screen lock" menu.
+ disableIfPasswordQualityManaged(mProfileChallengeUserId);
+ }
+ }
+}
diff --git a/src/com/android/settings/security/ChangeScreenLockPreferenceController.java b/src/com/android/settings/security/ChangeScreenLockPreferenceController.java
new file mode 100644
index 0000000..67b78fc
--- /dev/null
+++ b/src/com/android/settings/security/ChangeScreenLockPreferenceController.java
@@ -0,0 +1,176 @@
+/*
+ * 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.security;
+
+import static com.android.settings.security.SecuritySettingsV2.SET_OR_CHANGE_LOCK_METHOD_REQUEST;
+
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.os.storage.StorageManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.password.ChooseLockGeneric;
+import com.android.settings.security.screenlock.ScreenLockSettings;
+import com.android.settings.widget.GearPreference;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class ChangeScreenLockPreferenceController extends AbstractPreferenceController implements
+ PreferenceControllerMixin, GearPreference.OnGearClickListener {
+
+ private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
+
+ protected final DevicePolicyManager mDPM;
+ protected final SecuritySettingsV2 mHost;
+ protected final UserManager mUm;
+ protected final LockPatternUtils mLockPatternUtils;
+
+ protected final int mUserId = UserHandle.myUserId();
+ protected final int mProfileChallengeUserId;
+
+ protected RestrictedPreference mPreference;
+
+ public ChangeScreenLockPreferenceController(Context context, SecuritySettingsV2 host) {
+ super(context);
+ mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ mDPM = (DevicePolicyManager) context.getSystemService(Context.DEVICE_POLICY_SERVICE);
+ mLockPatternUtils = FeatureFactory.getFactory(context)
+ .getSecurityFeatureProvider()
+ .getLockPatternUtils(context);
+ mHost = host;
+ mProfileChallengeUserId = Utils.getManagedProfileId(mUm, mUserId);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ return true;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_UNLOCK_SET_OR_CHANGE;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = (RestrictedPreference) screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ if (mPreference != null && mPreference instanceof GearPreference) {
+ if (mLockPatternUtils.isSecure(mUserId)
+ || !mLockPatternUtils.isLockScreenDisabled(mUserId)) {
+ ((GearPreference) mPreference).setOnGearClickListener(this);
+ } else {
+ ((GearPreference) mPreference).setOnGearClickListener(null);
+ }
+ }
+
+ updateSummary(preference, mUserId);
+ disableIfPasswordQualityManaged(mUserId);
+ if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
+ // PO may disallow to change password for the profile, but screen lock and managed
+ // profile's lock is the same. Disable main "Screen lock" menu.
+ disableIfPasswordQualityManaged(mProfileChallengeUserId);
+ }
+ }
+
+ @Override
+ public void onGearClick(GearPreference p) {
+ if (TextUtils.equals(p.getKey(), getPreferenceKey())) {
+ mHost.startFragment(mHost, ScreenLockSettings.class.getName(), 0, 0, null);
+ }
+ }
+
+ @Override
+ public boolean handlePreferenceTreeClick(Preference preference) {
+ if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
+ return super.handlePreferenceTreeClick(preference);
+ }
+ // TODO(b/35930129): Remove once existing password can be passed into vold directly.
+ // Currently we need this logic to ensure that the QUIET_MODE is off for any work
+ // profile with unified challenge on FBE-enabled devices. Otherwise, vold would not be
+ // able to complete the operation due to the lack of (old) encryption key.
+ if (mProfileChallengeUserId != UserHandle.USER_NULL
+ && !mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)
+ && StorageManager.isFileEncryptedNativeOnly()) {
+ if (Utils.startQuietModeDialogIfNecessary(mContext, mUm, mProfileChallengeUserId)) {
+ return false;
+ }
+ }
+ mHost.startFragment(mHost, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
+ R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
+ return true;
+ }
+
+ protected void updateSummary(Preference preference, int userId) {
+ if (!mLockPatternUtils.isSecure(userId)) {
+ if (userId == mProfileChallengeUserId
+ || mLockPatternUtils.isLockScreenDisabled(userId)) {
+ preference.setSummary(R.string.unlock_set_unlock_mode_off);
+ } else {
+ preference.setSummary(R.string.unlock_set_unlock_mode_none);
+ }
+ } else {
+ switch (mLockPatternUtils.getKeyguardStoredPasswordQuality(userId)) {
+ case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
+ preference.setSummary(R.string.unlock_set_unlock_mode_pattern);
+ break;
+ case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
+ preference.setSummary(R.string.unlock_set_unlock_mode_pin);
+ break;
+ case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
+ case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
+ case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
+ preference.setSummary(R.string.unlock_set_unlock_mode_password);
+ break;
+ }
+ }
+ mPreference.setEnabled(true);
+ }
+
+ /**
+ * Sets the preference as disabled by admin if PASSWORD_QUALITY_MANAGED is set.
+ * The preference must be a RestrictedPreference.
+ * <p/>
+ * DO or PO installed in the user may disallow to change password.
+ */
+ void disableIfPasswordQualityManaged(int userId) {
+ final RestrictedLockUtils.EnforcedAdmin admin = RestrictedLockUtils
+ .checkIfPasswordQualityIsSet(mContext, userId);
+ final DevicePolicyManager dpm = (DevicePolicyManager) mContext
+ .getSystemService(Context.DEVICE_POLICY_SERVICE);
+ if (admin != null && dpm.getPasswordQuality(admin.component, userId)
+ == DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
+ mPreference.setDisabledByAdmin(admin);
+ }
+ }
+}
diff --git a/src/com/android/settings/security/EncryptionAndCredential.java b/src/com/android/settings/security/EncryptionAndCredential.java
index aa35dd3..627cf3e 100644
--- a/src/com/android/settings/security/EncryptionAndCredential.java
+++ b/src/com/android/settings/security/EncryptionAndCredential.java
@@ -66,7 +66,8 @@
Lifecycle lifecycle) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
final EncryptionStatusPreferenceController encryptStatusController =
- new EncryptionStatusPreferenceController(context, PREF_KEY_ENCRYPTION_DETAIL_PAGE);
+ new EncryptionStatusPreferenceController(context,
+ PREF_KEY_ENCRYPTION_DETAIL_PAGE);
controllers.add(encryptStatusController);
controllers.add(new PreferenceCategoryController(context,
"encryption_and_credentials_status_category",
diff --git a/src/com/android/settings/security/LockUnificationPreferenceController.java b/src/com/android/settings/security/LockUnificationPreferenceController.java
new file mode 100644
index 0000000..5486e29
--- /dev/null
+++ b/src/com/android/settings/security/LockUnificationPreferenceController.java
@@ -0,0 +1,218 @@
+/*
+ * 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.security;
+
+import static com.android.settings.security
+ .SecuritySettingsV2.SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE;
+import static com.android.settings.security.SecuritySettingsV2.UNIFY_LOCK_CONFIRM_DEVICE_REQUEST;
+import static com.android.settings.security.SecuritySettingsV2.UNIFY_LOCK_CONFIRM_PROFILE_REQUEST;
+import static com.android.settings.security.SecuritySettingsV2.UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST;
+
+import android.app.Activity;
+import android.app.admin.DevicePolicyManager;
+import android.content.Context;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.password.ChooseLockGeneric;
+import com.android.settings.password.ChooseLockSettingsHelper;
+import com.android.settingslib.RestrictedLockUtils;
+import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+public class LockUnificationPreferenceController extends AbstractPreferenceController
+ implements PreferenceControllerMixin, Preference.OnPreferenceChangeListener {
+
+ private static final String KEY_UNIFICATION = "unification";
+
+ private static final int MY_USER_ID = UserHandle.myUserId();
+
+ private final UserManager mUm;
+ private final LockPatternUtils mLockPatternUtils;
+ private final int mProfileChallengeUserId;
+ private final SecuritySettingsV2 mHost;
+
+ private RestrictedSwitchPreference mUnifyProfile;
+
+
+ private String mCurrentDevicePassword;
+ private String mCurrentProfilePassword;
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mUnifyProfile = (RestrictedSwitchPreference) screen.findPreference(KEY_UNIFICATION);
+ }
+
+ public LockUnificationPreferenceController(Context context, SecuritySettingsV2 host) {
+ super(context);
+ mHost = host;
+ mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ mLockPatternUtils = FeatureFactory.getFactory(context)
+ .getSecurityFeatureProvider()
+ .getLockPatternUtils(context);
+ mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
+ }
+
+ @Override
+ public boolean isAvailable() {
+ final boolean allowSeparateProfileChallenge =
+ mProfileChallengeUserId != UserHandle.USER_NULL
+ && mLockPatternUtils.isSeparateProfileChallengeAllowed(
+ mProfileChallengeUserId);
+ return allowSeparateProfileChallenge;
+ }
+
+ @Override
+ public String getPreferenceKey() {
+ return KEY_UNIFICATION;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object value) {
+ if (Utils.startQuietModeDialogIfNecessary(mContext, mUm, mProfileChallengeUserId)) {
+ return false;
+ }
+ if ((Boolean) value) {
+ final boolean compliantForDevice =
+ (mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)
+ >= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING
+ && mLockPatternUtils.isSeparateProfileChallengeAllowedToUnify(
+ mProfileChallengeUserId));
+ UnificationConfirmationDialog dialog =
+ UnificationConfirmationDialog.newInstance(compliantForDevice);
+ dialog.show(mHost);
+ } else {
+ final String title = mContext.getString(R.string.unlock_set_unlock_launch_picker_title);
+ final ChooseLockSettingsHelper helper =
+ new ChooseLockSettingsHelper(mHost.getActivity(), mHost);
+ if (!helper.launchConfirmationActivity(
+ UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST,
+ title, true /* returnCredentials */, MY_USER_ID)) {
+ ununifyLocks();
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ if (mUnifyProfile != null) {
+ final boolean separate =
+ mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId);
+ mUnifyProfile.setChecked(!separate);
+ if (separate) {
+ mUnifyProfile.setDisabledByAdmin(RestrictedLockUtils.checkIfRestrictionEnforced(
+ mContext, UserManager.DISALLOW_UNIFIED_PASSWORD,
+ mProfileChallengeUserId));
+ }
+ }
+ }
+
+ public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
+ if (requestCode == UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST
+ && resultCode == Activity.RESULT_OK) {
+ ununifyLocks();
+ return true;
+ } else if (requestCode == UNIFY_LOCK_CONFIRM_DEVICE_REQUEST
+ && resultCode == Activity.RESULT_OK) {
+ mCurrentDevicePassword =
+ data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
+ launchConfirmProfileLockForUnification();
+ return true;
+ } else if (requestCode == UNIFY_LOCK_CONFIRM_PROFILE_REQUEST
+ && resultCode == Activity.RESULT_OK) {
+ mCurrentProfilePassword =
+ data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
+ unifyLocks();
+ return true;
+ }
+ return false;
+ }
+
+ private void ununifyLocks() {
+ Bundle extras = new Bundle();
+ extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId);
+ mHost.startFragment(mHost,
+ ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
+ R.string.lock_settings_picker_title_profile,
+ SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE, extras);
+ }
+
+ void launchConfirmDeviceLockForUnification() {
+ final String title = mContext.getString(
+ R.string.unlock_set_unlock_launch_picker_title);
+ final ChooseLockSettingsHelper helper =
+ new ChooseLockSettingsHelper(mHost.getActivity(), mHost);
+ if (!helper.launchConfirmationActivity(
+ UNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, MY_USER_ID)) {
+ launchConfirmProfileLockForUnification();
+ }
+ }
+
+ private void launchConfirmProfileLockForUnification() {
+ final String title = mContext.getString(
+ R.string.unlock_set_unlock_launch_picker_title_profile);
+ final ChooseLockSettingsHelper helper =
+ new ChooseLockSettingsHelper(mHost.getActivity(), mHost);
+ if (!helper.launchConfirmationActivity(
+ UNIFY_LOCK_CONFIRM_PROFILE_REQUEST, title, true, mProfileChallengeUserId)) {
+ unifyLocks();
+ // TODO: update relevant prefs.
+ // createPreferenceHierarchy();
+ }
+ }
+
+ private void unifyLocks() {
+ int profileQuality =
+ mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId);
+ if (profileQuality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
+ mLockPatternUtils.saveLockPattern(
+ LockPatternUtils.stringToPattern(mCurrentProfilePassword),
+ mCurrentDevicePassword, MY_USER_ID);
+ } else {
+ mLockPatternUtils.saveLockPassword(
+ mCurrentProfilePassword, mCurrentDevicePassword,
+ profileQuality, MY_USER_ID);
+ }
+ mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, false,
+ mCurrentProfilePassword);
+ final boolean profilePatternVisibility =
+ mLockPatternUtils.isVisiblePatternEnabled(mProfileChallengeUserId);
+ mLockPatternUtils.setVisiblePatternEnabled(profilePatternVisibility, MY_USER_ID);
+ mCurrentDevicePassword = null;
+ mCurrentProfilePassword = null;
+ }
+
+ void unifyUncompliantLocks() {
+ mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, false,
+ mCurrentProfilePassword);
+ mHost.startFragment(mHost, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
+ R.string.lock_settings_picker_title,
+ SecuritySettingsV2.SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
+ }
+
+}
diff --git a/src/com/android/settings/security/SecuritySettings.java b/src/com/android/settings/security/SecuritySettings.java
index fc47b5c..f099b44 100644
--- a/src/com/android/settings/security/SecuritySettings.java
+++ b/src/com/android/settings/security/SecuritySettings.java
@@ -161,7 +161,6 @@
private LocationPreferenceController mLocationcontroller;
private ManageDeviceAdminPreferenceController mManageDeviceAdminPreferenceController;
private EnterprisePrivacyPreferenceController mEnterprisePrivacyPreferenceController;
- private LockScreenNotificationPreferenceController mLockScreenNotificationPreferenceController;
@Override
public int getMetricsCategory() {
@@ -208,8 +207,6 @@
= new ManageDeviceAdminPreferenceController(activity);
mEnterprisePrivacyPreferenceController
= new EnterprisePrivacyPreferenceController(activity);
- mLockScreenNotificationPreferenceController
- = new LockScreenNotificationPreferenceController(activity);
}
private static int getResIdForLockUnlockScreen(LockPatternUtils lockPatternUtils,
@@ -430,7 +427,7 @@
final Preference lockscreenPreferences = group.findPreference(KEY_LOCKSCREEN_PREFERENCES);
if (lockscreenPreferences != null) {
lockscreenPreferences.setSummary(
- mLockScreenNotificationPreferenceController.getSummaryResource());
+ LockScreenNotificationPreferenceController.getSummaryResource(getContext()));
}
}
diff --git a/src/com/android/settings/security/SecuritySettingsV2.java b/src/com/android/settings/security/SecuritySettingsV2.java
index 002e447..323c0f4 100644
--- a/src/com/android/settings/security/SecuritySettingsV2.java
+++ b/src/com/android/settings/security/SecuritySettingsV2.java
@@ -4,122 +4,42 @@
.PREF_KEY_ENCRYPTION_SECURITY_PAGE;
import android.app.Activity;
-import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.Intent;
-import android.content.res.Resources;
import android.hardware.fingerprint.FingerprintManager;
-import android.os.Bundle;
-import android.os.UserHandle;
-import android.os.UserManager;
-import android.os.storage.StorageManager;
import android.provider.SearchIndexableResource;
-import android.support.annotation.VisibleForTesting;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceGroup;
-import android.support.v7.preference.PreferenceScreen;
-import android.text.TextUtils;
import com.android.internal.logging.nano.MetricsProto;
-import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.Utils;
-import com.android.settings.dashboard.DashboardFeatureProvider;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
import com.android.settings.enterprise.ManageDeviceAdminPreferenceController;
-import com.android.settings.fingerprint.FingerprintSettings;
+import com.android.settings.fingerprint.FingerprintProfileStatusPreferenceController;
+import com.android.settings.fingerprint.FingerprintStatusPreferenceController;
import com.android.settings.location.LocationPreferenceController;
-import com.android.settings.notification.LockScreenNotificationPreferenceController;
-import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.password.ChooseLockGeneric;
-import com.android.settings.password.ChooseLockSettingsHelper;
-import com.android.settings.password.ManagedLockPasswordProvider;
import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.SearchIndexableRaw;
-import com.android.settings.security.screenlock.ScreenLockSettings;
+import com.android.settings.security.screenlock.LockScreenPreferenceController;
import com.android.settings.security.trustagent.ManageTrustAgentsPreferenceController;
import com.android.settings.security.trustagent.TrustAgentListPreferenceController;
-import com.android.settings.widget.GearPreference;
-import com.android.settingslib.RestrictedLockUtils;
-import com.android.settingslib.RestrictedPreference;
-import com.android.settingslib.RestrictedSwitchPreference;
+import com.android.settings.widget.PreferenceCategoryController;
import com.android.settingslib.core.AbstractPreferenceController;
-import com.android.settingslib.drawer.CategoryKey;
+import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.List;
-public class SecuritySettingsV2 extends DashboardFragment
- implements Preference.OnPreferenceChangeListener,
- GearPreference.OnGearClickListener {
+public class SecuritySettingsV2 extends DashboardFragment {
private static final String TAG = "SecuritySettingsV2";
- // Lock Settings
- private static final String KEY_UNLOCK_SET_OR_CHANGE = "unlock_set_or_change";
- private static final String KEY_UNLOCK_SET_OR_CHANGE_PROFILE = "unlock_set_or_change_profile";
- private static final String KEY_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile";
- private static final String KEY_SECURITY_CATEGORY = "security_category";
- private static final String KEY_UNIFICATION = "unification";
- @VisibleForTesting
- static final String KEY_LOCKSCREEN_PREFERENCES = "lockscreen_preferences";
- private static final String KEY_ENCRYPTION_AND_CREDENTIALS = "encryption_and_credential";
- private static final String KEY_LOCATION_SCANNING = "location_scanning";
- private static final String KEY_LOCATION = "location";
-
- private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
+ public static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST = 123;
public static final int CHANGE_TRUST_AGENT_SETTINGS = 126;
- private static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE = 127;
- private static final int UNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 128;
- private static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 129;
- private static final int UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 130;
- private static final String TAG_UNIFICATION_DIALOG = "unification_dialog";
-
- // Security status
- private static final String KEY_SECURITY_STATUS = "security_status";
- private static final String SECURITY_STATUS_KEY_PREFIX = "security_status_";
-
- // Device management settings
- private static final String KEY_ENTERPRISE_PRIVACY = "enterprise_privacy";
- private static final String KEY_MANAGE_DEVICE_ADMIN = "manage_device_admin";
-
- // These switch preferences need special handling since they're not all stored in Settings.
- private static final String SWITCH_PREFERENCE_KEYS[] = {
- KEY_UNIFICATION, KEY_VISIBLE_PATTERN_PROFILE
- };
-
- private static final int MY_USER_ID = UserHandle.myUserId();
-
- private DashboardFeatureProvider mDashboardFeatureProvider;
- private DevicePolicyManager mDPM;
- private SecurityFeatureProvider mSecurityFeatureProvider;
- private UserManager mUm;
-
- private ChooseLockSettingsHelper mChooseLockSettingsHelper;
- private LockPatternUtils mLockPatternUtils;
- private ManagedLockPasswordProvider mManagedPasswordProvider;
-
- private SwitchPreference mVisiblePatternProfile;
- private RestrictedSwitchPreference mUnifyProfile;
-
- private int mProfileChallengeUserId;
-
- private String mCurrentDevicePassword;
- private String mCurrentProfilePassword;
-
- private LocationPreferenceController mLocationController;
- private ManageDeviceAdminPreferenceController mManageDeviceAdminPreferenceController;
- private EnterprisePrivacyPreferenceController mEnterprisePrivacyPreferenceController;
- private EncryptionStatusPreferenceController mEncryptionStatusPreferenceController;
- private LockScreenNotificationPreferenceController mLockScreenNotificationPreferenceController;
- private ManageTrustAgentsPreferenceController mManageTrustAgentsPreferenceController;
- private ScreenPinningPreferenceController mScreenPinningPreferenceController;
- private SimLockPreferenceController mSimLockPreferenceController;
- private ShowPasswordPreferenceController mShowPasswordPreferenceController;
- private TrustAgentListPreferenceController mTrustAgentListPreferenceController;
+ public static final int SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE = 127;
+ public static final int UNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 128;
+ public static final int UNIFY_LOCK_CONFIRM_PROFILE_REQUEST = 129;
+ public static final int UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST = 130;
@Override
public int getMetricsCategory() {
@@ -127,21 +47,6 @@
}
@Override
- public void onAttach(Context context) {
- super.onAttach(context);
- mSecurityFeatureProvider = FeatureFactory.getFactory(context).getSecurityFeatureProvider();
- mLocationController = new LocationPreferenceController(context, getLifecycle());
- mLockPatternUtils = mSecurityFeatureProvider.getLockPatternUtils(context);
- mManagedPasswordProvider = ManagedLockPasswordProvider.get(context, MY_USER_ID);
- mDPM = (DevicePolicyManager) getSystemService(Context.DEVICE_POLICY_SERVICE);
- mUm = UserManager.get(context);
- mDashboardFeatureProvider = FeatureFactory.getFactory(context)
- .getDashboardFeatureProvider(context);
-
- mChooseLockSettingsHelper = new ChooseLockSettingsHelper(getActivity());
- }
-
- @Override
protected int getPreferenceScreenResId() {
return R.xml.security_settings_v2;
}
@@ -152,299 +57,13 @@
}
@Override
+ public int getHelpResource() {
+ return R.string.help_url_security;
+ }
+
+ @Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
- mManageDeviceAdminPreferenceController
- = new ManageDeviceAdminPreferenceController(context);
- mEnterprisePrivacyPreferenceController
- = new EnterprisePrivacyPreferenceController(context);
- mLockScreenNotificationPreferenceController
- = new LockScreenNotificationPreferenceController(context);
- mManageTrustAgentsPreferenceController = new ManageTrustAgentsPreferenceController(context);
- mScreenPinningPreferenceController = new ScreenPinningPreferenceController(context);
- mSimLockPreferenceController = new SimLockPreferenceController(context);
- mShowPasswordPreferenceController = new ShowPasswordPreferenceController(context);
- mEncryptionStatusPreferenceController = new EncryptionStatusPreferenceController(
- context, PREF_KEY_ENCRYPTION_SECURITY_PAGE);
- mTrustAgentListPreferenceController = new TrustAgentListPreferenceController(getActivity(),
- this /* host */, getLifecycle());
- return null;
- }
-
- private static int getResIdForLockUnlockScreen(LockPatternUtils lockPatternUtils,
- ManagedLockPasswordProvider managedPasswordProvider, int userId) {
- final boolean isMyUser = userId == MY_USER_ID;
- int resid = 0;
- if (!lockPatternUtils.isSecure(userId)) {
- if (!isMyUser) {
- resid = R.xml.security_settings_lockscreen_profile;
- } else if (lockPatternUtils.isLockScreenDisabled(userId)) {
- resid = R.xml.security_settings_lockscreen;
- } else {
- resid = R.xml.security_settings_chooser;
- }
- } else {
- switch (lockPatternUtils.getKeyguardStoredPasswordQuality(userId)) {
- case DevicePolicyManager.PASSWORD_QUALITY_SOMETHING:
- resid = isMyUser ? R.xml.security_settings_pattern
- : R.xml.security_settings_pattern_profile;
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC:
- case DevicePolicyManager.PASSWORD_QUALITY_NUMERIC_COMPLEX:
- resid = isMyUser ? R.xml.security_settings_pin
- : R.xml.security_settings_pin_profile;
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC:
- case DevicePolicyManager.PASSWORD_QUALITY_ALPHANUMERIC:
- case DevicePolicyManager.PASSWORD_QUALITY_COMPLEX:
- resid = isMyUser ? R.xml.security_settings_password
- : R.xml.security_settings_password_profile;
- break;
- case DevicePolicyManager.PASSWORD_QUALITY_MANAGED:
- resid = managedPasswordProvider.getResIdForLockUnlockScreen(!isMyUser);
- break;
- }
- }
- return resid;
- }
-
- /**
- * Important!
- *
- * Don't forget to update the SecuritySearchIndexProvider if you are doing any change in the
- * logic or adding/removing preferences here.
- */
- private PreferenceScreen createPreferenceHierarchy() {
- PreferenceScreen root = getPreferenceScreen();
- if (root != null) {
- root.removeAll();
- }
- addPreferencesFromResource(R.xml.security_settings_v2);
- root = getPreferenceScreen();
- mTrustAgentListPreferenceController.displayPreference(root);
-
- // Add options for lock/unlock screen
- final int resid = getResIdForLockUnlockScreen(mLockPatternUtils,
- mManagedPasswordProvider, MY_USER_ID);
- addPreferencesFromResource(resid);
-
- // DO or PO installed in the user may disallow to change password.
- disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, MY_USER_ID);
-
- mProfileChallengeUserId = Utils.getManagedProfileId(mUm, MY_USER_ID);
- if (mProfileChallengeUserId != UserHandle.USER_NULL
- && mLockPatternUtils.isSeparateProfileChallengeAllowed(mProfileChallengeUserId)) {
- addPreferencesFromResource(R.xml.security_settings_profile);
- addPreferencesFromResource(R.xml.security_settings_unification);
- final int profileResid = getResIdForLockUnlockScreen(mLockPatternUtils,
- mManagedPasswordProvider, mProfileChallengeUserId);
- addPreferencesFromResource(profileResid);
- maybeAddFingerprintPreference(root, mProfileChallengeUserId);
- if (!mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)) {
- final Preference lockPreference =
- root.findPreference(KEY_UNLOCK_SET_OR_CHANGE_PROFILE);
- final String summary = getContext().getString(
- R.string.lock_settings_profile_unified_summary);
- lockPreference.setSummary(summary);
- lockPreference.setEnabled(false);
- // PO may disallow to change password for the profile, but screen lock and managed
- // profile's lock is the same. Disable main "Screen lock" menu.
- disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE, mProfileChallengeUserId);
- } else {
- // PO may disallow to change profile password, and the profile's password is
- // separated from screen lock password. Disable profile specific "Screen lock" menu.
- disableIfPasswordQualityManaged(KEY_UNLOCK_SET_OR_CHANGE_PROFILE,
- mProfileChallengeUserId);
- }
- }
- Preference unlockSetOrChange = findPreference(KEY_UNLOCK_SET_OR_CHANGE);
- if (unlockSetOrChange instanceof GearPreference) {
- ((GearPreference) unlockSetOrChange).setOnGearClickListener(this);
- }
-
-
- // Fingerprint and trust agents
- PreferenceGroup securityCategory = (PreferenceGroup)
- root.findPreference(KEY_SECURITY_CATEGORY);
- if (securityCategory != null) {
- maybeAddFingerprintPreference(securityCategory, UserHandle.myUserId());
- setLockscreenPreferencesSummary(securityCategory);
- }
-
- mVisiblePatternProfile =
- (SwitchPreference) root.findPreference(KEY_VISIBLE_PATTERN_PROFILE);
- mUnifyProfile = (RestrictedSwitchPreference) root.findPreference(KEY_UNIFICATION);
-
- mSimLockPreferenceController.displayPreference(root);
- mScreenPinningPreferenceController.displayPreference(root);
-
- // Advanced Security features
- mManageTrustAgentsPreferenceController.displayPreference(root);
-
- PreferenceGroup securityStatusPreferenceGroup =
- (PreferenceGroup) root.findPreference(KEY_SECURITY_STATUS);
- final List<Preference> tilePrefs = mDashboardFeatureProvider.getPreferencesForCategory(
- getActivity(), getPrefContext(), getMetricsCategory(),
- CategoryKey.CATEGORY_SECURITY);
- int numSecurityStatusPrefs = 0;
- if (tilePrefs != null && !tilePrefs.isEmpty()) {
- for (Preference preference : tilePrefs) {
- if (!TextUtils.isEmpty(preference.getKey())
- && preference.getKey().startsWith(SECURITY_STATUS_KEY_PREFIX)) {
- // Injected security status settings are placed under the Security status
- // category.
- securityStatusPreferenceGroup.addPreference(preference);
- numSecurityStatusPrefs++;
- } else {
- // Other injected settings are placed under the Security preference screen.
- root.addPreference(preference);
- }
- }
- }
-
- if (numSecurityStatusPrefs == 0) {
- root.removePreference(securityStatusPreferenceGroup);
- } else if (numSecurityStatusPrefs > 0) {
- // Update preference data with tile data. Security feature provider only updates the
- // data if it actually needs to be changed.
- mSecurityFeatureProvider.updatePreferences(getActivity(), root,
- mDashboardFeatureProvider.getTilesForCategory(
- CategoryKey.CATEGORY_SECURITY));
- }
-
- for (int i = 0; i < SWITCH_PREFERENCE_KEYS.length; i++) {
- final Preference pref = findPreference(SWITCH_PREFERENCE_KEYS[i]);
- if (pref != null) pref.setOnPreferenceChangeListener(this);
- }
-
- mLocationController.displayPreference(root);
- mManageDeviceAdminPreferenceController.updateState(
- root.findPreference(KEY_MANAGE_DEVICE_ADMIN));
- mEnterprisePrivacyPreferenceController.displayPreference(root);
- final Preference enterprisePrivacyPreference = root.findPreference(
- mEnterprisePrivacyPreferenceController.getPreferenceKey());
- mEnterprisePrivacyPreferenceController.updateState(enterprisePrivacyPreference);
-
- return root;
- }
-
- @VisibleForTesting
- void setLockscreenPreferencesSummary(PreferenceGroup group) {
- final Preference lockscreenPreferences = group.findPreference(KEY_LOCKSCREEN_PREFERENCES);
- if (lockscreenPreferences != null) {
- lockscreenPreferences.setSummary(
- mLockScreenNotificationPreferenceController.getSummaryResource());
- }
- }
-
- /*
- * Sets the preference as disabled by admin if PASSWORD_QUALITY_MANAGED is set.
- * The preference must be a RestrictedPreference.
- */
- private void disableIfPasswordQualityManaged(String preferenceKey, int userId) {
- final RestrictedLockUtils.EnforcedAdmin admin =
- RestrictedLockUtils.checkIfPasswordQualityIsSet(
- getActivity(), userId);
- if (admin != null && mDPM.getPasswordQuality(admin.component, userId) ==
- DevicePolicyManager.PASSWORD_QUALITY_MANAGED) {
- final RestrictedPreference pref =
- (RestrictedPreference) getPreferenceScreen().findPreference(preferenceKey);
- pref.setDisabledByAdmin(admin);
- }
- }
-
- private void maybeAddFingerprintPreference(PreferenceGroup securityCategory, int userId) {
- Preference fingerprintPreference =
- FingerprintSettings.getFingerprintPreferenceForUser(
- securityCategory.getContext(), userId);
- if (fingerprintPreference != null) {
- securityCategory.addPreference(fingerprintPreference);
- }
- }
-
- @Override
- public void onGearClick(GearPreference p) {
- if (KEY_UNLOCK_SET_OR_CHANGE.equals(p.getKey())) {
- startFragment(this, ScreenLockSettings.class.getName(), 0, 0, null);
- }
- }
-
- @Override
- public void onResume() {
- super.onResume();
-
- // Make sure we reload the preference hierarchy since some of these settings
- // depend on others...
- createPreferenceHierarchy();
-
- if (mVisiblePatternProfile != null) {
- mVisiblePatternProfile.setChecked(mLockPatternUtils.isVisiblePatternEnabled(
- mProfileChallengeUserId));
- }
-
- updateUnificationPreference();
-
- final Preference showPasswordPref = getPreferenceScreen().findPreference(
- mShowPasswordPreferenceController.getPreferenceKey());
- showPasswordPref.setOnPreferenceChangeListener(mShowPasswordPreferenceController);
- mShowPasswordPreferenceController.updateState(showPasswordPref);
-
- final Preference encryptionStatusPref = getPreferenceScreen().findPreference(
- mEncryptionStatusPreferenceController.getPreferenceKey());
- mEncryptionStatusPreferenceController.updateState(encryptionStatusPref);
- mTrustAgentListPreferenceController.onResume();
- mLocationController.updateSummary();
- }
-
- @VisibleForTesting
- void updateUnificationPreference() {
- if (mUnifyProfile != null) {
- final boolean separate =
- mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId);
- mUnifyProfile.setChecked(!separate);
- if (separate) {
- mUnifyProfile.setDisabledByAdmin(RestrictedLockUtils.checkIfRestrictionEnforced(
- getContext(), UserManager.DISALLOW_UNIFIED_PASSWORD,
- mProfileChallengeUserId));
- }
- }
- }
-
- @Override
- public boolean onPreferenceTreeClick(Preference preference) {
- if (mTrustAgentListPreferenceController.handlePreferenceTreeClick(preference)) {
- return true;
- }
- final String key = preference.getKey();
- if (KEY_UNLOCK_SET_OR_CHANGE.equals(key)) {
- // TODO(b/35930129): Remove once existing password can be passed into vold directly.
- // Currently we need this logic to ensure that the QUIET_MODE is off for any work
- // profile with unified challenge on FBE-enabled devices. Otherwise, vold would not be
- // able to complete the operation due to the lack of (old) encryption key.
- if (mProfileChallengeUserId != UserHandle.USER_NULL
- && !mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileChallengeUserId)
- && StorageManager.isFileEncryptedNativeOnly()) {
- if (Utils.startQuietModeDialogIfNecessary(this.getActivity(), mUm,
- mProfileChallengeUserId)) {
- return false;
- }
- }
- startFragment(this, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
- R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
- } else if (KEY_UNLOCK_SET_OR_CHANGE_PROFILE.equals(key)) {
- if (Utils.startQuietModeDialogIfNecessary(this.getActivity(), mUm,
- mProfileChallengeUserId)) {
- return false;
- }
- Bundle extras = new Bundle();
- extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId);
- startFragment(this, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
- R.string.lock_settings_picker_title_profile,
- SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE, extras);
- } else {
- // If we didn't handle it, let preferences handle it.
- return super.onPreferenceTreeClick(preference);
- }
- return true;
+ return buildPreferenceControllers(context, getLifecycle(), this /* host*/);
}
/**
@@ -452,267 +71,85 @@
*/
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
- super.onActivityResult(requestCode, resultCode, data);
- if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) {
- mTrustAgentListPreferenceController.handleActivityResult(resultCode);
- return;
- } else if (requestCode == UNIFY_LOCK_CONFIRM_DEVICE_REQUEST
- && resultCode == Activity.RESULT_OK) {
- mCurrentDevicePassword =
- data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
- launchConfirmProfileLockForUnification();
- return;
- } else if (requestCode == UNIFY_LOCK_CONFIRM_PROFILE_REQUEST
- && resultCode == Activity.RESULT_OK) {
- mCurrentProfilePassword =
- data.getStringExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
- unifyLocks();
- return;
- } else if (requestCode == UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST
- && resultCode == Activity.RESULT_OK) {
- ununifyLocks();
+ if (getPreferenceController(TrustAgentListPreferenceController.class)
+ .handleActivityResult(requestCode, resultCode)) {
return;
}
- createPreferenceHierarchy();
+ if (getPreferenceController(LockUnificationPreferenceController.class)
+ .handleActivityResult(requestCode, resultCode, data)) {
+ return;
+ }
+ super.onActivityResult(requestCode, resultCode, data);
}
void launchConfirmDeviceLockForUnification() {
- final String title = getActivity().getString(
- R.string.unlock_set_unlock_launch_picker_title);
- final ChooseLockSettingsHelper helper =
- new ChooseLockSettingsHelper(getActivity(), this);
- if (!helper.launchConfirmationActivity(
- UNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, MY_USER_ID)) {
- launchConfirmProfileLockForUnification();
- }
- }
-
- private void launchConfirmProfileLockForUnification() {
- final String title = getActivity().getString(
- R.string.unlock_set_unlock_launch_picker_title_profile);
- final ChooseLockSettingsHelper helper =
- new ChooseLockSettingsHelper(getActivity(), this);
- if (!helper.launchConfirmationActivity(
- UNIFY_LOCK_CONFIRM_PROFILE_REQUEST, title, true, mProfileChallengeUserId)) {
- unifyLocks();
- createPreferenceHierarchy();
- }
- }
-
- private void unifyLocks() {
- int profileQuality =
- mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId);
- if (profileQuality == DevicePolicyManager.PASSWORD_QUALITY_SOMETHING) {
- mLockPatternUtils.saveLockPattern(
- LockPatternUtils.stringToPattern(mCurrentProfilePassword),
- mCurrentDevicePassword, MY_USER_ID);
- } else {
- mLockPatternUtils.saveLockPassword(
- mCurrentProfilePassword, mCurrentDevicePassword,
- profileQuality, MY_USER_ID);
- }
- mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, false,
- mCurrentProfilePassword);
- final boolean profilePatternVisibility =
- mLockPatternUtils.isVisiblePatternEnabled(mProfileChallengeUserId);
- mLockPatternUtils.setVisiblePatternEnabled(profilePatternVisibility, MY_USER_ID);
- mCurrentDevicePassword = null;
- mCurrentProfilePassword = null;
+ getPreferenceController(LockUnificationPreferenceController.class)
+ .launchConfirmDeviceLockForUnification();
}
void unifyUncompliantLocks() {
- mLockPatternUtils.setSeparateProfileChallengeEnabled(mProfileChallengeUserId, false,
- mCurrentProfilePassword);
- startFragment(this, ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
- R.string.lock_settings_picker_title, SET_OR_CHANGE_LOCK_METHOD_REQUEST, null);
+ getPreferenceController(LockUnificationPreferenceController.class).unifyUncompliantLocks();
}
- private void ununifyLocks() {
- Bundle extras = new Bundle();
- extras.putInt(Intent.EXTRA_USER_ID, mProfileChallengeUserId);
- startFragment(this,
- ChooseLockGeneric.ChooseLockGenericFragment.class.getName(),
- R.string.lock_settings_picker_title_profile,
- SET_OR_CHANGE_LOCK_METHOD_REQUEST_PROFILE, extras);
+ void updateUnificationPreference() {
+ getPreferenceController(LockUnificationPreferenceController.class).updateState(null);
}
- @Override
- public boolean onPreferenceChange(Preference preference, Object value) {
- boolean result = true;
- final String key = preference.getKey();
- final LockPatternUtils lockPatternUtils = mChooseLockSettingsHelper.utils();
- if (KEY_VISIBLE_PATTERN_PROFILE.equals(key)) {
- if (Utils.startQuietModeDialogIfNecessary(this.getActivity(), mUm,
- mProfileChallengeUserId)) {
- return false;
- }
- lockPatternUtils.setVisiblePatternEnabled((Boolean) value, mProfileChallengeUserId);
- } else if (KEY_UNIFICATION.equals(key)) {
- if (Utils.startQuietModeDialogIfNecessary(this.getActivity(), mUm,
- mProfileChallengeUserId)) {
- return false;
- }
- if ((Boolean) value) {
- final boolean compliantForDevice =
- (mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)
- >= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING
- && mLockPatternUtils.isSeparateProfileChallengeAllowedToUnify(
- mProfileChallengeUserId));
- UnificationConfirmationDialog dialog =
- UnificationConfirmationDialog.newIntance(compliantForDevice);
- dialog.show(getChildFragmentManager(), TAG_UNIFICATION_DIALOG);
- } else {
- final String title = getActivity().getString(
- R.string.unlock_set_unlock_launch_picker_title);
- final ChooseLockSettingsHelper helper =
- new ChooseLockSettingsHelper(getActivity(), this);
- if (!helper.launchConfirmationActivity(
- UNUNIFY_LOCK_CONFIRM_DEVICE_REQUEST, title, true, MY_USER_ID)) {
- ununifyLocks();
- }
- }
- }
- return result;
- }
+ private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
+ Lifecycle lifecycle, SecuritySettingsV2 host) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ controllers.add(new LocationPreferenceController(context, lifecycle));
+ controllers.add(new ManageDeviceAdminPreferenceController(context));
+ controllers.add(new EnterprisePrivacyPreferenceController(context));
+ controllers.add(new ManageTrustAgentsPreferenceController(context));
+ controllers.add(new ScreenPinningPreferenceController(context));
+ controllers.add(new SimLockPreferenceController(context));
+ controllers.add(new ShowPasswordPreferenceController(context));
+ controllers.add(new FingerprintStatusPreferenceController(context));
+ controllers.add(new EncryptionStatusPreferenceController(context,
+ PREF_KEY_ENCRYPTION_SECURITY_PAGE));
+ controllers.add(new TrustAgentListPreferenceController(context, host, lifecycle));
+ controllers.add(new LockScreenPreferenceController(context, lifecycle));
+ controllers.add(new ChangeScreenLockPreferenceController(context, host));
- @Override
- public int getHelpResource() {
- return R.string.help_url_security;
+ final List<AbstractPreferenceController> profileSecurityControllers = new ArrayList<>();
+ profileSecurityControllers.add(new ChangeProfileScreenLockPreferenceController(
+ context, host));
+ profileSecurityControllers.add(new LockUnificationPreferenceController(context, host));
+ profileSecurityControllers.add(new VisiblePatternProfilePreferenceController(
+ context, lifecycle));
+ profileSecurityControllers.add(new FingerprintProfileStatusPreferenceController(context));
+ controllers.add(new PreferenceCategoryController(context, "security_category_profile",
+ profileSecurityControllers));
+ controllers.addAll(profileSecurityControllers);
+
+ return controllers;
}
/**
* For Search. Please keep it in sync when updating "createPreferenceHierarchy()"
*/
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new SecuritySearchIndexProvider();
+ new BaseSearchIndexProvider() {
- private static class SecuritySearchIndexProvider extends BaseSearchIndexProvider {
-
- // TODO (b/68001777) Refactor indexing to include all XML and block other settings.
-
- @Override
- public List<SearchIndexableResource> getXmlResourcesToIndex(
- Context context, boolean enabled) {
- final List<SearchIndexableResource> index = new ArrayList<>();
-
- final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
- final ManagedLockPasswordProvider managedPasswordProvider =
- ManagedLockPasswordProvider.get(context, MY_USER_ID);
- final DevicePolicyManager dpm = (DevicePolicyManager)
- context.getSystemService(Context.DEVICE_POLICY_SERVICE);
- final UserManager um = UserManager.get(context);
- final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID);
-
- // To add option for unlock screen, user's password must not be managed and
- // must not be unified with managed profile, whose password is managed.
- if (!isPasswordManaged(MY_USER_ID, context, dpm)
- && (profileUserId == UserHandle.USER_NULL
- || lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)
- || !isPasswordManaged(profileUserId, context, dpm))) {
- // Add options for lock/unlock screen
- final int resId = getResIdForLockUnlockScreen(lockPatternUtils,
- managedPasswordProvider, MY_USER_ID);
- index.add(getSearchResource(context, resId));
- }
-
- if (profileUserId != UserHandle.USER_NULL
- && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)
- && !isPasswordManaged(profileUserId, context, dpm)) {
- index.add(getSearchResource(context, getResIdForLockUnlockScreen(
- lockPatternUtils, managedPasswordProvider, profileUserId)));
- }
-
- // Append the rest of the settings
- index.add(getSearchResource(context, R.xml.security_settings_misc));
-
- return index;
- }
-
- private SearchIndexableResource getSearchResource(Context context, int xmlResId) {
- final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = xmlResId;
- return sir;
- }
-
- private boolean isPasswordManaged(int userId, Context context, DevicePolicyManager dpm) {
- final RestrictedLockUtils.EnforcedAdmin admin =
- RestrictedLockUtils.checkIfPasswordQualityIsSet(
- context, userId);
- return admin != null && dpm.getPasswordQuality(admin.component, userId) ==
- DevicePolicyManager.PASSWORD_QUALITY_MANAGED;
- }
-
- @Override
- public List<SearchIndexableRaw> getRawDataToIndex(Context context, boolean enabled) {
- final List<SearchIndexableRaw> result = new ArrayList<SearchIndexableRaw>();
- final Resources res = context.getResources();
-
- final String screenTitle = res.getString(R.string.security_settings_title);
-
- SearchIndexableRaw data = new SearchIndexableRaw(context);
- data.title = screenTitle;
- data.key = "security_settings_screen";
- data.screenTitle = screenTitle;
- result.add(data);
-
- final UserManager um = UserManager.get(context);
-
- // Fingerprint
- final FingerprintManager fpm = Utils.getFingerprintManagerOrNull(context);
- if (fpm != null && fpm.isHardwareDetected()) {
- // This catches the title which can be overloaded in an overlay
- data = new SearchIndexableRaw(context);
- data.title = res.getString(R.string.security_settings_fingerprint_preference_title);
- data.key = "security_fingerprint";
- data.screenTitle = screenTitle;
- result.add(data);
- // Fallback for when the above doesn't contain "fingerprint"
- data = new SearchIndexableRaw(context);
- data.title = res.getString(R.string.fingerprint_manage_category_title);
- data.key = "security_managed_fingerprint";
- data.screenTitle = screenTitle;
- result.add(data);
- }
-
- final LockPatternUtils lockPatternUtils = new LockPatternUtils(context);
- final int profileUserId = Utils.getManagedProfileId(um, MY_USER_ID);
- if (profileUserId != UserHandle.USER_NULL
- && lockPatternUtils.isSeparateProfileChallengeAllowed(profileUserId)) {
- if (lockPatternUtils.getKeyguardStoredPasswordQuality(profileUserId)
- >= DevicePolicyManager.PASSWORD_QUALITY_SOMETHING
- && lockPatternUtils.isSeparateProfileChallengeAllowedToUnify(
- profileUserId)) {
- data = new SearchIndexableRaw(context);
- data.title = res.getString(R.string.lock_settings_profile_unification_title);
- data.key = "security_use_one_lock";
- data.screenTitle = screenTitle;
- result.add(data);
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(
+ Context context, boolean enabled) {
+ final List<SearchIndexableResource> index = new ArrayList<>();
+ // Append the rest of the settings
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.security_settings_v2;
+ index.add(sir);
+ return index;
}
- }
- return result;
- }
- @Override
- public List<String> getNonIndexableKeys(Context context) {
- final List<String> keys = super.getNonIndexableKeys(context);
-
- new SimLockPreferenceController(context).updateNonIndexableKeys(keys);
-
- if (!(new EnterprisePrivacyPreferenceController(context))
- .isAvailable()) {
- keys.add(KEY_ENTERPRISE_PRIVACY);
- }
-
- // Duplicate in special app access
- keys.add(KEY_MANAGE_DEVICE_ADMIN);
- // Duplicates between parent-child
- keys.add(KEY_LOCATION);
- keys.add(KEY_ENCRYPTION_AND_CREDENTIALS);
- keys.add(KEY_LOCATION_SCANNING);
-
- return keys;
- }
- }
+ @Override
+ public List<AbstractPreferenceController> getPreferenceControllers(Context
+ context) {
+ return buildPreferenceControllers(context, null /* lifecycle */,
+ null /* host*/);
+ }
+ };
static class SummaryProvider implements SummaryLoader.SummaryProvider {
diff --git a/src/com/android/settings/security/ShowPasswordPreferenceController.java b/src/com/android/settings/security/ShowPasswordPreferenceController.java
index 9f9b52d..d0216e8 100644
--- a/src/com/android/settings/security/ShowPasswordPreferenceController.java
+++ b/src/com/android/settings/security/ShowPasswordPreferenceController.java
@@ -44,10 +44,11 @@
}
@Override
- public void setChecked(boolean isChecked) {
+ public boolean setChecked(boolean isChecked) {
Settings.System.putInt(mContext.getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD,
isChecked ? 1 : 0);
mLockPatternUtils.setVisiblePasswordEnabled(isChecked, MY_USER_ID);
+ return true;
}
@Override
diff --git a/src/com/android/settings/security/UnificationConfirmationDialog.java b/src/com/android/settings/security/UnificationConfirmationDialog.java
index 21118d7..482e268 100644
--- a/src/com/android/settings/security/UnificationConfirmationDialog.java
+++ b/src/com/android/settings/security/UnificationConfirmationDialog.java
@@ -27,9 +27,11 @@
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
public class UnificationConfirmationDialog extends InstrumentedDialogFragment {
+
+ static final String TAG_UNIFICATION_DIALOG = "unification_dialog";
private static final String EXTRA_COMPLIANT = "compliant";
- public static UnificationConfirmationDialog newIntance(boolean compliant) {
+ public static UnificationConfirmationDialog newInstance(boolean compliant) {
UnificationConfirmationDialog
dialog = new UnificationConfirmationDialog();
Bundle args = new Bundle();
@@ -38,11 +40,11 @@
return dialog;
}
- @Override
- public void show(FragmentManager manager, String tag) {
- if (manager.findFragmentByTag(tag) == null) {
+ public void show(SecuritySettingsV2 host) {
+ final FragmentManager manager = host.getChildFragmentManager();
+ if (manager.findFragmentByTag(TAG_UNIFICATION_DIALOG) == null) {
// Prevent opening multiple dialogs if tapped on button quickly
- super.show(manager, tag);
+ show(manager, TAG_UNIFICATION_DIALOG);
}
}
@@ -56,11 +58,12 @@
: R.string.lock_settings_profile_unification_dialog_uncompliant_body)
.setPositiveButton(
compliant ? R.string.lock_settings_profile_unification_dialog_confirm
- : R.string.lock_settings_profile_unification_dialog_uncompliant_confirm,
+ : R.string
+ .lock_settings_profile_unification_dialog_uncompliant_confirm,
(dialog, whichButton) -> {
if (compliant) {
parentFragment.launchConfirmDeviceLockForUnification();
- } else {
+ } else {
parentFragment.unifyUncompliantLocks();
}
}
diff --git a/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java b/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java
new file mode 100644
index 0000000..a9e56f4
--- /dev/null
+++ b/src/com/android/settings/security/VisiblePatternProfilePreferenceController.java
@@ -0,0 +1,94 @@
+/*
+ * 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.security;
+
+import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.Utils;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class VisiblePatternProfilePreferenceController extends TogglePreferenceController
+ implements LifecycleObserver, OnResume {
+
+ private static final String KEY_VISIBLE_PATTERN_PROFILE = "visiblepattern_profile";
+
+ private final LockPatternUtils mLockPatternUtils;
+ private final UserManager mUm;
+ private final int mUserId = UserHandle.myUserId();
+ private final int mProfileChallengeUserId;
+
+ private Preference mPreference;
+
+ public VisiblePatternProfilePreferenceController(Context context, Lifecycle lifecycle) {
+ super(context, KEY_VISIBLE_PATTERN_PROFILE);
+ mUm = (UserManager) context.getSystemService(Context.USER_SERVICE);
+ mLockPatternUtils = FeatureFactory.getFactory(context)
+ .getSecurityFeatureProvider()
+ .getLockPatternUtils(context);
+ mProfileChallengeUserId = Utils.getManagedProfileId(mUm, mUserId);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (mLockPatternUtils.isSecure(mProfileChallengeUserId)
+ && mLockPatternUtils.getKeyguardStoredPasswordQuality(mProfileChallengeUserId)
+ == PASSWORD_QUALITY_SOMETHING) {
+ return AVAILABLE;
+ }
+ return DISABLED_FOR_USER;
+ }
+
+ @Override
+ public boolean isChecked() {
+ return mLockPatternUtils.isVisiblePatternEnabled(
+ mProfileChallengeUserId);
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ if (Utils.startQuietModeDialogIfNecessary(mContext, mUm, mProfileChallengeUserId)) {
+ return false;
+ }
+ mLockPatternUtils.setVisiblePatternEnabled(isChecked, mProfileChallengeUserId);
+ return true;
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public void onResume() {
+ mPreference.setVisible(isAvailable());
+ }
+}
diff --git a/src/com/android/settings/security/screenlock/LockScreenPreferenceController.java b/src/com/android/settings/security/screenlock/LockScreenPreferenceController.java
new file mode 100644
index 0000000..d42af2d
--- /dev/null
+++ b/src/com/android/settings/security/screenlock/LockScreenPreferenceController.java
@@ -0,0 +1,80 @@
+/*
+ * 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.security.screenlock;
+
+import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.notification.LockScreenNotificationPreferenceController;
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+import com.android.settingslib.core.lifecycle.LifecycleObserver;
+import com.android.settingslib.core.lifecycle.events.OnResume;
+
+public class LockScreenPreferenceController extends BasePreferenceController implements
+ LifecycleObserver, OnResume {
+
+ static final String KEY_LOCKSCREEN_PREFERENCES = "lockscreen_preferences";
+
+ private static final int MY_USER_ID = UserHandle.myUserId();
+ private final LockPatternUtils mLockPatternUtils;
+ private Preference mPreference;
+
+ public LockScreenPreferenceController(Context context, Lifecycle lifecycle) {
+ super(context, KEY_LOCKSCREEN_PREFERENCES);
+ mLockPatternUtils = FeatureFactory.getFactory(context)
+ .getSecurityFeatureProvider().getLockPatternUtils(context);
+ if (lifecycle != null) {
+ lifecycle.addObserver(this);
+ }
+ }
+
+ @Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ mPreference = screen.findPreference(getPreferenceKey());
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ if (!mLockPatternUtils.isSecure(MY_USER_ID)) {
+ return mLockPatternUtils.isLockScreenDisabled(MY_USER_ID)
+ ? DISABLED_FOR_USER : AVAILABLE;
+ } else {
+ return mLockPatternUtils.getKeyguardStoredPasswordQuality(MY_USER_ID)
+ == PASSWORD_QUALITY_UNSPECIFIED
+ ? DISABLED_FOR_USER : AVAILABLE;
+ }
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ preference.setSummary(
+ LockScreenNotificationPreferenceController.getSummaryResource(mContext));
+ }
+
+ @Override
+ public void onResume() {
+ mPreference.setVisible(isAvailable());
+ }
+}
diff --git a/src/com/android/settings/security/trustagent/TrustAgentListPreferenceController.java b/src/com/android/settings/security/trustagent/TrustAgentListPreferenceController.java
index d99757b..99aa6a4 100644
--- a/src/com/android/settings/security/trustagent/TrustAgentListPreferenceController.java
+++ b/src/com/android/settings/security/trustagent/TrustAgentListPreferenceController.java
@@ -16,7 +16,10 @@
package com.android.settings.security.trustagent;
+import static com.android.settings.security.SecuritySettingsV2.CHANGE_TRUST_AGENT_SETTINGS;
+
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.UserHandle;
@@ -54,20 +57,18 @@
private final LockPatternUtils mLockPatternUtils;
private final TrustAgentManager mTrustAgentManager;
- private final Activity mActivity;
private final SecuritySettingsV2 mHost;
private Intent mTrustAgentClickIntent;
private PreferenceCategory mSecurityCategory;
- public TrustAgentListPreferenceController(Activity activity, SecuritySettingsV2 host,
+ public TrustAgentListPreferenceController(Context context, SecuritySettingsV2 host,
Lifecycle lifecycle) {
- super(activity);
- final SecurityFeatureProvider provider = FeatureFactory.getFactory(activity)
+ super(context);
+ final SecurityFeatureProvider provider = FeatureFactory.getFactory(context)
.getSecurityFeatureProvider();
- mActivity = activity;
mHost = host;
- mLockPatternUtils = provider.getLockPatternUtils(activity);
+ mLockPatternUtils = provider.getLockPatternUtils(context);
mTrustAgentManager = provider.getTrustAgentManager();
if (lifecycle != null) {
lifecycle.addObserver(this);
@@ -88,6 +89,7 @@
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mSecurityCategory = (PreferenceCategory) screen.findPreference(PREF_KEY_SECURITY_CATEGORY);
+ updateTrustAgents();
}
@Override
@@ -110,10 +112,11 @@
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
return super.handlePreferenceTreeClick(preference);
}
- final ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(mActivity, mHost);
+ final ChooseLockSettingsHelper helper = new ChooseLockSettingsHelper(
+ mHost.getActivity(), mHost);
mTrustAgentClickIntent = preference.getIntent();
boolean confirmationLaunched = helper.launchConfirmationActivity(
- SecuritySettingsV2.CHANGE_TRUST_AGENT_SETTINGS, preference.getTitle());
+ CHANGE_TRUST_AGENT_SETTINGS, preference.getTitle());
if (!confirmationLaunched && mTrustAgentClickIntent != null) {
// If this returns false, it means no password confirmation is required.
@@ -125,6 +128,10 @@
@Override
public void onResume() {
+ updateTrustAgents();
+ }
+
+ private void updateTrustAgents() {
if (mSecurityCategory == null) {
return;
}
@@ -163,10 +170,14 @@
}
}
- public void handleActivityResult(int resultCode) {
- if (resultCode == Activity.RESULT_OK && mTrustAgentClickIntent != null) {
- mHost.startActivity(mTrustAgentClickIntent);
- mTrustAgentClickIntent = null;
+ public boolean handleActivityResult(int requestCode, int resultCode) {
+ if (requestCode == CHANGE_TRUST_AGENT_SETTINGS && resultCode == Activity.RESULT_OK) {
+ if (mTrustAgentClickIntent != null) {
+ mHost.startActivity(mTrustAgentClickIntent);
+ mTrustAgentClickIntent = null;
+ }
+ return true;
}
+ return false;
}
}
diff --git a/src/com/android/settings/utils/AnnotationSpan.java b/src/com/android/settings/utils/AnnotationSpan.java
new file mode 100644
index 0000000..645351d
--- /dev/null
+++ b/src/com/android/settings/utils/AnnotationSpan.java
@@ -0,0 +1,85 @@
+/*
+ * 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.utils;
+
+import android.text.Annotation;
+import android.text.SpannableString;
+import android.text.SpannableStringBuilder;
+import android.text.TextPaint;
+import android.text.style.URLSpan;
+import android.view.View;
+
+/**
+ * This class is used to add {@link View.OnClickListener} for the text been wrapped by
+ * annotation.
+ */
+public class AnnotationSpan extends URLSpan {
+ private final View.OnClickListener mClickListener;
+
+ private AnnotationSpan(View.OnClickListener lsn) {
+ super((String) null);
+ mClickListener = lsn;
+ }
+
+ @Override
+ public void onClick(View widget) {
+ if (mClickListener != null) {
+ mClickListener.onClick(widget);
+ }
+ }
+
+ @Override
+ public void updateDrawState(TextPaint ds) {
+ super.updateDrawState(ds);
+ ds.setUnderlineText(false);
+ }
+
+ public static CharSequence linkify(CharSequence rawText, LinkInfo... linkInfos) {
+ SpannableString msg = new SpannableString(rawText);
+ Annotation[] spans = msg.getSpans(0, msg.length(), Annotation.class);
+ SpannableStringBuilder builder = new SpannableStringBuilder(msg);
+ for (Annotation annotation : spans) {
+ final String key = annotation.getValue();
+ int start = msg.getSpanStart(annotation);
+ int end = msg.getSpanEnd(annotation);
+ AnnotationSpan link = null;
+ for (LinkInfo linkInfo : linkInfos) {
+ if (linkInfo.annotation.equals(key)) {
+ link = new AnnotationSpan(linkInfo.listener);
+ break;
+ }
+ }
+ if (link != null) {
+ builder.setSpan(link, start, end, msg.getSpanFlags(link));
+ }
+ }
+ return builder;
+ }
+
+ /**
+ * Data class to store the annotation and the click action
+ */
+ public static class LinkInfo {
+ public final String annotation;
+ public final View.OnClickListener listener;
+
+ public LinkInfo(String annotation, View.OnClickListener listener) {
+ this.annotation = annotation;
+ this.listener = listener;
+ }
+ }
+}
diff --git a/src/com/android/settings/widget/MasterCheckBoxPreference.java b/src/com/android/settings/widget/MasterCheckBoxPreference.java
new file mode 100644
index 0000000..333c9aa
--- /dev/null
+++ b/src/com/android/settings/widget/MasterCheckBoxPreference.java
@@ -0,0 +1,110 @@
+/*
+ * 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.widget;
+
+import android.content.Context;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.CheckBox;
+
+import com.android.settings.R;
+import com.android.settingslib.TwoTargetPreference;
+
+/**
+ * A custom preference that provides inline checkbox. It has a mandatory field for title, and
+ * optional fields for icon and sub-text.
+ */
+public class MasterCheckBoxPreference extends TwoTargetPreference {
+
+ private CheckBox mCheckBox;
+ private boolean mChecked;
+
+ public MasterCheckBoxPreference(Context context, AttributeSet attrs,
+ int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ public MasterCheckBoxPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public MasterCheckBoxPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public MasterCheckBoxPreference(Context context) {
+ super(context);
+ }
+
+ @Override
+ protected int getSecondTargetResId() {
+ return R.layout.preference_widget_master_checkbox;
+ }
+
+ @Override
+ public void onBindViewHolder(PreferenceViewHolder holder) {
+ super.onBindViewHolder(holder);
+ final View widgetView = holder.findViewById(android.R.id.widget_frame);
+ if (widgetView != null) {
+ widgetView.setOnClickListener(new OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ if (mCheckBox != null && !mCheckBox.isEnabled()) {
+ return;
+ }
+ setChecked(!mChecked);
+ if (!callChangeListener(mChecked)) {
+ setChecked(!mChecked);
+ } else {
+ persistBoolean(mChecked);
+ }
+ }
+ });
+ }
+
+ mCheckBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
+ if (mCheckBox != null) {
+ mCheckBox.setContentDescription(getTitle());
+ mCheckBox.setChecked(mChecked);
+ }
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ if (mCheckBox != null) {
+ mCheckBox.setEnabled(enabled);
+ }
+ }
+
+ public boolean isChecked() {
+ return mCheckBox != null && mChecked;
+ }
+
+ public void setChecked(boolean checked) {
+ mChecked = checked;
+ if (mCheckBox != null) {
+ mCheckBox.setChecked(checked);
+ }
+ }
+
+ public CheckBox getCheckBox() {
+ return mCheckBox;
+ }
+}
diff --git a/src/com/android/settings/widget/MasterSwitchPreference.java b/src/com/android/settings/widget/MasterSwitchPreference.java
index d47de88..73774be 100644
--- a/src/com/android/settings/widget/MasterSwitchPreference.java
+++ b/src/com/android/settings/widget/MasterSwitchPreference.java
@@ -22,7 +22,6 @@
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Switch;
-import android.widget.TextView;
import com.android.settings.R;
import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
diff --git a/tests/robotests/assets/grandfather_not_in_search_index_provider_registry b/tests/robotests/assets/grandfather_not_in_search_index_provider_registry
index 146893c..6a831b0 100644
--- a/tests/robotests/assets/grandfather_not_in_search_index_provider_registry
+++ b/tests/robotests/assets/grandfather_not_in_search_index_provider_registry
@@ -1,3 +1,3 @@
com.android.settings.display.ScreenZoomPreferenceFragmentForSetupWizard
com.android.settings.search.indexing.FakeSettingsFragment
-com.android.settings.security.SecuritySettingsV2
\ No newline at end of file
+com.android.settings.security.SecuritySettings
\ No newline at end of file
diff --git a/tests/robotests/res/values-mcc999/config.xml b/tests/robotests/res/values-mcc999/config.xml
index 7ae7c1f..e10fee1 100644
--- a/tests/robotests/res/values-mcc999/config.xml
+++ b/tests/robotests/res/values-mcc999/config.xml
@@ -30,4 +30,5 @@
<bool name="config_show_wallpaper_attribution">false</bool>
<bool name="config_show_default_home">false</bool>
<bool name="config_show_accessibility_shortcut_preference">false</bool>
+ <bool name="config_show_assist_and_voice_input">false</bool>
</resources>
diff --git a/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java b/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java
index 60972ee..1f701c2 100644
--- a/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java
+++ b/tests/robotests/src/com/android/settings/SetupChooseLockPatternTest.java
@@ -21,9 +21,12 @@
import static org.robolectric.RuntimeEnvironment.application;
import android.app.Activity;
+import android.app.AlertDialog;
import android.content.ComponentName;
import android.content.pm.PackageManager;
import android.os.UserHandle;
+import android.view.View;
+import android.widget.Button;
import com.android.settings.password.ChooseLockPattern.ChooseLockPatternFragment;
import com.android.settings.password.ChooseLockPattern.IntentBuilder;
@@ -40,6 +43,7 @@
import org.robolectric.Robolectric;
import org.robolectric.Shadows;
import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowAlertDialog;
import org.robolectric.shadows.ShadowPackageManager.ComponentState;
@RunWith(SettingsRobolectricTestRunner.class)
@@ -85,6 +89,19 @@
.isEqualTo(PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
}
+ @Test
+ public void screenLockOptions_shouldBeVisible() {
+ Button button = mActivity.findViewById(R.id.screen_lock_options);
+ assertThat(button).isNotNull();
+ assertThat(button.getVisibility()).isEqualTo(View.VISIBLE);
+
+ button.performClick();
+ AlertDialog chooserDialog = ShadowAlertDialog.getLatestAlertDialog();
+ assertThat(chooserDialog).isNotNull();
+ int count = Shadows.shadowOf(chooserDialog).getAdapter().getCount();
+ assertThat(count).named("List items shown").isEqualTo(3);
+ }
+
private ChooseLockPatternFragment findFragment(Activity activity) {
return (ChooseLockPatternFragment)
activity.getFragmentManager().findFragmentById(R.id.main_content);
diff --git a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java
index e44fdfb..8667f74 100644
--- a/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java
+++ b/tests/robotests/src/com/android/settings/applications/appinfo/DefaultAppShortcutPreferenceControllerBaseTest.java
@@ -96,8 +96,8 @@
mController.isDefault = true;
mController.updateState(mPreference);
-
- verify(mPreference).setSummary(R.string.yes);
+ String yesString = mContext.getString(R.string.yes);
+ verify(mPreference).setSummary(yesString);
}
@Test
@@ -106,7 +106,8 @@
mController.updateState(mPreference);
- verify(mPreference).setSummary(R.string.no);
+ String noString = mContext.getString(R.string.no);
+ verify(mPreference).setSummary(noString);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
index 180abbb..eeaba21 100644
--- a/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/applications/assist/DefaultAssistPreferenceControllerTest.java
@@ -50,6 +50,7 @@
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.annotation.Config;
+import org.robolectric.RuntimeEnvironment;
import org.robolectric.util.ReflectionHelpers;
import java.util.ArrayList;
@@ -62,26 +63,33 @@
private static final String TEST_KEY = "test_pref_key";
@Mock
- private Context mContext;
- @Mock
private SearchManager mSearchManager;
@Mock
private PackageManager mPackageManager;
+
+ private Context mContext;
private DefaultAssistPreferenceController mController;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
mController = new DefaultAssistPreferenceController(mContext, TEST_KEY,
true /* showSetting */);
}
@Test
- public void isAlwaysAvailable() {
+ public void testAssistAndVoiceInput_byDefault_shouldBeShown() {
assertThat(mController.isAvailable()).isTrue();
}
@Test
+ @Config(qualifiers = "mcc999")
+ public void testAssistAndVoiceInput_ifDisabled_shouldNotBeShown() {
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
public void getPrefKey_shouldReturnKey() {
assertThat(mController.getPreferenceKey())
.isEqualTo(TEST_KEY);
@@ -91,7 +99,8 @@
@Config(shadows = {ShadowSecureSettings.class})
public void getDefaultAppInfo_hasDefaultAssist_shouldReturnKey() {
final String flattenKey = "com.android.settings/assist";
- Settings.Secure.putString(null, Settings.Secure.ASSISTANT, flattenKey);
+ Settings.Secure.putString(mContext.getContentResolver(), Settings.Secure.ASSISTANT,
+ flattenKey);
DefaultAppInfo appInfo = mController.getDefaultAppInfo();
assertThat(appInfo.getKey()).isEqualTo(flattenKey);
diff --git a/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityPreferenceControllerTest.java
index 5fc3ebc..0c98ddc 100644
--- a/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/backup/BackupSettingsActivityPreferenceControllerTest.java
@@ -77,8 +77,8 @@
mBackupEnabled = true;
mController.updateState(mBackupPreference);
-
- verify(mBackupPreference).setSummary(R.string.accessibility_feature_state_on);
+ String summaryString = mContext.getString(R.string.accessibility_feature_state_on);
+ verify(mBackupPreference).setSummary(summaryString);
}
@Test
@@ -86,8 +86,8 @@
mBackupEnabled = false;
mController.updateState(mBackupPreference);
-
- verify(mBackupPreference).setSummary(R.string.accessibility_feature_state_off);
+ String summaryString = mContext.getString(R.string.accessibility_feature_state_off);
+ verify(mBackupPreference).setSummary(summaryString);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceControllerTest.java
index 2e094e2..c3515df 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceNamePreferenceControllerTest.java
@@ -63,13 +63,14 @@
doReturn(mContext).when(mPreferenceScreen).getContext();
mPreference = new Preference(mContext);
mPreference.setKey(BluetoothDeviceNamePreferenceController.KEY_DEVICE_NAME);
- mController = new BluetoothDeviceNamePreferenceController(
- mContext, mLocalAdapter);
+ mController = spy(new BluetoothDeviceNamePreferenceController(
+ mContext, mLocalAdapter));
+ doReturn(DEVICE_NAME).when(mController).getDeviceName();
}
@Test
public void testUpdateDeviceName_showSummaryWithDeviceName() {
- mController.updateDeviceName(mPreference, DEVICE_NAME);
+ mController.updateDeviceName(mPreference);
final CharSequence summary = mPreference.getSummary();
diff --git a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceControllerTest.java
index 62a0d42..faf9069 100644
--- a/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/bluetooth/BluetoothDeviceRenamePreferenceControllerTest.java
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -69,13 +70,14 @@
mPreference = new Preference(mContext);
mPreference.setKey(PREF_KEY);
- mController = new BluetoothDeviceRenamePreferenceController(
- mContext, PREF_KEY, mFragment, mLocalAdapter);
+ mController = spy(new BluetoothDeviceRenamePreferenceController(
+ mContext, PREF_KEY, mFragment, mLocalAdapter));
+ doReturn(DEVICE_NAME).when(mController).getDeviceName();
}
@Test
public void testUpdateDeviceName_showSummaryWithDeviceName() {
- mController.updateDeviceName(mPreference, DEVICE_NAME);
+ mController.updateDeviceName(mPreference);
final CharSequence summary = mPreference.getSummary();
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothInbandRingingPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothInbandRingingPreferenceControllerTest.java
index 4074e25..d0552ec 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothInbandRingingPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothInbandRingingPreferenceControllerTest.java
@@ -18,7 +18,7 @@
import static com.android.settings.development.BluetoothInbandRingingPreferenceController
- .BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY;
+ .BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY;
import static com.google.common.truth.Truth.assertThat;
@@ -84,7 +84,7 @@
mController.onPreferenceChange(mPreference, true /* new value */);
final boolean mode = SettingsShadowSystemProperties.getBoolean(
- BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, false /* default */);
+ BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY, false /* default */);
assertThat(mode).isTrue();
}
@@ -94,14 +94,14 @@
mController.onPreferenceChange(mPreference, false /* new value */);
final boolean mode = SettingsShadowSystemProperties.getBoolean(
- BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, false /* default */);
+ BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY, false /* default */);
assertThat(mode).isFalse();
}
@Test
public void updateState_settingEnabled_preferenceShouldBeChecked() {
- SettingsShadowSystemProperties.set(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY,
+ SettingsShadowSystemProperties.set(BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY,
Boolean.toString(true));
mController.updateState(mPreference);
@@ -110,7 +110,7 @@
@Test
public void updateState_settingDisabled_preferenceShouldNotBeChecked() {
- SettingsShadowSystemProperties.set(BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY,
+ SettingsShadowSystemProperties.set(BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY,
Boolean.toString(false));
mController.updateState(mPreference);
@@ -122,11 +122,11 @@
mController.onDeveloperOptionsDisabled();
final boolean mode = SettingsShadowSystemProperties.getBoolean(
- BLUETOOTH_ENABLE_INBAND_RINGING_PROPERTY, false /* default */);
+ BLUETOOTH_DISABLE_INBAND_RINGING_PROPERTY, false /* default */);
- assertThat(mode).isTrue();
+ assertThat(mode).isFalse();
verify(mPreference).setEnabled(false);
- verify(mPreference).setChecked(true);
+ verify(mPreference).setChecked(false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java
new file mode 100644
index 0000000..cf892f8
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java
@@ -0,0 +1,151 @@
+/*
+ * 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.development;
+
+import static com.android.settings.development.BluetoothMaxConnectedAudioDevicesPreferenceController
+ .BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.SystemProperties;
+import android.support.v7.preference.ListPreference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settings.testutils.shadow.SettingsShadowSystemProperties;
+
+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.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH,
+ sdk = TestConfig.SDK_VERSION,
+ shadows = {SettingsShadowSystemProperties.class})
+public class BluetoothMaxConnectedAudioDevicesPreferenceControllerTest {
+
+ @Mock
+ private PreferenceScreen mPreferenceScreen;
+
+ private Context mContext;
+ private ListPreference mPreference;
+ private BluetoothMaxConnectedAudioDevicesPreferenceController mController;
+
+ /**
+ * 0: 1 device maximum (Default)
+ * 1: 2 devices maximum
+ * 2: 3 devices maximum
+ * 3: 4 devices maximum
+ * 4: 5 devices maximum
+ */
+ private String[] mListValues;
+ private String[] mListSummaries;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ mPreference = new ListPreference(mContext);
+ mListValues = mContext.getResources().getStringArray(
+ R.array.bluetooth_max_connected_audio_devices_values);
+ mListSummaries = mContext.getResources().getStringArray(
+ R.array.bluetooth_max_connected_audio_devices);
+ mController = new BluetoothMaxConnectedAudioDevicesPreferenceController(mContext);
+ when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
+ mPreference);
+ mController.displayPreference(mPreferenceScreen);
+ }
+
+ @After
+ public void teardown() {
+ SettingsShadowSystemProperties.clear();
+ }
+
+ @Test
+ public void onPreferenceChange_setNumberOfDevices() {
+ for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) {
+ mController.onPreferenceChange(mPreference, mListValues[numberOfDevices]);
+
+ final String currentValue = SystemProperties.get(
+ BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
+
+ assertThat(currentValue).isEqualTo(mListValues[numberOfDevices]);
+ assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]);
+ assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]);
+ }
+ }
+
+ @Test
+ public void updateState_NumberOfDevicesUpdated_shouldSetPreference() {
+ for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) {
+ SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY,
+ mListValues[numberOfDevices]);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]);
+ assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]);
+ }
+ }
+
+ @Test
+ public void updateState_noValueSet_shouldSetDefaultTo1device() {
+ SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, "garbage");
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getValue()).isEqualTo(mListValues[0]);
+ assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]);
+ }
+
+ @Test
+ public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
+ mController.onDeveloperOptionsSwitchDisabled();
+
+ assertThat(mPreference.isEnabled()).isFalse();
+ assertThat(mPreference.getValue()).isEqualTo(mListValues[0]);
+ assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]);
+ final String currentValue = SystemProperties.get(
+ BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
+ assertThat(currentValue).isEqualTo(mListValues[0]);
+ }
+
+ @Test
+ public void onDeveloperOptionsSwitchEnabled_shouldEnablePreference() {
+ for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) {
+ mController.onDeveloperOptionsSwitchDisabled();
+ assertThat(mPreference.isEnabled()).isFalse();
+
+ SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY,
+ mListValues[numberOfDevices]);
+ mController.onDeveloperOptionsSwitchEnabled();
+
+ assertThat(mPreference.isEnabled()).isTrue();
+ assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]);
+ assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]);
+ }
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollSuggestionActivityTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollSuggestionActivityTest.java
index e299fd5..66114aa 100644
--- a/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollSuggestionActivityTest.java
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintEnrollSuggestionActivityTest.java
@@ -58,7 +58,8 @@
.thenReturn(mDevicePolicyManager);
when(mDevicePolicyManager.getKeyguardDisabledFeatures(any(), anyInt()))
.thenReturn(0);
- when(mContext.getSystemService(FingerprintManager.class)).thenReturn(mFingerprintManager);
+ when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
+ .thenReturn(mFingerprintManager);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintProfileStatusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintProfileStatusPreferenceControllerTest.java
new file mode 100644
index 0000000..9993a95
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintProfileStatusPreferenceControllerTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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.fingerprint;
+
+import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.hardware.fingerprint.FingerprintManager;
+import android.os.UserManager;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class FingerprintProfileStatusPreferenceControllerTest {
+
+ private static final int FAKE_PROFILE_USER_ID = 1234;
+
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private LockPatternUtils mLockPatternUtils;
+ @Mock
+ private FingerprintManager mFingerprintManager;
+ @Mock
+ private UserManager mUm;
+
+ private FakeFeatureFactory mFeatureFactory;
+ private Context mContext;
+ private FingerprintProfileStatusPreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
+ ShadowApplication.getInstance().setSystemService(Context.FINGERPRINT_SERVICE,
+ mFingerprintManager);
+ ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
+
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
+ when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+ .thenReturn(mLockPatternUtils);
+ when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
+ mController = new FingerprintProfileStatusPreferenceController(mContext);
+ }
+
+ @Test
+ public void getUserId_shouldReturnProfileId() {
+ assertThat(mController.getUserId()).isEqualTo(FAKE_PROFILE_USER_ID);
+ }
+
+ @Test
+ public void isUserSupported_separateChallengeAllowed_true() {
+ when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(true);
+ assertThat(mController.isUserSupported()).isTrue();
+ }
+
+ @Test
+ public void isUserSupported_separateChallengeNotAllowed_false() {
+ when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(false);
+
+ assertThat(mController.isUserSupported()).isFalse();
+ }
+
+ @Test
+ public void getAvailabilityStatus_userNotSupported_DISABLED() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fingerprint/FingerprintStatusPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fingerprint/FingerprintStatusPreferenceControllerTest.java
new file mode 100644
index 0000000..ab53382
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fingerprint/FingerprintStatusPreferenceControllerTest.java
@@ -0,0 +1,134 @@
+/*
+ * 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.fingerprint;
+
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_UNSUPPORTED;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.hardware.fingerprint.Fingerprint;
+import android.hardware.fingerprint.FingerprintManager;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+import java.util.Arrays;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class FingerprintStatusPreferenceControllerTest {
+
+ @Mock
+ private LockPatternUtils mLockPatternUtils;
+ @Mock
+ private FingerprintManager mFingerprintManager;
+ @Mock
+ private UserManager mUm;
+ @Mock
+ private PackageManager mPackageManager;
+
+ private FakeFeatureFactory mFeatureFactory;
+ private Context mContext;
+ private FingerprintStatusPreferenceController mController;
+ private Preference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
+ ShadowApplication.getInstance().setSystemService(Context.FINGERPRINT_SERVICE,
+ mFingerprintManager);
+ ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
+ mPreference = new Preference(mContext);
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
+ when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+ .thenReturn(mLockPatternUtils);
+ when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {1234});
+ mController = new FingerprintStatusPreferenceController(mContext);
+ }
+
+ @Test
+ public void getAvailabilityStatus_noFingerprintManger_DISABLED() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_UNSUPPORTED);
+ }
+
+ @Test
+ public void getAvailabilityStatus_hasFingerprintManger_AVAILABLE() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void updateState_notSupported_shouldDoNothing() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isVisible()).isFalse();
+ }
+
+ @Test
+ public void updateState_noFingerprint_shouldShowDefaultSummary() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(
+ mContext.getString(R.string.security_settings_fingerprint_preference_summary_none));
+ assertThat(mPreference.isVisible()).isTrue();
+ assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
+ }
+
+ @Test
+ public void updateState_hasFingerprint_shouldShowSummary() {
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+ when(mFingerprintManager.getEnrolledFingerprints(anyInt()))
+ .thenReturn(Arrays.asList(mock(Fingerprint.class)));
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo(mContext.getResources().getQuantityString(
+ R.plurals.security_settings_fingerprint_preference_summary, 1, 1));
+ assertThat(mPreference.isVisible()).isTrue();
+ assertThat(mPreference.getOnPreferenceClickListener()).isNotNull();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java
index bc5b1d7..45448a9 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryLegacyTest.java
@@ -401,18 +401,6 @@
}
@Test
- public void testNonIndexableKeys_MatchPreferenceKeys() {
- final Context context = RuntimeEnvironment.application;
- final List<String> niks = PowerUsageSummary.SEARCH_INDEX_DATA_PROVIDER
- .getNonIndexableKeys(context);
-
- final List<String> keys = XmlTestUtils.getKeysFromPreferenceXml(context,
- R.xml.power_usage_summary);
-
- assertThat(keys).containsAllIn(niks);
- }
-
- @Test
public void testPreferenceControllers_getPreferenceKeys_existInPreferenceScreen() {
final Context context = RuntimeEnvironment.application;
final PowerUsageSummary fragment = new PowerUsageSummary();
diff --git a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
index f3cc2ca..86fd267 100644
--- a/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/gestures/SwipeToNotificationPreferenceControllerTest.java
@@ -59,8 +59,7 @@
MockitoAnnotations.initMocks(this);
mController = new SwipeToNotificationPreferenceController(mContext, null, KEY_SWIPE_DOWN);
when(mContext.getPackageManager()).thenReturn(mPackageManager);
- // Explicit casting to object due to MockitoCast bug
- when((Object) mContext.getSystemService(FingerprintManager.class))
+ when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
.thenReturn(mFingerprintManager);
}
diff --git a/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java b/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java
index f1d7a73..bba689b 100644
--- a/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/network/PrivateDnsModeDialogFragmentTest.java
@@ -50,7 +50,6 @@
private PrivateDnsModeDialogFragment mFragment;
private Button mSaveButton;
-
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
diff --git a/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java b/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
index 28be616..cd5fcc2 100644
--- a/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
+++ b/tests/robotests/src/com/android/settings/password/SetupChooseLockPasswordTest.java
@@ -135,11 +135,9 @@
fragment.onLockTypeSelected(ScreenLockType.PATTERN);
ShadowActivity shadowActivity = shadowOf(activity);
- IntentForResult chooseLockIntent = shadowActivity.getNextStartedActivityForResult();
- assertThat(chooseLockIntent).isNotNull();
- assertThat(chooseLockIntent.requestCode)
- .isEqualTo(SetupChooseLockPasswordFragment.REQUEST_SCREEN_LOCK_OPTIONS);
- assertThat(chooseLockIntent.intent.getStringExtra("foo")).named("Foo extra")
+ final Intent nextStartedActivity = shadowActivity.getNextStartedActivity();
+ assertThat(nextStartedActivity).isNotNull();
+ assertThat(nextStartedActivity.getStringExtra("foo")).named("Foo extra")
.isEqualTo("bar");
}
diff --git a/tests/robotests/src/com/android/settings/security/LockUnificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/LockUnificationPreferenceControllerTest.java
new file mode 100644
index 0000000..7a5a9fa
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/LockUnificationPreferenceControllerTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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.security;
+
+
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+import org.robolectric.util.ReflectionHelpers;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LockUnificationPreferenceControllerTest {
+
+ private static final int FAKE_PROFILE_USER_ID = 1234;
+
+ @Mock
+ private LockPatternUtils mLockPatternUtils;
+ @Mock
+ private UserManager mUm;
+ @Mock
+ private PreferenceScreen mScreen;
+ @Mock
+ private SecuritySettingsV2 mHost;
+
+ private FakeFeatureFactory mFeatureFactory;
+ private Context mContext;
+ private LockUnificationPreferenceController mController;
+ private Preference mPreference;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
+ when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {FAKE_PROFILE_USER_ID});
+
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
+ when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+ .thenReturn(mLockPatternUtils);
+
+ mController = new LockUnificationPreferenceController(mContext, mHost);
+ when(mScreen.findPreference(mController.getPreferenceKey()))
+ .thenReturn(mPreference);
+ mPreference = new Preference(mContext);
+ }
+
+ @Test
+ public void isAvailable_noProfile_false() {
+ ReflectionHelpers.setField(mController, "mProfileChallengeUserId", UserHandle.USER_NULL);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_separateChallengeNotAllowed_false() {
+ when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(false);
+
+ assertThat(mController.isAvailable()).isFalse();
+ }
+
+ @Test
+ public void isAvailable_separateChallengeAllowed_true() {
+ when(mLockPatternUtils.isSeparateProfileChallengeAllowed(anyInt())).thenReturn(true);
+
+ assertThat(mController.isAvailable()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java b/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java
index 231cce9..3171c3d 100644
--- a/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java
@@ -17,32 +17,26 @@
package com.android.settings.security;
import static com.google.common.truth.Truth.assertThat;
-
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
import android.app.Activity;
import android.content.Context;
-import android.content.pm.PackageManager;
-import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
import android.os.UserManager;
import android.os.UserManager.EnforcingUser;
import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.dashboard.SummaryLoader;
-import com.android.settings.notification.LockScreenNotificationPreferenceController;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.XmlTestUtils;
@@ -90,54 +84,6 @@
}
@Test
- public void testSummaryProvider_notListening() {
- mSummaryProvider.setListening(false);
-
- verifyNoMoreInteractions(mSummaryLoader);
- }
-
- @Test
- public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
- final FingerprintManager fpm = mock(FingerprintManager.class);
- when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
- .thenReturn(true);
-
- // Cast to Object to workaround a robolectric casting bug
- when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
- when(fpm.isHardwareDetected()).thenReturn(true);
-
- mSummaryProvider.setListening(true);
-
- verify(mContext).getString(R.string.security_dashboard_summary);
- }
-
- @Test
- public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
- final FingerprintManager fpm = mock(FingerprintManager.class);
- when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
- .thenReturn(false);
-
- mSummaryProvider.setListening(true);
-
- verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
- }
-
- @Test
- public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoFingerprint() {
- final FingerprintManager fpm = mock(FingerprintManager.class);
- when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
- .thenReturn(true);
-
- // Cast to Object to workaround a robolectric casting bug
- when((Object) mContext.getSystemService(FingerprintManager.class)).thenReturn(fpm);
- when(fpm.isHardwareDetected()).thenReturn(false);
-
- mSummaryProvider.setListening(true);
-
- verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
- }
-
- @Test
public void testInitTrustAgentPreference_secure_shouldSetSummaryToNumberOfTrustAgent() {
final Preference preference = mock(Preference.class);
final PreferenceScreen screen = mock(PreferenceScreen.class);
@@ -162,24 +108,6 @@
}
@Test
- public void testSetLockscreenPreferencesSummary_shouldSetSummaryFromLockScreenNotification() {
- final Preference preference = mock(Preference.class);
- final PreferenceGroup group = mock(PreferenceGroup.class);
- when(group.findPreference(SecuritySettings.KEY_LOCKSCREEN_PREFERENCES))
- .thenReturn(preference);
- final LockScreenNotificationPreferenceController controller =
- mock(LockScreenNotificationPreferenceController.class);
-
- final SecuritySettings securitySettings = new SecuritySettings();
- ReflectionHelpers.setField(securitySettings,
- "mLockScreenNotificationPreferenceController", controller);
-
- when(controller.getSummaryResource()).thenReturn(1234);
- securitySettings.setLockscreenPreferencesSummary(group);
- verify(preference).setSummary(1234);
- }
-
- @Test
public void testNonIndexableKeys_existInXmlLayout() {
final Context context = spy(RuntimeEnvironment.application);
UserManager manager = mock(UserManager.class);
diff --git a/tests/robotests/src/com/android/settings/security/SecuritySettingsV2Test.java b/tests/robotests/src/com/android/settings/security/SecuritySettingsV2Test.java
new file mode 100644
index 0000000..f77903b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/SecuritySettingsV2Test.java
@@ -0,0 +1,99 @@
+/*
+ * 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.security;
+
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.hardware.fingerprint.FingerprintManager;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.dashboard.SummaryLoader;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+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.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SecuritySettingsV2Test {
+
+ @Mock(answer = Answers.RETURNS_DEEP_STUBS)
+ private Context mContext;
+ @Mock
+ private SummaryLoader mSummaryLoader;
+ @Mock
+ private FingerprintManager mFingerprintManager;
+ private SecuritySettings.SummaryProvider mSummaryProvider;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ when(mContext.getSystemService(Context.FINGERPRINT_SERVICE))
+ .thenReturn(mFingerprintManager);
+
+ mSummaryProvider = new SecuritySettings.SummaryProvider(mContext, mSummaryLoader);
+ }
+
+ @Test
+ public void testSummaryProvider_notListening() {
+ mSummaryProvider.setListening(false);
+
+ verifyNoMoreInteractions(mSummaryLoader);
+ }
+
+ @Test
+ public void testSummaryProvider_hasFingerPrint_hasStaticSummary() {
+ when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
+ .thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(true);
+
+ mSummaryProvider.setListening(true);
+
+ verify(mContext).getString(R.string.security_dashboard_summary);
+ }
+
+ @Test
+ public void testSummaryProvider_noFpFeature_shouldSetSummaryWithNoFingerprint() {
+ when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
+ .thenReturn(false);
+
+ mSummaryProvider.setListening(true);
+
+ verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
+ }
+
+ @Test
+ public void testSummaryProvider_noFpHardware_shouldSetSummaryWithNoFingerprint() {
+ when(mContext.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FINGERPRINT))
+ .thenReturn(true);
+ when(mFingerprintManager.isHardwareDetected()).thenReturn(false);
+
+ mSummaryProvider.setListening(true);
+
+ verify(mContext).getString(R.string.security_dashboard_summary_no_fingerprint);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java
new file mode 100644
index 0000000..dd98372
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/VisiblePatternProfilePreferenceControllerTest.java
@@ -0,0 +1,115 @@
+/*
+ * 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.security;
+
+
+import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
+import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_SOMETHING;
+import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.hardware.fingerprint.FingerprintManager;
+import android.os.UserManager;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class VisiblePatternProfilePreferenceControllerTest {
+
+ private static final int FAKE_PROFILE_USER_ID = 1234;
+
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private LockPatternUtils mLockPatternUtils;
+ @Mock
+ private FingerprintManager mFingerprintManager;
+ @Mock
+ private UserManager mUm;
+
+ private Lifecycle mLifecycle;
+ private FakeFeatureFactory mFeatureFactory;
+ private Context mContext;
+ private VisiblePatternProfilePreferenceController mController;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = spy(RuntimeEnvironment.application);
+ when(mContext.getPackageManager()).thenReturn(mPackageManager);
+ when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)).thenReturn(true);
+ ShadowApplication.getInstance().setSystemService(Context.FINGERPRINT_SERVICE,
+ mFingerprintManager);
+ ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
+
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
+ when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+ .thenReturn(mLockPatternUtils);
+ when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {FAKE_PROFILE_USER_ID});
+
+ mLifecycle = new Lifecycle(() -> mLifecycle);
+ mController = new VisiblePatternProfilePreferenceController(mContext, mLifecycle);
+ }
+
+ @Test
+ public void getAvailabilityStatus_notSecure_DISABLED() {
+ when(mLockPatternUtils.isSecure(FAKE_PROFILE_USER_ID)).thenReturn(false);
+ when(mLockPatternUtils.getKeyguardStoredPasswordQuality(FAKE_PROFILE_USER_ID))
+ .thenReturn(PASSWORD_QUALITY_UNSPECIFIED);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
+ }
+
+ @Test
+ public void getAvailabilityStatus_secureWithPassword_DISABLED() {
+ when(mLockPatternUtils.isSecure(FAKE_PROFILE_USER_ID)).thenReturn(true);
+ when(mLockPatternUtils.getKeyguardStoredPasswordQuality(FAKE_PROFILE_USER_ID))
+ .thenReturn(PASSWORD_QUALITY_ALPHABETIC);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
+ }
+
+ @Test
+ public void getAvailabilityStatus_secureWithPattern_AVAILABLE() {
+ when(mLockPatternUtils.isSecure(FAKE_PROFILE_USER_ID)).thenReturn(true);
+ when(mLockPatternUtils.getKeyguardStoredPasswordQuality(FAKE_PROFILE_USER_ID))
+ .thenReturn(PASSWORD_QUALITY_SOMETHING);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/security/screenlock/LockScreenPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/screenlock/LockScreenPreferenceControllerTest.java
new file mode 100644
index 0000000..671807b
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/security/screenlock/LockScreenPreferenceControllerTest.java
@@ -0,0 +1,143 @@
+/*
+ * 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.security.screenlock;
+
+import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_ALPHABETIC;
+import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
+import static android.arch.lifecycle.Lifecycle.Event.ON_RESUME;
+import static com.android.settings.core.BasePreferenceController.AVAILABLE;
+import static com.android.settings.core.BasePreferenceController.DISABLED_FOR_USER;
+import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.os.UserManager;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+
+import com.android.internal.widget.LockPatternUtils;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.FakeFeatureFactory;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+import com.android.settingslib.core.lifecycle.Lifecycle;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+import org.robolectric.shadows.ShadowApplication;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class LockScreenPreferenceControllerTest {
+
+ private static final int FAKE_PROFILE_USER_ID = 1234;
+
+ @Mock
+ private LockPatternUtils mLockPatternUtils;
+ @Mock
+ private UserManager mUm;
+ @Mock
+ private PreferenceScreen mScreen;
+
+ private Lifecycle mLifecycle;
+ private FakeFeatureFactory mFeatureFactory;
+ private Context mContext;
+ private LockScreenPreferenceController mController;
+ private Preference mPreference;
+
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ mContext = RuntimeEnvironment.application;
+ ShadowApplication.getInstance().setSystemService(Context.USER_SERVICE, mUm);
+
+ mFeatureFactory = FakeFeatureFactory.setupForTest();
+ when(mFeatureFactory.securityFeatureProvider.getLockPatternUtils(mContext))
+ .thenReturn(mLockPatternUtils);
+ when(mUm.getProfileIdsWithDisabled(anyInt())).thenReturn(new int[] {FAKE_PROFILE_USER_ID});
+ mPreference = new Preference(mContext);
+ when(mScreen.findPreference(anyString())).thenReturn(mPreference);
+ mLifecycle = new Lifecycle(() -> mLifecycle);
+ mController = new LockScreenPreferenceController(mContext, mLifecycle);
+
+ }
+
+ @Test
+ public void getAvailabilityStatus_notSecure_lockscreenDisabled_DISABLED() {
+ when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
+ when(mLockPatternUtils.isLockScreenDisabled(anyInt())).thenReturn(true);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
+ }
+
+ @Test
+ public void getAvailabilityStatus_notSecure_lockscreenEnabled_AVAILABLE() {
+ when(mLockPatternUtils.isSecure(anyInt())).thenReturn(false);
+ when(mLockPatternUtils.isLockScreenDisabled(anyInt())).thenReturn(false);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_secure_hasLockScreen_AVAILABLE() {
+ when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
+ when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
+ .thenReturn(PASSWORD_QUALITY_ALPHABETIC);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
+ }
+
+ @Test
+ public void getAvailabilityStatus_secure_noLockScreen_DISABLED() {
+ when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
+ when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
+ .thenReturn(PASSWORD_QUALITY_UNSPECIFIED);
+
+ assertThat(mController.getAvailabilityStatus()).isEqualTo(DISABLED_FOR_USER);
+ }
+
+ @Test
+ public void onResume_available_shouldShow() {
+ when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
+ when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
+ .thenReturn(PASSWORD_QUALITY_ALPHABETIC);
+
+ mController.displayPreference(mScreen);
+ mLifecycle.handleLifecycleEvent(ON_RESUME);
+
+ assertThat(mPreference.isVisible()).isTrue();
+ }
+
+ @Test
+ public void onResume_unavailable_shouldHide() {
+ when(mLockPatternUtils.isSecure(anyInt())).thenReturn(true);
+ when(mLockPatternUtils.getKeyguardStoredPasswordQuality(anyInt()))
+ .thenReturn(PASSWORD_QUALITY_UNSPECIFIED);
+
+ mController.displayPreference(mScreen);
+ mLifecycle.handleLifecycleEvent(ON_RESUME);
+
+ assertThat(mPreference.isVisible()).isFalse();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentListPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentListPreferenceControllerTest.java
index a97780b..6913c0c 100644
--- a/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentListPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/security/trustagent/TrustAgentListPreferenceControllerTest.java
@@ -23,6 +23,7 @@
.PREF_KEY_TRUST_AGENT;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -127,6 +128,6 @@
mController.displayPreference(mScreen);
mController.onResume();
- verify(mCategory).addPreference(any(Preference.class));
+ verify(mCategory, atLeastOnce()).addPreference(any(Preference.class));
}
}
diff --git a/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java
new file mode 100644
index 0000000..e6530d5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/widget/MasterCheckBoxPreferenceTest.java
@@ -0,0 +1,154 @@
+/*
+ * 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.widget;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import android.content.Context;
+import android.support.v7.preference.Preference.OnPreferenceChangeListener;
+import android.support.v7.preference.PreferenceViewHolder;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.CheckBox;
+
+import com.android.settings.R;
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class MasterCheckBoxPreferenceTest {
+
+ private Context mContext;
+ private MasterCheckBoxPreference mPreference;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mPreference = new MasterCheckBoxPreference(mContext);
+ }
+
+ @Test
+ public void createNewPreference_shouldSetLayout() {
+ assertThat(mPreference.getWidgetLayoutResource())
+ .isEqualTo(R.layout.preference_widget_master_checkbox);
+ }
+
+ @Test
+ public void setChecked_shouldUpdateCheckBoxCheckedState() {
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ LayoutInflater.from(mContext).inflate(
+ R.layout.preference_widget_master_checkbox, null));
+ final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
+ mPreference.onBindViewHolder(holder);
+
+ mPreference.setChecked(true);
+ assertThat(checkBox.isChecked()).isTrue();
+
+ mPreference.setChecked(false);
+ assertThat(checkBox.isChecked()).isFalse();
+ }
+
+ @Test
+ public void setEnabled_shouldUpdateCheckBoxEnabledState() {
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ LayoutInflater.from(mContext).inflate(
+ R.layout.preference_widget_master_checkbox, null));
+ final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
+ mPreference.onBindViewHolder(holder);
+
+ mPreference.setEnabled(true);
+ assertThat(checkBox.isEnabled()).isTrue();
+
+ mPreference.setEnabled(false);
+ assertThat(checkBox.isEnabled()).isFalse();
+ }
+
+ @Test
+ public void clickWidgetView_shouldToggleCheckBox() {
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ inflater.inflate(R.layout.preference_two_target, null));
+ final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
+ inflater.inflate(R.layout.preference_widget_master_checkbox, widgetView, true);
+ final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
+ mPreference.onBindViewHolder(holder);
+
+ widgetView.performClick();
+ assertThat(checkBox.isChecked()).isTrue();
+
+ widgetView.performClick();
+ assertThat(checkBox.isChecked()).isFalse();
+ }
+
+ @Test
+ public void clickWidgetView_shouldNotToggleCheckBoxIfDisabled() {
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ inflater.inflate(R.layout.preference_two_target, null));
+ final LinearLayout widgetView = holder.itemView.findViewById(android.R.id.widget_frame);
+ inflater.inflate(R.layout.preference_widget_master_checkbox, widgetView, true);
+ final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
+ mPreference.onBindViewHolder(holder);
+ mPreference.setEnabled(false);
+
+ widgetView.performClick();
+ assertThat(checkBox.isChecked()).isFalse();
+ }
+
+ @Test
+ public void clickWidgetView_shouldNotifyPreferenceChanged() {
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ LayoutInflater.from(mContext).inflate(R.layout.preference_two_target, null));
+ final View widgetView = holder.findViewById(android.R.id.widget_frame);
+ final OnPreferenceChangeListener listener = mock(OnPreferenceChangeListener.class);
+ mPreference.setOnPreferenceChangeListener(listener);
+ mPreference.onBindViewHolder(holder);
+
+ mPreference.setChecked(false);
+ widgetView.performClick();
+ verify(listener).onPreferenceChange(mPreference, true);
+
+ mPreference.setChecked(true);
+ widgetView.performClick();
+ verify(listener).onPreferenceChange(mPreference, false);
+ }
+
+ @Test
+ public void onBindViewHolder_checkBoxShouldHaveContentDescription() {
+ final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
+ LayoutInflater.from(mContext)
+ .inflate(R.layout.preference_widget_master_checkbox, null));
+ final CheckBox checkBox = (CheckBox) holder.findViewById(R.id.checkboxWidget);
+ final String label = "TestButton";
+ mPreference.setTitle(label);
+
+ mPreference.onBindViewHolder(holder);
+
+ assertThat(checkBox.getContentDescription()).isEqualTo(label);
+ }
+}