[automerger skipped] Merge "cellbroadcast provider refactor" am: 61119df4d4 am: 442fc2ae71
am: efcfb006cf -s ours
am skip reason: change_id I2cf0d0314e5f0283e6bde71407a1d43d7373a2e7 with SHA1 fc0a165b8e is in history

Change-Id: Ic5d27e3a12179c4735a99e12cb917b5208a81d46
diff --git a/Android.bp b/Android.bp
index eabd567..ad23fcd 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,7 +1,13 @@
+filegroup {
+    name: "jarjar-rules",
+    srcs: ["jarjar-rules.txt"],
+}
+
 android_app {
     name: "TelephonyProvider",
     privileged: true,
     srcs: ["src/**/*.java"],
+    jarjar_rules: ":jarjar-rules",
     platform_apis: true,
     certificate: "platform",
     libs: ["telephony-common"],
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d5c379b..4ae9acf 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -107,12 +107,6 @@
                   android:multiprocess="false"
                   android:writePermission="android.permission.MODIFY_PHONE_STATE" />
 
-        <provider android:name="CellBroadcastProvider"
-                  android:authorities="cellbroadcasts"
-                  android:exported="true"
-                  android:singleUser="true"
-                  android:multiprocess="false" />
-
         <provider android:name="HbpcdLookupProvider"
                   android:authorities="hbpcd_lookup"
                   android:exported="true"
diff --git a/jarjar-rules.txt b/jarjar-rules.txt
new file mode 100644
index 0000000..b0d73d3
--- /dev/null
+++ b/jarjar-rules.txt
@@ -0,0 +1 @@
+rule com.android.internal.util.XmlUtils* com.android.internal.telephony.XmlUtils@1
diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index 6cfcdfb..f3baf24 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -17,5 +17,5 @@
 <resources xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
     <string name="app_label" product="tablet" msgid="9194799012395299737">"Configuration du réseau mobile"</string>
-    <string name="app_label" product="default" msgid="8338087656149558019">"Stockage tél. et SMS/MMS"</string>
+    <string name="app_label" product="default" msgid="8338087656149558019">"Téléphone et stockage des messages"</string>
 </resources>
diff --git a/src/com/android/providers/telephony/CarrierIdProvider.java b/src/com/android/providers/telephony/CarrierIdProvider.java
index 44f053d..d43e6c6 100644
--- a/src/com/android/providers/telephony/CarrierIdProvider.java
+++ b/src/com/android/providers/telephony/CarrierIdProvider.java
@@ -25,23 +25,23 @@
 import android.content.pm.PackageManager;
 import android.database.Cursor;
 import android.database.MatrixCursor;
-import android.database.SQLException;
 import android.database.sqlite.SQLiteDatabase;
 import android.database.sqlite.SQLiteOpenHelper;
 import android.database.sqlite.SQLiteQueryBuilder;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Environment;
+import android.os.FileUtils;
 import android.os.SystemProperties;
 import android.provider.Telephony.CarrierId;
 import android.telephony.SubscriptionManager;
 import android.text.TextUtils;
 import android.util.Log;
-import android.util.Pair;
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.telephony.SubscriptionController;
 import com.android.internal.telephony.nano.CarrierIdProto;
+import com.android.internal.telephony.util.TelephonyUtils;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -54,8 +54,6 @@
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
-import libcore.io.IoUtils;
-
 /**
  * This class provides the ability to query the Carrier Identification databases
  * (A.K.A. cid) which is stored in a SQLite database.
@@ -536,7 +534,7 @@
         } catch (IOException ex) {
             Log.e(TAG, "read carrier list from assets pb failure: " + ex);
         } finally {
-            IoUtils.closeQuietly(is);
+            FileUtils.closeQuietly(is);
         }
         try {
             is = new FileInputStream(new File(Environment.getDataDirectory(), OTA_UPDATED_PB_PATH));
@@ -544,7 +542,7 @@
         } catch (IOException ex) {
             Log.e(TAG, "read carrier list from ota pb failure: " + ex);
         } finally {
-            IoUtils.closeQuietly(is);
+            FileUtils.closeQuietly(is);
         }
 
         // compare version
@@ -553,7 +551,7 @@
             version = assets.version;
         }
         // bypass version check for ota carrier id test
-        if (ota != null && ((Build.IS_DEBUGGABLE && SystemProperties.getBoolean(
+        if (ota != null && ((TelephonyUtils.IS_DEBUGGABLE && SystemProperties.getBoolean(
                 "persist.telephony.test.carrierid.ota", false))
                 || (ota.version > version))) {
             carrierList = ota;
diff --git a/src/com/android/providers/telephony/CellBroadcastProvider.java b/src/com/android/providers/telephony/CellBroadcastProvider.java
deleted file mode 100644
index 3c200bd..0000000
--- a/src/com/android/providers/telephony/CellBroadcastProvider.java
+++ /dev/null
@@ -1,381 +0,0 @@
-/*
- * Copyright (C) 2019 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.app.AppOpsManager;
-import android.content.ContentProvider;
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.UriMatcher;
-import android.content.pm.PackageManager;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.database.sqlite.SQLiteQueryBuilder;
-import android.net.Uri;
-import android.os.Binder;
-import android.os.Process;
-import android.provider.Telephony;
-import android.provider.Telephony.CellBroadcasts;
-import android.text.TextUtils;
-import android.util.Log;
-
-import com.android.internal.annotations.VisibleForTesting;
-
-import java.util.Arrays;
-
-/**
- * The content provider that provides access of cell broadcast message to application.
- * Permission {@link android.permission.READ_CELL_BROADCASTS} is required for querying the cell
- * broadcast message. Only phone process has the permission to write/update the database via this
- * provider.
- */
-public class CellBroadcastProvider extends ContentProvider {
-    /** Interface for read/write permission check. */
-    public interface PermissionChecker {
-        /** Return {@code True} if the caller has the permission to write/update the database. */
-        boolean hasWritePermission();
-
-        /** Return {@code True} if the caller has the permission to query the complete database. */
-        boolean hasReadPermission();
-
-        /**
-         * Return {@code True} if the caller has the permission to query the database for
-         * cell broadcast message history.
-         */
-        boolean hasReadPermissionForHistory();
-    }
-
-    private static final String TAG = CellBroadcastProvider.class.getSimpleName();
-
-    private static final boolean DBG = Log.isLoggable(TAG, Log.DEBUG);
-
-    /** Database name. */
-    private static final String DATABASE_NAME = "cellbroadcasts.db";
-
-    /** Database version. */
-    private static final int DATABASE_VERSION = 2;
-
-    /** URI matcher for ContentProvider queries. */
-    private static final UriMatcher sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
-
-    /** URI matcher type to get all cell broadcasts. */
-    private static final int ALL = 0;
-
-    /**
-     * URI matcher type for get all message history, this is used primarily for default
-     * cellbroadcast app or messaging app to display message history. some information is not
-     * exposed for messaging history, e.g, messages which are out of broadcast geometrics will not
-     * be delivered to end users thus will not be returned as message history query result.
-     */
-    private static final int MESSAGE_HISTORY = 1;
-
-    /** MIME type for the list of all cell broadcasts. */
-    private static final String LIST_TYPE = "vnd.android.cursor.dir/cellbroadcast";
-
-    /** Table name of cell broadcast message. */
-    @VisibleForTesting
-    public static final String CELL_BROADCASTS_TABLE_NAME = "cell_broadcasts";
-
-    /** Authority string for content URIs. */
-    @VisibleForTesting
-    public static final String AUTHORITY = "cellbroadcasts";
-
-    /** Content uri of this provider. */
-    public static final Uri CONTENT_URI = Uri.parse("content://cellbroadcasts");
-
-    @VisibleForTesting
-    public PermissionChecker mPermissionChecker;
-
-    /** The database helper for this content provider. */
-    @VisibleForTesting
-    public SQLiteOpenHelper mDbHelper;
-
-    static {
-        sUriMatcher.addURI(AUTHORITY, null, ALL);
-        sUriMatcher.addURI(AUTHORITY, "history", MESSAGE_HISTORY);
-    }
-
-    public CellBroadcastProvider() {}
-
-    @VisibleForTesting
-    public CellBroadcastProvider(PermissionChecker permissionChecker) {
-        mPermissionChecker = permissionChecker;
-    }
-
-    @Override
-    public boolean onCreate() {
-        mDbHelper = new CellBroadcastDatabaseHelper(getContext());
-        mPermissionChecker = new CellBroadcastPermissionChecker();
-        setAppOps(AppOpsManager.OP_READ_CELL_BROADCASTS, AppOpsManager.OP_NONE);
-        return true;
-    }
-
-    /**
-     * Return the MIME type of the data at the specified URI.
-     *
-     * @param uri the URI to query.
-     * @return a MIME type string, or null if there is no type.
-     */
-    @Override
-    public String getType(Uri uri) {
-        int match = sUriMatcher.match(uri);
-        switch (match) {
-            case ALL:
-                return LIST_TYPE;
-            default:
-                return null;
-        }
-    }
-
-    @Override
-    public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
-            String sortOrder) {
-        checkReadPermission(uri);
-
-        if (DBG) {
-            Log.d(TAG, "query:"
-                    + " uri = " + uri
-                    + " projection = " + Arrays.toString(projection)
-                    + " selection = " + selection
-                    + " selectionArgs = " + Arrays.toString(selectionArgs)
-                    + " sortOrder = " + sortOrder);
-        }
-        SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
-        qb.setStrict(true); // a little protection from injection attacks
-        qb.setTables(CELL_BROADCASTS_TABLE_NAME);
-
-        String orderBy;
-        if (!TextUtils.isEmpty(sortOrder)) {
-            orderBy = sortOrder;
-        } else {
-            orderBy = CellBroadcasts.RECEIVED_TIME + " DESC";
-        }
-
-        int match = sUriMatcher.match(uri);
-        switch (match) {
-            case ALL:
-                return getReadableDatabase().query(
-                        CELL_BROADCASTS_TABLE_NAME, projection, selection, selectionArgs,
-                        null /* groupBy */, null /* having */, orderBy);
-            case MESSAGE_HISTORY:
-                // limit projections to certain columns. limit result to broadcasted messages only.
-                qb.appendWhere(CellBroadcasts.MESSAGE_BROADCASTED  + "=1");
-                return qb.query(getReadableDatabase(), projection, selection, selectionArgs, null,
-                        null, orderBy);
-            default:
-                throw new IllegalArgumentException(
-                        "Query method doesn't support this uri = " + uri);
-        }
-    }
-
-    @Override
-    public Uri insert(Uri uri, ContentValues values) {
-        checkWritePermission();
-
-        if (DBG) {
-            Log.d(TAG, "insert:"
-                    + " uri = " + uri
-                    + " contentValue = " + values);
-        }
-
-        switch (sUriMatcher.match(uri)) {
-            case ALL:
-                long row = getWritableDatabase().insertOrThrow(CELL_BROADCASTS_TABLE_NAME, null,
-                        values);
-                if (row > 0) {
-                    Uri newUri = ContentUris.withAppendedId(CONTENT_URI, row);
-                    getContext().getContentResolver()
-                            .notifyChange(CONTENT_URI, null /* observer */);
-                    return newUri;
-                } else {
-                    Log.e(TAG, "Insert record failed because of unknown reason, uri = " + uri);
-                    return null;
-                }
-            default:
-                throw new IllegalArgumentException(
-                        "Insert method doesn't support this uri = " + uri);
-        }
-    }
-
-    @Override
-    public int delete(Uri uri, String selection, String[] selectionArgs) {
-        checkWritePermission();
-
-        if (DBG) {
-            Log.d(TAG, "delete:"
-                    + " uri = " + uri
-                    + " selection = " + selection
-                    + " selectionArgs = " + Arrays.toString(selectionArgs));
-        }
-
-        switch (sUriMatcher.match(uri)) {
-            case ALL:
-                return getWritableDatabase().delete(CELL_BROADCASTS_TABLE_NAME,
-                        selection, selectionArgs);
-            default:
-                throw new IllegalArgumentException(
-                        "Delete method doesn't support this uri = " + uri);
-        }
-    }
-
-    @Override
-    public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
-        checkWritePermission();
-
-        if (DBG) {
-            Log.d(TAG, "update:"
-                    + " uri = " + uri
-                    + " values = {" + values + "}"
-                    + " selection = " + selection
-                    + " selectionArgs = " + Arrays.toString(selectionArgs));
-        }
-
-        switch (sUriMatcher.match(uri)) {
-            case ALL:
-                int rowCount = getWritableDatabase().update(
-                        CELL_BROADCASTS_TABLE_NAME,
-                        values,
-                        selection,
-                        selectionArgs);
-                if (rowCount > 0) {
-                    getContext().getContentResolver().notifyChange(uri, null /* observer */);
-                }
-                return rowCount;
-            default:
-                throw new IllegalArgumentException(
-                        "Update method doesn't support this uri = " + uri);
-        }
-    }
-
-    @VisibleForTesting
-    public static String getStringForCellBroadcastTableCreation(String tableName) {
-        return "CREATE TABLE " + tableName + " ("
-                + CellBroadcasts._ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
-                + CellBroadcasts.SUB_ID + " INTEGER,"
-                + CellBroadcasts.SLOT_INDEX + " INTEGER DEFAULT 0,"
-                + CellBroadcasts.GEOGRAPHICAL_SCOPE + " INTEGER,"
-                + CellBroadcasts.PLMN + " TEXT,"
-                + CellBroadcasts.LAC + " INTEGER,"
-                + CellBroadcasts.CID + " INTEGER,"
-                + CellBroadcasts.SERIAL_NUMBER + " INTEGER,"
-                + CellBroadcasts.SERVICE_CATEGORY + " INTEGER,"
-                + CellBroadcasts.LANGUAGE_CODE + " TEXT,"
-                + CellBroadcasts.MESSAGE_BODY + " TEXT,"
-                + CellBroadcasts.MESSAGE_FORMAT + " INTEGER,"
-                + CellBroadcasts.MESSAGE_PRIORITY + " INTEGER,"
-                + CellBroadcasts.ETWS_WARNING_TYPE + " INTEGER,"
-                + CellBroadcasts.CMAS_MESSAGE_CLASS + " INTEGER,"
-                + CellBroadcasts.CMAS_CATEGORY + " INTEGER,"
-                + CellBroadcasts.CMAS_RESPONSE_TYPE + " INTEGER,"
-                + CellBroadcasts.CMAS_SEVERITY + " INTEGER,"
-                + CellBroadcasts.CMAS_URGENCY + " INTEGER,"
-                + CellBroadcasts.CMAS_CERTAINTY + " INTEGER,"
-                + CellBroadcasts.RECEIVED_TIME + " BIGINT,"
-                + CellBroadcasts.MESSAGE_BROADCASTED + " BOOLEAN DEFAULT 0,"
-                + CellBroadcasts.GEOMETRIES + " TEXT,"
-                + CellBroadcasts.MAXIMUM_WAIT_TIME + " INTEGER);";
-    }
-
-    private SQLiteDatabase getWritableDatabase() {
-        return mDbHelper.getWritableDatabase();
-    }
-
-    private SQLiteDatabase getReadableDatabase() {
-        return mDbHelper.getReadableDatabase();
-    }
-
-    private void checkWritePermission() {
-        if (!mPermissionChecker.hasWritePermission()) {
-            throw new SecurityException(
-                    "No permission to write CellBroadcast provider");
-        }
-    }
-
-    private void checkReadPermission(Uri uri) {
-        int match = sUriMatcher.match(uri);
-        switch (match) {
-            case ALL:
-                if (!mPermissionChecker.hasReadPermission()) {
-                    throw new SecurityException(
-                            "No permission to read CellBroadcast provider");
-                }
-                break;
-            case MESSAGE_HISTORY:
-                // TODO: if we plan to allow apps to query db in framework, we should migrate data
-                // first before deprecating app's database. otherwise users will lose all history.
-                if (!mPermissionChecker.hasReadPermissionForHistory()) {
-                    throw new SecurityException(
-                            "No permission to read CellBroadcast provider for message history");
-                }
-            default:
-                return;
-        }
-    }
-
-    private class CellBroadcastDatabaseHelper extends SQLiteOpenHelper {
-        CellBroadcastDatabaseHelper(Context context) {
-            super(context, DATABASE_NAME, null /* factory */, DATABASE_VERSION);
-        }
-
-        @Override
-        public void onCreate(SQLiteDatabase db) {
-            db.execSQL(getStringForCellBroadcastTableCreation(CELL_BROADCASTS_TABLE_NAME));
-        }
-
-        @Override
-        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
-            if (DBG) {
-                Log.d(TAG, "onUpgrade: oldV=" + oldVersion + " newV=" + newVersion);
-            }
-            if (newVersion == 2) {
-                db.execSQL("ALTER TABLE " + CELL_BROADCASTS_TABLE_NAME + " ADD COLUMN "
-                        + CellBroadcasts.SLOT_INDEX + " INTEGER DEFAULT 0;");
-                Log.d(TAG, "add slotIndex column");
-            }
-        }
-    }
-
-    private class CellBroadcastPermissionChecker implements PermissionChecker {
-        @Override
-        public boolean hasWritePermission() {
-            // Only the phone and network statck process has the write permission to modify this
-            // provider.
-            return Binder.getCallingUid() == Process.PHONE_UID
-                    || Binder.getCallingUid() == Process.NETWORK_STACK_UID;
-        }
-
-        @Override
-        public boolean hasReadPermission() {
-            // Only the phone and network stack process has the read permission to query data from
-            // this provider.
-            return Binder.getCallingUid() == Process.PHONE_UID
-                    || Binder.getCallingUid() == Process.NETWORK_STACK_UID;
-        }
-
-        @Override
-        public boolean hasReadPermissionForHistory() {
-            int status = getContext().checkCallingOrSelfPermission(
-                    "android.permission.RECEIVE_EMERGENCY_BROADCAST");
-            if (status == PackageManager.PERMISSION_GRANTED) {
-                return true;
-            }
-            return false;
-        }
-    }
-}
diff --git a/src/com/android/providers/telephony/MmsProvider.java b/src/com/android/providers/telephony/MmsProvider.java
index 30158c3..96059d7 100644
--- a/src/com/android/providers/telephony/MmsProvider.java
+++ b/src/com/android/providers/telephony/MmsProvider.java
@@ -31,7 +31,6 @@
 import android.database.sqlite.SQLiteQueryBuilder;
 import android.net.Uri;
 import android.os.Binder;
