Merge "Expose Geometry, LatLng, and maxWaitDuration"

This commit is contained in:
Jordan Liu
2019-11-19 20:55:36 +00:00
committed by Gerrit Code Review
4 changed files with 60 additions and 19 deletions

View File

@@ -7314,6 +7314,21 @@ package android.telephony {
method @NonNull public android.telephony.CarrierRestrictionRules.Builder setMultiSimPolicy(int); method @NonNull public android.telephony.CarrierRestrictionRules.Builder setMultiSimPolicy(int);
} }
public class CbGeoUtils {
}
public static interface CbGeoUtils.Geometry {
method public boolean contains(@NonNull android.telephony.CbGeoUtils.LatLng);
}
public static class CbGeoUtils.LatLng {
ctor public CbGeoUtils.LatLng(double, double);
method public double distance(@NonNull android.telephony.CbGeoUtils.LatLng);
method @NonNull public android.telephony.CbGeoUtils.LatLng subtract(@NonNull android.telephony.CbGeoUtils.LatLng);
field public final double lat;
field public final double lng;
}
public abstract class CellBroadcastService extends android.app.Service { public abstract class CellBroadcastService extends android.app.Service {
ctor public CellBroadcastService(); ctor public CellBroadcastService();
method @CallSuper @NonNull public android.os.IBinder onBind(@Nullable android.content.Intent); method @CallSuper @NonNull public android.os.IBinder onBind(@Nullable android.content.Intent);
@@ -8126,6 +8141,7 @@ package android.telephony {
method public int getGeographicalScope(); method public int getGeographicalScope();
method @Nullable public String getLanguageCode(); method @Nullable public String getLanguageCode();
method @NonNull public android.telephony.SmsCbLocation getLocation(); method @NonNull public android.telephony.SmsCbLocation getLocation();
method public int getMaximumWaitingDuration();
method @Nullable public String getMessageBody(); method @Nullable public String getMessageBody();
method public int getMessageFormat(); method public int getMessageFormat();
method public int getMessagePriority(); method public int getMessagePriority();

View File

@@ -14,10 +14,10 @@
* limitations under the License. * limitations under the License.
*/ */
package com.android.internal.telephony; package android.telephony;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.telephony.Rlog; import android.annotation.SystemApi;
import android.text.TextUtils; import android.text.TextUtils;
import java.util.ArrayList; import java.util.ArrayList;
@@ -30,8 +30,17 @@ import java.util.stream.Collectors;
* The coordinates used by this utils class are latitude and longitude, but some algorithms in this * The coordinates used by this utils class are latitude and longitude, but some algorithms in this
* class only use them as coordinates on plane, so the calculation will be inaccurate. So don't use * class only use them as coordinates on plane, so the calculation will be inaccurate. So don't use
* this class for anything other then geo-targeting of cellbroadcast messages. * this class for anything other then geo-targeting of cellbroadcast messages.
* @hide
*/ */
@SystemApi
public class CbGeoUtils { public class CbGeoUtils {
/**
* This class is never instantiated
* @hide
*/
private CbGeoUtils() {}
/** Geometric interface. */ /** Geometric interface. */
public interface Geometry { public interface Geometry {
/** /**
@@ -39,27 +48,36 @@ public class CbGeoUtils {
* @param p point in latitude, longitude format. * @param p point in latitude, longitude format.
* @return {@code True} if the given point is inside the geometry. * @return {@code True} if the given point is inside the geometry.
*/ */
boolean contains(LatLng p); boolean contains(@NonNull LatLng p);
} }
/** /**
* Tolerance for determining if the value is 0. If the absolute value of a value is less than * Tolerance for determining if the value is 0. If the absolute value of a value is less than
* this tolerance, it will be treated as 0. * this tolerance, it will be treated as 0.
* @hide
*/ */
public static final double EPS = 1e-7; public static final double EPS = 1e-7;
/** The radius of earth. */ /**
* The radius of earth.
* @hide
*/
public static final int EARTH_RADIUS_METER = 6371 * 1000; public static final int EARTH_RADIUS_METER = 6371 * 1000;
private static final String TAG = "CbGeoUtils"; private static final String TAG = "CbGeoUtils";
/** The TLV tags of WAC, defined in ATIS-0700041 5.2.3 WAC tag coding. */ // The TLV tags of WAC, defined in ATIS-0700041 5.2.3 WAC tag coding.
/** @hide */
public static final int GEO_FENCING_MAXIMUM_WAIT_TIME = 0x01; public static final int GEO_FENCING_MAXIMUM_WAIT_TIME = 0x01;
/** @hide */
public static final int GEOMETRY_TYPE_POLYGON = 0x02; public static final int GEOMETRY_TYPE_POLYGON = 0x02;
/** @hide */
public static final int GEOMETRY_TYPE_CIRCLE = 0x03; public static final int GEOMETRY_TYPE_CIRCLE = 0x03;
/** The identifier of geometry in the encoded string. */ // The identifier of geometry in the encoded string.
/** @hide */
private static final String CIRCLE_SYMBOL = "circle"; private static final String CIRCLE_SYMBOL = "circle";
/** @hide */
private static final String POLYGON_SYMBOL = "polygon"; private static final String POLYGON_SYMBOL = "polygon";
/** Point represent by (latitude, longitude). */ /** Point represent by (latitude, longitude). */
@@ -81,7 +99,8 @@ public class CbGeoUtils {
* @param p the point use to calculate the subtraction result. * @param p the point use to calculate the subtraction result.
* @return the result of this point subtract the given point {@code p}. * @return the result of this point subtract the given point {@code p}.
*/ */
public LatLng subtract(LatLng p) { @NonNull
public LatLng subtract(@NonNull LatLng p) {
return new LatLng(lat - p.lat, lng - p.lng); return new LatLng(lat - p.lat, lng - p.lng);
} }
@@ -90,7 +109,7 @@ public class CbGeoUtils {
* @param p the point use to calculate the distance. * @param p the point use to calculate the distance.
* @return the distance in meter. * @return the distance in meter.
*/ */
public double distance(LatLng p) { public double distance(@NonNull LatLng p) {
double dlat = Math.sin(0.5 * Math.toRadians(lat - p.lat)); double dlat = Math.sin(0.5 * Math.toRadians(lat - p.lat));
double dlng = Math.sin(0.5 * Math.toRadians(lng - p.lng)); double dlng = Math.sin(0.5 * Math.toRadians(lng - p.lng));
double x = dlat * dlat double x = dlat * dlat
@@ -106,6 +125,7 @@ public class CbGeoUtils {
/** /**
* The class represents a simple polygon with at least 3 points. * The class represents a simple polygon with at least 3 points.
* @hide
*/ */
public static class Polygon implements Geometry { public static class Polygon implements Geometry {
/** /**
@@ -239,7 +259,10 @@ public class CbGeoUtils {
} }
} }
/** The class represents a circle. */ /**
* The class represents a circle.
* @hide
*/
public static class Circle implements Geometry { public static class Circle implements Geometry {
private final LatLng mCenter; private final LatLng mCenter;
private final double mRadiusMeter; private final double mRadiusMeter;
@@ -266,6 +289,7 @@ public class CbGeoUtils {
/** /**
* Parse the geometries from the encoded string {@code str}. The string must follow the * Parse the geometries from the encoded string {@code str}. The string must follow the
* geometry encoding specified by {@link android.provider.Telephony.CellBroadcasts#GEOMETRIES}. * geometry encoding specified by {@link android.provider.Telephony.CellBroadcasts#GEOMETRIES}.
* @hide
*/ */
@NonNull @NonNull
public static List<Geometry> parseGeometriesFromString(@NonNull String str) { public static List<Geometry> parseGeometriesFromString(@NonNull String str) {
@@ -297,6 +321,7 @@ public class CbGeoUtils {
* *
* @param geometries the list of geometry objects need to be encoded. * @param geometries the list of geometry objects need to be encoded.
* @return the encoded string. * @return the encoded string.
* @hide
*/ */
@NonNull @NonNull
public static String encodeGeometriesToString(List<Geometry> geometries) { public static String encodeGeometriesToString(List<Geometry> geometries) {
@@ -313,6 +338,7 @@ public class CbGeoUtils {
* {@link android.provider.Telephony.CellBroadcasts#GEOMETRIES}. * {@link android.provider.Telephony.CellBroadcasts#GEOMETRIES}.
* @param geometry the geometry object need to be encoded. * @param geometry the geometry object need to be encoded.
* @return the encoded string. * @return the encoded string.
* @hide
*/ */
@NonNull @NonNull
private static String encodeGeometryToString(@NonNull Geometry geometry) { private static String encodeGeometryToString(@NonNull Geometry geometry) {
@@ -351,6 +377,7 @@ public class CbGeoUtils {
* *
* @param str encoded lat/lng string. * @param str encoded lat/lng string.
* @Return {@link LatLng} object. * @Return {@link LatLng} object.
* @hide
*/ */
@NonNull @NonNull
public static LatLng parseLatLngFromString(@NonNull String str) { public static LatLng parseLatLngFromString(@NonNull String str) {
@@ -361,6 +388,7 @@ public class CbGeoUtils {
/** /**
* @Return the sign of the given value {@code value} with the specified tolerance. Return 1 * @Return the sign of the given value {@code value} with the specified tolerance. Return 1
* means the sign is positive, -1 means negative, 0 means the value will be treated as 0. * means the sign is positive, -1 means negative, 0 means the value will be treated as 0.
* @hide
*/ */
public static int sign(double value) { public static int sign(double value) {
if (value > EPS) return 1; if (value > EPS) return 1;

View File

@@ -25,9 +25,7 @@ import android.database.Cursor;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.provider.Telephony.CellBroadcasts; import android.provider.Telephony.CellBroadcasts;
import android.telephony.CbGeoUtils.Geometry;
import com.android.internal.telephony.CbGeoUtils;
import com.android.internal.telephony.CbGeoUtils.Geometry;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
@@ -414,9 +412,8 @@ public final class SmsCbMessage implements Parcelable {
/** /**
* Get the Geo-Fencing Maximum Wait Time. * Get the Geo-Fencing Maximum Wait Time.
* @return the time in second. * @return the time in second.
* @hide
*/ */
public int getMaximumWaitingTime() { public int getMaximumWaitingDuration() {
return mMaximumWaitTimeSec; return mMaximumWaitTimeSec;
} }

View File

@@ -25,17 +25,17 @@ import static android.telephony.SmsCbEtwsInfo.ETWS_WARNING_TYPE_TSUNAMI;
import android.annotation.NonNull; import android.annotation.NonNull;
import android.content.Context; import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.telephony.CbGeoUtils;
import android.telephony.CbGeoUtils.Circle;
import android.telephony.CbGeoUtils.Geometry;
import android.telephony.CbGeoUtils.LatLng;
import android.telephony.CbGeoUtils.Polygon;
import android.telephony.SmsCbLocation; import android.telephony.SmsCbLocation;
import android.telephony.SmsCbMessage; import android.telephony.SmsCbMessage;
import android.util.Pair; import android.util.Pair;
import android.util.Slog; import android.util.Slog;
import com.android.internal.R; import com.android.internal.R;
import com.android.internal.telephony.CbGeoUtils;
import com.android.internal.telephony.CbGeoUtils.Circle;
import com.android.internal.telephony.CbGeoUtils.Geometry;
import com.android.internal.telephony.CbGeoUtils.LatLng;
import com.android.internal.telephony.CbGeoUtils.Polygon;
import com.android.internal.telephony.GsmAlphabet; import com.android.internal.telephony.GsmAlphabet;
import com.android.internal.telephony.SmsConstants; import com.android.internal.telephony.SmsConstants;
import com.android.internal.telephony.gsm.GsmSmsCbMessage.GeoFencingTriggerMessage.CellBroadcastIdentity; import com.android.internal.telephony.gsm.GsmSmsCbMessage.GeoFencingTriggerMessage.CellBroadcastIdentity;