From 019bb2153a0a1edefe78b09aea55910b30b97b44 Mon Sep 17 00:00:00 2001 From: Piotr Kosko Date: Tue, 10 Nov 2020 14:26:25 +0100 Subject: [PATCH] [Systeminfo] Refactor for getCapability The goal of this change is to avoid some strange error logs when 'trying' to gather each type in the pipeline one after another. Now the type is checked first, then the value is gathered. [Verification] Code compiles without errors. TCT passrate 100%. Below calls behaviour didn't change (all capabilities listed in Web API documentation): var caps = [ 'http://tizen.org/feature/content.scanning.others', 'http://tizen.org/feature/datasync', 'http://tizen.org/feature/download', 'http://tizen.org/feature/network.telephony', 'http://tizen.org/feature/network.wifi', 'http://tizen.org/feature/systemsetting', 'http://tizen.org/feature/systemsetting.home_screen', 'http://tizen.org/feature/systemsetting.lock_screen', 'http://tizen.org/feature/systemsetting.incoming_call', 'http://tizen.org/feature/systemsetting.notification_email', 'http://tizen.org/feature/network.bluetooth.audio.media', 'http://tizen.org/feature/network.telephony', 'http://tizen.org/feature/network.telephony.mms', 'http://tizen.org/feature/battery', 'http://tizen.org/feature/camera', 'http://tizen.org/feature/camera.back', 'http://tizen.org/feature/camera.back.flash', 'http://tizen.org/feature/camera.front', 'http://tizen.org/feature/camera.front.flash', 'http://tizen.org/feature/database.encryption', 'http://tizen.org/feature/fmradio', 'http://tizen.org/feature/humanactivitymonitor', 'http://tizen.org/feature/graphics.acceleration', 'http://tizen.org/feature/led', 'http://tizen.org/feature/input.keyboard', 'http://tizen.org/feature/input.keyboard.layout', 'http://tizen.org/feature/input.rotating_bezel', 'http://tizen.org/feature/security.tee', 'http://tizen.org/feature/location', 'http://tizen.org/feature/location.batch', 'http://tizen.org/feature/location.gps', 'http://tizen.org/feature/location.wps', 'http://tizen.org/feature/multimedia.transcoder', 'http://tizen.org/feature/microphone', 'http://tizen.org/feature/multi_point_touch.pinch_zoom', 'http://tizen.org/feature/multi_point_touch.point_count', 'http://tizen.org/feature/network.bluetooth', 'http://tizen.org/feature/network.bluetooth.audio.call', 'http://tizen.org/feature/network.bluetooth.audio.media', 'http://tizen.org/feature/network.bluetooth.health', 'http://tizen.org/feature/network.bluetooth.hid', 'http://tizen.org/feature/network.bluetooth.le', 'http://tizen.org/feature/network.bluetooth.opp', 'http://tizen.org/feature/network.ethernet', 'http://tizen.org/feature/network.internet', 'http://tizen.org/feature/network.nfc', 'http://tizen.org/feature/network.nfc.card_emulation', 'http://tizen.org/feature/network.nfc.card_emulation.hce', 'http://tizen.org/feature/network.nfc.p2p', 'http://tizen.org/feature/network.nfc.reserved_push', 'http://tizen.org/feature/network.nfc.tag', 'http://tizen.org/feature/network.push', 'http://tizen.org/feature/network.secure_element', 'http://tizen.org/feature/network.telephony', 'http://tizen.org/feature/network.telephony.mms', 'http://tizen.org/feature/network.wifi', 'http://tizen.org/feature/network.wifi.direct', 'http://tizen.org/feature/opengles', 'http://tizen.org/feature/opengles.texture_format', 'http://tizen.org/feature/opengles.texture_format.3dc', 'http://tizen.org/feature/opengles.texture_format.atc', 'http://tizen.org/feature/opengles.texture_format.etc', 'http://tizen.org/feature/opengles.texture_format.ptc', 'http://tizen.org/feature/opengles.texture_format.pvrtc', 'http://tizen.org/feature/opengles.texture_format.utc', 'http://tizen.org/feature/opengles.version.1_1', 'http://tizen.org/feature/opengles.version.2_0', 'http://tizen.org/feature/platform.core.api.version', 'http://tizen.org/feature/platform.core.cpu.arch', 'http://tizen.org/feature/platform.core.cpu.arch.armv6', 'http://tizen.org/feature/platform.core.cpu.arch.armv7', 'http://tizen.org/feature/platform.core.cpu.arch.x86', 'http://tizen.org/feature/platform.core.cpu.frequency', 'http://tizen.org/feature/platform.core.fpu.arch', 'http://tizen.org/feature/platform.core.fpu.arch.sse2', 'http://tizen.org/feature/platform.core.fpu.arch.sse3', 'http://tizen.org/feature/platform.core.fpu.arch.ssse3', 'http://tizen.org/feature/platform.core.fpu.arch.vfpv2', 'http://tizen.org/feature/platform.core.fpu.arch.vfpv3', 'http://tizen.org/feature/platform.native.api.version', 'http://tizen.org/feature/platform.native.osp_compatible', 'http://tizen.org/feature/platform.version', 'http://tizen.org/feature/platform.web.api.version', 'http://tizen.org/feature/platform.version.name', 'http://tizen.org/feature/profile', 'http://tizen.org/feature/screen', 'http://tizen.org/feature/screen.auto_rotation', 'http://tizen.org/feature/screen.bpp', 'http://tizen.org/feature/screen.coordinate_system.size.large', 'http://tizen.org/feature/screen.coordinate_system.size.normal', 'http://tizen.org/feature/screen.dpi', 'http://tizen.org/feature/screen.height', 'http://tizen.org/feature/screen.output.hdmi', 'http://tizen.org/feature/screen.output.rca', 'http://tizen.org/feature/screen.shape.circle', 'http://tizen.org/feature/screen.shape.rectangle', 'http://tizen.org/feature/screen.size.all', 'http://tizen.org/feature/screen.size.large', 'http://tizen.org/feature/screen.size.normal', 'http://tizen.org/feature/screen.size.normal.240.400', 'http://tizen.org/feature/screen.size.normal.320.320', 'http://tizen.org/feature/screen.size.normal.320.480', 'http://tizen.org/feature/screen.size.normal.360.360', 'http://tizen.org/feature/screen.size.normal.360.480', 'http://tizen.org/feature/screen.size.normal.480.800', 'http://tizen.org/feature/screen.size.normal.540.960', 'http://tizen.org/feature/screen.size.normal.600.1024', 'http://tizen.org/feature/screen.size.normal.720.1280', 'http://tizen.org/feature/screen.size.normal.1080.1920', 'http://tizen.org/feature/screen.width', 'http://tizen.org/feature/sensor.accelerometer', 'http://tizen.org/feature/sensor.accelerometer.wakeup', 'http://tizen.org/feature/sensor.activity_recognition', 'http://tizen.org/feature/sensor.barometer', 'http://tizen.org/feature/sensor.barometer.wakeup', 'http://tizen.org/feature/sensor.gesture_recognition', 'http://tizen.org/feature/sensor.gravity', 'http://tizen.org/feature/sensor.gyroscope', 'http://tizen.org/feature/sensor.gyroscope_rotation_vector', 'http://tizen.org/feature/sensor.gyroscope.wakeup', 'http://tizen.org/feature/sensor.heart_rate_monitor', 'http://tizen.org/feature/sensor.heart_rate_monitor.led_green', 'http://tizen.org/feature/sensor.heart_rate_monitor.led_ir', 'http://tizen.org/feature/sensor.heart_rate_monitor.led_red', 'http://tizen.org/feature/sensor.humidity', 'http://tizen.org/feature/sensor.linear_acceleration', 'http://tizen.org/feature/sensor.magnetometer', 'http://tizen.org/feature/sensor.magnetometer.wakeup', 'http://tizen.org/feature/sensor.pedometer', 'http://tizen.org/feature/sensor.photometer', 'http://tizen.org/feature/sensor.photometer.wakeup', 'http://tizen.org/feature/sensor.proximity', 'http://tizen.org/feature/sensor.proximity.wakeup', 'http://tizen.org/feature/sensor.rotation_vector', 'http://tizen.org/feature/sensor.sleep_monitor', 'http://tizen.org/feature/sensor.temperature', 'http://tizen.org/feature/sensor.tiltmeter', 'http://tizen.org/feature/sensor.tiltmeter.wakeup', 'http://tizen.org/feature/sensor.ultraviolet', 'http://tizen.org/feature/sensor.wrist_up', 'http://tizen.org/feature/shell.appwidget', 'http://tizen.org/feature/sip.voip', 'http://tizen.org/feature/speech.recognition', 'http://tizen.org/feature/speech.synthesis', 'http://tizen.org/feature/usb.accessory', 'http://tizen.org/feature/usb.host', 'http://tizen.org/feature/web.service', 'http://tizen.org/feature/vision.face_recognition', 'http://tizen.org/feature/vision.image_recognition', 'http://tizen.org/feature/vision.qrcode_generation', 'http://tizen.org/feature/vision.qrcode_recognition' ]; for (var i in caps) { try { console.log( 'Value of ' + caps[i] + ': ' + tizen.systeminfo.getCapability(caps[i]) ); } catch (e) { console.log('Exception for ' + caps[i] + ': ' + e); } } Change-Id: Ia154396e3ec19dcb8b30f1c3b4f90a37bdd05738 --- .../systeminfo_device_capability.cc | 317 +++++++++--------- src/systeminfo/systeminfo_device_capability.h | 24 +- 2 files changed, 180 insertions(+), 161 deletions(-) diff --git a/src/systeminfo/systeminfo_device_capability.cc b/src/systeminfo/systeminfo_device_capability.cc index 7c272fae..64ce555e 100644 --- a/src/systeminfo/systeminfo_device_capability.cc +++ b/src/systeminfo/systeminfo_device_capability.cc @@ -86,7 +86,72 @@ const char* kTizenFeaturePlatformNativeOspCompatible = const char* kTizenFeaturePlatformVersionName = "http://tizen.org/feature/platform.version.name"; } // namespace -PlatformResult SystemInfoDeviceCapability::GetValueBool(const char* key, bool* value) { +CapabilitiesMap SystemInfoDeviceCapability::bool_capabilities = + SystemInfoDeviceCapability::InitializeBoolCapabilities(); +CapabilitiesMap SystemInfoDeviceCapability::int_capabilities = + SystemInfoDeviceCapability::InitializeIntCapabilities(); +CapabilitiesMap SystemInfoDeviceCapability::string_capabilities = + SystemInfoDeviceCapability::InitializeStringCapabilities(); + +CapabilitiesMap SystemInfoDeviceCapability::InitializeBoolCapabilities() { + ScopeLogger(); + CapabilitiesMap result; + + result[kTizenFeatureBluetoothAlwaysOn] = SystemInfoDeviceCapability::IsBluetoothAlwaysOn; + result[kTizenFeatureScreen] = SystemInfoDeviceCapability::IsScreen; + result[kTizenFeaturePlatformNativeOspCompatible] = + SystemInfoDeviceCapability::IsNativeOspCompatible; + + return result; +}; + +CapabilitiesMap SystemInfoDeviceCapability::InitializeIntCapabilities() { + ScopeLogger(); + CapabilitiesMap result; + result[kTizenFeatureCpuFrequency] = SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency; + + return result; +}; + +CapabilitiesMap SystemInfoDeviceCapability::InitializeStringCapabilities() { + ScopeLogger(); + CapabilitiesMap result; + result[kTizenFeatureOpenglesTextureFormat] = SystemInfoDeviceCapability::GetOpenglesTextureFormat; + result[kTizenFeatureCoreApiVersion] = SystemInfoDeviceCapability::GetNativeAPIVersion; + result[kTizenFeaturePlatfromCoreCpuArch] = SystemInfoDeviceCapability::GetPlatfomCoreCpuArch; + result[kTizenFeaturePlatfromCoreFpuArch] = SystemInfoDeviceCapability::GetPlatfomCoreFpuArch; + result[kTizenFeatureProfile] = SystemInfoDeviceCapability::GetProfile; + result[kTizenFeaturePlatformNativeApiVersion] = SystemInfoDeviceCapability::GetNativeAPIVersion; + result[kTizenFeaturePlatformVersionName] = SystemInfoDeviceCapability::GetPlatformVersionName; + + return result; +}; + +common::PlatformResult SystemInfoDeviceCapability::CheckCapabilityType( + const std::string& key, system_info_type_e* capability_type) { + ScopeLogger(); + // checking 'hardcoded' map first + if (bool_capabilities.find(key) != bool_capabilities.end()) { + *capability_type = SYSTEM_INFO_BOOL; + } else if (int_capabilities.find(key) != int_capabilities.end()) { + *capability_type = SYSTEM_INFO_INT; + } else if (string_capabilities.find(key) != string_capabilities.end()) { + *capability_type = SYSTEM_INFO_STRING; + } else { + // checking platform capabilities database + int res = system_info_get_platform_type(key.c_str(), capability_type); + if (SYSTEM_INFO_ERROR_NONE != res) { + res = system_info_get_custom_type(key.c_str(), capability_type); + if (SYSTEM_INFO_ERROR_NONE != res) { + return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, + "Value for given key was not found"); + } + } + } + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult GetValueBoolNative(const char* key, bool* value) { ScopeLogger(); bool platform_result = false; int ret = system_info_get_platform_bool(key, &platform_result); @@ -106,7 +171,19 @@ PlatformResult SystemInfoDeviceCapability::GetValueBool(const char* key, bool* v return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult SystemInfoDeviceCapability::GetValueInt(const char* key, int* value) { +PlatformResult SystemInfoDeviceCapability::GetValueBool(const char* key, bool* value) { + ScopeLogger(); + // check 'hardcoded' keys + auto it = bool_capabilities.find(key); + if (bool_capabilities.end() != it) { + return it->second(value); + } + + // check 'database' keys + return GetValueBoolNative(key, value); +} + +PlatformResult GetValueIntNative(const char* key, int* value) { ScopeLogger(); int platform_result = 0; int ret = system_info_get_platform_int(key, &platform_result); @@ -126,7 +203,19 @@ PlatformResult SystemInfoDeviceCapability::GetValueInt(const char* key, int* val return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult SystemInfoDeviceCapability::GetValueString(const char* key, std::string* str_value) { +PlatformResult SystemInfoDeviceCapability::GetValueInt(const char* key, int* value) { + ScopeLogger(); + // check 'hardcoded' keys + auto it = int_capabilities.find(key); + if (int_capabilities.end() != it) { + return it->second(value); + } + + // check 'database' keys + return GetValueIntNative(key, value); +} + +PlatformResult GetValueStringNative(const char* key, std::string* str_value) { ScopeLogger(); char* value = nullptr; @@ -152,114 +241,16 @@ PlatformResult SystemInfoDeviceCapability::GetValueString(const char* key, std:: return PlatformResult(ErrorCode::NO_ERROR); } -static PlatformResult CheckStringCapability(const std::string& key, std::string* value, - bool* fetched) { - ScopeLogger(); - *fetched = false; - if (kTizenFeatureOpenglesTextureFormat == key) { - PlatformResult ret = SystemInfoDeviceCapability::GetOpenglesTextureFormat(value); - if (ret.IsError()) { - return ret; - } - } else if (kTizenFeatureCoreApiVersion == key) { - PlatformResult ret = SystemInfoDeviceCapability::GetNativeAPIVersion(value); - if (ret.IsError()) { - return ret; - } - } else if (key == kTizenFeaturePlatfromCoreCpuArch) { - PlatformResult ret = SystemInfoDeviceCapability::GetPlatfomCoreCpuArch(value); - if (ret.IsError()) { - return ret; - } - } else if (kTizenFeaturePlatfromCoreFpuArch == key) { - PlatformResult ret = SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(value); - if (ret.IsError()) { - return ret; - } - } else if (kTizenFeatureProfile == key) { - PlatformResult ret = SystemInfoDeviceCapability::GetProfile(value); - if (ret.IsError()) { - return ret; - } - } else if (kTizenFeaturePlatformNativeApiVersion == key) { - PlatformResult ret = SystemInfoDeviceCapability::GetNativeAPIVersion(value); - if (ret.IsError()) { - return ret; - } - } else if (kTizenFeaturePlatformVersionName == key) { - PlatformResult ret = SystemInfoDeviceCapability::GetPlatformVersionName(value); - if (ret.IsError()) { - return ret; - } - } else { - size_t prefix_len = strlen("http://"); - if (key.length() <= prefix_len) { - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found"); - } - PlatformResult ret = - SystemInfoDeviceCapability::GetValueString(key.substr(prefix_len).c_str(), value); - if (ret.IsError()) { - return PlatformResult(ErrorCode::NO_ERROR); - } - } - *fetched = true; - return PlatformResult(ErrorCode::NO_ERROR); -} - -static PlatformResult CheckBoolCapability(const std::string& key, bool* bool_value, bool* fetched) { +PlatformResult SystemInfoDeviceCapability::GetValueString(const char* key, std::string* str_value) { ScopeLogger(); - *fetched = false; - if (kTizenFeatureBluetoothAlwaysOn == key) { - *bool_value = SystemInfoDeviceCapability::IsBluetoothAlwaysOn(); - *fetched = true; - } else if (kTizenFeatureScreen == key) { - *bool_value = SystemInfoDeviceCapability::IsScreen(); - *fetched = true; - } else if (kTizenFeaturePlatformNativeOspCompatible == key) { - PlatformResult ret = SystemInfoDeviceCapability::IsNativeOspCompatible(bool_value); - if (ret.IsError()) { - return ret; - } - *fetched = true; - } else { - size_t prefix_len = strlen("http://"); - if (key.length() <= prefix_len) { - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found"); - } - PlatformResult ret = - SystemInfoDeviceCapability::GetValueBool(key.substr(prefix_len).c_str(), bool_value); - if (ret.IsSuccess()) { - *fetched = true; - } + // check 'hardcoded' keys + auto it = string_capabilities.find(key); + if (string_capabilities.end() != it) { + return it->second(str_value); } - return PlatformResult(ErrorCode::NO_ERROR); -} -static PlatformResult CheckIntCapability(const std::string& key, std::string* value, - bool* fetched) { - ScopeLogger(); - int result = 0; - if (key == kTizenFeatureCpuFrequency) { - PlatformResult ret = SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency(&result); - if (ret.IsError()) { - *fetched = false; - return ret; - } - } else { - size_t prefix_len = strlen("http://"); - if (key.length() <= prefix_len) { - return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found"); - } - PlatformResult ret = - SystemInfoDeviceCapability::GetValueInt(key.substr(prefix_len).c_str(), &result); - if (ret.IsError()) { - *fetched = false; - return PlatformResult(ErrorCode::NO_ERROR); - } - } - *value = std::to_string(result); - *fetched = true; - return PlatformResult(ErrorCode::NO_ERROR); + // check 'database' keys + return GetValueStringNative(key, str_value); } PlatformResult SystemInfoDeviceCapability::GetCapability(const std::string& key, @@ -267,39 +258,45 @@ PlatformResult SystemInfoDeviceCapability::GetCapability(const std::string& key, ScopeLogger(); picojson::object& result_obj = result->get(); - std::string value = ""; std::string type = ""; bool bool_value = false; - bool is_fetched = false; + int int_value = 0; + std::string string_value = ""; + + system_info_type_e capability_type = SYSTEM_INFO_BOOL; - PlatformResult ret = CheckBoolCapability(key, &bool_value, &is_fetched); + PlatformResult ret = CheckCapabilityType(key, &capability_type); if (ret.IsError()) { return ret; } - if (is_fetched) { + LoggerD("Capability %s is %d type", key.c_str(), capability_type); + + if (SYSTEM_INFO_BOOL == capability_type) { type = "bool"; - } else { - ret = CheckIntCapability(key, &value, &is_fetched); + PlatformResult ret = GetValueBool(key.c_str(), &bool_value); if (ret.IsError()) { return ret; } - if (is_fetched) { - type = "int"; - } else { - ret = CheckStringCapability(key, &value, &is_fetched); - if (ret.IsError()) { - return ret; - } - if (is_fetched) { - type = "string"; - } + } else if (SYSTEM_INFO_INT == capability_type) { + type = "int"; + PlatformResult ret = GetValueInt(key.c_str(), &int_value); + if (ret.IsError()) { + return ret; + } + } else if (SYSTEM_INFO_STRING == capability_type) { + type = "string"; + PlatformResult ret = GetValueString(key.c_str(), &string_value); + if (ret.IsError()) { + return ret; } } if (type == "bool") { result_obj.insert(std::make_pair("value", picojson::value(bool_value))); - } else if (type == "string" || type == "int") { - result_obj.insert(std::make_pair("value", picojson::value(value))); + } else if (type == "int") { + result_obj.insert(std::make_pair("value", picojson::value(std::to_string(int_value)))); + } else if (type == "string") { + result_obj.insert(std::make_pair("value", picojson::value(string_value))); } else { return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR, "Value for given key was not found"); } @@ -312,12 +309,12 @@ PlatformResult SystemInfoDeviceCapability::IsInputKeyboardLayout(bool* result) { ScopeLogger(); std::string input_keyboard_layout = ""; PlatformResult ret = - GetValueString("tizen.org/feature/input.keyboard.layout", &input_keyboard_layout); + GetValueStringNative("tizen.org/feature/input.keyboard.layout", &input_keyboard_layout); if (ret.IsError()) { return ret; } bool input_keyboard = false; - ret = GetValueBool("tizen.org/feature/input.keyboard", &input_keyboard); + ret = GetValueBoolNative("tizen.org/feature/input.keyboard", &input_keyboard); if (ret.IsError()) { return ret; } @@ -336,7 +333,7 @@ PlatformResult SystemInfoDeviceCapability::IsInputKeyboardLayout(bool* result) { PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* result) { ScopeLogger(); bool bool_result = false; - PlatformResult ret = GetValueBool("tizen.org/feature/opengles", &bool_result); + PlatformResult ret = GetValueBoolNative("tizen.org/feature/opengles", &bool_result); if (!bool_result) { // this exception is converted to "Undefined" value in JS layer std::string log_msg = "OpenGL-ES is not supported"; @@ -344,7 +341,7 @@ PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* } std::string texture_format = ""; - ret = GetValueBool("tizen.org/feature/opengles.texture_format.utc", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.utc", &bool_result); if (ret.IsError()) { return ret; } @@ -352,7 +349,7 @@ PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* texture_format += kOpenglesTextureUtc; } - ret = GetValueBool("tizen.org/feature/opengles.texture_format.ptc", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.ptc", &bool_result); if (ret.IsError()) { return ret; } @@ -363,7 +360,7 @@ PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* texture_format += kOpenglesTexturePtc; } - ret = GetValueBool("tizen.org/feature/opengles.texture_format.etc", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.etc", &bool_result); if (ret.IsError()) { return ret; } @@ -374,7 +371,7 @@ PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* texture_format += kOpenglesTextureEtc; } - ret = GetValueBool("tizen.org/feature/opengles.texture_format.3dc", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.3dc", &bool_result); if (ret.IsError()) { return ret; } @@ -385,7 +382,7 @@ PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* texture_format += kOpenglesTexture3dc; } - ret = GetValueBool("tizen.org/feature/opengles.texture_format.atc", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.atc", &bool_result); if (ret.IsError()) { return ret; } @@ -396,7 +393,7 @@ PlatformResult SystemInfoDeviceCapability::GetOpenglesTextureFormat(std::string* texture_format += kOpenglesTextureAtc; } - ret = GetValueBool("tizen.org/feature/opengles.texture_format.pvrtc", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/opengles.texture_format.pvrtc", &bool_result); if (ret.IsError()) { return ret; } @@ -422,13 +419,12 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreCpuArch(std::string* re bool bool_result = false; std::string arch = ""; - PlatformResult ret = - SystemInfoDeviceCapability::GetValueString("tizen.org/feature/platform.core.cpu.arch", &arch); + PlatformResult ret = GetValueStringNative("tizen.org/feature/platform.core.cpu.arch", &arch); if (ret.IsError()) { - LoggerE("GetValueString Error"); + LoggerE("GetValueStringNative Error"); } - ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv6", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/platform.core.cpu.arch.armv6", &bool_result); if (ret.IsError()) { return ret; } @@ -436,7 +432,7 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreCpuArch(std::string* re result = kPlatformCoreArmv6; } - ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.armv7", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/platform.core.cpu.arch.armv7", &bool_result); if (ret.IsError()) { return ret; } @@ -452,7 +448,7 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreCpuArch(std::string* re } } - ret = GetValueBool("tizen.org/feature/platform.core.cpu.arch.x86", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/platform.core.cpu.arch.x86", &bool_result); if (ret.IsError()) { return ret; } @@ -478,7 +474,8 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* re ScopeLogger(); std::string result; bool bool_result = false; - PlatformResult ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse2", &bool_result); + PlatformResult ret = + GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.sse2", &bool_result); if (ret.IsError()) { return ret; } @@ -486,7 +483,7 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* re result = kPlatformCoreSse2; } - ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.sse3", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.sse3", &bool_result); if (ret.IsError()) { return ret; } @@ -497,7 +494,7 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* re result += kPlatformCoreSse3; } - ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.ssse3", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.ssse3", &bool_result); if (ret.IsError()) { return ret; } @@ -508,7 +505,7 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* re result += kPlatformCoreSsse3; } - ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv2", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.vfpv2", &bool_result); if (ret.IsError()) { return ret; } @@ -519,7 +516,7 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* re result += kPlatformCoreVfpv2; } - ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv3", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.vfpv3", &bool_result); if (ret.IsError()) { return ret; } @@ -530,7 +527,7 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* re result += kPlatformCoreVfpv3; } - ret = GetValueBool("tizen.org/feature/platform.core.fpu.arch.vfpv4", &bool_result); + ret = GetValueBoolNative("tizen.org/feature/platform.core.fpu.arch.vfpv4", &bool_result); if (ret.IsError()) { return ret; } @@ -550,7 +547,7 @@ PlatformResult SystemInfoDeviceCapability::GetPlatfomCoreFpuArch(std::string* re PlatformResult SystemInfoDeviceCapability::GetProfile(std::string* return_value) { ScopeLogger(); std::string profile = ""; - PlatformResult ret = GetValueString("tizen.org/feature/profile", &profile); + PlatformResult ret = GetValueStringNative("tizen.org/feature/profile", &profile); if (ret.IsError()) { return ret; } @@ -571,23 +568,25 @@ PlatformResult SystemInfoDeviceCapability::GetProfile(std::string* return_value) return PlatformResult(ErrorCode::NO_ERROR); } -bool SystemInfoDeviceCapability::IsBluetoothAlwaysOn() { +PlatformResult SystemInfoDeviceCapability::IsBluetoothAlwaysOn(bool* return_value) { ScopeLogger(); #ifdef PROFILE_MOBILE_FULL - return false; + *return_value = false; #elif PROFILE_MOBILE - return false; + *return_value = false; #elif PROFILE_WEARABLE - return false; + *return_value = false; #elif PROFILE_TV - return true; + *return_value = true; #else - return false; + *return_value = false; #endif + return PlatformResult(ErrorCode::NO_ERROR); } -bool SystemInfoDeviceCapability::IsScreen() { - return true; +PlatformResult SystemInfoDeviceCapability::IsScreen(bool* return_value) { + *return_value = true; + return PlatformResult(ErrorCode::NO_ERROR); } #define MODEL_NAME "http://tizen.org/system/model_name" @@ -658,12 +657,12 @@ PlatformResult SystemInfoDeviceCapability::GetPlatformCoreCpuFrequency(int* retu PlatformResult SystemInfoDeviceCapability::IsNativeOspCompatible(bool* result) { ScopeLogger(); - return GetValueBool(kTizenFeaturePlatformNativeOspCompatible, result); + return GetValueBoolNative(kTizenFeaturePlatformNativeOspCompatible, result); } PlatformResult SystemInfoDeviceCapability::GetNativeAPIVersion(std::string* return_value) { ScopeLogger(); - return GetValueString(kTizenFeaturePlatformNativeApiVersion, return_value); + return GetValueStringNative(kTizenFeaturePlatformNativeApiVersion, return_value); } PlatformResult SystemInfoDeviceCapability::GetPlatformVersionName(std::string* result) { @@ -671,7 +670,7 @@ PlatformResult SystemInfoDeviceCapability::GetPlatformVersionName(std::string* r // Because of lack of 'http://tizen.org/feature/platform.version.name' // key on platform we use 'http://tizen.org/system/platform.name'. - return GetValueString("tizen.org/system/platform.name", result); + return GetValueStringNative("tizen.org/system/platform.name", result); } } // namespace systeminfo diff --git a/src/systeminfo/systeminfo_device_capability.h b/src/systeminfo/systeminfo_device_capability.h index b4b8164a..01597db1 100644 --- a/src/systeminfo/systeminfo_device_capability.h +++ b/src/systeminfo/systeminfo_device_capability.h @@ -17,6 +17,9 @@ #ifndef WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_DEVICE_CAPABILITY_H__ #define WEBAPI_PLUGINS_SYSTEMINFO_SYSTEMINFO_DEVICE_CAPABILITY_H__ +#include +#include +#include #include #include "common/picojson.h" #include "common/platform_result.h" @@ -24,9 +27,14 @@ namespace extension { namespace systeminfo { +template +using CapabilitiesMap = + std::map>; + class SystemInfoDeviceCapability { public: static common::PlatformResult GetCapability(const std::string& key, picojson::value* result); + static common::PlatformResult GetValueBool(const char* key, bool* value); static common::PlatformResult GetValueInt(const char* key, int* value); static common::PlatformResult GetValueString(const char* key, std::string* str_value); @@ -40,8 +48,20 @@ class SystemInfoDeviceCapability { static common::PlatformResult IsNativeOspCompatible(bool* result); static common::PlatformResult GetNativeAPIVersion(std::string* return_value); static common::PlatformResult GetPlatformVersionName(std::string* result); - static bool IsBluetoothAlwaysOn(); - static bool IsScreen(); + static common::PlatformResult IsBluetoothAlwaysOn(bool* result); + static common::PlatformResult IsScreen(bool* result); + + private: + static CapabilitiesMap InitializeBoolCapabilities(); + static CapabilitiesMap InitializeIntCapabilities(); + static CapabilitiesMap InitializeStringCapabilities(); + + static common::PlatformResult CheckCapabilityType(const std::string& key, + system_info_type_e* capability_type); + + static CapabilitiesMap bool_capabilities; + static CapabilitiesMap int_capabilities; + static CapabilitiesMap string_capabilities; }; } // namespace systeminfo -- 2.34.1