diff options
author | Mike Lockwood <lockwood@android.com> | 2009-05-01 07:53:28 -0400 |
---|---|---|
committer | Mike Lockwood <lockwood@android.com> | 2009-05-01 08:24:47 -0400 |
commit | 15e3d0f082d551f8819fbe4b0d502cc108627876 (patch) | |
tree | ee0b12d89c14986b5447e7a000fd2a3f91fb6c13 /location | |
parent | a56b318cf2d4c3700899f9de394c5635761dda66 (diff) | |
download | frameworks_base-15e3d0f082d551f8819fbe4b0d502cc108627876.zip frameworks_base-15e3d0f082d551f8819fbe4b0d502cc108627876.tar.gz frameworks_base-15e3d0f082d551f8819fbe4b0d502cc108627876.tar.bz2 |
location: Use ILocationProvider Binder interface for all location providers.
This change eliminates the LocationProviderImpl class which had been used
for location providers running in the system process.
Now the LocationProvider base class is only used to implement the
LocationManager.createProvider() method for retrieving provider information.
Added a new IGpsStatusProvider interface for providers that serve GPS status.
Signed-off-by: Mike Lockwood <lockwood@android.com>
Diffstat (limited to 'location')
6 files changed, 165 insertions, 354 deletions
diff --git a/location/java/android/location/IGpsStatusProvider.aidl b/location/java/android/location/IGpsStatusProvider.aidl new file mode 100644 index 0000000..cf277c8 --- /dev/null +++ b/location/java/android/location/IGpsStatusProvider.aidl @@ -0,0 +1,29 @@ +/* + * 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.IGpsStatusListener; + +/** + * An interface for location providers that provide GPS status information. + * + * {@hide} + */ +interface IGpsStatusProvider { + void addGpsStatusListener(IGpsStatusListener listener); + void removeGpsStatusListener(IGpsStatusListener listener); +} diff --git a/location/java/android/location/ILocationProvider.aidl b/location/java/android/location/ILocationProvider.aidl index 82533a5..e3e374d 100644 --- a/location/java/android/location/ILocationProvider.aidl +++ b/location/java/android/location/ILocationProvider.aidl @@ -19,13 +19,11 @@ package android.location; import android.os.Bundle; /** - * An interface for location providers implemented outside of the system process. + * Binder interface for location providers. * * {@hide} */ interface ILocationProvider { - - /* for LocationProvider */ boolean requiresNetwork(); boolean requiresSatellite(); boolean requiresCell(); @@ -35,8 +33,6 @@ interface ILocationProvider { boolean supportsBearing(); int getPowerRequirement(); int getAccuracy(); - - /* for LocationProviderImpl */ void enable(); void disable(); boolean isEnabled(); diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java index 57d3c53..693848b 100644 --- a/location/java/com/android/internal/location/GpsLocationProvider.java +++ b/location/java/com/android/internal/location/GpsLocationProvider.java @@ -22,7 +22,9 @@ import android.content.Intent; import android.content.IntentFilter; import android.location.Criteria; import android.location.IGpsStatusListener; +import android.location.IGpsStatusProvider; import android.location.ILocationManager; +import android.location.ILocationProvider; import android.location.Location; import android.location.LocationManager; import android.location.LocationProvider; @@ -54,7 +56,7 @@ import java.util.Properties; * * {@hide} */ -public class GpsLocationProvider extends LocationProviderImpl { +public class GpsLocationProvider extends ILocationProvider.Stub { private static final String TAG = "GpsLocationProvider"; @@ -142,7 +144,7 @@ public class GpsLocationProvider extends LocationProviderImpl { private int mLocationFlags = LOCATION_INVALID; // current status - private int mStatus = TEMPORARILY_UNAVAILABLE; + private int mStatus = LocationProvider.TEMPORARILY_UNAVAILABLE; // time for last status update private long mStatusUpdateTime = SystemClock.elapsedRealtime(); @@ -178,7 +180,8 @@ public class GpsLocationProvider extends LocationProviderImpl { private Properties mProperties; private String mNtpServer; - private Context mContext; + private final Context mContext; + private final ILocationManager mLocationManager; private Location mLocation = new Location(LocationManager.GPS_PROVIDER); private Bundle mLocationExtras = new Bundle(); private ArrayList<Listener> mListeners = new ArrayList<Listener>(); @@ -203,6 +206,57 @@ public class GpsLocationProvider extends LocationProviderImpl { // current setting - 5 minutes private static final long RETRY_INTERVAL = 5*60*1000; + private final IGpsStatusProvider mGpsStatusProvider = new IGpsStatusProvider.Stub() { + public void addGpsStatusListener(IGpsStatusListener listener) throws RemoteException { + if (listener == null) { + throw new NullPointerException("listener is null in addGpsStatusListener"); + } + + synchronized(mListeners) { + IBinder binder = listener.asBinder(); + int size = mListeners.size(); + for (int i = 0; i < size; i++) { + Listener test = mListeners.get(i); + if (binder.equals(test.mListener.asBinder())) { + // listener already added + return; + } + } + + Listener l = new Listener(listener); + binder.linkToDeath(l, 0); + mListeners.add(l); + } + } + + public void removeGpsStatusListener(IGpsStatusListener listener) { + if (listener == null) { + throw new NullPointerException("listener is null in addGpsStatusListener"); + } + + synchronized(mListeners) { + IBinder binder = listener.asBinder(); + Listener l = null; + int size = mListeners.size(); + for (int i = 0; i < size && l == null; i++) { + Listener test = mListeners.get(i); + if (binder.equals(test.mListener.asBinder())) { + l = test; + } + } + + if (l != null) { + mListeners.remove(l); + binder.unlinkToDeath(l, 0); + } + } + } + }; + + public IGpsStatusProvider getGpsStatusProvider() { + return mGpsStatusProvider; + } + private class TelephonyBroadcastReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); @@ -231,8 +285,8 @@ public class GpsLocationProvider extends LocationProviderImpl { } public GpsLocationProvider(Context context, ILocationManager locationManager) { - super(LocationManager.GPS_PROVIDER, locationManager); mContext = context; + mLocationManager = locationManager; TelephonyBroadcastReceiver receiver = new TelephonyBroadcastReceiver(); IntentFilter intentFilter = new IntentFilter(); @@ -270,7 +324,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * Returns true if the provider requires access to a * data network (e.g., the Internet), false otherwise. */ - @Override public boolean requiresNetwork() { // We want updateNetworkState() to get called when the network state changes // for XTRA and NTP time injection support. @@ -295,7 +348,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * satellite-based positioning system (e.g., GPS), false * otherwise. */ - @Override public boolean requiresSatellite() { return true; } @@ -305,7 +357,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * cellular network (e.g., to make use of cell tower IDs), false * otherwise. */ - @Override public boolean requiresCell() { return false; } @@ -315,7 +366,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * monetary charge to the user, false if use is free. It is up to * each provider to give accurate information. */ - @Override public boolean hasMonetaryCost() { return false; } @@ -326,7 +376,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * under most circumstances but may occassionally not report it * should return true. */ - @Override public boolean supportsAltitude() { return true; } @@ -337,7 +386,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * under most circumstances but may occassionally not report it * should return true. */ - @Override public boolean supportsSpeed() { return true; } @@ -348,7 +396,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * under most circumstances but may occassionally not report it * should return true. */ - @Override public boolean supportsBearing() { return true; } @@ -359,7 +406,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * @return the power requirement for this provider, as one of the * constants Criteria.POWER_REQUIREMENT_*. */ - @Override public int getPowerRequirement() { return Criteria.POWER_HIGH; } @@ -370,7 +416,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * @return the accuracy of location from this provider, as one * of the constants Criteria.ACCURACY_*. */ - @Override public int getAccuracy() { return Criteria.ACCURACY_FINE; } @@ -380,7 +425,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * must be handled. Hardware may be started up * when the provider is enabled. */ - @Override public synchronized void enable() { if (Config.LOGD) Log.d(TAG, "enable"); if (mEnabled) return; @@ -410,7 +454,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * need not be handled. Hardware may be shut * down while the provider is disabled. */ - @Override public synchronized void disable() { if (Config.LOGD) Log.d(TAG, "disable"); if (!mEnabled) return; @@ -443,12 +486,10 @@ public class GpsLocationProvider extends LocationProviderImpl { native_cleanup(); } - @Override public boolean isEnabled() { return mEnabled; } - @Override public int getStatus(Bundle extras) { if (extras != null) { extras.putInt("satellites", mSvCount); @@ -465,14 +506,11 @@ public class GpsLocationProvider extends LocationProviderImpl { } } - @Override public long getStatusUpdateTime() { return mStatusUpdateTime; } - @Override public void enableLocationTracking(boolean enable) { - super.enableLocationTracking(enable); if (enable) { mFixRequestTime = System.currentTimeMillis(); mTTFF = 0; @@ -483,9 +521,7 @@ public class GpsLocationProvider extends LocationProviderImpl { } } - @Override public void setMinTime(long minTime) { - super.setMinTime(minTime); if (Config.LOGD) Log.d(TAG, "setMinTime " + minTime); if (minTime >= 0) { @@ -516,48 +552,12 @@ public class GpsLocationProvider extends LocationProviderImpl { } } - public void addGpsStatusListener(IGpsStatusListener listener) throws RemoteException { - if (listener == null) throw new NullPointerException("listener is null in addGpsStatusListener"); - - synchronized(mListeners) { - IBinder binder = listener.asBinder(); - int size = mListeners.size(); - for (int i = 0; i < size; i++) { - Listener test = mListeners.get(i); - if (binder.equals(test.mListener.asBinder())) { - // listener already added - return; - } - } - - Listener l = new Listener(listener); - binder.linkToDeath(l, 0); - mListeners.add(l); - } + public void wakeLockAcquired() { } - - public void removeGpsStatusListener(IGpsStatusListener listener) { - if (listener == null) throw new NullPointerException("listener is null in addGpsStatusListener"); - - synchronized(mListeners) { - IBinder binder = listener.asBinder(); - Listener l = null; - int size = mListeners.size(); - for (int i = 0; i < size && l == null; i++) { - Listener test = mListeners.get(i); - if (binder.equals(test.mListener.asBinder())) { - l = test; - } - } - if (l != null) { - mListeners.remove(l); - binder.unlinkToDeath(l, 0); - } - } + public void wakeLockReleased() { } - @Override public void addListener(int uid) { mClientUids.put(uid, 0); if (mNavigating) { @@ -569,7 +569,6 @@ public class GpsLocationProvider extends LocationProviderImpl { } } - @Override public void removeListener(int uid) { mClientUids.delete(uid); if (mNavigating) { @@ -581,7 +580,6 @@ public class GpsLocationProvider extends LocationProviderImpl { } } - @Override public boolean sendExtraCommand(String command, Bundle extras) { if ("delete_aiding_data".equals(command)) { @@ -632,7 +630,7 @@ public class GpsLocationProvider extends LocationProviderImpl { } // reset SV count to zero - updateStatus(TEMPORARILY_UNAVAILABLE, 0); + updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE, 0); } } @@ -646,7 +644,7 @@ public class GpsLocationProvider extends LocationProviderImpl { mLocationFlags = LOCATION_INVALID; // reset SV count to zero - updateStatus(TEMPORARILY_UNAVAILABLE, 0); + updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE, 0); } } @@ -709,15 +707,19 @@ public class GpsLocationProvider extends LocationProviderImpl { mLocation.removeAccuracy(); } - reportLocationChanged(mLocation); + try { + mLocationManager.setLocation(mLocation); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException calling reportLocation"); + } } - if (mStarted && mStatus != AVAILABLE) { + if (mStarted && mStatus != LocationProvider.AVAILABLE) { // send an intent to notify that the GPS is receiving fixes. Intent intent = new Intent(GPS_FIX_CHANGE_ACTION); intent.putExtra(EXTRA_ENABLED, true); mContext.sendBroadcast(intent); - updateStatus(AVAILABLE, mSvCount); + updateStatus(LocationProvider.AVAILABLE, mSvCount); } } @@ -812,13 +814,13 @@ public class GpsLocationProvider extends LocationProviderImpl { updateStatus(mStatus, svCount); - if (mNavigating && mStatus == AVAILABLE && mLastFixTime > 0 && + if (mNavigating && mStatus == LocationProvider.AVAILABLE && mLastFixTime > 0 && System.currentTimeMillis() - mLastFixTime > RECENT_FIX_TIMEOUT) { // send an intent to notify that the GPS is no longer receiving fixes. Intent intent = new Intent(GPS_FIX_CHANGE_ACTION); intent.putExtra(EXTRA_ENABLED, false); mContext.sendBroadcast(intent); - updateStatus(TEMPORARILY_UNAVAILABLE, mSvCount); + updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE, mSvCount); } } diff --git a/location/java/com/android/internal/location/LocationProviderImpl.java b/location/java/com/android/internal/location/LocationProviderImpl.java deleted file mode 100644 index fc830f5..0000000 --- a/location/java/com/android/internal/location/LocationProviderImpl.java +++ /dev/null @@ -1,234 +0,0 @@ -/* - * Copyright (C) 2007 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.ILocationManager; -import android.location.Location; -import android.location.LocationProvider; -import android.os.Bundle; -import android.os.RemoteException; -import android.util.Log; - -import java.util.ArrayList; -import java.util.HashMap; - -/** - * An abstract superclass for location provider implementations. - * Location provider implementations are typically instantiated by the - * location manager service in the system process, and location - * information is made available to implementations via the manager. - * - * {@hide} - */ -public abstract class LocationProviderImpl extends LocationProvider { - private static final String TAG = "LocationProviderImpl"; - - private static ArrayList<LocationProviderImpl> sProviders = - new ArrayList<LocationProviderImpl>(); - private static HashMap<String, LocationProviderImpl> sProvidersByName - = new HashMap<String, LocationProviderImpl>(); - - private final ILocationManager mLocationManager; - private boolean mLocationTracking = false; - private long mMinTime = 0; - - protected LocationProviderImpl(String name, ILocationManager locationManager) { - super(name); - mLocationManager = locationManager; - } - - public static void addProvider(LocationProviderImpl provider) { - sProviders.add(provider); - sProvidersByName.put(provider.getName(), provider); - } - - public static void removeProvider(LocationProviderImpl provider) { - sProviders.remove(provider); - sProvidersByName.remove(provider.getName()); - } - - public static ArrayList<LocationProviderImpl> getProviders() { - return sProviders; - } - - public static LocationProviderImpl getProvider(String name) { - return sProvidersByName.get(name); - } - - public void reportLocationChanged(Location location) { - try { - mLocationManager.setLocation(location); - } catch (RemoteException e) { - Log.e(TAG, "RemoteException calling ILocationManager.setLocation"); - } - } - - /** - * Enables this provider. When enabled, calls to {@link #getStatus()} - * must be handled. Hardware may be started up - * when the provider is enabled. - */ - public abstract void enable(); - - /** - * Disables this provider. When disabled, calls to {@link #getStatus()} - * need not be handled. Hardware may be shut - * down while the provider is disabled. - */ - public abstract void disable(); - - /** - * Returns true if this provider is enabled, false otherwise; - */ - public abstract boolean isEnabled(); - - /** - * Returns a information on the status of this provider. - * {@link #OUT_OF_SERVICE} is returned if the provider is - * out of service, and this is not expected to change in the near - * future; {@link #TEMPORARILY_UNAVAILABLE} is returned if - * the provider is temporarily unavailable but is expected to be - * available shortly; and {@link #AVAILABLE} is returned - * if the provider is currently available. - */ - public int getStatus() { - return getStatus(null); - } - - /** - * Returns a information on the status of this provider. - * {@link #OUT_OF_SERVICE} is returned if the provider is - * out of service, and this is not expected to change in the near - * future; {@link #TEMPORARILY_UNAVAILABLE} is returned if - * the provider is temporarily unavailable but is expected to be - * available shortly; and {@link #AVAILABLE} is returned - * if the provider is currently available. - * - * <p> If extras is non-null, additional status information may be - * added to it in the form of provider-specific key/value pairs. - */ - public abstract int getStatus(Bundle extras); - - /** - * Returns the time at which the status was last updated. It is the - * responsibility of the provider to appropriately set this value - * using {@link android.os.SystemClock.elapsedRealtime()} each time - * there is a status update that it wishes to broadcast to all its - * listeners. The provider should be careful not to broadcast - * the same status again. - * - * @return time of last status update in millis since last reboot - */ - public long getStatusUpdateTime() { - return 0; - } - - /** - * Notifies the location provider that clients are listening for locations. - * Called with enable set to true when the first client is added and - * called with enable set to false when the last client is removed. - * This allows the provider to prepare for receiving locations, - * and to shut down when no clients are remaining. - * - * @param enable true if location tracking should be enabled. - */ - public void enableLocationTracking(boolean enable) { - mLocationTracking = enable; - } - - /** - * Returns true if the provider has any listeners - * - * @return true if provider is being tracked - */ - public boolean isLocationTracking() { - return mLocationTracking; - } - - /** - * Notifies the location provider of the smallest minimum time between updates amongst - * all clients that are listening for locations. This allows the provider to reduce - * the frequency of updates to match the requested frequency. - * - * @param minTime the smallest minTime value over all listeners for this provider. - */ - public void setMinTime(long minTime) { - mMinTime = minTime; - } - - /** - * Gets the smallest minimum time between updates amongst all the clients listening - * for locations. By default this value is 0 (as frqeuently as possible) - * - * @return the smallest minTime value over all listeners for this provider - */ - public long getMinTime() { - return mMinTime; - } - - /** - * Updates the network state for the given provider. This function must - * be overwritten if {@link #requiresNetwork} returns true. The state is - * {@link #TEMPORARILY_UNAVAILABLE} (disconnected), OR {@link #AVAILABLE} - * (connected or connecting). - * - * @param state data state - */ - public void updateNetworkState(int state) { - } - - /** - * Implements addditional location provider specific additional commands. - * - * @param command name of the command to send to the provider. - * @param extras optional arguments for the command (or null). - * The provider may optionally fill the extras Bundle with results from the command. - * - * @return true if the command succeeds. - */ - public boolean sendExtraCommand(String command, Bundle extras) { - return false; - } - - /** - * Informs the location provider when a new client is listening for location information - * - * @param uid the uid of the client proces - */ - public void addListener(int uid) { - } - - /** - * Informs the location provider when a client is no longer listening for location information - * - * @param uid the uid of the client proces - */ - public void removeListener(int uid) { - } - - /** - * Informs the location provider when the location manager service has acquired its wake lock - */ - public void wakeLockAcquired() { - } - - /** - * Informs the location provider when the location manager service has released its wake lock - */ - public void wakeLockReleased() { - } -} diff --git a/location/java/com/android/internal/location/LocationProviderProxy.java b/location/java/com/android/internal/location/LocationProviderProxy.java index d3c86db..abca28f 100644 --- a/location/java/com/android/internal/location/LocationProviderProxy.java +++ b/location/java/com/android/internal/location/LocationProviderProxy.java @@ -17,7 +17,6 @@ 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; @@ -32,19 +31,24 @@ import java.util.List; * * {@hide} */ -public class LocationProviderProxy extends LocationProviderImpl { +public class LocationProviderProxy { private static final String TAG = "LocationProviderProxy"; + private final String mName; private final ILocationProvider mProvider; + private boolean mLocationTracking = false; + private long mMinTime = 0; - public LocationProviderProxy(String name, ILocationManager locationManager, - ILocationProvider provider) { - super(name, locationManager); + public LocationProviderProxy(String name, ILocationProvider provider) { + mName = name; mProvider = provider; } - @Override + public String getName() { + return mName; + } + public boolean requiresNetwork() { try { return mProvider.requiresNetwork(); @@ -54,7 +58,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public boolean requiresSatellite() { try { return mProvider.requiresSatellite(); @@ -64,7 +67,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public boolean requiresCell() { try { return mProvider.requiresCell(); @@ -74,7 +76,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public boolean hasMonetaryCost() { try { return mProvider.hasMonetaryCost(); @@ -84,7 +85,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public boolean supportsAltitude() { try { return mProvider.supportsAltitude(); @@ -94,7 +94,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public boolean supportsSpeed() { try { return mProvider.supportsSpeed(); @@ -104,8 +103,7 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override - public boolean supportsBearing() { + public boolean supportsBearing() { try { return mProvider.supportsBearing(); } catch (RemoteException e) { @@ -114,7 +112,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public int getPowerRequirement() { try { return mProvider.getPowerRequirement(); @@ -124,7 +121,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public int getAccuracy() { try { return mProvider.getAccuracy(); @@ -134,7 +130,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public void enable() { try { mProvider.enable(); @@ -143,7 +138,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public void disable() { try { mProvider.disable(); @@ -152,7 +146,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public boolean isEnabled() { try { return mProvider.isEnabled(); @@ -162,7 +155,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public int getStatus(Bundle extras) { try { return mProvider.getStatus(extras); @@ -172,7 +164,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public long getStatusUpdateTime() { try { return mProvider.getStatusUpdateTime(); @@ -182,27 +173,32 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override + public boolean isLocationTracking() { + return mLocationTracking; + } + public void enableLocationTracking(boolean enable) { + mLocationTracking = enable; try { - super.enableLocationTracking(enable); mProvider.enableLocationTracking(enable); } catch (RemoteException e) { Log.e(TAG, "enableLocationTracking failed", e); } } - @Override + public long getMinTime() { + return mMinTime; + } + public void setMinTime(long minTime) { + mMinTime = 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); @@ -211,7 +207,6 @@ public class LocationProviderProxy extends LocationProviderImpl { } } - @Override public boolean sendExtraCommand(String command, Bundle extras) { try { return mProvider.sendExtraCommand(command, extras); diff --git a/location/java/com/android/internal/location/MockProvider.java b/location/java/com/android/internal/location/MockProvider.java index 6336e2b..6fa2c29 100644 --- a/location/java/com/android/internal/location/MockProvider.java +++ b/location/java/com/android/internal/location/MockProvider.java @@ -17,8 +17,12 @@ package com.android.internal.location; import android.location.ILocationManager; +import android.location.ILocationProvider; import android.location.Location; +import android.location.LocationProvider; import android.os.Bundle; +import android.os.RemoteException; +import android.util.Log; import android.util.PrintWriterPrinter; import java.io.PrintWriter; @@ -28,7 +32,9 @@ import java.io.PrintWriter; * * {@hide} */ -public class MockProvider extends LocationProviderImpl { +public class MockProvider extends ILocationProvider.Stub { + private final String mName; + private final ILocationManager mLocationManager; private final boolean mRequiresNetwork; private final boolean mRequiresSatellite; private final boolean mRequiresCell; @@ -46,12 +52,14 @@ public class MockProvider extends LocationProviderImpl { private boolean mHasStatus; private boolean mEnabled; + private static final String TAG = "MockProvider"; + public MockProvider(String name, ILocationManager locationManager, boolean requiresNetwork, boolean requiresSatellite, boolean requiresCell, boolean hasMonetaryCost, boolean supportsAltitude, boolean supportsSpeed, boolean supportsBearing, int powerRequirement, int accuracy) { - super(name, locationManager); - + mName = name; + mLocationManager = locationManager; mRequiresNetwork = requiresNetwork; mRequiresSatellite = requiresSatellite; mRequiresCell = requiresCell; @@ -64,78 +72,64 @@ public class MockProvider extends LocationProviderImpl { mLocation = new Location(name); } - @Override public void disable() { mEnabled = false; } - @Override public void enable() { mEnabled = true; } - @Override public int getStatus(Bundle extras) { if (mHasStatus) { extras.clear(); extras.putAll(mExtras); return mStatus; } else { - return AVAILABLE; + return LocationProvider.AVAILABLE; } } - @Override public long getStatusUpdateTime() { return mStatusUpdateTime; } - @Override public boolean isEnabled() { return mEnabled; } - @Override public int getAccuracy() { return mAccuracy; } - @Override public int getPowerRequirement() { return mPowerRequirement; } - @Override public boolean hasMonetaryCost() { return mHasMonetaryCost; } - @Override public boolean requiresCell() { return mRequiresCell; } - @Override public boolean requiresNetwork() { return mRequiresNetwork; } - @Override public boolean requiresSatellite() { return mRequiresSatellite; } - @Override public boolean supportsAltitude() { return mSupportsAltitude; } - @Override public boolean supportsBearing() { return mSupportsBearing; } - @Override public boolean supportsSpeed() { return mSupportsSpeed; } @@ -143,7 +137,11 @@ public class MockProvider extends LocationProviderImpl { public void setLocation(Location l) { mLocation.set(l); mHasLocation = true; - reportLocationChanged(mLocation); + try { + mLocationManager.setLocation(mLocation); + } catch (RemoteException e) { + Log.e(TAG, "RemoteException calling reportLocation"); + } } public void clearLocation() { @@ -165,8 +163,33 @@ public class MockProvider extends LocationProviderImpl { mStatusUpdateTime = 0; } + public void enableLocationTracking(boolean enable) { + } + + public void setMinTime(long minTime) { + } + + public void updateNetworkState(int state) { + } + + public boolean sendExtraCommand(String command, Bundle extras) { + return false; + } + + public void addListener(int uid) { + } + + public void removeListener(int uid) { + } + + public void wakeLockAcquired() { + } + + public void wakeLockReleased() { + } + public void dump(PrintWriter pw, String prefix) { - pw.println(prefix + getName()); + pw.println(prefix + mName); pw.println(prefix + "mHasLocation=" + mHasLocation); pw.println(prefix + "mLocation:"); mLocation.dump(new PrintWriterPrinter(pw), prefix + " "); |