Better event log tracking for initializeDevice() requests --
on success, record "backup_initialize" event; on failure,
record "backup_transport_failure" event (and add tags to
"backup_transport_failure" events that aren't associated
with a particular package -- namely "(initialize)" and
"(finish)").
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index d4cebef..ef0cbee 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -106,6 +106,7 @@
     private static final int BACKUP_PACKAGE_EVENT = 2824;
     private static final int BACKUP_SUCCESS_EVENT = 2825;
     private static final int BACKUP_RESET_EVENT = 2826;
+    private static final int BACKUP_INITIALIZE_EVENT = 2827;
 
     private static final int RESTORE_START_EVENT = 2830;
     private static final int RESTORE_TRANSPORT_FAILURE_EVENT = 2831;
@@ -1062,7 +1063,14 @@
 
                 // If we haven't stored anything yet, we need to do an init operation.
                 if (status == BackupConstants.TRANSPORT_OK && mEverStoredApps.size() == 0) {
+                    Log.i(TAG, "Initializing (wiping) backup transport storage");
                     status = mTransport.initializeDevice();
+                    if (status == BackupConstants.TRANSPORT_OK) {
+                        EventLog.writeEvent(BACKUP_INITIALIZE_EVENT);
+                    } else {
+                        EventLog.writeEvent(BACKUP_TRANSPORT_FAILURE_EVENT, "(initialize)");
+                        Log.e(TAG, "Transport error in initializeDevice()");
+                    }
                 }
 
                 // The package manager doesn't have a proper <application> etc, but since
@@ -1091,7 +1099,7 @@
                         int millis = (int) (SystemClock.elapsedRealtime() - startRealtime);
                         EventLog.writeEvent(BACKUP_SUCCESS_EVENT, mQueue.size(), millis);
                     } else {
-                        EventLog.writeEvent(BACKUP_TRANSPORT_FAILURE_EVENT, "");
+                        EventLog.writeEvent(BACKUP_TRANSPORT_FAILURE_EVENT, "(finish)");
                         Log.e(TAG, "Transport error in finishBackup()");
                     }
                 }
@@ -1714,7 +1722,6 @@
 
         @Override
         public void run() {
-            int status;
             try {
                 for (String transportName : mQueue) {
                     IBackupTransport transport = getTransport(transportName);
@@ -1723,33 +1730,30 @@
                         continue;
                     }
 
-                    status = BackupConstants.TRANSPORT_OK;
-                    File stateDir = null;
+                    Log.i(TAG, "Initializing (wiping) backup transport storage: " + transportName);
+                    EventLog.writeEvent(BACKUP_START_EVENT, transport.transportDirName());
+                    long startRealtime = SystemClock.elapsedRealtime();
+                    int status = transport.initializeDevice();
 
-                    Log.i(TAG, "Device init on " + transport.transportDirName());
-
-                    stateDir = new File(mBaseStateDir, transport.transportDirName());
-
-                    status = transport.initializeDevice();
-                    if (status != BackupConstants.TRANSPORT_OK) {
-                        Log.e(TAG, "Error from initializeDevice: " + status);
-                    }
                     if (status == BackupConstants.TRANSPORT_OK) {
                         status = transport.finishBackup();
                     }
 
                     // Okay, the wipe really happened.  Clean up our local bookkeeping.
                     if (status == BackupConstants.TRANSPORT_OK) {
-                        resetBackupState(stateDir);
+                        Log.i(TAG, "Device init successful");
+                        int millis = (int) (SystemClock.elapsedRealtime() - startRealtime);
+                        EventLog.writeEvent(BACKUP_INITIALIZE_EVENT);
+                        resetBackupState(new File(mBaseStateDir, transport.transportDirName()));
+                        EventLog.writeEvent(BACKUP_SUCCESS_EVENT, 0, millis);
                         synchronized (mQueueLock) {
                             recordInitPendingLocked(false, transportName);
                         }
-                    }
-
-                    // If this didn't work, requeue this one and try again
-                    // after a suitable interval
-                    if (status != BackupConstants.TRANSPORT_OK) {
-                        Log.i(TAG, "Device init failed");
+                    } else {
+                        // If this didn't work, requeue this one and try again
+                        // after a suitable interval
+                        Log.e(TAG, "Transport error in initializeDevice()");
+                        EventLog.writeEvent(BACKUP_TRANSPORT_FAILURE_EVENT, "(initialize)");
                         synchronized (mQueueLock) {
                             recordInitPendingLocked(true, transportName);
                         }
@@ -1759,11 +1763,7 @@
                                 + transportName + " resched in " + delay);
                         mAlarmManager.set(AlarmManager.RTC_WAKEUP,
                                 System.currentTimeMillis() + delay, mRunInitIntent);
-                    } else {
-                        // success!
-                        Log.i(TAG, "Device init successful");
                     }
-
                 }
             } catch (RemoteException e) {
                 // can't happen; the transports are local