Merge branch 'ub-now-master' of https://googleplex-android.googlesource.com/_direct/platform/packages/apps/Launcher3 into ub-now-master
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 82b9819..56a205f 100644
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -41,21 +41,14 @@
         <item name="android:background">@null</item>
         <item name="android:textColor">@color/quantum_panel_text_color</item>
         <item name="android:drawablePadding">@dimen/dynamic_grid_icon_drawable_padding</item>
-        <item name="android:shadowRadius">2.0</item>
-        <item name="android:shadowDx">0</item>
-        <item name="android:shadowDy">2</item>
-        <item name="android:shadowColor">@color/quantum_panel_text_shadow_color</item>
+        <item name="android:shadowRadius">0</item>
         <item name="customShadows">false</item>
     </style>
 
     <style name="WorkspaceIcon.Folder">
         <item name="android:background">@null</item>
         <item name="android:textColor">@color/quantum_panel_text_color</item>
-        <item name="android:shadowColor">@color/quantum_panel_text_shadow_color</item>
-        <item name="android:shadowRadius">2.0</item>
-        <item name="android:shadowDx">0</item>
-        <item name="android:shadowDy">2</item>
-
+        <item name="android:shadowRadius">0</item>
         <item name="customShadows">false</item>
     </style>
 
diff --git a/src/com/android/launcher3/AppsCustomizePagedView.java b/src/com/android/launcher3/AppsCustomizePagedView.java
index a92bff1..1bd2907 100644
--- a/src/com/android/launcher3/AppsCustomizePagedView.java
+++ b/src/com/android/launcher3/AppsCustomizePagedView.java
@@ -366,7 +366,11 @@
                     // This code triggers requestLayout so must be posted outside of the
                     // layout pass.
                     public void run() {
-                        if (isAttachedToWindow()) {
+                        boolean attached = true;
+                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+                            attached = isAttachedToWindow();
+                        }
+                        if (attached) {
                             setDataIsReady();
                             onDataReady(getMeasuredWidth(), getMeasuredHeight());
                         }
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 309ab46..1b95c2b 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -59,6 +59,7 @@
 import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.AsyncTask;
+import android.os.Build;
 import android.os.Bundle;
 import android.os.Environment;
 import android.os.Handler;
@@ -499,18 +500,7 @@
             showIntroScreen();
         } else {
             showFirstRunActivity();
-        }
-
-        // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
-        // on the device, then we always show the first run cling experience (or if there is no
-        // launcher2). Otherwise, we prompt the user upon started for migration
-        LauncherClings launcherClings = new LauncherClings(this);
-        if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
-            if (mModel.canMigrateFromOldLauncherDb(this)) {
-                launcherClings.showMigrationCling();
-            } else {
-                launcherClings.showLongPressCling(false);
-            }
+            showFirstRunClings();
         }
     }
 
@@ -3230,7 +3220,10 @@
             mAppsCustomizeTabHost.setContentTypeImmediate(contentType);
         }
 
