From: Lukasz Bardeli Date: Fri, 28 Aug 2015 09:08:11 +0000 (+0200) Subject: [SystemInfo] Fix for systemInfo CameraFlash X-Git-Tag: submit/tizen/20151026.073646^2^2~156 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4d32d632863cad52a2e47dfa0d8319fd69136a74;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [SystemInfo] Fix for systemInfo CameraFlash [Verification] Code compiles without error. Passrate 99.66% (297/296/1/0/0) Change-Id: I1d3b7058183620d6e47ef65fdf92527955bfe15e Signed-off-by: Lukasz Bardeli --- diff --git a/src/systeminfo/systeminfo-utils.cpp b/src/systeminfo/systeminfo-utils.cpp index 2b438bb0..abbfd786 100644 --- a/src/systeminfo/systeminfo-utils.cpp +++ b/src/systeminfo/systeminfo-utils.cpp @@ -540,6 +540,8 @@ class SystemInfoListeners { void DisconnectSensor(int handle_orientation); wifi_rssi_level_e GetWifiLevel(); void SetWifiLevel(wifi_rssi_level_e level); + std::string GetCameraTypes(int index); + int GetCameraTypesCount(); private: static PlatformResult RegisterVconfCallback(const char *in_key, vconf_callback_fn cb, SysteminfoInstance& instance); @@ -548,6 +550,7 @@ class SystemInfoListeners { PlatformResult UnregisterIpChangeCallback(); bool IsIpChangeCallbackInvalid(); void InitTapiHandles(); + void InitCameraTypes(); guint m_cpu_event_id; guint m_storage_event_id; @@ -579,6 +582,7 @@ class SystemInfoListeners { connection_h m_connection_handle; //! Sensor handle for DeviceOrientation purposes int m_sensor_handle; + std::vector m_camera_types; }; SystemInfoListeners::SystemInfoListeners(): m_cpu_event_id(0), @@ -623,6 +627,7 @@ SystemInfoListeners::SystemInfoListeners(): } else { LoggerD("Setting wifi listener succeed"); } + InitCameraTypes(); } SystemInfoListeners::~SystemInfoListeners(){ @@ -713,9 +718,19 @@ void SystemInfoListeners::SetWifiLevel(wifi_rssi_level_e level) m_wifi_level = level; } -PlatformResult SystemInfoListeners::RegisterBatteryListener(const SysteminfoUtilsCallback& callback, - SysteminfoInstance& instance) -{ +std::string SystemInfoListeners::GetCameraTypes(int index) { + if (index >= m_camera_types.size()) { + return ""; + } + return m_camera_types[index]; +} + +int SystemInfoListeners::GetCameraTypesCount() { + return m_camera_types.size(); +} + +PlatformResult SystemInfoListeners::RegisterBatteryListener( + const SysteminfoUtilsCallback& callback, SysteminfoInstance& instance) { LoggerD("Entered"); if (nullptr == m_battery_listener) { PlatformResult ret = PlatformResult(ErrorCode::NO_ERROR); @@ -1412,8 +1427,25 @@ void SystemInfoListeners::InitTapiHandles() } } -TapiHandle* SystemInfoListeners::GetTapiHandle() -{ +void SystemInfoListeners::InitCameraTypes() { + bool supported = false; + PlatformResult ret = SystemInfoDeviceCapability::GetValueBool( + "tizen.org/feature/camera.back.flash", &supported); + if (ret.IsSuccess()) { + if (supported) { + m_camera_types.push_back("BACK"); + } + } + ret = SystemInfoDeviceCapability::GetValueBool( + "tizen.org/feature/camera.front.flash", &supported); + if (ret.IsSuccess()) { + if (supported) { + m_camera_types.push_back("FRONT"); + } + } +} + +TapiHandle* SystemInfoListeners::GetTapiHandle() { LoggerD("Entered"); InitTapiHandles(); @@ -1748,10 +1780,7 @@ PlatformResult SysteminfoUtils::GetCount(const std::string& property, unsigned l count = sim_mgr.GetSimCount(system_info_listeners.GetTapiHandles()); } } else if ("CAMERA_FLASH" == property) { - const int numberOfCameraFlashProperties = 3; - PlatformResult ret = CheckCameraFlashSupport(); - if (ret.IsError()) count = 0; - else count = numberOfCameraFlashProperties; + count = system_info_listeners.GetCameraTypesCount(); } else if ("ETHERNET_NETWORK" == property) { PlatformResult ret = CheckIfEthernetNetworkSupported(); if (ret.IsError()) count = 0; @@ -1794,7 +1823,7 @@ PlatformResult SysteminfoUtils::ReportProperty(const std::string& property, int } else if ("MEMORY" == property) { return ReportMemory(res_obj); } else if ("CAMERA_FLASH" == property) { - return ReportCameraFlash(res_obj); + return ReportCameraFlash(res_obj, index); } LoggerD("Property with given id is not supported"); return PlatformResult(ErrorCode::NOT_SUPPORTED_ERR, "Property with given id is not supported"); @@ -2822,12 +2851,19 @@ PlatformResult SysteminfoUtils::ReportStorage(picojson::object& out) { out.insert(std::make_pair("storages", picojson::value(result))); return PlatformResult(ErrorCode::NO_ERROR); } -PlatformResult SysteminfoUtils::ReportCameraFlash(picojson::object& out) { - PlatformResult ret = CheckCameraFlashSupport(); - if (ret.IsError()) { - return ret; - } - return PlatformResult(ErrorCode::NO_ERROR); +PlatformResult SysteminfoUtils::ReportCameraFlash(picojson::object& out, + unsigned long index) { + + if (index < system_info_listeners.GetCameraTypesCount()) { + std::string camera = system_info_listeners.GetCameraTypes(index); + out.insert(std::make_pair("camera", picojson::value(camera))); + } else { + return PlatformResult( + ErrorCode::NOT_SUPPORTED_ERR, + "Camera is not supported on this device"); + } + + return PlatformResult(ErrorCode::NO_ERROR); } PlatformResult SysteminfoUtils::RegisterBatteryListener(const SysteminfoUtilsCallback& callback, diff --git a/src/systeminfo/systeminfo-utils.h b/src/systeminfo/systeminfo-utils.h index 58e7595d..df5af850 100644 --- a/src/systeminfo/systeminfo-utils.h +++ b/src/systeminfo/systeminfo-utils.h @@ -103,7 +103,7 @@ class SysteminfoUtils { static common::PlatformResult ReportSim(picojson::object& out, unsigned long count); static common::PlatformResult ReportPeripheral(picojson::object& out); static common::PlatformResult ReportMemory(picojson::object& out); - static common::PlatformResult ReportCameraFlash(picojson::object& out); + static common::PlatformResult ReportCameraFlash(picojson::object& out, unsigned long count); static common::PlatformResult ReportStorage(picojson::object& out); }; diff --git a/src/systeminfo/systeminfo_api.js b/src/systeminfo/systeminfo_api.js index 9bee0166..babcfe0e 100644 --- a/src/systeminfo/systeminfo_api.js +++ b/src/systeminfo/systeminfo_api.js @@ -694,8 +694,8 @@ function SystemInfoCameraFlash(data) { }; Object.defineProperties(this, { - brightness : {get: getBrightness, enumerable: true}, - camera : {value: null, enumerable: true}, + brightness : {set : function(){}, get: getBrightness, enumerable: true}, + camera : {value: data.camera, enumerable: true}, levels : {get: getLevels, enumerable: true}, }); } @@ -704,7 +704,7 @@ SystemInfoCameraFlash.prototype.setBrightness = function(brightness) { xwalk.utils.checkPrivilegeAccess(privilege_.LED); var args = validator_.validateArgs(arguments, [ - {name: 'brightness', type: types_.LONG} + {name: 'brightness', type: types_.DOUBLE} ]); args.brightness = args.brightness * this.levels; diff --git a/src/systeminfo/systeminfo_instance.cc b/src/systeminfo/systeminfo_instance.cc index a0f9dc90..bca7eb0c 100644 --- a/src/systeminfo/systeminfo_instance.cc +++ b/src/systeminfo/systeminfo_instance.cc @@ -505,9 +505,14 @@ void SysteminfoInstance::SetBrightness(const picojson::value& args, picojson::ob int result = device_flash_set_brightness(brightness); if (result != DEVICE_ERROR_NONE) { LoggerE("Error occured"); - ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error occured"), &out); + if (DEVICE_ERROR_INVALID_PARAMETER == result) { + ReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Error occured"), &out); + } else { + ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error occured"), &out); + } return; } + ReportSuccess(out); } @@ -521,6 +526,7 @@ void SysteminfoInstance::GetBrightness(const picojson::value& args, picojson::ob ReportError(PlatformResult(ErrorCode::UNKNOWN_ERR, "Error occured"), &out); return; } + ReportSuccess(picojson::value(std::to_string(brightness)), out); }