Remove dependency on libandroid

The main purpose of this change is to avoid having to pull in libandroid
for the sake of using the sensor manager from the audioserver process
(native). The way this is achieved is by using lower-level APIs, namely
those offered by libsensor.

As a result, we were able to use sensor handles in SensorPoseProvider,
rather than ASensor* objects, which is simpler and removes the need to
enumerate all the sensor for the sake of finding the one with the
correct handle.

Test: Manually enable head tracking and observe the logs to verify that
      the expected pose updates are received.
Bug: 198795859
Change-Id: Ic69c322d6ea9297309a4856b3047c841831e04d7
diff --git a/services/audiopolicy/service/Spatializer.cpp b/services/audiopolicy/service/Spatializer.cpp
index 32499f4..502a8d0 100644
--- a/services/audiopolicy/service/Spatializer.cpp
+++ b/services/audiopolicy/service/Spatializer.cpp
@@ -25,7 +25,6 @@
 #include <sys/types.h>
 
 #include <android/content/AttributionSourceState.h>
-#include <android/sensor.h>
 #include <audio_utils/fixedfft.h>
 #include <cutils/bitops.h>
 #include <hardware/sensors.h>
@@ -346,9 +345,9 @@
 
     modes->push_back(SpatializerHeadTrackingMode::DISABLED);
     if (mSupportsHeadTracking) {
-        if (mHeadSensor != nullptr) {
+        if (mHeadSensor != SpatializerPoseController::INVALID_SENSOR) {
             modes->push_back(SpatializerHeadTrackingMode::RELATIVE_WORLD);
-            if (mScreenSensor != nullptr) {
+            if (mScreenSensor != SpatializerPoseController::INVALID_SENSOR) {
                 modes->push_back(SpatializerHeadTrackingMode::RELATIVE_SCREEN);
             }
         }
@@ -451,11 +450,7 @@
         return binderStatusFromStatusT(INVALID_OPERATION);
     }
     std::lock_guard lock(mLock);
-    if (sensorHandle == ASENSOR_INVALID) {
-        mHeadSensor = nullptr;
-    } else {
-        mHeadSensor = VALUE_OR_RETURN_BINDER_STATUS(getSensorFromHandle(sensorHandle));
-    }
+    mHeadSensor = sensorHandle;
     if (mPoseController != nullptr) {
         mPoseController->setHeadSensor(mHeadSensor);
     }
@@ -468,11 +463,7 @@
         return binderStatusFromStatusT(INVALID_OPERATION);
     }
     std::lock_guard lock(mLock);
-    if (sensorHandle == ASENSOR_INVALID) {
-        mScreenSensor = nullptr;
-    } else {
-        mScreenSensor = VALUE_OR_RETURN_BINDER_STATUS(getSensorFromHandle(sensorHandle));
-    }
+    mScreenSensor = sensorHandle;
     if (mPoseController != nullptr) {
         mPoseController->setScreenSensor(mScreenSensor);
     }
@@ -634,24 +625,6 @@
     }
 }
 
-/* static */
-ConversionResult<ASensorRef> Spatializer::getSensorFromHandle(int handle) {
-    ASensorManager* sensorManager =
-            ASensorManager_getInstanceForPackage("headtracker");
-    if (!sensorManager) {
-        ALOGE("Failed to get a sensor manager");
-        return base::unexpected(NO_INIT);
-    }
-    ASensorList sensorList;
-    int numSensors = ASensorManager_getSensorList(sensorManager, &sensorList);
-    for (int i = 0; i < numSensors; ++i) {
-        if (ASensor_getHandle(sensorList[i]) == handle) {
-            return sensorList[i];
-        }
-    }
-    return base::unexpected(BAD_VALUE);
-}
-
 status_t Spatializer::attachOutput(audio_io_handle_t output) {
     std::shared_ptr<SpatializerPoseController> poseController;
     {