M7350v1_en_gpl

This commit is contained in:
T
2024-09-09 08:52:07 +00:00
commit f9cc65cfda
65988 changed files with 26357421 additions and 0 deletions

View File

@@ -0,0 +1,126 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.location;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.location.Address;
import android.location.GeocoderParams;
import android.location.IGeocodeProvider;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;
import java.util.List;
/**
* A class for proxying IGeocodeProvider implementations.
*
* {@hide}
*/
public class GeocoderProxy {
private static final String TAG = "GeocoderProxy";
private final Context mContext;
private final Intent mIntent;
private final Object mMutex = new Object(); // synchronizes access to mServiceConnection
private Connection mServiceConnection = new Connection(); // never null
public GeocoderProxy(Context context, String serviceName) {
mContext = context;
mIntent = new Intent(serviceName);
mContext.bindService(mIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
}
/**
* When unbundled NetworkLocationService package is updated, we
* need to unbind from the old version and re-bind to the new one.
*/
public void reconnect() {
synchronized (mMutex) {
mContext.unbindService(mServiceConnection);
mServiceConnection = new Connection();
mContext.bindService(mIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
}
}
private class Connection implements ServiceConnection {
private IGeocodeProvider mProvider;
public void onServiceConnected(ComponentName className, IBinder service) {
Log.d(TAG, "onServiceConnected " + className);
synchronized (this) {
mProvider = IGeocodeProvider.Stub.asInterface(service);
}
}
public void onServiceDisconnected(ComponentName className) {
Log.d(TAG, "onServiceDisconnected " + className);
synchronized (this) {
mProvider = null;
}
}
public IGeocodeProvider getProvider() {
synchronized (this) {
return mProvider;
}
}
}
public String getFromLocation(double latitude, double longitude, int maxResults,
GeocoderParams params, List<Address> addrs) {
IGeocodeProvider provider;
synchronized (mMutex) {
provider = mServiceConnection.getProvider();
}
if (provider != null) {
try {
return provider.getFromLocation(latitude, longitude, maxResults,
params, addrs);
} catch (RemoteException e) {
Log.e(TAG, "getFromLocation failed", e);
}
}
return "Service not Available";
}
public String getFromLocationName(String locationName,
double lowerLeftLatitude, double lowerLeftLongitude,
double upperRightLatitude, double upperRightLongitude, int maxResults,
GeocoderParams params, List<Address> addrs) {
IGeocodeProvider provider;
synchronized (mMutex) {
provider = mServiceConnection.getProvider();
}
if (provider != null) {
try {
return provider.getFromLocationName(locationName, lowerLeftLatitude,
lowerLeftLongitude, upperRightLatitude, upperRightLongitude,
maxResults, params, addrs);
} catch (RemoteException e) {
Log.e(TAG, "getFromLocationName failed", e);
}
}
return "Service not Available";
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,172 @@
/*
* Copyright (C) 2008 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.server.location;
import android.content.Context;
import android.net.Proxy;
import android.net.http.AndroidHttpClient;
import android.util.Config;
import android.util.Log;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.conn.params.ConnRouteParams;
import java.io.DataInputStream;
import java.io.IOException;
import java.util.Properties;
import java.util.Random;
/**
* A class for downloading GPS XTRA data.
*
* {@hide}
*/
public class GpsXtraDownloader {
private static final String TAG = "GpsXtraDownloader";
static final boolean DEBUG = false;
private Context mContext;
private String[] mXtraServers;
// to load balance our server requests
private int mNextServerIndex;
GpsXtraDownloader(Context context, Properties properties) {
mContext = context;
// read XTRA servers from the Properties object
int count = 0;
String server1 = properties.getProperty("XTRA_SERVER_1");
String server2 = properties.getProperty("XTRA_SERVER_2");
String server3 = properties.getProperty("XTRA_SERVER_3");
if (server1 != null) count++;
if (server2 != null) count++;
if (server3 != null) count++;
if (count == 0) {
Log.e(TAG, "No XTRA servers were specified in the GPS configuration");
return;
} else {
mXtraServers = new String[count];
count = 0;
if (server1 != null) mXtraServers[count++] = server1;
if (server2 != null) mXtraServers[count++] = server2;
if (server3 != null) mXtraServers[count++] = server3;
// randomize first server
Random random = new Random();
mNextServerIndex = random.nextInt(count);
}
}
byte[] downloadXtraData() {
String proxyHost = Proxy.getHost(mContext);
int proxyPort = Proxy.getPort(mContext);
boolean useProxy = (proxyHost != null && proxyPort != -1);
byte[] result = null;
int startIndex = mNextServerIndex;
if (mXtraServers == null) {
return null;
}
// load balance our requests among the available servers
while (result == null) {
result = doDownload(mXtraServers[mNextServerIndex], useProxy, proxyHost, proxyPort);
// increment mNextServerIndex and wrap around if necessary
mNextServerIndex++;
if (mNextServerIndex == mXtraServers.length) {
mNextServerIndex = 0;
}
// break if we have tried all the servers
if (mNextServerIndex == startIndex) break;
}
return result;
}
protected static byte[] doDownload(String url, boolean isProxySet,
String proxyHost, int proxyPort) {
if (DEBUG) Log.d(TAG, "Downloading XTRA data from " + url);
AndroidHttpClient client = null;
try {
client = AndroidHttpClient.newInstance("Android");
HttpUriRequest req = new HttpGet(url);
if (isProxySet) {
HttpHost proxy = new HttpHost(proxyHost, proxyPort);
ConnRouteParams.setDefaultProxy(req.getParams(), proxy);
}
req.addHeader(
"Accept",
"*/*, application/vnd.wap.mms-message, application/vnd.wap.sic");
req.addHeader(
"x-wap-profile",
"http://www.openmobilealliance.org/tech/profiles/UAPROF/ccppschema-20021212#");
HttpResponse response = client.execute(req);
StatusLine status = response.getStatusLine();
if (status.getStatusCode() != 200) { // HTTP 200 is success.
if (DEBUG) Log.d(TAG, "HTTP error: " + status.getReasonPhrase());
return null;
}
HttpEntity entity = response.getEntity();
byte[] body = null;
if (entity != null) {
try {
if (entity.getContentLength() > 0) {
body = new byte[(int) entity.getContentLength()];
DataInputStream dis = new DataInputStream(entity.getContent());
try {
dis.readFully(body);
} finally {
try {
dis.close();
} catch (IOException e) {
Log.e(TAG, "Unexpected IOException.", e);
}
}
}
} finally {
if (entity != null) {
entity.consumeContent();
}
}
}
return body;
} catch (Exception e) {
if (DEBUG) Log.d(TAG, "error " + e);
} finally {
if (client != null) {
client.close();
}
}
return null;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.location;
import android.location.Criteria;
import android.location.Location;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.WorkSource;
/**
* Location Manager's interface for location providers.
*
* {@hide}
*/
public interface LocationProviderInterface {
String getName();
boolean requiresNetwork();
boolean requiresSatellite();
boolean requiresCell();
boolean hasMonetaryCost();
boolean supportsAltitude();
boolean supportsSpeed();
boolean supportsBearing();
int getPowerRequirement();
boolean meetsCriteria(Criteria criteria);
int getAccuracy();
boolean isEnabled();
void enable();
void disable();
int getStatus(Bundle extras);
long getStatusUpdateTime();
void enableLocationTracking(boolean enable);
/* returns false if single shot is not supported */
boolean requestSingleShotFix();
String getInternalState();
void setMinTime(long minTime, WorkSource ws);
void updateNetworkState(int state, NetworkInfo info);
void updateLocation(Location location);
boolean sendExtraCommand(String command, Bundle extras);
void addListener(int uid);
void removeListener(int uid);
}

View File

@@ -0,0 +1,471 @@
/*
* 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.server.location;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.location.Criteria;
import android.location.ILocationProvider;
import android.location.Location;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.SystemClock;
import android.os.WorkSource;
import android.util.Log;
import com.android.internal.location.DummyLocationProvider;
/**
* A class for proxying location providers implemented as services.
*
* {@hide}
*/
public class LocationProviderProxy implements LocationProviderInterface {
private static final String TAG = "LocationProviderProxy";
private final Context mContext;
private final String mName;
private final Intent mIntent;
private final Handler mHandler;
private final Object mMutex = new Object(); // synchronizes access to non-final members
private Connection mServiceConnection = new Connection(); // never null
// cached values set by the location manager
private boolean mLocationTracking = false;
private boolean mEnabled = false;
private long mMinTime = -1;
private WorkSource mMinTimeSource = new WorkSource();
private int mNetworkState;
private NetworkInfo mNetworkInfo;
// constructor for proxying location providers implemented in a separate service
public LocationProviderProxy(Context context, String name, String serviceName,
Handler handler) {
mContext = context;
mName = name;
mIntent = new Intent(serviceName);
mHandler = handler;
mContext.bindService(mIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
}
/**
* When unbundled NetworkLocationService package is updated, we
* need to unbind from the old version and re-bind to the new one.
*/
public void reconnect() {
synchronized (mMutex) {
mContext.unbindService(mServiceConnection);
mServiceConnection = new Connection();
mContext.bindService(mIntent, mServiceConnection, Context.BIND_AUTO_CREATE);
}
}
private class Connection implements ServiceConnection, Runnable {
private ILocationProvider mProvider;
// for caching requiresNetwork, requiresSatellite, etc.
private DummyLocationProvider mCachedAttributes; // synchronized by mMutex
public void onServiceConnected(ComponentName className, IBinder service) {
Log.d(TAG, "LocationProviderProxy.onServiceConnected " + className);
synchronized (this) {
mProvider = ILocationProvider.Stub.asInterface(service);
if (mProvider != null) {
mHandler.post(this);
}
}
}
public void onServiceDisconnected(ComponentName className) {
Log.d(TAG, "LocationProviderProxy.onServiceDisconnected " + className);
synchronized (this) {
mProvider = null;
}
}
public synchronized ILocationProvider getProvider() {
return mProvider;
}
public synchronized DummyLocationProvider getCachedAttributes() {
return mCachedAttributes;
}
public void run() {
synchronized (mMutex) {
if (mServiceConnection != this) {
// This ServiceConnection no longer the one we want to bind to.
return;
}
ILocationProvider provider = getProvider();
if (provider == null) {
return;
}
// resend previous values from the location manager if the service has restarted
try {
if (mEnabled) {
provider.enable();
}
if (mLocationTracking) {
provider.enableLocationTracking(true);
}
if (mMinTime >= 0) {
provider.setMinTime(mMinTime, mMinTimeSource);
}
if (mNetworkInfo != null) {
provider.updateNetworkState(mNetworkState, mNetworkInfo);
}
} catch (RemoteException e) {
}
// init cache of parameters
if (mCachedAttributes == null) {
try {
mCachedAttributes = new DummyLocationProvider(mName, null);
mCachedAttributes.setRequiresNetwork(provider.requiresNetwork());
mCachedAttributes.setRequiresSatellite(provider.requiresSatellite());
mCachedAttributes.setRequiresCell(provider.requiresCell());
mCachedAttributes.setHasMonetaryCost(provider.hasMonetaryCost());
mCachedAttributes.setSupportsAltitude(provider.supportsAltitude());
mCachedAttributes.setSupportsSpeed(provider.supportsSpeed());
mCachedAttributes.setSupportsBearing(provider.supportsBearing());
mCachedAttributes.setPowerRequirement(provider.getPowerRequirement());
mCachedAttributes.setAccuracy(provider.getAccuracy());
} catch (RemoteException e) {
mCachedAttributes = null;
}
}
}
}
};
public String getName() {
return mName;
}
private DummyLocationProvider getCachedAttributes() {
synchronized (mMutex) {
return mServiceConnection.getCachedAttributes();
}
}
public boolean requiresNetwork() {
DummyLocationProvider cachedAttributes = getCachedAttributes();
if (cachedAttributes != null) {
return cachedAttributes.requiresNetwork();
} else {
return false;
}
}
public boolean requiresSatellite() {
DummyLocationProvider cachedAttributes = getCachedAttributes();
if (cachedAttributes != null) {
return cachedAttributes.requiresSatellite();
} else {
return false;
}
}
public boolean requiresCell() {
DummyLocationProvider cachedAttributes = getCachedAttributes();
if (cachedAttributes != null) {
return cachedAttributes.requiresCell();
} else {
return false;
}
}
public boolean hasMonetaryCost() {
DummyLocationProvider cachedAttributes = getCachedAttributes();
if (cachedAttributes != null) {
return cachedAttributes.hasMonetaryCost();
} else {
return false;
}
}
public boolean supportsAltitude() {
DummyLocationProvider cachedAttributes = getCachedAttributes();
if (cachedAttributes != null) {
return cachedAttributes.supportsAltitude();
} else {
return false;
}
}
public boolean supportsSpeed() {
DummyLocationProvider cachedAttributes = getCachedAttributes();
if (cachedAttributes != null) {
return cachedAttributes.supportsSpeed();
} else {
return false;
}
}
public boolean supportsBearing() {
DummyLocationProvider cachedAttributes = getCachedAttributes();
if (cachedAttributes != null) {
return cachedAttributes.supportsBearing();
} else {
return false;
}
}
public int getPowerRequirement() {
DummyLocationProvider cachedAttributes = getCachedAttributes();
if (cachedAttributes != null) {
return cachedAttributes.getPowerRequirement();
} else {
return -1;
}
}
public int getAccuracy() {
DummyLocationProvider cachedAttributes = getCachedAttributes();
if (cachedAttributes != null) {
return cachedAttributes.getAccuracy();
} else {
return -1;
}
}
public boolean meetsCriteria(Criteria criteria) {
synchronized (mMutex) {
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
return provider.meetsCriteria(criteria);
} catch (RemoteException e) {
}
}
}
// default implementation if we lost connection to the provider
if ((criteria.getAccuracy() != Criteria.NO_REQUIREMENT) &&
(criteria.getAccuracy() < getAccuracy())) {
return false;
}
int criteriaPower = criteria.getPowerRequirement();
if ((criteriaPower != Criteria.NO_REQUIREMENT) &&
(criteriaPower < getPowerRequirement())) {
return false;
}
if (criteria.isAltitudeRequired() && !supportsAltitude()) {
return false;
}
if (criteria.isSpeedRequired() && !supportsSpeed()) {
return false;
}
if (criteria.isBearingRequired() && !supportsBearing()) {
return false;
}
return true;
}
public void enable() {
synchronized (mMutex) {
mEnabled = true;
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
provider.enable();
} catch (RemoteException e) {
}
}
}
}
public void disable() {
synchronized (mMutex) {
mEnabled = false;
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
provider.disable();
} catch (RemoteException e) {
}
}
}
}
public boolean isEnabled() {
synchronized (mMutex) {
return mEnabled;
}
}
public int getStatus(Bundle extras) {
ILocationProvider provider;
synchronized (mMutex) {
provider = mServiceConnection.getProvider();
}
if (provider != null) {
try {
return provider.getStatus(extras);
} catch (RemoteException e) {
}
}
return 0;
}
public long getStatusUpdateTime() {
ILocationProvider provider;
synchronized (mMutex) {
provider = mServiceConnection.getProvider();
}
if (provider != null) {
try {
return provider.getStatusUpdateTime();
} catch (RemoteException e) {
}
}
return 0;
}
public String getInternalState() {
ILocationProvider provider;
synchronized (mMutex) {
provider = mServiceConnection.getProvider();
}
if (provider != null) {
try {
return provider.getInternalState();
} catch (RemoteException e) {
Log.e(TAG, "getInternalState failed", e);
}
}
return null;
}
public boolean isLocationTracking() {
synchronized (mMutex) {
return mLocationTracking;
}
}
public void enableLocationTracking(boolean enable) {
synchronized (mMutex) {
mLocationTracking = enable;
if (!enable) {
mMinTime = -1;
mMinTimeSource.clear();
}
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
provider.enableLocationTracking(enable);
} catch (RemoteException e) {
}
}
}
}
public boolean requestSingleShotFix() {
return false;
}
public long getMinTime() {
synchronized (mMutex) {
return mMinTime;
}
}
public void setMinTime(long minTime, WorkSource ws) {
synchronized (mMutex) {
mMinTime = minTime;
mMinTimeSource.set(ws);
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
provider.setMinTime(minTime, ws);
} catch (RemoteException e) {
}
}
}
}
public void updateNetworkState(int state, NetworkInfo info) {
synchronized (mMutex) {
mNetworkState = state;
mNetworkInfo = info;
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
provider.updateNetworkState(state, info);
} catch (RemoteException e) {
}
}
}
}
public void updateLocation(Location location) {
synchronized (mMutex) {
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
provider.updateLocation(location);
} catch (RemoteException e) {
}
}
}
}
public boolean sendExtraCommand(String command, Bundle extras) {
synchronized (mMutex) {
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
return provider.sendExtraCommand(command, extras);
} catch (RemoteException e) {
}
}
}
return false;
}
public void addListener(int uid) {
synchronized (mMutex) {
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
provider.addListener(uid);
} catch (RemoteException e) {
}
}
}
}
public void removeListener(int uid) {
synchronized (mMutex) {
ILocationProvider provider = mServiceConnection.getProvider();
if (provider != null) {
try {
provider.removeListener(uid);
} catch (RemoteException e) {
}
}
}
}
}

