Move tests to .test package

This will be used for excluding the tests in coverage configs. Also in
general tests should probably be a different package than the apk they
test.

Bug: 135956699
Test: atest CellBroadcastServiceTests
Change-Id: Ib10d694737ffa40c1eee063f8ac789a01dbdc7dd
Merged-In: Ib10d694737ffa40c1eee063f8ac789a01dbdc7dd
diff --git a/src/com/android/cellbroadcastservice/CellBroadcastHandler.java b/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
index 8966417..5364138 100644
--- a/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
+++ b/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
@@ -16,8 +16,6 @@
 
 package com.android.cellbroadcastservice;
 
-import static android.provider.Settings.Secure.CMAS_ADDITIONAL_BROADCAST_PKG;
-
 import android.Manifest;
 import android.annotation.NonNull;
 import android.annotation.Nullable;
@@ -43,7 +41,6 @@
 import android.os.SystemClock;
 import android.os.SystemProperties;
 import android.os.UserHandle;
-import android.provider.Settings;
 import android.provider.Telephony;
 import android.provider.Telephony.CellBroadcasts;
 import android.telephony.CbGeoUtils.Geometry;
@@ -120,7 +117,8 @@
         this("CellBroadcastHandler", context, Looper.myLooper());
     }
 
-    protected CellBroadcastHandler(String debugTag, Context context, Looper looper) {
+    @VisibleForTesting
+    public CellBroadcastHandler(String debugTag, Context context, Looper looper) {
         super(debugTag, context, looper);
         mLocationRequester = new LocationRequester(
                 context,
@@ -481,26 +479,31 @@
             if (IS_DEBUGGABLE) {
                 // Send additional broadcast intent to the specified package. This is only for sl4a
                 // automation tests.
-                final String additionalPackage = Settings.Secure.getString(
-                        mContext.getContentResolver(), CMAS_ADDITIONAL_BROADCAST_PKG);
-                if (additionalPackage != null) {
+                String[] testPkgs = mContext.getResources().getStringArray(
+                        R.array.config_testCellBroadcastReceiverPkgs);
+                if (testPkgs != null) {
+                    mReceiverCount.addAndGet(testPkgs.length);
                     Intent additionalIntent = new Intent(intent);
-                    additionalIntent.setPackage(additionalPackage);
-                    mContext.createContextAsUser(UserHandle.ALL, 0).sendOrderedBroadcast(
-                            additionalIntent, receiverPermission, appOp, null, getHandler(),
-                            Activity.RESULT_OK, null, null);
+                    for (String pkg : testPkgs) {
+                        additionalIntent.setPackage(pkg);
+                        mContext.createContextAsUser(UserHandle.ALL, 0).sendOrderedBroadcast(
+                                additionalIntent, receiverPermission, appOp, null, getHandler(),
+                                Activity.RESULT_OK, null, null);
+                    }
                 }
             }
 
             String[] pkgs = mContext.getResources().getStringArray(
-                    com.android.internal.R.array.config_defaultCellBroadcastReceiverPkgs);
-            mReceiverCount.addAndGet(pkgs.length);
-            for (String pkg : pkgs) {
-                // Explicitly send the intent to all the configured cell broadcast receivers.
-                intent.setPackage(pkg);
-                mContext.createContextAsUser(UserHandle.ALL, 0).sendOrderedBroadcast(
-                        intent, receiverPermission, appOp, null, getHandler(),
-                        Activity.RESULT_OK, null, null);
+                    R.array.config_defaultCellBroadcastReceiverPkgs);
+            if (pkgs != null) {
+                mReceiverCount.addAndGet(pkgs.length);
+                for (String pkg : pkgs) {
+                    // Explicitly send the intent to all the configured cell broadcast receivers.
+                    intent.setPackage(pkg);
+                    mContext.createContextAsUser(UserHandle.ALL, 0).sendOrderedBroadcast(
+                            intent, receiverPermission, appOp, null, getHandler(),
+                            Activity.RESULT_OK, null, null);
+                }
             }
         } else {
             msg = "Dispatching SMS CB, SmsCbMessage is: " + message;