Merge "Fixing issue with building velvet against lower support lib." into ub-launcher3-burnaby
diff --git a/res/anim/fade_in_fast.xml b/res/anim/fade_in_fast.xml
deleted file mode 100644
index 4fa9847..0000000
--- a/res/anim/fade_in_fast.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
-    android:interpolator="@android:anim/accelerate_interpolator"
-
-    android:fromAlpha="0.0"
-    android:toAlpha="1.0"
-
-    android:duration="@android:integer/config_mediumAnimTime" />
diff --git a/res/anim/fade_out_fast.xml b/res/anim/fade_out_fast.xml
deleted file mode 100644
index a061a6c..0000000
--- a/res/anim/fade_out_fast.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2009 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.
--->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
-    android:interpolator="@android:anim/accelerate_interpolator"
-
-    android:fromAlpha="1.0"
-    android:toAlpha="0.0"
-
-    android:duration="@android:integer/config_mediumAnimTime" />
diff --git a/res/anim/no_anim.xml b/res/anim/no_anim.xml
deleted file mode 100644
index 02b1625..0000000
--- a/res/anim/no_anim.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2014 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.
--->
-
-<alpha xmlns:android="http://schemas.android.com/apk/res/android"
-    android:duration="417" />
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index b4d225e..73f54ab 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -781,7 +781,8 @@
             lp.gravity = Gravity.BOTTOM;
             lp.width = LayoutParams.MATCH_PARENT;
             lp.height = hotseatBarHeightPx;
-            hotseat.setPadding(2 * edgeMarginPx, 0, 2 * edgeMarginPx, 0);
+            hotseat.findViewById(R.id.layout).setPadding(2 * edgeMarginPx, 0,
+                    2 * edgeMarginPx, 0);
         }
         hotseat.setLayoutParams(lp);
 
diff --git a/src/com/android/launcher3/IconCache.java b/src/com/android/launcher3/IconCache.java
index 9b2119e..f4af7f5 100644
--- a/src/com/android/launcher3/IconCache.java
+++ b/src/com/android/launcher3/IconCache.java
@@ -49,6 +49,7 @@
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map.Entry;
 
 /**
@@ -200,7 +201,7 @@
                     PackageManager.GET_UNINSTALLED_PACKAGES);
             long userSerial = mUserManager.getSerialNumberForUser(user);
             for (LauncherActivityInfoCompat app : mLauncherApps.getActivityList(packageName, user)) {
-                addIconToDB(app, info, userSerial);
+                addIconToDBAndMemCache(app, info, userSerial);
             }
         } catch (NameNotFoundException e) {
             Log.d(TAG, "Package not found", e);
@@ -225,6 +226,7 @@
      * @return The set of packages for which icons have updated.
      */
     public HashSet<String> updateDBIcons(UserHandleCompat user, List<LauncherActivityInfoCompat> apps) {
+        mIconDb.updateSystemStateString(mContext);
         long userSerial = mUserManager.getSerialNumberForUser(user);
         PackageManager pm = mContext.getPackageManager();
         HashMap<String, PackageInfo> pkgInfoMap = new HashMap<String, PackageInfo>();
@@ -239,7 +241,8 @@
 
         Cursor c = mIconDb.getReadableDatabase().query(IconDB.TABLE_NAME,
                 new String[] {IconDB.COLUMN_ROWID, IconDB.COLUMN_COMPONENT,
-                    IconDB.COLUMN_LAST_UPDATED, IconDB.COLUMN_VERSION},
+                    IconDB.COLUMN_LAST_UPDATED, IconDB.COLUMN_VERSION,
+                    IconDB.COLUMN_SYSTEM_STATE},
                 IconDB.COLUMN_USER + " = ? ",
                 new String[] {Long.toString(userSerial)},
                 null, null, null);
@@ -248,6 +251,7 @@
         final int indexLastUpdate = c.getColumnIndex(IconDB.COLUMN_LAST_UPDATED);
         final int indexVersion = c.getColumnIndex(IconDB.COLUMN_VERSION);
         final int rowIndex = c.getColumnIndex(IconDB.COLUMN_ROWID);
+        final int systemStateIndex = c.getColumnIndex(IconDB.COLUMN_SYSTEM_STATE);
 
         HashSet<Integer> itemsToRemove = new HashSet<Integer>();
         HashSet<String> updatedPackages = new HashSet<String>();
@@ -268,7 +272,8 @@
             long updateTime = c.getLong(indexLastUpdate);
             int version = c.getInt(indexVersion);
             LauncherActivityInfoCompat app = componentMap.remove(component);
-            if (version == info.versionCode && updateTime == info.lastUpdateTime) {
+            if (version == info.versionCode && updateTime == info.lastUpdateTime &&
+                    TextUtils.equals(mIconDb.mSystemState, c.getString(systemStateIndex))) {
                 continue;
             }
             if (app == null) {
@@ -295,14 +300,25 @@
             if (info == null) {
                 continue;
             }
-            addIconToDB(app, info, userSerial);
+            addIconToDBAndMemCache(app, info, userSerial);
         }
         return updatedPackages;
     }
 
