common: halcc: Introduce backend transport configuration 75/321375/13
authorYoungjae Cho <y0.cho@samsung.com>
Wed, 19 Mar 2025 07:40:16 +0000 (16:40 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Fri, 11 Apr 2025 07:42:24 +0000 (16:42 +0900)
The platform manifest has changed to specify which mode the platform
would supports. On top of this, now a backend have to choice one of
the transports provided by the platform manifest. To this end, the hal
image would have its configuration about transport at the predefined
location, /hal/etc/hal-backend-config.xml.
 - It would be like this:
   | <hal-backend>
   |  <manifest>
   |  <hal-module>
   |  <name>HAL_MODULE_AUDIO</name>
   |  <transport><!--empty implies passthrough--></transport>
   |  </hal-module>
   |  <hal-module>
   |  <name>HAL_MODULE_CODEC</name>
   |  <transport>passthrough</transport>
   |  </hal-module>
   |  <hal-module>
   |  <name>HAL_MODULE_CAMERA</name>
   |  <transport>ipc</transport>
   |  </hal-module>
   |  </manifest>
   | </hal-backend>

It is similar to the platform manifest excpet the <transport> is tag,
not the property of <version>. And only one transport, ipc or passthrough,
can be specified as a <transport> value.

If a backend chose transport that is not supported by platform, the
behavior is same as incompatible version, that is, it won't working.
This affects behavior of existing function, hal_common_get_transport().
But, on this patch, handle such case not an error but a success, working
passthrough. To fully operational, it needs time for deploying file,
hal-backend-config.xml, to every profile.

Change-Id: I08ee8faf465fe6fb27f9474c3ddcf51906b36b0e
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
14 files changed:
include/hal-common.h
src/hal-api-common.c
src/hal-api-compatibility-checker-object.c
src/hal-api-compatibility-checker-object.h
src/hal-api-compatibility-checker-parser.c
src/hal-api-compatibility-checker.c
src/hal-api-compatibility-checker.h
tests/unittest/test-hal-compatibility-checker [deleted file]
tests/unittest/test-hal-compatibility-checker-manifest/backend/hal-backend-manifest.xml [new file with mode: 0644]
tests/unittest/test-hal-compatibility-checker-manifest/hal-api-audio-manifest.xml [new file with mode: 0644]
tests/unittest/test-hal-compatibility-checker-manifest/hal-api-camera-manifest.xml [new file with mode: 0644]
tests/unittest/test-hal-compatibility-checker-manifest/hal-api-codec-manifest.xml [new file with mode: 0644]
tests/unittest/test-hal-compatibility-checker.cc
tools/lshal/lshal.c

index fd28dc95889926651c81f0957790fc0eb30378fd..e8eafeb82e656e7bea80d9c437a314f5b44843d5 100644 (file)
@@ -337,38 +337,107 @@ int hal_common_check_backend_compatibility(enum hal_module module,
  *             enum #hal_common_transport. An index is paired with the same index in the array
  *             major_versions and minor_versions. The caller takes ownership of the data so it
  *             is responsible for caller to free it using free()
+ * @param[out] default_transport Array of default transport by each version. An index is paired
+ *             with the same index in the array major_versions and minor_versions. The caller
+ *             takes ownership of the data so it is reponsible for caller to free it using free().
  * @param[out] num_versions Number of returned major and minor versions
  * @return @c 0 on success, otherwise a negative error value
  */
 int hal_common_get_supported_interface_versions(enum hal_module module,
        unsigned int **major_versions, unsigned int **minor_versions,
-       uint32_t **transports, int *num_versions);
+       uint32_t **transports, enum hal_common_transport **default_transport, int *num_versions);
 
 /**
  * @brief Get the transport that compatible with the current hal backend
  * @details Compare to the hal_common_get_supported_interface_versions(), this function
  *          is distinctive in that it returns single transport that is compatible with backend,
- *          wherase the hal_common_get_supported_interface_versions() returns all the possible
+ *          whereas the hal_common_get_supported_interface_versions() returns all the possible
  *          versions and transports specified on the manifest file.
+ *
+ *          The steps how it internally works are:
+ *           1. Gets platform transports of matching version of backend library.
+ *              For example on the below table, if installed backend of HAL_MODULE_CODEC is version of 2.0,
+ *              then it chooses 'passthrough,ipc' as a transport supported by platform.
+ *           2. Gets backend transport of a module specified by backend manifest.
+ *              For example, let the backend transport of module HAL_MODULE_CODEC is 'passthrough'.
+ *           3. Bitwise AND of platform transport and backend transport. In this case, 'passthrough,ipc' & 'passthrough'
+ *           4. The result of AND is what this function returns. If the reulst is 0, then it is error, which means
+ *              the backend has specified not supported transport by the platform.
+ *           5. There is one excpetional case, that is, the backend manifest has specified nothing. In this case,
+ *              result will be the 'default' of platform manifest. The 'default' here is the first specified transport
+ *              of platform manifest.
+ *               - "unspecified" -> default: passthrough
+ *               - "passthrough" -> default: passthrough
+ *               - "ipc" -> default: ipc
+ *               - "passthrough,ipc" -> default: passthorugh
+ *               - "ipc,passthrough" -> default: ipc
+ *          ┌────────────────────────────────────────────────╥───────────────────────╥─────────────────────────────┐
+ *          │ platform manifest                              ║  backend manifest     ║  hal_common_get_transport() │
+ *          │ (/etc/hal/hal-api-[module]-manifest.xml)       ║  (/hal/etc/hal        ║                             │
+ *          ├───────────────────┬─────────┬──────────────────╢   -backend-manifest   ║                             │
+ *          │ module            │ version │  transport       ║    .xml)              ║                             │
+ *          ├───────────────────┼─────────┼──────────────────╫───────────────────────╫─────────────────────────────┤
+ *          │ HAL_MODULE_AUDIO  │   1.0   │  unspecified     ║ unspecified           ║ passthrough                 │
+ *          │                   │         │  (=passthrough)  ║ => select 'default'   ║                             │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢    transport of       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   2.0   │  passthrough,ipc ║    platform manifest  ║ passthrough                 │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   3.0   │  ipc,passthrough ║                       ║ ipc                         │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   4.0   │  passthrough     ║                       ║ passthrough                 │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   5.0   │  ipc             ║                       ║ ipc                         │
+ *          ├───────────────────┼─────────┼──────────────────╫───────────────────────╫─────────────────────────────┤
+ *          │ HAL_MODULE_CODEC  │   1.0   │  unspecified     ║ passthrough           ║ passthrough                 │
+ *          │                   │         │  (=passthrough)  ║                       ║                             │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   2.0   │  passthrough,ipc ║                       ║ passthrough                 │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   3.0   │  ipc,passthrough ║                       ║ passthrough                 │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   4.0   │  passthrough     ║                       ║ passthrough                 │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   5.0   │  ipc             ║                       ║ error (-EMEDIUMTYPE)        │
+ *          ├───────────────────┼─────────┼──────────────────╫───────────────────────╫─────────────────────────────┤
+ *          │ HAL_MODULE_CAMERA │   1.0   │  unspecified     ║ ipc                   ║ error (-EMEDIUMTYPE)        │
+ *          │                   │         │  (=passthrough)  ║                       ║                             │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   2.0   │  passthrough,ipc ║                       ║ ipc                         │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   3.0   │  ipc,passthrough ║                       ║ ipc                         │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   4.0   │  passthrough     ║                       ║ error (-EMEDIUMTYPE)        │
+ *          │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+ *          │                   │   5.0   │  ipc             ║                       ║ ipc                         │
+ *          └───────────────────┴─────────┴──────────────────╨───────────────────────╨─────────────────────────────┘
  * @param[in] module HAL id among enum hal_module
  * @param[out] transport The transport of version that matching to the hal backend installed
  * @return @c 0 on success, otherwise a negative error value
  * @retval -ELIBBAD Incompatible backend version with platform manifest
+ * @retval -EMEDIUMTYPE Incompatible backend transport with platform manifest
  * @retval -ENOENT No backend library installed or no valid data symbol found
  * @code
  *  // If a module manifest has specified transport like below, and the underlying
  *  // backend is version of 2.0, then it returns HAL_COMMON_TRANSPORT_PASSTHROUGH.
- *  // <hal>
+ *  // * platform manifest
+ *  // <hal-module>
  *  //    <name>HAL_MODULE_FOO</name>
  *  //    <version transport="ipc">1.0</version>
- *  //    <version transport="passthrough">2.1</version>
- *  // </hal>
+ *  //    <version transport="ipc,passthrough">2.1</version>
+ *  // </hal-module>
+ *  //
+ *  // * backend manifest
+ *  // <hal-module>
+ *  //    <name>HAL_MODULE_FOO</name>
+ *  //    <transport>passthrough</transport>
+ *  // </hal-module>
  *  int ret = hal_common_get_transport(HAL_MODULE_FOO, &transport); // HAL_COMMON_TRANSPORT_PASSTHROUGH
  *
  *  // If there are multiple transport throughout the platform-version, then
- *  // the transport of the latest compatible platform-version will be returned. That is,
+ *  // the transport of the latest compatible platform-version will be taken. That is,
  *  // if a module manifest has specified transport like below, and the underlying
- *  // backend is version of 3.0, then it returns HAL_COMMON_TRANSPORT_IPC.
+ *  // backend is version of 3.0, then it returns error.
+ *  // * platform manifest
  *  // <manifest platform-version="9.0">
  *  //    <hal>
  *  //       <name>HAL_MODULE_BAR</name>
@@ -381,7 +450,15 @@ int hal_common_get_supported_interface_versions(enum hal_module module,
  *  //       <version transport="ipc">3.1</version>
  *  //    </hal>
  *  // </manifest>
- *  int ret = hal_common_get_transport(HAL_MODULE_BAR, &transport); // HAL_COMMON_TRANSPORT_IPC
+ *  //
+ *  // * backend manifest
+ *  // <hal-module>
+ *  //    <name>HAL_MODULE_FOO</name>
+ *  //    <transport>passthrough</transport>
+ *  // </hal-module>
+ *  int ret = hal_common_get_transport(HAL_MODULE_BAR, &transport); // error. This is because the
+ *                                             // passthrough specified by backend is not supported
+ *                                             // by the platform platform at version 3.1.
  * @endcode
  */
 int hal_common_get_transport(enum hal_module module, enum hal_common_transport *transport);
index 0464c1782a3ee440f6580ff3147319317d04e52c..ff118658b6fce23e318ce0fe9d813e7d902436b6 100644 (file)
@@ -774,9 +774,9 @@ int hal_common_check_backend_compatibility(enum hal_module module,
 EXPORT
 int hal_common_get_supported_interface_versions(enum hal_module module,
        unsigned int **major_versions, unsigned int **minor_versions,
-       uint32_t **transports, int *num_versions)
+       uint32_t **transports, enum hal_common_transport **default_transport, int *num_versions)
 {
-       if (!major_versions || !minor_versions || !transports || !num_versions)
+       if (!major_versions || !minor_versions || !transports || !default_transport || !num_versions)
                return -EINVAL;
 
        if (!HALCC_ENABLED) {
@@ -786,7 +786,7 @@ int hal_common_get_supported_interface_versions(enum hal_module module,
        }
 
        return hal_api_cc_get_supported_interface_versions(module,
-               major_versions, minor_versions, transports, num_versions);
+               major_versions, minor_versions, transports, default_transport, num_versions);
 }
 
 EXPORT
index 002b380ed8a8aba3e82006bc8587b111de6ecc7f..d393a2f24123e6fe3c3bb89e7b7cf2ca19c1d93b 100644 (file)
 typedef struct halcc_version {
        int major;
        int minor;
-       enum hal_common_transport transport;
+       enum hal_common_transport transport; /* can specify multiple transport */
+       enum hal_common_transport default_transport; /* only one among transport */
 } halcc_version;
 
 typedef struct halcc_hal {
        char *name;
        halcc_version version_list[HALCC_NUM_VERSION_LIST_MAX];
        int num_version_list;
+       enum hal_common_transport backend_transport;
 } halcc_hal;
 
 typedef struct halcc_manifest {
@@ -305,7 +307,8 @@ int halcc_hal_get_name(halcc_hal *hal, const char **hal_name)
        return 0;
 }
 
-int halcc_hal_add_version(halcc_hal *hal, int major, int minor, enum hal_common_transport transport)
+int halcc_hal_add_version(halcc_hal *hal, int major, int minor, enum hal_common_transport transport,
+       enum hal_common_transport default_transport)
 {
        int i;
 
@@ -330,8 +333,8 @@ int halcc_hal_add_version(halcc_hal *hal, int major, int minor, enum hal_common_
                 * one only when it has been specified, that is, only when it is other
                 * than HAL_COMMON_TRANSPORT_UNKNOWN.
                 */
-               if (transport != HAL_COMMON_TRANSPORT_UNKNOWN)
-                       hal->version_list[i].transport = transport;
+               hal->version_list[i].transport = transport;
+               hal->version_list[i].default_transport = default_transport;
 
                break;
        }
@@ -345,13 +348,34 @@ int halcc_hal_add_version(halcc_hal *hal, int major, int minor, enum hal_common_
        hal->version_list[hal->num_version_list].major = major;
        hal->version_list[hal->num_version_list].minor = minor;
        hal->version_list[hal->num_version_list].transport = transport;
+       hal->version_list[hal->num_version_list].default_transport = default_transport;
 
        hal->num_version_list += 1;
 
        return 0;
 }
 
-int halcc_hal_get_version_list(halcc_hal *hal, int version_list[][3],
+int halcc_hal_set_backend_transport(halcc_hal *hal, enum hal_common_transport backend_transport)
+{
+       if (!hal)
+               return -EINVAL;
+
+       hal->backend_transport = backend_transport;
+
+       return 0;
+}
+
+int halcc_hal_get_backend_transport(halcc_hal *hal, enum hal_common_transport *backend_transport)
+{
+       if (!hal || !backend_transport)
+               return -EINVAL;
+
+       *backend_transport = hal->backend_transport;
+
+       return 0;
+}
+
+int halcc_hal_get_version_list(halcc_hal *hal, int version_list[][4],
        int max_num_version_list, int *num_version_list)
 {
        if (!hal || !num_version_list)
@@ -361,6 +385,7 @@ int halcc_hal_get_version_list(halcc_hal *hal, int version_list[][3],
                version_list[i][0] = hal->version_list[i].major;
                version_list[i][1] = hal->version_list[i].minor;
                version_list[i][2] = hal->version_list[i].transport;
+               version_list[i][3] = hal->version_list[i].default_transport;
        }
 
        if (hal->num_version_list > max_num_version_list) {
@@ -396,7 +421,7 @@ bool halcc_hal_is_compatible_with_version(halcc_hal *hal, int major, int minor)
 int halcc_hal_get_transport_by_version(halcc_hal *hal, int major, int minor, enum hal_common_transport *transport)
 {
        int ret;
-       int version_list[64][3] = { 0 , };
+       int version_list[64][4] = { 0 , };
        int num_version_list = 0;
 
        if (!hal || !transport)
@@ -421,3 +446,32 @@ int halcc_hal_get_transport_by_version(halcc_hal *hal, int major, int minor, enu
 
        return -ENOENT;
 }
+
+int halcc_hal_get_default_transport_by_version(halcc_hal *hal, int major, int minor, enum hal_common_transport *transport)
+{
+       int ret;
+       int version_list[64][4] = { 0 , };
+       int num_version_list = 0;
+
+       if (!hal || !transport)
+               return -EINVAL;
+
+       ret = halcc_hal_get_version_list(hal, version_list,
+               sizeof(version_list) / sizeof(version_list[0]),
+               &num_version_list);
+       if (ret < 0)
+               return ret;
+
+       for (size_t i = 0; i < num_version_list; ++i) {
+               if (version_list[i][0] != major)
+                       continue;
+
+               if (version_list[i][1] < minor)
+                       continue;
+
+               *transport = version_list[i][3];
+               return 0;
+       }
+
+       return -ENOENT;
+}
index b9cc6eac4e0f3b3638d3163e59814e2a9120565d..0526fb8835d5532e935047a76642c80b4b741bef 100644 (file)
@@ -50,12 +50,17 @@ int halcc_hal_new(halcc_hal **hal);
 void halcc_hal_free(halcc_hal *hal);
 int halcc_hal_set_name(halcc_hal *hal, const char *hal_name);
 int halcc_hal_get_name(halcc_hal *hal, const char **hal_name);
-int halcc_hal_add_version(halcc_hal *hal, int major, int minor, enum hal_common_transport transport);
+int halcc_hal_add_version(halcc_hal *hal, int major, int minor, enum hal_common_transport transport,
+       enum hal_common_transport default_transport);
+int halcc_hal_set_backend_transport(halcc_hal *hal, enum hal_common_transport backend_transport);
+int halcc_hal_get_backend_transport(halcc_hal *hal, enum hal_common_transport *backend_transport);
 int halcc_hal_get_version_list(halcc_hal *hal,
-       int version_list[][3], int max_num_version_list, int *num_version_list);
+       int version_list[][4], int max_num_version_list, int *num_version_list);
 bool halcc_hal_is_compatible_with_version(halcc_hal *hal, int major, int minor);
 int halcc_hal_get_transport_by_version(halcc_hal *hal, int major, int minor,
        enum hal_common_transport *transport);
+int halcc_hal_get_default_transport_by_version(halcc_hal *hal, int major, int minor,
+       enum hal_common_transport *transport);
 
 #ifdef __cplusplus
 }
index eab1b3a97b600c30ed962abd0fa94594c6afeeb0..21d792b92373f16e1fa347aa40ec0fdf31d21675 100644 (file)
@@ -86,6 +86,7 @@ static int parse_hal(xmlNode *node, halcc_manifest *manifest)
                        int major, minor;
                        int scanned;
                        enum hal_common_transport transports = HAL_COMMON_TRANSPORT_UNKNOWN;
+                       enum hal_common_transport default_transport = HAL_COMMON_TRANSPORT_UNKNOWN;
                        const char *transport = NULL;
                        __xmlchar__ xmlChar *version = xmlNodeGetContent(child);
                        __xmlchar__ xmlChar *property = xmlGetProp(child, "transport");
@@ -107,24 +108,51 @@ static int parse_hal(xmlNode *node, halcc_manifest *manifest)
                                }
 
                                if (strncmp(transport, "passthrough", strlen("passtrhough")) == 0) {
+                                       if (default_transport == HAL_COMMON_TRANSPORT_UNKNOWN)
+                                               default_transport = HAL_COMMON_TRANSPORT_PASSTHROUGH;
                                        transports |= HAL_COMMON_TRANSPORT_PASSTHROUGH;
                                        transport += strlen("passthrough");
                                } else if (strncmp(transport, "ipc", strlen("ipc")) == 0) {
+                                       if (default_transport == HAL_COMMON_TRANSPORT_UNKNOWN)
+                                               default_transport = HAL_COMMON_TRANSPORT_IPC;
                                        transports |= HAL_COMMON_TRANSPORT_IPC;
                                        transport += strlen("ipc");
                                } else {
                                        _W("Invalid transport=%s", transport);
                                        transports = HAL_COMMON_TRANSPORT_UNKNOWN;
+                                       default_transport = HAL_COMMON_TRANSPORT_UNKNOWN;
                                        break;
                                }
                        }
 
-                       if (transports == HAL_COMMON_TRANSPORT_UNKNOWN)
-                               transports = HAL_COMMON_TRANSPORT_PASSTHROUGH; // set default
+                       // set default transport
+                       if (transports == HAL_COMMON_TRANSPORT_UNKNOWN) {
+                               transports = HAL_COMMON_TRANSPORT_PASSTHROUGH;
+                               default_transport = HAL_COMMON_TRANSPORT_PASSTHROUGH;
+                       }
 
-                       ret = halcc_hal_add_version(hal, major, minor, transports);
+                       ret = halcc_hal_add_version(hal, major, minor, transports, default_transport);
                        if (ret != 0)
                                _E("Failed to halcc_hal_add_version(), ret=%d\n", ret);
+               } else if (xmlStrEqual(child->name, "transport")) {
+                       __xmlchar__ xmlChar *transport = xmlNodeGetContent(child);
+                       enum hal_common_transport backend_transport = HAL_COMMON_TRANSPORT_UNKNOWN;
+
+                       if (!transport)
+                               continue;
+
+                       if (xmlStrEqual(transport, "ipc")) {
+                               backend_transport = HAL_COMMON_TRANSPORT_IPC;
+                       } else if (xmlStrEqual(transport, "passthrough")) {
+                               backend_transport = HAL_COMMON_TRANSPORT_PASSTHROUGH;
+                       } else {
+                               _E("Invalid transport=%s", transport);
+                               continue;
+                       }
+
+                       ret = halcc_hal_set_backend_transport(hal, backend_transport);
+                       if (ret != 0)
+                               _W("Failed to halcc_hal_set_backend_transport(), ret=%d", ret);
                }
        }
 
