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

am: e04765998e

Change-Id: I674191296c7d0a409e19614b2f18a4b86bf03ab8
This commit is contained in:
Svet Ganov
2017-05-16 00:03:00 +00:00
committed by android-build-merger
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) { 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();
} }

View File

@@ -617,7 +617,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);

View File

@@ -3610,8 +3610,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,
@@ -4334,7 +4333,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");
@@ -4345,8 +4345,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;
@@ -4369,7 +4370,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;
} }
@@ -9268,6 +9270,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);
}
} }
} }
@@ -17714,14 +17719,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();
@@ -17863,8 +17866,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;
@@ -23944,6 +23946,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
@@ -23951,18 +23959,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;