From d7a5de2b13c122dac1be242bbf443e89c404a9b2 Mon Sep 17 00:00:00 2001 From: Edwin Tung Date: Wed, 8 Dec 2021 13:27:51 +0800 Subject: [PATCH] Add GnssVisibilityControl AIDL HAL (hardware/interfaces) Bug: 208728105 Test: atest VtsHalGnssTargetTest Change-Id: Ie42793a4d0ddf9c9b62c6dff2dc7a34797702e7f --- .../compatibility_matrix.current.xml | 8 + gnss/aidl/Android.bp | 18 ++ .../IGnssVisibilityControl.aidl | 39 ++++ .../IGnssVisibilityControlCallback.aidl | 74 ++++++++ .../current/android/hardware/gnss/IGnss.aidl | 1 + gnss/aidl/android/hardware/gnss/IGnss.aidl | 8 + .../IGnssVisibilityControl.aidl | 82 ++++++++ .../IGnssVisibilityControlCallback.aidl | 176 ++++++++++++++++++ gnss/aidl/default/Android.bp | 2 + gnss/aidl/default/Gnss.cpp | 9 + gnss/aidl/default/Gnss.h | 4 + gnss/aidl/default/GnssVisibilityControl.cpp | 51 +++++ gnss/aidl/default/GnssVisibilityControl.h | 36 ++++ gnss/aidl/vts/Android.bp | 2 + .../vts/GnssVisibilityControlCallback.cpp | 28 +++ gnss/aidl/vts/GnssVisibilityControlCallback.h | 30 +++ gnss/aidl/vts/gnss_hal_test_cases.cpp | 27 +++ 17 files changed, 595 insertions(+) create mode 100644 gnss/aidl/aidl_api/android.hardware.gnss.visibility_control/current/android/hardware/gnss/visibility_control/IGnssVisibilityControl.aidl create mode 100644 gnss/aidl/aidl_api/android.hardware.gnss.visibility_control/current/android/hardware/gnss/visibility_control/IGnssVisibilityControlCallback.aidl create mode 100644 gnss/aidl/android/hardware/gnss/visibility_control/IGnssVisibilityControl.aidl create mode 100644 gnss/aidl/android/hardware/gnss/visibility_control/IGnssVisibilityControlCallback.aidl create mode 100644 gnss/aidl/default/GnssVisibilityControl.cpp create mode 100644 gnss/aidl/default/GnssVisibilityControl.h create mode 100644 gnss/aidl/vts/GnssVisibilityControlCallback.cpp create mode 100644 gnss/aidl/vts/GnssVisibilityControlCallback.h diff --git a/compatibility_matrices/compatibility_matrix.current.xml b/compatibility_matrices/compatibility_matrix.current.xml index 34fbaaf338..70d72cce49 100644 --- a/compatibility_matrices/compatibility_matrix.current.xml +++ b/compatibility_matrices/compatibility_matrix.current.xml @@ -260,6 +260,14 @@ default + + android.hardware.gnss.visibility_control + 1 + + IGnssVisibilityControl + default + + android.hardware.graphics.allocator diff --git a/gnss/aidl/Android.bp b/gnss/aidl/Android.bp index b197eae32d..12dd0ac16e 100644 --- a/gnss/aidl/Android.bp +++ b/gnss/aidl/Android.bp @@ -23,10 +23,28 @@ package { default_applicable_licenses: ["hardware_interfaces_license"], } +aidl_interface { + name: "android.hardware.gnss.visibility_control", + vendor_available: true, + srcs: ["android/hardware/gnss/visibility_control/*.aidl"], + stability: "vintf", + backend: { + java: { + platform_apis: true, + }, + ndk: { + vndk: { + enabled: true, + }, + }, + }, +} + aidl_interface { name: "android.hardware.gnss", vendor_available: true, srcs: ["android/hardware/gnss/*.aidl"], + imports: ["android.hardware.gnss.visibility_control"], stability: "vintf", backend: { java: { diff --git a/gnss/aidl/aidl_api/android.hardware.gnss.visibility_control/current/android/hardware/gnss/visibility_control/IGnssVisibilityControl.aidl b/gnss/aidl/aidl_api/android.hardware.gnss.visibility_control/current/android/hardware/gnss/visibility_control/IGnssVisibilityControl.aidl new file mode 100644 index 0000000000..7ef08d2f52 --- /dev/null +++ b/gnss/aidl/aidl_api/android.hardware.gnss.visibility_control/current/android/hardware/gnss/visibility_control/IGnssVisibilityControl.aidl @@ -0,0 +1,39 @@ +/* + * 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.gnss.visibility_control; +@VintfStability +interface IGnssVisibilityControl { + void enableNfwLocationAccess(in String[] proxyApps); + void setCallback(in android.hardware.gnss.visibility_control.IGnssVisibilityControlCallback callback); +} diff --git a/gnss/aidl/aidl_api/android.hardware.gnss.visibility_control/current/android/hardware/gnss/visibility_control/IGnssVisibilityControlCallback.aidl b/gnss/aidl/aidl_api/android.hardware.gnss.visibility_control/current/android/hardware/gnss/visibility_control/IGnssVisibilityControlCallback.aidl new file mode 100644 index 0000000000..37e1886576 --- /dev/null +++ b/gnss/aidl/aidl_api/android.hardware.gnss.visibility_control/current/android/hardware/gnss/visibility_control/IGnssVisibilityControlCallback.aidl @@ -0,0 +1,74 @@ +/* + * 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. + */ +/////////////////////////////////////////////////////////////////////////////// +// THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // +/////////////////////////////////////////////////////////////////////////////// + +// This file is a snapshot of an AIDL file. Do not edit it manually. There are +// two cases: +// 1). this is a frozen version file - do not edit this in any case. +// 2). this is a 'current' file. If you make a backwards compatible change to +// the interface (from the latest frozen version), the build system will +// prompt you to update this file with `m -update-api`. +// +// You must not make a backward incompatible change to any AIDL file built +// with the aidl_interface module type with versions property set. The module +// type is used to build AIDL files in a way that they can be used across +// independently updatable components of the system. If a device is shipped +// with such a backward incompatible change, it has a high risk of breaking +// later when a module using the interface is updated, e.g., Mainline modules. + +package android.hardware.gnss.visibility_control; +@VintfStability +interface IGnssVisibilityControlCallback { + void nfwNotifyCb(in android.hardware.gnss.visibility_control.IGnssVisibilityControlCallback.NfwNotification notification); + boolean isInEmergencySession(); + @Backing(type="int") @VintfStability + enum NfwProtocolStack { + CTRL_PLANE = 0, + SUPL = 1, + IMS = 10, + SIM = 11, + OTHER_PROTOCOL_STACK = 100, + } + @Backing(type="int") @VintfStability + enum NfwRequestor { + CARRIER = 0, + OEM = 10, + MODEM_CHIPSET_VENDOR = 11, + GNSS_CHIPSET_VENDOR = 12, + OTHER_CHIPSET_VENDOR = 13, + AUTOMOBILE_CLIENT = 20, + OTHER_REQUESTOR = 100, + } + @Backing(type="int") @VintfStability + enum NfwResponseType { + REJECTED = 0, + ACCEPTED_NO_LOCATION_PROVIDED = 1, + ACCEPTED_LOCATION_PROVIDED = 2, + } + @VintfStability + parcelable NfwNotification { + String proxyAppPackageName; + android.hardware.gnss.visibility_control.IGnssVisibilityControlCallback.NfwProtocolStack protocolStack; + String otherProtocolStackName; + android.hardware.gnss.visibility_control.IGnssVisibilityControlCallback.NfwRequestor requestor; + String requestorId; + android.hardware.gnss.visibility_control.IGnssVisibilityControlCallback.NfwResponseType responseType; + boolean inEmergencyMode; + boolean isCachedLocation; + } +} diff --git a/gnss/aidl/aidl_api/android.hardware.gnss/current/android/hardware/gnss/IGnss.aidl b/gnss/aidl/aidl_api/android.hardware.gnss/current/android/hardware/gnss/IGnss.aidl index 9df7fe521b..34773805f4 100644 --- a/gnss/aidl/aidl_api/android.hardware.gnss/current/android/hardware/gnss/IGnss.aidl +++ b/gnss/aidl/aidl_api/android.hardware.gnss/current/android/hardware/gnss/IGnss.aidl @@ -45,6 +45,7 @@ interface IGnss { @nullable android.hardware.gnss.IGnssNavigationMessageInterface getExtensionGnssNavigationMessage(); android.hardware.gnss.IAGnss getExtensionAGnss(); android.hardware.gnss.IGnssDebug getExtensionGnssDebug(); + android.hardware.gnss.visibility_control.IGnssVisibilityControl getExtensionGnssVisibilityControl(); const int ERROR_INVALID_ARGUMENT = 1; const int ERROR_ALREADY_INIT = 2; const int ERROR_GENERIC = 3; diff --git a/gnss/aidl/android/hardware/gnss/IGnss.aidl b/gnss/aidl/android/hardware/gnss/IGnss.aidl index 2751521efc..1351f594e9 100644 --- a/gnss/aidl/android/hardware/gnss/IGnss.aidl +++ b/gnss/aidl/android/hardware/gnss/IGnss.aidl @@ -26,6 +26,7 @@ import android.hardware.gnss.IGnssMeasurementInterface; import android.hardware.gnss.IGnssNavigationMessageInterface; import android.hardware.gnss.IGnssPowerIndication; import android.hardware.gnss.IGnssPsds; +import android.hardware.gnss.visibility_control.IGnssVisibilityControl; /** * Represents the standard GNSS (Global Navigation Satellite System) interface. @@ -144,4 +145,11 @@ interface IGnss { * @return Handle to the IGnssDebug interface. */ IGnssDebug getExtensionGnssDebug(); + + /** + * This method returns the IGnssVisibilityControl. + * + * @return Handle to the IGnssVisibilityControl. + */ + IGnssVisibilityControl getExtensionGnssVisibilityControl(); } diff --git a/gnss/aidl/android/hardware/gnss/visibility_control/IGnssVisibilityControl.aidl b/gnss/aidl/android/hardware/gnss/visibility_control/IGnssVisibilityControl.aidl new file mode 100644 index 0000000000..93c3f2c94f --- /dev/null +++ b/gnss/aidl/android/hardware/gnss/visibility_control/IGnssVisibilityControl.aidl @@ -0,0 +1,82 @@ +/* + * 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. + */ + +package android.hardware.gnss.visibility_control; + +import android.hardware.gnss.visibility_control.IGnssVisibilityControlCallback; + +/** + * Represents the GNSS location reporting permissions and notification interface. + * + * This interface is used to tell the GNSS HAL implementation whether the framework user has + * granted permission to the GNSS HAL implementation to provide GNSS location information for + * non-framework (NFW), non-user initiated emergency use cases, and to notify the framework user + * of these GNSS location information deliveries. + * + * For user initiated emergency cases (and for the configured extended emergency session duration), + * the GNSS HAL implementation must serve the emergency location supporting network initiated + * location requests immediately irrespective of this permission settings. + * + * There is no separate need for the GNSS HAL implementation to monitor the global device location + * on/off setting. Permission to use GNSS for non-framework use cases is expressly controlled + * by the method enableNfwLocationAccess(). The framework monitors the location permission settings + * of the configured proxy applications(s), and device location settings, and calls the method + * enableNfwLocationAccess() whenever the user control proxy applications have, or do not have, + * location permission. The proxy applications are used to provide user visibility and control of + * location access by the non-framework on/off device entities they are representing. + * + * For device user visibility, the GNSS HAL implementation must call the method + * IGnssVisibilityControlCallback.nfwNotifyCb() whenever location request is rejected or + * location information is provided to non-framework entities (on or off device). This includes + * the network initiated location requests for user-initiated emergency use cases as well. + * + * The HAL implementations that support this interface must not report GNSS location, measurement, + * status, or other information that can be used to derive user location to any entity when not + * expressly authorized by this HAL. This includes all endpoints for location information + * off the device, including carriers, vendors, OEM and others directly or indirectly. + */ +@VintfStability +interface IGnssVisibilityControl { + /** + * Enables/disables non-framework entity location access permission in the GNSS HAL. + * + * The framework will call this method to update GNSS HAL implementation every time the + * framework user, through the given proxy application(s) and/or device location settings, + * explicitly grants/revokes the location access permission for non-framework, non-user + * initiated emergency use cases. + * + * Whenever the user location information is delivered to non-framework entities, the HAL + * implementation must call the method IGnssVisibilityControlCallback.nfwNotifyCb() to notify + * the framework for user visibility. + * + * @param proxyApps Full list of package names of proxy Android applications representing + * the non-framework location access entities (on/off the device) for which the framework + * user has granted non-framework location access permission. The GNSS HAL implementation + * must provide location information only to non-framework entities represented by these + * proxy applications. + * + * The package name of the proxy Android application follows the standard Java language + * package naming format. For example, com.example.myapp. + */ + void enableNfwLocationAccess(in String[] proxyApps); + + /** + * Registers the callback for HAL implementation to use. + * + * @param callback Handle to IGnssVisibilityControlCallback interface. + */ + void setCallback(in IGnssVisibilityControlCallback callback); +} diff --git a/gnss/aidl/android/hardware/gnss/visibility_control/IGnssVisibilityControlCallback.aidl b/gnss/aidl/android/hardware/gnss/visibility_control/IGnssVisibilityControlCallback.aidl new file mode 100644 index 0000000000..051fbe6fb0 --- /dev/null +++ b/gnss/aidl/android/hardware/gnss/visibility_control/IGnssVisibilityControlCallback.aidl @@ -0,0 +1,176 @@ +/* + * 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. + */ + +package android.hardware.gnss.visibility_control; + +/** + * GNSS location reporting permissions and notification callback interface. + */ +@VintfStability +interface IGnssVisibilityControlCallback { + /** + * Protocol stack that is requesting the non-framework location information. + */ + @VintfStability + @Backing(type="int") + enum NfwProtocolStack { + /** Cellular control plane requests */ + CTRL_PLANE = 0, + + /** All types of SUPL requests */ + SUPL = 1, + + /** All types of requests from IMS */ + IMS = 10, + + /** All types of requests from SIM */ + SIM = 11, + + /** Requests from other protocol stacks */ + OTHER_PROTOCOL_STACK = 100 + } + + /** + * Entity that is requesting/receiving the location information. + */ + @VintfStability + @Backing(type="int") + enum NfwRequestor { + /** Wireless service provider */ + CARRIER = 0, + + /** Device manufacturer */ + OEM = 10, + + /** Modem chipset vendor */ + MODEM_CHIPSET_VENDOR = 11, + + /** GNSS chipset vendor */ + GNSS_CHIPSET_VENDOR = 12, + + /** Other chipset vendor */ + OTHER_CHIPSET_VENDOR = 13, + + /** Automobile client */ + AUTOMOBILE_CLIENT = 20, + + /** Other sources */ + OTHER_REQUESTOR = 100 + } + + /** + * GNSS response type for non-framework location requests. + */ + @VintfStability + @Backing(type="int") + enum NfwResponseType { + /** Request rejected because framework has not given permission for this use case */ + REJECTED = 0, + + /** Request accepted but could not provide location because of a failure */ + ACCEPTED_NO_LOCATION_PROVIDED = 1, + + /** Request accepted and location provided */ + ACCEPTED_LOCATION_PROVIDED = 2, + } + + /** + * Represents a non-framework location information request/response notification. + */ + @VintfStability + parcelable NfwNotification { + /** + * Package name of the Android proxy application representing the non-framework + * entity that requested location. Set to empty string if unknown. + * + * For user-initiated emergency use cases, this field must be set to empty string + * and the inEmergencyMode field must be set to true. + */ + String proxyAppPackageName; + + /** Protocol stack that initiated the non-framework location request. */ + NfwProtocolStack protocolStack; + + /** + * Name of the protocol stack if protocolStack field is set to OTHER_PROTOCOL_STACK. + * Otherwise, set to empty string. + * + * This field is opaque to the framework and used for logging purposes. + */ + String otherProtocolStackName; + + /** Source initiating/receiving the location information. */ + NfwRequestor requestor; + + /** + * Identity of the endpoint receiving the location information. For example, carrier + * name, OEM name, SUPL SLP/E-SLP FQDN, chipset vendor name, etc. + * + * This field is opaque to the framework and used for logging purposes. + */ + String requestorId; + + /** Indicates whether location information was provided for this request. */ + NfwResponseType responseType; + + /** Is the device in user initiated emergency session. */ + boolean inEmergencyMode; + + /** Is cached location provided */ + boolean isCachedLocation; + } + + /** + * Callback to report a non-framework delivered location. + * + * The GNSS HAL implementation must call this method to notify the framework whenever + * a non-framework location request is made to the GNSS HAL. + * + * Non-framework entities like low power sensor hubs that request location from GNSS and + * only pass location information through Android framework controls are exempt from this + * power-spending reporting. However, low power sensor hubs or other chipsets which may send + * the location information to anywhere other than Android framework (which provides user + * visibility and control), must report location information use through this API whenever + * location information (or events driven by that location such as "home" location detection) + * leaves the domain of that low power chipset. + * + * To avoid overly spamming the framework, high speed location reporting of the exact same + * type may be throttled to report location at a lower rate than the actual report rate, as + * long as the location is reported with a latency of no more than the larger of 5 seconds, + * or the next the Android processor awake time. For example, if an Automotive client is + * getting location information from the GNSS location system at 20Hz, this method may be + * called at 1Hz. As another example, if a low power processor is getting location from the + * GNSS chipset, and the Android processor is asleep, the notification to the Android HAL may + * be delayed until the next wake of the Android processor. + * + * @param notification Non-framework delivered location request/response description. + */ + void nfwNotifyCb(in NfwNotification notification); + + /** + * Tells if the device is currently in an emergency session. + * + * Emergency session is defined as the device being actively in a user initiated emergency + * call or in post emergency call extension time period. + * + * If the GNSS HAL implementation cannot determine if the device is in emergency session + * mode, it must call this method to confirm that the device is in emergency session before + * serving network initiated emergency SUPL and Control Plane location requests. + * + * @return success True if the framework determines that the device is in emergency session. + */ + boolean isInEmergencySession(); +} diff --git a/gnss/aidl/default/Android.bp b/gnss/aidl/default/Android.bp index 24569aec21..29c26d16ec 100644 --- a/gnss/aidl/default/Android.bp +++ b/gnss/aidl/default/Android.bp @@ -52,6 +52,7 @@ cc_binary { "android.hardware.gnss.measurement_corrections@1.1", "android.hardware.gnss.measurement_corrections@1.0", "android.hardware.gnss.visibility_control@1.0", + "android.hardware.gnss.visibility_control-V1-ndk", "android.hardware.gnss-V2-ndk", ], srcs: [ @@ -66,6 +67,7 @@ cc_binary { "GnssPsds.cpp", "GnssConfiguration.cpp", "GnssMeasurementInterface.cpp", + "GnssVisibilityControl.cpp", "service.cpp", ], static_libs: [ diff --git a/gnss/aidl/default/Gnss.cpp b/gnss/aidl/default/Gnss.cpp index 45d6b1d2f4..afb7b9507a 100644 --- a/gnss/aidl/default/Gnss.cpp +++ b/gnss/aidl/default/Gnss.cpp @@ -26,6 +26,7 @@ #include "GnssMeasurementInterface.h" #include "GnssNavigationMessageInterface.h" #include "GnssPsds.h" +#include "GnssVisibilityControl.h" namespace aidl::android::hardware::gnss { @@ -128,4 +129,12 @@ ndk::ScopedAStatus Gnss::getExtensionGnssDebug(std::shared_ptr* iGns return ndk::ScopedAStatus::ok(); } +ndk::ScopedAStatus Gnss::getExtensionGnssVisibilityControl( + std::shared_ptr* iGnssVisibilityControl) { + ALOGD("Gnss::getExtensionGnssVisibilityControl"); + + *iGnssVisibilityControl = SharedRefBase::make(); + return ndk::ScopedAStatus::ok(); +} + } // namespace aidl::android::hardware::gnss diff --git a/gnss/aidl/default/Gnss.h b/gnss/aidl/default/Gnss.h index f59607f267..67fef94ee7 100644 --- a/gnss/aidl/default/Gnss.h +++ b/gnss/aidl/default/Gnss.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "GnssConfiguration.h" #include "GnssPowerIndication.h" @@ -48,6 +49,9 @@ class Gnss : public BnGnss { std::shared_ptr* iGnssNavigationMessage) override; ndk::ScopedAStatus getExtensionAGnss(std::shared_ptr* iAGnss) override; ndk::ScopedAStatus getExtensionGnssDebug(std::shared_ptr* iGnssDebug) override; + ndk::ScopedAStatus getExtensionGnssVisibilityControl( + std::shared_ptr* + iGnssVisibilityControl) override; std::shared_ptr mGnssConfiguration; std::shared_ptr mGnssPowerIndication; diff --git a/gnss/aidl/default/GnssVisibilityControl.cpp b/gnss/aidl/default/GnssVisibilityControl.cpp new file mode 100644 index 0000000000..208d73ca20 --- /dev/null +++ b/gnss/aidl/default/GnssVisibilityControl.cpp @@ -0,0 +1,51 @@ +/* + * 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 "GnssVisibilityControl" + +#include "GnssVisibilityControl.h" +#include + +namespace aidl::android::hardware::gnss::visibility_control { + +std::shared_ptr GnssVisibilityControl::sCallback = nullptr; + +ndk::ScopedAStatus GnssVisibilityControl::enableNfwLocationAccess( + const std::vector& proxyApps) { + std::string os; + bool first = true; + for (const auto& proxyApp : proxyApps) { + if (first) { + first = false; + } else { + os += " "; + } + os += proxyApp; + } + + ALOGD("GnssVisibilityControl::enableNfwLocationAccess proxyApps: %s", os.c_str()); + return ndk::ScopedAStatus::ok(); +} + +ndk::ScopedAStatus GnssVisibilityControl::setCallback( + const std::shared_ptr& callback) { + ALOGD("GnssVisibilityControl::setCallback"); + std::unique_lock lock(mMutex); + sCallback = callback; + return ndk::ScopedAStatus::ok(); +} + +} // namespace aidl::android::hardware::gnss::visibility_control diff --git a/gnss/aidl/default/GnssVisibilityControl.h b/gnss/aidl/default/GnssVisibilityControl.h new file mode 100644 index 0000000000..5b36442374 --- /dev/null +++ b/gnss/aidl/default/GnssVisibilityControl.h @@ -0,0 +1,36 @@ +/* + * 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. + */ + +#pragma once + +#include + +namespace aidl::android::hardware::gnss::visibility_control { + +struct GnssVisibilityControl : public BnGnssVisibilityControl { + public: + ndk::ScopedAStatus enableNfwLocationAccess(const std::vector& hostname) override; + ndk::ScopedAStatus setCallback( + const std::shared_ptr& callback) override; + + private: + // Synchronization lock for sCallback + mutable std::mutex mMutex; + // Guarded by mMutex + static std::shared_ptr sCallback; +}; + +} // namespace aidl::android::hardware::gnss::visibility_control diff --git a/gnss/aidl/vts/Android.bp b/gnss/aidl/vts/Android.bp index 041d579091..d532fad357 100644 --- a/gnss/aidl/vts/Android.bp +++ b/gnss/aidl/vts/Android.bp @@ -37,6 +37,7 @@ cc_test { "GnssMeasurementCallbackAidl.cpp", "GnssNavigationMessageCallback.cpp", "GnssPowerIndicationCallback.cpp", + "GnssVisibilityControlCallback.cpp", "VtsHalGnssTargetTest.cpp", ], shared_libs: [ @@ -49,6 +50,7 @@ cc_test { static_libs: [ "android.hardware.gnss-V2-cpp", "android.hardware.gnss@common-vts-lib", + "android.hardware.gnss.visibility_control-V1-cpp", ], test_suites: [ "general-tests", diff --git a/gnss/aidl/vts/GnssVisibilityControlCallback.cpp b/gnss/aidl/vts/GnssVisibilityControlCallback.cpp new file mode 100644 index 0000000000..aa27af169b --- /dev/null +++ b/gnss/aidl/vts/GnssVisibilityControlCallback.cpp @@ -0,0 +1,28 @@ +/* + * 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. + */ + +#include "GnssVisibilityControlCallback.h" +#include + +android::binder::Status GnssVisibilityControlCallback::nfwNotifyCb(const NfwNotification&) { + // To implement + return android::binder::Status::ok(); +} + +android::binder::Status GnssVisibilityControlCallback::isInEmergencySession(bool*) { + // To implement + return android::binder::Status::ok(); +} diff --git a/gnss/aidl/vts/GnssVisibilityControlCallback.h b/gnss/aidl/vts/GnssVisibilityControlCallback.h new file mode 100644 index 0000000000..fbacde766d --- /dev/null +++ b/gnss/aidl/vts/GnssVisibilityControlCallback.h @@ -0,0 +1,30 @@ +/* + * 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. + */ + +#pragma once + +#include + +class GnssVisibilityControlCallback + : public android::hardware::gnss::visibility_control::BnGnssVisibilityControlCallback { + public: + GnssVisibilityControlCallback(){}; + ~GnssVisibilityControlCallback(){}; + android::binder::Status nfwNotifyCb( + const android::hardware::gnss::visibility_control::IGnssVisibilityControlCallback:: + NfwNotification& notification) override; + android::binder::Status isInEmergencySession(bool* _aidl_return) override; +}; diff --git a/gnss/aidl/vts/gnss_hal_test_cases.cpp b/gnss/aidl/vts/gnss_hal_test_cases.cpp index 36be631743..90b643ca86 100644 --- a/gnss/aidl/vts/gnss_hal_test_cases.cpp +++ b/gnss/aidl/vts/gnss_hal_test_cases.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "AGnssCallbackAidl.h" #include "GnssBatchingCallback.h" @@ -31,6 +32,7 @@ #include "GnssMeasurementCallbackAidl.h" #include "GnssNavigationMessageCallback.h" #include "GnssPowerIndicationCallback.h" +#include "GnssVisibilityControlCallback.h" #include "gnss_hal_test.h" using android::sp; @@ -55,6 +57,7 @@ using android::hardware::gnss::IGnssPowerIndication; using android::hardware::gnss::IGnssPsds; using android::hardware::gnss::PsdsType; using android::hardware::gnss::SatellitePvt; +using android::hardware::gnss::visibility_control::IGnssVisibilityControl; using GnssConstellationTypeAidl = android::hardware::gnss::GnssConstellationType; @@ -876,3 +879,27 @@ TEST_P(GnssHalTest, GnssDebugValuesSanityTest) { data.time.frequencyUncertaintyNsPerSec <= 2.0e5); // 200 ppm } } + +/* + * TestAGnssExtension: + * TestGnssVisibilityControlExtension: + * 1. Gets the IGnssVisibilityControl extension. + * 2. Sets GnssVisibilityControlCallback + * 3. Sets proxy apps + */ +TEST_P(GnssHalTest, TestGnssVisibilityControlExtension) { + if (aidl_gnss_hal_->getInterfaceVersion() == 1) { + return; + } + sp iGnssVisibilityControl; + auto status = aidl_gnss_hal_->getExtensionGnssVisibilityControl(&iGnssVisibilityControl); + ASSERT_TRUE(status.isOk()); + ASSERT_TRUE(iGnssVisibilityControl != nullptr); + auto gnssVisibilityControlCallback = sp::make(); + status = iGnssVisibilityControl->setCallback(gnssVisibilityControlCallback); + ASSERT_TRUE(status.isOk()); + + std::vector proxyApps{String16("com.example.ims"), String16("com.example.mdt")}; + status = iGnssVisibilityControl->enableNfwLocationAccess(proxyApps); + ASSERT_TRUE(status.isOk()); +}