@@ -146,23 +174,20 @@ static int parse_manifest(xmlNode *node, halcc_manifest *manifest)
 
        // version
        prop = xmlGetProp(node, "platform-version");
-       if (!prop) {
-               _E("Failed to xmlGetProp() \"platform-version\"\n");
-               return -EINVAL;
-       }
-
-       ret = sscanf(prop, "%d.%d", &major, &minor);
-       xmlFree(prop);
+       if (prop) {
+               ret = sscanf(prop, "%d.%d", &major, &minor);
+               xmlFree(prop);
 
-       if (ret != 2) {
-               _E("Failed to scan platform-version, ret=%d\n", ret);
-               return -EINVAL;
-       }
+               if (ret != 2) {
+                       _E("Failed to scan platform-version, ret=%d\n", ret);
+                       return -EINVAL;
+               }
 
-       ret = halcc_manifest_set_platform_version(manifest, major, minor);
-       if (ret != 0) {
-               _E("Failed to halcc_manifest_set_version(), ret=%d\n", ret);
-               return -EINVAL;
+               ret = halcc_manifest_set_platform_version(manifest, major, minor);
+               if (ret != 0) {
+                       _E("Failed to halcc_manifest_set_version(), ret=%d\n", ret);
+                       return -EINVAL;
+               }
        }
 
        for (xmlNode *child = node->children; child; child = child->next)
@@ -186,7 +211,7 @@ static int parse_xml_doc(xmlDoc *doc, halcc_manifest *manifest)
                return -EINVAL;
        }
 
