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

Commit d8e1dbb6 authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

Rework ParceledListSlice to be much easier to use.

Take advantage of this to return better information about
packages filtered by permissions -- include the permissions
they have in the requested array.

Also fix issue #8026793 (Contact picture shows default pic
while searching for a contact in qsb) by using the base
package name of the Context when reporting the app name
of an operation.  Otherwise you could make a resource-only
context for another application and do calls through that
and get reported as the wrong app.

Change-Id: I5e0488bf773acea5a3d22f245641828e1a106fb8
parent f25febf0
Loading
Loading
Loading
Loading
+2 −11
Original line number Diff line number Diff line
@@ -321,17 +321,8 @@ public final class Pm {
    @SuppressWarnings("unchecked")
    private List<PackageInfo> getInstalledPackages(IPackageManager pm, int flags, int userId)
            throws RemoteException {
        final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>();
        PackageInfo lastItem = null;
        ParceledListSlice<PackageInfo> slice;

        do {
            final String lastKey = lastItem != null ? lastItem.packageName : null;
            slice = pm.getInstalledPackages(flags, lastKey, userId);
            lastItem = slice.populateList(packageInfos, PackageInfo.CREATOR);
        } while (!slice.isLastSlice());

        return packageInfos;
        ParceledListSlice<PackageInfo> slice = pm.getInstalledPackages(flags, userId);
        return slice.getList();
    }

    /**
+3 −3
Original line number Diff line number Diff line
@@ -228,7 +228,7 @@ public class AppOpsManager {
    }

    public int noteOp(int op) {
        return noteOp(op, Process.myUid(), mContext.getPackageName());
        return noteOp(op, Process.myUid(), mContext.getBasePackageName());
    }

    public int startOp(int op, int uid, String packageName) {
@@ -252,7 +252,7 @@ public class AppOpsManager {
    }

    public int startOp(int op) {
        return startOp(op, Process.myUid(), mContext.getPackageName());
        return startOp(op, Process.myUid(), mContext.getBasePackageName());
    }

    public void finishOp(int op, int uid, String packageName) {
@@ -263,6 +263,6 @@ public class AppOpsManager {
    }

    public void finishOp(int op) {
        finishOp(op, Process.myUid(), mContext.getPackageName());
        finishOp(op, Process.myUid(), mContext.getBasePackageName());
    }
}
+7 −33
Original line number Diff line number Diff line
@@ -426,17 +426,8 @@ final class ApplicationPackageManager extends PackageManager {
    @Override
    public List<PackageInfo> getInstalledPackages(int flags, int userId) {
        try {
            final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>();
            PackageInfo lastItem = null;
            ParceledListSlice<PackageInfo> slice;

            do {
                final String lastKey = lastItem != null ? lastItem.packageName : null;
                slice = mPM.getInstalledPackages(flags, lastKey, userId);
                lastItem = slice.populateList(packageInfos, PackageInfo.CREATOR);
            } while (!slice.isLastSlice());

            return packageInfos;
            ParceledListSlice<PackageInfo> slice = mPM.getInstalledPackages(flags, userId);
            return slice.getList();
        } catch (RemoteException e) {
            throw new RuntimeException("Package manager has died", e);
        }
@@ -448,17 +439,9 @@ final class ApplicationPackageManager extends PackageManager {
            String[] permissions, int flags) {
        final int userId = mContext.getUserId();
        try {
            final List<PackageInfo> packageInfos = new ArrayList<PackageInfo>();
            PackageInfo lastItem = null;
            ParceledListSlice<PackageInfo> slice;

            do {
                final String lastKey = lastItem != null ? lastItem.packageName : null;
                slice = mPM.getPackagesHoldingPermissions(permissions, flags, lastKey, userId);
                lastItem = slice.populateList(packageInfos, PackageInfo.CREATOR);
            } while (!slice.isLastSlice());

            return packageInfos;
            ParceledListSlice<PackageInfo> slice = mPM.getPackagesHoldingPermissions(
                    permissions, flags, userId);
            return slice.getList();
        } catch (RemoteException e) {
            throw new RuntimeException("Package manager has died", e);
        }
@@ -469,17 +452,8 @@ final class ApplicationPackageManager extends PackageManager {
    public List<ApplicationInfo> getInstalledApplications(int flags) {
        final int userId = mContext.getUserId();
        try {
            final List<ApplicationInfo> applicationInfos = new ArrayList<ApplicationInfo>();
            ApplicationInfo lastItem = null;
            ParceledListSlice<ApplicationInfo> slice;

            do {
                final String lastKey = lastItem != null ? lastItem.packageName : null;
                slice = mPM.getInstalledApplications(flags, lastKey, userId);
                lastItem = slice.populateList(applicationInfos, ApplicationInfo.CREATOR);
            } while (!slice.isLastSlice());

            return applicationInfos;
            ParceledListSlice<ApplicationInfo> slice = mPM.getInstalledApplications(flags, userId);
            return slice.getList();
        } catch (RemoteException e) {
            throw new RuntimeException("Package manager has died", e);
        }
+6 −0
Original line number Diff line number Diff line
@@ -628,6 +628,12 @@ class ContextImpl extends Context {
        return "android";
    }

    /** @hide */
    @Override
    public String getBasePackageName() {
        return mBasePackageName != null ? mBasePackageName : getPackageName();
    }

    @Override
    public ApplicationInfo getApplicationInfo() {
        if (mPackageInfo != null) {
+1 −1
Original line number Diff line number Diff line
@@ -208,7 +208,7 @@ public abstract class ContentResolver {

    public ContentResolver(Context context) {
        mContext = context != null ? context : ActivityThread.currentApplication();
        mPackageName = mContext.getPackageName();
        mPackageName = context.getBasePackageName();
    }

    /** @hide */
Loading