OSDN Git Service

Using ParceledListSlice to get the list of activities in LauncherApps
authorSunny Goyal <sunnygoyal@google.com>
Tue, 24 Nov 2015 17:34:20 +0000 (09:34 -0800)
committerSunny Goyal <sunnygoyal@google.com>
Tue, 24 Nov 2015 19:22:16 +0000 (11:22 -0800)
Bug: 25430879
Change-Id: I3a93bb1abcbcc54bc467e57c51f592b5946850cf

core/java/android/content/pm/ILauncherApps.aidl
core/java/android/content/pm/LauncherApps.java
services/core/java/com/android/server/pm/LauncherAppsService.java

index d9005b2..6586426 100644 (file)
@@ -19,6 +19,7 @@ package android.content.pm;
 import android.content.ComponentName;
 import android.content.Intent;
 import android.content.pm.IOnAppsChangedListener;
+import android.content.pm.ParceledListSlice;
 import android.content.pm.ResolveInfo;
 import android.graphics.Rect;
 import android.os.Bundle;
@@ -31,7 +32,7 @@ import java.util.List;
 interface ILauncherApps {
     void addOnAppsChangedListener(in IOnAppsChangedListener listener);
     void removeOnAppsChangedListener(in IOnAppsChangedListener listener);
-    List<ResolveInfo> getLauncherActivities(String packageName, in UserHandle user);
+    ParceledListSlice getLauncherActivities(String packageName, in UserHandle user);
     ResolveInfo resolveActivity(in Intent intent, in UserHandle user);
     void startActivityAsUser(in ComponentName component, in Rect sourceBounds,
             in Bundle opts, in UserHandle user);
index f7d8013..6e67af4 100644 (file)
@@ -142,19 +142,17 @@ public class LauncherApps {
      * @return List of launchable activities. Can be an empty list but will not be null.
      */
     public List<LauncherActivityInfo> getActivityList(String packageName, UserHandle user) {
-        List<ResolveInfo> activities = null;
+        ParceledListSlice<ResolveInfo> activities = null;
         try {
             activities = mService.getLauncherActivities(packageName, user);
         } catch (RemoteException re) {
-            throw new RuntimeException("Failed to call LauncherAppsService");
+            throw new RuntimeException("Failed to call LauncherAppsService", re);
         }
         if (activities == null) {
             return Collections.EMPTY_LIST;
         }
         ArrayList<LauncherActivityInfo> lais = new ArrayList<LauncherActivityInfo>();
-        final int count = activities.size();
-        for (int i = 0; i < count; i++) {
-            ResolveInfo ri = activities.get(i);
+        for (ResolveInfo ri : activities.getList()) {
             LauncherActivityInfo lai = new LauncherActivityInfo(mContext, ri, user);
             if (DEBUG) {
                 Log.v(TAG, "Returning activity for profile " + user + " : "
@@ -185,7 +183,7 @@ public class LauncherApps {
                 return info;
             }
         } catch (RemoteException re) {
-            throw new RuntimeException("Failed to call LauncherAppsService");
+            throw new RuntimeException("Failed to call LauncherAppsService", re);
         }
         return null;
     }
@@ -240,7 +238,7 @@ public class LauncherApps {
         try {
             return mService.isPackageEnabled(packageName, user);
         } catch (RemoteException re) {
-            throw new RuntimeException("Failed to call LauncherAppsService");
+            throw new RuntimeException("Failed to call LauncherAppsService", re);
         }
     }
 
@@ -256,7 +254,7 @@ public class LauncherApps {
         try {
             return mService.isActivityEnabled(component, user);
         } catch (RemoteException re) {
-            throw new RuntimeException("Failed to call LauncherAppsService");
+            throw new RuntimeException("Failed to call LauncherAppsService", re);
         }
     }
 
index 4582828..0796811 100644 (file)
@@ -26,6 +26,7 @@ import android.content.pm.IOnAppsChangedListener;
 import android.content.pm.IPackageManager;
 import android.content.pm.PackageManager;
 import android.content.pm.PackageInfo;
+import android.content.pm.ParceledListSlice;
 import android.content.pm.ResolveInfo;
 import android.content.pm.UserInfo;
 import android.graphics.Rect;
@@ -187,11 +188,11 @@ public class LauncherAppsService extends SystemService {
         }
 
         @Override
-        public List<ResolveInfo> getLauncherActivities(String packageName, UserHandle user)
+        public ParceledListSlice<ResolveInfo> getLauncherActivities(String packageName, UserHandle user)
                 throws RemoteException {
             ensureInUserProfiles(user, "Cannot retrieve activities for unrelated profile " + user);
             if (!isUserEnabled(user)) {
-                return new ArrayList<ResolveInfo>();
+                return null;
             }
 
             final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
@@ -201,7 +202,7 @@ public class LauncherAppsService extends SystemService {
             try {
                 List<ResolveInfo> apps = mPm.queryIntentActivitiesAsUser(mainIntent, 0 /* flags */,
                         user.getIdentifier());
-                return apps;
+                return new ParceledListSlice<>(apps);
             } finally {
                 Binder.restoreCallingIdentity(ident);
             }