-       if (!xmlStrEqual(root->name, "hal-api")) {
+       if (!xmlStrEqual(root->name, "hal-api") && !xmlStrEqual(root->name, "hal-backend")) {
                _E("Invalid root node, %s\n", root->name);
                return -EINVAL;
        }
index 31312f2b46cfdc375144b6a6635971a4044b5275..0a51d2a93577b83d6b1b1f9f8d94c1921e3f0348 100644 (file)
 
 #define HAL_CC_DEFAULT_COMPATIBILITY_RESULT_PATH       "/opt/etc/hal/.hal-backend-compatibility"
 #define HAL_CC_DEFAULT_COMPATIBILITY_LOADED_PATH       "/opt/etc/hal/.hal-backend-compatibility-loaded"
+#define HAL_CC_DEFAULT_BACKEND_MANIFEST_PATH   "/hal/etc/hal-backend-manifest.xml"
 
 #define COMPAT_INFO_MODULE_NAME_MAX                    64
 
 struct compatibility_info {
        bool initialized;
        char module_name[COMPAT_INFO_MODULE_NAME_MAX];
-       int version_list[HALCC_NUM_VERSION_LIST_MAX][3];
+       int version_list[HALCC_NUM_VERSION_LIST_MAX][4];
        int num_version_list;
+       enum hal_common_transport compatible_platform_transport;
+       enum hal_common_transport compatible_platform_default_transport;
+       enum hal_common_transport backend_transport;
        enum hal_common_backend_compatibility compatibility;
-       enum hal_common_transport compatible_transport;
 };
 static struct compatibility_info g_compatibility_info[HAL_MODULE_END];
 
 static const char *compatibility_result_path = HAL_CC_DEFAULT_COMPATIBILITY_RESULT_PATH;
 static const char *compatibility_loaded_path = HAL_CC_DEFAULT_COMPATIBILITY_LOADED_PATH;
+static const char *backend_manifest_path = HAL_CC_DEFAULT_BACKEND_MANIFEST_PATH;
 
 #ifdef HAL_API_COMMON_UNITTEST
 void hal_api_cc_set_compatibility_result_path(const char *path)
@@ -85,6 +89,19 @@ void hal_api_cc_unset_compatibility_loaded_path(void)
 {
        compatibility_loaded_path = HAL_CC_DEFAULT_COMPATIBILITY_LOADED_PATH;
 }
+
+void hal_api_cc_set_backend_manifest_path(const char *path)
+{
+       if (!path)
+               return;
+
+       backend_manifest_path = path;
+}
+
+void hal_api_cc_unset_backend_manifest_path(void)
+{
+       backend_manifest_path = HAL_CC_DEFAULT_BACKEND_MANIFEST_PATH;
+}
 #endif /* HAL_API_COMMON_UNITTEST */
 
 static int get_module_by_name(const char *name, enum hal_module *module)
@@ -148,6 +165,8 @@ static void __convert_hal_to_info(void *data_hal, void *data_info, bool skip_ver
        if (ret < 0)
                return;
 
+       info->backend_transport = g_compatibility_info[module].backend_transport;
+
        /**
         * hal_common_get_backend_version() will acquire lock, but this subroutine
         * might have locked already if was triggered from hal_common_get_backend().
@@ -172,10 +191,16 @@ static void __convert_hal_to_info(void *data_hal, void *data_info, bool skip_ver
 
        info->compatibility = HAL_COMMON_BACKEND_COMPATIBILITY_COMPATIBLE;
 
-       ret = halcc_hal_get_transport_by_version(hal, major, minor, &info->compatible_transport);
+       ret = halcc_hal_get_transport_by_version(hal, major, minor,
+               &info->compatible_platform_transport);
        if (ret < 0)
                _W("Failed to get transport, %d", ret);
 
+       ret = halcc_hal_get_default_transport_by_version(hal, major, minor,
+               &info->compatible_platform_default_transport);
+       if (ret < 0)
+               _W("Failed to get default transport, %d", ret);
+
 out:
        info->initialized = true;
 }
@@ -331,6 +356,61 @@ static int load_module_compatibility_info(enum hal_module module,
        return 0;
 }
 
+static void load_backend_transport_all(void *data_hal, void *data)
+{
+       int ret;
+       halcc_hal *hal = data_hal;
+       const char *hal_name;
+       enum hal_common_transport backend_transport = HAL_COMMON_TRANSPORT_UNKNOWN;
+       enum hal_module module;
+
+       ret = halcc_hal_get_name(hal, &hal_name);
+       if (ret < 0)
+               return;
+
+       ret = get_module_by_name(hal_name, &module);
+       if(ret < 0)
+               return;
+
+       ret = halcc_hal_get_backend_transport(hal, &backend_transport);
+       if (ret < 0) {
+               _E("Failed to get transport");
+               return;
+       }
+
+       g_compatibility_info[module].backend_transport = backend_transport;
+}
+
+static int load_backend_transport(enum hal_module module, struct compatibility_info *info)
+{
+       int ret;
+       halcc_manifest *manifest = NULL;
+
+       assert(info);
+
+       if (g_compatibility_info[module].backend_transport != HAL_COMMON_TRANSPORT_UNKNOWN) {
+               info->backend_transport = g_compatibility_info[module].backend_transport;
+               return 0;
+       }
+
+       ret = halcc_manifest_new(&manifest);
+       if (ret < 0)
+               return ret;
+
+       ret = halcc_parse_path(backend_manifest_path, manifest);
+       if (ret < 0)
+               _W("Failed to parse backend manifest");
+
+       halcc_manifest_foreach_hal(manifest, load_backend_transport_all, NULL);
+
+       halcc_manifest_free(manifest);
+       manifest = NULL;
+
+       info->backend_transport = g_compatibility_info[module].backend_transport;
+
+       return 0;
+}
+
 static int load_module_compatibility_info_fallback(enum hal_module module,
        struct compatibility_info *info, bool skip_version_check)
 {
@@ -354,6 +434,10 @@ static int load_module_compatibility_info_fallback(enum hal_module module,
 
        _hal_api_conf_exit();
 
+       ret = load_backend_transport(module, info);
+       if (ret < 0)
+               return ret;
+
        ret = halcc_manifest_new(&manifest);
        if (ret < 0)
                return ret;
@@ -469,6 +553,7 @@ int hal_api_cc_get_supported_interface_versions(enum hal_module module,
        unsigned int **major_versions,
        unsigned int **minor_versions,
        uint32_t **transports,
+       enum hal_common_transport **default_transport,
        int *num_versions)
 {
        int ret;
@@ -476,6 +561,7 @@ int hal_api_cc_get_supported_interface_versions(enum hal_module module,
        unsigned int *ret_major_versions = NULL;
        unsigned int *ret_minor_versions = NULL;
        uint32_t *ret_transports = NULL;
+       enum hal_common_transport *ret_default_transport = NULL;
        struct compatibility_info info = { 0 , };
 
        if (!major_versions || !minor_versions || !num_versions)
@@ -509,10 +595,19 @@ int hal_api_cc_get_supported_interface_versions(enum hal_module module,
                return -ENOMEM;
        }
 
+       ret_default_transport = calloc(ret_num_versions, sizeof(enum hal_common_transport));
+       if (!ret_default_transport) {
+               free(ret_major_versions);
+               free(ret_minor_versions);
+               free(ret_transports);
+               return -ENOMEM;
+       }
+
        for (int i = 0; i < ret_num_versions; ++i) {
                ret_major_versions[i] = info.version_list[i][0];
                ret_minor_versions[i] = info.version_list[i][1];
                ret_transports[i] = (uint32_t) info.version_list[i][2];
+               ret_default_transport[i] = info.version_list[i][3];
        }
 
        *major_versions = ret_major_versions;
@@ -524,6 +619,9 @@ int hal_api_cc_get_supported_interface_versions(enum hal_module module,
        *transports = ret_transports;
        ret_transports = NULL;
 
+       *default_transport = ret_default_transport;
+       ret_default_transport = NULL;
+
        *num_versions = ret_num_versions;
        ret_num_versions = 0;
 
@@ -534,6 +632,9 @@ int hal_api_cc_get_transport(enum hal_module module, enum hal_common_transport *
 {
        int ret;
        struct compatibility_info info = { 0 , };
+       enum hal_common_transport platform_transport;
+       enum hal_common_transport backend_transport;
+       enum hal_common_transport available_transport;
 
        if (!transport)
                return -EINVAL;
@@ -550,7 +651,28 @@ int hal_api_cc_get_transport(enum hal_module module, enum hal_common_transport *
        else if (info.compatibility == HAL_COMMON_BACKEND_COMPATIBILITY_INCOMPATIBLE)
                return -ELIBBAD;
 
-       *transport = info.compatible_transport;
+       platform_transport = info.compatible_platform_transport;
+       backend_transport = info.backend_transport;
+
+       /**
+        * Special case: If no backend transport has specified
+        *               than use default of platform manifest
+        */
+       if (backend_transport == HAL_COMMON_TRANSPORT_UNKNOWN) {
+               *transport = info.compatible_platform_default_transport;
+               return 0;
+       }
+
+       available_transport = (platform_transport & backend_transport);
+       if (!available_transport)
+               return -EMEDIUMTYPE;
+
+       if (available_transport & HAL_COMMON_TRANSPORT_PASSTHROUGH)
+               *transport = HAL_COMMON_TRANSPORT_PASSTHROUGH;
+       else if (available_transport & HAL_COMMON_TRANSPORT_IPC)
+               *transport = HAL_COMMON_TRANSPORT_IPC;
+       else
+               return -EINVAL;
 
        return 0;
 }
index daab0f15fc747418ca261aed1a2218e3564f8330..ba6b70c3cade2bc7c5c2cd275a1031420fc44172 100644 (file)
@@ -30,7 +30,8 @@ int hal_api_cc_check_backend_compatibility_by_version(enum hal_module module,
        enum hal_common_backend_compatibility *backend_compatibility);
 int hal_api_cc_get_supported_interface_versions(enum hal_module module,
        unsigned int **major_versions, unsigned int **minor_versions,
-       uint32_t **transports, int *num_versions);
+       uint32_t **transports, enum hal_common_transport **default_transport,
+       int *num_versions);
 int hal_api_cc_get_transport(enum hal_module module, enum hal_common_transport *transport);
 
 #ifdef HAL_API_COMMON_UNITTEST /* For test use only */
