From 9fe25438f0b4c95bc7231f405f3966fd1d1764e1 Mon Sep 17 00:00:00 2001 From: Nagendra Prasad Nagarle Basavaraju Date: Tue, 11 Oct 2022 12:32:13 +0000 Subject: [PATCH] Expose Country & CountryDetector API's To Support new mainline module expose getCountryIso, getSource,addCountryListener,detectCountry API's as System API Bug: 252989268 CTS-Coverage-Bug: 255511190 Test: manual test && make update-api Change-Id: I6c4b2980ee04e56e8d0bb9ddda0391e3e23ada7e --- core/api/system-current.txt | 22 +++++++++++++ core/api/system-lint-baseline.txt | 6 ++++ location/java/android/location/Country.java | 33 ++++++++++++++----- .../android/location/CountryDetector.java | 12 ++++--- .../android/location/CountryListener.java | 8 +++-- 5 files changed, 64 insertions(+), 17 deletions(-) diff --git a/core/api/system-current.txt b/core/api/system-current.txt index a382ecfc99d31..94f4da2a22ba8 100644 --- a/core/api/system-current.txt +++ b/core/api/system-current.txt @@ -5552,6 +5552,28 @@ package android.location { method @NonNull public android.location.CorrelationVector.Builder setSamplingWidthMeters(@FloatRange(from=0.0f, fromInclusive=false) double); } + public final class Country implements android.os.Parcelable { + method public int describeContents(); + method @NonNull public String getCountryIso(); + method public int getSource(); + method public void writeToParcel(@NonNull android.os.Parcel, int); + field public static final int COUNTRY_SOURCE_LOCALE = 3; // 0x3 + field public static final int COUNTRY_SOURCE_LOCATION = 1; // 0x1 + field public static final int COUNTRY_SOURCE_NETWORK = 0; // 0x0 + field public static final int COUNTRY_SOURCE_SIM = 2; // 0x2 + field @NonNull public static final android.os.Parcelable.Creator CREATOR; + } + + public class CountryDetector { + method public void addCountryListener(@NonNull android.location.CountryListener, @Nullable android.os.Looper); + method @Nullable public android.location.Country detectCountry(); + method public void removeCountryListener(@NonNull android.location.CountryListener); + } + + public interface CountryListener { + method public void onCountryDetected(@NonNull android.location.Country); + } + public final class GnssCapabilities implements android.os.Parcelable { method @Deprecated public boolean hasMeasurementCorrectionsReflectingPane(); method @Deprecated public boolean hasNavMessages(); diff --git a/core/api/system-lint-baseline.txt b/core/api/system-lint-baseline.txt index 025e8629fc207..47588d97fdbf3 100644 --- a/core/api/system-lint-baseline.txt +++ b/core/api/system-lint-baseline.txt @@ -3,6 +3,10 @@ ArrayReturn: android.view.contentcapture.ViewNode#getAutofillOptions(): Method should return Collection (or subclass) instead of raw array; was `java.lang.CharSequence[]` +ExecutorRegistration: android.location.CountryDetector#addCountryListener(android.location.CountryListener, android.os.Looper): + Registration methods should have overload that accepts delivery Executor: `addCountryListener` + + GenericException: android.app.prediction.AppPredictor#finalize(): Methods must not throw generic exceptions (`java.lang.Throwable`) GenericException: android.hardware.location.ContextHubClient#finalize(): @@ -127,6 +131,8 @@ SamShouldBeLast: android.content.pm.PackageItemInfo#dumpFront(android.util.Print SAM-compatible parameters (such as parameter 1, "pw", in android.content.pm.PackageItemInfo.dumpFront) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions SamShouldBeLast: android.content.pm.ResolveInfo#dump(android.util.Printer, String): SAM-compatible parameters (such as parameter 1, "pw", in android.content.pm.ResolveInfo.dump) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions +SamShouldBeLast: android.location.CountryDetector#addCountryListener(android.location.CountryListener, android.os.Looper): + SAM-compatible parameters (such as parameter 1, "listener", in android.location.CountryDetector.addCountryListener) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions SamShouldBeLast: android.location.Location#dump(android.util.Printer, String): SAM-compatible parameters (such as parameter 1, "pw", in android.location.Location.dump) should be last to improve Kotlin interoperability; see https://kotlinlang.org/docs/reference/java-interop.html#sam-conversions SamShouldBeLast: android.location.LocationManager#addNmeaListener(android.location.OnNmeaMessageListener, android.os.Handler): diff --git a/location/java/android/location/Country.java b/location/java/android/location/Country.java index 8c40338e80fca..8e1bb1f0a9b33 100644 --- a/location/java/android/location/Country.java +++ b/location/java/android/location/Country.java @@ -16,6 +16,9 @@ package android.location; +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SystemApi; import android.compat.annotation.UnsupportedAppUsage; import android.os.Parcel; import android.os.Parcelable; @@ -28,7 +31,8 @@ import java.util.Locale; * * @hide */ -public class Country implements Parcelable { +@SystemApi(client = SystemApi.Client.PRIVILEGED_APPS) +public final class Country implements Parcelable { /** * The country code came from the mobile network */ @@ -78,6 +82,8 @@ public class Country implements Parcelable { *
  • {@link #COUNTRY_SOURCE_SIM}
  • *
  • {@link #COUNTRY_SOURCE_LOCALE}
  • * + * + * @hide */ @UnsupportedAppUsage public Country(final String countryIso, final int source) { @@ -100,6 +106,7 @@ public class Country implements Parcelable { mTimestamp = timestamp; } + /** @hide */ public Country(Country country) { mCountryIso = country.mCountryIso; mSource = country.mSource; @@ -109,8 +116,8 @@ public class Country implements Parcelable { /** * @return the ISO 3166-1 two letters country code */ - @UnsupportedAppUsage - public final String getCountryIso() { + @NonNull + public String getCountryIso() { return mCountryIso; } @@ -124,20 +131,22 @@ public class Country implements Parcelable { *
  • {@link #COUNTRY_SOURCE_LOCALE}
  • * */ - @UnsupportedAppUsage - public final int getSource() { + public int getSource() { return mSource; } /** * Returns the time that this object was created (which we assume to be the time that the source * was consulted). + * + * @hide */ - public final long getTimestamp() { + public long getTimestamp() { return mTimestamp; } - public static final @android.annotation.NonNull Parcelable.Creator CREATOR = new Parcelable.Creator() { + @android.annotation.NonNull + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public Country createFromParcel(Parcel in) { return new Country(in.readString(), in.readInt(), in.readLong()); } @@ -147,11 +156,13 @@ public class Country implements Parcelable { } }; + @Override public int describeContents() { return 0; } - public void writeToParcel(Parcel parcel, int flags) { + @Override + public void writeToParcel(@NonNull Parcel parcel, int flags) { parcel.writeString(mCountryIso); parcel.writeInt(mSource); parcel.writeLong(mTimestamp); @@ -161,9 +172,10 @@ public class Country implements Parcelable { * Returns true if this {@link Country} is equivalent to the given object. This ignores * the timestamp value and just checks for equivalence of countryIso and source values. * Returns false otherwise. + * */ @Override - public boolean equals(Object object) { + public boolean equals(@Nullable Object object) { if (object == this) { return true; } @@ -194,12 +206,15 @@ public class Country implements Parcelable { * @param country the country to compare * @return true if the specified country's countryIso field is equal to this * country's, false otherwise. + * + * @hide */ public boolean equalsIgnoreSource(Country country) { return country != null && mCountryIso.equals(country.getCountryIso()); } @Override + @NonNull public String toString() { return "Country {ISO=" + mCountryIso + ", source=" + mSource + ", time=" + mTimestamp + "}"; } diff --git a/location/java/android/location/CountryDetector.java b/location/java/android/location/CountryDetector.java index e344b820ca2af..3a0edfc571938 100644 --- a/location/java/android/location/CountryDetector.java +++ b/location/java/android/location/CountryDetector.java @@ -16,6 +16,9 @@ package android.location; +import android.annotation.NonNull; +import android.annotation.Nullable; +import android.annotation.SystemApi; import android.annotation.SystemService; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; @@ -47,6 +50,7 @@ import java.util.HashMap; * * @hide */ +@SystemApi(client = SystemApi.Client.PRIVILEGED_APPS) @SystemService(Context.COUNTRY_DETECTOR) public class CountryDetector { @@ -101,7 +105,7 @@ public class CountryDetector { * @return the country if it is available immediately, otherwise null will * be returned. */ - @UnsupportedAppUsage + @Nullable public Country detectCountry() { try { return mService.detectCountry(); @@ -120,8 +124,7 @@ public class CountryDetector { * implement the callback mechanism. If looper is null then the * callbacks will be called on the main thread. */ - @UnsupportedAppUsage - public void addCountryListener(CountryListener listener, Looper looper) { + public void addCountryListener(@NonNull CountryListener listener, @Nullable Looper looper) { synchronized (mListeners) { if (!mListeners.containsKey(listener)) { ListenerTransport transport = new ListenerTransport(listener, looper); @@ -138,8 +141,7 @@ public class CountryDetector { /** * Remove the listener */ - @UnsupportedAppUsage - public void removeCountryListener(CountryListener listener) { + public void removeCountryListener(@NonNull CountryListener listener) { synchronized (mListeners) { ListenerTransport transport = mListeners.get(listener); if (transport != null) { diff --git a/location/java/android/location/CountryListener.java b/location/java/android/location/CountryListener.java index eb67205f4de98..5c06d8239c236 100644 --- a/location/java/android/location/CountryListener.java +++ b/location/java/android/location/CountryListener.java @@ -16,7 +16,8 @@ package android.location; -import android.compat.annotation.UnsupportedAppUsage; +import android.annotation.NonNull; +import android.annotation.SystemApi; /** * The listener for receiving the notification when the country is detected or @@ -24,10 +25,11 @@ import android.compat.annotation.UnsupportedAppUsage; * * @hide */ +@SystemApi(client = SystemApi.Client.PRIVILEGED_APPS) public interface CountryListener { /** * @param country the changed or detected country. + * */ - @UnsupportedAppUsage - void onCountryDetected(Country country); + void onCountryDetected(@NonNull Country country); }