View File

@@ -0,0 +1,234 @@
/*
* 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.server.location;
import android.location.Criteria;
import android.location.ILocationManager;
import android.location.Location;
import android.location.LocationProvider;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.WorkSource;
import android.util.Log;
import android.util.PrintWriterPrinter;
import java.io.PrintWriter;
/**
* A mock location provider used by LocationManagerService to implement test providers.
*
* {@hide}
*/
public class MockProvider implements LocationProviderInterface {
private final String mName;
private final ILocationManager mLocationManager;
private final boolean mRequiresNetwork;
private final boolean mRequiresSatellite;
private final boolean mRequiresCell;
private final boolean mHasMonetaryCost;
private final boolean mSupportsAltitude;
private final boolean mSupportsSpeed;
private final boolean mSupportsBearing;
private final int mPowerRequirement;
private final int mAccuracy;
private final Location mLocation;
private int mStatus;
private long mStatusUpdateTime;
private final Bundle mExtras = new Bundle();
private boolean mHasLocation;
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) {
mName = name;
mLocationManager = locationManager;
mRequiresNetwork = requiresNetwork;
mRequiresSatellite = requiresSatellite;
mRequiresCell = requiresCell;
mHasMonetaryCost = hasMonetaryCost;
mSupportsAltitude = supportsAltitude;
mSupportsBearing = supportsBearing;
mSupportsSpeed = supportsSpeed;
mPowerRequirement = powerRequirement;
mAccuracy = accuracy;
mLocation = new Location(name);
}
public String getName() {
return mName;
}
public void disable() {
mEnabled = false;
}
public void enable() {
mEnabled = true;
}
public boolean isEnabled() {
return mEnabled;
}
public int getStatus(Bundle extras) {
if (mHasStatus) {
extras.clear();
extras.putAll(mExtras);
return mStatus;
} else {
return LocationProvider.AVAILABLE;
}
}
public long getStatusUpdateTime() {
return mStatusUpdateTime;
}
public int getAccuracy() {
return mAccuracy;
}
public int getPowerRequirement() {
return mPowerRequirement;
}
public boolean hasMonetaryCost() {
return mHasMonetaryCost;
}
public boolean requiresCell() {
return mRequiresCell;
}
public boolean requiresNetwork() {
return mRequiresNetwork;
}
public boolean requiresSatellite() {
return mRequiresSatellite;
}
public boolean supportsAltitude() {
return mSupportsAltitude;
}
public boolean supportsBearing() {
return mSupportsBearing;
}
public boolean supportsSpeed() {
return mSupportsSpeed;
}
public boolean meetsCriteria(Criteria criteria) {
if ((criteria.getAccuracy() != Criteria.NO_REQUIREMENT) &&
(criteria.getAccuracy() < mAccuracy)) {
return false;
}
int criteriaPower = criteria.getPowerRequirement();
if ((criteriaPower != Criteria.NO_REQUIREMENT) &&
(criteriaPower < mPowerRequirement)) {
return false;
}
if (criteria.isAltitudeRequired() && !mSupportsAltitude) {
return false;
}
if (criteria.isSpeedRequired() && !mSupportsSpeed) {
return false;
}
if (criteria.isBearingRequired() && !mSupportsBearing) {
return false;
}
return true;
}
public void setLocation(Location l) {
mLocation.set(l);
mHasLocation = true;
try {
mLocationManager.reportLocation(mLocation, false);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException calling reportLocation");
}
}
public void clearLocation() {
mHasLocation = false;
}
public void setStatus(int status, Bundle extras, long updateTime) {
mStatus = status;
mStatusUpdateTime = updateTime;
mExtras.clear();
if (extras != null) {
mExtras.putAll(extras);
}
mHasStatus = true;
}
public void clearStatus() {
mHasStatus = false;
mStatusUpdateTime = 0;
}
public String getInternalState() {
return null;
}
public void enableLocationTracking(boolean enable) {
}
public boolean requestSingleShotFix() {
return false;
}
public void setMinTime(long minTime, WorkSource ws) {
}
public void updateNetworkState(int state, NetworkInfo info) {
}
public void updateLocation(Location location) {
}
public boolean sendExtraCommand(String command, Bundle extras) {
return false;
}
public void addListener(int uid) {
}
public void removeListener(int uid) {
}
public void dump(PrintWriter pw, String prefix) {
pw.println(prefix + mName);
pw.println(prefix + "mHasLocation=" + mHasLocation);
pw.println(prefix + "mLocation:");
mLocation.dump(new PrintWriterPrinter(pw), prefix + " ");
pw.println(prefix + "mHasStatus=" + mHasStatus);
pw.println(prefix + "mStatus=" + mStatus);
pw.println(prefix + "mStatusUpdateTime=" + mStatusUpdateTime);
pw.println(prefix + "mExtras=" + mExtras);
}
}

