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
This commit is contained in:
Nagendra Prasad Nagarle Basavaraju
2022-10-11 12:32:13 +00:00
parent 108bb600d4
commit 9fe25438f0
5 changed files with 64 additions and 17 deletions

View File

@@ -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<android.location.Country> 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();

View File

@@ -3,6 +3,10 @@ ArrayReturn: android.view.contentcapture.ViewNode#getAutofillOptions():
Method should return Collection<CharSequence> (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):

View File

@@ -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 {
* <li>{@link #COUNTRY_SOURCE_SIM}</li>
* <li>{@link #COUNTRY_SOURCE_LOCALE}</li>
* </ul>
*
* @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 {
* <li>{@link #COUNTRY_SOURCE_LOCALE}</li>
* </ul>
*/
@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<Country> CREATOR = new Parcelable.Creator<Country>() {
@android.annotation.NonNull
public static final Parcelable.Creator<Country> CREATOR = new Parcelable.Creator<Country>() {
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 + "}";
}

View File

@@ -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) {

View File

@@ -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);
}