Settings: Add preference to enable/disable assisted GPS.

Signed-off-by: Mike Lockwood <lockwood@android.com>
This commit is contained in:
Mike Lockwood
2009-06-25 16:39:09 -04:00
parent 8b81160054
commit bcab8df83e
4 changed files with 39 additions and 7 deletions

View File

@@ -1927,6 +1927,12 @@ public final class Settings {
*/
public static final String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed";
/**
* Whether assisted GPS should be enabled or not.
* @hide
*/
public static final String ASSISTED_GPS_ENABLED = "assisted_gps_enabled";
/**
* The Logging ID (a unique 64-bit value) as a hex string.
* Used as a pseudonymous identifier for logging.

View File

@@ -38,6 +38,7 @@ import android.os.PowerManager;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.Config;
import android.util.Log;
import android.util.SparseIntArray;
@@ -183,7 +184,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
// number of fixes we have received since we started navigating
private int mFixCount;
private int mPositionMode = GPS_POSITION_MODE_STANDALONE;
private boolean mAgpsConfigured;
// true if we started navigation
private boolean mStarted;
@@ -355,8 +356,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
try {
int port = Integer.parseInt(portString);
native_set_agps_server(AGPS_TYPE_SUPL, host, port);
// use MS-Based position mode if SUPL support is enabled
mPositionMode = GPS_POSITION_MODE_MS_BASED;
mAgpsConfigured = true;
} catch (NumberFormatException e) {
Log.e(TAG, "unable to parse SUPL_PORT: " + portString);
}
@@ -368,8 +368,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
try {
int port = Integer.parseInt(portString);
native_set_agps_server(AGPS_TYPE_C2K, host, port);
// use MS-Based position mode if SUPL support is enabled
mPositionMode = GPS_POSITION_MODE_MS_BASED;
mAgpsConfigured = true;
} catch (NumberFormatException e) {
Log.e(TAG, "unable to parse C2K_PORT: " + portString);
}
@@ -719,7 +718,15 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
if (!mStarted) {
if (DEBUG) Log.d(TAG, "startNavigating");
mStarted = true;
if (!native_start(mPositionMode, false, mFixInterval)) {
int positionMode;
if (mAgpsConfigured && Settings.Secure.getInt(mContext.getContentResolver(),
Settings.Secure.ASSISTED_GPS_ENABLED, 0) != 0) {
positionMode = GPS_POSITION_MODE_MS_BASED;
} else {
positionMode = GPS_POSITION_MODE_STANDALONE;
}
if (!native_start(positionMode, false, mFixInterval)) {
mStarted = false;
Log.e(TAG, "native_start failed in startNavigating()");
return;

View File

@@ -36,6 +36,7 @@
user opt-in via Setup Wizard or Settings.
-->
<string name="def_location_providers_allowed">gps</string>
<bool name="assisted_gps_enabled">true</bool>
<!-- 0 == mobile, 1 == wifi. -->
<integer name="def_network_preference">1</integer>
<bool name="def_usb_mass_storage_enabled">true</bool>

View File

@@ -64,7 +64,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
private static final String TAG = "SettingsProvider";
private static final String DATABASE_NAME = "settings.db";
private static final int DATABASE_VERSION = 34;
private static final int DATABASE_VERSION = 35;
private Context mContext;
@@ -386,6 +386,21 @@ public class DatabaseHelper extends SQLiteOpenHelper {
upgradeVersion = 34;
}
if (upgradeVersion == 34) {
db.beginTransaction();
try {
String value =
mContext.getResources().getBoolean(R.bool.assisted_gps_enabled) ? "1" : "0";
db.execSQL("INSERT OR IGNORE INTO secure(name,value) values('" +
Settings.Secure.ASSISTED_GPS_ENABLED + "','" + value + "');");
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
upgradeVersion = 35;
}
if (upgradeVersion != currentVersion) {
Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
+ ", must wipe the settings provider");
@@ -653,6 +668,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
R.string.def_location_providers_allowed);
loadBooleanSetting(stmt, Settings.Secure.ASSISTED_GPS_ENABLED,
R.bool.assisted_gps_enabled);
loadIntegerSetting(stmt, Settings.Secure.NETWORK_PREFERENCE,
R.integer.def_network_preference);