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

Commit 8f7cc02c authored by Kenny Root's avatar Kenny Root
Browse files

Move native library removal function to helper

Moves the remoteNativeLibrariesLI call to NativeLibraryHelper to prepare
for being able to symlink the /data/data/<package>/lib dir to the ASEC
container.

Change-Id: Ie3648509c6b6293a8d9bdd815610ab408df5047f
parent 806cc13a
Loading
Loading
Loading
Loading
+30 −0
Original line number Diff line number Diff line
@@ -293,4 +293,34 @@ public class NativeLibraryHelper {
            inputStream.close();
        }
    }

    // Remove the native binaries of a given package. This simply
    // gets rid of the files in the 'lib' sub-directory.
    public static void removeNativeBinariesLI(String nativeLibraryPath) {
        if (DEBUG_NATIVE) {
            Slog.w(TAG, "Deleting native binaries from: " + nativeLibraryPath);
        }

        /*
         * Just remove any file in the directory. Since the directory is owned
         * by the 'system' UID, the application is not supposed to have written
         * anything there.
         */
        File binaryDir = new File(nativeLibraryPath);
        if (binaryDir.exists()) {
            File[] binaries = binaryDir.listFiles();
            if (binaries != null) {
                for (int nn = 0; nn < binaries.length; nn++) {
                    if (DEBUG_NATIVE) {
                        Slog.d(TAG, "    Deleting " + binaries[nn].getName());
                    }
                    if (!binaries[nn].delete()) {
                        Slog.w(TAG, "Could not delete native binary: " + binaries[nn].getPath());
                    }
                }
            }
            // Do not delete 'lib' directory itself, or this will prevent
            // installation of future updates.
        }
    }
}
+3 −37
Original line number Diff line number Diff line
@@ -3598,40 +3598,6 @@ class PackageManagerService extends IPackageManager.Stub {
        }
    }

    // Convenience call for removeNativeBinariesLI(File)
    private void removeNativeBinariesLI(PackageParser.Package pkg) {
        File nativeLibraryDir = getNativeBinaryDirForPackage(pkg);
        removeNativeBinariesLI(nativeLibraryDir);
    }

    // Remove the native binaries of a given package. This simply
    // gets rid of the files in the 'lib' sub-directory.
    public void removeNativeBinariesLI(File binaryDir) {
        if (DEBUG_NATIVE) {
            Slog.w(TAG, "Deleting native binaries from: " + binaryDir.getPath());
        }

        // Just remove any file in the directory. Since the directory
        // is owned by the 'system' UID, the application is not supposed
        // to have written anything there.
        //
        if (binaryDir.exists()) {
            File[] binaries = binaryDir.listFiles();
            if (binaries != null) {
                for (int nn = 0; nn < binaries.length; nn++) {
                    if (DEBUG_NATIVE) {
                        Slog.d(TAG, "    Deleting " + binaries[nn].getName());
                    }
                    if (!binaries[nn].delete()) {
                        Slog.w(TAG, "Could not delete native binary: " + binaries[nn].getPath());
                    }
                }
            }
            // Do not delete 'lib' directory itself, or this will prevent
            // installation of future updates.
        }
    }

    void removePackageLI(PackageParser.Package pkg, boolean chatty) {
        if (chatty && Config.LOGD) Log.d(
            TAG, "Removing package " + pkg.applicationInfo.packageName );
@@ -5135,7 +5101,7 @@ class PackageManagerService extends IPackageManager.Stub {
                }
            }
            if (libraryPath != null) {
                removeNativeBinariesLI(new File(libraryPath));
                NativeLibraryHelper.removeNativeBinariesLI(libraryPath);
            }
        }

@@ -6209,8 +6175,8 @@ class PackageManagerService extends IPackageManager.Stub {
        synchronized (mPackages) {
            // Reinstate the old system package
            mSettings.enableSystemPackageLP(p.packageName);
            // Remove any native libraries. XXX needed?
            removeNativeBinariesLI(p);
            // Remove any native libraries from the upgraded package.
            NativeLibraryHelper.removeNativeBinariesLI(p.applicationInfo.nativeLibraryDir);
        }
        // Install the system package
        PackageParser.Package newPkg = scanPackageLI(ps.codePath,