Add an 'init everything' operation to the first backup pass

IBackupTransport.performBackup() now takes a flag "wipeAllFirst", which if set
will result in the entire restore set for the current device/account being wiped
clean prior to the storage of the provided package.  This ensures that a device
on which backup has just been enabled will not confront potentially-stale
information, nor will the restore set potentially contain mismatched data from
orphaned packages.

The Backup Manager has also been revised to pass this flag when first backing up
its master metadata block (and never pass it thereafter unless something has
caused the backup state tracking to be erased, e.g. the user has opted out of
backup and then later re-enabled it).
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index 4186327..776de7e 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -949,11 +949,11 @@
             }
         }
 
-        void processOneBackup(BackupRequest request, IBackupAgent agent, IBackupTransport transport) {
+        void processOneBackup(BackupRequest request, IBackupAgent agent,
+                IBackupTransport transport) {
             final String packageName = request.appInfo.packageName;
             if (DEBUG) Log.d(TAG, "processOneBackup doBackup() on " + packageName);
 
-            // !!! TODO: get the state file dir from the transport
             File savedStateName = new File(mStateDir, packageName);
             File backupDataName = new File(mDataDir, packageName + ".data");
             File newStateName = new File(mStateDir, packageName + ".new");
@@ -962,6 +962,12 @@
             ParcelFileDescriptor backupData = null;
             ParcelFileDescriptor newState = null;
 
+            // Usually we won't force a server-side init, except the first time
+            // we ever back up following enable of backup.  To keep the bookkeeping
+            // simple, we detect this here rather than maintain state throughout
+            // the backup manager.
+            boolean doInit = false;
+
             PackageInfo packInfo;
             try {
                 // Look up the package info & signatures.  This is first so that if it
@@ -971,6 +977,13 @@
                     // The metadata 'package' is synthetic
                     packInfo = new PackageInfo();
                     packInfo.packageName = packageName;
+
+                    // if there's no metadata backup state, this must be the
+                    // first time we've done one since enabling it.
+                    if (savedStateName.exists() == false) {
+                        if (DEBUG) Log.i(TAG, "First backup pass, issuing init");
+                        doInit = true;
+                    }
                 } else {
                     packInfo = mPackageManager.getPackageInfo(packageName,
                         PackageManager.GET_SIGNATURES);
@@ -1023,7 +1036,7 @@
                     // hold off on finishBackup() until the end, which implies holding off on
                     // renaming *all* the output state files (see below) until that happens.
 
-                    if (!transport.performBackup(packInfo, backupData) ||
+                    if (!transport.performBackup(packInfo, backupData, doInit) ||
                         !transport.finishBackup()) {
                         throw new Exception("Backup transport failed");
                     }