Merge "Fix Auto click (dwell timing) the checked option isn't the same as the option before upgrading the OS" into rvc-dev
diff --git a/res/drawable/ic_accessibility_new.xml b/res/drawable/ic_accessibility_new.xml
index 1347239..265259c 100644
--- a/res/drawable/ic_accessibility_new.xml
+++ b/res/drawable/ic_accessibility_new.xml
@@ -15,8 +15,8 @@
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
+ android:width="18dp"
+ android:height="18dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?android:attr/colorControlNormal">
diff --git a/res/drawable/ic_accessibility_page_indicator.xml b/res/drawable/ic_accessibility_page_indicator.xml
new file mode 100644
index 0000000..4fa8204
--- /dev/null
+++ b/res/drawable/ic_accessibility_page_indicator.xml
@@ -0,0 +1,26 @@
+<!--
+ Copyright (C) 2020 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"
+ android:viewportHeight="24"
+ android:tint="?android:attr/colorControlNormal">
+ <path
+ android:pathData="M12,12m-8,0a8,8 0,1 1,16 0a8,8 0,1 1,-16 0"
+ android:fillColor="#FFFFFF"/>
+</vector>
diff --git a/res/drawable/ic_apps.xml b/res/drawable/ic_apps.xml
index 841c25a..8e9ba82 100644
--- a/res/drawable/ic_apps.xml
+++ b/res/drawable/ic_apps.xml
@@ -25,5 +25,5 @@
2zm4-8c0 1.1 .9 2 2 2s2-.9 2-2-.9-2-2-2-2 .9-2 2zm-4 2c1.1 0 2-.9
2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm6 6c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2
2zm0 6c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2z"
- android:fillColor="#FFFFFFFF"/>
+ android:fillColor="?android:attr/colorPrimary"/>
</vector>
diff --git a/res/drawable/ic_devices_other.xml b/res/drawable/ic_devices_other.xml
index c7b6cf2..5ef9f16 100644
--- a/res/drawable/ic_devices_other.xml
+++ b/res/drawable/ic_devices_other.xml
@@ -20,7 +20,7 @@
android:viewportHeight="24"
android:viewportWidth="24">
<path
- android:fillColor="@android:color/white"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M3,6h18V4H3C1.9,4 1,4.9 1,6v12c0,1.1 0.9,2 2,2h4v-2H3V6zM13,12H9v1.78C8.39,14.33 8,15.11 8,16c0,0.89 0.39,1.67 1,2.22V20h4v-1.78c0.61,-0.55 1,-1.34 1,-2.22s-0.39,-1.67 -1,-2.22V12zM11,17.5c-0.83,0 -1.5,-0.67 -1.5,-1.5s0.67,-1.5 1.5,-1.5s1.5,0.67 1.5,1.5S11.83,17.5 11,17.5zM22,8h-6c-0.5,0 -1,0.5 -1,1v10c0,0.5 0.5,1 1,1h6c0.5,0 1,-0.5 1,-1V9C23,8.5 22.5,8 22,8zM21,18h-4v-8h4V18z"/>
</vector>
diff --git a/res/drawable/ic_help.xml b/res/drawable/ic_help.xml
index f8bac71..c0afa14 100644
--- a/res/drawable/ic_help.xml
+++ b/res/drawable/ic_help.xml
@@ -19,6 +19,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M11,18h2v-2h-2V18zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10s10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8s8,3.59 8,8S16.41,20 12,20zM12,6c-2.21,0 -4,1.79 -4,4h2c0,-1.1 0.9,-2 2,-2s2,0.9 2,2c0,2 -3,1.75 -3,5h2c0,-2.25 3,-2.5 3,-5C16,7.79 14.21,6 12,6z"/>
</vector>
diff --git a/res/drawable/ic_phone_info.xml b/res/drawable/ic_phone_info.xml
index 7aee3e8..e0b64ee 100644
--- a/res/drawable/ic_phone_info.xml
+++ b/res/drawable/ic_phone_info.xml
@@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M17,1.01L7,1C5.9,1 5,1.9 5,3v18c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2V3C19,1.9 18.1,1.01 17,1.01zM17,21H7v-1h10V21zM17,18H7V6h10V18zM7,4V3h10v1H7zM11,7h2v2h-2V7zM11,11h2v6h-2V11z"/>
</vector>
diff --git a/res/drawable/ic_settings_accessibility.xml b/res/drawable/ic_settings_accessibility.xml
index d5c89b9..0055a65 100644
--- a/res/drawable/ic_settings_accessibility.xml
+++ b/res/drawable/ic_settings_accessibility.xml
@@ -19,9 +19,9 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M20.5,4c-2.61,0.7 -5.67,1 -8.5,1S6.11,4.7 3.5,4L3,6c1.86,0.5 4,0.83 6,1v13h2v-6h2v6h2V7c2,-0.17 4.14,-0.5 6,-1L20.5,4zM12,4c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2s-2,0.9 -2,2S10.9,4 12,4z"/>
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M7,24h2v-2H7V24zM11,24h2v-2h-2V24zM15,24h2v-2h-2V24z"/>
</vector>
diff --git a/res/drawable/ic_settings_accounts.xml b/res/drawable/ic_settings_accounts.xml
index 7f18286..50dcf76 100644
--- a/res/drawable/ic_settings_accounts.xml
+++ b/res/drawable/ic_settings_accounts.xml
@@ -19,9 +19,9 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M19,3H5C3.89,3 3,3.9 3,5v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5C21,3.9 20.1,3 19,3zM19,5v10.79C16.52,14.37 13.23,14 12,14s-4.52,0.37 -7,1.79V5H19zM5,19v-0.77C6.74,16.66 10.32,16 12,16s5.26,0.66 7,2.23V19H5z"/>
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M12,13c1.94,0 3.5,-1.56 3.5,-3.5C15.5,7.56 13.94,6 12,6c-1.94,0 -3.5,1.56 -3.5,3.5C8.5,11.44 10.06,13 12,13zM12,8c0.83,0 1.5,0.67 1.5,1.5c0,0.83 -0.67,1.5 -1.5,1.5c-0.83,0 -1.5,-0.67 -1.5,-1.5C10.5,8.67 11.17,8 12,8z"/>
</vector>
diff --git a/res/drawable/ic_settings_battery_white.xml b/res/drawable/ic_settings_battery_white.xml
index 255b75e..d1f91c5 100644
--- a/res/drawable/ic_settings_battery_white.xml
+++ b/res/drawable/ic_settings_battery_white.xml
@@ -19,6 +19,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M15.67,4H14V2h-4v2H8.33C7.6,4 7,4.6 7,5.33v15.33C7,21.4 7.6,22 8.33,22h7.33c0.74,0 1.34,-0.6 1.34,-1.33V5.33C17,4.6 16.4,4 15.67,4z"/>
</vector>
diff --git a/res/drawable/ic_settings_display_white.xml b/res/drawable/ic_settings_display_white.xml
index 62dc21f..96be116 100644
--- a/res/drawable/ic_settings_display_white.xml
+++ b/res/drawable/ic_settings_display_white.xml
@@ -19,6 +19,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M20,8.69V4h-4.69L12,0.69L8.69,4H4v4.69L0.69,12L4,15.31V20h4.69L12,23.31L15.31,20H20v-4.69L23.31,12L20,8.69zM18,14.48V18h-3.52L12,20.48L9.52,18H6v-3.52L3.52,12L6,9.52V6h3.52L12,3.52L14.48,6H18v3.52L20.48,12L18,14.48zM12,17c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5V17z"/>
</vector>
diff --git a/res/drawable/ic_settings_location.xml b/res/drawable/ic_settings_location.xml
index b7cfd6f..e1156a9 100644
--- a/res/drawable/ic_settings_location.xml
+++ b/res/drawable/ic_settings_location.xml
@@ -19,9 +19,9 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13C19,5.13 15.87,2 12,2zM7,9c0,-2.76 2.24,-5 5,-5s5,2.24 5,5c0,2.88 -2.88,7.19 -5,9.88C9.92,16.21 7,11.85 7,9z"/>
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M12,9m-2.5,0a2.5,2.5 0,1 1,5 0a2.5,2.5 0,1 1,-5 0"/>
</vector>
diff --git a/res/drawable/ic_settings_privacy.xml b/res/drawable/ic_settings_privacy.xml
index fcad83a..cdb2ac6 100644
--- a/res/drawable/ic_settings_privacy.xml
+++ b/res/drawable/ic_settings_privacy.xml
@@ -20,12 +20,12 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M21.25,16.5v-0.66c0,-1.13 -1.03,-2.09 -2.25,-2.09s-2.25,0.96 -2.25,2.09v0.66H16V22h6v-5.5H21.25zM19.75,16.5h-1.5v-0.66c0,-0.29 0.38,-0.59 0.75,-0.59s0.75,0.3 0.75,0.59V16.5z"/>
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M12,17c-3.79,0 -7.17,-2.13 -8.82,-5.5C4.83,8.13 8.21,6 12,6s7.17,2.13 8.82,5.5H23C21.27,7.11 17,4 12,4S2.73,7.11 1,11.5C2.73,15.89 7,19 12,19c0.68,0 1.35,-0.06 2,-0.17v-2.05C13.35,16.91 12.69,17 12,17z"/>
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M16.43,12.23c0.04,-0.24 0.07,-0.48 0.07,-0.73C16.5,9.02 14.48,7 12,7s-4.5,2.02 -4.5,4.5S9.52,16 12,16c0.77,0 1.48,-0.21 2.12,-0.55C14.41,14.08 15.27,12.93 16.43,12.23zM12,14.2c-1.49,0 -2.7,-1.21 -2.7,-2.7s1.21,-2.7 2.7,-2.7s2.7,1.21 2.7,2.7S13.49,14.2 12,14.2z"/>
</vector>
diff --git a/res/drawable/ic_settings_security_white.xml b/res/drawable/ic_settings_security_white.xml
index b9c81f1..a90bb8f 100644
--- a/res/drawable/ic_settings_security_white.xml
+++ b/res/drawable/ic_settings_security_white.xml
@@ -19,6 +19,6 @@
android:viewportWidth="24"
android:viewportHeight="24">
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM9,6c0,-1.66 1.34,-3 3,-3s3,1.34 3,3v2L9,8L9,6zM18,20L6,20L6,10h12v10zM12,17c1.1,0 2,-0.9 2,-2s-0.9,-2 -2,-2 -2,0.9 -2,2 0.9,2 2,2z"/>
</vector>
\ No newline at end of file
diff --git a/res/drawable/ic_settings_system_dashboard_white.xml b/res/drawable/ic_settings_system_dashboard_white.xml
index 5a697d4..cf3bb7b 100644
--- a/res/drawable/ic_settings_system_dashboard_white.xml
+++ b/res/drawable/ic_settings_system_dashboard_white.xml
@@ -19,12 +19,12 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M11,7h2v2h-2z"/>
<path
- android:fillColor="#FFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M11,11h2v6h-2z"/>
<path
- android:fillColor="#FFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M12,2C6.48,2 2,6.48 2,12c0,5.52 4.48,10 10,10s10,-4.48 10,-10C22,6.48 17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8c0,-4.41 3.59,-8 8,-8s8,3.59 8,8C20,16.41 16.41,20 12,20z"/>
</vector>
diff --git a/res/drawable/ic_settings_wireless_white.xml b/res/drawable/ic_settings_wireless_white.xml
index 63be43b..c56aa7e 100644
--- a/res/drawable/ic_settings_wireless_white.xml
+++ b/res/drawable/ic_settings_wireless_white.xml
@@ -16,4 +16,4 @@
<com.android.settings.widget.TintDrawable
xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_settings_wireless"
- android:tint="@android:color/white" />
\ No newline at end of file
+ android:tint="?android:attr/colorPrimary" />
\ No newline at end of file
diff --git a/res/drawable/ic_storage_white.xml b/res/drawable/ic_storage_white.xml
index eed9140..3b5d3c3 100644
--- a/res/drawable/ic_storage_white.xml
+++ b/res/drawable/ic_storage_white.xml
@@ -19,6 +19,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M3,20h18v-4H3V20zM5,17h2v2H5V17zM3,4v4h18V4H3zM7,7H5V5h2V7zM3,14h18v-4H3V14zM5,11h2v2H5V11z"/>
</vector>
diff --git a/res/drawable/ic_volume_up_24dp.xml b/res/drawable/ic_volume_up_24dp.xml
index 8c68c00..a1136d3 100644
--- a/res/drawable/ic_volume_up_24dp.xml
+++ b/res/drawable/ic_volume_up_24dp.xml
@@ -20,12 +20,12 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M3,9v6h4l5,5V4L7,9H3zM10,8.83v6.34L7.83,13H5v-2h2.83L10,8.83z"/>
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M16.5,12c0,-1.77 -1.02,-3.29 -2.5,-4.03v8.05C15.48,15.29 16.5,13.77 16.5,12z"/>
<path
- android:fillColor="#FFFFFFFF"
+ android:fillColor="?android:attr/colorPrimary"
android:pathData="M14,3.23v2.06c2.89,0.86 5,3.54 5,6.71c0,3.17 -2.11,5.85 -5,6.71v2.06c4.01,-0.91 7,-4.49 7,-8.77C21,7.72 18.01,4.14 14,3.23z"/>
</vector>
diff --git a/res/layout/accessibility_shortcut_tutorial_dialog.xml b/res/layout/accessibility_shortcut_tutorial_dialog.xml
new file mode 100644
index 0000000..9f3ee43
--- /dev/null
+++ b/res/layout/accessibility_shortcut_tutorial_dialog.xml
@@ -0,0 +1,58 @@
+<!--
+ Copyright (C) 2020 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"
+ android:gravity="center"
+ android:textDirection="locale"
+ android:scrollbarStyle="outsideOverlay">
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ android:padding="24dp">
+
+ <TextSwitcher
+ android:id="@+id/title"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:measureAllChildren="false" />
+
+ <androidx.viewpager.widget.ViewPager
+ android:id="@+id/view_pager"
+ android:layout_width="match_parent"
+ android:layout_height="176dp"
+ android:paddingTop="16dp"
+ android:paddingBottom="16dp" />
+
+ <LinearLayout
+ android:id="@+id/indicator_container"
+ android:layout_width="wrap_content"
+ android:layout_height="10dp"
+ android:layout_gravity="center" />
+
+ <TextSwitcher
+ android:id="@+id/instruction"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_marginTop="16dp"
+ android:measureAllChildren="false" />
+ </LinearLayout>
+
+</ScrollView>
diff --git a/res/layout/face_enroll_accessibility_toggle.xml b/res/layout/face_enroll_accessibility_toggle.xml
index d37175b..bb3a7ff 100644
--- a/res/layout/face_enroll_accessibility_toggle.xml
+++ b/res/layout/face_enroll_accessibility_toggle.xml
@@ -36,7 +36,7 @@
android:paddingTop="8dp"
android:gravity="start"
android:layout_alignParentStart="true"
- android:layout_toLeftOf="@+id/toggle"
+ android:layout_toStartOf="@+id/toggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
@@ -46,7 +46,7 @@
android:paddingHorizontal="8dp"
android:paddingBottom="8dp"
android:layout_alignParentStart="true"
- android:layout_toLeftOf="@+id/toggle"
+ android:layout_toStartOf="@+id/toggle"
android:layout_below="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
diff --git a/src/com/android/settings/accessibility/AccessibilityGestureNavigationTutorial.java b/src/com/android/settings/accessibility/AccessibilityGestureNavigationTutorial.java
index ddf7bd4..58245b7 100644
--- a/src/com/android/settings/accessibility/AccessibilityGestureNavigationTutorial.java
+++ b/src/com/android/settings/accessibility/AccessibilityGestureNavigationTutorial.java
@@ -16,35 +16,55 @@
package com.android.settings.accessibility;
+import static android.view.View.GONE;
+import static android.view.View.VISIBLE;
+
+import static com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
+
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.TypedArray;
+import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ImageSpan;
+import android.util.TypedValue;
+import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.TextureView;
import android.view.View;
+import android.view.ViewGroup;
import android.view.Window;
+import android.widget.ImageView;
+import android.widget.LinearLayout;
+import android.widget.TextSwitcher;
import android.widget.TextView;
+import androidx.annotation.AnimRes;
import androidx.annotation.ColorInt;
import androidx.annotation.IntDef;
+import androidx.annotation.NonNull;
+import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
+import androidx.core.util.Preconditions;
+import androidx.viewpager.widget.PagerAdapter;
+import androidx.viewpager.widget.ViewPager;
import com.android.settings.R;
+import com.android.settings.Utils;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
+import java.util.ArrayList;
+import java.util.List;
/**
* Utility class for creating the dialog that guides users for gesture navigation for
* accessibility services.
*/
-public class AccessibilityGestureNavigationTutorial {
-
+public final class AccessibilityGestureNavigationTutorial {
/** IntDef enum for dialog type. */
@Retention(RetentionPolicy.SOURCE)
@IntDef({
@@ -59,6 +79,8 @@
int GESTURE_NAVIGATION_SETTINGS = 2;
}
+ private AccessibilityGestureNavigationTutorial() {}
+
private static final DialogInterface.OnClickListener mOnClickListener =
(DialogInterface dialog, int which) -> dialog.dismiss();
@@ -91,6 +113,13 @@
return createDialog(context, DialogType.LAUNCH_SERVICE_BY_GESTURE_NAVIGATION);
}
+ static AlertDialog createAccessibilityTutorialDialog(Context context, int shortcutTypes) {
+ return new AlertDialog.Builder(context)
+ .setView(createShortcutNavigationContentView(context, shortcutTypes))
+ .setNegativeButton(R.string.accessibility_tutorial_dialog_button, mOnClickListener)
+ .create();
+ }
+
/**
* Get a content View for a dialog to confirm that they want to enable a service.
*
@@ -201,4 +230,302 @@
typedArray.recycle();
return colorResId;
}
+
+ private static class TutorialPagerAdapter extends PagerAdapter {
+ private final List<TutorialPage> mTutorialPages;
+ private TutorialPagerAdapter(List<TutorialPage> tutorialPages) {
+ this.mTutorialPages = tutorialPages;
+ }
+
+ @NonNull
+ @Override
+ public Object instantiateItem(@NonNull ViewGroup container, int position) {
+ final View itemView = mTutorialPages.get(position).getImageView();
+ container.addView(itemView);
+ return itemView;
+ }
+
+ @Override
+ public int getCount() {
+ return mTutorialPages.size();
+ }
+
+ @Override
+ public boolean isViewFromObject(@NonNull View view, @NonNull Object o) {
+ return view == o;
+ }
+
+ @Override
+ public void destroyItem(@NonNull ViewGroup container, int position,
+ @NonNull Object object) {
+ final View itemView = mTutorialPages.get(position).getImageView();
+ container.removeView(itemView);
+ }
+ }
+
+ private static ImageView createImageView(Context context, int imageRes) {
+ final ImageView imageView = new ImageView(context);
+ imageView.setImageResource(imageRes);
+ imageView.setAdjustViewBounds(true);
+
+ return imageView;
+ }
+
+ private static View createShortcutNavigationContentView(Context context, int shortcutTypes) {
+ final LayoutInflater inflater = context.getSystemService(LayoutInflater.class);
+ final View contentView = inflater.inflate(
+ R.layout.accessibility_shortcut_tutorial_dialog, /* root= */ null);
+ final List<TutorialPage> tutorialPages =
+ createShortcutTutorialPages(context, shortcutTypes);
+ Preconditions.checkArgument(!tutorialPages.isEmpty(),
+ /* errorMessage= */ "Unexpected tutorial pages size");
+
+ final LinearLayout indicatorContainer = contentView.findViewById(R.id.indicator_container);
+ indicatorContainer.setVisibility(tutorialPages.size() > 1 ? VISIBLE : GONE);
+ for (TutorialPage page : tutorialPages) {
+ indicatorContainer.addView(page.getIndicatorIcon());
+ }
+ tutorialPages.get(/* firstIndex */ 0).getIndicatorIcon().setEnabled(true);
+
+ final TextSwitcher title = contentView.findViewById(R.id.title);
+ title.setFactory(() -> makeTitleView(context));
+ title.setText(tutorialPages.get(/* firstIndex */ 0).getTitle());
+
+ final TextSwitcher instruction = contentView.findViewById(R.id.instruction);
+ instruction.setFactory(() -> makeInstructionView(context));
+ instruction.setText(tutorialPages.get(/* firstIndex */ 0).getInstruction());
+
+ final ViewPager viewPager = contentView.findViewById(R.id.view_pager);
+ viewPager.setAdapter(new TutorialPagerAdapter(tutorialPages));
+ viewPager.addOnPageChangeListener(
+ new TutorialPageChangeListener(context, title, instruction, tutorialPages));
+
+ return contentView;
+ }
+
+ private static View makeTitleView(Context context) {
+ final String familyName =
+ context.getString(
+ com.android.internal.R.string.config_headlineFontFamilyMedium);
+ final TextView textView = new TextView(context);
+
+ textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, /* size= */ 20);
+ textView.setTextColor(Utils.getColorAttr(context, android.R.attr.textColorPrimary));
+ textView.setGravity(Gravity.CENTER);
+ textView.setTypeface(Typeface.create(familyName, Typeface.NORMAL));
+
+ return textView;
+ }
+
+ private static View makeInstructionView(Context context) {
+ final TextView textView = new TextView(context);
+ textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, /* size= */ 16);
+ textView.setTextColor(Utils.getColorAttr(context, android.R.attr.textColorPrimary));
+ textView.setTypeface(
+ Typeface.create(/* familyName= */ "sans-serif", Typeface.NORMAL));
+ return textView;
+ }
+
+ private static TutorialPage createSoftwareTutorialPage(@NonNull Context context) {
+ final CharSequence title = getSoftwareTitle(context);
+ final ImageView image = createSoftwareImage(context);
+ final CharSequence instruction = getSoftwareInstruction(context);
+ final ImageView indicatorIcon =
+ createImageView(context, R.drawable.ic_accessibility_page_indicator);
+ indicatorIcon.setEnabled(false);
+
+ return new TutorialPage(title, image, indicatorIcon, instruction);
+ }
+
+ private static TutorialPage createHardwareTutorialPage(@NonNull Context context) {
+ final CharSequence title =
+ context.getText(R.string.accessibility_tutorial_dialog_title_volume);
+ final ImageView image =
+ createImageView(context, R.drawable.accessibility_shortcut_type_hardware);
+ final ImageView indicatorIcon =
+ createImageView(context, R.drawable.ic_accessibility_page_indicator);
+ final CharSequence instruction =
+ context.getText(R.string.accessibility_tutorial_dialog_message_volume);
+ indicatorIcon.setEnabled(false);
+
+ return new TutorialPage(title, image, indicatorIcon, instruction);
+ }
+
+ private static TutorialPage createTripleTapTutorialPage(@NonNull Context context) {
+ final CharSequence title =
+ context.getText(R.string.accessibility_tutorial_dialog_title_triple);
+ final ImageView image =
+ createImageView(context, R.drawable.accessibility_shortcut_type_triple_tap);
+ final CharSequence instruction =
+ context.getText(R.string.accessibility_tutorial_dialog_message_triple);
+ final ImageView indicatorIcon =
+ createImageView(context, R.drawable.ic_accessibility_page_indicator);
+ indicatorIcon.setEnabled(false);
+
+ return new TutorialPage(title, image, indicatorIcon, instruction);
+ }
+
+ @VisibleForTesting
+ static List<TutorialPage> createShortcutTutorialPages(@NonNull Context context,
+ int shortcutTypes) {
+ final List<TutorialPage> tutorialPages = new ArrayList<>();
+ if ((shortcutTypes & UserShortcutType.SOFTWARE) == UserShortcutType.SOFTWARE) {
+ tutorialPages.add(createSoftwareTutorialPage(context));
+ }
+
+ if ((shortcutTypes & UserShortcutType.HARDWARE) == UserShortcutType.HARDWARE) {
+ tutorialPages.add(createHardwareTutorialPage(context));
+ }
+
+ if ((shortcutTypes & UserShortcutType.TRIPLETAP) == UserShortcutType.TRIPLETAP) {
+ tutorialPages.add(createTripleTapTutorialPage(context));
+ }
+
+ return tutorialPages;
+ }
+
+ private static CharSequence getSoftwareTitle(Context context) {
+ final boolean isGestureNavigationEnabled =
+ AccessibilityUtil.isGestureNavigateEnabled(context);
+ final boolean isTouchExploreEnabled = AccessibilityUtil.isTouchExploreEnabled(context);
+
+ return (isGestureNavigationEnabled || isTouchExploreEnabled)
+ ? context.getText(R.string.accessibility_tutorial_dialog_title_gesture)
+ : context.getText(R.string.accessibility_tutorial_dialog_title_button);
+ }
+
+ private static ImageView createSoftwareImage(Context context) {
+ int resId = R.drawable.accessibility_shortcut_type_software;
+ if (AccessibilityUtil.isGestureNavigateEnabled(context)) {
+ resId = AccessibilityUtil.isTouchExploreEnabled(context)
+ ? R.drawable.accessibility_shortcut_type_software_gesture_talkback
+ : R.drawable.accessibility_shortcut_type_software_gesture;
+ }
+
+ return createImageView(context, resId);
+ }
+
+ private static CharSequence getSoftwareInstruction(Context context) {
+ final boolean isGestureNavigateEnabled =
+ AccessibilityUtil.isGestureNavigateEnabled(context);
+ final boolean isTouchExploreEnabled = AccessibilityUtil.isTouchExploreEnabled(context);
+ int resId = R.string.accessibility_tutorial_dialog_message_button;
+ if (isGestureNavigateEnabled) {
+ resId = isTouchExploreEnabled
+ ? R.string.accessibility_tutorial_dialog_message_gesture_talkback
+ : R.string.accessibility_tutorial_dialog_message_gesture;
+ }
+
+ CharSequence text = context.getText(resId);
+ if (resId == R.string.accessibility_tutorial_dialog_message_button) {
+ text = getSoftwareInstructionWithIcon(context, text);
+ }
+
+ return text;
+ }
+
+ private static CharSequence getSoftwareInstructionWithIcon(Context context, CharSequence text) {
+ final String message = text.toString();
+ final SpannableString spannableInstruction = SpannableString.valueOf(message);
+ final int indexIconStart = message.indexOf("%s");
+ final int indexIconEnd = indexIconStart + 2;
+ final ImageView iconView = new ImageView(context);
+ iconView.setImageDrawable(context.getDrawable(R.drawable.ic_accessibility_new));
+ final Drawable icon = iconView.getDrawable().mutate();
+ final ImageSpan imageSpan = new ImageSpan(icon);
+ imageSpan.setContentDescription("");
+ icon.setBounds(/* left= */ 0, /* top= */ 0,
+ icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
+ spannableInstruction.setSpan(imageSpan, indexIconStart, indexIconEnd,
+ Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
+
+ return spannableInstruction;
+ }
+
+ private static class TutorialPage {
+ private final CharSequence mTitle;
+ private final ImageView mImageView;
+ private final ImageView mIndicatorIcon;
+ private final CharSequence mInstruction;
+
+ TutorialPage(CharSequence title, ImageView imageView, ImageView indicatorIcon,
+ CharSequence instruction) {
+ this.mTitle = title;
+ this.mImageView = imageView;
+ this.mIndicatorIcon = indicatorIcon;
+ this.mInstruction = instruction;
+ }
+
+ public CharSequence getTitle() {
+ return mTitle;
+ }
+
+ public ImageView getImageView() {
+ return mImageView;
+ }
+
+ public ImageView getIndicatorIcon() {
+ return mIndicatorIcon;
+ }
+
+ public CharSequence getInstruction() {
+ return mInstruction;
+ }
+ }
+
+ private static class TutorialPageChangeListener implements ViewPager.OnPageChangeListener {
+ private int mLastTutorialPagePosition = 0;
+ private final Context mContext;
+ private final TextSwitcher mTitle;
+ private final TextSwitcher mInstruction;
+ private final List<TutorialPage> mTutorialPages;
+
+ TutorialPageChangeListener(Context context, ViewGroup title, ViewGroup instruction,
+ List<TutorialPage> tutorialPages) {
+ this.mContext = context;
+ this.mTitle = (TextSwitcher) title;
+ this.mInstruction = (TextSwitcher) instruction;
+ this.mTutorialPages = tutorialPages;
+ }
+
+ @Override
+ public void onPageScrolled(int position, float positionOffset,
+ int positionOffsetPixels) {
+ // Do nothing.
+ }
+
+ @Override
+ public void onPageSelected(int position) {
+ final boolean isPreviousPosition =
+ mLastTutorialPagePosition > position;
+ @AnimRes
+ final int inAnimationResId = isPreviousPosition
+ ? android.R.anim.slide_in_left
+ : com.android.internal.R.anim.slide_in_right;
+
+ @AnimRes
+ final int outAnimationResId = isPreviousPosition
+ ? android.R.anim.slide_out_right
+ : com.android.internal.R.anim.slide_out_left;
+
+ mTitle.setInAnimation(mContext, inAnimationResId);
+ mTitle.setOutAnimation(mContext, outAnimationResId);
+ mTitle.setText(mTutorialPages.get(position).getTitle());
+
+ mInstruction.setInAnimation(mContext, inAnimationResId);
+ mInstruction.setOutAnimation(mContext, outAnimationResId);
+ mInstruction.setText(mTutorialPages.get(position).getInstruction());
+
+ for (TutorialPage page : mTutorialPages) {
+ page.getIndicatorIcon().setEnabled(false);
+ }
+ mTutorialPages.get(position).getIndicatorIcon().setEnabled(true);
+ mLastTutorialPagePosition = position;
+ }
+
+ @Override
+ public void onPageScrollStateChanged(int state) {
+ // Do nothing.
+ }
+ }
}
diff --git a/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java b/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java
index de37bab..169a952 100644
--- a/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/LaunchAccessibilityActivityPreferenceFragment.java
@@ -101,6 +101,12 @@
}
@Override
+ int getUserShortcutTypes() {
+ return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
+ mComponentName);
+ }
+
+ @Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
// Do not call super. We don't want to see the "Help & feedback" option on this page so as
// not to confuse users who think they might be able to send feedback about a specific
diff --git a/src/com/android/settings/accessibility/LegacyAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/LegacyAccessibilityServicePreferenceFragment.java
index 1803874..4fcfff8 100644
--- a/src/com/android/settings/accessibility/LegacyAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/LegacyAccessibilityServicePreferenceFragment.java
@@ -18,6 +18,7 @@
import static com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
+import android.accessibilityservice.AccessibilityServiceInfo;
import android.os.Bundle;
import android.view.View;
@@ -48,6 +49,22 @@
setAllowedPreferredShortcutType(UserShortcutType.HARDWARE);
}
+ @Override
+ int getUserShortcutTypes() {
+ int shortcutTypes = super.getUserShortcutTypes();
+
+ final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
+ final boolean hasRequestAccessibilityButtonFlag =
+ (info.flags & AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0;
+ if (hasRequestAccessibilityButtonFlag) {
+ shortcutTypes |= UserShortcutType.SOFTWARE;
+ } else {
+ shortcutTypes &= (~UserShortcutType.SOFTWARE);
+ }
+
+ return shortcutTypes;
+ }
+
private void setAllowedPreferredShortcutType(int type) {
final AccessibilityUserShortcutType shortcut = new AccessibilityUserShortcutType(
mComponentName.flattenToString(), type);
diff --git a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
index 547a45a..86181e9 100644
--- a/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleAccessibilityServicePreferenceFragment.java
@@ -106,7 +106,7 @@
// capabilities. For
// example, before JellyBean MR2 the user was granting the explore by touch
// one.
- private AccessibilityServiceInfo getAccessibilityServiceInfo() {
+ AccessibilityServiceInfo getAccessibilityServiceInfo() {
final List<AccessibilityServiceInfo> infos = AccessibilityManager.getInstance(
getPrefContext()).getInstalledAccessibilityServiceList();
@@ -164,16 +164,6 @@
this::onDialogButtonFromDisableToggleClicked);
break;
}
- case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL: {
- if (AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())) {
- mDialog = AccessibilityGestureNavigationTutorial
- .showGestureNavigationTutorialDialog(getPrefContext());
- } else {
- mDialog = AccessibilityGestureNavigationTutorial
- .showAccessibilityButtonTutorialDialog(getPrefContext());
- }
- break;
- }
default: {
mDialog = super.onCreateDialog(dialogId);
}
@@ -191,15 +181,19 @@
case DialogEnums.DISABLE_WARNING_FROM_TOGGLE:
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_DISABLE;
case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
- return AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())
- ? SettingsEnums.DIALOG_TOGGLE_SCREEN_GESTURE_NAVIGATION
- : SettingsEnums.DIALOG_TOGGLE_SCREEN_ACCESSIBILITY_BUTTON;
+ return SettingsEnums.DIALOG_ACCESSIBILITY_TUTORIAL;
default:
return super.getDialogMetricsCategory(dialogId);
}
}
@Override
+ int getUserShortcutTypes() {
+ return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
+ mComponentName);
+ }
+
+ @Override
protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
final AccessibilityServiceInfo info = getAccessibilityServiceInfo();
final String switchBarText = (info == null) ? "" :
@@ -303,6 +297,7 @@
} else {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
mComponentName);
+ showPopupDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
}
} else {
AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes,
@@ -416,6 +411,9 @@
final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes, mComponentName);
+ mIsDialogShown.set(false);
+ showPopupDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
+
mDialog.dismiss();
mShortcutPreference.setSummary(getShortcutTypeSummary(getPrefContext()));
diff --git a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
index 07ff720..5cde5e6 100644
--- a/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleColorInversionPreferenceFragment.java
@@ -124,6 +124,12 @@
showDialog(DialogEnums.EDIT_SHORTCUT);
}
+ @Override
+ int getUserShortcutTypes() {
+ return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
+ mComponentName);
+ }
+
private void updateSwitchBarToggleSwitch() {
final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON;
if (mToggleServiceDividerSwitchPreference.isChecked() == checked) {
diff --git a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
index 5b9c55b..c7212a4 100644
--- a/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleDaltonizerPreferenceFragment.java
@@ -198,6 +198,12 @@
showDialog(DialogEnums.EDIT_SHORTCUT);
}
+ @Override
+ int getUserShortcutTypes() {
+ return AccessibilityUtil.getUserShortcutTypesFromSettings(getPrefContext(),
+ mComponentName);
+ }
+
private void updateSwitchBarToggleSwitch() {
final boolean checked = Settings.Secure.getInt(getContentResolver(), ENABLED, OFF) == ON;
if (mToggleServiceDividerSwitchPreference.isChecked() == checked) {
diff --git a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
index eeb1f3a..8b4f3f2 100644
--- a/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragment.java
@@ -42,7 +42,6 @@
import android.widget.CheckBox;
import android.widget.ImageView;
-import androidx.appcompat.app.AlertDialog;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceScreen;
@@ -250,14 +249,21 @@
@Override
public Dialog onCreateDialog(int dialogId) {
+ Dialog dialog;
switch (dialogId) {
case DialogEnums.EDIT_SHORTCUT:
final CharSequence dialogTitle = getPrefContext().getString(
R.string.accessibility_shortcut_title, mPackageName);
- final AlertDialog dialog = AccessibilityEditDialogUtils.showEditShortcutDialog(
+ dialog = AccessibilityEditDialogUtils.showEditShortcutDialog(
getPrefContext(), dialogTitle, this::callOnAlertDialogCheckboxClicked);
initializeDialogCheckBox(dialog);
return dialog;
+ case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
+ dialog = AccessibilityGestureNavigationTutorial
+ .createAccessibilityTutorialDialog(getPrefContext(),
+ getUserShortcutTypes());
+ dialog.setCanceledOnTouchOutside(false);
+ return dialog;
default:
throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
}
@@ -268,6 +274,8 @@
switch (dialogId) {
case DialogEnums.EDIT_SHORTCUT:
return SettingsEnums.DIALOG_ACCESSIBILITY_SERVICE_EDIT_SHORTCUT;
+ case DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL:
+ return SettingsEnums.DIALOG_ACCESSIBILITY_TUTORIAL;
default:
return SettingsEnums.ACTION_UNKNOWN;
}
@@ -334,6 +342,11 @@
removeActionBarToggleSwitch();
}
+ /**
+ * Returns the shortcut type list which has been checked by user.
+ */
+ abstract int getUserShortcutTypes();
+
protected void updateToggleServiceTitle(SwitchPreference switchPreference) {
switchPreference.setTitle(R.string.accessibility_service_master_switch_title);
}
@@ -658,6 +671,7 @@
if (preference.isChecked()) {
AccessibilityUtil.optInAllValuesToSettings(getPrefContext(), shortcutTypes,
mComponentName);
+ showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
} else {
AccessibilityUtil.optOutAllValuesFromSettings(getPrefContext(), shortcutTypes,
mComponentName);
diff --git a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
index 91b8eae..b550434 100644
--- a/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
+++ b/src/com/android/settings/accessibility/ToggleScreenMagnificationPreferenceFragment.java
@@ -224,24 +224,22 @@
@Override
public Dialog onCreateDialog(int dialogId) {
+ final AlertDialog dialog;
switch (dialogId) {
case DialogEnums.GESTURE_NAVIGATION_TUTORIAL:
return AccessibilityGestureNavigationTutorial
.showGestureNavigationTutorialDialog(getPrefContext());
- case DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL:
- return AccessibilityGestureNavigationTutorial
- .showAccessibilityButtonTutorialDialog(getPrefContext());
case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
final CharSequence dialogTitle = getPrefContext().getString(
R.string.accessibility_shortcut_title, mPackageName);
- final AlertDialog dialog =
- AccessibilityEditDialogUtils.showMagnificationEditShortcutDialog(
+ dialog = AccessibilityEditDialogUtils.showMagnificationEditShortcutDialog(
getPrefContext(), dialogTitle,
this::callOnAlertDialogCheckboxClicked);
initializeDialogCheckBox(dialog);
return dialog;
+ default:
+ return super.onCreateDialog(dialogId);
}
- throw new IllegalArgumentException("Unsupported dialogId " + dialogId);
}
private void setDialogTextAreaClickListener(View dialogView, CheckBox checkBox) {
@@ -408,18 +406,21 @@
case DialogEnums.MAGNIFICATION_EDIT_SHORTCUT:
return SettingsEnums.DIALOG_MAGNIFICATION_EDIT_SHORTCUT;
default:
- return 0;
+ return super.getDialogMetricsCategory(dialogId);
}
}
@Override
+ int getUserShortcutTypes() {
+ return getUserShortcutTypeFromSettings(getPrefContext());
+ }
+
+ @Override
protected void onPreferenceToggled(String preferenceKey, boolean enabled) {
if (enabled && TextUtils.equals(
Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_NAVBAR_ENABLED,
preferenceKey)) {
- showDialog(AccessibilityUtil.isGestureNavigateEnabled(getPrefContext())
- ? DialogEnums.GESTURE_NAVIGATION_TUTORIAL
- : DialogEnums.ACCESSIBILITY_BUTTON_TUTORIAL);
+ showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
}
MagnificationPreferenceFragment.setChecked(getContentResolver(), preferenceKey, enabled);
}
@@ -449,6 +450,7 @@
final int shortcutTypes = getUserShortcutTypes(getPrefContext(), UserShortcutType.SOFTWARE);
if (preference.isChecked()) {
optInAllMagnificationValuesToSettings(getPrefContext(), shortcutTypes);
+ showDialog(DialogEnums.LAUNCH_ACCESSIBILITY_TUTORIAL);
} else {
optOutAllMagnificationValuesFromSettings(getPrefContext(), shortcutTypes);
}
diff --git a/src/com/android/settings/dashboard/DashboardFragment.java b/src/com/android/settings/dashboard/DashboardFragment.java
index e4041fb..8084038 100644
--- a/src/com/android/settings/dashboard/DashboardFragment.java
+++ b/src/com/android/settings/dashboard/DashboardFragment.java
@@ -320,6 +320,14 @@
addPreferencesFromResource(resId);
final PreferenceScreen screen = getPreferenceScreen();
screen.setOnExpandButtonClickListener(this);
+ displayResourceTilesToScreen(screen);
+ }
+
+ /**
+ * Perform {@link AbstractPreferenceController#displayPreference(PreferenceScreen)}
+ * on all {@link AbstractPreferenceController}s.
+ */
+ protected void displayResourceTilesToScreen(PreferenceScreen screen) {
mPreferenceControllers.values().stream().flatMap(Collection::stream).forEach(
controller -> controller.displayPreference(screen));
}
diff --git a/src/com/android/settings/datausage/CellDataPreference.java b/src/com/android/settings/datausage/CellDataPreference.java
index 4a49f33..6dc40e8 100644
--- a/src/com/android/settings/datausage/CellDataPreference.java
+++ b/src/com/android/settings/datausage/CellDataPreference.java
@@ -50,15 +50,12 @@
public int mSubId = SubscriptionManager.INVALID_SUBSCRIPTION_ID;
public boolean mChecked;
public boolean mMultiSimDialog;
- @VisibleForTesting
- ProxySubscriptionManager mProxySubscriptionMgr;
private MobileDataEnabledListener mDataStateListener;
public CellDataPreference(Context context, AttributeSet attrs) {
super(context, attrs, TypedArrayUtils.getAttr(context,
androidx.preference.R.attr.switchPreferenceStyle,
android.R.attr.switchPreferenceStyle));
- mProxySubscriptionMgr = ProxySubscriptionManager.getInstance(context);
mDataStateListener = new MobileDataEnabledListener(context, this);
}
@@ -88,13 +85,15 @@
public void onAttached() {
super.onAttached();
mDataStateListener.start(mSubId);
- mProxySubscriptionMgr.addActiveSubscriptionsListener(mOnSubscriptionsChangeListener);
+ getProxySubscriptionManager()
+ .addActiveSubscriptionsListener(mOnSubscriptionsChangeListener);
}
@Override
public void onDetached() {
mDataStateListener.stop();
- mProxySubscriptionMgr.removeActiveSubscriptionsListener(mOnSubscriptionsChangeListener);
+ getProxySubscriptionManager()
+ .removeActiveSubscriptionsListener(mOnSubscriptionsChangeListener);
super.onDetached();
}
@@ -104,8 +103,8 @@
throw new IllegalArgumentException("CellDataPreference needs a SubscriptionInfo");
}
- mProxySubscriptionMgr = ProxySubscriptionManager.getInstance(getContext());
- mProxySubscriptionMgr.addActiveSubscriptionsListener(mOnSubscriptionsChangeListener);
+ getProxySubscriptionManager()
+ .addActiveSubscriptionsListener(mOnSubscriptionsChangeListener);
if (mSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
mSubId = subId;
@@ -115,6 +114,16 @@
updateChecked();
}
+ @VisibleForTesting
+ ProxySubscriptionManager getProxySubscriptionManager() {
+ return ProxySubscriptionManager.getInstance(getContext());
+ }
+
+ @VisibleForTesting
+ SubscriptionInfo getActiveSubscriptionInfo(int subId) {
+ return getProxySubscriptionManager().getActiveSubscriptionInfo(subId);
+ }
+
private void updateChecked() {
setChecked(getContext().getSystemService(TelephonyManager.class).getDataEnabled(mSubId));
}
@@ -122,7 +131,7 @@
private void updateEnabled() {
// If this subscription is not active, for example, SIM card is taken out, we disable
// the button.
- setEnabled(mProxySubscriptionMgr.getActiveSubscriptionInfo(mSubId) != null);
+ setEnabled(getActiveSubscriptionInfo(mSubId) != null);
}
@Override
@@ -130,9 +139,8 @@
final Context context = getContext();
FeatureFactory.getFactory(context).getMetricsFeatureProvider()
.action(context, SettingsEnums.ACTION_CELL_DATA_TOGGLE, !mChecked);
- final SubscriptionInfo currentSir = mProxySubscriptionMgr.getActiveSubscriptionInfo(
- mSubId);
- final SubscriptionInfo nextSir = mProxySubscriptionMgr.getActiveSubscriptionInfo(
+ final SubscriptionInfo currentSir = getActiveSubscriptionInfo(mSubId);
+ final SubscriptionInfo nextSir = getActiveSubscriptionInfo(
SubscriptionManager.getDefaultDataSubscriptionId());
if (mChecked) {
setMobileDataEnabled(false);
@@ -186,9 +194,8 @@
private void showMultiSimDialog(Builder builder,
DialogInterface.OnClickListener listener) {
- final SubscriptionInfo currentSir = mProxySubscriptionMgr.getActiveSubscriptionInfo(
- mSubId);
- final SubscriptionInfo nextSir = mProxySubscriptionMgr.getActiveSubscriptionInfo(
+ final SubscriptionInfo currentSir = getActiveSubscriptionInfo(mSubId);
+ final SubscriptionInfo nextSir = getActiveSubscriptionInfo(
SubscriptionManager.getDefaultDataSubscriptionId());
final String previousName = (nextSir == null)
@@ -205,8 +212,7 @@
}
private void disableDataForOtherSubscriptions(int subId) {
- final SubscriptionInfo subInfo = mProxySubscriptionMgr.getActiveSubscriptionInfo(
- subId);
+ final SubscriptionInfo subInfo = getActiveSubscriptionInfo(subId);
if (subInfo != null) {
getContext().getSystemService(TelephonyManager.class).setDataEnabled(subId, false);
}
@@ -218,7 +224,7 @@
return;
}
if (mMultiSimDialog) {
- mProxySubscriptionMgr.get().setDefaultDataSubId(mSubId);
+ getProxySubscriptionManager().get().setDefaultDataSubId(mSubId);
setMobileDataEnabled(true);
disableDataForOtherSubscriptions(mSubId);
} else {
diff --git a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
index 87bfe48..135abfa 100644
--- a/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
+++ b/src/com/android/settings/datausage/DataUsageSummaryPreferenceController.java
@@ -38,9 +38,9 @@
import com.android.internal.util.CollectionUtils;
import com.android.settings.R;
-import com.android.settings.core.BasePreferenceController;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.network.ProxySubscriptionManager;
+import com.android.settings.network.telephony.TelephonyBasePreferenceController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.NetworkPolicyEditor;
import com.android.settingslib.core.lifecycle.Lifecycle;
@@ -55,7 +55,7 @@
* subscriptions framework API if available. The controller reads subscription information from the
* framework and falls back to legacy usage data if none are available.
*/
-public class DataUsageSummaryPreferenceController extends BasePreferenceController
+public class DataUsageSummaryPreferenceController extends TelephonyBasePreferenceController
implements PreferenceControllerMixin, LifecycleObserver, OnStart {
private static final String TAG = "DataUsageController";
@@ -64,8 +64,7 @@
private static final float RELATIVE_SIZE_LARGE = 1.25f * 1.25f; // (1/0.8)^2
private static final float RELATIVE_SIZE_SMALL = 1.0f / RELATIVE_SIZE_LARGE; // 0.8^2
- private final Activity mActivity;
- private final EntityHeaderController mEntityHeaderController;
+ private EntityHeaderController mEntityHeaderController;
private final Lifecycle mLifecycle;
private final PreferenceFragmentCompat mFragment;
protected DataUsageController mDataUsageController;
@@ -97,8 +96,6 @@
private long mCycleStart;
/** The ending time of the billing cycle in ms since the epoch */
private long mCycleEnd;
- /** The subscription that we should show usage for. */
- private int mSubscriptionId;
private Intent mManageSubscriptionIntent;
@@ -106,9 +103,6 @@
Lifecycle lifecycle, PreferenceFragmentCompat fragment, int subscriptionId) {
super(activity, KEY);
- mActivity = activity;
- mEntityHeaderController = EntityHeaderController.newInstance(activity,
- fragment, null);
mLifecycle = lifecycle;
mFragment = fragment;
init(subscriptionId);
@@ -119,18 +113,18 @@
* @param subscriptionId is the target subscriptionId
*/
public void init(int subscriptionId) {
- mSubscriptionId = subscriptionId;
+ mSubId = subscriptionId;
- mDefaultTemplate = DataUsageUtils.getDefaultTemplate(mContext, mSubscriptionId);
+ mDefaultTemplate = DataUsageUtils.getDefaultTemplate(mContext, mSubId);
final NetworkPolicyManager policyManager =
mContext.getSystemService(NetworkPolicyManager.class);
mPolicyEditor = new NetworkPolicyEditor(policyManager);
- mHasMobileData = SubscriptionManager.isValidSubscriptionId(mSubscriptionId)
+ mHasMobileData = SubscriptionManager.isValidSubscriptionId(mSubId)
&& DataUsageUtils.hasMobileData(mContext);
mDataUsageController = new DataUsageController(mContext);
- mDataUsageController.setSubscriptionId(mSubscriptionId);
+ mDataUsageController.setSubscriptionId(mSubId);
mDataInfoController = new DataUsageInfoController();
if (mHasMobileData) {
@@ -161,18 +155,21 @@
mPolicyEditor = policyEditor;
mDataUsageTemplate = dataUsageTemplate;
mHasMobileData = true;
- mActivity = activity;
mLifecycle = lifecycle;
mEntityHeaderController = entityHeaderController;
mFragment = fragment;
- mSubscriptionId = subscriptionId;
+ mSubId = subscriptionId;
}
@Override
public void onStart() {
+ if (mEntityHeaderController == null) {
+ mEntityHeaderController =
+ EntityHeaderController.newInstance((Activity) mContext, mFragment, null);
+ }
RecyclerView view = mFragment.getListView();
mEntityHeaderController.setRecyclerView(view, mLifecycle);
- mEntityHeaderController.styleActionBar(mActivity);
+ mEntityHeaderController.styleActionBar((Activity) mContext);
}
@VisibleForTesting
@@ -193,7 +190,7 @@
}
@Override
- public int getAvailabilityStatus() {
+ public int getAvailabilityStatus(int subId) {
return hasSim()
|| DataUsageUtils.hasWifiRadio(mContext) ? AVAILABLE : CONDITIONALLY_UNAVAILABLE;
}
@@ -202,16 +199,20 @@
public void updateState(Preference preference) {
DataUsageSummaryPreference summaryPreference = (DataUsageSummaryPreference) preference;
- final DataUsageController.DataUsageInfo info;
- final SubscriptionInfo subInfo = getSubscriptionInfo(mSubscriptionId);
- if (hasSim()) {
- info = mDataUsageController.getDataUsageInfo(mDefaultTemplate);
+ final boolean isSimCardAdded = hasSim();
+ if (!isSimCardAdded) {
+ mDefaultTemplate = NetworkTemplate.buildTemplateWifiWildcard();
+ }
+
+ final DataUsageController.DataUsageInfo info =
+ mDataUsageController.getDataUsageInfo(mDefaultTemplate);
+
+ final SubscriptionInfo subInfo = getSubscriptionInfo(mSubId);
+ if (isSimCardAdded) {
mDataInfoController.updateDataLimit(info, mPolicyEditor.getPolicy(mDefaultTemplate));
summaryPreference.setWifiMode(/* isWifiMode */ false,
/* usagePeriod */ null, /* isSingleWifi */ false);
} else {
- info = mDataUsageController.getDataUsageInfo(
- NetworkTemplate.buildTemplateWifiWildcard());
summaryPreference.setWifiMode(/* isWifiMode */ true, /* usagePeriod */
info.period, /* isSingleWifi */ false);
summaryPreference.setLimitInfo(null);
@@ -276,7 +277,7 @@
if (subInfo != null && mHasMobileData) {
mCarrierName = subInfo.getCarrierName();
- final List<SubscriptionPlan> plans = getSubscriptionPlans(mSubscriptionId);
+ final List<SubscriptionPlan> plans = getSubscriptionPlans(mSubId);
final SubscriptionPlan primaryPlan = getPrimaryPlan(plans);
if (primaryPlan != null) {
@@ -296,8 +297,8 @@
mSnapshotTime = primaryPlan.getDataUsageTime();
}
}
- mManageSubscriptionIntent = createManageSubscriptionIntent(mSubscriptionId);
- Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubscriptionId
+ mManageSubscriptionIntent = createManageSubscriptionIntent(mSubId);
+ Log.i(TAG, "Have " + mDataplanCount + " plans, dflt sub-id " + mSubId
+ ", intent " + mManageSubscriptionIntent);
}
@@ -334,7 +335,7 @@
intent.setPackage(owner);
intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
- if (mActivity.getPackageManager().queryIntentActivities(intent,
+ if (mContext.getPackageManager().queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY).isEmpty()) {
return null;
}
diff --git a/src/com/android/settings/media/MediaOutputGroupSlice.java b/src/com/android/settings/media/MediaOutputGroupSlice.java
index 1a82b6d..7730b2d 100644
--- a/src/com/android/settings/media/MediaOutputGroupSlice.java
+++ b/src/com/android/settings/media/MediaOutputGroupSlice.java
@@ -168,7 +168,7 @@
}
private IconCompat getDisabledCheckboxIcon() {
- final Drawable drawable = mContext.getDrawable(R.drawable.ic_check_box_blue_24dp);
+ final Drawable drawable = mContext.getDrawable(R.drawable.ic_check_box_blue_24dp).mutate();
final Bitmap checkbox = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
final Canvas canvas = new Canvas(checkbox);
diff --git a/src/com/android/settings/network/ApnEditor.java b/src/com/android/settings/network/ApnEditor.java
index 5da6e2c..f9eccfa 100644
--- a/src/com/android/settings/network/ApnEditor.java
+++ b/src/com/android/settings/network/ApnEditor.java
@@ -68,6 +68,7 @@
private final static boolean VDBG = false; // STOPSHIP if true
private final static String KEY_AUTH_TYPE = "auth_type";
+ private static final String KEY_APN_TYPE = "apn_type";
private final static String KEY_PROTOCOL = "apn_protocol";
private final static String KEY_ROAMING_PROTOCOL = "apn_roaming_protocol";
private final static String KEY_CARRIER_ENABLED = "carrier_enabled";
@@ -344,6 +345,7 @@
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
super.onViewStateRestored(savedInstanceState);
fillUI(savedInstanceState == null);
+ setCarrierCustomizedConfigToUi();
}
@VisibleForTesting
@@ -645,7 +647,9 @@
* return null.
*/
private String protocolDescription(String raw, ListPreference protocol) {
- final int protocolIndex = protocol.findIndexOfValue(raw);
+ String uRaw = checkNull(raw).toUpperCase();
+ uRaw = uRaw.equals("IPV4") ? "IP" : uRaw;
+ final int protocolIndex = protocol.findIndexOfValue(uRaw);
if (protocolIndex == -1) {
return null;
} else {
@@ -745,6 +749,13 @@
} catch (NumberFormatException e) {
return false;
}
+ } else if (KEY_APN_TYPE.equals(key)) {
+ String data = (TextUtils.isEmpty((String) newValue)
+ && !ArrayUtils.isEmpty(mDefaultApnTypes))
+ ? getEditableApnType(mDefaultApnTypes) : (String) newValue;
+ if (!TextUtils.isEmpty(data)) {
+ mApnType.setSummary(data);
+ }
} else if (KEY_PROTOCOL.equals(key)) {
final String protocol = protocolDescription((String) newValue, mProtocol);
if (protocol == null) {
@@ -780,7 +791,6 @@
} else {
preference.setSummary(checkNull(newValue != null ? String.valueOf(newValue) : null));
}
-
return true;
}
@@ -1002,13 +1012,13 @@
callUpdate = setStringValueAndCheckIfDiff(values,
Telephony.Carriers.PROTOCOL,
- getUserEnteredApnProtocol(mProtocol, mDefaultApnProtocol),
+ checkNotSet(mProtocol.getValue()),
callUpdate,
PROTOCOL_INDEX);
callUpdate = setStringValueAndCheckIfDiff(values,
Telephony.Carriers.ROAMING_PROTOCOL,
- getUserEnteredApnProtocol(mRoamingProtocol, mDefaultApnRoamingProtocol),
+ checkNotSet(mRoamingProtocol.getValue()),
callUpdate,
ROAMING_PROTOCOL_INDEX);
@@ -1205,33 +1215,17 @@
}
@VisibleForTesting
- String getUserEnteredApnProtocol(ListPreference preference, String defaultApnProtocol) {
- // if user has not specified a protocol or enter empty type, map it just for default
- final String userEnteredApnProtocol = checkNotSet(
- ((preference == null) ? null : preference.getValue()));
- if (TextUtils.isEmpty(userEnteredApnProtocol)) {
- return defaultApnProtocol;
- }
- return userEnteredApnProtocol.trim();
- }
-
- @VisibleForTesting
String getUserEnteredApnType() {
// if user has not specified a type, map it to "ALL APN TYPES THAT ARE NOT READ-ONLY"
// but if user enter empty type, map it just for default
String userEnteredApnType = mApnType.getText();
if (userEnteredApnType != null) userEnteredApnType = userEnteredApnType.trim();
if ((TextUtils.isEmpty(userEnteredApnType)
- || APN_TYPE_ALL.equals(userEnteredApnType))
- && !ArrayUtils.isEmpty(mReadOnlyApnTypes)) {
- String[] apnTypeList = APN_TYPES;
- if (TextUtils.isEmpty(userEnteredApnType) && !ArrayUtils.isEmpty(mDefaultApnTypes)) {
- apnTypeList = mDefaultApnTypes;
- }
- userEnteredApnType = getEditableApnType(apnTypeList);
- Log.d(TAG, "getUserEnteredApnType: changed apn type to editable apn types: "
- + userEnteredApnType);
+ || APN_TYPE_ALL.equals(userEnteredApnType))) {
+ userEnteredApnType = getEditableApnType(APN_TYPES);
}
+ Log.d(TAG, "getUserEnteredApnType: changed apn type to editable apn types: "
+ + userEnteredApnType);
return userEnteredApnType;
}
@@ -1324,6 +1318,26 @@
}
}
+ private void setCarrierCustomizedConfigToUi() {
+ if (TextUtils.isEmpty(mApnType.getText()) && !ArrayUtils.isEmpty(mDefaultApnTypes)) {
+ String value = getEditableApnType(mDefaultApnTypes);
+ mApnType.setText(value);
+ mApnType.setSummary(value);
+ }
+
+ String protocol = protocolDescription(mDefaultApnProtocol, mProtocol);
+ if (TextUtils.isEmpty(mProtocol.getValue()) && !TextUtils.isEmpty(protocol)) {
+ mProtocol.setValue(mDefaultApnProtocol);
+ mProtocol.setSummary(protocol);
+ }
+
+ String roamingProtocol = protocolDescription(mDefaultApnRoamingProtocol, mRoamingProtocol);
+ if (TextUtils.isEmpty(mRoamingProtocol.getValue()) && !TextUtils.isEmpty(roamingProtocol)) {
+ mRoamingProtocol.setValue(mDefaultApnRoamingProtocol);
+ mRoamingProtocol.setSummary(roamingProtocol);
+ }
+ }
+
public static class ErrorDialog extends InstrumentedDialogFragment {
public static void showError(ApnEditor editor) {
diff --git a/src/com/android/settings/network/telephony/DataUsagePreferenceController.java b/src/com/android/settings/network/telephony/DataUsagePreferenceController.java
index d9617e6..035a8c1 100644
--- a/src/com/android/settings/network/telephony/DataUsagePreferenceController.java
+++ b/src/com/android/settings/network/telephony/DataUsagePreferenceController.java
@@ -22,24 +22,33 @@
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.text.TextUtils;
+import android.util.Log;
import androidx.preference.Preference;
+import com.android.internal.annotations.VisibleForTesting;
import com.android.settings.R;
import com.android.settings.datausage.DataUsageUtils;
import com.android.settingslib.net.DataUsageController;
+import com.android.settingslib.utils.ThreadUtils;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.atomic.AtomicReference;
/**
* Preference controller for "Data usage"
*/
public class DataUsagePreferenceController extends TelephonyBasePreferenceController {
- private NetworkTemplate mTemplate;
- private DataUsageController.DataUsageInfo mDataUsageInfo;
- private Intent mIntent;
+ private static final String LOG_TAG = "DataUsagePreferCtrl";
+
+ private Future<NetworkTemplate> mTemplateFuture;
+ private AtomicReference<NetworkTemplate> mTemplate;
public DataUsagePreferenceController(Context context, String key) {
super(context, key);
+ mTemplate = new AtomicReference<NetworkTemplate>();
}
@Override
@@ -54,8 +63,11 @@
if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) {
return false;
}
+ final Intent intent = new Intent(Settings.ACTION_MOBILE_DATA_USAGE);
+ intent.putExtra(Settings.EXTRA_NETWORK_TEMPLATE, getNetworkTemplate());
+ intent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
- mContext.startActivity(mIntent);
+ mContext.startActivity(intent);
return true;
}
@@ -66,34 +78,65 @@
preference.setEnabled(false);
return;
}
- long usageLevel = mDataUsageInfo.usageLevel;
- if (usageLevel <= 0L) {
- final DataUsageController controller = new DataUsageController(mContext);
- usageLevel = controller.getHistoricalUsageLevel(mTemplate);
- }
- final boolean enabled = usageLevel > 0L;
- preference.setEnabled(enabled);
-
- if (enabled) {
- preference.setSummary(mContext.getString(R.string.data_usage_template,
- DataUsageUtils.formatDataUsage(mContext, mDataUsageInfo.usageLevel),
- mDataUsageInfo.period));
+ final CharSequence summary = getDataUsageSummary(mContext, mSubId);
+ if (summary == null) {
+ preference.setEnabled(false);
+ } else {
+ preference.setEnabled(true);
+ preference.setSummary(summary);
}
}
public void init(int subId) {
mSubId = subId;
+ mTemplate.set(null);
+ mTemplateFuture = ThreadUtils.postOnBackgroundThread(()
+ -> fetchMobileTemplate(mContext, mSubId));
+ }
- if (mSubId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
- mTemplate = DataUsageUtils.getDefaultTemplate(mContext, mSubId);
-
- final DataUsageController controller = new DataUsageController(mContext);
- controller.setSubscriptionId(mSubId);
- mDataUsageInfo = controller.getDataUsageInfo(mTemplate);
-
- mIntent = new Intent(Settings.ACTION_MOBILE_DATA_USAGE);
- mIntent.putExtra(Settings.EXTRA_NETWORK_TEMPLATE, mTemplate);
- mIntent.putExtra(Settings.EXTRA_SUB_ID, mSubId);
+ private NetworkTemplate fetchMobileTemplate(Context context, int subId) {
+ if (!SubscriptionManager.isValidSubscriptionId(subId)) {
+ return null;
}
+ return DataUsageUtils.getMobileTemplate(context, subId);
+ }
+
+ private NetworkTemplate getNetworkTemplate() {
+ if (!SubscriptionManager.isValidSubscriptionId(mSubId)) {
+ return null;
+ }
+ NetworkTemplate template = mTemplate.get();
+ if (template != null) {
+ return template;
+ }
+ try {
+ template = mTemplateFuture.get();
+ mTemplate.set(template);
+ } catch (ExecutionException | InterruptedException | NullPointerException exception) {
+ Log.e(LOG_TAG, "Fail to get data usage template", exception);
+ }
+ return template;
+ }
+
+ @VisibleForTesting
+ DataUsageController.DataUsageInfo getDataUsageInfo(DataUsageController controller) {
+ return controller.getDataUsageInfo(getNetworkTemplate());
+ }
+
+ private CharSequence getDataUsageSummary(Context context, int subId) {
+ final DataUsageController controller = new DataUsageController(context);
+ controller.setSubscriptionId(subId);
+
+ final DataUsageController.DataUsageInfo usageInfo = getDataUsageInfo(controller);
+
+ long usageLevel = usageInfo.usageLevel;
+ if (usageLevel <= 0L) {
+ usageLevel = controller.getHistoricalUsageLevel(getNetworkTemplate());
+ }
+ if (usageLevel <= 0L) {
+ return null;
+ }
+ return context.getString(R.string.data_usage_template,
+ DataUsageUtils.formatDataUsage(context, usageLevel), usageInfo.period);
}
}
diff --git a/src/com/android/settings/network/telephony/Enhanced4gBasePreferenceController.java b/src/com/android/settings/network/telephony/Enhanced4gBasePreferenceController.java
index 0471f74..3a91616 100644
--- a/src/com/android/settings/network/telephony/Enhanced4gBasePreferenceController.java
+++ b/src/com/android/settings/network/telephony/Enhanced4gBasePreferenceController.java
@@ -133,6 +133,9 @@
@Override
public void updateState(Preference preference) {
super.updateState(preference);
+ if (preference == null) {
+ return;
+ }
final SwitchPreference switchPreference = (SwitchPreference) preference;
final VolteQueryImsState queryState = queryImsState(mSubId);
diff --git a/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java b/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java
index d235a9a..3321fb3 100644
--- a/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/VideoCallingPreferenceController.java
@@ -91,7 +91,8 @@
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- if (mCallState == null) {
+ if ((mCallState == null) || (preference == null)) {
+ Log.d(TAG, "Skip update under mCallState=" + mCallState);
return;
}
final SwitchPreference switchPreference = (SwitchPreference) preference;
diff --git a/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java b/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java
index bec8a51..32be36e 100644
--- a/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java
+++ b/src/com/android/settings/network/telephony/WifiCallingPreferenceController.java
@@ -30,6 +30,7 @@
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.ims.ImsMmTelManager;
+import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
@@ -98,7 +99,8 @@
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- if (mCallState == null) {
+ if ((mCallState == null) || (preference == null)) {
+ Log.d(TAG, "Skip update under mCallState=" + mCallState);
return;
}
CharSequence summaryText = null;
diff --git a/tests/robotests/src/com/android/settings/accessibility/AccessibilityGestureNavigationTutorialTest.java b/tests/robotests/src/com/android/settings/accessibility/AccessibilityGestureNavigationTutorialTest.java
new file mode 100644
index 0000000..cf0ce96
--- /dev/null
+++ b/tests/robotests/src/com/android/settings/accessibility/AccessibilityGestureNavigationTutorialTest.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2020 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.accessibility;
+
+import static com.android.settings.accessibility.AccessibilityGestureNavigationTutorial.createAccessibilityTutorialDialog;
+import static com.android.settings.accessibility.AccessibilityGestureNavigationTutorial.createShortcutTutorialPages;
+import static com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import android.content.Context;
+
+import androidx.appcompat.app.AlertDialog;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.robolectric.RobolectricTestRunner;
+import org.robolectric.RuntimeEnvironment;
+
+/** Tests for {@link AccessibilityGestureNavigationTutorial}. */
+@RunWith(RobolectricTestRunner.class)
+public final class AccessibilityGestureNavigationTutorialTest {
+
+ private Context mContext;
+ private int mShortcutTypes;
+
+ @Before
+ public void setUp() {
+ mContext = RuntimeEnvironment.application;
+ mShortcutTypes = /* initial */ 0;
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void createTutorialPages_shortcutListIsEmpty_throwsException() {
+ createAccessibilityTutorialDialog(mContext, mShortcutTypes);
+ }
+
+ @Test
+ public void createTutorialPages_turnOnTripleTapShortcut_hasOnePage() {
+ mShortcutTypes |= UserShortcutType.TRIPLETAP;
+
+ final AlertDialog alertDialog =
+ createAccessibilityTutorialDialog(mContext, mShortcutTypes);
+
+ assertThat(createShortcutTutorialPages(mContext,
+ mShortcutTypes)).hasSize(/* expectedSize= */ 1);
+ assertThat(alertDialog).isNotNull();
+ }
+
+ @Test
+ public void createTutorialPages_turnOnSoftwareShortcut_hasOnePage() {
+ mShortcutTypes |= UserShortcutType.SOFTWARE;
+
+ final AlertDialog alertDialog =
+ createAccessibilityTutorialDialog(mContext, mShortcutTypes);
+
+ assertThat(createShortcutTutorialPages(mContext,
+ mShortcutTypes)).hasSize(/* expectedSize= */ 1);
+ assertThat(alertDialog).isNotNull();
+ }
+
+ @Test
+ public void createTutorialPages_turnOnSoftwareAndHardwareShortcuts_hasTwoPages() {
+ mShortcutTypes |= UserShortcutType.SOFTWARE;
+ mShortcutTypes |= UserShortcutType.HARDWARE;
+
+ final AlertDialog alertDialog =
+ createAccessibilityTutorialDialog(mContext, mShortcutTypes);
+
+ assertThat(createShortcutTutorialPages(mContext,
+ mShortcutTypes)).hasSize(/* expectedSize= */ 2);
+ assertThat(alertDialog).isNotNull();
+ }
+}
diff --git a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
index e476c21..3df9c04 100644
--- a/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
@@ -130,6 +130,11 @@
}
@Override
+ int getUserShortcutTypes() {
+ return 0;
+ }
+
+ @Override
public int getPreferenceScreenResId() {
return R.xml.placeholder_prefs;
}
diff --git a/tests/robotests/src/com/android/settings/datausage/CellDataPreferenceTest.java b/tests/robotests/src/com/android/settings/datausage/CellDataPreferenceTest.java
index 5f2a54c..c0b12dc 100644
--- a/tests/robotests/src/com/android/settings/datausage/CellDataPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/datausage/CellDataPreferenceTest.java
@@ -17,11 +17,14 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import android.content.Context;
import android.telephony.SubscriptionInfo;
+import android.telephony.SubscriptionManager;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
@@ -31,7 +34,6 @@
import com.android.settings.network.ProxySubscriptionManager;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -40,12 +42,13 @@
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
-@Ignore
public class CellDataPreferenceTest {
@Mock
private ProxySubscriptionManager mProxySubscriptionMgr;
@Mock
+ private SubscriptionManager mSubscriptionManager;
+ @Mock
private SubscriptionInfo mSubInfo;
private Context mContext;
@@ -57,8 +60,20 @@
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
- mPreference = new CellDataPreference(mContext, null);
- mPreference.mProxySubscriptionMgr = mProxySubscriptionMgr;
+ mPreference = new CellDataPreference(mContext, null) {
+ @Override
+ ProxySubscriptionManager getProxySubscriptionManager() {
+ return mProxySubscriptionMgr;
+ }
+ @Override
+ SubscriptionInfo getActiveSubscriptionInfo(int subId) {
+ return mSubInfo;
+ }
+ };
+ doNothing().when(mSubscriptionManager).setDefaultDataSubId(anyInt());
+ doReturn(mSubscriptionManager).when(mProxySubscriptionMgr).get();
+ doNothing().when(mProxySubscriptionMgr).addActiveSubscriptionsListener(any());
+ doNothing().when(mProxySubscriptionMgr).removeActiveSubscriptionsListener(any());
final LayoutInflater inflater = LayoutInflater.from(mContext);
final View view = inflater.inflate(mPreference.getLayoutResource(),
@@ -69,14 +84,13 @@
@Test
public void noActiveSub_shouldDisable() {
- doReturn(null).when(mProxySubscriptionMgr).getActiveSubscriptionInfo(anyInt());
+ mSubInfo = null;
mPreference.mOnSubscriptionsChangeListener.onChanged();
assertThat(mPreference.isEnabled()).isFalse();
}
@Test
public void hasActiveSub_shouldEnable() {
- doReturn(mSubInfo).when(mProxySubscriptionMgr).getActiveSubscriptionInfo(anyInt());
mPreference.mOnSubscriptionsChangeListener.onChanged();
assertThat(mPreference.isEnabled()).isTrue();
}
diff --git a/tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java
index 862f78f..25e5a22 100644
--- a/tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/development/WifiEnhancedMacRandomizationPreferenceControllerTest.java
@@ -18,6 +18,7 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -27,7 +28,6 @@
import androidx.preference.SwitchPreference;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -75,13 +75,12 @@
}
@Test
- @Ignore
public void updateState_preferenceShouldBeChecked() {
Settings.Global.putInt(mContext.getContentResolver(),
ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 1);
mController.updateState(mPreference);
- assertThat(mPreference.isChecked()).isTrue();
+ verify(mPreference).setChecked(true);
}
@Test
@@ -90,7 +89,7 @@
ENHANCED_MAC_RANDOMIZATION_FEATURE_FLAG, 0);
mController.updateState(mPreference);
- assertThat(mPreference.isChecked()).isFalse();
+ verify(mPreference).setChecked(false);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/display/NightDisplayAutoModePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/display/NightDisplayAutoModePreferenceControllerTest.java
index d6500dbb..7c046f8 100644
--- a/tests/robotests/src/com/android/settings/display/NightDisplayAutoModePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/NightDisplayAutoModePreferenceControllerTest.java
@@ -16,16 +16,20 @@
import static com.google.common.truth.Truth.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
+import static org.mockito.Mockito.when;
+
import android.content.Context;
import android.hardware.display.ColorDisplayManager;
+import android.location.LocationManager;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mockito;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
@@ -36,10 +40,14 @@
private Context mContext;
private NightDisplayAutoModePreferenceController mController;
+ private LocationManager mLocationManager;
@Before
public void setUp() {
- mContext = RuntimeEnvironment.application;
+ mContext = Mockito.spy(RuntimeEnvironment.application);
+ mLocationManager = Mockito.mock(LocationManager.class);
+ when(mLocationManager.isLocationEnabled()).thenReturn(true);
+ when(mContext.getSystemService(eq(LocationManager.class))).thenReturn(mLocationManager);
mController = new NightDisplayAutoModePreferenceController(mContext,
"night_display_auto_mode");
}
@@ -64,7 +72,6 @@
}
@Test
- @Ignore
public void onPreferenceChange_changesAutoMode() {
mController.onPreferenceChange(null,
String.valueOf(ColorDisplayManager.AUTO_MODE_TWILIGHT));
diff --git a/tests/robotests/src/com/android/settings/display/darkmode/DarkModeScheduleSelectorControllerTest.java b/tests/robotests/src/com/android/settings/display/darkmode/DarkModeScheduleSelectorControllerTest.java
index 92ecdc8..1bbbe7d 100644
--- a/tests/robotests/src/com/android/settings/display/darkmode/DarkModeScheduleSelectorControllerTest.java
+++ b/tests/robotests/src/com/android/settings/display/darkmode/DarkModeScheduleSelectorControllerTest.java
@@ -37,7 +37,6 @@
import com.android.settings.R;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -103,16 +102,6 @@
}
@Test
- @Ignore
- public void nightMode_selectNightMode_locationOff() {
- when(mLocationManager.isLocationEnabled()).thenReturn(false);
- mController.onPreferenceChange(mPreference,
- mContext.getString(R.string.dark_ui_auto_mode_never));
- assertFalse(mController.onPreferenceChange(mPreference,
- mContext.getString(R.string.dark_ui_auto_mode_auto)));
- }
-
- @Test
public void nightMode_updateStateNone_dropDownValueChangedToAuto() {
when(mUiService.getNightMode()).thenReturn(UiModeManager.MODE_NIGHT_AUTO);
mController.displayPreference(mScreen);
diff --git a/tests/robotests/src/com/android/settings/network/ApnEditorTest.java b/tests/robotests/src/com/android/settings/network/ApnEditorTest.java
index 20334e0..7ec1174 100644
--- a/tests/robotests/src/com/android/settings/network/ApnEditorTest.java
+++ b/tests/robotests/src/com/android/settings/network/ApnEditorTest.java
@@ -81,11 +81,11 @@
"" /* MMS port */,
0 /* Authentication type */,
"default,supl,ia" /* APN type */,
- "IPv6" /* APN protocol */,
+ "IP" /* APN protocol */,
1 /* APN enable/disable */,
0 /* Bearer */,
0 /* Bearer BITMASK*/,
- "IPv4" /* APN roaming protocol */,
+ "IPV6" /* APN roaming protocol */,
"None" /* MVNO type */,
"", /* MVNO value */
};
@@ -464,33 +464,25 @@
}
@Test
- public void getUserEnteredApnProtocol_emptyApnProtocol_shouldReturnDefaultIPv4v6() {
- // GIVEN read default APN protocol with IPV4V6
- mApnEditorUT.mDefaultApnProtocol = "IPV4V6";
+ public void testOnViewStateRestored_customizedValueWithoutDefault_shouldShowCustomized() {
+ mApnEditorUT.mDefaultApnProtocol = "IP";
+ mApnEditorUT.mApnData.mData[ApnEditor.PROTOCOL_INDEX] = null;
+ mApnEditorUT.mProtocol.setEntryValues(new CharSequence[]{"IP", "IPV6", "IPV4V6"});
- // Input empty in TYPE
- mApnEditorUT.mApnData.mData[ApnEditor.PROTOCOL_INDEX] = "";
- mApnEditorUT.fillUI(true /* firstTime */);
+ mApnEditorUT.onViewStateRestored(null);
- // THEN APN type should be IPV4V6
- assertThat(mApnEditorUT.getUserEnteredApnProtocol(
- mApnEditorUT.mProtocol, mApnEditorUT.mDefaultApnProtocol))
- .isEqualTo("IPV4V6");
+ assertThat(mApnEditorUT.mProtocol.getSummary()).isEqualTo("IPv4");
}
@Test
- public void getUserEnteredApnProtocol_emptyApnProtocol_shouldReturnDefaultIP() {
- // GIVEN read default APN protocol with IP
+ public void testOnViewStateRestored_customizedValueWithDefault_shouldShowDefault() {
mApnEditorUT.mDefaultApnProtocol = "IP";
+ mApnEditorUT.mApnData.mData[ApnEditor.PROTOCOL_INDEX] = "IPV6";
+ mApnEditorUT.mProtocol.setEntryValues(new CharSequence[]{"IP", "IPV6", "IPV4V6"});
- // Input empty in TYPE
- mApnEditorUT.mApnData.mData[ApnEditor.PROTOCOL_INDEX] = "";
- mApnEditorUT.fillUI(true /* firstTime */);
+ mApnEditorUT.onViewStateRestored(null);
- // THEN APN type should be IPV4V6
- assertThat(mApnEditorUT.getUserEnteredApnProtocol(
- mApnEditorUT.mProtocol, mApnEditorUT.mDefaultApnProtocol))
- .isEqualTo("IP");
+ assertThat(mApnEditorUT.mProtocol.getSummary()).isEqualTo("IPv6");
}
@Test
@@ -503,7 +495,7 @@
// Input empty in TYPE
mApnEditorUT.mApnData.mData[ApnEditor.TYPE_INDEX] = "";
- mApnEditorUT.fillUI(true /* firstTime */);
+ mApnEditorUT.onViewStateRestored(null);
// THEN APN type should be default
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
@@ -516,7 +508,7 @@
// Input empty in TYPE
mApnEditorUT.mApnData.mData[ApnEditor.TYPE_INDEX] = "";
- mApnEditorUT.fillUI(true /* firstTime */);
+ mApnEditorUT.onViewStateRestored(null);
// THEN APN type should be default
assertThat(mApnEditorUT.getUserEnteredApnType()).isEqualTo("default");
diff --git a/tests/robotests/src/com/android/settings/network/telephony/DataUsagePreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/DataUsagePreferenceControllerTest.java
index 7681f44..43bda4e3 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/DataUsagePreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/DataUsagePreferenceControllerTest.java
@@ -17,12 +17,12 @@
package com.android.settings.network.telephony;
import static com.google.common.truth.Truth.assertThat;
+
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
-import android.app.Activity;
import android.app.usage.NetworkStatsManager;
import android.content.Context;
import android.content.Intent;
@@ -30,21 +30,22 @@
import android.provider.Settings;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
+
import androidx.preference.SwitchPreference;
+
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.net.DataUsageController;
+
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
-import org.robolectric.Robolectric;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.Shadows;
import org.robolectric.shadows.ShadowTelephonyManager;
-import org.robolectric.util.ReflectionHelpers;
@RunWith(RobolectricTestRunner.class)
public class DataUsagePreferenceControllerTest {
@@ -71,7 +72,7 @@
doReturn(mNetworkStatsManager).when(mContext).getSystemService(NetworkStatsManager.class);
mPreference = new SwitchPreference(mContext);
- mController = new DataUsagePreferenceController(mContext, "data_usage");
+ mController = spy(new DataUsagePreferenceController(mContext, "data_usage"));
mController.init(SUB_ID);
mPreference.setKey(mController.getPreferenceKey());
}
@@ -114,8 +115,9 @@
@Test
public void updateState_noUsageData_shouldDisablePreference() {
- ReflectionHelpers.setField(
- mController, "mDataUsageInfo", new DataUsageController.DataUsageInfo());
+ final DataUsageController.DataUsageInfo usageInfo =
+ new DataUsageController.DataUsageInfo();
+ doReturn(usageInfo).when(mController).getDataUsageInfo(any());
mController.updateState(mPreference);
@@ -124,9 +126,10 @@
@Test
public void updateState_shouldUseIECUnit() {
- final DataUsageController.DataUsageInfo usageInfo = new DataUsageController.DataUsageInfo();
+ final DataUsageController.DataUsageInfo usageInfo =
+ new DataUsageController.DataUsageInfo();
usageInfo.usageLevel = TrafficStats.MB_IN_BYTES;
- ReflectionHelpers.setField(mController, "mDataUsageInfo", usageInfo);
+ doReturn(usageInfo).when(mController).getDataUsageInfo(any());
mController.updateState(mPreference);
diff --git a/tests/robotests/src/com/android/settings/network/telephony/NrDisabledInDsdsFooterPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/network/telephony/NrDisabledInDsdsFooterPreferenceControllerTest.java
index 2cd4d42..b4e8a25 100644
--- a/tests/robotests/src/com/android/settings/network/telephony/NrDisabledInDsdsFooterPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/network/telephony/NrDisabledInDsdsFooterPreferenceControllerTest.java
@@ -24,6 +24,7 @@
import static org.mockito.Mockito.when;
import android.content.Context;
+import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import org.junit.Before;
@@ -43,6 +44,8 @@
private Context mContext;
@Mock
private TelephonyManager mTelephonyManager;
+ @Mock
+ private SubscriptionManager mSubscriptionManager;
private NrDisabledInDsdsFooterPreferenceController mController;
@Before
@@ -50,6 +53,8 @@
MockitoAnnotations.initMocks(this);
mContext = spy(RuntimeEnvironment.application);
doReturn(mTelephonyManager).when(mContext).getSystemService(Context.TELEPHONY_SERVICE);
+ doReturn(mSubscriptionManager).when(mContext).getSystemService(
+ Context.TELEPHONY_SUBSCRIPTION_SERVICE);
doReturn(mTelephonyManager).when(mTelephonyManager).createForSubscriptionId(anyInt());
mController = new NrDisabledInDsdsFooterPreferenceController(mContext, PREF_KEY);
}
@@ -64,7 +69,7 @@
public void isAvailable_dataOnAndDsdsAnd5GSupported_Available() {
when(mTelephonyManager.getSupportedRadioAccessFamily())
.thenReturn(TelephonyManager.NETWORK_TYPE_BITMASK_NR);
- when(mTelephonyManager.getActiveModemCount()).thenReturn(2);
+ when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[] {1, 2});
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
mController.init(SUB_ID);
assertThat(mController.isAvailable()).isTrue();
@@ -74,7 +79,7 @@
public void isAvailable_5gNotSupported_notAvailable() {
when(mTelephonyManager.getSupportedRadioAccessFamily())
.thenReturn(TelephonyManager.NETWORK_TYPE_BITMASK_LTE);
- when(mTelephonyManager.getActiveModemCount()).thenReturn(2);
+ when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[] {1, 2});
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
mController.init(SUB_ID);
assertThat(mController.isAvailable()).isFalse();
@@ -84,7 +89,7 @@
public void isAvailable_mobileDataOff_notAvailable() {
when(mTelephonyManager.getSupportedRadioAccessFamily())
.thenReturn(TelephonyManager.NETWORK_TYPE_BITMASK_NR);
- when(mTelephonyManager.getActiveModemCount()).thenReturn(2);
+ when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[] {1, 2});
when(mTelephonyManager.isDataEnabled()).thenReturn(false);
mController.init(SUB_ID);
assertThat(mController.isAvailable()).isFalse();
@@ -94,7 +99,7 @@
public void isAvailable_singleSimMode_notAvailable() {
when(mTelephonyManager.getSupportedRadioAccessFamily())
.thenReturn(TelephonyManager.NETWORK_TYPE_BITMASK_NR);
- when(mTelephonyManager.getActiveModemCount()).thenReturn(1);
+ when(mSubscriptionManager.getActiveSubscriptionIdList()).thenReturn(new int[] {1});
when(mTelephonyManager.isDataEnabled()).thenReturn(true);
mController.init(SUB_ID);
assertThat(mController.isAvailable()).isFalse();
diff --git a/tests/unit/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java b/tests/unit/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
index 9a3b526..e0013e0 100644
--- a/tests/unit/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
+++ b/tests/unit/src/com/android/settings/accessibility/ToggleFeaturePreferenceFragmentTest.java
@@ -86,5 +86,10 @@
public int getMetricsCategory() {
return 0;
}
+
+ @Override
+ int getUserShortcutTypes() {
+ return 0;
+ }
}
}
\ No newline at end of file