Merge "Add message_body to raw table when it is created." into nyc-dev
diff --git a/src/com/android/providers/telephony/MmsProvider.java b/src/com/android/providers/telephony/MmsProvider.java
index 2c7222a..5acfe13 100644
--- a/src/com/android/providers/telephony/MmsProvider.java
+++ b/src/com/android/providers/telephony/MmsProvider.java
@@ -71,6 +71,7 @@
     public boolean onCreate() {
         setAppOps(AppOpsManager.OP_READ_SMS, AppOpsManager.OP_WRITE_SMS);
         mOpenHelper = MmsSmsDatabaseHelper.getInstanceForCe(getContext());
+        TelephonyBackupAgent.DeferredSmsMmsRestoreService.startIfFilesExist(getContext());
         return true;
     }
 
diff --git a/src/com/android/providers/telephony/MmsSmsProvider.java b/src/com/android/providers/telephony/MmsSmsProvider.java
index b2fa117..d5e0ef9 100644
--- a/src/com/android/providers/telephony/MmsSmsProvider.java
+++ b/src/com/android/providers/telephony/MmsSmsProvider.java
@@ -312,6 +312,7 @@
         mUseStrictPhoneNumberComparation =
             getContext().getResources().getBoolean(
                     com.android.internal.R.bool.config_use_strict_phone_number_comparation);
+        TelephonyBackupAgent.DeferredSmsMmsRestoreService.startIfFilesExist(getContext());
         return true;
     }
 
diff --git a/src/com/android/providers/telephony/SmsProvider.java b/src/com/android/providers/telephony/SmsProvider.java
index d8b97c5..f50f804 100644
--- a/src/com/android/providers/telephony/SmsProvider.java
+++ b/src/com/android/providers/telephony/SmsProvider.java
@@ -92,6 +92,7 @@
         setAppOps(AppOpsManager.OP_READ_SMS, AppOpsManager.OP_WRITE_SMS);
         mDeOpenHelper = MmsSmsDatabaseHelper.getInstanceForDe(getContext());
         mCeOpenHelper = MmsSmsDatabaseHelper.getInstanceForCe(getContext());
+        TelephonyBackupAgent.DeferredSmsMmsRestoreService.startIfFilesExist(getContext());
         return true;
     }
 
diff --git a/src/com/android/providers/telephony/TelephonyBackupAgent.java b/src/com/android/providers/telephony/TelephonyBackupAgent.java
index 61796a2..5f4acaa 100644
--- a/src/com/android/providers/telephony/TelephonyBackupAgent.java
+++ b/src/com/android/providers/telephony/TelephonyBackupAgent.java
@@ -476,15 +476,9 @@
         protected void onHandleIntent(Intent intent) {
             try {
                 mWakeLock.acquire();
-                File[] files = getFilesDir().listFiles(new FileFilter() {
-                    @Override
-                    public boolean accept(File file) {
-                        return file.getName().endsWith(SMS_BACKUP_FILE_SUFFIX) ||
-                                file.getName().endsWith(MMS_BACKUP_FILE_SUFFIX);
-                    }
-                });
+                File[] files = getFilesToRestore(this);
 
-                if (files == null) {
+                if (files == null || files.length == 0) {
                     return;
                 }
                 Arrays.sort(files, mFileComparator);
@@ -525,15 +519,29 @@
             super.onDestroy();
         }
 
-        public static Intent getIntent(Context context) {
-            return new Intent(context, DeferredSmsMmsRestoreService.class);
+        static void startIfFilesExist(Context context) {
+            File[] files = getFilesToRestore(context);
+            if (files == null || files.length == 0) {
+                return;
+            }
+            context.startService(new Intent(context, DeferredSmsMmsRestoreService.class));
+        }
+
+        private static File[] getFilesToRestore(Context context) {
+            return context.getFilesDir().listFiles(new FileFilter() {
+                @Override
+                public boolean accept(File file) {
+                    return file.getName().endsWith(SMS_BACKUP_FILE_SUFFIX) ||
+                            file.getName().endsWith(MMS_BACKUP_FILE_SUFFIX);
+                }
+            });
         }
     }
 
     @Override
     public void onRestoreFinished() {
         super.onRestoreFinished();
-        startService(DeferredSmsMmsRestoreService.getIntent(this));
+        DeferredSmsMmsRestoreService.startIfFilesExist(this);
     }
 
     private void doRestoreFile(String fileName, FileDescriptor fd) throws IOException {
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 808a660..23e75f2 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -1081,11 +1081,12 @@
             addBoolAttribute(parser, "modem_cognitive", map, MODEM_COGNITIVE);
             addBoolAttribute(parser, "user_visible", map, USER_VISIBLE);
 
+            int bearerBitmask = 0;
             String bearerList = parser.getAttributeValue(null, "bearer_bitmask");
             if (bearerList != null) {
-                int bearerBitmask = ServiceState.getBitmaskFromString(bearerList);
-                map.put(BEARER_BITMASK, bearerBitmask);
+                bearerBitmask = ServiceState.getBitmaskFromString(bearerList);
             }
+            map.put(BEARER_BITMASK, bearerBitmask);
 
             String mvno_type = parser.getAttributeValue(null, "mvno_type");
             if (mvno_type != null) {