-    private void addIconToDB(LauncherActivityInfoCompat app, PackageInfo info, long userSerial) {
+    private void addIconToDBAndMemCache(LauncherActivityInfoCompat app, PackageInfo info,
+            long userSerial) {
         ContentValues values = updateCacheAndGetContentValues(app);
+        addIconToDB(values, app.getComponentName(), info, userSerial);
         values.put(IconDB.COLUMN_COMPONENT, app.getComponentName().flattenToString());
+    }
+
+    /**
+     * Updates {@param values} to contain versoning information and adds it to the DB.
+     * @param values {@link ContentValues} containing icon & title
+     */
+    private void addIconToDB(ContentValues values, ComponentName key,
+            PackageInfo info, long userSerial) {
+        values.put(IconDB.COLUMN_COMPONENT, key.flattenToString());
         values.put(IconDB.COLUMN_USER, userSerial);
         values.put(IconDB.COLUMN_LAST_UPDATED, info.lastUpdateTime);
         values.put(IconDB.COLUMN_VERSION, info.versionCode);
@@ -320,7 +336,6 @@
         return mIconDb.newContentValues(entry.icon, entry.title.toString());
     }
 
-
     /**
      * Empty out the cache.
      */
@@ -435,6 +450,18 @@
         shortcutInfo.usingLowResIcon = entry.isLowResIcon;
     }
 
