Remove unnecessary cast to PlatformAudioBase

- The previous auto could cause a copy of PlatformAudio to be made which
  prevents the correct state from being updated.
- A cast is not required anyway, so just remove it.

Bug: 110840618
Test: ./load_chre.sh, wait for AR still, see only one disable call
Change-Id: I063ef4ec7884a4b5d1885f63274c4004c83a194e
diff --git a/apps/audio_stress_test/Makefile b/apps/audio_stress_test/Makefile
new file mode 100644
index 0000000..0a1f1b9
--- /dev/null
+++ b/apps/audio_stress_test/Makefile
@@ -0,0 +1,36 @@
+#
+# Audio Stress Test Nanoapp Makefile
+#
+
+# Environment Checks ###########################################################
+
+ifeq ($(CHRE_PREFIX),)
+ifneq ($(ANDROID_BUILD_TOP),)
+CHRE_PREFIX = $(ANDROID_BUILD_TOP)/system/chre
+else
+$(error "You must run 'lunch' to setup ANDROID_BUILD_TOP, or explicitly define \
+         the CHRE_PREFIX environment variable to point to the CHRE root \
+         directory.")
+endif
+endif
+
+# Nanoapp Configuration ########################################################
+
+NANOAPP_NAME_STRING = \"Audio\ Stress\ Test\"
+NANOAPP_NAME = audio_stress_test
+NANOAPP_ID = 0x476f6f676c002007
+NANOAPP_VERSION = 0x00000001
+
+# Common Compiler Flags ########################################################
+
+# Defines.
+COMMON_CFLAGS += -DCHRE_NANOAPP_DISABLE_BACKCOMPAT
+COMMON_CFLAGS += -DNANOAPP_MINIMUM_LOG_LEVEL=CHRE_LOG_LEVEL_DEBUG
+
+# Common Source Files ##########################################################
+
+COMMON_SRCS += audio_stress_test.cc
+
+# Makefile Includes ############################################################
+
+include $(CHRE_PREFIX)/build/nanoapp/app.mk
diff --git a/apps/audio_stress_test/audio_stress_test.cc b/apps/audio_stress_test/audio_stress_test.cc
new file mode 100644
index 0000000..e3ad2aa
--- /dev/null
+++ b/apps/audio_stress_test/audio_stress_test.cc
@@ -0,0 +1,132 @@
+/*
+ * 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.
+ */
+
+#include <chre.h>
+#include <cinttypes>
+
+#include "chre/util/optional.h"
+#include "chre/util/nanoapp/audio.h"
+#include "chre/util/nanoapp/log.h"
+#include "chre/util/time.h"
+
+#define LOG_TAG "[AudioStress]"
+
+/**
+ * @file
+ *
+ * This nanoapp is designed to subscribe to audio for varying durations of
+ * time and verify that audio data is delivered when it is expected to be. It is
+ * designed to be loaded by a companion host binary that listens for messages
+ * from this nanoapp to indicate failure or otherwise.
+ */
+
+using chre::Milliseconds;
+using chre::Nanoseconds;
+using chre::Optional;
+using chre::Seconds;
+
+namespace {
+
+//! The required buffer size for the stress test.
+constexpr Nanoseconds kBufferDuration = Nanoseconds(Seconds(2));
+
+//! The required sample format for the stress test.
+constexpr uint8_t kBufferFormat = CHRE_AUDIO_DATA_FORMAT_16_BIT_SIGNED_PCM;
+
+//! The required sample rate for the stress test.
+constexpr uint32_t kBufferSampleRate = 16000;
+
+//! The list of durations to subscribe to audio for. Even durations are for when
+//! audio is enabled and odd is for when audio is disabled.
+constexpr Milliseconds kStressPlan[] = {
+  // Enabled, Disabled
+  Milliseconds(1000), Milliseconds(2000),
+  Milliseconds(10000), Disabled(1000),
+};
+
+//! The discovered audio handle found at startup.
+uint32_t gAudioHandle;
+
+//! The current position in the stress plan.
+size_t gTestPosition = 0;
+
+//! The timer handle to advance through the stress test.
+uint32_t gTimerHandle;
+
+/**
+ * Discovers an audio source to use for the stress test. The gAudioHandle will
+ * be set if the audio source was found.
+ *
+ * @return true if a matching source was discovered successfully.
+ */
+bool discoverAudioHandle() {
+  bool success = false;
+  struct chreAudioSource source;
+  for (uint32_t i = 0; !success && chreAudioGetSource(i, &source); i++) {
+    LOGI("Found audio source '%s' with %" PRIu32 "Hz %s data",
+         source.name, source.sampleRate,
+         chre::getChreAudioFormatString(source.format));
+    LOGI("  buffer duration: [%" PRIu64 "ns, %" PRIu64 "ns]",
+        source.minBufferDuration, source.maxBufferDuration);
+
+    if (source.sampleRate == kBufferSampleRate
+        && source.minBufferDuration <= kBufferDuration.toRawNanoseconds()
+        && source.maxBufferDuration >= kBufferDuration.toRawNanoseconds()
+        && source.format == kBufferFormat) {
+      gAudioHandle = i;
+      success = true;
+    }
+  }
+
+  if (!success) {
+    LOGW("Failed to find suitable audio source");
+  }
+
+  return success;
+}
+
+bool advanceTestPosition() {
+  gTimerHandle = chreTimerSet(kStressPlan[gTestPosition++].toRawNanoseconds(),
+                              nullptr, true /* oneShot */);
+  bool success = (gTimerHandle != CHRE_TIMER_INVALID);
+  if (!success) {
+    LOGE("Failed to set test timer");
+  }
+
+  return success;
+}
+
+bool startStressTest() {
+  return true;
+}
+
+}  // namespace
+
+
+bool nanoappStart() {
+  LOGI("start");
+  return (discoverAudioHandle() && startStressTest());
+}
+
+void nanoappHandleEvent(uint32_t senderInstanceId,
+                        uint16_t eventType,
+                        const void *eventData) {
+
+}
+
+void nanoappEnd() {
+  LOGI("stop");
+}
diff --git a/platform/slpi/platform_audio.cc b/platform/slpi/platform_audio.cc
index 0648f36..150358b 100644
--- a/platform/slpi/platform_audio.cc
+++ b/platform/slpi/platform_audio.cc
@@ -106,10 +106,9 @@
   }
 
   if (lastNumAudioClients == 0 && mNumAudioClients > 0) {
-    // When enabling, request audio immediately.
-    LOGD("Enabling WCD SLPI");
     mTargetAudioEnabled = true;
     if (!mCurrentAudioEnabled) {
+      LOGD("Enabling WCD SLPI");
       mCurrentAudioEnabled = true;
       sendAudioRequest();
     }
diff --git a/platform/slpi/see/power_control_manager.cc b/platform/slpi/see/power_control_manager.cc
index e98c495..3359723 100644
--- a/platform/slpi/see/power_control_manager.cc
+++ b/platform/slpi/see/power_control_manager.cc
@@ -38,10 +38,8 @@
 #ifdef CHRE_AUDIO_SUPPORT_ENABLED
     if (awake) {
       auto callback = [](uint16_t /* eventType */, void * /* eventData*/) {
-        auto platformAudioBase = static_cast<PlatformAudioBase&>(
-            EventLoopManagerSingleton::get()->getAudioRequestManager()
-                .getPlatformAudio());
-        platformAudioBase.onHostAwake();
+        EventLoopManagerSingleton::get()->getAudioRequestManager()
+            .getPlatformAudio().onHostAwake();
       };
 
       EventLoopManagerSingleton::get()->deferCallback(