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

Commit 0f3f29b1 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Use canonical paths to compare library directory with data directory.

Fix for unexpected recursive symbolic link when unpacking
native libraries contained in apks. This happened due to the data
directory of primary user becoming a symlink to the legacy data directory.

Bug: 4396427

Change-Id: Iaed2f21ada4eda16ce729ead259a52203300dfa8
parent 48a880bc
Loading
Loading
Loading
Loading
+36 −30
Original line number Diff line number Diff line
@@ -2855,8 +2855,8 @@ public class PackageManagerService extends IPackageManager.Stub {
    }

    private File getDataPathForPackage(String packageName, int userId) {
        return new File(mUserAppDataDir.getAbsolutePath() + File.separator
                    + userId + File.separator + packageName);
        return new File(mUserAppDataDir.getAbsolutePath() + File.separator + userId
                + File.separator + packageName);
    }

    private PackageParser.Package scanPackageLI(PackageParser.Package pkg,
@@ -3319,8 +3319,9 @@ public class PackageManagerService extends IPackageManager.Stub {
             *        only for non-system apps and system app upgrades.
             */
            if (pkg.applicationInfo.nativeLibraryDir != null) {
                try {
                    final File nativeLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir);
                final String dataPathString = dataPath.getPath();
                    final String dataPathString = dataPath.getCanonicalFile().getPath();

                    if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) {
                        /*
@@ -3331,9 +3332,11 @@ public class PackageManagerService extends IPackageManager.Stub {
                         * necessitates we remove those to match previous behavior.
                         */
                        if (NativeLibraryHelper.removeNativeBinariesFromDirLI(nativeLibraryDir)) {
                        Log.i(TAG, "removed obsolete native libraries for system package " + path);
                            Log.i(TAG, "removed obsolete native libraries for system package "
                                    + path);
                        }
                } else if (nativeLibraryDir.getParent().equals(dataPathString)) {
                    } else if (nativeLibraryDir.getCanonicalFile().getParent()
                            .equals(dataPathString)) {
                        /*
                         * If this is an internal application or our
                         * nativeLibraryPath points to our data directory, unpack
@@ -3350,6 +3353,9 @@ public class PackageManagerService extends IPackageManager.Stub {
                        mInstaller.linkNativeLibraryDirectory(dataPathString,
                                pkg.applicationInfo.nativeLibraryDir);
                    }
                } catch (IOException ioe) {
                    Log.e(TAG, "Unable to get canonical file " + ioe.toString());
                }
            }
            pkg.mScanPath = path;