-        if (animated) {
+        // If for some reason our views aren't initialized, don't animate
+        boolean initialized = getAllAppsButton() != null;
+
+        if (animated && initialized) {
             mStateAnimation = LauncherAnimUtils.createAnimatorSet();
             final AppsCustomizePagedView content = (AppsCustomizePagedView)
                     toView.findViewById(R.id.apps_customize_pane_content);
@@ -3375,9 +3368,6 @@
             final AnimatorSet stateAnimation = mStateAnimation;
             final Runnable startAnimRunnable = new Runnable() {
                 public void run() {
-                    if (!toView.isAttachedToWindow()) {
-                        return;
-                    }
                     // Check that mStateAnimation hasn't changed while
                     // we waited for a layout/draw pass
                     if (mStateAnimation != stateAnimation)
@@ -3389,7 +3379,13 @@
                     if (Utilities.isLmp()) {
                         for (int i = 0; i < layerViews.size(); i++) {
                             View v = layerViews.get(i);
-                            if (v != null) v.buildLayer();
+                            if (v != null) {
+                                boolean attached = true;
+                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+                                    attached = v.isAttachedToWindow();
+                                }
+                                if (attached) v.buildLayer();
+                            }
                         }
                     }
                     mStateAnimation.start();
@@ -3460,7 +3456,10 @@
                     toState, animated, layerViews);
         }
 
-        if (animated) {
+        // If for some reason our views aren't initialized, don't animate
+        boolean initialized = getAllAppsButton() != null;
+
+        if (animated && initialized) {
             mStateAnimation = LauncherAnimUtils.createAnimatorSet();
             if (workspaceAnim != null) {
                 mStateAnimation.play(workspaceAnim);
@@ -3470,6 +3469,15 @@
                     fromView.findViewById(R.id.apps_customize_pane_content);
 
             final View page = content.getPageAt(content.getNextPage());
+
+            // We need to hide side pages of the Apps / Widget tray to avoid some ugly edge cases
+            int count = content.getChildCount();
+            for (int i = 0; i < count; i++) {
+                View child = content.getChildAt(i);
+                if (child != page) {
+                    child.setVisibility(View.INVISIBLE);
+                }
+            }
             final View revealView = fromView.findViewById(R.id.fake_page);
 
             // hideAppsCustomizeHelper is called in some cases when it is already hidden
@@ -3616,6 +3624,19 @@
                         page.setLayerType(View.LAYER_TYPE_NONE, null);
                     }
                     content.setPageBackgroundsVisible(true);
+                    // Unhide side pages
+                    int count = content.getChildCount();
+                    for (int i = 0; i < count; i++) {
+                        View child = content.getChildAt(i);
+                        child.setVisibility(View.VISIBLE);
+                    }
+
+                    // Reset page transforms
+                    page.setTranslationX(0);
+                    page.setTranslationY(0);
+                    page.setAlpha(1);
+                    content.setCurrentPage(content.getNextPage());
+
                     mAppsCustomizeContent.updateCurrentPageScroll();
                 }
             });
@@ -3623,9 +3644,6 @@
             final AnimatorSet stateAnimation = mStateAnimation;
             final Runnable startAnimRunnable = new Runnable() {
                 public void run() {
-                    if (!fromView.isAttachedToWindow()) {
-                        return;
-                    }
                     // Check that mStateAnimation hasn't changed while
                     // we waited for a layout/draw pass
                     if (mStateAnimation != stateAnimation)
@@ -3636,7 +3654,13 @@
                     if (Utilities.isLmp()) {
                         for (int i = 0; i < layerViews.size(); i++) {
                             View v = layerViews.get(i);
-                            if (v != null) v.buildLayer();
+                            if (v != null) {
+                                boolean attached = true;
+                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
+                                    attached = v.isAttachedToWindow();
+                                }
+                                if (attached) v.buildLayer();
+                            }
                         }
                     }
                     mStateAnimation.start();
@@ -4942,10 +4966,12 @@
                 @Override
                 public void run() {
                     mDragLayer.dismissOverlayView();
+                    showFirstRunClings();
                 }
             }, ACTIVITY_START_DELAY);
         } else {
             mDragLayer.dismissOverlayView();
+            showFirstRunClings();
         }
         changeWallpaperVisiblity(true);
     }
@@ -4956,6 +4982,20 @@
         editor.apply();
     }
 
+    private void showFirstRunClings() {
+        // The two first run cling paths are mutually exclusive, if the launcher is preinstalled
+        // on the device, then we always show the first run cling experience (or if there is no
+        // launcher2). Otherwise, we prompt the user upon started for migration
+        LauncherClings launcherClings = new LauncherClings(this);
+        if (launcherClings.shouldShowFirstRunOrMigrationClings()) {
+            if (mModel.canMigrateFromOldLauncherDb(this)) {
+                launcherClings.showMigrationCling();
+            } else {
+                launcherClings.showLongPressCling(false);
+            }
+        }
+    }
+
     void showWorkspaceSearchAndHotseat() {
         if (mWorkspace != null) mWorkspace.setAlpha(1f);
         if (mHotseat != null) mHotseat.setAlpha(1f);
diff --git a/src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java b/src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java
index 535c74b..30af38e 100644
--- a/src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java
+++ b/src/com/android/launcher3/compat/AppWidgetManagerCompatVL.java
@@ -121,12 +121,15 @@
         } else {
             badgeLocation.offset(bitmap.getWidth() - badgeSize - badgeMargin, top);
         }
