Merge "Add TEST_MAPPING"
diff --git a/res/values/config.xml b/res/values/config.xml
index 4d640eb..23c8177 100644
--- a/res/values/config.xml
+++ b/res/values/config.xml
@@ -24,6 +24,10 @@
<item>com.android.cellbroadcastreceiver</item>
</string-array>
+ <!-- Package names of the test cell broadcast receivers, only used on debug builds -->
+ <string-array name="config_testCellBroadcastReceiverPkgs" translatable="false">
+ </string-array>
+
<!-- The message expiration time in milliseconds for duplicate detection -->
<integer name="message_expiration_time">86400000</integer>
diff --git a/res/values/overlayable.xml b/res/values/overlayable.xml
new file mode 100644
index 0000000..85ba114
--- /dev/null
+++ b/res/values/overlayable.xml
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- 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.
+-->
+
+<!-- These values can be used to control CellBroadcastService behavior on individual devices.
+ These can be overridden by OEM's by using an RRO overlay app. -->
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+ <overlayable name="CellBroadcastServiceCustomization">
+ <!-- START VENDOR CUSTOMIZATION -->
+ <policy type="product|system|vendor">
+
+ <!-- Params from config.xml that can be overlayed -->
+ <item type="array" name="config_defaultCellBroadcastReceiverPkgs" />
+ <item type="array" name="config_testCellBroadcastReceiverPkgs" />
+ <!-- Params from config.xml that can be overlayed -->
+ </policy>
+ <!-- END VENDOR CUSTOMIZATION -->
+ </overlayable>
+</resources>
diff --git a/res/values/symbols.xml b/res/values/symbols.xml
index c2f50eb..2cfb796 100644
--- a/res/values/symbols.xml
+++ b/res/values/symbols.xml
@@ -23,6 +23,7 @@
and in layout xml as: "@*android:<type>/<name>" -->
<java-symbol type="array" name="config_defaultCellBroadcastReceiverPkgs" />
+ <java-symbol type="array" name="config_testCellBroadcastReceiverPkgs" />
<!-- ETWS primary messages -->
<java-symbol type="string" name="etws_primary_default_message_earthquake" />
diff --git a/src/com/android/cellbroadcastservice/CdmaServiceCategoryProgramHandler.java b/src/com/android/cellbroadcastservice/CdmaServiceCategoryProgramHandler.java
index 212962e..4b73258 100644
--- a/src/com/android/cellbroadcastservice/CdmaServiceCategoryProgramHandler.java
+++ b/src/com/android/cellbroadcastservice/CdmaServiceCategoryProgramHandler.java
@@ -139,7 +139,7 @@
// TODO: move this resource and its overlays to the CellBroadcastService directory
String[] pkgs = mContext.getResources().getStringArray(
- com.android.internal.R.array.config_defaultCellBroadcastReceiverPkgs);
+ R.array.config_defaultCellBroadcastReceiverPkgs);
mReceiverCount.addAndGet(pkgs.length);
for (String pkg : pkgs) {
intent.setPackage(pkg);
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;
diff --git a/src/com/android/cellbroadcastservice/GsmCellBroadcastHandler.java b/src/com/android/cellbroadcastservice/GsmCellBroadcastHandler.java
index 637edd4..f2fbec5 100644
--- a/src/com/android/cellbroadcastservice/GsmCellBroadcastHandler.java
+++ b/src/com/android/cellbroadcastservice/GsmCellBroadcastHandler.java
@@ -61,7 +61,7 @@
new HashMap<>(4);
@VisibleForTesting
- protected GsmCellBroadcastHandler(Context context, Looper looper) {
+ public GsmCellBroadcastHandler(Context context, Looper looper) {
super("GsmCellBroadcastHandler", context, looper);
}
diff --git a/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java b/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
index d498e25..152f4e8 100644
--- a/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
+++ b/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
@@ -498,7 +498,11 @@
return type == TYPE_ACTIVE_ALERT_SHARE_WAC;
}
- static final class CellBroadcastIdentity {
+ /**
+ * The GSM cell broadcast identity
+ */
+ @VisibleForTesting
+ public static final class CellBroadcastIdentity {
public final int messageIdentifier;
public final int serialNumber;
CellBroadcastIdentity(int messageIdentifier, int serialNumber) {
diff --git a/tests/src/com/android/cellbroadcastservice/CdmaSmsMessageTest.java b/tests/src/com/android/cellbroadcastservice/tests/CdmaSmsMessageTest.java
similarity index 99%
rename from tests/src/com/android/cellbroadcastservice/CdmaSmsMessageTest.java
rename to tests/src/com/android/cellbroadcastservice/tests/CdmaSmsMessageTest.java
index e24dbd5..171d437 100644
--- a/tests/src/com/android/cellbroadcastservice/CdmaSmsMessageTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CdmaSmsMessageTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.cellbroadcastservice;
+package com.android.cellbroadcastservice.tests;
import android.content.Context;
import android.hardware.radio.V1_0.CdmaSmsMessage;
@@ -25,6 +25,8 @@
import android.testing.TestableLooper;
import android.util.Log;
+import com.android.cellbroadcastservice.BearerData;
+import com.android.cellbroadcastservice.DefaultCellBroadcastService;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.cdma.SmsMessage;
import com.android.internal.telephony.cdma.SmsMessageConverter;
@@ -128,7 +130,7 @@
@Before
public void setUp() throws Exception {
super.setUp();
- putResources(R.bool.config_sms_utf8_support, false);
+ putResources(com.android.cellbroadcastservice.R.bool.config_sms_utf8_support, false);
}
@After
diff --git a/tests/src/com/android/cellbroadcastservice/CellBroadcastHandlerTest.java b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastHandlerTest.java
similarity index 91%
rename from tests/src/com/android/cellbroadcastservice/CellBroadcastHandlerTest.java
rename to tests/src/com/android/cellbroadcastservice/tests/CellBroadcastHandlerTest.java
index a9658cd..3fce3c5 100644
--- a/tests/src/com/android/cellbroadcastservice/CellBroadcastHandlerTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastHandlerTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.cellbroadcastservice;
+package com.android.cellbroadcastservice.tests;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.doReturn;
@@ -35,6 +35,10 @@
import android.testing.TestableLooper;
import android.text.format.DateUtils;
+import com.android.cellbroadcastservice.CellBroadcastHandler;
+import com.android.cellbroadcastservice.CellBroadcastProvider;
+import com.android.cellbroadcastservice.SmsCbConstants;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -57,7 +61,7 @@
private class CellBroadcastContentProvider extends MockContentProvider {
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
- String sortOrder) {
+ String sortOrder) {
if (uri.compareTo(Telephony.CellBroadcasts.CONTENT_URI) == 0) {
MatrixCursor mc = new MatrixCursor(CellBroadcastProvider.QUERY_COLUMNS);
@@ -116,7 +120,8 @@
doReturn(mMockedResources).when(mMockedResourcesCache).get(anyInt());
replaceInstance(CellBroadcastHandler.class, "mResourcesCache", mCellBroadcastHandler,
mMockedResourcesCache);
- putResources(R.integer.message_expiration_time, (int) DateUtils.DAY_IN_MILLIS);
+ putResources(com.android.cellbroadcastservice.R.integer.message_expiration_time,
+ (int) DateUtils.DAY_IN_MILLIS);
}
@After
@@ -125,7 +130,7 @@
}
private SmsCbMessage createSmsCbMessage(int serialNumber, int serviceCategory,
- String messageBody) {
+ String messageBody) {
return new SmsCbMessage(SmsCbMessage.MESSAGE_FORMAT_3GPP,
0, serialNumber, new SmsCbLocation(),
serviceCategory, "en", messageBody, 3,
@@ -156,7 +161,7 @@
@Test
@SmallTest
public void testNotDuplicateMessageBodyDifferent() throws Exception {
- putResources(R.bool.duplicate_compare_body, true);
+ putResources(com.android.cellbroadcastservice.R.bool.duplicate_compare_body, true);
SmsCbMessage msg = createSmsCbMessage(1234, 4370, "msg");
assertFalse(mCellBroadcastHandler.isDuplicate(msg));
}
diff --git a/tests/src/com/android/cellbroadcastservice/CellBroadcastProviderTest.java b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTest.java
similarity index 99%
rename from tests/src/com/android/cellbroadcastservice/CellBroadcastProviderTest.java
rename to tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTest.java
index a639a79..b5c3faf 100644
--- a/tests/src/com/android/cellbroadcastservice/CellBroadcastProviderTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.cellbroadcastservice;
+package com.android.cellbroadcastservice.tests;
import static com.android.cellbroadcastservice.CellBroadcastProvider.QUERY_COLUMNS;
@@ -31,6 +31,7 @@
import android.test.mock.MockContext;
import android.util.Log;
+import com.android.cellbroadcastservice.CellBroadcastProvider;
import com.android.cellbroadcastservice.CellBroadcastProvider.PermissionChecker;
import junit.framework.TestCase;
diff --git a/tests/src/com/android/cellbroadcastservice/CellBroadcastProviderTestable.java b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTestable.java
similarity index 95%
rename from tests/src/com/android/cellbroadcastservice/CellBroadcastProviderTestable.java
rename to tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTestable.java
index 2be7512..b50ccb0 100644
--- a/tests/src/com/android/cellbroadcastservice/CellBroadcastProviderTestable.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTestable.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.cellbroadcastservice;
+package com.android.cellbroadcastservice.tests;
import android.content.Context;
import android.content.pm.ProviderInfo;
@@ -24,6 +24,8 @@
import androidx.test.InstrumentationRegistry;
+import com.android.cellbroadcastservice.CellBroadcastProvider;
+
public class CellBroadcastProviderTestable extends CellBroadcastProvider {
private static final String TAG = CellBroadcastProviderTestable.class.getSimpleName();
diff --git a/tests/src/com/android/cellbroadcastservice/CellBroadcastServiceTestBase.java b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastServiceTestBase.java
similarity index 99%
rename from tests/src/com/android/cellbroadcastservice/CellBroadcastServiceTestBase.java
rename to tests/src/com/android/cellbroadcastservice/tests/CellBroadcastServiceTestBase.java
index 74659dd..009986e 100644
--- a/tests/src/com/android/cellbroadcastservice/CellBroadcastServiceTestBase.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastServiceTestBase.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.cellbroadcastservice;
+package com.android.cellbroadcastservice.tests;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
diff --git a/tests/src/com/android/cellbroadcastservice/GsmCellBroadcastHandlerTest.java b/tests/src/com/android/cellbroadcastservice/tests/GsmCellBroadcastHandlerTest.java
similarity index 92%
rename from tests/src/com/android/cellbroadcastservice/GsmCellBroadcastHandlerTest.java
rename to tests/src/com/android/cellbroadcastservice/tests/GsmCellBroadcastHandlerTest.java
index 5df26f2..65f0c4b 100644
--- a/tests/src/com/android/cellbroadcastservice/GsmCellBroadcastHandlerTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/GsmCellBroadcastHandlerTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.cellbroadcastservice;
+package com.android.cellbroadcastservice.tests;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString;
@@ -41,6 +41,11 @@
import android.testing.TestableLooper;
import android.text.format.DateUtils;
+import com.android.cellbroadcastservice.CellBroadcastHandler;
+import com.android.cellbroadcastservice.CellBroadcastProvider;
+import com.android.cellbroadcastservice.GsmCellBroadcastHandler;
+import com.android.cellbroadcastservice.SmsCbConstants;
+
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -149,8 +154,9 @@
doReturn(mMockedResources).when(mMockedResourcesCache).get(anyInt());
replaceInstance(CellBroadcastHandler.class, "mResourcesCache",
mGsmCellBroadcastHandler, mMockedResourcesCache);
- putResources(R.integer.message_expiration_time, 86400000);
- putResources(com.android.internal.R.array.config_defaultCellBroadcastReceiverPkgs,
+ putResources(com.android.cellbroadcastservice.R.integer.message_expiration_time, 86400000);
+ putResources(
+ com.android.cellbroadcastservice.R.array.config_defaultCellBroadcastReceiverPkgs,
new String[]{"fake.cellbroadcast.pkg"});
}
@@ -182,7 +188,8 @@
@Test
@SmallTest
public void testAirplaneModeReset() {
- putResources(R.bool.reset_on_power_cycle_or_airplane_mode, true);
+ putResources(com.android.cellbroadcastservice.R.bool.reset_on_power_cycle_or_airplane_mode,
+ true);
Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intent.putExtra("state", true);
// Send fake airplane mode on event.
diff --git a/tests/src/com/android/cellbroadcastservice/GsmSmsCbMessageTest.java b/tests/src/com/android/cellbroadcastservice/tests/GsmSmsCbMessageTest.java
similarity index 99%
rename from tests/src/com/android/cellbroadcastservice/GsmSmsCbMessageTest.java
rename to tests/src/com/android/cellbroadcastservice/tests/GsmSmsCbMessageTest.java
index c39f650..73820b6 100644
--- a/tests/src/com/android/cellbroadcastservice/GsmSmsCbMessageTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/GsmSmsCbMessageTest.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.cellbroadcastservice;
+package com.android.cellbroadcastservice.tests;
import android.telephony.CbGeoUtils;
import android.telephony.SmsCbCmasInfo;
@@ -29,6 +29,10 @@
import com.android.cellbroadcastservice.CbGeoUtils.Circle;
import com.android.cellbroadcastservice.CbGeoUtils.Polygon;
+import com.android.cellbroadcastservice.GsmSmsCbMessage;
+import com.android.cellbroadcastservice.R;
+import com.android.cellbroadcastservice.SmsCbConstants;
+import com.android.cellbroadcastservice.SmsCbHeader;
import org.junit.After;
import org.junit.Before;