OSDN Git Service

SDK Manager: fix extra package update detection.
authorRaphael Moll <ralf@android.com>
Sat, 19 Feb 2011 01:02:29 +0000 (17:02 -0800)
committerRaphael Moll <ralf@android.com>
Sat, 19 Feb 2011 01:02:29 +0000 (17:02 -0800)
Change-Id: Ie512a8cc75075987d1eb88dafd079e52083e2a3c

sdkmanager/libs/sdklib/src/com/android/sdklib/internal/repository/ExtraPackage.java
sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/RepoSourcesAdapter.java

index 49236dc..3472544 100755 (executable)
@@ -394,19 +394,33 @@ public class ExtraPackage extends MinToolsPackage
             ExtraPackage ep = (ExtraPackage) pkg;\r
 \r
             // To be backward compatible, we need to support the old vendor-path form\r
-            if (ep.mPath != null && (ep.mVendor == null || ep.mVendor.length() == 0) &&\r
-                    mPath != null && mVendor != null) {\r
-                if (ep.mPath.equals(mVendor + "-" + mPath)) {  //$NON-NLS-1$\r
+            // in either the current or the remote package.\r
+            //\r
+            // The vendor test below needs to account for an old installed package\r
+            // (e.g. with an install path of vendor-name) that has then beeen updated\r
+            // in-place and thus when reloaded contains the vendor name in both the\r
+            // path and the vendor attributes.\r
+            if (ep.mPath != null && mPath != null && mVendor != null) {\r
+                if (ep.mPath.equals(mVendor + "-" + mPath) &&  //$NON-NLS-1$\r
+                        (ep.mVendor == null || ep.mVendor.length() == 0\r
+                                || ep.mVendor.equals(mVendor))) {\r
+                    return true;\r
+                }\r
+            }\r
+            if (mPath != null && ep.mPath != null && ep.mVendor != null) {\r
+                if (mPath.equals(ep.mVendor + "-" + ep.mPath) &&  //$NON-NLS-1$\r
+                        (mVendor == null || mVendor.length() == 0 || mVendor.equals(ep.mVendor))) {\r
                     return true;\r
                 }\r
             }\r
 \r
+\r
             if (!mPath.equals(ep.mPath)) {\r
                 return false;\r
             }\r
             if ((mVendor == null && ep.mVendor == null) ||\r
-                (mVendor != null && !mVendor.equals(ep.mVendor))) {\r
-                return false;\r
+                (mVendor != null && mVendor.equals(ep.mVendor))) {\r
+                return true;\r
             }\r
         }\r
 \r
index 8722e02..54bc068 100755 (executable)
@@ -316,13 +316,13 @@ public class RepoSourcesAdapter {
         // get the installed packages\r
         Package[] installedPackages = mUpdaterData.getInstalledPackages();\r
 \r
+        // we'll populate this package list with either upgrades or new packages.\r
         ArrayList<Package> filteredList = new ArrayList<Package>();\r
 \r
         // for each remote packages, we look for an existing version.\r
         // If no existing version -> add to the list\r
         // if existing version but with older revision -> add it to the list\r
         for (Package remotePkg : remotePackages) {\r
-            boolean newPkg = true;\r
 \r
             // Obsolete packages are not offered as updates.\r
             if (remotePkg.isObsolete()) {\r
@@ -332,20 +332,27 @@ public class RepoSourcesAdapter {
             // For all potential packages, we also make sure that there's an archive for\r
             // the current platform, or we simply skip them.\r
             if (remotePkg.hasCompatibleArchive()) {\r
-                for (Package installedPkg : installedPackages) {\r
+                boolean keepPkg = true;\r
+\r
+                nextPkg: for (Package installedPkg : installedPackages) {\r
                     UpdateInfo info = installedPkg.canBeUpdatedBy(remotePkg);\r
-                    if (info == UpdateInfo.UPDATE) {\r
-                        filteredList.add(remotePkg);\r
-                        newPkg = false;\r
-                        break; // there shouldn't be 2 revisions of the same package\r
-                    } else if (info != UpdateInfo.INCOMPATIBLE) {\r
-                        newPkg = false;\r
-                        break; // there shouldn't be 2 revisions of the same package\r
+                    switch(info) {\r
+                    case UPDATE:\r
+                        // The remote package is an update to an existing one.\r
+                        // We're done looking.\r
+                        keepPkg = true;\r
+                        break nextPkg;\r
+                    case NOT_UPDATE:\r
+                        // The remote package is the same as one that is already installed.\r
+                        keepPkg = false;\r
+                        break;\r
+                    case INCOMPATIBLE:\r
+                        // We can't compare and decide on incompatible things.\r
+                        break;\r
                     }\r
                 }\r
 \r
-                // if we have not found the same package, then we add it (it's a new package)\r
-                if (newPkg) {\r
+                if (keepPkg) {\r
                     filteredList.add(remotePkg);\r
                 }\r
             }\r