Merge "TV Input target-side test"
diff --git a/drm/1.0/default/CryptoFactory.cpp b/drm/1.0/default/CryptoFactory.cpp
index e46233d..13cad67 100644
--- a/drm/1.0/default/CryptoFactory.cpp
+++ b/drm/1.0/default/CryptoFactory.cpp
@@ -15,10 +15,11 @@
  */
 #define LOG_TAG "android.hardware.drm@1.0-impl"
 
+#include <utils/Log.h>
+
 #include "CryptoFactory.h"
 #include "CryptoPlugin.h"
 #include "TypeConvert.h"
-#include <utils/Log.h>
 
 namespace android {
 namespace hardware {
@@ -26,45 +27,63 @@
 namespace V1_0 {
 namespace implementation {
 
-    CryptoFactory::CryptoFactory() :
-        loader("/vendor/lib/mediadrm", "createCryptoFactory") {
-    }
+CryptoFactory::CryptoFactory() :
+    trebleLoader("/vendor/lib/hw", "createCryptoFactory"),
+    legacyLoader("/vendor/lib/mediadrm", "createCryptoFactory") {
+}
 
-    // Methods from ::android::hardware::drm::V1_0::ICryptoFactory follow.
-    Return<bool> CryptoFactory::isCryptoSchemeSupported(
-            const hidl_array<uint8_t, 16>& uuid) {
-        for (size_t i = 0; i < loader.factoryCount(); i++) {
-            if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
-                return true;
-            }
-        }
-        return false;
-    }
+// Methods from ::android::hardware::drm::V1_0::ICryptoFactory follow.
+Return<bool> CryptoFactory::isCryptoSchemeSupported(
+        const hidl_array<uint8_t, 16>& uuid) {
+    return isCryptoSchemeSupported(trebleLoader, uuid) ||
+            isCryptoSchemeSupported(legacyLoader, uuid);
+}
 
-    Return<void> CryptoFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
-            const hidl_vec<uint8_t>& initData, createPlugin_cb _hidl_cb) {
-        for (size_t i = 0; i < loader.factoryCount(); i++) {
-            if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
-                android::CryptoPlugin *legacyPlugin = NULL;
-                status_t status = loader.getFactory(i)->createPlugin(uuid.data(),
-                        initData.data(), initData.size(), &legacyPlugin);
-                CryptoPlugin *newPlugin = NULL;
-                if (legacyPlugin == NULL) {
-                    ALOGE("Crypto legacy HAL: failed to create crypto plugin");
-                } else {
-                    newPlugin = new CryptoPlugin(legacyPlugin);
+Return<void> CryptoFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
+        const hidl_vec<uint8_t>& initData, createPlugin_cb _hidl_cb) {
+    sp<ICryptoPlugin> plugin = createTreblePlugin(uuid, initData);
+    if (plugin == nullptr) {
+        plugin = createLegacyPlugin(uuid, initData);
+    }
+    _hidl_cb(plugin != nullptr ? Status::OK : Status::ERROR_DRM_CANNOT_HANDLE, plugin);
+    return Void();
+}
+
+sp<ICryptoPlugin> CryptoFactory::createTreblePlugin(const hidl_array<uint8_t, 16>& uuid,
+        const hidl_vec<uint8_t>& initData) {
+    sp<ICryptoPlugin> plugin;
+    for (size_t i = 0; i < trebleLoader.factoryCount(); i++) {
+        Return<void> hResult = trebleLoader.getFactory(i)->createPlugin(uuid, initData,
+                [&](Status status, const sp<ICryptoPlugin>& hPlugin) {
+                    if (status == Status::OK) {
+                        plugin = hPlugin;
+                    }
                 }
-                _hidl_cb(toStatus(status), newPlugin);
-                return Void();
-            }
+            );
+        if (plugin != nullptr) {
+            return plugin;
         }
-        _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL);
-        return Void();
     }
+    return nullptr;
+}
 
-    ICryptoFactory* HIDL_FETCH_ICryptoFactory(const char* /* name */) {
-        return new CryptoFactory();
+sp<ICryptoPlugin> CryptoFactory::createLegacyPlugin(const hidl_array<uint8_t, 16>& uuid,
+        const hidl_vec<uint8_t>& initData) {
+    android::CryptoPlugin *legacyPlugin = nullptr;
+    for (size_t i = 0; i < legacyLoader.factoryCount(); i++) {
+        legacyLoader.getFactory(i)->createPlugin(uuid.data(),
+                initData.data(), initData.size(), &legacyPlugin);
+        if (legacyPlugin) {
+            return new CryptoPlugin(legacyPlugin);
+        }
     }
+    return nullptr;
+}
+
+
+ICryptoFactory* HIDL_FETCH_ICryptoFactory(const char* /* name */) {
+    return new CryptoFactory();
+}
 
 }  // namespace implementation
 }  // namespace V1_0
diff --git a/drm/1.0/default/CryptoFactory.h b/drm/1.0/default/CryptoFactory.h
index 412b557..d774406 100644
--- a/drm/1.0/default/CryptoFactory.h
+++ b/drm/1.0/default/CryptoFactory.h
@@ -41,8 +41,7 @@
     CryptoFactory();
     virtual ~CryptoFactory() {}
 
-    // Methods from ::android::hardware::drm::V1_0::ICryptoFactory follow.
-
+    // Methods from ::android::hardware::drmn::V1_0::ICryptoFactory follow.
     Return<bool> isCryptoSchemeSupported(const hidl_array<uint8_t, 16>& uuid)
             override;
 
@@ -51,7 +50,27 @@
             override;
 
 private:
-    android::PluginLoader<android::CryptoFactory> loader;
+    template <typename L> Return<bool> isCryptoSchemeSupported(
+            const L& loader, const hidl_array<uint8_t, 16>& uuid) {
+        for (size_t i = 0; i < loader.factoryCount(); i++) {
+           if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    sp<ICryptoPlugin> createTreblePlugin(const hidl_array<uint8_t, 16>& uuid,
+                    const hidl_vec<uint8_t>& initData);
+
+    sp<ICryptoPlugin> createLegacyPlugin(const hidl_array<uint8_t, 16>& uuid,
+                    const hidl_vec<uint8_t>& initData);
+
+    typedef android::PluginLoader<ICryptoFactory> PluginLoader;
+    PluginLoader trebleLoader;
+
+    typedef android::PluginLoader<android::CryptoFactory> LegacyLoader;
+    LegacyLoader legacyLoader;
 
     CryptoFactory(const CryptoFactory &) = delete;
     void operator=(const CryptoFactory &) = delete;
diff --git a/drm/1.0/default/DrmFactory.cpp b/drm/1.0/default/DrmFactory.cpp
index b6f642f..d7a7c6d 100644
--- a/drm/1.0/default/DrmFactory.cpp
+++ b/drm/1.0/default/DrmFactory.cpp
@@ -15,10 +15,11 @@
  */
 #define LOG_TAG "android.hardware.drm@1.0-impl"
 
+#include <utils/Log.h>
+
 #include "DrmFactory.h"
 #include "DrmPlugin.h"
 #include "TypeConvert.h"
-#include <utils/Log.h>
 
 namespace android {
 namespace hardware {
@@ -26,56 +27,65 @@
 namespace V1_0 {
 namespace implementation {
 
-    DrmFactory::DrmFactory() :
-        loader("/vendor/lib/mediadrm", "createDrmFactory") {
+DrmFactory::DrmFactory() :
+    trebleLoader("/vendor/lib/hw", "createDrmFactory"),
+    legacyLoader("/vendor/lib/mediadrm", "createDrmFactory") {
+}
+
+// Methods from ::android::hardware::drm::V1_0::IDrmFactory follow.
+Return<bool> DrmFactory::isCryptoSchemeSupported(
+        const hidl_array<uint8_t, 16>& uuid) {
+    return isCryptoSchemeSupported(trebleLoader, uuid) ||
+            isCryptoSchemeSupported(legacyLoader, uuid);
+}
+
+Return<bool> DrmFactory::isContentTypeSupported (
+        const hidl_string& mimeType) {
+    return isContentTypeSupported<PluginLoader, hidl_string>(trebleLoader, mimeType) ||
+            isContentTypeSupported<LegacyLoader, String8>(legacyLoader, mimeType);
+}
+
+Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
+        createPlugin_cb _hidl_cb) {
+    sp<IDrmPlugin> plugin = createTreblePlugin(uuid);
+    if (plugin == nullptr) {
+        plugin = createLegacyPlugin(uuid);
     }
+    _hidl_cb(plugin != nullptr ? Status::OK : Status::ERROR_DRM_CANNOT_HANDLE, plugin);
+    return Void();
+}
 
-    // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow.
-    Return<bool> DrmFactory::isCryptoSchemeSupported (
-            const hidl_array<uint8_t, 16>& uuid) {
-        for (size_t i = 0; i < loader.factoryCount(); i++) {
-            if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    Return<bool> DrmFactory::isContentTypeSupported (
-            const hidl_string& mimeType) {
-        for (size_t i = 0; i < loader.factoryCount(); i++) {
-            if (loader.getFactory(i)->isContentTypeSupported(String8(mimeType.c_str()))) {
-                return true;
-            }
-        }
-        return false;
-    }
-
-    Return<void> DrmFactory::createPlugin(const hidl_array<uint8_t, 16>& uuid,
-            createPlugin_cb _hidl_cb) {
-
-        for (size_t i = 0; i < loader.factoryCount(); i++) {
-            if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
-                android::DrmPlugin *legacyPlugin = NULL;
-                status_t status = loader.getFactory(i)->createDrmPlugin(
-                        uuid.data(), &legacyPlugin);
-                DrmPlugin *newPlugin = NULL;
-                if (legacyPlugin == NULL) {
-                    ALOGE("Drm legacy HAL: failed to create drm plugin");
-                } else {
-                    newPlugin = new DrmPlugin(legacyPlugin);
+sp<IDrmPlugin> DrmFactory::createTreblePlugin(const hidl_array<uint8_t, 16>& uuid) {
+    sp<IDrmPlugin> plugin;
+    for (size_t i = 0; i < trebleLoader.factoryCount(); i++) {
+        Return<void> hResult = trebleLoader.getFactory(i)->createPlugin(uuid,
+                [&](Status status, const sp<IDrmPlugin>& hPlugin) {
+                    if (status == Status::OK) {
+                        plugin = hPlugin;
+                    }
                 }
-                _hidl_cb(toStatus(status), newPlugin);
-                return Void();
-            }
+            );
+        if (plugin != nullptr) {
+            return plugin;
         }
-        _hidl_cb(Status::ERROR_DRM_CANNOT_HANDLE, NULL);
-        return Void();
     }
+    return nullptr;
+}
 
-    IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) {
-        return new DrmFactory();
+sp<IDrmPlugin> DrmFactory::createLegacyPlugin(const hidl_array<uint8_t, 16>& uuid) {
+    android::DrmPlugin *legacyPlugin = nullptr;
+    for (size_t i = 0; i < legacyLoader.factoryCount(); i++) {
+        legacyLoader.getFactory(i)->createDrmPlugin(uuid.data(), &legacyPlugin);
+        if (legacyPlugin) {
+            return new DrmPlugin(legacyPlugin);
+        }
     }
+    return nullptr;
+}
+
+IDrmFactory* HIDL_FETCH_IDrmFactory(const char* /* name */) {
+    return new DrmFactory();
+}
 
 }  // namespace implementation
 }  // namespace V1_0
diff --git a/drm/1.0/default/DrmFactory.h b/drm/1.0/default/DrmFactory.h
index 78b7f6e..3291ea2 100644
--- a/drm/1.0/default/DrmFactory.h
+++ b/drm/1.0/default/DrmFactory.h
@@ -42,18 +42,43 @@
     virtual ~DrmFactory() {}
 
     // Methods from ::android::hardware::drm::V1_0::IDrmFactory follow.
-
     Return<bool> isCryptoSchemeSupported(const hidl_array<uint8_t, 16>& uuid)
             override;
 
-    Return<bool> isContentTypeSupported(const hidl_string &mimeType)
+    Return<bool> isContentTypeSupported(const hidl_string& mimeType)
             override;
 
     Return<void> createPlugin(const hidl_array<uint8_t, 16>& uuid,
-            createPlugin_cb _hidl_cb) override;
-
+             createPlugin_cb _hidl_cb) override;
 private:
-    android::PluginLoader<android::DrmFactory> loader;
+    template <typename L> Return<bool> isCryptoSchemeSupported(
+            const L& loader, const hidl_array<uint8_t, 16>& uuid) {
+        for (size_t i = 0; i < loader.factoryCount(); i++) {
+            if (loader.getFactory(i)->isCryptoSchemeSupported(uuid.data())) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    template <typename L, typename S> Return<bool> isContentTypeSupported(
+            const L& loader, const hidl_string& mimeType) {
+        for (size_t i = 0; i < loader.factoryCount(); i++) {
+            if (loader.getFactory(i)->isContentTypeSupported(S(mimeType))) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    sp<IDrmPlugin> createTreblePlugin(const hidl_array<uint8_t, 16>& uuid);
+    sp<IDrmPlugin> createLegacyPlugin(const hidl_array<uint8_t, 16>& uuid);
+
+    typedef android::PluginLoader<IDrmFactory> PluginLoader;
+    PluginLoader trebleLoader;
+
+    typedef android::PluginLoader<android::DrmFactory> LegacyLoader;
+    LegacyLoader legacyLoader;
 
     DrmFactory(const DrmFactory &) = delete;
     void operator=(const DrmFactory &) = delete;
diff --git a/radio/1.0/IRadioIndication.hal b/radio/1.0/IRadioIndication.hal
index 79ebf30..fb8666f 100644
--- a/radio/1.0/IRadioIndication.hal
+++ b/radio/1.0/IRadioIndication.hal
@@ -342,10 +342,6 @@
    oneway exitEmergencyCallbackMode(RadioIndicationType type);
 
    /*
-    * TODO(Consider moving this to separate interface. Client will receive this function with an
-    * IRadioResponse interface so that all requests in that IRadioResponse will fail before
-    * rilConnected() is received)
-    *
     * Indicates the ril connects and returns the version
     *
     * @param type Type of radio indication
@@ -472,4 +468,4 @@
     *        restart" that explains the cause of the modem restart
     */
    oneway modemReset(RadioIndicationType type, string reason);
-};
\ No newline at end of file
+};
diff --git a/radio/1.0/types.hal b/radio/1.0/types.hal
index 593dc92..c0a6475 100644
--- a/radio/1.0/types.hal
+++ b/radio/1.0/types.hal
@@ -117,9 +117,6 @@
     ABORTED = 65,                         // Operation aborted
     INVALID_RESPONSE = 66,                // Response from vendor had invalid data
 
-    // TODO(May be moved to vendor HAL extension)
-    // OEM specific error codes. To be used by OEM when they don't want to reveal
-    // specific error codes which would be replaced by Generic failure.
     OEM_ERROR_1 = 501,
     OEM_ERROR_2 = 502,
     OEM_ERROR_3 = 503,
@@ -462,9 +459,6 @@
     AUTH_FAILURE_ON_EMERGENCY_CALL = 0x7A,
     OEM_DCFAILCAUSE_1 = 0x1001,
 
-    // OEM specific error codes. To be used by OEMs when they don't want to
-    // reveal error code which would be replaced by PDP_FAIL_ERROR_UNSPECIFIED
-    // TODO(May be moved to vendor HAL extension)
     OEM_DCFAILCAUSE_2 = 0x1002,
     OEM_DCFAILCAUSE_3 = 0x1003,
     OEM_DCFAILCAUSE_4 = 0x1004,
diff --git a/vehicle/2.0/Android.mk b/vehicle/2.0/Android.mk
index 9544960..1dd0f45 100644
--- a/vehicle/2.0/Android.mk
+++ b/vehicle/2.0/Android.mk
@@ -1081,6 +1081,25 @@
 LOCAL_GENERATED_SOURCES += $(GEN)
 
 #
+# Build types.hal (Wheel)
+#
+GEN := $(intermediates)/android/hardware/vehicle/V2_0/Wheel.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava \
+        -randroid.hardware:hardware/interfaces \
+        -randroid.hidl:system/libhidl/transport \
+        android.hardware.vehicle@2.0::types.Wheel
+
+$(GEN): $(LOCAL_PATH)/types.hal
+	$(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
 # Build IVehicle.hal
 #
 GEN := $(intermediates)/android/hardware/vehicle/V2_0/IVehicle.java
@@ -2205,6 +2224,25 @@
 LOCAL_GENERATED_SOURCES += $(GEN)
 
 #
+# Build types.hal (Wheel)
+#
+GEN := $(intermediates)/android/hardware/vehicle/V2_0/Wheel.java
+$(GEN): $(HIDL)
+$(GEN): PRIVATE_HIDL := $(HIDL)
+$(GEN): PRIVATE_DEPS := $(LOCAL_PATH)/types.hal
+$(GEN): PRIVATE_OUTPUT_DIR := $(intermediates)
+$(GEN): PRIVATE_CUSTOM_TOOL = \
+        $(PRIVATE_HIDL) -o $(PRIVATE_OUTPUT_DIR) \
+        -Ljava \
+        -randroid.hardware:hardware/interfaces \
+        -randroid.hidl:system/libhidl/transport \
+        android.hardware.vehicle@2.0::types.Wheel
+
+$(GEN): $(LOCAL_PATH)/types.hal
+	$(transform-generated-source)
+LOCAL_GENERATED_SOURCES += $(GEN)
+
+#
 # Build IVehicle.hal
 #
 GEN := $(intermediates)/android/hardware/vehicle/V2_0/IVehicle.java
diff --git a/vehicle/2.0/types.hal b/vehicle/2.0/types.hal
index fb59a5a..2026655 100644
--- a/vehicle/2.0/types.hal
+++ b/vehicle/2.0/types.hal
@@ -226,6 +226,28 @@
         | VehicleArea:GLOBAL),
 
     /*
+     * Reports wheel rotational distance in meters since last wheel tick
+     * event
+     *
+     * The value is a vector each element represents distance for individual
+     * wheel in the following order: left front, right front, left rear,
+     * right rear. VehiclePropValue.timestamp must be correctly filled in.
+     *
+     * Vendors must specify wheels that support this sensor in
+     * VehiclePropConfig.configFlags. The format of this field is a bitset of
+     * values from Wheel enum.
+     *
+     * @change_mode VehiclePropertyChangeMode:ON_CHANGE|VehiclePropertyChangeMode:CONTINUOUS
+     * @access VehiclePropertyAccess:READ
+     * @unit VehicleUnit:METER
+     */
+    WHEEL_TICK = (
+        0x0306
+        | VehiclePropertyGroup:SYSTEM
+        | VehiclePropertyType:FLOAT_VEC
+        | VehicleArea:GLOBAL),
+
+    /*
      * Currently selected gear
      *
      * @change_mode VehiclePropertyChangeMode:ON_CHANGE
@@ -2745,6 +2767,15 @@
   NMHC_CATALYST_INCOMPLETE = 0x1 << 17,
 };
 
+enum Wheel : int32_t {
+    UNKNOWN = 0x0,
+
+    LEFT_FRONT = 0x1,
+    RIGHT_FRONT = 0x2,
+    LEFT_REAR = 0x4,
+    RIGHT_REAR = 0x8,
+};
+
 enum SecondaryAirStatus : int32_t {
   UPSTREAM = 1,
 
diff --git a/vibrator/1.0/default/service.cpp b/vibrator/1.0/default/service.cpp
index 064e1e2..7cc0744 100644
--- a/vibrator/1.0/default/service.cpp
+++ b/vibrator/1.0/default/service.cpp
@@ -22,5 +22,5 @@
 using android::hardware::defaultPassthroughServiceImplementation;
 
 int main() {
-    return defaultPassthroughServiceImplementation<IVibrator>("vibrator");
+    return defaultPassthroughServiceImplementation<IVibrator>();
 }