-import android.os.FileUtils;
 import android.os.ParcelFileDescriptor;
 import android.os.UserHandle;
 import android.provider.BaseColumns;
@@ -44,6 +43,8 @@
 import android.provider.Telephony.Mms.Rate;
 import android.provider.Telephony.MmsSms;
 import android.provider.Telephony.Threads;
+import android.system.ErrnoException;
+import android.system.Os;
 import android.text.TextUtils;
 import android.util.Log;
 
@@ -518,9 +519,13 @@
                         // Give everyone rw permission until we encrypt the file
                         // (in PduPersister.persistData). Once the file is encrypted, the
                         // permissions will be set to 0644.
-                        int result = FileUtils.setPermissions(path, 0666, -1, -1);
-                        if (LOCAL_LOGV) {
-                            Log.d(TAG, "MmsProvider.insert setPermissions result: " + result);
+                        try {
+                            Os.chmod(path, 0666);
+                            if (LOCAL_LOGV) {
+                                Log.d(TAG, "MmsProvider.insert chmod is successful");
+                            }
+                        } catch (ErrnoException e) {
+                            Log.e(TAG, "Exception in chmod: " + e);
                         }
                     } catch (IOException e) {
                         Log.e(TAG, "createNewFile", e);
@@ -816,10 +821,13 @@
                 String path = getContext().getDir(PARTS_DIR_NAME, 0).getPath() + '/' +
                         uri.getPathSegments().get(1);
                 // Reset the file permission back to read for everyone but me.
-                int result = FileUtils.setPermissions(path, 0644, -1, -1);
-                if (LOCAL_LOGV) {
-                    Log.d(TAG, "MmsProvider.update setPermissions result: " + result +
-                            " for path: " + path);
+                try {
+                    Os.chmod(path, 0644);
+                    if (LOCAL_LOGV) {
+                        Log.d(TAG, "MmsProvider.update chmod is successful for path: " + path);
+                    }
+                } catch (ErrnoException e) {
+                    Log.e(TAG, "Exception in chmod: " + e);
                 }
                 return 0;
 
diff --git a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
index 4add85d..034efaa 100644
--- a/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
+++ b/src/com/android/providers/telephony/MmsSmsDatabaseHelper.java
@@ -47,7 +47,6 @@
 import android.provider.Telephony.Threads;
 import android.telephony.SubscriptionManager;
 import android.util.Log;
-import android.util.Slog;
 
 import com.android.internal.annotations.VisibleForTesting;
 import com.android.internal.telephony.PhoneFactory;
@@ -267,7 +266,7 @@
 
     /**
      * The primary purpose of this DatabaseErrorHandler is to broadcast an intent on corruption and
-     * print a Slog.wtf so database corruption can be caught earlier.
+     * print a Log.wtf so database corruption can be caught earlier.
      */
     private static class MmsSmsDatabaseErrorHandler implements DatabaseErrorHandler {
         private DefaultDatabaseErrorHandler mDefaultDatabaseErrorHandler
@@ -571,7 +570,7 @@
     }
 
     private static void localLogWtf(String logMsg) {
-        Slog.wtf(TAG, logMsg);
+        Log.wtf(TAG, logMsg);
         PhoneFactory.localLog(TAG, logMsg);
     }
 
diff --git a/src/com/android/providers/telephony/TelephonyBackupAgent.java b/src/com/android/providers/telephony/TelephonyBackupAgent.java
index 437b5a2..dcf98c7 100644
--- a/src/com/android/providers/telephony/TelephonyBackupAgent.java
+++ b/src/com/android/providers/telephony/TelephonyBackupAgent.java
@@ -531,9 +531,7 @@
 
                 for (File file : files) {
                     final String fileName = file.getName();
-                    if (DEBUG) {
-                        Log.d(TAG, "onHandleIntent restoring file " + fileName);
-                    }
+                    Log.d(TAG, "onHandleIntent restoring file " + fileName);
                     try (FileInputStream fileInputStream = new FileInputStream(file)) {
                         mTelephonyBackupAgent.doRestoreFile(fileName, fileInputStream.getFD());
                         didRestore = true;
@@ -547,9 +545,7 @@
                 if (didRestore) {
                   // Tell the default sms app to do a full sync now that the messages have been
                   // restored.
-                  if (DEBUG) {
-                    Log.d(TAG, "onHandleIntent done - notifying default sms app");
-                  }
+                  Log.d(TAG, "onHandleIntent done - notifying default sms app");
                   ProviderUtil.notifyIfNotDefaultSmsApp(null /*uri*/, null /*calling package*/,
                       this);
                 }
@@ -605,25 +601,17 @@
     }
 
     private void doRestoreFile(String fileName, FileDescriptor fd) throws IOException {
-        if (DEBUG) {
-            Log.d(TAG, "Restoring file " + fileName);
-        }
+        Log.d(TAG, "Restoring file " + fileName);
 
         try (JsonReader jsonReader = getJsonReader(fd)) {
             if (fileName.endsWith(SMS_BACKUP_FILE_SUFFIX)) {
-                if (DEBUG) {
-                    Log.d(TAG, "Restoring SMS");
-                }
+                Log.d(TAG, "Restoring SMS");
                 putSmsMessagesToProvider(jsonReader);
             } else if (fileName.endsWith(MMS_BACKUP_FILE_SUFFIX)) {
-                if (DEBUG) {
-                    Log.d(TAG, "Restoring text MMS");
-                }
+                Log.d(TAG, "Restoring text MMS");
                 putMmsMessagesToProvider(jsonReader);
             } else {
-                if (DEBUG) {
-                    Log.e(TAG, "Unknown file to restore:" + fileName);
-                }
+                Log.e(TAG, "Unknown file to restore:" + fileName);
             }
         }
     }
@@ -654,6 +642,7 @@
     @VisibleForTesting
     void putMmsMessagesToProvider(JsonReader jsonReader) throws IOException {
         jsonReader.beginArray();
+        int total = 0;
         while (jsonReader.hasNext()) {
             final Mms mms = readMmsFromReader(jsonReader);
             if (DEBUG) {
@@ -662,11 +651,15 @@
             if (doesMmsExist(mms)) {
                 if (DEBUG) {
                     Log.e(TAG, String.format("Mms: %s already exists", mms.toString()));
+                } else {
+                    Log.w(TAG, "Mms: Found duplicate MMS");
                 }
                 continue;
             }
+            total++;
             addMmsMessage(mms);
         }
+        Log.d(TAG, "putMmsMessagesToProvider handled " + total + " new messages.");
     }
 
     @VisibleForTesting
@@ -823,6 +816,8 @@
                 default:
                     if (DEBUG) {
                         Log.w(TAG, "readSmsValuesFromReader Unknown name:" + name);
+                    } else {
+                        Log.w(TAG, "readSmsValuesFromReader encountered unknown name.");
                     }
                     jsonReader.skipValue();
                     break;
@@ -955,9 +950,7 @@
                     mms.values.put(name, jsonReader.nextString());
                     break;
                 default:
-                    if (DEBUG) {
-                        Log.d(TAG, "Unknown name:" + name);
-                    }
+                    Log.d(TAG, "Unknown JSON element name:" + name);
                     jsonReader.skipValue();
                     break;
             }
@@ -995,9 +988,7 @@
                 values,
                 ARCHIVE_THREAD_SELECTION,
                 new String[] { Long.toString(threadId)}) != 1) {
-            if (DEBUG) {
-                Log.e(TAG, "archiveThread: failed to update database");
-            }
+            Log.e(TAG, "archiveThread: failed to update database");
         }
     }
 
