Merge "[Settings] Do not set text if the fragment is not attached" into udc-dev
diff --git a/res/drawable/ic_lock_24dp.xml b/res/drawable/ic_lock_24dp.xml
new file mode 100644
index 0000000..a3f699f
--- /dev/null
+++ b/res/drawable/ic_lock_24dp.xml
@@ -0,0 +1,27 @@
+<!--
+    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
+-->
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+        android:width="24dp"
+        android:height="24dp"
+        android:viewportWidth="24"
+        android:viewportHeight="24">
+    <path
+        android:fillColor="?android:attr/colorPrimary"
+        android:pathData="M12,15m-2,0a2,2 0,1 1,4 0a2,2 0,1 1,-4 0"/>
+    <path
+        android:fillColor="?android:attr/colorPrimary"
+        android:pathData="M18,8h-1.5V5.5C16.5,3.01 14.49,1 12,1S7.5,3.01 7.5,5.5V8H6c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V10C20,8.9 19.1,8 18,8zM9.5,5.5C9.5,4.12 10.62,3 12,3c1.38,0 2.5,1.12 2.5,2.5V8h-5V5.5zM18,20H6V10h1.5h9H18V20z"/>
+</vector>
diff --git a/res/layout/fingerprint_enroll_introduction.xml b/res/layout/fingerprint_enroll_introduction.xml
index e3c9a01..5271e6a 100644
--- a/res/layout/fingerprint_enroll_introduction.xml
+++ b/res/layout/fingerprint_enroll_introduction.xml
@@ -94,7 +94,7 @@
                     android:layout_width="wrap_content"
                     android:layout_height="wrap_content"
                     android:contentDescription="@null"
-                    android:src="@drawable/ic_device_locked_24dp"/>
+                    android:src="@drawable/ic_lock_24dp"/>
                 <Space
                     android:layout_width="16dp"
                     android:layout_height="wrap_content"/>
diff --git a/res/values/dimens.xml b/res/values/dimens.xml
index 2f3d875..0d54cf4 100755
--- a/res/values/dimens.xml
+++ b/res/values/dimens.xml
@@ -161,6 +161,7 @@
     <dimen name="sfps_lottie_translate_x">12dp</dimen>
     <dimen name="sfps_lottie_translate_y">12dp</dimen>
     <dimen name="udfps_lottie_translate_y">0dp</dimen>
+    <dimen name="udfps_lottie_padding_top">20dp</dimen>
 
     <!-- Face -->
     <item name="face_preview_translate_y" format="float" type="dimen">0</item>
diff --git a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
index 9b1b30a..835e15d 100644
--- a/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
+++ b/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrolling.java
@@ -63,6 +63,7 @@
 import android.view.animation.AnimationUtils;
 import android.view.animation.Interpolator;
 import android.widget.FrameLayout;
+import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.ProgressBar;
 import android.widget.RelativeLayout;
@@ -328,6 +329,23 @@
                             final ViewGroup.LayoutParams containerLp =
                                     portraitLayoutContainer.getLayoutParams();
                             containerLp.height = 0;
+
+                            // In the portrait mode, the title and lottie animation view may
+                            // overlap when title needs three lines, so adding some paddings
+                            // between them, and adjusting the fp progress view here accordingly.
+                            final int layoutLottieAnimationPadding = (int) getResources()
+                                    .getDimension(R.dimen.udfps_lottie_padding_top);
+                            portraitLayoutContainer.setPadding(0,
+                                    layoutLottieAnimationPadding, 0, 0);
+                            final ImageView progressView = udfpsEnrollView.findViewById(
+                                    R.id.udfps_enroll_animation_fp_progress_view);
+                            progressView.setPadding(0, -(layoutLottieAnimationPadding),
+                                    0, layoutLottieAnimationPadding);
+                            final ImageView fingerprintView = udfpsEnrollView.findViewById(
+                                    R.id.udfps_enroll_animation_fp_view);
+                            fingerprintView.setPadding(0, -layoutLottieAnimationPadding,
+                                    0, layoutLottieAnimationPadding);
+
                             portraitLayoutContainer.addView(udfpsEnrollView);
                             setOnHoverListener(false, defaultLayout, udfpsEnrollView);
                         } else if (rotation == Surface.ROTATION_270) {
diff --git a/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.java b/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.java
index f46a452..c0b903d 100644
--- a/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.java
+++ b/src/com/android/settings/network/telephony/gsm/AutoSelectPreferenceController.java
@@ -211,6 +211,7 @@
                             mSwitchPreference.setChecked(isChecked());
                         }
                         mRecursiveUpdate.decrementAndGet();
+                        updateListenerValue();
                         dismissProgressBar();
                     });
                 });
@@ -245,13 +246,13 @@
 
         ThreadUtils.postOnBackgroundThread(() -> {
             queryNetworkSelectionMode(INTERNAL_LOG_TAG_INIT);
-
             //Update UI in UI thread
             mUiHandler.post(() -> {
                 if (mSwitchPreference != null) {
                     mRecursiveUpdate.getAndIncrement();
                     mSwitchPreference.setChecked(isChecked());
                     mRecursiveUpdate.decrementAndGet();
+                    updateListenerValue();
                 }
             });
         });
@@ -267,7 +268,6 @@
     private void queryNetworkSelectionMode(String tag) {
         mCacheOfModeStatus = mTelephonyManager.getNetworkSelectionMode();
         Log.d(LOG_TAG, tag + ": query commend done. mCacheOfModeStatus: " + mCacheOfModeStatus);
-        updateListenerValue();
     }
 
     @VisibleForTesting