@@ -39,6 +40,8 @@ void hal_api_cc_unset_compatibility_result_path(void);
 void hal_api_cc_set_compatibility_loaded_path(const char *path);
 void hal_api_cc_unset_compatibility_loaded_path(void);
 void hal_api_cc_reset_compatibility_info(void);
+void hal_api_cc_set_backend_manifest_path(const char *path);
+void hal_api_cc_unset_backend_manifest_path(void);
 #endif /* HAL_API_COMMON_UNITTEST */
 
 #ifdef __cplusplus
diff --git a/tests/unittest/test-hal-compatibility-checker b/tests/unittest/test-hal-compatibility-checker
deleted file mode 100644 (file)
index e69de29..0000000
diff --git a/tests/unittest/test-hal-compatibility-checker-manifest/backend/hal-backend-manifest.xml b/tests/unittest/test-hal-compatibility-checker-manifest/backend/hal-backend-manifest.xml
new file mode 100644 (file)
index 0000000..881628f
--- /dev/null
@@ -0,0 +1,16 @@
+<hal-backend>
+       <manifest>
+               <hal-module>
+                       <name>HAL_MODULE_AUDIO</name>
+                       <transport><!--empty or unspecified--></transport>
+               </hal-module>
+               <hal-module>
+                       <name>HAL_MODULE_CODEC</name>
+                       <transport>passthrough</transport>
+               </hal-module>
+               <hal-module>
+                       <name>HAL_MODULE_CAMERA</name>
+                       <transport>ipc</transport>
+               </hal-module>
+       </manifest>
+</hal-backend>
diff --git a/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-audio-manifest.xml b/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-audio-manifest.xml
new file mode 100644 (file)
index 0000000..32d0a4a
--- /dev/null
@@ -0,0 +1,13 @@
+<hal-api>
+       <manifest platform-version="10.0">
+               <hal-module>
+                       <name>HAL_MODULE_AUDIO</name>
+                       <version>1.0</version>
+                       <version transport="passthrough,ipc">2.0</version>
+                       <version transport="ipc,passthrough">3.0</version>
+                       <version transport="passthrough">4.0</version>
+                       <version transport="ipc">5.0</version>
+               </hal-module>
+       </manifest>
+</hal-api>
+
diff --git a/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-camera-manifest.xml b/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-camera-manifest.xml
new file mode 100644 (file)
index 0000000..fe72e34
--- /dev/null
@@ -0,0 +1,13 @@
+<hal-api>
+       <manifest platform-version="10.0">
+               <hal-module>
+                       <name>HAL_MODULE_CAMERA</name>
+                       <version>1.0</version>
+                       <version transport="passthrough,ipc">2.0</version>
+                       <version transport="ipc,passthrough">3.0</version>
+                       <version transport="passthrough">4.0</version>
+                       <version transport="ipc">5.0</version>
+               </hal-module>
+       </manifest>
+</hal-api>
+
diff --git a/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-codec-manifest.xml b/tests/unittest/test-hal-compatibility-checker-manifest/hal-api-codec-manifest.xml
new file mode 100644 (file)
index 0000000..539fab3
--- /dev/null
@@ -0,0 +1,13 @@
+<hal-api>
+       <manifest platform-version="10.0">
+               <hal-module>
+                       <name>HAL_MODULE_CODEC</name>
+                       <version>1.0</version>
+                       <version transport="passthrough,ipc">2.0</version>
+                       <version transport="ipc,passthrough">3.0</version>
+                       <version transport="passthrough">4.0</version>
+                       <version transport="ipc">5.0</version>
+               </hal-module>
+       </manifest>
+</hal-api>
+
index 89712ef87eada8c15e4078ffaf4178b2e9e8a424..0a6cdd81d3a368173e81d4840eba3e43607272be 100644 (file)
 
 #include <unistd.h>
 #include <stdint.h>
