summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/util/ManagedProfileHeuristic.java
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2015-11-24 10:16:37 -0800
committerSunny Goyal <sunnygoyal@google.com>2015-11-30 09:51:39 -0800
commit0c2f0700a55080318a4c21457408abb8af26740d (patch)
tree11896088b0fdd65a7a7517e15702fa51bd9f8249 /src/com/android/launcher3/util/ManagedProfileHeuristic.java
parentd007d0722c782266f494806e750c24208d6d3ca5 (diff)
downloadandroid_packages_apps_Trebuchet-0c2f0700a55080318a4c21457408abb8af26740d.tar.gz
android_packages_apps_Trebuchet-0c2f0700a55080318a4c21457408abb8af26740d.tar.bz2
android_packages_apps_Trebuchet-0c2f0700a55080318a4c21457408abb8af26740d.zip
Only fetching firstInstallTime for an activity when required
Change-Id: Ia16c05718938849f4250802d8770ddfe6dbef055
Diffstat (limited to 'src/com/android/launcher3/util/ManagedProfileHeuristic.java')
-rw-r--r--src/com/android/launcher3/util/ManagedProfileHeuristic.java51
1 files changed, 29 insertions, 22 deletions
diff --git a/src/com/android/launcher3/util/ManagedProfileHeuristic.java b/src/com/android/launcher3/util/ManagedProfileHeuristic.java
index 849b05c0a..fb9bbb29c 100644
--- a/src/com/android/launcher3/util/ManagedProfileHeuristic.java
+++ b/src/com/android/launcher3/util/ManagedProfileHeuristic.java
@@ -42,6 +42,7 @@ import com.android.launcher3.compat.UserManagerCompat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -85,6 +86,7 @@ public class ManagedProfileHeuristic {
private ArrayList<ShortcutInfo> mHomescreenApps;
private ArrayList<ShortcutInfo> mWorkFolderApps;
+ private HashMap<ShortcutInfo, Long> mShortcutToInstallTimeMap;
private ManagedProfileHeuristic(Context context, UserHandleCompat user) {
mContext = context;
@@ -100,32 +102,29 @@ public class ManagedProfileHeuristic {
Context.MODE_PRIVATE);
}
+ private void initVars() {
+ mHomescreenApps = new ArrayList<>();
+ mWorkFolderApps = new ArrayList<>();
+ mShortcutToInstallTimeMap = new HashMap<>();
+ }
+
/**
* Checks the list of user apps and adds icons for newly installed apps on the homescreen or
* workfolder.
*/
public void processUserApps(List<LauncherActivityInfoCompat> apps) {
- mHomescreenApps = new ArrayList<>();
- mWorkFolderApps = new ArrayList<>();
+ initVars();
HashSet<String> packageSet = new HashSet<>();
final boolean userAppsExisted = getUserApps(packageSet);
boolean newPackageAdded = false;
-
for (LauncherActivityInfoCompat info : apps) {
String packageName = info.getComponentName().getPackageName();
if (!packageSet.contains(packageName)) {
packageSet.add(packageName);
newPackageAdded = true;
-
- try {
- PackageInfo pkgInfo = mContext.getPackageManager()
- .getPackageInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
- markForAddition(info, pkgInfo.firstInstallTime);
- } catch (NameNotFoundException e) {
- Log.e(TAG, "Unknown package " + packageName, e);
- }
+ markForAddition(info, info.getFirstInstallTime());
}
}
@@ -142,7 +141,22 @@ public class ManagedProfileHeuristic {
ArrayList<ShortcutInfo> targetList =
(installTime <= mUserCreationTime + AUTO_ADD_TO_FOLDER_DURATION) ?
mWorkFolderApps : mHomescreenApps;
- targetList.add(ShortcutInfo.fromActivityInfo(info, mContext));
+ ShortcutInfo si = ShortcutInfo.fromActivityInfo(info, mContext);
+ mShortcutToInstallTimeMap.put(si, installTime);
+ targetList.add(si);
+ }
+
+ private void sortList(ArrayList<ShortcutInfo> infos) {
+ Collections.sort(infos, new Comparator<ShortcutInfo>() {
+
+ @Override
+ public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
+ Long lhsTime = mShortcutToInstallTimeMap.get(lhs);
+ Long rhsTime = mShortcutToInstallTimeMap.get(rhs);
+ return Utilities.longCompare(lhsTime == null ? 0 : lhsTime,
+ rhsTime == null ? 0 : rhsTime);
+ }
+ });
}
/**
@@ -152,13 +166,7 @@ public class ManagedProfileHeuristic {
if (mWorkFolderApps.isEmpty()) {
return;
}
- Collections.sort(mWorkFolderApps, new Comparator<ShortcutInfo>() {
-
- @Override
- public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
- return Utilities.longCompare(lhs.firstInstallTime, rhs.firstInstallTime);
- }
- });
+ sortList(mWorkFolderApps);
// Try to get a work folder.
String folderIdKey = USER_FOLDER_ID_PREFIX + mUserSerial;
@@ -222,6 +230,7 @@ public class ManagedProfileHeuristic {
finalizeWorkFolder();
if (addHomeScreenShortcuts && !mHomescreenApps.isEmpty()) {
+ sortList(mHomescreenApps);
mModel.addAndBindAddedWorkspaceItems(mContext, mHomescreenApps);
}
}
@@ -230,9 +239,7 @@ public class ManagedProfileHeuristic {
* Updates the list of installed apps and adds any new icons on homescreen or work folder.
*/
public void processPackageAdd(String[] packages) {
- mHomescreenApps = new ArrayList<>();
- mWorkFolderApps = new ArrayList<>();
-
+ initVars();
HashSet<String> packageSet = new HashSet<>();
final boolean userAppsExisted = getUserApps(packageSet);