Merge "audioflinger: refactor EffectModule class"
diff --git a/apex/Android.bp b/apex/Android.bp
index 42a620b..73dc264 100644
--- a/apex/Android.bp
+++ b/apex/Android.bp
@@ -41,6 +41,8 @@
 
     // Use a custom AndroidManifest.xml used for API targeting.
     androidManifest: ":com.android.media-androidManifest",
+
+    legacy_android10_support: true,
 }
 
 apex {
@@ -76,6 +78,8 @@
 
     // Use a custom AndroidManifest.xml used for API targeting.
     androidManifest: ":com.android.media.swcodec-androidManifest",
+
+    legacy_android10_support: true,
 }
 
 prebuilt_etc {
diff --git a/camera/Android.bp b/camera/Android.bp
index b288bcf..ea7259a 100644
--- a/camera/Android.bp
+++ b/camera/Android.bp
@@ -85,6 +85,7 @@
         "aidl/android/hardware/ICameraServiceProxy.aidl",
         "aidl/android/hardware/camera2/ICameraDeviceCallbacks.aidl",
         "aidl/android/hardware/camera2/ICameraDeviceUser.aidl",
+        "aidl/android/hardware/camera2/ICameraOfflineSession.aidl",
     ],
     path: "aidl",
 }
diff --git a/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl b/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl
index 93549e0..cdb7ac3 100644
--- a/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl
+++ b/camera/aidl/android/hardware/camera2/ICameraDeviceUser.aidl
@@ -17,6 +17,8 @@
 package android.hardware.camera2;
 
 import android.hardware.camera2.CaptureRequest;
+import android.hardware.camera2.ICameraDeviceCallbacks;
+import android.hardware.camera2.ICameraOfflineSession;
 import android.hardware.camera2.impl.CameraMetadataNative;
 import android.hardware.camera2.params.OutputConfiguration;
 import android.hardware.camera2.params.SessionConfiguration;
@@ -177,4 +179,15 @@
       * @return the currently applied system-wide audio restriction mode
       */
     int getGlobalAudioRestriction();
+
+    /**
+     * Offline processing main entry point
+     *
+     * @param callbacks Object that will receive callbacks from offline session
+     * @param offlineOutputIds The ID of streams that needs to be preserved in offline session
+     *
+     * @return Offline session object.
+     */
+    ICameraOfflineSession switchToOffline(in ICameraDeviceCallbacks callbacks,
+            in Surface[] offlineOutputs);
 }
diff --git a/camera/aidl/android/hardware/camera2/ICameraOfflineSession.aidl b/camera/aidl/android/hardware/camera2/ICameraOfflineSession.aidl
new file mode 100644
index 0000000..ab030ab
--- /dev/null
+++ b/camera/aidl/android/hardware/camera2/ICameraOfflineSession.aidl
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+package android.hardware.camera2;
+
+ /** @hide */
+interface ICameraOfflineSession
+{
+    void disconnect();
+}
diff --git a/camera/ndk/include/camera/NdkCameraMetadataTags.h b/camera/ndk/include/camera/NdkCameraMetadataTags.h
index 825f308..0652cbb 100644
--- a/camera/ndk/include/camera/NdkCameraMetadataTags.h
+++ b/camera/ndk/include/camera/NdkCameraMetadataTags.h
@@ -1311,7 +1311,7 @@
     /**
      * <p>List of the maximum number of regions that can be used for metering in
      * auto-exposure (AE), auto-white balance (AWB), and auto-focus (AF);
-     * this corresponds to the the maximum number of elements in
+     * this corresponds to the maximum number of elements in
      * ACAMERA_CONTROL_AE_REGIONS, ACAMERA_CONTROL_AWB_REGIONS,
      * and ACAMERA_CONTROL_AF_REGIONS.</p>
      *
diff --git a/drm/drmserver/DrmManager.cpp b/drm/drmserver/DrmManager.cpp
index e2ea83a..38dc052 100644
--- a/drm/drmserver/DrmManager.cpp
+++ b/drm/drmserver/DrmManager.cpp
@@ -31,7 +31,7 @@
 #include <drm/DrmInfoRequest.h>
 #include <drm/DrmSupportInfo.h>
 #include <drm/DrmConvertedStatus.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <IDrmEngine.h>
 
 #include "DrmManager.h"
@@ -58,7 +58,7 @@
         const char func[], const String8& plugInId, const String8& mimeType) {
     IDrmEngine& engine = mPlugInManager.getPlugIn(plugInId);
 
-    std::unique_ptr<MediaAnalyticsItem> item(MediaAnalyticsItem::create("drmmanager"));
+    std::unique_ptr<mediametrics::Item> item(mediametrics::Item::create("drmmanager"));
     item->setUid(IPCThreadState::self()->getCallingUid());
     item->setCString("function_name", func);
     item->setCString("plugin_id", plugInId.getPathLeaf().getBasePath().c_str());
diff --git a/drm/mediadrm/plugins/clearkey/hidl/Android.bp b/drm/mediadrm/plugins/clearkey/hidl/Android.bp
index eb623f9..a194416 100644
--- a/drm/mediadrm/plugins/clearkey/hidl/Android.bp
+++ b/drm/mediadrm/plugins/clearkey/hidl/Android.bp
@@ -78,18 +78,37 @@
     },
     srcs: ["protos/DeviceFiles.proto"],
 }
+
 cc_binary {
     name: "android.hardware.drm@1.2-service.clearkey",
     defaults: ["clearkey_service_defaults"],
     srcs: ["service.cpp"],
     init_rc: ["android.hardware.drm@1.2-service.clearkey.rc"],
-    vintf_fragments: ["manifest_android.hardware.drm@1.3-service.clearkey.xml"],
+    vintf_fragments: ["manifest_android.hardware.drm@1.2-service.clearkey.xml"],
 }
+
 cc_binary {
     name: "android.hardware.drm@1.2-service-lazy.clearkey",
     overrides: ["android.hardware.drm@1.2-service.clearkey"],
     defaults: ["clearkey_service_defaults"],
     srcs: ["serviceLazy.cpp"],
     init_rc: ["android.hardware.drm@1.2-service-lazy.clearkey.rc"],
+    vintf_fragments: ["manifest_android.hardware.drm@1.2-service.clearkey.xml"],
+}
+
+cc_binary {
+    name: "android.hardware.drm@1.3-service.clearkey",
+    defaults: ["clearkey_service_defaults"],
+    srcs: ["service.cpp"],
+    init_rc: ["android.hardware.drm@1.3-service.clearkey.rc"],
+    vintf_fragments: ["manifest_android.hardware.drm@1.3-service.clearkey.xml"],
+}
+
+cc_binary {
+    name: "android.hardware.drm@1.3-service-lazy.clearkey",
+    overrides: ["android.hardware.drm@1.3-service.clearkey"],
+    defaults: ["clearkey_service_defaults"],
+    srcs: ["serviceLazy.cpp"],
+    init_rc: ["android.hardware.drm@1.3-service-lazy.clearkey.rc"],
     vintf_fragments: ["manifest_android.hardware.drm@1.3-service.clearkey.xml"],
 }
diff --git a/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service-lazy.clearkey.rc b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service-lazy.clearkey.rc
index cff4d74..9afd3d7 100644
--- a/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service-lazy.clearkey.rc
+++ b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service-lazy.clearkey.rc
@@ -5,8 +5,6 @@
     interface android.hardware.drm@1.1::IDrmFactory clearkey
     interface android.hardware.drm@1.2::ICryptoFactory clearkey
     interface android.hardware.drm@1.2::IDrmFactory clearkey
-    interface android.hardware.drm@1.3::ICryptoFactory clearkey
-    interface android.hardware.drm@1.3::IDrmFactory clearkey
     disabled
     oneshot
     class hal
diff --git a/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service.clearkey.rc b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service.clearkey.rc
index dca232a..c1abe7f 100644
--- a/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service.clearkey.rc
+++ b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.2-service.clearkey.rc
@@ -5,8 +5,7 @@
     interface android.hardware.drm@1.1::IDrmFactory clearkey
     interface android.hardware.drm@1.2::ICryptoFactory clearkey
     interface android.hardware.drm@1.2::IDrmFactory clearkey
-    interface android.hardware.drm@1.3::ICryptoFactory clearkey
-    interface android.hardware.drm@1.3::IDrmFactory clearkey
+    disabled
     class hal
     user media
     group media mediadrm
diff --git a/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.3-service-lazy.clearkey.rc b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.3-service-lazy.clearkey.rc
new file mode 100644
index 0000000..1e0d431
--- /dev/null
+++ b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.3-service-lazy.clearkey.rc
@@ -0,0 +1,16 @@
+service vendor.drm-clearkey-hal-1-3 /vendor/bin/hw/android.hardware.drm@1.3-service-lazy.clearkey
+    interface android.hardware.drm@1.0::ICryptoFactory clearkey
+    interface android.hardware.drm@1.0::IDrmFactory clearkey
+    interface android.hardware.drm@1.1::ICryptoFactory clearkey
+    interface android.hardware.drm@1.1::IDrmFactory clearkey
+    interface android.hardware.drm@1.2::ICryptoFactory clearkey
+    interface android.hardware.drm@1.2::IDrmFactory clearkey
+    interface android.hardware.drm@1.3::ICryptoFactory clearkey
+    interface android.hardware.drm@1.3::IDrmFactory clearkey
+    disabled
+    oneshot
+    class hal
+    user media
+    group media mediadrm
+    ioprio rt 4
+    writepid /dev/cpuset/foreground/tasks
diff --git a/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.3-service.clearkey.rc b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.3-service.clearkey.rc
new file mode 100644
index 0000000..8130511
--- /dev/null
+++ b/drm/mediadrm/plugins/clearkey/hidl/android.hardware.drm@1.3-service.clearkey.rc
@@ -0,0 +1,14 @@
+service vendor.drm-clearkey-hal-1-3 /vendor/bin/hw/android.hardware.drm@1.3-service.clearkey
+    interface android.hardware.drm@1.0::ICryptoFactory clearkey
+    interface android.hardware.drm@1.0::IDrmFactory clearkey
+    interface android.hardware.drm@1.1::ICryptoFactory clearkey
+    interface android.hardware.drm@1.1::IDrmFactory clearkey
+    interface android.hardware.drm@1.2::ICryptoFactory clearkey
+    interface android.hardware.drm@1.2::IDrmFactory clearkey
+    interface android.hardware.drm@1.3::ICryptoFactory clearkey
+    interface android.hardware.drm@1.3::IDrmFactory clearkey
+    class hal
+    user media
+    group media mediadrm
+    ioprio rt 4
+    writepid /dev/cpuset/foreground/tasks
diff --git a/drm/mediadrm/plugins/clearkey/hidl/manifest_android.hardware.drm@1.2-service.clearkey.xml b/drm/mediadrm/plugins/clearkey/hidl/manifest_android.hardware.drm@1.2-service.clearkey.xml
new file mode 100644
index 0000000..16cba11
--- /dev/null
+++ b/drm/mediadrm/plugins/clearkey/hidl/manifest_android.hardware.drm@1.2-service.clearkey.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2019 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.
+-->
+<manifest version="1.0" type="device">
+    <hal format="hidl">
+        <name>android.hardware.drm</name>
+        <transport>hwbinder</transport>
+        <fqname>@1.2::ICryptoFactory/clearkey</fqname>
+        <fqname>@1.2::IDrmFactory/clearkey</fqname>
+    </hal>
+</manifest>
diff --git a/include/media/IMediaAnalyticsService.h b/include/media/IMediaAnalyticsService.h
deleted file mode 120000
index a596d60..0000000
--- a/include/media/IMediaAnalyticsService.h
+++ /dev/null
@@ -1 +0,0 @@
-../../media/libmediametrics/include/IMediaAnalyticsService.h
\ No newline at end of file
diff --git a/include/media/IMediaMetricsService.h b/include/media/IMediaMetricsService.h
new file mode 120000
index 0000000..84b99ee
--- /dev/null
+++ b/include/media/IMediaMetricsService.h
@@ -0,0 +1 @@
+../../media/libmediametrics/include/IMediaMetricsService.h
\ No newline at end of file
diff --git a/include/media/MediaAnalyticsItem.h b/include/media/MediaAnalyticsItem.h
deleted file mode 120000
index e8124e0..0000000
--- a/include/media/MediaAnalyticsItem.h
+++ /dev/null
@@ -1 +0,0 @@
-../../media/libmediametrics/include/MediaAnalyticsItem.h
\ No newline at end of file
diff --git a/include/media/MediaMetricsItem.h b/include/media/MediaMetricsItem.h
new file mode 120000
index 0000000..5438953
--- /dev/null
+++ b/include/media/MediaMetricsItem.h
@@ -0,0 +1 @@
+../../media/libmediametrics/include/MediaMetricsItem.h
\ No newline at end of file
diff --git a/include/soundtrigger/ISoundTrigger.h b/include/soundtrigger/ISoundTrigger.h
deleted file mode 100644
index d628c05..0000000
--- a/include/soundtrigger/ISoundTrigger.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#ifndef ANDROID_HARDWARE_ISOUNDTRIGGER_H
-#define ANDROID_HARDWARE_ISOUNDTRIGGER_H
-
-#include <utils/RefBase.h>
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-#include <binder/IMemory.h>
-#include <system/sound_trigger.h>
-
-namespace android {
-
-class ISoundTrigger : public IInterface
-{
-public:
-    DECLARE_META_INTERFACE(SoundTrigger);
-
-    virtual void detach() = 0;
-
-    virtual status_t loadSoundModel(const sp<IMemory>& modelMemory,
-                                    sound_model_handle_t *handle) = 0;
-
-    virtual status_t unloadSoundModel(sound_model_handle_t handle) = 0;
-
-    virtual status_t startRecognition(sound_model_handle_t handle,
-                                      const sp<IMemory>& dataMemory) = 0;
-    virtual status_t stopRecognition(sound_model_handle_t handle) = 0;
-    virtual status_t getModelState(sound_model_handle_t handle) = 0;
-    virtual status_t setParameter(sound_model_handle_t handle,
-            sound_trigger_model_parameter_t param, int32_t value) = 0;
-    virtual status_t getParameter(sound_model_handle_t handle,
-            sound_trigger_model_parameter_t param, int32_t* value) = 0;
-    virtual status_t queryParameter(sound_model_handle_t handle,
-            sound_trigger_model_parameter_t param,
-            sound_trigger_model_parameter_range_t* param_range) = 0;
-};
-
-// ----------------------------------------------------------------------------
-
-class BnSoundTrigger: public BnInterface<ISoundTrigger>
-{
-public:
-    virtual status_t    onTransact( uint32_t code,
-                                    const Parcel& data,
-                                    Parcel* reply,
-                                    uint32_t flags = 0);
-};
-
-}; // namespace android
-
-#endif //ANDROID_HARDWARE_ISOUNDTRIGGER_H
diff --git a/include/soundtrigger/ISoundTriggerClient.h b/include/soundtrigger/ISoundTriggerClient.h
deleted file mode 100644
index 480429a..0000000
--- a/include/soundtrigger/ISoundTriggerClient.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#ifndef ANDROID_HARDWARE_ISOUNDTRIGGER_CLIENT_H
-#define ANDROID_HARDWARE_ISOUNDTRIGGER_CLIENT_H
-
-#include <utils/RefBase.h>
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-
-namespace android {
-
-class ISoundTriggerClient : public IInterface
-{
-public:
-
-    DECLARE_META_INTERFACE(SoundTriggerClient);
-
-    virtual void onRecognitionEvent(const sp<IMemory>& eventMemory) = 0;
-
-    virtual void onSoundModelEvent(const sp<IMemory>& eventMemory) = 0;
-
-    virtual void onServiceStateChange(const sp<IMemory>& eventMemory) = 0;
-
-};
-
-// ----------------------------------------------------------------------------
-
-class BnSoundTriggerClient : public BnInterface<ISoundTriggerClient>
-{
-public:
-    virtual status_t    onTransact( uint32_t code,
-                                    const Parcel& data,
-                                    Parcel* reply,
-                                    uint32_t flags = 0);
-};
-
-}; // namespace android
-
-#endif //ANDROID_HARDWARE_ISOUNDTRIGGER_CLIENT_H
diff --git a/include/soundtrigger/ISoundTriggerHwService.h b/include/soundtrigger/ISoundTriggerHwService.h
deleted file mode 100644
index 1faeb0f..0000000
--- a/include/soundtrigger/ISoundTriggerHwService.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#ifndef ANDROID_HARDWARE_ISOUNDTRIGGER_SERVICE_H
-#define ANDROID_HARDWARE_ISOUNDTRIGGER_SERVICE_H
-
-#include <utils/RefBase.h>
-#include <binder/IInterface.h>
-#include <binder/Parcel.h>
-#include <system/sound_trigger.h>
-
-namespace android {
-
-class ISoundTrigger;
-class ISoundTriggerClient;
-
-class ISoundTriggerHwService : public IInterface
-{
-public:
-
-    DECLARE_META_INTERFACE(SoundTriggerHwService);
-
-    virtual status_t listModules(const String16& opPackageName,
-                                 struct sound_trigger_module_descriptor *modules,
-                                 uint32_t *numModules) = 0;
-
-    virtual status_t attach(const String16& opPackageName,
-                            const sound_trigger_module_handle_t handle,
-                            const sp<ISoundTriggerClient>& client,
-                            sp<ISoundTrigger>& module) = 0;
-
-    virtual status_t setCaptureState(bool active) = 0;
-};
-
-// ----------------------------------------------------------------------------
-
-class BnSoundTriggerHwService: public BnInterface<ISoundTriggerHwService>
-{
-public:
-    virtual status_t    onTransact( uint32_t code,
-                                    const Parcel& data,
-                                    Parcel* reply,
-                                    uint32_t flags = 0);
-};
-
-}; // namespace android
-
-#endif //ANDROID_HARDWARE_ISOUNDTRIGGER_SERVICE_H
diff --git a/include/soundtrigger/OWNERS b/include/soundtrigger/OWNERS
deleted file mode 100644
index e83f6b9..0000000
--- a/include/soundtrigger/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-elaurent@google.com
-thorntonc@google.com
diff --git a/include/soundtrigger/SoundTrigger.h b/include/soundtrigger/SoundTrigger.h
deleted file mode 100644
index 248620a..0000000
--- a/include/soundtrigger/SoundTrigger.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#ifndef ANDROID_HARDWARE_SOUNDTRIGGER_H
-#define ANDROID_HARDWARE_SOUNDTRIGGER_H
-
-#include <binder/IBinder.h>
-#include <utils/threads.h>
-#include <soundtrigger/SoundTriggerCallback.h>
-#include <soundtrigger/ISoundTrigger.h>
-#include <soundtrigger/ISoundTriggerHwService.h>
-#include <soundtrigger/ISoundTriggerClient.h>
-#include <system/sound_trigger.h>
-
-namespace android {
-
-class MemoryDealer;
-
-class SoundTrigger : public BnSoundTriggerClient,
-                        public IBinder::DeathRecipient
-{
-public:
-
-    virtual ~SoundTrigger();
-
-    static  status_t listModules(const String16& opPackageName,
-                                 struct sound_trigger_module_descriptor *modules,
-                                 uint32_t *numModules);
-    static  sp<SoundTrigger> attach(const String16& opPackageName,
-                                    const sound_trigger_module_handle_t module,
-                                    const sp<SoundTriggerCallback>& callback);
-
-    static  status_t setCaptureState(bool active);
-
-            void detach();
-
-            status_t loadSoundModel(const sp<IMemory>& modelMemory,
-                                            sound_model_handle_t *handle);
-
-            status_t unloadSoundModel(sound_model_handle_t handle);
-
-            status_t startRecognition(sound_model_handle_t handle, const sp<IMemory>& dataMemory);
-            status_t stopRecognition(sound_model_handle_t handle);
-            status_t getModelState(sound_model_handle_t handle);
-            status_t setParameter(sound_model_handle_t handle,
-                    sound_trigger_model_parameter_t param, int32_t value);
-            status_t getParameter(sound_model_handle_t handle,
-                    sound_trigger_model_parameter_t param, int32_t* value);
-            status_t queryParameter(sound_model_handle_t handle,
-                    sound_trigger_model_parameter_t param,
-                    sound_trigger_model_parameter_range_t* param_range);
-
-            // BpSoundTriggerClient
-            virtual void onRecognitionEvent(const sp<IMemory>& eventMemory);
-            virtual void onSoundModelEvent(const sp<IMemory>& eventMemory);
-            virtual void onServiceStateChange(const sp<IMemory>& eventMemory);
-
-            //IBinder::DeathRecipient
-            virtual void binderDied(const wp<IBinder>& who);
-
-            static status_t stringToGuid(const char *str, sound_trigger_uuid_t *guid);
-            static status_t guidToString(const sound_trigger_uuid_t *guid,
-                                         char *str, size_t maxLen);
-
-private:
-            SoundTrigger(sound_trigger_module_handle_t module,
-                            const sp<SoundTriggerCallback>&);
-            static const sp<ISoundTriggerHwService> getSoundTriggerHwService();
-
-            Mutex                               mLock;
-            sp<ISoundTrigger>                   mISoundTrigger;
-            sp<SoundTriggerCallback>            mCallback;
-};
-
-}; // namespace android
-
-#endif //ANDROID_HARDWARE_SOUNDTRIGGER_H
diff --git a/include/soundtrigger/SoundTriggerCallback.h b/include/soundtrigger/SoundTriggerCallback.h
deleted file mode 100644
index b5277f2..0000000
--- a/include/soundtrigger/SoundTriggerCallback.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#ifndef ANDROID_HARDWARE_SOUNDTRIGGER_CALLBACK_H
-#define ANDROID_HARDWARE_SOUNDTRIGGER_CALLBACK_H
-
-#include <utils/RefBase.h>
-#include <system/sound_trigger.h>
-
-namespace android {
-
-class SoundTriggerCallback : public RefBase
-{
-public:
-
-            SoundTriggerCallback() {}
-    virtual ~SoundTriggerCallback() {}
-
-    virtual void onRecognitionEvent(struct sound_trigger_recognition_event *event) = 0;
-
-    virtual void onSoundModelEvent(struct sound_trigger_model_event *event) = 0;
-
-    virtual void onServiceStateChange(sound_trigger_service_state_t state) = 0;
-
-    virtual void onServiceDied() = 0;
-
-};
-
-}; // namespace android
-
-#endif //ANDROID_HARDWARE_SOUNDTRIGGER_CALLBACK_H
diff --git a/media/audioserver/Android.mk b/media/audioserver/Android.mk
index e33804d..fcf7cb1 100644
--- a/media/audioserver/Android.mk
+++ b/media/audioserver/Android.mk
@@ -19,7 +19,6 @@
 	libmediautils \
 	libnbaio \
 	libnblog \
-	libsoundtriggerservice \
 	libutils \
 	libvibrator
 
@@ -33,7 +32,6 @@
 	frameworks/av/services/audiopolicy/service \
 	frameworks/av/services/medialog \
 	frameworks/av/services/oboeservice \
-	frameworks/av/services/soundtrigger \
 	frameworks/av/media/libaaudio/include \
 	frameworks/av/media/libaaudio/src \
 	frameworks/av/media/libaaudio/src/binding \
diff --git a/media/audioserver/main_audioserver.cpp b/media/audioserver/main_audioserver.cpp
index db57248..4a2ac1d 100644
--- a/media/audioserver/main_audioserver.cpp
+++ b/media/audioserver/main_audioserver.cpp
@@ -36,7 +36,6 @@
 #include "utility/AAudioUtilities.h"
 #include "MediaLogService.h"
 #include "MediaUtils.h"
-#include "SoundTriggerHwService.h"
 
 using namespace android;
 
@@ -148,7 +147,6 @@
             AAudioService::instantiate();
         }
 
-        SoundTriggerHwService::instantiate();
         ProcessState::self()->startThreadPool();
         IPCThreadState::self()->joinThreadPool();
     }
diff --git a/media/libaudioclient/AudioRecord.cpp b/media/libaudioclient/AudioRecord.cpp
index c22db59..2494313 100644
--- a/media/libaudioclient/AudioRecord.cpp
+++ b/media/libaudioclient/AudioRecord.cpp
@@ -32,7 +32,7 @@
 #include <private/media/AudioTrackShared.h>
 #include <processgroup/sched_policy.h>
 #include <media/IAudioFlinger.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/TypeConverter.h>
 
 #define WAIT_PERIOD_MS          10
@@ -79,37 +79,37 @@
 #define MM_PREFIX "android.media.audiorecord." // avoid cut-n-paste errors.
 
     // Java API 28 entries, do not change.
-    mAnalyticsItem->setCString(MM_PREFIX "encoding", toString(record->mFormat).c_str());
-    mAnalyticsItem->setCString(MM_PREFIX "source", toString(record->mAttributes.source).c_str());
-    mAnalyticsItem->setInt32(MM_PREFIX "latency", (int32_t)record->mLatency); // bad estimate.
-    mAnalyticsItem->setInt32(MM_PREFIX "samplerate", (int32_t)record->mSampleRate);
-    mAnalyticsItem->setInt32(MM_PREFIX "channels", (int32_t)record->mChannelCount);
+    mMetricsItem->setCString(MM_PREFIX "encoding", toString(record->mFormat).c_str());
+    mMetricsItem->setCString(MM_PREFIX "source", toString(record->mAttributes.source).c_str());
+    mMetricsItem->setInt32(MM_PREFIX "latency", (int32_t)record->mLatency); // bad estimate.
+    mMetricsItem->setInt32(MM_PREFIX "samplerate", (int32_t)record->mSampleRate);
+    mMetricsItem->setInt32(MM_PREFIX "channels", (int32_t)record->mChannelCount);
 
     // Non-API entries, these can change.
-    mAnalyticsItem->setInt32(MM_PREFIX "portId", (int32_t)record->mPortId);
-    mAnalyticsItem->setInt32(MM_PREFIX "frameCount", (int32_t)record->mFrameCount);
-    mAnalyticsItem->setCString(MM_PREFIX "attributes", toString(record->mAttributes).c_str());
-    mAnalyticsItem->setInt64(MM_PREFIX "channelMask", (int64_t)record->mChannelMask);
+    mMetricsItem->setInt32(MM_PREFIX "portId", (int32_t)record->mPortId);
+    mMetricsItem->setInt32(MM_PREFIX "frameCount", (int32_t)record->mFrameCount);
+    mMetricsItem->setCString(MM_PREFIX "attributes", toString(record->mAttributes).c_str());
+    mMetricsItem->setInt64(MM_PREFIX "channelMask", (int64_t)record->mChannelMask);
 
     // log total duration recording, including anything currently running.
     int64_t activeNs = 0;
     if (mStartedNs != 0) {
         activeNs = systemTime() - mStartedNs;
     }
-    mAnalyticsItem->setDouble(MM_PREFIX "durationMs", (mDurationNs + activeNs) * 1e-6);
-    mAnalyticsItem->setInt64(MM_PREFIX "startCount", (int64_t)mCount);
+    mMetricsItem->setDouble(MM_PREFIX "durationMs", (mDurationNs + activeNs) * 1e-6);
+    mMetricsItem->setInt64(MM_PREFIX "startCount", (int64_t)mCount);
 
     if (mLastError != NO_ERROR) {
-        mAnalyticsItem->setInt32(MM_PREFIX "lastError.code", (int32_t)mLastError);
-        mAnalyticsItem->setCString(MM_PREFIX "lastError.at", mLastErrorFunc.c_str());
+        mMetricsItem->setInt32(MM_PREFIX "lastError.code", (int32_t)mLastError);
+        mMetricsItem->setCString(MM_PREFIX "lastError.at", mLastErrorFunc.c_str());
     }
 }
 
 // hand the user a snapshot of the metrics.
-status_t AudioRecord::getMetrics(MediaAnalyticsItem * &item)
+status_t AudioRecord::getMetrics(mediametrics::Item * &item)
 {
     mMediaMetrics.gather(this);
-    MediaAnalyticsItem *tmp = mMediaMetrics.dup();
+    mediametrics::Item *tmp = mMediaMetrics.dup();
     if (tmp == nullptr) {
         return BAD_VALUE;
     }
diff --git a/media/libaudioclient/AudioTrack.cpp b/media/libaudioclient/AudioTrack.cpp
index e8d7b60..3151feb 100644
--- a/media/libaudioclient/AudioTrack.cpp
+++ b/media/libaudioclient/AudioTrack.cpp
@@ -35,7 +35,7 @@
 #include <media/AudioParameter.h>
 #include <media/AudioResamplerPublic.h>
 #include <media/AudioSystem.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/TypeConverter.h>
 
 #define WAIT_PERIOD_MS                  10
@@ -183,26 +183,26 @@
 #define MM_PREFIX "android.media.audiotrack." // avoid cut-n-paste errors.
 
     // Java API 28 entries, do not change.
-    mAnalyticsItem->setCString(MM_PREFIX "streamtype", toString(track->streamType()).c_str());
-    mAnalyticsItem->setCString(MM_PREFIX "type",
+    mMetricsItem->setCString(MM_PREFIX "streamtype", toString(track->streamType()).c_str());
+    mMetricsItem->setCString(MM_PREFIX "type",
             toString(track->mAttributes.content_type).c_str());
-    mAnalyticsItem->setCString(MM_PREFIX "usage", toString(track->mAttributes.usage).c_str());
+    mMetricsItem->setCString(MM_PREFIX "usage", toString(track->mAttributes.usage).c_str());
 
     // Non-API entries, these can change due to a Java string mistake.
-    mAnalyticsItem->setInt32(MM_PREFIX "sampleRate", (int32_t)track->mSampleRate);
-    mAnalyticsItem->setInt64(MM_PREFIX "channelMask", (int64_t)track->mChannelMask);
+    mMetricsItem->setInt32(MM_PREFIX "sampleRate", (int32_t)track->mSampleRate);
+    mMetricsItem->setInt64(MM_PREFIX "channelMask", (int64_t)track->mChannelMask);
     // Non-API entries, these can change.
-    mAnalyticsItem->setInt32(MM_PREFIX "portId", (int32_t)track->mPortId);
-    mAnalyticsItem->setCString(MM_PREFIX "encoding", toString(track->mFormat).c_str());
-    mAnalyticsItem->setInt32(MM_PREFIX "frameCount", (int32_t)track->mFrameCount);
-    mAnalyticsItem->setCString(MM_PREFIX "attributes", toString(track->mAttributes).c_str());
+    mMetricsItem->setInt32(MM_PREFIX "portId", (int32_t)track->mPortId);
+    mMetricsItem->setCString(MM_PREFIX "encoding", toString(track->mFormat).c_str());
+    mMetricsItem->setInt32(MM_PREFIX "frameCount", (int32_t)track->mFrameCount);
+    mMetricsItem->setCString(MM_PREFIX "attributes", toString(track->mAttributes).c_str());
 }
 
 // hand the user a snapshot of the metrics.
-status_t AudioTrack::getMetrics(MediaAnalyticsItem * &item)
+status_t AudioTrack::getMetrics(mediametrics::Item * &item)
 {
     mMediaMetrics.gather(this);
-    MediaAnalyticsItem *tmp = mMediaMetrics.dup();
+    mediametrics::Item *tmp = mMediaMetrics.dup();
     if (tmp == nullptr) {
         return BAD_VALUE;
     }
diff --git a/media/libaudioclient/IAudioPolicyService.cpp b/media/libaudioclient/IAudioPolicyService.cpp
index ab942df..b9e6e33 100644
--- a/media/libaudioclient/IAudioPolicyService.cpp
+++ b/media/libaudioclient/IAudioPolicyService.cpp
@@ -1371,8 +1371,6 @@
         case UNREGISTER_EFFECT:
         case SET_EFFECT_ENABLED:
         case GET_OUTPUT_FOR_ATTR:
-        case ACQUIRE_SOUNDTRIGGER_SESSION:
-        case RELEASE_SOUNDTRIGGER_SESSION:
         case MOVE_EFFECTS_TO_IO:
             ALOGW("%s: transaction %d received from PID %d",
                   __func__, code, IPCThreadState::self()->getCallingPid());
@@ -1410,6 +1408,8 @@
         case GET_OFFLOAD_FORMATS_A2DP:
         case LIST_AUDIO_VOLUME_GROUPS:
         case GET_VOLUME_GROUP_FOR_ATTRIBUTES:
+        case ACQUIRE_SOUNDTRIGGER_SESSION:
+        case RELEASE_SOUNDTRIGGER_SESSION:
         case SET_RTT_ENABLED:
         case IS_CALL_SCREEN_MODE_SUPPORTED:
         case SET_PREFERRED_DEVICE_FOR_PRODUCT_STRATEGY:
@@ -2027,8 +2027,6 @@
 
         case ACQUIRE_SOUNDTRIGGER_SESSION: {
             CHECK_INTERFACE(IAudioPolicyService, data, reply);
-            sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
-                    data.readStrongBinder());
             audio_session_t session = AUDIO_SESSION_NONE;
             audio_io_handle_t ioHandle = AUDIO_IO_HANDLE_NONE;
             audio_devices_t device = AUDIO_DEVICE_NONE;
@@ -2044,8 +2042,6 @@
 
         case RELEASE_SOUNDTRIGGER_SESSION: {
             CHECK_INTERFACE(IAudioPolicyService, data, reply);
-            sp<IAudioPolicyServiceClient> client = interface_cast<IAudioPolicyServiceClient>(
-                    data.readStrongBinder());
             audio_session_t session = (audio_session_t)data.readInt32();
             status_t status = releaseSoundTriggerSession(session);
             reply->writeInt32(status);
diff --git a/media/libaudioclient/include/media/AudioRecord.h b/media/libaudioclient/include/media/AudioRecord.h
index a3c0fe4..db90e6a 100644
--- a/media/libaudioclient/include/media/AudioRecord.h
+++ b/media/libaudioclient/include/media/AudioRecord.h
@@ -24,7 +24,7 @@
 #include <cutils/sched_policy.h>
 #include <media/AudioSystem.h>
 #include <media/AudioTimestamp.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/Modulo.h>
 #include <media/MicrophoneInfo.h>
 #include <media/RecordingActivityTracker.h>
@@ -270,7 +270,7 @@
     /*
      * return metrics information for the current instance.
      */
-            status_t getMetrics(MediaAnalyticsItem * &item);
+            status_t getMetrics(mediametrics::Item * &item);
 
     /* After it's created the track is not active. Call start() to
      * make it active. If set, the callback will start being called.
@@ -733,27 +733,27 @@
 private:
     class MediaMetrics {
       public:
-        MediaMetrics() : mAnalyticsItem(MediaAnalyticsItem::create("audiorecord")),
+        MediaMetrics() : mMetricsItem(mediametrics::Item::create("audiorecord")),
                          mCreatedNs(systemTime(SYSTEM_TIME_REALTIME)),
                          mStartedNs(0), mDurationNs(0), mCount(0),
                          mLastError(NO_ERROR) {
         }
         ~MediaMetrics() {
-            // mAnalyticsItem alloc failure will be flagged in the constructor
+            // mMetricsItem alloc failure will be flagged in the constructor
             // don't log empty records
-            if (mAnalyticsItem->count() > 0) {
-                mAnalyticsItem->selfrecord();
+            if (mMetricsItem->count() > 0) {
+                mMetricsItem->selfrecord();
             }
         }
         void gather(const AudioRecord *record);
-        MediaAnalyticsItem *dup() { return mAnalyticsItem->dup(); }
+        mediametrics::Item *dup() { return mMetricsItem->dup(); }
 
         void logStart(nsecs_t when) { mStartedNs = when; mCount++; }
         void logStop(nsecs_t when) { mDurationNs += (when-mStartedNs); mStartedNs = 0;}
         void markError(status_t errcode, const char *func)
                  { mLastError = errcode; mLastErrorFunc = func;}
       private:
-        std::unique_ptr<MediaAnalyticsItem> mAnalyticsItem;
+        std::unique_ptr<mediametrics::Item> mMetricsItem;
         nsecs_t mCreatedNs;     // XXX: perhaps not worth it in production
         nsecs_t mStartedNs;
         nsecs_t mDurationNs;
diff --git a/media/libaudioclient/include/media/AudioTrack.h b/media/libaudioclient/include/media/AudioTrack.h
index df5eabc..cfbce03 100644
--- a/media/libaudioclient/include/media/AudioTrack.h
+++ b/media/libaudioclient/include/media/AudioTrack.h
@@ -22,7 +22,7 @@
 #include <media/AudioTimestamp.h>
 #include <media/IAudioTrack.h>
 #include <media/AudioResamplerPublic.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/Modulo.h>
 #include <utils/threads.h>
 
@@ -400,7 +400,7 @@
     /*
      * return metrics information for the current track.
      */
-            status_t getMetrics(MediaAnalyticsItem * &item);
+            status_t getMetrics(mediametrics::Item * &item);
 
     /* After it's created the track is not active. Call start() to
      * make it active. If set, the callback will start being called.
@@ -1230,19 +1230,19 @@
 private:
     class MediaMetrics {
       public:
-        MediaMetrics() : mAnalyticsItem(MediaAnalyticsItem::create("audiotrack")) {
+        MediaMetrics() : mMetricsItem(mediametrics::Item::create("audiotrack")) {
         }
         ~MediaMetrics() {
-            // mAnalyticsItem alloc failure will be flagged in the constructor
+            // mMetricsItem alloc failure will be flagged in the constructor
             // don't log empty records
-            if (mAnalyticsItem->count() > 0) {
-                mAnalyticsItem->selfrecord();
+            if (mMetricsItem->count() > 0) {
+                mMetricsItem->selfrecord();
             }
         }
         void gather(const AudioTrack *track);
-        MediaAnalyticsItem *dup() { return mAnalyticsItem->dup(); }
+        mediametrics::Item *dup() { return mMetricsItem->dup(); }
       private:
-        std::unique_ptr<MediaAnalyticsItem> mAnalyticsItem;
+        std::unique_ptr<mediametrics::Item> mMetricsItem;
     };
     MediaMetrics mMediaMetrics;
 };
diff --git a/media/libaudiohal/impl/DeviceHalHidl.cpp b/media/libaudiohal/impl/DeviceHalHidl.cpp
index cd3ac1f..342ceb6 100644
--- a/media/libaudiohal/impl/DeviceHalHidl.cpp
+++ b/media/libaudiohal/impl/DeviceHalHidl.cpp
@@ -323,25 +323,45 @@
     if (mDevice == 0) return NO_INIT;
     if (patch == nullptr) return BAD_VALUE;
 
+#if MAJOR_VERSION < 6
     if (*patch != AUDIO_PATCH_HANDLE_NONE) {
         status_t status = releaseAudioPatch(*patch);
         ALOGW_IF(status != NO_ERROR, "%s error %d releasing patch handle %d",
             __func__, status, *patch);
+        *patch = AUDIO_PATCH_HANDLE_NONE;
     }
+#endif
 
     hidl_vec<AudioPortConfig> hidlSources, hidlSinks;
     HidlUtils::audioPortConfigsFromHal(num_sources, sources, &hidlSources);
     HidlUtils::audioPortConfigsFromHal(num_sinks, sinks, &hidlSinks);
-    Result retval;
-    Return<void> ret = mDevice->createAudioPatch(
-            hidlSources, hidlSinks,
-            [&](Result r, AudioPatchHandle hidlPatch) {
-                retval = r;
-                if (retval == Result::OK) {
-                    *patch = static_cast<audio_patch_handle_t>(hidlPatch);
-                }
-            });
-    return processReturn("createAudioPatch", ret, retval);
+    Result retval = Result::OK;
+    Return<void> ret;
+    std::string methodName = "createAudioPatch";
+    if (*patch == AUDIO_PATCH_HANDLE_NONE) {  // always true for MAJOR_VERSION < 6
+        ret = mDevice->createAudioPatch(
+                hidlSources, hidlSinks,
+                [&](Result r, AudioPatchHandle hidlPatch) {
+                    retval = r;
+                    if (retval == Result::OK) {
+                        *patch = static_cast<audio_patch_handle_t>(hidlPatch);
+                    }
+                });
+    } else {
+#if MAJOR_VERSION >= 6
+        ret = mDevice->updateAudioPatch(
+                *patch,
+                hidlSources, hidlSinks,
+                [&](Result r, AudioPatchHandle hidlPatch) {
+                    retval = r;
+                    if (retval == Result::OK) {
+                        *patch = static_cast<audio_patch_handle_t>(hidlPatch);
+                    }
+                });
+        methodName = "updateAudioPatch";
+#endif
+    }
+    return processReturn(methodName.c_str(), ret, retval);
 }
 
 status_t DeviceHalHidl::releaseAudioPatch(audio_patch_handle_t patch) {
diff --git a/media/libmedia/include/media/CounterMetric.h b/media/libmedia/include/media/CounterMetric.h
index b53470d..8bd4049 100644
--- a/media/libmedia/include/media/CounterMetric.h
+++ b/media/libmedia/include/media/CounterMetric.h
@@ -20,7 +20,7 @@
 #include <map>
 #include <string>
 
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <utils/Log.h>
 
 namespace android {
diff --git a/media/libmedia/include/media/EventMetric.h b/media/libmedia/include/media/EventMetric.h
index dbb736a..d6f3402 100644
--- a/media/libmedia/include/media/EventMetric.h
+++ b/media/libmedia/include/media/EventMetric.h
@@ -16,7 +16,7 @@
 #ifndef ANDROID_EVENT_METRIC_H_
 #define ANDROID_EVENT_METRIC_H_
 
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <utils/Timers.h>
 
 namespace android {
diff --git a/media/libmediametrics/Android.bp b/media/libmediametrics/Android.bp
index f599190..7fd5408 100644
--- a/media/libmediametrics/Android.bp
+++ b/media/libmediametrics/Android.bp
@@ -2,8 +2,8 @@
     name: "libmediametrics",
 
     srcs: [
-        "IMediaAnalyticsService.cpp",
-        "MediaAnalyticsItem.cpp",
+        "IMediaMetricsService.cpp",
+        "MediaMetricsItem.cpp",
         "MediaMetrics.cpp",
     ],
 
diff --git a/media/libmediametrics/IMediaAnalyticsService.cpp b/media/libmediametrics/IMediaMetricsService.cpp
similarity index 80%
rename from media/libmediametrics/IMediaAnalyticsService.cpp
rename to media/libmediametrics/IMediaMetricsService.cpp
index 534aece..b5675e6 100644
--- a/media/libmediametrics/IMediaAnalyticsService.cpp
+++ b/media/libmediametrics/IMediaMetricsService.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#define LOG_TAG "MediaAnalytics"
+#define LOG_TAG "MediaMetrics"
 
 #include <stdint.h>
 #include <inttypes.h>
@@ -29,8 +29,8 @@
 #include <utils/Log.h>
 #include <utils/String8.h>
 
-#include <media/MediaAnalyticsItem.h>
-#include <media/IMediaAnalyticsService.h>
+#include <media/MediaMetricsItem.h>
+#include <media/IMediaMetricsService.h>
 
 namespace android {
 
@@ -41,15 +41,15 @@
     SUBMIT_BUFFER,
 };
 
-class BpMediaAnalyticsService: public BpInterface<IMediaAnalyticsService>
+class BpMediaMetricsService: public BpInterface<IMediaMetricsService>
 {
 public:
-    explicit BpMediaAnalyticsService(const sp<IBinder>& impl)
-        : BpInterface<IMediaAnalyticsService>(impl)
+    explicit BpMediaMetricsService(const sp<IBinder>& impl)
+        : BpInterface<IMediaMetricsService>(impl)
     {
     }
 
-    status_t submit(MediaAnalyticsItem *item) override
+    status_t submit(mediametrics::Item *item) override
     {
         if (item == nullptr) {
             return BAD_VALUE;
@@ -57,7 +57,7 @@
         ALOGV("%s: (ONEWAY) item=%s", __func__, item->toString().c_str());
 
         Parcel data;
-        data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor());
+        data.writeInterfaceToken(IMediaMetricsService::getInterfaceDescriptor());
 
         status_t status = item->writeToParcel(&data);
         if (status != NO_ERROR) { // assume failure logged in item
@@ -79,7 +79,7 @@
         ALOGV("%s: (ONEWAY) length:%zu", __func__, length);
 
         Parcel data;
-        data.writeInterfaceToken(IMediaAnalyticsService::getInterfaceDescriptor());
+        data.writeInterfaceToken(IMediaMetricsService::getInterfaceDescriptor());
 
         status_t status = data.writeInt32(length)
                 ?: data.write((uint8_t*)buffer, length);
@@ -95,18 +95,18 @@
     }
 };
 
-IMPLEMENT_META_INTERFACE(MediaAnalyticsService, "android.media.IMediaAnalyticsService");
+IMPLEMENT_META_INTERFACE(MediaMetricsService, "android.media.IMediaMetricsService");
 
 // ----------------------------------------------------------------------
 
-status_t BnMediaAnalyticsService::onTransact(
+status_t BnMediaMetricsService::onTransact(
     uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
 {
     switch (code) {
     case SUBMIT_ITEM: {
-        CHECK_INTERFACE(IMediaAnalyticsService, data, reply);
+        CHECK_INTERFACE(IMediaMetricsService, data, reply);
 
-        MediaAnalyticsItem * const item = MediaAnalyticsItem::create();
+        mediametrics::Item * const item = mediametrics::Item::create();
         status_t status = item->readFromParcel(data);
         if (status != NO_ERROR) { // assume failure logged in item
             return status;
@@ -116,7 +116,7 @@
         return NO_ERROR;
     }
     case SUBMIT_BUFFER: {
-        CHECK_INTERFACE(IMediaAnalyticsService, data, reply);
+        CHECK_INTERFACE(IMediaMetricsService, data, reply);
         int32_t length;
         status_t status = data.readInt32(&length);
         if (status != NO_ERROR || length <= 0) {
diff --git a/media/libmediametrics/MediaMetrics.cpp b/media/libmediametrics/MediaMetrics.cpp
index cf268e0..a3c2f1a 100644
--- a/media/libmediametrics/MediaMetrics.cpp
+++ b/media/libmediametrics/MediaMetrics.cpp
@@ -21,7 +21,7 @@
 #include <string.h>
 #include <sys/types.h>
 
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/MediaMetrics.h>
 
 //
@@ -31,28 +31,31 @@
 // ALL functions returning a char * give responsibility for the allocated buffer
 // to the caller. The caller is responsible to call free() on that pointer.
 //
+//
+
+using namespace android::mediametrics;
 
 // manage the overall record
 mediametrics_handle_t mediametrics_create(mediametricskey_t key) {
-    android::MediaAnalyticsItem *item = android::MediaAnalyticsItem::create(key);
+    Item *item = Item::create(key);
     return (mediametrics_handle_t) item;
 }
 
 void mediametrics_delete(mediametrics_handle_t handle) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return;
     delete item;
 }
 
 mediametricskey_t mediametrics_getKey(mediametrics_handle_t handle) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return NULL;
     return strdup(item->getKey().c_str());
 }
 
 // nuplayer, et al use it when acting as proxies
 void mediametrics_setUid(mediametrics_handle_t handle, uid_t uid) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->setUid(uid);
 }
 
@@ -61,31 +64,31 @@
 
 void mediametrics_setInt32(mediametrics_handle_t handle, attr_t attr,
                                 int32_t value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->setInt32(attr, value);
 }
 
 void mediametrics_setInt64(mediametrics_handle_t handle, attr_t attr,
                                 int64_t value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->setInt64(attr, value);
 }
 
 void mediametrics_setDouble(mediametrics_handle_t handle, attr_t attr,
                                  double value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->setDouble(attr, value);
 }
 
 void mediametrics_setRate(mediametrics_handle_t handle, attr_t attr,
                                int64_t count, int64_t duration) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->setRate(attr, count, duration);
 }
 
 void mediametrics_setCString(mediametrics_handle_t handle, attr_t attr,
                                  const char *value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->setCString(attr, value);
 }
 
@@ -94,25 +97,25 @@
 
 void mediametrics_addInt32(mediametrics_handle_t handle, attr_t attr,
                                 int32_t value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->addInt32(attr, value);
 }
 
 void mediametrics_addInt64(mediametrics_handle_t handle, attr_t attr,
                                 int64_t value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->addInt64(attr, value);
 }
 
 void mediametrics_addDouble(mediametrics_handle_t handle, attr_t attr,
                                  double value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->addDouble(attr, value);
 }
 
 void mediametrics_addRate(mediametrics_handle_t handle, attr_t attr,
                                int64_t count, int64_t duration) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item != NULL) item->addRate(attr, count, duration);
 }
 
@@ -123,28 +126,28 @@
 
 bool mediametrics_getInt32(mediametrics_handle_t handle, attr_t attr,
                                 int32_t * value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return false;
     return item->getInt32(attr, value);
 }
 
 bool mediametrics_getInt64(mediametrics_handle_t handle, attr_t attr,
                                 int64_t * value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return false;
     return item->getInt64(attr, value);
 }
 
 bool mediametrics_getDouble(mediametrics_handle_t handle, attr_t attr,
                                  double *value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return false;
     return item->getDouble(attr, value);
 }
 
 bool mediametrics_getRate(mediametrics_handle_t handle, attr_t attr,
                                int64_t * count, int64_t * duration, double *rate) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return false;
     return item->getRate(attr, count, duration, rate);
 }
@@ -152,7 +155,7 @@
 // NB: caller owns the string that comes back, is responsible for freeing it
 bool mediametrics_getCString(mediametrics_handle_t handle, attr_t attr,
                                  char **value) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return false;
 
     return item->getCString(attr, value);
@@ -164,36 +167,36 @@
 }
 
 bool mediametrics_selfRecord(mediametrics_handle_t handle) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return false;
     return item->selfrecord();
 }
 
 mediametrics_handle_t mediametrics_dup(mediametrics_handle_t handle) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
-    if (item == NULL) return android::MediaAnalyticsItem::convert(item);
-    return android::MediaAnalyticsItem::convert(item->dup());
+    Item *item = (Item *) handle;
+    if (item == NULL) return Item::convert(item);
+    return Item::convert(item->dup());
 }
 
 const char *mediametrics_readable(mediametrics_handle_t handle) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return "";
     return item->toCString();
 }
 
 int32_t mediametrics_count(mediametrics_handle_t handle) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return 0;
     return item->count();
 }
 
 bool mediametrics_isEnabled() {
     // static, so doesn't need an instance
-    return android::MediaAnalyticsItem::isEnabled();
+    return Item::isEnabled();
 }
 
 bool mediametrics_getAttributes(mediametrics_handle_t handle, char **buffer, size_t *length) {
-    android::MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+    Item *item = (Item *) handle;
     if (item == NULL) return false;
     return item->writeToByteString(buffer, length) == android::NO_ERROR;
 
diff --git a/media/libmediametrics/MediaAnalyticsItem.cpp b/media/libmediametrics/MediaMetricsItem.cpp
similarity index 87%
rename from media/libmediametrics/MediaAnalyticsItem.cpp
rename to media/libmediametrics/MediaMetricsItem.cpp
index 8025e49..98158d2 100644
--- a/media/libmediametrics/MediaAnalyticsItem.cpp
+++ b/media/libmediametrics/MediaMetricsItem.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#define LOG_TAG "MediaAnalyticsItem"
+#define LOG_TAG "mediametrics::Item"
 
 #include <inttypes.h>
 #include <stdlib.h>
@@ -31,15 +31,15 @@
 #include <utils/threads.h>
 
 #include <binder/IServiceManager.h>
-#include <media/IMediaAnalyticsService.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/IMediaMetricsService.h>
+#include <media/MediaMetricsItem.h>
 #include <private/android_filesystem_config.h>
 
 // Max per-property string size before truncation in toString().
 // Do not make too large, as this is used for dumpsys purposes.
 static constexpr size_t kMaxPropertyStringSize = 4096;
 
-namespace android {
+namespace android::mediametrics {
 
 #define DEBUG_SERVICEACCESS     0
 #define DEBUG_API               0
@@ -49,24 +49,24 @@
 // the service is off.
 #define SVC_TRIES               2
 
-MediaAnalyticsItem* MediaAnalyticsItem::convert(mediametrics_handle_t handle) {
-    MediaAnalyticsItem *item = (android::MediaAnalyticsItem *) handle;
+mediametrics::Item* mediametrics::Item::convert(mediametrics_handle_t handle) {
+    mediametrics::Item *item = (android::mediametrics::Item *) handle;
     return item;
 }
 
-mediametrics_handle_t MediaAnalyticsItem::convert(MediaAnalyticsItem *item ) {
+mediametrics_handle_t mediametrics::Item::convert(mediametrics::Item *item ) {
     mediametrics_handle_t handle = (mediametrics_handle_t) item;
     return handle;
 }
 
-MediaAnalyticsItem::~MediaAnalyticsItem() {
+mediametrics::Item::~Item() {
     if (DEBUG_ALLOCATIONS) {
-        ALOGD("Destroy  MediaAnalyticsItem @ %p", this);
+        ALOGD("Destroy  mediametrics::Item @ %p", this);
     }
     clear();
 }
 
-void MediaAnalyticsItem::clear() {
+void mediametrics::Item::clear() {
 
     // clean allocated storage from key
     mKey.clear();
@@ -88,8 +88,8 @@
 }
 
 // make a deep copy of myself
-MediaAnalyticsItem *MediaAnalyticsItem::dup() {
-    MediaAnalyticsItem *dst = new MediaAnalyticsItem(this->mKey);
+mediametrics::Item *mediametrics::Item::dup() {
+    mediametrics::Item *dst = new mediametrics::Item(this->mKey);
 
     if (dst != NULL) {
         // key as part of constructor
@@ -110,50 +110,50 @@
     return dst;
 }
 
-MediaAnalyticsItem &MediaAnalyticsItem::setTimestamp(nsecs_t ts) {
+mediametrics::Item &mediametrics::Item::setTimestamp(nsecs_t ts) {
     mTimestamp = ts;
     return *this;
 }
 
-nsecs_t MediaAnalyticsItem::getTimestamp() const {
+nsecs_t mediametrics::Item::getTimestamp() const {
     return mTimestamp;
 }
 
-MediaAnalyticsItem &MediaAnalyticsItem::setPid(pid_t pid) {
+mediametrics::Item &mediametrics::Item::setPid(pid_t pid) {
     mPid = pid;
     return *this;
 }
 
-pid_t MediaAnalyticsItem::getPid() const {
+pid_t mediametrics::Item::getPid() const {
     return mPid;
 }
 
-MediaAnalyticsItem &MediaAnalyticsItem::setUid(uid_t uid) {
+mediametrics::Item &mediametrics::Item::setUid(uid_t uid) {
     mUid = uid;
     return *this;
 }
 
-uid_t MediaAnalyticsItem::getUid() const {
+uid_t mediametrics::Item::getUid() const {
     return mUid;
 }
 
-MediaAnalyticsItem &MediaAnalyticsItem::setPkgName(const std::string &pkgName) {
+mediametrics::Item &mediametrics::Item::setPkgName(const std::string &pkgName) {
     mPkgName = pkgName;
     return *this;
 }
 
-MediaAnalyticsItem &MediaAnalyticsItem::setPkgVersionCode(int64_t pkgVersionCode) {
+mediametrics::Item &mediametrics::Item::setPkgVersionCode(int64_t pkgVersionCode) {
     mPkgVersionCode = pkgVersionCode;
     return *this;
 }
 
-int64_t MediaAnalyticsItem::getPkgVersionCode() const {
+int64_t mediametrics::Item::getPkgVersionCode() const {
     return mPkgVersionCode;
 }
 
 
 // find the proper entry in the list
-size_t MediaAnalyticsItem::findPropIndex(const char *name) const
+size_t mediametrics::Item::findPropIndex(const char *name) const
 {
     size_t i = 0;
     for (; i < mPropCount; i++) {
@@ -162,7 +162,7 @@
     return i;
 }
 
-MediaAnalyticsItem::Prop *MediaAnalyticsItem::findProp(const char *name) const {
+mediametrics::Item::Prop *mediametrics::Item::findProp(const char *name) const {
     const size_t i = findPropIndex(name);
     if (i < mPropCount) {
         return &mProps[i];
@@ -172,7 +172,7 @@
 
 // consider this "find-or-allocate".
 // caller validates type and uses clearPropValue() accordingly
-MediaAnalyticsItem::Prop *MediaAnalyticsItem::allocateProp(const char *name) {
+mediametrics::Item::Prop *mediametrics::Item::allocateProp(const char *name) {
     const size_t i = findPropIndex(name);
     if (i < mPropCount) {
         return &mProps[i]; // already have it, return
@@ -184,7 +184,7 @@
     return prop;
 }
 
-MediaAnalyticsItem::Prop *MediaAnalyticsItem::allocateProp() {
+mediametrics::Item::Prop *mediametrics::Item::allocateProp() {
     if (mPropCount == mPropSize && growProps() == false) {
         ALOGE("%s: failed allocation for new properties", __func__);
         return nullptr;
@@ -193,7 +193,7 @@
 }
 
 // used within the summarizers; return whether property existed
-bool MediaAnalyticsItem::removeProp(const char *name) {
+bool mediametrics::Item::removeProp(const char *name) {
     const size_t i = findPropIndex(name);
     if (i < mPropCount) {
         mProps[i].clear();
@@ -209,7 +209,7 @@
 
 // remove indicated keys and their values
 // return value is # keys removed
-size_t MediaAnalyticsItem::filter(size_t n, const char *attrs[]) {
+size_t mediametrics::Item::filter(size_t n, const char *attrs[]) {
     size_t zapped = 0;
     for (size_t i = 0; i < n; ++i) {
         const char *name = attrs[i];
@@ -235,7 +235,7 @@
 
 // remove any keys NOT in the provided list
 // return value is # keys removed
-size_t MediaAnalyticsItem::filterNot(size_t n, const char *attrs[]) {
+size_t mediametrics::Item::filterNot(size_t n, const char *attrs[]) {
     std::set<std::string> check(attrs, attrs + n);
     size_t zapped = 0;
     for (size_t j = 0; j < mPropCount;) {
@@ -260,7 +260,7 @@
     return zapped;
 }
 
-bool MediaAnalyticsItem::growProps(int increment)
+bool mediametrics::Item::growProps(int increment)
 {
     if (increment <= 0) {
         increment = kGrowProps;
@@ -276,7 +276,7 @@
         mPropSize = nsize;
         return true;
     } else {
-        ALOGW("MediaAnalyticsItem::growProps fails");
+        ALOGW("mediametrics::Item::growProps fails");
         return false;
     }
 }
@@ -284,7 +284,7 @@
 // Parcel / serialize things for binder calls
 //
 
-status_t MediaAnalyticsItem::readFromParcel(const Parcel& data) {
+status_t mediametrics::Item::readFromParcel(const Parcel& data) {
     int32_t version;
     status_t status = data.readInt32(&version);
     if (status != NO_ERROR) return status;
@@ -298,7 +298,7 @@
     }
 }
 
-status_t MediaAnalyticsItem::readFromParcel0(const Parcel& data) {
+status_t mediametrics::Item::readFromParcel0(const Parcel& data) {
     const char *s = data.readCString();
     mKey = s == nullptr ? "" : s;
     int32_t pid, uid;
@@ -323,7 +323,7 @@
     return NO_ERROR;
 }
 
-status_t MediaAnalyticsItem::writeToParcel(Parcel *data) const {
+status_t mediametrics::Item::writeToParcel(Parcel *data) const {
     if (data == nullptr) return BAD_VALUE;
 
     const int32_t version = 0;
@@ -339,7 +339,7 @@
     }
 }
 
-status_t MediaAnalyticsItem::writeToParcel0(Parcel *data) const {
+status_t mediametrics::Item::writeToParcel0(Parcel *data) const {
     status_t status =
         data->writeCString(mKey.c_str())
         ?: data->writeInt32(mPid)
@@ -357,20 +357,20 @@
     return NO_ERROR;
 }
 
-const char *MediaAnalyticsItem::toCString() {
+const char *mediametrics::Item::toCString() {
    return toCString(PROTO_LAST);
 }
 
-const char * MediaAnalyticsItem::toCString(int version) {
+const char * mediametrics::Item::toCString(int version) {
     std::string val = toString(version);
     return strdup(val.c_str());
 }
 
-std::string MediaAnalyticsItem::toString() const {
+std::string mediametrics::Item::toString() const {
    return toString(PROTO_LAST);
 }
 
-std::string MediaAnalyticsItem::toString(int version) const {
+std::string mediametrics::Item::toString(int version) const {
     std::string result;
     char buffer[kMaxPropertyStringSize];
 
@@ -388,9 +388,9 @@
 
 // for the lazy, we offer methods that finds the service and
 // calls the appropriate daemon
-bool MediaAnalyticsItem::selfrecord() {
+bool mediametrics::Item::selfrecord() {
     ALOGD_IF(DEBUG_API, "%s: delivering %s", __func__, this->toString().c_str());
-    sp<IMediaAnalyticsService> svc = getInstance();
+    sp<IMediaMetricsService> svc = getInstance();
     if (svc != NULL) {
         status_t status = svc->submit(this);
         if (status != NO_ERROR) {
@@ -403,7 +403,6 @@
     }
 }
 
-namespace mediametrics {
 //static
 bool BaseItem::isEnabled() {
     // completely skip logging from certain UIDs. We do this here
@@ -420,12 +419,12 @@
         return false;
     }
 
-    int enabled = property_get_int32(MediaAnalyticsItem::EnabledProperty, -1);
+    int enabled = property_get_int32(Item::EnabledProperty, -1);
     if (enabled == -1) {
-        enabled = property_get_int32(MediaAnalyticsItem::EnabledPropertyPersist, -1);
+        enabled = property_get_int32(Item::EnabledPropertyPersist, -1);
     }
     if (enabled == -1) {
-        enabled = MediaAnalyticsItem::EnabledProperty_default;
+        enabled = Item::EnabledProperty_default;
     }
     return enabled > 0;
 }
@@ -440,7 +439,7 @@
 
 static sp<MediaMetricsDeathNotifier> sNotifier;
 // static
-sp<IMediaAnalyticsService> BaseItem::sAnalyticsService;
+sp<IMediaMetricsService> BaseItem::sMediaMetricsService;
 static std::mutex sServiceMutex;
 static int sRemainingBindAttempts = SVC_TRIES;
 
@@ -448,20 +447,20 @@
 void BaseItem::dropInstance() {
     std::lock_guard  _l(sServiceMutex);
     sRemainingBindAttempts = SVC_TRIES;
-    sAnalyticsService = nullptr;
+    sMediaMetricsService = nullptr;
 }
 
 // static
 bool BaseItem::submitBuffer(const char *buffer, size_t size) {
 /*
-    MediaAnalyticsItem item;
+    mediametrics::Item item;
     status_t status = item.readFromByteString(buffer, size);
     ALOGD("%s: status:%d, size:%zu, item:%s", __func__, status, size, item.toString().c_str());
     return item.selfrecord();
     */
 
     ALOGD_IF(DEBUG_API, "%s: delivering %zu bytes", __func__, size);
-    sp<IMediaAnalyticsService> svc = getInstance();
+    sp<IMediaMetricsService> svc = getInstance();
     if (svc != nullptr) {
         const status_t status = svc->submitBuffer(buffer, size);
         if (status != NO_ERROR) {
@@ -474,7 +473,7 @@
 }
 
 //static
-sp<IMediaAnalyticsService> BaseItem::getInstance() {
+sp<IMediaMetricsService> BaseItem::getInstance() {
     static const char *servicename = "media.metrics";
     static const bool enabled = isEnabled(); // singleton initialized
 
@@ -486,13 +485,13 @@
     // think of remainingBindAttempts as telling us whether service == nullptr because
     // (1) we haven't tried to initialize it yet
     // (2) we've tried to initialize it, but failed.
-    if (sAnalyticsService == nullptr && sRemainingBindAttempts > 0) {
+    if (sMediaMetricsService == nullptr && sRemainingBindAttempts > 0) {
         const char *badness = "";
         sp<IServiceManager> sm = defaultServiceManager();
         if (sm != nullptr) {
             sp<IBinder> binder = sm->getService(String16(servicename));
             if (binder != nullptr) {
-                sAnalyticsService = interface_cast<IMediaAnalyticsService>(binder);
+                sMediaMetricsService = interface_cast<IMediaMetricsService>(binder);
                 sNotifier = new MediaMetricsDeathNotifier();
                 binder->linkToDeath(sNotifier);
             } else {
@@ -501,7 +500,7 @@
         } else {
             badness = "No Service Manager access";
         }
-        if (sAnalyticsService == nullptr) {
+        if (sMediaMetricsService == nullptr) {
             if (sRemainingBindAttempts > 0) {
                 sRemainingBindAttempts--;
             }
@@ -509,14 +508,13 @@
                     __func__, servicename, badness);
         }
     }
-    return sAnalyticsService;
+    return sMediaMetricsService;
 }
 
-} // namespace mediametrics
 
 // merge the info from 'incoming' into this record.
 // we finish with a union of this+incoming and special handling for collisions
-bool MediaAnalyticsItem::merge(MediaAnalyticsItem *incoming) {
+bool mediametrics::Item::merge(mediametrics::Item *incoming) {
 
     // if I don't have key or session id, take them from incoming
     // 'this' should never be missing both of them...
@@ -623,7 +621,7 @@
 
 } // namespace
 
-status_t MediaAnalyticsItem::writeToByteString(char **pbuffer, size_t *plength) const
+status_t mediametrics::Item::writeToByteString(char **pbuffer, size_t *plength) const
 {
     if (pbuffer == nullptr || plength == nullptr)
         return BAD_VALUE;
@@ -701,7 +699,7 @@
     return NO_ERROR;
 }
 
-status_t MediaAnalyticsItem::readFromByteString(const char *bufferptr, size_t length)
+status_t mediametrics::Item::readFromByteString(const char *bufferptr, size_t length)
 {
     if (bufferptr == nullptr) return BAD_VALUE;
 
@@ -761,7 +759,7 @@
     return NO_ERROR;
 }
 
-status_t MediaAnalyticsItem::Prop::writeToParcel(Parcel *data) const
+status_t mediametrics::Item::Prop::writeToParcel(Parcel *data) const
 {
    switch (mType) {
    case kTypeInt32:
@@ -791,7 +789,7 @@
    }
 }
 
-status_t MediaAnalyticsItem::Prop::readFromParcel(const Parcel& data)
+status_t mediametrics::Item::Prop::readFromParcel(const Parcel& data)
 {
     const char *key = data.readCString();
     if (key == nullptr) return BAD_VALUE;
@@ -834,23 +832,23 @@
     return status;
 }
 
-void MediaAnalyticsItem::Prop::toString(char *buffer, size_t length) const
+void mediametrics::Item::Prop::toString(char *buffer, size_t length) const
 {
     switch (mType) {
     case kTypeInt32:
         snprintf(buffer, length, "%s=%d:", mName, u.int32Value);
         break;
-    case MediaAnalyticsItem::kTypeInt64:
+    case mediametrics::Item::kTypeInt64:
         snprintf(buffer, length, "%s=%lld:", mName, (long long)u.int64Value);
         break;
-    case MediaAnalyticsItem::kTypeDouble:
+    case mediametrics::Item::kTypeDouble:
         snprintf(buffer, length, "%s=%e:", mName, u.doubleValue);
         break;
-    case MediaAnalyticsItem::kTypeRate:
+    case mediametrics::Item::kTypeRate:
         snprintf(buffer, length, "%s=%lld/%lld:",
                 mName, (long long)u.rate.first, (long long)u.rate.second);
         break;
-    case MediaAnalyticsItem::kTypeCString:
+    case mediametrics::Item::kTypeCString:
         // TODO sanitize string for ':' '='
         snprintf(buffer, length, "%s=%s:", mName, u.CStringValue);
         break;
@@ -861,7 +859,7 @@
     }
 }
 
-size_t MediaAnalyticsItem::Prop::getByteStringSize() const
+size_t mediametrics::Item::Prop::getByteStringSize() const
 {
     const size_t header =
         sizeof(uint16_t)      // length
@@ -869,19 +867,19 @@
         + strlen(mName) + 1;  // mName + 0 termination
     size_t payload = 0;
     switch (mType) {
-    case MediaAnalyticsItem::kTypeInt32:
+    case mediametrics::Item::kTypeInt32:
         payload = sizeof(u.int32Value);
         break;
-    case MediaAnalyticsItem::kTypeInt64:
+    case mediametrics::Item::kTypeInt64:
         payload = sizeof(u.int64Value);
         break;
-    case MediaAnalyticsItem::kTypeDouble:
+    case mediametrics::Item::kTypeDouble:
         payload = sizeof(u.doubleValue);
         break;
-    case MediaAnalyticsItem::kTypeRate:
+    case mediametrics::Item::kTypeRate:
         payload = sizeof(u.rate.first) + sizeof(u.rate.second);
         break;
-    case MediaAnalyticsItem::kTypeCString:
+    case mediametrics::Item::kTypeCString:
         payload = strlen(u.CStringValue) + 1;
         break;
     default:
@@ -892,7 +890,6 @@
     return header + payload;
 }
 
-namespace mediametrics {
 
 // TODO: fold into a template later.
 status_t BaseItem::writeToByteString(
@@ -968,9 +965,8 @@
             ?: insert(name, bufferpptr, bufferptrmax);
 }
 
-} // namespace mediametrics
 
-status_t MediaAnalyticsItem::Prop::writeToByteString(
+status_t mediametrics::Item::Prop::writeToByteString(
         char **bufferpptr, char *bufferptrmax) const
 {
     switch (mType) {
@@ -993,7 +989,7 @@
     }
 }
 
-status_t MediaAnalyticsItem::Prop::readFromByteString(
+status_t mediametrics::Item::Prop::readFromByteString(
         const char **bufferpptr, const char *bufferptrmax)
 {
     uint16_t len;
@@ -1036,4 +1032,4 @@
     }
 }
 
-} // namespace android
+} // namespace android::mediametrics
diff --git a/media/libmediametrics/include/IMediaAnalyticsService.h b/media/libmediametrics/include/IMediaMetricsService.h
similarity index 83%
rename from media/libmediametrics/include/IMediaAnalyticsService.h
rename to media/libmediametrics/include/IMediaMetricsService.h
index 30c63e7..d6871ec 100644
--- a/media/libmediametrics/include/IMediaAnalyticsService.h
+++ b/media/libmediametrics/include/IMediaMetricsService.h
@@ -29,15 +29,14 @@
 
 #include <binder/IServiceManager.h>
 
-#include <media/MediaAnalyticsItem.h>
-// nope...#include <media/MediaAnalytics.h>
+#include <media/MediaMetricsItem.h>
 
 namespace android {
 
-class IMediaAnalyticsService: public IInterface
+class IMediaMetricsService: public IInterface
 {
 public:
-    DECLARE_META_INTERFACE(MediaAnalyticsService);
+    DECLARE_META_INTERFACE(MediaMetricsService);
 
     /**
      * Submits the indicated record to the mediaanalytics service, where
@@ -48,14 +47,14 @@
      * \return status which is negative if an error is detected (some errors
                may be silent and return 0 - success).
      */
-    virtual status_t submit(MediaAnalyticsItem *item) = 0;
+    virtual status_t submit(mediametrics::Item *item) = 0;
 
     virtual status_t submitBuffer(const char *buffer, size_t length) = 0;
 };
 
 // ----------------------------------------------------------------------------
 
-class BnMediaAnalyticsService: public BnInterface<IMediaAnalyticsService>
+class BnMediaMetricsService: public BnInterface<IMediaMetricsService>
 {
 public:
     status_t onTransact(uint32_t code,
@@ -66,7 +65,7 @@
 protected:
     // Internal call where release is true if the service is to delete the item.
     virtual status_t submitInternal(
-            MediaAnalyticsItem *item, bool release) = 0;
+            mediametrics::Item *item, bool release) = 0;
 };
 
 }; // namespace android
diff --git a/media/libmediametrics/include/MediaAnalyticsItem.h b/media/libmediametrics/include/MediaMetricsItem.h
similarity index 90%
rename from media/libmediametrics/include/MediaAnalyticsItem.h
rename to media/libmediametrics/include/MediaMetricsItem.h
index bff7c9b..5f33650 100644
--- a/media/libmediametrics/include/MediaAnalyticsItem.h
+++ b/media/libmediametrics/include/MediaMetricsItem.h
@@ -32,7 +32,7 @@
 
 namespace android {
 
-class IMediaAnalyticsService;
+class IMediaMetricsService;
 class Parcel;
 
 /*
@@ -115,8 +115,8 @@
     static const int EnabledProperty_default = 1;
 
     // let's reuse a binder connection
-    static sp<IMediaAnalyticsService> sAnalyticsService;
-    static sp<IMediaAnalyticsService> getInstance();
+    static sp<IMediaMetricsService> sMediaMetricsService;
+    static sp<IMediaMetricsService> getInstance();
     static void dropInstance();
     static bool submitBuffer(const char *buffer, size_t len);
 
@@ -329,26 +329,26 @@
 };
 
 /**
- * MediaMetrics Item is a stack allocated media analytics item used for
+ * MediaMetrics LogItem is a stack allocated media analytics item used for
  * fast logging.  It falls over to a malloc if needed.
  *
  * This is templated with a buffer size to allocate on the stack.
  */
 template <size_t N = 4096>
-class Item : public BufferedItem {
+class LogItem : public BufferedItem {
 public:
-    explicit Item(const std::string key) : Item(key.c_str()) { }
+    explicit LogItem(const std::string key) : LogItem(key.c_str()) { }
 
     // Since this class will not be defined before the base class, we initialize variables
     // in our own order.
-    explicit Item(const char *key) {
+    explicit LogItem(const char *key) {
          mBegin = mBuffer;
          mEnd = mBuffer + N;
          mBaseRealloc = &mReallocPtr;
          init(key);
     }
 
-    ~Item() override {
+    ~LogItem() override {
         if (mReallocPtr != nullptr) { // do the check before calling free to avoid overhead.
             free(mReallocPtr);
         }
@@ -359,18 +359,17 @@
     char mBuffer[N];
 };
 
-} // mediametrics
 
 /**
- * Media Metrics MediaAnalyticsItem
+ * Media Metrics Item
  *
  * A mutable item representing an event or record that will be
  * logged with the Media Metrics service.  For client logging, one should
  * use the mediametrics::Item.
  *
- * The MediaAnalyticsItem is designed for the service as it has getters.
+ * The Item is designed for the service as it has getters.
  */
-class MediaAnalyticsItem : public mediametrics::BaseItem {
+class Item : public mediametrics::BaseItem {
     friend class MediaMetricsJNI;           // TODO: remove this access
 
 public:
@@ -397,14 +396,14 @@
 
     // T must be convertible to mKey
     template <typename T>
-    explicit MediaAnalyticsItem(T key)
+    explicit Item(T key)
         : mKey(key) { }
-    MediaAnalyticsItem() = default;
+    Item() = default;
 
-    MediaAnalyticsItem(const MediaAnalyticsItem&) = delete;
-    MediaAnalyticsItem &operator=(const MediaAnalyticsItem&) = delete;
+    Item(const Item&) = delete;
+    Item &operator=(const Item&) = delete;
 
-    bool operator==(const MediaAnalyticsItem& other) const {
+    bool operator==(const Item& other) const {
         if (mPropCount != other.mPropCount
             || mPid != other.mPid
             || mUid != other.mUid
@@ -418,29 +417,29 @@
          }
          return true;
     }
-    bool operator!=(const MediaAnalyticsItem& other) const {
+    bool operator!=(const Item& other) const {
         return !(*this == other);
     }
 
     template <typename T>
-    static MediaAnalyticsItem* create(T key) {
-        return new MediaAnalyticsItem(key);
+    static Item* create(T key) {
+        return new Item(key);
     }
-    static MediaAnalyticsItem* create() {
-        return new MediaAnalyticsItem();
+    static Item* create() {
+        return new Item();
     }
 
-        static MediaAnalyticsItem* convert(mediametrics_handle_t);
-        static mediametrics_handle_t convert(MediaAnalyticsItem *);
+        static Item* convert(mediametrics_handle_t);
+        static mediametrics_handle_t convert(Item *);
 
         // access functions for the class
-        ~MediaAnalyticsItem();
+        ~Item();
 
         // reset all contents, discarding any extra data
         void clear();
-        MediaAnalyticsItem *dup();
+        Item *dup();
 
-    MediaAnalyticsItem &setKey(const char *key) {
+    Item &setKey(const char *key) {
         mKey = key;
         return *this;
     }
@@ -450,46 +449,46 @@
     size_t count() const { return mPropCount; }
 
     template<typename S, typename T>
-    MediaAnalyticsItem &set(S key, T value) {
+    Item &set(S key, T value) {
         allocateProp(key)->set(value);
         return *this;
     }
 
     // set values appropriately
-    MediaAnalyticsItem &setInt32(const char *key, int32_t value) {
+    Item &setInt32(const char *key, int32_t value) {
         return set(key, value);
     }
-    MediaAnalyticsItem &setInt64(const char *key, int64_t value) {
+    Item &setInt64(const char *key, int64_t value) {
         return set(key, value);
     }
-    MediaAnalyticsItem &setDouble(const char *key, double value) {
+    Item &setDouble(const char *key, double value) {
         return set(key, value);
     }
-    MediaAnalyticsItem &setRate(const char *key, int64_t count, int64_t duration) {
+    Item &setRate(const char *key, int64_t count, int64_t duration) {
         return set(key, std::make_pair(count, duration));
     }
-    MediaAnalyticsItem &setCString(const char *key, const char *value) {
+    Item &setCString(const char *key, const char *value) {
         return set(key, value);
     }
 
     // fused get/add/set; if attr wasn't there, it's a simple set.
     // type-mismatch counts as "wasn't there".
     template<typename S, typename T>
-    MediaAnalyticsItem &add(S key, T value) {
+    Item &add(S key, T value) {
         allocateProp(key)->add(value);
         return *this;
     }
 
-    MediaAnalyticsItem &addInt32(const char *key, int32_t value) {
+    Item &addInt32(const char *key, int32_t value) {
         return add(key, value);
     }
-    MediaAnalyticsItem &addInt64(const char *key, int64_t value) {
+    Item &addInt64(const char *key, int64_t value) {
         return add(key, value);
     }
-    MediaAnalyticsItem &addDouble(const char *key, double value) {
+    Item &addDouble(const char *key, double value) {
         return add(key, value);
     }
-    MediaAnalyticsItem &addRate(const char *key, int64_t count, int64_t duration) {
+    Item &addRate(const char *key, int64_t count, int64_t duration) {
         return add(key, std::make_pair(count, duration));
     }
 
@@ -555,19 +554,19 @@
 
         // timestamp, pid, and uid only used on server side
         // timestamp is in 'nanoseconds, unix time'
-        MediaAnalyticsItem &setTimestamp(nsecs_t);
+        Item &setTimestamp(nsecs_t);
         nsecs_t getTimestamp() const;
 
-        MediaAnalyticsItem &setPid(pid_t);
+        Item &setPid(pid_t);
         pid_t getPid() const;
 
-        MediaAnalyticsItem &setUid(uid_t);
+        Item &setUid(uid_t);
         uid_t getUid() const;
 
-        MediaAnalyticsItem &setPkgName(const std::string &pkgName);
+        Item &setPkgName(const std::string &pkgName);
         std::string getPkgName() const { return mPkgName; }
 
-        MediaAnalyticsItem &setPkgVersionCode(int64_t);
+        Item &setPkgVersionCode(int64_t);
         int64_t getPkgVersionCode() const;
 
     // our serialization code for binder calls
@@ -589,7 +588,7 @@
         // with rules for first/last/add, etc
         // XXX: document semantics and how they are indicated
         // caller continues to own 'incoming'
-        bool merge(MediaAnalyticsItem *incoming);
+        bool merge(Item *incoming);
 
 private:
     // handle Parcel version 0
@@ -712,19 +711,19 @@
 
         template <typename T> void visit(T f) const {
             switch (mType) {
-            case MediaAnalyticsItem::kTypeInt32:
+            case Item::kTypeInt32:
                 f(u.int32Value);
                 return;
-            case MediaAnalyticsItem::kTypeInt64:
+            case Item::kTypeInt64:
                 f(u.int64Value);
                 return;
-            case MediaAnalyticsItem::kTypeDouble:
+            case Item::kTypeDouble:
                 f(u.doubleValue);
                 return;
-            case MediaAnalyticsItem::kTypeRate:
+            case Item::kTypeRate:
                 f(u.rate);
                 return;
-            case MediaAnalyticsItem::kTypeCString:
+            case Item::kTypeCString:
                 f(u.CStringValue);
                 return;
             default:
@@ -885,7 +884,7 @@
 
     class iterator {
     public:
-       iterator(size_t pos, const MediaAnalyticsItem &_item)
+       iterator(size_t pos, const Item &_item)
            : i(std::min(pos, _item.count()))
            , item(_item) { }
        iterator &operator++() {
@@ -901,7 +900,7 @@
 
     private:
       size_t i;
-      const MediaAnalyticsItem &item;
+      const Item &item;
     };
 
     iterator begin() const {
@@ -938,6 +937,7 @@
     nsecs_t       mTimestamp = 0;
 };
 
+} // namespace mediametrics
 } // namespace android
 
 #endif
diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp
index d36c6e3..001dccf 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.cpp
+++ b/media/libmediaplayerservice/StagefrightRecorder.cpp
@@ -31,7 +31,7 @@
 #include <binder/IServiceManager.h>
 
 #include <media/IMediaPlayerService.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/stagefright/foundation/ABuffer.h>
 #include <media/stagefright/foundation/ADebug.h>
 #include <media/stagefright/foundation/AMessage.h>
@@ -138,7 +138,7 @@
     }
 
     // log the current record, provided it has some information worth recording
-    // NB: this also reclaims & clears mAnalyticsItem.
+    // NB: this also reclaims & clears mMetricsItem.
     flushAndResetMetrics(false);
 }
 
@@ -147,69 +147,69 @@
 
     // we run as part of the media player service; what we really want to
     // know is the app which requested the recording.
-    mAnalyticsItem->setUid(mClientUid);
+    mMetricsItem->setUid(mClientUid);
 
     // populate the values from the raw fields.
 
     // TBD mOutputFormat  = OUTPUT_FORMAT_THREE_GPP;
     // TBD mAudioEncoder  = AUDIO_ENCODER_AMR_NB;
     // TBD mVideoEncoder  = VIDEO_ENCODER_DEFAULT;
-    mAnalyticsItem->setInt32(kRecorderHeight, mVideoHeight);
-    mAnalyticsItem->setInt32(kRecorderWidth, mVideoWidth);
-    mAnalyticsItem->setInt32(kRecorderFrameRate, mFrameRate);
-    mAnalyticsItem->setInt32(kRecorderVideoBitrate, mVideoBitRate);
-    mAnalyticsItem->setInt32(kRecorderAudioSampleRate, mSampleRate);
-    mAnalyticsItem->setInt32(kRecorderAudioChannels, mAudioChannels);
-    mAnalyticsItem->setInt32(kRecorderAudioBitrate, mAudioBitRate);
+    mMetricsItem->setInt32(kRecorderHeight, mVideoHeight);
+    mMetricsItem->setInt32(kRecorderWidth, mVideoWidth);
+    mMetricsItem->setInt32(kRecorderFrameRate, mFrameRate);
+    mMetricsItem->setInt32(kRecorderVideoBitrate, mVideoBitRate);
+    mMetricsItem->setInt32(kRecorderAudioSampleRate, mSampleRate);
+    mMetricsItem->setInt32(kRecorderAudioChannels, mAudioChannels);
+    mMetricsItem->setInt32(kRecorderAudioBitrate, mAudioBitRate);
     // TBD mInterleaveDurationUs = 0;
-    mAnalyticsItem->setInt32(kRecorderVideoIframeInterval, mIFramesIntervalSec);
+    mMetricsItem->setInt32(kRecorderVideoIframeInterval, mIFramesIntervalSec);
     // TBD mAudioSourceNode = 0;
     // TBD mUse64BitFileOffset = false;
     if (mMovieTimeScale != -1)
-        mAnalyticsItem->setInt32(kRecorderMovieTimescale, mMovieTimeScale);
+        mMetricsItem->setInt32(kRecorderMovieTimescale, mMovieTimeScale);
     if (mAudioTimeScale != -1)
-        mAnalyticsItem->setInt32(kRecorderAudioTimescale, mAudioTimeScale);
+        mMetricsItem->setInt32(kRecorderAudioTimescale, mAudioTimeScale);
     if (mVideoTimeScale != -1)
-        mAnalyticsItem->setInt32(kRecorderVideoTimescale, mVideoTimeScale);
+        mMetricsItem->setInt32(kRecorderVideoTimescale, mVideoTimeScale);
     // TBD mCameraId        = 0;
     // TBD mStartTimeOffsetMs = -1;
-    mAnalyticsItem->setInt32(kRecorderVideoProfile, mVideoEncoderProfile);
-    mAnalyticsItem->setInt32(kRecorderVideoLevel, mVideoEncoderLevel);
+    mMetricsItem->setInt32(kRecorderVideoProfile, mVideoEncoderProfile);
+    mMetricsItem->setInt32(kRecorderVideoLevel, mVideoEncoderLevel);
     // TBD mMaxFileDurationUs = 0;
     // TBD mMaxFileSizeBytes = 0;
     // TBD mTrackEveryTimeDurationUs = 0;
-    mAnalyticsItem->setInt32(kRecorderCaptureFpsEnable, mCaptureFpsEnable);
-    mAnalyticsItem->setDouble(kRecorderCaptureFps, mCaptureFps);
+    mMetricsItem->setInt32(kRecorderCaptureFpsEnable, mCaptureFpsEnable);
+    mMetricsItem->setDouble(kRecorderCaptureFps, mCaptureFps);
     // TBD mCameraSourceTimeLapse = NULL;
     // TBD mMetaDataStoredInVideoBuffers = kMetadataBufferTypeInvalid;
     // TBD mEncoderProfiles = MediaProfiles::getInstance();
-    mAnalyticsItem->setInt32(kRecorderRotation, mRotationDegrees);
+    mMetricsItem->setInt32(kRecorderRotation, mRotationDegrees);
     // PII mLatitudex10000 = -3600000;
     // PII mLongitudex10000 = -3600000;
     // TBD mTotalBitRate = 0;
 
     // duration information (recorded, paused, # of pauses)
-    mAnalyticsItem->setInt64(kRecorderDurationMs, (mDurationRecordedUs+500)/1000 );
+    mMetricsItem->setInt64(kRecorderDurationMs, (mDurationRecordedUs+500)/1000 );
     if (mNPauses != 0) {
-        mAnalyticsItem->setInt64(kRecorderPaused, (mDurationPausedUs+500)/1000 );
-        mAnalyticsItem->setInt32(kRecorderNumPauses, mNPauses);
+        mMetricsItem->setInt64(kRecorderPaused, (mDurationPausedUs+500)/1000 );
+        mMetricsItem->setInt32(kRecorderNumPauses, mNPauses);
     }
 }
 
 void StagefrightRecorder::flushAndResetMetrics(bool reinitialize) {
     ALOGV("flushAndResetMetrics");
     // flush anything we have, maybe setup a new record
-    if (mAnalyticsDirty && mAnalyticsItem != NULL) {
+    if (mAnalyticsDirty && mMetricsItem != NULL) {
         updateMetrics();
-        if (mAnalyticsItem->count() > 0) {
-            mAnalyticsItem->selfrecord();
+        if (mMetricsItem->count() > 0) {
+            mMetricsItem->selfrecord();
         }
-        delete mAnalyticsItem;
-        mAnalyticsItem = NULL;
+        delete mMetricsItem;
+        mMetricsItem = NULL;
     }
     mAnalyticsDirty = false;
     if (reinitialize) {
-        mAnalyticsItem = MediaAnalyticsItem::create(kKeyRecorder);
+        mMetricsItem = mediametrics::Item::create(kKeyRecorder);
     }
 }
 
@@ -1184,10 +1184,10 @@
     }
 
     // log audio mime type for media metrics
-    if (mAnalyticsItem != NULL) {
+    if (mMetricsItem != NULL) {
         AString audiomime;
         if (format->findString("mime", &audiomime)) {
-            mAnalyticsItem->setCString(kRecorderAudioMime, audiomime.c_str());
+            mMetricsItem->setCString(kRecorderAudioMime, audiomime.c_str());
         }
     }
 
@@ -1745,10 +1745,10 @@
     }
 
     // log video mime type for media metrics
-    if (mAnalyticsItem != NULL) {
+    if (mMetricsItem != NULL) {
         AString videomime;
         if (format->findString("mime", &videomime)) {
-            mAnalyticsItem->setCString(kRecorderVideoMime, videomime.c_str());
+            mMetricsItem->setCString(kRecorderVideoMime, videomime.c_str());
         }
     }
 
@@ -2266,12 +2266,12 @@
         return BAD_VALUE;
     }
 
-    if (mAnalyticsItem == NULL) {
+    if (mMetricsItem == NULL) {
         return UNKNOWN_ERROR;
     }
 
     updateMetrics();
-    mAnalyticsItem->writeToParcel(reply);
+    mMetricsItem->writeToParcel(reply);
     return OK;
 }
 
diff --git a/media/libmediaplayerservice/StagefrightRecorder.h b/media/libmediaplayerservice/StagefrightRecorder.h
index 9e0f4b7..a725bee 100644
--- a/media/libmediaplayerservice/StagefrightRecorder.h
+++ b/media/libmediaplayerservice/StagefrightRecorder.h
@@ -18,7 +18,7 @@
 
 #define STAGEFRIGHT_RECORDER_H_
 
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/MediaRecorderBase.h>
 #include <camera/CameraParameters.h>
 #include <utils/String8.h>
@@ -104,7 +104,7 @@
     int mOutputFd;
     sp<AudioSource> mAudioSourceNode;
 
-    MediaAnalyticsItem *mAnalyticsItem;
+    mediametrics::Item *mMetricsItem;
     bool mAnalyticsDirty;
     void flushAndResetMetrics(bool reinitialize);
     void updateMetrics();
diff --git a/media/libmediaplayerservice/nuplayer/GenericSource.cpp b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
index a49e72e..4657f9e 100644
--- a/media/libmediaplayerservice/nuplayer/GenericSource.cpp
+++ b/media/libmediaplayerservice/nuplayer/GenericSource.cpp
@@ -418,7 +418,7 @@
                     sp<IMediaExtractorService> mediaExService(
                             interface_cast<IMediaExtractorService>(binder));
                     sp<IDataSource> source;
-                    mediaExService->makeIDataSource(mFd, mOffset, mLength, &source);
+                    mediaExService->makeIDataSource(base::unique_fd(dup(mFd.get())), mOffset, mLength, &source);
                     ALOGV("IDataSource(FileSource): %p %d %lld %lld",
                             source.get(), mFd.get(), (long long)mOffset, (long long)mLength);
                     if (source.get() != nullptr) {
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
index 4d9872a..24afd43 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.cpp
@@ -35,8 +35,6 @@
 #include <media/stagefright/Utils.h>
 #include <media/stagefright/FoundationUtils.h>
 
-#include <media/IMediaAnalyticsService.h>
-
 static const int kDumpLockRetries = 50;
 static const int kDumpLockSleepUs = 20000;
 
@@ -87,7 +85,7 @@
       mMediaClock(new MediaClock),
       mPlayer(new NuPlayer(pid, mMediaClock)),
       mPlayerFlags(0),
-      mAnalyticsItem(NULL),
+      mMetricsItem(NULL),
       mClientUid(-1),
       mAtEOS(false),
       mLooping(false),
@@ -98,7 +96,7 @@
     mMediaClock->init();
 
     // set up an analytics record
-    mAnalyticsItem = MediaAnalyticsItem::create(kKeyPlayer);
+    mMetricsItem = mediametrics::Item::create(kKeyPlayer);
 
     mLooper->start(
             false, /* runOnCallingThread */
@@ -118,9 +116,9 @@
     updateMetrics("destructor");
     logMetrics("destructor");
 
-    if (mAnalyticsItem != NULL) {
-        delete mAnalyticsItem;
-        mAnalyticsItem = NULL;
+    if (mMetricsItem != NULL) {
+        delete mMetricsItem;
+        mMetricsItem = NULL;
     }
 }
 
@@ -131,8 +129,8 @@
 status_t NuPlayerDriver::setUID(uid_t uid) {
     mPlayer->setUID(uid);
     mClientUid = uid;
-    if (mAnalyticsItem) {
-        mAnalyticsItem->setUid(mClientUid);
+    if (mMetricsItem) {
+        mMetricsItem->setUid(mClientUid);
     }
 
     return OK;
@@ -560,15 +558,15 @@
 
             if (mime.startsWith("video/")) {
                 int32_t width, height;
-                mAnalyticsItem->setCString(kPlayerVMime, mime.c_str());
+                mMetricsItem->setCString(kPlayerVMime, mime.c_str());
                 if (!name.empty()) {
-                    mAnalyticsItem->setCString(kPlayerVCodec, name.c_str());
+                    mMetricsItem->setCString(kPlayerVCodec, name.c_str());
                 }
 
                 if (stats->findInt32("width", &width)
                         && stats->findInt32("height", &height)) {
-                    mAnalyticsItem->setInt32(kPlayerWidth, width);
-                    mAnalyticsItem->setInt32(kPlayerHeight, height);
+                    mMetricsItem->setInt32(kPlayerWidth, width);
+                    mMetricsItem->setInt32(kPlayerHeight, height);
                 }
 
                 int64_t numFramesTotal = 0;
@@ -576,18 +574,18 @@
                 stats->findInt64("frames-total", &numFramesTotal);
                 stats->findInt64("frames-dropped-output", &numFramesDropped);
 
-                mAnalyticsItem->setInt64(kPlayerFrames, numFramesTotal);
-                mAnalyticsItem->setInt64(kPlayerFramesDropped, numFramesDropped);
+                mMetricsItem->setInt64(kPlayerFrames, numFramesTotal);
+                mMetricsItem->setInt64(kPlayerFramesDropped, numFramesDropped);
 
                 float frameRate = 0;
                 if (stats->findFloat("frame-rate-total", &frameRate)) {
-                    mAnalyticsItem->setDouble(kPlayerFrameRate, (double) frameRate);
+                    mMetricsItem->setDouble(kPlayerFrameRate, (double) frameRate);
                 }
 
             } else if (mime.startsWith("audio/")) {
-                mAnalyticsItem->setCString(kPlayerAMime, mime.c_str());
+                mMetricsItem->setCString(kPlayerAMime, mime.c_str());
                 if (!name.empty()) {
-                    mAnalyticsItem->setCString(kPlayerACodec, name.c_str());
+                    mMetricsItem->setCString(kPlayerACodec, name.c_str());
                 }
             }
         }
@@ -598,20 +596,20 @@
     // getDuration() uses mLock for mutex -- careful where we use it.
     int duration_ms = -1;
     getDuration(&duration_ms);
-    mAnalyticsItem->setInt64(kPlayerDuration, duration_ms);
+    mMetricsItem->setInt64(kPlayerDuration, duration_ms);
 
     mPlayer->updateInternalTimers();
 
-    mAnalyticsItem->setInt64(kPlayerPlaying, (mPlayingTimeUs+500)/1000 );
+    mMetricsItem->setInt64(kPlayerPlaying, (mPlayingTimeUs+500)/1000 );
 
     if (mRebufferingEvents != 0) {
-        mAnalyticsItem->setInt64(kPlayerRebuffering, (mRebufferingTimeUs+500)/1000 );
-        mAnalyticsItem->setInt32(kPlayerRebufferingCount, mRebufferingEvents);
-        mAnalyticsItem->setInt32(kPlayerRebufferingAtExit, mRebufferingAtExit);
+        mMetricsItem->setInt64(kPlayerRebuffering, (mRebufferingTimeUs+500)/1000 );
+        mMetricsItem->setInt32(kPlayerRebufferingCount, mRebufferingEvents);
+        mMetricsItem->setInt32(kPlayerRebufferingAtExit, mRebufferingAtExit);
 
     }
 
-    mAnalyticsItem->setCString(kPlayerDataSourceType, mPlayer->getDataSourceType());
+    mMetricsItem->setCString(kPlayerDataSourceType, mPlayer->getDataSourceType());
 }
 
 
@@ -621,7 +619,7 @@
     }
     ALOGV("logMetrics(%p) from %s at state %d", this, where, mState);
 
-    if (mAnalyticsItem == NULL || mAnalyticsItem->isEnabled() == false) {
+    if (mMetricsItem == NULL || mMetricsItem->isEnabled() == false) {
         return;
     }
 
@@ -630,18 +628,18 @@
     // and that always injects 3 fields (duration, playing time, and
     // datasource) into the record.
     // So the canonical "empty" record has 3 elements in it.
-    if (mAnalyticsItem->count() > 3) {
+    if (mMetricsItem->count() > 3) {
 
-        mAnalyticsItem->selfrecord();
+        mMetricsItem->selfrecord();
 
         // re-init in case we prepare() and start() again.
-        delete mAnalyticsItem ;
-        mAnalyticsItem = MediaAnalyticsItem::create(kKeyPlayer);
-        if (mAnalyticsItem) {
-            mAnalyticsItem->setUid(mClientUid);
+        delete mMetricsItem ;
+        mMetricsItem = mediametrics::Item::create(kKeyPlayer);
+        if (mMetricsItem) {
+            mMetricsItem->setUid(mClientUid);
         }
     } else {
-        ALOGV("nothing to record (only %zu fields)", mAnalyticsItem->count());
+        ALOGV("nothing to record (only %zu fields)", mMetricsItem->count());
     }
 }
 
@@ -779,11 +777,11 @@
 
 status_t NuPlayerDriver::getParameter(int key, Parcel *reply) {
 
-    if (key == FOURCC('m','t','r','X') && mAnalyticsItem != NULL) {
+    if (key == FOURCC('m','t','r','X') && mMetricsItem != NULL) {
         // mtrX -- a play on 'metrics' (not matrix)
         // gather current info all together, parcel it, and send it back
         updateMetrics("api");
-        mAnalyticsItem->writeToParcel(reply);
+        mMetricsItem->writeToParcel(reply);
         return OK;
     }
 
@@ -1007,12 +1005,12 @@
             // when we have an error, add it to the analytics for this playback.
             // ext1 is our primary 'error type' value. Only add ext2 when non-zero.
             // [test against msg is due to fall through from previous switch value]
-            if (msg == MEDIA_ERROR && mAnalyticsItem != NULL) {
-                mAnalyticsItem->setInt32(kPlayerError, ext1);
+            if (msg == MEDIA_ERROR && mMetricsItem != NULL) {
+                mMetricsItem->setInt32(kPlayerError, ext1);
                 if (ext2 != 0) {
-                    mAnalyticsItem->setInt32(kPlayerErrorCode, ext2);
+                    mMetricsItem->setInt32(kPlayerErrorCode, ext2);
                 }
-                mAnalyticsItem->setCString(kPlayerErrorState, stateString(mState).c_str());
+                mMetricsItem->setCString(kPlayerErrorState, stateString(mState).c_str());
             }
             mAtEOS = true;
             break;
diff --git a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h
index ad878f8..7001f4a 100644
--- a/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h
+++ b/media/libmediaplayerservice/nuplayer/NuPlayerDriver.h
@@ -16,7 +16,7 @@
 
 #include <media/MediaPlayerInterface.h>
 
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/stagefright/foundation/ABase.h>
 
 namespace android {
@@ -141,7 +141,7 @@
     sp<AudioSink> mAudioSink;
     uint32_t mPlayerFlags;
 
-    MediaAnalyticsItem *mAnalyticsItem;
+    mediametrics::Item *mMetricsItem;
     uid_t mClientUid;
 
     bool mAtEOS;
diff --git a/media/libnblog/ReportPerformance.cpp b/media/libnblog/ReportPerformance.cpp
index b050b83..aa678ba 100644
--- a/media/libnblog/ReportPerformance.cpp
+++ b/media/libnblog/ReportPerformance.cpp
@@ -30,7 +30,7 @@
 #include <sys/time.h>
 #include <utility>
 #include <json/json.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/nblog/Events.h>
 #include <media/nblog/PerformanceAnalysis.h>
 #include <media/nblog/ReportPerformance.h>
@@ -168,7 +168,7 @@
         return false;
     }
 
-    std::unique_ptr<MediaAnalyticsItem> item(MediaAnalyticsItem::create("audiothread"));
+    std::unique_ptr<mediametrics::Item> item(mediametrics::Item::create("audiothread"));
 
     const Histogram &workHist = data.workHist;
     if (workHist.totalCount() > 0) {
diff --git a/media/libstagefright/MediaCodec.cpp b/media/libstagefright/MediaCodec.cpp
index b69f347..709bc08 100644
--- a/media/libstagefright/MediaCodec.cpp
+++ b/media/libstagefright/MediaCodec.cpp
@@ -39,7 +39,7 @@
 #include <mediadrm/ICrypto.h>
 #include <media/IOMX.h>
 #include <media/MediaCodecBuffer.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/MediaResource.h>
 #include <media/stagefright/foundation/ABuffer.h>
 #include <media/stagefright/foundation/ADebug.h>
diff --git a/media/libstagefright/RemoteMediaExtractor.cpp b/media/libstagefright/RemoteMediaExtractor.cpp
index 29c3a35..2e26fd0 100644
--- a/media/libstagefright/RemoteMediaExtractor.cpp
+++ b/media/libstagefright/RemoteMediaExtractor.cpp
@@ -20,7 +20,7 @@
 
 #include <binder/IPCThreadState.h>
 #include <media/stagefright/InterfaceUtils.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/MediaSource.h>
 #include <media/stagefright/RemoteMediaExtractor.h>
 
@@ -48,20 +48,20 @@
      mSource(source),
      mExtractorPlugin(plugin) {
 
-    mAnalyticsItem = nullptr;
+    mMetricsItem = nullptr;
     if (MEDIA_LOG) {
-        mAnalyticsItem = MediaAnalyticsItem::create(kKeyExtractor);
+        mMetricsItem = mediametrics::Item::create(kKeyExtractor);
 
         // we're in the extractor service, we want to attribute to the app
         // that invoked us.
         int uid = IPCThreadState::self()->getCallingUid();
-        mAnalyticsItem->setUid(uid);
+        mMetricsItem->setUid(uid);
 
         // track the container format (mpeg, aac, wvm, etc)
         size_t ntracks = extractor->countTracks();
-        mAnalyticsItem->setCString(kExtractorFormat, extractor->name());
+        mMetricsItem->setCString(kExtractorFormat, extractor->name());
         // tracks (size_t)
-        mAnalyticsItem->setInt32(kExtractorTracks, ntracks);
+        mMetricsItem->setInt32(kExtractorTracks, ntracks);
         // metadata
         MetaDataBase pMetaData;
         if (extractor->getMetaData(pMetaData) == OK) {
@@ -70,7 +70,7 @@
             // 'mime'
             const char *mime = nullptr;
             if (pMetaData.findCString(kKeyMIMEType, &mime)) {
-                mAnalyticsItem->setCString(kExtractorMime,  mime);
+                mMetricsItem->setCString(kExtractorMime,  mime);
             }
             // what else is interesting and not already available?
         }
@@ -84,15 +84,15 @@
     mExtractorPlugin = nullptr;
     // log the current record, provided it has some information worth recording
     if (MEDIA_LOG) {
-        if (mAnalyticsItem != nullptr) {
-            if (mAnalyticsItem->count() > 0) {
-                mAnalyticsItem->selfrecord();
+        if (mMetricsItem != nullptr) {
+            if (mMetricsItem->count() > 0) {
+                mMetricsItem->selfrecord();
             }
         }
     }
-    if (mAnalyticsItem != nullptr) {
-        delete mAnalyticsItem;
-        mAnalyticsItem = nullptr;
+    if (mMetricsItem != nullptr) {
+        delete mMetricsItem;
+        mMetricsItem = nullptr;
     }
 }
 
@@ -123,11 +123,11 @@
 }
 
 status_t RemoteMediaExtractor::getMetrics(Parcel *reply) {
-    if (mAnalyticsItem == nullptr || reply == nullptr) {
+    if (mMetricsItem == nullptr || reply == nullptr) {
         return UNKNOWN_ERROR;
     }
 
-    mAnalyticsItem->writeToParcel(reply);
+    mMetricsItem->writeToParcel(reply);
     return OK;
 }
 
diff --git a/media/libstagefright/include/media/stagefright/RemoteMediaExtractor.h b/media/libstagefright/include/media/stagefright/RemoteMediaExtractor.h
index 2bf5a8b..e33e303 100644
--- a/media/libstagefright/include/media/stagefright/RemoteMediaExtractor.h
+++ b/media/libstagefright/include/media/stagefright/RemoteMediaExtractor.h
@@ -18,12 +18,12 @@
 #define REMOTE_MEDIA_EXTRACTOR_H_
 
 #include <android/IMediaExtractor.h>
+#include <media/MediaMetricsItem.h>
 #include <media/stagefright/MediaExtractor.h>
 #include <media/stagefright/foundation/ABase.h>
 
 namespace android {
 
-class MediaAnalyticsItem;
 
 // IMediaExtractor wrapper to the MediaExtractor.
 class RemoteMediaExtractor : public BnMediaExtractor {
@@ -48,7 +48,7 @@
     sp<DataSource> mSource;
     sp<RefBase> mExtractorPlugin;
 
-    MediaAnalyticsItem *mAnalyticsItem;
+    mediametrics::Item *mMetricsItem;
 
     explicit RemoteMediaExtractor(
             MediaExtractor *extractor,
diff --git a/media/mtp/MtpServer.cpp b/media/mtp/MtpServer.cpp
index af69a10..fdf51b1 100644
--- a/media/mtp/MtpServer.cpp
+++ b/media/mtp/MtpServer.cpp
@@ -84,8 +84,8 @@
 //    MTP_OPERATION_SET_OBJECT_PROP_LIST,
 //    MTP_OPERATION_GET_INTERDEPENDENT_PROP_DESC,
 //    MTP_OPERATION_SEND_OBJECT_PROP_LIST,
-    MTP_OPERATION_GET_OBJECT_REFERENCES,
-    MTP_OPERATION_SET_OBJECT_REFERENCES,
+//    MTP_OPERATION_GET_OBJECT_REFERENCES,
+//    MTP_OPERATION_SET_OBJECT_REFERENCES,
 //    MTP_OPERATION_SKIP,
     // Android extension for direct file IO
     MTP_OPERATION_GET_PARTIAL_OBJECT_64,
diff --git a/services/audioflinger/PatchPanel.cpp b/services/audioflinger/PatchPanel.cpp
index 53e2dd5..dbd761a 100644
--- a/services/audioflinger/PatchPanel.cpp
+++ b/services/audioflinger/PatchPanel.cpp
@@ -448,18 +448,6 @@
         *mPlayback.handlePtr() = AUDIO_PATCH_HANDLE_NONE;
     }
 
-    // use a pseudo LCM between input and output framecount
-    size_t playbackFrameCount = mPlayback.thread()->frameCount();
-    int playbackShift = __builtin_ctz(playbackFrameCount);
-    size_t recordFrameCount = mRecord.thread()->frameCount();
-    int shift = __builtin_ctz(recordFrameCount);
-    if (playbackShift < shift) {
-        shift = playbackShift;
-    }
-    size_t frameCount = (playbackFrameCount * recordFrameCount) >> shift;
-    ALOGV("%s() playframeCount %zu recordFrameCount %zu frameCount %zu",
-            __func__, playbackFrameCount, recordFrameCount, frameCount);
-
     // create a special record track to capture from record thread
     uint32_t channelCount = mPlayback.thread()->channelCount();
     audio_channel_mask_t inChannelMask = audio_channel_in_mask_from_count(channelCount);
@@ -503,7 +491,15 @@
     }
 
     sp<RecordThread::PatchRecord> tempRecordTrack;
+    const size_t playbackFrameCount = mPlayback.thread()->frameCount();
+    const size_t recordFrameCount = mRecord.thread()->frameCount();
+    size_t frameCount = 0;
     if ((inputFlags & AUDIO_INPUT_FLAG_DIRECT) && (outputFlags & AUDIO_OUTPUT_FLAG_DIRECT)) {
+        // PassthruPatchRecord producesBufferOnDemand, so use
+        // maximum of playback and record thread framecounts
+        frameCount = std::max(playbackFrameCount, recordFrameCount);
+        ALOGV("%s() playframeCount %zu recordFrameCount %zu frameCount %zu",
+            __func__, playbackFrameCount, recordFrameCount, frameCount);
         tempRecordTrack = new RecordThread::PassthruPatchRecord(
                                                  mRecord.thread().get(),
                                                  sampleRate,
@@ -512,6 +508,16 @@
                                                  frameCount,
                                                  inputFlags);
     } else {
+        // use a pseudo LCM between input and output framecount
+        int playbackShift = __builtin_ctz(playbackFrameCount);
+        int shift = __builtin_ctz(recordFrameCount);
+        if (playbackShift < shift) {
+            shift = playbackShift;
+        }
+        frameCount = (playbackFrameCount * recordFrameCount) >> shift;
+        ALOGV("%s() playframeCount %zu recordFrameCount %zu frameCount %zu",
+            __func__, playbackFrameCount, recordFrameCount, frameCount);
+
         tempRecordTrack = new RecordThread::PatchRecord(
                                                  mRecord.thread().get(),
                                                  sampleRate,
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 7ba48c2..b9afba8 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -1742,7 +1742,7 @@
     mLastRecordedTimestampVerifierN = mTimestampVerifier.getN();
     mLastRecordedTimeNs = timeNs;
 
-    std::unique_ptr<MediaAnalyticsItem> item(MediaAnalyticsItem::create("audiothread"));
+    std::unique_ptr<mediametrics::Item> item(mediametrics::Item::create("audiothread"));
 
 #define MM_PREFIX "android.media.audiothread." // avoid cut-n-paste errors.
 
diff --git a/services/audiopolicy/AudioPolicyInterface.h b/services/audiopolicy/AudioPolicyInterface.h
index 00f14e1..c5cdc25 100644
--- a/services/audiopolicy/AudioPolicyInterface.h
+++ b/services/audiopolicy/AudioPolicyInterface.h
@@ -403,6 +403,12 @@
                                                 std::vector<effect_descriptor_t> effects,
                                                 audio_patch_handle_t patchHandle,
                                                 audio_source_t source) = 0;
+
+    // Used to notify the sound trigger module that an audio capture is about to
+    // take place. This should typically result in any active recognition
+    // sessions to be preempted on modules that do not support sound trigger
+    // recognition concurrently with audio capture.
+    virtual void setSoundTriggerCaptureState(bool active) = 0;
 };
 
 extern "C" AudioPolicyInterface* createAudioPolicyManager(AudioPolicyClientInterface *clientInterface);
diff --git a/services/audiopolicy/managerdefault/Android.bp b/services/audiopolicy/managerdefault/Android.bp
index 1fa0d19..577b42f 100644
--- a/services/audiopolicy/managerdefault/Android.bp
+++ b/services/audiopolicy/managerdefault/Android.bp
@@ -15,7 +15,6 @@
         "libutils",
         "liblog",
         "libaudiopolicy",
-        "libsoundtrigger",
         "libmedia_helper",
         "libmediametrics",
         "libbinder",
diff --git a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
index 9d80a16..2124646 100644
--- a/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
+++ b/services/audiopolicy/managerdefault/AudioPolicyManager.cpp
@@ -46,7 +46,6 @@
 #include <utils/Log.h>
 #include <media/AudioParameter.h>
 #include <private/android_filesystem_config.h>
-#include <soundtrigger/SoundTrigger.h>
 #include <system/audio.h>
 #include "AudioPolicyManager.h"
 #include <Serializer.h>
@@ -2277,7 +2276,7 @@
         DeviceVector primaryInputDevices = availablePrimaryModuleInputDevices();
         if (primaryInputDevices.contains(device) &&
                 mInputs.activeInputsCountOnDevices(primaryInputDevices) == 1) {
-            SoundTrigger::setCaptureState(true);
+            mpClientInterface->setSoundTriggerCaptureState(true);
         }
 
         // automatically enable the remote submix output when input is started if not
@@ -2360,7 +2359,7 @@
         DeviceVector primaryInputDevices = availablePrimaryModuleInputDevices();
         if (primaryInputDevices.contains(inputDesc->getDevice()) &&
                 mInputs.activeInputsCountOnDevices(primaryInputDevices) == 0) {
-            SoundTrigger::setCaptureState(false);
+            mpClientInterface->setSoundTriggerCaptureState(false);
         }
         inputDesc->clearPreemptedSessions();
     }
@@ -5075,7 +5074,7 @@
     DeviceVector primaryInputDevices = availablePrimaryModuleInputDevices();
     if (primaryInputDevices.contains(device) &&
             mInputs.activeInputsCountOnDevices(primaryInputDevices) == 0) {
-        SoundTrigger::setCaptureState(false);
+        mpClientInterface->setSoundTriggerCaptureState(false);
     }
 
     cleanUpEffectsForIo(input);
diff --git a/services/audiopolicy/service/Android.mk b/services/audiopolicy/service/Android.mk
index fdf3eae..80f4eab 100644
--- a/services/audiopolicy/service/Android.mk
+++ b/services/audiopolicy/service/Android.mk
@@ -31,7 +31,8 @@
     libmediametrics \
     libmediautils \
     libeffectsconfig \
-    libsensorprivacy
+    libsensorprivacy \
+    soundtrigger_middleware-aidl-cpp
 
 LOCAL_EXPORT_SHARED_LIBRARY_HEADERS := \
     libsensorprivacy
diff --git a/services/audiopolicy/service/AudioPolicyClientImpl.cpp b/services/audiopolicy/service/AudioPolicyClientImpl.cpp
index 6de0c80..5b81b9d 100644
--- a/services/audiopolicy/service/AudioPolicyClientImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyClientImpl.cpp
@@ -17,10 +17,13 @@
 #define LOG_TAG "AudioPolicyClientImpl"
 //#define LOG_NDEBUG 0
 
-#include <soundtrigger/SoundTrigger.h>
-#include <utils/Log.h>
 #include "AudioPolicyService.h"
 
+#include <android/media/soundtrigger_middleware/ISoundTriggerMiddlewareService.h>
+#include <utils/Log.h>
+
+#include "BinderProxy.h"
+
 namespace android {
 
 /* implementation of the client interface from the policy manager */
@@ -239,4 +242,12 @@
     return AudioSystem::newAudioUniqueId(use);
 }
 
+void AudioPolicyService::AudioPolicyClient::setSoundTriggerCaptureState(bool active) {
+    using media::soundtrigger_middleware::ISoundTriggerMiddlewareService;
+
+    static BinderProxy<ISoundTriggerMiddlewareService>
+        proxy("soundtrigger_middleware");
+    proxy.waitServiceOrDie()->setExternalCaptureState(active);
+}
+
 } // namespace android
diff --git a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
index 6379a8a..44c1d09 100644
--- a/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
+++ b/services/audiopolicy/service/AudioPolicyInterfaceImpl.cpp
@@ -19,7 +19,7 @@
 
 #include "AudioPolicyService.h"
 #include "TypeConverter.h"
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <media/AudioPolicy.h>
 #include <utils/Log.h>
 
@@ -548,7 +548,7 @@
         static constexpr char kAudioPolicyActiveDevice[] =
                 "android.media.audiopolicy.active.device";
 
-        MediaAnalyticsItem *item = MediaAnalyticsItem::create(kAudioPolicy);
+        mediametrics::Item *item = mediametrics::Item::create(kAudioPolicy);
         if (item != NULL) {
 
             item->setInt32(kAudioPolicyStatus, status);
diff --git a/services/audiopolicy/service/AudioPolicyService.h b/services/audiopolicy/service/AudioPolicyService.h
index c6fff63..135b3ac 100644
--- a/services/audiopolicy/service/AudioPolicyService.h
+++ b/services/audiopolicy/service/AudioPolicyService.h
@@ -717,6 +717,8 @@
 
         virtual audio_unique_id_t newAudioUniqueId(audio_unique_id_use_t use);
 
+        void setSoundTriggerCaptureState(bool active) override;
+
      private:
         AudioPolicyService *mAudioPolicyService;
     };
diff --git a/services/audiopolicy/service/BinderProxy.h b/services/audiopolicy/service/BinderProxy.h
new file mode 100644
index 0000000..516e84d
--- /dev/null
+++ b/services/audiopolicy/service/BinderProxy.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#pragma once
+
+#include <mutex>
+#include <type_traits>
+#include <binder/IInterface.h>
+#include <binder/IServiceManager.h>
+#include <utils/Log.h>
+
+namespace android {
+
+// A simple utility that caches a proxy for a service and handles death notification.
+// Typically, intended to be used as a static-lifetime object.
+//
+// Example usage:
+// static BinderProxy<IMyInterface> myInterface("my_interface_svc");
+// ...
+// myInterface.waitServiceOrDie()->doSomething();
+//
+// If the service is unavailable, will wait until it becomes available.
+// Will die if the service doesn't implement the requested interface, or cannot be used for
+// permission reasons.
+template<typename ServiceType>
+class BinderProxy {
+public:
+    static_assert(std::is_base_of_v<IInterface, ServiceType>,
+                  "Service type must be a sub-type of IInterface.");
+
+    explicit BinderProxy(std::string_view serviceName)
+            : mServiceName(serviceName), mDeathRecipient(new DeathRecipient(this)) {}
+
+    ~BinderProxy() {
+        if (mDelegate != nullptr) {
+            sp<IBinder> binder = IInterface::asBinder(mDelegate);
+            if (binder != nullptr) {
+                binder->unlinkToDeath(mDeathRecipient);
+            }
+        }
+    }
+
+    sp<ServiceType> waitServiceOrDie() {
+        std::lock_guard<std::mutex> _l(mDelegateMutex);
+        if (mDelegate == nullptr) {
+            mDelegate = waitForService<ServiceType>(String16(mServiceName.c_str()));
+            LOG_ALWAYS_FATAL_IF(mDelegate == nullptr,
+                                "Service %s doesn't implement the required interface.",
+                                mServiceName.c_str());
+            sp<IBinder> binder = IInterface::asBinder(mDelegate);
+            if (binder != nullptr) {
+                binder->linkToDeath(mDeathRecipient);
+            }
+        }
+        return mDelegate;
+    }
+
+private:
+    sp<ServiceType> mDelegate;
+    std::mutex mDelegateMutex;
+    const std::string mServiceName;
+    sp<IBinder::DeathRecipient> mDeathRecipient;
+
+    class DeathRecipient : public IBinder::DeathRecipient {
+    public:
+        DeathRecipient(BinderProxy* proxy) : mProxy(proxy) {}
+
+        void binderDied(const wp<IBinder>&) override {
+            mProxy->binderDied();
+        }
+
+    private:
+        BinderProxy* const mProxy;
+    };
+
+    void binderDied() {
+        std::lock_guard<std::mutex> _l(mDelegateMutex);
+        mDelegate.clear();
+        ALOGW("Binder died: %s", mServiceName.c_str());
+    }
+};
+
+}  // namespace android
diff --git a/services/audiopolicy/tests/AudioPolicyTestClient.h b/services/audiopolicy/tests/AudioPolicyTestClient.h
index b92a2e6..c628e70 100644
--- a/services/audiopolicy/tests/AudioPolicyTestClient.h
+++ b/services/audiopolicy/tests/AudioPolicyTestClient.h
@@ -86,6 +86,7 @@
     void setEffectSuspended(int effectId __unused,
                             audio_session_t sessionId __unused,
                             bool suspended __unused) {}
+    void setSoundTriggerCaptureState(bool active __unused) override {};
 };
 
 } // namespace android
diff --git a/services/camera/libcameraservice/Android.bp b/services/camera/libcameraservice/Android.bp
index c50a3c6..9cc15cd 100644
--- a/services/camera/libcameraservice/Android.bp
+++ b/services/camera/libcameraservice/Android.bp
@@ -26,6 +26,7 @@
         "CameraFlashlight.cpp",
         "common/Camera2ClientBase.cpp",
         "common/CameraDeviceBase.cpp",
+        "common/CameraOfflineSessionBase.cpp",
         "common/CameraProviderManager.cpp",
         "common/FrameProcessorBase.cpp",
         "api1/CameraClient.cpp",
@@ -45,6 +46,7 @@
         "api2/HeicCompositeStream.cpp",
         "device1/CameraHardwareInterface.cpp",
         "device3/Camera3Device.cpp",
+        "device3/Camera3OfflineSession.cpp",
         "device3/Camera3Stream.cpp",
         "device3/Camera3IOStreamBase.cpp",
         "device3/Camera3InputStream.cpp",
@@ -110,6 +112,7 @@
         "android.hardware.camera.device@3.3",
         "android.hardware.camera.device@3.4",
         "android.hardware.camera.device@3.5",
+        "android.hardware.camera.device@3.6"
     ],
 
     export_shared_lib_headers: [
diff --git a/services/camera/libcameraservice/CameraService.cpp b/services/camera/libcameraservice/CameraService.cpp
index b704573..18ed3a5 100644
--- a/services/camera/libcameraservice/CameraService.cpp
+++ b/services/camera/libcameraservice/CameraService.cpp
@@ -2776,6 +2776,20 @@
 
 // ----------------------------------------------------------------------------
 
+sp<CameraService> CameraService::OfflineClient::sCameraService;
+
+status_t CameraService::OfflineClient::startCameraOps() {
+    // TODO
+    return OK;
+}
+
+status_t CameraService::OfflineClient::finishCameraOps() {
+    // TODO
+    return OK;
+}
+
+// ----------------------------------------------------------------------------
+
 void CameraService::Client::notifyError(int32_t errorCode,
         const CaptureResultExtras& resultExtras) {
     (void) resultExtras;
diff --git a/services/camera/libcameraservice/CameraService.h b/services/camera/libcameraservice/CameraService.h
index 1f40fc3..dae9c09 100644
--- a/services/camera/libcameraservice/CameraService.h
+++ b/services/camera/libcameraservice/CameraService.h
@@ -71,6 +71,7 @@
 public:
     class Client;
     class BasicClient;
+    class OfflineClient;
 
     // The effective API level.  The Camera2 API running in LEGACY mode counts as API_1.
     enum apiLevel {
@@ -401,6 +402,87 @@
         int mCameraId;  // All API1 clients use integer camera IDs
     }; // class Client
 
+
+    // Client for offline session. Note that offline session client does not affect camera service's
+    // client arbitration logic. It is camera HAL's decision to decide whether a normal camera
+    // client is conflicting with existing offline client(s).
+    // The other distinctive difference between offline clients and normal clients is that normal
+    // clients are created through ICameraService binder calls, while the offline session client
+    // is created through ICameraDeviceUser::switchToOffline call.
+    class OfflineClient : public virtual RefBase {
+
+        virtual status_t dump(int fd, const Vector<String16>& args) = 0;
+
+        // Block the client form using the camera
+        virtual void block() = 0;
+
+        // Return the package name for this client
+        virtual String16 getPackageName() const = 0;
+
+        // Notify client about a fatal error
+        // TODO: maybe let impl notify within block?
+        virtual void notifyError(int32_t errorCode,
+                const CaptureResultExtras& resultExtras) = 0;
+
+        // Get the UID of the application client using this
+        virtual uid_t getClientUid() const = 0;
+
+        // Get the PID of the application client using this
+        virtual int getClientPid() const = 0;
+
+        protected:
+            OfflineClient(const sp<CameraService>& cameraService,
+                    const String16& clientPackageName,
+                    const String8& cameraIdStr,
+                    int clientPid,
+                    uid_t clientUid,
+                    int servicePid): mCameraIdStr(cameraIdStr),
+                            mClientPackageName(clientPackageName), mClientPid(clientPid),
+                            mClientUid(clientUid), mServicePid(servicePid) {
+                if (sCameraService == nullptr) {
+                    sCameraService = cameraService;
+                }
+            }
+
+            virtual ~OfflineClient() { /*TODO*/ }
+
+            // these are initialized in the constructor.
+            static sp<CameraService>        sCameraService;
+            const String8                   mCameraIdStr;
+            String16                        mClientPackageName;
+            pid_t                           mClientPid;
+            const uid_t                     mClientUid;
+            const pid_t                     mServicePid;
+            bool                            mDisconnected;
+
+            // - The app-side Binder interface to receive callbacks from us
+            sp<IBinder>                     mRemoteBinder;   // immutable after constructor
+
+            // permissions management
+            status_t                        startCameraOps();
+            status_t                        finishCameraOps();
+
+        private:
+            std::unique_ptr<AppOpsManager>  mAppOpsManager = nullptr;
+
+            class OpsCallback : public BnAppOpsCallback {
+            public:
+                explicit OpsCallback(wp<OfflineClient> client) : mClient(client) {}
+                virtual void opChanged(int32_t /*op*/, const String16& /*packageName*/) {
+                    //TODO
+                }
+
+            private:
+                wp<OfflineClient> mClient;
+
+            }; // class OpsCallback
+
+            sp<OpsCallback> mOpsCallback;
+
+            // IAppOpsCallback interface, indirected through opListener
+            // virtual void opChanged(int32_t op, const String16& packageName);
+    }; // class OfflineClient
+
     /**
      * A listener class that implements the LISTENER interface for use with a ClientManager, and
      * implements the following methods:
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
index 27bebde..28421ba 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.cpp
@@ -1901,6 +1901,80 @@
     return binder::Status::ok();
 }
 
+binder::Status CameraDeviceClient::switchToOffline(
+        const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
+        const std::vector<view::Surface>& offlineOutputs,
+        /*out*/
+        sp<hardware::camera2::ICameraOfflineSession>* session) {
+    ATRACE_CALL();
+
+    binder::Status res;
+    if (!(res = checkPidStatus(__FUNCTION__)).isOk()) return res;
+
+    Mutex::Autolock icl(mBinderSerializationLock);
+
+    if (!mDevice.get()) {
+        return STATUS_ERROR(CameraService::ERROR_DISCONNECTED, "Camera device no longer alive");
+    }
+
+    if (offlineOutputs.empty()) {
+        String8 msg = String8::format("Offline outputs must not be empty");
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
+    }
+
+    if (session == nullptr) {
+        String8 msg = String8::format("Invalid offline session");
+        ALOGE("%s: %s", __FUNCTION__, msg.string());
+        return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
+    }
+
+    std::vector<int32_t> offlineStreamIds(offlineOutputs.size());
+    for (auto& surface : offlineOutputs) {
+        sp<IBinder> binder = IInterface::asBinder(surface.graphicBufferProducer);
+        ssize_t index = mStreamMap.indexOfKey(binder);
+        if (index == NAME_NOT_FOUND) {
+            String8 msg = String8::format("Offline output is invalid");
+            ALOGE("%s: %s", __FUNCTION__, msg.string());
+            return STATUS_ERROR(CameraService::ERROR_ILLEGAL_ARGUMENT, msg.string());
+        }
+        // TODO: Also check whether the offline output is supported by Hal for offline mode.
+
+        sp<Surface> s = new Surface(surface.graphicBufferProducer);
+        bool isCompositeStream = camera3::DepthCompositeStream::isDepthCompositeStream(s);
+        isCompositeStream |= camera3::HeicCompositeStream::isHeicCompositeStream(s);
+        if (isCompositeStream) {
+            // TODO: Add composite specific handling
+        } else {
+            offlineStreamIds.push_back(mStreamMap.valueAt(index).streamId());
+        }
+    }
+
+    sp<CameraOfflineSessionBase> offlineSession;
+    auto ret = mDevice->switchToOffline(offlineStreamIds, &offlineSession);
+    if (ret != OK) {
+        return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                "Camera %s: Error switching to offline mode: %s (%d)",
+                mCameraIdStr.string(), strerror(ret), ret);
+    }
+
+    sp<CameraOfflineSessionClient> offlineClient = new CameraOfflineSessionClient(sCameraService,
+            offlineSession, cameraCb, mClientPackageName, mCameraIdStr, mClientPid, mClientUid,
+            mServicePid);
+    ret = offlineClient->initialize();
+    if (ret == OK) {
+        // TODO: We need to update mStreamMap, mConfiguredOutputs
+    } else {
+        return STATUS_ERROR_FMT(CameraService::ERROR_ILLEGAL_ARGUMENT,
+                "Camera %s: Failed to initilize offline session: %s (%d)",
+                mCameraIdStr.string(), strerror(ret), ret);
+    }
+
+    *session = offlineClient;
+
+    return binder::Status::ok();
+}
+
 status_t CameraDeviceClient::dump(int fd, const Vector<String16>& args) {
     return BasicClient::dump(fd, args);
 }
diff --git a/services/camera/libcameraservice/api2/CameraDeviceClient.h b/services/camera/libcameraservice/api2/CameraDeviceClient.h
index 7efc5ab..0a8f377 100644
--- a/services/camera/libcameraservice/api2/CameraDeviceClient.h
+++ b/services/camera/libcameraservice/api2/CameraDeviceClient.h
@@ -23,6 +23,7 @@
 #include <camera/camera2/SessionConfiguration.h>
 #include <camera/camera2/SubmitInfo.h>
 
+#include "CameraOfflineSessionClient.h"
 #include "CameraService.h"
 #include "common/FrameProcessorBase.h"
 #include "common/Camera2ClientBase.h"
@@ -157,6 +158,12 @@
 
     virtual binder::Status getGlobalAudioRestriction(/*out*/int32_t* outMode) override;
 
+    virtual binder::Status switchToOffline(
+            const sp<hardware::camera2::ICameraDeviceCallbacks>& cameraCb,
+            const std::vector<view::Surface>& offlineOutputs,
+            /*out*/
+            sp<hardware::camera2::ICameraOfflineSession>* session) override;
+
     /**
      * Interface used by CameraService
      */
diff --git a/services/camera/libcameraservice/api2/CameraOfflineSessionClient.h b/services/camera/libcameraservice/api2/CameraOfflineSessionClient.h
new file mode 100644
index 0000000..cb83e29
--- /dev/null
+++ b/services/camera/libcameraservice/api2/CameraOfflineSessionClient.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#ifndef ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H
+#define ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H
+
+#include <android/hardware/camera2/BnCameraOfflineSession.h>
+#include <android/hardware/camera2/ICameraDeviceCallbacks.h>
+#include "CameraService.h"
+
+namespace android {
+
+using android::hardware::camera2::ICameraDeviceCallbacks;
+
+class CameraOfflineSessionClient :
+        public CameraService::OfflineClient,
+        public hardware::camera2::BnCameraOfflineSession
+        // public camera2::FrameProcessorBase::FilteredListener?
+{
+public:
+    CameraOfflineSessionClient(
+            const sp<CameraService>& cameraService,
+            sp<CameraOfflineSessionBase> session,
+            const sp<ICameraDeviceCallbacks>& remoteCallback,
+            const String16& clientPackageName,
+            const String8& cameraIdStr,
+            int clientPid, uid_t clientUid, int servicePid) :
+                    CameraService::OfflineClient(cameraService, clientPackageName,
+                            cameraIdStr, clientPid, clientUid, servicePid),
+                            mRemoteCallback(remoteCallback), mOfflineSession(session) {}
+
+    ~CameraOfflineSessionClient() {}
+
+    virtual binder::Status disconnect() override { return binder::Status::ok(); }
+
+    virtual status_t dump(int /*fd*/, const Vector<String16>& /*args*/) override {
+        return OK;
+    }
+
+    // Block the client form using the camera
+    virtual void block() override {};
+
+    // Return the package name for this client
+    virtual String16 getPackageName() const override { String16 ret; return ret; };
+
+    // Notify client about a fatal error
+    // TODO: maybe let impl notify within block?
+    virtual void notifyError(int32_t /*errorCode*/,
+            const CaptureResultExtras& /*resultExtras*/) override {}
+
+    // Get the UID of the application client using this
+    virtual uid_t getClientUid() const override { return 0; }
+
+    // Get the PID of the application client using this
+    virtual int getClientPid() const override { return 0; }
+
+    status_t initialize() {
+        // TODO: Talk to camera service to add the offline session client book keeping
+        return OK;
+    }
+private:
+    sp<CameraOfflineSessionBase> mSession;
+
+    sp<hardware::camera2::ICameraDeviceCallbacks> mRemoteCallback;
+    // This class is responsible to convert HAL callbacks to AIDL callbacks
+
+    sp<CameraOfflineSessionBase> mOfflineSession;
+};
+
+} // namespace android
+
+#endif // ANDROID_SERVERS_CAMERA_PHOTOGRAPHY_CAMERAOFFLINESESSIONCLIENT_H
diff --git a/services/camera/libcameraservice/common/CameraDeviceBase.h b/services/camera/libcameraservice/common/CameraDeviceBase.h
index 935bc37..1026fdf 100644
--- a/services/camera/libcameraservice/common/CameraDeviceBase.h
+++ b/services/camera/libcameraservice/common/CameraDeviceBase.h
@@ -35,6 +35,8 @@
 #include "device3/Camera3StreamInterface.h"
 #include "binder/Status.h"
 
+#include "CameraOfflineSessionBase.h"
+
 namespace android {
 
 class CameraProviderManager;
@@ -389,6 +391,13 @@
      * requests to complete, based on their settings
      */
     virtual nsecs_t getExpectedInFlightDuration() = 0;
+
+    /**
+     * switch to offline session
+     */
+    virtual status_t switchToOffline(
+            const std::vector<int32_t>& streamsToKeep,
+            /*out*/ sp<CameraOfflineSessionBase>* session) = 0;
 };
 
 }; // namespace android
diff --git a/services/camera/libcameraservice/common/CameraOfflineSessionBase.cpp b/services/camera/libcameraservice/common/CameraOfflineSessionBase.cpp
new file mode 100644
index 0000000..ff673a9
--- /dev/null
+++ b/services/camera/libcameraservice/common/CameraOfflineSessionBase.cpp
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2019 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 "CameraOfflineSessionBase.h"
+
+namespace android {
+
+/**
+ * Base class destructors
+ */
+CameraOfflineSessionBase::~CameraOfflineSessionBase() {
+}
+
+} // namespace android
diff --git a/services/camera/libcameraservice/common/CameraOfflineSessionBase.h b/services/camera/libcameraservice/common/CameraOfflineSessionBase.h
new file mode 100644
index 0000000..3862521
--- /dev/null
+++ b/services/camera/libcameraservice/common/CameraOfflineSessionBase.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#ifndef ANDROID_SERVERS_CAMERA_CAMERAOFFLINESESSIONBASE_H
+#define ANDROID_SERVERS_CAMERA_CAMERAOFFLINESESSIONBASE_H
+
+#include <utils/RefBase.h>
+#include <utils/String8.h>
+#include <utils/Timers.h>
+
+#include "camera/CaptureResult.h"
+
+namespace android {
+
+class CameraOfflineSessionBase : public virtual RefBase {
+  public:
+    virtual ~CameraOfflineSessionBase();
+
+    // The session's original camera ID
+    virtual const String8& getId() const = 0;
+
+    virtual status_t disconnect() = 0;
+
+    virtual status_t dump(int fd) = 0;
+
+    virtual status_t abort() = 0;
+
+    /**
+     * Capture result passing
+     */
+    virtual status_t waitForNextFrame(nsecs_t timeout) = 0;
+
+    virtual status_t getNextResult(CaptureResult *frame) = 0;
+
+    // TODO: notification passing path
+}; // class CameraOfflineSessionBase
+
+} // namespace android
+
+#endif
diff --git a/services/camera/libcameraservice/device3/Camera3Device.cpp b/services/camera/libcameraservice/device3/Camera3Device.cpp
index 2541365..4e5c8d6 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.cpp
+++ b/services/camera/libcameraservice/device3/Camera3Device.cpp
@@ -58,6 +58,7 @@
 #include "device3/Camera3InputStream.h"
 #include "device3/Camera3DummyStream.h"
 #include "device3/Camera3SharedOutputStream.h"
+#include "device3/Camera3OfflineSession.h"
 #include "CameraService.h"
 #include "utils/CameraThreadState.h"
 
@@ -206,7 +207,15 @@
             ANDROID_INFO_SUPPORTED_BUFFER_MANAGEMENT_VERSION_HIDL_DEVICE_3_5);
     }
 
-    mInterface = new HalInterface(session, queue, mUseHalBufManager);
+    camera_metadata_entry_t capabilities = mDeviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
+    for (size_t i = 0; i < capabilities.count; i++) {
+        uint8_t capability = capabilities.data.u8[i];
+        if (capability == ANDROID_REQUEST_AVAILABLE_CAPABILITIES_OFFLINE_PROCESSING) {
+            mSupportOfflineProcessing = true;
+        }
+    }
+
+    mInterface = new HalInterface(session, queue, mUseHalBufManager, mSupportOfflineProcessing);
     std::string providerType;
     mVendorTagId = manager->getProviderTagIdLocked(mId.string());
     mTagMonitor.initialize(mVendorTagId);
@@ -227,9 +236,8 @@
             maxVersion.get_major(), maxVersion.get_minor());
 
     bool isMonochrome = false;
-    camera_metadata_entry_t entry = mDeviceInfo.find(ANDROID_REQUEST_AVAILABLE_CAPABILITIES);
-    for (size_t i = 0; i < entry.count; i++) {
-        uint8_t capability = entry.data.u8[i];
+    for (size_t i = 0; i < capabilities.count; i++) {
+        uint8_t capability = capabilities.data.u8[i];
         if (capability == ANDROID_REQUEST_AVAILABLE_CAPABILITIES_MONOCHROME) {
             isMonochrome = true;
         }
@@ -4045,13 +4053,18 @@
 Camera3Device::HalInterface::HalInterface(
             sp<ICameraDeviceSession> &session,
             std::shared_ptr<RequestMetadataQueue> queue,
-            bool useHalBufManager) :
+            bool useHalBufManager, bool supportOfflineProcessing) :
         mHidlSession(session),
         mRequestMetadataQueue(queue),
         mUseHalBufManager(useHalBufManager),
-        mIsReconfigurationQuerySupported(true) {
+        mIsReconfigurationQuerySupported(true),
+        mSupportOfflineProcessing(supportOfflineProcessing) {
     // Check with hardware service manager if we can downcast these interfaces
     // Somewhat expensive, so cache the results at startup
+    auto castResult_3_6 = device::V3_6::ICameraDeviceSession::castFrom(mHidlSession);
+    if (castResult_3_6.isOk()) {
+        mHidlSession_3_6 = castResult_3_6;
+    }
     auto castResult_3_5 = device::V3_5::ICameraDeviceSession::castFrom(mHidlSession);
     if (castResult_3_5.isOk()) {
         mHidlSession_3_5 = castResult_3_5;
@@ -4066,18 +4079,22 @@
     }
 }
 
-Camera3Device::HalInterface::HalInterface() : mUseHalBufManager(false) {}
+Camera3Device::HalInterface::HalInterface() :
+        mUseHalBufManager(false),
+        mSupportOfflineProcessing(false) {}
 
 Camera3Device::HalInterface::HalInterface(const HalInterface& other) :
         mHidlSession(other.mHidlSession),
         mRequestMetadataQueue(other.mRequestMetadataQueue),
-        mUseHalBufManager(other.mUseHalBufManager) {}
+        mUseHalBufManager(other.mUseHalBufManager),
+        mSupportOfflineProcessing(other.mSupportOfflineProcessing) {}
 
 bool Camera3Device::HalInterface::valid() {
     return (mHidlSession != nullptr);
 }
 
 void Camera3Device::HalInterface::clear() {
+    mHidlSession_3_6.clear();
     mHidlSession_3_5.clear();
     mHidlSession_3_4.clear();
     mHidlSession_3_3.clear();
@@ -4753,6 +4770,38 @@
     }
 }
 
+status_t Camera3Device::HalInterface::switchToOffline(
+        const std::vector<int32_t>& streamsToKeep,
+        /*out*/hardware::camera::device::V3_6::CameraOfflineSessionInfo* offlineSessionInfo,
+        /*out*/sp<hardware::camera::device::V3_6::ICameraOfflineSession>* offlineSession) {
+    ATRACE_NAME("CameraHal::switchToOffline");
+    if (!valid() || mHidlSession_3_6 == nullptr) {
+        ALOGE("%s called on invalid camera!", __FUNCTION__);
+        return INVALID_OPERATION;
+    }
+
+    if (offlineSessionInfo == nullptr || offlineSession == nullptr) {
+        ALOGE("%s: offlineSessionInfo and offlineSession must not be null!", __FUNCTION__);
+        return INVALID_OPERATION;
+    }
+
+    common::V1_0::Status status = common::V1_0::Status::INTERNAL_ERROR;
+
+    auto resultCallback =
+        [&status, &offlineSessionInfo, &offlineSession] (auto s, auto info, auto session) {
+                status = s;
+                *offlineSessionInfo = info;
+                *offlineSession = session;
+        };
+    auto err = mHidlSession_3_6->switchToOffline(streamsToKeep, resultCallback);
+
+    if (!err.isOk()) {
+        ALOGE("%s: Transaction error: %s", __FUNCTION__, err.description().c_str());
+        return DEAD_OBJECT;
+    }
+    return CameraProviderManager::mapToStatusT(status);
+}
+
 void Camera3Device::HalInterface::getInflightBufferKeys(
         std::vector<std::pair<int32_t, int32_t>>* out) {
     std::lock_guard<std::mutex> lock(mInflightLock);
@@ -5524,6 +5573,7 @@
         Mutex::Autolock l(mRequestLock);
         mNextRequests.clear();
     }
+    mRequestSubmittedSignal.signal();
 
     return submitRequestSuccess;
 }
@@ -5903,6 +5953,32 @@
     mStreamIdsToBeDrained = streamIds;
 }
 
+status_t Camera3Device::RequestThread::switchToOffline(
+        const std::vector<int32_t>& streamsToKeep,
+        /*out*/hardware::camera::device::V3_6::CameraOfflineSessionInfo* offlineSessionInfo,
+        /*out*/sp<hardware::camera::device::V3_6::ICameraOfflineSession>* offlineSession) {
+    Mutex::Autolock l(mRequestLock);
+    clearRepeatingRequestsLocked(/*lastFrameNumber*/nullptr);
+
+    // Theoretically we should also check for mRepeatingRequests.empty(), but the API interface
+    // is serialized by mInterfaceLock so skip that check.
+    bool queueEmpty = mNextRequests.empty() && mRequestQueue.empty();
+    while (!queueEmpty) {
+        status_t res = mRequestSubmittedSignal.waitRelative(mRequestLock, kRequestSubmitTimeout);
+        if (res == TIMED_OUT) {
+            ALOGE("%s: request thread failed to submit a request within timeout!", __FUNCTION__);
+            return res;
+        } else if (res != OK) {
+            ALOGE("%s: request thread failed to submit a request: %s (%d)!",
+                    __FUNCTION__, strerror(-res), res);
+            return res;
+        }
+        queueEmpty = mNextRequests.empty() && mRequestQueue.empty();
+    }
+    return mInterface->switchToOffline(
+            streamsToKeep, offlineSessionInfo, offlineSession);
+}
+
 nsecs_t Camera3Device::getExpectedInFlightDuration() {
     ATRACE_CALL();
     Mutex::Autolock al(mInFlightLock);
@@ -6812,4 +6888,34 @@
     return res;
 }
 
+status_t Camera3Device::switchToOffline(
+        const std::vector<int32_t>& streamsToKeep,
+        /*out*/ sp<CameraOfflineSessionBase>* session) {
+    ATRACE_CALL();
+    if (session == nullptr) {
+        ALOGE("%s: session must not be null", __FUNCTION__);
+        return BAD_VALUE;
+    }
+
+    Mutex::Autolock il(mInterfaceLock);
+    Mutex::Autolock l(mLock);
+
+    // 1. Stop repeating request, wait until request thread submitted all requests, then
+    //    call HAL switchToOffline
+    hardware::camera::device::V3_6::CameraOfflineSessionInfo offlineSessionInfo;
+    sp<hardware::camera::device::V3_6::ICameraOfflineSession> offlineSession;
+
+    mRequestThread->switchToOffline(streamsToKeep, &offlineSessionInfo, &offlineSession);
+
+
+    // 2. Verify offlineSessionInfo
+    // 3. create Camera3OfflineSession and transfer object ownership
+    //   (streams, inflight requests, buffer caches)
+    *session = new Camera3OfflineSession(mId);
+
+    // 4. Delete unneeded streams
+    // 5. Verify Camera3Device is in unconfigured state
+    return OK;
+}
+
 }; // namespace android
diff --git a/services/camera/libcameraservice/device3/Camera3Device.h b/services/camera/libcameraservice/device3/Camera3Device.h
index 2573b48..eabc44d 100644
--- a/services/camera/libcameraservice/device3/Camera3Device.h
+++ b/services/camera/libcameraservice/device3/Camera3Device.h
@@ -34,6 +34,7 @@
 #include <android/hardware/camera/device/3.3/ICameraDeviceSession.h>
 #include <android/hardware/camera/device/3.4/ICameraDeviceSession.h>
 #include <android/hardware/camera/device/3.5/ICameraDeviceSession.h>
+#include <android/hardware/camera/device/3.6/ICameraDeviceSession.h>
 #include <android/hardware/camera/device/3.2/ICameraDeviceCallback.h>
 #include <android/hardware/camera/device/3.4/ICameraDeviceCallback.h>
 #include <android/hardware/camera/device/3.5/ICameraDeviceCallback.h>
@@ -196,6 +197,9 @@
 
     nsecs_t getExpectedInFlightDuration() override;
 
+    status_t switchToOffline(const std::vector<int32_t>& streamsToKeep,
+            /*out*/ sp<CameraOfflineSessionBase>* session) override;
+
     /**
      * Helper functions to map between framework and HIDL values
      */
@@ -282,7 +286,7 @@
       public:
         HalInterface(sp<hardware::camera::device::V3_2::ICameraDeviceSession> &session,
                      std::shared_ptr<RequestMetadataQueue> queue,
-                     bool useHalBufManager);
+                     bool useHalBufManager, bool supportOfflineProcessing);
         HalInterface(const HalInterface &other);
         HalInterface();
 
@@ -316,6 +320,11 @@
         bool isReconfigurationRequired(CameraMetadata& oldSessionParams,
                 CameraMetadata& newSessionParams);
 
+        status_t switchToOffline(
+                const std::vector<int32_t>& streamsToKeep,
+                /*out*/hardware::camera::device::V3_6::CameraOfflineSessionInfo* offlineSessionInfo,
+                /*out*/sp<hardware::camera::device::V3_6::ICameraOfflineSession>* offlineSession);
+
         // method to extract buffer's unique ID
         // return pair of (newlySeenBuffer?, bufferId)
         std::pair<bool, uint64_t> getBufferId(const buffer_handle_t& buf, int streamId);
@@ -352,6 +361,8 @@
         sp<hardware::camera::device::V3_4::ICameraDeviceSession> mHidlSession_3_4;
         // Valid if ICameraDeviceSession is @3.5 or newer
         sp<hardware::camera::device::V3_5::ICameraDeviceSession> mHidlSession_3_5;
+        // Valid if ICameraDeviceSession is @3.6 or newer
+        sp<hardware::camera::device::V3_6::ICameraDeviceSession> mHidlSession_3_6;
 
         std::shared_ptr<RequestMetadataQueue> mRequestMetadataQueue;
 
@@ -424,6 +435,8 @@
 
         const bool mUseHalBufManager;
         bool mIsReconfigurationQuerySupported;
+
+        const bool mSupportOfflineProcessing;
     };
 
     sp<HalInterface> mInterface;
@@ -842,6 +855,11 @@
 
         void signalPipelineDrain(const std::vector<int>& streamIds);
 
+        status_t switchToOffline(
+                const std::vector<int32_t>& streamsToKeep,
+                /*out*/hardware::camera::device::V3_6::CameraOfflineSessionInfo* offlineSessionInfo,
+                /*out*/sp<hardware::camera::device::V3_6::ICameraOfflineSession>* offlineSession);
+
       protected:
 
         virtual bool threadLoop();
@@ -862,6 +880,9 @@
 
         static const nsecs_t kRequestTimeout = 50e6; // 50 ms
 
+        // TODO: does this need to be adjusted for long exposure requests?
+        static const nsecs_t kRequestSubmitTimeout = 200e6; // 200 ms
+
         // Used to prepare a batch of requests.
         struct NextRequest {
             sp<CaptureRequest>              captureRequest;
@@ -936,6 +957,7 @@
 
         Mutex              mRequestLock;
         Condition          mRequestSignal;
+        Condition          mRequestSubmittedSignal;
         RequestList        mRequestQueue;
         RequestList        mRepeatingRequests;
         // The next batch of requests being prepped for submission to the HAL, no longer
@@ -1364,6 +1386,9 @@
     // Fix up result metadata for monochrome camera.
     bool mNeedFixupMonochromeTags;
     status_t fixupMonochromeTags(const CameraMetadata& deviceInfo, CameraMetadata& resultMetadata);
+
+    // Whether HAL supports offline processing capability.
+    bool mSupportOfflineProcessing = false;
 }; // class Camera3Device
 
 }; // namespace android
diff --git a/services/camera/libcameraservice/device3/Camera3OfflineSession.cpp b/services/camera/libcameraservice/device3/Camera3OfflineSession.cpp
new file mode 100644
index 0000000..dc5cbb3
--- /dev/null
+++ b/services/camera/libcameraservice/device3/Camera3OfflineSession.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#define LOG_TAG "Camera3-OffLnSsn"
+#define ATRACE_TAG ATRACE_TAG_CAMERA
+//#define LOG_NDEBUG 0
+//#define LOG_NNDEBUG 0  // Per-frame verbose logging
+
+#ifdef LOG_NNDEBUG
+#define ALOGVV(...) ALOGV(__VA_ARGS__)
+#else
+#define ALOGVV(...) ((void)0)
+#endif
+
+#include <inttypes.h>
+
+#include <utils/Trace.h>
+
+#include "device3/Camera3OfflineSession.h"
+#include "device3/Camera3OutputStream.h"
+#include "device3/Camera3InputStream.h"
+#include "device3/Camera3SharedOutputStream.h"
+
+using namespace android::camera3;
+using namespace android::hardware::camera;
+
+namespace android {
+
+Camera3OfflineSession::Camera3OfflineSession(const String8 &id):
+        mId(id)
+{
+    ATRACE_CALL();
+    ALOGV("%s: Created offline session for camera %s", __FUNCTION__, mId.string());
+}
+
+Camera3OfflineSession::~Camera3OfflineSession()
+{
+    ATRACE_CALL();
+    ALOGV("%s: Tearing down offline session for camera id %s", __FUNCTION__, mId.string());
+}
+
+const String8& Camera3OfflineSession::getId() const {
+    return mId;
+}
+
+status_t Camera3OfflineSession::initialize(
+        sp<hardware::camera::device::V3_6::ICameraOfflineSession> /*hidlSession*/) {
+    ATRACE_CALL();
+    return OK;
+}
+
+status_t Camera3OfflineSession::dump(int /*fd*/) {
+    ATRACE_CALL();
+    return OK;
+}
+
+status_t Camera3OfflineSession::abort() {
+    ATRACE_CALL();
+    return OK;
+}
+
+status_t Camera3OfflineSession::disconnect() {
+    ATRACE_CALL();
+    return OK;
+}
+
+status_t Camera3OfflineSession::waitForNextFrame(nsecs_t /*timeout*/) {
+    ATRACE_CALL();
+    return OK;
+}
+
+status_t Camera3OfflineSession::getNextResult(CaptureResult* /*frame*/) {
+    ATRACE_CALL();
+    return OK;
+}
+
+hardware::Return<void> Camera3OfflineSession::processCaptureResult_3_4(
+        const hardware::hidl_vec<
+                hardware::camera::device::V3_4::CaptureResult>& /*results*/) {
+    return hardware::Void();
+}
+
+hardware::Return<void> Camera3OfflineSession::processCaptureResult(
+        const hardware::hidl_vec<
+                hardware::camera::device::V3_2::CaptureResult>& /*results*/) {
+    return hardware::Void();
+}
+
+hardware::Return<void> Camera3OfflineSession::notify(
+        const hardware::hidl_vec<hardware::camera::device::V3_2::NotifyMsg>& /*msgs*/) {
+    return hardware::Void();
+}
+
+hardware::Return<void> Camera3OfflineSession::requestStreamBuffers(
+        const hardware::hidl_vec<hardware::camera::device::V3_5::BufferRequest>& /*bufReqs*/,
+        requestStreamBuffers_cb /*_hidl_cb*/) {
+    return hardware::Void();
+}
+
+hardware::Return<void> Camera3OfflineSession::returnStreamBuffers(
+        const hardware::hidl_vec<hardware::camera::device::V3_2::StreamBuffer>& /*buffers*/) {
+    return hardware::Void();
+}
+
+}; // namespace android
diff --git a/services/camera/libcameraservice/device3/Camera3OfflineSession.h b/services/camera/libcameraservice/device3/Camera3OfflineSession.h
new file mode 100644
index 0000000..30e8c4f
--- /dev/null
+++ b/services/camera/libcameraservice/device3/Camera3OfflineSession.h
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2019 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.
+ */
+
+#ifndef ANDROID_SERVERS_CAMERA3OFFLINESESSION_H
+#define ANDROID_SERVERS_CAMERA3OFFLINESESSION_H
+
+#include <utils/String8.h>
+#include <utils/String16.h>
+
+#include <android/hardware/camera/device/3.6/ICameraOfflineSession.h>
+#include <fmq/MessageQueue.h>
+
+#include "common/CameraOfflineSessionBase.h"
+
+#include "device3/Camera3BufferManager.h"
+#include "device3/DistortionMapper.h"
+#include "utils/TagMonitor.h"
+#include "utils/LatencyHistogram.h"
+#include <camera_metadata_hidden.h>
+
+namespace android {
+
+namespace camera3 {
+
+class Camera3Stream;
+class Camera3OutputStreamInterface;
+class Camera3StreamInterface;
+
+} // namespace camera3
+
+/**
+ * Camera3OfflineSession for offline session defined in HIDL ICameraOfflineSession@3.6 or higher
+ */
+class Camera3OfflineSession :
+            public CameraOfflineSessionBase,
+            virtual public hardware::camera::device::V3_5::ICameraDeviceCallback {
+
+  public:
+
+    // initialize by Camera3Device. Camera3Device must send all info in separate argument.
+    // monitored tags
+    // mUseHalBufManager
+    // mUsePartialResult
+    // mNumPartialResults
+    explicit Camera3OfflineSession(const String8& id);
+
+    virtual ~Camera3OfflineSession();
+
+    status_t initialize(
+        sp<hardware::camera::device::V3_6::ICameraOfflineSession> hidlSession);
+
+    /**
+     * CameraOfflineSessionBase interface
+     */
+    const String8& getId() const override;
+
+    status_t disconnect() override;
+
+    status_t dump(int fd) override;
+
+    status_t abort() override;
+
+    // methods for capture result passing
+    status_t waitForNextFrame(nsecs_t timeout) override;
+    status_t getNextResult(CaptureResult *frame) override;
+
+    // TODO: methods for notification (error/idle/finished etc) passing
+
+    /**
+     * End of CameraOfflineSessionBase interface
+     */
+
+    /**
+     * HIDL ICameraDeviceCallback interface
+     */
+
+    /**
+     * Implementation of android::hardware::camera::device::V3_5::ICameraDeviceCallback
+     */
+
+    hardware::Return<void> processCaptureResult_3_4(
+            const hardware::hidl_vec<
+                    hardware::camera::device::V3_4::CaptureResult>& results) override;
+    hardware::Return<void> processCaptureResult(
+            const hardware::hidl_vec<
+                    hardware::camera::device::V3_2::CaptureResult>& results) override;
+    hardware::Return<void> notify(
+            const hardware::hidl_vec<
+                    hardware::camera::device::V3_2::NotifyMsg>& msgs) override;
+
+    hardware::Return<void> requestStreamBuffers(
+            const hardware::hidl_vec<
+                    hardware::camera::device::V3_5::BufferRequest>& bufReqs,
+            requestStreamBuffers_cb _hidl_cb) override;
+
+    hardware::Return<void> returnStreamBuffers(
+            const hardware::hidl_vec<
+                    hardware::camera::device::V3_2::StreamBuffer>& buffers) override;
+
+    /**
+     * End of CameraOfflineSessionBase interface
+     */
+
+  private:
+
+    // Camera device ID
+    const String8 mId;
+
+}; // class Camera3OfflineSession
+
+}; // namespace android
+
+#endif
diff --git a/services/mediacodec/Android.bp b/services/mediacodec/Android.bp
index 3141c31..5811068 100644
--- a/services/mediacodec/Android.bp
+++ b/services/mediacodec/Android.bp
@@ -15,10 +15,6 @@
     ],
 
     target: {
-        vendor: {
-            exclude_shared_libs: ["libavservices_minijail"],
-            shared_libs: ["libavservices_minijail_vendor"],
-        },
         android: {
             product_variables: {
                 malloc_not_svelte: {
diff --git a/services/mediacodec/Android.mk b/services/mediacodec/Android.mk
index 1cf0534..88a79e7 100644
--- a/services/mediacodec/Android.mk
+++ b/services/mediacodec/Android.mk
@@ -37,7 +37,7 @@
     libutils \
     liblog \
     libbase \
-    libavservices_minijail_vendor \
+    libavservices_minijail \
     libcutils \
     libhidlbase \
     libstagefright_omx \
diff --git a/services/mediaextractor/MediaExtractorService.cpp b/services/mediaextractor/MediaExtractorService.cpp
index 9e814d1..a6cd224 100644
--- a/services/mediaextractor/MediaExtractorService.cpp
+++ b/services/mediaextractor/MediaExtractorService.cpp
@@ -61,13 +61,11 @@
 }
 
 ::android::binder::Status MediaExtractorService::makeIDataSource(
-        const base::unique_fd &fd,
+        base::unique_fd fd,
         int64_t offset,
         int64_t length,
         ::android::sp<::android::IDataSource>* _aidl_return) {
-    // the caller will close the fd owned by the unique_fd upon return of this function,
-    // so we need to dup() it to retain it.
-    sp<DataSource> source = DataSourceFactory::getInstance()->CreateFromFd(dup(fd.get()), offset, length);
+    sp<DataSource> source = DataSourceFactory::getInstance()->CreateFromFd(fd.release(), offset, length);
     *_aidl_return = CreateIDataSourceFromDataSource(source);
     return binder::Status::ok();
 }
diff --git a/services/mediaextractor/MediaExtractorService.h b/services/mediaextractor/MediaExtractorService.h
index 1b61c4b..1b40bf9 100644
--- a/services/mediaextractor/MediaExtractorService.h
+++ b/services/mediaextractor/MediaExtractorService.h
@@ -37,7 +37,7 @@
             ::android::sp<::android::IMediaExtractor>* _aidl_return);
 
     virtual ::android::binder::Status makeIDataSource(
-            const base::unique_fd &fd,
+            base::unique_fd fd,
             int64_t offset,
             int64_t length,
             ::android::sp<::android::IDataSource>* _aidl_return);
diff --git a/services/mediametrics/AudioAnalytics.cpp b/services/mediametrics/AudioAnalytics.cpp
index 638c4ab..fffe517 100644
--- a/services/mediametrics/AudioAnalytics.cpp
+++ b/services/mediametrics/AudioAnalytics.cpp
@@ -35,7 +35,7 @@
 }
 
 status_t AudioAnalytics::submit(
-        const std::shared_ptr<const MediaAnalyticsItem>& item, bool isTrusted)
+        const std::shared_ptr<const mediametrics::Item>& item, bool isTrusted)
 {
     if (startsWith(item->getKey(), "audio.")) {
         return mTimeMachine.put(item, isTrusted)
diff --git a/services/mediametrics/AudioAnalytics.h b/services/mediametrics/AudioAnalytics.h
index 366a809..b931258 100644
--- a/services/mediametrics/AudioAnalytics.h
+++ b/services/mediametrics/AudioAnalytics.h
@@ -43,7 +43,7 @@
      *        UID to be a system service by MediaMetrics service.
      *        Do not use true if you haven't really checked!
      */
-    status_t submit(const std::shared_ptr<const MediaAnalyticsItem>& item, bool isTrusted);
+    status_t submit(const std::shared_ptr<const mediametrics::Item>& item, bool isTrusted);
 
     /**
      * Returns a pair consisting of the dump string, and the number of lines in the string.
diff --git a/services/mediametrics/MediaMetricsService.cpp b/services/mediametrics/MediaMetricsService.cpp
index b735b81..bbd13fa 100644
--- a/services/mediametrics/MediaMetricsService.cpp
+++ b/services/mediametrics/MediaMetricsService.cpp
@@ -15,7 +15,7 @@
  */
 
 //#define LOG_NDEBUG 0
-#define LOG_TAG "MediaAnalyticsService"
+#define LOG_TAG "MediaMetricsService"
 #include <utils/Log.h>
 
 #include "MediaMetricsService.h"
@@ -52,21 +52,21 @@
 // TODO: need to look at tuning kMaxRecords and friends for low-memory devices
 
 /* static */
-nsecs_t MediaAnalyticsService::roundTime(nsecs_t timeNs)
+nsecs_t MediaMetricsService::roundTime(nsecs_t timeNs)
 {
     return (timeNs + NANOS_PER_SECOND / 2) / NANOS_PER_SECOND * NANOS_PER_SECOND;
 }
 
-MediaAnalyticsService::MediaAnalyticsService()
+MediaMetricsService::MediaMetricsService()
         : mMaxRecords(kMaxRecords),
           mMaxRecordAgeNs(kMaxRecordAgeNs),
           mMaxRecordsExpiredAtOnce(kMaxExpiredAtOnce),
-          mDumpProtoDefault(MediaAnalyticsItem::PROTO_V1)
+          mDumpProtoDefault(mediametrics::Item::PROTO_V1)
 {
     ALOGD("%s", __func__);
 }
 
-MediaAnalyticsService::~MediaAnalyticsService()
+MediaMetricsService::~MediaMetricsService()
 {
     ALOGD("%s", __func__);
     // the class destructor clears anyhow, but we enforce clearing items first.
@@ -74,7 +74,7 @@
     mItems.clear();
 }
 
-status_t MediaAnalyticsService::submitInternal(MediaAnalyticsItem *item, bool release)
+status_t MediaMetricsService::submitInternal(mediametrics::Item *item, bool release)
 {
     // calling PID is 0 for one-way calls.
     const pid_t pid = IPCThreadState::self()->getCallingPid();
@@ -157,23 +157,23 @@
     }
 
     // now attach either the item or its dup to a const shared pointer
-    std::shared_ptr<const MediaAnalyticsItem> sitem(release ? item : item->dup());
+    std::shared_ptr<const mediametrics::Item> sitem(release ? item : item->dup());
 
     (void)mAudioAnalytics.submit(sitem, isTrusted);
 
-    extern bool dump2Statsd(const std::shared_ptr<const MediaAnalyticsItem>& item);
+    extern bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item);
     (void)dump2Statsd(sitem);  // failure should be logged in function.
     saveItem(sitem);
     return NO_ERROR;
 }
 
-status_t MediaAnalyticsService::dump(int fd, const Vector<String16>& args)
+status_t MediaMetricsService::dump(int fd, const Vector<String16>& args)
 {
     String8 result;
 
     if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
         result.appendFormat("Permission Denial: "
-                "can't dump MediaAnalyticsService from pid=%d, uid=%d\n",
+                "can't dump MediaMetricsService from pid=%d, uid=%d\n",
                 IPCThreadState::self()->getCallingPid(),
                 IPCThreadState::self()->getCallingUid());
         write(fd, result.string(), result.size());
@@ -198,15 +198,15 @@
             i++;
             if (i < n) {
                 String8 value(args[i]);
-                int proto = MediaAnalyticsItem::PROTO_V0;
+                int proto = mediametrics::Item::PROTO_V0;
                 char *endp;
                 const char *p = value.string();
                 proto = strtol(p, &endp, 10);
                 if (endp != p || *endp == '\0') {
-                    if (proto < MediaAnalyticsItem::PROTO_FIRST) {
-                        proto = MediaAnalyticsItem::PROTO_FIRST;
-                    } else if (proto > MediaAnalyticsItem::PROTO_LAST) {
-                        proto = MediaAnalyticsItem::PROTO_LAST;
+                    if (proto < mediametrics::Item::PROTO_FIRST) {
+                        proto = mediametrics::Item::PROTO_FIRST;
+                    } else if (proto > mediametrics::Item::PROTO_LAST) {
+                        proto = mediametrics::Item::PROTO_LAST;
                     }
                     chosenProto = proto;
                 } else {
@@ -275,10 +275,10 @@
 }
 
 // dump headers
-void MediaAnalyticsService::dumpHeaders_l(String8 &result, int dumpProto, nsecs_t ts_since)
+void MediaMetricsService::dumpHeaders_l(String8 &result, int dumpProto, nsecs_t ts_since)
 {
     result.appendFormat("Protocol Version: %d\n", dumpProto);
-    if (MediaAnalyticsItem::isEnabled()) {
+    if (mediametrics::Item::isEnabled()) {
         result.append("Metrics gathering: enabled\n");
     } else {
         result.append("Metrics gathering: DISABLED via property\n");
@@ -297,7 +297,7 @@
     }
 }
 
-void MediaAnalyticsService::dumpRecent_l(
+void MediaMetricsService::dumpRecent_l(
         String8 &result, int dumpProto, nsecs_t ts_since, const char * only)
 {
     if (only != nullptr && *only == '\0') {
@@ -311,11 +311,11 @@
     // talk about # records we discarded, perhaps "discarded w/o reading" too
 }
 
-void MediaAnalyticsService::dumpQueue_l(String8 &result, int dumpProto) {
+void MediaMetricsService::dumpQueue_l(String8 &result, int dumpProto) {
     dumpQueue_l(result, dumpProto, (nsecs_t) 0, nullptr /* only */);
 }
 
-void MediaAnalyticsService::dumpQueue_l(
+void MediaMetricsService::dumpQueue_l(
         String8 &result, int dumpProto, nsecs_t ts_since, const char * only) {
     int slot = 0;
 
@@ -346,7 +346,7 @@
 
 // if item != NULL, it's the item we just inserted
 // true == more items eligible to be recovered
-bool MediaAnalyticsService::expirations_l(const std::shared_ptr<const MediaAnalyticsItem>& item)
+bool MediaMetricsService::expirations_l(const std::shared_ptr<const mediametrics::Item>& item)
 {
     bool more = false;
 
@@ -395,7 +395,7 @@
     return more;
 }
 
-void MediaAnalyticsService::processExpirations()
+void MediaMetricsService::processExpirations()
 {
     bool more;
     do {
@@ -405,7 +405,7 @@
     } while (more);
 }
 
-void MediaAnalyticsService::saveItem(const std::shared_ptr<const MediaAnalyticsItem>& item)
+void MediaMetricsService::saveItem(const std::shared_ptr<const mediametrics::Item>& item)
 {
     std::lock_guard _l(mLock);
     // we assume the items are roughly in time order.
@@ -419,7 +419,7 @@
 }
 
 /* static */
-bool MediaAnalyticsService::isContentValid(const MediaAnalyticsItem *item, bool isTrusted)
+bool MediaMetricsService::isContentValid(const mediametrics::Item *item, bool isTrusted)
 {
     if (isTrusted) return true;
     // untrusted uids can only send us a limited set of keys
@@ -445,7 +445,7 @@
 }
 
 // are we rate limited, normally false
-bool MediaAnalyticsService::isRateLimited(MediaAnalyticsItem *) const
+bool MediaMetricsService::isRateLimited(mediametrics::Item *) const
 {
     return false;
 }
@@ -455,8 +455,8 @@
 
 // give me the package name, perhaps going to find it
 // manages its own mutex operations internally
-void MediaAnalyticsService::UidInfo::setPkgInfo(
-        MediaAnalyticsItem *item, uid_t uid, bool setName, bool setVersion)
+void MediaMetricsService::UidInfo::setPkgInfo(
+        mediametrics::Item *item, uid_t uid, bool setName, bool setVersion)
 {
     ALOGV("%s: uid=%d", __func__, uid);
 
diff --git a/services/mediametrics/MediaMetricsService.h b/services/mediametrics/MediaMetricsService.h
index 5bdc48f..b736c30 100644
--- a/services/mediametrics/MediaMetricsService.h
+++ b/services/mediametrics/MediaMetricsService.h
@@ -22,19 +22,19 @@
 #include <mutex>
 #include <unordered_map>
 
-// IMediaAnalyticsService must include Vector, String16, Errors
-#include <media/IMediaAnalyticsService.h>
+// IMediaMetricsService must include Vector, String16, Errors
+#include <media/IMediaMetricsService.h>
 #include <utils/String8.h>
 
 #include "AudioAnalytics.h"
 
 namespace android {
 
-class MediaAnalyticsService : public BnMediaAnalyticsService
+class MediaMetricsService : public BnMediaMetricsService
 {
 public:
-    MediaAnalyticsService();
-    ~MediaAnalyticsService() override;
+    MediaMetricsService();
+    ~MediaMetricsService() override;
 
     /**
      * Submits the indicated record to the mediaanalytics service.
@@ -43,12 +43,12 @@
      * \return status failure, which is negative on binder transaction failure.
      *         As the transaction is one-way, remote failures will not be reported.
      */
-    status_t submit(MediaAnalyticsItem *item) override {
+    status_t submit(mediametrics::Item *item) override {
         return submitInternal(item, false /* release */);
     }
 
     status_t submitBuffer(const char *buffer, size_t length) override {
-        MediaAnalyticsItem *item = new MediaAnalyticsItem();
+        mediametrics::Item *item = new mediametrics::Item();
         return item->readFromByteString(buffer, length)
                 ?: submitInternal(item, true /* release */);
     }
@@ -66,17 +66,17 @@
 
     // Internal call where release is true if ownership of item is transferred
     // to the service (that is, the service will eventually delete the item).
-    status_t submitInternal(MediaAnalyticsItem *item, bool release) override;
+    status_t submitInternal(mediametrics::Item *item, bool release) override;
 
 private:
     void processExpirations();
     // input validation after arrival from client
-    static bool isContentValid(const MediaAnalyticsItem *item, bool isTrusted);
-    bool isRateLimited(MediaAnalyticsItem *) const;
-    void saveItem(const std::shared_ptr<const MediaAnalyticsItem>& item);
+    static bool isContentValid(const mediametrics::Item *item, bool isTrusted);
+    bool isRateLimited(mediametrics::Item *) const;
+    void saveItem(const std::shared_ptr<const mediametrics::Item>& item);
 
     // The following methods are GUARDED_BY(mLock)
-    bool expirations_l(const std::shared_ptr<const MediaAnalyticsItem>& item);
+    bool expirations_l(const std::shared_ptr<const mediametrics::Item>& item);
 
     // support for generating output
     void dumpQueue_l(String8 &result, int dumpProto);
@@ -98,7 +98,7 @@
 
     class UidInfo {
     public:
-        void setPkgInfo(MediaAnalyticsItem *item, uid_t uid, bool setName, bool setVersion);
+        void setPkgInfo(mediametrics::Item *item, uid_t uid, bool setName, bool setVersion);
 
     private:
         std::mutex mUidInfoLock;
@@ -132,7 +132,7 @@
     // Our item queue, generally (oldest at front)
     // TODO: Make separate class, use segmented queue, write lock only end.
     // Note: Another analytics module might have ownership of an item longer than the log.
-    std::deque<std::shared_ptr<const MediaAnalyticsItem>> mItems; // GUARDED_BY(mLock)
+    std::deque<std::shared_ptr<const mediametrics::Item>> mItems; // GUARDED_BY(mLock)
 };
 
 } // namespace android
diff --git a/services/mediametrics/TimeMachine.h b/services/mediametrics/TimeMachine.h
index 578b838..0cd8dc6 100644
--- a/services/mediametrics/TimeMachine.h
+++ b/services/mediametrics/TimeMachine.h
@@ -23,7 +23,7 @@
 #include <variant>
 #include <vector>
 
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 #include <utils/Timers.h>
 
 namespace android::mediametrics {
@@ -101,7 +101,7 @@
         }
 
         void putProp(
-                const std::string &name, const MediaAnalyticsItem::Prop &prop, int64_t time = 0) {
+                const std::string &name, const mediametrics::Item::Prop &prop, int64_t time = 0) {
             prop.visit([&](auto value) { putValue(name, value, time); });
         }
 
@@ -188,7 +188,7 @@
     /**
      * Put all the properties from an item into the Time Machine log.
      */
-    status_t put(const std::shared_ptr<const MediaAnalyticsItem>& item, bool isTrusted = false) {
+    status_t put(const std::shared_ptr<const mediametrics::Item>& item, bool isTrusted = false) {
         const int64_t time = item->getTimestamp();
         const std::string &key = item->getKey();
 
@@ -214,7 +214,7 @@
         }
 
         // deferred contains remote properties (for other keys) to do later.
-        std::vector<const MediaAnalyticsItem::Prop *> deferred;
+        std::vector<const mediametrics::Item::Prop *> deferred;
         {
             // handle local properties
             std::lock_guard lock(getLockForKey(key));
diff --git a/services/mediametrics/TransactionLog.h b/services/mediametrics/TransactionLog.h
index ca37862..7a520d9 100644
--- a/services/mediametrics/TransactionLog.h
+++ b/services/mediametrics/TransactionLog.h
@@ -21,12 +21,12 @@
 #include <sstream>
 #include <string>
 
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 
 namespace android::mediametrics {
 
 /**
- * The TransactionLog is used to record MediaAnalyticsItems to present
+ * The TransactionLog is used to record mediametrics::Items to present
  * different views on the time information (selected by audio, and sorted by key).
  *
  * The TransactionLog will always present data in timestamp order. (Perhaps we
@@ -61,7 +61,7 @@
     /**
      * Put an item in the TransactionLog.
      */
-    status_t put(const std::shared_ptr<const MediaAnalyticsItem>& item) {
+    status_t put(const std::shared_ptr<const mediametrics::Item>& item) {
         const std::string& key = item->getKey();
         const int64_t time = item->getTimestamp();
 
@@ -77,7 +77,7 @@
     /**
      * Returns all records within [startTime, endTime]
      */
-    std::vector<std::shared_ptr<const MediaAnalyticsItem>> get(
+    std::vector<std::shared_ptr<const mediametrics::Item>> get(
             int64_t startTime = 0, int64_t endTime = INT64_MAX) const {
         std::lock_guard lock(mLock);
         return getItemsInRange_l(mLog, startTime, endTime);
@@ -86,7 +86,7 @@
     /**
      * Returns all records for a key within [startTime, endTime]
      */
-    std::vector<std::shared_ptr<const MediaAnalyticsItem>> get(
+    std::vector<std::shared_ptr<const mediametrics::Item>> get(
             const std::string& key,
             int64_t startTime = 0, int64_t endTime = INT64_MAX) const {
         std::lock_guard lock(mLock);
@@ -158,7 +158,7 @@
 
 private:
     using MapTimeItem =
-            std::multimap<int64_t /* time */, std::shared_ptr<const MediaAnalyticsItem>>;
+            std::multimap<int64_t /* time */, std::shared_ptr<const mediametrics::Item>>;
 
     // GUARDED_BY mLock
     /**
@@ -179,7 +179,7 @@
         // remove at least those elements.
 
         // use a stale vector with precise type to avoid type erasure overhead in garbage
-        std::vector<std::shared_ptr<const MediaAnalyticsItem>> stale;
+        std::vector<std::shared_ptr<const mediametrics::Item>> stale;
 
         for (size_t i = 0; i < toRemove; ++i) {
             stale.emplace_back(std::move(eraseEnd->second));
@@ -224,7 +224,7 @@
         return true;
     }
 
-    static std::vector<std::shared_ptr<const MediaAnalyticsItem>> getItemsInRange_l(
+    static std::vector<std::shared_ptr<const mediametrics::Item>> getItemsInRange_l(
             const MapTimeItem& map,
             int64_t startTime = 0, int64_t endTime = INT64_MAX) {
         auto it = map.lower_bound(startTime);
@@ -232,7 +232,7 @@
 
         auto it2 = map.upper_bound(endTime);
 
-        std::vector<std::shared_ptr<const MediaAnalyticsItem>> ret;
+        std::vector<std::shared_ptr<const mediametrics::Item>> ret;
         while (it != it2) {
             ret.push_back(it->second);
             ++it;
diff --git a/services/mediametrics/iface_statsd.cpp b/services/mediametrics/iface_statsd.cpp
index 962cafe..3a1eea7 100644
--- a/services/mediametrics/iface_statsd.cpp
+++ b/services/mediametrics/iface_statsd.cpp
@@ -38,10 +38,10 @@
 
 namespace android {
 
-// set of routines that crack a MediaAnalyticsItem
+// set of routines that crack a mediametrics::Item
 // and send it off to statsd with the appropriate hooks
 //
-// each MediaAnalyticsItem type (extractor, codec, nuplayer, etc)
+// each mediametrics::Item type (extractor, codec, nuplayer, etc)
 // has its own routine to handle this.
 //
 
@@ -49,7 +49,7 @@
 
 struct statsd_hooks {
     const char *key;
-    bool (*handler)(const MediaAnalyticsItem *);
+    bool (*handler)(const mediametrics::Item *);
 };
 
 // keep this sorted, so we can do binary searches
@@ -70,7 +70,7 @@
 };
 
 // give me a record, i'll look at the type and upload appropriately
-bool dump2Statsd(const std::shared_ptr<const MediaAnalyticsItem>& item) {
+bool dump2Statsd(const std::shared_ptr<const mediametrics::Item>& item) {
     if (item == NULL) return false;
 
     // get the key
diff --git a/services/mediametrics/iface_statsd.h b/services/mediametrics/iface_statsd.h
index 1c48118..19505a4 100644
--- a/services/mediametrics/iface_statsd.h
+++ b/services/mediametrics/iface_statsd.h
@@ -19,17 +19,17 @@
 extern bool enabled_statsd;
 
 // component specific dumpers
-extern bool statsd_audiopolicy(const MediaAnalyticsItem *);
-extern bool statsd_audiorecord(const MediaAnalyticsItem *);
-extern bool statsd_audiothread(const MediaAnalyticsItem *);
-extern bool statsd_audiotrack(const MediaAnalyticsItem *);
-extern bool statsd_codec(const MediaAnalyticsItem *);
-extern bool statsd_extractor(const MediaAnalyticsItem *);
-extern bool statsd_nuplayer(const MediaAnalyticsItem *);
-extern bool statsd_recorder(const MediaAnalyticsItem *);
+extern bool statsd_audiopolicy(const mediametrics::Item *);
+extern bool statsd_audiorecord(const mediametrics::Item *);
+extern bool statsd_audiothread(const mediametrics::Item *);
+extern bool statsd_audiotrack(const mediametrics::Item *);
+extern bool statsd_codec(const mediametrics::Item *);
+extern bool statsd_extractor(const mediametrics::Item *);
+extern bool statsd_nuplayer(const mediametrics::Item *);
+extern bool statsd_recorder(const mediametrics::Item *);
 
-extern bool statsd_mediadrm(const MediaAnalyticsItem *);
-extern bool statsd_widevineCDM(const MediaAnalyticsItem *);
-extern bool statsd_drmmanager(const MediaAnalyticsItem *);
+extern bool statsd_mediadrm(const mediametrics::Item *);
+extern bool statsd_widevineCDM(const mediametrics::Item *);
+extern bool statsd_drmmanager(const mediametrics::Item *);
 
 } // namespace android
diff --git a/services/mediametrics/main_mediametrics.cpp b/services/mediametrics/main_mediametrics.cpp
index 4b2a9fa..ec392e2 100644
--- a/services/mediametrics/main_mediametrics.cpp
+++ b/services/mediametrics/main_mediametrics.cpp
@@ -34,10 +34,10 @@
     // to match the service name
     // we're replacing "/system/bin/mediametrics" with "media.metrics"
     // we add a ".", but discard the path components: we finish with a shorter string
-    strcpy(argv[0], MediaAnalyticsService::kServiceName);
+    strcpy(argv[0], MediaMetricsService::kServiceName);
 
     defaultServiceManager()->addService(
-            String16(MediaAnalyticsService::kServiceName), new MediaAnalyticsService());
+            String16(MediaMetricsService::kServiceName), new MediaMetricsService());
 
     sp<ProcessState> processState(ProcessState::self());
     // processState->setThreadPoolMaxThreadCount(8);
diff --git a/services/mediametrics/statsd_audiopolicy.cpp b/services/mediametrics/statsd_audiopolicy.cpp
index 2f934f8..634c801 100644
--- a/services/mediametrics/statsd_audiopolicy.cpp
+++ b/services/mediametrics/statsd_audiopolicy.cpp
@@ -37,12 +37,12 @@
 
 namespace android {
 
-bool statsd_audiopolicy(const MediaAnalyticsItem *item)
+bool statsd_audiopolicy(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
     // these go into the statsd wrapper
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
diff --git a/services/mediametrics/statsd_audiorecord.cpp b/services/mediametrics/statsd_audiorecord.cpp
index 4e2829d..69d1661 100644
--- a/services/mediametrics/statsd_audiorecord.cpp
+++ b/services/mediametrics/statsd_audiorecord.cpp
@@ -37,12 +37,12 @@
 
 namespace android {
 
-bool statsd_audiorecord(const MediaAnalyticsItem *item)
+bool statsd_audiorecord(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
     // these go into the statsd wrapper
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
diff --git a/services/mediametrics/statsd_audiothread.cpp b/services/mediametrics/statsd_audiothread.cpp
index a5bfcba..300151b 100644
--- a/services/mediametrics/statsd_audiothread.cpp
+++ b/services/mediametrics/statsd_audiothread.cpp
@@ -37,12 +37,12 @@
 
 namespace android {
 
-bool statsd_audiothread(const MediaAnalyticsItem *item)
+bool statsd_audiothread(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
     // these go into the statsd wrapper
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
diff --git a/services/mediametrics/statsd_audiotrack.cpp b/services/mediametrics/statsd_audiotrack.cpp
index 9d76d43..397cdf3 100644
--- a/services/mediametrics/statsd_audiotrack.cpp
+++ b/services/mediametrics/statsd_audiotrack.cpp
@@ -37,12 +37,12 @@
 
 namespace android {
 
-bool statsd_audiotrack(const MediaAnalyticsItem *item)
+bool statsd_audiotrack(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
     // these go into the statsd wrapper
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
diff --git a/services/mediametrics/statsd_codec.cpp b/services/mediametrics/statsd_codec.cpp
index fde0bfa..214c51a 100644
--- a/services/mediametrics/statsd_codec.cpp
+++ b/services/mediametrics/statsd_codec.cpp
@@ -37,12 +37,12 @@
 
 namespace android {
 
-bool statsd_codec(const MediaAnalyticsItem *item)
+bool statsd_codec(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
     // these go into the statsd wrapper
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
diff --git a/services/mediametrics/statsd_drm.cpp b/services/mediametrics/statsd_drm.cpp
index 78d0a22..b12f4f3 100644
--- a/services/mediametrics/statsd_drm.cpp
+++ b/services/mediametrics/statsd_drm.cpp
@@ -38,11 +38,11 @@
 namespace android {
 
 // mediadrm
-bool statsd_mediadrm(const MediaAnalyticsItem *item)
+bool statsd_mediadrm(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
@@ -75,11 +75,11 @@
 }
 
 // widevineCDM
-bool statsd_widevineCDM(const MediaAnalyticsItem *item)
+bool statsd_widevineCDM(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
@@ -105,11 +105,11 @@
 }
 
 // drmmanager
-bool statsd_drmmanager(const MediaAnalyticsItem *item)
+bool statsd_drmmanager(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
diff --git a/services/mediametrics/statsd_extractor.cpp b/services/mediametrics/statsd_extractor.cpp
index cc62241..8574358 100644
--- a/services/mediametrics/statsd_extractor.cpp
+++ b/services/mediametrics/statsd_extractor.cpp
@@ -37,12 +37,12 @@
 
 namespace android {
 
-bool statsd_extractor(const MediaAnalyticsItem *item)
+bool statsd_extractor(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
     // these go into the statsd wrapper
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
diff --git a/services/mediametrics/statsd_nuplayer.cpp b/services/mediametrics/statsd_nuplayer.cpp
index 9db1e81..df7e59f 100644
--- a/services/mediametrics/statsd_nuplayer.cpp
+++ b/services/mediametrics/statsd_nuplayer.cpp
@@ -41,12 +41,12 @@
  *  handles nuplayer AND nuplayer2
  *  checks for the union of what the two players generate
  */
-bool statsd_nuplayer(const MediaAnalyticsItem *item)
+bool statsd_nuplayer(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
     // these go into the statsd wrapper
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
diff --git a/services/mediametrics/statsd_recorder.cpp b/services/mediametrics/statsd_recorder.cpp
index 972a221..4de1746 100644
--- a/services/mediametrics/statsd_recorder.cpp
+++ b/services/mediametrics/statsd_recorder.cpp
@@ -37,12 +37,12 @@
 
 namespace android {
 
-bool statsd_recorder(const MediaAnalyticsItem *item)
+bool statsd_recorder(const mediametrics::Item *item)
 {
     if (item == NULL) return false;
 
     // these go into the statsd wrapper
-    const nsecs_t timestamp = MediaAnalyticsService::roundTime(item->getTimestamp());
+    const nsecs_t timestamp = MediaMetricsService::roundTime(item->getTimestamp());
     std::string pkgName = item->getPkgName();
     int64_t pkgVersionCode = item->getPkgVersionCode();
     int64_t mediaApexVersion = 0;
diff --git a/services/mediametrics/tests/mediametrics_tests.cpp b/services/mediametrics/tests/mediametrics_tests.cpp
index 808da7b..285a1ba 100644
--- a/services/mediametrics/tests/mediametrics_tests.cpp
+++ b/services/mediametrics/tests/mediametrics_tests.cpp
@@ -22,7 +22,7 @@
 #include <stdio.h>
 
 #include <gtest/gtest.h>
-#include <media/MediaAnalyticsItem.h>
+#include <media/MediaMetricsItem.h>
 
 using namespace android;
 
@@ -36,11 +36,11 @@
 }
 
 TEST(mediametrics_tests, instantiate) {
-  sp mediaMetrics = new MediaAnalyticsService();
+  sp mediaMetrics = new MediaMetricsService();
   status_t status;
 
   // random keys ignored when empty
-  std::unique_ptr<MediaAnalyticsItem> random_key(MediaAnalyticsItem::create("random_key"));
+  std::unique_ptr<mediametrics::Item> random_key(mediametrics::Item::create("random_key"));
   status = mediaMetrics->submit(random_key.get());
   ASSERT_EQ(PERMISSION_DENIED, status);
 
@@ -50,7 +50,7 @@
   ASSERT_EQ(PERMISSION_DENIED, status);
 
   // known keys ignored if empty
-  std::unique_ptr<MediaAnalyticsItem> audiotrack_key(MediaAnalyticsItem::create("audiotrack"));
+  std::unique_ptr<mediametrics::Item> audiotrack_key(mediametrics::Item::create("audiotrack"));
   status = mediaMetrics->submit(audiotrack_key.get());
   ASSERT_EQ(BAD_VALUE, status);
 
@@ -62,7 +62,7 @@
 
   /*
   // fluent style that goes directly to mediametrics
-  ASSERT_EQ(true, MediaAnalyticsItem("audiorecord")
+  ASSERT_EQ(true, mediametrics::Item("audiorecord")
                      .setInt32("value", 2)
                      .addInt32("bar", 1)
                      .addInt32("value", 3)
@@ -73,7 +73,7 @@
 }
 
 TEST(mediametrics_tests, item_manipulation) {
-  MediaAnalyticsItem item("audiorecord");
+  mediametrics::Item item("audiorecord");
 
   item.setInt32("value", 2).addInt32("bar", 3).addInt32("value", 4);
 
@@ -128,14 +128,14 @@
   printf("item: %s\n", item.toString().c_str());
   fflush(stdout);
 
-  sp mediaMetrics = new MediaAnalyticsService();
+  sp mediaMetrics = new MediaMetricsService();
   status_t status = mediaMetrics->submit(&item);
   ASSERT_EQ(NO_ERROR, status);
   mediaMetrics->dump(fileno(stdout), {} /* args */);
 }
 
 TEST(mediametrics_tests, superbig_item) {
-  MediaAnalyticsItem item("TheBigOne");
+  mediametrics::Item item("TheBigOne");
   constexpr size_t count = 10000;
 
   for (size_t i = 0; i < count; ++i) {
@@ -149,7 +149,7 @@
 }
 
 TEST(mediametrics_tests, superbig_item_removal) {
-  MediaAnalyticsItem item("TheOddBigOne");
+  mediametrics::Item item("TheOddBigOne");
   constexpr size_t count = 10000;
 
   for (size_t i = 0; i < count; ++i) {
@@ -170,7 +170,7 @@
 }
 
 TEST(mediametrics_tests, superbig_item_removal2) {
-  MediaAnalyticsItem item("TheOne");
+  mediametrics::Item item("TheOne");
   constexpr size_t count = 10000;
 
   for (size_t i = 0; i < count; ++i) {
@@ -191,7 +191,7 @@
 }
 
 TEST(mediametrics_tests, item_transmutation) {
-  MediaAnalyticsItem item("Alchemist's Stone");
+  mediametrics::Item item("Alchemist's Stone");
 
   item.setInt64("convert", 123);
   int64_t i64;
@@ -207,7 +207,7 @@
 }
 
 TEST(mediametrics_tests, item_binderization) {
-  MediaAnalyticsItem item;
+  mediametrics::Item item;
   item.setInt32("i32", 1)
       .setInt64("i64", 2)
       .setDouble("double", 3.1)
@@ -218,14 +218,14 @@
   item.writeToParcel(&p);
 
   p.setDataPosition(0); // rewind for reading
-  MediaAnalyticsItem item2;
+  mediametrics::Item item2;
   item2.readFromParcel(p);
 
   ASSERT_EQ(item, item2);
 }
 
 TEST(mediametrics_tests, item_byteserialization) {
-  MediaAnalyticsItem item;
+  mediametrics::Item item;
   item.setInt32("i32", 1)
       .setInt64("i64", 2)
       .setDouble("double", 3.1)
@@ -237,7 +237,7 @@
   ASSERT_EQ(0, item.writeToByteString(&data, &length));
   ASSERT_GT(length, (size_t)0);
 
-  MediaAnalyticsItem item2;
+  mediametrics::Item item2;
   item2.readFromByteString(data, length);
 
   printf("item: %s\n", item.toString().c_str());
@@ -248,7 +248,7 @@
 }
 
 TEST(mediametrics_tests, item_iteration) {
-  MediaAnalyticsItem item;
+  mediametrics::Item item;
   item.setInt32("i32", 1)
       .setInt64("i64", 2)
       .setDouble("double", 3.125)
@@ -292,7 +292,7 @@
 }
 
 TEST(mediametrics_tests, item_expansion) {
-  mediametrics::Item<1> item("I");
+  mediametrics::LogItem<1> item("I");
   item.set("i32", (int32_t)1)
       .set("i64", (int64_t)2)
       .set("double", (double)3.125)
@@ -300,7 +300,7 @@
       .set("rate", std::pair<int64_t, int64_t>(11, 12));
   ASSERT_TRUE(item.updateHeader());
 
-  MediaAnalyticsItem item2;
+  mediametrics::Item item2;
   item2.readFromByteString(item.getBuffer(), item.getLength());
   ASSERT_EQ((pid_t)-1, item2.getPid());
   ASSERT_EQ((uid_t)-1, item2.getUid());
@@ -341,7 +341,7 @@
 }
 
 TEST(mediametrics_tests, item_expansion2) {
-  mediametrics::Item<1> item("Bigly");
+  mediametrics::LogItem<1> item("Bigly");
   item.setPid(123)
       .setUid(456);
   constexpr size_t count = 10000;
@@ -352,7 +352,7 @@
   }
   ASSERT_TRUE(item.updateHeader());
 
-  MediaAnalyticsItem item2;
+  mediametrics::Item item2;
   printf("begin buffer:%p  length:%zu\n", item.getBuffer(), item.getLength());
   fflush(stdout);
   item2.readFromByteString(item.getBuffer(), item.getLength());
@@ -367,7 +367,7 @@
 }
 
 TEST(mediametrics_tests, time_machine_storage) {
-  auto item = std::make_shared<MediaAnalyticsItem>("Key");
+  auto item = std::make_shared<mediametrics::Item>("Key");
   (*item).set("i32", (int32_t)1)
       .set("i64", (int64_t)2)
       .set("double", (double)3.125)
@@ -414,21 +414,21 @@
 }
 
 TEST(mediametrics_tests, time_machine_remote_key) {
-  auto item = std::make_shared<MediaAnalyticsItem>("Key1");
+  auto item = std::make_shared<mediametrics::Item>("Key1");
   (*item).set("one", (int32_t)1)
          .set("two", (int32_t)2);
 
   android::mediametrics::TimeMachine timeMachine;
   ASSERT_EQ(NO_ERROR, timeMachine.put(item, true));
 
-  auto item2 = std::make_shared<MediaAnalyticsItem>("Key2");
+  auto item2 = std::make_shared<mediametrics::Item>("Key2");
   (*item2).set("three", (int32_t)3)
          .set("[Key1]four", (int32_t)4)   // affects Key1
          .set("[Key1]five", (int32_t)5);  // affects key1
 
   ASSERT_EQ(NO_ERROR, timeMachine.put(item2, true));
 
-  auto item3 = std::make_shared<MediaAnalyticsItem>("Key2");
+  auto item3 = std::make_shared<mediametrics::Item>("Key2");
   (*item3).set("six", (int32_t)6)
          .set("[Key1]seven", (int32_t)7);   // affects Key1
 
@@ -464,7 +464,7 @@
 }
 
 TEST(mediametrics_tests, time_machine_gc) {
-  auto item = std::make_shared<MediaAnalyticsItem>("Key1");
+  auto item = std::make_shared<mediametrics::Item>("Key1");
   (*item).set("one", (int32_t)1)
          .set("two", (int32_t)2)
          .setTimestamp(10);
@@ -477,7 +477,7 @@
 
   ASSERT_EQ((size_t)1, timeMachine.size());
 
-  auto item2 = std::make_shared<MediaAnalyticsItem>("Key2");
+  auto item2 = std::make_shared<mediametrics::Item>("Key2");
   (*item2).set("three", (int32_t)3)
          .set("[Key1]three", (int32_t)3)
          .setTimestamp(11);
@@ -487,7 +487,7 @@
 
   //printf("Before\n%s\n\n", timeMachine.dump().c_str());
 
-  auto item3 = std::make_shared<MediaAnalyticsItem>("Key3");
+  auto item3 = std::make_shared<mediametrics::Item>("Key3");
   (*item3).set("six", (int32_t)6)
           .set("[Key1]four", (int32_t)4)   // affects Key1
           .set("[Key1]five", (int32_t)5)   // affects key1
@@ -515,7 +515,7 @@
 }
 
 TEST(mediametrics_tests, transaction_log_gc) {
-  auto item = std::make_shared<MediaAnalyticsItem>("Key1");
+  auto item = std::make_shared<mediametrics::Item>("Key1");
   (*item).set("one", (int32_t)1)
          .set("two", (int32_t)2)
          .setTimestamp(10);
@@ -526,7 +526,7 @@
   ASSERT_EQ(NO_ERROR, transactionLog.put(item));
   ASSERT_EQ((size_t)1, transactionLog.size());
 
-  auto item2 = std::make_shared<MediaAnalyticsItem>("Key2");
+  auto item2 = std::make_shared<mediametrics::Item>("Key2");
   (*item2).set("three", (int32_t)3)
          .set("[Key1]three", (int32_t)3)
          .setTimestamp(11);
@@ -534,7 +534,7 @@
   ASSERT_EQ(NO_ERROR, transactionLog.put(item2));
   ASSERT_EQ((size_t)2, transactionLog.size());
 
-  auto item3 = std::make_shared<MediaAnalyticsItem>("Key3");
+  auto item3 = std::make_shared<mediametrics::Item>("Key3");
   (*item3).set("six", (int32_t)6)
           .set("[Key1]four", (int32_t)4)   // affects Key1
           .set("[Key1]five", (int32_t)5)   // affects key1
@@ -545,16 +545,16 @@
 }
 
 TEST(mediametrics_tests, audio_analytics_permission) {
-  auto item = std::make_shared<MediaAnalyticsItem>("audio.1");
+  auto item = std::make_shared<mediametrics::Item>("audio.1");
   (*item).set("one", (int32_t)1)
          .set("two", (int32_t)2)
          .setTimestamp(10);
 
-  auto item2 = std::make_shared<MediaAnalyticsItem>("audio.1");
+  auto item2 = std::make_shared<mediametrics::Item>("audio.1");
   (*item2).set("three", (int32_t)3)
          .setTimestamp(11);
 
-  auto item3 = std::make_shared<MediaAnalyticsItem>("audio.2");
+  auto item3 = std::make_shared<mediametrics::Item>("audio.2");
   (*item3).set("four", (int32_t)4)
           .setTimestamp(12);
 
@@ -577,16 +577,16 @@
 }
 
 TEST(mediametrics_tests, audio_analytics_dump) {
-  auto item = std::make_shared<MediaAnalyticsItem>("audio.1");
+  auto item = std::make_shared<mediametrics::Item>("audio.1");
   (*item).set("one", (int32_t)1)
          .set("two", (int32_t)2)
          .setTimestamp(10);
 
-  auto item2 = std::make_shared<MediaAnalyticsItem>("audio.1");
+  auto item2 = std::make_shared<mediametrics::Item>("audio.1");
   (*item2).set("three", (int32_t)3)
          .setTimestamp(11);
 
-  auto item3 = std::make_shared<MediaAnalyticsItem>("audio.2");
+  auto item3 = std::make_shared<mediametrics::Item>("audio.2");
   (*item3).set("four", (int32_t)4)
           .setTimestamp(12);
 
diff --git a/services/minijail/Android.bp b/services/minijail/Android.bp
index 07a94cc..0713a87 100644
--- a/services/minijail/Android.bp
+++ b/services/minijail/Android.bp
@@ -17,10 +17,14 @@
 cc_library_shared {
     name: "libavservices_minijail",
     defaults: ["libavservices_minijail_defaults"],
+    vendor_available: true,
     export_include_dirs: ["."],
 }
 
-// Small library for media.extractor and media.codec sandboxing.
+// By adding "vendor_available: true" to "libavservices_minijail", we don't
+// need to have "libavservices_minijail_vendor" any longer.
+// "libavservices_minijail_vendor" will be removed, once we replace it with
+// "libavservices_minijail" in all vendor modules. (b/146313710)
 cc_library_shared {
     name: "libavservices_minijail_vendor",
     vendor: true,
diff --git a/services/soundtrigger/Android.bp b/services/soundtrigger/Android.bp
deleted file mode 100644
index 600f4a3..0000000
--- a/services/soundtrigger/Android.bp
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2014 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.
-
-cc_library_shared {
-    name: "libsoundtriggerservice",
-
-    srcs: [
-        "SoundTriggerHwService.cpp",
-        "SoundTriggerHalHidl.cpp",
-    ],
-
-    shared_libs: [
-        "liblog",
-        "libutils",
-        "libbinder",
-        "libcutils",
-        "libhardware",
-        "libsoundtrigger",
-        "libaudioclient",
-        "libaudioutils",
-        "libmediautils",
-
-        "libhidlbase",
-        "libhidlmemory",
-        "libbase",
-        "libaudiohal",
-        "libaudiohal_deathhandler",
-        "android.hardware.soundtrigger@2.0",
-        "android.hardware.soundtrigger@2.1",
-        "android.hardware.soundtrigger@2.2",
-        "android.hardware.soundtrigger@2.3",
-        "android.hardware.audio.common@2.0",
-        "android.hidl.allocator@1.0",
-        "android.hidl.memory@1.0",
-    ],
-
-    include_dirs: ["frameworks/av/services/audioflinger"],
-
-    cflags: [
-        "-Wall",
-        "-Werror",
-    ],
-}
diff --git a/services/soundtrigger/OWNERS b/services/soundtrigger/OWNERS
deleted file mode 100644
index e83f6b9..0000000
--- a/services/soundtrigger/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-elaurent@google.com
-thorntonc@google.com
diff --git a/services/soundtrigger/SoundTriggerHalHidl.cpp b/services/soundtrigger/SoundTriggerHalHidl.cpp
deleted file mode 100644
index b1d34df..0000000
--- a/services/soundtrigger/SoundTriggerHalHidl.cpp
+++ /dev/null
@@ -1,999 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-#define LOG_TAG "SoundTriggerHalHidl"
-//#define LOG_NDEBUG 0
-
-#include <android/hidl/allocator/1.0/IAllocator.h>
-#include <media/audiohal/hidl/HalDeathHandler.h>
-#include <utils/Log.h>
-#include "SoundTriggerHalHidl.h"
-#include <hidlmemory/mapping.h>
-#include <hwbinder/IPCThreadState.h>
-#include <hwbinder/ProcessState.h>
-
-namespace android {
-
-using ::android::hardware::ProcessState;
-using ::android::hardware::Return;
-using ::android::hardware::Status;
-using ::android::hardware::Void;
-using ::android::hardware::audio::common::V2_0::AudioDevice;
-using ::android::hardware::hidl_memory;
-using ::android::hidl::allocator::V1_0::IAllocator;
-using ::android::hidl::memory::V1_0::IMemory;
-
-namespace {
-
-// Backs up by the vector with the contents of shared memory.
-// It is assumed that the passed hidl_vector is empty, so it's
-// not cleared if the memory is a null object.
-// The caller needs to keep the returned sp<IMemory> as long as
-// the data is needed.
-std::pair<bool, sp<IMemory>> memoryAsVector(const hidl_memory& m, hidl_vec<uint8_t>* vec) {
-    sp<IMemory> memory;
-    if (m.size() == 0) {
-        return std::make_pair(true, memory);
-    }
-    memory = mapMemory(m);
-    if (memory != nullptr) {
-        memory->read();
-        vec->setToExternal(static_cast<uint8_t*>(static_cast<void*>(memory->getPointer())),
-                memory->getSize());
-        return std::make_pair(true, memory);
-    }
-    ALOGE("%s: Could not map HIDL memory to IMemory", __func__);
-    return std::make_pair(false, memory);
-}
-
-// Moves the data from the vector into allocated shared memory,
-// emptying the vector.
-// It is assumed that the passed hidl_memory is a null object, so it's
-// not reset if the vector is empty.
-// The caller needs to keep the returned sp<IMemory> as long as
-// the data is needed.
-std::pair<bool, sp<IMemory>> moveVectorToMemory(hidl_vec<uint8_t>* v, hidl_memory* mem) {
-    sp<IMemory> memory;
-    if (v->size() == 0) {
-        return std::make_pair(true, memory);
-    }
-    sp<IAllocator> ashmem = IAllocator::getService("ashmem");
-    if (ashmem == 0) {
-        ALOGE("Failed to retrieve ashmem allocator service");
-        return std::make_pair(false, memory);
-    }
-    bool success = false;
-    Return<void> r = ashmem->allocate(v->size(), [&](bool s, const hidl_memory& m) {
-        success = s;
-        if (success) *mem = m;
-    });
-    if (r.isOk() && success) {
-        memory = hardware::mapMemory(*mem);
-        if (memory != 0) {
-            memory->update();
-            memcpy(memory->getPointer(), v->data(), v->size());
-            memory->commit();
-            v->resize(0);
-            return std::make_pair(true, memory);
-        } else {
-            ALOGE("Failed to map allocated ashmem");
-        }
-    } else {
-        ALOGE("Failed to allocate %llu bytes from ashmem", (unsigned long long)v->size());
-    }
-    return std::make_pair(false, memory);
-}
-
-}  // namespace
-
-/* static */
-sp<SoundTriggerHalInterface> SoundTriggerHalInterface::connectModule(const char *moduleName)
-{
-    return new SoundTriggerHalHidl(moduleName);
-}
-
-int SoundTriggerHalHidl::getProperties(struct sound_trigger_properties *properties)
-{
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (soundtrigger == 0) {
-        return -ENODEV;
-    }
-
-    ISoundTriggerHw::Properties halProperties;
-    Return<void> hidlReturn;
-    int ret;
-    {
-        AutoMutex lock(mHalLock);
-        hidlReturn = soundtrigger->getProperties([&](int rc, auto res) {
-            ret = rc;
-            halProperties = res;
-            ALOGI("getProperties res implementor %s", res.implementor.c_str());
-        });
-    }
-
-    if (hidlReturn.isOk()) {
-        if (ret == 0) {
-            convertPropertiesFromHal(properties, &halProperties);
-        }
-    } else {
-        ALOGE("getProperties error %s", hidlReturn.description().c_str());
-        return FAILED_TRANSACTION;
-    }
-    ALOGI("getProperties ret %d", ret);
-    return ret;
-}
-
-int SoundTriggerHalHidl::loadSoundModel(struct sound_trigger_sound_model *sound_model,
-                        sound_model_callback_t callback,
-                        void *cookie,
-                        sound_model_handle_t *handle)
-{
-    if (handle == NULL) {
-        return -EINVAL;
-    }
-
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (soundtrigger == 0) {
-        return -ENODEV;
-    }
-
-    uint32_t modelId;
-    {
-        AutoMutex lock(mLock);
-        do {
-            modelId = nextUniqueId();
-            ALOGI("loadSoundModel modelId %u", modelId);
-            sp<SoundModel> model = mSoundModels.valueFor(modelId);
-            ALOGI("loadSoundModel model %p", model.get());
-        } while (mSoundModels.valueFor(modelId) != 0 && modelId != 0);
-    }
-    LOG_ALWAYS_FATAL_IF(modelId == 0,
-                        "loadSoundModel(): wrap around in sound model IDs, num loaded models %zd",
-                        mSoundModels.size());
-
-    Return<void> hidlReturn;
-    int ret;
-    SoundModelHandle halHandle;
-    sp<V2_1_ISoundTriggerHw> soundtrigger_2_1 = toService2_1(soundtrigger);
-    sp<V2_2_ISoundTriggerHw> soundtrigger_2_2 = toService2_2(soundtrigger);
-    if (sound_model->type == SOUND_MODEL_TYPE_KEYPHRASE) {
-        if (soundtrigger_2_2) {
-            V2_2_ISoundTriggerHw::PhraseSoundModel halSoundModel;
-            auto result = convertPhraseSoundModelToHal(&halSoundModel, sound_model);
-            if (result.first) {
-                AutoMutex lock(mHalLock);
-                hidlReturn = soundtrigger_2_2->loadPhraseSoundModel_2_1(
-                        halSoundModel,
-                        this, modelId, [&](int32_t retval, auto res) {
-                            ret = retval;
-                            halHandle = res;
-                        });
-            } else {
-                return NO_MEMORY;
-            }
-        } else if (soundtrigger_2_1) {
-            V2_1_ISoundTriggerHw::PhraseSoundModel halSoundModel;
-            auto result = convertPhraseSoundModelToHal(&halSoundModel, sound_model);
-            if (result.first) {
-                AutoMutex lock(mHalLock);
-                hidlReturn = soundtrigger_2_1->loadPhraseSoundModel_2_1(
-                        halSoundModel,
-                        this, modelId, [&](int32_t retval, auto res) {
-                            ret = retval;
-                            halHandle = res;
-                        });
-            } else {
-                return NO_MEMORY;
-            }
-        } else {
-            ISoundTriggerHw::PhraseSoundModel halSoundModel;
-            convertPhraseSoundModelToHal(&halSoundModel, sound_model);
-            AutoMutex lock(mHalLock);
-            hidlReturn = soundtrigger->loadPhraseSoundModel(
-                    halSoundModel,
-                    this, modelId, [&](int32_t retval, auto res) {
-                        ret = retval;
-                        halHandle = res;
-                    });
-        }
-    } else {
-        if (soundtrigger_2_2) {
-            V2_2_ISoundTriggerHw::SoundModel halSoundModel;
-            auto result = convertSoundModelToHal(&halSoundModel, sound_model);
-            if (result.first) {
-                AutoMutex lock(mHalLock);
-                hidlReturn = soundtrigger_2_2->loadSoundModel_2_1(halSoundModel,
-                        this, modelId, [&](int32_t retval, auto res) {
-                            ret = retval;
-                            halHandle = res;
-                        });
-            } else {
-                return NO_MEMORY;
-            }
-        } else if (soundtrigger_2_1) {
-            V2_1_ISoundTriggerHw::SoundModel halSoundModel;
-            auto result = convertSoundModelToHal(&halSoundModel, sound_model);
-            if (result.first) {
-                AutoMutex lock(mHalLock);
-                hidlReturn = soundtrigger_2_1->loadSoundModel_2_1(halSoundModel,
-                        this, modelId, [&](int32_t retval, auto res) {
-                            ret = retval;
-                            halHandle = res;
-                        });
-            } else {
-                return NO_MEMORY;
-            }
-        } else {
-            ISoundTriggerHw::SoundModel halSoundModel;
-            convertSoundModelToHal(&halSoundModel, sound_model);
-            AutoMutex lock(mHalLock);
-            hidlReturn = soundtrigger->loadSoundModel(halSoundModel,
-                    this, modelId, [&](int32_t retval, auto res) {
-                        ret = retval;
-                        halHandle = res;
-                    });
-        }
-    }
-
-    if (hidlReturn.isOk()) {
-        if (ret == 0) {
-            AutoMutex lock(mLock);
-            *handle = (sound_model_handle_t)modelId;
-            sp<SoundModel> model = new SoundModel(*handle, callback, cookie, halHandle);
-            mSoundModels.add(*handle, model);
-        }
-    } else {
-        ALOGE("loadSoundModel error %s", hidlReturn.description().c_str());
-        return FAILED_TRANSACTION;
-    }
-
-    return ret;
-}
-
-int SoundTriggerHalHidl::unloadSoundModel(sound_model_handle_t handle)
-{
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (soundtrigger == 0) {
-        return -ENODEV;
-    }
-
-    sp<SoundModel> model = removeModel(handle);
-    if (model == 0) {
-        ALOGE("unloadSoundModel model not found for handle %u", handle);
-        return -EINVAL;
-    }
-
-    Return<int32_t> hidlReturn(0);
-    {
-        AutoMutex lock(mHalLock);
-        hidlReturn = soundtrigger->unloadSoundModel(model->mHalHandle);
-    }
-
-    if (!hidlReturn.isOk()) {
-        ALOGE("unloadSoundModel error %s", hidlReturn.description().c_str());
-        return FAILED_TRANSACTION;
-    }
-
-    return hidlReturn;
-}
-
-int SoundTriggerHalHidl::startRecognition(sound_model_handle_t handle,
-                         const struct sound_trigger_recognition_config *config,
-                         recognition_callback_t callback,
-                         void *cookie)
-{
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (soundtrigger == 0) {
-        return -ENODEV;
-    }
-
-    sp<SoundModel> model = getModel(handle);
-    if (model == 0) {
-        ALOGE("startRecognition model not found for handle %u", handle);
-        return -EINVAL;
-    }
-
-    model->mRecognitionCallback = callback;
-    model->mRecognitionCookie = cookie;
-
-    sp<V2_1_ISoundTriggerHw> soundtrigger_2_1 = toService2_1(soundtrigger);
-    sp<V2_2_ISoundTriggerHw> soundtrigger_2_2 = toService2_2(soundtrigger);
-    Return<int32_t> hidlReturn(0);
-
-    if (soundtrigger_2_2) {
-        V2_2_ISoundTriggerHw::RecognitionConfig halConfig;
-        auto result = convertRecognitionConfigToHal(&halConfig, config);
-        if (result.first) {
-            AutoMutex lock(mHalLock);
-            hidlReturn = soundtrigger_2_2->startRecognition_2_1(
-                    model->mHalHandle, halConfig, this, handle);
-        } else {
-            return NO_MEMORY;
-        }
-    } else if (soundtrigger_2_1) {
-        V2_1_ISoundTriggerHw::RecognitionConfig halConfig;
-        auto result = convertRecognitionConfigToHal(&halConfig, config);
-        if (result.first) {
-            AutoMutex lock(mHalLock);
-            hidlReturn = soundtrigger_2_1->startRecognition_2_1(
-                    model->mHalHandle, halConfig, this, handle);
-        } else {
-            return NO_MEMORY;
-        }
-    } else {
-        ISoundTriggerHw::RecognitionConfig halConfig;
-        convertRecognitionConfigToHal(&halConfig, config);
-        {
-            AutoMutex lock(mHalLock);
-            hidlReturn = soundtrigger->startRecognition(model->mHalHandle, halConfig, this, handle);
-        }
-    }
-
-    if (!hidlReturn.isOk()) {
-        ALOGE("startRecognition error %s", hidlReturn.description().c_str());
-        return FAILED_TRANSACTION;
-    }
-    return hidlReturn;
-}
-
-int SoundTriggerHalHidl::stopRecognition(sound_model_handle_t handle)
-{
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (soundtrigger == 0) {
-        return -ENODEV;
-    }
-
-    sp<SoundModel> model = getModel(handle);
-    if (model == 0) {
-        ALOGE("stopRecognition model not found for handle %u", handle);
-        return -EINVAL;
-    }
-
-    Return<int32_t> hidlReturn(0);
-    {
-        AutoMutex lock(mHalLock);
-        hidlReturn = soundtrigger->stopRecognition(model->mHalHandle);
-    }
-
-    if (!hidlReturn.isOk()) {
-        ALOGE("stopRecognition error %s", hidlReturn.description().c_str());
-        return FAILED_TRANSACTION;
-    }
-    return hidlReturn;
-}
-
-int SoundTriggerHalHidl::stopAllRecognitions()
-{
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (soundtrigger == 0) {
-        return -ENODEV;
-    }
-
-    Return<int32_t> hidlReturn(0);
-    {
-        AutoMutex lock(mHalLock);
-        hidlReturn = soundtrigger->stopAllRecognitions();
-    }
-
-    if (!hidlReturn.isOk()) {
-        ALOGE("stopAllRecognitions error %s", hidlReturn.description().c_str());
-        return FAILED_TRANSACTION;
-    }
-    return hidlReturn;
-}
-
-int SoundTriggerHalHidl::getModelState(sound_model_handle_t handle)
-{
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (soundtrigger == 0) {
-        return -ENODEV;
-    }
-
-    sp<V2_2_ISoundTriggerHw> soundtrigger_2_2 = toService2_2(soundtrigger);
-    if (soundtrigger_2_2 == 0) {
-        ALOGE("getModelState not supported");
-        return -ENODEV;
-    }
-
-    sp<SoundModel> model = getModel(handle);
-    if (model == 0) {
-        ALOGE("getModelState model not found for handle %u", handle);
-        return -EINVAL;
-    }
-
-    int ret = NO_ERROR;
-    Return<int32_t> hidlReturn(0);
-    {
-        AutoMutex lock(mHalLock);
-        hidlReturn = soundtrigger_2_2->getModelState(model->mHalHandle);
-    }
-    if (!hidlReturn.isOk()) {
-        ALOGE("getModelState error %s", hidlReturn.description().c_str());
-        ret = FAILED_TRANSACTION;
-    }
-    return ret;
-}
-
-int SoundTriggerHalHidl::setParameter(sound_model_handle_t handle,
-                                sound_trigger_model_parameter_t model_param, int32_t value)
-{
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (!soundtrigger) {
-        return -ENODEV;
-    }
-
-    sp<V2_3_ISoundTriggerHw> soundtrigger_2_3 = toService2_3(soundtrigger);
-    if (!soundtrigger_2_3) {
-        ALOGE("setParameter not supported");
-        return -ENOSYS;
-    }
-
-    sp<SoundModel> model = getModel(handle);
-    if (!model) {
-        ALOGE("setParameter model not found for handle %u", handle);
-        return -EINVAL;
-    }
-
-    V2_3_ModelParameter halParam;
-    convertModelParameterToHal(&halParam, model_param);
-
-    Return<int32_t> hidlReturn(0);
-    {
-        AutoMutex lock(mHalLock);
-        hidlReturn = soundtrigger_2_3->setParameter(model->mHalHandle, halParam, value);
-    }
-    if (!hidlReturn.isOk()) {
-        ALOGE("getModelState error %s", hidlReturn.description().c_str());
-        return FAILED_TRANSACTION;
-    }
-
-    return hidlReturn;
-}
-
-int SoundTriggerHalHidl::getParameter(sound_model_handle_t handle,
-                                sound_trigger_model_parameter_t model_param, int32_t* value)
-{
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (!soundtrigger) {
-        return -ENODEV;
-    }
-
-    sp<V2_3_ISoundTriggerHw> soundtrigger_2_3 = toService2_3(soundtrigger);
-    if (!soundtrigger_2_3) {
-        ALOGE("getParameter not supported");
-        return -ENOSYS;
-    }
-
-    if (value == NULL) {
-        ALOGE("getParameter invalid value pointer");
-        return -EINVAL;
-    }
-
-    sp<SoundModel> model = getModel(handle);
-    if (!model) {
-        ALOGE("getParameter model not found for handle %u", handle);
-        return -EINVAL;
-    }
-
-    V2_3_ModelParameter halParam;
-    convertModelParameterToHal(&halParam, model_param);
-
-    Return<void> hidlReturn;
-    int32_t hidlStatus;
-    int32_t hidlValue;
-    {
-        AutoMutex lock(mHalLock);
-        hidlReturn = soundtrigger_2_3->getParameter(model->mHalHandle, halParam,
-            [&](int32_t retStatus, int32_t retValue) {
-                hidlStatus = retStatus;
-                hidlValue = retValue;
-            });
-    }
-    if (!hidlReturn.isOk()) {
-        ALOGE("getModelState error %s", hidlReturn.description().c_str());
-        return FAILED_TRANSACTION;
-    }
-
-    *value = hidlValue;
-    return hidlStatus;
-}
-
-int SoundTriggerHalHidl::queryParameter(sound_model_handle_t handle,
-                    sound_trigger_model_parameter_t model_param,
-                    sound_trigger_model_parameter_range_t* param_range)
-{
-    sp<ISoundTriggerHw> soundtrigger = getService();
-    if (!soundtrigger) {
-        return -ENODEV;
-    }
-
-    sp<V2_3_ISoundTriggerHw> soundtrigger_2_3 = toService2_3(soundtrigger);
-    if (!soundtrigger_2_3) {
-        ALOGE("queryParameter not supported");
-        return -ENOSYS;
-    }
-
-    sp<SoundModel> model = getModel(handle);
-    if (!model) {
-        ALOGE("queryParameter model not found for handle %u", handle);
-        return -EINVAL;
-    }
-
-    V2_3_ModelParameter halParam;
-    convertModelParameterToHal(&halParam, model_param);
-
-    Return<void> hidlReturn;
-    int32_t hidlStatus;
-    V2_3_OptionalModelParameterRange hidlValue;
-    {
-        AutoMutex lock(mHalLock);
-        hidlReturn = soundtrigger_2_3->queryParameter(model->mHalHandle, halParam,
-            [&](int32_t retStatus, V2_3_OptionalModelParameterRange retValue) {
-                hidlStatus = retStatus;
-                hidlValue = retValue;
-            });
-    }
-    if (!hidlReturn.isOk()) {
-        ALOGE("queryParameter error %s", hidlReturn.description().c_str());
-        return FAILED_TRANSACTION;
-    }
-
-    if (hidlStatus != 0) {
-        ALOGE("queryParameter error code: %d", hidlStatus);
-        return hidlStatus;
-    }
-
-    if (hidlValue.getDiscriminator() ==
-            V2_3_OptionalModelParameterRange::hidl_discriminator::noinit) {
-        return -1;
-    }
-
-    param_range->start = hidlValue.range().start;
-    param_range->end = hidlValue.range().end;
-
-    return 0;
-}
-
-SoundTriggerHalHidl::SoundTriggerHalHidl(const char *moduleName)
-    : mModuleName(moduleName), mNextUniqueId(1)
-{
-    LOG_ALWAYS_FATAL_IF(strcmp(mModuleName, "primary") != 0,
-            "Treble soundtrigger only supports primary module");
-}
-
-SoundTriggerHalHidl::~SoundTriggerHalHidl()
-{
-}
-
-sp<ISoundTriggerHw> SoundTriggerHalHidl::getService()
-{
-    AutoMutex lock(mLock);
-    if (mISoundTrigger == 0) {
-        if (mModuleName == NULL) {
-            mModuleName = "primary";
-        }
-        mISoundTrigger = ISoundTriggerHw::getService();
-        if (mISoundTrigger != 0) {
-            mISoundTrigger->linkToDeath(HalDeathHandler::getInstance(), 0 /*cookie*/);
-        }
-    }
-    return mISoundTrigger;
-}
-
-sp<V2_1_ISoundTriggerHw> SoundTriggerHalHidl::toService2_1(const sp<ISoundTriggerHw>& s)
-{
-    auto castResult_2_1 = V2_1_ISoundTriggerHw::castFrom(s);
-    return castResult_2_1.isOk() ? static_cast<sp<V2_1_ISoundTriggerHw>>(castResult_2_1) : nullptr;
-}
-
-sp<V2_2_ISoundTriggerHw> SoundTriggerHalHidl::toService2_2(const sp<ISoundTriggerHw>& s)
-{
-    auto castResult_2_2 = V2_2_ISoundTriggerHw::castFrom(s);
-    return castResult_2_2.isOk() ? static_cast<sp<V2_2_ISoundTriggerHw>>(castResult_2_2) : nullptr;
-}
-
-sp<V2_3_ISoundTriggerHw> SoundTriggerHalHidl::toService2_3(const sp<ISoundTriggerHw>& s)
-{
-    auto castResult_3_0 = V2_3_ISoundTriggerHw::castFrom(s);
-    return castResult_3_0.isOk() ? static_cast<sp<V2_3_ISoundTriggerHw>>(castResult_3_0) : nullptr;
-}
-
-sp<SoundTriggerHalHidl::SoundModel> SoundTriggerHalHidl::getModel(sound_model_handle_t handle)
-{
-    AutoMutex lock(mLock);
-    return mSoundModels.valueFor(handle);
-}
-
-sp<SoundTriggerHalHidl::SoundModel> SoundTriggerHalHidl::removeModel(sound_model_handle_t handle)
-{
-    AutoMutex lock(mLock);
-    sp<SoundModel> model = mSoundModels.valueFor(handle);
-    mSoundModels.removeItem(handle);
-    return model;
-}
-
-uint32_t SoundTriggerHalHidl::nextUniqueId()
-{
-    return (uint32_t) atomic_fetch_add_explicit(&mNextUniqueId,
-                (uint_fast32_t) 1, memory_order_acq_rel);
-}
-
-void SoundTriggerHalHidl::convertUuidToHal(Uuid *halUuid,
-                                           const sound_trigger_uuid_t *uuid)
-{
-    halUuid->timeLow = uuid->timeLow;
-    halUuid->timeMid = uuid->timeMid;
-    halUuid->versionAndTimeHigh = uuid->timeHiAndVersion;
-    halUuid->variantAndClockSeqHigh = uuid->clockSeq;
-    memcpy(halUuid->node.data(), &uuid->node[0], sizeof(uuid->node));
-}
-
-void SoundTriggerHalHidl::convertUuidFromHal(sound_trigger_uuid_t *uuid,
-                                             const Uuid *halUuid)
-{
-    uuid->timeLow = halUuid->timeLow;
-    uuid->timeMid = halUuid->timeMid;
-    uuid->timeHiAndVersion = halUuid->versionAndTimeHigh;
-    uuid->clockSeq = halUuid->variantAndClockSeqHigh;
-    memcpy(&uuid->node[0], halUuid->node.data(), sizeof(uuid->node));
-}
-
-void SoundTriggerHalHidl::convertPropertiesFromHal(
-        struct sound_trigger_properties *properties,
-        const ISoundTriggerHw::Properties *halProperties)
-{
-    strlcpy(properties->implementor,
-            halProperties->implementor.c_str(), SOUND_TRIGGER_MAX_STRING_LEN);
-    strlcpy(properties->description,
-            halProperties->description.c_str(), SOUND_TRIGGER_MAX_STRING_LEN);
-    properties->version = halProperties->version;
-    convertUuidFromHal(&properties->uuid, &halProperties->uuid);
-    properties->max_sound_models = halProperties->maxSoundModels;
-    properties->max_key_phrases = halProperties->maxKeyPhrases;
-    properties->max_users = halProperties->maxUsers;
-    properties->recognition_modes = halProperties->recognitionModes;
-    properties->capture_transition = (bool)halProperties->captureTransition;
-    properties->max_buffer_ms = halProperties->maxBufferMs;
-    properties->concurrent_capture = (bool)halProperties->concurrentCapture;
-    properties->trigger_in_event = (bool)halProperties->triggerInEvent;
-    properties->power_consumption_mw = halProperties->powerConsumptionMw;
-}
-
-// static
-void SoundTriggerHalHidl::convertModelParameterToHal(V2_3_ModelParameter* halParam,
-    sound_trigger_model_parameter_t param)
-{
-    switch (param) {
-        case MODEL_PARAMETER_THRESHOLD_FACTOR:
-            *halParam = V2_3_ModelParameter::THRESHOLD_FACTOR;
-            return;
-        case MODEL_PARAMETER_INVALID:
-        default:
-            *halParam = V2_3_ModelParameter::INVALID;
-    }
-}
-
-void SoundTriggerHalHidl::convertTriggerPhraseToHal(
-        ISoundTriggerHw::Phrase *halTriggerPhrase,
-        const struct sound_trigger_phrase *triggerPhrase)
-{
-    halTriggerPhrase->id = triggerPhrase->id;
-    halTriggerPhrase->recognitionModes = triggerPhrase->recognition_mode;
-    halTriggerPhrase->users.setToExternal((uint32_t *)&triggerPhrase->users[0], triggerPhrase->num_users);
-    halTriggerPhrase->locale = triggerPhrase->locale;
-    halTriggerPhrase->text = triggerPhrase->text;
-}
-
-
-void SoundTriggerHalHidl::convertTriggerPhrasesToHal(
-        hidl_vec<ISoundTriggerHw::Phrase> *halTriggerPhrases,
-        struct sound_trigger_phrase_sound_model *keyPhraseModel)
-{
-    halTriggerPhrases->resize(keyPhraseModel->num_phrases);
-    for (unsigned int i = 0; i < keyPhraseModel->num_phrases; i++) {
-        convertTriggerPhraseToHal(&(*halTriggerPhrases)[i], &keyPhraseModel->phrases[i]);
-    }
-}
-
-void SoundTriggerHalHidl::convertSoundModelToHal(ISoundTriggerHw::SoundModel *halModel,
-        const struct sound_trigger_sound_model *soundModel)
-{
-    halModel->type = (SoundModelType)soundModel->type;
-    convertUuidToHal(&halModel->uuid, &soundModel->uuid);
-    convertUuidToHal(&halModel->vendorUuid, &soundModel->vendor_uuid);
-    halModel->data.setToExternal((uint8_t *)soundModel + soundModel->data_offset, soundModel->data_size);
-}
-
-std::pair<bool, sp<IMemory>> SoundTriggerHalHidl::convertSoundModelToHal(
-        V2_1_ISoundTriggerHw::SoundModel *halModel,
-        const struct sound_trigger_sound_model *soundModel)
-{
-    convertSoundModelToHal(&halModel->header, soundModel);
-    return moveVectorToMemory(&halModel->header.data, &halModel->data);
-}
-
-void SoundTriggerHalHidl::convertPhraseSoundModelToHal(
-        ISoundTriggerHw::PhraseSoundModel *halKeyPhraseModel,
-        const struct sound_trigger_sound_model *soundModel)
-{
-    struct sound_trigger_phrase_sound_model *keyPhraseModel =
-            (struct sound_trigger_phrase_sound_model *)soundModel;
-    convertTriggerPhrasesToHal(&halKeyPhraseModel->phrases, keyPhraseModel);
-    convertSoundModelToHal(&halKeyPhraseModel->common, soundModel);
-}
-
-std::pair<bool, sp<IMemory>> SoundTriggerHalHidl::convertPhraseSoundModelToHal(
-        V2_1_ISoundTriggerHw::PhraseSoundModel *halKeyPhraseModel,
-        const struct sound_trigger_sound_model *soundModel)
-{
-    struct sound_trigger_phrase_sound_model *keyPhraseModel =
-            (struct sound_trigger_phrase_sound_model *)soundModel;
-    convertTriggerPhrasesToHal(&halKeyPhraseModel->phrases, keyPhraseModel);
-    return convertSoundModelToHal(&halKeyPhraseModel->common, soundModel);
-}
-
-void SoundTriggerHalHidl::convertPhraseRecognitionExtraToHal(
-        PhraseRecognitionExtra *halExtra,
-        const struct sound_trigger_phrase_recognition_extra *extra)
-{
-    halExtra->id = extra->id;
-    halExtra->recognitionModes = extra->recognition_modes;
-    halExtra->confidenceLevel = extra->confidence_level;
-    halExtra->levels.resize(extra->num_levels);
-    for (unsigned int i = 0; i < extra->num_levels; i++) {
-        halExtra->levels[i].userId = extra->levels[i].user_id;
-        halExtra->levels[i].levelPercent = extra->levels[i].level;
-    }
-}
-
-void SoundTriggerHalHidl::convertRecognitionConfigToHal(
-        ISoundTriggerHw::RecognitionConfig *halConfig,
-        const struct sound_trigger_recognition_config *config)
-{
-    halConfig->captureHandle = config->capture_handle;
-    halConfig->captureDevice = (AudioDevice)config->capture_device;
-    halConfig->captureRequested = (uint32_t)config->capture_requested;
-
-    halConfig->phrases.resize(config->num_phrases);
-    for (unsigned int i = 0; i < config->num_phrases; i++) {
-        convertPhraseRecognitionExtraToHal(&halConfig->phrases[i],
-                                  &config->phrases[i]);
-    }
-
-    halConfig->data.setToExternal((uint8_t *)config + config->data_offset, config->data_size);
-}
-
-std::pair<bool, sp<IMemory>> SoundTriggerHalHidl::convertRecognitionConfigToHal(
-        V2_1_ISoundTriggerHw::RecognitionConfig *halConfig,
-        const struct sound_trigger_recognition_config *config)
-{
-    convertRecognitionConfigToHal(&halConfig->header, config);
-    return moveVectorToMemory(&halConfig->header.data, &halConfig->data);
-}
-
-
-// ISoundTriggerHwCallback
-::android::hardware::Return<void> SoundTriggerHalHidl::recognitionCallback(
-        const V2_0_ISoundTriggerHwCallback::RecognitionEvent& halEvent,
-        CallbackCookie cookie)
-{
-    sp<SoundModel> model;
-    {
-        AutoMutex lock(mLock);
-        model = mSoundModels.valueFor((SoundModelHandle)cookie);
-        if (model == 0) {
-            return Return<void>();
-        }
-    }
-    struct sound_trigger_recognition_event *event = convertRecognitionEventFromHal(&halEvent);
-    if (event == NULL) {
-        return Return<void>();
-    }
-    event->model = model->mHandle;
-    model->mRecognitionCallback(event, model->mRecognitionCookie);
-
-    free(event);
-
-    return Return<void>();
-}
-
-::android::hardware::Return<void> SoundTriggerHalHidl::phraseRecognitionCallback(
-        const V2_0_ISoundTriggerHwCallback::PhraseRecognitionEvent& halEvent,
-        CallbackCookie cookie)
-{
-    sp<SoundModel> model;
-    {
-        AutoMutex lock(mLock);
-        model = mSoundModels.valueFor((SoundModelHandle)cookie);
-        if (model == 0) {
-            return Return<void>();
-        }
-    }
-
-    struct sound_trigger_phrase_recognition_event *event =
-            convertPhraseRecognitionEventFromHal(&halEvent);
-    if (event == NULL) {
-        return Return<void>();
-    }
-    event->common.model = model->mHandle;
-    model->mRecognitionCallback(&event->common, model->mRecognitionCookie);
-
-    free(event);
-
-    return Return<void>();
-}
-
-::android::hardware::Return<void> SoundTriggerHalHidl::soundModelCallback(
-        const V2_0_ISoundTriggerHwCallback::ModelEvent& halEvent,
-        CallbackCookie cookie)
-{
-    sp<SoundModel> model;
-    {
-        AutoMutex lock(mLock);
-        model = mSoundModels.valueFor((SoundModelHandle)cookie);
-        if (model == 0) {
-            return Return<void>();
-        }
-    }
-
-    struct sound_trigger_model_event *event = convertSoundModelEventFromHal(&halEvent);
-    if (event == NULL) {
-        return Return<void>();
-    }
-
-    event->model = model->mHandle;
-    model->mSoundModelCallback(event, model->mSoundModelCookie);
-
-    free(event);
-
-    return Return<void>();
-}
-
-::android::hardware::Return<void> SoundTriggerHalHidl::recognitionCallback_2_1(
-        const ISoundTriggerHwCallback::RecognitionEvent& event, CallbackCookie cookie) {
-    // The data vector in the 'header' part of V2.1 structure is empty, thus copying is cheap.
-    V2_0_ISoundTriggerHwCallback::RecognitionEvent event_2_0 = event.header;
-    auto result = memoryAsVector(event.data, &event_2_0.data);
-    return result.first ? recognitionCallback(event_2_0, cookie) : Void();
-}
-
-::android::hardware::Return<void> SoundTriggerHalHidl::phraseRecognitionCallback_2_1(
-        const ISoundTriggerHwCallback::PhraseRecognitionEvent& event, int32_t cookie) {
-    V2_0_ISoundTriggerHwCallback::PhraseRecognitionEvent event_2_0;
-    // The data vector in the 'header' part of V2.1 structure is empty, thus copying is cheap.
-    event_2_0.common = event.common.header;
-    event_2_0.phraseExtras.setToExternal(
-            const_cast<PhraseRecognitionExtra*>(event.phraseExtras.data()),
-            event.phraseExtras.size());
-    auto result = memoryAsVector(event.common.data, &event_2_0.common.data);
-    return result.first ? phraseRecognitionCallback(event_2_0, cookie) : Void();
-}
-
-::android::hardware::Return<void> SoundTriggerHalHidl::soundModelCallback_2_1(
-        const ISoundTriggerHwCallback::ModelEvent& event, CallbackCookie cookie) {
-    // The data vector in the 'header' part of V2.1 structure is empty, thus copying is cheap.
-    V2_0_ISoundTriggerHwCallback::ModelEvent event_2_0 = event.header;
-    auto result = memoryAsVector(event.data, &event_2_0.data);
-    return result.first ? soundModelCallback(event_2_0, cookie) : Void();
-}
-
-
-struct sound_trigger_model_event *SoundTriggerHalHidl::convertSoundModelEventFromHal(
-                                              const V2_0_ISoundTriggerHwCallback::ModelEvent *halEvent)
-{
-    struct sound_trigger_model_event *event = (struct sound_trigger_model_event *)malloc(
-            sizeof(struct sound_trigger_model_event) +
-            halEvent->data.size());
-    if (event == NULL) {
-        return NULL;
-    }
-
-    event->status = (int)halEvent->status;
-    // event->model to be set by caller
-    event->data_offset = sizeof(struct sound_trigger_model_event);
-    event->data_size = halEvent->data.size();
-    uint8_t *dst = (uint8_t *)event + event->data_offset;
-    uint8_t *src = (uint8_t *)&halEvent->data[0];
-    memcpy(dst, src, halEvent->data.size());
-
-    return event;
-}
-
-void SoundTriggerHalHidl::convertPhraseRecognitionExtraFromHal(
-        struct sound_trigger_phrase_recognition_extra *extra,
-        const PhraseRecognitionExtra *halExtra)
-{
-    extra->id = halExtra->id;
-    extra->recognition_modes = halExtra->recognitionModes;
-    extra->confidence_level = halExtra->confidenceLevel;
-
-    size_t i;
-    for (i = 0; i < halExtra->levels.size() && i < SOUND_TRIGGER_MAX_USERS; i++) {
-        extra->levels[i].user_id = halExtra->levels[i].userId;
-        extra->levels[i].level = halExtra->levels[i].levelPercent;
-    }
-    extra->num_levels = (unsigned int)i;
-}
-
-
-struct sound_trigger_phrase_recognition_event* SoundTriggerHalHidl::convertPhraseRecognitionEventFromHal(
-        const V2_0_ISoundTriggerHwCallback::PhraseRecognitionEvent *halPhraseEvent)
-{
-    if (halPhraseEvent->common.type != SoundModelType::KEYPHRASE) {
-        ALOGE("Received non-keyphrase event type as PhraseRecognitionEvent");
-        return NULL;
-    }
-    struct sound_trigger_phrase_recognition_event *phraseEvent =
-            (struct sound_trigger_phrase_recognition_event *)malloc(
-                    sizeof(struct sound_trigger_phrase_recognition_event) +
-                    halPhraseEvent->common.data.size());
-    if (phraseEvent == NULL) {
-        return NULL;
-    }
-    phraseEvent->common.data_offset = sizeof(sound_trigger_phrase_recognition_event);
-
-    for (unsigned int i = 0; i < halPhraseEvent->phraseExtras.size(); i++) {
-        convertPhraseRecognitionExtraFromHal(&phraseEvent->phrase_extras[i],
-                                             &halPhraseEvent->phraseExtras[i]);
-    }
-    phraseEvent->num_phrases = halPhraseEvent->phraseExtras.size();
-
-    fillRecognitionEventFromHal(&phraseEvent->common, &halPhraseEvent->common);
-    return phraseEvent;
-}
-
-struct sound_trigger_recognition_event *SoundTriggerHalHidl::convertRecognitionEventFromHal(
-        const V2_0_ISoundTriggerHwCallback::RecognitionEvent *halEvent)
-{
-    if (halEvent->type == SoundModelType::KEYPHRASE) {
-        ALOGE("Received keyphrase event type as RecognitionEvent");
-        return NULL;
-    }
-    struct sound_trigger_recognition_event *event;
-    event = (struct sound_trigger_recognition_event *)malloc(
-            sizeof(struct sound_trigger_recognition_event) + halEvent->data.size());
-    if (event == NULL) {
-        return NULL;
-    }
-    event->data_offset = sizeof(sound_trigger_recognition_event);
-
-    fillRecognitionEventFromHal(event, halEvent);
-    return event;
-}
-
-void SoundTriggerHalHidl::fillRecognitionEventFromHal(
-        struct sound_trigger_recognition_event *event,
-        const V2_0_ISoundTriggerHwCallback::RecognitionEvent *halEvent)
-{
-    event->status = (int)halEvent->status;
-    event->type = (sound_trigger_sound_model_type_t)halEvent->type;
-    // event->model to be set by caller
-    event->capture_available = (bool)halEvent->captureAvailable;
-    event->capture_session = halEvent->captureSession;
-    event->capture_delay_ms = halEvent->captureDelayMs;
-    event->capture_preamble_ms = halEvent->capturePreambleMs;
-    event->trigger_in_data = (bool)halEvent->triggerInData;
-    event->audio_config.sample_rate = halEvent->audioConfig.sampleRateHz;
-    event->audio_config.channel_mask = (audio_channel_mask_t)halEvent->audioConfig.channelMask;
-    event->audio_config.format = (audio_format_t)halEvent->audioConfig.format;
-
-    event->data_size = halEvent->data.size();
-    uint8_t *dst = (uint8_t *)event + event->data_offset;
-    uint8_t *src = (uint8_t *)&halEvent->data[0];
-    memcpy(dst, src, halEvent->data.size());
-}
-
-} // namespace android
diff --git a/services/soundtrigger/SoundTriggerHalHidl.h b/services/soundtrigger/SoundTriggerHalHidl.h
deleted file mode 100644
index 25878d0..0000000
--- a/services/soundtrigger/SoundTriggerHalHidl.h
+++ /dev/null
@@ -1,253 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-#ifndef ANDROID_HARDWARE_SOUNDTRIGGER_HAL_HIDL_H
-#define ANDROID_HARDWARE_SOUNDTRIGGER_HAL_HIDL_H
-
-#include <utility>
-
-#include <stdatomic.h>
-#include <utils/RefBase.h>
-#include <utils/KeyedVector.h>
-#include <utils/Vector.h>
-#include <utils/threads.h>
-#include "SoundTriggerHalInterface.h"
-#include <android/hardware/soundtrigger/2.0/types.h>
-#include <android/hardware/soundtrigger/2.3/types.h>
-#include <android/hardware/soundtrigger/2.1/ISoundTriggerHw.h>
-#include <android/hardware/soundtrigger/2.2/ISoundTriggerHw.h>
-#include <android/hardware/soundtrigger/2.3/ISoundTriggerHw.h>
-#include <android/hardware/soundtrigger/2.0/ISoundTriggerHwCallback.h>
-#include <android/hardware/soundtrigger/2.1/ISoundTriggerHwCallback.h>
-
-namespace android {
-
-using ::android::hardware::audio::common::V2_0::Uuid;
-using ::android::hardware::hidl_vec;
-using ::android::hardware::soundtrigger::V2_0::ConfidenceLevel;
-using ::android::hardware::soundtrigger::V2_0::PhraseRecognitionExtra;
-using ::android::hardware::soundtrigger::V2_0::SoundModelType;
-using ::android::hardware::soundtrigger::V2_0::SoundModelHandle;
-using ::android::hardware::soundtrigger::V2_0::ISoundTriggerHw;
-using V2_0_ISoundTriggerHwCallback =
-        ::android::hardware::soundtrigger::V2_0::ISoundTriggerHwCallback;
-using V2_1_ISoundTriggerHw =
-        ::android::hardware::soundtrigger::V2_1::ISoundTriggerHw;
-using V2_1_ISoundTriggerHwCallback =
-        ::android::hardware::soundtrigger::V2_1::ISoundTriggerHwCallback;
-using ::android::hidl::memory::V1_0::IMemory;
-using V2_2_ISoundTriggerHw =
-        ::android::hardware::soundtrigger::V2_2::ISoundTriggerHw;
-using V2_3_ISoundTriggerHw =
-        ::android::hardware::soundtrigger::V2_3::ISoundTriggerHw;
-using V2_3_ModelParameter =
-        ::android::hardware::soundtrigger::V2_3::ModelParameter;
-using V2_3_OptionalModelParameterRange =
-        ::android::hardware::soundtrigger::V2_3::OptionalModelParameterRange;
-
-class SoundTriggerHalHidl : public SoundTriggerHalInterface,
-                            public virtual V2_1_ISoundTriggerHwCallback
-
-{
-public:
-        virtual int getProperties(struct sound_trigger_properties *properties);
-
-        /*
-         * Load a sound model. Once loaded, recognition of this model can be started and stopped.
-         * Only one active recognition per model at a time. The SoundTrigger service will handle
-         * concurrent recognition requests by different users/applications on the same model.
-         * The implementation returns a unique handle used by other functions (unload_sound_model(),
-         * start_recognition(), etc...
-         */
-        virtual int loadSoundModel(struct sound_trigger_sound_model *sound_model,
-                                sound_model_callback_t callback,
-                                void *cookie,
-                                sound_model_handle_t *handle);
-
-        /*
-         * Unload a sound model. A sound model can be unloaded to make room for a new one to overcome
-         * implementation limitations.
-         */
-        virtual int unloadSoundModel(sound_model_handle_t handle);
-
-        /* Start recognition on a given model. Only one recognition active at a time per model.
-         * Once recognition succeeds of fails, the callback is called.
-         * TODO: group recognition configuration parameters into one struct and add key phrase options.
-         */
-        virtual int startRecognition(sound_model_handle_t handle,
-                                 const struct sound_trigger_recognition_config *config,
-                                 recognition_callback_t callback,
-                                 void *cookie);
-
-        /* Stop recognition on a given model.
-         * The implementation does not have to call the callback when stopped via this method.
-         */
-        virtual int stopRecognition(sound_model_handle_t handle);
-
-        /* Stop recognition on all models.
-         * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_1 or above.
-         * If no implementation is provided, stop_recognition will be called for each running model.
-         */
-        virtual int stopAllRecognitions();
-
-        /* Get the current state of a given model.
-         * Returns 0 or an error code. If successful the state will be returned asynchronously
-         * via a recognition event in the callback method that was registered in the
-         * startRecognition() method.
-         * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_2 or above.
-         */
-        virtual int getModelState(sound_model_handle_t handle);
-
-        /* Set a model specific ModelParameter with the given value. This parameter
-         * will keep its value for the duration the model is loaded regardless of starting and
-         * stopping recognition. Once the model is unloaded, the value will be lost.
-         * Returns 0 or an error code.
-         * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
-         */
-        int setParameter(sound_model_handle_t handle,
-                         sound_trigger_model_parameter_t model_param, int32_t value);
-
-        /* Get a model specific ModelParameter. This parameter will keep its value
-         * for the duration the model is loaded regardless of starting and stopping recognition.
-         * Once the model is unloaded, the value will be lost. If the value is not set, a default
-         * value is returned. See sound_trigger_model_parameter_t for parameter default values.
-         * Returns 0 or an error code.  On return 0, value pointer will be set.
-         * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
-         */
-        int getParameter(sound_model_handle_t handle,
-                         sound_trigger_model_parameter_t model_param, int32_t* value);
-
-        /* Get supported parameter attributes with respect to the provided model
-         * handle. Along with determining the valid range, this API is also used
-         * to determine if a given parameter ID is supported at all by the
-         * modelHandle for use with getParameter and setParameter APIs.
-         */
-        int queryParameter(sound_model_handle_t handle,
-                            sound_trigger_model_parameter_t model_param,
-                            sound_trigger_model_parameter_range_t* param_range);
-
-        // ISoundTriggerHwCallback
-        virtual ::android::hardware::Return<void> recognitionCallback(
-                const V2_0_ISoundTriggerHwCallback::RecognitionEvent& event, CallbackCookie cookie);
-        virtual ::android::hardware::Return<void> phraseRecognitionCallback(
-                const V2_0_ISoundTriggerHwCallback::PhraseRecognitionEvent& event, int32_t cookie);
-        virtual ::android::hardware::Return<void> soundModelCallback(
-                const V2_0_ISoundTriggerHwCallback::ModelEvent& event, CallbackCookie cookie);
-        virtual ::android::hardware::Return<void> recognitionCallback_2_1(
-                const RecognitionEvent& event, CallbackCookie cookie);
-        virtual ::android::hardware::Return<void> phraseRecognitionCallback_2_1(
-                const PhraseRecognitionEvent& event, int32_t cookie);
-        virtual ::android::hardware::Return<void> soundModelCallback_2_1(
-                const ModelEvent& event, CallbackCookie cookie);
-private:
-        class SoundModel : public RefBase {
-        public:
-            SoundModel(sound_model_handle_t handle, sound_model_callback_t callback,
-                       void *cookie, android::hardware::soundtrigger::V2_0::SoundModelHandle halHandle)
-                 : mHandle(handle), mHalHandle(halHandle),
-                   mSoundModelCallback(callback), mSoundModelCookie(cookie),
-                   mRecognitionCallback(NULL), mRecognitionCookie(NULL) {}
-            ~SoundModel() {}
-
-            sound_model_handle_t   mHandle;
-            android::hardware::soundtrigger::V2_0::SoundModelHandle mHalHandle;
-            sound_model_callback_t mSoundModelCallback;
-            void *                 mSoundModelCookie;
-            recognition_callback_t mRecognitionCallback;
-            void *                 mRecognitionCookie;
-        };
-
-        friend class SoundTriggerHalInterface;
-
-        explicit SoundTriggerHalHidl(const char *moduleName = NULL);
-        virtual  ~SoundTriggerHalHidl();
-
-        void convertUuidToHal(Uuid *halUuid,
-                              const sound_trigger_uuid_t *uuid);
-        void convertUuidFromHal(sound_trigger_uuid_t *uuid,
-                                const Uuid *halUuid);
-
-        void convertPropertiesFromHal(
-                struct sound_trigger_properties *properties,
-                const ISoundTriggerHw::Properties *halProperties);
-        static void convertModelParameterToHal(V2_3_ModelParameter* halParam,
-                sound_trigger_model_parameter_t param);
-
-        void convertTriggerPhraseToHal(
-                ISoundTriggerHw::Phrase *halTriggerPhrase,
-                const struct sound_trigger_phrase *triggerPhrase);
-        void convertTriggerPhrasesToHal(
-                hidl_vec<ISoundTriggerHw::Phrase> *halTriggerPhrases,
-                struct sound_trigger_phrase_sound_model *keyPhraseModel);
-        void convertSoundModelToHal(ISoundTriggerHw::SoundModel *halModel,
-                const struct sound_trigger_sound_model *soundModel);
-        std::pair<bool, sp<IMemory>> convertSoundModelToHal(
-                V2_1_ISoundTriggerHw::SoundModel *halModel,
-                const struct sound_trigger_sound_model *soundModel)
-                __attribute__((warn_unused_result));
-        void convertPhraseSoundModelToHal(ISoundTriggerHw::PhraseSoundModel *halKeyPhraseModel,
-                const struct sound_trigger_sound_model *soundModel);
-        std::pair<bool, sp<IMemory>> convertPhraseSoundModelToHal(
-                V2_1_ISoundTriggerHw::PhraseSoundModel *halKeyPhraseModel,
-                const struct sound_trigger_sound_model *soundModel)
-                __attribute__((warn_unused_result));
-
-        void convertPhraseRecognitionExtraToHal(
-                PhraseRecognitionExtra *halExtra,
-                const struct sound_trigger_phrase_recognition_extra *extra);
-        void convertRecognitionConfigToHal(ISoundTriggerHw::RecognitionConfig *halConfig,
-                const struct sound_trigger_recognition_config *config);
-        std::pair<bool, sp<IMemory>> convertRecognitionConfigToHal(
-                V2_1_ISoundTriggerHw::RecognitionConfig *halConfig,
-                const struct sound_trigger_recognition_config *config)
-                __attribute__((warn_unused_result));
-
-        struct sound_trigger_model_event *convertSoundModelEventFromHal(
-                                              const V2_0_ISoundTriggerHwCallback::ModelEvent *halEvent);
-        void convertPhraseRecognitionExtraFromHal(
-                struct sound_trigger_phrase_recognition_extra *extra,
-                const PhraseRecognitionExtra *halExtra);
-        struct sound_trigger_phrase_recognition_event* convertPhraseRecognitionEventFromHal(
-                const V2_0_ISoundTriggerHwCallback::PhraseRecognitionEvent *halPhraseEvent);
-        struct sound_trigger_recognition_event *convertRecognitionEventFromHal(
-                const V2_0_ISoundTriggerHwCallback::RecognitionEvent *halEvent);
-        void fillRecognitionEventFromHal(
-                struct sound_trigger_recognition_event *event,
-                const V2_0_ISoundTriggerHwCallback::RecognitionEvent *halEvent);
-
-        uint32_t nextUniqueId();
-        sp<ISoundTriggerHw> getService();
-        sp<V2_1_ISoundTriggerHw> toService2_1(const sp<ISoundTriggerHw>& s);
-        sp<V2_2_ISoundTriggerHw> toService2_2(const sp<ISoundTriggerHw>& s);
-        sp<V2_3_ISoundTriggerHw> toService2_3(const sp<ISoundTriggerHw>& s);
-        sp<SoundModel> getModel(sound_model_handle_t handle);
-        sp<SoundModel> removeModel(sound_model_handle_t handle);
-
-        static pthread_once_t sOnceControl;
-        static void sOnceInit();
-
-        Mutex mLock;
-        Mutex mHalLock;
-        const char *mModuleName;
-        volatile atomic_uint_fast32_t  mNextUniqueId;
-        // Effect chains without a valid thread
-        DefaultKeyedVector< sound_model_handle_t , sp<SoundModel> > mSoundModels;
-        sp<::android::hardware::soundtrigger::V2_0::ISoundTriggerHw> mISoundTrigger;
-};
-
-} // namespace android
-
-#endif // ANDROID_HARDWARE_SOUNDTRIGGER_HAL_HIDL_H
diff --git a/services/soundtrigger/SoundTriggerHalInterface.h b/services/soundtrigger/SoundTriggerHalInterface.h
deleted file mode 100644
index e1fffff..0000000
--- a/services/soundtrigger/SoundTriggerHalInterface.h
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2016 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.
- */
-
-#ifndef ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H
-#define ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H
-
-#include <utils/RefBase.h>
-#include <system/sound_trigger.h>
-#include <hardware/sound_trigger.h>
-
-namespace android {
-
-class SoundTriggerHalInterface : public virtual RefBase
-{
-public:
-        /* get a sound trigger HAL instance */
-        static sp<SoundTriggerHalInterface> connectModule(const char *moduleName);
-
-        virtual     ~SoundTriggerHalInterface() {}
-
-        virtual int getProperties(struct sound_trigger_properties *properties) = 0;
-
-        /*
-         * Load a sound model. Once loaded, recognition of this model can be started and stopped.
-         * Only one active recognition per model at a time. The SoundTrigger service will handle
-         * concurrent recognition requests by different users/applications on the same model.
-         * The implementation returns a unique handle used by other functions (unload_sound_model(),
-         * start_recognition(), etc...
-         */
-        virtual int loadSoundModel(struct sound_trigger_sound_model *sound_model,
-                                sound_model_callback_t callback,
-                                void *cookie,
-                                sound_model_handle_t *handle) = 0;
-
-        /*
-         * Unload a sound model. A sound model can be unloaded to make room for a new one to overcome
-         * implementation limitations.
-         */
-        virtual int unloadSoundModel(sound_model_handle_t handle) = 0;
-
-        /* Start recognition on a given model. Only one recognition active at a time per model.
-         * Once recognition succeeds of fails, the callback is called.
-         * TODO: group recognition configuration parameters into one struct and add key phrase options.
-         */
-        virtual int startRecognition(sound_model_handle_t handle,
-                                 const struct sound_trigger_recognition_config *config,
-                                 recognition_callback_t callback,
-                                 void *cookie) = 0;
-
-        /* Stop recognition on a given model.
-         * The implementation does not have to call the callback when stopped via this method.
-         */
-        virtual int stopRecognition(sound_model_handle_t handle) = 0;
-
-        /* Stop recognition on all models.
-         * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_1 or above.
-         * If no implementation is provided, stop_recognition will be called for each running model.
-         */
-        virtual int stopAllRecognitions() = 0;
-
-        /* Get the current state of a given model.
-         * Returns 0 or an error code. If successful the state will be returned asynchronously
-         * via a recognition event in the callback method that was registered in the
-         * startRecognition() method.
-         * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_2 or above.
-         */
-        virtual int getModelState(sound_model_handle_t handle) = 0;
-
-        /* Set a model specific ModelParameter with the given value. This parameter
-         * will keep its value for the duration the model is loaded regardless of starting and stopping
-         * recognition. Once the model is unloaded, the value will be lost.
-         * Returns 0 or an error code.
-         * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
-         */
-        virtual int setParameter(sound_model_handle_t handle,
-                                 sound_trigger_model_parameter_t model_param, int32_t value) = 0;
-
-        /* Get a model specific ModelParameter. This parameter will keep its value
-         * for the duration the model is loaded regardless of starting and stopping recognition.
-         * Once the model is unloaded, the value will be lost. If the value is not set, a default
-         * value is returned. See sound_trigger_model_parameter_t for parameter default values.
-         * Returns 0 or an error code. On return 0, value pointer will be set.
-         * Only supported for device api versions SOUND_TRIGGER_DEVICE_API_VERSION_1_3 or above.
-         */
-        virtual int getParameter(sound_model_handle_t sound_model_handle,
-                                 sound_trigger_model_parameter_t model_param, int32_t* value) = 0;
-
-        /* Get supported parameter attributes with respect to the provided model
-         * handle. Along with determining the valid range, this API is also used
-         * to determine if a given parameter ID is supported at all by the
-         * modelHandle for use with getParameter and setParameter APIs.
-         */
-        virtual int queryParameter(sound_model_handle_t sound_model_handle,
-                                 sound_trigger_model_parameter_t model_param,
-                                 sound_trigger_model_parameter_range_t* param_range) = 0;
-
-protected:
-        SoundTriggerHalInterface() {}
-};
-
-} // namespace android
-
-#endif // ANDROID_HARDWARE_SOUNDTRIGGER_HAL_INTERFACE_H
diff --git a/services/soundtrigger/SoundTriggerHwService.cpp b/services/soundtrigger/SoundTriggerHwService.cpp
deleted file mode 100644
index 4d8b0da..0000000
--- a/services/soundtrigger/SoundTriggerHwService.cpp
+++ /dev/null
@@ -1,1249 +0,0 @@
-/*
- * Copyright (C) 2014 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.
- */
-
-#define LOG_TAG "SoundTriggerHwService"
-//#define LOG_NDEBUG 0
-
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <pthread.h>
-
-#include <audio_utils/clock.h>
-#include <system/sound_trigger.h>
-#include <cutils/atomic.h>
-#include <cutils/properties.h>
-#include <hardware/hardware.h>
-#include <media/AudioSystem.h>
-#include <mediautils/ServiceUtilities.h>
-#include <utils/Errors.h>
-#include <utils/Log.h>
-#include <binder/IServiceManager.h>
-#include <binder/MemoryBase.h>
-#include <binder/MemoryHeapBase.h>
-#include <system/sound_trigger.h>
-#include "SoundTriggerHwService.h"
-
-#define HW_MODULE_PREFIX "primary"
-namespace android {
-
-namespace {
-
-// Given an IMemory, returns a copy of its content along with its size.
-// Returns nullptr on failure or if input is nullptr.
-std::pair<std::unique_ptr<uint8_t[]>,
-          size_t> CopyToArray(const sp<IMemory>& mem) {
-    if (mem == nullptr) {
-        return std::make_pair(nullptr, 0);
-    }
-
-    const size_t size = mem->size();
-    if (size == 0) {
-        return std::make_pair(nullptr, 0);
-    }
-
-    std::unique_ptr<uint8_t[]> ar = std::make_unique<uint8_t[]>(size);
-    if (ar == nullptr) {
-        return std::make_pair(nullptr, 0);
-    }
-
-    memcpy(ar.get(), mem->unsecurePointer(), size);
-    return std::make_pair(std::move(ar), size);
-}
-
-}
-
-SoundTriggerHwService::SoundTriggerHwService()
-    : BnSoundTriggerHwService(),
-      mNextUniqueId(1),
-      mMemoryDealer(new MemoryDealer(1024 * 1024, "SoundTriggerHwService")),
-      mCaptureState(false)
-{
-}
-
-void SoundTriggerHwService::onFirstRef()
-{
-    int rc;
-
-    sp<SoundTriggerHalInterface> halInterface =
-            SoundTriggerHalInterface::connectModule(HW_MODULE_PREFIX);
-
-    if (halInterface == 0) {
-        ALOGW("could not connect to HAL");
-        return;
-    }
-    sound_trigger_module_descriptor descriptor;
-    rc = halInterface->getProperties(&descriptor.properties);
-    if (rc != 0) {
-        ALOGE("could not read implementation properties");
-        return;
-    }
-    descriptor.handle =
-            (sound_trigger_module_handle_t)android_atomic_inc(&mNextUniqueId);
-    ALOGI("loaded default module %s, handle %d", descriptor.properties.description,
-                                                 descriptor.handle);
-
-    sp<Module> module = new Module(this, halInterface, descriptor);
-    mModules.add(descriptor.handle, module);
-    mCallbackThread = new CallbackThread(this);
-}
-
-SoundTriggerHwService::~SoundTriggerHwService()
-{
-    if (mCallbackThread != 0) {
-        mCallbackThread->exit();
-    }
-}
-
-status_t SoundTriggerHwService::listModules(const String16& opPackageName,
-                             struct sound_trigger_module_descriptor *modules,
-                             uint32_t *numModules)
-{
-    ALOGV("listModules");
-    if (!captureHotwordAllowed(opPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-
-    AutoMutex lock(mServiceLock);
-    if (numModules == NULL || (*numModules != 0 && modules == NULL)) {
-        return BAD_VALUE;
-    }
-    size_t maxModules = *numModules;
-    *numModules = mModules.size();
-    for (size_t i = 0; i < mModules.size() && i < maxModules; i++) {
-        modules[i] = mModules.valueAt(i)->descriptor();
-    }
-    return NO_ERROR;
-}
-
-status_t SoundTriggerHwService::attach(const String16& opPackageName,
-                        const sound_trigger_module_handle_t handle,
-                        const sp<ISoundTriggerClient>& client,
-                        sp<ISoundTrigger>& moduleInterface)
-{
-    ALOGV("attach module %d", handle);
-    if (!captureHotwordAllowed(opPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-
-    AutoMutex lock(mServiceLock);
-    moduleInterface.clear();
-    if (client == 0) {
-        return BAD_VALUE;
-    }
-    ssize_t index = mModules.indexOfKey(handle);
-    if (index < 0) {
-        return BAD_VALUE;
-    }
-    sp<Module> module = mModules.valueAt(index);
-
-    sp<ModuleClient> moduleClient = module->addClient(client, opPackageName);
-    if (moduleClient == 0) {
-        return NO_INIT;
-    }
-
-    moduleClient->setCaptureState_l(mCaptureState);
-    moduleInterface = moduleClient;
-
-    return NO_ERROR;
-}
-
-status_t SoundTriggerHwService::setCaptureState(bool active)
-{
-    ALOGV("setCaptureState %d", active);
-    AutoMutex lock(mServiceLock);
-    mCaptureState = active;
-    for (size_t i = 0; i < mModules.size(); i++) {
-        mModules.valueAt(i)->setCaptureState_l(active);
-    }
-    return NO_ERROR;
-}
-
-
-static const int kDumpLockTimeoutNs = 1 * NANOS_PER_SECOND;
-
-static bool dumpTryLock(Mutex& mutex)
-{
-    status_t err = mutex.timedLock(kDumpLockTimeoutNs);
-    return err == NO_ERROR;
-}
-
-status_t SoundTriggerHwService::dump(int fd, const Vector<String16>& args __unused) {
-    String8 result;
-    if (checkCallingPermission(String16("android.permission.DUMP")) == false) {
-        result.appendFormat("Permission Denial: can't dump SoundTriggerHwService");
-        write(fd, result.string(), result.size());
-    } else {
-        bool locked = dumpTryLock(mServiceLock);
-        // failed to lock - SoundTriggerHwService is probably deadlocked
-        if (!locked) {
-            result.append("SoundTriggerHwService may be deadlocked\n");
-            write(fd, result.string(), result.size());
-        }
-
-        if (locked) mServiceLock.unlock();
-    }
-    return NO_ERROR;
-}
-
-status_t SoundTriggerHwService::onTransact(
-    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags) {
-    return BnSoundTriggerHwService::onTransact(code, data, reply, flags);
-}
-
-
-// static
-void SoundTriggerHwService::recognitionCallback(struct sound_trigger_recognition_event *event,
-                                                void *cookie)
-{
-    Module *module = (Module *)cookie;
-    if (module == NULL) {
-        return;
-    }
-    sp<SoundTriggerHwService> service = module->service().promote();
-    if (service == 0) {
-        return;
-    }
-
-    service->sendRecognitionEvent(event, module);
-}
-
-sp<IMemory> SoundTriggerHwService::prepareRecognitionEvent(
-                                                    struct sound_trigger_recognition_event *event)
-{
-    AutoMutex lock(mMemoryDealerLock);
-    sp<IMemory> eventMemory;
-
-    //sanitize event
-    switch (event->type) {
-    case SOUND_MODEL_TYPE_KEYPHRASE:
-        ALOGW_IF(event->data_size != 0 && event->data_offset !=
-                    sizeof(struct sound_trigger_phrase_recognition_event),
-                    "prepareRecognitionEvent(): invalid data offset %u for keyphrase event type",
-                    event->data_offset);
-        event->data_offset = sizeof(struct sound_trigger_phrase_recognition_event);
-        break;
-    case SOUND_MODEL_TYPE_GENERIC:
-        ALOGW_IF(event->data_size != 0 && event->data_offset !=
-                    sizeof(struct sound_trigger_generic_recognition_event),
-                    "prepareRecognitionEvent(): invalid data offset %u for generic event type",
-                    event->data_offset);
-        event->data_offset = sizeof(struct sound_trigger_generic_recognition_event);
-        break;
-    case SOUND_MODEL_TYPE_UNKNOWN:
-        ALOGW_IF(event->data_size != 0 && event->data_offset !=
-                    sizeof(struct sound_trigger_recognition_event),
-                    "prepareRecognitionEvent(): invalid data offset %u for unknown event type",
-                    event->data_offset);
-        event->data_offset = sizeof(struct sound_trigger_recognition_event);
-        break;
-    default:
-        return eventMemory;
-    }
-
-    size_t size = event->data_offset + event->data_size;
-    eventMemory = mMemoryDealer->allocate(size);
-    if (eventMemory == 0 || eventMemory->unsecurePointer() == NULL) {
-        eventMemory.clear();
-        return eventMemory;
-    }
-    memcpy(eventMemory->unsecurePointer(), event, size);
-
-    return eventMemory;
-}
-
-void SoundTriggerHwService::sendRecognitionEvent(struct sound_trigger_recognition_event *event,
-                                                 Module *module)
-{
-    if (module == NULL) {
-        return;
-    }
-    sp<IMemory> eventMemory = prepareRecognitionEvent(event);
-    if (eventMemory == 0) {
-        return;
-    }
-
-    sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_RECOGNITION,
-                                                        eventMemory);
-    callbackEvent->setModule(module);
-    sendCallbackEvent(callbackEvent);
-}
-
-// static
-void SoundTriggerHwService::soundModelCallback(struct sound_trigger_model_event *event,
-                                               void *cookie)
-{
-    Module *module = (Module *)cookie;
-    if (module == NULL) {
-        return;
-    }
-    sp<SoundTriggerHwService> service = module->service().promote();
-    if (service == 0) {
-        return;
-    }
-
-    service->sendSoundModelEvent(event, module);
-}
-
-sp<IMemory> SoundTriggerHwService::prepareSoundModelEvent(struct sound_trigger_model_event *event)
-{
-    AutoMutex lock(mMemoryDealerLock);
-    sp<IMemory> eventMemory;
-
-    size_t size = event->data_offset + event->data_size;
-    eventMemory = mMemoryDealer->allocate(size);
-    if (eventMemory == 0 || eventMemory->unsecurePointer() == NULL) {
-        eventMemory.clear();
-        return eventMemory;
-    }
-    memcpy(eventMemory->unsecurePointer(), event, size);
-
-    return eventMemory;
-}
-
-void SoundTriggerHwService::sendSoundModelEvent(struct sound_trigger_model_event *event,
-                                                Module *module)
-{
-    sp<IMemory> eventMemory = prepareSoundModelEvent(event);
-    if (eventMemory == 0) {
-        return;
-    }
-    sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_SOUNDMODEL,
-                                                        eventMemory);
-    callbackEvent->setModule(module);
-    sendCallbackEvent(callbackEvent);
-}
-
-
-sp<IMemory> SoundTriggerHwService::prepareServiceStateEvent(sound_trigger_service_state_t state)
-{
-    AutoMutex lock(mMemoryDealerLock);
-    sp<IMemory> eventMemory;
-
-    size_t size = sizeof(sound_trigger_service_state_t);
-    eventMemory = mMemoryDealer->allocate(size);
-    if (eventMemory == 0 || eventMemory->unsecurePointer() == NULL) {
-        eventMemory.clear();
-        return eventMemory;
-    }
-    *((sound_trigger_service_state_t *)eventMemory->unsecurePointer()) = state;
-    return eventMemory;
-}
-
-void SoundTriggerHwService::sendServiceStateEvent(sound_trigger_service_state_t state,
-                                                  Module *module)
-{
-    sp<IMemory> eventMemory = prepareServiceStateEvent(state);
-    if (eventMemory == 0) {
-        return;
-    }
-    sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_SERVICE_STATE,
-                                                        eventMemory);
-    callbackEvent->setModule(module);
-    sendCallbackEvent(callbackEvent);
-}
-
-void SoundTriggerHwService::sendServiceStateEvent(sound_trigger_service_state_t state,
-                                                  ModuleClient *moduleClient)
-{
-    sp<IMemory> eventMemory = prepareServiceStateEvent(state);
-    if (eventMemory == 0) {
-        return;
-    }
-    sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_SERVICE_STATE,
-                                                        eventMemory);
-    callbackEvent->setModuleClient(moduleClient);
-    sendCallbackEvent(callbackEvent);
-}
-
-void SoundTriggerHwService::sendCallbackEvent(const sp<CallbackEvent>& event)
-{
-    mCallbackThread->sendCallbackEvent(event);
-}
-
-void SoundTriggerHwService::onCallbackEvent(const sp<CallbackEvent>& event)
-{
-    ALOGV("onCallbackEvent");
-    sp<Module> module;
-    sp<ModuleClient> moduleClient;
-    {
-        AutoMutex lock(mServiceLock);
-        //CallbackEvent is either for Module or ModuleClient
-        module = event->mModule.promote();
-        if (module == 0) {
-            moduleClient = event->mModuleClient.promote();
-            if (moduleClient == 0) {
-                return;
-            }
-        } else {
-            // Sanity check on this being a Module we know about.
-            bool foundModule = false;
-            for (size_t i = 0; i < mModules.size(); i++) {
-                if (mModules.valueAt(i).get() == module.get()) {
-                    foundModule = true;
-                    break;
-                }
-            }
-            if (!foundModule) {
-                ALOGE("onCallbackEvent for unknown module");
-                return;
-            }
-        }
-    }
-    if (module != 0) {
-        ALOGV("onCallbackEvent for module");
-        module->onCallbackEvent(event);
-    } else if (moduleClient != 0) {
-        ALOGV("onCallbackEvent for moduleClient");
-        moduleClient->onCallbackEvent(event);
-    }
-    {
-        AutoMutex lock(mServiceLock);
-        // clear now to execute with mServiceLock locked
-        event->mMemory.clear();
-    }
-}
-
-#undef LOG_TAG
-#define LOG_TAG "SoundTriggerHwService::CallbackThread"
-
-SoundTriggerHwService::CallbackThread::CallbackThread(const wp<SoundTriggerHwService>& service)
-    : mService(service)
-{
-}
-
-SoundTriggerHwService::CallbackThread::~CallbackThread()
-{
-    while (!mEventQueue.isEmpty()) {
-        mEventQueue[0]->mMemory.clear();
-        mEventQueue.removeAt(0);
-    }
-}
-
-void SoundTriggerHwService::CallbackThread::onFirstRef()
-{
-    run("soundTrigger cbk", ANDROID_PRIORITY_URGENT_AUDIO);
-}
-
-bool SoundTriggerHwService::CallbackThread::threadLoop()
-{
-    while (!exitPending()) {
-        sp<CallbackEvent> event;
-        sp<SoundTriggerHwService> service;
-        {
-            Mutex::Autolock _l(mCallbackLock);
-            while (mEventQueue.isEmpty() && !exitPending()) {
-                ALOGV("CallbackThread::threadLoop() sleep");
-                mCallbackCond.wait(mCallbackLock);
-                ALOGV("CallbackThread::threadLoop() wake up");
-            }
-            if (exitPending()) {
-                break;
-            }
-            event = mEventQueue[0];
-            mEventQueue.removeAt(0);
-            service = mService.promote();
-        }
-        if (service != 0) {
-            service->onCallbackEvent(event);
-        }
-    }
-    return false;
-}
-
-void SoundTriggerHwService::CallbackThread::exit()
-{
-    Mutex::Autolock _l(mCallbackLock);
-    requestExit();
-    mCallbackCond.broadcast();
-}
-
-void SoundTriggerHwService::CallbackThread::sendCallbackEvent(
-                        const sp<SoundTriggerHwService::CallbackEvent>& event)
-{
-    AutoMutex lock(mCallbackLock);
-    mEventQueue.add(event);
-    mCallbackCond.signal();
-}
-
-SoundTriggerHwService::CallbackEvent::CallbackEvent(event_type type, sp<IMemory> memory)
-    : mType(type), mMemory(memory)
-{
-}
-
-SoundTriggerHwService::CallbackEvent::~CallbackEvent()
-{
-}
-
-
-#undef LOG_TAG
-#define LOG_TAG "SoundTriggerHwService::Module"
-
-SoundTriggerHwService::Module::Module(const sp<SoundTriggerHwService>& service,
-                                      const sp<SoundTriggerHalInterface>& halInterface,
-                                      sound_trigger_module_descriptor descriptor)
- : mService(service), mHalInterface(halInterface), mDescriptor(descriptor),
-   mServiceState(SOUND_TRIGGER_STATE_NO_INIT)
-{
-}
-
-SoundTriggerHwService::Module::~Module() {
-    mModuleClients.clear();
-}
-
-sp<SoundTriggerHwService::ModuleClient>
-SoundTriggerHwService::Module::addClient(const sp<ISoundTriggerClient>& client,
-                                         const String16& opPackageName)
-{
-    AutoMutex lock(mLock);
-    sp<ModuleClient> moduleClient;
-
-    for (size_t i = 0; i < mModuleClients.size(); i++) {
-        if (mModuleClients[i]->client() == client) {
-            // Client already present, reuse client
-            return moduleClient;
-        }
-    }
-    moduleClient = new ModuleClient(this, client, opPackageName);
-
-    ALOGV("addClient() client %p", moduleClient.get());
-    mModuleClients.add(moduleClient);
-
-    return moduleClient;
-}
-
-void SoundTriggerHwService::Module::detach(const sp<ModuleClient>& moduleClient)
-{
-    ALOGV("Module::detach()");
-    Vector<audio_session_t> releasedSessions;
-
-    {
-        AutoMutex lock(mLock);
-        ssize_t index = -1;
-
-        for (size_t i = 0; i < mModuleClients.size(); i++) {
-            if (mModuleClients[i] == moduleClient) {
-                index = i;
-                break;
-            }
-        }
-        if (index == -1) {
-            return;
-        }
-
-        ALOGV("remove client %p", moduleClient.get());
-        mModuleClients.removeAt(index);
-
-        // Iterate in reverse order as models are removed from list inside the loop.
-        for (size_t i = mModels.size(); i > 0; i--) {
-            sp<Model> model = mModels.valueAt(i - 1);
-            if (moduleClient == model->mModuleClient) {
-                mModels.removeItemsAt(i - 1);
-                ALOGV("detach() unloading model %d", model->mHandle);
-                if (mHalInterface != 0) {
-                    if (model->mState == Model::STATE_ACTIVE) {
-                        mHalInterface->stopRecognition(model->mHandle);
-                    }
-                    mHalInterface->unloadSoundModel(model->mHandle);
-                }
-                releasedSessions.add(model->mCaptureSession);
-            }
-        }
-    }
-
-    for (size_t i = 0; i < releasedSessions.size(); i++) {
-        // do not call AudioSystem methods with mLock held
-        AudioSystem::releaseSoundTriggerSession(releasedSessions[i]);
-    }
-}
-
-status_t SoundTriggerHwService::Module::loadSoundModel(const sp<IMemory>& modelMemory,
-                                                       sp<ModuleClient> moduleClient,
-                                                       sound_model_handle_t *handle)
-{
-    ALOGV("loadSoundModel() handle");
-    if (mHalInterface == 0) {
-        return NO_INIT;
-    }
-
-    auto immutableMemory = CopyToArray(modelMemory);
-    if (immutableMemory.first == nullptr) {
-        return NO_MEMORY;
-    }
-
-    struct sound_trigger_sound_model* sound_model =
-        (struct sound_trigger_sound_model*) immutableMemory.first.get();
-
-    size_t structSize;
-    if (sound_model->type == SOUND_MODEL_TYPE_KEYPHRASE) {
-        structSize = sizeof(struct sound_trigger_phrase_sound_model);
-    } else {
-        structSize = sizeof(struct sound_trigger_sound_model);
-    }
-
-    if (sound_model->data_offset < structSize ||
-        sound_model->data_size > (UINT_MAX - sound_model->data_offset) ||
-        immutableMemory.second < sound_model->data_offset ||
-            sound_model->data_size >
-            (immutableMemory.second - sound_model->data_offset)) {
-        android_errorWriteLog(0x534e4554, "30148546");
-        ALOGE("loadSoundModel() data_size is too big");
-        return BAD_VALUE;
-    }
-
-    audio_session_t session;
-    audio_io_handle_t ioHandle;
-    audio_devices_t device;
-    // do not call AudioSystem methods with mLock held
-    status_t status = AudioSystem::acquireSoundTriggerSession(&session, &ioHandle, &device);
-    if (status != NO_ERROR) {
-        return status;
-    }
-
-    {
-        AutoMutex lock(mLock);
-
-        if (mModels.size() >= mDescriptor.properties.max_sound_models) {
-            ALOGW("loadSoundModel(): Not loading, max number of models (%d) would be exceeded",
-                  mDescriptor.properties.max_sound_models);
-            status = INVALID_OPERATION;
-            goto exit;
-        }
-
-        status = mHalInterface->loadSoundModel(sound_model,
-                                                      SoundTriggerHwService::soundModelCallback,
-                                                      this, handle);
-        if (status != NO_ERROR) {
-            goto exit;
-        }
-
-        sp<Model> model = new Model(*handle, session, ioHandle, device, sound_model->type,
-                                    moduleClient);
-        mModels.replaceValueFor(*handle, model);
-    }
-exit:
-    if (status != NO_ERROR) {
-        // do not call AudioSystem methods with mLock held
-        AudioSystem::releaseSoundTriggerSession(session);
-    }
-    return status;
-}
-
-status_t SoundTriggerHwService::Module::unloadSoundModel(sound_model_handle_t handle)
-{
-    ALOGV("unloadSoundModel() model handle %d", handle);
-    status_t status;
-    audio_session_t session;
-
-    {
-        AutoMutex lock(mLock);
-        if (mHalInterface == 0) {
-            return NO_INIT;
-        }
-        ssize_t index = mModels.indexOfKey(handle);
-        if (index < 0) {
-            return BAD_VALUE;
-        }
-        sp<Model> model = mModels.valueAt(index);
-        mModels.removeItem(handle);
-        if (model->mState == Model::STATE_ACTIVE) {
-            mHalInterface->stopRecognition(model->mHandle);
-            model->mState = Model::STATE_IDLE;
-        }
-        status = mHalInterface->unloadSoundModel(handle);
-        session = model->mCaptureSession;
-    }
-    // do not call AudioSystem methods with mLock held
-    AudioSystem::releaseSoundTriggerSession(session);
-    return status;
-}
-
-status_t SoundTriggerHwService::Module::startRecognition(sound_model_handle_t handle,
-                                 const sp<IMemory>& dataMemory)
-{
-    ALOGV("startRecognition() model handle %d", handle);
-    if (mHalInterface == 0) {
-        return NO_INIT;
-    }
-
-    auto immutableMemory = CopyToArray(dataMemory);
-    if (immutableMemory.first == nullptr) {
-        return NO_MEMORY;
-    }
-
-    struct sound_trigger_recognition_config* config =
-        (struct sound_trigger_recognition_config*) immutableMemory.first.get();
-
-    if (config->data_offset < sizeof(struct sound_trigger_recognition_config) ||
-        config->data_size > (UINT_MAX - config->data_offset) ||
-        immutableMemory.second < config->data_offset ||
-            config->data_size >
-            (immutableMemory.second - config->data_offset)) {
-        ALOGE("startRecognition() data_size is too big");
-        return BAD_VALUE;
-    }
-
-    AutoMutex lock(mLock);
-    if (mServiceState == SOUND_TRIGGER_STATE_DISABLED) {
-        return INVALID_OPERATION;
-    }
-    sp<Model> model = getModel(handle);
-    if (model == 0) {
-        return BAD_VALUE;
-    }
-
-    if (model->mState == Model::STATE_ACTIVE) {
-        return INVALID_OPERATION;
-    }
-
-
-    //TODO: get capture handle and device from audio policy service
-    config->capture_handle = model->mCaptureIOHandle;
-    config->capture_device = model->mCaptureDevice;
-    status_t status = mHalInterface->startRecognition(handle, config,
-                                        SoundTriggerHwService::recognitionCallback,
-                                        this);
-
-    if (status == NO_ERROR) {
-        model->mState = Model::STATE_ACTIVE;
-        model->mConfig = *config;
-    }
-
-    return status;
-}
-
-status_t SoundTriggerHwService::Module::stopRecognition(sound_model_handle_t handle)
-{
-    ALOGV("stopRecognition() model handle %d", handle);
-    if (mHalInterface == 0) {
-        return NO_INIT;
-    }
-    AutoMutex lock(mLock);
-    sp<Model> model = getModel(handle);
-    if (model == 0) {
-        return BAD_VALUE;
-    }
-
-    if (model->mState != Model::STATE_ACTIVE) {
-        return INVALID_OPERATION;
-    }
-    mHalInterface->stopRecognition(handle);
-    model->mState = Model::STATE_IDLE;
-    return NO_ERROR;
-}
-
-status_t SoundTriggerHwService::Module::getModelState(sound_model_handle_t handle)
-{
-    ALOGV("getModelState() model handle %d", handle);
-    if (mHalInterface == 0) {
-        return NO_INIT;
-    }
-    AutoMutex lock(mLock);
-    sp<Model> model = getModel(handle);
-    if (model == 0) {
-        return BAD_VALUE;
-    }
-
-    if (model->mState != Model::STATE_ACTIVE) {
-        return INVALID_OPERATION;
-    }
-
-    return mHalInterface->getModelState(handle);
-}
-
-status_t SoundTriggerHwService::Module::setParameter(sound_model_handle_t handle,
-                                sound_trigger_model_parameter_t param,
-                                int32_t value)
-{
-    ALOGV("setParameter() handle=%d, param=%d, value=%d", handle, param, value);
-    if (mHalInterface == 0) {
-        return NO_INIT;
-    }
-
-    AutoMutex lock(mLock);
-    return mHalInterface->setParameter(handle, param, value);
-}
-
-status_t SoundTriggerHwService::Module::getParameter(sound_model_handle_t handle,
-                                sound_trigger_model_parameter_t param,
-                                int32_t* value)
-{
-    ALOGV("getParameter() handle=%d, param=%d", handle, param);
-    if (mHalInterface == 0) {
-        return NO_INIT;
-    }
-
-    AutoMutex lock(mLock);
-    return mHalInterface->getParameter(handle, param, value);
-}
-
-status_t SoundTriggerHwService::Module::queryParameter(sound_model_handle_t handle,
-                                sound_trigger_model_parameter_t param,
-                                sound_trigger_model_parameter_range_t* param_range)
-{
-    ALOGV("queryParameter() handle=%d, param=%d", handle, param);
-    if (mHalInterface == 0) {
-        return NO_INIT;
-    }
-
-    AutoMutex lock(mLock);
-    return mHalInterface->queryParameter(handle, param, param_range);
-}
-
-void SoundTriggerHwService::Module::onCallbackEvent(const sp<CallbackEvent>& event)
-{
-    ALOGV("onCallbackEvent type %d", event->mType);
-
-    // Memory is coming from a trusted process.
-    sp<IMemory> eventMemory = event->mMemory;
-
-    if (eventMemory == 0 || eventMemory->unsecurePointer() == NULL) {
-        return;
-    }
-    if (mModuleClients.isEmpty()) {
-        ALOGI("%s no clients", __func__);
-        return;
-    }
-
-    Vector< sp<ModuleClient> > clients;
-
-    switch (event->mType) {
-    case CallbackEvent::TYPE_RECOGNITION: {
-        struct sound_trigger_recognition_event *recognitionEvent =
-                (struct sound_trigger_recognition_event *)eventMemory->unsecurePointer();
-        {
-            AutoMutex lock(mLock);
-            sp<Model> model = getModel(recognitionEvent->model);
-            if (model == 0) {
-                ALOGW("%s model == 0", __func__);
-                return;
-            }
-            if (model->mState != Model::STATE_ACTIVE) {
-                ALOGV("onCallbackEvent model->mState %d != Model::STATE_ACTIVE", model->mState);
-                return;
-            }
-
-            recognitionEvent->capture_session = model->mCaptureSession;
-            model->mState = Model::STATE_IDLE;
-            clients.add(model->mModuleClient);
-        }
-    } break;
-    case CallbackEvent::TYPE_SOUNDMODEL: {
-        struct sound_trigger_model_event *soundmodelEvent =
-                (struct sound_trigger_model_event *)eventMemory->unsecurePointer();
-        {
-            AutoMutex lock(mLock);
-            sp<Model> model = getModel(soundmodelEvent->model);
-            if (model == 0) {
-                ALOGW("%s model == 0", __func__);
-                return;
-            }
-            clients.add(model->mModuleClient);
-        }
-    } break;
-    case CallbackEvent::TYPE_SERVICE_STATE: {
-        {
-            AutoMutex lock(mLock);
-            for (size_t i = 0; i < mModuleClients.size(); i++) {
-                if (mModuleClients[i] != 0) {
-                    clients.add(mModuleClients[i]);
-                }
-            }
-        }
-    } break;
-    default:
-        LOG_ALWAYS_FATAL("onCallbackEvent unknown event type %d", event->mType);
-    }
-
-    for (size_t i = 0; i < clients.size(); i++) {
-        clients[i]->onCallbackEvent(event);
-    }
-}
-
-sp<SoundTriggerHwService::Model> SoundTriggerHwService::Module::getModel(
-        sound_model_handle_t handle)
-{
-    sp<Model> model;
-    ssize_t index = mModels.indexOfKey(handle);
-    if (index >= 0) {
-        model = mModels.valueAt(index);
-    }
-    return model;
-}
-
-// Called with mServiceLock held
-void SoundTriggerHwService::Module::setCaptureState_l(bool active)
-{
-    ALOGV("Module::setCaptureState_l %d", active);
-    sp<SoundTriggerHwService> service;
-    sound_trigger_service_state_t state;
-
-    Vector< sp<IMemory> > events;
-    {
-        AutoMutex lock(mLock);
-        state = (active && !mDescriptor.properties.concurrent_capture) ?
-                                        SOUND_TRIGGER_STATE_DISABLED : SOUND_TRIGGER_STATE_ENABLED;
-
-        if (state == mServiceState) {
-            return;
-        }
-
-        mServiceState = state;
-
-        service = mService.promote();
-        if (service == 0) {
-            return;
-        }
-
-        if (state == SOUND_TRIGGER_STATE_ENABLED) {
-            goto exit;
-        }
-
-        const bool supports_stop_all =
-                (mHalInterface != 0) && (mHalInterface->stopAllRecognitions() != -ENOSYS);
-
-        for (size_t i = 0; i < mModels.size(); i++) {
-            sp<Model> model = mModels.valueAt(i);
-            if (model->mState == Model::STATE_ACTIVE) {
-                if (mHalInterface != 0 && !supports_stop_all) {
-                    mHalInterface->stopRecognition(model->mHandle);
-                }
-                // keep model in ACTIVE state so that event is processed by onCallbackEvent()
-                if (model->mType == SOUND_MODEL_TYPE_KEYPHRASE) {
-                    struct sound_trigger_phrase_recognition_event event;
-                    memset(&event, 0, sizeof(struct sound_trigger_phrase_recognition_event));
-                    event.num_phrases = model->mConfig.num_phrases;
-                    for (size_t i = 0; i < event.num_phrases; i++) {
-                        event.phrase_extras[i] = model->mConfig.phrases[i];
-                    }
-                    event.common.status = RECOGNITION_STATUS_ABORT;
-                    event.common.type = model->mType;
-                    event.common.model = model->mHandle;
-                    event.common.data_size = 0;
-                    sp<IMemory> eventMemory = service->prepareRecognitionEvent(&event.common);
-                    if (eventMemory != 0) {
-                        events.add(eventMemory);
-                    }
-                } else if (model->mType == SOUND_MODEL_TYPE_GENERIC) {
-                    struct sound_trigger_generic_recognition_event event;
-                    memset(&event, 0, sizeof(struct sound_trigger_generic_recognition_event));
-                    event.common.status = RECOGNITION_STATUS_ABORT;
-                    event.common.type = model->mType;
-                    event.common.model = model->mHandle;
-                    event.common.data_size = 0;
-                    sp<IMemory> eventMemory = service->prepareRecognitionEvent(&event.common);
-                    if (eventMemory != 0) {
-                        events.add(eventMemory);
-                    }
-                } else if (model->mType == SOUND_MODEL_TYPE_UNKNOWN) {
-                    struct sound_trigger_phrase_recognition_event event;
-                    memset(&event, 0, sizeof(struct sound_trigger_phrase_recognition_event));
-                    event.common.status = RECOGNITION_STATUS_ABORT;
-                    event.common.type = model->mType;
-                    event.common.model = model->mHandle;
-                    event.common.data_size = 0;
-                    sp<IMemory> eventMemory = service->prepareRecognitionEvent(&event.common);
-                    if (eventMemory != 0) {
-                        events.add(eventMemory);
-                    }
-                } else {
-                    goto exit;
-                }
-            }
-        }
-    }
-
-    for (size_t i = 0; i < events.size(); i++) {
-        sp<CallbackEvent> callbackEvent = new CallbackEvent(CallbackEvent::TYPE_RECOGNITION,
-                                                            events[i]);
-        callbackEvent->setModule(this);
-        service->sendCallbackEvent(callbackEvent);
-    }
-
-exit:
-    service->sendServiceStateEvent(state, this);
-}
-
-
-SoundTriggerHwService::Model::Model(sound_model_handle_t handle, audio_session_t session,
-                                    audio_io_handle_t ioHandle, audio_devices_t device,
-                                    sound_trigger_sound_model_type_t type,
-                                    sp<ModuleClient>& moduleClient) :
-    mHandle(handle), mState(STATE_IDLE), mCaptureSession(session),
-    mCaptureIOHandle(ioHandle), mCaptureDevice(device), mType(type),
-    mModuleClient(moduleClient)
-{
-}
-
-#undef LOG_TAG
-#define LOG_TAG "SoundTriggerHwService::ModuleClient"
-
-SoundTriggerHwService::ModuleClient::ModuleClient(const sp<Module>& module,
-                                                  const sp<ISoundTriggerClient>& client,
-                                                  const String16& opPackageName)
- : mModule(module), mClient(client), mOpPackageName(opPackageName)
-{
-}
-
-void SoundTriggerHwService::ModuleClient::onFirstRef()
-{
-    sp<IBinder> binder = IInterface::asBinder(mClient);
-    if (binder != 0) {
-        binder->linkToDeath(this);
-    }
-}
-
-SoundTriggerHwService::ModuleClient::~ModuleClient()
-{
-}
-
-status_t SoundTriggerHwService::ModuleClient::dump(int fd __unused,
-                                                   const Vector<String16>& args __unused) {
-    String8 result;
-    return NO_ERROR;
-}
-
-void SoundTriggerHwService::ModuleClient::detach() {
-    ALOGV("detach()");
-    if (!captureHotwordAllowed(mOpPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return;
-    }
-
-    {
-        AutoMutex lock(mLock);
-        if (mClient != 0) {
-            IInterface::asBinder(mClient)->unlinkToDeath(this);
-            mClient.clear();
-        }
-    }
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return;
-    }
-    module->detach(this);
-}
-
-status_t SoundTriggerHwService::ModuleClient::loadSoundModel(const sp<IMemory>& modelMemory,
-                                sound_model_handle_t *handle)
-{
-    ALOGV("loadSoundModel() handle");
-    if (!captureHotwordAllowed(mOpPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-    if (checkIMemory(modelMemory) != NO_ERROR) {
-        return BAD_VALUE;
-    }
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return NO_INIT;
-    }
-    return module->loadSoundModel(modelMemory, this, handle);
-}
-
-status_t SoundTriggerHwService::ModuleClient::unloadSoundModel(sound_model_handle_t handle)
-{
-    ALOGV("unloadSoundModel() model handle %d", handle);
-    if (!captureHotwordAllowed(mOpPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return NO_INIT;
-    }
-    return module->unloadSoundModel(handle);
-}
-
-status_t SoundTriggerHwService::ModuleClient::startRecognition(sound_model_handle_t handle,
-                                 const sp<IMemory>& dataMemory)
-{
-    ALOGV("startRecognition() model handle %d", handle);
-    if (!captureHotwordAllowed(mOpPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-    if (checkIMemory(dataMemory) != NO_ERROR) {
-        return BAD_VALUE;
-    }
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return NO_INIT;
-    }
-    return module->startRecognition(handle, dataMemory);
-}
-
-status_t SoundTriggerHwService::ModuleClient::stopRecognition(sound_model_handle_t handle)
-{
-    ALOGV("stopRecognition() model handle %d", handle);
-    if (!captureHotwordAllowed(mOpPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return NO_INIT;
-    }
-    return module->stopRecognition(handle);
-}
-
-status_t SoundTriggerHwService::ModuleClient::getModelState(sound_model_handle_t handle)
-{
-    ALOGV("getModelState() model handle %d", handle);
-    if (!captureHotwordAllowed(mOpPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return NO_INIT;
-    }
-    return module->getModelState(handle);
-}
-
-status_t SoundTriggerHwService::ModuleClient::setParameter(sound_model_handle_t handle,
-        sound_trigger_model_parameter_t param, int32_t value)
-{
-    ALOGV("setParameter() handle=%d, param=%d, value=%d", handle, param, value);
-    if (!captureHotwordAllowed(mOpPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return NO_INIT;
-    }
-    return module->setParameter(handle, param, value);
-}
-
-status_t SoundTriggerHwService::ModuleClient::getParameter(sound_model_handle_t handle,
-        sound_trigger_model_parameter_t param, int32_t* value)
-{
-    ALOGV("getParameter() handle=%d, param=%d", handle, param);
-    if (!captureHotwordAllowed(mOpPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return NO_INIT;
-    }
-    return module->getParameter(handle, param, value);
-}
-
-status_t SoundTriggerHwService::ModuleClient::queryParameter(sound_model_handle_t handle,
-        sound_trigger_model_parameter_t param,
-        sound_trigger_model_parameter_range_t* param_range)
-{
-    ALOGV("isParameterSupported() handle=%d, param=%d", handle, param);
-    if (!captureHotwordAllowed(mOpPackageName,
-                               IPCThreadState::self()->getCallingPid(),
-                               IPCThreadState::self()->getCallingUid())) {
-        return PERMISSION_DENIED;
-    }
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return NO_INIT;
-    }
-    return module->queryParameter(handle, param, param_range);
-}
-
-void SoundTriggerHwService::ModuleClient::setCaptureState_l(bool active)
-{
-    ALOGV("ModuleClient::setCaptureState_l %d", active);
-    sp<SoundTriggerHwService> service;
-    sound_trigger_service_state_t state;
-
-    sp<Module> module = mModule.promote();
-    if (module == 0) {
-        return;
-    }
-    {
-        AutoMutex lock(mLock);
-        state = (active && !module->isConcurrentCaptureAllowed()) ?
-                                        SOUND_TRIGGER_STATE_DISABLED : SOUND_TRIGGER_STATE_ENABLED;
-
-        service = module->service().promote();
-        if (service == 0) {
-            return;
-        }
-    }
-    service->sendServiceStateEvent(state, this);
-}
-
-void SoundTriggerHwService::ModuleClient::onCallbackEvent(const sp<CallbackEvent>& event)
-{
-    ALOGV("ModuleClient onCallbackEvent type %d", event->mType);
-
-    sp<IMemory> eventMemory = event->mMemory;
-
-    // Memory is coming from a trusted process.
-    if (eventMemory == 0 || eventMemory->unsecurePointer() == NULL) {
-        return;
-    }
-
-    sp<ISoundTriggerClient> client;
-    {
-        AutoMutex lock(mLock);
-        client = mClient;
-    }
-
-    if (client != 0) {
-        switch (event->mType) {
-        case CallbackEvent::TYPE_RECOGNITION: {
-            client->onRecognitionEvent(eventMemory);
-        } break;
-        case CallbackEvent::TYPE_SOUNDMODEL: {
-            client->onSoundModelEvent(eventMemory);
-        } break;
-        case CallbackEvent::TYPE_SERVICE_STATE: {
-            client->onServiceStateChange(eventMemory);
-        } break;
-        default:
-            LOG_ALWAYS_FATAL("onCallbackEvent unknown event type %d", event->mType);
-        }
-    }
-}
-
-void SoundTriggerHwService::ModuleClient::binderDied(
-    const wp<IBinder> &who __unused) {
-    ALOGW("client binder died for client %p", this);
-    detach();
-}
-
-}; // namespace android
diff --git a/services/soundtrigger/SoundTriggerHwService.h b/services/soundtrigger/SoundTriggerHwService.h
deleted file mode 100644
index 4057e14..0000000
--- a/services/soundtrigger/SoundTriggerHwService.h
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * Copyright (C) 2008 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.
- */
-
-#ifndef ANDROID_HARDWARE_SOUNDTRIGGER_HAL_SERVICE_H
-#define ANDROID_HARDWARE_SOUNDTRIGGER_HAL_SERVICE_H
-
-#include <utils/Vector.h>
-//#include <binder/AppOpsManager.h>
-#include <binder/MemoryDealer.h>
-#include <binder/BinderService.h>
-#include <binder/IAppOpsCallback.h>
-#include <soundtrigger/ISoundTriggerHwService.h>
-#include <soundtrigger/ISoundTrigger.h>
-#include <soundtrigger/ISoundTriggerClient.h>
-#include <system/sound_trigger.h>
-#include "SoundTriggerHalInterface.h"
-
-namespace android {
-
-class MemoryHeapBase;
-
-class SoundTriggerHwService :
-    public BinderService<SoundTriggerHwService>,
-    public BnSoundTriggerHwService
-{
-    friend class BinderService<SoundTriggerHwService>;
-public:
-    class Module;
-    class ModuleClient;
-
-    static char const* getServiceName() { return "media.sound_trigger_hw"; }
-
-                        SoundTriggerHwService();
-    virtual             ~SoundTriggerHwService();
-
-    // ISoundTriggerHwService
-    virtual status_t listModules(const String16& opPackageName,
-                                 struct sound_trigger_module_descriptor *modules,
-                                 uint32_t *numModules);
-
-    virtual status_t attach(const String16& opPackageName,
-                            const sound_trigger_module_handle_t handle,
-                            const sp<ISoundTriggerClient>& client,
-                            sp<ISoundTrigger>& module);
-
-    virtual status_t setCaptureState(bool active);
-
-    virtual status_t    onTransact(uint32_t code, const Parcel& data,
-                                   Parcel* reply, uint32_t flags);
-
-    virtual status_t    dump(int fd, const Vector<String16>& args);
-
-    class Model : public RefBase {
-     public:
-
-        enum {
-            STATE_IDLE,
-            STATE_ACTIVE
-        };
-
-        Model(sound_model_handle_t handle, audio_session_t session, audio_io_handle_t ioHandle,
-              audio_devices_t device, sound_trigger_sound_model_type_t type,
-              sp<ModuleClient>& moduleClient);
-        ~Model() {}
-
-        sound_model_handle_t    mHandle;
-        int                     mState;
-        audio_session_t         mCaptureSession;
-        audio_io_handle_t       mCaptureIOHandle;
-        audio_devices_t         mCaptureDevice;
-        sound_trigger_sound_model_type_t mType;
-        struct sound_trigger_recognition_config mConfig;
-        sp<ModuleClient>        mModuleClient;
-    };
-
-    class CallbackEvent : public RefBase {
-    public:
-        typedef enum {
-            TYPE_RECOGNITION,
-            TYPE_SOUNDMODEL,
-            TYPE_SERVICE_STATE,
-        } event_type;
-        CallbackEvent(event_type type, sp<IMemory> memory);
-
-        virtual             ~CallbackEvent();
-
-        void setModule(wp<Module> module) { mModule = module; }
-        void setModuleClient(wp<ModuleClient> moduleClient) { mModuleClient = moduleClient; }
-
-        event_type mType;
-        sp<IMemory> mMemory;
-        wp<Module> mModule;
-        wp<ModuleClient> mModuleClient;
-    };
-
-    class Module : public RefBase {
-    public:
-
-       Module(const sp<SoundTriggerHwService>& service,
-              const sp<SoundTriggerHalInterface>& halInterface,
-              sound_trigger_module_descriptor descriptor);
-
-       virtual ~Module();
-
-       virtual status_t loadSoundModel(const sp<IMemory>& modelMemory,
-                                       sp<ModuleClient> moduleClient,
-                                       sound_model_handle_t *handle);
-
-       virtual status_t unloadSoundModel(sound_model_handle_t handle);
-
-       virtual status_t startRecognition(sound_model_handle_t handle,
-                                         const sp<IMemory>& dataMemory);
-       virtual status_t stopRecognition(sound_model_handle_t handle);
-       virtual status_t getModelState(sound_model_handle_t handle);
-       virtual status_t setParameter(sound_model_handle_t handle,
-                                     sound_trigger_model_parameter_t param,
-                                     int32_t value);
-       virtual status_t getParameter(sound_model_handle_t handle,
-                                     sound_trigger_model_parameter_t param,
-                                     int32_t* value);
-       virtual status_t queryParameter(sound_model_handle_t handle,
-                                       sound_trigger_model_parameter_t param,
-                                       sound_trigger_model_parameter_range_t* param_range);
-
-       sp<SoundTriggerHalInterface> halInterface() const { return mHalInterface; }
-       struct sound_trigger_module_descriptor descriptor() { return mDescriptor; }
-       wp<SoundTriggerHwService> service() const { return mService; }
-       bool isConcurrentCaptureAllowed() const { return mDescriptor.properties.concurrent_capture; }
-
-       sp<Model> getModel(sound_model_handle_t handle);
-
-       void setCaptureState_l(bool active);
-
-       sp<ModuleClient> addClient(const sp<ISoundTriggerClient>& client,
-                                  const String16& opPackageName);
-
-       void detach(const sp<ModuleClient>& moduleClient);
-
-       void onCallbackEvent(const sp<CallbackEvent>& event);
-
-    private:
-
-        Mutex                                  mLock;
-        wp<SoundTriggerHwService>              mService;
-        sp<SoundTriggerHalInterface>           mHalInterface;
-        struct sound_trigger_module_descriptor mDescriptor;
-        Vector< sp<ModuleClient> >             mModuleClients;
-        DefaultKeyedVector< sound_model_handle_t, sp<Model> >     mModels;
-        sound_trigger_service_state_t          mServiceState;
-    }; // class Module
-
-    class ModuleClient : public virtual RefBase,
-                         public BnSoundTrigger,
-                         public IBinder::DeathRecipient {
-    public:
-
-       ModuleClient(const sp<Module>& module,
-              const sp<ISoundTriggerClient>& client,
-              const String16& opPackageName);
-
-       virtual ~ModuleClient();
-
-       virtual void detach();
-
-       virtual status_t loadSoundModel(const sp<IMemory>& modelMemory,
-                                       sound_model_handle_t *handle);
-
-       virtual status_t unloadSoundModel(sound_model_handle_t handle);
-
-       virtual status_t startRecognition(sound_model_handle_t handle,
-                                         const sp<IMemory>& dataMemory);
-       virtual status_t stopRecognition(sound_model_handle_t handle);
-       virtual status_t getModelState(sound_model_handle_t handle);
-       virtual status_t setParameter(sound_model_handle_t handle,
-                                     sound_trigger_model_parameter_t param,
-                                     int32_t value);
-       virtual status_t getParameter(sound_model_handle_t handle,
-                                     sound_trigger_model_parameter_t param,
-                                     int32_t* value);
-       virtual status_t queryParameter(sound_model_handle_t handle,
-                                sound_trigger_model_parameter_t param,
-                                sound_trigger_model_parameter_range_t* param_range);
-
-       virtual status_t dump(int fd, const Vector<String16>& args);
-
-       virtual void onFirstRef();
-
-       // IBinder::DeathRecipient implementation
-       virtual void        binderDied(const wp<IBinder> &who);
-
-       void onCallbackEvent(const sp<CallbackEvent>& event);
-
-       void setCaptureState_l(bool active);
-
-       sp<ISoundTriggerClient> client() const { return mClient; }
-
-    private:
-
-        mutable Mutex               mLock;
-        wp<Module>                  mModule;
-        sp<ISoundTriggerClient>     mClient;
-        const String16              mOpPackageName;
-    }; // class ModuleClient
-
-    class CallbackThread : public Thread {
-    public:
-
-        explicit CallbackThread(const wp<SoundTriggerHwService>& service);
-
-        virtual             ~CallbackThread();
-
-        // Thread virtuals
-        virtual bool        threadLoop();
-
-        // RefBase
-        virtual void        onFirstRef();
-
-                void        exit();
-                void        sendCallbackEvent(const sp<CallbackEvent>& event);
-
-    private:
-        wp<SoundTriggerHwService>   mService;
-        Condition                   mCallbackCond;
-        Mutex                       mCallbackLock;
-        Vector< sp<CallbackEvent> > mEventQueue;
-    };
-
-    static void recognitionCallback(struct sound_trigger_recognition_event *event, void *cookie);
-           sp<IMemory> prepareRecognitionEvent(struct sound_trigger_recognition_event *event);
-           void sendRecognitionEvent(struct sound_trigger_recognition_event *event, Module *module);
-
-    static void soundModelCallback(struct sound_trigger_model_event *event, void *cookie);
-           sp<IMemory> prepareSoundModelEvent(struct sound_trigger_model_event *event);
-           void sendSoundModelEvent(struct sound_trigger_model_event *event, Module *module);
-
-           sp<IMemory> prepareServiceStateEvent(sound_trigger_service_state_t state);
-           void sendServiceStateEvent(sound_trigger_service_state_t state, Module *module);
-           void sendServiceStateEvent(sound_trigger_service_state_t state,
-                                      ModuleClient *moduleClient);
-
-           void sendCallbackEvent(const sp<CallbackEvent>& event);
-           void onCallbackEvent(const sp<CallbackEvent>& event);
-
-private:
-
-    virtual void onFirstRef();
-
-    Mutex               mServiceLock;
-    volatile int32_t    mNextUniqueId;
-    DefaultKeyedVector< sound_trigger_module_handle_t, sp<Module> >     mModules;
-    sp<CallbackThread>  mCallbackThread;
-    sp<MemoryDealer>    mMemoryDealer;
-    Mutex               mMemoryDealerLock;
-    bool                mCaptureState;
-};
-
-} // namespace android
-
-#endif // ANDROID_HARDWARE_SOUNDTRIGGER_HAL_SERVICE_H
diff --git a/soundtrigger/Android.bp b/soundtrigger/Android.bp
deleted file mode 100644
index 6178153..0000000
--- a/soundtrigger/Android.bp
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2014 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.
-
-cc_library_shared {
-    name: "libsoundtrigger",
-
-    srcs: [
-        "SoundTrigger.cpp",
-        "ISoundTrigger.cpp",
-        "ISoundTriggerClient.cpp",
-        "ISoundTriggerHwService.cpp",
-    ],
-
-    shared_libs: [
-        "libcutils",
-        "libutils",
-        "liblog",
-        "libbinder",
-    ],
-
-    cflags: [
-        "-Werror",
-        "-Wall",
-    ],
-}
diff --git a/soundtrigger/ISoundTrigger.cpp b/soundtrigger/ISoundTrigger.cpp
deleted file mode 100644
index 9b1da13..0000000
--- a/soundtrigger/ISoundTrigger.cpp
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
-**
-** Copyright 2014, 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.
-*/
-
-#define LOG_TAG "ISoundTrigger"
-#include <utils/Log.h>
-#include <utils/Errors.h>
-#include <binder/IMemory.h>
-#include <soundtrigger/ISoundTrigger.h>
-#include <soundtrigger/ISoundTriggerHwService.h>
-#include <soundtrigger/ISoundTriggerClient.h>
-#include <system/sound_trigger.h>
-
-namespace android {
-
-enum {
-    DETACH = IBinder::FIRST_CALL_TRANSACTION,
-    LOAD_SOUND_MODEL,
-    UNLOAD_SOUND_MODEL,
-    START_RECOGNITION,
-    STOP_RECOGNITION,
-    GET_MODEL_STATE,
-    SET_PARAMETER,
-    GET_PARAMETER,
-    QUERY_PARAMETER,
-};
-
-class BpSoundTrigger: public BpInterface<ISoundTrigger>
-{
-public:
-    explicit BpSoundTrigger(const sp<IBinder>& impl)
-        : BpInterface<ISoundTrigger>(impl)
-    {
-    }
-
-    void detach()
-    {
-        ALOGV("detach");
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        remote()->transact(DETACH, data, &reply);
-    }
-
-    status_t loadSoundModel(const sp<IMemory>&  modelMemory,
-                                    sound_model_handle_t *handle)
-    {
-        if (modelMemory == 0 || handle == NULL) {
-            return BAD_VALUE;
-        }
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(modelMemory));
-        status_t status = remote()->transact(LOAD_SOUND_MODEL, data, &reply);
-        if (status != NO_ERROR) {
-            return status;
-        }
-        status = (status_t)reply.readInt32();
-        if (status == NO_ERROR) {
-            reply.read(handle, sizeof(sound_model_handle_t));
-        }
-        return status;
-    }
-
-    virtual status_t unloadSoundModel(sound_model_handle_t handle)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        data.write(&handle, sizeof(sound_model_handle_t));
-        status_t status = remote()->transact(UNLOAD_SOUND_MODEL, data, &reply);
-        if (status == NO_ERROR) {
-            status = (status_t)reply.readInt32();
-        }
-        return status;
-    }
-
-    virtual status_t startRecognition(sound_model_handle_t handle,
-                                      const sp<IMemory>& dataMemory)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        data.write(&handle, sizeof(sound_model_handle_t));
-        if (dataMemory == 0) {
-            data.writeInt32(0);
-        } else {
-            data.writeInt32(dataMemory->size());
-        }
-        data.writeStrongBinder(IInterface::asBinder(dataMemory));
-        status_t status = remote()->transact(START_RECOGNITION, data, &reply);
-        if (status == NO_ERROR) {
-            status = (status_t)reply.readInt32();
-        }
-        return status;
-    }
-
-    virtual status_t stopRecognition(sound_model_handle_t handle)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        data.write(&handle, sizeof(sound_model_handle_t));
-        status_t status = remote()->transact(STOP_RECOGNITION, data, &reply);
-        if (status == NO_ERROR) {
-            status = (status_t)reply.readInt32();
-        }
-        return status;
-    }
-
-    virtual status_t getModelState(sound_model_handle_t handle)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        data.write(&handle, sizeof(sound_model_handle_t));
-        status_t status = remote()->transact(GET_MODEL_STATE, data, &reply);
-        if (status == NO_ERROR) {
-            status = (status_t)reply.readInt32();
-        }
-        return status;
-    }
-
-    virtual status_t setParameter(sound_model_handle_t handle,
-                                     sound_trigger_model_parameter_t param,
-                                     int32_t value)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        data.write(&handle, sizeof(sound_model_handle_t));
-        data.write(&param, sizeof(sound_trigger_model_parameter_t));
-        data.writeInt32(value);
-        status_t status = remote()->transact(SET_PARAMETER, data, &reply);
-        if (status == NO_ERROR) {
-            status = (status_t)reply.readInt32();
-        }
-        return status;
-    }
-
-    virtual status_t getParameter(sound_model_handle_t handle,
-                                     sound_trigger_model_parameter_t param,
-                                     int32_t* value)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        data.write(&handle, sizeof(sound_model_handle_t));
-        data.write(&param, sizeof(sound_trigger_model_parameter_t));
-        status_t status = remote()->transact(GET_PARAMETER, data, &reply);
-        if (status == NO_ERROR) {
-            status = (status_t)reply.readInt32();
-            *value = reply.readInt32();
-        }
-        return status;
-    }
-
-    virtual status_t queryParameter(sound_model_handle_t handle,
-            sound_trigger_model_parameter_t param,
-            sound_trigger_model_parameter_range_t* param_range)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTrigger::getInterfaceDescriptor());
-        data.write(&handle, sizeof(sound_model_handle_t));
-        data.write(&param, sizeof(sound_trigger_model_parameter_t));
-        status_t status = remote()->transact(QUERY_PARAMETER, data, &reply);
-        if (status == NO_ERROR) {
-            status = (status_t)reply.readInt32();
-            param_range->start = reply.readInt32();
-            param_range->end = reply.readInt32();
-        }
-        return status;
-    }
-
-};
-
-IMPLEMENT_META_INTERFACE(SoundTrigger, "android.hardware.ISoundTrigger");
-
-// ----------------------------------------------------------------------
-
-status_t BnSoundTrigger::onTransact(
-    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
-    switch(code) {
-        case DETACH: {
-            ALOGV("DETACH");
-            CHECK_INTERFACE(ISoundTrigger, data, reply);
-            detach();
-            return NO_ERROR;
-        } break;
-        case LOAD_SOUND_MODEL: {
-            CHECK_INTERFACE(ISoundTrigger, data, reply);
-            sp<IMemory> modelMemory = interface_cast<IMemory>(
-                data.readStrongBinder());
-            sound_model_handle_t handle;
-            status_t status = loadSoundModel(modelMemory, &handle);
-            reply->writeInt32(status);
-            if (status == NO_ERROR) {
-                reply->write(&handle, sizeof(sound_model_handle_t));
-            }
-            return NO_ERROR;
-        }
-        case UNLOAD_SOUND_MODEL: {
-            CHECK_INTERFACE(ISoundTrigger, data, reply);
-            sound_model_handle_t handle;
-            data.read(&handle, sizeof(sound_model_handle_t));
-            status_t status = unloadSoundModel(handle);
-            reply->writeInt32(status);
-            return NO_ERROR;
-        }
-        case START_RECOGNITION: {
-            CHECK_INTERFACE(ISoundTrigger, data, reply);
-            sound_model_handle_t handle;
-            data.read(&handle, sizeof(sound_model_handle_t));
-            sp<IMemory> dataMemory;
-            if (data.readInt32() != 0) {
-                dataMemory = interface_cast<IMemory>(data.readStrongBinder());
-            }
-            status_t status = startRecognition(handle, dataMemory);
-            reply->writeInt32(status);
-            return NO_ERROR;
-        }
-        case STOP_RECOGNITION: {
-            CHECK_INTERFACE(ISoundTrigger, data, reply);
-            sound_model_handle_t handle;
-            data.read(&handle, sizeof(sound_model_handle_t));
-            status_t status = stopRecognition(handle);
-            reply->writeInt32(status);
-            return NO_ERROR;
-        }
-        case GET_MODEL_STATE: {
-            CHECK_INTERFACE(ISoundTrigger, data, reply);
-            sound_model_handle_t handle;
-            status_t status = UNKNOWN_ERROR;
-            status_t ret = data.read(&handle, sizeof(sound_model_handle_t));
-            if (ret == NO_ERROR) {
-                status = getModelState(handle);
-            }
-            reply->writeInt32(status);
-            return ret;
-        }
-        case SET_PARAMETER: {
-            CHECK_INTERFACE(ISoundTrigger, data, reply);
-            sound_model_handle_t handle;
-            sound_trigger_model_parameter_t param;
-            int32_t value;
-            status_t status = UNKNOWN_ERROR;
-            status_t ret;
-            ret = data.read(&handle, sizeof(sound_model_handle_t));
-            if (ret != NO_ERROR) {
-                return ret;
-            }
-            ret = data.read(&param, sizeof(sound_trigger_model_parameter_t));
-            if (ret != NO_ERROR) {
-                return ret;
-            }
-            ret = data.read(&value, sizeof(int32_t));
-            if (ret != NO_ERROR) {
-                return ret;
-            }
-            status = setParameter(handle, param, value);
-            reply->writeInt32(status);
-            return NO_ERROR;
-        }
-        case GET_PARAMETER: {
-            CHECK_INTERFACE(ISoundTrigger, data, reply);
-            sound_model_handle_t handle;
-            sound_trigger_model_parameter_t param;
-            int32_t value;
-            status_t status = UNKNOWN_ERROR;
-            status_t ret;
-            ret = data.read(&handle, sizeof(sound_model_handle_t));
-            if (ret != NO_ERROR) {
-                return ret;
-            }
-            ret = data.read(&param, sizeof(sound_trigger_model_parameter_t));
-            if (ret != NO_ERROR) {
-                return ret;
-            }
-            status = getParameter(handle, param, &value);
-            reply->writeInt32(status);
-            reply->writeInt32(value);
-            return NO_ERROR;
-        }
-        case QUERY_PARAMETER: {
-            CHECK_INTERFACE(ISoundTrigger, data, reply);
-            sound_model_handle_t handle;
-            sound_trigger_model_parameter_t param;
-            status_t ret;
-            status_t status = UNKNOWN_ERROR;
-            sound_trigger_model_parameter_range_t retValue;
-            ret = data.read(&handle, sizeof(sound_model_handle_t));
-            if (ret != NO_ERROR) {
-                return ret;
-            }
-            ret = data.read(&param, sizeof(sound_trigger_model_parameter_t));
-            if (ret != NO_ERROR) {
-                return ret;
-            }
-            status = queryParameter(handle, param, &retValue);
-            reply->writeInt32(status);
-            reply->writeInt32(retValue.start);
-            reply->writeInt32(retValue.end);
-            return NO_ERROR;
-        }
-        default:
-            return BBinder::onTransact(code, data, reply, flags);
-    }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/soundtrigger/ISoundTriggerClient.cpp b/soundtrigger/ISoundTriggerClient.cpp
deleted file mode 100644
index 1385631..0000000
--- a/soundtrigger/ISoundTriggerClient.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
-**
-** Copyright 2014, 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 <stdint.h>
-#include <sys/types.h>
-#include <binder/IMemory.h>
-#include <binder/Parcel.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-#include <soundtrigger/ISoundTriggerClient.h>
-
-namespace android {
-
-enum {
-    ON_RECOGNITION_EVENT = IBinder::FIRST_CALL_TRANSACTION,
-    ON_SOUNDMODEL_EVENT,
-    ON_SERVICE_STATE_CHANGE
-};
-
-class BpSoundTriggerClient: public BpInterface<ISoundTriggerClient>
-{
-
-public:
-    explicit BpSoundTriggerClient(const sp<IBinder>& impl)
-        : BpInterface<ISoundTriggerClient>(impl)
-    {
-    }
-
-    virtual void onRecognitionEvent(const sp<IMemory>& eventMemory)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTriggerClient::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(eventMemory));
-        remote()->transact(ON_RECOGNITION_EVENT,
-                           data,
-                           &reply);
-    }
-
-    virtual void onSoundModelEvent(const sp<IMemory>& eventMemory)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTriggerClient::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(eventMemory));
-        remote()->transact(ON_SOUNDMODEL_EVENT,
-                           data,
-                           &reply);
-    }
-    virtual void onServiceStateChange(const sp<IMemory>& eventMemory)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTriggerClient::getInterfaceDescriptor());
-        data.writeStrongBinder(IInterface::asBinder(eventMemory));
-        remote()->transact(ON_SERVICE_STATE_CHANGE,
-                           data,
-                           &reply);
-    }
-};
-
-IMPLEMENT_META_INTERFACE(SoundTriggerClient,
-                         "android.hardware.ISoundTriggerClient");
-
-// ----------------------------------------------------------------------
-
-status_t BnSoundTriggerClient::onTransact(
-    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
-    switch(code) {
-        case ON_RECOGNITION_EVENT: {
-            CHECK_INTERFACE(ISoundTriggerClient, data, reply);
-            sp<IMemory> eventMemory = interface_cast<IMemory>(
-                data.readStrongBinder());
-            onRecognitionEvent(eventMemory);
-            return NO_ERROR;
-        } break;
-        case ON_SOUNDMODEL_EVENT: {
-            CHECK_INTERFACE(ISoundTriggerClient, data, reply);
-            sp<IMemory> eventMemory = interface_cast<IMemory>(
-                data.readStrongBinder());
-            onSoundModelEvent(eventMemory);
-            return NO_ERROR;
-        } break;
-        case ON_SERVICE_STATE_CHANGE: {
-            CHECK_INTERFACE(ISoundTriggerClient, data, reply);
-            sp<IMemory> eventMemory = interface_cast<IMemory>(
-                data.readStrongBinder());
-            onServiceStateChange(eventMemory);
-            return NO_ERROR;
-        } break;
-        default:
-            return BBinder::onTransact(code, data, reply, flags);
-    }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/soundtrigger/ISoundTriggerHwService.cpp b/soundtrigger/ISoundTriggerHwService.cpp
deleted file mode 100644
index bd107b4..0000000
--- a/soundtrigger/ISoundTriggerHwService.cpp
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
-**
-** Copyright 2014, 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.
-*/
-
-#define LOG_TAG "BpSoundTriggerHwService"
-//#define LOG_NDEBUG 0
-
-#include <utils/Log.h>
-#include <utils/Errors.h>
-
-#include <stdint.h>
-#include <sys/types.h>
-#include <binder/IMemory.h>
-#include <binder/Parcel.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-
-#include <soundtrigger/ISoundTriggerHwService.h>
-#include <soundtrigger/ISoundTrigger.h>
-#include <soundtrigger/ISoundTriggerClient.h>
-
-namespace android {
-
-enum {
-    LIST_MODULES = IBinder::FIRST_CALL_TRANSACTION,
-    ATTACH,
-    SET_CAPTURE_STATE,
-};
-
-#define MAX_ITEMS_PER_LIST 1024
-
-class BpSoundTriggerHwService: public BpInterface<ISoundTriggerHwService>
-{
-public:
-    explicit BpSoundTriggerHwService(const sp<IBinder>& impl)
-        : BpInterface<ISoundTriggerHwService>(impl)
-    {
-    }
-
-    virtual status_t listModules(const String16& opPackageName,
-                                 struct sound_trigger_module_descriptor *modules,
-                                 uint32_t *numModules)
-    {
-        if (numModules == NULL || (*numModules != 0 && modules == NULL)) {
-            return BAD_VALUE;
-        }
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTriggerHwService::getInterfaceDescriptor());
-        data.writeString16(opPackageName);
-        unsigned int numModulesReq = (modules == NULL) ? 0 : *numModules;
-        data.writeInt32(numModulesReq);
-        status_t status = remote()->transact(LIST_MODULES, data, &reply);
-        if (status == NO_ERROR) {
-            status = (status_t)reply.readInt32();
-            *numModules = (unsigned int)reply.readInt32();
-        }
-        ALOGV("listModules() status %d got *numModules %d", status, *numModules);
-        if (status == NO_ERROR) {
-            if (numModulesReq > *numModules) {
-                numModulesReq = *numModules;
-            }
-            if (numModulesReq > 0) {
-                reply.read(modules, numModulesReq * sizeof(struct sound_trigger_module_descriptor));
-            }
-        }
-        return status;
-    }
-
-    virtual status_t attach(const String16& opPackageName,
-                            const sound_trigger_module_handle_t handle,
-                            const sp<ISoundTriggerClient>& client,
-                            sp<ISoundTrigger>& module)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTriggerHwService::getInterfaceDescriptor());
-        data.writeString16(opPackageName);
-        data.write(&handle, sizeof(sound_trigger_module_handle_t));
-        data.writeStrongBinder(IInterface::asBinder(client));
-        status_t status = remote()->transact(ATTACH, data, &reply);
-        if (status != NO_ERROR) {
-            return status;
-        }
-        status = reply.readInt32();
-        if (reply.readInt32() != 0) {
-            module = interface_cast<ISoundTrigger>(reply.readStrongBinder());
-        }
-        return status;
-    }
-
-    virtual status_t setCaptureState(bool active)
-    {
-        Parcel data, reply;
-        data.writeInterfaceToken(ISoundTriggerHwService::getInterfaceDescriptor());
-        data.writeInt32(active);
-        status_t status = remote()->transact(SET_CAPTURE_STATE, data, &reply);
-        if (status == NO_ERROR) {
-            status = reply.readInt32();
-        }
-        return status;
-    }
-
-};
-
-IMPLEMENT_META_INTERFACE(SoundTriggerHwService, "android.hardware.ISoundTriggerHwService");
-
-// ----------------------------------------------------------------------
-
-status_t BnSoundTriggerHwService::onTransact(
-    uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags)
-{
-    switch(code) {
-        case LIST_MODULES: {
-            CHECK_INTERFACE(ISoundTriggerHwService, data, reply);
-            String16 opPackageName;
-            status_t status = data.readString16(&opPackageName);
-            if (status != NO_ERROR) {
-                return status;
-            }
-            unsigned int numModulesReq = data.readInt32();
-            if (numModulesReq > MAX_ITEMS_PER_LIST) {
-                numModulesReq = MAX_ITEMS_PER_LIST;
-            }
-            unsigned int numModules = numModulesReq;
-            struct sound_trigger_module_descriptor *modules =
-                    (struct sound_trigger_module_descriptor *)calloc(numModulesReq,
-                                                   sizeof(struct sound_trigger_module_descriptor));
-            if (modules == NULL) {
-                reply->writeInt32(NO_MEMORY);
-                reply->writeInt32(0);
-                return NO_ERROR;
-            }
-            status = listModules(opPackageName, modules, &numModules);
-            reply->writeInt32(status);
-            reply->writeInt32(numModules);
-            ALOGV("LIST_MODULES status %d got numModules %d", status, numModules);
-
-            if (status == NO_ERROR) {
-                if (numModulesReq > numModules) {
-                    numModulesReq = numModules;
-                }
-                reply->write(modules,
-                             numModulesReq * sizeof(struct sound_trigger_module_descriptor));
-            }
-            free(modules);
-            return NO_ERROR;
-        }
-
-        case ATTACH: {
-            CHECK_INTERFACE(ISoundTriggerHwService, data, reply);
-            String16 opPackageName;
-            status_t status = data.readString16(&opPackageName);
-            if (status != NO_ERROR) {
-                return status;
-            }
-            sound_trigger_module_handle_t handle;
-            data.read(&handle, sizeof(sound_trigger_module_handle_t));
-            sp<ISoundTriggerClient> client =
-                    interface_cast<ISoundTriggerClient>(data.readStrongBinder());
-            sp<ISoundTrigger> module;
-            status = attach(opPackageName, handle, client, module);
-            reply->writeInt32(status);
-            if (module != 0) {
-                reply->writeInt32(1);
-                reply->writeStrongBinder(IInterface::asBinder(module));
-            } else {
-                reply->writeInt32(0);
-            }
-            return NO_ERROR;
-        } break;
-
-        case SET_CAPTURE_STATE: {
-            CHECK_INTERFACE(ISoundTriggerHwService, data, reply);
-            reply->writeInt32(setCaptureState((bool)data.readInt32()));
-            return NO_ERROR;
-        } break;
-
-        default:
-            return BBinder::onTransact(code, data, reply, flags);
-    }
-}
-
-// ----------------------------------------------------------------------------
-
-}; // namespace android
diff --git a/soundtrigger/OWNERS b/soundtrigger/OWNERS
deleted file mode 100644
index e83f6b9..0000000
--- a/soundtrigger/OWNERS
+++ /dev/null
@@ -1,2 +0,0 @@
-elaurent@google.com
-thorntonc@google.com
diff --git a/soundtrigger/SoundTrigger.cpp b/soundtrigger/SoundTrigger.cpp
deleted file mode 100644
index 021697b..0000000
--- a/soundtrigger/SoundTrigger.cpp
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
-**
-** Copyright (C) 2014, 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.
-*/
-
-#define LOG_TAG "SoundTrigger"
-//#define LOG_NDEBUG 0
-
-#include <utils/Log.h>
-#include <utils/threads.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
-#include <binder/IMemory.h>
-
-#include <soundtrigger/SoundTrigger.h>
-#include <soundtrigger/ISoundTrigger.h>
-#include <soundtrigger/ISoundTriggerHwService.h>
-#include <soundtrigger/ISoundTriggerClient.h>
-#include <soundtrigger/SoundTriggerCallback.h>
-
-namespace android {
-
-namespace {
-    sp<ISoundTriggerHwService> gSoundTriggerHwService;
-    const int                  kSoundTriggerHwServicePollDelay = 500000; // 0.5s
-    const char*                kSoundTriggerHwServiceName      = "media.sound_trigger_hw";
-    Mutex                      gLock;
-
-    class DeathNotifier : public IBinder::DeathRecipient
-    {
-    public:
-        DeathNotifier() {
-        }
-
-        virtual void binderDied(const wp<IBinder>& who __unused) {
-            ALOGV("binderDied");
-            Mutex::Autolock _l(gLock);
-            gSoundTriggerHwService.clear();
-            ALOGW("Sound trigger service died!");
-        }
-    };
-
-    sp<DeathNotifier>         gDeathNotifier;
-}; // namespace anonymous
-
-const sp<ISoundTriggerHwService> SoundTrigger::getSoundTriggerHwService()
-{
-    Mutex::Autolock _l(gLock);
-    if (gSoundTriggerHwService.get() == 0) {
-        sp<IServiceManager> sm = defaultServiceManager();
-        sp<IBinder> binder;
-        do {
-            binder = sm->getService(String16(kSoundTriggerHwServiceName));
-            if (binder != 0) {
-                break;
-            }
-            ALOGW("SoundTriggerHwService not published, waiting...");
-            usleep(kSoundTriggerHwServicePollDelay);
-        } while(true);
-        if (gDeathNotifier == NULL) {
-            gDeathNotifier = new DeathNotifier();
-        }
-        binder->linkToDeath(gDeathNotifier);
-        gSoundTriggerHwService = interface_cast<ISoundTriggerHwService>(binder);
-    }
-    ALOGE_IF(gSoundTriggerHwService == 0, "no SoundTriggerHwService!?");
-    return gSoundTriggerHwService;
-}
-
-// Static methods
-status_t SoundTrigger::listModules(const String16& opPackageName,
-                                   struct sound_trigger_module_descriptor *modules,
-                                   uint32_t *numModules)
-{
-    ALOGV("listModules()");
-    const sp<ISoundTriggerHwService> service = getSoundTriggerHwService();
-    if (service == 0) {
-        return NO_INIT;
-    }
-    return service->listModules(opPackageName, modules, numModules);
-}
-
-sp<SoundTrigger> SoundTrigger::attach(const String16& opPackageName,
-                                      const sound_trigger_module_handle_t module,
-                                      const sp<SoundTriggerCallback>& callback)
-{
-    ALOGV("attach()");
-    sp<SoundTrigger> soundTrigger;
-    const sp<ISoundTriggerHwService> service = getSoundTriggerHwService();
-    if (service == 0) {
-        return soundTrigger;
-    }
-    soundTrigger = new SoundTrigger(module, callback);
-    status_t status = service->attach(opPackageName, module, soundTrigger,
-                                      soundTrigger->mISoundTrigger);
-
-    if (status == NO_ERROR && soundTrigger->mISoundTrigger != 0) {
-        IInterface::asBinder(soundTrigger->mISoundTrigger)->linkToDeath(soundTrigger);
-    } else {
-        ALOGW("Error %d connecting to sound trigger service", status);
-        soundTrigger.clear();
-    }
-    return soundTrigger;
-}
-
-
-status_t SoundTrigger::setCaptureState(bool active)
-{
-    ALOGV("setCaptureState(%d)", active);
-    const sp<ISoundTriggerHwService> service = getSoundTriggerHwService();
-    if (service == 0) {
-        return NO_INIT;
-    }
-    return service->setCaptureState(active);
-}
-
-// SoundTrigger
-SoundTrigger::SoundTrigger(sound_trigger_module_handle_t /*module*/,
-                                 const sp<SoundTriggerCallback>& callback)
-    : mCallback(callback)
-{
-}
-
-SoundTrigger::~SoundTrigger()
-{
-    if (mISoundTrigger != 0) {
-        mISoundTrigger->detach();
-    }
-}
-
-
-void SoundTrigger::detach() {
-    ALOGV("detach()");
-    Mutex::Autolock _l(mLock);
-    mCallback.clear();
-    if (mISoundTrigger != 0) {
-        mISoundTrigger->detach();
-        IInterface::asBinder(mISoundTrigger)->unlinkToDeath(this);
-        mISoundTrigger = 0;
-    }
-}
-
-status_t SoundTrigger::loadSoundModel(const sp<IMemory>& modelMemory,
-                                sound_model_handle_t *handle)
-{
-    Mutex::Autolock _l(mLock);
-    if (mISoundTrigger == 0) {
-        return NO_INIT;
-    }
-
-    return mISoundTrigger->loadSoundModel(modelMemory, handle);
-}
-
-status_t SoundTrigger::unloadSoundModel(sound_model_handle_t handle)
-{
-    Mutex::Autolock _l(mLock);
-    if (mISoundTrigger == 0) {
-        return NO_INIT;
-    }
-    return mISoundTrigger->unloadSoundModel(handle);
-}
-
-status_t SoundTrigger::startRecognition(sound_model_handle_t handle,
-                                        const sp<IMemory>& dataMemory)
-{
-    Mutex::Autolock _l(mLock);
-    if (mISoundTrigger == 0) {
-        return NO_INIT;
-    }
-    return mISoundTrigger->startRecognition(handle, dataMemory);
-}
-
-status_t SoundTrigger::stopRecognition(sound_model_handle_t handle)
-{
-    Mutex::Autolock _l(mLock);
-    if (mISoundTrigger == 0) {
-        return NO_INIT;
-    }
-    return mISoundTrigger->stopRecognition(handle);
-}
-
-status_t SoundTrigger::getModelState(sound_model_handle_t handle)
-{
-    Mutex::Autolock _l(mLock);
-    if (mISoundTrigger == 0) {
-        return NO_INIT;
-    }
-    return mISoundTrigger->getModelState(handle);
-}
-
-status_t SoundTrigger::setParameter(sound_model_handle_t handle,
-        sound_trigger_model_parameter_t param, int32_t value)
-{
-    Mutex::Autolock _l(mLock);
-    if (mISoundTrigger == 0) {
-        return NO_INIT;
-    }
-    return mISoundTrigger->setParameter(handle, param, value);
-}
-
-status_t SoundTrigger::getParameter(sound_model_handle_t handle,
-        sound_trigger_model_parameter_t param, int32_t* value)
-{
-    Mutex::Autolock _l(mLock);
-    if (mISoundTrigger == 0) {
-        return NO_INIT;
-    }
-    return mISoundTrigger->getParameter(handle, param, value);
-}
-
-status_t SoundTrigger::queryParameter(sound_model_handle_t handle,
-        sound_trigger_model_parameter_t param,
-        sound_trigger_model_parameter_range_t* param_range)
-{
-    Mutex::Autolock _l(mLock);
-    if (mISoundTrigger == 0) {
-        return NO_INIT;
-    }
-    return mISoundTrigger->queryParameter(handle, param, param_range);
-}
-
-// BpSoundTriggerClient
-void SoundTrigger::onRecognitionEvent(const sp<IMemory>& eventMemory)
-{
-    Mutex::Autolock _l(mLock);
-    if (eventMemory == 0 || eventMemory->unsecurePointer() == NULL) {
-        return;
-    }
-
-    if (mCallback != 0) {
-        // Memory is coming from a trusted process.
-        mCallback->onRecognitionEvent(
-                (struct sound_trigger_recognition_event *)eventMemory->unsecurePointer());
-    }
-}
-
-void SoundTrigger::onSoundModelEvent(const sp<IMemory>& eventMemory)
-{
-    Mutex::Autolock _l(mLock);
-    if (eventMemory == 0 || eventMemory->unsecurePointer() == NULL) {
-        return;
-    }
-
-    if (mCallback != 0) {
-        // Memory is coming from a trusted process.
-        mCallback->onSoundModelEvent(
-                (struct sound_trigger_model_event *)eventMemory->unsecurePointer());
-    }
-}
-
-void SoundTrigger::onServiceStateChange(const sp<IMemory>& eventMemory)
-{
-    Mutex::Autolock _l(mLock);
-    if (eventMemory == 0 || eventMemory->unsecurePointer() == NULL) {
-        return;
-    }
-
-    if (mCallback != 0) {
-        // Memory is coming from a trusted process.
-        mCallback->onServiceStateChange(
-                *((sound_trigger_service_state_t *)eventMemory->unsecurePointer()));
-    }
-}
-
-//IBinder::DeathRecipient
-void SoundTrigger::binderDied(const wp<IBinder>& who __unused) {
-    Mutex::Autolock _l(mLock);
-    ALOGW("SoundTrigger server binder Died ");
-    mISoundTrigger = 0;
-    if (mCallback != 0) {
-        mCallback->onServiceDied();
-    }
-}
-
-status_t SoundTrigger::stringToGuid(const char *str, sound_trigger_uuid_t *guid)
-{
-    if (str == NULL || guid == NULL) {
-        return BAD_VALUE;
-    }
-
-    int tmp[10];
-
-    if (sscanf(str, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
-            tmp, tmp+1, tmp+2, tmp+3, tmp+4, tmp+5, tmp+6, tmp+7, tmp+8, tmp+9) < 10) {
-        return BAD_VALUE;
-    }
-    guid->timeLow = (uint32_t)tmp[0];
-    guid->timeMid = (uint16_t)tmp[1];
-    guid->timeHiAndVersion = (uint16_t)tmp[2];
-    guid->clockSeq = (uint16_t)tmp[3];
-    guid->node[0] = (uint8_t)tmp[4];
-    guid->node[1] = (uint8_t)tmp[5];
-    guid->node[2] = (uint8_t)tmp[6];
-    guid->node[3] = (uint8_t)tmp[7];
-    guid->node[4] = (uint8_t)tmp[8];
-    guid->node[5] = (uint8_t)tmp[9];
-
-    return NO_ERROR;
-}
-
-status_t SoundTrigger::guidToString(const sound_trigger_uuid_t *guid, char *str, size_t maxLen)
-{
-    if (guid == NULL || str == NULL) {
-        return BAD_VALUE;
-    }
-
-    snprintf(str, maxLen, "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
-            guid->timeLow,
-            guid->timeMid,
-            guid->timeHiAndVersion,
-            guid->clockSeq,
-            guid->node[0],
-            guid->node[1],
-            guid->node[2],
-            guid->node[3],
-            guid->node[4],
-            guid->node[5]);
-
-    return NO_ERROR;
-}
-
-}; // namespace android