+    /**
+     * Fill in {@param appInfo} with the icon and label for {@param packageName}
+     */
+    public synchronized void getTitleAndIconForApp(
+            String packageName, UserHandleCompat user, boolean useLowResIcon, AppInfo appInfoOut) {
+        CacheEntry entry = getEntryForPackageLocked(packageName, user, useLowResIcon);
+        appInfoOut.iconBitmap = entry.icon;
+        appInfoOut.title = entry.title;
+        appInfoOut.usingLowResIcon = entry.isLowResIcon;
+        appInfoOut.contentDescription = entry.contentDescription;
+    }
+
     public synchronized Bitmap getDefaultIcon(UserHandleCompat user) {
         if (!mDefaultIcons.containsKey(user)) {
             mDefaultIcons.put(user, makeDefaultIcon(user));
@@ -464,8 +491,8 @@
                     entry.icon = Utilities.createIconBitmap(info.getBadgedIcon(mIconDpi), mContext);
                 } else {
                     if (usePackageIcon) {
-                        CacheEntry packageEntry = getEntryForPackage(
-                                componentName.getPackageName(), user);
+                        CacheEntry packageEntry = getEntryForPackageLocked(
+                                componentName.getPackageName(), user, false);
                         if (packageEntry != null) {
                             if (DEBUG) Log.d(TAG, "using package default icon for " +
                                     componentName.toShortString());
@@ -498,7 +525,7 @@
             Bitmap icon, CharSequence title) {
         removeFromMemCacheLocked(packageName, user);
 
-        CacheEntry entry = getEntryForPackage(packageName, user);
+        CacheEntry entry = getEntryForPackageLocked(packageName, user, false);
         if (!TextUtils.isEmpty(title)) {
             entry.title = title;
         }
@@ -510,24 +537,41 @@
     /**
      * Gets an entry for the package, which can be used as a fallback entry for various components.
      * This method is not thread safe, it must be called from a synchronized method.
+     *
      */
-    private CacheEntry getEntryForPackage(String packageName, UserHandleCompat user) {
-        ComponentName cn = new ComponentName(packageName, EMPTY_CLASS_NAME);;
+    private CacheEntry getEntryForPackageLocked(String packageName, UserHandleCompat user,
+            boolean useLowResIcon) {
+        ComponentName cn = new ComponentName(packageName, EMPTY_CLASS_NAME);
         ComponentKey cacheKey = new ComponentKey(cn, user);
         CacheEntry entry = mCache.get(cacheKey);
-        if (entry == null) {
+        if (entry == null || (entry.isLowResIcon && !useLowResIcon)) {
             entry = new CacheEntry();
-            entry.title = "";
-            entry.contentDescription = "";
             mCache.put(cacheKey, entry);
 
-            try {
-                ApplicationInfo info = mPackageManager.getApplicationInfo(packageName, 0);
-                entry.icon = Utilities.createIconBitmap(info.loadIcon(mPackageManager), mContext);
-                entry.title = info.loadLabel(mPackageManager);
-                entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
-            } catch (NameNotFoundException e) {
-                if (DEBUG) Log.d(TAG, "Application not installed " + packageName);
+            // Check the DB first.
+            if (!getEntryFromDB(cn, user, entry, useLowResIcon)) {
+                try {
+                    PackageInfo info = mPackageManager.getPackageInfo(packageName, 0);
+                    ApplicationInfo appInfo = info.applicationInfo;
+                    if (appInfo == null) {
+                        throw new NameNotFoundException("ApplicationInfo is null");
+                    }
+                    Drawable drawable = mUserManager.getBadgedDrawableForUser(
+                            appInfo.loadIcon(mPackageManager), user);
+                    entry.icon = Utilities.createIconBitmap(drawable, mContext);
+                    entry.title = appInfo.loadLabel(mPackageManager);
+                    entry.contentDescription = mUserManager.getBadgedLabelForUser(entry.title, user);
+                    entry.isLowResIcon = false;
+
+                    // Add the icon in the DB here, since these do not get written during
+                    // package updates.
+                    ContentValues values =
+                            mIconDb.newContentValues(entry.icon, entry.title.toString());
+                    addIconToDB(values, cn, info, mUserManager.getSerialNumberForUser(user));
+
+                } catch (NameNotFoundException e) {
+                    if (DEBUG) Log.d(TAG, "Application not installed " + packageName);
+                }
             }
         }
         return entry;
@@ -605,7 +649,7 @@
     }
 
     private static final class IconDB extends SQLiteOpenHelper {
-        private final static int DB_VERSION = 2;
+        private final static int DB_VERSION = 3;
 
         private final static String TABLE_NAME = "icons";
         private final static String COLUMN_ROWID = "rowid";
@@ -616,11 +660,21 @@
         private final static String COLUMN_ICON = "icon";
         private final static String COLUMN_ICON_LOW_RES = "icon_low_res";
         private final static String COLUMN_LABEL = "label";
+        private final static String COLUMN_SYSTEM_STATE = "system_state";
+
+        public String mSystemState;
 
         public IconDB(Context context) {
             super(context, LauncherFiles.APP_ICONS_DB, null, DB_VERSION);
+            updateSystemStateString(context);
         }
 
+        public void updateSystemStateString(Context c) {
+            mSystemState = Locale.getDefault().toString() + ","
+                    + c.getResources().getConfiguration().mcc;
+        }
+
+
         @Override
         public void onCreate(SQLiteDatabase db) {
             db.execSQL("CREATE TABLE IF NOT EXISTS " + TABLE_NAME + " (" +
@@ -631,6 +685,7 @@
                     COLUMN_ICON + " BLOB, " +
                     COLUMN_ICON_LOW_RES + " BLOB, " +
                     COLUMN_LABEL + " TEXT, " +
+                    COLUMN_SYSTEM_STATE + " TEXT, " +
                     "PRIMARY KEY (" + COLUMN_COMPONENT + ", " + COLUMN_USER + ") " +
                     ");");
         }
@@ -656,12 +711,13 @@
 
         public ContentValues newContentValues(Bitmap icon, String label) {
             ContentValues values = new ContentValues();
-            values.put(IconDB.COLUMN_ICON, Utilities.flattenBitmap(icon));
-            values.put(IconDB.COLUMN_ICON_LOW_RES, Utilities.flattenBitmap(
+            values.put(COLUMN_ICON, Utilities.flattenBitmap(icon));
+            values.put(COLUMN_ICON_LOW_RES, Utilities.flattenBitmap(
                     Bitmap.createScaledBitmap(icon,
                             icon.getWidth() / LOW_RES_SCALE_FACTOR,
                             icon.getHeight() / LOW_RES_SCALE_FACTOR, true)));
-            values.put(IconDB.COLUMN_LABEL, label);
+            values.put(COLUMN_LABEL, label);
+            values.put(COLUMN_SYSTEM_STATE, mSystemState);
             return values;
         }
     }
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index c040d93..2fa2f4a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -2958,14 +2958,11 @@
                         sClipRevealMethod = null;
                     }
                 }
-                if (opts == null) {
-                    opts = Utilities.isLmpOrAbove() ?
-                            ActivityOptions.makeCustomAnimation(this,
-                                    R.anim.task_open_enter, R.anim.no_anim) :
-                            ActivityOptions.makeScaleUpAnimation(v, 0, 0,
+                if (opts == null && !Utilities.isLmpOrAbove()) {
+                    opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0,
                                     v.getMeasuredWidth(), v.getMeasuredHeight());
                 }
-                optsBundle = opts.toBundle();
+                optsBundle = opts != null ? opts.toBundle() : null;
             }
 
             if (user == null || user.equals(UserHandleCompat.myUserHandle())) {
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index a23553a..1f59533 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -341,8 +341,11 @@
         Context ctx = getContext();
         UserManager um = (UserManager) ctx.getSystemService(Context.USER_SERVICE);
         Bundle bundle = um.getApplicationRestrictions(ctx.getPackageName());
-        String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
+        if (bundle == null) {
+            return null;
+        }
 
+        String packageName = bundle.getString(RESTRICTION_PACKAGE_NAME);
         if (packageName != null) {
             try {
                 Resources targetResources = ctx.getPackageManager()