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

This commit is contained in:
TreeHugger Robot
2017-05-15 23:48:58 +00:00
committed by Android (Google) Code Review
3 changed files with 31 additions and 18 deletions

View File

@@ -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();
}

View File

@@ -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);

View File

@@ -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;