View File

@@ -0,0 +1,153 @@
/*
* Copyright (C) 2010 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.server.location;
import android.location.Criteria;
import android.location.ILocationManager;
import android.location.Location;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.WorkSource;
import android.util.Log;
/**
* A passive location provider reports locations received from other providers
* for clients that want to listen passively without actually triggering
* location updates.
*
* {@hide}
*/
public class PassiveProvider implements LocationProviderInterface {
private static final String TAG = "PassiveProvider";
private final ILocationManager mLocationManager;
private boolean mTracking;
public PassiveProvider(ILocationManager locationManager) {
mLocationManager = locationManager;
}
public String getName() {
return LocationManager.PASSIVE_PROVIDER;
}
public boolean requiresNetwork() {
return false;
}
public boolean requiresSatellite() {
return false;
}
public boolean requiresCell() {
return false;
}
public boolean hasMonetaryCost() {
return false;
}
public boolean supportsAltitude() {
return false;
}
public boolean supportsSpeed() {
return false;
}
public boolean supportsBearing() {
return false;
}
public int getPowerRequirement() {
return -1;
}
public boolean meetsCriteria(Criteria criteria) {
// We do not want to match the special passive provider based on criteria.
return false;
}
public int getAccuracy() {
return -1;
}
public boolean isEnabled() {
return true;
}
public void enable() {
}
public void disable() {
}
public int getStatus(Bundle extras) {
if (mTracking) {
return LocationProvider.AVAILABLE;
} else {
return LocationProvider.TEMPORARILY_UNAVAILABLE;
}
}
public long getStatusUpdateTime() {
return -1;
}
public String getInternalState() {
return null;
}
public void enableLocationTracking(boolean enable) {
mTracking = enable;
}
public boolean requestSingleShotFix() {
return false;
}
public void setMinTime(long minTime, WorkSource ws) {
}
public void updateNetworkState(int state, NetworkInfo info) {
}
public void updateLocation(Location location) {
if (mTracking) {
try {
// pass the location back to the location manager
mLocationManager.reportLocation(location, true);
} catch (RemoteException e) {
Log.e(TAG, "RemoteException calling reportLocation");
}
}
}
public boolean sendExtraCommand(String command, Bundle extras) {
return false;
}
public void addListener(int uid) {
}
public void removeListener(int uid) {
}
}