AI 143776: am: CL 143622 Correctly startListening() for widget updates when first boot completes.
  During the first boot upgrade, LauncherProvider will deleteHost() to clear out any old appWidgetId bindings.  During the first boot, Launcher calls AppWidgetHost.startListening() to watch for widget updates.  It also calls loadUserItems(), which loads data from LauncherProvider, triggering the database creation and deleteHost() call.  Because deleteHost() removes any existing callbacks, any future widget updates are dropped on the floor.  (This can currently be solved by rebooting, because there isn't an upgrade on subsequent boots.)
  This bug was particularly evident on vfpioneer-userdebug builds, as there aren't any configuration changes that cause Launcher to be destroyed and recreated.  (When destroyed and recreated, we startListening() again, and LauncherProvider doesn't call deleteHost().)
  To handle this special case, Launcher creates a ContentObserver pointing at a specific URI, which the LauncherProvider notifies when the AppWidgetHost is reset through deleteHost(), allowing Launcher to correctly startListening() again.
  Original author: jsharkey
  Merged from: //branches/cupcake/...

Automated import of CL 143776
diff --git a/src/com/android/launcher/LauncherProvider.java b/src/com/android/launcher/LauncherProvider.java
index e63ef30..a27b746 100644
--- a/src/com/android/launcher/LauncherProvider.java
+++ b/src/com/android/launcher/LauncherProvider.java
@@ -65,6 +65,14 @@
     static final String TABLE_FAVORITES = "favorites";
     static final String PARAMETER_NOTIFY = "notify";
 
+    /**
+     * {@link Uri} triggered at any registered {@link ContentObserver} when
+     * {@link AppWidgetHost#deleteHost()} is called during database creation.
+     * Use this to recall {@link AppWidgetHost#startListening()} if needed.
+     */
+    static final Uri CONTENT_APPWIDGET_RESET_URI =
+            Uri.parse("content://" + AUTHORITY + "/appWidgetReset");
+    
     private SQLiteOpenHelper mOpenHelper;
 
     @Override
@@ -176,6 +184,17 @@
             mAppWidgetHost = new AppWidgetHost(context, Launcher.APPWIDGET_HOST_ID);
         }
 
+        /**
+         * Send notification that we've deleted the {@link AppWidgetHost},
+         * probably as part of the initial database creation. The receiver may
+         * want to re-call {@link AppWidgetHost#startListening()} to ensure
+         * callbacks are correctly set.
+         */
+        private void sendAppWidgetResetNotify() {
+            final ContentResolver resolver = mContext.getContentResolver();
+            resolver.notifyChange(CONTENT_APPWIDGET_RESET_URI, null);
+        }
+
         @Override
         public void onCreate(SQLiteDatabase db) {
             if (LOGD) Log.d(LOG_TAG, "creating new launcher database");
@@ -204,6 +223,7 @@
             // Database was just created, so wipe any previous widgets
             if (mAppWidgetHost != null) {
                 mAppWidgetHost.deleteHost();
+                sendAppWidgetResetNotify();
             }
             
             if (!convertDatabase(db)) {