@@ -1066,9 +1057,7 @@
                         addrValues.put(name, jsonReader.nextString());
                         break;
                     default:
-                        if (DEBUG) {
-                            Log.d(TAG, "Unknown name:" + name);
-                        }
+                        Log.d(TAG, "Unknown JSON Element name:" + name);
                         jsonReader.skipValue();
                         break;
                 }
@@ -1099,9 +1088,7 @@
                         attachmentValues.put(name, jsonReader.nextString());
                         break;
                     default:
-                        if (DEBUG) {
-                            Log.d(TAG, "getMmsAttachmentsFromReader Unknown name:" + name);
-                        }
+                        Log.d(TAG, "getMmsAttachmentsFromReader Unknown name:" + name);
                         jsonReader.skipValue();
                         break;
                 }
@@ -1110,9 +1097,7 @@
             if (attachmentValues.containsKey(MMS_ATTACHMENT_FILENAME)) {
                 mms.attachments.add(attachmentValues);
             } else {
-                if (DEBUG) {
-                    Log.d(TAG, "Attachment json with no filenames");
-                }
+                Log.d(TAG, "Attachment json with no filenames");
             }
         }
         jsonReader.endArray();
@@ -1140,9 +1125,7 @@
             values.put(Telephony.Mms.Part.CONTENT_LOCATION, "smil.xml");
             values.put(Telephony.Mms.Part.TEXT, smil);
             if (mContentResolver.insert(partUri, values) == null) {
-                if (DEBUG) {
-                    Log.e(TAG, "Could not insert SMIL part");
-                }
+                Log.e(TAG, "Could not insert SMIL part");
                 return;
             }
         }