+#include <fcntl.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
@@ -44,6 +47,11 @@ class HalccObjectTest : public ::testing::Test
                        if (ret == -1)
                                FAIL();
 
+                       ret = asprintf(&g_backend_config_path, "%s/%s", g_cwd,
+                               "test-hal-compatibility-checker-manifest/backend/hal-backend-manifest.xml");
+                       if (ret == -1)
+                               FAIL();
+
                        set_module_info_manifest_all(g_manifest_directory);
 
                        ret = asprintf(&g_compatibility_result_path, "%s/.hal-backend-compatibility", g_cwd);
@@ -71,8 +79,10 @@ class HalccObjectTest : public ::testing::Test
                        hal_api_cc_unset_compatibility_loaded_path();
                        free(g_compatibility_loaded_path);
                        free(g_compatibility_result_path);
+                       free(g_backend_config_path);
                        free(g_manifest_directory);
                        free(g_cwd);
+                       g_backend_config_path = NULL;
                        g_manifest_directory = NULL;
                }
 
@@ -88,6 +98,7 @@ class HalccObjectTest : public ::testing::Test
 
                static halcc_manifest *g_manifest;
                static char *g_manifest_directory;
+               static char *g_backend_config_path;
                static char *g_compatibility_result_path;
                static char *g_compatibility_loaded_path;
                static char *g_cwd;
