Revert "Move all sms tables except raw into credential encrypted storage."

This reverts commit 8f3ad6fe306155ffe87d6d0860db2e2c238d158d.

Change-Id: I1c1ca585fdeeed6cf34f1f682b42ea74d3127993
diff --git a/src/com/android/providers/telephony/DeviceEncryptedMmsSmsDatabaseHelper.java b/src/com/android/providers/telephony/DeviceEncryptedMmsSmsDatabaseHelper.java
deleted file mode 100644
index 04a7abb..0000000
--- a/src/com/android/providers/telephony/DeviceEncryptedMmsSmsDatabaseHelper.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Copyright (C) 2008 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.providers.telephony;
-
-import android.content.Context;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.telephony.SubscriptionManager;
-import android.util.Log;
-
-/**
- * Database open helper responsible for Mms/Sms tables in the Device-Encrypted storage.
- */
-public class DeviceEncryptedMmsSmsDatabaseHelper extends SQLiteOpenHelper {
-  private static final String TAG = "MmsSmsDeDatabaseHelper";
-
-    private static DeviceEncryptedMmsSmsDatabaseHelper sInstance = null;
-
-
-    private DeviceEncryptedMmsSmsDatabaseHelper(Context context) {
-      super(
-          context, MmsSmsDatabaseHelper.DATABASE_NAME, null, MmsSmsDatabaseHelper.DATABASE_VERSION);
-    }
-
-    /**
-     * Return a singleton helper for the combined MMS and SMS
-     * database.
-     */
-    /* package */ static synchronized DeviceEncryptedMmsSmsDatabaseHelper getInstance(Context context) {
-        if (sInstance == null) {
-            sInstance = new DeviceEncryptedMmsSmsDatabaseHelper(context);
-        }
-        return sInstance;
-    }
-
-    @Override
-    public void onCreate(SQLiteDatabase db) {
-        createSmsTables(db);
-    }
-
-    private void createSmsTables(SQLiteDatabase db) {
-        /**
-         * This table is used by the SMS dispatcher to hold
-         * incomplete partial messages until all the parts arrive.
-         */
-        db.execSQL("CREATE TABLE raw (" +
-                   "_id INTEGER PRIMARY KEY," +
-                   "date INTEGER," +
-                   "reference_number INTEGER," + // one per full message
-                   "count INTEGER," + // the number of parts
-                   "sequence INTEGER," + // the part number of this message
-                   "destination_port INTEGER," +
-                   "address TEXT," +
-                   "sub_id INTEGER DEFAULT " + SubscriptionManager.INVALID_SUBSCRIPTION_ID + ", " +
-                   "pdu TEXT);"); // the raw PDU for this part
-    }
-
-    @Override
-    public void onUpgrade(SQLiteDatabase db, int oldVersion, int currentVersion) {
-        Log.w(TAG, "Upgrading database from version " + oldVersion
-                + " to " + currentVersion + ".");
-        Log.e(TAG, "Destroying all old data.");
-        dropAll(db);
-        onCreate(db);
-    }
-
-    private void dropAll(SQLiteDatabase db) {
-        // Clean the database out in order to start over from scratch.
-        // We don't need to drop our triggers here because SQLite automatically
-        // drops a trigger when its attached database is dropped.
-        db.execSQL("DROP TABLE IF EXISTS raw");
-    }
-
-    @Override
-    public synchronized SQLiteDatabase getWritableDatabase() {
-      return super.getWritableDatabase();
-    }
-}
diff --git a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
index 5d668ec..f2d12d3 100644
--- a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
+++ b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
@@ -16,9 +16,6 @@
 
 package com.android.providers.telephony;
 
-import com.google.android.mms.pdu.EncodedStringValue;
-import com.google.android.mms.pdu.PduHeaders;
-
 import android.content.BroadcastReceiver;
 import android.content.ContentValues;
 import android.content.Context;