@@ -1162,9 +1145,7 @@
             values.put(Telephony.Mms.Part.TEXT, mms.body == null ? "" : mms.body.text);
 
             if (mContentResolver.insert(partUri, values) == null) {
-                if (DEBUG) {
-                    Log.e(TAG, "Could not insert body part");
-                }
+                Log.e(TAG, "Could not insert body part");
                 return;
             }
         }
@@ -1184,9 +1165,7 @@
                         getDataDir() + ATTACHMENT_DATA_PATH + filename);
                 Uri newPartUri = mContentResolver.insert(partUri, values);
                 if (newPartUri == null) {
-                    if (DEBUG) {
-                        Log.e(TAG, "Could not insert attachment part");
-                    }
+                    Log.e(TAG, "Could not insert attachment part");
                     return;
                 }
             }
@@ -1195,9 +1174,7 @@
         // Insert mms.
         final Uri mmsUri = mContentResolver.insert(Telephony.Mms.CONTENT_URI, mms.values);
         if (mmsUri == null) {
-            if (DEBUG) {
-                Log.e(TAG, "Could not insert mms");
-            }
+            Log.e(TAG, "Could not insert mms");
             return;
         }
 
@@ -1301,9 +1278,7 @@
             try {
                 threadId = Telephony.Threads.getOrCreateThreadId(this, recipients);
             } catch (RuntimeException e) {
-                if (DEBUG) {
-                    Log.e(TAG, e.toString());
-                }
+                Log.e(TAG, "Problem obtaining thread.", e);
             }
             mCacheGetOrCreateThreadId.put(recipients, threadId);
             return threadId;
