Loading Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,7 @@ LOCAL_SRC_FILES += \ im/java/android/im/IImPlugin.aidl \ location/java/android/location/IGeocodeProvider.aidl \ location/java/android/location/IGpsStatusListener.aidl \ location/java/android/location/IGpsStatusProvider.aidl \ location/java/android/location/ILocationCollector.aidl \ location/java/android/location/ILocationListener.aidl \ location/java/android/location/ILocationManager.aidl \ Loading location/java/android/location/IGpsStatusProvider.aidl 0 → 100644 +29 −0 Original line number Diff line number Diff line /* * 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); } location/java/android/location/ILocationProvider.aidl +1 −5 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -35,8 +33,6 @@ interface ILocationProvider { boolean supportsBearing(); int getPowerRequirement(); int getAccuracy(); /* for LocationProviderImpl */ void enable(); void disable(); boolean isEnabled(); Loading location/java/com/android/internal/location/GpsLocationProvider.java +71 −69 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"; Loading Loading @@ -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(); Loading Loading @@ -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>(); Loading @@ -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(); Loading Loading @@ -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(); Loading Loading @@ -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. Loading @@ -295,7 +348,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * satellite-based positioning system (e.g., GPS), false * otherwise. */ @Override public boolean requiresSatellite() { return true; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading @@ -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; Loading @@ -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) { Loading Loading @@ -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 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; } public void wakeLockAcquired() { } 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) { Loading @@ -569,7 +569,6 @@ public class GpsLocationProvider extends LocationProviderImpl { } } @Override public void removeListener(int uid) { mClientUids.delete(uid); if (mNavigating) { Loading @@ -581,7 +580,6 @@ public class GpsLocationProvider extends LocationProviderImpl { } } @Override public boolean sendExtraCommand(String command, Bundle extras) { if ("delete_aiding_data".equals(command)) { Loading Loading @@ -632,7 +630,7 @@ public class GpsLocationProvider extends LocationProviderImpl { } // reset SV count to zero updateStatus(TEMPORARILY_UNAVAILABLE, 0); updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE, 0); } } Loading @@ -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); } } Loading Loading @@ -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); } } Loading Loading @@ -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); } } Loading location/java/com/android/internal/location/LocationProviderImpl.javadeleted 100644 → 0 +0 −234 Original line number Diff line number Diff line /* * 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() { } } Loading
Android.mk +1 −0 Original line number Diff line number Diff line Loading @@ -119,6 +119,7 @@ LOCAL_SRC_FILES += \ im/java/android/im/IImPlugin.aidl \ location/java/android/location/IGeocodeProvider.aidl \ location/java/android/location/IGpsStatusListener.aidl \ location/java/android/location/IGpsStatusProvider.aidl \ location/java/android/location/ILocationCollector.aidl \ location/java/android/location/ILocationListener.aidl \ location/java/android/location/ILocationManager.aidl \ Loading
location/java/android/location/IGpsStatusProvider.aidl 0 → 100644 +29 −0 Original line number Diff line number Diff line /* * 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); }
location/java/android/location/ILocationProvider.aidl +1 −5 Original line number Diff line number Diff line Loading @@ -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(); Loading @@ -35,8 +33,6 @@ interface ILocationProvider { boolean supportsBearing(); int getPowerRequirement(); int getAccuracy(); /* for LocationProviderImpl */ void enable(); void disable(); boolean isEnabled(); Loading
location/java/com/android/internal/location/GpsLocationProvider.java +71 −69 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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"; Loading Loading @@ -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(); Loading Loading @@ -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>(); Loading @@ -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(); Loading Loading @@ -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(); Loading Loading @@ -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. Loading @@ -295,7 +348,6 @@ public class GpsLocationProvider extends LocationProviderImpl { * satellite-based positioning system (e.g., GPS), false * otherwise. */ @Override public boolean requiresSatellite() { return true; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; } Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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); Loading @@ -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; Loading @@ -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) { Loading Loading @@ -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 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; } public void wakeLockAcquired() { } 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) { Loading @@ -569,7 +569,6 @@ public class GpsLocationProvider extends LocationProviderImpl { } } @Override public void removeListener(int uid) { mClientUids.delete(uid); if (mNavigating) { Loading @@ -581,7 +580,6 @@ public class GpsLocationProvider extends LocationProviderImpl { } } @Override public boolean sendExtraCommand(String command, Bundle extras) { if ("delete_aiding_data".equals(command)) { Loading Loading @@ -632,7 +630,7 @@ public class GpsLocationProvider extends LocationProviderImpl { } // reset SV count to zero updateStatus(TEMPORARILY_UNAVAILABLE, 0); updateStatus(LocationProvider.TEMPORARILY_UNAVAILABLE, 0); } } Loading @@ -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); } } Loading Loading @@ -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); } } Loading Loading @@ -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); } } Loading
location/java/com/android/internal/location/LocationProviderImpl.javadeleted 100644 → 0 +0 −234 Original line number Diff line number Diff line /* * 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() { } }