Snap for 11297784 from a2bac821fd1ff4aa6c470bde16cf4c9485458a5c to mainline-adbd-release

Change-Id: I6f0dc1e5b438e566ce41a9cead32d6f24b019eb3
diff --git a/Android.bp b/Android.bp
index 3315400..30edee7 100644
--- a/Android.bp
+++ b/Android.bp
@@ -654,12 +654,15 @@
     cflags: [
         "-DMBEDTLS_CONFIG_FILE=\"mbedtls-config.h\"",
         "-DOPENTHREAD_CONFIG_ANDROID_VERSION_HEADER_ENABLE=1",
+        "-DOPENTHREAD_CONFIG_DNS_CLIENT_ENABLE=1",
+        "-DOPENTHREAD_CONFIG_ECDSA_ENABLE=1",
         "-DOPENTHREAD_CONFIG_FILE=\"openthread-config-android-version.h\"",
         "-DOPENTHREAD_CONFIG_LOG_LEVEL_DYNAMIC_ENABLE=1",
         "-DOPENTHREAD_CONFIG_MAC_FILTER_ENABLE=1",
         "-DOPENTHREAD_CONFIG_MLR_ENABLE=1",
         "-DOPENTHREAD_CONFIG_NCP_HDLC_ENABLE=1",
         "-DOPENTHREAD_CONFIG_PING_SENDER_ENABLE=1",
+        "-DOPENTHREAD_CONFIG_SRP_CLIENT_ENABLE=1",
         "-DOPENTHREAD_CONFIG_PLATFORM_FLASH_API_ENABLE=0",
         "-DOPENTHREAD_EXAMPLES_SIMULATION=1",
         "-DOPENTHREAD_CONFIG_TCP_ENABLE=0",
@@ -671,6 +674,7 @@
         "-DPACKAGE_TARNAME=\"openthread\"",
         "-DPACKAGE_URL=\"http://github.com/openthread/openthread\"",
         "-DSPINEL_PLATFORM_HEADER=\"spinel_platform.h\"",
+        "-Wno-implicit-fallthrough",
     ],
 }
 
diff --git a/src/android/openthread-core-android-config.h b/src/android/openthread-core-android-config.h
index 28d669d..b6929bf 100644
--- a/src/android/openthread-core-android-config.h
+++ b/src/android/openthread-core-android-config.h
@@ -43,7 +43,7 @@
  * The run time data path.
  *
  */
-#define OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH "/data/misc/threadnetwork"
+#define OPENTHREAD_CONFIG_POSIX_SETTINGS_PATH "/data/misc/apexdata/com.android.tethering/threadnetwork"
 
 /**
  * @def OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME
@@ -51,7 +51,7 @@
  * Define socket basename used by POSIX app daemon.
  *
  */
-#define OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME "/data/misc/threadnetwork/openthread-%s"
+#define OPENTHREAD_POSIX_CONFIG_DAEMON_SOCKET_BASENAME "/data/misc/apexdata/com.android.tethering/threadnetwork/openthread-%s"
 
 /**
  * @def OPENTHREAD_POSIX_CONFIG_RCP_PTY_ENABLE
diff --git a/src/android/thread_network_hal/hal_interface.cpp b/src/android/thread_network_hal/hal_interface.cpp
index a4bb792..f1de827 100644
--- a/src/android/thread_network_hal/hal_interface.cpp
+++ b/src/android/thread_network_hal/hal_interface.cpp
@@ -62,6 +62,8 @@
     , mHalInterfaceId(0)
 {
     IgnoreError(aRadioUrl.ParseUint8("id", mHalInterfaceId));
+    memset(&mInterfaceMetrics, 0, sizeof(mInterfaceMetrics));
+    mInterfaceMetrics.mRcpInterfaceType = kSpinelInterfaceTypeVendor;
 }
 
 otError HalInterface::Init(SpinelInterface::ReceiveFrameCallback aCallback,
@@ -227,6 +229,12 @@
     otLogWarnPlat("[HAL] Send frame to HAL interface failed: %s", otThreadErrorToString(error));
 
 exit:
+    if (error == OT_ERROR_NONE)
+    {
+        mInterfaceMetrics.mTxFrameCount++;
+        mInterfaceMetrics.mTxFrameByteCount += aLength;
+    }
+
     return error;
 }
 
@@ -243,7 +251,7 @@
         {
             otLogNotePlat("[HAL] Drop the received spinel frame: %s", otThreadErrorToString(error));
             mRxFrameBuffer->DiscardFrame();
-            ExitNow();
+            ExitNow(error = OT_ERROR_NO_BUFS);
         }
     }
 
@@ -253,6 +261,12 @@
     }
 
 exit:
+    if (error == OT_ERROR_NONE)
+    {
+        mInterfaceMetrics.mRxFrameCount++;
+        mInterfaceMetrics.mRxFrameByteCount += aFrame.size();
+    }
+
     return;
 }
 
diff --git a/src/android/thread_network_hal/hal_interface.hpp b/src/android/thread_network_hal/hal_interface.hpp
index 07331e4..ef72d05 100644
--- a/src/android/thread_network_hal/hal_interface.hpp
+++ b/src/android/thread_network_hal/hal_interface.hpp
@@ -54,7 +54,7 @@
  * This class defines an IPC Binder interface to the Radio Co-processor (RCP).
  *
  */
