Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6cbc2fec authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Using ParceledListSlice to get the list of activities in LauncherApps

Bug: 25430879
Change-Id: I3a93bb1abcbcc54bc467e57c51f592b5946850cf
parent 9549544a
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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);
+6 −8
Original line number Diff line number Diff line
@@ -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);
        }
    }

+4 −3
Original line number Diff line number Diff line
@@ -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);
            }