From 34901409a404c8c66914c5a8ad0f29b1bcde0e78 Mon Sep 17 00:00:00 2001 From: Mike Lockwood Date: Mon, 4 Jan 2010 12:14:21 -0500 Subject: [PATCH] Cleanup and add public wrapper for IGeocodeProvider interface to prepare for network location unbundling. Change-Id: I6523d115b56dbf450121e73d48e151f200827eb4 Signed-off-by: Mike Lockwood --- api/current.xml | 125 ++++++++++++++++++ location/java/android/location/Geocoder.java | 17 +-- .../java/android/location/GeocoderParams.aidl | 19 +++ .../java/android/location/GeocoderParams.java | 92 +++++++++++++ .../android/location/IGeocodeProvider.aidl | 5 +- .../android/location/ILocationManager.aidl | 5 +- .../android/location/LocationManager.java | 46 ++++++- .../server/LocationManagerService.java | 11 +- 8 files changed, 297 insertions(+), 23 deletions(-) create mode 100644 location/java/android/location/GeocoderParams.aidl create mode 100644 location/java/android/location/GeocoderParams.java diff --git a/api/current.xml b/api/current.xml index 335c8da3b8487..9308be0a87104 100644 --- a/api/current.xml +++ b/api/current.xml @@ -74882,6 +74882,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + results = new ArrayList
(); 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
results = new ArrayList
(); 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
result = new ArrayList
(); 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 { diff --git a/location/java/android/location/GeocoderParams.aidl b/location/java/android/location/GeocoderParams.aidl new file mode 100644 index 0000000000000..2484e207dae74 --- /dev/null +++ b/location/java/android/location/GeocoderParams.aidl @@ -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; diff --git a/location/java/android/location/GeocoderParams.java b/location/java/android/location/GeocoderParams.java new file mode 100644 index 0000000000000..8b8e63b2c98af --- /dev/null +++ b/location/java/android/location/GeocoderParams.java @@ -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 CREATOR = + new Parcelable.Creator() { + 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); + } +} diff --git a/location/java/android/location/IGeocodeProvider.aidl b/location/java/android/location/IGeocodeProvider.aidl index e79e8d2db623a..aaa70c74778aa 100644 --- a/location/java/android/location/IGeocodeProvider.aidl +++ b/location/java/android/location/IGeocodeProvider.aidl @@ -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
addrs); + in GeocoderParams params, out List
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
addrs); + in GeocoderParams params, out List
addrs); } diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl index b6c59d67b2205..1fac07c97d404 100644 --- a/location/java/android/location/ILocationManager.aidl +++ b/location/java/android/location/ILocationManager.aidl @@ -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
addrs); + in GeocoderParams params, out List
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
addrs); + in GeocoderParams params, out List
addrs); void addTestProvider(String name, boolean requiresNetwork, boolean requiresSatellite, boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude, diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index 94ced227ed806..cbe10d9153a09 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -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
addrs); + + String getFromLocationName(String locationName, + double lowerLeftLatitude, double lowerLeftLongitude, + double upperRightLatitude, double upperRightLongitude, int maxResults, + GeocoderParams params, List
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
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
addrs) { + return mProvider.getFromLocationName(locationName, lowerLeftLatitude, + lowerLeftLongitude, upperRightLatitude, upperRightLongitude, + maxResults, params, addrs); + } + } + // Map from LocationListeners to their associated ListenerTransport objects private HashMap mListeners = new HashMap(); @@ -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); diff --git a/services/java/com/android/server/LocationManagerService.java b/services/java/com/android/server/LocationManagerService.java index c17a3bcb24f24..406897d7aeaac 100644 --- a/services/java/com/android/server/LocationManagerService.java +++ b/services/java/com/android/server/LocationManagerService.java @@ -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
addrs) { + GeocoderParams params, List
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
addrs) { + GeocoderParams params, List
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;