@@ -40,6 +37,9 @@
 import android.telephony.SubscriptionManager;
 import android.util.Log;
 
+import com.google.android.mms.pdu.EncodedStringValue;
+import com.google.android.mms.pdu.PduHeaders;
+
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
@@ -48,9 +48,6 @@
 import java.util.HashSet;
 import java.util.Iterator;
 
-/**
- * Database open helper responsible for tables in the Credentials-Encrypted storage.
- */
 public class MmsSmsDatabaseHelper extends SQLiteOpenHelper {
     private static final String TAG = "MmsSmsDatabaseHelper";
 
@@ -235,7 +232,6 @@
      * database.
      */
     /* package */ static synchronized MmsSmsDatabaseHelper getInstance(Context context) {
-        context = ProviderUtil.getCredentialEncryptedContext(context);
         if (sInstance == null) {
             sInstance = new MmsSmsDatabaseHelper(context);
         }
@@ -858,6 +854,21 @@
                    "seen INTEGER DEFAULT 0" +
                    ");");
 
+        /**
+         * This table is used by the SMS dispatcher to hold
+         * incomplete partial messages until all the parts arrive.
+         */
+        db.execSQL("CREATE TABLE raw (" +
+                   "_id INTEGER PRIMARY KEY," +
+                   "date INTEGER," +
+                   "reference_number INTEGER," + // one per full message
+                   "count INTEGER," + // the number of parts
+                   "sequence INTEGER," + // the part number of this message
+                   "destination_port INTEGER," +
+                   "address TEXT," +
+                   "sub_id INTEGER DEFAULT " + SubscriptionManager.INVALID_SUBSCRIPTION_ID + ", " +
+                   "pdu TEXT);"); // the raw PDU for this part
+
         db.execSQL("CREATE TABLE attachments (" +
                    "sms_id INTEGER," +
                    "content_url TEXT," +
@@ -1368,6 +1379,7 @@
         db.execSQL("DROP TABLE IF EXISTS threads");
         db.execSQL("DROP TABLE IF EXISTS " + MmsSmsProvider.TABLE_PENDING_MSG);
         db.execSQL("DROP TABLE IF EXISTS sms");
+        db.execSQL("DROP TABLE IF EXISTS raw");
         db.execSQL("DROP TABLE IF EXISTS attachments");
         db.execSQL("DROP TABLE IF EXISTS thread_ids");
         db.execSQL("DROP TABLE IF EXISTS sr_pending");
@@ -1562,6 +1574,9 @@
         db.execSQL("ALTER TABLE " + SmsProvider.TABLE_SMS
                 + " ADD COLUMN " + Sms.SUBSCRIPTION_ID
                 + " INTEGER DEFAULT " + SubscriptionManager.INVALID_SUBSCRIPTION_ID);
+        db.execSQL("ALTER TABLE " + SmsProvider.TABLE_RAW
+                +" ADD COLUMN " + Sms.SUBSCRIPTION_ID
+                + " INTEGER DEFAULT " + SubscriptionManager.INVALID_SUBSCRIPTION_ID);
     }
 
     private void upgradeDatabaseToVersion59(SQLiteDatabase db) {
@@ -1888,7 +1903,6 @@
         public LowStorageMonitor() {
         }
 
-        @Override
         public void onReceive(Context context, Intent intent) {
             String action = intent.getAction();
 
diff --git a/src/com/android/providers/telephony/ProviderUtil.java b/src/com/android/providers/telephony/ProviderUtil.java
index 7d8ab21..34c6da9 100644
--- a/src/com/android/providers/telephony/ProviderUtil.java
+++ b/src/com/android/providers/telephony/ProviderUtil.java
@@ -23,6 +23,7 @@
 import android.net.Uri;
 import android.os.Process;
 import android.provider.Telephony;
+import android.provider.Telephony.Sms;
 import android.text.TextUtils;
 import android.util.Log;
 
@@ -111,12 +112,4 @@
         context.sendBroadcast(intent);
     }
 
-    public static Context getCredentialEncryptedContext(Context context) {
-        if (context.isCredentialEncryptedStorage()) {
-            return context;
-        }
-        Context ceContext = context.createCredentialEncryptedStorageContext();
-        return ceContext != null ? ceContext : context;
-    }
-
 }
diff --git a/src/com/android/providers/telephony/SmsProvider.java b/src/com/android/providers/telephony/SmsProvider.java
index 4201eca..c282a7f 100644
--- a/src/com/android/providers/telephony/SmsProvider.java
+++ b/src/com/android/providers/telephony/SmsProvider.java
@@ -17,10 +17,12 @@
 package com.android.providers.telephony;
 
 import android.app.AppOpsManager;
+import android.content.ComponentName;
 import android.content.ContentProvider;
 import android.content.ContentResolver;
 import android.content.ContentValues;
 import android.content.Context;
+import android.content.Intent;
 import android.content.UriMatcher;
 import android.database.Cursor;
 import android.database.DatabaseUtils;
@@ -42,6 +44,8 @@
 import android.text.TextUtils;
 import android.util.Log;
 
+import com.android.internal.telephony.SmsApplication;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 
@@ -87,7 +91,6 @@
     public boolean onCreate() {
         setAppOps(AppOpsManager.OP_READ_SMS, AppOpsManager.OP_WRITE_SMS);
         mOpenHelper = MmsSmsDatabaseHelper.getInstance(getContext());
-        mDeOpenHelper = DeviceEncryptedMmsSmsDatabaseHelper.getInstance(getContext());
         return true;
     }
 
@@ -253,7 +256,7 @@
             orderBy = Sms.DEFAULT_SORT_ORDER;
         }
 
