diff --git a/gnss/2.0/Android.bp b/gnss/2.0/Android.bp index 6a06bf4ce9..6972e40656 100644 --- a/gnss/2.0/Android.bp +++ b/gnss/2.0/Android.bp @@ -7,6 +7,8 @@ hidl_interface { enabled: true, }, srcs: [ + "types.hal", + "IAGnssRil.hal", "IGnss.hal", "IGnssCallback.hal", "IGnssMeasurement.hal", @@ -18,6 +20,8 @@ hidl_interface { "android.hardware.gnss@1.1", "android.hidl.base@1.0", ], + types: [ + ], gen_java: true, gen_java_constants: true, } diff --git a/gnss/2.0/IAGnssRil.hal b/gnss/2.0/IAGnssRil.hal new file mode 100644 index 0000000000..00a2e79b0f --- /dev/null +++ b/gnss/2.0/IAGnssRil.hal @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2018 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@2.0; + +import @1.0::IAGnssRil; + +/** + * Extended interface for AGNSS RIL support. An Assisted GNSS Radio Interface + * Layer interface allows the GNSS chipset to request radio interface layer + * information from Android platform. Examples of such information are reference + * location, unique subscriber ID, phone number string and network availability changes. + */ +interface IAGnssRil extends @1.0::IAGnssRil { + /** Flags to indicate capabilities of the network */ + enum NetworkCapability : uint16_t { + /** Network is not metered. */ + NOT_METERED = 1 << 0, + /** Network is not roaming. */ + NOT_ROAMING = 1 << 1 + }; + + /** Represents network connection status and capabilities. */ + struct NetworkAttributes { + /** Network handle of the network for use with the NDK API. */ + net_handle_t networkHandle; + + /** + * True indicates that network connectivity exists and it is possible to + * establish connections and pass data. If false, only the networkHandle field + * is populated to indicate that this network has just disconnected. + */ + bool isConnected; + + /** A set of flags indicating the capabilities of this network. */ + bitfield capabilities; + + /** + * Telephony preferred Access Point Name to use for carrier data connection when + * connected to a cellular network. Empty string, otherwise. + */ + string apn; + }; + + /** + * Notifies GNSS of network status changes. + * + * The framework calls this method to update the GNSS HAL implementation of network + * state changes. The methods updateNetworkState() and updateNetworkAvailability + * in @1.0::IAGnssRil are deprecated and are not called by the framework. + * + * @param attributes Updated network attributes. + * + * @return success True if all parameters were valid and the operation was + * successful. + */ + updateNetworkState_2_0(NetworkAttributes attributes) generates (bool success); +}; diff --git a/gnss/2.0/IGnss.hal b/gnss/2.0/IGnss.hal index 55621e555f..0799a60798 100644 --- a/gnss/2.0/IGnss.hal +++ b/gnss/2.0/IGnss.hal @@ -21,6 +21,7 @@ import @1.1::IGnss; import IGnssCallback; import IGnssMeasurement; +import IAGnssRil; /** Represents the standard GNSS (Global Navigation Satellite System) interface. */ interface IGnss extends @1.1::IGnss { @@ -34,6 +35,13 @@ interface IGnss extends @1.1::IGnss { */ setCallback_2_0(IGnssCallback callback) generates (bool success); + /** + * This method returns the IAGnssRil Interface. + * + * @return aGnssRilIface Handle to the IAGnssRil interface. + */ + getExtensionAGnssRil_2_0() generates (IAGnssRil aGnssRilIface); + /** * This method returns the IGnssMeasurement interface. * diff --git a/gnss/2.0/default/AGnssRil.cpp b/gnss/2.0/default/AGnssRil.cpp new file mode 100644 index 0000000000..eae2169805 --- /dev/null +++ b/gnss/2.0/default/AGnssRil.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2018 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 "AGnssRil" + +#include "AGnssRil.h" +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +// Methods from V1_0::IAGnssRil follow. +Return AGnssRil::setCallback(const sp&) { + // TODO implement + return Void(); +} + +Return AGnssRil::setRefLocation(const V1_0::IAGnssRil::AGnssRefLocation&) { + // TODO implement + return Void(); +} + +Return AGnssRil::setSetId(V1_0::IAGnssRil::SetIDType, const hidl_string&) { + // TODO implement + return bool{}; +} + +Return AGnssRil::updateNetworkState(bool, V1_0::IAGnssRil::NetworkType, bool) { + // TODO implement + return bool{}; +} + +Return AGnssRil::updateNetworkAvailability(bool, const hidl_string&) { + // TODO implement + return bool{}; +} + +// Methods from ::android::hardware::gnss::V2_0::IAGnssRil follow. +Return AGnssRil::updateNetworkState_2_0( + const V2_0::IAGnssRil::NetworkAttributes& attributes) { + ALOGD("updateNetworkState_2_0 networkAttributes: %s", toString(attributes).c_str()); + return true; +} + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android diff --git a/gnss/2.0/default/AGnssRil.h b/gnss/2.0/default/AGnssRil.h new file mode 100644 index 0000000000..0f822f8b0f --- /dev/null +++ b/gnss/2.0/default/AGnssRil.h @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2018 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_HARDWARE_GNSS_V2_0_AGNSSRIL_H +#define ANDROID_HARDWARE_GNSS_V2_0_AGNSSRIL_H + +#include +#include +#include + +namespace android { +namespace hardware { +namespace gnss { +namespace V2_0 { +namespace implementation { + +using ::android::sp; +using ::android::hardware::hidl_array; +using ::android::hardware::hidl_memory; +using ::android::hardware::hidl_string; +using ::android::hardware::hidl_vec; +using ::android::hardware::Return; +using ::android::hardware::Void; + +struct AGnssRil : public IAGnssRil { + // Methods from ::android::hardware::gnss::V1_0::IAGnssRil follow. + Return setCallback(const sp& callback) override; + Return setRefLocation(const V1_0::IAGnssRil::AGnssRefLocation& agnssReflocation) override; + Return setSetId(V1_0::IAGnssRil::SetIDType type, const hidl_string& setid) override; + Return updateNetworkState(bool connected, V1_0::IAGnssRil::NetworkType type, + bool roaming) override; + Return updateNetworkAvailability(bool available, const hidl_string& apn) override; + + // Methods from ::android::hardware::gnss::V2_0::IAGnssRil follow. + Return updateNetworkState_2_0( + const V2_0::IAGnssRil::NetworkAttributes& attributes) override; +}; + +} // namespace implementation +} // namespace V2_0 +} // namespace gnss +} // namespace hardware +} // namespace android + +#endif // ANDROID_HARDWARE_GNSS_V2_0_AGNSSRIL_H \ No newline at end of file diff --git a/gnss/2.0/default/Android.bp b/gnss/2.0/default/Android.bp index bec8260724..cdaa33e22f 100644 --- a/gnss/2.0/default/Android.bp +++ b/gnss/2.0/default/Android.bp @@ -20,6 +20,7 @@ cc_binary { relative_install_path: "hw", vendor: true, srcs: [ + "AGnssRil.cpp", "Gnss.cpp", "GnssMeasurement.cpp", "service.cpp" diff --git a/gnss/2.0/default/Gnss.cpp b/gnss/2.0/default/Gnss.cpp index e21fb175a6..7f1ef9bdf8 100644 --- a/gnss/2.0/default/Gnss.cpp +++ b/gnss/2.0/default/Gnss.cpp @@ -18,6 +18,7 @@ #include "Gnss.h" #include +#include "AGnssRil.h" namespace android { namespace hardware { @@ -176,6 +177,10 @@ Return Gnss::injectBestLocation(const V1_0::GnssLocation&) { } // Methods from V2_0::IGnss follow. +Return> Gnss::getExtensionAGnssRil_2_0() { + return new AGnssRil{}; +} + Return> Gnss::getExtensionGnssMeasurement_2_0() { // TODO implement return sp{}; diff --git a/gnss/2.0/default/Gnss.h b/gnss/2.0/default/Gnss.h index 7f14513f6c..cd69a937cf 100644 --- a/gnss/2.0/default/Gnss.h +++ b/gnss/2.0/default/Gnss.h @@ -72,6 +72,7 @@ struct Gnss : public IGnss { Return injectBestLocation(const V1_0::GnssLocation& location) override; // Methods from V2_0::IGnss follow. + Return> getExtensionAGnssRil_2_0() override; Return> getExtensionGnssMeasurement_2_0() override; Return setCallback_2_0(const sp& callback) override; Return> diff --git a/gnss/2.0/types.hal b/gnss/2.0/types.hal new file mode 100644 index 0000000000..97c178ff32 --- /dev/null +++ b/gnss/2.0/types.hal @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2018 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@2.0; + +/** Network handle type. */ +typedef uint64_t net_handle_t; diff --git a/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp b/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp index 12a15e8cc7..478a4b2b02 100644 --- a/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp +++ b/gnss/2.0/vts/functional/gnss_hal_test_cases.cpp @@ -23,6 +23,7 @@ using android::hardware::hidl_vec; using IGnssMeasurement_2_0 = android::hardware::gnss::V2_0::IGnssMeasurement; using IGnssMeasurement_1_1 = android::hardware::gnss::V1_1::IGnssMeasurement; +using IAGnssRil_2_0 = android::hardware::gnss::V2_0::IAGnssRil; /* * SetupTeardownCreateCleanup: @@ -47,3 +48,45 @@ TEST_F(GnssHalTest, TestGnssMeasurementCallback) { ASSERT_TRUE((iGnssMeas_1_1 != nullptr) != (iGnssMeas_2_0 != nullptr)); } } + +/* + * TestAGnssRilExtension: + * Gets the AGnssRilExtension and verifies that it returns an actual extension. + * + * The GNSS HAL 2.0 implementation must support @2.0::IAGnssRil interface due to the deprecation + * of framework network API methods needed to support the @1::IAGnssRil interface. + */ +TEST_F(GnssHalTest, TestAGnssRilExtension) { + auto agnssRil = gnss_hal_->getExtensionAGnssRil_2_0(); + ASSERT_TRUE(agnssRil.isOk()); + sp iAGnssRil = agnssRil; + ASSERT_NE(iAGnssRil, nullptr); +} + +/* + * TestAGnssRilUpdateNetworkState_2_0: + * 1. Update GNSS HAL that a network has connected. + * 2. Update GNSS HAL that network has disconnected. + */ +TEST_F(GnssHalTest, TestAGnssRilUpdateNetworkState_2_0) { + auto agnssRil = gnss_hal_->getExtensionAGnssRil_2_0(); + ASSERT_TRUE(agnssRil.isOk()); + sp iAGnssRil = agnssRil; + ASSERT_NE(iAGnssRil, nullptr); + + // Update GNSS HAL that a network is connected. + IAGnssRil_2_0::NetworkAttributes networkAttributes = { + .networkHandle = static_cast(7700664333), + .isConnected = true, + .capabilities = static_cast(IAGnssRil_2_0::NetworkCapability::NOT_ROAMING), + .apn = "dummy-apn"}; + auto result = iAGnssRil->updateNetworkState_2_0(networkAttributes); + ASSERT_TRUE(result.isOk()); + EXPECT_TRUE(result); + + // Update GNSS HAL that network has disconnected. + networkAttributes.isConnected = false; + result = iAGnssRil->updateNetworkState_2_0(networkAttributes); + ASSERT_TRUE(result.isOk()); + EXPECT_TRUE(result); +}