OSDN Git Service

Fetching firstInstallTime on demand
authorSunny Goyal <sunnygoyal@google.com>
Tue, 24 Nov 2015 18:42:11 +0000 (10:42 -0800)
committerSunny Goyal <sunnygoyal@google.com>
Tue, 24 Nov 2015 18:42:32 +0000 (10:42 -0800)
Change-Id: I96442aaf119553ffb0ea94ff06713752e4490e0b

core/java/android/content/pm/LauncherActivityInfo.java
core/java/android/content/pm/LauncherApps.java

index 6827d7a..a5617b4 100644 (file)
@@ -41,7 +41,6 @@ public class LauncherActivityInfo {
     private ComponentName mComponentName;
     private ResolveInfo mResolveInfo;
     private UserHandle mUser;
-    private long mFirstInstallTime;
 
     /**
      * Create a launchable activity object for a given ResolveInfo and user.
@@ -50,14 +49,12 @@ public class LauncherActivityInfo {
      * @param info ResolveInfo from which to create the LauncherActivityInfo.
      * @param user The UserHandle of the profile to which this activity belongs.
      */
-    LauncherActivityInfo(Context context, ResolveInfo info, UserHandle user,
-            long firstInstallTime) {
+    LauncherActivityInfo(Context context, ResolveInfo info, UserHandle user) {
         this(context);
         mResolveInfo = info;
         mActivityInfo = info.activityInfo;
         mComponentName = LauncherApps.getComponentName(info);
         mUser = user;
-        mFirstInstallTime = firstInstallTime;
     }
 
     LauncherActivityInfo(Context context) {
@@ -136,7 +133,7 @@ public class LauncherActivityInfo {
 
     /**
      * Returns the drawable for this activity, without any badging for the profile.
-     * @param resource id of the drawable.
+     * @param iconRes id of the drawable.
      * @param density The preferred density of the icon, zero for default density. Use
      * density DPI values from {@link DisplayMetrics}.
      * @see DisplayMetrics
@@ -179,7 +176,13 @@ public class LauncherActivityInfo {
      * @return The time of installation of the package, in milliseconds.
      */
     public long getFirstInstallTime() {
-        return mFirstInstallTime;
+        try {
+            return mPm.getPackageInfo(mActivityInfo.packageName,
+                    PackageManager.GET_UNINSTALLED_PACKAGES).firstInstallTime;
+        } catch (NameNotFoundException nnfe) {
+            // Sorry, can't find package
+            return 0;
+        }
     }
 
     /**
index e9ec771..f7d8013 100644 (file)
@@ -155,15 +155,7 @@ public class LauncherApps {
         final int count = activities.size();
         for (int i = 0; i < count; i++) {
             ResolveInfo ri = activities.get(i);
-            long firstInstallTime = 0;
-            try {
-                firstInstallTime = mPm.getPackageInfo(ri.activityInfo.packageName,
-                    PackageManager.GET_UNINSTALLED_PACKAGES).firstInstallTime;
-            } catch (NameNotFoundException nnfe) {
-                // Sorry, can't find package
-            }
-            LauncherActivityInfo lai = new LauncherActivityInfo(mContext, ri, user,
-                    firstInstallTime);
+            LauncherActivityInfo lai = new LauncherActivityInfo(mContext, ri, user);
             if (DEBUG) {
                 Log.v(TAG, "Returning activity for profile " + user + " : "
                         + lai.getComponentName());
@@ -189,15 +181,7 @@ public class LauncherApps {
         try {
             ResolveInfo ri = mService.resolveActivity(intent, user);
             if (ri != null) {
-                long firstInstallTime = 0;
-                try {
-                    firstInstallTime = mPm.getPackageInfo(ri.activityInfo.packageName,
-                            PackageManager.GET_UNINSTALLED_PACKAGES).firstInstallTime;
-                } catch (NameNotFoundException nnfe) {
-                    // Sorry, can't find package
-                }
-                LauncherActivityInfo info = new LauncherActivityInfo(mContext, ri, user,
-                        firstInstallTime);
+                LauncherActivityInfo info = new LauncherActivityInfo(mContext, ri, user);
                 return info;
             }
         } catch (RemoteException re) {