Merge "Fix snapshot starting window isn't apply fixed-rotation with IME visible" into tm-dev
diff --git a/core/java/android/app/ComponentOptions.java b/core/java/android/app/ComponentOptions.java
index 58732f0..4e5e384 100644
--- a/core/java/android/app/ComponentOptions.java
+++ b/core/java/android/app/ComponentOptions.java
@@ -99,8 +99,10 @@
     public Bundle toBundle() {
         Bundle b = new Bundle();
         b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED, mPendingIntentBalAllowed);
-        b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION,
-                mPendingIntentBalAllowedByPermission);
+        if (mPendingIntentBalAllowedByPermission) {
+            b.putBoolean(KEY_PENDING_INTENT_BACKGROUND_ACTIVITY_ALLOWED_BY_PERMISSION,
+                    mPendingIntentBalAllowedByPermission);
+        }
         return b;
     }
 }
diff --git a/core/java/android/view/InsetsSourceConsumer.java b/core/java/android/view/InsetsSourceConsumer.java
index d6b75b9..b17e199 100644
--- a/core/java/android/view/InsetsSourceConsumer.java
+++ b/core/java/android/view/InsetsSourceConsumer.java
@@ -36,6 +36,7 @@
 import android.annotation.Nullable;
 import android.graphics.Insets;
 import android.graphics.Rect;
+import android.util.ArraySet;
 import android.util.Log;
 import android.util.proto.ProtoOutputStream;
 import android.view.InsetsState.InternalInsetsType;
@@ -272,11 +273,7 @@
                     mController.getHost().getInputMethodManager(), null /* icProto */);
         }
 
-        // We still need to let the legacy app know the visibility change even if we don't have the
-        // control. If we don't have the source, we don't change the requested visibility for making
-        // the callback behavior compatible.
-        mController.updateCompatSysUiVisibility(
-                mType, (hasControl || source == null) ? mRequestedVisible : isVisible, hasControl);
+        updateCompatSysUiVisibility(hasControl, source, isVisible);
 
         // If we don't have control, we are not able to change the visibility.
         if (!hasControl) {
@@ -294,6 +291,36 @@
         return true;
     }
 
