Merge "Fix incorrect background bounds set by stackscroll view" into pi-dev
diff --git a/config/hiddenapi-light-greylist.txt b/config/hiddenapi-light-greylist.txt
index 7bc997d..e053c3e 100644
--- a/config/hiddenapi-light-greylist.txt
+++ b/config/hiddenapi-light-greylist.txt
@@ -29,6 +29,7 @@
 Landroid/app/ActionBar;->setShowHideAnimationEnabled(Z)V
 Landroid/app/Activity;->getActivityOptions()Landroid/app/ActivityOptions;
 Landroid/app/Activity;->getActivityToken()Landroid/os/IBinder;
+Landroid/app/Activity;->isResumed()Z
 Landroid/app/Activity;->mActivityInfo:Landroid/content/pm/ActivityInfo;
 Landroid/app/Activity;->mApplication:Landroid/app/Application;
 Landroid/app/Activity;->mCalled:Z
@@ -268,6 +269,7 @@
 Landroid/app/ContextImpl;->mPackageManager:Landroid/content/pm/PackageManager;
 Landroid/app/ContextImpl;->mResources:Landroid/content/res/Resources;
 Landroid/app/ContextImpl;->mServiceCache:[Ljava/lang/Object;
+Landroid/app/ContextImpl;->mSharedPrefsPaths:Landroid/util/ArrayMap;
 Landroid/app/ContextImpl;->mTheme:Landroid/content/res/Resources$Theme;
 Landroid/app/ContextImpl;->mThemeResource:I
 Landroid/app/ContextImpl;->scheduleFinalCleanup(Ljava/lang/String;Ljava/lang/String;)V
@@ -2591,10 +2593,13 @@
 Landroid/view/ContextThemeWrapper;->mThemeResource:I
 Landroid/view/Display$HdrCapabilities;-><init>([IFFF)V
 Landroid/view/Display;->getDisplayAdjustments()Landroid/view/DisplayAdjustments;
+Landroid/view/Display;->getDisplayInfo(Landroid/view/DisplayInfo;)Z
 Landroid/view/DisplayAdjustments;->getConfiguration()Landroid/content/res/Configuration;
 Landroid/view/DisplayAdjustments;->setCompatibilityInfo(Landroid/content/res/CompatibilityInfo;)V
 Landroid/view/DisplayEventReceiver;->dispatchHotplug(JIZ)V
 Landroid/view/DisplayEventReceiver;->dispatchVsync(JII)V
+Landroid/view/DisplayInfo;-><init>()V
+Landroid/view/DisplayInfo;->displayCutout:Landroid/view/DisplayCutout;
 Landroid/view/DisplayListCanvas;->callDrawGLFunction2(J)V
 Landroid/view/DisplayListCanvas;->drawGLFunctor2(JLjava/lang/Runnable;)V
 Landroid/view/FrameMetrics;->mTimingData:[J
@@ -3405,16 +3410,19 @@
 Lcom/android/internal/R$drawable;->no_tile_256:I
 Lcom/android/internal/R$drawable;->reticle:I
 Lcom/android/internal/R$id;->amPm:I
+Lcom/android/internal/R$id;->day:I
 Lcom/android/internal/R$id;->edittext_container:I
 Lcom/android/internal/R$id;->icon:I
 Lcom/android/internal/R$id;->message:I
 Lcom/android/internal/R$id;->minute:I
+Lcom/android/internal/R$id;->month:I
 Lcom/android/internal/R$id;->shortcut:I
 Lcom/android/internal/R$id;->text:I
 Lcom/android/internal/R$id;->time:I
 Lcom/android/internal/R$id;->timePicker:I
 Lcom/android/internal/R$id;->title:I
 Lcom/android/internal/R$id;->title_container:I
+Lcom/android/internal/R$id;->year:I
 Lcom/android/internal/R$integer;->config_screenBrightnessDim:I
 Lcom/android/internal/R$integer;->config_toastDefaultGravity:I
 Lcom/android/internal/R$layout;->screen_title:I
diff --git a/core/java/android/app/Activity.java b/core/java/android/app/Activity.java
index b456b72..3b62bd7 100644
--- a/core/java/android/app/Activity.java
+++ b/core/java/android/app/Activity.java
@@ -5578,7 +5578,7 @@
         if (mParent != null) {
             throw new IllegalStateException("Can only be called on top-level activity");
         }
-        mMainThread.handleRelaunchActivityLocally(mToken);
+        mMainThread.scheduleRelaunchActivity(mToken);
     }
 
     /**
diff --git a/core/java/android/app/ActivityThread.java b/core/java/android/app/ActivityThread.java
index 3f66747..a183f73 100644
--- a/core/java/android/app/ActivityThread.java
+++ b/core/java/android/app/ActivityThread.java
@@ -1555,6 +1555,7 @@
         public static final int APPLICATION_INFO_CHANGED = 156;
         public static final int RUN_ISOLATED_ENTRY_POINT = 158;
         public static final int EXECUTE_TRANSACTION = 159;
+        public static final int RELAUNCH_ACTIVITY = 160;
 
         String codeToString(int code) {
             if (DEBUG_MESSAGES) {
@@ -1598,6 +1599,7 @@
                     case APPLICATION_INFO_CHANGED: return "APPLICATION_INFO_CHANGED";
                     case RUN_ISOLATED_ENTRY_POINT: return "RUN_ISOLATED_ENTRY_POINT";
                     case EXECUTE_TRANSACTION: return "EXECUTE_TRANSACTION";
+                    case RELAUNCH_ACTIVITY: return "RELAUNCH_ACTIVITY";
                 }
             }
             return Integer.toString(code);
@@ -1780,6 +1782,9 @@
                     }
                     // TODO(lifecycler): Recycle locally scheduled transactions.
                     break;
+                case RELAUNCH_ACTIVITY:
+                    handleRelaunchActivityLocally((IBinder) msg.obj);
+                    break;
             }
             Object obj = msg.obj;
             if (obj instanceof SomeArgs) {
@@ -4284,7 +4289,7 @@
         for (Map.Entry<IBinder, ActivityClientRecord> entry : mActivities.entrySet()) {
             final Activity activity = entry.getValue().activity;
             if (!activity.mFinished) {
-                handleRelaunchActivityLocally(entry.getKey());
+                scheduleRelaunchActivity(entry.getKey());
             }
         }
     }
@@ -4662,21 +4667,29 @@
         }
     }
 
-    /** Performs the activity relaunch locally vs. requesting from system-server. */
-    void handleRelaunchActivityLocally(IBinder token) {
-        if (Looper.myLooper() != getLooper()) {
-            throw new IllegalStateException("Must be called from main thread");
-        }
+    /**
+     * Post a message to relaunch the activity. We do this instead of launching it immediately,
+     * because this will destroy the activity from which it was called and interfere with the
+     * lifecycle changes it was going through before. We need to make sure that we have finished
+     * handling current transaction item before relaunching the activity.
+     */
+    void scheduleRelaunchActivity(IBinder token) {
+        sendMessage(H.RELAUNCH_ACTIVITY, token);
+    }
 
+    /** Performs the activity relaunch locally vs. requesting from system-server. */
+    private void handleRelaunchActivityLocally(IBinder token) {
         final ActivityClientRecord r = mActivities.get(token);
         if (r == null) {
+            Log.w(TAG, "Activity to relaunch no longer exists");
             return;
         }
 
         final int prevState = r.getLifecycleState();
 
-        if (prevState < ON_RESUME) {
-            Log.w(TAG, "Activity needs to be already resumed in other to be relaunched.");
+        if (prevState < ON_RESUME || prevState > ON_STOP) {
+            Log.w(TAG, "Activity state must be in [ON_RESUME..ON_STOP] in order to be relaunched,"
+                    + "current state is " + prevState);
             return;
         }
 
diff --git a/core/java/android/app/WallpaperManager.java b/core/java/android/app/WallpaperManager.java
index 6c2fb2d..fde756c 100644
--- a/core/java/android/app/WallpaperManager.java
+++ b/core/java/android/app/WallpaperManager.java
@@ -442,9 +442,6 @@
             synchronized (this) {
                 mCachedWallpaper = null;
                 mCachedWallpaperUserId = 0;
-                if (mDefaultWallpaper != null) {
-                    mDefaultWallpaper.recycle();
-                }
                 mDefaultWallpaper = null;
             }
         }
diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java
index 510626b..5546e80 100644
--- a/core/java/android/service/notification/ZenModeConfig.java
+++ b/core/java/android/service/notification/ZenModeConfig.java
@@ -93,11 +93,11 @@
     private static final boolean DEFAULT_ALLOW_ALARMS = true;
     private static final boolean DEFAULT_ALLOW_MEDIA = true;
     private static final boolean DEFAULT_ALLOW_SYSTEM = false;
-    private static final boolean DEFAULT_ALLOW_CALLS = false;
+    private static final boolean DEFAULT_ALLOW_CALLS = true;
     private static final boolean DEFAULT_ALLOW_MESSAGES = false;
     private static final boolean DEFAULT_ALLOW_REMINDERS = false;
     private static final boolean DEFAULT_ALLOW_EVENTS = false;
-    private static final boolean DEFAULT_ALLOW_REPEAT_CALLERS = false;
+    private static final boolean DEFAULT_ALLOW_REPEAT_CALLERS = true;
     private static final boolean DEFAULT_CHANNELS_BYPASSING_DND = false;
     private static final int DEFAULT_SUPPRESSED_VISUAL_EFFECTS = 0;
 
@@ -486,7 +486,7 @@
                         rt.allowCallsFrom = from;
                         rt.allowMessagesFrom = from;
                     } else {
-                        rt.allowCallsFrom = DEFAULT_SOURCE;
+                        rt.allowCallsFrom = DEFAULT_CALLS_SOURCE;
                         rt.allowMessagesFrom = DEFAULT_SOURCE;
                     }
                     rt.allowAlarms = safeBoolean(parser, ALLOW_ATT_ALARMS, DEFAULT_ALLOW_ALARMS);
diff --git a/core/res/res/xml/default_zen_mode_config.xml b/core/res/res/xml/default_zen_mode_config.xml
index ba8173e..35a0cc2 100644
--- a/core/res/res/xml/default_zen_mode_config.xml
+++ b/core/res/res/xml/default_zen_mode_config.xml
@@ -19,8 +19,8 @@
 
 <!-- Default configuration for zen mode.  See android.service.notification.ZenModeConfig. -->
 <zen version="7">
-    <allow alarms="true" media="true" system="false" calls="false" callsFrom="2" messages="false"
-           reminders="false" events="false" />
+    <allow alarms="true" media="true" system="false" calls="true" callsFrom="2" messages="false"
+           reminders="false" events="false" repeatCallers="true" />
 
     <!-- all visual effects that exist as of P -->
     <disallow suppressedVisualEffect="511" />
diff --git a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
index d732a46..79bb534 100644
--- a/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
+++ b/libs/hwui/pipeline/skia/SkiaOpenGLPipeline.cpp
@@ -28,6 +28,8 @@
 #include "utils/TraceUtils.h"
 
 #include <GrBackendSurface.h>
+#include <SkImageInfo.h>
+#include <SkBlendMode.h>
 
 #include <cutils/properties.h>
 #include <strings.h>
@@ -129,20 +131,49 @@
     deferredLayer->updateTexImage();
     deferredLayer->apply();
 
+    // drop the colorSpace as we only support readback into sRGB or extended sRGB
+    SkImageInfo surfaceInfo = bitmap->info().makeColorSpace(nullptr);
+
     /* This intermediate surface is present to work around a bug in SwiftShader that
      * prevents us from reading the contents of the layer's texture directly. The
      * workaround involves first rendering that texture into an intermediate buffer and
      * then reading from the intermediate buffer into the bitmap.
      */
     sk_sp<SkSurface> tmpSurface = SkSurface::MakeRenderTarget(mRenderThread.getGrContext(),
-                                                              SkBudgeted::kYes, bitmap->info());
+                                                              SkBudgeted::kYes, surfaceInfo);
+
+    if (!tmpSurface.get()) {
+        surfaceInfo = surfaceInfo.makeColorType(SkColorType::kN32_SkColorType);
+        tmpSurface = SkSurface::MakeRenderTarget(mRenderThread.getGrContext(),
+                                                 SkBudgeted::kYes, surfaceInfo);
+        if (!tmpSurface.get()) {
+            ALOGW("Unable to readback GPU contents into the provided bitmap");
+            return false;
+        }
+    }
 
     Layer* layer = deferredLayer->backingLayer();
     const SkRect dstRect = SkRect::MakeIWH(bitmap->width(), bitmap->height());
     if (LayerDrawable::DrawLayer(mRenderThread.getGrContext(), tmpSurface->getCanvas(), layer,
                                  &dstRect)) {
         sk_sp<SkImage> tmpImage = tmpSurface->makeImageSnapshot();
-        if (tmpImage->readPixels(bitmap->info(), bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
+        if (tmpImage->readPixels(surfaceInfo, bitmap->getPixels(), bitmap->rowBytes(), 0, 0)) {
+            bitmap->notifyPixelsChanged();
+            return true;
+        }
+
+        // if we fail to readback from the GPU directly (e.g. 565) then we attempt to read into 8888
+        // and then draw that into the destination format before giving up.
+        SkBitmap tmpBitmap;
+        SkImageInfo bitmapInfo = SkImageInfo::MakeN32(bitmap->width(), bitmap->height(),
+                                                      bitmap->alphaType());
+        if (tmpBitmap.tryAllocPixels(bitmapInfo) &&
+                tmpImage->readPixels(bitmapInfo, tmpBitmap.getPixels(),
+                                     tmpBitmap.rowBytes(), 0, 0)) {
+            SkCanvas canvas(*bitmap);
+            SkPaint paint;
+            paint.setBlendMode(SkBlendMode::kSrc);
+            canvas.drawBitmap(tmpBitmap, 0, 0, &paint);
             bitmap->notifyPixelsChanged();
             return true;
         }
diff --git a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java
index 1ca3c1d..cdaabdc 100644
--- a/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java
+++ b/packages/CompanionDeviceManager/src/com/android/companiondevicemanager/DeviceDiscoveryService.java
@@ -234,7 +234,9 @@
 
         DeviceChooserActivity activity = mActivity;
         if (activity != null) {
-            activity.mDeviceListView.removeFooterView(activity.mLoadingIndicator);
+            if (activity.mDeviceListView != null) {
+                activity.mDeviceListView.removeFooterView(activity.mLoadingIndicator);
+            }
             mActivity = null;
         }
 
diff --git a/packages/SystemUI/res/layout/notification_info.xml b/packages/SystemUI/res/layout/notification_info.xml
index 095f181..88d19f4 100644
--- a/packages/SystemUI/res/layout/notification_info.xml
+++ b/packages/SystemUI/res/layout/notification_info.xml
@@ -16,24 +16,23 @@
 -->
 
 <com.android.systemui.statusbar.NotificationInfo
-        xmlns:android="http://schemas.android.com/apk/res/android"
-        android:id="@+id/notification_guts"
-        android:layout_width="match_parent"
-        android:layout_height="wrap_content"
-        android:clickable="true"
-        android:clipChildren="false"
-        android:clipToPadding="false"
-        android:orientation="vertical"
-        android:paddingStart="@*android:dimen/notification_content_margin_start"
-        android:paddingEnd="@*android:dimen/notification_content_margin_end"
-        android:background="@color/notification_guts_bg_color"
-        android:theme="@*android:style/Theme.DeviceDefault.Light">
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/notification_guts"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:clickable="true"
+    android:clipChildren="false"
+    android:clipToPadding="false"
+    android:orientation="vertical"
+    android:background="@color/notification_guts_bg_color"
+    android:theme="@*android:style/Theme.DeviceDefault.Light">
 
     <!-- Package Info -->
     <RelativeLayout
         android:id="@+id/header"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_marginStart="@*android:dimen/notification_content_margin_start"
         android:clipChildren="false"
         android:clipToPadding="false">
         <ImageView
@@ -73,13 +72,13 @@
             android:maxLines="1"
             android:layout_centerVertical="true"
             android:layout_toEndOf="@id/pkg_group_divider" />
+        <!-- 24 dp icon with 16 dp padding all around to mirror notification content margins -->
         <ImageButton
             android:id="@+id/info"
             android:layout_width="56dp"
             android:layout_height="56dp"
             android:layout_alignParentEnd="true"
             android:layout_centerVertical="true"
-            android:layout_marginEnd="-16dp"
             android:background="@drawable/ripple_drawable"
             android:contentDescription="@string/notification_more_settings"
             android:padding="16dp"
@@ -100,6 +99,8 @@
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
+            android:layout_marginStart="@*android:dimen/notification_content_margin_start"
+            android:layout_marginEnd="@*android:dimen/notification_content_margin_start"
             android:orientation="vertical">
             <!-- Channel Name -->
             <TextView
@@ -120,9 +121,11 @@
         <LinearLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:orientation="horizontal"
             android:layout_marginTop="@dimen/notification_guts_button_spacing"
-            android:gravity="end" >
+            android:layout_marginStart="@dimen/notification_guts_button_side_margin"
+            android:layout_marginEnd="@dimen/notification_guts_button_side_margin"
+            android:gravity="end"
+            android:orientation="horizontal">
 
             <!-- Optional link to app. Only appears if the channel is not disabled and the app
             asked for it -->
@@ -154,7 +157,6 @@
                 android:text="@string/inline_keep_button"
                 android:layout_width="wrap_content"
                 android:layout_height="match_parent"
-                android:layout_marginEnd="-8dp"
                 android:layout_marginStart="@dimen/notification_guts_button_horizontal_spacing"
                 style="@style/TextAppearance.NotificationInfo.Button"/>
         </LinearLayout>
@@ -165,6 +167,8 @@
         android:layout_height="wrap_content"
         android:layout_marginBottom="@dimen/notification_guts_button_spacing"
         android:layout_marginTop="@dimen/notification_guts_button_spacing"
+        android:layout_marginStart="@dimen/notification_guts_button_side_margin"
+        android:layout_marginEnd="@dimen/notification_guts_button_side_margin"
         android:visibility="gone"
         android:orientation="horizontal" >
         <TextView
@@ -180,7 +184,6 @@
             android:layout_height="wrap_content"
             android:layout_alignParentEnd="true"
             android:layout_centerVertical="true"
-            android:layout_marginEnd="-8dp"
             android:text="@string/inline_undo"
             style="@style/TextAppearance.NotificationInfo.Button"/>
     </RelativeLayout>
diff --git a/packages/SystemUI/res/layout/notification_snooze.xml b/packages/SystemUI/res/layout/notification_snooze.xml
index 7476abd..ea6ef4c 100644
--- a/packages/SystemUI/res/layout/notification_snooze.xml
+++ b/packages/SystemUI/res/layout/notification_snooze.xml
@@ -50,13 +50,13 @@
 
         <TextView
             android:id="@+id/undo"
-            style="@style/TextAppearance.NotificationInfo.Button"
             android:layout_width="wrap_content"
-            android:layout_height="36dp"
-            android:layout_marginEnd="@*android:dimen/notification_content_margin_end"
+            android:layout_height="48dp"
+            android:layout_marginEnd="@dimen/notification_guts_button_side_margin"
             android:layout_alignParentEnd="true"
             android:layout_centerVertical="true"
-            android:text="@string/snooze_undo" />
+            android:text="@string/snooze_undo"
+            style="@style/TextAppearance.NotificationInfo.Button" />
     </RelativeLayout>
 
     <View
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index af343fb..ad74725 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -161,11 +161,14 @@
     <!-- The vertical space around the buttons in the inline settings -->
     <dimen name="notification_guts_button_spacing">6dp</dimen>
 
+    <!-- Extra horizontal space for properly aligning guts buttons with the notification content -->
+    <dimen name="notification_guts_button_side_margin">8dp</dimen>
+
     <!-- The vertical padding a notification guts button has to fulfill the 48dp touch target -->
     <dimen name="notification_guts_button_vertical_padding">14dp</dimen>
 
     <!-- The horizontal padding for notification guts buttons-->
-    <dimen name="notification_guts_button_horizontal_padding">14dp</dimen>
+    <dimen name="notification_guts_button_horizontal_padding">8dp</dimen>
 
     <!-- The horizontal space around the buttons in the inline settings -->
     <dimen name="notification_guts_button_horizontal_spacing">8dp</dimen>
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java
index a0df558..18e8775 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NavigationBarGestureHelper.java
@@ -74,6 +74,7 @@
     private boolean mDownOnRecents;
     private VelocityTracker mVelocityTracker;
     private boolean mIsInScreenPinning;
+    private boolean mNotificationsVisibleOnDown;
 
     private boolean mDockWindowEnabled;
     private boolean mDockWindowTouchSlopExceeded;
@@ -108,6 +109,7 @@
     public boolean onInterceptTouchEvent(MotionEvent event) {
         if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
             mIsInScreenPinning = mNavigationBarView.inScreenPinning();
+            mNotificationsVisibleOnDown = !mStatusBar.isPresenterFullyCollapsed();
         }
         if (!canHandleGestures()) {
             return false;
@@ -274,7 +276,7 @@
 
     private boolean canHandleGestures() {
         return !mIsInScreenPinning && !mStatusBar.isKeyguardShowing()
-                && mStatusBar.isPresenterFullyCollapsed();
+                && !mNotificationsVisibleOnDown;
     }
 
     private int calculateDragMode() {