@@ -95,13 +106,29 @@ class HalccObjectTest : public ::testing::Test
 
 halcc_manifest* HalccObjectTest::g_manifest = NULL;
 char* HalccObjectTest::g_manifest_directory = NULL;
+char* HalccObjectTest::g_backend_config_path = NULL;
 char* HalccObjectTest::g_compatibility_result_path = NULL;
 char* HalccObjectTest::g_compatibility_loaded_path = NULL;
 char* HalccObjectTest::g_cwd = NULL;
 
+static void reset_result_file(const char *result_path, const char *loaded_path)
+{
+       int fd;
+       int ret;
+
+       fd = open(result_path, O_RDWR, 0);
+       if (fd > 0) {
+               ret = ftruncate(fd, 0);
+               EXPECT_EQ(ret, 0);
+               close(fd);
+       }
+
+       unlink(loaded_path);
+}
+
 static bool have_exact_version_within_halcc_hal(halcc_hal *hal, const char *version)
 {
-       int version_list[HALCC_NUM_VERSION_LIST_MAX][3] = { 0 , };
+       int version_list[HALCC_NUM_VERSION_LIST_MAX][4] = { 0 , };
        int num_version_list = 0;
        int major, minor;
        int ret;
@@ -131,6 +158,7 @@ struct versions_info {
        unsigned int *major_versions;
        unsigned int *minor_versions;
        uint32_t *transports;
+       enum hal_common_transport *default_transport;
        int num_versions;
 };
 
@@ -340,7 +368,8 @@ TEST_F(HalccObjectTest, hal_get_manifest_version_success_with_result_file)
        ASSERT_EQ(ret, 0);
 
        ret = hal_common_get_supported_interface_versions(HAL_MODULE_DEVICE_DISPLAY,
-               &vi.major_versions, &vi.minor_versions, &vi.transports, &vi.num_versions);
+               &vi.major_versions, &vi.minor_versions, &vi.transports, &vi.default_transport,
+               &vi.num_versions);
        ASSERT_EQ(ret, 0);
 
        ASSERT_THAT(&vi, HasExactVersionArray("1.2"));
