Merge "Cleanup and add public wrapper for IGeocodeProvider interface to prepare for network location unbundling."
This commit is contained in:
committed by
Android (Google) Code Review
commit
5ef58f6d0f
125
api/current.xml
125
api/current.xml
@@ -74882,6 +74882,75 @@
|
||||
</exception>
|
||||
</method>
|
||||
</class>
|
||||
<class name="GeocoderParams"
|
||||
extends="java.lang.Object"
|
||||
abstract="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<implements name="android.os.Parcelable">
|
||||
</implements>
|
||||
<method name="describeContents"
|
||||
return="int"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getClientPackage"
|
||||
return="java.lang.String"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="getLocale"
|
||||
return="java.util.Locale"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</method>
|
||||
<method name="writeToParcel"
|
||||
return="void"
|
||||
abstract="false"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="parcel" type="android.os.Parcel">
|
||||
</parameter>
|
||||
<parameter name="flags" type="int">
|
||||
</parameter>
|
||||
</method>
|
||||
<field name="CREATOR"
|
||||
type="android.os.Parcelable.Creator"
|
||||
transient="false"
|
||||
volatile="false"
|
||||
static="true"
|
||||
final="true"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
</field>
|
||||
</class>
|
||||
<class name="GpsSatellite"
|
||||
extends="java.lang.Object"
|
||||
abstract="false"
|
||||
@@ -76181,6 +76250,62 @@
|
||||
>
|
||||
</field>
|
||||
</class>
|
||||
<interface name="LocationManager.GeocodeProvider"
|
||||
abstract="true"
|
||||
static="true"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<method name="getFromLocation"
|
||||
return="java.lang.String"
|
||||
abstract="true"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="latitude" type="double">
|
||||
</parameter>
|
||||
<parameter name="longitude" type="double">
|
||||
</parameter>
|
||||
<parameter name="maxResults" type="int">
|
||||
</parameter>
|
||||
<parameter name="params" type="android.location.GeocoderParams">
|
||||
</parameter>
|
||||
<parameter name="addrs" type="java.util.List<android.location.Address>">
|
||||
</parameter>
|
||||
</method>
|
||||
<method name="getFromLocationName"
|
||||
return="java.lang.String"
|
||||
abstract="true"
|
||||
native="false"
|
||||
synchronized="false"
|
||||
static="false"
|
||||
final="false"
|
||||
deprecated="not deprecated"
|
||||
visibility="public"
|
||||
>
|
||||
<parameter name="locationName" type="java.lang.String">
|
||||
</parameter>
|
||||
<parameter name="lowerLeftLatitude" type="double">
|
||||
</parameter>
|
||||
<parameter name="lowerLeftLongitude" type="double">
|
||||
</parameter>
|
||||
<parameter name="upperRightLatitude" type="double">
|
||||
</parameter>
|
||||
<parameter name="upperRightLongitude" type="double">
|
||||
</parameter>
|
||||
<parameter name="maxResults" type="int">
|
||||
</parameter>
|
||||
<parameter name="params" type="android.location.GeocoderParams">
|
||||
</parameter>
|
||||
<parameter name="addrs" type="java.util.List<android.location.Address>">
|
||||
</parameter>
|
||||
</method>
|
||||
</interface>
|
||||
<class name="LocationProvider"
|
||||
extends="java.lang.Object"
|
||||
abstract="true"
|
||||
|
||||
@@ -45,10 +45,7 @@ import java.util.List;
|
||||
public final class Geocoder {
|
||||
private static final String TAG = "Geocoder";
|
||||
|
||||
private String mLanguage;
|
||||
private String mCountry;
|
||||
private String mVariant;
|
||||
private String mAppName;
|
||||
private GeocoderParams mParams;
|
||||
private ILocationManager mService;
|
||||
|
||||
/**
|
||||
@@ -64,11 +61,7 @@ public final class Geocoder {
|
||||
if (locale == null) {
|
||||
throw new NullPointerException("locale == null");
|
||||
}
|
||||
mLanguage = locale.getLanguage();
|
||||
mCountry = locale.getCountry();
|
||||
mVariant = locale.getVariant();
|
||||
mAppName = context.getPackageName();
|
||||
|
||||
mParams = new GeocoderParams(context, locale);
|
||||
IBinder b = ServiceManager.getService(Context.LOCATION_SERVICE);
|
||||
mService = ILocationManager.Stub.asInterface(b);
|
||||
}
|
||||
@@ -119,7 +112,7 @@ public final class Geocoder {
|
||||
try {
|
||||
List<Address> results = new ArrayList<Address>();
|
||||
String ex = mService.getFromLocation(latitude, longitude, maxResults,
|
||||
mLanguage, mCountry, mVariant, mAppName, results);
|
||||
mParams, results);
|
||||
if (ex != null) {
|
||||
throw new IOException(ex);
|
||||
} else {
|
||||
@@ -161,7 +154,7 @@ public final class Geocoder {
|
||||
try {
|
||||
List<Address> results = new ArrayList<Address>();
|
||||
String ex = mService.getFromLocationName(locationName,
|
||||
0, 0, 0, 0, maxResults, mLanguage, mCountry, mVariant, mAppName, results);
|
||||
0, 0, 0, 0, maxResults, mParams, results);
|
||||
if (ex != null) {
|
||||
throw new IOException(ex);
|
||||
} else {
|
||||
@@ -234,7 +227,7 @@ public final class Geocoder {
|
||||
ArrayList<Address> result = new ArrayList<Address>();
|
||||
String ex = mService.getFromLocationName(locationName,
|
||||
lowerLeftLatitude, lowerLeftLongitude, upperRightLatitude, upperRightLongitude,
|
||||
maxResults, mLanguage, mCountry, mVariant, mAppName, result);
|
||||
maxResults, mParams, result);
|
||||
if (ex != null) {
|
||||
throw new IOException(ex);
|
||||
} else {
|
||||
|
||||
19
location/java/android/location/GeocoderParams.aidl
Normal file
19
location/java/android/location/GeocoderParams.aidl
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright (C) 2010, 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.
|
||||
*/
|
||||
|
||||
package android.location;
|
||||
|
||||
parcelable GeocoderParams;
|
||||
92
location/java/android/location/GeocoderParams.java
Normal file
92
location/java/android/location/GeocoderParams.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
|
||||
package android.location;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* This class contains extra parameters to pass to an IGeocodeProvider
|
||||
* implementation from the Geocoder class. Currently this contains the
|
||||
* language, country and variant information from the Geocoder's locale
|
||||
* as well as the Geocoder client's package name for geocoder server
|
||||
* logging. This information is kept in a separate class to allow for
|
||||
* future expansion of the IGeocodeProvider interface.
|
||||
*/
|
||||
public class GeocoderParams implements Parcelable {
|
||||
private Locale mLocale;
|
||||
private String mPackageName;
|
||||
|
||||
// used only for parcelling
|
||||
private GeocoderParams() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This object is only constructed by the Geocoder class
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public GeocoderParams(Context context, Locale locale) {
|
||||
mLocale = locale;
|
||||
mPackageName = context.getPackageName();
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the Geocoder's locale
|
||||
*/
|
||||
public Locale getLocale() {
|
||||
return mLocale;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the package name of the Geocoder's client
|
||||
*/
|
||||
public String getClientPackage() {
|
||||
return mPackageName;
|
||||
}
|
||||
|
||||
public static final Parcelable.Creator<GeocoderParams> CREATOR =
|
||||
new Parcelable.Creator<GeocoderParams>() {
|
||||
public GeocoderParams createFromParcel(Parcel in) {
|
||||
GeocoderParams gp = new GeocoderParams();
|
||||
String language = in.readString();
|
||||
String country = in.readString();
|
||||
String variant = in.readString();
|
||||
gp.mLocale = new Locale(language, country, variant);
|
||||
gp.mPackageName = in.readString();
|
||||
return gp;
|
||||
}
|
||||
|
||||
public GeocoderParams[] newArray(int size) {
|
||||
return new GeocoderParams[size];
|
||||
}
|
||||
};
|
||||
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void writeToParcel(Parcel parcel, int flags) {
|
||||
parcel.writeString(mLocale.getLanguage());
|
||||
parcel.writeString(mLocale.getCountry());
|
||||
parcel.writeString(mLocale.getVariant());
|
||||
parcel.writeString(mPackageName);
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package android.location;
|
||||
|
||||
import android.location.Address;
|
||||
import android.location.GeocoderParams;
|
||||
|
||||
/**
|
||||
* An interface for location providers implementing the Geocoder services.
|
||||
@@ -26,10 +27,10 @@ import android.location.Address;
|
||||
interface IGeocodeProvider {
|
||||
|
||||
String getFromLocation(double latitude, double longitude, int maxResults,
|
||||
String language, String country, String variant, String appName, out List<Address> addrs);
|
||||
in GeocoderParams params, out List<Address> addrs);
|
||||
|
||||
String getFromLocationName(String locationName,
|
||||
double lowerLeftLatitude, double lowerLeftLongitude,
|
||||
double upperRightLatitude, double upperRightLongitude, int maxResults,
|
||||
String language, String country, String variant, String appName, out List<Address> addrs);
|
||||
in GeocoderParams params, out List<Address> addrs);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package android.location;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.location.Address;
|
||||
import android.location.GeocoderParams;
|
||||
import android.location.IGeocodeProvider;
|
||||
import android.location.IGpsStatusListener;
|
||||
import android.location.ILocationListener;
|
||||
@@ -63,11 +64,11 @@ interface ILocationManager
|
||||
void reportLocation(in Location location);
|
||||
|
||||
String getFromLocation(double latitude, double longitude, int maxResults,
|
||||
String language, String country, String variant, String appName, out List<Address> addrs);
|
||||
in GeocoderParams params, out List<Address> addrs);
|
||||
String getFromLocationName(String locationName,
|
||||
double lowerLeftLatitude, double lowerLeftLongitude,
|
||||
double upperRightLatitude, double upperRightLongitude, int maxResults,
|
||||
String language, String country, String variant, String appName, out List<Address> addrs);
|
||||
in GeocoderParams params, out List<Address> addrs);
|
||||
|
||||
void addTestProvider(String name, boolean requiresNetwork, boolean requiresSatellite,
|
||||
boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude,
|
||||
|
||||
@@ -105,6 +105,48 @@ public class LocationManager {
|
||||
*/
|
||||
public static final String KEY_LOCATION_CHANGED = "location";
|
||||
|
||||
public interface GeocodeProvider {
|
||||
String getFromLocation(double latitude, double longitude, int maxResults,
|
||||
GeocoderParams params, List<Address> addrs);
|
||||
|
||||
String getFromLocationName(String locationName,
|
||||
double lowerLeftLatitude, double lowerLeftLongitude,
|
||||
double upperRightLatitude, double upperRightLongitude, int maxResults,
|
||||
GeocoderParams params, List<Address> addrs);
|
||||
}
|
||||
|
||||
private static final class GeocodeProviderProxy extends IGeocodeProvider.Stub {
|
||||
private GeocodeProvider mProvider;
|
||||
|
||||
GeocodeProviderProxy(GeocodeProvider provider) {
|
||||
mProvider = provider;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is overridden to implement the
|
||||
* {@link Geocoder#getFromLocation(double, double, int)} method.
|
||||
* Classes implementing this method should not hold a reference to the params parameter.
|
||||
*/
|
||||
public String getFromLocation(double latitude, double longitude, int maxResults,
|
||||
GeocoderParams params, List<Address> addrs) {
|
||||
return mProvider.getFromLocation(latitude, longitude, maxResults, params, addrs);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is overridden to implement the
|
||||
* {@link Geocoder#getFromLocationName(String, int, double, double, double, double)} method.
|
||||
* Classes implementing this method should not hold a reference to the params parameter.
|
||||
*/
|
||||
public String getFromLocationName(String locationName,
|
||||
double lowerLeftLatitude, double lowerLeftLongitude,
|
||||
double upperRightLatitude, double upperRightLongitude, int maxResults,
|
||||
GeocoderParams params, List<Address> addrs) {
|
||||
return mProvider.getFromLocationName(locationName, lowerLeftLatitude,
|
||||
lowerLeftLongitude, upperRightLatitude, upperRightLongitude,
|
||||
maxResults, params, addrs);
|
||||
}
|
||||
}
|
||||
|
||||
// Map from LocationListeners to their associated ListenerTransport objects
|
||||
private HashMap<LocationListener,ListenerTransport> mListeners =
|
||||
new HashMap<LocationListener,ListenerTransport>();
|
||||
@@ -1388,9 +1430,9 @@ public class LocationManager {
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public boolean installGeocodeProvider(IGeocodeProvider provider) {
|
||||
public boolean installGeocodeProvider(GeocodeProvider provider) {
|
||||
try {
|
||||
mService.installGeocodeProvider(provider);
|
||||
mService.installGeocodeProvider(new GeocodeProviderProxy(provider));
|
||||
return true;
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "RemoteException in setGeocodeProvider: ", e);
|
||||
|
||||
@@ -37,6 +37,7 @@ import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.location.Address;
|
||||
import android.location.GeocoderParams;
|
||||
import android.location.IGeocodeProvider;
|
||||
import android.location.IGpsStatusListener;
|
||||
import android.location.IGpsStatusProvider;
|
||||
@@ -1655,11 +1656,11 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
||||
// Geocoder
|
||||
|
||||
public String getFromLocation(double latitude, double longitude, int maxResults,
|
||||
String language, String country, String variant, String appName, List<Address> addrs) {
|
||||
GeocoderParams params, List<Address> addrs) {
|
||||
if (mGeocodeProvider != null) {
|
||||
try {
|
||||
return mGeocodeProvider.getFromLocation(latitude, longitude, maxResults, language, country,
|
||||
variant, appName, addrs);
|
||||
return mGeocodeProvider.getFromLocation(latitude, longitude, maxResults,
|
||||
params, addrs);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "getFromLocation failed", e);
|
||||
mGeocodeProvider = null;
|
||||
@@ -1672,13 +1673,13 @@ public class LocationManagerService extends ILocationManager.Stub implements Run
|
||||
public String getFromLocationName(String locationName,
|
||||
double lowerLeftLatitude, double lowerLeftLongitude,
|
||||
double upperRightLatitude, double upperRightLongitude, int maxResults,
|
||||
String language, String country, String variant, String appName, List<Address> addrs) {
|
||||
GeocoderParams params, List<Address> addrs) {
|
||||
|
||||
if (mGeocodeProvider != null) {
|
||||
try {
|
||||
return mGeocodeProvider.getFromLocationName(locationName, lowerLeftLatitude,
|
||||
lowerLeftLongitude, upperRightLatitude, upperRightLongitude,
|
||||
maxResults, language, country, variant, appName, addrs);
|
||||
maxResults, params, addrs);
|
||||
} catch (RemoteException e) {
|
||||
Log.e(TAG, "getFromLocationName failed", e);
|
||||
mGeocodeProvider = null;
|
||||
|
||||
Reference in New Issue
Block a user