OSDN Git Service

Add null checks when scanning a package.
authorSuchi Amalapurapu <asuchitra@google.com>
Tue, 9 Feb 2010 00:30:06 +0000 (16:30 -0800)
committerSuchi Amalapurapu <asuchitra@google.com>
Tue, 9 Feb 2010 01:10:24 +0000 (17:10 -0800)
Delete packages whose code and resource paths haven't been set
correctly.

services/java/com/android/server/PackageManagerService.java

index 86504a0..6df9f2b 100644 (file)
@@ -1977,6 +1977,12 @@ class PackageManagerService extends IPackageManager.Stub {
             }
             PackageParser.Package pkg = scanPackageLI(file, file, resFile,
                     flags|PackageParser.PARSE_MUST_BE_APK, scanMode);
+            // Don't mess around with apps in system partition.
+            if (pkg == null && (flags & PackageParser.PARSE_IS_SYSTEM) == 0) {
+                // Delete the apk
+                Log.w(TAG, "Cleaning up failed install of " + file);
+                file.delete();
+            }
         }
     }
 
@@ -2171,6 +2177,13 @@ class PackageManagerService extends IPackageManager.Stub {
         File scanFile, File destCodeFile, File destResourceFile,
         PackageParser.Package pkg, int parseFlags, int scanMode) {
 
+        if (scanFile == null || destCodeFile == null ||
+                destResourceFile == null) {
+            // Bail out. The resource and code paths haven't been set.
+            Log.w(TAG, " Code and resource paths haven't been set correctly");
+            mLastScanError = PackageManager.INSTALL_FAILED_INVALID_APK;
+            return null;
+        }
         mScanningPath = scanFile;
         if (pkg == null) {
             mLastScanError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;