fixup! [0.0.5] Add required feature and privilege check 88/280688/2
authorSeungbae Shin <seungbae.shin@samsung.com>
Fri, 2 Sep 2022 07:31:59 +0000 (16:31 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Fri, 2 Sep 2022 07:36:26 +0000 (16:36 +0900)
Change-Id: I5da6817d810a39cd90f6b2d0fe2d92ff4b73b0c4

src/MediaTransporterUtil.cpp

index 550460b..14c9f90 100644 (file)
@@ -61,29 +61,31 @@ void util::throwIfNotPrivileged(const std::string& privilege)
        LOG_INFO("privilege[%s] allowed", privilege.c_str());
 }
 
-void util::throwIfFeatureNotSupported(const std::string& feature)
+static bool __isFeatureSupported(const std::string& feature)
 {
        bool supported = false;
+       if (system_info_get_platform_bool(feature.c_str(), &supported) != SYSTEM_INFO_ERROR_NONE) {
+               LOG_ERROR("failed to system_info_get_platform_bool(%s)", feature.c_str());
+               return false;
+       }
 
-       if (system_info_get_platform_bool(feature.c_str(), &supported) != SYSTEM_INFO_ERROR_NONE)
-               throw MediaTransporterException(MTPR_ERROR_INVALID_OPERATION,
-                                                                               "failed to system_info_get_platform_bool(" + feature + ")");
+       LOG_INFO("feature[%s] supported[%d]", feature.c_str(), supported);
+       return supported;
+}
 
-       if (!supported)
+void util::throwIfFeatureNotSupported(const std::string& feature)
+{
+       if (!__isFeatureSupported(feature))
                throw MediaTransporterException(MTPR_ERROR_NOT_SUPPORTED,
                                                                                "[" + feature + "] not supported");
-
-       LOG_INFO("feature[%s] supported", feature.c_str());
 }
 
 void util::throwIfNetworkFeaturesNotSupported()
 {
-       try {
-               throwIfFeatureNotSupported(MTPR_FEATURE_NETWORK_WIFI);
-               throwIfFeatureNotSupported(MTPR_FEATURE_NETWORK_TELE);
-               throwIfFeatureNotSupported(MTPR_FEATURE_NETWORK_ETH);
-       } catch (const MediaTransporterException& e) {
-               throw MediaTransporterException(MTPR_ERROR_NOT_SUPPORTED, e.what());
-       }
+       if (!(__isFeatureSupported(MTPR_FEATURE_NETWORK_WIFI) ||
+               __isFeatureSupported(MTPR_FEATURE_NETWORK_TELE) ||
+               __isFeatureSupported(MTPR_FEATURE_NETWORK_ETH)))
+               throw MediaTransporterException(MTPR_ERROR_NOT_SUPPORTED,
+                       "One of the network feature (WIFI/TELE/ETH) must be supported");
 }