@@ -372,7 +401,8 @@ TEST_F(HalccObjectTest, hal_get_manifest_version_transport_with_result_file)
        ASSERT_EQ(ret, 0);
 
        ret = hal_common_get_supported_interface_versions(HAL_MODULE_TBM,
-                       &vi.major_versions, &vi.minor_versions, &vi.transports, &vi.num_versions);
+                       &vi.major_versions, &vi.minor_versions, &vi.transports, &vi.default_transport,
+                       &vi.num_versions);
 
        ASSERT_EQ(ret, 0);
 
@@ -404,47 +434,143 @@ TEST_F(HalccObjectTest, hal_get_transport_with_result_file)
        enum hal_common_transport transport;
 
        hal_api_cc_set_compatibility_result_path(g_compatibility_result_path);
+       hal_api_cc_set_backend_manifest_path(g_backend_config_path);
+
+       /**
+        * ┌────────────────────────────────────────────────╥───────────────────────╥─────────────────────────────┐
+        * │ platform manifest                              ║  backend manifest     ║  hal_common_get_transport() │
+        * │ (/etc/hal/hal-api-[module]-manifest.xml)       ║  (/hal/etc/hal        ║                             │
+        * ├───────────────────┬─────────┬──────────────────╢   -backend-manifest   ║                             │
+        * │ module            │ version │  transport       ║    .xml)              ║                             │
+        * ├───────────────────┼─────────┼──────────────────╫───────────────────────╫─────────────────────────────┤
+        * │ HAL_MODULE_AUDIO  │   1.0   │  unspecified     ║ unspecified           ║ passthrough                 │
+        * │                   │         │  (=passthrough)  ║ => select 'default'   ║                             │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢    transport of       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   2.0   │  passthrough,ipc ║    platform manifest  ║ passthrough                 │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   3.0   │  ipc,passthrough ║                       ║ ipc                         │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   4.0   │  passthrough     ║                       ║ passthrough                 │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   5.0   │  ipc             ║                       ║ ipc                         │
+        * ├───────────────────┼─────────┼──────────────────╫───────────────────────╫─────────────────────────────┤
+        * │ HAL_MODULE_CODEC  │   1.0   │  unspecified     ║ passthrough           ║ passthrough                 │
+        * │                   │         │  (=passthrough)  ║                       ║                             │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   2.0   │  passthrough,ipc ║                       ║ passthrough                 │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   3.0   │  ipc,passthrough ║                       ║ passthrough                 │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   4.0   │  passthrough     ║                       ║ passthrough                 │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   5.0   │  ipc             ║                       ║ error (-EMEDIUMTYPE)        │
+        * ├───────────────────┼─────────┼──────────────────╫───────────────────────╫─────────────────────────────┤
+        * │ HAL_MODULE_CAMERA │   1.0   │  unspecified     ║ ipc                   ║ error (-EMEDIUMTYPE)        │
+        * │                   │         │  (=passthrough)  ║                       ║                             │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   2.0   │  passthrough,ipc ║                       ║ ipc                         │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   3.0   │  ipc,passthrough ║                       ║ ipc                         │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   4.0   │  passthrough     ║                       ║ error (-EMEDIUMTYPE)        │
+        * │                   ├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╢                       ╟╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
+        * │                   │   5.0   │  ipc             ║                       ║ ipc                         │
+        * └───────────────────┴─────────┴──────────────────╨───────────────────────╨─────────────────────────────┘
+        *
+        */
+
+       /* backend version 1.0 */
+       mock_hal_backend_data_set_version(HAL_MODULE_AUDIO, 1, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CODEC, 1, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CAMERA, 1, 0);
+
+       ret = hal_common_get_transport(HAL_MODULE_AUDIO, &transport);
+       ASSERT_EQ(ret, 0);
+       ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_PASSTHROUGH);
+
+       ret = hal_common_get_transport(HAL_MODULE_CODEC, &transport);
+       ASSERT_EQ(ret, 0);
+       ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_PASSTHROUGH);
 
-       mock_hal_backend_data_set_version(HAL_MODULE_TBM, 1, 0);
+       ret = hal_common_get_transport(HAL_MODULE_CAMERA, &transport);
+       ASSERT_EQ(ret, -EMEDIUMTYPE);
 
-       ret = hal_common_get_transport(HAL_MODULE_TBM, &transport);
+       /* backend version 2.0 */
+       reset_result_file(g_compatibility_result_path, g_compatibility_loaded_path);
+       hal_api_cc_reset_compatibility_info();
+       mock_hal_backend_data_set_version(HAL_MODULE_AUDIO, 2, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CODEC, 2, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CAMERA, 2, 0);
+
+       ret = hal_common_get_transport(HAL_MODULE_AUDIO, &transport);
        ASSERT_EQ(ret, 0);
        ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_PASSTHROUGH);
 