-class HalInterface
+class HalInterface : public ot::Spinel::SpinelInterface
 {
 public:
     /**
@@ -87,13 +87,13 @@
      */
     otError Init(Spinel::SpinelInterface::ReceiveFrameCallback aCallback,
                  void                                         *aCallbackContext,
-                 Spinel::SpinelInterface::RxFrameBuffer       &aFrameBuffer);
+                 Spinel::SpinelInterface::RxFrameBuffer       &aFrameBuffer) override;
 
     /**
      * This method deinitializes the interface to the RCP.
      *
      */
-    void Deinit(void);
+    void Deinit(void) override;
 
     /**
      * This method encodes and sends a spinel frame to Radio Co-processor (RCP) over the socket.
@@ -107,7 +107,7 @@
      * @retval OT_ERROR_FAILED   Failed to call the HAL to send the frame.
      *
      */
-    otError SendFrame(const uint8_t *aFrame, uint16_t aLength);
+    otError SendFrame(const uint8_t *aFrame, uint16_t aLength) override;
 
     /**
      * This method waits for receiving part or all of spinel frame within specified interval.
@@ -118,7 +118,7 @@
      * @retval OT_ERROR_RESPONSE_TIMEOUT No spinel frame is received within @p aTimeout.
      *
      */
-    otError WaitForFrame(uint64_t aTimeoutUs);
+    otError WaitForFrame(uint64_t aTimeoutUs) override;
 
     /**
      * This method updates the file descriptor sets with file descriptors used by the radio driver.
@@ -126,7 +126,7 @@
      * @param[in]   aMainloopContext  The context containing fd_sets.
      *
      */
-    void UpdateFdSet(void *aMainloopContext);
+    void UpdateFdSet(void *aMainloopContext) override;
 
     /**
      * This method performs radio driver processing.
@@ -134,7 +134,7 @@
      * @param[in]   aMainloopContext  The context containing fd_sets.
      *
      */
-    void Process(const void *aMainloopContext);
+    void Process(const void *aMainloopContext) override;
 
     /**
      * This method returns the bus speed between the host and the radio.
@@ -142,7 +142,7 @@
      * @returns   Bus speed in bits/second.
      *
      */
-    uint32_t GetBusSpeed(void) const;
+    uint32_t GetBusSpeed(void) const override;
 
     /**
      * This method hardware resets the RCP. It will be called after a software reset fails.
@@ -151,7 +151,15 @@
      * @retval OT_ERROR_NOT_IMPLEMENT   The hardware reset is not implemented.
      *
      */
-    otError HardwareReset(void);
+    otError HardwareReset(void) override;
+
+    /**
+     * Returns the RCP interface metrics.
+     *
+     * @returns The RCP interface metrics.
+     *
+     */
+    const otRcpInterfaceMetrics *GetRcpInterfaceMetrics(void) const override { return &mInterfaceMetrics; }
 
 private:
     void        ReceiveFrameCallback(const std::vector<uint8_t> &aFrame);
@@ -185,6 +193,8 @@
     void                                         *mRxFrameContext;
     Spinel::SpinelInterface::RxFrameBuffer       *mRxFrameBuffer;
 
+    otRcpInterfaceMetrics mInterfaceMetrics;
+
     std::shared_ptr<::aidl::android::hardware::threadnetwork::IThreadChip>         mThreadChip;
     std::shared_ptr<::aidl::android::hardware::threadnetwork::IThreadChipCallback> mThreadChipCallback;
 
diff --git a/src/android/thread_network_hal/vendor_interface.cpp b/src/android/thread_network_hal/vendor_interface.cpp
index fca1ae6..6fbc8cf 100644
--- a/src/android/thread_network_hal/vendor_interface.cpp
+++ b/src/android/thread_network_hal/vendor_interface.cpp
@@ -86,7 +86,10 @@
 
 otError VendorInterface::HardwareReset(void) { return sHalInterface->HardwareReset(); }
 
-const otRcpInterfaceMetrics *VendorInterface::GetRcpInterfaceMetrics(void) const { return nullptr; }
+const otRcpInterfaceMetrics *VendorInterface::GetRcpInterfaceMetrics(void) const
+{
+    return sHalInterface->GetRcpInterfaceMetrics();
+}
 } // namespace Posix
 } // namespace ot
 
diff --git a/src/posix/platform/include/openthread/openthread-system.h b/src/posix/platform/include/openthread/openthread-system.h
index 29dc3ee..61a0741 100644
--- a/src/posix/platform/include/openthread/openthread-system.h
+++ b/src/posix/platform/include/openthread/openthread-system.h
@@ -246,6 +246,14 @@
  */
 void otSysSetInfraNetif(const char *aInfraNetifName, int aIcmp6Socket);
 
