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

Commit 82f893d6 authored by Lifu Tang's avatar Lifu Tang
Browse files

Added an API to query GPS hardware version info

Change-Id: Ic45357d30da350759f56c9d061e60196acb3255b
parent a8b7bb5a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -19228,6 +19228,7 @@ package android.location {
    method public java.util.List<java.lang.String> getAllProviders();
    method public java.lang.String getBestProvider(android.location.Criteria, boolean);
    method public deprecated android.location.GpsStatus getGpsStatus(android.location.GpsStatus);
    method public int getGpsYearOfHardware();
    method public android.location.Location getLastKnownLocation(java.lang.String);
    method public android.location.LocationProvider getProvider(java.lang.String);
    method public java.util.List<java.lang.String> getProviders(boolean);
+2 −0
Original line number Diff line number Diff line
@@ -69,6 +69,8 @@ interface ILocationManager
            in String packageName);
    void removeGpsNavigationMessageListener(in IGpsNavigationMessageListener listener);

    int getGpsYearOfHardware();

    // --- deprecated ---
    List<String> getAllProviders();
    List<String> getProviders(in Criteria criteria, boolean enabledOnly);
+16 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.android.internal.location.ProviderProperties;

import android.annotation.RequiresPermission;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
@@ -1907,6 +1908,21 @@ public class LocationManager {
        return status;
    }

    /**
     * Returns the system information of the GPS hardware.
     * May return 0 if GPS hardware is earlier than 2016.
     * @hide
     */
    @TestApi
    public int getGpsYearOfHardware() {
        try {
            return mService.getGpsYearOfHardware();
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in getGpsSystemInfo: ", e);
            return 0;
        }
    }

    /**
     * Sends additional commands to a location provider.
     * Can be used to support provider specific extensions to the Location Manager API
+15 −0
Original line number Diff line number Diff line
@@ -214,6 +214,8 @@ public class LocationManagerService extends ILocationManager.Stub {
    private int mCurrentUserId = UserHandle.USER_SYSTEM;
    private int[] mCurrentUserProfiles = new int[] { UserHandle.USER_SYSTEM };

    private GnssLocationProvider.GpsSystemInfoProvider mGpsSystemInfoProvider;

    public LocationManagerService(Context context) {
        super();
        mContext = context;
@@ -460,6 +462,7 @@ public class LocationManagerService extends ILocationManager.Stub {
            // Create a gps location provider
            GnssLocationProvider gnssProvider = new GnssLocationProvider(mContext, this,
                    mLocationHandler.getLooper());
            mGpsSystemInfoProvider = gnssProvider.getGpsSystemInfoProvider();
            mGnssStatusProvider = gnssProvider.getGnssStatusProvider();
            mNetInitiatedListener = gnssProvider.getNetInitiatedListener();
            addProviderLocked(gnssProvider);
@@ -986,6 +989,18 @@ public class LocationManagerService extends ILocationManager.Stub {
        }
    }

    /**
     * Returns the system information of the GPS hardware.
     */
    @Override
    public int getGpsYearOfHardware() {
        if (mGpsNavigationMessageProvider != null) {
            return mGpsSystemInfoProvider.getGpsYearOfHardware();
        } else {
            return 0;
        }
    }

    private void addProviderLocked(LocationProviderInterface provider) {
        mProviders.add(provider);
        mProvidersByName.put(provider.getName(), provider);
+29 −0
Original line number Diff line number Diff line
@@ -406,6 +406,8 @@ public class GnssLocationProvider implements LocationProviderInterface {

    private GeofenceHardwareImpl mGeofenceHardwareImpl;

    private int mYearOfHardware = 0;

    private final IGnssStatusProvider mGnssStatusProvider = new IGnssStatusProvider.Stub() {
        @Override
        public void registerGnssStatusCallback(IGnssStatusListener callback) {
@@ -1681,6 +1683,33 @@ public class GnssLocationProvider implements LocationProviderInterface {
                (capabilities & GPS_CAPABILITY_NAV_MESSAGES) == GPS_CAPABILITY_NAV_MESSAGES);
    }

    /**
     * Called from native code to inform us the hardware information.
     */
    private void setGpsYearOfHardware(int yearOfHardware) {
        if (DEBUG) Log.d(TAG, "setGpsYearOfHardware called with " + yearOfHardware);
        mYearOfHardware = yearOfHardware;
    }

    public interface GpsSystemInfoProvider {
        /**
         * Returns the year of GPS hardware.
         */
        int getGpsYearOfHardware();
    }

    /**
     * @hide
     */
    public GpsSystemInfoProvider getGpsSystemInfoProvider() {
        return new GpsSystemInfoProvider() {
            @Override
            public int getGpsYearOfHardware() {
                return mYearOfHardware;
            }
        };
    }

    /**
     * called from native code to request XTRA data
     */
Loading