Merge "Introduce boolean flags to show/hide items for Language & input."
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index facfeab..8c1ab56 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -90,6 +90,7 @@
<uses-permission android:name="android.permission.READ_PRINT_SERVICES" />
<uses-permission android:name="android.permission.NETWORK_SETTINGS" />
<uses-permission android:name="android.permission.TEST_BLACKLISTED_PASSWORD" />
+ <uses-permission android:name="android.permission.USE_RESERVED_DISK" />
<application android:label="@string/settings_label"
android:icon="@drawable/ic_launcher_settings"
@@ -3104,13 +3105,6 @@
<meta-data android:name="com.android.settings.FRAGMENT_CLASS"
android:value="com.android.settings.deletionhelper.AutomaticStorageManagerSettings" />
</activity>
-
- <activity android:name="Settings$LegacySupportActivity"
- android:label="@string/page_tab_title_support">
- <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
- android:value="com.android.settings.dashboard.SupportFragment"/>
- </activity>
-
<!-- Information architecture host activities -->
<!-- Alias for battery settings in new IA. Remove and merge metadata into TargetActivity -->
diff --git a/res/drawable/ic_attach_money_black_24dp.xml b/res/drawable/ic_attach_money_black_24dp.xml
new file mode 100644
index 0000000..12605fd
--- /dev/null
+++ b/res/drawable/ic_attach_money_black_24dp.xml
@@ -0,0 +1,25 @@
+<?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.
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="24dp"
+ android:height="24dp"
+ android:viewportWidth="24.0"
+ android:viewportHeight="24.0"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M11.8,10.9c-2.27,-0.59 -3,-1.2 -3,-2.15 0,-1.09 1.01,-1.85 2.7,-1.85 1.78,0 2.44,0.85 2.5,2.1h2.21c-0.07,-1.72 -1.12,-3.3 -3.21,-3.81V3h-3v2.16c-1.94,0.42 -3.5,1.68 -3.5,3.61 0,2.31 1.91,3.46 4.7,4.13 2.5,0.6 3,1.48 3,2.41 0,0.69 -0.49,1.79 -2.7,1.79 -2.06,0 -2.87,-0.92 -2.98,-2.1h-2.2c0.12,2.19 1.76,3.42 3.68,3.83V21h3v-2.15c1.95,-0.37 3.5,-1.5 3.5,-3.55 0,-2.84 -2.43,-3.81 -4.7,-4.4z"/>
+</vector>
\ No newline at end of file
diff --git a/res/layout/app_high_usage_item.xml b/res/layout/app_high_usage_item.xml
new file mode 100755
index 0000000..473315f
--- /dev/null
+++ b/res/layout/app_high_usage_item.xml
@@ -0,0 +1,48 @@
+<?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.
+-->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="4dp"
+ android:paddingStart="?android:dialogPreferredPadding"
+ android:paddingEnd="?android:dialogPreferredPadding"
+ android:orientation="horizontal">
+ <ImageView
+ android:id="@+id/app_icon"
+ android:layout_width="24dp"
+ android:layout_height="24dp"
+ android:layout_gravity="center_vertical"/>
+ <TextView
+ android:id="@+id/app_name"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_marginStart="24dp"
+ android:textColor="?android:textColorPrimary"
+ android:paddingEnd="7dp"/>
+ <TextView
+ android:id="@+id/app_screen_time"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ android:layout_gravity="center_vertical"
+ android:paddingEnd="16dp"
+ android:textAlignment="viewEnd"
+ android:textColor="?android:textColorPrimary"/>
+</LinearLayout>
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/layout/recycler_view.xml b/res/layout/recycler_view.xml
new file mode 100644
index 0000000..a7dabe5
--- /dev/null
+++ b/res/layout/recycler_view.xml
@@ -0,0 +1,23 @@
+<?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.
+ -->
+<android.support.v7.widget.RecyclerView
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/recycler_view"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:paddingTop="8dp"
+ android:scrollbars="vertical"/>
diff --git a/res/layout/smart_battery_header.xml b/res/layout/smart_battery_header.xml
new file mode 100644
index 0000000..960f04a
--- /dev/null
+++ b/res/layout/smart_battery_header.xml
@@ -0,0 +1,30 @@
+<?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.
+ -->
+
+<!-- Entity header -->
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/entity_header"
+ style="@style/EntityHeader"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:minHeight="200dp"
+ android:paddingBottom="32dp"
+ android:paddingStart="@dimen/preference_no_icon_padding_start"
+ android:paddingTop="24dp">
+
+</LinearLayout>
diff --git a/res/layout/support_account_spinner_item.xml b/res/layout/support_account_spinner_item.xml
deleted file mode 100644
index fe37a85..0000000
--- a/res/layout/support_account_spinner_item.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<TextView xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@android:id/text1"
- style="?android:attr/spinnerItemStyle"
- android:singleLine="true"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:ellipsize="marquee"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textAlignment="inherit"/>
diff --git a/res/layout/support_disclaimer_content.xml b/res/layout/support_disclaimer_content.xml
deleted file mode 100644
index 1e81f1a..0000000
--- a/res/layout/support_disclaimer_content.xml
+++ /dev/null
@@ -1,39 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<ScrollView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:padding="24dp">
-
- <com.android.settingslib.widget.LinkTextView
- android:id="@+id/support_disclaimer_text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingBottom="24dp"/>
-
- <CheckBox
- android:id="@+id/support_disclaimer_do_not_show_again"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/support_disclaimer_do_not_show"
- android:textColor="?android:attr/textColorSecondary"/>
- </LinearLayout>
-</ScrollView>
diff --git a/res/layout/support_escalation_options.xml b/res/layout/support_escalation_options.xml
deleted file mode 100644
index ae208f1..0000000
--- a/res/layout/support_escalation_options.xml
+++ /dev/null
@@ -1,101 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- style="@style/SupportEscalationCard"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <TextView
- android:id="@+id/tile_title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- android:textAppearance="@style/TextAppearance.SupportTitle"/>
- <TextView
- android:id="@+id/tile_summary"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- android:paddingTop="8dp"
- android:paddingBottom="30dp"
- android:textAppearance="?android:attr/textAppearanceSmall"/>
- <TextView
- android:id="@+id/account_request_prefix"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- android:text="@string/support_account_request_prefix"
- android:textAppearance="?android:attr/textAppearanceSmall"/>
- <Spinner
- android:id="@+id/account_spinner"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="5dp"
- android:layout_marginStart="16dp"
- android:gravity="center_horizontal"/>
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="30dp"
- android:gravity="center_horizontal"
- android:orientation="horizontal">
- <LinearLayout
- android:layout_width="0dp"
- android:layout_weight="1"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginEnd="8dp"
- android:gravity="center_horizontal"
- android:orientation="vertical">
- <Button
- android:id="@android:id/text1"
- style="@style/ActionPrimaryButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="8dp"/>
- <TextView
- android:id="@+id/summary1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="14dp"
- android:textAppearance="?android:attr/textAppearanceSmall"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="0dp"
- android:layout_weight="1"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginEnd="8dp"
- android:gravity="center_horizontal"
- android:orientation="vertical">
- <Button
- android:id="@android:id/text2"
- style="@style/ActionPrimaryButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="8dp"/>
- <TextView
- android:id="@+id/summary2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="14dp"
- android:textAppearance="?android:attr/textAppearanceSmall"/>
- </LinearLayout>
- </LinearLayout>
-</LinearLayout>
diff --git a/res/layout/support_fragment.xml b/res/layout/support_fragment.xml
deleted file mode 100644
index 6864d32..0000000
--- a/res/layout/support_fragment.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<FrameLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:clipChildren="false"
- android:clipToPadding="false"
- android:focusable="false"
- android:paddingStart="@dimen/dashboard_padding_start"
- android:paddingEnd="@dimen/dashboard_padding_end">
- <android.support.v7.widget.RecyclerView
- android:id="@+id/support_items"
- android:layout_height="match_parent"
- android:layout_width="match_parent"/>
-</FrameLayout>
diff --git a/res/layout/support_offline_escalation_options.xml b/res/layout/support_offline_escalation_options.xml
deleted file mode 100644
index 09863d3..0000000
--- a/res/layout/support_offline_escalation_options.xml
+++ /dev/null
@@ -1,71 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- style="@style/SupportEscalationCard"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <TextView
- android:id="@+id/tile_title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- android:textAppearance="@style/TextAppearance.SupportTitle"/>
- <TextView
- android:id="@+id/tile_summary"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- android:paddingTop="8dp"
- android:paddingBottom="10dp"
- android:textAppearance="@style/TextAppearance.Small"
- android:textColor="?android:attr/textColorSecondary"/>
- <LinearLayout
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:orientation="horizontal">
- <TextView
- android:id="@+id/support_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingEnd="8dp"
- android:text="@string/support_country_list_title"
- android:textAppearance="@style/TextAppearance.Small"
- android:textColor="?android:attr/textColorSecondary"/>
- <Spinner
- android:id="@+id/spinner"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:dropDownWidth="196dp"/>
- </LinearLayout>
- <Button
- android:id="@android:id/text1"
- style="@style/ActionPrimaryButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="8dp"
- android:layoutDirection="ltr"/>
- <Button
- android:id="@android:id/text2"
- style="@style/SupportSecondaryButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:minHeight="48dp"
- android:visibility="gone"/>
-</LinearLayout>
diff --git a/res/layout/support_phone_dialog_content.xml b/res/layout/support_phone_dialog_content.xml
deleted file mode 100644
index ce6d2bb..0000000
--- a/res/layout/support_phone_dialog_content.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:paddingStart="24dp"
- android:paddingEnd="24dp"
- android:paddingTop="12dp"
- android:paddingBottom="12dp">
- <TextView
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:paddingBottom="16dp"
- android:text="@string/support_international_phone_summary"/>
- <LinearLayout
- android:id="@+id/phone_number_container"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?android:attr/selectableItemBackground"
- android:gravity="center_vertical"
- android:minHeight="48dp"
- android:orientation="horizontal">
- <ImageView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:paddingEnd="32dp"
- android:src="@drawable/ic_call_24dp"/>
- <TextView
- android:id="@+id/phone_number"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_vertical"
- android:textAppearance="@style/TextAppearance.TileTitle"/>
- </LinearLayout>
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/support_sign_in_button.xml b/res/layout/support_sign_in_button.xml
deleted file mode 100644
index 5bea068..0000000
--- a/res/layout/support_sign_in_button.xml
+++ /dev/null
@@ -1,52 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- style="@style/SupportEscalationCard"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical">
- <TextView
- android:id="@+id/tile_title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- android:textAppearance="@style/TextAppearance.SupportTitle"/>
- <TextView
- android:id="@+id/tile_summary"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center_horizontal"
- android:paddingTop="8dp"
- android:paddingBottom="30dp"
- android:textAppearance="@style/TextAppearance.Small"
- android:textColor="?android:attr/textColorSecondary"/>
- <Button
- android:id="@android:id/text1"
- style="@style/ActionPrimaryButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_margin="8dp"/>
- <Button
- android:id="@android:id/text2"
- style="@style/SupportSecondaryButton"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dp"
- android:minHeight="48dp"/>
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/support_tile.xml b/res/layout/support_tile.xml
deleted file mode 100644
index a42faf0..0000000
--- a/res/layout/support_tile.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?android:attr/selectableItemBackground"
- android:gravity="center_vertical"
- android:minHeight="@dimen/support_tile_min_height"
- android:orientation="horizontal">
- <ImageView
- android:id="@android:id/icon"
- android:layout_width="@dimen/dashboard_tile_image_size"
- android:layout_height="@dimen/dashboard_tile_image_size"
- android:scaleType="centerInside"
- android:layout_marginStart="@dimen/dashboard_tile_image_margin"
- android:layout_marginEnd="@dimen/dashboard_tile_image_margin"/>
- <TextView
- android:id="@+id/tile_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:maxLines="2"
- android:textAppearance="@style/TextAppearance.TileTitle"
- android:ellipsize="end"
- android:fadingEdge="horizontal"/>
-</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/support_tile_spacer.xml b/res/layout/support_tile_spacer.xml
deleted file mode 100644
index aa86e1e..0000000
--- a/res/layout/support_tile_spacer.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2016 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<View
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="@dimen/support_spacer_height"/>
diff --git a/res/layout/two_action_buttons.xml b/res/layout/two_action_buttons.xml
index 41bcfc3..23bb886 100644
--- a/res/layout/two_action_buttons.xml
+++ b/res/layout/two_action_buttons.xml
@@ -20,9 +20,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
- android:paddingTop="8dp"
+ android:paddingTop="24dp"
android:paddingStart="68dp"
- android:paddingEnd="8dp"
+ android:paddingEnd="24dp"
android:orientation="horizontal">
<FrameLayout
@@ -42,6 +42,9 @@
android:layout_height="wrap_content"
android:layout_marginBottom="4dp" />
</FrameLayout>
+ <Space
+ android:layout_width="16dp"
+ android:layout_height="wrap_content" />
<FrameLayout
android:layout_width="0dp"
android:layout_weight="1"
diff --git a/res/layout/wifi_dialog.xml b/res/layout/wifi_dialog.xml
index cfb6d9a..2c4a1ed 100644
--- a/res/layout/wifi_dialog.xml
+++ b/res/layout/wifi_dialog.xml
@@ -316,6 +316,26 @@
android:orientation="vertical"
android:visibility="gone">
+ <LinearLayout android:id="@+id/metered_settings_fields"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ style="@style/wifi_item">
+
+ <TextView android:id="@+id/metered_settings_title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ style="@style/wifi_item_label"
+ android:text="@string/data_usage_metered_yes" />
+
+ <Spinner android:id="@+id/metered_settings"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ style="@style/wifi_item_spinner"
+ android:prompt="@string/data_usage_metered_yes"
+ android:entries="@array/wifi_metered_entries"/>
+
+ </LinearLayout>
+
<LinearLayout android:id="@+id/proxy_settings_fields"
android:layout_width="match_parent"
android:layout_height="wrap_content"
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index dbcfee1..64a2788 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -1063,4 +1063,16 @@
<item>zen_mode_from_none</item>
</string-array>
+ <string-array name="wifi_metered_entries">
+ <item>Use network preference</item>
+ <item>Treat as metered</item>
+ <item>Treat as unmetered</item>
+ </string-array>
+
+ <string-array name="wifi_metered_values" translatable="false">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ </string-array>
+
</resources>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index ef4d269..557318b 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -279,17 +279,8 @@
<dimen name="gestures_play_button_size">36dp</dimen>
<dimen name="gesture_animation_padding">0dp</dimen>
- <!-- Support tile minimum height -->
- <dimen name="support_tile_min_height">48dp</dimen>
- <!-- support spacer layout height -->
- <dimen name="support_spacer_height">8dp</dimen>
-
<dimen name="password_requirement_textsize">14sp</dimen>
- <!-- Padding for the escalation card in normal dimens -->
- <dimen name="support_escalation_card_padding_start">40dp</dimen>
- <dimen name="support_escalation_card_padding_end">40dp</dimen>
-
<!-- Padding between the donut and the storage summary. -->
<dimen name="storage_summary_padding_end">16dp</dimen>
<!-- Text size of the big number in the donut. -->
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a1ff0be..8c7b6f4 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1630,7 +1630,7 @@
<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 number of connected Bluetooth audio devices</string>
+ <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>
@@ -2274,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/>
@@ -4772,6 +4773,34 @@
<string name="battery_tip_low_battery_title">Low battery capacity</string>
<!-- Summary for the low battery tip [CHAR LIMIT=NONE] -->
<string name="battery_tip_low_battery_summary">Battery can\'t provide good battery life</string>
+ <!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_high_usage_title" product="default">Phone used heavily</string>
+ <!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_high_usage_title" product="tablet">Tablet used heavily</string>
+ <!-- Title for the battery high usage tip [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_high_usage_title" product="device">Device used heavily</string>
+ <!-- Summary for the battery high usage tip, which presents how many hours the device been used since last full charge [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_high_usage_summary">About <xliff:g id="hour">%1$s</xliff:g> used since last full charge</string>
+ <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_dialog_message" product="default">Your phone was used heavily and this consumed a lot of battery. Your battery is behaving normally.\n\n Your phone was used for about <xliff:g id="hour">%1$s</xliff:g> since last full charge.\n\n Total usage:</string>
+ <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_dialog_message" product="tablet">Your tablet was used heavily and this consumed a lot of battery. Your battery is behaving normally.\n\n Your tablet was used for about <xliff:g id="hour">%1$s</xliff:g> since last full charge.\n\n Total usage:</string>
+ <!-- Message for battery tip dialog to show the status about the battery [CHAR LIMIT=NONE] -->
+ <string name="battery_tip_dialog_message" product="device">Your device was used heavily and this consumed a lot of battery. Your battery is behaving normally.\n\n Your device was used for about <xliff:g id="hour">%1$s</xliff:g> since last full charge.\n\n Total usage:</string>
+
+ <!-- Title for the smart battery manager preference [CHAR LIMIT=NONE] -->
+ <string name="smart_battery_manager_title">Smart battery manager</string>
+ <!-- Title for the smart battery toggle [CHAR LIMIT=NONE] -->
+ <string name="smart_battery_title">Auto-manage battery</string>
+ <!-- Summary for the smart battery toggle [CHAR LIMIT=NONE] -->
+ <string name="smart_battery_summary">Automatically adjust power usage by apps based on usage</string>
+ <!-- Title for restricted app preference, clicking it will goes to restricted app list [CHAR LIMIT=NONE] -->
+ <string name="restricted_app_title">Restricted apps</string>
+ <!-- Summary for restricted app preference, clicking it will goes to restricted app list [CHAR LIMIT=NONE] -->
+ <plurals name="restricted_app_summary">
+ <item quantity="one">%1$d app</item>
+ <item quantity="other">%1$d apps</item>
+ </plurals>
<!-- Title for force stop dialog [CHAR LIMIT=30] -->
<string name="dialog_stop_title">Stop app?</string>
@@ -6346,6 +6375,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>
@@ -6809,10 +6839,10 @@
<string name="zen_mode_add">Add</string>
<!-- Do not disturb: Label for button that will turn on zen mode. [CHAR LIMIT=30] -->
- <string name="zen_mode_button_turn_on">TURN ON NOW</string>
+ <string name="zen_mode_button_turn_on">Turn on now</string>
<!-- Do not disturb: Label for button that will turn off zen mode. [CHAR LIMIT=30] -->
- <string name="zen_mode_button_turn_off">TURN OFF NOW</string>
+ <string name="zen_mode_button_turn_off">Turn off now</string>
<!-- [CHAR LIMIT=110] Zen mode settings footer: Footer showing end time of DND -->
<string name="zen_mode_settings_dnd_manual_end_time">Do Not Disturb is on until <xliff:g id="formatted_time" example="7:00 AM">%s</xliff:g></string>
@@ -8653,93 +8683,6 @@
<!-- [CHAR LIMIT=60] Name of dev option to enable extra quick settings tiles -->
<string name="quick_settings_developer_tiles">Quick settings developer tiles</string>
- <!-- Title text for connecting to customer support [CHAR LIMIT=80]-->
- <string name="support_escalation_title">We\'re here to help</string>
-
- <!-- Title text for connecting to 24/7 available customer support [CHAR LIMIT=80]-->
- <string name="support_escalation_24_7_title">We\'re here for you 24/7</string>
-
- <!-- Content description for connecting customer support. The "24 7" part indicates
- support is available 24 hours a day, 7 days a week. It's used by screenreaders so it
- cannot contain any symbol other that space. [CHAR LIMIT=80]-->
- <string name="support_escalation_24_7_content_description">We\'re here for you 24 7</string>
-
- <!-- Summary text for connecting to customer support [CHAR LIMIT=NONE]-->
- <string name="support_escalation_summary">Our support team is here to help address any issue</string>
-
- <!-- Summary text for connecting to 24/7 customer support [CHAR LIMIT=NONE]-->
- <string name="support_escalation_24_7_summary">Our support team is available all day, every day</string>
-
- <!-- Summary text when customer support is closed. [CHAR LIMIT=NONE]-->
- <string name="support_escalation_closed_summary">Search help or come back during support hours (local time):<br><b><xliff:g id="operation_hours">%s</xliff:g></b></string>
-
- <!-- Summary text to call customer support when there is no internet. [CHAR LIMIT=NONE]-->
- <string name="support_escalation_no_internet_summary">Phone support hours (local time)<br><b><xliff:g id="operation_hours">%s</xliff:g></b></string>
-
- <!-- Summary text when customer support is unavailable in the region. [CHAR LIMIT=NONE]-->
- <string name="support_escalation_unavailable_summary">Search help or explore tips & tricks</string>
-
- <!-- Template for formatting support hours eg Mon - Fri, 8:00 AM - 19:30 PM. [CHAR LIMIT=NONE]-->
- <string name="support_hour_format" translatable="false">
- <xliff:g id="start_day">%1$s</xliff:g> - <xliff:g id="end_day">%2$s</xliff:g>, <xliff:g id="start_time">%3$s</xliff:g> - <xliff:g id="end_time">%4$s</xliff:g><br>
- </string>
-
- <!-- Button label for choosing country for phone support. [CHAR LIMIT=40]-->
- <string name="support_country_list_title">Support for:</string>
-
- <!-- Template for formatting country and language. eg Canada - French [CHAR LIMIT=NONE]-->
- <string name="support_country_format"><xliff:g id="country" example="Canada">%1$s</xliff:g> - <xliff:g id="language" example="French">%2$s</xliff:g></string>
-
- <!-- Template for formatting phone number and language. eg English (800-000-0000) [CHAR LIMIT=NONE]-->
- <string name ="support_phone_international_format">
- <xliff:g id="language" example="English">%1$s</xliff:g> (<xliff:g id="phone" example="800-000-0000">%2$s</xliff:g>)
- </string>
-
- <!-- Title text for a list of international support phone numbers. [CHAR LIMIT=60]-->
- <string name="support_international_phone_title">Traveling abroad?</string>
-
- <!-- Description text warning international phone charge may apply when dialing support numbers. [CHAR LIMIT=NONE]-->
- <string name="support_international_phone_summary">International charges may apply</string>
-
- <!-- Button label for contacting customer support by phone [CHAR LIMIT=20]-->
- <string name="support_escalation_by_phone">Phone</string>
-
- <!-- Button label for contacting customer support by chat [CHAR LIMIT=20]-->
- <string name="support_escalation_by_chat">Chat</string>
-
- <!-- Button label for visiting the tips & tricks site [CHAR LIMIT=60]-->
- <string name="support_tips_and_tricks_title">Explore tips & tricks</string>
-
- <!-- Button label for visiting help and/or send feedback [CHAR LIMIT=60]-->
- <string name="support_help_feedback_title">Search help & send feedback</string>
-
- <!-- Title text that indicates user needs to sign in to get customer support. [CHAR LIMIT=80]-->
- <string name="support_sign_in_required_title">Contact support</string>
-
- <!-- Summary text that indicates user needs to sign-in to get real time customer support. [CHAR LIMIT=NONE]-->
- <string name="support_sign_in_required_summary" translatable="false"></string>
-
- <!-- Button label for signing in an account [CHAR LIMIT=40]-->
- <string name="support_sign_in_button_text">Sign in</string>
-
- <!-- Button label that redirects user who needs help for signin to help screen [CHAR LIMIT=NONE]-->
- <string name="support_sign_in_required_help">Can\'t sign in?</string>
-
- <!-- Dialog title displayed before initiating real time support [CHAR LIMIT=80]-->
- <string name="support_disclaimer_title">Send system information</string>
-
- <!-- Checkbox text, when checked dialog will not show again [CHAR LIMIT=80] -->
- <string name="support_disclaimer_do_not_show">Do not show again</string>
-
- <!-- Prefix text for the account picker, e.g. "Requesting as user@gmail.com" [CHAR LIMIT=60] -->
- <string name="support_account_request_prefix">Requesting as</string>
-
- <!-- Spinner dropdown text, when selected will try to add account [CHAR LIMIT=60] -->
- <string name="support_account_picker_add_account">Add account</string>
-
- <!-- Title for the dialog containing system information shown [CHAR LIMIT=30] -->
- <string name="support_system_information_title">System information</string>
-
<!-- [CHAR LIMIT=60] Title of work profile setting page -->
<string name="managed_profile_settings_title">Work profile settings</string>
<!-- [CHAR LIMIT=60] The preference title for enabling cross-profile remote contact search -->
@@ -8765,9 +8708,6 @@
<item quantity="other"><xliff:g id="number" example="7">%s</xliff:g> seconds</item>
</plurals>
- <!-- Estimated wait time range for real time supports -->
- <string name="support_estimated_wait_time">~<xliff:g id="ESTIMATE" example="2 minutes">%1$s</xliff:g> wait</string>
-
<!-- Used as title on the automatic storage manager settings. [CHAR LIMIT=60] -->
<string name="automatic_storage_manager_settings">Manage storage</string>
diff --git a/res/values/styles.xml b/res/values/styles.xml
index a07bade..579ee48 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -330,19 +330,6 @@
<item name="android:textColor">?android:attr/colorError</item>
</style>
- <style name="TextAppearance.SupportTitle"
- parent="@android:style/TextAppearance.Material.Subhead">
- <item name="android:textColor">?android:attr/colorAccent</item>
- <item name="android:textSize">24sp</item>
- </style>
-
- <style name="TextAppearance.SupportSummary" parent="TextAppearance.CategoryTitle"/>
-
- <style name="SupportSecondaryButton"
- parent="android:Widget.DeviceDefault.Button.Borderless.Colored">
- <item name="android:textSize">12sp</item>
- </style>
-
<style name="FingerprintLayoutTheme">
<item name="android:icon">@drawable/ic_fingerprint_header</item>
</style>
@@ -386,14 +373,6 @@
<item name="android:textAppearance">@android:style/TextAppearance.Material.Subhead</item>
</style>
- <style name="SupportEscalationCard">
- <item name="android:background">?android:attr/colorSecondary</item>
- <item name="android:gravity">center</item>
- <item name="android:minHeight">368dp</item>
- <item name="android:paddingStart">@dimen/support_escalation_card_padding_start</item>
- <item name="android:paddingEnd">@dimen/support_escalation_card_padding_end</item>
- </style>
-
<style name="FingerprintHeaderStyle" parent="android:style/TextAppearance.Material.Subhead">
<item name="android:paddingTop">16dp</item>
<item name="android:textColor">@color/primary_dark_material_light</item>
diff --git a/res/xml/connected_devices_advanced.xml b/res/xml/connected_devices_advanced.xml
index 57a2580..dfe23df 100644
--- a/res/xml/connected_devices_advanced.xml
+++ b/res/xml/connected_devices_advanced.xml
@@ -17,7 +17,7 @@
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="connected_devices_screen"
- android:title="@string/connected_devices_dashboard_title">
+ android:title="@string/connected_device_connections_title">
<SwitchPreference
android:key="toggle_bluetooth_switch"
diff --git a/res/xml/data_usage_wifi.xml b/res/xml/data_usage_wifi.xml
index 607cee1..905b15a 100644
--- a/res/xml/data_usage_wifi.xml
+++ b/res/xml/data_usage_wifi.xml
@@ -27,11 +27,6 @@
android:key="wifi_data_usage"
android:title="@string/wifi_data_usage" />
- <com.android.settings.datausage.NetworkRestrictionsPreference
- android:key="network_restrictions"
- android:title="@string/network_restrictions"
- android:fragment="com.android.settings.datausage.DataUsageMeteredSettings" />
-
</com.android.settings.datausage.TemplatePreferenceCategory>
</PreferenceScreen>
diff --git a/res/xml/network_and_internet.xml b/res/xml/network_and_internet.xml
index bc027d3..134f5b3 100644
--- a/res/xml/network_and_internet.xml
+++ b/res/xml/network_and_internet.xml
@@ -75,12 +75,13 @@
settings:userRestriction="no_config_mobile_networks"
settings:useAdminDisabledSummary="true" />
- <SwitchPreference
+ <com.android.settingslib.RestrictedSwitchPreference
android:key="toggle_airplane"
android:title="@string/airplane_mode"
android:icon="@drawable/ic_airplanemode_active"
android:disableDependentsState="true"
- android:order="5" />
+ android:order="5"
+ settings:userRestriction="no_airplane_mode"/>
<Preference
android:fragment="com.android.settings.ProxySelector"
diff --git a/res/xml/power_usage_summary.xml b/res/xml/power_usage_summary.xml
index 5d6c9e9..d7c3c39 100644
--- a/res/xml/power_usage_summary.xml
+++ b/res/xml/power_usage_summary.xml
@@ -38,6 +38,11 @@
android:key="battery_saver_summary"
android:title="@string/battery_saver"/>
+ <Preference
+ android:fragment="com.android.settings.fuelgauge.SmartBatterySettings"
+ android:key="smart_battery_manager"
+ android:title="@string/smart_battery_manager_title"/>
+
<SwitchPreference
android:key="battery_percentage"
android:title="@string/battery_percentage"
diff --git a/res/xml/smart_battery_detail.xml b/res/xml/smart_battery_detail.xml
new file mode 100644
index 0000000..8cfd797
--- /dev/null
+++ b/res/xml/smart_battery_detail.xml
@@ -0,0 +1,38 @@
+<?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.
+ -->
+
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
+ android:title="@string/smart_battery_manager_title">
+
+ <!-- TODO(b/71722498): Add header back, otherwise also remove smart_battery_header
+ <com.android.settings.applications.LayoutPreference
+ android:key="header_view"
+ android:layout="@layout/smart_battery_header"
+ android:selectable="false"
+ android:order="-10000"/>
+ -->
+
+ <SwitchPreference
+ android:key="smart_battery"
+ android:title="@string/smart_battery_title"
+ android:summary="@string/smart_battery_summary"/>
+
+ <Preference
+ android:key="restricted_app"
+ android:title="@string/restricted_app_title"/>
+
+</PreferenceScreen>
\ No newline at end of file
diff --git a/res/xml/wifi_network_details_fragment.xml b/res/xml/wifi_network_details_fragment.xml
index 8203bec..5e2745a 100644
--- a/res/xml/wifi_network_details_fragment.xml
+++ b/res/xml/wifi_network_details_fragment.xml
@@ -49,6 +49,13 @@
android:icon="@drawable/ic_security_lock_24dp"
android:title="@string/wifi_security"
android:selectable="false"/>
+
+ <DropDownPreference
+ android:key="metered"
+ android:icon="@drawable/ic_attach_money_black_24dp"
+ android:title="@string/data_usage_metered_yes"
+ android:entries="@array/wifi_metered_entries"
+ android:entryValues="@array/wifi_metered_values"/>
</PreferenceCategory>
<!-- Network Details -->
diff --git a/res/xml/zen_mode_behavior_settings.xml b/res/xml/zen_mode_behavior_settings.xml
index 31d429b..57bc4fd 100644
--- a/res/xml/zen_mode_behavior_settings.xml
+++ b/res/xml/zen_mode_behavior_settings.xml
@@ -61,7 +61,7 @@
<!-- Repeat callers -->
<SwitchPreference
android:key="zen_mode_repeat_callers"
- android:title="@string/zen_mode_repeat_callers"/>
+ android:title="@string/zen_mode_repeat_callers" />
</PreferenceCategory>
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index d21a061..505977d 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -162,7 +162,6 @@
}
}
public static class WebViewAppPickerActivity extends SettingsActivity { /* empty */ }
- public static class LegacySupportActivity extends SettingsActivity{ /* empty */ }
// Top level categories for new IA
public static class NetworkDashboardActivity extends SettingsActivity {}
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 6b0a5b8..ad95121 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -94,6 +94,7 @@
import android.text.format.DateUtils;
import android.text.style.TtsSpan;
import android.util.ArraySet;
+import android.util.IconDrawableFactory;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
@@ -1222,7 +1223,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;
}
@@ -1382,4 +1383,18 @@
}
return new BitmapDrawable(null, bitmap);
}
+
+ /**
+ * Get the {@link Drawable} that represents the app icon
+ */
+ public static Drawable getBadgedIcon(IconDrawableFactory iconDrawableFactory,
+ PackageManager packageManager, String packageName, int userId) {
+ try {
+ final ApplicationInfo appInfo = packageManager.getApplicationInfo(packageName,
+ PackageManager.GET_META_DATA);
+ return iconDrawableFactory.getBadgedIcon(appInfo, userId);
+ } catch (PackageManager.NameNotFoundException e) {
+ return packageManager.getDefaultActivityIcon();
+ }
+ }
}
diff --git a/src/com/android/settings/applications/RunningServices.java b/src/com/android/settings/applications/RunningServices.java
index 4e3d629..bf48492 100644
--- a/src/com/android/settings/applications/RunningServices.java
+++ b/src/com/android/settings/applications/RunningServices.java
@@ -42,8 +42,6 @@
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
-
getActivity().setTitle(R.string.runningservices_settings_title);
}
@@ -64,9 +62,9 @@
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
mOptionsMenu = menu;
menu.add(0, SHOW_RUNNING_SERVICES, 1, R.string.show_running_services)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
menu.add(0, SHOW_BACKGROUND_PROCESSES, 2, R.string.show_background_processes)
- .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
+ .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
updateOptionsMenu();
}
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index 4c861fb..664dda8 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -59,7 +59,6 @@
import com.android.settings.bluetooth.BluetoothSettings;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
-import com.android.settings.dashboard.SupportFragment;
import com.android.settings.datausage.DataPlanUsageSummary;
import com.android.settings.datausage.DataUsageList;
import com.android.settings.datausage.DataUsageSummary;
@@ -242,7 +241,6 @@
NightDisplaySettings.class.getName(),
ManageDomainUrls.class.getName(),
AutomaticStorageManagerSettings.class.getName(),
- SupportFragment.class.getName(),
StorageDashboardFragment.class.getName(),
SystemDashboardFragment.class.getName(),
NetworkDashboardFragment.class.getName(),
@@ -270,6 +268,7 @@
Settings.PowerUsageSummaryLegacyActivity.class.getName(),
Settings.UserAndAccountDashboardActivity.class.getName(),
Settings.SecuritySettingsActivity.class.getName(),
+ Settings.SecuritySettingsActivityV2.class.getName(),
Settings.AccessibilitySettingsActivity.class.getName(),
Settings.SystemDashboardActivity.class.getName(),
SupportDashboardActivity.class.getName(),
diff --git a/src/com/android/settings/dashboard/SupportFragment.java b/src/com/android/settings/dashboard/SupportFragment.java
deleted file mode 100644
index fcc9f78..0000000
--- a/src/com/android/settings/dashboard/SupportFragment.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.dashboard;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.OnAccountsUpdateListener;
-import android.app.Activity;
-import android.content.Context;
-import android.net.ConnectivityManager;
-import android.net.Network;
-import android.net.NetworkCapabilities;
-import android.net.NetworkInfo;
-import android.net.NetworkRequest;
-import android.os.Bundle;
-import android.support.v7.widget.LinearLayoutManager;
-import android.support.v7.widget.RecyclerView;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.R;
-import com.android.settings.core.InstrumentedFragment;
-import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.overlay.SupportFeatureProvider;
-import com.android.settingslib.utils.ThreadUtils;
-
-/**
- * Fragment for support tab in SettingsGoogle.
- */
-public final class SupportFragment extends InstrumentedFragment implements View.OnClickListener,
- OnAccountsUpdateListener {
-
- private final ConnectivityManager.NetworkCallback mNetworkCallback =
- new ConnectivityManager.NetworkCallback() {
-
- @Override
- public void onCapabilitiesChanged(Network network,
- NetworkCapabilities capabilities) {
- postConnectivityChanged();
- }
-
- @Override
- public void onAvailable(Network network) {
- postConnectivityChanged();
- }
-
- @Override
- public void onLost(Network network) {
- postConnectivityChanged();
- }
- };
-
- private Activity mActivity;
- private View mContent;
- private RecyclerView mRecyclerView;
- private SupportItemAdapter mSupportItemAdapter;
- private AccountManager mAccountManager;
- private SupportFeatureProvider mSupportFeatureProvider;
- private ConnectivityManager mConnectivityManager;
-
- @Override
- public int getMetricsCategory() {
- return MetricsProto.MetricsEvent.SUPPORT_FRAGMENT;
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setHasOptionsMenu(true);
- mActivity = getActivity();
- mAccountManager = AccountManager.get(mActivity);
- mSupportFeatureProvider =
- FeatureFactory.getFactory(mActivity).getSupportFeatureProvider(mActivity);
- mSupportItemAdapter = new SupportItemAdapter(mActivity, savedInstanceState,
- mSupportFeatureProvider, mMetricsFeatureProvider, this /* itemClickListener */);
- mConnectivityManager =
- (ConnectivityManager) mActivity.getSystemService(Context.CONNECTIVITY_SERVICE);
- }
-
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- mContent = inflater.inflate(R.layout.support_fragment, container, false);
- mRecyclerView = (RecyclerView) mContent.findViewById(R.id.support_items);
- mRecyclerView.setLayoutManager(new LinearLayoutManager(
- getActivity(), LinearLayoutManager.VERTICAL, false /* reverseLayout */));
- mRecyclerView.setAdapter(mSupportItemAdapter);
- return mContent;
- }
-
- @Override
- public void onResume() {
- super.onResume();
- // Monitor account change.
- mAccountManager.addOnAccountsUpdatedListener(
- this /* listener */, null /* handler */, true /* updateImmediately */);
- // Monitor connectivity
- mConnectivityManager.registerNetworkCallback(
- new NetworkRequest.Builder()
- .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
- .build(),
- mNetworkCallback);
- mSupportItemAdapter.setHasInternet(hasInternet());
- mSupportItemAdapter.refreshData();
- }
-
- @Override
- public void onPause() {
- super.onPause();
- // Stop monitor account change.
- mAccountManager.removeOnAccountsUpdatedListener(this /* listener */);
- // Stop monitor connectivity.
- mConnectivityManager.unregisterNetworkCallback(mNetworkCallback);
- }
-
- @Override
- public void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- mSupportItemAdapter.onSaveInstanceState(outState);
- }
-
- @Override
- public void onAccountsUpdated(Account[] accounts) {
- // Account changed, update support items.
- mSupportItemAdapter.setAccounts(
- mSupportFeatureProvider.getSupportEligibleAccounts(mActivity));
- }
-
- @Override
- public void onClick(View v) {
- final SupportItemAdapter.ViewHolder vh =
- (SupportItemAdapter.ViewHolder) mRecyclerView.getChildViewHolder(v);
- mSupportItemAdapter.onItemClicked(vh.getAdapterPosition());
- }
-
- private void postConnectivityChanged() {
- ThreadUtils.postOnMainThread(() -> {
- if (mSupportItemAdapter != null) {
- mSupportItemAdapter.setHasInternet(hasInternet());
- }
- });
- }
-
- private boolean hasInternet() {
- final NetworkInfo activeNetwork = mConnectivityManager.getActiveNetworkInfo();
- return activeNetwork != null && activeNetwork.isConnectedOrConnecting();
- }
-}
diff --git a/src/com/android/settings/dashboard/SupportItemAdapter.java b/src/com/android/settings/dashboard/SupportItemAdapter.java
deleted file mode 100644
index 54c5ae6..0000000
--- a/src/com/android/settings/dashboard/SupportItemAdapter.java
+++ /dev/null
@@ -1,823 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.dashboard;
-
-import android.accounts.Account;
-import android.annotation.DrawableRes;
-import android.annotation.LayoutRes;
-import android.annotation.StringRes;
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.app.DialogFragment;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.os.Bundle;
-import android.support.annotation.VisibleForTesting;
-import android.support.v7.widget.RecyclerView;
-import android.text.TextUtils;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.ArrayAdapter;
-import android.widget.ImageView;
-import android.widget.Spinner;
-import android.widget.TextView;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.internal.util.ArrayUtils;
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.MetricsFeatureProvider;
-import com.android.settings.overlay.SupportFeatureProvider;
-import com.android.settings.support.SupportDisclaimerDialogFragment;
-import com.android.settings.support.SupportPhone;
-import com.android.settings.support.SupportPhoneDialogFragment;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import static com.android.settings.overlay.SupportFeatureProvider.SupportType.CHAT;
-import static com.android.settings.overlay.SupportFeatureProvider.SupportType.PHONE;
-
-/**
- * Item adapter for support tiles.
- */
-public final class SupportItemAdapter extends RecyclerView.Adapter<SupportItemAdapter.ViewHolder> {
-
- private static final String STATE_SELECTED_COUNTRY = "STATE_SELECTED_COUNTRY";
- private static final String ACCOUNT_SELECTED_INDEX = "ACCOUNT_SELECTED_INDEX";
- private static final int TYPE_ESCALATION_OPTIONS = R.layout.support_escalation_options;
- private static final int TYPE_ESCALATION_OPTIONS_OFFLINE =
- R.layout.support_offline_escalation_options;
- private static final int TYPE_SUPPORT_TILE = R.layout.support_tile;
- private static final int TYPE_SUPPORT_TILE_SPACER = R.layout.support_tile_spacer;
- private static final int TYPE_SIGN_IN_BUTTON = R.layout.support_sign_in_button;
-
- private final Activity mActivity;
- private final EscalationClickListener mEscalationClickListener;
- private final OfflineSpinnerItemSelectListener mOfflineSpinnerItemSelectListener;
- private final OnlineSpinnerItemSelectListener mOnlineSpinnerItemSelectListener;
- private final SupportFeatureProvider mSupportFeatureProvider;
- private final MetricsFeatureProvider mMetricsFeatureProvider;
- private final View.OnClickListener mItemClickListener;
- private final List<SupportData> mSupportData;
-
- private String mSelectedCountry;
- private boolean mHasInternet;
- private Account[] mAccounts;
- private int mSelectedAccountIndex;
-
- public SupportItemAdapter(Activity activity, Bundle savedInstanceState,
- SupportFeatureProvider supportFeatureProvider,
- MetricsFeatureProvider metricsFeatureProvider,
- View.OnClickListener itemClickListener) {
- mActivity = activity;
- mSupportFeatureProvider = supportFeatureProvider;
- mMetricsFeatureProvider = metricsFeatureProvider;
- mItemClickListener = itemClickListener;
- mEscalationClickListener = new EscalationClickListener();
- mOfflineSpinnerItemSelectListener = new OfflineSpinnerItemSelectListener();
- mOnlineSpinnerItemSelectListener = new OnlineSpinnerItemSelectListener();
- mSupportData = new ArrayList<>();
- // Optimistically assume we have Internet access. It will be updated later to correct value.
- mHasInternet = true;
- if (savedInstanceState != null) {
- mSelectedCountry = savedInstanceState.getString(STATE_SELECTED_COUNTRY);
- mSelectedAccountIndex = savedInstanceState.getInt(ACCOUNT_SELECTED_INDEX);
- } else {
- mSelectedCountry = mSupportFeatureProvider.getCurrentCountryCodeIfHasConfig(PHONE);
- mSelectedAccountIndex = 0;
- }
-
- mAccounts = mSupportFeatureProvider.getSupportEligibleAccounts(mActivity);
- refreshData();
- }
-
- @Override
- public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
- return new ViewHolder(LayoutInflater.from(parent.getContext()).inflate(
- viewType, parent, false));
- }
-
- @Override
- public void onBindViewHolder(ViewHolder holder, int position) {
- final SupportData data = mSupportData.get(position);
- switch (holder.getItemViewType()) {
- case TYPE_SIGN_IN_BUTTON:
- bindSignInPromoTile(holder, (EscalationData) data);
- break;
- case TYPE_ESCALATION_OPTIONS:
- bindEscalationOptions(holder, (EscalationData) data);
- break;
- case TYPE_ESCALATION_OPTIONS_OFFLINE:
- bindOfflineEscalationOptions(holder, (OfflineEscalationData) data);
- break;
- case TYPE_SUPPORT_TILE_SPACER:
- break;
- default:
- bindSupportTile(holder, data);
- break;
- }
- }
-
- @Override
- public int getItemViewType(int position) {
- return mSupportData.get(position).type;
- }
-
- @Override
- public int getItemCount() {
- return mSupportData.size();
- }
-
- /**
- * Called when a support item is clicked.
- */
- public void onItemClicked(int position) {
- if (position >= 0 && position < mSupportData.size()) {
- final SupportData data = mSupportData.get(position);
- if (data.intent != null &&
- mActivity.getPackageManager().resolveActivity(data.intent, 0) != null) {
- if (data.metricsEvent >= 0) {
- mMetricsFeatureProvider.action(mActivity, data.metricsEvent);
- }
- mActivity.startActivityForResult(data.intent, 0);
- }
- }
- }
-
- public void setHasInternet(boolean hasInternet) {
- if (mHasInternet != hasInternet) {
- mHasInternet = hasInternet;
- refreshEscalationCards();
- }
- }
-
- public void setAccounts(Account accounts[]) {
- if (!Arrays.equals(mAccounts, accounts)) {
- if (mAccounts.length == 0) {
- mSelectedAccountIndex = 0;
- } else {
- final int index = ArrayUtils.indexOf(accounts, mAccounts[mSelectedAccountIndex]);
- mSelectedAccountIndex = index != -1 ? index : 0;
- }
-
- mAccounts = accounts;
- mSupportFeatureProvider.refreshOperationRules();
- refreshEscalationCards();
- }
- }
-
- public void onSaveInstanceState(Bundle outState) {
- outState.putString(STATE_SELECTED_COUNTRY, mSelectedCountry);
- outState.putInt(ACCOUNT_SELECTED_INDEX, mSelectedAccountIndex);
- }
-
- /**
- * Create data for the adapter. If there is already data in the adapter, they will be
- * destroyed and recreated.
- */
- void refreshData() {
- mSupportData.clear();
- addEscalationCards();
- addMoreHelpItems();
- notifyDataSetChanged();
- }
-
- /**
- * Adds 1 escalation card. Based on current phone state, the escalation card can display
- * different content.
- */
- private void addEscalationCards() {
- if (mAccounts.length == 0) {
- addSignInPromo();
- } else if (mHasInternet) {
- addOnlineEscalationCards();
- } else {
- addOfflineEscalationCards();
- }
- }
-
- /**
- * Finds and refreshes escalation card data.
- */
- private void refreshEscalationCards() {
- if (getItemCount() > 0) {
- final int itemType = getItemViewType(0 /* position */);
- if (itemType == TYPE_SIGN_IN_BUTTON
- || itemType == TYPE_ESCALATION_OPTIONS
- || itemType == TYPE_ESCALATION_OPTIONS_OFFLINE) {
- mSupportData.remove(0 /* position */);
- addEscalationCards();
- notifyItemChanged(0 /* position */);
- }
- }
- }
-
- private void addOnlineEscalationCards() {
- final boolean hasPhoneOperation =
- mSupportFeatureProvider.isSupportTypeEnabled(mActivity, PHONE);
- final boolean hasChatOperation =
- mSupportFeatureProvider.isSupportTypeEnabled(mActivity, CHAT);
- final EscalationData.Builder builder = new EscalationData.Builder(mActivity);
- if (!hasPhoneOperation && !hasChatOperation) {
- // No support at all.
- builder.setTileTitle(R.string.support_escalation_title)
- .setTileSummary(R.string.support_escalation_unavailable_summary);
- } else if (mSupportFeatureProvider.isAlwaysOperating(PHONE, null /* countryCode */)
- || mSupportFeatureProvider.isAlwaysOperating(CHAT, null /* countryCode */)) {
- // Support is available.
- builder.setTileTitle(R.string.support_escalation_24_7_title)
- .setTileTitleDescription(R.string.support_escalation_24_7_content_description)
- .setTileSummary(mActivity.getString(R.string.support_escalation_24_7_summary));
- } else if (mSupportFeatureProvider.isOperatingNow(PHONE)
- || mSupportFeatureProvider.isOperatingNow(CHAT)) {
- // Support is available now.
- builder.setTileTitle(R.string.support_escalation_title)
- .setTileSummary(R.string.support_escalation_summary);
- } else {
- // Support is now temporarily unavailable.
- builder.setTileTitle(R.string.support_escalation_title)
- .setTileSummary(
- mSupportFeatureProvider.getOperationHours(mActivity, PHONE, null,
- true /* hasInternet */));
- }
- if (hasPhoneOperation) {
- builder.setText1(R.string.support_escalation_by_phone)
- .setSummary1(mSupportFeatureProvider.getEstimatedWaitTime(mActivity, PHONE))
- .setEnabled1(mSupportFeatureProvider.isOperatingNow(PHONE));
- }
- if (hasChatOperation) {
- builder.setText2(R.string.support_escalation_by_chat)
- .setSummary2(mSupportFeatureProvider.getEstimatedWaitTime(mActivity, CHAT))
- .setEnabled2(mSupportFeatureProvider.isOperatingNow(CHAT));
- }
- mSupportData.add(0 /* index */, builder.build());
- }
-
- private void addOfflineEscalationCards() {
- final CharSequence operatingHours;
- final boolean isPhoneSupportAlwaysOperating =
- mSupportFeatureProvider.isAlwaysOperating(PHONE, mSelectedCountry);
- if (isPhoneSupportAlwaysOperating) {
- operatingHours = mActivity.getString(R.string.support_escalation_24_7_summary);
- } else {
- operatingHours = mSupportFeatureProvider.getOperationHours(mActivity,
- PHONE, mSelectedCountry, false /* hasInternet */);
- }
- mSupportData.add(0 /* index */, new OfflineEscalationData.Builder(mActivity)
- .setCountries(mSupportFeatureProvider.getPhoneSupportCountries())
- .setTollFreePhone(mSupportFeatureProvider.getSupportPhones(
- mSelectedCountry, true /* isTollFree */))
- .setTolledPhone(mSupportFeatureProvider.getSupportPhones(
- mSelectedCountry, false /* isTollFree */))
- .setTileTitle(isPhoneSupportAlwaysOperating
- ? R.string.support_escalation_24_7_title
- : R.string.support_escalation_title)
- .setTileTitleDescription(isPhoneSupportAlwaysOperating
- ? R.string.support_escalation_24_7_content_description
- : R.string.support_escalation_title)
- .setTileSummary(operatingHours)
- .build());
- }
-
- private void addSignInPromo() {
- mSupportData.add(0 /* index */, new EscalationData.Builder(mActivity, TYPE_SIGN_IN_BUTTON)
- .setText1(R.string.support_sign_in_button_text)
- .setText2(R.string.support_sign_in_required_help)
- .setTileTitle(R.string.support_sign_in_required_title)
- .setTileSummary(R.string.support_sign_in_required_summary)
- .build());
- }
-
- private void addMoreHelpItems() {
- mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE_SPACER).build());
- PackageManager packageManager = mActivity.getPackageManager();
- Intent intent = mSupportFeatureProvider.getHelpIntent(mActivity);
- if (packageManager.resolveActivity(intent, 0) != null) {
- mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE)
- .setIcon(R.drawable.ic_help_24dp)
- .setTileTitle(R.string.support_help_feedback_title)
- .setIntent(intent)
- .setMetricsEvent(MetricsProto.MetricsEvent.ACTION_SUPPORT_HELP_AND_FEEDBACK)
- .build());
- }
- intent = mSupportFeatureProvider.getTipsAndTricksIntent(mActivity);
- if (packageManager.resolveActivity(intent, 0) != null) {
- mSupportData.add(new SupportData.Builder(mActivity, TYPE_SUPPORT_TILE)
- .setIcon(R.drawable.ic_lightbulb_outline_24)
- .setTileTitle(R.string.support_tips_and_tricks_title)
- .setIntent(intent)
- .setMetricsEvent(MetricsProto.MetricsEvent.ACTION_SUPPORT_TIPS_AND_TRICKS)
- .build());
- }
- }
-
- private void bindEscalationOptions(ViewHolder holder, EscalationData data) {
- holder.tileTitleView.setText(data.tileTitle);
- holder.tileTitleView.setContentDescription(data.tileTitleDescription);
- holder.tileSummaryView.setText(data.tileSummary);
- if (data.text1 == 0) {
- holder.text1View.setVisibility(View.GONE);
- } else {
- holder.text1View.setText(data.text1);
- holder.text1View.setOnClickListener(mEscalationClickListener);
- holder.text1View.setEnabled(data.enabled1 && mHasInternet);
- holder.text1View.setVisibility(View.VISIBLE);
- }
- if (TextUtils.isEmpty(data.text2)) {
- holder.text2View.setVisibility(View.GONE);
- } else {
- holder.text2View.setText(data.text2);
- holder.text2View.setOnClickListener(mEscalationClickListener);
- holder.text2View.setEnabled(data.enabled2 && mHasInternet);
- holder.text2View.setVisibility(View.VISIBLE);
- }
- if (holder.summary1View != null) {
- holder.summary1View.setText(data.summary1);
- holder.summary1View.setVisibility(mHasInternet && !TextUtils.isEmpty(data.summary1)
- ? View.VISIBLE : View.GONE);
- }
- if (holder.summary2View != null) {
- holder.summary2View.setText(data.summary2);
- holder.summary2View.setVisibility(mHasInternet && !TextUtils.isEmpty(data.summary2)
- ? View.VISIBLE : View.GONE);
- }
-
- bindAccountPicker(holder);
- }
-
- @VisibleForTesting
- public void bindAccountPicker(ViewHolder holder) {
- final Spinner spinner = (Spinner) holder.itemView.findViewById(R.id.account_spinner);
-
- final ArrayAdapter<String> adapter = new ArrayAdapter(
- mActivity, R.layout.support_account_spinner_item,
- extractAccountNames(mAccounts));
- adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
- spinner.setAdapter(adapter);
- spinner.setOnItemSelectedListener(mOnlineSpinnerItemSelectListener);
- spinner.setSelection(mSelectedAccountIndex);
- }
-
- private void bindOfflineEscalationOptions(ViewHolder holder, OfflineEscalationData data) {
- // Bind Title
- holder.tileTitleView.setText(data.tileTitle);
- holder.tileTitleView.setContentDescription(data.tileTitleDescription);
- holder.tileSummaryView.setText(data.tileSummary);
- // Bind spinner
- final Spinner spinner = (Spinner) holder.itemView.findViewById(R.id.spinner);
- final ArrayAdapter<String> adapter = new ArrayAdapter(
- mActivity, android.R.layout.simple_spinner_dropdown_item, data.countries);
- spinner.setAdapter(adapter);
- final List<String> countryCodes = mSupportFeatureProvider.getPhoneSupportCountryCodes();
- for (int i = 0; i < countryCodes.size(); i++) {
- if (TextUtils.equals(countryCodes.get(i), mSelectedCountry)) {
- spinner.setSelection(i);
- break;
- }
- }
- spinner.setOnItemSelectedListener(mOfflineSpinnerItemSelectListener);
- // Bind buttons
- if (data.tollFreePhone != null) {
- holder.text1View.setText(data.tollFreePhone.number);
- holder.text1View.setVisibility(View.VISIBLE);
- holder.text1View.setOnClickListener(mEscalationClickListener);
- } else {
- holder.text1View.setVisibility(View.GONE);
- }
- if (data.tolledPhone != null) {
- holder.text2View.setText(
- mActivity.getString(R.string.support_international_phone_title));
- holder.text2View.setVisibility(View.VISIBLE);
- holder.text2View.setOnClickListener(mEscalationClickListener);
- } else {
- holder.text2View.setVisibility(View.GONE);
- }
-
- if (ActivityManager.isUserAMonkey()) {
- holder.text1View.setVisibility(View.GONE);
- holder.text2View.setVisibility(View.GONE);
- spinner.setVisibility(View.GONE);
- holder.itemView.findViewById(R.id.support_text).setVisibility(View.GONE);
- }
- }
-
- private void bindSignInPromoTile(ViewHolder holder, EscalationData data) {
- holder.tileTitleView.setText(data.tileTitle);
- holder.tileTitleView.setContentDescription(data.tileTitleDescription);
- holder.tileSummaryView.setText(data.tileSummary);
- holder.text1View.setText(data.text1);
- holder.text2View.setText(data.text2);
- holder.text1View.setOnClickListener(mEscalationClickListener);
- holder.text2View.setOnClickListener(mEscalationClickListener);
- }
-
- private void bindSupportTile(ViewHolder holder, SupportData data) {
- if (holder.iconView != null) {
- holder.iconView.setImageResource(data.icon);
- }
- if (holder.tileTitleView != null) {
- holder.tileTitleView.setText(data.tileTitle);
- holder.tileTitleView.setContentDescription(data.tileTitleDescription);
- }
- if (holder.tileSummaryView != null) {
- holder.tileSummaryView.setText(data.tileSummary);
- }
- holder.itemView.setOnClickListener(mItemClickListener);
- }
-
- /**
- * Show a disclaimer dialog and start support action after disclaimer has been acknowledged.
- */
- private void tryStartDisclaimerAndSupport(final @SupportFeatureProvider.SupportType int type) {
- if (mSupportFeatureProvider.shouldShowDisclaimerDialog(mActivity)) {
- DialogFragment fragment = SupportDisclaimerDialogFragment.newInstance(
- mAccounts[mSelectedAccountIndex], type);
- fragment.show(mActivity.getFragmentManager(), SupportDisclaimerDialogFragment.TAG);
- return;
- }
- mSupportFeatureProvider.startSupport(mActivity, mAccounts[mSelectedAccountIndex], type);
- }
-
- private String[] extractAccountNames(Account[] accounts) {
- String[] accountNames = new String[accounts.length+1];
- for (int i = 0; i < accounts.length; i++) {
- accountNames[i] = accounts[i].name;
- }
- accountNames[accounts.length] = mActivity.getString(
- R.string.support_account_picker_add_account);
-
- return accountNames;
- }
-
- /**
- * Click handler for starting escalation options.
- */
- private final class EscalationClickListener implements View.OnClickListener {
- @Override
- public void onClick(final View v) {
- if (mAccounts.length == 0) {
- switch (v.getId()) {
- case android.R.id.text1:
- mMetricsFeatureProvider.action(mActivity,
- MetricsProto.MetricsEvent.ACTION_SUPPORT_SIGN_IN);
- mActivity.startActivityForResult(
- mSupportFeatureProvider.getAccountLoginIntent(),
- 0 /* requestCode */);
- break;
- case android.R.id.text2:
- mActivity.startActivityForResult(
- mSupportFeatureProvider.getSignInHelpIntent(mActivity),
- 0 /* requestCode */);
- break;
- }
- } else if (mHasInternet) {
- switch (v.getId()) {
- case android.R.id.text1:
- mMetricsFeatureProvider.action(mActivity,
- MetricsProto.MetricsEvent.ACTION_SUPPORT_PHONE);
- tryStartDisclaimerAndSupport(PHONE);
- break;
- case android.R.id.text2:
- mMetricsFeatureProvider.action(mActivity,
- MetricsProto.MetricsEvent.ACTION_SUPPORT_CHAT);
- tryStartDisclaimerAndSupport(CHAT);
- break;
- }
- } else {
- switch (v.getId()) {
- case android.R.id.text1: {
- final SupportPhone phone = mSupportFeatureProvider
- .getSupportPhones(mSelectedCountry, true /* isTollFree */);
- if (phone != null) {
- final Intent intent = phone.getDialIntent();
- final boolean canDial = !mActivity.getPackageManager()
- .queryIntentActivities(intent, 0)
- .isEmpty();
- if (canDial) {
- mMetricsFeatureProvider.action(mActivity,
- MetricsProto.MetricsEvent.ACTION_SUPPORT_DAIL_TOLLFREE);
- mActivity.startActivity(intent);
- }
- }
- break;
- }
- case android.R.id.text2: {
- final SupportPhone phone = mSupportFeatureProvider
- .getSupportPhones(mSelectedCountry, false /* isTollFree */);
- final SupportPhoneDialogFragment fragment =
- SupportPhoneDialogFragment.newInstance(phone);
- mMetricsFeatureProvider.action(mActivity,
- MetricsProto.MetricsEvent.ACTION_SUPPORT_VIEW_TRAVEL_ABROAD_DIALOG);
- fragment.show(mActivity.getFragmentManager(),
- SupportPhoneDialogFragment.TAG);
- break;
- }
- }
- }
- }
- }
-
- private final class OfflineSpinnerItemSelectListener
- implements AdapterView.OnItemSelectedListener {
-
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- final List<String> countryCodes = mSupportFeatureProvider.getPhoneSupportCountryCodes();
- final String selectedCountry = countryCodes.get(position);
- if (!TextUtils.equals(selectedCountry, mSelectedCountry)) {
- mSelectedCountry = selectedCountry;
- refreshEscalationCards();
- }
- }
-
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- // Do nothing.
- }
- }
-
- private final class OnlineSpinnerItemSelectListener
- implements AdapterView.OnItemSelectedListener {
-
- @Override
- public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
- if (position == mAccounts.length) {
- mActivity.startActivity(mSupportFeatureProvider.getAccountLoginIntent());
- // Make sure "Add account" is not shown as selected item
- parent.setSelection(mSelectedAccountIndex);
- } else if (position != mSelectedAccountIndex) {
- mSelectedAccountIndex = position;
- }
- }
-
- @Override
- public void onNothingSelected(AdapterView<?> parent) {
- // Do nothing.
- }
- }
-
- /**
- * {@link RecyclerView.ViewHolder} for support items.
- */
- static final class ViewHolder extends RecyclerView.ViewHolder {
-
- final ImageView iconView;
- final TextView tileTitleView;
- final TextView tileSummaryView;
- final TextView text1View;
- final TextView text2View;
- final TextView summary1View;
- final TextView summary2View;
-
- ViewHolder(View itemView) {
- super(itemView);
- iconView = (ImageView) itemView.findViewById(android.R.id.icon);
- tileTitleView = (TextView) itemView.findViewById(R.id.tile_title);
- tileSummaryView = (TextView) itemView.findViewById(R.id.tile_summary);
- text1View = (TextView) itemView.findViewById(android.R.id.text1);
- text2View = (TextView) itemView.findViewById(android.R.id.text2);
- summary1View = (TextView) itemView.findViewById(R.id.summary1);
- summary2View = (TextView) itemView.findViewById(R.id.summary2);
- }
- }
-
- /**
- * Data for a single support item.
- */
- @VisibleForTesting
- static class SupportData {
-
- final Intent intent;
- final int metricsEvent;
- @LayoutRes
- final int type;
- @DrawableRes
- final int icon;
- @StringRes
- final int tileTitle;
- final CharSequence tileTitleDescription;
- final CharSequence tileSummary;
-
-
- private SupportData(Builder builder) {
- this.type = builder.mType;
- this.icon = builder.mIcon;
- this.tileTitle = builder.mTileTitle;
- this.tileTitleDescription = builder.mTileTitleDescription;
- this.tileSummary = builder.mTileSummary;
- this.intent = builder.mIntent;
- this.metricsEvent = builder.mMetricsEvent;
- }
-
- static class Builder {
-
- protected final Context mContext;
- @LayoutRes
- private final int mType;
- @DrawableRes
- private int mIcon;
- @StringRes
- private int mTileTitle;
- private CharSequence mTileTitleDescription;
- private CharSequence mTileSummary;
- private Intent mIntent;
- private int mMetricsEvent = -1;
-
- Builder(Context context, @LayoutRes int type) {
- mContext = context;
- mType = type;
- }
-
- Builder setIcon(@DrawableRes int icon) {
- mIcon = icon;
- return this;
- }
-
- Builder setTileTitle(@StringRes int title) {
- mTileTitle = title;
- return this;
- }
-
- Builder setTileTitleDescription(@StringRes int titleDescription) {
- mTileTitleDescription = mContext.getString(titleDescription);
- return this;
- }
-
- Builder setTileSummary(@StringRes int summary) {
- mTileSummary = mContext.getString(summary);
- return this;
- }
-
- Builder setTileSummary(CharSequence summary) {
- mTileSummary = summary;
- return this;
- }
-
- Builder setMetricsEvent(int metricsEvent) {
- mMetricsEvent = metricsEvent;
- return this;
- }
-
- Builder setIntent(Intent intent) {
- mIntent = intent;
- return this;
- }
-
- SupportData build() {
- return new SupportData(this);
- }
- }
- }
-
- /**
- * Data model for escalation cards.
- */
- @VisibleForTesting
- static class EscalationData extends SupportData {
-
- @StringRes
- final int text1;
- final CharSequence text2;
- final boolean enabled1;
- final boolean enabled2;
- final CharSequence summary1;
- final CharSequence summary2;
-
- private EscalationData(Builder builder) {
- super(builder);
- this.text1 = builder.mText1;
- this.text2 = builder.mText2;
- this.summary1 = builder.mSummary1;
- this.summary2 = builder.mSummary2;
- this.enabled1 = builder.mEnabled1;
- this.enabled2 = builder.mEnabled2;
- }
-
- static class Builder extends SupportData.Builder {
-
- @StringRes
- private int mText1;
- private CharSequence mText2;
- private CharSequence mSummary1;
- private CharSequence mSummary2;
- private boolean mEnabled1;
- private boolean mEnabled2;
-
- protected Builder(Context context, @LayoutRes int type) {
- super(context, type);
- }
-
- Builder(Context context) {
- this(context, TYPE_ESCALATION_OPTIONS);
- }
-
- Builder setEnabled1(boolean enabled) {
- mEnabled1 = enabled;
- return this;
- }
-
- Builder setText1(@StringRes int text1) {
- mText1 = text1;
- return this;
- }
-
- Builder setText2(@StringRes int text2) {
- mText2 = mContext.getString(text2);
- return this;
- }
-
- Builder setText2(CharSequence text2) {
- mText2 = text2;
- return this;
- }
-
- Builder setSummary1(String summary1) {
- mSummary1 = summary1;
- return this;
- }
-
- Builder setEnabled2(boolean enabled) {
- mEnabled2 = enabled;
- return this;
- }
-
- Builder setSummary2(String summary2) {
- mSummary2 = summary2;
- return this;
- }
-
- EscalationData build() {
- return new EscalationData(this);
- }
- }
- }
-
- /**
- * Support data for offline mode.
- */
- private static final class OfflineEscalationData extends EscalationData {
-
- final List<String> countries;
- final SupportPhone tollFreePhone;
- final SupportPhone tolledPhone;
-
- private OfflineEscalationData(Builder builder) {
- super(builder);
- countries = builder.mCountries;
- tollFreePhone = builder.mTollFreePhone;
- tolledPhone = builder.mTolledPhone;
- }
-
- static final class Builder extends EscalationData.Builder {
-
- private List<String> mCountries;
- private SupportPhone mTollFreePhone;
- private SupportPhone mTolledPhone;
-
- Builder(Context context) {
- super(context, TYPE_ESCALATION_OPTIONS_OFFLINE);
- }
-
- Builder setCountries(List<String> countries) {
- mCountries = countries;
- return this;
- }
-
- Builder setTollFreePhone(SupportPhone phone) {
- mTollFreePhone = phone;
- return this;
- }
-
- Builder setTolledPhone(SupportPhone phone) {
- mTolledPhone = phone;
- return this;
- }
-
- OfflineEscalationData build() {
- return new OfflineEscalationData(this);
- }
- }
- }
-
- @VisibleForTesting
- List<SupportData> getSupportData() {
- return mSupportData;
- }
-}
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/datausage/DataUsageMeteredSettings.java b/src/com/android/settings/datausage/DataUsageMeteredSettings.java
deleted file mode 100644
index 8bc7e04..0000000
--- a/src/com/android/settings/datausage/DataUsageMeteredSettings.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software distributed under the
- * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the specific language governing
- * permissions and limitations under the License.
- */
-
-package com.android.settings.datausage;
-
-import android.app.backup.BackupManager;
-import android.content.Context;
-import android.net.NetworkPolicyManager;
-import android.net.wifi.WifiConfiguration;
-import android.net.wifi.WifiManager;
-import android.os.Bundle;
-import android.provider.SearchIndexableResource;
-import android.support.v7.preference.DropDownPreference;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.PreferenceCategory;
-import android.text.TextUtils;
-
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.Indexable;
-import com.android.settingslib.NetworkPolicyEditor;
-
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * Panel to configure {@link WifiConfiguration#meteredOverride}.
- */
-public class DataUsageMeteredSettings extends SettingsPreferenceFragment implements Indexable {
-
- private NetworkPolicyManager mPolicyManager;
- private WifiManager mWifiManager;
-
- private NetworkPolicyEditor mPolicyEditor;
-
- private PreferenceCategory mMobileCategory;
- private PreferenceCategory mWifiCategory;
- private Preference mWifiDisabled;
-
- @Override
- public int getMetricsCategory() {
- return MetricsEvent.NET_DATA_USAGE_METERED;
- }
-
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- final Context context = getActivity();
-
- mPolicyManager = NetworkPolicyManager.from(context);
- mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
-
- mPolicyEditor = new NetworkPolicyEditor(mPolicyManager);
- mPolicyEditor.read();
-
- addPreferencesFromResource(R.xml.data_usage_metered_prefs);
- mMobileCategory = (PreferenceCategory) findPreference("mobile");
- mWifiCategory = (PreferenceCategory) findPreference("wifi");
- mWifiDisabled = findPreference("wifi_disabled");
-
- updateNetworks(context);
- }
-
- private void updateNetworks(Context context) {
- getPreferenceScreen().removePreference(mMobileCategory);
-
- mWifiCategory.removeAll();
- if (DataUsageUtils.hasWifiRadio(context) && mWifiManager.isWifiEnabled()) {
- for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
- final Preference pref = new MeteredPreference(getPrefContext(), config);
- if (!TextUtils.isEmpty(pref.getTitle())) {
- mWifiCategory.addPreference(pref);
- }
- }
- } else {
- mWifiCategory.addPreference(mWifiDisabled);
- }
- }
-
- private class MeteredPreference extends DropDownPreference {
- private final WifiConfiguration mConfig;
-
- public MeteredPreference(Context context, WifiConfiguration config) {
- super(context);
- mConfig = config;
-
- setPersistent(false);
- setEntries(new CharSequence[] {
- getString(R.string.data_usage_metered_auto),
- getString(R.string.data_usage_metered_yes),
- getString(R.string.data_usage_metered_no),
- });
- setEntryValues(new CharSequence[] {
- Integer.toString(WifiConfiguration.METERED_OVERRIDE_NONE),
- Integer.toString(WifiConfiguration.METERED_OVERRIDE_METERED),
- Integer.toString(WifiConfiguration.METERED_OVERRIDE_NOT_METERED),
- });
- setValue(Integer.toString(mConfig.meteredOverride));
- setTitle(NetworkPolicyManager.resolveNetworkId(mConfig));
- setSummary(getEntries()[mConfig.meteredOverride]);
-
- setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- mConfig.meteredOverride = Integer.parseInt((String) newValue);
- setSummary(getEntries()[mConfig.meteredOverride]);
-
- mWifiManager.updateNetwork(mConfig);
- // Stage the backup of the SettingsProvider package which backs this up
- BackupManager.dataChanged("com.android.providers.settings");
- return true;
- }
- });
- }
- }
-
- /**
- * For search
- */
- public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider() {
- @Override
- public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
- boolean enabled) {
- final SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.data_usage_metered_prefs;
- return Arrays.asList(sir);
- }
-
- @Override
- public List<String> getNonIndexableKeys(Context context) {
- final List<String> result = super.getNonIndexableKeys(context);
- result.add("mobile");
- return result;
- }
- };
-}
diff --git a/src/com/android/settings/datausage/DataUsageSummary.java b/src/com/android/settings/datausage/DataUsageSummary.java
index fe22022..b4d5f50 100644
--- a/src/com/android/settings/datausage/DataUsageSummary.java
+++ b/src/com/android/settings/datausage/DataUsageSummary.java
@@ -77,8 +77,6 @@
// Wifi keys
public static final String KEY_WIFI_USAGE_TITLE = "wifi_category";
public static final String KEY_WIFI_DATA_USAGE = "wifi_data_usage";
- public static final String KEY_NETWORK_RESTRICTIONS = "network_restrictions";
-
private DataUsageController mDataUsageController;
private DataUsageInfoController mDataInfoController;
@@ -86,8 +84,6 @@
private Preference mLimitPreference;
private NetworkTemplate mDefaultTemplate;
private int mDataUsageTemplate;
- private NetworkRestrictionsPreference mNetworkRestrictionPreference;
- private WifiManager mWifiManager;
private NetworkPolicyEditor mPolicyEditor;
@Override
@@ -101,7 +97,6 @@
final Context context = getContext();
NetworkPolicyManager policyManager = NetworkPolicyManager.from(context);
- mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
boolean hasMobileData = DataUsageUtils.hasMobileData(context);
@@ -203,8 +198,6 @@
TemplatePreferenceCategory category = (TemplatePreferenceCategory)
inflatePreferences(R.xml.data_usage_wifi);
category.setTemplate(NetworkTemplate.buildTemplateWifiWildcard(), 0, services);
- mNetworkRestrictionPreference =
- (NetworkRestrictionsPreference) category.findPreference(KEY_NETWORK_RESTRICTIONS);
}
private void addEthernetSection() {
@@ -293,8 +286,6 @@
mLimitPreference.setSummary(null);
}
- updateNetworkRestrictionSummary(mNetworkRestrictionPreference);
-
PreferenceScreen screen = getPreferenceScreen();
for (int i = 1; i < screen.getPreferenceCount(); i++) {
((TemplatePreferenceCategory) screen.getPreference(i)).pushTemplates(services);
@@ -321,22 +312,6 @@
updateState();
}
- @VisibleForTesting
- void updateNetworkRestrictionSummary(NetworkRestrictionsPreference preference) {
- if (preference == null) {
- return;
- }
- mPolicyEditor.read();
- int count = 0;
- for (WifiConfiguration config : mWifiManager.getConfiguredNetworks()) {
- if (WifiConfiguration.isMetered(config, null)) {
- count++;
- }
- }
- preference.setSummary(getResources().getQuantityString(
- R.plurals.network_restrictions_summary, count, count));
- }
-
private static class SummaryProvider
implements SummaryLoader.SummaryProvider {
@@ -409,7 +384,6 @@
if (!DataUsageUtils.hasWifiRadio(context)) {
keys.add(KEY_WIFI_DATA_USAGE);
- keys.add(KEY_NETWORK_RESTRICTIONS);
}
// This title is named Wifi, and will confuse users.
diff --git a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java
index 4d571ec..5512685 100644
--- a/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java
+++ b/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceController.java
@@ -67,6 +67,7 @@
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
SystemProperties.set(BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY, newValue.toString());
+ updateState(preference);
return true;
}
@@ -88,13 +89,13 @@
@Override
protected void onDeveloperOptionsSwitchEnabled() {
mPreference.setEnabled(true);
- mPreference.setValue(mListValues[0]);
- mPreference.setSummary(mListSummaries[0]);
+ 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/CameraLaserSensorPreferenceController.java b/src/com/android/settings/development/CameraLaserSensorPreferenceController.java
index 41a7983..3f09513 100644
--- a/src/com/android/settings/development/CameraLaserSensorPreferenceController.java
+++ b/src/com/android/settings/development/CameraLaserSensorPreferenceController.java
@@ -57,10 +57,7 @@
@Override
public boolean isAvailable() {
- final String buildType = SystemProperties.get(BUILD_TYPE);
- return mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor) &&
- (TextUtils.equals(USERDEBUG_BUILD, buildType) || TextUtils.equals(ENG_BUILD,
- buildType));
+ return mContext.getResources().getBoolean(R.bool.config_show_camera_laser_sensor);
}
@Override
diff --git a/src/com/android/settings/security/FingerprintProfileStatusPreferenceController.java b/src/com/android/settings/fingerprint/FingerprintProfileStatusPreferenceController.java
similarity index 96%
rename from src/com/android/settings/security/FingerprintProfileStatusPreferenceController.java
rename to src/com/android/settings/fingerprint/FingerprintProfileStatusPreferenceController.java
index 1c72a46..68d2ade 100644
--- a/src/com/android/settings/security/FingerprintProfileStatusPreferenceController.java
+++ b/src/com/android/settings/fingerprint/FingerprintProfileStatusPreferenceController.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.security;
+package com.android.settings.fingerprint;
import android.content.Context;
import android.os.UserHandle;
diff --git a/src/com/android/settings/fingerprint/FingerprintSettings.java b/src/com/android/settings/fingerprint/FingerprintSettings.java
index 5d178d2..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,6 @@
}
}
- 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.
*/
diff --git a/src/com/android/settings/security/FingerprintStatusPreferenceController.java b/src/com/android/settings/fingerprint/FingerprintStatusPreferenceController.java
similarity index 95%
rename from src/com/android/settings/security/FingerprintStatusPreferenceController.java
rename to src/com/android/settings/fingerprint/FingerprintStatusPreferenceController.java
index 2985f40..19eb4bb 100644
--- a/src/com/android/settings/security/FingerprintStatusPreferenceController.java
+++ b/src/com/android/settings/fingerprint/FingerprintStatusPreferenceController.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.security;
+package com.android.settings.fingerprint;
import android.content.Context;
import android.content.Intent;
@@ -28,8 +28,6 @@
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
-import com.android.settings.fingerprint.FingerprintEnrollIntroduction;
-import com.android.settings.fingerprint.FingerprintSettings;
import com.android.settings.overlay.FeatureFactory;
import java.util.List;
diff --git a/src/com/android/settings/fuelgauge/BatteryInfo.java b/src/com/android/settings/fuelgauge/BatteryInfo.java
index 7a0cd27..acd8144 100644
--- a/src/com/android/settings/fuelgauge/BatteryInfo.java
+++ b/src/com/android/settings/fuelgauge/BatteryInfo.java
@@ -170,11 +170,12 @@
if (discharging && provider != null
&& provider.isEnhancedBatteryPredictionEnabled(context)) {
- final long prediction = provider.getEnhancedBatteryPrediction(context);
+ Estimate estimate = provider.getEnhancedBatteryPrediction(context);
BatteryUtils.logRuntime(LOG_TAG, "time for enhanced BatteryInfo", startTime);
return BatteryInfo.getBatteryInfo(context, batteryBroadcast, stats,
- elapsedRealtimeUs, shortString, BatteryUtils.convertMsToUs(prediction),
- true);
+ elapsedRealtimeUs, shortString,
+ BatteryUtils.convertMsToUs(estimate.estimateMillis),
+ estimate.isBasedOnUsage);
} else {
long prediction = discharging
? stats.computeBatteryTimeRemaining(elapsedRealtimeUs) : 0;
diff --git a/src/com/android/settings/fuelgauge/BatteryUtils.java b/src/com/android/settings/fuelgauge/BatteryUtils.java
index c623396..0952f1f 100644
--- a/src/com/android/settings/fuelgauge/BatteryUtils.java
+++ b/src/com/android/settings/fuelgauge/BatteryUtils.java
@@ -21,8 +21,6 @@
import android.content.IntentFilter;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
-import android.database.Cursor;
-import android.net.Uri;
import android.os.BatteryManager;
import android.os.BatteryStats;
import android.os.Bundle;
@@ -347,6 +345,17 @@
}
+ /**
+ * Calculate the screen usage time since last full charge.
+ * @param batteryStatsHelper utility class that contains the screen usage data
+ * @return time in millis
+ */
+ public long calculateScreenUsageTime(BatteryStatsHelper batteryStatsHelper) {
+ final BatterySipper sipper = findBatterySipperByType(
+ batteryStatsHelper.getUsageList(), BatterySipper.DrainType.SCREEN);
+ return sipper != null ? sipper.usageTimeMs : 0;
+ }
+
public static void logRuntime(String tag, String message, long startTime) {
Log.d(tag, message + ": " + (System.currentTimeMillis() - startTime) + "ms");
}
@@ -410,19 +419,19 @@
final boolean discharging = batteryBroadcast.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1)
== 0;
// Get enhanced prediction if available and discharging, otherwise use the old code
- Cursor cursor = null;
+ Estimate estimate = null;
if (discharging && mPowerUsageFeatureProvider != null &&
mPowerUsageFeatureProvider.isEnhancedBatteryPredictionEnabled(mContext)) {
- final Uri queryUri = mPowerUsageFeatureProvider.getEnhancedBatteryPredictionUri();
- cursor = mContext.getContentResolver().query(queryUri, null, null, null, null);
+ estimate = mPowerUsageFeatureProvider.getEnhancedBatteryPrediction(mContext);
}
final BatteryStats stats = statsHelper.getStats();
BatteryUtils.logRuntime(tag, "BatteryInfoLoader post query", startTime);
- if (cursor != null && cursor.moveToFirst()) {
- long enhancedEstimate = mPowerUsageFeatureProvider.getTimeRemainingEstimate(cursor);
+
+ if (estimate != null) {
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
elapsedRealtimeUs, false /* shortString */,
- BatteryUtils.convertMsToUs(enhancedEstimate), true /* basedOnUsage */);
+ BatteryUtils.convertMsToUs(estimate.estimateMillis),
+ estimate.isBasedOnUsage);
} else {
batteryInfo = BatteryInfo.getBatteryInfo(mContext, batteryBroadcast, stats,
elapsedRealtimeUs, false /* shortString */,
@@ -434,6 +443,20 @@
return batteryInfo;
}
+ /**
+ * Find the {@link BatterySipper} with the corresponding {@link BatterySipper.DrainType}
+ */
+ public BatterySipper findBatterySipperByType(List<BatterySipper> usageList,
+ BatterySipper.DrainType type) {
+ for (int i = 0, size = usageList.size(); i < size; i++) {
+ final BatterySipper sipper = usageList.get(i);
+ if (sipper.drainType == type) {
+ return sipper;
+ }
+ }
+ return null;
+ }
+
private boolean isDataCorrupted() {
return mPackageManager == null || mAppOpsManager == null;
}
diff --git a/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java b/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java
index 19aa639..a080e2b 100644
--- a/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java
+++ b/src/com/android/settings/fuelgauge/DebugEstimatesLoader.java
@@ -54,14 +54,15 @@
BatteryInfo oldinfo = BatteryInfo.getBatteryInfoOld(getContext(), batteryBroadcast,
stats, elapsedRealtimeUs, false);
- final long timeRemainingEnhanced = BatteryUtils.convertMsToUs(
- powerUsageFeatureProvider.getEnhancedBatteryPrediction(getContext()));
- BatteryInfo newinfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
- elapsedRealtimeUs, false, timeRemainingEnhanced, true);
+ Estimate estimate = powerUsageFeatureProvider.getEnhancedBatteryPrediction(context);
+ BatteryInfo newInfo = BatteryInfo.getBatteryInfo(getContext(), batteryBroadcast, stats,
+ elapsedRealtimeUs, false,
+ BatteryUtils.convertMsToUs(estimate.estimateMillis),
+ estimate.isBasedOnUsage);
List<BatteryInfo> infos = new ArrayList<>();
infos.add(oldinfo);
- infos.add(newinfo);
+ infos.add(newInfo);
return infos;
}
}
diff --git a/src/com/android/settings/fuelgauge/Estimate.java b/src/com/android/settings/fuelgauge/Estimate.java
new file mode 100644
index 0000000..541678c
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/Estimate.java
@@ -0,0 +1,12 @@
+package com.android.settings.fuelgauge;
+
+public class Estimate {
+
+ public final long estimateMillis;
+ public final boolean isBasedOnUsage;
+
+ public Estimate(long estimateMillis, boolean isBasedOnUsage) {
+ this.estimateMillis = estimateMillis;
+ this.isBasedOnUsage = isBasedOnUsage;
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetails.java b/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetails.java
index 0d73511..143733d 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetails.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetails.java
@@ -31,6 +31,7 @@
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
+import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.fuelgauge.anomaly.Anomaly;
import com.android.settings.fuelgauge.anomaly.AnomalyDialogFragment;
@@ -151,12 +152,6 @@
@VisibleForTesting
Drawable getBadgedIcon(String packageName, int userId) {
- try {
- final ApplicationInfo appInfo = mPackageManager.getApplicationInfo(packageName,
- PackageManager.GET_META_DATA);
- return mIconDrawableFactory.getBadgedIcon(appInfo, userId);
- } catch (PackageManager.NameNotFoundException e) {
- return mPackageManager.getDefaultActivityIcon();
- }
+ return Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, packageName, userId);
}
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
index 1fb02c4..67bdada 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProvider.java
@@ -18,8 +18,6 @@
import android.content.Context;
import android.content.Intent;
-import android.database.Cursor;
-import android.net.Uri;
import android.util.SparseIntArray;
import com.android.internal.os.BatterySipper;
@@ -28,6 +26,7 @@
* Feature Provider used in power usage
*/
public interface PowerUsageFeatureProvider {
+
/**
* Check whether location setting is enabled
*/
@@ -66,7 +65,7 @@
/**
* Returns an improved prediction for battery time remaining.
*/
- long getEnhancedBatteryPrediction(Context context);
+ Estimate getEnhancedBatteryPrediction(Context context);
/**
* Returns an improved projection curve for future battery level.
@@ -80,16 +79,6 @@
boolean isEnhancedBatteryPredictionEnabled(Context context);
/**
- * Returns the Uri used to query for an enhanced battery prediction from a cursor loader.
- */
- Uri getEnhancedBatteryPredictionUri();
-
- /**
- * Returns the the estimate in the cursor as a long or -1 if the cursor is null
- */
- long getTimeRemainingEstimate(Cursor cursor);
-
- /**
* Checks whether debugging should be enabled for battery estimates.
* @return
*/
diff --git a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
index cda4d3d..3d99386 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageFeatureProviderImpl.java
@@ -21,7 +21,6 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
-import android.database.Cursor;
import android.net.Uri;
import android.os.Process;
import android.util.FeatureFlagUtils;
@@ -95,8 +94,8 @@
}
@Override
- public long getEnhancedBatteryPrediction(Context context) {
- return -1;
+ public Estimate getEnhancedBatteryPrediction(Context context) {
+ return null;
}
@Override
@@ -110,16 +109,6 @@
}
@Override
- public Uri getEnhancedBatteryPredictionUri() {
- return null;
- }
-
- @Override
- public long getTimeRemainingEstimate(Cursor cursor) {
- return 0;
- }
-
- @Override
public String getEnhancedEstimateDebugString(String timeRemaining) {
return null;
}
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 0315f03..205ac0b 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -266,7 +266,7 @@
KEY_APP_LIST, lifecycle, activity, this);
controllers.add(mBatteryAppListPreferenceController);
mBatteryTipPreferenceController = new BatteryTipPreferenceController(context,
- KEY_BATTERY_TIP, this);
+ KEY_BATTERY_TIP, this, this);
controllers.add(mBatteryTipPreferenceController);
controllers.add(new BatterySaverController(context, getLifecycle()));
controllers.add(new BatteryPercentagePreferenceController(context));
@@ -369,8 +369,9 @@
restartBatteryInfoLoader();
final long lastFullChargeTime = mBatteryUtils.calculateLastFullChargeTime(mStatsHelper,
System.currentTimeMillis());
- updateScreenPreference();
updateLastFullChargePreference(lastFullChargeTime);
+ mScreenUsagePref.setSubtitle(Utils.formatElapsedTime(getContext(),
+ mBatteryUtils.calculateScreenUsageTime(mStatsHelper), false));
final CharSequence timeSequence = Utils.formatRelativeTime(context, lastFullChargeTime,
false);
@@ -394,26 +395,6 @@
}
@VisibleForTesting
- BatterySipper findBatterySipperByType(List<BatterySipper> usageList, DrainType type) {
- for (int i = 0, size = usageList.size(); i < size; i++) {
- final BatterySipper sipper = usageList.get(i);
- if (sipper.drainType == type) {
- return sipper;
- }
- }
- return null;
- }
-
- @VisibleForTesting
- void updateScreenPreference() {
- final BatterySipper sipper = findBatterySipperByType(
- mStatsHelper.getUsageList(), DrainType.SCREEN);
- final long usageTimeMs = sipper != null ? sipper.usageTimeMs : 0;
-
- mScreenUsagePref.setSubtitle(Utils.formatElapsedTime(getContext(), usageTimeMs, false));
- }
-
- @VisibleForTesting
void updateLastFullChargePreference(long timeMs) {
final CharSequence timeSequence = Utils.formatRelativeTime(getContext(), timeMs, false);
mLastFullChargePref.setSubtitle(timeSequence);
diff --git a/src/com/android/settings/fuelgauge/RestrictAppPreferenceController.java b/src/com/android/settings/fuelgauge/RestrictAppPreferenceController.java
new file mode 100644
index 0000000..7df0fb1
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/RestrictAppPreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * 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.fuelgauge;
+
+import android.app.AppOpsManager;
+import android.content.Context;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.R;
+import com.android.settings.applications.LayoutPreference;
+import com.android.settings.core.BasePreferenceController;
+
+import java.util.List;
+
+/**
+ * Controller to change and update the smart battery toggle
+ */
+public class RestrictAppPreferenceController extends BasePreferenceController {
+ @VisibleForTesting
+ static final String KEY_RESTRICT_APP = "restricted_app";
+
+ private AppOpsManager mAppOpsManager;
+ private List<AppOpsManager.PackageOps> mPackageOps;
+
+ public RestrictAppPreferenceController(Context context) {
+ super(context, KEY_RESTRICT_APP);
+ mAppOpsManager = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ mPackageOps = mAppOpsManager.getPackagesForOps(
+ new int[]{AppOpsManager.OP_RUN_ANY_IN_BACKGROUND});
+ final int num = mPackageOps != null ? mPackageOps.size() : 0;
+
+ preference.setSummary(
+ mContext.getResources().getQuantityString(R.plurals.restricted_app_summary, num,
+ num));
+ }
+
+}
diff --git a/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java b/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java
new file mode 100644
index 0000000..ee5279e
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/SmartBatteryPreferenceController.java
@@ -0,0 +1,63 @@
+/*
+ * 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.fuelgauge;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.support.annotation.VisibleForTesting;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.applications.LayoutPreference;
+import com.android.settings.core.BasePreferenceController;
+
+/**
+ * Controller to change and update the smart battery toggle
+ */
+public class SmartBatteryPreferenceController extends BasePreferenceController implements
+ Preference.OnPreferenceChangeListener {
+ private static final String KEY_SMART_BATTERY = "smart_battery";
+ private static final int ON = 1;
+ private static final int OFF = 0;
+
+ public SmartBatteryPreferenceController(Context context) {
+ super(context, KEY_SMART_BATTERY);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ // TODO(b/71502850): get Availability from API. The device may not support it.
+ return AVAILABLE;
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+ final boolean smartBatteryOn = Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.APP_STANDBY_ENABLED, ON) == ON;
+ ((SwitchPreference) preference).setChecked(smartBatteryOn);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ final boolean smartBatteryOn = (Boolean) newValue;
+ Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.APP_STANDBY_ENABLED,
+ smartBatteryOn ? ON : OFF);
+ return true;
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/SmartBatterySettings.java b/src/com/android/settings/fuelgauge/SmartBatterySettings.java
new file mode 100644
index 0000000..5faaef4
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/SmartBatterySettings.java
@@ -0,0 +1,98 @@
+/*
+ * 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.fuelgauge;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.provider.SearchIndexableResource;
+
+import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
+import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.search.BaseSearchIndexProvider;
+import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settingslib.widget.FooterPreferenceMixin;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Fragment to show smart battery and restricted app controls
+ */
+public class SmartBatterySettings extends DashboardFragment {
+ public static final String TAG = "SmartBatterySettings";
+
+ private final FooterPreferenceMixin mFooterPreferenceMixin =
+ new FooterPreferenceMixin(this, getLifecycle());
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.battery_footer_summary);
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ return MetricsProto.MetricsEvent.FUELGAUGE_SMART_BATTERY;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.smart_battery_detail;
+ }
+
+ @Override
+ protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ return buildPreferenceControllers(context);
+ }
+
+ private static List<AbstractPreferenceController> buildPreferenceControllers(
+ Context context) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
+ controllers.add(new SmartBatteryPreferenceController(context));
+ controllers.add(new RestrictAppPreferenceController(context));
+ return controllers;
+ }
+
+ public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
+ new BaseSearchIndexProvider() {
+ @Override
+ public List<SearchIndexableResource> getXmlResourcesToIndex(
+ Context context, boolean enabled) {
+ final SearchIndexableResource sir = new SearchIndexableResource(context);
+ sir.xmlResId = R.xml.smart_battery_detail;
+ return Arrays.asList(sir);
+ }
+
+ @Override
+ public List<String> getNonIndexableKeys(Context context) {
+ return super.getNonIndexableKeys(context);
+ }
+
+ @Override
+ public List<AbstractPreferenceController> getPreferenceControllers(
+ Context context) {
+ return buildPreferenceControllers(context);
+ }
+ };
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
new file mode 100644
index 0000000..3e091b3
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipDialogFragment.java
@@ -0,0 +1,104 @@
+/*
+ * 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.fuelgauge.batterytip;
+
+import android.app.AlertDialog;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Bundle;
+import android.support.annotation.VisibleForTesting;
+import android.support.v7.widget.LinearLayoutManager;
+import android.support.v7.widget.RecyclerView;
+import android.view.LayoutInflater;
+
+import com.android.settings.R;
+import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
+import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController.BatteryTipListener;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
+
+/**
+ * Dialog Fragment to show action dialog for each anomaly
+ */
+public class BatteryTipDialogFragment extends InstrumentedDialogFragment implements
+ DialogInterface.OnClickListener {
+
+ private static final String ARG_BATTERY_TIP = "battery_tip";
+
+ @VisibleForTesting
+ BatteryTip mBatteryTip;
+
+ public static BatteryTipDialogFragment newInstance(BatteryTip batteryTip) {
+ BatteryTipDialogFragment dialogFragment = new BatteryTipDialogFragment();
+
+ Bundle args = new Bundle(1);
+ args.putParcelable(ARG_BATTERY_TIP, batteryTip);
+ dialogFragment.setArguments(args);
+
+ return dialogFragment;
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ final Bundle bundle = getArguments();
+ final Context context = getContext();
+
+ mBatteryTip = bundle.getParcelable(ARG_BATTERY_TIP);
+
+ switch (mBatteryTip.getType()) {
+ case BatteryTip.TipType.SUMMARY:
+ case BatteryTip.TipType.LOW_BATTERY:
+ //TODO(b/70570352): add dialog
+ return null;
+ case BatteryTip.TipType.HIGH_DEVICE_USAGE:
+ final HighUsageTip highUsageTip = (HighUsageTip) mBatteryTip;
+ final RecyclerView view = (RecyclerView) LayoutInflater.from(context).inflate(
+ R.layout.recycler_view,
+ null);
+ view.setLayoutManager(new LinearLayoutManager(context));
+ view.setAdapter(new HighUsageAdapter(context,
+ highUsageTip.getHighUsageAppList()));
+
+ return new AlertDialog.Builder(context)
+ .setMessage(getString(R.string.battery_tip_dialog_message,
+ highUsageTip.getScreenTimeMs()))
+ .setView(view)
+ .setPositiveButton(android.R.string.ok, null)
+ .create();
+ default:
+ throw new IllegalArgumentException("unknown type " + mBatteryTip.getType());
+ }
+ }
+
+ @Override
+ public int getMetricsCategory() {
+ //TODO(b/70570352): add correct metric id
+ return 0;
+ }
+
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ final BatteryTipListener lsn = (BatteryTipListener) getTargetFragment();
+ if (lsn == null) {
+ return;
+ }
+ mBatteryTip.action();
+ lsn.onBatteryTipHandled(mBatteryTip);
+ }
+
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
index 9c3f48c..a1db57a 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipLoader.java
@@ -23,6 +23,7 @@
import com.android.settings.fuelgauge.BatteryInfo;
import com.android.settings.fuelgauge.BatteryUtils;
import com.android.settings.fuelgauge.batterytip.detectors.BatteryTipDetector;
+import com.android.settings.fuelgauge.batterytip.detectors.HighUsageDetector;
import com.android.settings.fuelgauge.batterytip.detectors.LowBatteryDetector;
import com.android.settings.fuelgauge.batterytip.detectors.SummaryDetector;
import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
@@ -65,6 +66,8 @@
mVisibleTips = 0;
addBatteryTipFromDetector(tips, new LowBatteryDetector(policy, batteryInfo));
+ addBatteryTipFromDetector(tips,
+ new HighUsageDetector(getContext(), policy, mBatteryStatsHelper));
// Add summary detector at last since it need other detectors to update the mVisibleTips
addBatteryTipFromDetector(tips, new SummaryDetector(policy, mVisibleTips));
diff --git a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
index f611405..9aa70c5 100644
--- a/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceController.java
@@ -18,6 +18,7 @@
import android.content.Context;
import android.support.annotation.VisibleForTesting;
+import android.support.v14.preference.PreferenceFragment;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceGroup;
import android.support.v7.preference.PreferenceScreen;
@@ -34,6 +35,9 @@
* Controller in charge of the battery tip group
*/
public class BatteryTipPreferenceController extends BasePreferenceController {
+ private static final String TAG = "BatteryTipPreferenceController";
+ private static final int REQUEST_ANOMALY_ACTION = 0;
+
private BatteryTipListener mBatteryTipListener;
private List<BatteryTip> mBatteryTips;
private Map<String, BatteryTip> mBatteryTipMap;
@@ -41,16 +45,18 @@
PreferenceGroup mPreferenceGroup;
@VisibleForTesting
Context mPrefContext;
+ PreferenceFragment mFragment;
public BatteryTipPreferenceController(Context context, String preferenceKey) {
- this(context, preferenceKey, null);
+ this(context, preferenceKey, null, null);
}
public BatteryTipPreferenceController(Context context, String preferenceKey,
- BatteryTipListener batteryTipListener) {
+ PreferenceFragment fragment, BatteryTipListener batteryTipListener) {
super(context, preferenceKey);
mBatteryTipListener = batteryTipListener;
mBatteryTipMap = new HashMap<>();
+ mFragment = fragment;
}
@Override
@@ -96,7 +102,10 @@
final BatteryTip batteryTip = mBatteryTipMap.get(preference.getKey());
if (batteryTip != null) {
if (batteryTip.shouldShowDialog()) {
- // build and show the dialog
+ BatteryTipDialogFragment dialogFragment = BatteryTipDialogFragment.newInstance(
+ batteryTip);
+ dialogFragment.setTargetFragment(mFragment, REQUEST_ANOMALY_ACTION);
+ dialogFragment.show(mFragment.getFragmentManager(), TAG);
} else {
batteryTip.action();
if (mBatteryTipListener != null) {
diff --git a/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java b/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java
new file mode 100644
index 0000000..8b74394
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/HighUsageAdapter.java
@@ -0,0 +1,87 @@
+/*
+ * 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.fuelgauge.batterytip;
+
+import android.content.Context;
+import android.content.pm.PackageManager;
+import android.os.UserHandle;
+import android.support.v7.widget.RecyclerView;
+import android.util.IconDrawableFactory;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import com.android.settings.R;
+import com.android.settings.Utils;
+
+import java.util.List;
+
+/**
+ * Adapter for the high usage app list
+ */
+public class HighUsageAdapter extends RecyclerView.Adapter<HighUsageAdapter.ViewHolder> {
+ private final Context mContext;
+ private final IconDrawableFactory mIconDrawableFactory;
+ private final PackageManager mPackageManager;
+ private final List<HighUsageApp> mHighUsageAppList;
+
+ public static class ViewHolder extends RecyclerView.ViewHolder {
+ public View view;
+ public ImageView appIcon;
+ public TextView appName;
+ public TextView appTime;
+
+ public ViewHolder(View v) {
+ super(v);
+ view = v;
+ appIcon = v.findViewById(R.id.app_icon);
+ appName = v.findViewById(R.id.app_name);
+ appTime = v.findViewById(R.id.app_screen_time);
+ }
+ }
+
+ public HighUsageAdapter(Context context, List<HighUsageApp> highUsageAppList) {
+ mContext = context;
+ mHighUsageAppList = highUsageAppList;
+ mIconDrawableFactory = IconDrawableFactory.newInstance(context);
+ mPackageManager = context.getPackageManager();
+ }
+
+ @Override
+ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
+ final View view = LayoutInflater.from(mContext).inflate(R.layout.app_high_usage_item,
+ parent, false);
+ return new ViewHolder(view);
+ }
+
+ @Override
+ public void onBindViewHolder(ViewHolder holder, int position) {
+ final HighUsageApp app = mHighUsageAppList.get(position);
+ holder.appIcon.setImageDrawable(
+ Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, app.packageName,
+ UserHandle.myUserId()));
+ holder.appName.setText(Utils.getApplicationLabel(mContext, app.packageName));
+ holder.appTime.setText(Utils.formatElapsedTime(mContext, app.screenOnTimeMs, false));
+ }
+
+ @Override
+ public int getItemCount() {
+ return mHighUsageAppList.size();
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/fuelgauge/batterytip/HighUsageApp.java b/src/com/android/settings/fuelgauge/batterytip/HighUsageApp.java
new file mode 100644
index 0000000..f75ecf0
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/HighUsageApp.java
@@ -0,0 +1,64 @@
+/*
+ * 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.fuelgauge.batterytip;
+
+import android.os.Parcel;
+import android.os.Parcelable;
+
+/**
+ * Class representing app with high screen usage
+ */
+public class HighUsageApp implements Comparable<HighUsageApp>, Parcelable {
+ public final String packageName;
+ public final long screenOnTimeMs;
+
+ public HighUsageApp(String packageName, long screenOnTimeMs) {
+ this.packageName = packageName;
+ this.screenOnTimeMs = screenOnTimeMs;
+ }
+
+ private HighUsageApp(Parcel in) {
+ packageName = in.readString();
+ screenOnTimeMs = in.readLong();
+ }
+
+ @Override
+ public int compareTo(HighUsageApp o) {
+ return Long.compare(screenOnTimeMs, o.screenOnTimeMs);
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeString(packageName);
+ dest.writeLong(screenOnTimeMs);
+ }
+
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public HighUsageApp createFromParcel(Parcel in) {
+ return new HighUsageApp(in);
+ }
+
+ public HighUsageApp[] newArray(int size) {
+ return new HighUsageApp[size];
+ }
+ };
+}
\ No newline at end of file
diff --git a/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
new file mode 100644
index 0000000..237f430
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetector.java
@@ -0,0 +1,84 @@
+/*
+ * 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.fuelgauge.batterytip.detectors;
+
+import android.content.Context;
+import android.os.BatteryStats;
+import android.support.annotation.VisibleForTesting;
+import android.text.format.DateUtils;
+
+import com.android.internal.os.BatterySipper;
+import com.android.internal.os.BatteryStatsHelper;
+import com.android.settings.Utils;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
+import com.android.settings.fuelgauge.batterytip.HighUsageApp;
+import com.android.settings.fuelgauge.batterytip.tips.BatteryTip;
+import com.android.settings.fuelgauge.batterytip.tips.HighUsageTip;
+import com.android.settings.fuelgauge.batterytip.tips.SummaryTip;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Detector whether to show summary tip. This detector should be executed as the last
+ * {@link BatteryTipDetector} since it need the most up-to-date {@code visibleTips}
+ */
+public class HighUsageDetector implements BatteryTipDetector {
+ private BatteryTipPolicy mPolicy;
+ private BatteryStatsHelper mBatteryStatsHelper;
+ private List<HighUsageApp> mHighUsageAppList;
+ private Context mContext;
+ @VisibleForTesting
+ BatteryUtils mBatteryUtils;
+
+ public HighUsageDetector(Context context, BatteryTipPolicy policy,
+ BatteryStatsHelper batteryStatsHelper) {
+ mContext = context;
+ mPolicy = policy;
+ mBatteryStatsHelper = batteryStatsHelper;
+ mHighUsageAppList = new ArrayList<>();
+ mBatteryUtils = BatteryUtils.getInstance(context);
+ }
+
+ @Override
+ public BatteryTip detect() {
+ final long screenUsageTimeMs = mBatteryUtils.calculateScreenUsageTime(mBatteryStatsHelper);
+ //TODO(b/70570352): Change it to detect whether battery drops 25% in last 2 hours
+ if (mPolicy.highUsageEnabled && screenUsageTimeMs > DateUtils.HOUR_IN_MILLIS) {
+ final List<BatterySipper> batterySippers = mBatteryStatsHelper.getUsageList();
+ for (int i = 0, size = batterySippers.size(); i < size; i++) {
+ final BatterySipper batterySipper = batterySippers.get(i);
+ if (!mBatteryUtils.shouldHideSipper(batterySipper)) {
+ final long foregroundTimeMs = mBatteryUtils.getProcessTimeMs(
+ BatteryUtils.StatusType.FOREGROUND, batterySipper.uidObj,
+ BatteryStats.STATS_SINCE_CHARGED);
+ mHighUsageAppList.add(new HighUsageApp(
+ mBatteryUtils.getPackageName(batterySipper.getUid()),
+ foregroundTimeMs));
+ }
+ }
+
+ mHighUsageAppList = mHighUsageAppList.subList(0,
+ Math.min(mPolicy.highUsageAppCount, mHighUsageAppList.size()));
+ Collections.sort(mHighUsageAppList, Collections.reverseOrder());
+ }
+
+ return new HighUsageTip(screenUsageTimeMs, mHighUsageAppList);
+ }
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
index 17e395e..eadd0e1 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTip.java
@@ -16,8 +16,9 @@
package com.android.settings.fuelgauge.batterytip.tips;
-import android.app.Dialog;
import android.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.support.annotation.IdRes;
import android.support.annotation.IntDef;
import android.support.v7.preference.Preference;
@@ -31,7 +32,7 @@
* Each {@link BatteryTip} contains basic data(e.g. title, summary, icon) as well as the
* pre-defined action(e.g. turn on battery saver)
*/
-public abstract class BatteryTip implements Comparable<BatteryTip> {
+public abstract class BatteryTip implements Comparable<BatteryTip>, Parcelable {
@Retention(RetentionPolicy.SOURCE)
@IntDef({StateType.NEW,
StateType.HANDLED,
@@ -62,12 +63,34 @@
private static final String KEY_PREFIX = "key_battery_tip";
- @TipType
protected int mType;
- @StateType
protected int mState;
protected boolean mShowDialog;
+ BatteryTip(Parcel in) {
+ mType = in.readInt();
+ mState = in.readInt();
+ mShowDialog = in.readBoolean();
+ }
+
+ BatteryTip(int type, int state, boolean showDialog) {
+ mType = type;
+ mState = state;
+ mShowDialog = showDialog;
+ }
+
+ @Override
+ public int describeContents() {
+ return 0;
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ dest.writeInt(mType);
+ dest.writeInt(mState);
+ dest.writeBoolean(mShowDialog);
+ }
+
public abstract CharSequence getTitle(Context context);
public abstract CharSequence getSummary(Context context);
@@ -77,6 +100,7 @@
/**
* Update the current {@link #mState} using the new {@code tip}.
+ *
* @param tip used to update
*/
public abstract void updateState(BatteryTip tip);
@@ -86,12 +110,6 @@
*/
public abstract void action();
- /**
- * Build the dialog to display either the info about {@link BatteryTip} or confirmation
- * about the action.
- */
- public abstract Dialog buildDialog();
-
public Preference buildPreference(Context context) {
Preference preference = new Preference(context);
@@ -110,6 +128,10 @@
return KEY_PREFIX + mType;
}
+ public int getType() {
+ return mType;
+ }
+
@StateType
public int getState() {
return mState;
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
new file mode 100644
index 0000000..001a48e
--- /dev/null
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTip.java
@@ -0,0 +1,104 @@
+/*
+ * 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.fuelgauge.batterytip.tips;
+
+import android.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.support.annotation.VisibleForTesting;
+
+import com.android.settings.R;
+import com.android.settings.Utils;
+import com.android.settings.fuelgauge.batterytip.HighUsageApp;
+
+import java.util.List;
+
+/**
+ * Tip to show general summary about battery life
+ */
+public class HighUsageTip extends BatteryTip {
+
+ private final long mScreenTimeMs;
+ @VisibleForTesting
+ final List<HighUsageApp> mHighUsageAppList;
+
+ public HighUsageTip(long screenTimeMs, List<HighUsageApp> appList) {
+ super(TipType.HIGH_DEVICE_USAGE, appList.isEmpty() ? StateType.INVISIBLE : StateType.NEW,
+ true /* showDialog */);
+ mScreenTimeMs = screenTimeMs;
+ mHighUsageAppList = appList;
+ }
+
+ @VisibleForTesting
+ HighUsageTip(Parcel in) {
+ super(in);
+ mScreenTimeMs = in.readLong();
+ mHighUsageAppList = in.createTypedArrayList(HighUsageApp.CREATOR);
+ }
+
+ @Override
+ public void writeToParcel(Parcel dest, int flags) {
+ super.writeToParcel(dest, flags);
+ dest.writeLong(mScreenTimeMs);
+ dest.writeTypedList(mHighUsageAppList);
+ }
+
+ @Override
+ public CharSequence getTitle(Context context) {
+ return context.getString(R.string.battery_tip_high_usage_title);
+ }
+
+ @Override
+ public CharSequence getSummary(Context context) {
+ return context.getString(R.string.battery_tip_high_usage_summary,
+ Utils.formatElapsedTime(context, mScreenTimeMs, false));
+ }
+
+ @Override
+ public int getIconId() {
+ return R.drawable.ic_perm_device_information_red_24dp;
+ }
+
+ @Override
+ public void updateState(BatteryTip tip) {
+ mState = tip.mState;
+ }
+
+ @Override
+ public void action() {
+ // do nothing
+ }
+
+ public long getScreenTimeMs() {
+ return mScreenTimeMs;
+ }
+
+ public List<HighUsageApp> getHighUsageAppList() {
+ return mHighUsageAppList;
+ }
+
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new HighUsageTip(in);
+ }
+
+ public BatteryTip[] newArray(int size) {
+ return new HighUsageTip[size];
+ }
+ };
+
+}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
index 8605fbb..4a207e0 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/LowBatteryTip.java
@@ -16,8 +16,9 @@
package com.android.settings.fuelgauge.batterytip.tips;
-import android.app.Dialog;
import android.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
import com.android.settings.R;
@@ -27,9 +28,11 @@
public class LowBatteryTip extends BatteryTip {
public LowBatteryTip(@StateType int state) {
- mShowDialog = false;
- mState = state;
- mType = TipType.LOW_BATTERY;
+ super(TipType.LOW_BATTERY, state, false /* showDialog */);
+ }
+
+ private LowBatteryTip(Parcel in) {
+ super(in);
}
@Override
@@ -57,9 +60,14 @@
// do nothing
}
- @Override
- public Dialog buildDialog() {
- //TODO(b/70570352): create the dialog for low battery tip and add test
- return null;
- }
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new LowBatteryTip(in);
+ }
+
+ public BatteryTip[] newArray(int size) {
+ return new LowBatteryTip[size];
+ }
+ };
+
}
diff --git a/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java b/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java
index 2a2deab..51019a8 100644
--- a/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java
+++ b/src/com/android/settings/fuelgauge/batterytip/tips/SummaryTip.java
@@ -16,8 +16,9 @@
package com.android.settings.fuelgauge.batterytip.tips;
-import android.app.Dialog;
import android.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
import com.android.settings.R;
@@ -27,9 +28,11 @@
public class SummaryTip extends BatteryTip {
public SummaryTip(@StateType int state) {
- mShowDialog = false;
- mState = state;
- mType = TipType.SUMMARY;
+ super(TipType.SUMMARY, state, false /* showDialog */);
+ }
+
+ private SummaryTip(Parcel in) {
+ super(in);
}
@Override
@@ -57,9 +60,13 @@
// do nothing
}
- @Override
- public Dialog buildDialog() {
- //TODO(b/70570352): create the dialog for summary tip and add test
- return null;
- }
+ public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new SummaryTip(in);
+ }
+
+ public BatteryTip[] newArray(int size) {
+ return new SummaryTip[size];
+ }
+ };
}
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/AbstractZenModePreferenceController.java b/src/com/android/settings/notification/AbstractZenModePreferenceController.java
index 33c027c..81ceca1 100644
--- a/src/com/android/settings/notification/AbstractZenModePreferenceController.java
+++ b/src/com/android/settings/notification/AbstractZenModePreferenceController.java
@@ -31,7 +31,6 @@
import android.service.notification.ZenModeConfig;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
-import android.util.Slog;
import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.core.PreferenceControllerMixin;
@@ -54,6 +53,7 @@
final private NotificationManager mNotificationManager;
protected static ZenModeConfigWrapper mZenModeConfigWrapper;
protected MetricsFeatureProvider mMetricsFeatureProvider;
+ protected final ZenModeBackend mBackend;
public AbstractZenModePreferenceController(Context context, String key,
Lifecycle lifecycle) {
@@ -68,6 +68,7 @@
final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
mMetricsFeatureProvider = featureFactory.getMetricsFeatureProvider();
+ mBackend = ZenModeBackend.getInstance(context);
}
@Override
@@ -90,6 +91,14 @@
}
}
+ @Override
+ public void updateState(Preference preference) {
+ super.updateState(preference);
+
+ mBackend.updatePolicy();
+ mBackend.updateZenMode();
+ }
+
protected NotificationManager.Policy getPolicy() {
return mNotificationManager.getNotificationPolicy();
}
@@ -99,8 +108,8 @@
}
protected int getZenMode() {
- return Settings.Global.getInt(mContext.getContentResolver(),
- Settings.Global.ZEN_MODE, 0);
+ return Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.ZEN_MODE,
+ mBackend.mZenMode);
}
class SettingObserver extends ContentObserver {
@@ -188,7 +197,6 @@
}
}
-
return endTimeMs;
}
diff --git a/src/com/android/settings/notification/ZenModeAlarmsPreferenceController.java b/src/com/android/settings/notification/ZenModeAlarmsPreferenceController.java
index a15f7fc..af59107 100644
--- a/src/com/android/settings/notification/ZenModeAlarmsPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeAlarmsPreferenceController.java
@@ -30,11 +30,9 @@
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_alarms";
- private final ZenModeBackend mBackend;
public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
}
@Override
diff --git a/src/com/android/settings/notification/ZenModeBackend.java b/src/com/android/settings/notification/ZenModeBackend.java
index 945da0b..6cee28e 100644
--- a/src/com/android/settings/notification/ZenModeBackend.java
+++ b/src/com/android/settings/notification/ZenModeBackend.java
@@ -82,7 +82,6 @@
mZenMode = zenMode;
}
- /** gets last zen mode set by setZenMode or updateZenMode **/
protected int getZenMode() {
mZenMode = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.ZEN_MODE, mZenMode);
diff --git a/src/com/android/settings/notification/ZenModeBehaviorSettings.java b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
index bfa95a7..e2e85f3 100644
--- a/src/com/android/settings/notification/ZenModeBehaviorSettings.java
+++ b/src/com/android/settings/notification/ZenModeBehaviorSettings.java
@@ -45,7 +45,9 @@
controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
- controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle));
+ controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
+ context.getResources().getInteger(com.android.internal.R.integer
+ .config_zen_repeat_callers_threshold)));
controllers.add(new ZenModeScreenOnPreferenceController(context, lifecycle));
controllers.add(new ZenModeScreenOffPreferenceController(context, lifecycle));
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle));
diff --git a/src/com/android/settings/notification/ZenModeButtonPreferenceController.java b/src/com/android/settings/notification/ZenModeButtonPreferenceController.java
index 1886dab..f5169f0 100644
--- a/src/com/android/settings/notification/ZenModeButtonPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeButtonPreferenceController.java
@@ -34,11 +34,9 @@
protected static final String KEY = "zen_mode_settings_button_container";
private Button mZenButtonOn;
private Button mZenButtonOff;
- private ZenModeBackend mBackend;
public ZenModeButtonPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
}
@Override
diff --git a/src/com/android/settings/notification/ZenModeCallsPreferenceController.java b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
index d952c11..3e2f802 100644
--- a/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeCallsPreferenceController.java
@@ -26,11 +26,9 @@
public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceController {
protected static final String KEY = "zen_mode_calls";
- private final ZenModeBackend mBackend;
public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
}
@Override
diff --git a/src/com/android/settings/notification/ZenModeEventsPreferenceController.java b/src/com/android/settings/notification/ZenModeEventsPreferenceController.java
index be5e6d6..4423494 100644
--- a/src/com/android/settings/notification/ZenModeEventsPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeEventsPreferenceController.java
@@ -31,11 +31,9 @@
implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_events";
- private final ZenModeBackend mBackend;
public ZenModeEventsPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
}
@Override
diff --git a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
index dad6cf1..0ffc44d 100644
--- a/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeMessagesPreferenceController.java
@@ -10,11 +10,9 @@
public class ZenModeMessagesPreferenceController extends AbstractZenModePreferenceController {
protected static final String KEY = "zen_mode_messages";
- private final ZenModeBackend mBackend;
public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
}
@Override
diff --git a/src/com/android/settings/notification/ZenModeRemindersPreferenceController.java b/src/com/android/settings/notification/ZenModeRemindersPreferenceController.java
index 99a4f0d7..b6c2922 100644
--- a/src/com/android/settings/notification/ZenModeRemindersPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeRemindersPreferenceController.java
@@ -30,11 +30,9 @@
implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_reminders";
- private final ZenModeBackend mBackend;
public ZenModeRemindersPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
}
@Override
diff --git a/src/com/android/settings/notification/ZenModeRepeatCallersPreferenceController.java b/src/com/android/settings/notification/ZenModeRepeatCallersPreferenceController.java
index 82fe865..765d407 100644
--- a/src/com/android/settings/notification/ZenModeRepeatCallersPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeRepeatCallersPreferenceController.java
@@ -21,19 +21,26 @@
import android.provider.Settings;
import android.support.v14.preference.SwitchPreference;
import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
import android.util.Log;
import com.android.internal.logging.nano.MetricsProto;
+import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeRepeatCallersPreferenceController extends AbstractZenModePreferenceController
implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_repeat_callers";
- private final ZenModeBackend mBackend;
- public ZenModeRepeatCallersPreferenceController(Context context, Lifecycle lifecycle) {
+ private final ZenModeBackend mBackend;
+ private final int mRepeatCallersThreshold;
+
+ public ZenModeRepeatCallersPreferenceController(Context context, Lifecycle lifecycle,
+ int repeatCallersThreshold) {
super(context, KEY, lifecycle);
+
+ mRepeatCallersThreshold = repeatCallersThreshold;
mBackend = ZenModeBackend.getInstance(context);
}
@@ -48,11 +55,16 @@
}
@Override
+ public void displayPreference(PreferenceScreen screen) {
+ super.displayPreference(screen);
+ setRepeatCallerSummary(screen.findPreference(KEY));
+ }
+
+ @Override
public void updateState(Preference preference) {
super.updateState(preference);
SwitchPreference pref = (SwitchPreference) preference;
-
switch (getZenMode()) {
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
case Settings.Global.ZEN_MODE_ALARMS:
@@ -86,4 +98,9 @@
mBackend.saveSoundPolicy(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, allowRepeatCallers);
return true;
}
+
+ private void setRepeatCallerSummary(Preference preference) {
+ preference.setSummary(mContext.getString(R.string.zen_mode_repeat_callers_summary,
+ mRepeatCallersThreshold));
+ }
}
diff --git a/src/com/android/settings/notification/ZenModeScreenOffPreferenceController.java b/src/com/android/settings/notification/ZenModeScreenOffPreferenceController.java
index 0ba24c0..81c9b0d 100644
--- a/src/com/android/settings/notification/ZenModeScreenOffPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeScreenOffPreferenceController.java
@@ -29,11 +29,9 @@
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_screen_off";
- private final ZenModeBackend mBackend;
public ZenModeScreenOffPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
}
@Override
diff --git a/src/com/android/settings/notification/ZenModeScreenOnPreferenceController.java b/src/com/android/settings/notification/ZenModeScreenOnPreferenceController.java
index bcb1af8..bab4dd1 100644
--- a/src/com/android/settings/notification/ZenModeScreenOnPreferenceController.java
+++ b/src/com/android/settings/notification/ZenModeScreenOnPreferenceController.java
@@ -29,11 +29,9 @@
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
protected static final String KEY = "zen_mode_screen_on";
- private final ZenModeBackend mBackend;
public ZenModeScreenOnPreferenceController(Context context, Lifecycle lifecycle) {
super(context, KEY, lifecycle);
- mBackend = ZenModeBackend.getInstance(context);
}
@Override
diff --git a/src/com/android/settings/overlay/SupportFeatureProvider.java b/src/com/android/settings/overlay/SupportFeatureProvider.java
index 55d5d0e..ad68a74 100644
--- a/src/com/android/settings/overlay/SupportFeatureProvider.java
+++ b/src/com/android/settings/overlay/SupportFeatureProvider.java
@@ -46,89 +46,27 @@
}
/**
- * Returns a intent that will open help & feedback.
- */
- Intent getHelpIntent(Context context);
-
- /**
- * Whether or not a support type is enabled.
- */
- boolean isSupportTypeEnabled(Context context, @SupportType int type);
-
- /**
* Refreshes all operation rules.
*/
void refreshOperationRules();
/**
- * Whether or not a support type is in operation 24/7. If country is null, use
- * current country.
- */
- boolean isAlwaysOperating(@SupportType int type, String countryCode);
-
- /**
- * Whether or not a support type is operating now.
- */
- boolean isOperatingNow(@SupportType int type);
-
- /**
* Returns the current country code if it has a operation config, otherwise returns null.
*/
String getCurrentCountryCodeIfHasConfig(@SupportType int type);
/**
- * Returns localized string for operation hours in specified country. If country is null, use
- * current country to figure out operation hours.
- */
- CharSequence getOperationHours(Context context, @SupportType int type, String countryCode,
- boolean hasInternet);
-
- /**
- * Returns a localized string indicating estimated wait time for a support time.
- */
- String getEstimatedWaitTime(Context context, @SupportType int type);
-
- /**
- * Returns a list of country codes that have phone support.
- */
- List<String> getPhoneSupportCountryCodes();
-
- /**
- * Returns a list of countries that have phone support.
- */
- List<String> getPhoneSupportCountries();
-
- /**
* Returns a support phone for specified country.
*/
SupportPhone getSupportPhones(String countryCode, boolean isTollfree);
/**
- * Whether or not a disclaimer dialog should be displayed.
- */
- boolean shouldShowDisclaimerDialog(Context context);
-
- /**
- * Sets whether or not a disclaimer dialog should be displayed.
- */
- void setShouldShowDisclaimerDialog(Context context, boolean shouldShow);
-
- /**
* Returns array of {@link Account} that's eligible for support options.
*/
@NonNull
Account[] getSupportEligibleAccounts(Context context);
/**
- * Starts support activity of specified type
- *
- * @param activity Calling activity
- * @param account A account that selected by user
- * @param type The type of support account needs.
- */
- void startSupport(Activity activity, Account account, @SupportType int type);
-
- /**
* Starts support v2, invokes the support home page. Will no-op if support v2 is not enabled.
*
* @param activity Calling activity.
@@ -136,39 +74,6 @@
void startSupportV2(Activity activity);
/**
- * Checks if support v2 is enabled for this device.
- *
- * @return a boolean indicating if support v2 is enabled.
- */
- boolean isSupportV2Enabled();
-
- /**
- * Returns an {@link Intent} that opens help and allow user get help on sign in.
- */
- Intent getSignInHelpIntent(Context context);
-
- /**
- * Returns an intent that will start the add account UI.
- */
- Intent getAccountLoginIntent();
-
- /**
- * Returns an intent that will launch the tips and tricks UI.
- */
- Intent getTipsAndTricksIntent(Context context);
-
- /**
- * Returns the string for the disclaimer in the Support dialog.
- */
- @StringRes
- int getDisclaimerStringResId();
-
- /**
- * launches the fragment that displays the system information being sent to support agents.
- */
- void launchSystemInfoFragment(Bundle args, FragmentManager manager);
-
- /**
* Returns a url with information to introduce user to new device.
*/
String getNewDeviceIntroUrl(Context context);
diff --git a/src/com/android/settings/search/SearchFeatureProvider.java b/src/com/android/settings/search/SearchFeatureProvider.java
index 437fc86..b9d5045 100644
--- a/src/com/android/settings/search/SearchFeatureProvider.java
+++ b/src/com/android/settings/search/SearchFeatureProvider.java
@@ -28,6 +28,7 @@
import com.android.settings.core.FeatureFlags;
import com.android.settings.dashboard.SiteMapManager;
+import com.android.settings.overlay.FeatureFactory;
import java.util.List;
import java.util.concurrent.ExecutorService;
@@ -185,6 +186,9 @@
} else {
intent = new Intent(activity, SearchActivity.class);
}
+ FeatureFactory.getFactory(
+ activity.getApplicationContext()).getSlicesFeatureProvider()
+ .indexSliceDataAsync(activity.getApplicationContext());
activity.startActivityForResult(intent, 0 /* requestCode */);
});
}
diff --git a/src/com/android/settings/search/SearchIndexableResources.java b/src/com/android/settings/search/SearchIndexableResources.java
index 0207c94..f8125cb 100644
--- a/src/com/android/settings/search/SearchIndexableResources.java
+++ b/src/com/android/settings/search/SearchIndexableResources.java
@@ -36,7 +36,6 @@
import com.android.settings.connecteddevice.AdvancedConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragment;
import com.android.settings.connecteddevice.ConnectedDeviceDashboardFragmentOld;
-import com.android.settings.datausage.DataUsageMeteredSettings;
import com.android.settings.datausage.DataUsageSummary;
import com.android.settings.deletionhelper.AutomaticStorageManagerSettings;
import com.android.settings.development.DevelopmentSettingsDashboardFragment;
@@ -50,6 +49,7 @@
import com.android.settings.fuelgauge.BatterySaverSettings;
import com.android.settings.fuelgauge.PowerUsageAdvanced;
import com.android.settings.fuelgauge.PowerUsageSummary;
+import com.android.settings.fuelgauge.SmartBatterySettings;
import com.android.settings.gestures.AssistGestureSettings;
import com.android.settings.gestures.DoubleTapPowerSettings;
import com.android.settings.gestures.DoubleTapScreenSettings;
@@ -110,7 +110,6 @@
addIndex(BluetoothSettings.class);
addIndex(SimSettings.class);
addIndex(DataUsageSummary.class);
- addIndex(DataUsageMeteredSettings.class);
addIndex(ScreenZoomSettings.class);
addIndex(DisplaySettings.class);
addIndex(AmbientDisplaySettings.class);
@@ -174,6 +173,7 @@
addIndex(ZenModeBehaviorSettings.class);
addIndex(ZenModeAutomationSettings.class);
addIndex(NightDisplaySettings.class);
+ addIndex(SmartBatterySettings.class);
}
private SearchIndexableResources() {
diff --git a/src/com/android/settings/security/SecuritySettingsV2.java b/src/com/android/settings/security/SecuritySettingsV2.java
index 9909ccf..323c0f4 100644
--- a/src/com/android/settings/security/SecuritySettingsV2.java
+++ b/src/com/android/settings/security/SecuritySettingsV2.java
@@ -16,8 +16,11 @@
import com.android.settings.dashboard.SummaryLoader;
import com.android.settings.enterprise.EnterprisePrivacyPreferenceController;
import com.android.settings.enterprise.ManageDeviceAdminPreferenceController;
+import com.android.settings.fingerprint.FingerprintProfileStatusPreferenceController;
+import com.android.settings.fingerprint.FingerprintStatusPreferenceController;
import com.android.settings.location.LocationPreferenceController;
import com.android.settings.search.BaseSearchIndexProvider;
+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.PreferenceCategoryController;
diff --git a/src/com/android/settings/security/LockScreenPreferenceController.java b/src/com/android/settings/security/screenlock/LockScreenPreferenceController.java
similarity index 98%
rename from src/com/android/settings/security/LockScreenPreferenceController.java
rename to src/com/android/settings/security/screenlock/LockScreenPreferenceController.java
index 156ad81..d42af2d 100644
--- a/src/com/android/settings/security/LockScreenPreferenceController.java
+++ b/src/com/android/settings/security/screenlock/LockScreenPreferenceController.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.settings.security;
+package com.android.settings.security.screenlock;
import static android.app.admin.DevicePolicyManager.PASSWORD_QUALITY_UNSPECIFIED;
diff --git a/src/com/android/settings/slices/SettingsSliceProvider.java b/src/com/android/settings/slices/SettingsSliceProvider.java
index 08ea7c6..7136182 100644
--- a/src/com/android/settings/slices/SettingsSliceProvider.java
+++ b/src/com/android/settings/slices/SettingsSliceProvider.java
@@ -24,6 +24,7 @@
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.net.wifi.WifiManager;
+import android.support.annotation.VisibleForTesting;
import com.android.settings.R;
@@ -32,13 +33,25 @@
import androidx.app.slice.builders.ListBuilder;
public class SettingsSliceProvider extends SliceProvider {
+
+ private static final String TAG = "SettingsSliceProvider";
+
public static final String SLICE_AUTHORITY = "com.android.settings.slices";
public static final String PATH_WIFI = "wifi";
public static final String ACTION_WIFI_CHANGED =
"com.android.settings.slice.action.WIFI_CHANGED";
+ public static final String ACTION_TOGGLE_CHANGED =
+ "com.android.settings.slice.action.TOGGLE_CHANGED";
+
+ public static final String EXTRA_SLICE_KEY = "com.android.settings.slice.extra.key";
+
// TODO -- Associate slice URI with search result instead of separate hardcoded thing
+
+ @VisibleForTesting
+ SlicesDatabaseAccessor mSlicesDatabaseAccessor;
+
public static Uri getUri(String path) {
return new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
@@ -48,19 +61,26 @@
@Override
public boolean onCreateSliceProvider() {
+ mSlicesDatabaseAccessor = new SlicesDatabaseAccessor(getContext());
return true;
}
@Override
public Slice onBindSlice(Uri sliceUri) {
String path = sliceUri.getPath();
+ // If adding a new Slice, do not directly match Slice URIs.
+ // Use {@link SlicesDatabaseAccessor}.
switch (path) {
case "/" + PATH_WIFI:
return createWifiSlice(sliceUri);
}
- throw new IllegalArgumentException("Unrecognized slice uri: " + sliceUri);
+
+ return getHoldingSlice(sliceUri);
}
+ private Slice getHoldingSlice(Uri uri) {
+ return new ListBuilder(uri).build();
+ }
// TODO (b/70622039) remove this when the proper wifi slice is enabled.
private Slice createWifiSlice(Uri sliceUri) {
diff --git a/src/com/android/settings/slices/SliceBroadcastReceiver.java b/src/com/android/settings/slices/SliceBroadcastReceiver.java
index b6f2ab9..970b72a 100644
--- a/src/com/android/settings/slices/SliceBroadcastReceiver.java
+++ b/src/com/android/settings/slices/SliceBroadcastReceiver.java
@@ -16,7 +16,9 @@
package com.android.settings.slices;
+import static com.android.settings.slices.SettingsSliceProvider.ACTION_TOGGLE_CHANGED;
import static com.android.settings.slices.SettingsSliceProvider.ACTION_WIFI_CHANGED;
+import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
import android.app.slice.Slice;
import android.content.BroadcastReceiver;
@@ -25,19 +27,34 @@
import android.net.Uri;
import android.net.wifi.WifiManager;
import android.os.Handler;
+import android.text.TextUtils;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.TogglePreferenceController;
/**
* Responds to actions performed on slices and notifies slices of updates in state changes.
*/
public class SliceBroadcastReceiver extends BroadcastReceiver {
+ private static String TAG = "SettSliceBroadcastRec";
+
+ /**
+ * TODO (b/) move wifi action into generalized case.
+ */
@Override
- public void onReceive(Context context, Intent i) {
- String action = i.getAction();
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ String key = intent.getStringExtra(EXTRA_SLICE_KEY);
+
switch (action) {
+ case ACTION_TOGGLE_CHANGED:
+ handleToggleAction(context, key);
+ break;
case ACTION_WIFI_CHANGED:
WifiManager wm = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
- boolean newState = i.getBooleanExtra(Slice.EXTRA_TOGGLE_STATE, wm.isWifiEnabled());
+ boolean newState = intent.getBooleanExtra(Slice.EXTRA_TOGGLE_STATE,
+ wm.isWifiEnabled());
wm.setWifiEnabled(newState);
// Wait a bit for wifi to update (TODO: is there a better way to do this?)
Handler h = new Handler();
@@ -48,4 +65,28 @@
break;
}
}
+
+ private void handleToggleAction(Context context, String key) {
+ if (TextUtils.isEmpty(key)) {
+ throw new IllegalStateException("No key passed to Intent for toggle controller");
+ }
+
+ BasePreferenceController controller = getBasePreferenceController(context, key);
+
+ if (!(controller instanceof TogglePreferenceController)) {
+ throw new IllegalStateException("Toggle action passed for a non-toggle key: " + key);
+ }
+
+ // TODO post context.getContentResolver().notifyChanged(uri, null) in the Toggle controller
+ // so that it's automatically broadcast to any slice.
+ TogglePreferenceController toggleController = (TogglePreferenceController) controller;
+ boolean currentValue = toggleController.isChecked();
+ toggleController.setChecked(!currentValue);
+ }
+
+ private BasePreferenceController getBasePreferenceController(Context context, String key) {
+ final SlicesDatabaseAccessor accessor = new SlicesDatabaseAccessor(context);
+ final SliceData sliceData = accessor.getSliceDataFromKey(key);
+ return SliceBuilderUtils.getPreferenceController(context, sliceData);
+ }
}
diff --git a/src/com/android/settings/slices/SliceBuilderUtils.java b/src/com/android/settings/slices/SliceBuilderUtils.java
new file mode 100644
index 0000000..3663e89
--- /dev/null
+++ b/src/com/android/settings/slices/SliceBuilderUtils.java
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.settings.slices;
+
+import static com.android.settings.slices.SettingsSliceProvider.EXTRA_SLICE_KEY;
+
+import android.app.PendingIntent;
+import android.content.Context;
+import android.content.Intent;
+import android.graphics.drawable.Icon;
+import android.text.TextUtils;
+
+import com.android.settings.SubSettings;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.TogglePreferenceController;
+import com.android.settings.search.DatabaseIndexingUtils;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import androidx.app.slice.Slice;
+import androidx.app.slice.builders.ListBuilder;
+import androidx.app.slice.builders.ListBuilder.RowBuilder;
+
+/**
+ * Utility class to build Slices objects and Preference Controllers based on the Database managed
+ * by {@link SlicesDatabaseHelper}
+ */
+public class SliceBuilderUtils {
+
+ private static final String TAG = "SliceBuilder";
+
+ /**
+ * Build a Slice from {@link SliceData}.
+ *
+ * @return a {@link Slice} based on the data provided by {@param sliceData}.
+ * Will build an {@link Intent} based Slice unless the Preference Controller name in
+ * {@param sliceData} is an inline controller.
+ */
+ public static Slice buildSlice(Context context, SliceData sliceData) {
+ final PendingIntent contentIntent = getContentIntent(context, sliceData);
+ final Icon icon = Icon.createWithResource(context, sliceData.getIconResource());
+ String summaryText = sliceData.getSummary();
+ String subtitleText = TextUtils.isEmpty(summaryText)
+ ? sliceData.getScreenTitle()
+ : summaryText;
+
+ RowBuilder builder = new RowBuilder(sliceData.getUri())
+ .setTitle(sliceData.getTitle())
+ .setTitleItem(icon)
+ .setSubtitle(subtitleText)
+ .setContentIntent(contentIntent);
+
+ BasePreferenceController controller = getPreferenceController(context, sliceData);
+
+ // TODO (b/71640747) Respect setting availability.
+ // TODO (b/71640678) Add dynamic summary text.
+
+ if (controller instanceof TogglePreferenceController) {
+ addToggleAction(context, builder, ((TogglePreferenceController) controller).isChecked(),
+ sliceData.getKey());
+ }
+
+ return new ListBuilder(sliceData.getUri())
+ .addRow(builder)
+ .build();
+ }
+
+ /**
+ * Looks at the {@link SliceData#preferenceController} from {@param sliceData} and attempts to
+ * build a {@link BasePreferenceController}.
+ */
+ public static BasePreferenceController getPreferenceController(Context context,
+ SliceData sliceData) {
+ // TODO check for context-only controller first.
+ try {
+ Class<?> clazz = Class.forName(sliceData.getPreferenceController());
+ Constructor<?> preferenceConstructor = clazz.getConstructor(Context.class,
+ String.class);
+ return (BasePreferenceController) preferenceConstructor.newInstance(
+ new Object[]{context, sliceData.getKey()});
+ } catch (ClassNotFoundException | NoSuchMethodException | InstantiationException |
+ IllegalArgumentException | InvocationTargetException | IllegalAccessException e) {
+ throw new IllegalStateException(
+ "Invalid preference controller: " + sliceData.getPreferenceController());
+ }
+ }
+
+ private static void addToggleAction(Context context, RowBuilder builder, boolean isChecked,
+ String key) {
+ PendingIntent actionIntent = getActionIntent(context,
+ SettingsSliceProvider.ACTION_TOGGLE_CHANGED, key);
+ builder.addToggle(actionIntent, isChecked);
+ }
+
+ private static PendingIntent getActionIntent(Context context, String action, String key) {
+ Intent intent = new Intent(action);
+ intent.setClass(context, SliceBroadcastReceiver.class);
+ intent.putExtra(EXTRA_SLICE_KEY, key);
+ return PendingIntent.getBroadcast(context, 0 /* requestCode */, intent,
+ PendingIntent.FLAG_CANCEL_CURRENT);
+ }
+
+ private static PendingIntent getContentIntent(Context context, SliceData sliceData) {
+ Intent intent = DatabaseIndexingUtils.buildSearchResultPageIntent(context,
+ sliceData.getFragmentClassName(), sliceData.getKey(), sliceData.getScreenTitle(),
+ 0 /* TODO */);
+ intent.setClassName("com.android.settings", SubSettings.class.getName());
+ return PendingIntent.getActivity(context, 0 /* requestCode */, intent, 0 /* flags */);
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/slices/SliceData.java b/src/com/android/settings/slices/SliceData.java
index f83676a..f72add7 100644
--- a/src/com/android/settings/slices/SliceData.java
+++ b/src/com/android/settings/slices/SliceData.java
@@ -18,7 +18,6 @@
import android.net.Uri;
import android.text.TextUtils;
-
/**
* Data class representing a slice stored by {@link SlicesIndexer}.
* Note that {@link #key} is treated as a primary key for this class and determines equality.
@@ -179,5 +178,4 @@
return mKey;
}
}
-
}
\ No newline at end of file
diff --git a/src/com/android/settings/slices/SlicesDatabaseAccessor.java b/src/com/android/settings/slices/SlicesDatabaseAccessor.java
new file mode 100644
index 0000000..4fca63a
--- /dev/null
+++ b/src/com/android/settings/slices/SlicesDatabaseAccessor.java
@@ -0,0 +1,141 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.settings.slices;
+
+import static com.android.settings.slices.SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX;
+
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.net.Uri;
+
+import android.content.Context;
+import android.os.Binder;
+
+import com.android.settings.overlay.FeatureFactory;
+import com.android.settings.slices.SlicesDatabaseHelper.IndexColumns;
+
+import androidx.app.slice.Slice;
+
+/**
+ * Class used to map a {@link Uri} from {@link SettingsSliceProvider} to a Slice.
+ */
+public class SlicesDatabaseAccessor {
+
+ public static final String[] SELECT_COLUMNS = {
+ IndexColumns.KEY,
+ IndexColumns.TITLE,
+ IndexColumns.SUMMARY,
+ IndexColumns.SCREENTITLE,
+ IndexColumns.ICON_RESOURCE,
+ IndexColumns.FRAGMENT,
+ IndexColumns.CONTROLLER,
+ };
+
+ Context mContext;
+
+ public SlicesDatabaseAccessor(Context context) {
+ mContext = context;
+ }
+
+ /**
+ * Query the slices database and return a {@link SliceData} object corresponding to the row
+ * matching the key provided by the {@param uri}. Additionally adds the {@param uri} to the
+ * {@link SliceData} object so the {@link Slice} can bind to the {@link Uri}.
+ * Used when building a {@link Slice}.
+ */
+ public SliceData getSliceDataFromUri(Uri uri) {
+ String key = uri.getLastPathSegment();
+ Cursor cursor = getIndexedSliceData(key);
+ return buildSliceData(cursor, uri);
+ }
+
+ /**
+ * Query the slices database and return a {@link SliceData} object corresponding to the row
+ * matching the {@param key}.
+ * Used when handling the action of the {@link Slice}.
+ */
+ public SliceData getSliceDataFromKey(String key) {
+ Cursor cursor = getIndexedSliceData(key);
+ return buildSliceData(cursor, null /* uri */);
+ }
+
+ private Cursor getIndexedSliceData(String path) {
+ verifyIndexing();
+
+ final String whereClause = buildWhereClause();
+ final SlicesDatabaseHelper helper = SlicesDatabaseHelper.getInstance(mContext);
+ final SQLiteDatabase database = helper.getReadableDatabase();
+ final String[] selection = new String[]{path};
+
+ Cursor resultCursor = database.query(TABLE_SLICES_INDEX, SELECT_COLUMNS, whereClause,
+ selection, null /* groupBy */, null /* having */, null /* orderBy */);
+
+ int numResults = resultCursor.getCount();
+
+ if (numResults == 0) {
+ throw new IllegalStateException("Invalid Slices key from path: " + path);
+ }
+
+ if (numResults > 1) {
+ throw new IllegalStateException(
+ "Should not match more than 1 slice with path: " + path);
+ }
+
+ resultCursor.moveToFirst();
+ return resultCursor;
+ }
+
+ private String buildWhereClause() {
+ return new StringBuilder(IndexColumns.KEY)
+ .append(" = ?")
+ .toString();
+ }
+
+ private SliceData buildSliceData(Cursor cursor, Uri uri) {
+ final String key = cursor.getString(cursor.getColumnIndex(IndexColumns.KEY));
+ final String title = cursor.getString(cursor.getColumnIndex(IndexColumns.TITLE));
+ final String summary = cursor.getString(cursor.getColumnIndex(IndexColumns.SUMMARY));
+ final String screenTitle = cursor.getString(
+ cursor.getColumnIndex(IndexColumns.SCREENTITLE));
+ final int iconResource = cursor.getInt(cursor.getColumnIndex(IndexColumns.ICON_RESOURCE));
+ final String fragmentClassName = cursor.getString(
+ cursor.getColumnIndex(IndexColumns.FRAGMENT));
+ final String controllerClassName = cursor.getString(
+ cursor.getColumnIndex(IndexColumns.CONTROLLER));
+
+ return new SliceData.Builder()
+ .setKey(key)
+ .setTitle(title)
+ .setSummary(summary)
+ .setScreenTitle(screenTitle)
+ .setIcon(iconResource)
+ .setFragmentName(fragmentClassName)
+ .setPreferenceControllerClassName(controllerClassName)
+ .setUri(uri)
+ .build();
+ }
+
+ private void verifyIndexing() {
+ final long uidToken = Binder.clearCallingIdentity();
+ try {
+ FeatureFactory.getFactory(
+ mContext).getSlicesFeatureProvider().indexSliceData(mContext);
+ } finally {
+ Binder.restoreCallingIdentity(uidToken);
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/slices/SlicesDatabaseHelper.java b/src/com/android/settings/slices/SlicesDatabaseHelper.java
index 18f8cc9..448d8f1 100644
--- a/src/com/android/settings/slices/SlicesDatabaseHelper.java
+++ b/src/com/android/settings/slices/SlicesDatabaseHelper.java
@@ -104,7 +104,7 @@
public static synchronized SlicesDatabaseHelper getInstance(Context context) {
if (sSingleton == null) {
- sSingleton = new SlicesDatabaseHelper(context);
+ sSingleton = new SlicesDatabaseHelper(context.getApplicationContext());
}
return sSingleton;
}
diff --git a/src/com/android/settings/slices/SlicesFeatureProvider.java b/src/com/android/settings/slices/SlicesFeatureProvider.java
index cbf1b75..e5bba61 100644
--- a/src/com/android/settings/slices/SlicesFeatureProvider.java
+++ b/src/com/android/settings/slices/SlicesFeatureProvider.java
@@ -13,5 +13,15 @@
SliceDataConverter getSliceDataConverter(Context context);
+ /**
+ * Asynchronous call to index the data used to build Slices.
+ * If the data is already indexed, the data will not change.
+ */
+ void indexSliceDataAsync(Context context);
+
+ /**
+ * Indexes the data used to build Slices.
+ * If the data is already indexed, the data will not change.
+ */
void indexSliceData(Context context);
}
\ No newline at end of file
diff --git a/src/com/android/settings/slices/SlicesFeatureProviderImpl.java b/src/com/android/settings/slices/SlicesFeatureProviderImpl.java
index 34ef884..8e5bc06 100644
--- a/src/com/android/settings/slices/SlicesFeatureProviderImpl.java
+++ b/src/com/android/settings/slices/SlicesFeatureProviderImpl.java
@@ -15,7 +15,7 @@
@Override
public SlicesIndexer getSliceIndexer(Context context) {
if (mSlicesIndexer == null) {
- mSlicesIndexer = new SlicesIndexer(context.getApplicationContext());
+ mSlicesIndexer = new SlicesIndexer(context);
}
return mSlicesIndexer;
}
@@ -29,9 +29,14 @@
}
@Override
- public void indexSliceData(Context context) {
- // TODO (b/67996923) add indexing time log
+ public void indexSliceDataAsync(Context context) {
SlicesIndexer indexer = getSliceIndexer(context);
ThreadUtils.postOnBackgroundThread(indexer);
}
-}
+
+ @Override
+ public void indexSliceData(Context context) {
+ SlicesIndexer indexer = getSliceIndexer(context);
+ indexer.indexSliceData();
+ }
+}
\ No newline at end of file
diff --git a/src/com/android/settings/slices/SlicesIndexer.java b/src/com/android/settings/slices/SlicesIndexer.java
index 0297f3f..a92388a 100644
--- a/src/com/android/settings/slices/SlicesIndexer.java
+++ b/src/com/android/settings/slices/SlicesIndexer.java
@@ -20,6 +20,7 @@
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.support.annotation.VisibleForTesting;
+import android.util.Log;
import com.android.settings.dashboard.DashboardFragment;
@@ -36,7 +37,7 @@
*/
class SlicesIndexer implements Runnable {
- private static final String TAG = "SlicesIndexingManager";
+ private static final String TAG = "SlicesIndexer";
private Context mContext;
@@ -48,18 +49,27 @@
}
/**
- * Synchronously takes data obtained from {@link SliceDataConverter} and indexes it into a
- * SQLite database.
+ * Asynchronously index slice data from {@link #indexSliceData()}.
*/
@Override
public void run() {
+ indexSliceData();
+ }
+
+ /**
+ * Synchronously takes data obtained from {@link SliceDataConverter} and indexes it into a
+ * SQLite database
+ */
+ protected void indexSliceData() {
if (mHelper.isSliceDataIndexed()) {
+ Log.d(TAG, "Slices already indexed - returning.");
return;
}
SQLiteDatabase database = mHelper.getWritableDatabase();
try {
+ long startTime = System.currentTimeMillis();
database.beginTransaction();
mHelper.reconstruct(mHelper.getWritableDatabase());
@@ -67,6 +77,10 @@
insertSliceData(database, indexData);
mHelper.setIndexedState();
+
+ // TODO (b/71503044) Log indexing time.
+ Log.d(TAG,
+ "Indexing slices database took: " + (System.currentTimeMillis() - startTime));
database.setTransactionSuccessful();
} finally {
database.endTransaction();
diff --git a/src/com/android/settings/support/SupportDashboardActivity.java b/src/com/android/settings/support/SupportDashboardActivity.java
index d3fcf9a..3b5d623 100644
--- a/src/com/android/settings/support/SupportDashboardActivity.java
+++ b/src/com/android/settings/support/SupportDashboardActivity.java
@@ -21,7 +21,6 @@
import android.os.Bundle;
import com.android.settings.R;
-import com.android.settings.Settings.LegacySupportActivity;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.overlay.SupportFeatureProvider;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -43,12 +42,10 @@
.getSupportFeatureProvider(this);
// try to launch support v2 if we have the feature provider
- if (supportFeatureProvider != null && supportFeatureProvider.isSupportV2Enabled()) {
- supportFeatureProvider.startSupportV2(this);
- } else {
- startActivity(new Intent(this, LegacySupportActivity.class));
+ if (supportFeatureProvider != null) {
+ supportFeatureProvider.startSupportV2(this);
+ finish();
}
- finish();
}
/**
diff --git a/src/com/android/settings/support/SupportDisclaimerDialogFragment.java b/src/com/android/settings/support/SupportDisclaimerDialogFragment.java
deleted file mode 100644
index 07a451a..0000000
--- a/src/com/android/settings/support/SupportDisclaimerDialogFragment.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.support;
-
-import android.accounts.Account;
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.app.DialogFragment;
-import android.content.DialogInterface;
-import android.os.Bundle;
-import android.text.Annotation;
-import android.text.Spannable;
-import android.text.Spanned;
-import android.text.TextPaint;
-import android.text.TextUtils;
-import android.text.style.URLSpan;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.CheckBox;
-import android.widget.TextView;
-
-import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-import com.android.settings.overlay.FeatureFactory;
-import com.android.settings.overlay.SupportFeatureProvider;
-
-/**
- * {@link DialogFragment} for support disclaimer.
- */
-public final class SupportDisclaimerDialogFragment extends InstrumentedDialogFragment
- implements DialogInterface.OnClickListener {
-
- public static final String TAG = "SupportDisclaimerDialog";
- public static final String EXTRA_TYPE = "extra_type";
- public static final String EXTRA_ACCOUNT = "extra_account";
-
- public static SupportDisclaimerDialogFragment newInstance(Account account,
- @SupportFeatureProvider.SupportType int type) {
- final SupportDisclaimerDialogFragment fragment = new SupportDisclaimerDialogFragment();
- final Bundle bundle = new Bundle(2);
- bundle.putParcelable(SupportDisclaimerDialogFragment.EXTRA_ACCOUNT, account);
- bundle.putInt(SupportDisclaimerDialogFragment.EXTRA_TYPE, type);
- fragment.setArguments(bundle);
- return fragment;
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
- .setTitle(R.string.support_disclaimer_title)
- .setPositiveButton(android.R.string.ok, this)
- .setNegativeButton(android.R.string.cancel, this);
- final View content = LayoutInflater.from(builder.getContext())
- .inflate(R.layout.support_disclaimer_content, null);
- final TextView disclaimer = (TextView) content.findViewById(R.id.support_disclaimer_text);
- final Activity activity = getActivity();
- final SupportFeatureProvider supportFeatureProvider =
- FeatureFactory.getFactory(activity).getSupportFeatureProvider(activity);
-
- // sets the two links that go to privacy policy and terms of service
- disclaimer.setText(supportFeatureProvider.getDisclaimerStringResId());
- Spannable viewText = (Spannable) disclaimer.getText();
- stripUnderlines(viewText);
- SystemInformationSpan.linkify(viewText, this);
- // sets the link that launches a dialog to expose the signals we are sending
- return builder
- .setView(content)
- .create();
- }
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (which == Dialog.BUTTON_NEGATIVE) {
- mMetricsFeatureProvider.action(getContext(),
- MetricsProto.MetricsEvent.ACTION_SUPPORT_DISCLAIMER_CANCEL);
- return;
- }
- final Activity activity = getActivity();
- final CheckBox doNotShow =
- (CheckBox) getDialog().findViewById(R.id.support_disclaimer_do_not_show_again);
- final boolean isChecked = doNotShow.isChecked();
- final SupportFeatureProvider supportFeatureProvider =
- FeatureFactory.getFactory(activity).getSupportFeatureProvider(activity);
- supportFeatureProvider.setShouldShowDisclaimerDialog(getContext(), !isChecked);
- final Bundle bundle = getArguments();
- if (isChecked) {
- mMetricsFeatureProvider.action(activity,
- MetricsProto.MetricsEvent.ACTION_SKIP_DISCLAIMER_SELECTED);
- }
- mMetricsFeatureProvider.action(activity,
- MetricsProto.MetricsEvent.ACTION_SUPPORT_DISCLAIMER_OK);
- supportFeatureProvider.startSupport(getActivity(),
- bundle.getParcelable(EXTRA_ACCOUNT), bundle.getInt(EXTRA_TYPE));
- }
-
- @Override
- public void onCancel(DialogInterface dialog) {
- super.onCancel(dialog);
- mMetricsFeatureProvider.action(getContext(),
- MetricsProto.MetricsEvent.ACTION_SUPPORT_DISCLAIMER_CANCEL);
- }
-
- /**
- * Removes the underlines of {@link android.text.style.URLSpan}s.
- */
- private static void stripUnderlines(Spannable input) {
- final URLSpan[] urls = input.getSpans(0, input.length(), URLSpan.class);
-
- for (URLSpan span : urls) {
- final int start = input.getSpanStart(span);
- final int end = input.getSpanEnd(span);
- if (!TextUtils.isEmpty(span.getURL())) {
- input.removeSpan(span);
- input.setSpan(new NoUnderlineUrlSpan(span.getURL()), start, end,
- Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- }
- }
-
- @Override
- public int getMetricsCategory() {
- return MetricsProto.MetricsEvent.DIALOG_SUPPORT_DISCLAIMER;
- }
-
- /**
- * A {@link URLSpan} that doesn't decorate the link with underline.
- */
- public static class NoUnderlineUrlSpan extends URLSpan {
-
- public NoUnderlineUrlSpan(String url) {
- super(url);
- }
-
- @Override
- public void updateDrawState(TextPaint ds) {
- super.updateDrawState(ds);
- ds.setUnderlineText(false);
- }
- }
-
- /**
- * A {@link URLSpan} that opens a dialog when clicked
- */
- public static class SystemInformationSpan extends URLSpan {
-
- private static final String ANNOTATION_URL = "url";
- private final DialogFragment mDialog;
- private SupportFeatureProvider mSupport;
-
- public SystemInformationSpan(DialogFragment parent) {
- // sets the url to empty string so we can prevent the NoUnderlineUrlSpan from stripping
- // this one
- super("");
- mSupport = FeatureFactory.getFactory(parent.getContext())
- .getSupportFeatureProvider(parent.getContext());
- mDialog = parent;
- }
-
- @Override
- public void onClick(View widget) {
- Activity activity = mDialog.getActivity();
- if (mSupport != null && activity != null) {
- // launch the system info fragment
- mSupport.launchSystemInfoFragment(mDialog.getArguments(),
- activity.getFragmentManager());
-
- // dismiss this fragment
- mDialog.dismiss();
- }
- }
-
- @Override
- public void updateDrawState(TextPaint ds) {
- super.updateDrawState(ds);
- // remove underline
- ds.setUnderlineText(false);
- }
-
- /**
- * This method takes a string and turns it into a url span that will launch a
- * SupportSystemInformationDialogFragment
- * @param msg The text to turn into a link
- * @param parent The dialog the text is in
- * @return A CharSequence containing the original text content as a url
- */
- public static CharSequence linkify(Spannable msg, DialogFragment parent) {
- Annotation[] spans = msg.getSpans(0, msg.length(), Annotation.class);
- for (Annotation annotation : spans) {
- int start = msg.getSpanStart(annotation);
- int end = msg.getSpanEnd(annotation);
- if (ANNOTATION_URL.equals(annotation.getValue())) {
- SystemInformationSpan link = new SystemInformationSpan(parent);
- msg.removeSpan(annotation);
- msg.setSpan(link, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
- }
- }
- return msg;
- }
-
- @VisibleForTesting
- public void setSupportProvider(SupportFeatureProvider prov) {
- mSupport = prov;
- }
- }
-}
diff --git a/src/com/android/settings/support/SupportPhoneDialogFragment.java b/src/com/android/settings/support/SupportPhoneDialogFragment.java
deleted file mode 100644
index 8abdae0..0000000
--- a/src/com/android/settings/support/SupportPhoneDialogFragment.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.settings.support;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.Intent;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.TextView;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.R;
-import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
-
-import java.util.Locale;
-
-/**
- * A dialog fragment that displays support phone numbers.
- */
-public final class SupportPhoneDialogFragment extends InstrumentedDialogFragment
- implements View.OnClickListener {
-
- public static final String TAG = "SupportPhoneDialog";
- private static final String EXTRA_PHONE = "extra_phone";
-
- public static SupportPhoneDialogFragment newInstance(SupportPhone phone) {
- final SupportPhoneDialogFragment fragment = new SupportPhoneDialogFragment();
- final Bundle bundle = new Bundle(2);
- bundle.putParcelable(EXTRA_PHONE, phone);
- fragment.setArguments(bundle);
- return fragment;
- }
-
- @Override
- public Dialog onCreateDialog(Bundle savedInstanceState) {
- final SupportPhone phone = getArguments().getParcelable(EXTRA_PHONE);
- final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
- .setTitle(R.string.support_international_phone_title);
- final View content = LayoutInflater.from(builder.getContext())
- .inflate(R.layout.support_phone_dialog_content, null);
- final View phoneNumberContainer = content.findViewById(R.id.phone_number_container);
- final TextView phoneView = (TextView) content.findViewById(R.id.phone_number);
- final String formattedPhoneNumber = getContext().getString(
- R.string.support_phone_international_format,
- new Locale(phone.language).getDisplayLanguage(), phone.number);
- phoneView.setText(formattedPhoneNumber);
- phoneNumberContainer.setOnClickListener(this);
- return builder
- .setView(content)
- .create();
- }
-
- @Override
- public void onClick(View v) {
- final SupportPhone phone = getArguments().getParcelable(EXTRA_PHONE);
- final Activity activity = getActivity();
- final Intent intent = phone.getDialIntent();
- final boolean canDial = !activity.getPackageManager()
- .queryIntentActivities(intent, 0)
- .isEmpty();
- if (canDial) {
- mMetricsFeatureProvider.action(getActivity(),
- MetricsProto.MetricsEvent.ACTION_SUPPORT_DIAL_TOLLED);
- getActivity().startActivity(intent);
- }
- dismiss();
- }
-
- @Override
- public int getMetricsCategory() {
- return MetricsProto.MetricsEvent.DIALOG_SUPPORT_PHONE;
- }
-}
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/wifi/WifiConfigController.java b/src/com/android/settings/wifi/WifiConfigController.java
index 4da7366..5e5d5ff 100644
--- a/src/com/android/settings/wifi/WifiConfigController.java
+++ b/src/com/android/settings/wifi/WifiConfigController.java
@@ -146,11 +146,11 @@
private TextView mDns2View;
private Spinner mProxySettingsSpinner;
+ private Spinner mMeteredSettingsSpinner;
private TextView mProxyHostView;
private TextView mProxyPortView;
private TextView mProxyExclusionListView;
private TextView mProxyPacView;
-
private CheckBox mSharedCheckBox;
private IpAssignment mIpAssignment = IpAssignment.UNASSIGNED;
@@ -208,6 +208,7 @@
mProxySettingsSpinner = (Spinner) mView.findViewById(R.id.proxy_settings);
mProxySettingsSpinner.setOnItemSelectedListener(this);
mSharedCheckBox = (CheckBox) mView.findViewById(R.id.shared);
+ mMeteredSettingsSpinner = mView.findViewById(R.id.metered_settings);
if (mAccessPoint == null) { // new network
mConfigUi.setTitle(R.string.wifi_add_network);
@@ -237,6 +238,7 @@
boolean showAdvancedFields = false;
if (mAccessPoint.isSaved()) {
WifiConfiguration config = mAccessPoint.getConfig();
+ mMeteredSettingsSpinner.setSelection(config.meteredOverride);
if (config.getIpAssignment() == IpAssignment.STATIC) {
mIpSettingsSpinner.setSelection(STATIC_IP);
showAdvancedFields = true;
@@ -671,6 +673,9 @@
config.setIpConfiguration(
new IpConfiguration(mIpAssignment, mProxySettings,
mStaticIpConfiguration, mHttpProxy));
+ if (mMeteredSettingsSpinner != null) {
+ config.meteredOverride = mMeteredSettingsSpinner.getSelectedItemPosition();
+ }
return config;
}
diff --git a/src/com/android/settings/wifi/details/WifiMeteredPreferenceController.java b/src/com/android/settings/wifi/details/WifiMeteredPreferenceController.java
new file mode 100644
index 0000000..1a3d195
--- /dev/null
+++ b/src/com/android/settings/wifi/details/WifiMeteredPreferenceController.java
@@ -0,0 +1,83 @@
+/*
+ * 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.wifi.details;
+
+import android.app.backup.BackupManager;
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiManager;
+import android.provider.Settings;
+import android.support.annotation.VisibleForTesting;
+import android.support.v14.preference.SwitchPreference;
+import android.support.v7.preference.DropDownPreference;
+import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
+import android.text.TextUtils;
+
+import com.android.settings.core.BasePreferenceController;
+import com.android.settings.core.PreferenceControllerMixin;
+import com.android.settingslib.core.AbstractPreferenceController;
+
+/**
+ * {@link AbstractPreferenceController} that controls whether the wifi network is metered or not
+ */
+public class WifiMeteredPreferenceController extends BasePreferenceController implements
+ Preference.OnPreferenceChangeListener {
+
+ private static final String KEY_WIFI_METERED = "metered";
+ private WifiConfiguration mWifiConfiguration;
+ private WifiManager mWifiManager;
+
+ public WifiMeteredPreferenceController(Context context, WifiConfiguration wifiConfiguration) {
+ super(context, KEY_WIFI_METERED);
+ mWifiConfiguration = wifiConfiguration;
+ mWifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
+ }
+
+ @Override
+ public void updateState(Preference preference) {
+ final DropDownPreference dropDownPreference = (DropDownPreference) preference;
+ final int meteredOverride = getMeteredOverride();
+ dropDownPreference.setValue(Integer.toString(meteredOverride));
+ updateSummary(dropDownPreference, meteredOverride);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ mWifiConfiguration.meteredOverride = Integer.parseInt((String) newValue);
+ mWifiManager.updateNetwork(mWifiConfiguration);
+ // Stage the backup of the SettingsProvider package which backs this up
+ BackupManager.dataChanged("com.android.providers.settings");
+ updateSummary((DropDownPreference) preference, getMeteredOverride());
+ return true;
+ }
+
+ @VisibleForTesting
+ int getMeteredOverride() {
+ // Wrap the meteredOverride since robolectric cannot recognize it
+ return mWifiConfiguration.meteredOverride;
+ }
+
+ private void updateSummary(DropDownPreference preference, int meteredOverride) {
+ preference.setSummary(preference.getEntries()[meteredOverride]);
+ }
+}
diff --git a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
index ea30b56..9a5430b 100644
--- a/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
+++ b/src/com/android/settings/wifi/details/WifiNetworkDetailsFragment.java
@@ -20,10 +20,13 @@
import android.app.Dialog;
import android.content.Context;
import android.net.ConnectivityManager;
+import android.net.NetworkPolicyManager;
+import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
+import android.support.v7.preference.DropDownPreference;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
@@ -122,6 +125,7 @@
@Override
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
+ final List<AbstractPreferenceController> controllers = new ArrayList<>();
ConnectivityManager cm = context.getSystemService(ConnectivityManager.class);
mWifiDetailPreferenceController = WifiDetailPreferenceController.newInstance(
mAccessPoint,
@@ -133,6 +137,9 @@
context.getSystemService(WifiManager.class),
mMetricsFeatureProvider);
- return new ArrayList<>(Collections.singletonList(mWifiDetailPreferenceController));
+ controllers.add(mWifiDetailPreferenceController);
+ controllers.add(new WifiMeteredPreferenceController(context, mAccessPoint.getConfig()));
+
+ return controllers;
}
}
diff --git a/tests/robotests/src/com/android/settings/UtilsTest.java b/tests/robotests/src/com/android/settings/UtilsTest.java
index f813457..fb571bb 100644
--- a/tests/robotests/src/com/android/settings/UtilsTest.java
+++ b/tests/robotests/src/com/android/settings/UtilsTest.java
@@ -4,13 +4,16 @@
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ApplicationInfo;
+import android.content.pm.PackageManager;
import android.content.pm.UserInfo;
import android.net.ConnectivityManager;
import android.net.LinkAddress;
@@ -25,6 +28,7 @@
import android.text.SpannableStringBuilder;
import android.text.format.DateUtils;
import android.text.style.TtsSpan;
+import android.util.IconDrawableFactory;
import android.widget.EditText;
import android.widget.TextView;
@@ -46,8 +50,8 @@
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class UtilsTest {
-
private static final String PACKAGE_NAME = "com.android.app";
+ private static final int USER_ID = 1;
@Mock
private WifiManager wifiManager;
@@ -59,6 +63,12 @@
private DevicePolicyManagerWrapper mDevicePolicyManager;
@Mock
private UserManager mUserManager;
+ @Mock
+ private PackageManager mPackageManager;
+ @Mock
+ private IconDrawableFactory mIconDrawableFactory;
+ @Mock
+ private ApplicationInfo mApplicationInfo;
private Context mContext;
@Before
@@ -332,4 +342,17 @@
assertThat(editText.getSelectionEnd()).isEqualTo(length);
}
+
+ @Test
+ public void testGetBadgedIcon_usePackageNameAndUserId() throws
+ PackageManager.NameNotFoundException {
+ doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(PACKAGE_NAME,
+ PackageManager.GET_META_DATA);
+
+ Utils.getBadgedIcon(mIconDrawableFactory, mPackageManager, PACKAGE_NAME, USER_ID);
+
+ // Verify that it uses the correct user id
+ verify(mIconDrawableFactory).getBadgedIcon(mApplicationInfo, USER_ID);
+ }
+
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java b/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java
index cda9a22..7ec2c58 100644
--- a/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/DashboardItemAnimatorTest.java
@@ -17,10 +17,11 @@
package com.android.settings.dashboard;
import android.content.Context;
+import android.support.v7.widget.RecyclerView;
+import android.view.View;
import android.widget.TextView;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.TestConfig;
-import com.android.settings.dashboard.SupportItemAdapter.ViewHolder;
import com.android.settingslib.drawer.Tile;
import org.junit.Before;
import org.junit.Test;
@@ -68,4 +69,12 @@
.animateChange(mViewHolder, mViewHolder, 0, 1, 0, 1);
assertThat(hasPendingAnimation).isFalse();
}
+
+ // Sample viewholder to use for test
+ static final class ViewHolder extends RecyclerView.ViewHolder {
+
+ ViewHolder(View itemView) {
+ super(itemView);
+ }
+ }
}
diff --git a/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java b/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java
deleted file mode 100644
index 3dd5266..0000000
--- a/tests/robotests/src/com/android/settings/dashboard/SupportItemAdapterTest.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*
- * Copyright (C) 2016 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.settings.dashboard;
-
-import android.accounts.Account;
-import android.app.Activity;
-import android.content.Intent;
-import android.provider.Settings;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.widget.Spinner;
-import android.widget.SpinnerAdapter;
-
-import com.android.settings.R;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.TestConfig;
-import com.android.settings.core.instrumentation.MetricsFeatureProvider;
-import com.android.settings.dashboard.SupportItemAdapter.EscalationData;
-import com.android.settings.overlay.SupportFeatureProvider;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.robolectric.Robolectric;
-import org.robolectric.annotation.Config;
-import org.robolectric.shadows.ShadowActivity;
-
-import static com.google.common.truth.Truth.assertThat;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.robolectric.Shadows.shadowOf;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
-public class SupportItemAdapterTest {
- private static final String ACCOUNT_TYPE = "com.google";
- private final Account USER_1 = new Account("user1", ACCOUNT_TYPE);
- private final Account USER_2 = new Account("user2", ACCOUNT_TYPE);
- private final Account TWO_ACCOUNTS[] = {USER_1, USER_2};
- private final Account ONE_ACCOUNT[] = {USER_1};
- private final Account ZERO_ACCOUNT[] = {};
-
- private ShadowActivity mShadowActivity;
- private Activity mActivity;
- private SupportItemAdapter mSupportItemAdapter;
- private SupportItemAdapter.ViewHolder mViewHolder;
- @Mock
- private SupportFeatureProvider mSupportFeatureProvider;
- @Mock
- private MetricsFeatureProvider mMetricsFeatureProvider;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mActivity = Robolectric.setupActivity(Activity.class);
- mShadowActivity = shadowOf(mActivity);
-
- final View itemView = LayoutInflater.from(mActivity).inflate(
- R.layout.support_escalation_options, null);
- mViewHolder = new SupportItemAdapter.ViewHolder(itemView);
-
- // Mock this to prevent crash in testing
- when(mSupportFeatureProvider.getAccountLoginIntent()).thenReturn(
- new Intent(Settings.ACTION_ADD_ACCOUNT));
- }
-
- @Test
- public void testBindAccountPicker_TwoAccounts_ShouldHaveTwoAccounts() {
- testBindAccountPickerInner(mViewHolder, TWO_ACCOUNTS);
- }
-
- @Test
- public void testBindAccountPicker_OneAccount_ShouldHaveOneAccount() {
- testBindAccountPickerInner(mViewHolder, ONE_ACCOUNT);
- }
-
- @Test
- public void testOnSpinnerItemClick_AddAccountClicked_AccountLoginIntentInvoked() {
- bindAccountPickerInner(mViewHolder, TWO_ACCOUNTS);
-
- final Spinner spinner = (Spinner) mViewHolder.itemView.findViewById(R.id.account_spinner);
- spinner.setSelection(TWO_ACCOUNTS.length);
-
- Robolectric.flushForegroundThreadScheduler();
-
- verify(mSupportFeatureProvider).getAccountLoginIntent();
- }
-
- @Test
- public void testSetAccount_AccountEmpty_NotCrash() {
- when(mSupportFeatureProvider.getSupportEligibleAccounts(mActivity)).thenReturn(
- ZERO_ACCOUNT);
- mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
- mMetricsFeatureProvider, null);
-
- // Should not crash in this method
- mSupportItemAdapter.setAccounts(ONE_ACCOUNT);
-
- verify(mSupportFeatureProvider).getSupportEligibleAccounts(mActivity);
- }
-
- @Test
- public void testRefreshData_CardUpdatedOnEnteringOrLeavingSupportHours() {
- // pretend we have support right now
- when(mSupportFeatureProvider.isSupportTypeEnabled(any(), anyInt()))
- .thenReturn(true);
- when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
- when(mSupportFeatureProvider.getSupportEligibleAccounts(any())).thenReturn(ONE_ACCOUNT);
- mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
- mMetricsFeatureProvider, null);
-
- // If this doesn't return escalation data something has gone wrong
- EscalationData data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
-
- // precondition, support is enabled
- assertThat(data.enabled1).isTrue();
-
- // pretend we support hours are over
- when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(false);
- mSupportItemAdapter.refreshData();
- data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
-
- assertThat(data.enabled1).isFalse();
-
- // pretend support hours have started again
- when(mSupportFeatureProvider.isOperatingNow(anyInt())).thenReturn(true);
- mSupportItemAdapter.refreshData();
- data = (EscalationData) mSupportItemAdapter.getSupportData().get(0);
-
- assertThat(data.enabled1).isTrue();
- }
-
- /**
- * Check after {@link SupportItemAdapter#bindAccountPicker(SupportItemAdapter.ViewHolder)} is
- * invoked, whether the spinner in {@paramref viewHolder} has all the data from {@paramref
- * accounts}
- *
- * @param viewHolder holds the view that contains the spinner to test
- * @param accounts holds the accounts info to be showed in spinner.
- */
- private void testBindAccountPickerInner(SupportItemAdapter.ViewHolder viewHolder,
- Account accounts[]) {
- bindAccountPickerInner(viewHolder, accounts);
-
- final Spinner spinner = (Spinner) viewHolder.itemView.findViewById(R.id.account_spinner);
- final SpinnerAdapter adapter = spinner.getAdapter();
-
- // Contains "Add account" option, so should be 'count+1'
- assertThat(adapter.getCount()).isEqualTo(accounts.length + 1);
- for (int i = 0; i < accounts.length; i++) {
- assertThat(adapter.getItem(i)).isEqualTo(accounts[i].name);
- }
- }
-
- /**
- * Create {@link SupportItemAdapter} and bind the account picker view into
- * {@paramref viewholder}
- *
- * @param viewHolder holds the view that contains the spinner to test
- * @param accounts holds the accounts info to be showed in spinner.
- */
- private void bindAccountPickerInner(SupportItemAdapter.ViewHolder viewHolder,
- Account accounts[]) {
- when(mSupportFeatureProvider.getSupportEligibleAccounts(mActivity)).thenReturn(accounts);
- mSupportItemAdapter = new SupportItemAdapter(mActivity, null, mSupportFeatureProvider,
- mMetricsFeatureProvider, null);
-
- mSupportItemAdapter.bindAccountPicker(viewHolder);
- }
-
-}
diff --git a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
index dc53ca1..c122105 100644
--- a/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/DataUsageSummaryTest.java
@@ -69,23 +69,6 @@
}
@Test
- public void testUpdateNetworkRestrictionSummary_shouldSetSummary() {
- final DataUsageSummary dataUsageSummary = spy(new DataUsageSummary());
- final NetworkRestrictionsPreference preference = mock(NetworkRestrictionsPreference.class);
- final NetworkPolicyEditor policyEditor = mock(NetworkPolicyEditor.class);
- final WifiManager wifiManager = mock(WifiManager.class);
- ReflectionHelpers.setField(dataUsageSummary, "mPolicyEditor", policyEditor);
- ReflectionHelpers.setField(dataUsageSummary, "mWifiManager", wifiManager);
- when(wifiManager.getConfiguredNetworks()).thenReturn(new ArrayList<WifiConfiguration>());
- doReturn(mContext.getResources()).when(dataUsageSummary).getResources();
-
- dataUsageSummary.updateNetworkRestrictionSummary(preference);
-
- verify(preference).setSummary(mContext.getResources().getQuantityString(
- R.plurals.network_restrictions_summary, 0, 0));
- }
-
- @Test
@Config(shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class
diff --git a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java
index a75e296..cf892f8 100644
--- a/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/BluetoothMaxConnectedAudioDevicesPreferenceControllerTest.java
@@ -94,6 +94,8 @@
BLUETOOTH_MAX_CONNECTED_AUDIO_DEVICES_PROPERTY);
assertThat(currentValue).isEqualTo(mListValues[numberOfDevices]);
+ assertThat(mPreference.getValue()).isEqualTo(mListValues[numberOfDevices]);
+ assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[numberOfDevices]);
}
}
@@ -122,20 +124,28 @@
@Test
public void onDeveloperOptionsSwitchDisabled_shouldDisablePreference() {
mController.onDeveloperOptionsSwitchDisabled();
- mController.updateState(mPreference);
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() {
- mController.onDeveloperOptionsSwitchEnabled();
- mController.updateState(mPreference);
+ for (int numberOfDevices = 0; numberOfDevices < mListValues.length; numberOfDevices++) {
+ mController.onDeveloperOptionsSwitchDisabled();
+ assertThat(mPreference.isEnabled()).isFalse();
- assertThat(mPreference.isEnabled()).isTrue();
- assertThat(mPreference.getValue()).isEqualTo(mListValues[0]);
- assertThat(mPreference.getSummary()).isEqualTo(mListSummaries[0]);
+ 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/development/CameraLaserSensorPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java
index 1443d16..7c8f318 100644
--- a/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/CameraLaserSensorPreferenceControllerTest.java
@@ -96,11 +96,11 @@
}
@Test
- public void isAvailable_withUserBuild_shouldReturnFalse() {
+ public void isAvailable_withUserBuild_shouldReturnTrue() {
SettingsShadowSystemProperties.set(
CameraLaserSensorPreferenceController.BUILD_TYPE, USER_BUILD);
- assertThat(mController.isAvailable()).isFalse();
+ assertThat(mController.isAvailable()).isTrue();
}
@Test
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/BatteryUtilsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
index 1393d57..844aca4 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryUtilsTest.java
@@ -20,7 +20,9 @@
import static android.os.BatteryStats.Uid.PROCESS_STATE_FOREGROUND_SERVICE;
import static android.os.BatteryStats.Uid.PROCESS_STATE_TOP;
import static android.os.BatteryStats.Uid.PROCESS_STATE_TOP_SLEEPING;
+
import static com.google.common.truth.Truth.assertThat;
+
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.anyLong;
@@ -141,6 +143,7 @@
private BatteryUtils mBatteryUtils;
private FakeFeatureFactory mFeatureFactory;
private PowerUsageFeatureProvider mProvider;
+ private List<BatterySipper> mUsageList;
@Before
public void setUp() {
@@ -194,6 +197,12 @@
mBatteryUtils.mPowerUsageFeatureProvider = mProvider;
doReturn(0L).when(mBatteryUtils).getForegroundServiceTotalTimeUs(
any(BatteryStats.Uid.class), anyLong());
+
+ mUsageList = new ArrayList<>();
+ mUsageList.add(mNormalBatterySipper);
+ mUsageList.add(mScreenBatterySipper);
+ mUsageList.add(mCellBatterySipper);
+ doReturn(mUsageList).when(mBatteryStatsHelper).getUsageList();
}
@Test
@@ -468,4 +477,28 @@
verify(mBatteryStatsHelper).refreshStats(BatteryStats.STATS_SINCE_CHARGED,
mUserManager.getUserProfiles());
}
+
+ @Test
+ public void testFindBatterySipperByType_findTypeScreen() {
+ BatterySipper sipper = mBatteryUtils.findBatterySipperByType(mUsageList,
+ BatterySipper.DrainType.SCREEN);
+
+ assertThat(sipper).isSameAs(mScreenBatterySipper);
+ }
+
+ @Test
+ public void testFindBatterySipperByType_findTypeApp() {
+ BatterySipper sipper = mBatteryUtils.findBatterySipperByType(mUsageList,
+ BatterySipper.DrainType.APP);
+
+ assertThat(sipper).isSameAs(mNormalBatterySipper);
+ }
+
+ @Test
+ public void testCalculateScreenUsageTime_returnCorrectTime() {
+ mScreenBatterySipper.usageTimeMs = TIME_EXPECTED_FOREGROUND;
+
+ assertThat(mBatteryUtils.calculateScreenUsageTime(mBatteryStatsHelper)).isEqualTo(
+ TIME_EXPECTED_FOREGROUND);
+ }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
index c992d0a..8aa0659 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageAnomalyDetailsTest.java
@@ -67,7 +67,6 @@
private static final String PACKAGE_NAME_1 = "com.android.app1";
private static final String PACKAGE_NAME_2 = "com.android.app2";
private static final String PACKAGE_NAME_3 = "com.android.app3";
- private static final int USER_ID = 1;
@Mock
private SettingsActivity mSettingsActivity;
@@ -198,16 +197,4 @@
assertThat(mBundle.getParcelableArrayList(
PowerUsageAnomalyDetails.EXTRA_ANOMALY_LIST)).isEqualTo(mAnomalyList);
}
-
- @Test
- public void testGetBadgedIcon_usePackageNameAndUserId() throws
- PackageManager.NameNotFoundException {
- doReturn(mApplicationInfo).when(mPackageManager).getApplicationInfo(PACKAGE_NAME_1,
- PackageManager.GET_META_DATA);
-
- mFragment.getBadgedIcon(PACKAGE_NAME_1, USER_ID);
-
- // Verify that it uses the correct user id
- verify(mIconDrawableFactory).getBadgedIcon(mApplicationInfo, USER_ID);
- }
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 2728909..6fecf3c 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -248,34 +248,6 @@
}
@Test
- public void testFindBatterySipperByType_findTypeScreen() {
- BatterySipper sipper = mFragment.findBatterySipperByType(mUsageList,
- BatterySipper.DrainType.SCREEN);
-
- assertThat(sipper).isSameAs(mScreenBatterySipper);
- }
-
- @Test
- public void testFindBatterySipperByType_findTypeApp() {
- BatterySipper sipper = mFragment.findBatterySipperByType(mUsageList,
- BatterySipper.DrainType.APP);
-
- assertThat(sipper).isSameAs(mNormalBatterySipper);
- }
-
- @Test
- public void testUpdateScreenPreference_showCorrectSummary() {
- doReturn(mScreenBatterySipper).when(mFragment).findBatterySipperByType(any(), any());
- doReturn(mRealContext).when(mFragment).getContext();
- final CharSequence expectedSummary = Utils.formatElapsedTime(mRealContext, USAGE_TIME_MS,
- false);
-
- mFragment.updateScreenPreference();
-
- assertThat(mScreenUsagePref.getSubtitle()).isEqualTo(expectedSummary);
- }
-
- @Test
public void testUpdateLastFullChargePreference_showCorrectSummary() {
doReturn(mRealContext).when(mFragment).getContext();
@@ -285,16 +257,6 @@
}
@Test
- public void testUpdatePreference_usageListEmpty_shouldNotCrash() {
- when(mBatteryHelper.getUsageList()).thenReturn(new ArrayList<BatterySipper>());
- doReturn(STUB_STRING).when(mFragment).getString(anyInt(), any());
- doReturn(mRealContext).when(mFragment).getContext();
-
- // Should not crash when update
- mFragment.updateScreenPreference();
- }
-
- @Test
public void testNonIndexableKeys_MatchPreferenceKeys() {
final Context context = RuntimeEnvironment.application;
final List<String> niks = PowerUsageSummary.SEARCH_INDEX_DATA_PROVIDER
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/RestrictAppPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/RestrictAppPreferenceControllerTest.java
new file mode 100644
index 0000000..c944148
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/RestrictAppPreferenceControllerTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.fuelgauge;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.app.AppOpsManager;
+import android.content.Context;
+import android.support.v7.preference.Preference;
+
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class RestrictAppPreferenceControllerTest {
+
+ @Mock
+ private AppOpsManager mAppOpsManager;
+ @Mock
+ private AppOpsManager.PackageOps mPackageOps;
+ private List<AppOpsManager.PackageOps> mPackageOpsList;
+ private RestrictAppPreferenceController mRestrictAppPreferenceController;
+ private Preference mPreference;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = spy(RuntimeEnvironment.application);
+ doReturn(mAppOpsManager).when(mContext).getSystemService(Context.APP_OPS_SERVICE);
+ mRestrictAppPreferenceController = new RestrictAppPreferenceController(mContext);
+ mPackageOpsList = new ArrayList<>();
+ mPreference = new Preference(mContext);
+ }
+
+ @Test
+ public void testUpdateState_oneApp_showCorrectSummary() {
+ mPackageOpsList.add(mPackageOps);
+ doReturn(mPackageOpsList).when(mAppOpsManager).getPackagesForOps(any());
+
+ mRestrictAppPreferenceController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo("1 app");
+ }
+
+ @Test
+ public void testUpdateState_twoApps_showCorrectSummary() {
+ mPackageOpsList.add(mPackageOps);
+ mPackageOpsList.add(mPackageOps);
+ doReturn(mPackageOpsList).when(mAppOpsManager).getPackagesForOps(any());
+
+ mRestrictAppPreferenceController.updateState(mPreference);
+
+ assertThat(mPreference.getSummary()).isEqualTo("2 apps");
+ }
+
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java
new file mode 100644
index 0000000..cc5fb30
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/SmartBatteryPreferenceControllerTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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.fuelgauge;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.provider.Settings;
+import android.support.v14.preference.SwitchPreference;
+
+import com.android.settings.TestConfig;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.MockitoAnnotations;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(RobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SmartBatteryPreferenceControllerTest {
+ private static final int ON = 1;
+ private static final int OFF = 0;
+
+ private SmartBatteryPreferenceController mController;
+ private SwitchPreference mPreference;
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ mController = new SmartBatteryPreferenceController(mContext);
+ mPreference = new SwitchPreference(mContext);
+ }
+
+ @Test
+ public void testUpdateState_smartBatteryOn_preferenceChecked() {
+ putSmartBatteryValue(ON);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isChecked()).isTrue();
+ }
+
+ @Test
+ public void testUpdateState_smartBatteryOff_preferenceUnchecked() {
+ putSmartBatteryValue(OFF);
+
+ mController.updateState(mPreference);
+
+ assertThat(mPreference.isChecked()).isFalse();
+ }
+
+ @Test
+ public void testUpdateState_checkPreference_smartBatteryOn() {
+ mController.onPreferenceChange(mPreference, true);
+
+ assertThat(getSmartBatteryValue()).isEqualTo(ON);
+ }
+
+ @Test
+ public void testUpdateState_unCheckPreference_smartBatteryOff() {
+ mController.onPreferenceChange(mPreference, false);
+
+ assertThat(getSmartBatteryValue()).isEqualTo(OFF);
+ }
+
+ private void putSmartBatteryValue(int value) {
+ Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.APP_STANDBY_ENABLED,
+ value);
+ }
+
+ private int getSmartBatteryValue() {
+ return Settings.Global.getInt(mContext.getContentResolver(),
+ Settings.Global.APP_STANDBY_ENABLED, ON);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java
index 944587f..9f0c61f 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/BatteryTipPreferenceControllerTest.java
@@ -85,7 +85,7 @@
mNewBatteryTips.add(new SummaryTip(BatteryTip.StateType.INVISIBLE));
mBatteryTipPreferenceController = new BatteryTipPreferenceController(mContext, KEY_PREF,
- mBatteryTipListener);
+ null, mBatteryTipListener);
mBatteryTipPreferenceController.mPreferenceGroup = mPreferenceGroup;
mBatteryTipPreferenceController.mPrefContext = mContext;
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java
new file mode 100644
index 0000000..2a71991
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/detectors/HighUsageDetectorTest.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.fuelgauge.batterytip.detectors;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.os.BatteryStats;
+import android.text.format.DateUtils;
+
+import com.android.internal.os.BatterySipper;
+import com.android.internal.os.BatteryStatsHelper;
+import com.android.settings.TestConfig;
+import com.android.settings.fuelgauge.BatteryInfo;
+import com.android.settings.fuelgauge.BatteryUtils;
+import com.android.settings.fuelgauge.batterytip.BatteryTipPolicy;
+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.util.ReflectionHelpers;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class HighUsageDetectorTest {
+ private Context mContext;
+ @Mock
+ private BatteryStatsHelper mBatteryStatsHelper;
+ @Mock
+ private BatteryUtils mBatteryUtils;
+ @Mock
+ private BatterySipper mBatterySipper;
+
+ private BatteryTipPolicy mPolicy;
+ private HighUsageDetector mHighUsageDetector;
+ private List<BatterySipper> mUsageList;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ mContext = RuntimeEnvironment.application;
+ mPolicy = spy(new BatteryTipPolicy(mContext));
+ mHighUsageDetector = new HighUsageDetector(mContext, mPolicy, mBatteryStatsHelper);
+ mHighUsageDetector.mBatteryUtils = mBatteryUtils;
+
+ mUsageList = new ArrayList<>();
+ mUsageList.add(mBatterySipper);
+ }
+
+ @Test
+ public void testDetect_disabledByPolicy_tipInvisible() {
+ ReflectionHelpers.setField(mPolicy, "highUsageEnabled", false);
+
+ assertThat(mHighUsageDetector.detect().isVisible()).isFalse();
+ }
+
+ @Test
+ public void testDetect_containsHighUsageApp_tipVisible() {
+ doReturn(2 * DateUtils.HOUR_IN_MILLIS).when(mBatteryUtils).calculateScreenUsageTime(
+ mBatteryStatsHelper);
+ doReturn(mUsageList).when(mBatteryStatsHelper).getUsageList();
+ doReturn(DateUtils.HOUR_IN_MILLIS).when(mBatteryUtils).getProcessTimeMs(
+ BatteryUtils.StatusType.FOREGROUND, mBatterySipper.uidObj,
+ BatteryStats.STATS_SINCE_CHARGED);
+
+ assertThat(mHighUsageDetector.detect().isVisible()).isTrue();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
index eec8e76..1c6c868 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/BatteryTipTest.java
@@ -19,6 +19,8 @@
import android.app.Dialog;
import android.content.Context;
+import android.os.Parcel;
+import android.os.Parcelable;
import android.support.annotation.IdRes;
import android.support.v7.preference.Preference;
@@ -58,10 +60,32 @@
assertThat(preference.getIcon()).isEqualTo(mContext.getDrawable(ICON_ID));
}
+ @Test
+ public void testParcelable() {
+ final BatteryTip batteryTip = new TestBatteryTip();
+
+ Parcel parcel = Parcel.obtain();
+ batteryTip.writeToParcel(parcel, batteryTip.describeContents());
+ parcel.setDataPosition(0);
+
+ final BatteryTip parcelTip = new TestBatteryTip(parcel);
+
+ assertThat(parcelTip.getTitle(mContext)).isEqualTo(TITLE);
+ assertThat(parcelTip.getSummary(mContext)).isEqualTo(SUMMARY);
+ assertThat(parcelTip.getIconId()).isEqualTo(ICON_ID);
+ }
+
/**
* Used to test the non abstract methods in {@link TestBatteryTip}
*/
- public class TestBatteryTip extends BatteryTip {
+ public static class TestBatteryTip extends BatteryTip {
+ TestBatteryTip() {
+ super(TipType.SUMMARY, StateType.NEW, true);
+ }
+
+ TestBatteryTip(Parcel in) {
+ super(in);
+ }
@Override
public String getTitle(Context context) {
@@ -88,10 +112,15 @@
// do nothing
}
- @Override
- public Dialog buildDialog() {
- return null;
- }
+ public final Parcelable.Creator CREATOR = new Parcelable.Creator() {
+ public BatteryTip createFromParcel(Parcel in) {
+ return new TestBatteryTip(in);
+ }
+
+ public BatteryTip[] newArray(int size) {
+ return new TestBatteryTip[size];
+ }
+ };
}
}
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java
new file mode 100644
index 0000000..e2f8a26
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/fuelgauge/batterytip/tips/HighUsageTipTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.fuelgauge.batterytip.tips;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.os.Parcel;
+import android.text.format.DateUtils;
+
+import com.android.settings.TestConfig;
+import com.android.settings.fuelgauge.batterytip.HighUsageApp;
+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;
+
+import java.util.ArrayList;
+import java.util.List;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class HighUsageTipTest {
+ private static final String PACKAGE_NAME = "com.android.app";
+ private static final long SCREEN_TIME = 30 * DateUtils.MINUTE_IN_MILLIS;
+
+ private Context mContext;
+ private HighUsageTip mBatteryTip;
+ private List<HighUsageApp> mUsageAppList;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+
+ mUsageAppList = new ArrayList<>();
+ mUsageAppList.add(new HighUsageApp(PACKAGE_NAME, SCREEN_TIME));
+ mBatteryTip = new HighUsageTip(SCREEN_TIME, mUsageAppList);
+ }
+
+ @Test
+ public void testParcelable() {
+
+ Parcel parcel = Parcel.obtain();
+ mBatteryTip.writeToParcel(parcel, mBatteryTip.describeContents());
+ parcel.setDataPosition(0);
+
+ final HighUsageTip parcelTip = new HighUsageTip(parcel);
+
+ assertThat(parcelTip.getTitle(mContext)).isEqualTo("Phone used heavily");
+ assertThat(parcelTip.getType()).isEqualTo(BatteryTip.TipType.HIGH_DEVICE_USAGE);
+ assertThat(parcelTip.getState()).isEqualTo(BatteryTip.StateType.NEW);
+ assertThat(parcelTip.getScreenTimeMs()).isEqualTo(SCREEN_TIME);
+ assertThat(parcelTip.mHighUsageAppList.size()).isEqualTo(1);
+ final HighUsageApp app = parcelTip.mHighUsageAppList.get(0);
+ assertThat(app.packageName).isEqualTo(PACKAGE_NAME);
+ assertThat(app.screenOnTimeMs).isEqualTo(SCREEN_TIME);
+ }
+}
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/notification/ZenModeRepeatCallersPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/ZenModeRepeatCallersPreferenceControllerTest.java
index ba52ce2..a7ea4c9 100644
--- a/tests/robotests/src/com/android/settings/notification/ZenModeRepeatCallersPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/notification/ZenModeRepeatCallersPreferenceControllerTest.java
@@ -78,7 +78,8 @@
mContentResolver = RuntimeEnvironment.application.getContentResolver();
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
- mController = new ZenModeRepeatCallersPreferenceController(mContext, mock(Lifecycle.class));
+ mController = new ZenModeRepeatCallersPreferenceController(mContext, mock(Lifecycle.class),
+ 15);
ReflectionHelpers.setField(mController, "mBackend", mBackend);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(
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 81e1481..3171c3d 100644
--- a/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java
+++ b/tests/robotests/src/com/android/settings/security/SecuritySettingsTest.java
@@ -23,13 +23,10 @@
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;
@@ -87,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);
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/slices/FakeToggleController.java b/tests/robotests/src/com/android/settings/slices/FakeToggleController.java
new file mode 100644
index 0000000..1b08e35
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/slices/FakeToggleController.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.android.settings.slices;
+
+import android.content.Context;
+import android.provider.Settings;
+
+import com.android.settings.core.TogglePreferenceController;
+
+public class FakeToggleController extends TogglePreferenceController {
+
+ private String settingKey = "toggle_key";
+
+ private final int ON = 1;
+ private final int OFF = 0;
+
+ public FakeToggleController(Context context, String preferenceKey) {
+ super(context, preferenceKey);
+ }
+
+ @Override
+ public boolean isChecked() {
+ return Settings.System.getInt(mContext.getContentResolver(),
+ settingKey, OFF) == ON;
+ }
+
+ @Override
+ public boolean setChecked(boolean isChecked) {
+ return Settings.System.putInt(mContext.getContentResolver(), settingKey,
+ isChecked ? ON : OFF);
+ }
+
+ @Override
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
new file mode 100644
index 0000000..2af15e2
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/slices/SettingsSliceProviderTest.java
@@ -0,0 +1,97 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.android.settings.slices;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.ContentResolver;
+import android.database.sqlite.SQLiteDatabase;
+import android.net.Uri;
+
+import com.android.settings.TestConfig;
+import com.android.settings.testutils.DatabaseTestUtils;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import androidx.app.slice.Slice;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SettingsSliceProviderTest {
+
+ private final String fakeTitle = "title";
+ private final String KEY = "key";
+
+ private Context mContext;
+ private SettingsSliceProvider mProvider;
+ private SQLiteDatabase mDb;
+
+ @Before
+ public void setUp() {
+ mContext = spy(RuntimeEnvironment.application);
+ mProvider = spy(new SettingsSliceProvider());
+ mDb = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
+ SlicesDatabaseHelper.getInstance(mContext).setIndexedState();
+ }
+
+ @After
+ public void cleanUp() {
+ DatabaseTestUtils.clearDb(mContext);
+ }
+
+ @Test
+ public void testInitialSliceReturned_emmptySlice() {
+ Uri uri = SettingsSliceProvider.getUri(KEY);
+ Slice slice = mProvider.onBindSlice(uri);
+
+ assertThat(slice.getUri()).isEqualTo(uri);
+ assertThat(slice.getItems()).isEmpty();
+ }
+
+ @Test
+ public void testUriBuilder_returnsValidSliceUri() {
+ Uri uri = SettingsSliceProvider.getUri(KEY);
+
+ assertThat(uri.getScheme()).isEqualTo(ContentResolver.SCHEME_CONTENT);
+ assertThat(uri.getAuthority()).isEqualTo(SettingsSliceProvider.SLICE_AUTHORITY);
+ assertThat(uri.getLastPathSegment()).isEqualTo(KEY);
+ }
+
+ private void insertSpecialCase(String key) {
+ ContentValues values = new ContentValues();
+ values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
+ values.put(SlicesDatabaseHelper.IndexColumns.TITLE, fakeTitle);
+ values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, "s");
+ values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, "s");
+ values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, 1234);
+ values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, "test");
+ values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, "test");
+
+ mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java b/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java
new file mode 100644
index 0000000..efd1cc5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/slices/SliceBroadcastReceiverTest.java
@@ -0,0 +1,121 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.android.settings.slices;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.content.Intent;
+import android.database.sqlite.SQLiteDatabase;
+
+import com.android.settings.TestConfig;
+import com.android.settings.search.FakeIndexProvider;
+import com.android.settings.search.SearchIndexableResources;
+import com.android.settings.testutils.DatabaseTestUtils;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+import java.util.HashSet;
+import java.util.Set;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class SliceBroadcastReceiverTest {
+
+ private final String fakeTitle = "title";
+ private final String fakeSummary = "summary";
+ private final String fakeScreenTitle = "screen_title";
+ private final int fakeIcon = 1234;
+ private final String fakeFragmentClassName = FakeIndexProvider.class.getName();
+ private final String fakeControllerName = FakeToggleController.class.getName();
+
+ private Context mContext;
+ private SQLiteDatabase mDb;
+ private SliceBroadcastReceiver mReceiver;
+
+ private Set<Class> mProviderClassesCopy;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mDb = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
+ mReceiver = new SliceBroadcastReceiver();
+ mProviderClassesCopy = new HashSet<>(SearchIndexableResources.providerValues());
+ SlicesDatabaseHelper helper = SlicesDatabaseHelper.getInstance(mContext);
+ helper.setIndexedState();
+ }
+
+ @After
+ public void cleanUp() {
+ DatabaseTestUtils.clearDb(mContext);
+ SearchIndexableResources.providerValues().clear();
+ SearchIndexableResources.providerValues().addAll(mProviderClassesCopy);
+ }
+
+ @Test
+ public void testOnReceive_toggleChanged() {
+ String key = "key";
+ SearchIndexableResources.providerValues().clear();
+ insertSpecialCase(key);
+ // Turn on toggle setting
+ FakeToggleController fakeToggleController = new FakeToggleController(mContext, key);
+ fakeToggleController.setChecked(true);
+ Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
+ intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, key);
+
+ assertThat(fakeToggleController.isChecked()).isTrue();
+
+ // Toggle setting
+ mReceiver.onReceive(mContext, intent);
+
+ assertThat(fakeToggleController.isChecked()).isFalse();
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testOnReceive_noExtra_illegalSatetException() {
+ Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
+ mReceiver.onReceive(mContext, intent);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testOnReceive_emptyKey_throwsIllegalStateException() {
+ Intent intent = new Intent(SettingsSliceProvider.ACTION_TOGGLE_CHANGED);
+ intent.putExtra(SettingsSliceProvider.EXTRA_SLICE_KEY, (String) null);
+ mReceiver.onReceive(mContext, intent);
+ }
+
+ private void insertSpecialCase(String key) {
+ ContentValues values = new ContentValues();
+ values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
+ values.put(SlicesDatabaseHelper.IndexColumns.TITLE, fakeTitle);
+ values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, fakeSummary);
+ values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, fakeScreenTitle);
+ values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, fakeIcon);
+ values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, fakeFragmentClassName);
+ values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, fakeControllerName);
+
+ mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
+ }
+}
\ No newline at end of file
diff --git a/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java
new file mode 100644
index 0000000..106e6fe
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseAccessorTest.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package com.android.settings.slices;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.spy;
+
+import android.content.ContentValues;
+import android.content.Context;
+import android.database.sqlite.SQLiteDatabase;
+import android.net.Uri;
+
+import com.android.settings.TestConfig;
+import com.android.settings.search.FakeIndexProvider;
+import com.android.settings.testutils.DatabaseTestUtils;
+import com.android.settings.testutils.SettingsRobolectricTestRunner;
+
+import org.junit.After;
+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 SlicesDatabaseAccessorTest {
+
+ private final String fakeTitle = "title";
+ private final String fakeSummary = "summary";
+ private final String fakeScreenTitle = "screen_title";
+ private final int fakeIcon = 1234;
+ private final String fakeFragmentClassName = FakeIndexProvider.class.getName();
+ private final String fakeControllerName = FakePreferenceController.class.getName();
+
+ private Context mContext;
+ private SQLiteDatabase mDb;
+ private SlicesDatabaseAccessor mAccessor;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mAccessor = spy(new SlicesDatabaseAccessor(mContext));
+ mDb = SlicesDatabaseHelper.getInstance(mContext).getWritableDatabase();
+ SlicesDatabaseHelper.getInstance(mContext).setIndexedState();
+ }
+
+ @After
+ public void cleanUp() {
+ DatabaseTestUtils.clearDb(mContext);
+ }
+
+ @Test
+ public void testGetSliceDataFromKey_validKey_validSliceReturned() {
+ String key = "key";
+ insertSpecialCase(key);
+
+ SliceData data = mAccessor.getSliceDataFromKey(key);
+
+ assertThat(data.getKey()).isEqualTo(key);
+ assertThat(data.getTitle()).isEqualTo(fakeTitle);
+ assertThat(data.getSummary()).isEqualTo(fakeSummary);
+ assertThat(data.getScreenTitle()).isEqualTo(fakeScreenTitle);
+ assertThat(data.getIconResource()).isEqualTo(fakeIcon);
+ assertThat(data.getFragmentClassName()).isEqualTo(fakeFragmentClassName);
+ assertThat(data.getUri()).isNull();
+ assertThat(data.getPreferenceController()).isEqualTo(fakeControllerName);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testGetSliceDataFromKey_invalidKey_errorThrown() {
+ String key = "key";
+
+ mAccessor.getSliceDataFromKey(key);
+ }
+
+ @Test
+ public void testGetSliceFromUri_validUri_validSliceReturned() {
+ String key = "key";
+ insertSpecialCase(key);
+ Uri uri = SettingsSliceProvider.getUri(key);
+
+ SliceData data = mAccessor.getSliceDataFromUri(uri);
+
+ assertThat(data.getKey()).isEqualTo(key);
+ assertThat(data.getTitle()).isEqualTo(fakeTitle);
+ assertThat(data.getSummary()).isEqualTo(fakeSummary);
+ assertThat(data.getScreenTitle()).isEqualTo(fakeScreenTitle);
+ assertThat(data.getIconResource()).isEqualTo(fakeIcon);
+ assertThat(data.getFragmentClassName()).isEqualTo(fakeFragmentClassName);
+ assertThat(data.getUri()).isEqualTo(uri);
+ assertThat(data.getPreferenceController()).isEqualTo(fakeControllerName);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void testGetSliceFromUri_invalidUri_errorThrown() {
+ Uri uri = SettingsSliceProvider.getUri("durr");
+
+ mAccessor.getSliceDataFromUri(uri);
+ }
+
+ private void insertSpecialCase(String key) {
+ ContentValues values = new ContentValues();
+ values.put(SlicesDatabaseHelper.IndexColumns.KEY, key);
+ values.put(SlicesDatabaseHelper.IndexColumns.TITLE, fakeTitle);
+ values.put(SlicesDatabaseHelper.IndexColumns.SUMMARY, fakeSummary);
+ values.put(SlicesDatabaseHelper.IndexColumns.SCREENTITLE, fakeScreenTitle);
+ values.put(SlicesDatabaseHelper.IndexColumns.ICON_RESOURCE, fakeIcon);
+ values.put(SlicesDatabaseHelper.IndexColumns.FRAGMENT, fakeFragmentClassName);
+ values.put(SlicesDatabaseHelper.IndexColumns.CONTROLLER, fakeControllerName);
+
+ mDb.replaceOrThrow(SlicesDatabaseHelper.Tables.TABLE_SLICES_INDEX, null, values);
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/slices/SlicesDatabaseUtilsTest.java b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseUtilsTest.java
new file mode 100644
index 0000000..f22e85f
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/slices/SlicesDatabaseUtilsTest.java
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.settings.slices;
+
+import static com.android.settings.TestConfig.SDK_VERSION;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+import android.net.Uri;
+
+import com.android.settings.TestConfig;
+import com.android.settings.core.BasePreferenceController;
+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;
+
+import androidx.app.slice.Slice;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = SDK_VERSION)
+public class SlicesDatabaseUtilsTest {
+
+ private final String KEY = "KEY";
+ private final String TITLE = "title";
+ private final String SUMMARY = "summary";
+ private final String SCREEN_TITLE = "screen title";
+ private final String FRAGMENT_NAME = "fragment name";
+ private final int ICON = 1234; // I declare a thumb war
+ private final Uri URI = Uri.parse("content://com.android.settings.slices/test");
+ private final String PREF_CONTROLLER = FakeToggleController.class.getName();
+ ;
+
+ private Context mContext;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ }
+
+ @Test
+ public void testBuildSlice_returnsMatchingSlice() {
+ Slice slice = SliceBuilderUtils.buildSlice(mContext, getDummyData());
+
+ assertThat(slice).isNotNull(); // TODO improve test for Slice content
+ }
+
+ @Test
+ public void testGetPreferenceController_buildsMatchingController() {
+ BasePreferenceController controller = SliceBuilderUtils.getPreferenceController(mContext,
+ getDummyData());
+
+ assertThat(controller).isInstanceOf(FakeToggleController.class);
+ }
+
+ private SliceData getDummyData() {
+ return new SliceData.Builder()
+ .setKey(KEY)
+ .setTitle(TITLE)
+ .setSummary(SUMMARY)
+ .setScreenTitle(SCREEN_TITLE)
+ .setIcon(ICON)
+ .setFragmentName(FRAGMENT_NAME)
+ .setUri(URI)
+ .setPreferenceControllerClassName(PREF_CONTROLLER)
+ .build();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java b/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
deleted file mode 100644
index 6aebe36..0000000
--- a/tests/robotests/src/com/android/settings/support/SupportDisclaimerDialogFragmentTest.java
+++ /dev/null
@@ -1,119 +0,0 @@
-package com.android.settings.support;
-
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.robolectric.shadow.api.Shadow.directlyOn;
-
-import android.accounts.Account;
-import android.annotation.NonNull;
-import android.annotation.StringRes;
-import android.app.Dialog;
-import android.content.Context;
-import android.content.res.Resources;
-import android.content.res.Resources.NotFoundException;
-import android.text.Spannable;
-import android.text.style.URLSpan;
-import android.widget.CheckBox;
-
-import com.android.internal.logging.nano.MetricsProto;
-import com.android.settings.R;
-import com.android.settings.TestConfig;
-import com.android.settings.core.instrumentation.MetricsFeatureProvider;
-import com.android.settings.overlay.SupportFeatureProvider;
-import com.android.settings.overlay.SupportFeatureProvider.SupportType;
-import com.android.settings.support.SupportDisclaimerDialogFragmentTest.SupportDisclaimerShadowResources;
-import com.android.settings.testutils.FakeFeatureFactory;
-import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.testutils.shadow.SettingsShadowResources;
-
-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;
-import org.robolectric.annotation.Implementation;
-import org.robolectric.annotation.Implements;
-import org.robolectric.util.FragmentTestUtil;
-
-@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
- shadows = {SupportDisclaimerShadowResources.class})
-public class SupportDisclaimerDialogFragmentTest {
-
- @Mock(answer = Answers.RETURNS_DEEP_STUBS)
- Context mContext;
- private FakeFeatureFactory mFakeFeatureFactory;
- private MetricsFeatureProvider mMetricsFeatureProvider;
- private SupportFeatureProvider mSupportFeatureProvider;
-
- private final Account mFakeAccount = new Account("user1", "fake_type");
-
- private static final int FAKE_RES_ID = -1000;
-
- @Before
- public void setUp() {
- MockitoAnnotations.initMocks(this);
- mFakeFeatureFactory = FakeFeatureFactory.setupForTest();
- mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
- mSupportFeatureProvider = mFakeFeatureFactory.getSupportFeatureProvider(mContext);
- when(mSupportFeatureProvider.getDisclaimerStringResId())
- .thenReturn(FAKE_RES_ID);
- }
-
- @Test
- public void onClick_DoNotShowCheckedLogsAction() {
- SupportDisclaimerDialogFragment fragment =
- SupportDisclaimerDialogFragment.newInstance(mFakeAccount, SupportType.CHAT);
- FragmentTestUtil.startFragment(fragment);
-
- // pretend the user selected to skip the dialog in the future
- CheckBox doNotShow = (CheckBox) fragment.getDialog()
- .findViewById(R.id.support_disclaimer_do_not_show_again);
- doNotShow.setChecked(true);
-
- // verify we logged the action
- fragment.onClick(fragment.getDialog(), Dialog.BUTTON_POSITIVE);
- verify(mMetricsFeatureProvider, times(1)).action(any(),
- eq(MetricsProto.MetricsEvent.ACTION_SKIP_DISCLAIMER_SELECTED));
- }
-
- @Test
- public void onClick_DoNotShowUncheckedDoesNotLogAction() {
- SupportDisclaimerDialogFragment fragment =
- SupportDisclaimerDialogFragment.newInstance(mFakeAccount, SupportType.CHAT);
- FragmentTestUtil.startFragment(fragment);
-
- // pretend the user selected to skip the dialog in the future
- CheckBox doNotShow = (CheckBox) fragment.getDialog()
- .findViewById(R.id.support_disclaimer_do_not_show_again);
- doNotShow.setChecked(false);
-
- // verify we logged the action
- fragment.onClick(fragment.getDialog(), Dialog.BUTTON_POSITIVE);
- verify(mMetricsFeatureProvider, never()).action(any(),
- eq(MetricsProto.MetricsEvent.ACTION_SKIP_DISCLAIMER_SELECTED));
- }
-
- @Implements(Resources.class)
- public static class SupportDisclaimerShadowResources extends SettingsShadowResources {
-
- @Implementation
- @NonNull public CharSequence getText(@StringRes int id) throws NotFoundException {
- if (id == FAKE_RES_ID) {
- Spannable text = Spannable.Factory.getInstance()
- .newSpannable("string with url");
- text.setSpan(new URLSpan("https://google.com"), 0, 1,
- Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
- return text;
- }
- return directlyOn(realResources, Resources.class).getText(id);
- }
- }
-
-}
diff --git a/tests/robotests/src/com/android/settings/wifi/details/WifiMeteredPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/details/WifiMeteredPreferenceControllerTest.java
new file mode 100644
index 0000000..f624bd5
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/wifi/details/WifiMeteredPreferenceControllerTest.java
@@ -0,0 +1,89 @@
+/*
+ * 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.wifi.details;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.spy;
+
+import android.content.Context;
+import android.net.wifi.WifiConfiguration;
+import android.support.v7.preference.DropDownPreference;
+
+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.mockito.Mock;
+import org.robolectric.RuntimeEnvironment;
+import org.robolectric.annotation.Config;
+
+@RunWith(SettingsRobolectricTestRunner.class)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
+public class WifiMeteredPreferenceControllerTest {
+ public static final int METERED_OVERRIDE_NONE = 0;
+ public static final int METERED_OVERRIDE_METERED = 1;
+ public static final int METERED_OVERRIDE_NOT_METERED = 2;
+
+ @Mock
+ private WifiConfiguration mWifiConfiguration;
+
+ private WifiMeteredPreferenceController mPreferenceController;
+ private Context mContext;
+ private DropDownPreference mDropDownPreference;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+
+ mPreferenceController = spy(
+ new WifiMeteredPreferenceController(mContext, mWifiConfiguration));
+ mDropDownPreference = new DropDownPreference(mContext);
+ mDropDownPreference.setEntries(R.array.wifi_metered_entries);
+ mDropDownPreference.setEntryValues(R.array.wifi_metered_values);
+ }
+
+ @Test
+ public void testUpdateState_wifiMetered_setCorrectValue() {
+ doReturn(METERED_OVERRIDE_METERED).when(mPreferenceController).getMeteredOverride();
+
+ mPreferenceController.updateState(mDropDownPreference);
+
+ assertThat(mDropDownPreference.getEntry()).isEqualTo("Treat as metered");
+ }
+
+ @Test
+ public void testUpdateState_wifiNotMetered_setCorrectValue() {
+ doReturn(METERED_OVERRIDE_NOT_METERED).when(mPreferenceController).getMeteredOverride();
+
+ mPreferenceController.updateState(mDropDownPreference);
+
+ assertThat(mDropDownPreference.getEntry()).isEqualTo("Treat as unmetered");
+ }
+
+ @Test
+ public void testUpdateState_wifiAuto_setCorrectValue() {
+ doReturn(METERED_OVERRIDE_NONE).when(mPreferenceController).getMeteredOverride();
+
+ mPreferenceController.updateState(mDropDownPreference);
+
+ assertThat(mDropDownPreference.getEntry()).isEqualTo("Use network preference");
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
index a40cce6..2a39515 100644
--- a/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/wifi/tether/WifiTetherPreferenceControllerTest.java
@@ -137,7 +137,6 @@
mController.displayPreference(mScreen);
mLifecycle.handleLifecycleEvent(ON_START);
- assertThat(ShadowWifiTetherSwitchBarController.onStartCalled).isTrue();
verify(mContext).registerReceiver(eq(receiver), any(IntentFilter.class));
verify(pref).setChecked(false);
}
diff --git a/tests/unit/src/com/android/settings/core/UserRestrictionTest.java b/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
index ad00bd7..da09d3c 100644
--- a/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
+++ b/tests/unit/src/com/android/settings/core/UserRestrictionTest.java
@@ -63,7 +63,8 @@
UserManager.DISALLOW_FACTORY_RESET,
UserManager.DISALLOW_CONFIG_TETHERING,
UserManager.DISALLOW_CONFIG_VPN,
- UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS
+ UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS,
+ UserManager.DISALLOW_AIRPLANE_MODE
);
@Before