Snap for 6626121 from c898b974e7579f4b3a02900b885d418c8127935c to rvc-release

Change-Id: Ida63690cf0eb50a95354c338e0c9d67c17852924
diff --git a/audio/Android.bp b/audio/Android.bp
index 4b80fd7..4905fe5 100644
--- a/audio/Android.bp
+++ b/audio/Android.bp
@@ -41,6 +41,7 @@
         "libtinyalsa",
         "libutils",
         "libfmq",
+        "libprocessgroup",
     ],
     header_libs: [
         "libaudio_system_headers",
diff --git a/audio/io_thread.cpp b/audio/io_thread.cpp
index 35a4d2a..81982b3 100644
--- a/audio/io_thread.cpp
+++ b/audio/io_thread.cpp
@@ -32,7 +32,6 @@
 }
 
 void IOThread::requestExit() {
-    Thread::requestExit();
     notify(EXIT_REQUEST);
 }
 
diff --git a/audio/io_thread.h b/audio/io_thread.h
index 355a29c..698df49 100644
--- a/audio/io_thread.h
+++ b/audio/io_thread.h
@@ -15,7 +15,6 @@
  */
 
 #pragma once
-#include <utils/Thread.h>
 #include <fmq/EventFlag.h>
 
 namespace android {
@@ -24,15 +23,15 @@
 namespace V6_0 {
 namespace implementation {
 
-struct IOThread : public ::android::Thread {
+struct IOThread {
     static constexpr uint32_t STAND_BY_REQUEST = 1 << 20;
     static constexpr uint32_t EXIT_REQUEST = 1 << 21;
 
-    IOThread() : Thread(false /*canCallJava*/) {}
+    virtual ~IOThread() {}
     virtual EventFlag *getEventFlag() = 0;
     virtual bool notify(uint32_t mask);
     virtual bool standby();
-    void requestExit() override;
+    virtual void requestExit();
 };
 
 }  // namespace implementation
diff --git a/audio/stream_in.cpp b/audio/stream_in.cpp
index 172617d..89ca7e6 100644
--- a/audio/stream_in.cpp
+++ b/audio/stream_in.cpp
@@ -23,6 +23,12 @@
 #include "deleters.h"
 #include "talsa.h"
 #include "util.h"
+#include <sys/resource.h>
+#include <pthread.h>
+#include <cutils/sched_policy.h>
+#include <utils/ThreadDefs.h>
+#include <future>
+#include <thread>
 
 namespace android {
 namespace hardware {
@@ -75,29 +81,39 @@
             mEfGroup.reset(rawEfGroup);
         }
 
-        status = run("reader", PRIORITY_URGENT_AUDIO);
-        if (status != OK) {
-            ALOGE("ReadThread::%s:%d: failed to start the thread: %s",
-                  __func__, __LINE__, strerror(-status));
-        }
+        mThread = std::thread(&ReadThread::threadLoop, this);
     }
 
     ~ReadThread() {
-        requestExit();
-        LOG_ALWAYS_FATAL_IF(join() != OK);
+        if (mThread.joinable()) {
+            requestExit();
+            mThread.join();
+        }
     }
 
     EventFlag *getEventFlag() override {
         return mEfGroup.get();
     }
 
-    bool threadLoop() override {
-        while (!exitPending()) {
+    bool isRunning() const {
+        return mThread.joinable();
+    }
+
+    std::future<pthread_t> getTid() {
+        return mTid.get_future();
+    }
+
+    void threadLoop() {
+        setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_AUDIO);
+        set_sched_policy(0, SP_FOREGROUND);
+        mTid.set_value(pthread_self());
+
+        while (true) {
             uint32_t efState = 0;
             mEfGroup->wait(MessageQueueFlagBits::NOT_FULL | EXIT_REQUEST | STAND_BY_REQUEST,
                            &efState);
             if (efState & EXIT_REQUEST) {
-                return false;
+                return;
             }
 
             if (efState & STAND_BY_REQUEST) {
@@ -122,8 +138,6 @@
                 processCommand();
             }
         }
-
-        return false;   // do not restart threadLoop
     }
 
     void processCommand() {
@@ -217,6 +231,8 @@
     std::unique_ptr<uint8_t[]> mBuffer;
     talsa::PcmPtr mPcm;
     util::StreamPosition mPos;
+    std::thread mThread;
+    std::promise<pthread_t> mTid;
 };
 
 } // namespace
@@ -413,7 +429,7 @@
                  *(t->mCommandMQ.getDesc()),
                  *(t->mDataMQ.getDesc()),
                  *(t->mStatusMQ.getDesc()),
-                 {.pid = getpid(), .tid = t->getTid()});
+                 {.pid = getpid(), .tid = t->getTid().get()});
 
         mReadThread = std::move(t);
     } else {
diff --git a/audio/stream_out.cpp b/audio/stream_out.cpp
index 4665efb..8de1963 100644
--- a/audio/stream_out.cpp
+++ b/audio/stream_out.cpp
@@ -24,6 +24,12 @@
 #include "talsa.h"
 #include "deleters.h"
 #include "util.h"
+#include <sys/resource.h>
+#include <pthread.h>
+#include <cutils/sched_policy.h>
+#include <utils/ThreadDefs.h>
+#include <future>
+#include <thread>
 
 namespace android {
 namespace hardware {
@@ -78,29 +84,39 @@
             mEfGroup.reset(rawEfGroup);
         }
 
-        status = run("writer", PRIORITY_URGENT_AUDIO);
-        if (status != OK) {
-            ALOGE("WriteThread::%s:%d: failed to start the thread: %s",
-                  __func__, __LINE__, strerror(-status));
-        }
+        mThread = std::thread(&WriteThread::threadLoop, this);
     }
 
     ~WriteThread() {
-        requestExit();
-        LOG_ALWAYS_FATAL_IF(join() != OK);
+        if (mThread.joinable()) {
+            requestExit();
+            mThread.join();
+        }
     }
 
     EventFlag *getEventFlag() override {
         return mEfGroup.get();
     }
 
-    bool threadLoop() override {
-        while (!exitPending()) {
+    bool isRunning() const {
+        return mThread.joinable();
+    }
+
+    std::future<pthread_t> getTid() {
+        return mTid.get_future();
+    }
+
+    void threadLoop() {
+        setpriority(PRIO_PROCESS, 0, PRIORITY_URGENT_AUDIO);
+        set_sched_policy(0, SP_FOREGROUND);
+        mTid.set_value(pthread_self());
+
+        while (true) {
             uint32_t efState = 0;
             mEfGroup->wait(MessageQueueFlagBits::NOT_EMPTY | STAND_BY_REQUEST | EXIT_REQUEST,
                            &efState);
             if (efState & EXIT_REQUEST) {
-                return false;
+                return;
             }
 
             if (efState & STAND_BY_REQUEST) {
@@ -125,8 +141,6 @@
                 processCommand();
             }
         }
-
-        return false;   // do not restart threadLoop
     }
 
     void processCommand() {
@@ -235,6 +249,8 @@
     std::unique_ptr<uint8_t[]> mBuffer;
     talsa::PcmPtr mPcm;
     util::StreamPosition mPos;
+    std::thread mThread;
+    std::promise<pthread_t> mTid;
 };
 
 } // namespace
@@ -431,7 +447,7 @@
                  *(t->mCommandMQ.getDesc()),
                  *(t->mDataMQ.getDesc()),
                  *(t->mStatusMQ.getDesc()),
-                 {.pid = getpid(), .tid = t->getTid()});
+                 {.pid = getpid(), .tid = t->getTid().get()});
 
         mWriteThread = std::move(t);
     } else {
diff --git a/gnss/gnss_measurement.cpp b/gnss/gnss_measurement.cpp
index 746167d..6acedd4 100644
--- a/gnss/gnss_measurement.cpp
+++ b/gnss/gnss_measurement.cpp
@@ -88,7 +88,7 @@
         .receivedSvTimeUncertaintyInNs = 15,
         .cN0DbHz = 30.0,
         .pseudorangeRateMps = -484.13739013671875,
-        .pseudorangeRateUncertaintyMps = 1.0379999876022339,
+        .pseudorangeRateUncertaintyMps = 0.12,
         .accumulatedDeltaRangeState = GnssAccumulatedDeltaRangeState10::ADR_STATE_UNKNOWN | 0,
         .accumulatedDeltaRangeM = 0.0,
         .accumulatedDeltaRangeUncertaintyM = 0.0,