diff --git a/api/test-current.txt b/api/test-current.txt index e1d6e840a02da..5927e621c22f9 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -19228,6 +19228,7 @@ package android.location { method public java.util.List 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 getProviders(boolean); diff --git a/location/java/android/location/ILocationManager.aidl b/location/java/android/location/ILocationManager.aidl index 34e7a1a4a0638..49d841fb11169 100644 --- a/location/java/android/location/ILocationManager.aidl +++ b/location/java/android/location/ILocationManager.aidl @@ -69,6 +69,8 @@ interface ILocationManager in String packageName); void removeGpsNavigationMessageListener(in IGpsNavigationMessageListener listener); + int getGpsYearOfHardware(); + // --- deprecated --- List getAllProviders(); List getProviders(in Criteria criteria, boolean enabledOnly); diff --git a/location/java/android/location/LocationManager.java b/location/java/android/location/LocationManager.java index 02639b621606e..5447bb13707f6 100644 --- a/location/java/android/location/LocationManager.java +++ b/location/java/android/location/LocationManager.java @@ -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 diff --git a/services/core/java/com/android/server/LocationManagerService.java b/services/core/java/com/android/server/LocationManagerService.java index dc4309c0e0175..c55c5b61c9995 100644 --- a/services/core/java/com/android/server/LocationManagerService.java +++ b/services/core/java/com/android/server/LocationManagerService.java @@ -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); diff --git a/services/core/java/com/android/server/location/GnssLocationProvider.java b/services/core/java/com/android/server/location/GnssLocationProvider.java index 022f1b31be461..9798e56237e54 100644 --- a/services/core/java/com/android/server/location/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/GnssLocationProvider.java @@ -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 */ diff --git a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp index 21320e04f3f01..7878bc08030f2 100644 --- a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp +++ b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp @@ -42,6 +42,7 @@ static jmethodID method_reportSvStatus; static jmethodID method_reportAGpsStatus; static jmethodID method_reportNmea; static jmethodID method_setEngineCapabilities; +static jmethodID method_setGpsYearOfHardware; static jmethodID method_xtraDownloadRequest; static jmethodID method_reportNiNotification; static jmethodID method_requestRefLocation; @@ -177,6 +178,14 @@ static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length) checkAndClearExceptionFromCallback(env, __FUNCTION__); } +static void set_system_info_callback(const GpsSystemInfo* info) { + ALOGD("set_system_info_callback: year_of_hw=%d\n", info->year_of_hw); + JNIEnv* env = AndroidRuntime::getJNIEnv(); + env->CallVoidMethod(mCallbacksObj, method_setGpsYearOfHardware, + info->year_of_hw); + checkAndClearExceptionFromCallback(env, __FUNCTION__); +} + static void set_capabilities_callback(uint32_t capabilities) { ALOGD("set_capabilities_callback: %du\n", capabilities); @@ -218,7 +227,7 @@ GpsCallbacks sGpsCallbacks = { release_wakelock_callback, create_thread_callback, request_utc_time_callback, - NULL, + set_system_info_callback, }; static void xtra_download_request_callback() @@ -506,6 +515,7 @@ static void android_location_GnssLocationProvider_class_init_native(JNIEnv* env, method_reportAGpsStatus = env->GetMethodID(clazz, "reportAGpsStatus", "(II[B)V"); method_reportNmea = env->GetMethodID(clazz, "reportNmea", "(J)V"); method_setEngineCapabilities = env->GetMethodID(clazz, "setEngineCapabilities", "(I)V"); + method_setGpsYearOfHardware = env->GetMethodID(clazz, "setGpsYearOfHardware", "(I)V"); method_xtraDownloadRequest = env->GetMethodID(clazz, "xtraDownloadRequest", "()V"); method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", "(IIIIILjava/lang/String;Ljava/lang/String;IILjava/lang/String;)V");