Merge "Adding support for loading package icon in iconCache" 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/IconCache.java b/src/com/android/launcher3/IconCache.java
index aaec2b4..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;
 
 /**
@@ -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) {
@@ -644,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";
@@ -655,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 + " (" +
@@ -670,6 +685,7 @@
                     COLUMN_ICON + " BLOB, " +
                     COLUMN_ICON_LOW_RES + " BLOB, " +
                     COLUMN_LABEL + " TEXT, " +
+                    COLUMN_SYSTEM_STATE + " TEXT, " +
                     "PRIMARY KEY (" + COLUMN_COMPONENT + ", " + COLUMN_USER + ") " +
                     ");");
         }
@@ -695,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()