@@ -1377,15 +1352,11 @@
             try {
                 longId = Long.parseLong(id);
                 if (longId < 0) {
-                    if (DEBUG) {
-                        Log.e(TAG, "getAddresses: invalid id " + longId);
-                    }
+                    Log.e(TAG, "getAddresses: invalid id " + longId);
                     continue;
                 }
             } catch (final NumberFormatException ex) {
-                if (DEBUG) {
-                    Log.e(TAG, "getAddresses: invalid id. " + ex, ex);
-                }
+                Log.e(TAG, "getAddresses: invalid id " + ex, ex);
                 // skip this id
                 continue;
             }
@@ -1397,10 +1368,9 @@
                         ContentUris.withAppendedId(SINGLE_CANONICAL_ADDRESS_URI, longId),
                         null, null, null, null);
             } catch (final Exception e) {
-                if (DEBUG) {
-                    Log.e(TAG, "getAddresses: query failed for id " + longId, e);
-                }
+                Log.e(TAG, "getAddresses: query failed for id " + longId, e);
             }
+
             if (c != null) {
                 try {
                     if (c.moveToFirst()) {
@@ -1408,9 +1378,7 @@
                         if (!TextUtils.isEmpty(number)) {
                             numbers.add(number);
                         } else {
-                            if (DEBUG) {
-                                Log.d(TAG, "Canonical MMS/SMS address is empty for id: " + longId);
-                            }
+                            Log.d(TAG, "Canonical MMS/SMS address is empty for id: " + longId);
                         }
                     }
                 } finally {
@@ -1419,9 +1387,7 @@
             }
         }
         if (numbers.isEmpty()) {
-            if (DEBUG) {
-                Log.d(TAG, "No MMS addresses found from ids string [" + spaceSepIds + "]");
-            }
+            Log.d(TAG, "No MMS addresses found from ids string [" + spaceSepIds + "]");
         }
         return numbers;
     }
diff --git a/src/com/android/providers/telephony/TelephonyProvider.java b/src/com/android/providers/telephony/TelephonyProvider.java
index 0edbffc..359ff50 100644
--- a/src/com/android/providers/telephony/TelephonyProvider.java
+++ b/src/com/android/providers/telephony/TelephonyProvider.java
@@ -93,7 +93,6 @@
 import android.net.Uri;
 import android.os.Binder;
 import android.os.Environment;
-import android.os.FileUtils;
 import android.os.IBinder;
 import android.os.Process;
 import android.os.RemoteException;
@@ -101,7 +100,6 @@
 import android.os.UserHandle;
 import android.provider.Telephony;
 import android.telephony.ServiceState;
-import android.telephony.SubscriptionInfo;
 import android.telephony.SubscriptionManager;
 import android.telephony.TelephonyManager;
 import android.telephony.data.ApnSetting;
@@ -112,19 +110,20 @@
 
 import com.android.internal.annotations.GuardedBy;
 import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.telephony.IApnSourceService;
 import com.android.internal.telephony.PhoneConstants;
 import com.android.internal.telephony.PhoneFactory;
 import com.android.internal.telephony.dataconnection.ApnSettingUtils;
 import com.android.internal.telephony.uicc.IccRecords;
 import com.android.internal.telephony.uicc.UiccController;
 import com.android.internal.util.XmlUtils;
+import android.service.carrier.IApnSourceService;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileReader;
 import java.io.IOException;
@@ -137,6 +136,7 @@
 import java.util.Locale;
 import java.util.Map;
 import java.util.Set;
+import java.util.zip.CheckedInputStream;
 import java.util.zip.CRC32;
 
 public class TelephonyProvider extends ContentProvider
