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

Commit e0476599 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Support recursive static shared lib dependency" into oc-dev

parents f5b68180 58c99f02
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -478,7 +478,7 @@ public class ApplicationPackageManager extends PackageManager {
    public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
        try {
            ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
                    flags, userId);
                    mContext.getOpPackageName(), flags, userId);
            if (sharedLibs == null) {
                return Collections.emptyList();
            }
+1 −1
Original line number Diff line number Diff line
@@ -617,7 +617,7 @@ interface IPackageManager {

    int getInstallReason(String packageName, int userId);

    ParceledListSlice getSharedLibraries(int flags, int userId);
    ParceledListSlice getSharedLibraries(in String packageName, int flags, int userId);

    boolean canRequestPackageInstalls(String packageName, int userId);

+29 −16
Original line number Diff line number Diff line
@@ -3610,8 +3610,7 @@ public class PackageManagerService extends IPackageManager.Stub
    public PackageInfo getPackageInfoVersioned(VersionedPackage versionedPackage,
            int flags, int userId) {
        return getPackageInfoInternal(versionedPackage.getPackageName(),
                // TODO: We will change version code to long, so in the new API it is long
                (int) versionedPackage.getVersionCode(), flags, userId);
                versionedPackage.getVersionCode(), flags, userId);
    }
    private PackageInfo getPackageInfoInternal(String packageName, int versionCode,
@@ -4334,7 +4333,8 @@ public class PackageManagerService extends IPackageManager.Stub
    }
    @Override
    public ParceledListSlice<SharedLibraryInfo> getSharedLibraries(int flags, int userId) {
    public ParceledListSlice<SharedLibraryInfo> getSharedLibraries(String packageName,
            int flags, int userId) {
        if (!sUserManager.exists(userId)) return null;
        Preconditions.checkArgumentNonnegative(userId, "userId must be >= 0");
@@ -4345,8 +4345,9 @@ public class PackageManagerService extends IPackageManager.Stub
                        == PERMISSION_GRANTED
                || mContext.checkCallingOrSelfPermission(DELETE_PACKAGES)
                        == PERMISSION_GRANTED
                || mContext.checkCallingOrSelfPermission(REQUEST_INSTALL_PACKAGES)
                        == PERMISSION_GRANTED
                || canRequestPackageInstallsInternal(packageName,
                        PackageManager.MATCH_STATIC_SHARED_LIBRARIES, userId,
                        false  /* throwIfPermNotDeclared*/)
                || mContext.checkCallingOrSelfPermission(REQUEST_DELETE_PACKAGES)
                        == PERMISSION_GRANTED;
@@ -4369,7 +4370,8 @@ public class PackageManagerService extends IPackageManager.Stub
                    final long identity = Binder.clearCallingIdentity();
                    try {
                        PackageInfo packageInfo = getPackageInfoVersioned(
                                libInfo.getDeclaringPackage(), flags, userId);
                                libInfo.getDeclaringPackage(), flags
                                        | PackageManager.MATCH_STATIC_SHARED_LIBRARIES, userId);
                        if (packageInfo == null) {
                            continue;
                        }
@@ -9268,6 +9270,9 @@ public class PackageManagerService extends IPackageManager.Stub
        }
        if (p != null) {
            usesLibraryFiles.addAll(p.getAllCodePaths());
            if (p.usesLibraryFiles != null) {
                Collections.addAll(usesLibraryFiles, p.usesLibraryFiles);
            }
        }
    }
@@ -17714,14 +17719,12 @@ public class PackageManagerService extends IPackageManager.Stub
                Integer.MAX_VALUE, "versionCode must be >= -1");
        final String packageName = versionedPackage.getPackageName();
        // TODO: We will change version code to long, so in the new API it is long
        final int versionCode = (int) versionedPackage.getVersionCode();
        final int versionCode = versionedPackage.getVersionCode();
        final String internalPackageName;
        synchronized (mPackages) {
            // Normalize package name to handle renamed packages and static libs
            internalPackageName = resolveInternalPackageNameLPr(versionedPackage.getPackageName(),
                    // TODO: We will change version code to long, so in the new API it is long
                    (int) versionedPackage.getVersionCode());
                    versionedPackage.getVersionCode());
        }
        final int uid = Binder.getCallingUid();
@@ -17863,8 +17866,7 @@ public class PackageManagerService extends IPackageManager.Stub
                    libEntry.info.getVersion()) < 0) {
                continue;
            }
            // TODO: We will change version code to long, so in the new API it is long
            final int libVersionCode = (int) libEntry.info.getDeclaringPackage().getVersionCode();
            final int libVersionCode = libEntry.info.getDeclaringPackage().getVersionCode();
            if (versionCode != PackageManager.VERSION_CODE_HIGHEST) {
                if (libVersionCode == versionCode) {
                    return libEntry.apk;
@@ -23944,6 +23946,12 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
    @Override
    public boolean canRequestPackageInstalls(String packageName, int userId) {
        return canRequestPackageInstallsInternal(packageName, 0, userId,
                true /* throwIfPermNotDeclared*/);
    }
    private boolean canRequestPackageInstallsInternal(String packageName, int flags, int userId,
            boolean throwIfPermNotDeclared) {
        int callingUid = Binder.getCallingUid();
        int uid = getPackageUid(packageName, 0, userId);
        if (callingUid != uid && callingUid != Process.ROOT_UID
@@ -23951,18 +23959,23 @@ Slog.v(TAG, ":: stepped forward, applying functor at tag " + parser.getName());
            throw new SecurityException(
                    "Caller uid " + callingUid + " does not own package " + packageName);
        }
        ApplicationInfo info = getApplicationInfo(packageName, 0, userId);
        ApplicationInfo info = getApplicationInfo(packageName, flags, userId);
        if (info == null) {
            return false;
        }
        if (info.targetSdkVersion < Build.VERSION_CODES.O) {
            throw new UnsupportedOperationException(
                    "Operation only supported on apps targeting Android O or higher");
            return false;
        }
        String appOpPermission = Manifest.permission.REQUEST_INSTALL_PACKAGES;
        String[] packagesDeclaringPermission = getAppOpPermissionPackages(appOpPermission);
        if (!ArrayUtils.contains(packagesDeclaringPermission, packageName)) {
            throw new SecurityException("Need to declare " + appOpPermission + " to call this api");
            if (throwIfPermNotDeclared) {
                throw new SecurityException("Need to declare " + appOpPermission
                        + " to call this api");
            } else {
                Slog.e(TAG, "Need to declare " + appOpPermission + " to call this api");
                return false;
            }
        }
        if (sUserManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, userId)) {
            return false;