@@ -284,12 +284,11 @@
             }
             mCacheOfModeStatus = networkSelectionMode;
             Log.d(LOG_TAG, "updateUiAutoSelectValue: mCacheOfModeStatus: " + mCacheOfModeStatus);
-            updateListenerValue();
 
             mRecursiveUpdate.getAndIncrement();
             updateState(mSwitchPreference);
             mRecursiveUpdate.decrementAndGet();
-
+            updateListenerValue();
         }
     }
 
diff --git a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
index 2886194..2232960 100644
--- a/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
+++ b/tests/robotests/src/com/android/settings/biometrics/fingerprint/FingerprintEnrollEnrollingTest.java
@@ -43,6 +43,7 @@
 import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Color;
+import android.graphics.Rect;
 import android.hardware.biometrics.ComponentInfoInternal;
 import android.hardware.biometrics.SensorProperties;
 import android.hardware.fingerprint.FingerprintManager;
@@ -58,6 +59,7 @@
 import android.view.View;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
+import android.widget.TextView;
 
 import com.android.settings.R;
 import com.android.settings.testutils.FakeFeatureFactory;
@@ -81,6 +83,7 @@
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
 
 @RunWith(RobolectricTestRunner.class)
 public class FingerprintEnrollEnrollingTest {
@@ -246,6 +249,78 @@
     }
 
     @Test
+    public void fingerprintUdfpsOverlayEnrollment_checkViewOverlapPortrait() {
+        FeatureFlagUtils.setEnabled(mContext,
+                FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);
+        when(mMockDisplay.getRotation()).thenReturn(Surface.ROTATION_90);
+        initializeActivityFor(TYPE_UDFPS_OPTICAL);
+
+        final GlifLayout defaultLayout = mActivity.findViewById(R.id.setup_wizard_layout);
+        final TextView headerTextView = defaultLayout.getHeaderTextView();
+        final TextView descriptionTextView = defaultLayout.getDescriptionTextView();
+        final FrameLayout lottieAnimationContainer = mActivity.findViewById(R.id.layout_container);
+        final UdfpsEnrollView udfpsEnrollView =
+                defaultLayout.findViewById(R.id.udfps_animation_view);
+
+        final int[] headerTextViewPosition = new int[2];
+        final int[] descriptionTextViewPosition = new int[2];
+        final int[] lottieAnimationPosition = new int[2];
+        final int[] udfpsEnrollViewPosition = new int[2];
+        final AtomicReference<Rect> rectHeaderTextView = new AtomicReference<>(
+                new Rect(0, 0, 0, 0));
+        final AtomicReference<Rect> rectDescriptionTextView =
+                new AtomicReference<>(new Rect(0, 0, 0, 0));
+        final AtomicReference<Rect> rectLottieAnimationView = new AtomicReference<>(
+                new Rect(0, 0, 0, 0));
+        final AtomicReference<Rect> rectUdfpsEnrollView = new AtomicReference<>(
+                new Rect(0, 0, 0, 0));
+
+        headerTextView.getViewTreeObserver().addOnDrawListener(() -> {
+            headerTextView.getLocationOnScreen(headerTextViewPosition);
+            rectHeaderTextView.set(new Rect(headerTextViewPosition[0], headerTextViewPosition[1],
+                    headerTextViewPosition[0] + headerTextView.getWidth(),
+                    headerTextViewPosition[1] + headerTextView.getHeight()));
+        });
+
+        descriptionTextView.getViewTreeObserver().addOnDrawListener(() -> {
+            descriptionTextView.getLocationOnScreen(descriptionTextViewPosition);
+            rectDescriptionTextView.set(new Rect(descriptionTextViewPosition[0],
+                    descriptionTextViewPosition[1], descriptionTextViewPosition[0]
+                    + descriptionTextView.getWidth(), descriptionTextViewPosition[1]
+                    + descriptionTextView.getHeight()));
+
+        });
+
+        udfpsEnrollView.getViewTreeObserver().addOnDrawListener(() -> {
+            udfpsEnrollView.getLocationOnScreen(udfpsEnrollViewPosition);
+            rectUdfpsEnrollView.set(new Rect(udfpsEnrollViewPosition[0],
+                            udfpsEnrollViewPosition[1], udfpsEnrollViewPosition[0]
+                            + udfpsEnrollView.getWidth(), udfpsEnrollViewPosition[1]
+                            + udfpsEnrollView.getHeight()));
+        });
+
+        lottieAnimationContainer.getViewTreeObserver().addOnDrawListener(() -> {
+            lottieAnimationContainer.getLocationOnScreen(lottieAnimationPosition);
+            rectLottieAnimationView.set(new Rect(lottieAnimationPosition[0],
+                    lottieAnimationPosition[1], lottieAnimationPosition[0]
+                    + lottieAnimationContainer.getWidth(), lottieAnimationPosition[1]
+                    + lottieAnimationContainer.getHeight()));
+        });
+
+        // Check if the HeaderTextView and DescriptionTextView overlapped
+        assertThat(rectHeaderTextView.get()
+                .intersect(rectDescriptionTextView.get())).isFalse();
+
+        // Check if the DescriptionTextView and Lottie animation overlapped
+        assertThat(rectDescriptionTextView.get()
+                .intersect(rectLottieAnimationView.get())).isFalse();
+
+        // Check if the Lottie animation and UDSPFEnrollView overlapped
+        assertThat(rectLottieAnimationView.get()
+                .intersect(rectUdfpsEnrollView.get())).isFalse();
+    }
+
+    @Test
     public void forwardEnrollProgressEvents() {
         FeatureFlagUtils.setEnabled(mContext,
                 FeatureFlagUtils.SETTINGS_SHOW_UDFPS_ENROLL_IN_SETTINGS, true);