From e932f7f2a47b770c636443d411436bd29cc4bb43 Mon Sep 17 00:00:00 2001 From: Mike Lockwood <> Date: Mon, 6 Apr 2009 10:51:26 -0700 Subject: AI 144663: Use Binder interfaces between NetworkLocationManager and LocationManagerService. This fixes a hack that was added when NetworkLocationManager was moved out of the framework. This also lays the groundwork for supporting location providers outside of the system process. BUG=1729031 Automated import of CL 144663 --- .../java/android/location/ILocationCollector.aidl | 36 +++ .../java/android/location/ILocationManager.aidl | 6 + .../java/android/location/ILocationProvider.aidl | 61 +++++ .../android/location/LocationProviderImpl.java | 2 +- .../internal/location/GpsLocationProvider.java | 7 +- .../internal/location/ILocationCollector.java | 35 --- .../internal/location/INetworkLocationManager.java | 30 --- .../location/INetworkLocationProvider.java | 64 ----- .../internal/location/LocationProviderProxy.java | 273 +++++++++++++++++++++ 9 files changed, 383 insertions(+), 131 deletions(-) create mode 100644 location/java/android/location/ILocationCollector.aidl create mode 100644 location/java/android/location/ILocationProvider.aidl delete mode 100644 location/java/com/android/internal/location/ILocationCollector.java delete mode 100644 location/java/com/android/internal/location/INetworkLocationManager.java delete mode 100644 location/java/com/android/internal/location/INetworkLocationProvider.java create mode 100644 location/java/com/android/internal/location/LocationProviderProxy.java (limited to 'location') diff --git a/location/java/android/location/ILocationCollector.aidl b/location/java/android/location/ILocationCollector.aidl new file mode 100644 index 0000000..b2e1796 --- /dev/null +++ b/location/java/android/location/ILocationCollector.aidl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2009 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.location.Location; + +/** + * Listens for GPS and cell/wifi changes and anonymously uploads to server + * for improving quality of service of NetworkLocationProvider. + * This service is only enabled when the user has enabled the + * network location provider. + * + * {@hide} + */ +oneway interface ILocationCollector { + /** + * Updates GPS location if collection is enabled + * + * @param location location object + */ + void updateLocation(in Location location); +} diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl index a7fb04d..86bd8b6 100644 --- a/location/java/android/location/ILocationManager.aidl +++ b/location/java/android/location/ILocationManager.aidl @@ -19,7 +19,9 @@ package android.location; import android.app.PendingIntent; import android.location.Address; import android.location.IGpsStatusListener; +import android.location.ILocationCollector; import android.location.ILocationListener; +import android.location.ILocationProvider; import android.location.Location; import android.os.Bundle; @@ -74,4 +76,8 @@ interface ILocationManager void clearTestProviderEnabled(String provider); void setTestProviderStatus(String provider, int status, in Bundle extras, long updateTime); void clearTestProviderStatus(String provider); + + /* for installing Network Location Provider */ + void setNetworkLocationProvider(ILocationProvider provider); + void setLocationCollector(ILocationCollector collector); } diff --git a/location/java/android/location/ILocationProvider.aidl b/location/java/android/location/ILocationProvider.aidl new file mode 100644 index 0000000..6f9daff --- /dev/null +++ b/location/java/android/location/ILocationProvider.aidl @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2009 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.location.Address; +import android.os.Bundle; + +/** + * An interface for location providers implemented outside of the system process. + * + * {@hide} + */ +interface ILocationProvider { + + /* for LocationProvider */ + boolean requiresNetwork(); + boolean requiresSatellite(); + boolean requiresCell(); + boolean hasMonetaryCost(); + boolean supportsAltitude(); + boolean supportsSpeed(); + boolean supportsBearing(); + int getPowerRequirement(); + int getAccuracy(); + + /* for LocationProviderImpl */ + void enable(); + void disable(); + boolean isEnabled(); + int getStatus(out Bundle extras); + long getStatusUpdateTime(); + void enableLocationTracking(boolean enable); + void setMinTime(long minTime); + void updateNetworkState(int state); + boolean sendExtraCommand(String command, inout Bundle extras); + + /* the following are only used for NetworkLocationProvider */ + void updateCellLockStatus(boolean acquired); + void addListener(in String[] applications); + void removeListener(in String[] applications); + String getFromLocation(double latitude, double longitude, int maxResults, + String language, String country, String variant, String appName, 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); +} diff --git a/location/java/android/location/LocationProviderImpl.java b/location/java/android/location/LocationProviderImpl.java index b6453c6..2a9199e 100644 --- a/location/java/android/location/LocationProviderImpl.java +++ b/location/java/android/location/LocationProviderImpl.java @@ -119,7 +119,7 @@ public abstract class LocationProviderImpl extends LocationProvider { try { mLocationManager.setLocation(location); } catch (RemoteException e) { - Log.e(TAG, "RemoteException calling ILocationManager.onLocationChanged"); + Log.e(TAG, "RemoteException calling ILocationManager.setLocation"); } } diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java index d09318a..8a33574 100644 --- a/location/java/com/android/internal/location/GpsLocationProvider.java +++ b/location/java/com/android/internal/location/GpsLocationProvider.java @@ -22,6 +22,7 @@ import android.content.Intent; import android.content.IntentFilter; import android.location.Criteria; import android.location.IGpsStatusListener; +import android.location.ILocationCollector; import android.location.ILocationManager; import android.location.Location; import android.location.LocationManager; @@ -678,7 +679,11 @@ public class GpsLocationProvider extends LocationProviderImpl { // Send to collector if ((flags & LOCATION_HAS_LAT_LONG) == LOCATION_HAS_LAT_LONG && mCollector != null) { - mCollector.updateLocation(mLocation); + try { + mCollector.updateLocation(mLocation); + } catch (RemoteException e) { + Log.w(TAG, "mCollector.updateLocation failed"); + } } } diff --git a/location/java/com/android/internal/location/ILocationCollector.java b/location/java/com/android/internal/location/ILocationCollector.java deleted file mode 100644 index 2196144..0000000 --- a/location/java/com/android/internal/location/ILocationCollector.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2009 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 com.android.internal.location; - -import android.location.Location; - -/** - * Listens for GPS and cell/wifi changes and anonymously uploads to server for - * improving quality of service of NetworkLocationProvider. This service is only enabled when - * the user has enabled the network location provider. - * - * {@hide} - */ -public interface ILocationCollector { - /** - * Updates GPS location if collection is enabled - * - * @param location location object - */ - abstract public void updateLocation(Location location); -} diff --git a/location/java/com/android/internal/location/INetworkLocationManager.java b/location/java/com/android/internal/location/INetworkLocationManager.java deleted file mode 100644 index e487556..0000000 --- a/location/java/com/android/internal/location/INetworkLocationManager.java +++ /dev/null @@ -1,30 +0,0 @@ - /* - * Copyright (C) 2009 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 com.android.internal.location; - -import android.content.Context; - -/** - * Used to register network location and collection services - * with the Location Manager Service. - * - * {@hide} - */ -public interface INetworkLocationManager { - void setNetworkLocationProvider(INetworkLocationProvider provider); - void setLocationCollector(ILocationCollector collector); -} \ No newline at end of file diff --git a/location/java/com/android/internal/location/INetworkLocationProvider.java b/location/java/com/android/internal/location/INetworkLocationProvider.java deleted file mode 100644 index 937ab4d..0000000 --- a/location/java/com/android/internal/location/INetworkLocationProvider.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2009 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 com.android.internal.location; - -import android.location.Address; -import android.location.Location; -import android.net.wifi.ScanResult; - -import java.util.List; - -/** - * Interface for network location provider - * - * {@hide} - */ -public interface INetworkLocationProvider { - - /** - * Updates the current cell lock status. - * - * @param acquired true if a cell lock has been acquired - */ - abstract public void updateCellLockStatus(boolean acquired); - - /** - * Adds a list of application clients - * Only used by the NetworkLocationProvider - * - * @param applications list of package names - */ - abstract public void addListener(String[] applications); - - /** - * Removes a list of application clients - * Only used by the NetworkLocationProvider - * - * @param applications list of package names - */ - abstract public void removeListener(String[] applications); - - - abstract public String getFromLocation(double latitude, double longitude, int maxResults, - String language, String country, String variant, String appName, List
addrs); - - abstract 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); - -} diff --git a/location/java/com/android/internal/location/LocationProviderProxy.java b/location/java/com/android/internal/location/LocationProviderProxy.java new file mode 100644 index 0000000..1f4940f --- /dev/null +++ b/location/java/com/android/internal/location/LocationProviderProxy.java @@ -0,0 +1,273 @@ +/* + * Copyright (C) 2009 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 com.android.internal.location; + +import android.location.Address; +import android.location.ILocationManager; +import android.location.ILocationProvider; +import android.location.Location; +import android.location.LocationManager; +import android.location.LocationProviderImpl; +import android.os.Bundle; +import android.os.RemoteException; +import android.util.Log; + +import java.util.List; + +/** + * A class for proxying remote ILocationProvider implementations. + * + * {@hide} + */ +public class LocationProviderProxy extends LocationProviderImpl { + + private static final String TAG = "LocationProviderProxy"; + + private final ILocationProvider mProvider; + + public LocationProviderProxy(String name, ILocationManager locationManager, + ILocationProvider provider) { + super(name, locationManager); + mProvider = provider; + } + + @Override + public boolean requiresNetwork() { + try { + return mProvider.requiresNetwork(); + } catch (RemoteException e) { + Log.e(TAG, "requiresNetwork failed", e); + return false; + } + } + + @Override + public boolean requiresSatellite() { + try { + return mProvider.requiresSatellite(); + } catch (RemoteException e) { + Log.e(TAG, "requiresSatellite failed", e); + return false; + } + } + + @Override + public boolean requiresCell() { + try { + return mProvider.requiresCell(); + } catch (RemoteException e) { + Log.e(TAG, "requiresCell failed", e); + return false; + } + } + + @Override + public boolean hasMonetaryCost() { + try { + return mProvider.hasMonetaryCost(); + } catch (RemoteException e) { + Log.e(TAG, "hasMonetaryCost failed", e); + return false; + } + } + + @Override + public boolean supportsAltitude() { + try { + return mProvider.supportsAltitude(); + } catch (RemoteException e) { + Log.e(TAG, "supportsAltitude failed", e); + return false; + } + } + + @Override + public boolean supportsSpeed() { + try { + return mProvider.supportsSpeed(); + } catch (RemoteException e) { + Log.e(TAG, "supportsSpeed failed", e); + return false; + } + } + + @Override + public boolean supportsBearing() { + try { + return mProvider.supportsBearing(); + } catch (RemoteException e) { + Log.e(TAG, "supportsBearing failed", e); + return false; + } + } + + @Override + public int getPowerRequirement() { + try { + return mProvider.getPowerRequirement(); + } catch (RemoteException e) { + Log.e(TAG, "getPowerRequirement failed", e); + return 0; + } + } + + @Override + public int getAccuracy() { + try { + return mProvider.getAccuracy(); + } catch (RemoteException e) { + Log.e(TAG, "getAccuracy failed", e); + return 0; + } + } + + @Override + public void enable() { + try { + mProvider.enable(); + } catch (RemoteException e) { + Log.e(TAG, "enable failed", e); + } + } + + @Override + public void disable() { + try { + mProvider.disable(); + } catch (RemoteException e) { + Log.e(TAG, "disable failed", e); + } + } + + @Override + public boolean isEnabled() { + try { + return mProvider.isEnabled(); + } catch (RemoteException e) { + Log.e(TAG, "isEnabled failed", e); + return false; + } + } + + @Override + public int getStatus(Bundle extras) { + try { + return mProvider.getStatus(extras); + } catch (RemoteException e) { + Log.e(TAG, "getStatus failed", e); + return 0; + } + } + + @Override + public long getStatusUpdateTime() { + try { + return mProvider.getStatusUpdateTime(); + } catch (RemoteException e) { + Log.e(TAG, "getStatusUpdateTime failed", e); + return 0; + } + } + + @Override + public void enableLocationTracking(boolean enable) { + try { + super.enableLocationTracking(enable); + mProvider.enableLocationTracking(enable); + } catch (RemoteException e) { + Log.e(TAG, "enableLocationTracking failed", e); + } + } + + @Override + public void setMinTime(long minTime) { + try { + super.setMinTime(minTime); + mProvider.setMinTime(minTime); + } catch (RemoteException e) { + Log.e(TAG, "setMinTime failed", e); + } + } + + @Override + public void updateNetworkState(int state) { + try { + mProvider.updateNetworkState(state); + } catch (RemoteException e) { + Log.e(TAG, "updateNetworkState failed", e); + } + } + + @Override + public boolean sendExtraCommand(String command, Bundle extras) { + try { + return mProvider.sendExtraCommand(command, extras); + } catch (RemoteException e) { + Log.e(TAG, "sendExtraCommand failed", e); + return false; + } + } + + public void updateCellLockStatus(boolean acquired) { + try { + mProvider.updateCellLockStatus(acquired); + } catch (RemoteException e) { + Log.e(TAG, "updateCellLockStatus failed", e); + } + } + + public void addListener(String[] applications) { + try { + mProvider.addListener(applications); + } catch (RemoteException e) { + Log.e(TAG, "addListener failed", e); + } + } + + public void removeListener(String[] applications) { + try { + mProvider.removeListener(applications); + } catch (RemoteException e) { + Log.e(TAG, "removeListener failed", e); + } + } + + public String getFromLocation(double latitude, double longitude, int maxResults, + String language, String country, String variant, String appName, List
addrs) { + try { + return mProvider.getFromLocation(latitude, longitude, maxResults, language, country, + variant, appName, addrs); + } catch (RemoteException e) { + Log.e(TAG, "getFromLocation failed", e); + return null; + } + } + + 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) { + try { + return mProvider.getFromLocationName(locationName, lowerLeftLatitude, + lowerLeftLongitude, upperRightLatitude, upperRightLongitude, + maxResults, language, country, variant, appName, addrs); + } catch (RemoteException e) { + Log.e(TAG, "getFromLocationName failed", e); + return null; + } + } +} -- cgit v1.1