Only fetching firstInstallTime for an activity when required
Change-Id: Ia16c05718938849f4250802d8770ddfe6dbef055
This commit is contained in:
@@ -51,11 +51,6 @@ public class AppInfo extends ItemInfo {
|
|||||||
*/
|
*/
|
||||||
boolean usingLowResIcon;
|
boolean usingLowResIcon;
|
||||||
|
|
||||||
/**
|
|
||||||
* The time at which the app was first installed.
|
|
||||||
*/
|
|
||||||
long firstInstallTime;
|
|
||||||
|
|
||||||
public ComponentName componentName;
|
public ComponentName componentName;
|
||||||
|
|
||||||
static final int DOWNLOADED_FLAG = 1;
|
static final int DOWNLOADED_FLAG = 1;
|
||||||
@@ -84,7 +79,6 @@ public class AppInfo extends ItemInfo {
|
|||||||
this.container = ItemInfo.NO_ID;
|
this.container = ItemInfo.NO_ID;
|
||||||
|
|
||||||
flags = initFlags(info);
|
flags = initFlags(info);
|
||||||
firstInstallTime = info.getFirstInstallTime();
|
|
||||||
iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
|
iconCache.getTitleAndIcon(this, info, true /* useLowResIcon */);
|
||||||
intent = makeLaunchIntent(context, info, user);
|
intent = makeLaunchIntent(context, info, user);
|
||||||
this.user = user;
|
this.user = user;
|
||||||
@@ -109,7 +103,6 @@ public class AppInfo extends ItemInfo {
|
|||||||
title = Utilities.trim(info.title);
|
title = Utilities.trim(info.title);
|
||||||
intent = new Intent(info.intent);
|
intent = new Intent(info.intent);
|
||||||
flags = info.flags;
|
flags = info.flags;
|
||||||
firstInstallTime = info.firstInstallTime;
|
|
||||||
iconBitmap = info.iconBitmap;
|
iconBitmap = info.iconBitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,7 +122,6 @@ public class AppInfo extends ItemInfo {
|
|||||||
Log.d(tag, label + " size=" + list.size());
|
Log.d(tag, label + " size=" + list.size());
|
||||||
for (AppInfo info: list) {
|
for (AppInfo info: list) {
|
||||||
Log.d(tag, " title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap
|
Log.d(tag, " title=\"" + info.title + "\" iconBitmap=" + info.iconBitmap
|
||||||
+ " firstInstallTime=" + info.firstInstallTime
|
|
||||||
+ " componentName=" + info.componentName.getPackageName());
|
+ " componentName=" + info.componentName.getPackageName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class ShortcutInfo extends ItemInfo {
|
|||||||
public static final int FLAG_AUTOINTALL_ICON = 2; //0B10;
|
public static final int FLAG_AUTOINTALL_ICON = 2; //0B10;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The icon is being installed. If {@link FLAG_RESTORED_ICON} or {@link FLAG_AUTOINTALL_ICON}
|
* The icon is being installed. If {@link #FLAG_RESTORED_ICON} or {@link #FLAG_AUTOINTALL_ICON}
|
||||||
* is set, then the icon is either being installed or is in a broken state.
|
* is set, then the icon is either being installed or is in a broken state.
|
||||||
*/
|
*/
|
||||||
public static final int FLAG_INSTALL_SESSION_ACTIVE = 4; // 0B100;
|
public static final int FLAG_INSTALL_SESSION_ACTIVE = 4; // 0B100;
|
||||||
@@ -126,19 +126,14 @@ public class ShortcutInfo extends ItemInfo {
|
|||||||
private int mInstallProgress;
|
private int mInstallProgress;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refer {@link AppInfo#firstInstallTime}.
|
* TODO move this to {@link #status}
|
||||||
*/
|
|
||||||
public long firstInstallTime;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO move this to {@link status}
|
|
||||||
*/
|
*/
|
||||||
int flags = 0;
|
int flags = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If this shortcut is a placeholder, then intent will be a market intent for the package, and
|
* If this shortcut is a placeholder, then intent will be a market intent for the package, and
|
||||||
* this will hold the original intent from the database. Otherwise, null.
|
* this will hold the original intent from the database. Otherwise, null.
|
||||||
* Refer {@link #FLAG_RESTORE_PENDING}, {@link #FLAG_INSTALL_PENDING}
|
* Refer {@link #FLAG_RESTORED_ICON}, {@link #FLAG_AUTOINTALL_ICON}
|
||||||
*/
|
*/
|
||||||
Intent promisedIntent;
|
Intent promisedIntent;
|
||||||
|
|
||||||
@@ -172,7 +167,6 @@ public class ShortcutInfo extends ItemInfo {
|
|||||||
mIcon = info.mIcon; // TODO: should make a copy here. maybe we don't need this ctor at all
|
mIcon = info.mIcon; // TODO: should make a copy here. maybe we don't need this ctor at all
|
||||||
customIcon = info.customIcon;
|
customIcon = info.customIcon;
|
||||||
flags = info.flags;
|
flags = info.flags;
|
||||||
firstInstallTime = info.firstInstallTime;
|
|
||||||
user = info.user;
|
user = info.user;
|
||||||
status = info.status;
|
status = info.status;
|
||||||
}
|
}
|
||||||
@@ -184,7 +178,6 @@ public class ShortcutInfo extends ItemInfo {
|
|||||||
intent = new Intent(info.intent);
|
intent = new Intent(info.intent);
|
||||||
customIcon = false;
|
customIcon = false;
|
||||||
flags = info.flags;
|
flags = info.flags;
|
||||||
firstInstallTime = info.firstInstallTime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIcon(Bitmap b) {
|
public void setIcon(Bitmap b) {
|
||||||
@@ -293,7 +286,6 @@ public class ShortcutInfo extends ItemInfo {
|
|||||||
shortcut.intent = AppInfo.makeLaunchIntent(context, info, info.getUser());
|
shortcut.intent = AppInfo.makeLaunchIntent(context, info, info.getUser());
|
||||||
shortcut.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
|
shortcut.itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
|
||||||
shortcut.flags = AppInfo.initFlags(info);
|
shortcut.flags = AppInfo.initFlags(info);
|
||||||
shortcut.firstInstallTime = info.getFirstInstallTime();
|
|
||||||
return shortcut;
|
return shortcut;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import com.android.launcher3.compat.UserManagerCompat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -85,6 +86,7 @@ public class ManagedProfileHeuristic {
|
|||||||
|
|
||||||
private ArrayList<ShortcutInfo> mHomescreenApps;
|
private ArrayList<ShortcutInfo> mHomescreenApps;
|
||||||
private ArrayList<ShortcutInfo> mWorkFolderApps;
|
private ArrayList<ShortcutInfo> mWorkFolderApps;
|
||||||
|
private HashMap<ShortcutInfo, Long> mShortcutToInstallTimeMap;
|
||||||
|
|
||||||
private ManagedProfileHeuristic(Context context, UserHandleCompat user) {
|
private ManagedProfileHeuristic(Context context, UserHandleCompat user) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
@@ -100,32 +102,29 @@ public class ManagedProfileHeuristic {
|
|||||||
Context.MODE_PRIVATE);
|
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
|
* Checks the list of user apps and adds icons for newly installed apps on the homescreen or
|
||||||
* workfolder.
|
* workfolder.
|
||||||
*/
|
*/
|
||||||
public void processUserApps(List<LauncherActivityInfoCompat> apps) {
|
public void processUserApps(List<LauncherActivityInfoCompat> apps) {
|
||||||
mHomescreenApps = new ArrayList<>();
|
initVars();
|
||||||
mWorkFolderApps = new ArrayList<>();
|
|
||||||
|
|
||||||
HashSet<String> packageSet = new HashSet<>();
|
HashSet<String> packageSet = new HashSet<>();
|
||||||
final boolean userAppsExisted = getUserApps(packageSet);
|
final boolean userAppsExisted = getUserApps(packageSet);
|
||||||
|
|
||||||
boolean newPackageAdded = false;
|
boolean newPackageAdded = false;
|
||||||
|
|
||||||
for (LauncherActivityInfoCompat info : apps) {
|
for (LauncherActivityInfoCompat info : apps) {
|
||||||
String packageName = info.getComponentName().getPackageName();
|
String packageName = info.getComponentName().getPackageName();
|
||||||
if (!packageSet.contains(packageName)) {
|
if (!packageSet.contains(packageName)) {
|
||||||
packageSet.add(packageName);
|
packageSet.add(packageName);
|
||||||
newPackageAdded = true;
|
newPackageAdded = true;
|
||||||
|
markForAddition(info, info.getFirstInstallTime());
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +141,22 @@ public class ManagedProfileHeuristic {
|
|||||||
ArrayList<ShortcutInfo> targetList =
|
ArrayList<ShortcutInfo> targetList =
|
||||||
(installTime <= mUserCreationTime + AUTO_ADD_TO_FOLDER_DURATION) ?
|
(installTime <= mUserCreationTime + AUTO_ADD_TO_FOLDER_DURATION) ?
|
||||||
mWorkFolderApps : mHomescreenApps;
|
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()) {
|
if (mWorkFolderApps.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Collections.sort(mWorkFolderApps, new Comparator<ShortcutInfo>() {
|
sortList(mWorkFolderApps);
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(ShortcutInfo lhs, ShortcutInfo rhs) {
|
|
||||||
return Utilities.longCompare(lhs.firstInstallTime, rhs.firstInstallTime);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Try to get a work folder.
|
// Try to get a work folder.
|
||||||
String folderIdKey = USER_FOLDER_ID_PREFIX + mUserSerial;
|
String folderIdKey = USER_FOLDER_ID_PREFIX + mUserSerial;
|
||||||
@@ -222,6 +230,7 @@ public class ManagedProfileHeuristic {
|
|||||||
finalizeWorkFolder();
|
finalizeWorkFolder();
|
||||||
|
|
||||||
if (addHomeScreenShortcuts && !mHomescreenApps.isEmpty()) {
|
if (addHomeScreenShortcuts && !mHomescreenApps.isEmpty()) {
|
||||||
|
sortList(mHomescreenApps);
|
||||||
mModel.addAndBindAddedWorkspaceItems(mContext, 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.
|
* Updates the list of installed apps and adds any new icons on homescreen or work folder.
|
||||||
*/
|
*/
|
||||||
public void processPackageAdd(String[] packages) {
|
public void processPackageAdd(String[] packages) {
|
||||||
mHomescreenApps = new ArrayList<>();
|
initVars();
|
||||||
mWorkFolderApps = new ArrayList<>();
|
|
||||||
|
|
||||||
HashSet<String> packageSet = new HashSet<>();
|
HashSet<String> packageSet = new HashSet<>();
|
||||||
final boolean userAppsExisted = getUserApps(packageSet);
|
final boolean userAppsExisted = getUserApps(packageSet);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user