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

Commit 1f060a17 authored by Colin Cross's avatar Colin Cross Committed by Gerrit Code Review
Browse files

Merge "GpsLocationProvider: look for config file in /etc/gps.<ro.hardware.gps>.conf"

parents 4fea742c 0246363b
Loading
Loading
Loading
Loading
+53 −28
Original line number Original line Diff line number Diff line
@@ -53,6 +53,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.os.SystemProperties;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.WorkSource;
import android.os.WorkSource;
import android.provider.Settings;
import android.provider.Settings;
@@ -61,6 +62,7 @@ import android.provider.Telephony.Sms.Intents;
import android.telephony.SmsMessage;
import android.telephony.SmsMessage;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.telephony.gsm.GsmCellLocation;
import android.telephony.gsm.GsmCellLocation;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
import android.util.NtpTrustedTime;
import android.util.NtpTrustedTime;


@@ -84,6 +86,8 @@ import java.util.Date;
import java.util.Map.Entry;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Properties;


import libcore.io.IoUtils;

/**
/**
 * A GPS implementation of LocationProvider used by LocationManager.
 * A GPS implementation of LocationProvider used by LocationManager.
 *
 *
@@ -194,7 +198,9 @@ public class GpsLocationProvider implements LocationProviderInterface {
    private static final int AGPS_SETID_TYPE_IMSI = 1;
    private static final int AGPS_SETID_TYPE_IMSI = 1;
    private static final int AGPS_SETID_TYPE_MSISDN = 2;
    private static final int AGPS_SETID_TYPE_MSISDN = 2;


    private static final String PROPERTIES_FILE = "/etc/gps.conf";
    private static final String PROPERTIES_FILE_PREFIX = "/etc/gps";
    private static final String PROPERTIES_FILE_SUFFIX = ".conf";
    private static final String DEFAULT_PROPERTIES_FILE = PROPERTIES_FILE_PREFIX + PROPERTIES_FILE_SUFFIX;


    private static final int GPS_GEOFENCE_UNAVAILABLE = 1<<0L;
    private static final int GPS_GEOFENCE_UNAVAILABLE = 1<<0L;
    private static final int GPS_GEOFENCE_AVAILABLE = 1<<1L;
    private static final int GPS_GEOFENCE_AVAILABLE = 1<<1L;
@@ -444,6 +450,44 @@ public class GpsLocationProvider implements LocationProviderInterface {
        return native_is_supported();
        return native_is_supported();
    }
    }


    private boolean loadPropertiesFile(String filename) {
        mProperties = new Properties();
        try {
            File file = new File(filename);
            FileInputStream stream = null;
            try {
                stream = new FileInputStream(file);
                mProperties.load(stream);
            } finally {
                IoUtils.closeQuietly(stream);
            }

            mSuplServerHost = mProperties.getProperty("SUPL_HOST");
            String portString = mProperties.getProperty("SUPL_PORT");
            if (mSuplServerHost != null && portString != null) {
                try {
                    mSuplServerPort = Integer.parseInt(portString);
                } catch (NumberFormatException e) {
                    Log.e(TAG, "unable to parse SUPL_PORT: " + portString);
                }
            }

            mC2KServerHost = mProperties.getProperty("C2K_HOST");
            portString = mProperties.getProperty("C2K_PORT");
            if (mC2KServerHost != null && portString != null) {
                try {
                    mC2KServerPort = Integer.parseInt(portString);
                } catch (NumberFormatException e) {
                    Log.e(TAG, "unable to parse C2K_PORT: " + portString);
                }
            }
        } catch (IOException e) {
            Log.w(TAG, "Could not open GPS configuration file " + filename);
            return false;
        }
        return true;
    }

    public GpsLocationProvider(Context context, ILocationManager ilocationManager,
    public GpsLocationProvider(Context context, ILocationManager ilocationManager,
            Looper looper) {
            Looper looper) {
        mContext = context;
        mContext = context;
@@ -472,34 +516,15 @@ public class GpsLocationProvider implements LocationProviderInterface {
        mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService(
        mBatteryStats = IBatteryStats.Stub.asInterface(ServiceManager.getService(
                BatteryStats.SERVICE_NAME));
                BatteryStats.SERVICE_NAME));


        mProperties = new Properties();
        boolean propertiesLoaded = false;
        try {
        final String gpsHardware = SystemProperties.get("ro.hardware.gps");
            File file = new File(PROPERTIES_FILE);
        if (!TextUtils.isEmpty(gpsHardware)) {
            FileInputStream stream = new FileInputStream(file);
            final String propFilename = PROPERTIES_FILE_PREFIX + "." + gpsHardware + PROPERTIES_FILE_SUFFIX;
            mProperties.load(stream);
            propertiesLoaded = loadPropertiesFile(propFilename);
            stream.close();

            mSuplServerHost = mProperties.getProperty("SUPL_HOST");
            String portString = mProperties.getProperty("SUPL_PORT");
            if (mSuplServerHost != null && portString != null) {
                try {
                    mSuplServerPort = Integer.parseInt(portString);
                } catch (NumberFormatException e) {
                    Log.e(TAG, "unable to parse SUPL_PORT: " + portString);
                }
        }
        }


            mC2KServerHost = mProperties.getProperty("C2K_HOST");
        if (!propertiesLoaded) {
            portString = mProperties.getProperty("C2K_PORT");
            loadPropertiesFile(DEFAULT_PROPERTIES_FILE);
            if (mC2KServerHost != null && portString != null) {
                try {
                    mC2KServerPort = Integer.parseInt(portString);
                } catch (NumberFormatException e) {
                    Log.e(TAG, "unable to parse C2K_PORT: " + portString);
                }
            }
        } catch (IOException e) {
            Log.w(TAG, "Could not open GPS configuration file " + PROPERTIES_FILE);
        }
        }


        // construct handler, listen for events
        // construct handler, listen for events