Loading core/java/com/android/internal/content/NativeLibraryHelper.java +16 −5 Original line number Diff line number Diff line Loading @@ -294,33 +294,44 @@ public class NativeLibraryHelper { } } // Convenience method to call removeNativeBinariesFromDirLI(File) public static boolean removeNativeBinariesLI(String nativeLibraryPath) { return removeNativeBinariesFromDirLI(new File(nativeLibraryPath)); } // 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) { public static boolean removeNativeBinariesFromDirLI(File nativeLibraryDir) { if (DEBUG_NATIVE) { Slog.w(TAG, "Deleting native binaries from: " + nativeLibraryPath); Slog.w(TAG, "Deleting native binaries from: " + nativeLibraryDir.getPath()); } boolean deletedFiles = false; /* * 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 (nativeLibraryDir.exists()) { final File[] binaries = nativeLibraryDir.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()); } else { deletedFiles = true; } } } // Do not delete 'lib' directory itself, or this will prevent // installation of future updates. } return deletedFiles; } } core/tests/coretests/src/android/content/pm/PackageManagerTests.java +0 −1 Original line number Diff line number Diff line Loading @@ -579,7 +579,6 @@ public class PackageManagerTests extends AndroidTestCase { private InstallParams installFromRawResource(String outFileName, int rawResId, int flags, boolean cleanUp, boolean fail, int result, int expInstallLocation) { PackageManager pm = mContext.getPackageManager(); InstallParams ip = new InstallParams(outFileName, rawResId); installFromRawResource(ip, flags, cleanUp, fail, result, expInstallLocation); return ip; Loading services/java/com/android/server/PackageManagerService.java +17 −5 Original line number Diff line number Diff line Loading @@ -140,7 +140,6 @@ class PackageManagerService extends IPackageManager.Stub { private static final boolean DEBUG_PREFERRED = false; private static final boolean DEBUG_UPGRADE = false; private static final boolean DEBUG_INSTALL = false; private static final boolean DEBUG_NATIVE = false; private static final boolean MULTIPLE_APPLICATION_UIDS = true; private static final int RADIO_UID = Process.PHONE_UID; Loading Loading @@ -3276,11 +3275,24 @@ class PackageManagerService extends IPackageManager.Stub { * In other words, we're going to unpack the binaries * only for non-system apps and system app upgrades. */ if ((!isSystemApp(pkg) || isUpdatedSystemApp(pkg)) && !isExternal(pkg)) { if (pkg.applicationInfo.nativeLibraryDir != null) { final File sharedLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) { /* * Upgrading from a previous version of the OS sometimes * leaves native libraries in the /data/data/<app>/lib * directory for system apps even when they shouldn't be. * Recent changes in the JNI library search path * necessitates we remove those to match previous behavior. */ if (NativeLibraryHelper.removeNativeBinariesFromDirLI(sharedLibraryDir)) { Log.i(TAG, "removed obsolete native libraries for system package " + path); } } else if (!isExternal(pkg)) { Log.i(TAG, path + " changed; unpacking"); File sharedLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); NativeLibraryHelper.copyNativeBinariesLI(scanFile, sharedLibraryDir); } } pkg.mScanPath = path; if ((scanMode&SCAN_NO_DEX) == 0) { Loading Loading
core/java/com/android/internal/content/NativeLibraryHelper.java +16 −5 Original line number Diff line number Diff line Loading @@ -294,33 +294,44 @@ public class NativeLibraryHelper { } } // Convenience method to call removeNativeBinariesFromDirLI(File) public static boolean removeNativeBinariesLI(String nativeLibraryPath) { return removeNativeBinariesFromDirLI(new File(nativeLibraryPath)); } // 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) { public static boolean removeNativeBinariesFromDirLI(File nativeLibraryDir) { if (DEBUG_NATIVE) { Slog.w(TAG, "Deleting native binaries from: " + nativeLibraryPath); Slog.w(TAG, "Deleting native binaries from: " + nativeLibraryDir.getPath()); } boolean deletedFiles = false; /* * 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 (nativeLibraryDir.exists()) { final File[] binaries = nativeLibraryDir.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()); } else { deletedFiles = true; } } } // Do not delete 'lib' directory itself, or this will prevent // installation of future updates. } return deletedFiles; } }
core/tests/coretests/src/android/content/pm/PackageManagerTests.java +0 −1 Original line number Diff line number Diff line Loading @@ -579,7 +579,6 @@ public class PackageManagerTests extends AndroidTestCase { private InstallParams installFromRawResource(String outFileName, int rawResId, int flags, boolean cleanUp, boolean fail, int result, int expInstallLocation) { PackageManager pm = mContext.getPackageManager(); InstallParams ip = new InstallParams(outFileName, rawResId); installFromRawResource(ip, flags, cleanUp, fail, result, expInstallLocation); return ip; Loading
services/java/com/android/server/PackageManagerService.java +17 −5 Original line number Diff line number Diff line Loading @@ -140,7 +140,6 @@ class PackageManagerService extends IPackageManager.Stub { private static final boolean DEBUG_PREFERRED = false; private static final boolean DEBUG_UPGRADE = false; private static final boolean DEBUG_INSTALL = false; private static final boolean DEBUG_NATIVE = false; private static final boolean MULTIPLE_APPLICATION_UIDS = true; private static final int RADIO_UID = Process.PHONE_UID; Loading Loading @@ -3276,11 +3275,24 @@ class PackageManagerService extends IPackageManager.Stub { * In other words, we're going to unpack the binaries * only for non-system apps and system app upgrades. */ if ((!isSystemApp(pkg) || isUpdatedSystemApp(pkg)) && !isExternal(pkg)) { if (pkg.applicationInfo.nativeLibraryDir != null) { final File sharedLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); if (isSystemApp(pkg) && !isUpdatedSystemApp(pkg)) { /* * Upgrading from a previous version of the OS sometimes * leaves native libraries in the /data/data/<app>/lib * directory for system apps even when they shouldn't be. * Recent changes in the JNI library search path * necessitates we remove those to match previous behavior. */ if (NativeLibraryHelper.removeNativeBinariesFromDirLI(sharedLibraryDir)) { Log.i(TAG, "removed obsolete native libraries for system package " + path); } } else if (!isExternal(pkg)) { Log.i(TAG, path + " changed; unpacking"); File sharedLibraryDir = new File(pkg.applicationInfo.nativeLibraryDir); NativeLibraryHelper.copyNativeBinariesLI(scanFile, sharedLibraryDir); } } pkg.mScanPath = path; if ((scanMode&SCAN_NO_DEX) == 0) { Loading