-        SQLiteDatabase db = getDBOpenHelper(match).getReadableDatabase();
+        SQLiteDatabase db = mOpenHelper.getReadableDatabase();
         Cursor ret = qb.query(db, projectionIn, selection, selectionArgs,
                               null, null, orderBy);
 
@@ -263,13 +266,6 @@
         return ret;
     }
 
-    private SQLiteOpenHelper getDBOpenHelper(int match) {
-        if (match == SMS_RAW_MESSAGE) {
-            return mDeOpenHelper;
-        }
-        return mOpenHelper;
-    }
-
     private Object[] convertIccToSms(SmsMessage message, int id) {
         // N.B.: These calls must appear in the same order as the
         // columns appear in ICC_COLUMNS.
@@ -473,7 +469,7 @@
                 return null;
         }
 
-        SQLiteDatabase db = getDBOpenHelper(match).getWritableDatabase();
+        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
 
         if (table.equals(TABLE_SMS)) {
             boolean addDate = false;
@@ -602,7 +598,7 @@
     public int delete(Uri url, String where, String[] whereArgs) {
         int count;
         int match = sURLMatcher.match(url);
-        SQLiteDatabase db = getDBOpenHelper(match).getWritableDatabase();
+        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
         boolean notifyIfNotDefault = true;
         switch (match) {
             case SMS_ALL:
@@ -695,10 +691,9 @@
         String table = TABLE_SMS;
         String extraWhere = null;
         boolean notifyIfNotDefault = true;
-        int match = sURLMatcher.match(url);
-        SQLiteDatabase db = getDBOpenHelper(match).getWritableDatabase();
+        SQLiteDatabase db = mOpenHelper.getWritableDatabase();
 
-        switch (match) {
+        switch (sURLMatcher.match(url)) {
             case SMS_RAW_MESSAGE:
                 table = TABLE_RAW;
                 notifyIfNotDefault = false;
@@ -784,7 +779,6 @@
     }
 
     private SQLiteOpenHelper mOpenHelper;
-    private SQLiteOpenHelper mDeOpenHelper;
 
     private final static String TAG = "SmsProvider";
     private final static String VND_ANDROID_SMS = "vnd.android.cursor.item/sms";