From 607b88cb7f08407e2d64a4dc38052ed442cd7201 Mon Sep 17 00:00:00 2001 From: Shubham Dubey Date: Tue, 11 Jan 2022 05:26:13 +0000 Subject: [PATCH] Revert "Add AGnssRil AIDL HAL (frameworks/base)" Revert submission 16548632-IAGnssRil-AIDL Reason for revert: Breaking Build BUGID: b/213964109 Reverted Changes: I087f7c9ae:Add AGnssRil AIDL HAL (frameworks/base) Ie5746ae25:Add IAGnssRil AIDL HAL (hardware/interfaces) Change-Id: Idc83d9a3c973a4ce9ea9d876d56321c5e7bf4dd4 --- .../location/gnss/GnssLocationProvider.java | 147 ++------------- .../server/location/gnss/hal/GnssNative.java | 15 +- ...d_server_location_GnssLocationProvider.cpp | 125 ++++++++++--- services/core/jni/gnss/AGnssRil.cpp | 172 ------------------ services/core/jni/gnss/AGnssRil.h | 91 --------- services/core/jni/gnss/AGnssRilCallback.cpp | 69 ------- services/core/jni/gnss/AGnssRilCallback.h | 90 --------- services/core/jni/gnss/Android.bp | 2 - .../server/location/gnss/hal/FakeGnssHal.java | 3 +- 9 files changed, 123 insertions(+), 591 deletions(-) delete mode 100644 services/core/jni/gnss/AGnssRil.cpp delete mode 100644 services/core/jni/gnss/AGnssRil.h delete mode 100644 services/core/jni/gnss/AGnssRilCallback.cpp delete mode 100644 services/core/jni/gnss/AGnssRilCallback.h diff --git a/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java b/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java index a8102f3aa33b6..f1141845f2bd6 100644 --- a/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java +++ b/services/core/java/com/android/server/location/gnss/GnssLocationProvider.java @@ -16,15 +16,14 @@ package com.android.server.location.gnss; -import static android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP; import static android.content.pm.PackageManager.FEATURE_WATCH; + +import static android.app.AlarmManager.ELAPSED_REALTIME_WAKEUP; import static android.location.provider.ProviderProperties.ACCURACY_FINE; import static android.location.provider.ProviderProperties.POWER_USAGE_HIGH; import static com.android.internal.util.ConcurrentUtils.DIRECT_EXECUTOR; import static com.android.server.location.gnss.hal.GnssNative.AGPS_REF_LOCATION_TYPE_GSM_CELLID; -import static com.android.server.location.gnss.hal.GnssNative.AGPS_REF_LOCATION_TYPE_LTE_CELLID; -import static com.android.server.location.gnss.hal.GnssNative.AGPS_REF_LOCATION_TYPE_NR_CELLID; import static com.android.server.location.gnss.hal.GnssNative.AGPS_REF_LOCATION_TYPE_UMTS_CELLID; import static com.android.server.location.gnss.hal.GnssNative.AGPS_SETID_TYPE_IMSI; import static com.android.server.location.gnss.hal.GnssNative.AGPS_SETID_TYPE_MSISDN; @@ -85,18 +84,9 @@ import android.os.WorkSource; import android.os.WorkSource.WorkChain; import android.provider.Settings; import android.telephony.CarrierConfigManager; -import android.telephony.CellIdentity; -import android.telephony.CellIdentityGsm; -import android.telephony.CellIdentityLte; -import android.telephony.CellIdentityNr; -import android.telephony.CellIdentityWcdma; -import android.telephony.CellInfo; -import android.telephony.CellInfoGsm; -import android.telephony.CellInfoLte; -import android.telephony.CellInfoNr; -import android.telephony.CellInfoWcdma; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; +import android.telephony.gsm.GsmCellLocation; import android.text.TextUtils; import android.text.format.DateUtils; import android.util.Log; @@ -120,7 +110,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Objects; @@ -1397,127 +1386,29 @@ public class GnssLocationProvider extends AbstractLocationProvider implements postWithWakeLockHeld(mNtpTimeHelper::retrieveAndInjectNtpTime); } - - private static int getCellType(CellInfo ci) { - if (ci instanceof CellInfoGsm) { - return CellInfo.TYPE_GSM; - } else if (ci instanceof CellInfoWcdma) { - return CellInfo.TYPE_WCDMA; - } else if (ci instanceof CellInfoLte) { - return CellInfo.TYPE_LTE; - } else if (ci instanceof CellInfoNr) { - return CellInfo.TYPE_NR; - } - return CellInfo.TYPE_UNKNOWN; - } - - /** - * Extract the CID/CI for GSM/WCDMA/LTE/NR - * - * @return the cell ID or -1 if invalid - */ - private static long getCidFromCellIdentity(CellIdentity id) { - if (id == null) return -1; - long cid = -1; - switch(id.getType()) { - case CellInfo.TYPE_GSM: cid = ((CellIdentityGsm) id).getCid(); break; - case CellInfo.TYPE_WCDMA: cid = ((CellIdentityWcdma) id).getCid(); break; - case CellInfo.TYPE_LTE: cid = ((CellIdentityLte) id).getCi(); break; - case CellInfo.TYPE_NR: cid = ((CellIdentityNr) id).getNci(); break; - default: break; - } - // If the CID is unreported - if (cid == (id.getType() == CellInfo.TYPE_NR - ? CellInfo.UNAVAILABLE_LONG : CellInfo.UNAVAILABLE)) { - cid = -1; - } - - return cid; - } - - private void setRefLocation(int type, CellIdentity ci) { - String mcc_str = ci.getMccString(); - String mnc_str = ci.getMncString(); - int mcc = mcc_str != null ? Integer.parseInt(mcc_str) : CellInfo.UNAVAILABLE; - int mnc = mnc_str != null ? Integer.parseInt(mnc_str) : CellInfo.UNAVAILABLE; - int lac = CellInfo.UNAVAILABLE; - int tac = CellInfo.UNAVAILABLE; - int pcid = CellInfo.UNAVAILABLE; - int arfcn = CellInfo.UNAVAILABLE; - long cid = CellInfo.UNAVAILABLE_LONG; - - switch (type) { - case AGPS_REF_LOCATION_TYPE_GSM_CELLID: - CellIdentityGsm cig = (CellIdentityGsm) ci; - cid = cig.getCid(); - lac = cig.getLac(); - break; - case AGPS_REF_LOCATION_TYPE_UMTS_CELLID: - CellIdentityWcdma ciw = (CellIdentityWcdma) ci; - cid = ciw.getCid(); - lac = ciw.getLac(); - break; - case AGPS_REF_LOCATION_TYPE_LTE_CELLID: - CellIdentityLte cil = (CellIdentityLte) ci; - cid = cil.getCi(); - tac = cil.getTac(); - pcid = cil.getPci(); - break; - case AGPS_REF_LOCATION_TYPE_NR_CELLID: - CellIdentityNr cin = (CellIdentityNr) ci; - cid = cin.getNci(); - tac = cin.getTac(); - pcid = cin.getPci(); - arfcn = cin.getNrarfcn(); - break; - default: - } - - mGnssNative.setAgpsReferenceLocationCellId( - type, mcc, mnc, lac, cid, tac, pcid, arfcn); - } - private void requestRefLocation() { TelephonyManager phone = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); - final int phoneType = phone.getPhoneType(); if (phoneType == TelephonyManager.PHONE_TYPE_GSM) { - - List cil = phone.getAllCellInfo(); - if (cil != null) { - HashMap cellIdentityMap = new HashMap<>(); - cil.sort(Comparator.comparingInt( - (CellInfo ci) -> ci.getCellSignalStrength().getAsuLevel()).reversed()); - - for (CellInfo ci : cil) { - int status = ci.getCellConnectionStatus(); - if (status == CellInfo.CONNECTION_PRIMARY_SERVING - || status == CellInfo.CONNECTION_SECONDARY_SERVING) { - CellIdentity c = ci.getCellIdentity(); - int t = getCellType(ci); - if (getCidFromCellIdentity(c) != -1 - && !cellIdentityMap.containsKey(t)) { - cellIdentityMap.put(t, c); - } - } - } - - if (cellIdentityMap.containsKey(CellInfo.TYPE_GSM)) { - setRefLocation(AGPS_REF_LOCATION_TYPE_GSM_CELLID, - cellIdentityMap.get(CellInfo.TYPE_GSM)); - } else if (cellIdentityMap.containsKey(CellInfo.TYPE_WCDMA)) { - setRefLocation(AGPS_REF_LOCATION_TYPE_UMTS_CELLID, - cellIdentityMap.get(CellInfo.TYPE_WCDMA)); - } else if (cellIdentityMap.containsKey(CellInfo.TYPE_LTE)) { - setRefLocation(AGPS_REF_LOCATION_TYPE_LTE_CELLID, - cellIdentityMap.get(CellInfo.TYPE_LTE)); - } else if (cellIdentityMap.containsKey(CellInfo.TYPE_NR)) { - setRefLocation(AGPS_REF_LOCATION_TYPE_NR_CELLID, - cellIdentityMap.get(CellInfo.TYPE_NR)); + GsmCellLocation gsm_cell = (GsmCellLocation) phone.getCellLocation(); + if ((gsm_cell != null) && (phone.getNetworkOperator() != null) + && (phone.getNetworkOperator().length() > 3)) { + int type; + int mcc = Integer.parseInt(phone.getNetworkOperator().substring(0, 3)); + int mnc = Integer.parseInt(phone.getNetworkOperator().substring(3)); + int networkType = phone.getNetworkType(); + if (networkType == TelephonyManager.NETWORK_TYPE_UMTS + || networkType == TelephonyManager.NETWORK_TYPE_HSDPA + || networkType == TelephonyManager.NETWORK_TYPE_HSUPA + || networkType == TelephonyManager.NETWORK_TYPE_HSPA + || networkType == TelephonyManager.NETWORK_TYPE_HSPAP) { + type = AGPS_REF_LOCATION_TYPE_UMTS_CELLID; } else { - Log.e(TAG, "No available serving cell information."); + type = AGPS_REF_LOCATION_TYPE_GSM_CELLID; } + mGnssNative.setAgpsReferenceLocationCellId(type, mcc, mnc, gsm_cell.getLac(), + gsm_cell.getCid()); } else { Log.e(TAG, "Error getting cell location info."); } diff --git a/services/core/java/com/android/server/location/gnss/hal/GnssNative.java b/services/core/java/com/android/server/location/gnss/hal/GnssNative.java index 01b1394e6525b..a513e08983444 100644 --- a/services/core/java/com/android/server/location/gnss/hal/GnssNative.java +++ b/services/core/java/com/android/server/location/gnss/hal/GnssNative.java @@ -124,12 +124,9 @@ public class GnssNative { // IMPORTANT - must match OEM definitions, this isn't part of a hal for some reason public static final int AGPS_REF_LOCATION_TYPE_GSM_CELLID = 1; public static final int AGPS_REF_LOCATION_TYPE_UMTS_CELLID = 2; - public static final int AGPS_REF_LOCATION_TYPE_LTE_CELLID = 4; - public static final int AGPS_REF_LOCATION_TYPE_NR_CELLID = 8; @IntDef(prefix = "AGPS_REF_LOCATION_TYPE_", value = {AGPS_REF_LOCATION_TYPE_GSM_CELLID, - AGPS_REF_LOCATION_TYPE_UMTS_CELLID, AGPS_REF_LOCATION_TYPE_LTE_CELLID, - AGPS_REF_LOCATION_TYPE_NR_CELLID}) + AGPS_REF_LOCATION_TYPE_UMTS_CELLID}) @Retention(RetentionPolicy.SOURCE) public @interface AgpsReferenceLocationType {} @@ -933,9 +930,9 @@ public class GnssNative { * Sets AGPS reference cell id location. */ public void setAgpsReferenceLocationCellId(@AgpsReferenceLocationType int type, int mcc, - int mnc, int lac, long cid, int tac, int pcid, int arfcn) { + int mnc, int lac, int cid) { Preconditions.checkState(mRegistered); - mGnssHal.setAgpsReferenceLocationCellId(type, mcc, mnc, lac, cid, tac, pcid, arfcn); + mGnssHal.setAgpsReferenceLocationCellId(type, mcc, mnc, lac, cid); } /** @@ -1436,8 +1433,8 @@ public class GnssNative { } protected void setAgpsReferenceLocationCellId(@AgpsReferenceLocationType int type, int mcc, - int mnc, int lac, long cid, int tac, int pcid, int arfcn) { - native_agps_set_ref_location_cellid(type, mcc, mnc, lac, cid, tac, pcid, arfcn); + int mnc, int lac, int cid) { + native_agps_set_ref_location_cellid(type, mcc, mnc, lac, cid); } protected boolean isPsdsSupported() { @@ -1578,7 +1575,7 @@ public class GnssNative { private static native void native_agps_set_id(int type, String setid); private static native void native_agps_set_ref_location_cellid(int type, int mcc, int mnc, - int lac, long cid, int tac, int pcid, int arfcn); + int lac, int cid); // PSDS APIs diff --git a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp index 5d0023ecd53ac..be656e3f3a27e 100644 --- a/services/core/jni/com_android_server_location_GnssLocationProvider.cpp +++ b/services/core/jni/com_android_server_location_GnssLocationProvider.cpp @@ -51,7 +51,6 @@ #include "android_runtime/AndroidRuntime.h" #include "android_runtime/Log.h" #include "gnss/AGnss.h" -#include "gnss/AGnssRil.h" #include "gnss/GnssAntennaInfoCallback.h" #include "gnss/GnssBatching.h" #include "gnss/GnssConfiguration.h" @@ -77,6 +76,8 @@ static jmethodID method_setGnssHardwareModelName; static jmethodID method_psdsDownloadRequest; static jmethodID method_reportNiNotification; static jmethodID method_requestLocation; +static jmethodID method_requestRefLocation; +static jmethodID method_requestSetID; static jmethodID method_requestUtcTime; static jmethodID method_reportGnssServiceDied; static jmethodID method_reportGnssPowerStats; @@ -125,6 +126,7 @@ using android::hardware::hidl_string; using android::hardware::hidl_death_recipient; using android::hardware::gnss::V1_0::GnssLocationFlags; +using android::hardware::gnss::V1_0::IAGnssRilCallback; using android::hardware::gnss::V1_0::IGnssNavigationMessage; using android::hardware::gnss::V1_0::IGnssNavigationMessageCallback; using android::hardware::gnss::V1_0::IGnssNi; @@ -156,6 +158,8 @@ using IGnssCallback_V1_0 = android::hardware::gnss::V1_0::IGnssCallback; using IGnssCallback_V2_0 = android::hardware::gnss::V2_0::IGnssCallback; using IGnssCallback_V2_1 = android::hardware::gnss::V2_1::IGnssCallback; using IGnssAntennaInfo = android::hardware::gnss::V2_1::IGnssAntennaInfo; +using IAGnssRil_V1_0 = android::hardware::gnss::V1_0::IAGnssRil; +using IAGnssRil_V2_0 = android::hardware::gnss::V2_0::IAGnssRil; using IMeasurementCorrections_V1_0 = android::hardware::gnss::measurement_corrections::V1_0::IMeasurementCorrections; using IMeasurementCorrections_V1_1 = android::hardware::gnss::measurement_corrections::V1_1::IMeasurementCorrections; @@ -171,9 +175,7 @@ using android::hardware::gnss::GnssPowerStats; using android::hardware::gnss::IGnssPowerIndication; using android::hardware::gnss::IGnssPowerIndicationCallback; using android::hardware::gnss::PsdsType; - using IAGnssAidl = android::hardware::gnss::IAGnss; -using IAGnssRilAidl = android::hardware::gnss::IAGnssRil; using IGnssAidl = android::hardware::gnss::IGnss; using IGnssCallbackAidl = android::hardware::gnss::IGnssCallback; using IGnssBatchingAidl = android::hardware::gnss::IGnssBatching; @@ -206,6 +208,8 @@ sp gnssHalAidl = nullptr; sp gnssBatchingAidlIface = nullptr; sp gnssPsdsAidlIface = nullptr; sp gnssXtraIface = nullptr; +sp agnssRilIface = nullptr; +sp agnssRilIface_V2_0 = nullptr; sp gnssNiIface = nullptr; sp gnssPowerIndicationIface = nullptr; sp gnssCorrectionsIface_V1_0 = nullptr; @@ -220,7 +224,6 @@ std::unique_ptr gnssBatchingIface = nullpt std::unique_ptr gnssGeofencingIface = nullptr; std::unique_ptr agnssIface = nullptr; std::unique_ptr gnssDebugIface = nullptr; -std::unique_ptr agnssRilIface = nullptr; #define WAKE_LOCK_NAME "GPS" @@ -906,6 +909,29 @@ Return GnssVisibilityControlCallback::isInEmergencySession() { return result; } +/* + * AGnssRilCallback implements the callback methods required by the AGnssRil + * interface. + */ +struct AGnssRilCallback : IAGnssRilCallback { + Return requestSetIdCb(uint32_t setIdFlag) override; + Return requestRefLocCb() override; +}; + +Return AGnssRilCallback::requestSetIdCb(uint32_t setIdFlag) { + JNIEnv* env = getJniEnv(); + env->CallVoidMethod(mCallbacksObj, method_requestSetID, setIdFlag); + checkAndClearExceptionFromCallback(env, __FUNCTION__); + return Void(); +} + +Return AGnssRilCallback::requestRefLocCb() { + JNIEnv* env = getJniEnv(); + env->CallVoidMethod(mCallbacksObj, method_requestRefLocation); + checkAndClearExceptionFromCallback(env, __FUNCTION__); + return Void(); +} + /* Initializes the GNSS service handle. */ static void android_location_gnss_hal_GnssNative_set_gps_service_handle() { gnssHalAidl = waitForVintfService(); @@ -964,6 +990,8 @@ static void android_location_gnss_hal_GnssNative_class_init_once(JNIEnv* env, jc method_reportNiNotification = env->GetMethodID(clazz, "reportNiNotification", "(IIIIILjava/lang/String;Ljava/lang/String;II)V"); method_requestLocation = env->GetMethodID(clazz, "requestLocation", "(ZZ)V"); + method_requestRefLocation = env->GetMethodID(clazz, "requestRefLocation", "()V"); + method_requestSetID = env->GetMethodID(clazz, "requestSetID", "(I)V"); method_requestUtcTime = env->GetMethodID(clazz, "requestUtcTime", "()V"); method_reportGnssServiceDied = env->GetMethodID(clazz, "reportGnssServiceDied", "()V"); method_reportNfwNotification = env->GetMethodID(clazz, "reportNfwNotification", @@ -1041,7 +1069,6 @@ static void android_location_gnss_hal_GnssNative_class_init_once(JNIEnv* env, jc gnss::GnssMeasurement_class_init_once(env, clazz); gnss::GnssNavigationMessage_class_init_once(env, clazz); gnss::AGnss_class_init_once(env, clazz); - gnss::AGnssRil_class_init_once(env, clazz); gnss::Utils_class_init_once(env); } @@ -1097,21 +1124,20 @@ static void android_location_gnss_hal_GnssNative_init_once(JNIEnv* env, jobject } } - if (gnssHalAidl != nullptr && gnssHalAidl->getInterfaceVersion() >= 2) { - sp agnssRilAidl; - auto status = gnssHalAidl->getExtensionAGnssRil(&agnssRilAidl); - if (checkAidlStatus(status, "Unable to get a handle to AGnssRil interface.")) { - agnssRilIface = std::make_unique(agnssRilAidl); - } - } else if (gnssHal_V2_0 != nullptr) { + if (gnssHal_V2_0 != nullptr) { auto agnssRil_V2_0 = gnssHal_V2_0->getExtensionAGnssRil_2_0(); - if (checkHidlReturn(agnssRil_V2_0, "Unable to get a handle to AGnssRil_V2_0")) { - agnssRilIface = std::make_unique(agnssRil_V2_0); + if (!agnssRil_V2_0.isOk()) { + ALOGD("Unable to get a handle to AGnssRil_V2_0"); + } else { + agnssRilIface_V2_0 = agnssRil_V2_0; + agnssRilIface = agnssRilIface_V2_0; } } else if (gnssHal != nullptr) { auto agnssRil_V1_0 = gnssHal->getExtensionAGnssRil(); - if (checkHidlReturn(agnssRil_V1_0, "Unable to get a handle to AGnssRil_V1_0")) { - agnssRilIface = std::make_unique(agnssRil_V1_0); + if (!agnssRil_V1_0.isOk()) { + ALOGD("Unable to get a handle to AGnssRil"); + } else { + agnssRilIface = agnssRil_V1_0; } } @@ -1446,9 +1472,12 @@ static jboolean android_location_gnss_hal_GnssNative_init(JNIEnv* /* env */, jcl ALOGI("Unable to initialize IGnssNi interface."); } - // Set IAGnssRil callback. - if (agnssRilIface == nullptr || - !agnssRilIface->setCallback(std::make_unique())) { + // Set IAGnssRil.hal callback. + sp aGnssRilCbIface = new AGnssRilCallback(); + if (agnssRilIface != nullptr) { + auto status = agnssRilIface->setCallback(aGnssRilCbIface); + checkHidlReturn(status, "IAGnssRil setCallback() failed."); + } else { ALOGI("Unable to initialize IAGnssRil interface."); } @@ -1576,13 +1605,31 @@ static void android_location_gnss_hal_GnssNative_delete_aiding_data(JNIEnv* /* e } static void android_location_gnss_hal_GnssNative_agps_set_reference_location_cellid( - JNIEnv* /* env */, jclass, jint type, jint mcc, jint mnc, jint lac, jlong cid, jint tac, - jint pcid, jint arfcn) { + JNIEnv* /* env */, jclass, jint type, jint mcc, jint mnc, jint lac, jint cid) { + IAGnssRil_V1_0::AGnssRefLocation location; + if (agnssRilIface == nullptr) { ALOGE("%s: IAGnssRil interface not available.", __func__); return; } - agnssRilIface->setRefLocation(type, mcc, mnc, lac, cid, tac, pcid, arfcn); + + switch (static_cast(type)) { + case IAGnssRil_V1_0::AGnssRefLocationType::GSM_CELLID: + case IAGnssRil_V1_0::AGnssRefLocationType::UMTS_CELLID: + location.type = static_cast(type); + location.cellID.mcc = mcc; + location.cellID.mnc = mnc; + location.cellID.lac = lac; + location.cellID.cid = cid; + break; + default: + ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).", __FUNCTION__, __LINE__); + return; + break; + } + + auto result = agnssRilIface->setRefLocation(location); + checkHidlReturn(result, "IAGnssRil setRefLocation() failed."); } static void android_location_gnss_hal_GnssNative_agps_set_id(JNIEnv* env, jclass, jint type, @@ -1591,7 +1638,10 @@ static void android_location_gnss_hal_GnssNative_agps_set_id(JNIEnv* env, jclass ALOGE("%s: IAGnssRil interface not available.", __func__); return; } - agnssRilIface->setSetId(type, setid_string); + + ScopedJniString jniSetId{env, setid_string}; + auto result = agnssRilIface->setSetId((IAGnssRil_V1_0::SetIDType)type, jniSetId); + checkHidlReturn(result, "IAGnssRil setSetId() failed."); } static jint android_location_gnss_hal_GnssNative_read_nmea(JNIEnv* env, jclass, @@ -1828,12 +1878,31 @@ static void android_location_GnssNetworkConnectivityHandler_update_network_state jstring apn, jlong networkHandle, jshort capabilities) { - if (agnssRilIface == nullptr) { + if (agnssRilIface_V2_0 != nullptr) { + ScopedJniString jniApn{env, apn}; + IAGnssRil_V2_0::NetworkAttributes networkAttributes = { + .networkHandle = static_cast(networkHandle), + .isConnected = static_cast(connected), + .capabilities = static_cast(capabilities), + .apn = jniApn + }; + + auto result = agnssRilIface_V2_0->updateNetworkState_2_0(networkAttributes); + checkHidlReturn(result, "IAGnssRil updateNetworkState_2_0() failed."); + } else if (agnssRilIface != nullptr) { + ScopedJniString jniApn{env, apn}; + hidl_string hidlApn{jniApn}; + auto result = agnssRilIface->updateNetworkState(connected, + static_cast(type), roaming); + checkHidlReturn(result, "IAGnssRil updateNetworkState() failed."); + + if (!hidlApn.empty()) { + result = agnssRilIface->updateNetworkAvailability(available, hidlApn); + checkHidlReturn(result, "IAGnssRil updateNetworkAvailability() failed."); + } + } else { ALOGE("%s: IAGnssRil interface not available.", __func__); - return; } - agnssRilIface->updateNetworkState(connected, type, roaming, available, apn, networkHandle, - capabilities); } static jboolean android_location_gnss_hal_GnssNative_is_geofence_supported(JNIEnv* /* env */, @@ -2349,7 +2418,7 @@ static const JNINativeMethod sLocationProviderMethods[] = { reinterpret_cast(android_location_gnss_hal_GnssNative_inject_psds_data)}, {"native_agps_set_id", "(ILjava/lang/String;)V", reinterpret_cast(android_location_gnss_hal_GnssNative_agps_set_id)}, - {"native_agps_set_ref_location_cellid", "(IIIIJIII)V", + {"native_agps_set_ref_location_cellid", "(IIIII)V", reinterpret_cast( android_location_gnss_hal_GnssNative_agps_set_reference_location_cellid)}, {"native_set_agps_server", "(ILjava/lang/String;I)V", diff --git a/services/core/jni/gnss/AGnssRil.cpp b/services/core/jni/gnss/AGnssRil.cpp deleted file mode 100644 index d760b4d2195ea..0000000000000 --- a/services/core/jni/gnss/AGnssRil.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -// Define LOG_TAG before to overwrite the default value. -#define LOG_TAG "AGnssRilJni" - -#include "AGnssRil.h" - -#include "Utils.h" - -using android::hardware::gnss::IAGnssRil; -using IAGnssRil_V1_0 = android::hardware::gnss::V1_0::IAGnssRil; -using IAGnssRil_V2_0 = android::hardware::gnss::V2_0::IAGnssRil; - -namespace android::gnss { - -// Implementation of AGnssRil (AIDL HAL) - -AGnssRil::AGnssRil(const sp& iAGnssRil) : mIAGnssRil(iAGnssRil) { - assert(mIAGnssRil != nullptr); -} - -jboolean AGnssRil::setCallback(const std::unique_ptr& callback) { - auto status = mIAGnssRil->setCallback(callback->getAidl()); - return checkAidlStatus(status, "IAGnssRilAidl setCallback() failed."); -} - -jboolean AGnssRil::setSetId(jint type, const jstring& setid_string) { - JNIEnv* env = getJniEnv(); - ScopedJniString jniSetId{env, setid_string}; - auto status = mIAGnssRil->setSetId((IAGnssRil::SetIDType)type, jniSetId.c_str()); - return checkAidlStatus(status, "IAGnssRilAidl setSetId() failed."); -} - -jboolean AGnssRil::setRefLocation(jint type, jint mcc, jint mnc, jint lac, jlong cid, jint tac, - jint pcid, jint arfcn) { - IAGnssRil::AGnssRefLocation location; - location.type = static_cast(type); - - switch (location.type) { - case IAGnssRil::AGnssRefLocationType::GSM_CELLID: - case IAGnssRil::AGnssRefLocationType::UMTS_CELLID: - case IAGnssRil::AGnssRefLocationType::LTE_CELLID: - case IAGnssRil::AGnssRefLocationType::NR_CELLID: - location.cellID.mcc = mcc; - location.cellID.mnc = mnc; - location.cellID.lac = lac; - location.cellID.cid = cid; - location.cellID.tac = tac; - location.cellID.pcid = pcid; - location.cellID.arfcn = arfcn; - break; - default: - ALOGE("Unknown cellid (%s:%d).", __FUNCTION__, __LINE__); - return JNI_FALSE; - break; - } - - auto status = mIAGnssRil->setRefLocation(location); - return checkAidlStatus(status, "IAGnssRilAidl dataConnClosed() failed."); -} - -jboolean AGnssRil::updateNetworkState(jboolean connected, jint type, jboolean roaming, - jboolean available, const jstring& apn, jlong networkHandle, - jshort capabilities) { - JNIEnv* env = getJniEnv(); - ScopedJniString jniApn{env, apn}; - IAGnssRil::NetworkAttributes networkAttributes; - networkAttributes.networkHandle = static_cast(networkHandle), - networkAttributes.isConnected = static_cast(connected), - networkAttributes.capabilities = static_cast(capabilities), - networkAttributes.apn = jniApn.c_str(); - - auto result = mIAGnssRil->updateNetworkState(networkAttributes); - return checkAidlStatus(result, "IAGnssRilAidl updateNetworkState() failed."); -} - -// Implementation of AGnssRil_V1_0 - -AGnssRil_V1_0::AGnssRil_V1_0(const sp& iAGnssRil) : mAGnssRil_V1_0(iAGnssRil) { - assert(mIAGnssRil_V1_0 != nullptr); -} - -jboolean AGnssRil_V1_0::setCallback(const std::unique_ptr& callback) { - auto result = mAGnssRil_V1_0->setCallback(callback->getV1_0()); - return checkHidlReturn(result, "IAGnssRil_V1_0 setCallback() failed."); -} - -jboolean AGnssRil_V1_0::setSetId(jint type, const jstring& setid_string) { - JNIEnv* env = getJniEnv(); - ScopedJniString jniSetId{env, setid_string}; - auto result = mAGnssRil_V1_0->setSetId((IAGnssRil_V1_0::SetIDType)type, jniSetId); - return checkHidlReturn(result, "IAGnssRil_V1_0 setSetId() failed."); -} - -jboolean AGnssRil_V1_0::setRefLocation(jint type, jint mcc, jint mnc, jint lac, jlong cid, jint, - jint, jint) { - IAGnssRil_V1_0::AGnssRefLocation location; - switch (static_cast(type)) { - case IAGnssRil_V1_0::AGnssRefLocationType::GSM_CELLID: - case IAGnssRil_V1_0::AGnssRefLocationType::UMTS_CELLID: - location.type = static_cast(type); - location.cellID.mcc = mcc; - location.cellID.mnc = mnc; - location.cellID.lac = lac; - location.cellID.cid = cid; - break; - default: - ALOGE("Neither a GSM nor a UMTS cellid (%s:%d).", __FUNCTION__, __LINE__); - return JNI_FALSE; - break; - } - - auto result = mAGnssRil_V1_0->setRefLocation(location); - return checkHidlReturn(result, "IAGnssRil_V1_0 setRefLocation() failed."); -} - -jboolean AGnssRil_V1_0::updateNetworkState(jboolean connected, jint type, jboolean roaming, - jboolean available, const jstring& apn, - jlong networkHandle, jshort capabilities) { - JNIEnv* env = getJniEnv(); - ScopedJniString jniApn{env, apn}; - hardware::hidl_string hidlApn{jniApn}; - hardware::Return result(false); - - if (!hidlApn.empty()) { - result = mAGnssRil_V1_0->updateNetworkAvailability(available, hidlApn); - checkHidlReturn(result, "IAGnssRil_V1_0 updateNetworkAvailability() failed."); - } - - result = mAGnssRil_V1_0->updateNetworkState(connected, - static_cast(type), - roaming); - return checkHidlReturn(result, "IAGnssRil_V1_0 updateNetworkState() failed."); -} - -// Implementation of AGnssRil_V2_0 - -AGnssRil_V2_0::AGnssRil_V2_0(const sp& iAGnssRil) - : AGnssRil_V1_0{iAGnssRil}, mAGnssRil_V2_0(iAGnssRil) { - assert(mIAGnssRil_V2_0 != nullptr); -} - -jboolean AGnssRil_V2_0::updateNetworkState(jboolean connected, jint type, jboolean roaming, - jboolean available, const jstring& apn, - jlong networkHandle, jshort capabilities) { - JNIEnv* env = getJniEnv(); - ScopedJniString jniApn{env, apn}; - IAGnssRil_V2_0::NetworkAttributes networkAttributes = - {.networkHandle = static_cast(networkHandle), - .isConnected = static_cast(connected), - .capabilities = static_cast(capabilities), - .apn = jniApn.c_str()}; - - auto result = mAGnssRil_V2_0->updateNetworkState_2_0(networkAttributes); - return checkHidlReturn(result, "AGnssRil_V2_0 updateNetworkState_2_0() failed."); -} - -} // namespace android::gnss diff --git a/services/core/jni/gnss/AGnssRil.h b/services/core/jni/gnss/AGnssRil.h deleted file mode 100644 index ce14a77d56c47..0000000000000 --- a/services/core/jni/gnss/AGnssRil.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _ANDROID_SERVER_GNSS_AGNSSRIL_H -#define _ANDROID_SERVER_GNSS_AGNSSRIL_H - -#pragma once - -#ifndef LOG_TAG -#error LOG_TAG must be defined before including this file. -#endif - -#include -#include -#include -#include - -#include "AGnssRilCallback.h" -#include "jni.h" - -namespace android::gnss { - -class AGnssRilInterface { -public: - virtual ~AGnssRilInterface() {} - virtual jboolean setCallback(const std::unique_ptr& callback) = 0; - virtual jboolean setSetId(jint type, const jstring& setid_string) = 0; - virtual jboolean setRefLocation(jint type, jint mcc, jint mnc, jint lac, jlong cid, jint tac, - jint pcid, jint arfcn) = 0; - virtual jboolean updateNetworkState(jboolean connected, jint type, jboolean roaming, - jboolean available, const jstring& apn, jlong networkHandle, - jshort capabilities) = 0; -}; - -class AGnssRil : public AGnssRilInterface { -public: - AGnssRil(const sp& iAGnssRil); - jboolean setCallback(const std::unique_ptr& callback) override; - jboolean setSetId(jint type, const jstring& setid_string) override; - jboolean setRefLocation(jint type, jint mcc, jint mnc, jint lac, jlong cid, jint tac, jint pcid, - jint arfcn) override; - jboolean updateNetworkState(jboolean connected, jint type, jboolean roaming, jboolean available, - const jstring& apn, jlong networkHandle, - jshort capabilities) override; - -private: - const sp mIAGnssRil; -}; - -class AGnssRil_V1_0 : public AGnssRilInterface { -public: - AGnssRil_V1_0(const sp& iAGnssRil); - jboolean setCallback(const std::unique_ptr& callback) override; - jboolean setSetId(jint type, const jstring& setid_string) override; - jboolean setRefLocation(jint type, jint mcc, jint mnc, jint lac, jlong cid, jint, jint, - jint) override; - jboolean updateNetworkState(jboolean connected, jint type, jboolean roaming, jboolean available, - const jstring& apn, jlong networkHandle, - jshort capabilities) override; - -private: - const sp mAGnssRil_V1_0; -}; - -class AGnssRil_V2_0 : public AGnssRil_V1_0 { -public: - AGnssRil_V2_0(const sp& iAGnssRil); - jboolean updateNetworkState(jboolean connected, jint type, jboolean roaming, jboolean available, - const jstring& apn, jlong networkHandle, - jshort capabilities) override; - -private: - const sp mAGnssRil_V2_0; -}; - -} // namespace android::gnss - -#endif // _ANDROID_SERVER_GNSS_AGNSSRIL_H diff --git a/services/core/jni/gnss/AGnssRilCallback.cpp b/services/core/jni/gnss/AGnssRilCallback.cpp deleted file mode 100644 index b63ccc281aa9b..0000000000000 --- a/services/core/jni/gnss/AGnssRilCallback.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "AGnssRilCbJni" - -#include "AGnssRilCallback.h" - -namespace android::gnss { - -jmethodID method_requestSetID; -jmethodID method_requestRefLocation; - -using binder::Status; -using hardware::Return; -using hardware::Void; - -void AGnssRil_class_init_once(JNIEnv* env, jclass clazz) { - method_requestSetID = env->GetMethodID(clazz, "requestSetID", "(I)V"); - method_requestRefLocation = env->GetMethodID(clazz, "requestRefLocation", "()V"); -} - -Status AGnssRilCallbackAidl::requestSetIdCb(int setIdflag) { - AGnssRilCallbackUtil::requestSetIdCb(setIdflag); - return Status::ok(); -} - -Status AGnssRilCallbackAidl::requestRefLocCb() { - AGnssRilCallbackUtil::requestRefLocCb(); - return Status::ok(); -} - -Return AGnssRilCallback_V1_0::requestSetIdCb(uint32_t setIdflag) { - AGnssRilCallbackUtil::requestSetIdCb(setIdflag); - return Void(); -} - -Return AGnssRilCallback_V1_0::requestRefLocCb() { - AGnssRilCallbackUtil::requestRefLocCb(); - return Void(); -} - -void AGnssRilCallbackUtil::requestSetIdCb(int setIdflag) { - ALOGD("%s. setIdflag: %d, ", __func__, setIdflag); - JNIEnv* env = getJniEnv(); - env->CallVoidMethod(mCallbacksObj, method_requestSetID, setIdflag); - checkAndClearExceptionFromCallback(env, __FUNCTION__); -} - -void AGnssRilCallbackUtil::requestRefLocCb() { - ALOGD("%s.", __func__); - JNIEnv* env = getJniEnv(); - env->CallVoidMethod(mCallbacksObj, method_requestRefLocation); - checkAndClearExceptionFromCallback(env, __FUNCTION__); -} - -} // namespace android::gnss diff --git a/services/core/jni/gnss/AGnssRilCallback.h b/services/core/jni/gnss/AGnssRilCallback.h deleted file mode 100644 index 2d12089fd6e3f..0000000000000 --- a/services/core/jni/gnss/AGnssRilCallback.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2021 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _ANDROID_SERVER_GNSS_AGNSSRILCALLBACK_H -#define _ANDROID_SERVER_GNSS_AGNSSRILCALLBACK_H - -#pragma once - -#ifndef LOG_TAG -#error LOG_TAG must be defined before including this file. -#endif - -#include -#include -#include - -#include "Utils.h" -#include "jni.h" - -namespace android::gnss { - -void AGnssRil_class_init_once(JNIEnv* env, jclass clazz); - -/* - * AGnssRilCallbackAidl class implements the callback methods required by the - * android::hardware::gnss::IAGnssRil interface. - */ -class AGnssRilCallbackAidl : public android::hardware::gnss::BnAGnssRilCallback { -public: - binder::Status requestSetIdCb(int setIdflag) override; - binder::Status requestRefLocCb() override; -}; - -/* - * AGnssRilCallback_V1_0 implements callback methods required by the IAGnssRilCallback 1.0 - * interface. - */ -class AGnssRilCallback_V1_0 : public android::hardware::gnss::V1_0::IAGnssRilCallback { -public: - // Methods from ::android::hardware::gps::V1_0::IAGnssRilCallback follow. - hardware::Return requestSetIdCb(uint32_t setIdflag) override; - hardware::Return requestRefLocCb() override; -}; - -class AGnssRilCallback { -public: - AGnssRilCallback() {} - sp getAidl() { - if (callbackAidl == nullptr) { - callbackAidl = sp::make(); - } - return callbackAidl; - } - - sp getV1_0() { - if (callbackV1_0 == nullptr) { - callbackV1_0 = sp::make(); - } - return callbackV1_0; - } - -private: - sp callbackAidl; - sp callbackV1_0; -}; - -struct AGnssRilCallbackUtil { - static void requestSetIdCb(int setIdflag); - static void requestRefLocCb(); - -private: - AGnssRilCallbackUtil() = delete; -}; - -} // namespace android::gnss - -#endif // _ANDROID_SERVER_GNSS_AGNSSRILCALLBACK_H \ No newline at end of file diff --git a/services/core/jni/gnss/Android.bp b/services/core/jni/gnss/Android.bp index d8de5a604b3d0..63f5f526db179 100644 --- a/services/core/jni/gnss/Android.bp +++ b/services/core/jni/gnss/Android.bp @@ -25,8 +25,6 @@ cc_library_shared { srcs: [ "AGnss.cpp", "AGnssCallback.cpp", - "AGnssRil.cpp", - "AGnssRilCallback.cpp", "GnssAntennaInfoCallback.cpp", "GnssBatching.cpp", "GnssBatchingCallback.cpp", diff --git a/services/tests/mockingservicestests/src/com/android/server/location/gnss/hal/FakeGnssHal.java b/services/tests/mockingservicestests/src/com/android/server/location/gnss/hal/FakeGnssHal.java index 93929b4cfee2b..93a2d317c40e6 100644 --- a/services/tests/mockingservicestests/src/com/android/server/location/gnss/hal/FakeGnssHal.java +++ b/services/tests/mockingservicestests/src/com/android/server/location/gnss/hal/FakeGnssHal.java @@ -673,8 +673,7 @@ public final class FakeGnssHal extends GnssNative.GnssHal { protected void setAgpsSetId(int type, String setId) {} @Override - protected void setAgpsReferenceLocationCellId(int type, int mcc, int mnc, int lac, long cid, - int tac, int pcid, int arfcn) {} + protected void setAgpsReferenceLocationCellId(int type, int mcc, int mnc, int lac, int cid) {} @Override protected boolean isPsdsSupported() {