Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bcab8df8 authored by Mike Lockwood's avatar Mike Lockwood
Browse files

Settings: Add preference to enable/disable assisted GPS.

parent 8b811600
Loading
Loading
Loading
Loading
+6 −0
Original line number Original line Diff line number Diff line
@@ -1927,6 +1927,12 @@ public final class Settings {
         */
         */
        public static final String LOCATION_PROVIDERS_ALLOWED = "location_providers_allowed";
        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.
         * The Logging ID (a unique 64-bit value) as a hex string.
         * Used as a pseudonymous identifier for logging.
         * Used as a pseudonymous identifier for logging.
+13 −6
Original line number Original line Diff line number Diff line
@@ -38,6 +38,7 @@ import android.os.PowerManager;
import android.os.RemoteException;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.ServiceManager;
import android.os.SystemClock;
import android.os.SystemClock;
import android.provider.Settings;
import android.util.Config;
import android.util.Config;
import android.util.Log;
import android.util.Log;
import android.util.SparseIntArray;
import android.util.SparseIntArray;
@@ -183,7 +184,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
    // number of fixes we have received since we started navigating
    // number of fixes we have received since we started navigating
    private int mFixCount;
    private int mFixCount;


    private int mPositionMode = GPS_POSITION_MODE_STANDALONE;
    private boolean mAgpsConfigured;


    // true if we started navigation
    // true if we started navigation
    private boolean mStarted;
    private boolean mStarted;
@@ -355,8 +356,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
                try {
                try {
                    int port = Integer.parseInt(portString);
                    int port = Integer.parseInt(portString);
                    native_set_agps_server(AGPS_TYPE_SUPL, host, port);
                    native_set_agps_server(AGPS_TYPE_SUPL, host, port);
                    // use MS-Based position mode if SUPL support is enabled
                    mAgpsConfigured = true;
                    mPositionMode = GPS_POSITION_MODE_MS_BASED;
                } catch (NumberFormatException e) {
                } catch (NumberFormatException e) {
                    Log.e(TAG, "unable to parse SUPL_PORT: " + portString);
                    Log.e(TAG, "unable to parse SUPL_PORT: " + portString);
                }
                }
@@ -368,8 +368,7 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
                try {
                try {
                    int port = Integer.parseInt(portString);
                    int port = Integer.parseInt(portString);
                    native_set_agps_server(AGPS_TYPE_C2K, host, port);
                    native_set_agps_server(AGPS_TYPE_C2K, host, port);
                    // use MS-Based position mode if SUPL support is enabled
                    mAgpsConfigured = true;
                    mPositionMode = GPS_POSITION_MODE_MS_BASED;
                } catch (NumberFormatException e) {
                } catch (NumberFormatException e) {
                    Log.e(TAG, "unable to parse C2K_PORT: " + portString);
                    Log.e(TAG, "unable to parse C2K_PORT: " + portString);
                }
                }
@@ -719,7 +718,15 @@ public class GpsLocationProvider extends ILocationProvider.Stub {
        if (!mStarted) {
        if (!mStarted) {
            if (DEBUG) Log.d(TAG, "startNavigating");
            if (DEBUG) Log.d(TAG, "startNavigating");
            mStarted = true;
            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;
                mStarted = false;
                Log.e(TAG, "native_start failed in startNavigating()");
                Log.e(TAG, "native_start failed in startNavigating()");
                return;
                return;
+1 −0
Original line number Original line Diff line number Diff line
@@ -36,6 +36,7 @@
         user opt-in via Setup Wizard or Settings.  
         user opt-in via Setup Wizard or Settings.  
    -->
    -->
    <string name="def_location_providers_allowed">gps</string>
    <string name="def_location_providers_allowed">gps</string>
    <bool name="assisted_gps_enabled">true</bool>
    <!--  0 == mobile, 1 == wifi. -->
    <!--  0 == mobile, 1 == wifi. -->
    <integer name="def_network_preference">1</integer>
    <integer name="def_network_preference">1</integer>
    <bool name="def_usb_mass_storage_enabled">true</bool>
    <bool name="def_usb_mass_storage_enabled">true</bool>
+19 −1
Original line number Original line Diff line number Diff line
@@ -64,7 +64,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {


    private static final String TAG = "SettingsProvider";
    private static final String TAG = "SettingsProvider";
    private static final String DATABASE_NAME = "settings.db";
    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;
    private Context mContext;


@@ -386,6 +386,21 @@ public class DatabaseHelper extends SQLiteOpenHelper {
            upgradeVersion = 34;
            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) {
        if (upgradeVersion != currentVersion) {
            Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
            Log.w(TAG, "Got stuck trying to upgrade from version " + upgradeVersion
                    + ", must wipe the settings provider");
                    + ", must wipe the settings provider");
@@ -653,6 +668,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
        loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
        loadStringSetting(stmt, Settings.Secure.LOCATION_PROVIDERS_ALLOWED,
                R.string.def_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,
        loadIntegerSetting(stmt, Settings.Secure.NETWORK_PREFERENCE,
                R.integer.def_network_preference);
                R.integer.def_network_preference);