Update log level and messages for checking features 53/315353/2
authorYonggoo Kang <ygace.kang@samsung.com>
Tue, 30 Jul 2024 12:45:28 +0000 (21:45 +0900)
committerYonggoo Kang <ygace.kang@samsung.com>
Wed, 31 Jul 2024 00:17:54 +0000 (09:17 +0900)
Change-Id: I0d1e780adf8df4184053e7ddb16358461ca572b4

srcs/client/client.cpp

index 5316d274813c1a87752b2c75579547b053be2d7b..980f7cd2cd5b9be716e60cb36935ec451242b6e1 100644 (file)
@@ -42,17 +42,42 @@ int has_feature(const char *feature) {
 
     if (SYSTEM_INFO_ERROR_NONE
             != system_info_get_platform_bool(feature, &is_supported)) {
-        LogError("Failed to check feature " << feature);
+        LogWarning("Failed to check feature " << feature);
         return WAUTHN_ERROR_UNKNOWN;
     }
 
     if (!is_supported) {
-        LogError("Unsupported feature " << feature);
+        LogWarning("Unsupported feature " << feature);
         return WAUTHN_ERROR_NOT_SUPPORTED;
     }
     return WAUTHN_ERROR_NONE;
 #endif
 }
+
+int check_network_features() {
+    if ((has_feature(TELEPHONY) != WAUTHN_ERROR_NONE) &&
+        has_feature(WIFI) != WAUTHN_ERROR_NONE &&
+        has_feature(ETHERNET) != WAUTHN_ERROR_NONE)
+        return WAUTHN_ERROR_NOT_SUPPORTED;
+    return WAUTHN_ERROR_NONE;
+}
+
+int check_features() {
+#ifdef NO_FEATURE_CHECK
+    LogWarning("Skip to check features");
+    return WAUTHN_ERROR_NONE;
+#else
+    int ret = WAUTHN_ERROR_NONE;
+    if (((ret = has_feature(WEBAUTHN)) != WAUTHN_ERROR_NONE) ||
+        ((ret = has_feature(BLUETOOTH)) != WAUTHN_ERROR_NONE) ||
+        ((ret = check_network_features()) != WAUTHN_ERROR_NONE))
+        {
+            LogError("Features are not supported");
+            return ret;
+        }
+    return WAUTHN_ERROR_NONE;
+#endif
+}
 } // namespace
 
 #define WEBAUTHN_API __attribute__((visibility("default")))
@@ -61,7 +86,10 @@ WEBAUTHN_API
 int wauthn_set_api_version(int api_version_number) {
     int ret = has_feature(WEBAUTHN);
     if (ret != WAUTHN_ERROR_NONE)
+    {
+        LogError(get_error_message(ret));
         return ret;
+    }
 
     if (api_version_number != WAUTHN_API_VERSION_NUMBER)
         return WAUTHN_ERROR_NOT_SUPPORTED;
@@ -73,7 +101,10 @@ WEBAUTHN_API
 int wauthn_supported_authenticators(unsigned int *supported) {
     int ret = has_feature(WEBAUTHN);
     if (ret != WAUTHN_ERROR_NONE)
+    {
+        LogError(get_error_message(ret));
         return ret;
+    }
 
     if (supported == nullptr)
         return WAUTHN_ERROR_INVALID_PARAMETER;
@@ -86,12 +117,8 @@ WEBAUTHN_API
 int wauthn_make_credential(const wauthn_client_data_s *client_data,
         const wauthn_pubkey_cred_creation_options_s *options,
         wauthn_mc_callbacks_s *callbacks) {
-    int ret = WAUTHN_ERROR_NONE;
-    if (((ret = has_feature(WEBAUTHN)) != WAUTHN_ERROR_NONE) ||
-        ((ret = has_feature(BLUETOOTH)) != WAUTHN_ERROR_NONE) || (
-            ((ret = has_feature(TELEPHONY)) != WAUTHN_ERROR_NONE) &&
-            ((ret = has_feature(WIFI)) != WAUTHN_ERROR_NONE) &&
-            ((ret = has_feature(ETHERNET)) != WAUTHN_ERROR_NONE)))
+    int ret = check_features();
+    if (ret != WAUTHN_ERROR_NONE)
         return ret;
 
     return try_catch([&]() -> int {
@@ -105,12 +132,8 @@ WEBAUTHN_API
 int wauthn_get_assertion(const wauthn_client_data_s *client_data,
         const wauthn_pubkey_cred_request_options_s *options,
         wauthn_ga_callbacks_s *callbacks) {
-    int ret = WAUTHN_ERROR_NONE;
-    if (((ret = has_feature(WEBAUTHN)) != WAUTHN_ERROR_NONE) ||
-        ((ret = has_feature(BLUETOOTH)) != WAUTHN_ERROR_NONE) || (
-            ((ret = has_feature(TELEPHONY)) != WAUTHN_ERROR_NONE) &&
-            ((ret = has_feature(WIFI)) != WAUTHN_ERROR_NONE) &&
-            ((ret = has_feature(ETHERNET)) != WAUTHN_ERROR_NONE)))
+    int ret = check_features();
+    if (ret != WAUTHN_ERROR_NONE)
         return ret;
 
     return try_catch([&]() -> int {
@@ -124,7 +147,10 @@ WEBAUTHN_API
 int wauthn_cancel() {
     int ret = has_feature(WEBAUTHN);
     if (ret != WAUTHN_ERROR_NONE)
+    {
+        LogError(get_error_message(ret));
         return ret;
+    }
 
     return try_catch([&]() -> int {
         ClientRequest request(WebAuthnCall::CANCEL);