SharedLibraryInfo.isNative() returns true for native libs

This CL fixes a bug that SharedLibraryInfo.isNative() returns false
even for native shared libraries. This was because when a
SharedLibraryInfo is copied to a new SharedLibraryInfo (to add some
extra info about declaring package, etc.), the native-ness was
mistakenly ignored. Fixing the issue.

Also, the old constructor of SharedLibraryInfo that doesn't accept the
native-ness was removed to prevent similar mistakes.

Bug: 142191088
Test: atest CtsUsesNativeLibraryTest
Test: write an app that calls PackageManager.getSharedLibraries()
and inspect the mIsNative fields in the returned list. Entries for
native shared libs all have mIsNative=false. Will add a testcase to
the CTS test when isNative() becomes an API.

Change-Id: I35d9530f332614e0444448feec70a4461c9bbfa8
This commit is contained in:
Jiyong Park
2020-11-23 21:42:27 +09:00
parent 8b0cc5a24c
commit 4e4e82225a
6 changed files with 14 additions and 18 deletions

View File

@@ -114,15 +114,6 @@ public final class SharedLibraryInfo implements Parcelable {
mIsNative = isNative;
}
/** @hide */
public SharedLibraryInfo(String path, String packageName, List<String> codePaths,
String name, long version, int type,
VersionedPackage declaringPackage, List<VersionedPackage> dependentPackages,
List<SharedLibraryInfo> dependencies) {
this(path, packageName, codePaths, name, version, type, declaringPackage, dependentPackages,
dependencies, false /* isNative */);
}
private SharedLibraryInfo(Parcel parcel) {
mPath = parcel.readString8();
mPackageName = parcel.readString8();

View File

@@ -391,16 +391,19 @@ public class ZygoteInit {
SharedLibraryInfo hidlBase = new SharedLibraryInfo(
"/system/framework/android.hidl.base-V1.0-java.jar", null /*packageName*/,
null /*codePaths*/, null /*name*/, 0 /*version*/, SharedLibraryInfo.TYPE_BUILTIN,
null /*declaringPackage*/, null /*dependentPackages*/, null /*dependencies*/);
null /*declaringPackage*/, null /*dependentPackages*/, null /*dependencies*/,
false /*isNative*/);
SharedLibraryInfo hidlManager = new SharedLibraryInfo(
"/system/framework/android.hidl.manager-V1.0-java.jar", null /*packageName*/,
null /*codePaths*/, null /*name*/, 0 /*version*/, SharedLibraryInfo.TYPE_BUILTIN,
null /*declaringPackage*/, null /*dependentPackages*/, null /*dependencies*/);
null /*declaringPackage*/, null /*dependentPackages*/, null /*dependencies*/,
false /*isNative*/);
SharedLibraryInfo androidTestBase = new SharedLibraryInfo(
"/system/framework/android.test.base.jar", null /*packageName*/,
null /*codePaths*/, null /*name*/, 0 /*version*/, SharedLibraryInfo.TYPE_BUILTIN,
null /*declaringPackage*/, null /*dependentPackages*/, null /*dependencies*/);
null /*declaringPackage*/, null /*dependentPackages*/, null /*dependencies*/,
false /*isNative*/);
ApplicationLoaders.getDefault().createAndCacheNonBootclasspathSystemClassLoaders(
new SharedLibraryInfo[]{

View File

@@ -42,7 +42,7 @@ public class ApplicationLoadersTest {
return new SharedLibraryInfo(
zip, null /*packageName*/, null /*codePaths*/, null /*name*/, 0 /*version*/,
SharedLibraryInfo.TYPE_BUILTIN, null /*declaringPackage*/,
null /*dependentPackages*/, null /*dependencies*/);
null /*dependentPackages*/, null /*dependencies*/, false /*isNative*/);
}
@Test

View File

@@ -5722,7 +5722,8 @@ public class PackageManagerService extends IPackageManager.Stub
getPackagesUsingSharedLibraryLPr(libInfo, flags, userId),
(libInfo.getDependencies() == null
? null
: new ArrayList<>(libInfo.getDependencies())));
: new ArrayList<>(libInfo.getDependencies())),
libInfo.isNative());
if (result == null) {
result = new ArrayList<>();
@@ -5791,7 +5792,8 @@ public class PackageManagerService extends IPackageManager.Stub
libraryInfo.getLongVersion(), libraryInfo.getType(),
libraryInfo.getDeclaringPackage(), getPackagesUsingSharedLibraryLPr(
libraryInfo, flags, userId), libraryInfo.getDependencies() == null
? null : new ArrayList<>(libraryInfo.getDependencies()));
? null : new ArrayList<>(libraryInfo.getDependencies()),
libraryInfo.isNative());
if (result == null) {
result = new ArrayList<>();

View File

@@ -94,7 +94,7 @@ public class AndroidPackageUtils {
SharedLibraryInfo.TYPE_STATIC,
new VersionedPackage(pkg.getManifestPackageName(),
pkg.getLongVersionCode()),
null, null);
null, null, false /* isNative */);
}
public static SharedLibraryInfo createSharedLibraryForDynamic(AndroidPackage pkg, String name) {
@@ -103,7 +103,7 @@ public class AndroidPackageUtils {
SharedLibraryInfo.VERSION_UNDEFINED,
SharedLibraryInfo.TYPE_DYNAMIC, new VersionedPackage(pkg.getPackageName(),
pkg.getLongVersionCode()),
null, null);
null, null, false /* isNative */);
}
/**

View File

@@ -134,7 +134,7 @@ public class DexoptUtilsTest {
private List<SharedLibraryInfo> createMockSharedLibrary(String [] sharedLibrary) {
SharedLibraryInfo info = new SharedLibraryInfo(null, null, Arrays.asList(sharedLibrary),
null, 0L, SharedLibraryInfo.TYPE_STATIC, null, null, null);
null, 0L, SharedLibraryInfo.TYPE_STATIC, null, null, null, false /* isNative */);
ArrayList<SharedLibraryInfo> libraries = new ArrayList<>();
libraries.add(info);
return libraries;