Fix handling of initialization error

When an error occurs before mLooper has been initialized, the dtor
will access uninitialized memory.
This change initializes mLooper first, to avoid this error.

Bug: 188502620
Test: Manual running of SensorPoseProvider-example
Change-Id: I0a493ff766f53d17a9a2679efed693df702ba92c
diff --git a/media/libheadtracking/SensorPoseProvider.cpp b/media/libheadtracking/SensorPoseProvider.cpp
index 0142d56..8e6c2ff 100644
--- a/media/libheadtracking/SensorPoseProvider.cpp
+++ b/media/libheadtracking/SensorPoseProvider.cpp
@@ -144,6 +144,9 @@
     bool waitInitFinished() { return mInitPromise.get_future().get(); }
 
     void threadFunc(const char* packageName) {
+        // Obtain looper.
+        mLooper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
+
         // The number 19 is arbitrary, only useful if using multiple objects on the same looper.
         constexpr int kIdent = 19;
 
@@ -155,9 +158,6 @@
             return;
         }
 
-        // Obtain looper.
-        mLooper = ALooper_prepare(ALOOPER_PREPARE_ALLOW_NON_CALLBACKS);
-
         // Create event queue.
         ASensorEventQueue* queue =
                 ASensorManager_createEventQueue(sensor_manager, mLooper, kIdent, nullptr, nullptr);