+    private void updateCompatSysUiVisibility(boolean hasControl, InsetsSource source,
+            boolean visible) {
+        final @InsetsType int publicType = InsetsState.toPublicType(mType);
+        if (publicType != WindowInsets.Type.statusBars()
+                && publicType != WindowInsets.Type.navigationBars()) {
+            // System UI visibility only controls status bars and navigation bars.
+            return;
+        }
+        final boolean compatVisible;
+        if (hasControl) {
+            compatVisible = mRequestedVisible;
+        } else if (source != null && !source.getFrame().isEmpty()) {
+            compatVisible = visible;
+        } else {
+            final ArraySet<Integer> types = InsetsState.toInternalType(publicType);
+            for (int i = types.size() - 1; i >= 0; i--) {
+                final InsetsSource s = mState.peekSource(types.valueAt(i));
+                if (s != null && !s.getFrame().isEmpty()) {
+                    // The compat system UI visibility would be updated by another consumer which
+                    // handles the same public insets type.
+                    return;
+                }
+            }
+            // No one provides the public type. Use the requested visibility for making the callback
+            // behavior compatible.
+            compatVisible = mRequestedVisible;
+        }
+        mController.updateCompatSysUiVisibility(mType, compatVisible, hasControl);
+    }
+
     @VisibleForTesting
     public boolean isRequestedVisible() {
         return mRequestedVisible;
diff --git a/core/res/res/layout/log_access_user_consent_dialog_permission.xml b/core/res/res/layout/log_access_user_consent_dialog_permission.xml
index 1a395b9..3da14c8 100644
--- a/core/res/res/layout/log_access_user_consent_dialog_permission.xml
+++ b/core/res/res/layout/log_access_user_consent_dialog_permission.xml
@@ -16,77 +16,86 @@
 ** limitations under the License.
 */
 -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
-              xmlns:app="http://schemas.android.com/apk/res-auto"
-              xmlns:tools="http://schemas.android.com/tools"
-              android:layout_width="380dp"
-              android:layout_height="match_parent"
-              android:orientation="vertical"
-              android:gravity="center"
-              android:paddingLeft="24dp"
-              android:paddingRight="24dp"
-              android:paddingTop="24dp"
-              android:paddingBottom="24dp">
-
-    <ImageView
-            android:id="@+id/log_access_image_view"
-            android:layout_width="32dp"
-            android:layout_height="32dp"
-            android:layout_marginBottom="16dp"
-            android:src="@drawable/ic_doc_document"
-            tools:layout_editor_absoluteX="148dp"
-            tools:layout_editor_absoluteY="35dp"
-            android:gravity="center" />
-
-    <TextView
-            android:id="@+id/log_access_dialog_title"
-            android:layout_height="wrap_content"
-            android:layout_width="wrap_content"
-            android:layout_marginBottom="32dp"
-            android:text="@string/log_access_confirmation_title"
-            android:textAppearance="@style/AllowLogAccess"
-            android:textColor="?android:attr/textColorPrimary"
-            android:gravity="center" />
-
-    <TextView
-            android:id="@+id/log_access_dialog_body"
-            android:layout_height="wrap_content"
-            android:layout_width="wrap_content"
-            android:layout_marginBottom="40dp"
-            android:text="@string/log_access_confirmation_body"
-            android:textAppearance="@style/PrimaryAllowLogAccess"
-            android:textColor="?android:attr/textColorPrimary"
-            android:gravity="center" />
-
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+        xmlns:tools="http://schemas.android.com/tools"
+        android:layout_width="380dp"
+        android:layout_height="match_parent"
+        android:clipToPadding="false">
     <LinearLayout
-            android:orientation="vertical"
             android:layout_width="match_parent"
-            android:layout_height="wrap_content">
-        <Button
-                android:id="@+id/log_access_dialog_allow_button"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:text="@string/log_access_confirmation_allow"
-                style="@style/PermissionGrantButtonTop"
-                android:textAppearance="@style/PermissionGrantButtonTextAppearance"
-                android:layout_marginBottom="5dp"
-                android:layout_centerHorizontal="true"
-                android:layout_alignParentTop="true"
-                android:layout_alignParentBottom="true"
-                android:clipToOutline="true"
+            android:layout_height="match_parent"
+            android:orientation="vertical"
+            android:gravity="center"
+            android:paddingLeft="24dp"
+            android:paddingRight="24dp"
+            android:paddingTop="24dp"
+            android:paddingBottom="24dp">
+
+        <ImageView
+                android:id="@+id/log_access_image_view"
+                android:layout_width="32dp"
+                android:layout_height="32dp"
+                android:layout_marginBottom="16dp"
+                android:src="@drawable/ic_doc_document"
+                tools:layout_editor_absoluteX="148dp"
+                tools:layout_editor_absoluteY="35dp"
                 android:gravity="center" />
 
-        <Button
-                android:id="@+id/log_access_dialog_deny_button"
-                android:layout_width="match_parent"
+        <TextView
+                android:id="@+id/log_access_dialog_title"
                 android:layout_height="wrap_content"
-                android:text="@string/log_access_confirmation_deny"
-                style="@style/PermissionGrantButtonBottom"
-                android:textAppearance="@style/PermissionGrantButtonTextAppearance"
-                android:layout_centerHorizontal="true"
-                android:layout_alignParentTop="true"
-                android:layout_alignParentBottom="true"
-                android:clipToOutline="true"
+                android:layout_width="wrap_content"
+                android:layout_marginBottom="32dp"
+                android:text="@string/log_access_confirmation_title"
+                android:textAppearance="@style/AllowLogAccess"
+                android:textColor="?android:attr/textColorPrimary"
                 android:gravity="center" />
+
+        <TextView
+                android:id="@+id/log_access_dialog_body"
+                android:layout_height="wrap_content"
+                android:layout_width="wrap_content"
+                android:layout_marginBottom="40dp"
+                android:text="@string/log_access_confirmation_body"
+                android:textAppearance="@style/PrimaryAllowLogAccess"
+                android:textColor="?android:attr/textColorPrimary"
+                android:gravity="center" />
+
+        <Space
+                android:layout_width="match_parent"
+                android:layout_height="0dp"
+                android:layout_weight="1" />
+
+        <LinearLayout
+                android:orientation="vertical"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content">
+            <Button
+                    android:id="@+id/log_access_dialog_allow_button"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:text="@string/log_access_confirmation_allow"
+                    style="@style/PermissionGrantButtonTop"
+                    android:textAppearance="@style/PermissionGrantButtonTextAppearance"
+                    android:layout_marginBottom="5dp"
+                    android:layout_centerHorizontal="true"
+                    android:layout_alignParentTop="true"
+                    android:layout_alignParentBottom="true"
+                    android:clipToOutline="true"
+                    android:gravity="center" />
+
+            <Button
+                    android:id="@+id/log_access_dialog_deny_button"
+                    android:layout_width="match_parent"
+                    android:layout_height="wrap_content"
+                    android:text="@string/log_access_confirmation_deny"
+                    style="@style/PermissionGrantButtonBottom"
+                    android:textAppearance="@style/PermissionGrantButtonTextAppearance"
+                    android:layout_centerHorizontal="true"
+                    android:layout_alignParentTop="true"
+                    android:layout_alignParentBottom="true"
+                    android:clipToOutline="true"
+                    android:gravity="center" />
+        </LinearLayout>
     </LinearLayout>
-</LinearLayout>
\ No newline at end of file
+</ScrollView>
diff --git a/services/core/java/com/android/server/logcat/LogAccessDialogActivity.java b/services/core/java/com/android/server/logcat/LogAccessDialogActivity.java
index f9a8407..98bae3d 100644
--- a/services/core/java/com/android/server/logcat/LogAccessDialogActivity.java
+++ b/services/core/java/com/android/server/logcat/LogAccessDialogActivity.java
@@ -105,7 +105,7 @@
     @Override
     protected void onDestroy() {
         super.onDestroy();
-        if (mAlert != null && mAlert.isShowing()) {
+        if (!isChangingConfigurations() && mAlert != null && mAlert.isShowing()) {
             mAlert.dismiss();
         }
         mAlert = null;