am b34b3211: Merge "Re-introduce single-shot mode, set MS Assist Mode A when in single-shot mode." into jb-mr2-dev

* commit 'b34b3211e01b0ae946f786b220f73d340159503b':
  Re-introduce single-shot mode, set MS Assist Mode A when in single-shot mode.
This commit is contained in:
Stan Chesnutt
2013-04-15 19:52:52 -07:00
committed by Android Git Automerger

View File

@@ -36,6 +36,7 @@ import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
import android.location.LocationProvider; import android.location.LocationProvider;
import android.location.LocationRequest;
import android.net.ConnectivityManager; import android.net.ConnectivityManager;
import android.net.NetworkInfo; import android.net.NetworkInfo;
import android.net.Uri; import android.net.Uri;
@@ -262,6 +263,9 @@ public class GpsLocationProvider implements LocationProviderInterface {
// true if we started navigation // true if we started navigation
private boolean mStarted; private boolean mStarted;
// true if single shot request is in progress
private boolean mSingleShot;
// capabilities of the GPS engine // capabilities of the GPS engine
private int mEngineCapabilities; private int mEngineCapabilities;
@@ -382,7 +386,7 @@ public class GpsLocationProvider implements LocationProviderInterface {
if (action.equals(ALARM_WAKEUP)) { if (action.equals(ALARM_WAKEUP)) {
if (DEBUG) Log.d(TAG, "ALARM_WAKEUP"); if (DEBUG) Log.d(TAG, "ALARM_WAKEUP");
startNavigating(); startNavigating(false);
} else if (action.equals(ALARM_TIMEOUT)) { } else if (action.equals(ALARM_TIMEOUT)) {
if (DEBUG) Log.d(TAG, "ALARM_TIMEOUT"); if (DEBUG) Log.d(TAG, "ALARM_TIMEOUT");
hibernate(); hibernate();
@@ -803,10 +807,22 @@ public class GpsLocationProvider implements LocationProviderInterface {
} }
private void handleSetRequest(ProviderRequest request, WorkSource source) { private void handleSetRequest(ProviderRequest request, WorkSource source) {
boolean singleShot = false;
// see if the request is for a single update
if (request.locationRequests != null && request.locationRequests.size() > 0) {
// if any request has zero or more than one updates
// requested, then this is not single-shot mode
singleShot = true;
for (LocationRequest lr : request.locationRequests) {
if (lr.getNumUpdates() != 1) {
singleShot = false;
}
}
}
if (DEBUG) Log.d(TAG, "setRequest " + request); if (DEBUG) Log.d(TAG, "setRequest " + request);
if (request.reportLocation) { if (request.reportLocation) {
// update client uids // update client uids
updateClientUids(source); updateClientUids(source);
@@ -828,7 +844,7 @@ public class GpsLocationProvider implements LocationProviderInterface {
} }
} else if (!mStarted) { } else if (!mStarted) {
// start GPS // start GPS
startNavigating(); startNavigating(singleShot);
} }
} else { } else {
updateClientUids(new WorkSource()); updateClientUids(new WorkSource());
@@ -982,21 +998,44 @@ public class GpsLocationProvider implements LocationProviderInterface {
return false; return false;
} }
private void startNavigating() { private void startNavigating(boolean singleShot) {
if (!mStarted) { if (!mStarted) {
if (DEBUG) Log.d(TAG, "startNavigating"); if (DEBUG) Log.d(TAG, "startNavigating, singleShot is " + singleShot);
mTimeToFirstFix = 0; mTimeToFirstFix = 0;
mLastFixTime = 0; mLastFixTime = 0;
mStarted = true; mStarted = true;
mSingleShot = singleShot;
mPositionMode = GPS_POSITION_MODE_STANDALONE; mPositionMode = GPS_POSITION_MODE_STANDALONE;
if (Settings.Global.getInt(mContext.getContentResolver(), if (Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.ASSISTED_GPS_ENABLED, 1) != 0) { Settings.Global.ASSISTED_GPS_ENABLED, 1) != 0) {
if (hasCapability(GPS_CAPABILITY_MSB)) { if (singleShot && hasCapability(GPS_CAPABILITY_MSA)) {
mPositionMode = GPS_POSITION_MODE_MS_ASSISTED;
} else if (hasCapability(GPS_CAPABILITY_MSB)) {
mPositionMode = GPS_POSITION_MODE_MS_BASED; mPositionMode = GPS_POSITION_MODE_MS_BASED;
} }
} }
if (DEBUG) {
String mode;
switch(mPositionMode) {
case GPS_POSITION_MODE_STANDALONE:
mode = "standalone";
break;
case GPS_POSITION_MODE_MS_ASSISTED:
mode = "MS_ASSISTED";
break;
case GPS_POSITION_MODE_MS_BASED:
mode = "MS_BASED";
break;
default:
mode = "unknown";
break;
}
Log.d(TAG, "setting position_mode to " + mode);
}
int interval = (hasCapability(GPS_CAPABILITY_SCHEDULING) ? mFixInterval : 1000); int interval = (hasCapability(GPS_CAPABILITY_SCHEDULING) ? mFixInterval : 1000);
if (!native_set_position_mode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC, if (!native_set_position_mode(mPositionMode, GPS_POSITION_RECURRENCE_PERIODIC,
interval, 0, 0)) { interval, 0, 0)) {
@@ -1028,6 +1067,7 @@ public class GpsLocationProvider implements LocationProviderInterface {
if (DEBUG) Log.d(TAG, "stopNavigating"); if (DEBUG) Log.d(TAG, "stopNavigating");
if (mStarted) { if (mStarted) {
mStarted = false; mStarted = false;
mSingleShot = false;
native_stop(); native_stop();
mTimeToFirstFix = 0; mTimeToFirstFix = 0;
mLastFixTime = 0; mLastFixTime = 0;
@@ -1122,6 +1162,10 @@ public class GpsLocationProvider implements LocationProviderInterface {
} }
} }
if (mSingleShot) {
stopNavigating();
}
if (mStarted && mStatus != LocationProvider.AVAILABLE) { if (mStarted && mStatus != LocationProvider.AVAILABLE) {
// we want to time out if we do not receive a fix // we want to time out if we do not receive a fix
// within the time out and we are requesting infrequent fixes // within the time out and we are requesting infrequent fixes
@@ -1283,7 +1327,8 @@ public class GpsLocationProvider implements LocationProviderInterface {
if (DEBUG) Log.d(TAG, "PhoneConstants.APN_REQUEST_STARTED"); if (DEBUG) Log.d(TAG, "PhoneConstants.APN_REQUEST_STARTED");
// Nothing to do here // Nothing to do here
} else { } else {
if (DEBUG) Log.d(TAG, "startUsingNetworkFeature failed"); if (DEBUG) Log.d(TAG, "startUsingNetworkFeature failed, value is " +
result);
mAGpsDataConnectionState = AGPS_DATA_CONNECTION_CLOSED; mAGpsDataConnectionState = AGPS_DATA_CONNECTION_CLOSED;
native_agps_data_conn_failed(); native_agps_data_conn_failed();
} }