-
-        UserManager userManager = (UserManager) mContext.getSystemService(
-                Context.USER_SERVICE);
-
-        Drawable drawable = userManager.getBadgedDrawableForUser(new BitmapDrawable(res, bitmap),
-                info.getProfile(), badgeLocation, 0);
+        Drawable drawable = null;
+        // STOPSHIP(mokani): Remove catch block once dogfood build is bigger than LRW70.
+        // This hack is just to prevent crash in older builds.
+        try {
+            drawable = mPm.getUserBadgedDrawableForDensity(new BitmapDrawable(res, bitmap),
+                    info.getProfile(), badgeLocation, 0);
+        } catch (Exception e) {
+            return bitmap;
+        }
 
         if (drawable instanceof BitmapDrawable) {
             return ((BitmapDrawable) drawable).getBitmap();
diff --git a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
index 5d016a8..0a84280 100644
--- a/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
+++ b/src/com/android/launcher3/compat/PackageInstallerCompatVL.java
@@ -47,7 +47,7 @@
         mResumed = false;
         mBound = false;
 
-        mInstaller.addSessionCallback(mCallback);
+        mInstaller.registerSessionCallback(mCallback);
         // On start, send updates for all active sessions
         for (SessionInfo info : mInstaller.getAllSessions()) {
             mPendingReplays.append(info.getSessionId(), info);
@@ -72,7 +72,7 @@
 
     @Override
     public void onStop() {
-        mInstaller.removeSessionCallback(mCallback);
+        mInstaller.unregisterSessionCallback(mCallback);
     }
 
     @Override
@@ -168,10 +168,9 @@
         }
 
         @Override
-        public void onOpened(int sessionId) { }
+        public void onActiveChanged(int sessionId, boolean active) { }
 
         @Override
-        public void onClosed(int sessionId) { }
-
+        public void onBadgingChanged(int sessionId) { }
     };
 }
diff --git a/src/com/android/launcher3/compat/UserManagerCompatVL.java b/src/com/android/launcher3/compat/UserManagerCompatVL.java
index ad6f78e..e54db61 100644
--- a/src/com/android/launcher3/compat/UserManagerCompatVL.java
+++ b/src/com/android/launcher3/compat/UserManagerCompatVL.java
@@ -18,6 +18,7 @@
 package com.android.launcher3.compat;
 
 import android.content.Context;
+import android.content.pm.PackageManager;
 import android.graphics.drawable.Drawable;
 import android.os.UserHandle;
 import android.os.UserManager;
@@ -27,9 +28,11 @@
 import java.util.List;
 
 public class UserManagerCompatVL extends UserManagerCompatV17 {
+    private final PackageManager mPm;
 
     UserManagerCompatVL(Context context) {
         super(context);
+        mPm = context.getPackageManager();
     }
 
     @Override
@@ -48,7 +51,13 @@
 
     @Override
     public Drawable getBadgedDrawableForUser(Drawable unbadged, UserHandleCompat user) {
-        return mUserManager.getBadgedIconForUser(unbadged, user.getUser());
+        // STOPSHIP(mokani): Remove catch block once dogfood build is bigger than LRW70.
+        // This hack is just to prevent crash in older builds.
+        try {
+            return mPm.getUserBadgedIcon(unbadged, user.getUser());
+        } catch (Exception e) {
+            return unbadged;
+        }
     }
 
     @Override
@@ -56,7 +65,13 @@
         if (user == null) {
             return label;
         }
-        return mUserManager.getBadgedLabelForUser(label, user.getUser());
+        // STOPSHIP(mokani): Remove catch block once dogfood build is bigger than LRW70.
+        // This hack is just to prevent crash in older builds.
+        try {
+        return mPm.getUserBadgedLabel(label, user.getUser());
+        } catch (Exception e) {
+            return label;
+        }
     }
 }