DeskClock: Schedule alarms after restore

Fix a bug causing the backup agent's handling of the restore process
to crash, preventing enabled alarms from being scheduled.

Maybe squash with: I1321da4b2250d083c8785386af5ba096cd0e05eb
"DeskClock: Enable backup"

Test: Manual: Steps below:
0. Establish Seedvault backup (easiest to just do a local internal storage backup).
1. Set a few alarms, maybe for 5, 10, and 15 minutes in the future.
2. Run "Backup now" in Seedvault.
3. Once it has finished, turn off the alarms.
4. Run `adb shell bmgr list sets` to get the restore set ID ("${RESTORE_SET_ID}" below).
5. Run `adb shell bmgr restore ${RESTORE_SET_ID} com.android.deskclock`.
6. Within a minute, the alarm icon should appear in the status bar because the alarms have been successfully scheduled. They will sound at the expected time(s).

Change-Id: Ib8bd0cf03f943469fec105b141c58f5f543ccaa0
diff --git a/src/com/android/deskclock/AlarmInitReceiver.java b/src/com/android/deskclock/AlarmInitReceiver.java
index 8361542..557afd8 100644
--- a/src/com/android/deskclock/AlarmInitReceiver.java
+++ b/src/com/android/deskclock/AlarmInitReceiver.java
@@ -16,6 +16,8 @@
 
 package com.android.deskclock;
 
+import static com.android.deskclock.DeskClockBackupAgent.ACTION_COMPLETE_RESTORE;
+
 import android.annotation.SuppressLint;
 import android.content.BroadcastReceiver;
 import android.content.ContentResolver;
@@ -75,6 +77,12 @@
         // We need to increment the global id out of the async task to prevent race conditions
         DataModel.getDataModel().updateGlobalIntentId();
 
+        if (ACTION_COMPLETE_RESTORE.equals(action)) {
+            // Our "minimalist" state in DeskClockBackupAgent's onRestoreFinished prevents
+            // accessing the data model from there, so we set this here.
+            DataModel.getDataModel().setRestoreBackupFinished(true);
+        }
+
         // Updates stopwatch and timer data after a device reboot so they are as accurate as
         // possible.
         if (ACTION_BOOT_COMPLETED.equals(action)) {
diff --git a/src/com/android/deskclock/DeskClockBackupAgent.java b/src/com/android/deskclock/DeskClockBackupAgent.java
index 97fddf4..3de0b4a 100644
--- a/src/com/android/deskclock/DeskClockBackupAgent.java
+++ b/src/com/android/deskclock/DeskClockBackupAgent.java
@@ -83,8 +83,9 @@
         // TODO: migrate restored database and preferences over into
         // the device-encrypted storage area
 
-        // Indicate a data restore has been completed.
-        DataModel.getDataModel().setRestoreBackupFinished(true);
+        // We are executing in a "minimalist" state in which DataModel.getDataModel() unexpectedly
+        // returns null, so we must call setRestoreBackupFinished in AlarmInitReceiver's handling
+        // of ACTION_COMPLETE_RESTORE instead.
 
         // Create an Intent to send into DeskClock indicating restore is complete.
         final PendingIntent restoreIntent = PendingIntent.getBroadcast(this, 0,