Clean up use of hidden APIs
Also update imports of CbGeoUtils
Bug: 135956699
Test: build and run appcompat script
Change-Id: Iabf338fbf9213bcf69cac491ebe13e3437f98f04
diff --git a/src/com/android/cellbroadcastservice/CbGeoUtils.java b/src/com/android/cellbroadcastservice/CbGeoUtils.java
index 292f0f6..0a8fe48 100644
--- a/src/com/android/cellbroadcastservice/CbGeoUtils.java
+++ b/src/com/android/cellbroadcastservice/CbGeoUtils.java
@@ -17,11 +17,10 @@
package com.android.cellbroadcastservice;
import android.annotation.NonNull;
-import android.telephony.Rlog;
+import android.telephony.CbGeoUtils.Geometry;
+import android.telephony.CbGeoUtils.LatLng;
import android.text.TextUtils;
-
-import com.android.internal.telephony.CbGeoUtils.Geometry;
-import com.android.internal.telephony.CbGeoUtils.LatLng;
+import android.util.Log;
import java.util.ArrayList;
import java.util.List;
@@ -54,7 +53,7 @@
/**
* The class represents a simple polygon with at least 3 points.
*/
- public static class Polygon implements com.android.internal.telephony.CbGeoUtils.Geometry {
+ public static class Polygon implements Geometry {
/**
* In order to reduce the loss of precision in floating point calculations, all vertices
* of the polygon are scaled. Set the value of scale to 1000 can take into account the
@@ -232,7 +231,7 @@
geometries.add(new Polygon(vertices));
break;
default:
- Rlog.e(TAG, "Invalid geometry format " + geometryStr);
+ Log.e(TAG, "Invalid geometry format " + geometryStr);
}
}
return geometries;
@@ -285,7 +284,7 @@
sb.append("|");
sb.append(circle.getRadius());
} else {
- Rlog.e(TAG, "Unsupported geometry object " + geometry);
+ Log.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 2542b4d..008663c 100644
--- a/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
+++ b/src/com/android/cellbroadcastservice/CellBroadcastHandler.java
@@ -47,6 +47,8 @@
import android.provider.Settings;
import android.provider.Telephony;
import android.provider.Telephony.CellBroadcasts;
+import android.telephony.CbGeoUtils.Geometry;
+import android.telephony.CbGeoUtils.LatLng;
import android.telephony.SmsCbMessage;
import android.telephony.SubscriptionManager;
import android.telephony.cdma.CdmaSmsCbProgramData;
@@ -55,8 +57,6 @@
import android.util.Log;
import com.android.internal.annotations.VisibleForTesting;
-import com.android.internal.telephony.CbGeoUtils.Geometry;
-import com.android.internal.telephony.CbGeoUtils.LatLng;
import com.android.internal.telephony.metrics.TelephonyMetrics;
import java.io.FileDescriptor;
@@ -275,7 +275,7 @@
} else {
performGeoFencing(message, uri, message.getGeometries(), location, slotIndex);
}
- }, message.getMaximumWaitingTime());
+ }, message.getMaximumWaitingDuration());
} else {
if (DBG) {
log("Broadcast the message directly because no geo-fencing required, "
@@ -436,6 +436,24 @@
}
/**
+ * Get the subscription ID for a phone ID, or INVALID_SUBSCRIPTION_ID if the phone does not
+ * have an active sub
+ * @param phoneId the phoneId to use
+ * @return the associated sub id
+ */
+ protected int getSubIdForPhone(int phoneId) {
+ SubscriptionManager subMan =
+ (SubscriptionManager) mContext.getSystemService(
+ Context.TELEPHONY_SUBSCRIPTION_SERVICE);
+ int[] subIds = subMan.getSubscriptionIds(phoneId);
+ if (subIds != null) {
+ return subIds[0];
+ } else {
+ return SubscriptionManager.INVALID_SUBSCRIPTION_ID;
+ }
+ }
+
+ /**
* Broadcast the {@code message} to the applications.
* @param message a message need to broadcast
* @param messageUri message's uri
@@ -457,9 +475,15 @@
appOp = AppOpsManager.OP_RECEIVE_EMERGECY_SMS;
intent.putExtra(EXTRA_MESSAGE, message);
- SubscriptionManager.putPhoneIdAndSubIdExtra(intent, slotIndex);
+ int subId = getSubIdForPhone(slotIndex);
+ if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
+ intent.putExtra("subscription", subId);
+ intent.putExtra(SubscriptionManager.EXTRA_SUBSCRIPTION_INDEX, subId);
+ }
+ intent.putExtra("phone", slotIndex);
+ intent.putExtra(SubscriptionManager.EXTRA_SLOT_INDEX, slotIndex);
- if (Build.IS_DEBUGGABLE) {
+ if (IS_DEBUGGABLE) {
// Send additional broadcast intent to the specified package. This is only for sl4a
// automation tests.
final String additionalPackage = Settings.Secure.getString(
@@ -480,7 +504,7 @@
// Explicitly send the intent to all the configured cell broadcast receivers.
intent.setPackage(pkg);
mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, receiverPermission,
- appOp, mReceiver, getHandler(), Activity.RESULT_OK, null, null);
+ appOp, null, mReceiver, getHandler(), Activity.RESULT_OK, null, null);
}
} else {
msg = "Dispatching SMS CB, SmsCbMessage is: " + message;
@@ -497,8 +521,8 @@
SubscriptionManager.putPhoneIdAndSubIdExtra(intent, slotIndex);
mReceiverCount.incrementAndGet();
- mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, receiverPermission, appOp,
- mReceiver, getHandler(), Activity.RESULT_OK, null, null);
+ mContext.sendOrderedBroadcastAsUser(intent, UserHandle.ALL, receiverPermission,
+ appOp, null, mReceiver, getHandler(), Activity.RESULT_OK, null, null);
}
if (messageUri != null) {
diff --git a/src/com/android/cellbroadcastservice/GsmCellBroadcastHandler.java b/src/com/android/cellbroadcastservice/GsmCellBroadcastHandler.java
index 1a5ed14..6838497 100644
--- a/src/com/android/cellbroadcastservice/GsmCellBroadcastHandler.java
+++ b/src/com/android/cellbroadcastservice/GsmCellBroadcastHandler.java
@@ -25,17 +25,18 @@
import android.net.Uri;
import android.os.Message;
import android.provider.Telephony.CellBroadcasts;
+import android.telephony.CbGeoUtils.Geometry;
+import android.telephony.CellIdentity;
+import android.telephony.CellIdentityGsm;
import android.telephony.CellInfo;
-import android.telephony.CellLocation;
import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.telephony.TelephonyManager;
-import android.telephony.gsm.GsmCellLocation;
import android.text.format.DateUtils;
+import android.util.Pair;
import com.android.cellbroadcastservice.GsmSmsCbMessage.GeoFencingTriggerMessage;
import com.android.cellbroadcastservice.GsmSmsCbMessage.GeoFencingTriggerMessage.CellBroadcastIdentity;
-import com.android.internal.telephony.CbGeoUtils.Geometry;
import dalvik.annotation.compat.UnsupportedAppUsage;
@@ -141,7 +142,7 @@
// cell broadcasts.
int maximumWaitTimeSec = 0;
for (SmsCbMessage msg : cbMessages) {
- maximumWaitTimeSec = Math.max(maximumWaitTimeSec, msg.getMaximumWaitingTime());
+ maximumWaitTimeSec = Math.max(maximumWaitTimeSec, msg.getMaximumWaitingDuration());
}
if (DBG) {
@@ -214,22 +215,21 @@
return super.handleSmsMessage(message);
}
- // return the cell location from the first returned cell info, prioritizing GSM
- private CellLocation getCellLocation() {
+ // return the GSM cell location from the first GSM cell info
+ private Pair<Integer, Integer> getGsmLacAndCid() {
TelephonyManager tm =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
List<CellInfo> infos = tm.getAllCellInfo();
for (CellInfo info : infos) {
- CellLocation cl = info.getCellIdentity().asCellLocation();
- if (cl instanceof GsmCellLocation) {
- return cl;
+ CellIdentity ci = info.getCellIdentity();
+ if (ci instanceof CellIdentityGsm) {
+ CellIdentityGsm ciGsm = (CellIdentityGsm) ci;
+ int lac = ciGsm.getLac() != CellInfo.UNAVAILABLE ? ciGsm.getLac() : -1;
+ int cid = ciGsm.getCid() != CellInfo.UNAVAILABLE ? ciGsm.getCid() : -1;
+ return Pair.create(lac, cid);
}
}
- // If no GSM, return first in list
- if (infos != null && !infos.isEmpty() && infos.get(0) != null) {
- return infos.get(0).getCellIdentity().asCellLocation();
- }
- return CellLocation.getEmpty();
+ return null;
}
@@ -259,18 +259,18 @@
if (VDBG) log("header=" + header);
TelephonyManager tm =
(TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
+ tm.createForSubscriptionId(getSubIdForPhone(slotIndex));
// TODO make a systemAPI for getNetworkOperatorForSlotIndex
- String plmn = tm.getNetworkOperatorForPhone(slotIndex);
+ String plmn = tm.getSimOperator();
int lac = -1;
int cid = -1;
- CellLocation cl = getCellLocation();
- // Check if cell location is GsmCellLocation. This is required to support
+ Pair<Integer, Integer> lacAndCid = getGsmLacAndCid();
+ // Check if GSM lac and cid are available. This is required to support
// dual-mode devices such as CDMA/LTE devices that require support for
// both 3GPP and 3GPP2 format messages
- if (cl instanceof GsmCellLocation) {
- GsmCellLocation cellLocation = (GsmCellLocation) cl;
- lac = cellLocation.getLac();
- cid = cellLocation.getCid();
+ if (lacAndCid != null) {
+ lac = lacAndCid.first;
+ cid = lacAndCid.second;
}
SmsCbLocation location;
diff --git a/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java b/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
index cd2d964..c0ded3b 100644
--- a/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
+++ b/src/com/android/cellbroadcastservice/GsmSmsCbMessage.java
@@ -25,6 +25,8 @@
import android.annotation.NonNull;
import android.content.Context;
import android.content.res.Resources;
+import android.telephony.CbGeoUtils.Geometry;
+import android.telephony.CbGeoUtils.LatLng;
import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage;
import android.util.Pair;
@@ -35,8 +37,6 @@
import com.android.cellbroadcastservice.GsmSmsCbMessage.GeoFencingTriggerMessage.CellBroadcastIdentity;
import com.android.cellbroadcastservice.SmsCbHeader.DataCodingScheme;
import com.android.internal.R;
-import com.android.internal.telephony.CbGeoUtils.Geometry;
-import com.android.internal.telephony.CbGeoUtils.LatLng;
import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.SmsConstants;
diff --git a/src/com/android/cellbroadcastservice/WakeLockStateMachine.java b/src/com/android/cellbroadcastservice/WakeLockStateMachine.java
index 99b935c..edb392e 100644
--- a/src/com/android/cellbroadcastservice/WakeLockStateMachine.java
+++ b/src/com/android/cellbroadcastservice/WakeLockStateMachine.java
@@ -20,9 +20,9 @@
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.os.Build;
import android.os.Message;
import android.os.PowerManager;
+import android.os.SystemProperties;
import android.util.Log;
import com.android.internal.util.State;
@@ -38,7 +38,7 @@
* {@link #quit}.
*/
public abstract class WakeLockStateMachine extends StateMachine {
- protected static final boolean DBG = Build.IS_DEBUGGABLE;
+ protected static final boolean DBG = SystemProperties.getInt("ro.debuggable", 0) == 1;
private final PowerManager.WakeLock mWakeLock;
@@ -123,7 +123,7 @@
switch (msg.what) {
default: {
String errorText = "processMessage: unhandled message type " + msg.what;
- if (Build.IS_DEBUGGABLE) {
+ if (DBG) {
throw new RuntimeException(errorText);
} else {
loge(errorText);