Add boot message when upgrading database.

Change-Id: I3f17aed690066ed4d2ab645a059c66a1bdd7a1f1
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c7719ed..bc14294 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -26,6 +26,9 @@
     <!-- What to show in messaging that refers to this provider, e.g. AccountSyncSettings -->
     <string name="provider_label">Contacts</string>
 
+    <!-- [CHAR LIMIT=NONE] Boot message while upgrading contacts. -->
+    <string name="upgrade_msg">Upgrading Contacts database.</string>
+
     <!-- Ticker for the notification shown when updating contacts fails because of memory shortage -->
     <string name="upgrade_out_of_memory_notification_ticker">Contact upgrade needs more memory</string>
 
diff --git a/src/com/android/providers/contacts/ContactsUpgradeReceiver.java b/src/com/android/providers/contacts/ContactsUpgradeReceiver.java
index 747ecca..f27eae8 100644
--- a/src/com/android/providers/contacts/ContactsUpgradeReceiver.java
+++ b/src/com/android/providers/contacts/ContactsUpgradeReceiver.java
@@ -16,12 +16,14 @@
 
 package com.android.providers.contacts;
 
+import android.app.ActivityManagerNative;
 import android.content.BroadcastReceiver;
 import android.content.ComponentName;
 import android.content.Context;
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.pm.PackageManager;
+import android.os.RemoteException;
 import android.util.Log;
 
 /**
@@ -57,14 +59,21 @@
                 // is attempted to be conservative. If the upgrade fails for some reason and we
                 // crash and burn we don't want to get into a loop doing so.
                 prefs.edit().putInt(
-                    PREF_DB_VERSION, ContactsDatabaseHelper.DATABASE_VERSION).apply();
+                    PREF_DB_VERSION, ContactsDatabaseHelper.DATABASE_VERSION).commit();
 
                 // Ask for a reference to the database to force the helper to either
                 // create the database or open it up, performing any necessary upgrades
                 // in the process.
-                Log.i(TAG, "Creating or opening contacts database");
                 ContactsDatabaseHelper helper = ContactsDatabaseHelper.getInstance(context);
-                helper.getWritableDatabase();
+                if (context.getDatabasePath(helper.getDatabaseName()).exists()) {
+                    Log.i(TAG, "Creating or opening contacts database");
+                    try {
+                        ActivityManagerNative.getDefault().showBootMessage(
+                                context.getText(R.string.upgrade_msg), true);
+                    } catch (RemoteException e) {
+                    }
+                    helper.getWritableDatabase();
+                }
                 helper.close();
 
                 // Log the total time taken for the receiver to perform the operation