@@ -584,10 +584,18 @@
         }
 
         private long getChecksum(File file) {
-            long checksum = -1;
-            try {
-                checksum = FileUtils.checksumCrc32(file);
-                if (DBG) log("Checksum for " + file.getAbsolutePath() + " is " + checksum);
+            CRC32 checkSummer = new CRC32();
+            long checkSum = -1;
+            try (CheckedInputStream cis =
+                new CheckedInputStream(new FileInputStream(file), checkSummer)){
+                byte[] buf = new byte[128];
+                if(cis != null) {
+                    while(cis.read(buf) >= 0) {
+                        // Just read for checksum to get calculated.
+                    }
+                }
+                checkSum = checkSummer.getValue();
+                if (DBG) log("Checksum for " + file.getAbsolutePath() + " is " + checkSum);
             } catch (FileNotFoundException e) {
                 loge("FileNotFoundException for " + file.getAbsolutePath() + ":" + e);
             } catch (IOException e) {
@@ -599,14 +607,14 @@
             try (InputStream inputStream = mContext.getResources().
                         openRawResource(com.android.internal.R.xml.apns)) {
                 byte[] array = toByteArray(inputStream);
-                CRC32 c = new CRC32();
-                c.update(array);
-                checksum += c.getValue();
-                if (DBG) log("Checksum after adding resource is " + checksum);
+                checkSummer.reset();
+                checkSummer.update(array);
+                checkSum += checkSummer.getValue();
+                if (DBG) log("Checksum after adding resource is " + checkSummer.getValue());
             } catch (IOException | Resources.NotFoundException e) {
                 loge("Exception when calculating checksum for internal apn resources: " + e);
             }
-            return checksum;
+            return checkSum;
         }
 
         private byte[] toByteArray(InputStream input) throws IOException {
@@ -3779,15 +3787,6 @@
         throw new SecurityException("No permission to write APN settings");
     }
 
-    private void checkPhonePrivilegePermission() {
-        int status = getContext().checkCallingOrSelfPermission(
-                "android.permission.READ_PRIVILEGED_PHONE_STATE");
-        if (status == PackageManager.PERMISSION_GRANTED) {
-            return;
-        }
-        throw new SecurityException("No phone privilege permission");
-    }
-
     private DatabaseHelper mOpenHelper;
 
     private void restoreDefaultAPN(int subId) {
diff --git a/tests/src/com/android/providers/telephony/CellBroadcastProviderTest.java b/tests/src/com/android/providers/telephony/CellBroadcastProviderTest.java
deleted file mode 100644
index bd92643..0000000
--- a/tests/src/com/android/providers/telephony/CellBroadcastProviderTest.java
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * Copyright (C) 2019 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 static com.google.common.truth.Truth.assertThat;
-
-import static org.mockito.Mockito.doReturn;
-
-import junit.framework.TestCase;
-
-import android.content.ContentValues;
-import android.content.pm.PackageManager;
-import android.database.Cursor;
-import android.net.Uri;
-import android.provider.Telephony.CellBroadcasts;
-import android.test.mock.MockContentResolver;
-import android.test.mock.MockContext;
-import android.util.Log;
-
-import com.android.providers.telephony.CellBroadcastProvider.PermissionChecker;
-
-import org.junit.Test;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-
-public class CellBroadcastProviderTest extends TestCase {
-    private static final String TAG = CellBroadcastProviderTest.class.getSimpleName();
-
-    public static final Uri CONTENT_URI = Uri.parse("content://cellbroadcasts");
-
-    private static final int GEO_SCOPE = 1;
-    private static final String PLMN = "123456";
-    private static final int LAC = 13;
-    private static final int CID = 123;
-    private static final int SERIAL_NUMBER = 17984;
-    private static final int SERVICE_CATEGORY = 4379;
-    private static final String LANGUAGE_CODE = "en";
-    private static final String MESSAGE_BODY = "AMBER Alert: xxxx";
-    private static final int MESSAGE_FORMAT = 1;
-    private static final int MESSAGE_PRIORITY = 3;
-    private static final int ETWS_WARNING_TYPE = 1;
-    private static final int CMAS_MESSAGE_CLASS = 1;
-    private static final int CMAS_CATEGORY = 6;
-    private static final int CMAS_RESPONSE_TYPE = 1;
-    private static final int CMAS_SEVERITY = 2;
-    private static final int CMAS_URGENCY = 3;
-    private static final int CMAS_CERTAINTY = 4;
-    private static final int RECEIVED_TIME = 1562792637;
-    private static final int MESSAGE_BROADCASTED = 1;
-    private static final String GEOMETRIES_COORDINATES
-            = "polygon|0,0|0,1|1,1|1,0;circle|0,0|100";
-
-    private static final String SELECT_BY_ID = CellBroadcasts._ID + "=?";
-
-    private static final String[] QUERY_COLUMNS = {
-            CellBroadcasts._ID,
-            CellBroadcasts.GEOGRAPHICAL_SCOPE,
-            CellBroadcasts.PLMN,
-            CellBroadcasts.LAC,
-            CellBroadcasts.CID,
-            CellBroadcasts.SERIAL_NUMBER,
-            CellBroadcasts.SERVICE_CATEGORY,
-            CellBroadcasts.LANGUAGE_CODE,
-            CellBroadcasts.MESSAGE_BODY,
-            CellBroadcasts.MESSAGE_FORMAT,
-            CellBroadcasts.MESSAGE_PRIORITY,
-            CellBroadcasts.ETWS_WARNING_TYPE,
-            CellBroadcasts.CMAS_MESSAGE_CLASS,
-            CellBroadcasts.CMAS_CATEGORY,
-            CellBroadcasts.CMAS_RESPONSE_TYPE,
-            CellBroadcasts.CMAS_SEVERITY,
-            CellBroadcasts.CMAS_URGENCY,
-            CellBroadcasts.CMAS_CERTAINTY,
-            CellBroadcasts.RECEIVED_TIME,
-            CellBroadcasts.MESSAGE_BROADCASTED,
-            CellBroadcasts.GEOMETRIES
-    };
-
-    private CellBroadcastProviderTestable mCellBroadcastProviderTestable;
-    private MockContextWithProvider mContext;
-    private MockContentResolver mContentResolver;
-
-    @Mock
-    private PermissionChecker mMockPermissionChecker;
-
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-        MockitoAnnotations.initMocks(this);
-        doReturn(true).when(mMockPermissionChecker).hasReadPermission();
-        doReturn(true).when(mMockPermissionChecker).hasWritePermission();
-
-        mCellBroadcastProviderTestable = new CellBroadcastProviderTestable(mMockPermissionChecker);
-        mContext = new MockContextWithProvider(mCellBroadcastProviderTestable);
-        mContentResolver = mContext.getContentResolver();
-    }
-
-    @Override
-    protected void tearDown() throws Exception {
-        mCellBroadcastProviderTestable.closeDatabase();
-        super.tearDown();
-    }
-
-    @Test
-    public void testUpdate() {
-        // Insert a cellbroadcast to the database.
-        ContentValues cv = fakeCellBroadcast();
-        Uri uri = mContentResolver.insert(CONTENT_URI, cv);
-        assertThat(uri).isNotNull();
-
-        // Change some fields of this cell broadcast.
-        int messageBroadcasted = 1 - cv.getAsInteger(CellBroadcasts.MESSAGE_BROADCASTED);
-        int receivedTime = 1234555555;
-        cv.put(CellBroadcasts.MESSAGE_BROADCASTED, messageBroadcasted);
-        cv.put(CellBroadcasts.RECEIVED_TIME, receivedTime);
-        mContentResolver.update(CONTENT_URI, cv, SELECT_BY_ID,
-                new String[] { uri.getLastPathSegment() });
-
-        // Query and check if the update is successed.
-        Cursor cursor = mContentResolver.query(CONTENT_URI, QUERY_COLUMNS,
-                SELECT_BY_ID, new String[] { uri.getLastPathSegment() }, null /* orderBy */);
-        cursor.moveToNext();
-
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.RECEIVED_TIME)))
-                .isEqualTo(receivedTime);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.MESSAGE_BROADCASTED)))
-                .isEqualTo(messageBroadcasted);
-        cursor.close();
-    }
-
-    @Test
-    public void testUpdate_WithoutWritePermission_fail() {
-        ContentValues cv = fakeCellBroadcast();
-        Uri uri = mContentResolver.insert(CONTENT_URI, cv);
-        assertThat(uri).isNotNull();
-
-        // Revoke the write permission
-        doReturn(false).when(mMockPermissionChecker).hasWritePermission();
-
-        try {
-            mContentResolver.update(CONTENT_URI, cv, SELECT_BY_ID,
-                    new String[] { uri.getLastPathSegment() });
-            fail();
-        } catch (SecurityException ex) {
-            // pass the test
-        }
-    }
-
-    @Test
-    public void testGetAllCellBroadcast() {
-        // Insert some cell broadcasts which message_broadcasted is false
-        int messageNotBroadcastedCount = 5;
-        ContentValues cv = fakeCellBroadcast();
-        cv.put(CellBroadcasts.MESSAGE_BROADCASTED, 0);
-        for (int i = 0; i < messageNotBroadcastedCount; i++) {
-            mContentResolver.insert(CONTENT_URI, cv);
-        }
-
-        // Insert some cell broadcasts which message_broadcasted is true
-        int messageBroadcastedCount = 6;
-        cv.put(CellBroadcasts.MESSAGE_BROADCASTED, 1);
-        for (int i = 0; i < messageBroadcastedCount; i++) {
-            mContentResolver.insert(CONTENT_URI, cv);
-        }
-
-        // Query the broadcast with message_broadcasted is false
-        Cursor cursor = mContentResolver.query(
-                CONTENT_URI,
-                QUERY_COLUMNS,
-                String.format("%s=?", CellBroadcasts.MESSAGE_BROADCASTED), /* selection */
-                new String[] {"0"}, /* selectionArgs */
-                null /* sortOrder */);
-        assertThat(cursor.getCount()).isEqualTo(messageNotBroadcastedCount);
-    }
-
-    @Test
-    public void testDelete_withoutWritePermission_throwSecurityException() {
-        Uri uri = mContentResolver.insert(CONTENT_URI, fakeCellBroadcast());
-        assertThat(uri).isNotNull();
-
-        // Revoke the write permission
-        doReturn(false).when(mMockPermissionChecker).hasWritePermission();
-
-        try {
-            mContentResolver.delete(CONTENT_URI, SELECT_BY_ID,
-                    new String[] { uri.getLastPathSegment() });
-            fail();
-        } catch (SecurityException ex) {
-            // pass the test
-        }
-    }
-
-
-    @Test
-    public void testDelete_oneRecord_success() {
-        // Insert a cellbroadcast to the database.
-        ContentValues cv = fakeCellBroadcast();
-        Uri uri = mContentResolver.insert(CONTENT_URI, cv);
-        assertThat(uri).isNotNull();
-
-        String[] selectionArgs = new String[] { uri.getLastPathSegment() };
-
-        // Ensure the cell broadcast is inserted.
-        Cursor cursor = mContentResolver.query(CONTENT_URI, QUERY_COLUMNS,
-                SELECT_BY_ID, selectionArgs, null /* orderBy */);
-        assertThat(cursor.getCount()).isEqualTo(1);
-        cursor.close();
-
-        // Delete the cell broadcast
-        int rowCount = mContentResolver.delete(CONTENT_URI, SELECT_BY_ID,
-                selectionArgs);
-        assertThat(rowCount).isEqualTo(1);
-
-        // Ensure the cell broadcast is deleted.
-        cursor = mContentResolver.query(CONTENT_URI, QUERY_COLUMNS, SELECT_BY_ID,
-                selectionArgs, null /* orderBy */);
-        assertThat(cursor.getCount()).isEqualTo(0);
-        cursor.close();
-    }
-
-    @Test
-    public void testDelete_all_success() {
-        // Insert a cellbroadcast to the database.
-        mContentResolver.insert(CONTENT_URI, fakeCellBroadcast());
-        mContentResolver.insert(CONTENT_URI, fakeCellBroadcast());
-
-        // Ensure the cell broadcast are inserted.
-        Cursor cursor = mContentResolver.query(CONTENT_URI, QUERY_COLUMNS,
-                null /* selection */, null /* selectionArgs */, null /* orderBy */);
-        assertThat(cursor.getCount()).isEqualTo(2);
-        cursor.close();
-
-        // Delete all cell broadcasts.
-        int rowCount = mContentResolver.delete(
-                CONTENT_URI, null /* selection */, null /* selectionArgs */);
-        assertThat(rowCount).isEqualTo(2);
-        cursor.close();
-
-        // Ensure all cell broadcasts are deleted.
-        cursor = mContentResolver.query(CONTENT_URI, QUERY_COLUMNS,
-                null /* selection */, null /* selectionArgs */, null /* orderBy */);
-        assertThat(cursor.getCount()).isEqualTo(0);
-        cursor.close();
-    }
-
-    @Test
-    public void testInsert_withoutWritePermission_fail() {
-        doReturn(false).when(mMockPermissionChecker).hasWritePermission();
-
-        try {
-            mContentResolver.insert(CONTENT_URI, fakeCellBroadcast());
-            fail();
-        } catch (SecurityException ex) {
-            // pass the test
-        }
-    }
-
-    @Test
-    public void testInsertAndQuery() {
-        // Insert a cell broadcast message
-        Uri uri = mContentResolver.insert(CONTENT_URI, fakeCellBroadcast());
-
-        // Verify that the return uri is not null and the record is inserted into the database
-        // correctly.
-        assertThat(uri).isNotNull();
-        Cursor cursor = mContentResolver.query(
-                CONTENT_URI, QUERY_COLUMNS, SELECT_BY_ID,
-                new String[] { uri.getLastPathSegment() }, null /* orderBy */);
-        assertThat(cursor.getCount()).isEqualTo(1);
-
-        cursor.moveToNext();
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.GEOGRAPHICAL_SCOPE)))
-                .isEqualTo(GEO_SCOPE);
-        assertThat(cursor.getString(cursor.getColumnIndexOrThrow(CellBroadcasts.PLMN)))
-                .isEqualTo(PLMN);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.LAC))).isEqualTo(LAC);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.CID))).isEqualTo(CID);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.SERIAL_NUMBER)))
-                .isEqualTo(SERIAL_NUMBER);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.SERVICE_CATEGORY)))
-                .isEqualTo(SERVICE_CATEGORY);
-        assertThat(cursor.getString(cursor.getColumnIndexOrThrow(CellBroadcasts.LANGUAGE_CODE)))
-                .isEqualTo(LANGUAGE_CODE);
-        assertThat(cursor.getString(cursor.getColumnIndexOrThrow(CellBroadcasts.MESSAGE_BODY)))
-                .isEqualTo(MESSAGE_BODY);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.MESSAGE_FORMAT)))
-                .isEqualTo(MESSAGE_FORMAT);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.MESSAGE_PRIORITY)))
-                .isEqualTo(MESSAGE_PRIORITY);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.ETWS_WARNING_TYPE)))
-                .isEqualTo(ETWS_WARNING_TYPE);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.CMAS_MESSAGE_CLASS)))
-                .isEqualTo(CMAS_MESSAGE_CLASS);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.CMAS_CATEGORY)))
-                .isEqualTo(CMAS_CATEGORY);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.CMAS_RESPONSE_TYPE)))
-                .isEqualTo(CMAS_RESPONSE_TYPE);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.CMAS_SEVERITY)))
-                .isEqualTo(CMAS_SEVERITY);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.CMAS_URGENCY)))
-                .isEqualTo(CMAS_URGENCY);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.CMAS_CERTAINTY)))
-                .isEqualTo(CMAS_CERTAINTY);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.RECEIVED_TIME)))
-                .isEqualTo(RECEIVED_TIME);
-        assertThat(cursor.getInt(cursor.getColumnIndexOrThrow(CellBroadcasts.MESSAGE_BROADCASTED)))
-                .isEqualTo(MESSAGE_BROADCASTED);
-        assertThat(cursor.getString(cursor.getColumnIndexOrThrow(
-                CellBroadcasts.GEOMETRIES))).isEqualTo(GEOMETRIES_COORDINATES);
-    }
-
-    /**
-     * This is used to give the CellBroadcastProviderTest a mocked context which takes a
-     * CellBroadcastProvider and attaches it to the ContentResolver.
-     */
-    private class MockContextWithProvider extends MockContext {
-        private final MockContentResolver mResolver;
-
-        public MockContextWithProvider(CellBroadcastProviderTestable cellBroadcastProvider) {
-            mResolver = new MockContentResolver();
-            cellBroadcastProvider.initializeForTesting(this);
-
-            // Add given cellBroadcastProvider to mResolver, so that mResolver can send queries
-            // to the provider.
-            mResolver.addProvider(CellBroadcastProvider.AUTHORITY, cellBroadcastProvider);
-        }
-
-        @Override
-        public MockContentResolver getContentResolver() {
-            return mResolver;
-        }
-
-
-        @Override
-        public Object getSystemService(String name) {
-            Log.d(TAG, "getSystemService: returning null");
-            return null;
-        }
-
-        @Override
-        public int checkCallingOrSelfPermission(String permission) {
-            return PackageManager.PERMISSION_GRANTED;
-        }
-    }
-
-    private static ContentValues fakeCellBroadcast() {
-        ContentValues cv = new ContentValues();
-        cv.put(CellBroadcasts.GEOGRAPHICAL_SCOPE, GEO_SCOPE);
-        cv.put(CellBroadcasts.PLMN, PLMN);
-        cv.put(CellBroadcasts.LAC, LAC);
-        cv.put(CellBroadcasts.CID, CID);
-        cv.put(CellBroadcasts.SERIAL_NUMBER, SERIAL_NUMBER);
-        cv.put(CellBroadcasts.SERVICE_CATEGORY, SERVICE_CATEGORY);
-        cv.put(CellBroadcasts.LANGUAGE_CODE, LANGUAGE_CODE);
-        cv.put(CellBroadcasts.MESSAGE_BODY, MESSAGE_BODY);
-        cv.put(CellBroadcasts.MESSAGE_FORMAT, MESSAGE_FORMAT);
-        cv.put(CellBroadcasts.MESSAGE_PRIORITY, MESSAGE_PRIORITY);
-        cv.put(CellBroadcasts.ETWS_WARNING_TYPE, ETWS_WARNING_TYPE);
-        cv.put(CellBroadcasts.CMAS_MESSAGE_CLASS, CMAS_MESSAGE_CLASS);
-        cv.put(CellBroadcasts.CMAS_CATEGORY, CMAS_CATEGORY);
-        cv.put(CellBroadcasts.CMAS_RESPONSE_TYPE, CMAS_RESPONSE_TYPE);
-        cv.put(CellBroadcasts.CMAS_SEVERITY, CMAS_SEVERITY);
-        cv.put(CellBroadcasts.CMAS_URGENCY, CMAS_URGENCY);
-        cv.put(CellBroadcasts.CMAS_CERTAINTY, CMAS_CERTAINTY);
-        cv.put(CellBroadcasts.RECEIVED_TIME, RECEIVED_TIME);
-        cv.put(CellBroadcasts.MESSAGE_BROADCASTED, MESSAGE_BROADCASTED);
-        cv.put(CellBroadcasts.GEOMETRIES, GEOMETRIES_COORDINATES);
-        return cv;
-    }
-}
diff --git a/tests/src/com/android/providers/telephony/CellBroadcastProviderTestable.java b/tests/src/com/android/providers/telephony/CellBroadcastProviderTestable.java
deleted file mode 100644
index 8334312..0000000
--- a/tests/src/com/android/providers/telephony/CellBroadcastProviderTestable.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Copyright (C) 2019 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.content.pm.ProviderInfo;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.util.Log;
-
-import androidx.test.InstrumentationRegistry;
-
-public class CellBroadcastProviderTestable extends CellBroadcastProvider {
-    private static final String TAG = CellBroadcastProviderTestable.class.getSimpleName();
-
-    public CellBroadcastProviderTestable(PermissionChecker permissionChecker) {
-        super(permissionChecker);
-    }
-
-    @Override
-    public boolean onCreate() {
-        // DO NOT call super.onCreate(), otherwise the permission checker will be override.
-        Log.d(TAG, "CellBroadcastProviderTestable onCreate");
-        mDbHelper = new InMemoryCellBroadcastProviderDbHelper();
-        return true;
-    }
-
-    public void closeDatabase() {
-        mDbHelper.close();
-    }
-
-    public static class InMemoryCellBroadcastProviderDbHelper extends SQLiteOpenHelper {
-        public InMemoryCellBroadcastProviderDbHelper() {
-            super(InstrumentationRegistry.getTargetContext(),
-                    null,    // db file name is null for in-memory db
-                    null,    // CursorFactory is null by default
-                    1);      // db version is no-op for tests
-        }
-
-        @Override
-        public void onCreate(SQLiteDatabase db) {
-            Log.d(TAG, "IN MEMORY DB CREATED");
-            db.execSQL(getStringForCellBroadcastTableCreation(CELL_BROADCASTS_TABLE_NAME));
-        }
-
-        @Override
-        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}
-    }
-
-    public void initializeForTesting(Context context) {
-        ProviderInfo providerInfo = new ProviderInfo();
-        providerInfo.authority = CellBroadcastProvider.AUTHORITY;
-
-        // Add context to given carrierIdProvider
-        attachInfoForTesting(context, providerInfo);
-    }
-}