diff options
author | Mike Lockwood <lockwood@android.com> | 2009-04-29 13:35:34 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-29 13:35:34 -0700 |
commit | 05d024329604bb92dca02f1ecdff4876d6d7b28c (patch) | |
tree | 6b1cc8baa4eab07e20e9bad7169953cdddae61a4 /location/java/com | |
parent | 8749fecd99dbc468a79b993ff9926cded8e0552f (diff) | |
parent | 79762a3ee34eb8be5549bcb183af844b6f19c266 (diff) | |
download | frameworks_base-05d024329604bb92dca02f1ecdff4876d6d7b28c.zip frameworks_base-05d024329604bb92dca02f1ecdff4876d6d7b28c.tar.gz frameworks_base-05d024329604bb92dca02f1ecdff4876d6d7b28c.tar.bz2 |
am 79762a3: location: Move DummyLocationProvider.java and LocationProvid
Merge commit '79762a3ee34eb8be5549bcb183af844b6f19c266'
* commit '79762a3ee34eb8be5549bcb183af844b6f19c266':
location: Move DummyLocationProvider.java and LocationProviderImpl.java to the internal package.
Diffstat (limited to 'location/java/com')
6 files changed, 453 insertions, 4 deletions
diff --git a/location/java/com/android/internal/location/DummyLocationProvider.java b/location/java/com/android/internal/location/DummyLocationProvider.java new file mode 100644 index 0000000..ff5e27b --- /dev/null +++ b/location/java/com/android/internal/location/DummyLocationProvider.java @@ -0,0 +1,170 @@ +/* + * 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.LocationProvider; + +/** + * A stub implementation of LocationProvider used by LocationManager. + * A DummyLocationProvider may be queried to determine the properties + * of the provider whcih it shadows, but does not actually provide location + * data. + * + * {@hide} + */ +public class DummyLocationProvider extends LocationProvider { + + private static final String TAG = "DummyLocationProvider"; + + String mName; + boolean mRequiresNetwork; + boolean mRequiresSatellite; + boolean mRequiresCell; + boolean mHasMonetaryCost; + boolean mSupportsAltitude; + boolean mSupportsSpeed; + boolean mSupportsBearing; + int mPowerRequirement; + int mAccuracy; + + public DummyLocationProvider(String name) { + super(name); + } + + public void setRequiresNetwork(boolean requiresNetwork) { + mRequiresNetwork = requiresNetwork; + } + + public void setRequiresSatellite(boolean requiresSatellite) { + mRequiresSatellite = requiresSatellite; + } + + public void setRequiresCell(boolean requiresCell) { + mRequiresCell = requiresCell; + } + + public void setHasMonetaryCost(boolean hasMonetaryCost) { + mHasMonetaryCost = hasMonetaryCost; + } + + public void setSupportsAltitude(boolean supportsAltitude) { + mSupportsAltitude = supportsAltitude; + } + + public void setSupportsSpeed(boolean supportsSpeed) { + mSupportsSpeed = supportsSpeed; + } + + public void setSupportsBearing(boolean supportsBearing) { + mSupportsBearing = supportsBearing; + } + + public void setPowerRequirement(int powerRequirement) { + mPowerRequirement = powerRequirement; + } + + public void setAccuracy(int accuracy) { + mAccuracy = accuracy; + } + + /** + * Returns true if the provider requires access to a + * data network (e.g., the Internet), false otherwise. + */ + public boolean requiresNetwork() { + return mRequiresNetwork; + } + + /** + * Returns true if the provider requires access to a + * satellite-based positioning system (e.g., GPS), false + * otherwise. + */ + public boolean requiresSatellite() { + return mRequiresSatellite; + } + + /** + * Returns true if the provider requires access to an appropriate + * cellular network (e.g., to make use of cell tower IDs), false + * otherwise. + */ + public boolean requiresCell() { + return mRequiresCell; + } + + /** + * Returns true if the use of this provider may result in a + * monetary charge to the user, false if use is free. It is up to + * each provider to give accurate information. + */ + public boolean hasMonetaryCost() { + return mHasMonetaryCost; + } + + /** + * Returns true if the provider is able to provide altitude + * information, false otherwise. A provider that reports altitude + * under most circumstances but may occassionally not report it + * should return true. + */ + public boolean supportsAltitude() { + return mSupportsAltitude; + } + + /** + * Returns true if the provider is able to provide speed + * information, false otherwise. A provider that reports speed + * under most circumstances but may occassionally not report it + * should return true. + */ + public boolean supportsSpeed() { + return mSupportsSpeed; + } + + /** + * Returns true if the provider is able to provide bearing + * information, false otherwise. A provider that reports bearing + * under most circumstances but may occassionally not report it + * should return true. + */ + public boolean supportsBearing() { + return mSupportsBearing; + } + + /** + * Returns the power requirement for this provider. + * + * @return the power requirement for this provider, as one of the + * constants Criteria.POWER_REQUIREMENT_*. + */ + public int getPowerRequirement() { + return mPowerRequirement; + } + + /** + * Returns a constant describing the horizontal accuracy returned + * by this provider. + * + * @return the horizontal accuracy for this provider, as one of the + * constants Criteria.ACCURACY_*. + */ + public int getAccuracy() { + return mAccuracy; + } +} + diff --git a/location/java/com/android/internal/location/GpsLocationProvider.java b/location/java/com/android/internal/location/GpsLocationProvider.java index b15cf41..57d3c53 100644 --- a/location/java/com/android/internal/location/GpsLocationProvider.java +++ b/location/java/com/android/internal/location/GpsLocationProvider.java @@ -26,7 +26,6 @@ import android.location.ILocationManager; import android.location.Location; import android.location.LocationManager; import android.location.LocationProvider; -import android.location.LocationProviderImpl; import android.net.ConnectivityManager; import android.net.SntpClient; import android.os.Bundle; diff --git a/location/java/com/android/internal/location/LocationProviderImpl.java b/location/java/com/android/internal/location/LocationProviderImpl.java new file mode 100644 index 0000000..7041849 --- /dev/null +++ b/location/java/com/android/internal/location/LocationProviderImpl.java @@ -0,0 +1,283 @@ +/* + * 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.Config; +import android.util.Log; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; + +/** + * 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 List<LocationProviderImpl> getProviders() { + return new ArrayList<LocationProviderImpl>(sProviders); + } + + public static LocationProviderImpl getProvider(String name) { + return sProvidersByName.get(name); + } + + public static LocationProviderImpl loadFromClass(File classFile) { + if (!classFile.exists()) { + return null; + } + if (Config.LOGD) { + Log.d(TAG, "Loading class specifier file " + classFile.getPath()); + } + String className = null; + try { + BufferedReader br = + new BufferedReader(new FileReader(classFile), 8192); + className = br.readLine(); + br.close(); + Class providerClass = Class.forName(className); + if (Config.LOGD) { + Log.d(TAG, "Loading provider class " + providerClass.getName()); + } + LocationProviderImpl provider = + (LocationProviderImpl) providerClass.newInstance(); + if (Config.LOGD) { + Log.d(TAG, "Got provider instance " + provider); + } + + return provider; + } catch (IOException ioe) { + Log.e(TAG, "IOException loading config file " + + classFile.getPath(), ioe); + } catch (IllegalAccessException iae) { + Log.e(TAG, "IllegalAccessException loading class " + + className, iae); + } catch (InstantiationException ie) { + Log.e(TAG, "InstantiationException loading class " + + className, ie); + } catch (ClassNotFoundException cnfe) { + Log.e(TAG, "ClassNotFoundException loading class " + + className, cnfe); + } catch (ClassCastException cce) { + Log.e(TAG, "ClassCastException loading class " + + className, cce); + } + return null; + } + + 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 72dd07d..d3c86db 100644 --- a/location/java/com/android/internal/location/LocationProviderProxy.java +++ b/location/java/com/android/internal/location/LocationProviderProxy.java @@ -21,7 +21,6 @@ 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; diff --git a/location/java/com/android/internal/location/MockProvider.java b/location/java/com/android/internal/location/MockProvider.java index c8d5b4f..6336e2b 100644 --- a/location/java/com/android/internal/location/MockProvider.java +++ b/location/java/com/android/internal/location/MockProvider.java @@ -18,7 +18,6 @@ package com.android.internal.location; import android.location.ILocationManager; import android.location.Location; -import android.location.LocationProviderImpl; import android.os.Bundle; import android.util.PrintWriterPrinter; diff --git a/location/java/com/android/internal/location/TrackProvider.java b/location/java/com/android/internal/location/TrackProvider.java index 1686260..c6abe13 100644 --- a/location/java/com/android/internal/location/TrackProvider.java +++ b/location/java/com/android/internal/location/TrackProvider.java @@ -18,7 +18,6 @@ import java.util.StringTokenizer; import android.location.Criteria; import android.location.ILocationManager; import android.location.Location; -import android.location.LocationProviderImpl; import android.os.Bundle; import android.util.Config; import android.util.Log; |