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

Commit c52d8661 authored by Nicolas Geoffray's avatar Nicolas Geoffray
Browse files

Check for null in applyDefiningSharedLibraryUpdateLocked.

Handle two cases:
1) We haven't been able to create the shared library. The package manager
still installs the package, but doesn't create the shared library.

2) When installing a shared library, we update shared lib dependency
mappings before scanning. In the case that we're installing a
new shared library, we will not have reference to that shared library in
memory. This change adds a null check to account for such a scenario.

bug: 119438703
bug: 119497540
Test: atest android.os.cts.StaticSharedLibsHostTests#testAppCanSeeOnlyLibrariesItDependOnFullMode
Change-Id: I93d67f79ad0a58acd8cd4cb961cf82ada085821c
parent b5138766
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -9308,7 +9308,7 @@ public class PackageManagerService extends IPackageManager.Stub
        }
    }
    private SharedLibraryInfo getSharedLibraryInfoLPr(String name, long version) {
    private @Nullable SharedLibraryInfo getSharedLibraryInfoLPr(String name, long version) {
        LongSparseArray<SharedLibraryInfo> versionedLib = mSharedLibraries.get(name);
        if (versionedLib == null) {
            return null;
@@ -9580,20 +9580,30 @@ public class PackageManagerService extends IPackageManager.Stub
    private void applyDefiningSharedLibraryUpdateLocked(
            PackageParser.Package pkg, SharedLibraryInfo libInfo,
            BiConsumer<SharedLibraryInfo, SharedLibraryInfo> action) {
        // Note that libraries defined by this package may be null if:
        // - Package manager was unable to create the shared library. The package still
        //   gets installed, but the shared library does not get created.
        // Or:
        // - Package manager is in a state where package isn't scanned yet. This will
        //   get called again after scanning to fix the dependencies.
        if (pkg.isLibrary()) {
            if (pkg.staticSharedLibName != null) {
                SharedLibraryInfo definedLibrary = getSharedLibraryInfoLPr(
                        pkg.staticSharedLibName, pkg.staticSharedLibVersion);
                if (definedLibrary != null) {
                    action.accept(definedLibrary, libInfo);
                }
            } else {
                for (String libraryName : pkg.libraryNames) {
                    SharedLibraryInfo definedLibrary = getSharedLibraryInfoLPr(
                            libraryName, SharedLibraryInfo.VERSION_UNDEFINED);
                    if (definedLibrary != null) {
                        action.accept(definedLibrary, libInfo);
                    }
                }
            }
        }
    }
    @GuardedBy("mPackages")
    private void addSharedLibraryLPr(PackageParser.Package pkg, Set<String> usesLibraryFiles,