[automerger skipped] Remove UnsupportedAppUsage, use correct State* classes am: cdfc9f3809 am: f25a0bf1b5
am: 84dc8b957c -s ours
am skip reason: change_id Id620c4c7c4c74cf304def7cb5779285762760035 with SHA1 ac12bae569 is in history
Change-Id: I27c916e6aa7bb3c6ef68bc1ac0e3695568afd29b
diff --git a/Android.bp b/Android.bp
index c72b5c8..68fd40b 100644
--- a/Android.bp
+++ b/Android.bp
@@ -1,7 +1,7 @@
// Copyright 2019 The Android Open Source Project
-
-android_app {
- name: "CellBroadcastServiceModule",
+java_defaults {
+ name: "CellBroadcastServiceCommon",
+ min_sdk_version: "29",
srcs: [
"src/**/*.java",
":framework-annotations",
@@ -15,6 +15,25 @@
optimize: {
proguard_flags_files: ["proguard.flags"],
},
+ jarjar_rules: "cellbroadcast-jarjar-rules.txt",
+ plugins: ["java_api_finder"],
+}
+
+android_app {
+ name: "CellBroadcastServiceModule",
+ defaults: ["CellBroadcastServiceCommon"],
+ certificate: "networkstack",
+ manifest: "AndroidManifest.xml",
+}
+
+android_app {
+ name: "CellBroadcastServiceModulePlatform",
+ defaults: ["CellBroadcastServiceCommon"],
+ certificate: "platform",
+ // CellBroadcastServicePlatformModule is a replacement for com.android.cellbroadcast apex
+ // which consists of CellBroadcastServiceModule
+ overrides: ["com.android.cellbroadcast"],
+ manifest: "AndroidManifest_Platform.xml",
}
// used to share common constants between cellbroadcastservice and cellbroadcastreceier
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 4dc0b97..bd76af1 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -17,7 +17,9 @@
*/
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- android:sharedUserId="android.uid.phone"
+ android:sharedUserId="android.uid.networkstack"
+ android:versionCode="300000000"
+ android:versionName="R-initial"
package="com.android.cellbroadcastservice">
<original-package android:name="com.android.cellbroadcastservice" />
@@ -29,15 +31,19 @@
<uses-permission android:name="android.permission.READ_CELL_BROADCASTS" />
<uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.BROADCAST_SMS" />
+ <uses-permission android:name="android.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS" />
<uses-sdk android:minSdkVersion="29"/>
<application android:label="Module used to handle cell broadcasts."
android:defaultToDeviceProtectedStorage="true"
android:directBootAware="true"
- android:process="com.android.phone">
+ android:persistent="true"
+ android:process="com.android.networkstack.process">
<service android:name="DefaultCellBroadcastService"
+ android:process="com.android.networkstack.process"
android:exported="true"
android:permission="android.permission.BIND_CELL_BROADCAST_SERVICE">
<intent-filter>
diff --git a/AndroidManifest_Platform.xml b/AndroidManifest_Platform.xml
new file mode 100644
index 0000000..067741f
--- /dev/null
+++ b/AndroidManifest_Platform.xml
@@ -0,0 +1,52 @@
+<?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.
+ */
+-->
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ android:sharedUserId="android.uid.phone"
+ package="com.android.cellbroadcastservice">
+
+ <original-package android:name="com.android.cellbroadcastservice" />
+
+ <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
+ <uses-permission android:name="android.permission.RECEIVE_SMS" />
+ <uses-permission android:name="android.permission.RECEIVE_EMERGENCY_BROADCAST" />
+ <uses-permission android:name="android.permission.READ_PRIVILEGED_PHONE_STATE" />
+ <uses-permission android:name="android.permission.READ_CELL_BROADCASTS" />
+ <uses-permission android:name="android.permission.MODIFY_PHONE_STATE" />
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
+ <uses-permission android:name="android.permission.BROADCAST_SMS" />
+ <uses-permission android:name="android.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS" />
+
+ <uses-sdk android:minSdkVersion="29"/>
+
+ <application android:label="Module used to handle cell broadcasts."
+ android:defaultToDeviceProtectedStorage="true"
+ android:persistent="true"
+ android:directBootAware="true"
+ android:process="com.android.phone">
+
+ <service android:name="DefaultCellBroadcastService"
+ android:process="com.android.phone"
+ android:exported="true"
+ android:permission="android.permission.BIND_CELL_BROADCAST_SERVICE">
+ <intent-filter>
+ <action android:name="android.telephony.CellBroadcastService" />
+ </intent-filter>
+ </service>
+ </application>
+</manifest>
diff --git a/CleanSpec.mk b/CleanSpec.mk
new file mode 100644
index 0000000..f69421d
--- /dev/null
+++ b/CleanSpec.mk
@@ -0,0 +1,50 @@
+# Copyright (C) 2007 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.
+#
+
+# If you don't need to do a full clean build but would like to touch
+# a file or delete some intermediate files, add a clean step to the end
+# of the list. These steps will only be run once, if they haven't been
+# run before.
+#
+# E.g.:
+# $(call add-clean-step, touch -c external/sqlite/sqlite3.h)
+# $(call add-clean-step, rm -rf $(PRODUCT_OUT)/obj/STATIC_LIBRARIES/libz_intermediates)
+#
+# Always use "touch -c" and "rm -f" or "rm -rf" to gracefully deal with
+# files that are missing or have been moved.
+#
+# Use $(PRODUCT_OUT) to get to the "out/target/product/blah/" directory.
+# Use $(OUT_DIR) to refer to the "out" directory.
+#
+# If you need to re-do something that's already mentioned, just copy
+# the command and add it to the bottom of the list. E.g., if a change
+# that you made last week required touching a file and a change you
+# made today requires touching the same file, just copy the old
+# touch step and add it to the end of the list.
+#
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
+
+# For example:
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/APPS/AndroidTests_intermediates)
+#$(call add-clean-step, rm -rf $(OUT_DIR)/target/common/obj/JAVA_LIBRARIES/core_intermediates)
+#$(call add-clean-step, find $(OUT_DIR) -type f -name "IGTalkSession*" -print0 | xargs -0 rm -f)
+#$(call add-clean-step, rm -rf $(PRODUCT_OUT)/data/*)
+
+$(call add-clean-step, rm -rf $(PRODUCT_OUT)/system/priv-app/CellBroadcastServiceModule)
+# ************************************************
+# NEWER CLEAN STEPS MUST BE AT THE END OF THE LIST
+# ************************************************
diff --git a/cellbroadcast-jarjar-rules.txt b/cellbroadcast-jarjar-rules.txt
index 32cfb51..3e4127a 100644
--- a/cellbroadcast-jarjar-rules.txt
+++ b/cellbroadcast-jarjar-rules.txt
@@ -1,6 +1,5 @@
rule android.os.HandlerExecutor* com.android.cellbroadcastservice.HandlerExecutor@1
rule android.util.LocalLog* com.android.cellbroadcastservice.LocalLog@1
-rule android.util.Slog* com.android.cellbroadcastservice.Slog@1
rule android.internal.util.IState* com.android.cellbroadcastservice.IState@1
rule android.internal.util.Preconditions* com.android.cellbroadcastservice.Preconditions@1
rule android.internal.util.State* com.android.cellbroadcastservice.State@1
diff --git a/src/com/android/cellbroadcastservice/BearerData.java b/src/com/android/cellbroadcastservice/BearerData.java
index cc7a155..d73339c 100644
--- a/src/com/android/cellbroadcastservice/BearerData.java
+++ b/src/com/android/cellbroadcastservice/BearerData.java
@@ -17,9 +17,9 @@
package com.android.cellbroadcastservice;
import android.content.Context;
+import android.telephony.Rlog;
import android.telephony.SmsCbCmasInfo;
import android.telephony.cdma.CdmaSmsCbProgramData;
-import android.util.Log;
/**
* An object to decode CDMA SMS bearer data.
@@ -194,9 +194,9 @@
inStream.skip(3);
}
if ((!decodeSuccess) || (paramBits > 0)) {
- Log.d(LOG_TAG, "MESSAGE_IDENTIFIER decode " +
- (decodeSuccess ? "succeeded" : "failed") +
- " (extra bits = " + paramBits + ")");
+ Rlog.d(LOG_TAG, "MESSAGE_IDENTIFIER decode "
+ + (decodeSuccess ? "succeeded" : "failed")
+ + " (extra bits = " + paramBits + ")");
}
inStream.skip(paramBits);
return decodeSuccess;
@@ -211,7 +211,7 @@
decodeSuccess = true;
inStream.skip(paramBits);
}
- Log.d(LOG_TAG, "RESERVED bearer data subparameter " + subparamId + " decode "
+ Rlog.d(LOG_TAG, "RESERVED bearer data subparameter " + subparamId + " decode "
+ (decodeSuccess ? "succeeded" : "failed") + " (param bits = " + paramBits + ")");
if (!decodeSuccess) {
throw new CodingException("RESERVED bearer data subparameter " + subparamId
@@ -263,7 +263,7 @@
if (maxNumFields < 0) {
throw new CodingException(charset + " decode failed: offset out of range");
}
- Log.e(LOG_TAG, charset + " decode error: offset = " + offset + " numFields = "
+ Rlog.e(LOG_TAG, charset + " decode error: offset = " + offset + " numFields = "
+ numFields + " data.length = " + data.length + " maxNumFields = "
+ maxNumFields);
numFields = maxNumFields;
@@ -432,9 +432,9 @@
bData.language = inStream.read(8);
}
if ((!decodeSuccess) || (paramBits > 0)) {
- Log.d(LOG_TAG, "LANGUAGE_INDICATOR decode " +
- (decodeSuccess ? "succeeded" : "failed") +
- " (extra bits = " + paramBits + ")");
+ Rlog.d(LOG_TAG, "LANGUAGE_INDICATOR decode "
+ + (decodeSuccess ? "succeeded" : "failed")
+ + " (extra bits = " + paramBits + ")");
}
inStream.skip(paramBits);
return decodeSuccess;
@@ -452,9 +452,9 @@
inStream.skip(6);
}
if ((!decodeSuccess) || (paramBits > 0)) {
- Log.d(LOG_TAG, "PRIORITY_INDICATOR decode " +
- (decodeSuccess ? "succeeded" : "failed") +
- " (extra bits = " + paramBits + ")");
+ Rlog.d(LOG_TAG, "PRIORITY_INDICATOR decode "
+ + (decodeSuccess ? "succeeded" : "failed")
+ + " (extra bits = " + paramBits + ")");
}
inStream.skip(paramBits);
return decodeSuccess;
@@ -553,7 +553,7 @@
break;
default:
- Log.w(LOG_TAG, "skipping unsupported CMAS record type " + recordType);
+ Rlog.w(LOG_TAG, "skipping unsupported CMAS record type " + recordType);
inStream.skip(recordLen * 8);
break;
}
@@ -631,9 +631,9 @@
}
return bData;
} catch (BitwiseInputStream.AccessException ex) {
- Log.e(LOG_TAG, "BearerData decode failed: " + ex);
+ Rlog.e(LOG_TAG, "BearerData decode failed: " + ex);
} catch (CodingException ex) {
- Log.e(LOG_TAG, "BearerData decode failed: " + ex);
+ Rlog.e(LOG_TAG, "BearerData decode failed: " + ex);
}
return null;
}
diff --git a/src/com/android/cellbroadcastservice/CbGeoUtils.java b/src/com/android/cellbroadcastservice/CbGeoUtils.java
index 0a8fe48..2a7a1d7 100644
--- a/src/com/android/cellbroadcastservice/CbGeoUtils.java
+++ b/src/com/android/cellbroadcastservice/CbGeoUtils.java
@@ -19,8 +19,8 @@
import android.annotation.NonNull;
import android.telephony.CbGeoUtils.Geometry;
import android.telephony.CbGeoUtils.LatLng;
+import android.telephony.Rlog;
import android.text.TextUtils;
-import android.util.Log;
import java.util.ArrayList;
import java.util.List;
@@ -231,7 +231,7 @@
geometries.add(new Polygon(vertices));
break;
default:
- Log.e(TAG, "Invalid geometry format " + geometryStr);
+ Rlog.e(TAG, "Invalid geometry format " + geometryStr);
}
}
return geometries;
@@ -284,7 +284,7 @@
sb.append("|");
sb.append(circle.getRadius());
} else {
- Log.e(TAG, "Unsupported geometry object " + geometry);
+ Rlog.e(TAG, "Unsupported geometry object " + geometry);
return null;
}
return sb.toString();
diff --git a/src/com/android/cellbroadcastservice/CellBroadcastHandler.java b/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
index 1615f3d..28e56b5 100644
--- a/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
+++ b/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
@@ -16,6 +16,9 @@
package com.android.cellbroadcastservice;
+import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
+import static android.Manifest.permission.ACCESS_FINE_LOCATION;
+
import android.Manifest;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -30,11 +33,12 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.location.Location;
-import android.location.LocationListener;
import android.location.LocationManager;
+import android.location.LocationRequest;
import android.net.Uri;
-import android.os.Bundle;
+import android.os.CancellationSignal;
import android.os.Handler;
+import android.os.HandlerExecutor;
import android.os.Looper;
import android.os.Message;
import android.os.Process;
@@ -45,13 +49,13 @@
import android.provider.Telephony.CellBroadcasts;
import android.telephony.CbGeoUtils.Geometry;
import android.telephony.CbGeoUtils.LatLng;
+import android.telephony.CellBroadcastIntents;
+import android.telephony.Rlog;
import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionManager;
import android.telephony.cdma.CdmaSmsCbProgramData;
import android.text.TextUtils;
-import android.text.format.DateUtils;
import android.util.LocalLog;
-import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
@@ -64,6 +68,7 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@@ -96,7 +101,7 @@
private static final boolean IS_DEBUGGABLE = SystemProperties.getInt("ro.debuggable", 0) == 1;
/** Uses to request the location update. */
- public final LocationRequester mLocationRequester;
+ private final LocationRequester mLocationRequester;
/** Timestamp of last airplane mode on */
protected long mLastAirplaneModeTime = 0;
@@ -123,7 +128,7 @@
mLocationRequester = new LocationRequester(
context,
(LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE),
- getHandler().getLooper());
+ getHandler());
// Adding GSM / CDMA service category mapping.
mServiceCategoryCrossRATMap = Stream.of(new Integer[][] {
@@ -346,7 +351,6 @@
// Check serial number if message is from the same carrier.
if (message.getSerialNumber() != messageToCheck.getSerialNumber()) {
// Not a dup. Check next one.
- log("Serial number check. Not a dup. " + messageToCheck);
continue;
}
@@ -355,7 +359,6 @@
&& message.getEtwsWarningInfo().isPrimary()
!= messageToCheck.getEtwsWarningInfo().isPrimary()) {
// Not a dup. Check next one.
- log("ETWS primary check. Not a dup. " + messageToCheck);
continue;
}
@@ -369,7 +372,6 @@
messageToCheck.getServiceCategory()),
message.getServiceCategory())) {
// Not a dup. Check next one.
- log("Service category check. Not a dup. " + messageToCheck);
continue;
}
@@ -516,10 +518,9 @@
msg = "Dispatching SMS CB, SmsCbMessage is: " + message;
log(msg);
mLocalLog.log(msg);
- intent = new Intent(Telephony.Sms.Intents.SMS_CB_RECEIVED_ACTION);
// Send implicit intent since there are various 3rd party carrier apps listen to
// this intent.
- intent.addFlags(Intent.FLAG_RECEIVER_INCLUDE_BACKGROUND);
+ intent = new Intent(Telephony.Sms.Intents.SMS_CB_RECEIVED_ACTION);
receiverPermission = Manifest.permission.RECEIVE_SMS;
appOp = AppOpsManager.OPSTR_RECEIVE_SMS;
@@ -527,9 +528,10 @@
putPhoneIdAndSubIdExtra(mContext, intent, slotIndex);
mReceiverCount.incrementAndGet();
- mContext.createContextAsUser(UserHandle.ALL, 0).sendOrderedBroadcast(
- intent, receiverPermission, appOp, mReceiver, getHandler(),
- Activity.RESULT_OK, null, null);
+ CellBroadcastIntents.sendOrderedBroadcastForBackgroundReceivers(
+ mContext, UserHandle.ALL, intent,
+ receiverPermission, appOp, mReceiver, getHandler(), Activity.RESULT_OK,
+ null, null);
}
if (messageUri != null) {
@@ -585,18 +587,9 @@
/**
* Use as the default maximum wait time if the cell broadcast doesn't specify the value.
- * Most of the location request should be responded within 20 seconds.
+ * Most of the location request should be responded within 30 seconds.
*/
- private static final int DEFAULT_MAXIMUM_WAIT_TIME_SEC = 20;
-
- /**
- * Trigger this event when the {@link LocationManager} is not responded within the given
- * time.
- */
- private static final int EVENT_LOCATION_REQUEST_TIMEOUT = 1;
-
- /** Request a single location update. */
- private static final int EVENT_REQUEST_LOCATION_UPDATE = 2;
+ private static final int DEFAULT_MAXIMUM_WAIT_TIME_SEC = 30;
/**
* Request location update from network or gps location provider. Network provider will be
@@ -606,17 +599,20 @@
LocationManager.NETWORK_PROVIDER, LocationManager.GPS_PROVIDER);
private final LocationManager mLocationManager;
- private final Looper mLooper;
private final List<LocationUpdateCallback> mCallbacks;
private final Context mContext;
- private Handler mLocationHandler;
+ private final Handler mLocationHandler;
- LocationRequester(Context context, LocationManager locationManager, Looper looper) {
+ private int mNumLocationUpdatesInProgress;
+
+ private final List<CancellationSignal> mCancellationSignals = new ArrayList<>();
+
+ LocationRequester(Context context, LocationManager locationManager, Handler handler) {
mLocationManager = locationManager;
- mLooper = looper;
mCallbacks = new ArrayList<>();
mContext = context;
- mLocationHandler = new LocationHandler(looper);
+ mLocationHandler = handler;
+ mNumLocationUpdatesInProgress = 0;
}
/**
@@ -624,103 +620,83 @@
* {@code null} location will be called immediately.
*
* @param callback a callback to the response when the location is available
- * @param maximumWaitTimeSec the maximum wait time of this request. If location is not
+ * @param maximumWaitTimeS the maximum wait time of this request. If location is not
* updated within the maximum wait time, {@code callback#onLocationUpadte(null)} will be
* called.
*/
void requestLocationUpdate(@NonNull LocationUpdateCallback callback,
- int maximumWaitTimeSec) {
- mLocationHandler.obtainMessage(EVENT_REQUEST_LOCATION_UPDATE, maximumWaitTimeSec,
- 0 /* arg2 */, callback).sendToTarget();
+ int maximumWaitTimeS) {
+ mLocationHandler.post(() -> requestLocationUpdateInternal(callback, maximumWaitTimeS));
}
- private void onLocationUpdate(@Nullable LatLng location) {
+ private void onLocationUpdate(@Nullable Location location) {
+ mNumLocationUpdatesInProgress--;
+
+ LatLng latLng = null;
+ if (location != null) {
+ Rlog.d(TAG, "Got location update");
+ latLng = new LatLng(location.getLatitude(), location.getLongitude());
+ } else if (mNumLocationUpdatesInProgress > 0) {
+ Rlog.d(TAG, "Still waiting for " + mNumLocationUpdatesInProgress
+ + " more location updates.");
+ return;
+ } else {
+ Rlog.d(TAG, "Location is not available.");
+ }
+
for (LocationUpdateCallback callback : mCallbacks) {
- callback.onLocationUpdate(location);
+ callback.onLocationUpdate(latLng);
}
mCallbacks.clear();
+
+ mCancellationSignals.forEach(CancellationSignal::cancel);
+ mCancellationSignals.clear();
+
+ mNumLocationUpdatesInProgress = 0;
}
private void requestLocationUpdateInternal(@NonNull LocationUpdateCallback callback,
- int maximumWaitTimeSec) {
- if (DBG) Log.d(TAG, "requestLocationUpdate");
- if (!isLocationServiceAvailable()) {
+ int maximumWaitTimeS) {
+ if (DBG) Rlog.d(TAG, "requestLocationUpdate");
+ if (!hasPermission(ACCESS_FINE_LOCATION) && !hasPermission(ACCESS_COARSE_LOCATION)) {
if (DBG) {
- Log.d(TAG, "Can't request location update because of no location permission");
+ Rlog.d(TAG, "Can't request location update because of no location permission");
}
callback.onLocationUpdate(null);
return;
}
+ if (mNumLocationUpdatesInProgress == 0) {
+ for (String provider : LOCATION_PROVIDERS) {
+ if (!mLocationManager.isProviderEnabled(provider)) {
+ if (DBG) {
+ Rlog.d(TAG, "provider " + provider + " not available");
+ }
+ continue;
+ }
+ LocationRequest request = LocationRequest.createFromDeprecatedProvider(provider,
+ 0, 0, true);
+ if (maximumWaitTimeS == SmsCbMessage.MAXIMUM_WAIT_TIME_NOT_SET) {
+ maximumWaitTimeS = DEFAULT_MAXIMUM_WAIT_TIME_SEC;
+ }
+ request.setExpireIn(TimeUnit.SECONDS.toMillis(maximumWaitTimeS));
- if (!mLocationHandler.hasMessages(EVENT_LOCATION_REQUEST_TIMEOUT)) {
- if (maximumWaitTimeSec == SmsCbMessage.MAXIMUM_WAIT_TIME_NOT_SET) {
- maximumWaitTimeSec = DEFAULT_MAXIMUM_WAIT_TIME_SEC;
- }
- mLocationHandler.sendMessageDelayed(
- mLocationHandler.obtainMessage(EVENT_LOCATION_REQUEST_TIMEOUT),
- maximumWaitTimeSec * DateUtils.SECOND_IN_MILLIS);
- }
-
- mCallbacks.add(callback);
-
- for (String provider : LOCATION_PROVIDERS) {
- if (mLocationManager.isProviderEnabled(provider)) {
- mLocationManager.requestSingleUpdate(provider, mLocationListener, mLooper);
- break;
+ CancellationSignal signal = new CancellationSignal();
+ mCancellationSignals.add(signal);
+ mLocationManager.getCurrentLocation(request, signal,
+ new HandlerExecutor(mLocationHandler), this::onLocationUpdate);
+ mNumLocationUpdatesInProgress++;
}
}
- }
-
- private boolean isLocationServiceAvailable() {
- if (!hasPermission(Manifest.permission.ACCESS_FINE_LOCATION)
- && !hasPermission(Manifest.permission.ACCESS_COARSE_LOCATION)) return false;
- for (String provider : LOCATION_PROVIDERS) {
- if (mLocationManager.isProviderEnabled(provider)) return true;
+ if (mNumLocationUpdatesInProgress > 0) {
+ mCallbacks.add(callback);
+ } else {
+ callback.onLocationUpdate(null);
}
- return false;
}
private boolean hasPermission(String permission) {
return mContext.checkPermission(permission, Process.myPid(), Process.myUid())
== PackageManager.PERMISSION_GRANTED;
}
-
- private final LocationListener mLocationListener = new LocationListener() {
- @Override
- public void onLocationChanged(Location location) {
- mLocationHandler.removeMessages(EVENT_LOCATION_REQUEST_TIMEOUT);
- onLocationUpdate(new LatLng(location.getLatitude(), location.getLongitude()));
- }
-
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) {}
-
- @Override
- public void onProviderEnabled(String provider) {}
-
- @Override
- public void onProviderDisabled(String provider) {}
- };
-
- private final class LocationHandler extends Handler {
- LocationHandler(Looper looper) {
- super(looper);
- }
-
- @Override
- public void handleMessage(Message msg) {
- switch (msg.what) {
- case EVENT_LOCATION_REQUEST_TIMEOUT:
- if (DBG) Log.d(TAG, "location request timeout");
- onLocationUpdate(null);
- break;
- case EVENT_REQUEST_LOCATION_UPDATE:
- requestLocationUpdateInternal((LocationUpdateCallback) msg.obj, msg.arg1);
- break;
- default:
- Log.e(TAG, "Unsupported message type " + msg.what);
- }
- }
- }
}
}
diff --git a/src/com/android/cellbroadcastservice/CellBroadcastProvider.java b/src/com/android/cellbroadcastservice/CellBroadcastProvider.java
index e45daca..f7dea4e 100644
--- a/src/com/android/cellbroadcastservice/CellBroadcastProvider.java
+++ b/src/com/android/cellbroadcastservice/CellBroadcastProvider.java
@@ -31,6 +31,7 @@
import android.os.Binder;
import android.os.Process;
import android.provider.Telephony.CellBroadcasts;
+import android.telephony.Rlog;
import android.text.TextUtils;
import android.util.Log;
@@ -179,7 +180,7 @@
checkReadPermission(uri);
if (DBG) {
- Log.d(TAG, "query:"
+ Rlog.d(TAG, "query:"
+ " uri = " + uri
+ " projection = " + Arrays.toString(projection)
+ " selection = " + selection
@@ -219,7 +220,7 @@
checkWritePermission();
if (DBG) {
- Log.d(TAG, "insert:"
+ Rlog.d(TAG, "insert:"
+ " uri = " + uri
+ " contentValue = " + values);
}
@@ -234,7 +235,7 @@
.notifyChange(CONTENT_URI, null /* observer */);
return newUri;
} else {
- Log.e(TAG, "Insert record failed because of unknown reason, uri = " + uri);
+ Rlog.e(TAG, "Insert record failed because of unknown reason, uri = " + uri);
return null;
}
default:
@@ -248,7 +249,7 @@
checkWritePermission();
if (DBG) {
- Log.d(TAG, "delete:"
+ Rlog.d(TAG, "delete:"
+ " uri = " + uri
+ " selection = " + selection
+ " selectionArgs = " + Arrays.toString(selectionArgs));
@@ -269,7 +270,7 @@
checkWritePermission();
if (DBG) {
- Log.d(TAG, "update:"
+ Rlog.d(TAG, "update:"
+ " uri = " + uri
+ " values = {" + values + "}"
+ " selection = " + selection
@@ -376,12 +377,12 @@
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (DBG) {
- Log.d(TAG, "onUpgrade: oldV=" + oldVersion + " newV=" + newVersion);
+ Rlog.d(TAG, "onUpgrade: oldV=" + oldVersion + " newV=" + newVersion);
}
if (oldVersion < 2) {
db.execSQL("ALTER TABLE " + CELL_BROADCASTS_TABLE_NAME + " ADD COLUMN "
+ CellBroadcasts.SLOT_INDEX + " INTEGER DEFAULT 0;");
- Log.d(TAG, "add slotIndex column");
+ Rlog.d(TAG, "add slotIndex column");
}
}
}
@@ -389,18 +390,26 @@
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;
+ // Only the telephony system compontents e.g, Cellbroadcast service has the write
+ // permission to modify this provider.
+ int status = getContext().checkCallingOrSelfPermission(
+ "android.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS");
+ if (status == PackageManager.PERMISSION_GRANTED) {
+ return true;
+ }
+ return false;
}
@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;
+ // Only the telephony system compontents e.g, Cellbroadcast service has the read
+ // permission to access this provider.
+ int status = getContext().checkCallingOrSelfPermission(
+ "android.permission.GRANT_RUNTIME_PERMISSIONS_TO_TELEPHONY_DEFAULTS");
+ if (status == PackageManager.PERMISSION_GRANTED) {
+ return true;
+ }
+ return false;
}
@Override
diff --git a/src/com/android/cellbroadcastservice/DefaultCellBroadcastService.java b/src/com/android/cellbroadcastservice/DefaultCellBroadcastService.java
index 09f0bcd..340d72d 100644
--- a/src/com/android/cellbroadcastservice/DefaultCellBroadcastService.java
+++ b/src/com/android/cellbroadcastservice/DefaultCellBroadcastService.java
@@ -19,12 +19,12 @@
import android.content.Context;
import android.os.Bundle;
import android.telephony.CellBroadcastService;
+import android.telephony.Rlog;
import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyManager;
import android.telephony.cdma.CdmaSmsCbProgramData;
-import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
@@ -59,13 +59,13 @@
@Override
public void onGsmCellBroadcastSms(int slotIndex, byte[] message) {
- Log.d(TAG, "onGsmCellBroadcastSms received message on slotId=" + slotIndex);
+ Rlog.d(TAG, "onGsmCellBroadcastSms received message on slotId=" + slotIndex);
mGsmCellBroadcastHandler.onGsmCellBroadcastSms(slotIndex, message);
}
@Override
public void onCdmaCellBroadcastSms(int slotIndex, byte[] bearerData, int serviceCategory) {
- Log.d(TAG, "onCdmaCellBroadcastSms received message on slotId=" + slotIndex);
+ Rlog.d(TAG, "onCdmaCellBroadcastSms received message on slotId=" + slotIndex);
int[] subIds =
((SubscriptionManager) getSystemService(
Context.TELEPHONY_SUBSCRIPTION_SERVICE)).getSubscriptionIds(slotIndex);
@@ -88,7 +88,7 @@
@Override
public void onCdmaScpMessage(int slotIndex, List<CdmaSmsCbProgramData> programData,
String originatingAddress, Consumer<Bundle> callback) {
- Log.d(TAG, "onCdmaScpMessage received message on slotId=" + slotIndex);
+ Rlog.d(TAG, "onCdmaScpMessage received message on slotId=" + slotIndex);
mCdmaScpHandler.onCdmaScpMessage(slotIndex, new ArrayList<>(programData),
originatingAddress, callback);
}
@@ -107,10 +107,10 @@
int serviceCategory) {
BearerData bData = BearerData.decode(context, bearerData, serviceCategory);
if (bData == null) {
- Log.w(TAG, "BearerData.decode() returned null");
+ Rlog.w(TAG, "BearerData.decode() returned null");
return null;
}
- Log.d(TAG, "MT raw BearerData = " + toHexString(bearerData, 0, bearerData.length));
+ Rlog.d(TAG, "MT raw BearerData = " + toHexString(bearerData, 0, bearerData.length));
SmsCbLocation location = new SmsCbLocation(plmn);
SubscriptionManager sm = (SubscriptionManager) context.getSystemService(
diff --git a/src/com/android/cellbroadcastservice/GsmAlphabet.java b/src/com/android/cellbroadcastservice/GsmAlphabet.java
index 1efb7be..9c52189 100644
--- a/src/com/android/cellbroadcastservice/GsmAlphabet.java
+++ b/src/com/android/cellbroadcastservice/GsmAlphabet.java
@@ -16,7 +16,7 @@
package com.android.cellbroadcastservice;
-import android.util.Log;
+import android.telephony.Rlog;
import android.util.SparseIntArray;
/**
@@ -579,7 +579,7 @@
int numTables = sLanguageTables.length;
int numShiftTables = sLanguageShiftTables.length;
if (numTables != numShiftTables) {
- Log.e(TAG, "Error: language tables array length " + numTables
+ Rlog.e(TAG, "Error: language tables array length " + numTables
+ " != shift tables array length " + numShiftTables);
}
@@ -589,7 +589,7 @@
int tableLen = table.length();
if (tableLen != 0 && tableLen != 128) {
- Log.e(TAG, "Error: language tables index " + i + " length " + tableLen
+ Rlog.e(TAG, "Error: language tables index " + i + " length " + tableLen
+ " (expected 128 or 0)");
}
@@ -607,7 +607,7 @@
int shiftTableLen = shiftTable.length();
if (shiftTableLen != 0 && shiftTableLen != 128) {
- Log.e(TAG, "Error: language shift tables index " + i + " length " + shiftTableLen
+ Rlog.e(TAG, "Error: language shift tables index " + i + " length " + shiftTableLen
+ " (expected 128 or 0)");
}
@@ -659,11 +659,11 @@
StringBuilder ret = new StringBuilder(lengthSeptets);
if (languageTable < 0 || languageTable > sLanguageTables.length) {
- Log.w(TAG, "unknown language table " + languageTable + ", using default");
+ Rlog.w(TAG, "unknown language table " + languageTable + ", using default");
languageTable = 0;
}
if (shiftTable < 0 || shiftTable > sLanguageShiftTables.length) {
- Log.w(TAG, "unknown single shift table " + shiftTable + ", using default");
+ Rlog.w(TAG, "unknown single shift table " + shiftTable + ", using default");
shiftTable = 0;
}
@@ -673,11 +673,11 @@
String shiftTableToChar = sLanguageShiftTables[shiftTable];
if (languageTableToChar.isEmpty()) {
- Log.w(TAG, "no language table for code " + languageTable + ", using default");
+ Rlog.w(TAG, "no language table for code " + languageTable + ", using default");
languageTableToChar = sLanguageTables[0];
}
if (shiftTableToChar.isEmpty()) {
- Log.w(TAG, "no single shift table for code " + shiftTable + ", using default");
+ Rlog.w(TAG, "no single shift table for code " + shiftTable + ", using default");
shiftTableToChar = sLanguageShiftTables[0];
}
@@ -717,7 +717,7 @@
}
}
} catch (RuntimeException ex) {
- Log.e(TAG, "Error GSM 7 bit packed: ", ex);
+ Rlog.e(TAG, "Error GSM 7 bit packed: ", ex);
return null;
}
diff --git a/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java b/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
index af948ae..b91dd19 100644
--- a/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
+++ b/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
@@ -27,12 +27,12 @@
import android.content.res.Resources;
import android.telephony.CbGeoUtils.Geometry;
import android.telephony.CbGeoUtils.LatLng;
+import android.telephony.Rlog;
import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.telephony.SmsMessage;
import android.telephony.SubscriptionManager;
import android.util.Pair;
-import android.util.Slog;
import com.android.cellbroadcastservice.CbGeoUtils.Circle;
import com.android.cellbroadcastservice.CbGeoUtils.Polygon;
@@ -138,7 +138,7 @@
} catch (Exception ex) {
// Catch the exception here, the message will be considered as having no WAC
// information which means the message will be broadcasted directly.
- Slog.e(TAG, "Can't parse warning area coordinates, ex = " + ex.toString());
+ Rlog.e(TAG, "Can't parse warning area coordinates, ex = " + ex.toString());
}
}
@@ -205,7 +205,7 @@
}
return new GeoFencingTriggerMessage(type, cbIdentifiers);
} catch (Exception ex) {
- Slog.e(TAG, "create geo-fencing trigger failed, ex = " + ex.toString());
+ Rlog.e(TAG, "create geo-fencing trigger failed, ex = " + ex.toString());
return null;
}
}
diff --git a/src/com/android/cellbroadcastservice/WakeLockStateMachine.java b/src/com/android/cellbroadcastservice/WakeLockStateMachine.java
index 1874cef..1d08f54 100644
--- a/src/com/android/cellbroadcastservice/WakeLockStateMachine.java
+++ b/src/com/android/cellbroadcastservice/WakeLockStateMachine.java
@@ -16,7 +16,6 @@
package com.android.cellbroadcastservice;
-import android.annotation.UnsupportedAppUsage;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@@ -24,7 +23,7 @@
import android.os.Message;
import android.os.PowerManager;
import android.os.SystemProperties;
-import android.util.Log;
+import android.telephony.Rlog;
import com.android.internal.util.State;
import com.android.internal.util.StateMachine;
@@ -55,7 +54,6 @@
/** Broadcast not required due to geo-fencing check */
static final int EVENT_BROADCAST_NOT_REQUIRED = 4;
- @UnsupportedAppUsage
protected Context mContext;
protected AtomicInteger mReceiverCount = new AtomicInteger(0);
@@ -64,7 +62,6 @@
private static final int WAKE_LOCK_TIMEOUT = 3000;
private final DefaultState mDefaultState = new DefaultState();
- @UnsupportedAppUsage
private final IdleState mIdleState = new IdleState();
private final WaitingState mWaitingState = new WaitingState();
@@ -236,10 +233,9 @@
* Log with debug level.
* @param s the string to log
*/
- @UnsupportedAppUsage
@Override
protected void log(String s) {
- Log.d(getName(), s);
+ Rlog.d(getName(), s);
}
/**
@@ -248,7 +244,7 @@
*/
@Override
protected void loge(String s) {
- Log.e(getName(), s);
+ Rlog.e(getName(), s);
}
/**
@@ -258,6 +254,6 @@
*/
@Override
protected void loge(String s, Throwable e) {
- Log.e(getName(), s, e);
+ Rlog.e(getName(), s, e);
}
}
diff --git a/tests/Android.bp b/tests/Android.bp
index f59dde6..ef9568e 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -15,7 +15,7 @@
],
srcs: ["src/**/*.java", ":cellbroadcast-shared-srcs"],
platform_apis: true,
- test_suites: ["device-tests"],
+ test_suites: ["device-tests", "mts"],
certificate: "platform",
instrumentation_for: "CellBroadcastServiceModule",
}
diff --git a/tests/src/com/android/cellbroadcastservice/tests/CdmaSmsMessageTest.java b/tests/src/com/android/cellbroadcastservice/tests/CdmaSmsMessageTest.java
index 171d437..7e34a40 100644
--- a/tests/src/com/android/cellbroadcastservice/tests/CdmaSmsMessageTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CdmaSmsMessageTest.java
@@ -18,12 +18,12 @@
import android.content.Context;
import android.hardware.radio.V1_0.CdmaSmsMessage;
+import android.telephony.Rlog;
import android.telephony.SmsCbCmasInfo;
import android.telephony.SmsCbMessage;
import android.telephony.cdma.CdmaSmsCbProgramData;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
-import android.util.Log;
import com.android.cellbroadcastservice.BearerData;
import com.android.cellbroadcastservice.DefaultCellBroadcastService;
@@ -650,10 +650,10 @@
//SmsCbMessage cbMessage = msg.parseBroadcastSms("", 0);
// with random input, cbMessage will almost always be null (log when it isn't)
if (cbMessage != null) {
- Log.d(TAG, "success: " + cbMessage);
+ Rlog.d(TAG, "success: " + cbMessage);
}
} catch (Exception e) {
- Log.d(TAG, "exception thrown", e);
+ Rlog.d(TAG, "exception thrown", e);
fail("Exception in decoder at run " + run + " length " + len + ": " + e);
}
}
@@ -686,7 +686,7 @@
msg.getEnvelopeBearerData(), msg.getEnvelopeServiceCategory());
//SmsCbMessage cbMessage = msg.parseBroadcastSms("", 0);
} catch (Exception e) {
- Log.d(TAG, "exception thrown", e);
+ Rlog.d(TAG, "exception thrown", e);
fail("Exception in decoder at run " + run + " length " + len + ": " + e);
}
}
diff --git a/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTest.java b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTest.java
index b5c3faf..b19d55f 100644
--- a/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTest.java
@@ -27,9 +27,9 @@
import android.database.Cursor;
import android.net.Uri;
import android.provider.Telephony.CellBroadcasts;
+import android.telephony.Rlog;
import android.test.mock.MockContentResolver;
import android.test.mock.MockContext;
-import android.util.Log;
import com.android.cellbroadcastservice.CellBroadcastProvider;
import com.android.cellbroadcastservice.CellBroadcastProvider.PermissionChecker;
@@ -325,7 +325,7 @@
@Override
public Object getSystemService(String name) {
- Log.d(TAG, "getSystemService: returning null");
+ Rlog.d(TAG, "getSystemService: returning null");
return null;
}
diff --git a/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTestable.java b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTestable.java
index b50ccb0..06fde6b 100644
--- a/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTestable.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastProviderTestable.java
@@ -20,7 +20,7 @@
import android.content.pm.ProviderInfo;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
-import android.util.Log;
+import android.telephony.Rlog;
import androidx.test.InstrumentationRegistry;
@@ -36,7 +36,7 @@
@Override
public boolean onCreate() {
// DO NOT call super.onCreate(), otherwise the permission checker will be override.
- Log.d(TAG, "CellBroadcastProviderTestable onCreate");
+ Rlog.d(TAG, "CellBroadcastProviderTestable onCreate");
mDbHelper = new InMemoryCellBroadcastProviderDbHelper();
return true;
}
@@ -55,7 +55,7 @@
@Override
public void onCreate(SQLiteDatabase db) {
- Log.d(TAG, "IN MEMORY DB CREATED");
+ Rlog.d(TAG, "IN MEMORY DB CREATED");
db.execSQL(getStringForCellBroadcastTableCreation(CELL_BROADCASTS_TABLE_NAME));
}
diff --git a/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastServiceTestBase.java b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastServiceTestBase.java
index 009986e..c230f2d 100644
--- a/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastServiceTestBase.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/CellBroadcastServiceTestBase.java
@@ -18,6 +18,7 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.eq;
@@ -135,6 +136,7 @@
return null;
}).when(mMockedContext).registerReceiver(
any(BroadcastReceiver.class), any(IntentFilter.class));
+ doReturn(true).when(mMockedLocationManager).isProviderEnabled(anyString());
}
protected void tearDown() throws Exception {
diff --git a/tests/src/com/android/cellbroadcastservice/tests/GsmCellBroadcastHandlerTest.java b/tests/src/com/android/cellbroadcastservice/tests/GsmCellBroadcastHandlerTest.java
index 65f0c4b..1fefbbf 100644
--- a/tests/src/com/android/cellbroadcastservice/tests/GsmCellBroadcastHandlerTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/GsmCellBroadcastHandlerTest.java
@@ -21,6 +21,7 @@
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import android.content.ContentValues;
@@ -28,6 +29,8 @@
import android.content.res.Resources;
import android.database.Cursor;
import android.database.MatrixCursor;
+import android.location.Location;
+import android.location.LocationRequest;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
@@ -52,8 +55,10 @@
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
+import org.mockito.Mockito;
import java.util.Map;
+import java.util.function.Consumer;
@RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper
@@ -168,6 +173,7 @@
@Test
@SmallTest
public void testTriggerMessage() throws Exception {
+ doReturn(false).when(mMockedLocationManager).isProviderEnabled(anyString());
final byte[] pdu = hexStringToBytes("0001113001010010C0111204D2");
mGsmCellBroadcastHandler.onGsmCellBroadcastSms(0, pdu);
mTestableLooper.processAllMessages();
@@ -202,4 +208,27 @@
verify(mMockedContext, never()).sendOrderedBroadcast(any(), anyString(), anyString(),
any(), any(), anyInt(), any(), any());
}
+
+ @Test
+ @SmallTest
+ public void testGeofencingAlertOutOfPolygon() {
+ final byte[] pdu = hexStringToBytes("01111D7090010254747A0E4ACF416110B538A582DE6650906AA28"
+ + "2AE6979995D9ECF41C576597E2EBBC77950905D96D3D3EE33689A9FD3CB6D1708CA2E87E76550FAE"
+ + "C7ECBCB203ABA0C6A97E7F3F0B9EC02C15CB5769A5D0652A030FB1ECECF5D5076393C2F83C8E9B9B"
+ + "C7C0ECBC9203A3A3D07B5CBF379F85C06E16030580D660BB662B51A0D57CC3500000000000000000"
+ + "0000000000000000000000000000000000000000000000000003021002078B53B6CA4B84B53988A4"
+ + "B86B53958A4C2DB53B54A4C28B53B6CA4B840100CFF");
+ mGsmCellBroadcastHandler.onGsmCellBroadcastSms(0, pdu);
+ mTestableLooper.processAllMessages();
+
+ ArgumentCaptor<Consumer<Location>> captor = ArgumentCaptor.forClass(Consumer.class);
+ verify(mMockedLocationManager, times(2)).getCurrentLocation(
+ any(LocationRequest.class), any(), any(), captor.capture());
+
+ Consumer<Location> consumer = captor.getValue();
+ consumer.accept(Mockito.mock(Location.class));
+
+ verify(mMockedContext, never()).sendOrderedBroadcast(any(), anyString(), anyString(),
+ any(), any(), anyInt(), any(), any());
+ }
}
diff --git a/tests/src/com/android/cellbroadcastservice/tests/GsmSmsCbMessageTest.java b/tests/src/com/android/cellbroadcastservice/tests/GsmSmsCbMessageTest.java
index 73820b6..1547a56 100644
--- a/tests/src/com/android/cellbroadcastservice/tests/GsmSmsCbMessageTest.java
+++ b/tests/src/com/android/cellbroadcastservice/tests/GsmSmsCbMessageTest.java
@@ -17,13 +17,13 @@
package com.android.cellbroadcastservice.tests;
import android.telephony.CbGeoUtils;
+import android.telephony.Rlog;
import android.telephony.SmsCbCmasInfo;
import android.telephony.SmsCbEtwsInfo;
import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
-import android.util.Log;
import androidx.test.InstrumentationRegistry;
@@ -77,27 +77,27 @@
String message = GsmSmsCbMessage.getEtwsPrimaryMessage(mMockedContext,
SmsCbEtwsInfo.ETWS_WARNING_TYPE_EARTHQUAKE);
- Log.d("GsmSmsCbMessageTest", "earthquake message=" + message);
+ Rlog.d("GsmSmsCbMessageTest", "earthquake message=" + message);
assertEquals(testMessage1, message);
message = GsmSmsCbMessage.getEtwsPrimaryMessage(mMockedContext,
SmsCbEtwsInfo.ETWS_WARNING_TYPE_TSUNAMI);
- Log.d("GsmSmsCbMessageTest", "tsunami message=" + message);
+ Rlog.d("GsmSmsCbMessageTest", "tsunami message=" + message);
assertEquals(testMessage2, message);
message = GsmSmsCbMessage.getEtwsPrimaryMessage(mMockedContext,
SmsCbEtwsInfo.ETWS_WARNING_TYPE_EARTHQUAKE_AND_TSUNAMI);
- Log.d("GsmSmsCbMessageTest", "earthquake and tsunami message=" + message);
+ Rlog.d("GsmSmsCbMessageTest", "earthquake and tsunami message=" + message);
assertEquals(testMessage3, message);
message = GsmSmsCbMessage.getEtwsPrimaryMessage(mMockedContext,
SmsCbEtwsInfo.ETWS_WARNING_TYPE_TEST_MESSAGE);
- Log.d("GsmSmsCbMessageTest", "test message=" + message);
+ Rlog.d("GsmSmsCbMessageTest", "test message=" + message);
assertEquals(testMessage4, message);
message = GsmSmsCbMessage.getEtwsPrimaryMessage(mMockedContext,
SmsCbEtwsInfo.ETWS_WARNING_TYPE_OTHER_EMERGENCY);
- Log.d("GsmSmsCbMessageTest", "others message=" + message);
+ Rlog.d("GsmSmsCbMessageTest", "others message=" + message);
assertEquals(testMessage5, message);
}
@@ -126,7 +126,7 @@
SmsCbMessage msg = GsmSmsCbMessage.createSmsCbMessage(mMockedContext, header, null, pdus,
0);
- Log.d(TAG, "msg=" + msg);
+ Rlog.d(TAG, "msg=" + msg);
assertEquals(SmsCbMessage.GEOGRAPHICAL_SCOPE_CELL_WIDE_IMMEDIATE,
msg.getGeographicalScope());
@@ -171,7 +171,7 @@
GsmSmsCbMessage.GeoFencingTriggerMessage triggerMessage =
GsmSmsCbMessage.createGeoFencingTriggerMessage(pdu);
- Log.d(TAG, "trigger message=" + triggerMessage);
+ Rlog.d(TAG, "trigger message=" + triggerMessage);
assertEquals(1, triggerMessage.type);
assertEquals(1, triggerMessage.cbIdentifiers.size());
@@ -1013,7 +1013,7 @@
@Test
public void testEtwsMessageNormal() {
SmsCbMessage msg = createFromPdu(etwsMessageNormal);
- Log.d(TAG, msg.toString());
+ Rlog.d(TAG, msg.toString());
assertEquals("GS mismatch", 0, msg.getGeographicalScope());
assertEquals("serial number mismatch", 0, msg.getSerialNumber());
assertEquals("message ID mismatch", 0x1100, msg.getServiceCategory());
@@ -1024,7 +1024,7 @@
@Test
public void testEtwsMessageCancel() {
SmsCbMessage msg = createFromPdu(etwsMessageCancel);
- Log.d(TAG, msg.toString());
+ Rlog.d(TAG, msg.toString());
assertEquals("GS mismatch", 0, msg.getGeographicalScope());
assertEquals("serial number mismatch", 0, msg.getSerialNumber());
assertEquals("message ID mismatch", 0x1100, msg.getServiceCategory());
@@ -1035,7 +1035,7 @@
@Test
public void testEtwsMessageTest() {
SmsCbMessage msg = createFromPdu(etwsMessageTest);
- Log.d(TAG, msg.toString());
+ Rlog.d(TAG, msg.toString());
assertEquals("GS mismatch", 0, msg.getGeographicalScope());
assertEquals("serial number mismatch", 0, msg.getSerialNumber());
assertEquals("message ID mismatch", 0x1103, msg.getServiceCategory());
@@ -1057,7 +1057,7 @@
// this should return a SmsCbMessage object or null for invalid data
SmsCbMessage msg = createFromPdu(data);
} catch (Exception e) {
- Log.d(TAG, "exception thrown", e);
+ Rlog.d(TAG, "exception thrown", e);
fail("Exception in decoder at run " + run + " length " + len + ": " + e);
}
}