-       /* need to reset cache as the backend version will be changed */
-       ret = truncate(g_compatibility_result_path, 0);
+       ret = hal_common_get_transport(HAL_MODULE_CODEC, &transport);
        ASSERT_EQ(ret, 0);
-       hal_api_cc_reset_compatibility_info();
+       ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_PASSTHROUGH);
 
-       mock_hal_backend_data_set_version(HAL_MODULE_TBM, 2, 0);
+       ret = hal_common_get_transport(HAL_MODULE_CAMERA, &transport);
+       ASSERT_EQ(ret, 0);
+       ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_IPC);
 
-       ret = hal_common_get_transport(HAL_MODULE_TBM, &transport);
+       /* backend version 3.0 */
+       reset_result_file(g_compatibility_result_path, g_compatibility_loaded_path);
+       hal_api_cc_reset_compatibility_info();
+       mock_hal_backend_data_set_version(HAL_MODULE_AUDIO, 3, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CODEC, 3, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CAMERA, 3, 0);
+
+       ret = hal_common_get_transport(HAL_MODULE_AUDIO, &transport);
        ASSERT_EQ(ret, 0);
        ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_IPC);
 
-       /* need to remove cache as the backend version will be changed */
-       ret = truncate(g_compatibility_result_path, 0);
+       ret = hal_common_get_transport(HAL_MODULE_CODEC, &transport);
        ASSERT_EQ(ret, 0);
-       hal_api_cc_reset_compatibility_info();
+       ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_PASSTHROUGH);
 
-       mock_hal_backend_data_set_version(HAL_MODULE_TBM, 3, 0);
+       ret = hal_common_get_transport(HAL_MODULE_CAMERA, &transport);
+       ASSERT_EQ(ret, 0);
+       ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_IPC);
+
+       /* backend version 4.0 */
+       reset_result_file(g_compatibility_result_path, g_compatibility_loaded_path);
+       hal_api_cc_reset_compatibility_info();
+       mock_hal_backend_data_set_version(HAL_MODULE_AUDIO, 4, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CODEC, 4, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CAMERA, 4, 0);
 
-       ret = hal_common_get_transport(HAL_MODULE_TBM, &transport);
+       ret = hal_common_get_transport(HAL_MODULE_AUDIO, &transport);
        ASSERT_EQ(ret, 0);
        ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_PASSTHROUGH);
 
-       /* need to remove cache as the backend version will be changed */
-       ret = truncate(g_compatibility_result_path, 0);
+       ret = hal_common_get_transport(HAL_MODULE_CODEC, &transport);
        ASSERT_EQ(ret, 0);
+       ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_PASSTHROUGH);
+
+       ret = hal_common_get_transport(HAL_MODULE_CAMERA, &transport);
+       ASSERT_EQ(ret, -EMEDIUMTYPE);
+
+       /* backend version 5.0 */
+       reset_result_file(g_compatibility_result_path, g_compatibility_loaded_path);
        hal_api_cc_reset_compatibility_info();
+       mock_hal_backend_data_set_version(HAL_MODULE_AUDIO, 5, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CODEC, 5, 0);
+       mock_hal_backend_data_set_version(HAL_MODULE_CAMERA, 5, 0);
 
-       /* incompatible version should return error */
-       mock_hal_backend_data_set_version(HAL_MODULE_TBM, 8, 0);
+       ret = hal_common_get_transport(HAL_MODULE_AUDIO, &transport);
+       ASSERT_EQ(ret, 0);
+       ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_IPC);
 
-       ret = hal_common_get_transport(HAL_MODULE_TBM, &transport);
-       ASSERT_EQ(ret, -ELIBBAD);
+       ret = hal_common_get_transport(HAL_MODULE_CODEC, &transport);
+       ASSERT_EQ(ret, -EMEDIUMTYPE);
 
-       unlink(g_compatibility_result_path);
+       ret = hal_common_get_transport(HAL_MODULE_CAMERA, &transport);
+       ASSERT_EQ(ret, 0);
+       ASSERT_EQ(transport, HAL_COMMON_TRANSPORT_IPC);
+
+       hal_api_cc_unset_backend_manifest_path();
        hal_api_cc_unset_compatibility_result_path();
        hal_api_cc_reset_compatibility_info();
+       reset_result_file(g_compatibility_result_path, g_compatibility_loaded_path);
 }
index 3dfde761e78ec84c611d8883af77050e1149ab63..5b6953daaed487df3515910c7a80c11d762594b4 100644 (file)
@@ -153,12 +153,14 @@ static void lshal_print_hal_backend_info(u_int32_t flags) {
                        unsigned int *major_versions = NULL;
                        unsigned int *minor_versions = NULL;
                        uint32_t *transports = NULL;
+                       enum hal_common_transport *default_transport = NULL;
                        int num_versions = 0;
 
                        strncpy(str, "", BUFF_MAX - 1);
 
                        ret = hal_common_get_supported_interface_versions(module,
-                               &major_versions, &minor_versions, &transports, &num_versions);
+                               &major_versions, &minor_versions, &transports, &default_transport,
+                               &num_versions);
                        if (ret < 0) {
                                printf(" %-25s |", "");
                        } else {
@@ -172,7 +174,8 @@ static void lshal_print_hal_backend_info(u_int32_t flags) {
 
                                        transport = (transports[i] == HAL_COMMON_TRANSPORT_IPC ? "ipc"
                                                 : transports[i] == HAL_COMMON_TRANSPORT_PASSTHROUGH ? "passthrough"
-                                                : transports[i] == (HAL_COMMON_TRANSPORT_IPC | HAL_COMMON_TRANSPORT_PASSTHROUGH) ? "ipc,passthrough"
+                                                : transports[i] == (HAL_COMMON_TRANSPORT_IPC | HAL_COMMON_TRANSPORT_PASSTHROUGH) ?
+                                                       (default_transport[i] == HAL_COMMON_TRANSPORT_IPC ? "ipc,passthrough" : "passthrough,ipc")
                                                 : "Unknown");
 
                                        pos += snprintf(pos, end - pos, "%u.%u(%s), ",
@@ -185,6 +188,8 @@ static void lshal_print_hal_backend_info(u_int32_t flags) {
                                minor_versions = NULL;
                                free(transports);
                                transports = NULL;
+                               free(default_transport);
+                               default_transport = NULL;
 
                                /* Remove trailing ',' and terminate the string */
                                if (pos < end)