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

Commit 647dc845 authored by Svet Ganov's avatar Svet Ganov Committed by android-build-merger
Browse files

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

am: 8adfc2ca

Change-Id: Ib07a986a02372d40ce93b9beb8e1ac74f0d3561b
parents 93d5c062 8adfc2ca
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -482,7 +482,7 @@ public class ApplicationPackageManager extends PackageManager {
    public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
    public @NonNull List<SharedLibraryInfo> getSharedLibrariesAsUser(int flags, int userId) {
        try {
        try {
            ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
            ParceledListSlice<SharedLibraryInfo> sharedLibs = mPM.getSharedLibraries(
                    flags, userId);
                    mContext.getOpPackageName(), flags, userId);
            if (sharedLibs == null) {
            if (sharedLibs == null) {
                return Collections.emptyList();
                return Collections.emptyList();
            }
            }
+1 −1
Original line number Original line Diff line number Diff line
@@ -650,7 +650,7 @@ interface IPackageManager {


    int getInstallReason(String packageName, int userId);
    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);
    boolean canRequestPackageInstalls(String packageName, int userId);


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