remove OTA packages from the old (pre-froyo) updater

The old updater ran in the system process, so only that UID can delete
its downloads.  Do this on startup in case we've just upgraded from
something before froyo and need to clean up those packages.

b/2571619 - eclair -> froyo update package not deleted

Change-Id: I0a5e7834c3ecd2cc2f6fd73052b3a38e1294b5d5
diff --git a/services/java/com/android/server/BootReceiver.java b/services/java/com/android/server/BootReceiver.java
index 15aad0e..f409751 100644
--- a/services/java/com/android/server/BootReceiver.java
+++ b/services/java/com/android/server/BootReceiver.java
@@ -21,6 +21,7 @@
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
+import android.net.Downloads;
 import android.os.Build;
 import android.os.DropBoxManager;
 import android.os.FileObserver;
@@ -45,6 +46,14 @@
 
     private static final File TOMBSTONE_DIR = new File("/data/tombstones");
 
+    // The pre-froyo package and class of the system updater, which
+    // ran in the system process.  We need to remove its packages here
+    // in order to clean up after a pre-froyo-to-froyo update.
+    private static final String OLD_UPDATER_PACKAGE =
+        "com.google.android.systemupdater";
+    private static final String OLD_UPDATER_CLASS =
+        "com.google.android.systemupdater.SystemUpdateReceiver";
+
     // Keep a reference to the observer so the finalizer doesn't disable it.
     private static FileObserver sTombstoneObserver = null;
 
@@ -70,10 +79,21 @@
                 } catch (Exception e) {
                     Slog.e(TAG, "Can't log boot events", e);
                 }
+                try {
+                    removeOldUpdatePackages(context);
+                } catch (Exception e) {
+                    Slog.e(TAG, "Can't remove old update packages", e);
+                }
+
             }
         }.start();
     }
 
+    private void removeOldUpdatePackages(Context ctx) {
+        Downloads.ByUri.removeAllDownloadsByPackage(
+            ctx, OLD_UPDATER_PACKAGE, OLD_UPDATER_CLASS);
+    }
+
     private void logBootEvents(Context ctx) throws IOException {
         final DropBoxManager db = (DropBoxManager) ctx.getSystemService(Context.DROPBOX_SERVICE);
         final SharedPreferences prefs = ctx.getSharedPreferences("log_files", Context.MODE_PRIVATE);