+/**
+ * Returns TRUE if the infrastructure interface is running.
+ *
+ * @returns TRUE if the infrastructure interface is running, FALSE if not.
+ *
+ */
+bool otSysInfraIfIsRunning(void);
+
 #ifdef __cplusplus
 } // end of extern "C"
 #endif
diff --git a/src/posix/platform/infra_if.cpp b/src/posix/platform/infra_if.cpp
index 626d128..6e16b3f 100644
--- a/src/posix/platform/infra_if.cpp
+++ b/src/posix/platform/infra_if.cpp
@@ -112,7 +112,7 @@
 #endif
 }
 
-bool platformInfraIfIsRunning(void) { return ot::Posix::InfraNetif::Get().IsRunning(); }
+bool otSysInfraIfIsRunning(void) { return ot::Posix::InfraNetif::Get().IsRunning(); }
 
 const char *otSysGetInfraNetifName(void) { return ot::Posix::InfraNetif::Get().GetNetifName(); }
 
@@ -452,7 +452,7 @@
     VerifyOrExit(mNetLinkSocket != -1);
 
 #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
-    SuccessOrDie(otBorderRoutingInit(gInstance, mInfraIfIndex, platformInfraIfIsRunning()));
+    SuccessOrDie(otBorderRoutingInit(gInstance, mInfraIfIndex, otSysInfraIfIsRunning()));
     SuccessOrDie(otBorderRoutingSetEnabled(gInstance, /* aEnabled */ true));
 #endif
 
@@ -546,7 +546,7 @@
         case RTM_NEWLINK:
         case RTM_DELLINK:
 #if OPENTHREAD_CONFIG_BORDER_ROUTING_ENABLE
-            SuccessOrDie(otPlatInfraIfStateChanged(gInstance, mInfraIfIndex, platformInfraIfIsRunning()));
+            SuccessOrDie(otPlatInfraIfStateChanged(gInstance, mInfraIfIndex, otSysInfraIfIsRunning()));
 #endif
             break;
         case NLMSG_ERROR:
diff --git a/src/posix/platform/platform-posix.h b/src/posix/platform/platform-posix.h
index 0617bfc..912ceb5 100644
--- a/src/posix/platform/platform-posix.h
+++ b/src/posix/platform/platform-posix.h
@@ -416,14 +416,6 @@
 extern otInstance *gInstance;
 
 /**
- * Tells if the infrastructure interface is running.
- *
- * @returns TRUE if the infrastructure interface is running, FALSE if not.
- *
- */
-bool platformInfraIfIsRunning(void);
-
-/**
  * Initializes backtrace module.
  *
  */
diff --git a/src/posix/platform/radio.cpp b/src/posix/platform/radio.cpp
index 491c6db..7cf2737 100644
--- a/src/posix/platform/radio.cpp
+++ b/src/posix/platform/radio.cpp
@@ -71,7 +71,7 @@
     spinel_iid_t                            iidList[Spinel::kSpinelHeaderMaxNumIid];
     struct ot::Spinel::RadioSpinelCallbacks callbacks;
 
-    mRadioUrl = aUrl;
+    mRadioUrl.Init(aUrl);
     VerifyOrDie(mRadioUrl.GetPath() != nullptr, OT_EXIT_INVALID_ARGUMENTS);
 
     memset(&callbacks, 0, sizeof(callbacks));
diff --git a/src/posix/platform/radio_url.cpp b/src/posix/platform/radio_url.cpp
index bd34d9c..db0c134 100644
--- a/src/posix/platform/radio_url.cpp
+++ b/src/posix/platform/radio_url.cpp
@@ -135,7 +135,7 @@
 namespace ot {
 namespace Posix {
 
-RadioUrl::RadioUrl(const char *aUrl)
+void RadioUrl::Init(const char *aUrl)
 {
     if (aUrl != nullptr)
     {
diff --git a/src/posix/platform/radio_url.hpp b/src/posix/platform/radio_url.hpp
index 32b2c4c..0246070 100644
--- a/src/posix/platform/radio_url.hpp
+++ b/src/posix/platform/radio_url.hpp
@@ -52,7 +52,20 @@
      * @param[in]   aUrl    The null-terminated URL string.
      *
      */
-    RadioUrl(const char *aUrl);
+    explicit RadioUrl(const char *aUrl) { Init(aUrl); };
+
+    /**
+     * Initializes the radio URL.
+     *
+     * @param[in]   aUrl    The null-terminated URL string.
+     *
+     */
+    void Init(const char *aUrl);
+
+    RadioUrl(const RadioUrl &)            = delete;
+    RadioUrl(RadioUrl &&)                 = delete;
+    RadioUrl &operator=(const RadioUrl &) = delete;
+    RadioUrl &operator=(RadioUrl &&)      = delete;
 
 private:
     enum