From 000e66db1e7c846d06fe61c016951d9cc31912c3 Mon Sep 17 00:00:00 2001 From: Tomasz Marciniak Date: Tue, 26 Jul 2016 08:08:36 +0200 Subject: [PATCH 01/16] [Widgetservice] NotFoundError separated from AbortError. [Verification] Code compiles. Change-Id: I291ad7deb001fe32284cff520a82746e673ea563 Signed-off-by: Tomasz Marciniak --- src/widgetservice/widgetservice_utils.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/widgetservice/widgetservice_utils.cc b/src/widgetservice/widgetservice_utils.cc index 7ba52e0..142cbbb 100644 --- a/src/widgetservice/widgetservice_utils.cc +++ b/src/widgetservice/widgetservice_utils.cc @@ -84,12 +84,13 @@ TizenResult WidgetServiceUtils::ConvertErrorCode(int error) { return common::NotSupportedError(error); case WIDGET_ERROR_CANCELED: return common::OperationCanceledError(error); + case WIDGET_ERROR_NOT_EXIST: + return common::NotFoundError(error); case WIDGET_ERROR_OUT_OF_MEMORY: case WIDGET_ERROR_FILE_NO_SPACE_ON_DEVICE: case WIDGET_ERROR_FAULT: case WIDGET_ERROR_ALREADY_EXIST: case WIDGET_ERROR_ALREADY_STARTED: - case WIDGET_ERROR_NOT_EXIST: default: return common::AbortError(error); } -- 2.7.4 From 9e34abf8c7412659d6a8bb65c20dc9c19f67792f Mon Sep 17 00:00:00 2001 From: Tomasz Marciniak Date: Tue, 19 Jul 2016 13:14:54 +0200 Subject: [PATCH 02/16] [HAM] Added recording functionality. [Verification] Code compiles. TCT pass rate did not change. Change-Id: Ib1e0475547f8fc094f647065afc129e84d8bcaac Signed-off-by: Tomasz Marciniak --- .../humanactivitymonitor_api.js | 171 +++++++++ .../humanactivitymonitor_instance.cc | 113 ++++++ .../humanactivitymonitor_instance.h | 6 + .../humanactivitymonitor_manager.cc | 415 ++++++++++++++++++++- .../humanactivitymonitor_manager.h | 6 + 5 files changed, 707 insertions(+), 4 deletions(-) diff --git a/src/humanactivitymonitor/humanactivitymonitor_api.js b/src/humanactivitymonitor/humanactivitymonitor_api.js index d9c3bf0..2d2d65e 100755 --- a/src/humanactivitymonitor/humanactivitymonitor_api.js +++ b/src/humanactivitymonitor/humanactivitymonitor_api.js @@ -33,6 +33,10 @@ function SetReadOnlyProperty(obj, n, v) { } var ACCUMULATIVE_PEDOMETER_DATA = 'ACCUMULATIVE_PEDOMETER_DATA'; +var MIN_OPTION_INTERVAL = 0; +var MIN_OPTION_RETENTION_PERIOD = 1; +var MIN_QUERY_TIME = 0; +var MIN_QUERY_INTERVAL = 0; var HumanActivityType = { PEDOMETER: 'PEDOMETER', @@ -42,6 +46,13 @@ var HumanActivityType = { SLEEP_MONITOR: 'SLEEP_MONITOR' }; +var HumanActivityRecorderType = { + PEDOMETER: 'PEDOMETER', + HRM: 'HRM', + SLEEP_MONITOR: 'SLEEP_MONITOR', + PRESSURE: 'PRESSURE' +}; + var PedometerStepStatus = { NOT_MOVING: 'NOT_MOVING', WALKING: 'WALKING', @@ -90,6 +101,39 @@ function convertActivityData(type, data) { } } +function createRecorderData(func, data) { + var array = []; + + data.forEach(function (d) { + array.push(new func(d)); + }); + + return array; +} + +function convertActivityRecorderData(type, data) { + var func = undefined; + switch (type) { + case HumanActivityRecorderType.PEDOMETER: + func = HumanActivityRecorderPedometerData; + break; + case HumanActivityRecorderType.HRM: + func = HumanActivityRecorderHRMData; + break; + case HumanActivityRecorderType.SLEEP_MONITOR: + func = HumanActivityRecorderSleepMonitorData; + break; + case HumanActivityRecorderType.PRESSURE: + func = HumanActivityRecorderPressureData; + break; + default: + console.error('Uknown human activity recorder type: ' + type); + return; + } + + return createRecorderData(func, data); +} + function ActivityRecognitionListenerManager() { this.listeners = {}; this.nextId = 1; @@ -386,6 +430,87 @@ HumanActivityMonitorManager.prototype.removeActivityRecognitionListener = functi activityRecognitionListener.removeListener(args.watchId); }; +HumanActivityMonitorManager.prototype.startRecorder = function() { + var args = validator_.validateArgs(arguments, [ + {name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityRecorderType)}, + {name: 'options', type : types_.DICTIONARY, optional: true, nullable: false} + ]); + + var callArgs = {}; + + if (args.options) { + if (MIN_OPTION_INTERVAL > args.options.interval || + MIN_OPTION_RETENTION_PERIOD > args.options.interval) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Invalid option value'); + } + + callArgs.options = args.options; + } + + callArgs.type = args.type; + + var result = native_.callSync('HumanActivityMonitorManager_startRecorder', callArgs); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } +}; + +HumanActivityMonitorManager.prototype.stopRecorder = function() { + var args = validator_.validateArgs(arguments, [ + {name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityRecorderType)}, + ]); + + var callArgs = {}; + callArgs.type = args.type; + + var result = native_.callSync('HumanActivityMonitorManager_stopRecorder', callArgs); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } +}; + +HumanActivityMonitorManager.prototype.readRecorderData = function() { + var args = validator_.validateArgs(arguments, [ + {name: 'type', type: types_.ENUM, values: Object.keys(HumanActivityRecorderType)}, + {name: 'query', type : types_.DICTIONARY, optional: false, nullable: true}, + {name: 'successCallback', type: types_.FUNCTION}, + {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} + ]); + + var callArgs = {}; + + if (args.query) { + if ((args.query.startTime && MIN_QUERY_TIME > args.query.startTime) || + (args.query.endTime && MIN_QUERY_TIME > args.query.endTime) || + (args.query.anchorTime && MIN_QUERY_TIME > args.query.anchorTime) || + (args.query.interval && MIN_QUERY_INTERVAL > args.query.interval) || + (args.query.startTime && args.query.endTime && args.query.startTime > args.query.endTime)) { + throw new WebAPIException(WebAPIException.INVALID_VALUES_ERR, 'Invalid query value'); + } + } + + callArgs.options = args.options; + callArgs.type = args.type; + callArgs.query = args.query; + + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + } else { + var array = convertActivityRecorderData(args.type, native_.getResultObject(result)); + args.successCallback(array); + } + }; + + var result = native_.call('HumanActivityMonitorManager_readRecorderData', callArgs, callback); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } +}; + function StepDifference(data) { SetReadOnlyProperty(this, 'stepCountDifference', data.stepCountDifference); SetReadOnlyProperty(this, 'timestamp', data.timestamp); @@ -480,4 +605,50 @@ function HumanActivitySleepMonitorData(data) { HumanActivitySleepMonitorData.prototype = new HumanActivityData(); HumanActivitySleepMonitorData.prototype.constructor = HumanActivitySleepMonitorData; +//Recorded data +function HumanActivityRecorderData(data) { + if (data) { + SetReadOnlyProperty(this, 'startTime', data.startTime); + SetReadOnlyProperty(this, 'endTime', data.endTime); + } +} + +function HumanActivityRecorderPedometerData(data) { + HumanActivityRecorderData.call(this, data); + SetReadOnlyProperty(this, 'distance', data.distance); + SetReadOnlyProperty(this, 'calorie', data.calorie); + SetReadOnlyProperty(this, 'totalStepCount', data.totalStepCount); + SetReadOnlyProperty(this, 'walkStepCount', data.walkStepCount); + SetReadOnlyProperty(this, 'runStepCount', data.runStepCount); +} + +HumanActivityRecorderPedometerData.prototype = new HumanActivityRecorderData(); +HumanActivityRecorderPedometerData.prototype.constructor = HumanActivityRecorderPedometerData; + +function HumanActivityRecorderHRMData(data) { + HumanActivityRecorderData.call(this, data); + SetReadOnlyProperty(this, 'heartRate', data.heartRate); +} + +HumanActivityRecorderHRMData.prototype = new HumanActivityRecorderData(); +HumanActivityRecorderHRMData.prototype.constructor = HumanActivityRecorderHRMData; + +function HumanActivityRecorderSleepMonitorData(data) { + HumanActivityRecorderData.call(this, data); + SetReadOnlyProperty(this, 'status', data.status); +} + +HumanActivityRecorderSleepMonitorData.prototype = new HumanActivityRecorderData(); +HumanActivityRecorderSleepMonitorData.prototype.constructor = HumanActivityRecorderSleepMonitorData; + +function HumanActivityRecorderPressureData(data) { + HumanActivityRecorderData.call(this, data); + SetReadOnlyProperty(this, 'max', data.max); + SetReadOnlyProperty(this, 'min', data.min); + SetReadOnlyProperty(this, 'average', data.average); +} + +HumanActivityRecorderPressureData.prototype = new HumanActivityRecorderData(); +HumanActivityRecorderPressureData.prototype.constructor = HumanActivityRecorderPressureData; + exports = new HumanActivityMonitorManager(); diff --git a/src/humanactivitymonitor/humanactivitymonitor_instance.cc b/src/humanactivitymonitor/humanactivitymonitor_instance.cc index d572ba3..5000cb4 100755 --- a/src/humanactivitymonitor/humanactivitymonitor_instance.cc +++ b/src/humanactivitymonitor/humanactivitymonitor_instance.cc @@ -35,6 +35,8 @@ namespace { const std::string kPrivilegeHealthInfo = "http://tizen.org/privilege/healthinfo"; const std::string kPrivilegeLocation = "http://tizen.org/privilege/location"; +const int DEFAULT_HRM_INTERVAL = 1440; // 1440 (1 day) default value for HRM's interval +const int DEFAULT_RETENTION_PERIOD = 1; // 1 hour default value for retention period } // namespace using common::PlatformResult; @@ -58,6 +60,12 @@ HumanActivityMonitorInstance::HumanActivityMonitorInstance() { HumanActivityMonitorManagerAddActivityRecognitionListener); REGISTER_SYNC("HumanActivityMonitorManager_removeActivityRecognitionListener", HumanActivityMonitorManagerRemoveActivityRecognitionListener); + REGISTER_SYNC("HumanActivityMonitorManager_startRecorder", + HumanActivityMonitorManagerStartRecorder); + REGISTER_SYNC("HumanActivityMonitorManager_stopRecorder", + HumanActivityMonitorManagerStopRecorder); + REGISTER_SYNC("HumanActivityMonitorManager_readRecorderData", + HumanActivityMonitorManagerReadRecorderData); #undef REGISTER_SYNC } @@ -261,6 +269,111 @@ void HumanActivityMonitorInstance::HumanActivityMonitorManagerRemoveActivityReco } } +void HumanActivityMonitorInstance::HumanActivityMonitorManagerStartRecorder( + const picojson::value& args, picojson::object& out) { + LoggerD("Enter"); + + CHECK_PRIVILEGE_ACCESS(kPrivilegeHealthInfo, &out); + CHECK_EXIST(args, "type", out) + + const auto& type = args.get("type").get(); + + PlatformResult result = Init(); + if (!result) { + LogAndReportError(result, &out, ("Failed: Init()")); + return; + } + + int interval = DEFAULT_HRM_INTERVAL; + int retention_period = DEFAULT_RETENTION_PERIOD; + + if (args.contains("options")) { + const auto& options = args.get("options"); + auto& js_interval = options.get("interval"); + auto& js_retention_period = options.get("retentionPeriod"); + + if (js_interval.is()) { + interval = js_interval.get(); + } + + if (js_retention_period.is()) { + retention_period = js_retention_period.get(); + } + } + + LoggerD("interval: %d retentionPeriod: %d", interval, retention_period); + + result = manager_->StartDataRecorder(type, interval, retention_period); + if (result) { + ReportSuccess(out); + } else { + LogAndReportError(result, &out, ("Failed: manager_->StartDataRecorder()")); + } +} + +void HumanActivityMonitorInstance::HumanActivityMonitorManagerStopRecorder( + const picojson::value& args, picojson::object& out) { + LoggerD("Enter"); + CHECK_EXIST(args, "type", out) + + const auto& type = args.get("type").get(); + + PlatformResult result = Init(); + if (!result) { + LogAndReportError(result, &out, ("Failed: Init()")); + return; + } + + result = manager_->StopDataRecorder(type); + if (result) { + ReportSuccess(out); + } else { + LogAndReportError(result, &out, ("Failed: manager_->StopDataRecorder()")); + } +} + +void HumanActivityMonitorInstance::HumanActivityMonitorManagerReadRecorderData( + const picojson::value& args, picojson::object& out) { + LoggerD("Enter"); + CHECK_EXIST(args, "type", out) + CHECK_EXIST(args, "query", out) + + const auto& type = args.get("type").get(); + const auto& query = args.get("query"); + + PlatformResult result = Init(); + if (!result) { + LogAndReportError(result, &out, ("Failed: Init()")); + return; + } + + const auto callback_id = args.get("callbackId").get(); + + auto get = [this, type, query, callback_id]() -> void { + picojson::value response = picojson::value(picojson::object()); + picojson::object& response_obj = response.get(); + response_obj["callbackId"] = picojson::value(callback_id); + + //picojson::value data = picojson::value(); + picojson::value array_value{picojson::array{}}; + auto* array = &array_value.get(); + + PlatformResult result = manager_->ReadRecorderData(type, array, query); + + if (result) { + ReportSuccess(array_value, response_obj); + } else { + LogAndReportError(result, &response_obj, ("Failed: manager_->ReadRecorderData()")); + } + + Instance::PostMessage(this, response.serialize().c_str()); + }; + + TaskQueue::GetInstance().Async(get); + + ReportSuccess(out); +} + #undef CHECK_EXIST } // namespace humanactivitymonitor diff --git a/src/humanactivitymonitor/humanactivitymonitor_instance.h b/src/humanactivitymonitor/humanactivitymonitor_instance.h index 07f0e1a..1ab6829 100755 --- a/src/humanactivitymonitor/humanactivitymonitor_instance.h +++ b/src/humanactivitymonitor/humanactivitymonitor_instance.h @@ -42,6 +42,12 @@ class HumanActivityMonitorInstance : public common::ParsedInstance { const picojson::value& args, picojson::object& out); void HumanActivityMonitorManagerRemoveActivityRecognitionListener( const picojson::value& args, picojson::object& out); + void HumanActivityMonitorManagerStartRecorder( + const picojson::value& args, picojson::object& out); + void HumanActivityMonitorManagerStopRecorder( + const picojson::value& args, picojson::object& out); + void HumanActivityMonitorManagerReadRecorderData( + const picojson::value& args, picojson::object& out); std::shared_ptr manager_; common::PlatformResult Init(); diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.cc b/src/humanactivitymonitor/humanactivitymonitor_manager.cc index 284a686..387220f 100755 --- a/src/humanactivitymonitor/humanactivitymonitor_manager.cc +++ b/src/humanactivitymonitor/humanactivitymonitor_manager.cc @@ -22,11 +22,13 @@ #include #include #include +#include #include "common/logger.h" #include "common/optional.h" #include "common/picojson.h" #include "common/tools.h" +#include "common/scope_exit.h" namespace extension { namespace humanactivitymonitor { @@ -36,12 +38,16 @@ using common::ErrorCode; using common::tools::ReportError; using common::tools::ReportSuccess; +typedef std::map SensorRecorderDataMap; +typedef std::map SensorRecorderQueryMap; + namespace { const std::string kActivityTypePedometer = "PEDOMETER"; const std::string kActivityTypeWristUp = "WRIST_UP"; const std::string kActivityTypeHrm = "HRM"; const std::string kActivityTypeSleepMonitor = "SLEEP_MONITOR"; +const std::string kActivityTypePressure = "PRESSURE"; const std::string kSleepStateAwake = "AWAKE"; const std::string kSleepStateAsleep = "ASLEEP"; @@ -70,6 +76,46 @@ const std::string kAccumulativeTotalStepCount = "accumulativeTotalStepCount"; const std::string kAccumulativeWalkStepCount = "accumulativeWalkStepCount"; const std::string kAccumulativeRunStepCount = "accumulativeRunStepCount"; +const std::string kRecordedStartTime = "startTime"; +const std::string kRecordedEndTime = "endTime"; +const std::string kRecordedHeartRate = "heartRate"; + +const std::string kRecordedDistance = "distance"; +const std::string kRecordedCalorie = "calorie"; +const std::string kRecordedTotalStepCount = "totalStepCount"; +const std::string kRecordedWalkStepCount = "walkStepCount"; +const std::string kRecordedRunStepCount = "runStepCount"; + +const std::string kRecordedMin = "min"; +const std::string kRecordedMax = "max"; +const std::string kRecordedAverage = "average"; + +const std::string kRecordedAnchorTime = "anchorTime"; +const std::string kRecordedInterval = "interval"; + +ErrorCode getErrorCode (const int errorCode) { + ScopeLogger(); + switch (errorCode) { + case SENSOR_ERROR_IO_ERROR: + return ErrorCode::IO_ERR; + case SENSOR_ERROR_NOT_SUPPORTED: + return ErrorCode::NOT_SUPPORTED_ERR; + case SENSOR_ERROR_PERMISSION_DENIED: + return ErrorCode::PERMISSION_DENIED_ERR; + case SENSOR_ERROR_NOT_AVAILABLE: + return ErrorCode::SERVICE_NOT_AVAILABLE_ERR; + case SENSOR_ERROR_NO_DATA: + return ErrorCode::NOT_FOUND_ERR; + case SENSOR_ERROR_INVALID_PARAMETER: + return ErrorCode::INVALID_VALUES_ERR; + case SENSOR_ERROR_OUT_OF_MEMORY: + case SENSOR_ERROR_OPERATION_FAILED: + case SENSOR_ERROR_NOT_NEED_CALIBRATION: + default: + return ErrorCode::ABORT_ERR; + } +} + // helper structure, allows easier access to data values struct PedometerDataWrapper : public sensor_pedometer_data_t { inline float steps() const { @@ -155,6 +201,66 @@ std::string FromSensorPedometerState(sensor_pedometer_state_e e) { } } +PlatformResult ConvertRecordedTime(void* data, picojson::object* obj) { + ScopeLogger("convert_recorded_time"); + + time_t start_time, end_time; + + int ret = sensor_recorder_data_get_time(data, &start_time, &end_time); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(getErrorCode(ret), + "Failed to get time", + ("Failed to get time, error: %d (%s)", ret, get_error_message(ret))); + } + + obj->insert(std::make_pair(kRecordedStartTime, picojson::value(static_cast(start_time)))); + obj->insert(std::make_pair(kRecordedEndTime, picojson::value(static_cast(end_time)))); + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult ConvertRecordedInt(void* data, picojson::object* obj, + const SensorRecorderDataMap& map) { + ScopeLogger(); + + int ret = SENSOR_ERROR_NONE; + int tmp = 0; + + for (auto& it : map) { + ret = sensor_recorder_data_get_int(data, it.first, &tmp); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(getErrorCode(ret), + "Failed to get int value", + ("Failed to get int value, error: %d (%s)", ret, get_error_message(ret))); + } + + obj->insert(std::make_pair(it.second, picojson::value(static_cast(tmp)))); + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + +PlatformResult ConvertRecordedDouble(void* data, picojson::object* obj, + const SensorRecorderDataMap& map) { + ScopeLogger(); + + int ret = SENSOR_ERROR_NONE; + double tmp = 0; + + for (auto& it : map) { + ret = sensor_recorder_data_get_double(data, it.first, &tmp); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(getErrorCode(ret), + "Failed to get double value", + ("Failed to get double value, error: %d (%s)", ret, get_error_message(ret))); + } + + obj->insert(std::make_pair(it.second, picojson::value(static_cast(tmp)))); + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + } // namespace const std::string kActivityTypeGps = "GPS"; @@ -227,6 +333,34 @@ class HumanActivityMonitorManager::Monitor { return GetDataImpl(data); } + PlatformResult StartDataRecorder(int interval, int retention_period) { + ScopeLogger(type()); + + auto result = IsSupported(); + if (!result) { + return result; + } + + return StartDataRecorderImpl(interval, retention_period); + } + + PlatformResult StopDataRecorder() { + ScopeLogger(type()); + + return StopDataRecorderImpl(); + } + + PlatformResult ReadRecorderData(picojson::array* data, const picojson::value& query) { + ScopeLogger(type()); + + auto result = IsSupported(); + if (!result) { + return result; + } + + return ReadRecorderDataImpl(data, query); + } + protected: virtual PlatformResult IsSupportedImpl(bool* supported) const { ScopeLogger(type()); @@ -249,6 +383,21 @@ class HumanActivityMonitorManager::Monitor { return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,"NOT_SUPPORTED_ERR"); } + virtual PlatformResult StartDataRecorderImpl(int interval, int retention_period) const { + ScopeLogger(type()); + return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,"NOT_SUPPORTED_ERR"); + } + + virtual PlatformResult StopDataRecorderImpl() const { + ScopeLogger(type()); + return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,"NOT_SUPPORTED_ERR"); + } + + virtual PlatformResult ReadRecorderDataImpl(picojson::array* data, const picojson::value& query) { + ScopeLogger(type()); + return LogAndCreateResult(ErrorCode::NOT_SUPPORTED_ERR,"NOT_SUPPORTED_ERR"); + } + private: PlatformResult IsSupported() { ScopeLogger(type()); @@ -383,8 +532,10 @@ class HumanActivityMonitorManager::Monitor::GestureMonitor : public HumanActivit class HumanActivityMonitorManager::Monitor::SensorMonitor : public HumanActivityMonitorManager::Monitor { public: using SensorEventConverter = std::function; + using SensorRecordedConverter = std::function; - SensorMonitor(const std::string& t, sensor_type_e s, const SensorEventConverter& c) : Monitor(t), sensor_(s), handle_(nullptr), converter_(c) { + SensorMonitor(const std::string& t, sensor_type_e s, const SensorEventConverter& c, const SensorRecordedConverter& r) + : Monitor(t), sensor_(s), handle_(nullptr), converter_(c), converter_recorded_(r), recorded_data_(nullptr) { ScopeLogger(type()); } @@ -522,6 +673,90 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor : public HumanActivity return PlatformResult(ErrorCode::NO_ERROR); } + virtual PlatformResult StartDataRecorderImpl(int interval, int retention_period) const override { + ScopeLogger(type()); + + sensor_recorder_option_h option = nullptr; + + int ret = sensor_recorder_create_option(&option); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(getErrorCode(ret), + "Failed to create recorder option", + ("Failed to create (%d) recorder option, error: %d (%s)", sensor_, ret, get_error_message(ret))); + } + + SCOPE_EXIT { + sensor_recorder_destroy_option(option); + }; + + auto result = SetOptions(&option, interval, retention_period); + if (!result) { + return result; + } + + ret = sensor_recorder_start(sensor_, option); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(getErrorCode(ret), + "Failed to start recording", + ("Failed to start (%d) recording, error: %d (%s)", sensor_, ret, get_error_message(ret))); + } + + return PlatformResult(ErrorCode::NO_ERROR); + } + + virtual PlatformResult StopDataRecorderImpl() const override { + ScopeLogger(type()); + + int ret = sensor_recorder_stop(sensor_); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(getErrorCode(ret), + "Failed to stop recording", + ("Failed to stop (%d) recording, error: %d (%s)", sensor_, ret, get_error_message(ret))); + } + + return PlatformResult(ErrorCode::NO_ERROR); + } + + virtual PlatformResult ReadRecorderDataImpl(picojson::array* data, const picojson::value& query) override { + ScopeLogger(type()); + + std::lock_guard lock(mutex_); + this->recorded_data_ = data; + + sensor_recorder_query_h query_h = nullptr; + int ret = sensor_recorder_create_query(&query_h); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(getErrorCode(ret), + "Failed to create query", + ("Failed to create (%d) query, error: %d (%s)", sensor_, ret, get_error_message(ret))); + } + + SCOPE_EXIT { + sensor_recorder_destroy_query(query_h); + }; + + if (!query.is()) { + auto result = SetQuery(&query_h, query); + if (!result) { + return result; + } + } + + ret = sensor_recorder_read_sync(sensor_, query_h, SensorRecordedDataCb, static_cast(this)); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(getErrorCode(ret), + "Failed to read recorded data", + ("Failed to read (%d) recorded data, error: %d (%s)", sensor_, ret, get_error_message(ret))); + } + + return PlatformResult(ErrorCode::NO_ERROR); + } + + void addRecordedData(picojson::value* data) { + ScopeLogger(); + recorded_data_->push_back(*data); + } + private: static void OnSensorEvent(sensor_h, sensor_event_s* event, void* user_data) { ScopeLogger(); @@ -545,9 +780,89 @@ class HumanActivityMonitorManager::Monitor::SensorMonitor : public HumanActivity callback(&sensor_data); } + static bool SensorRecordedDataCb(sensor_type_e type, void* data, int remains, + sensor_error_e error, void* user_data) { + ScopeLogger(); + + auto monitor = static_cast(user_data); + + picojson::value val = picojson::value(picojson::object()); + picojson::object* obj = &val.get(); + + auto result = monitor->converter_recorded_(data, obj); + if (result) { + monitor->addRecordedData(&val); + } + + return true; // continue + } + + PlatformResult SetOptions(sensor_recorder_option_h *option, + int interval, int retention_period) const { + ScopeLogger(); + + int ret = SENSOR_ERROR_NONE; + + if (SENSOR_HRM == sensor_) { + ret = sensor_recorder_option_set_int( + *option, SENSOR_RECORDER_OPTION_INTERVAL, interval); + + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Failed to set recorder option", + ("Failed to set (%d) recorder option, error: %d (%s)", sensor_, ret, get_error_message(ret))); + } + } + + ret = sensor_recorder_option_set_int( + *option, SENSOR_RECORDER_OPTION_RETENTION_PERIOD, retention_period); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Failed to set recorder option", + ("Failed to set (%d) recorder option, error: %d (%s)", sensor_, ret, get_error_message(ret))); + } + + return PlatformResult(ErrorCode::NO_ERROR); + } + + PlatformResult SetQuery(sensor_recorder_query_h *query_h, + const picojson::value& query) const { + ScopeLogger(); + + SensorRecorderQueryMap map_query { + {SENSOR_RECORDER_QUERY_START_TIME, kRecordedStartTime}, + {SENSOR_RECORDER_QUERY_END_TIME, kRecordedEndTime}, + }; + + if (SENSOR_HUMAN_PEDOMETER == sensor_ || SENSOR_PRESSURE == sensor_) { + map_query.insert(std::make_pair(SENSOR_RECORDER_QUERY_ANCHOR_TIME, kRecordedAnchorTime)); + map_query.insert(std::make_pair(SENSOR_RECORDER_QUERY_TIME_INTERVAL, kRecordedInterval)); + } + + for (auto& it : map_query) { + int val = -1; + if (query.get(it.second).is()) { + val = query.get(it.second).get(); + if (0 <= val) { + int ret = sensor_recorder_query_set_time(query_h, it.first, val); + if (SENSOR_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, + "Failed to set query parameter", + ("Failed to set (%d) query parameter, error: %d (%s)", sensor_, ret, get_error_message(ret))); + } + } + } + } + + return PlatformResult(ErrorCode::NO_ERROR); + } + sensor_type_e sensor_; sensor_listener_h handle_; SensorEventConverter converter_; + SensorRecordedConverter converter_recorded_; + picojson::array* recorded_data_; + std::mutex mutex_; }; class HumanActivityMonitorManager::Monitor::GpsMonitor : public HumanActivityMonitorManager::Monitor { @@ -1089,11 +1404,86 @@ HumanActivityMonitorManager::HumanActivityMonitorManager() return PlatformResult(ErrorCode::NO_ERROR); }; - monitors_.insert(std::make_pair(kActivityTypePedometer, std::make_shared(kActivityTypePedometer, SENSOR_HUMAN_PEDOMETER, convert_pedometer))); + auto convert_recorded_pedometer = [](void* data, picojson::object* obj) -> PlatformResult { + ScopeLogger("convert_recorded_pedometer"); + + SensorRecorderDataMap map_int { + {SENSOR_RECORDER_DATA_STEPS, kRecordedTotalStepCount}, + {SENSOR_RECORDER_DATA_WALK_STEPS, kRecordedWalkStepCount}, + {SENSOR_RECORDER_DATA_RUN_STEPS, kRecordedRunStepCount} + }; + + SensorRecorderDataMap map_double { + {SENSOR_RECORDER_DATA_DISTANCE, kRecordedDistance}, + {SENSOR_RECORDER_DATA_CALORIE, kRecordedCalorie} + }; + + auto result = ConvertRecordedInt(data, obj, map_int); + if (!result) { + return result; + } + + result = ConvertRecordedDouble(data, obj, map_double); + if (!result) { + return result; + } + + return ConvertRecordedTime(data, obj); + }; + + auto convert_recorded_hrm = [](void* data, picojson::object* obj) -> PlatformResult { + ScopeLogger("convert_recorded_hrm"); + + SensorRecorderDataMap map_int { + {SENSOR_RECORDER_DATA_HEART_RATE, kRecordedHeartRate}, + }; + + auto result = ConvertRecordedInt(data, obj, map_int); + if (!result) { + return result; + } + + return ConvertRecordedTime(data, obj); + }; + + auto convert_recorded_sleep_monitor = [](void* data, picojson::object* obj) -> PlatformResult { + ScopeLogger("convert_recorded_sleep_monitor"); + + SensorRecorderDataMap map_int { + {SENSOR_RECORDER_DATA_SLEEP_STATE, kStatus} + }; + + auto result = ConvertRecordedInt(data, obj, map_int); + if (!result) { + return result; + } + + return ConvertRecordedTime(data, obj); + }; + + auto convert_recorded_pressure = [](void* data, picojson::object* obj) -> PlatformResult { + ScopeLogger("convert_recorded_pressure"); + + SensorRecorderDataMap map_double { + {SENSOR_RECORDER_DATA_MAX_PRESSURE, kRecordedMax}, + {SENSOR_RECORDER_DATA_MIN_PRESSURE, kRecordedMin}, + {SENSOR_RECORDER_DATA_AVERAGE_PRESSURE, kRecordedAverage} + }; + + auto result = ConvertRecordedDouble(data, obj, map_double); + if (!result) { + return result; + } + + return ConvertRecordedTime(data, obj); + }; + + monitors_.insert(std::make_pair(kActivityTypePedometer, std::make_shared(kActivityTypePedometer, SENSOR_HUMAN_PEDOMETER, convert_pedometer, convert_recorded_pedometer))); monitors_.insert(std::make_pair(kActivityTypeWristUp, std::make_shared(kActivityTypeWristUp))); - monitors_.insert(std::make_pair(kActivityTypeHrm, std::make_shared(kActivityTypeHrm, SENSOR_HRM, convert_hrm))); + monitors_.insert(std::make_pair(kActivityTypeHrm, std::make_shared(kActivityTypeHrm, SENSOR_HRM, convert_hrm, convert_recorded_hrm))); monitors_.insert(std::make_pair(kActivityTypeGps, std::make_shared(kActivityTypeGps))); - monitors_.insert(std::make_pair(kActivityTypeSleepMonitor, std::make_shared(kActivityTypeSleepMonitor, SENSOR_HUMAN_SLEEP_MONITOR, convert_sleep))); + monitors_.insert(std::make_pair(kActivityTypeSleepMonitor, std::make_shared(kActivityTypeSleepMonitor, SENSOR_HUMAN_SLEEP_MONITOR, convert_sleep, convert_recorded_sleep_monitor))); + monitors_.insert(std::make_pair(kActivityTypePressure, std::make_shared(kActivityTypePressure, SENSOR_PRESSURE, nullptr, convert_recorded_pressure))); } HumanActivityMonitorManager::~HumanActivityMonitorManager() { @@ -1135,6 +1525,23 @@ PlatformResult HumanActivityMonitorManager::RemoveActivityRecognitionListener(co return activity_recognition_->RemoveListener(watch_id); } +PlatformResult HumanActivityMonitorManager::StartDataRecorder(const std::string& type, + int interval, int retention_period) { + ScopeLogger(); + return GetMonitor(type)->StartDataRecorder(interval, retention_period); +} + +PlatformResult HumanActivityMonitorManager::StopDataRecorder(const std::string& type) { + ScopeLogger(); + return GetMonitor(type)->StopDataRecorder(); +} + +PlatformResult HumanActivityMonitorManager::ReadRecorderData( + const std::string& type, picojson::array* data, const picojson::value& query) { + ScopeLogger(); + return GetMonitor(type)->ReadRecorderData(data, query); +} + std::shared_ptr HumanActivityMonitorManager::GetMonitor(const std::string& type) { ScopeLogger(); diff --git a/src/humanactivitymonitor/humanactivitymonitor_manager.h b/src/humanactivitymonitor/humanactivitymonitor_manager.h index ffa858f..caca7a3 100755 --- a/src/humanactivitymonitor/humanactivitymonitor_manager.h +++ b/src/humanactivitymonitor/humanactivitymonitor_manager.h @@ -49,6 +49,12 @@ class HumanActivityMonitorManager { JsonCallback callback, long* watch_id); common::PlatformResult RemoveActivityRecognitionListener(const long watchId); + common::PlatformResult StartDataRecorder(const std::string& type, + int interval, int retention_period); + common::PlatformResult StopDataRecorder(const std::string& type); + common::PlatformResult ReadRecorderData(const std::string& type, + picojson::array* data, + const picojson::value& query); private: class Monitor; -- 2.7.4 From e6a0cc67b9978cc041bf8a02da5d02f93812296b Mon Sep 17 00:00:00 2001 From: Piotr Kosko Date: Wed, 27 Jul 2016 09:38:57 +0200 Subject: [PATCH 03/16] [IotCon] Enable module in spec, make quick fixes for building iotcon [Verification] Code compiles without errors. Change-Id: I452ac6dbf4231866a49d813653a45057f275f5a6 Signed-off-by: Piotr Kosko --- packaging/webapi-plugins.spec | 2 +- src/iotcon/iotcon_instance.cc | 20 ++++++++++++++------ src/iotcon/iotcon_instance.h | 2 +- src/iotcon/iotcon_utils.cc | 4 ++-- src/iotcon/iotcon_utils.h | 4 ++-- 5 files changed, 20 insertions(+), 12 deletions(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index d00125b..0ca2d5c 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -116,7 +116,7 @@ Source0: %{name}-%{version}.tar.gz %else %define tizen_feature_ham_support 0 %endif -%define tizen_feature_iotcon_support 0 +%define tizen_feature_iotcon_support 1 %define tizen_feature_location_batch 0 %define tizen_feature_key_manager_support 1 %define tizen_feature_media_controller_support 1 diff --git a/src/iotcon/iotcon_instance.cc b/src/iotcon/iotcon_instance.cc index ba67255..7e7b5fb 100644 --- a/src/iotcon/iotcon_instance.cc +++ b/src/iotcon/iotcon_instance.cc @@ -85,6 +85,8 @@ const std::string kResult = "result"; const std::string kTimeout = "timeout"; const std::string kData = "data"; +const std::string kVirtualResourcesHandlingPath = "/home/tmp_file_iotcon.dat"; + } // namespace IotconInstance::IotconInstance() { @@ -135,7 +137,7 @@ IotconInstance::IotconInstance() { #undef REGISTER_ASYNC // initialize connection to iotcon service - int ret = iotcon_initialize(); + int ret = iotcon_initialize(kVirtualResourcesHandlingPath.c_str()); if (IOTCON_ERROR_NONE != ret) { LoggerE("Could not connnect to iotcon service: %s", get_error_message(ret)); } else { @@ -978,14 +980,14 @@ common::TizenResult IotconInstance::RemoteResourceUnsetConnectionChangeListener( return common::TizenSuccess{IotconClientManager::GetInstance().RemoveRemoteResource(ptr)}; } -void IotconInstance::ResourceFoundCallback(iotcon_remote_resource_h resource, +bool IotconInstance::ResourceFoundCallback(iotcon_remote_resource_h resource, iotcon_error_e result, void *user_data) { ScopeLogger(); CallbackData* data = static_cast(user_data); auto ret = IotconUtils::ConvertIotconError(result); if (!ret) { data->fun(ret, picojson::value{}); - return; + return IOTCON_FUNC_STOP; } picojson::value json_result = picojson::value(picojson::object()); @@ -993,9 +995,11 @@ void IotconInstance::ResourceFoundCallback(iotcon_remote_resource_h resource, ret = IotconUtils::RemoteResourceToJson(resource, &(json_result.get())); if (!ret) { data->fun(ret, picojson::value{}); - return; + return IOTCON_FUNC_STOP; } data->fun(ret, json_result); + + return IOTCON_FUNC_STOP; } common::TizenResult IotconInstance::ClientFindResource(const picojson::object& args) { @@ -1128,7 +1132,7 @@ common::TizenResult IotconInstance::ClientRemovePresenceEventListener(const pico return common::TizenSuccess(); } -void IotconDeviceInfoCb(iotcon_device_info_h device_info, +bool IotconDeviceInfoCb(iotcon_device_info_h device_info, iotcon_error_e result, void *user_data) { ScopeLogger(); @@ -1144,6 +1148,8 @@ void IotconDeviceInfoCb(iotcon_device_info_h device_info, data->fun(ret, v); delete data; + + return IOTCON_FUNC_STOP; } common::TizenResult IotconInstance::ClientGetDeviceInfo(const picojson::object& args, @@ -1173,7 +1179,7 @@ common::TizenResult IotconInstance::ClientGetDeviceInfo(const picojson::object& return common::TizenSuccess(); } -void IotconPlatformInfoCb(iotcon_platform_info_h platform_info, +bool IotconPlatformInfoCb(iotcon_platform_info_h platform_info, iotcon_error_e result, void *user_data) { ScopeLogger(); @@ -1189,6 +1195,8 @@ void IotconPlatformInfoCb(iotcon_platform_info_h platform_info, data->fun(ret, v); delete data; + + return IOTCON_FUNC_STOP; } common::TizenResult IotconInstance::ClientGetPlatformInfo(const picojson::object& args, diff --git a/src/iotcon/iotcon_instance.h b/src/iotcon/iotcon_instance.h index 528abdb..5af4f6f 100644 --- a/src/iotcon/iotcon_instance.h +++ b/src/iotcon/iotcon_instance.h @@ -32,7 +32,7 @@ class IotconInstance : public common::TizenInstance { virtual ~IotconInstance(); private: static void ConnectionChangedCallback(bool is_connected, void* user_data); - static void ResourceFoundCallback(iotcon_remote_resource_h resource, + static bool ResourceFoundCallback(iotcon_remote_resource_h resource, iotcon_error_e result, void *user_data); common::TizenResult ResourceGetObserverIds(const picojson::object& args); diff --git a/src/iotcon/iotcon_utils.cc b/src/iotcon/iotcon_utils.cc index dbf4d0e..4edc261 100644 --- a/src/iotcon/iotcon_utils.cc +++ b/src/iotcon/iotcon_utils.cc @@ -286,7 +286,7 @@ TizenResult IotconUtils::ExtractFromResource(const ResourceInfoPtr& pointer, char** uri_path, iotcon_resource_types_h* res_types, iotcon_resource_interfaces_h* ifaces, - int* properties) { + uint8_t* properties) { ScopeLogger(); auto result = ConvertIotconError(iotcon_resource_get_uri_path(pointer->handle, uri_path)); @@ -318,7 +318,7 @@ TizenResult IotconUtils::ResourceToJson(ResourceInfoPtr pointer, char* uri_path = nullptr; iotcon_resource_types_h res_types = nullptr; iotcon_resource_interfaces_h ifaces = nullptr; - int properties = 0; + uint8_t properties = 0; auto ret = ExtractFromResource(pointer, &uri_path, &res_types, &ifaces, &properties); if (!ret){ return ret; diff --git a/src/iotcon/iotcon_utils.h b/src/iotcon/iotcon_utils.h index 42d9c06..f946419 100644 --- a/src/iotcon/iotcon_utils.h +++ b/src/iotcon/iotcon_utils.h @@ -98,7 +98,7 @@ struct RemoteResourceInfo { char* device_id; iotcon_resource_types_h types; iotcon_resource_interfaces_h ifaces; - int properties; // to check if observable + uint8_t properties; // to check if observable iotcon_options_h options; iotcon_representation_h representation; RemoteResourceInfo() : @@ -144,7 +144,7 @@ class IotconUtils { char** uri_path, iotcon_resource_types_h* res_types, iotcon_resource_interfaces_h* ifaces, - int* properties); + uint8_t* properties); static common::TizenResult ResourceToJson(ResourceInfoPtr pointer, picojson::object* res); static common::TizenResult ExtractFromRemoteResource(RemoteResourceInfo* resource); -- 2.7.4 From c869fee472860571ab6ae6ef5a2e5980412a1cdf Mon Sep 17 00:00:00 2001 From: Piotr Kosko Date: Thu, 28 Jul 2016 08:44:47 +0200 Subject: [PATCH 04/16] [Notification] Added missing values casting [Bug] Native API expects range of 0-1, but webapi spec defines it with 0-100, additional values casting was needed. [Verification] TCT passrate is 100%. Code below generates notification with "12%" progress bar: tizen.notification.post( new tizen.StatusNotification( "PROGRESS", "Progress Notification", { content:"Progress", progressValue : 12 , progressType : "PERCENTAGE" } ) ); Change-Id: Ib8b5ed9bbc8235071591e93f4dc19b1fa450b557 Signed-off-by: Piotr Kosko --- src/notification/status_notification.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/notification/status_notification.cc b/src/notification/status_notification.cc index 894b432..9b03933 100644 --- a/src/notification/status_notification.cc +++ b/src/notification/status_notification.cc @@ -856,6 +856,8 @@ PlatformResult StatusNotification::GetProgressValue( return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Get notification progress error"); } + // native api uses range 0-1, but webapi expects 0-100, so we need to multiply result with 100 + tmp_progress_value *= 100; } else { return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown notification progress type", @@ -884,7 +886,8 @@ PlatformResult StatusNotification::SetProgressValue( progress_value); } } else if (progress_type == kProgressTypePercentage) { - ret = notification_set_progress(noti_handle, progress_value); + // native api uses range 0-1, but webapi expects 0-100, so we need to divide by 100 + ret = notification_set_progress(noti_handle, progress_value/100); if (is_update) { ret = notification_update_progress(noti_handle, NOTIFICATION_PRIV_ID_NONE, -- 2.7.4 From 26f6db12db968028bd5e477a9e10135fcaa0868a Mon Sep 17 00:00:00 2001 From: Andrzej Popowski Date: Thu, 28 Jul 2016 11:24:27 +0200 Subject: [PATCH 05/16] [Iotcon] - fixing bugs to pass TCT tests Change-Id: I262dcc13661f4a9ae5ee4a69b45084a179765af1 Signed-off-by: Andrzej Popowski --- src/iotcon/iotcon_api.js | 28 +++++++++++++++++++++++----- src/iotcon/iotcon_client_manager.cc | 2 +- src/iotcon/iotcon_instance.cc | 2 +- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/iotcon/iotcon_api.js b/src/iotcon/iotcon_api.js index fa5899b..55e19bb 100644 --- a/src/iotcon/iotcon_api.js +++ b/src/iotcon/iotcon_api.js @@ -178,18 +178,36 @@ function DeviceInfo(data) { function IotconOption(id, data) { validator.isConstructorCall(this, tizen.IotconOption); + var _id = 0; + var _data = ''; + Object.defineProperties(this, { id: { - value: id, - writable: false, + get: function() { + return _id; + }, + set: function(v) { + if (v) { + _id = v; + } + }, enumerable: true }, data: { - value: data, - writable: false, + get: function() { + return _data; + }, + set: function(v) { + if (v) { + _data = v; + } + }, enumerable: true } }); + + this["id"] = id; + this["data"] = data; } function PlatformInfo(data) { @@ -1078,7 +1096,7 @@ Server.prototype.createResource = function() { name: 'dictionary', type: types.DICTIONARY, optional: true, - nullable: true + nullable: false }]); var callArgs = args.dictionary || {}; diff --git a/src/iotcon/iotcon_client_manager.cc b/src/iotcon/iotcon_client_manager.cc index 41f9c3b..7ecd9bb 100644 --- a/src/iotcon/iotcon_client_manager.cc +++ b/src/iotcon/iotcon_client_manager.cc @@ -84,7 +84,7 @@ common::TizenResult IotconClientManager::AddPresenceEventListener( presence->id = GetPresenceNextId(); presence_map_.insert(std::make_pair(presence->id, presence)); - return TizenSuccess(); + return result; } common::TizenResult IotconClientManager::RemovePresenceEventListener(long long id) { diff --git a/src/iotcon/iotcon_instance.cc b/src/iotcon/iotcon_instance.cc index 7e7b5fb..29af641 100644 --- a/src/iotcon/iotcon_instance.cc +++ b/src/iotcon/iotcon_instance.cc @@ -85,7 +85,7 @@ const std::string kResult = "result"; const std::string kTimeout = "timeout"; const std::string kData = "data"; -const std::string kVirtualResourcesHandlingPath = "/home/tmp_file_iotcon.dat"; +const std::string kVirtualResourcesHandlingPath = "/home/owner/share/tmp_file_iotcon.dat"; } // namespace -- 2.7.4 From 4975191c4aad30161c89a21b4b0bb92926a81a22 Mon Sep 17 00:00:00 2001 From: Piotr Kosko Date: Mon, 1 Aug 2016 07:44:17 +0200 Subject: [PATCH 06/16] [Iotcon] fixed additional throwing error on getProperty Change-Id: I77fea66d35875cd3d370a33db24b2ecb2223de5e Signed-off-by: Piotr Kosko --- src/iotcon/iotcon_utils.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/iotcon/iotcon_utils.cc b/src/iotcon/iotcon_utils.cc index 4edc261..c167418 100644 --- a/src/iotcon/iotcon_utils.cc +++ b/src/iotcon/iotcon_utils.cc @@ -1767,8 +1767,11 @@ common::TizenResult IotconUtils::PlatformInfoGetProperty(iotcon_platform_info_h auto result = ConvertIotconError(iotcon_platform_info_get_property(platform, property_e, &property)); - if (!result || !property) { + if (!result) { LogAndReturnTizenError(result, ("iotcon_platform_info_get_property() failed")); + } else if (!property) { + // TODO check if it should be an error or rather it should be ignored and used some default value + LogAndReturnTizenError(common::AbortError("iotcon_platform_info_get_property() returned no result")); } out->insert(std::make_pair(name, picojson::value{property})); -- 2.7.4 From fdce93945c9998c69b5d18be4644b02e5fda24b0 Mon Sep 17 00:00:00 2001 From: Andrzej Popowski Date: Mon, 13 Jun 2016 14:48:20 +0200 Subject: [PATCH 07/16] [Content] - The function createThumbnail() implemented Change-Id: I0b3589ea25c87db9b5765f77d0b308dc7b25f9f8 Signed-off-by: Andrzej Popowski --- src/content/content_instance.cc | 23 ++++++++++++++-- src/content/content_instance.h | 1 + src/content/content_manager.cc | 60 +++++++++++++++++++++++++++++++++++++++++ src/content/content_manager.h | 13 ++++++--- src/content/js/manager.js | 26 ++++++++++++++++++ 5 files changed, 117 insertions(+), 6 deletions(-) diff --git a/src/content/content_instance.cc b/src/content/content_instance.cc index 659c4f1..9008f68 100755 --- a/src/content/content_instance.cc +++ b/src/content/content_instance.cc @@ -51,7 +51,7 @@ ContentInstance::ContentInstance() : using std::placeholders::_1; using std::placeholders::_2; - #define REGISTER_SYNC(c,x) \ +#define REGISTER_SYNC(c,x) \ RegisterSyncHandler(c, std::bind(&ContentInstance::x, this, _1, _2)); REGISTER_SYNC("ContentManager_find", ContentManagerFind); @@ -80,7 +80,10 @@ ContentInstance::ContentInstance() : REGISTER_SYNC("ContentPlaylist_getThumbnailUri", PlaylistGetThumbnailUri); REGISTER_SYNC("ContentPlaylist_setThumbnailUri", PlaylistSetThumbnailUri); REGISTER_SYNC("ContentPlaylist_getNumberOfTracks", PlaylistGetNumberOfTracks); - #undef REGISTER_SYNC + REGISTER_SYNC("ContentManager_createThumbnail", ContentManagerCreateThumbnail); +#undef REGISTER_SYNC + + ContentManager::getInstance()->setContentInstance(this); } ContentInstance::~ContentInstance() { @@ -93,6 +96,7 @@ ContentInstance::~ContentInstance() { delete listener_data_; listener_data_ = nullptr; } + ContentManager::getInstance()->setContentInstance(nullptr); } static gboolean CompletedCallback(const std::shared_ptr& user_data) { @@ -593,7 +597,22 @@ void ContentInstance::ContentManagerRemoveplaylist(const picojson::value& args, // implement it common::TaskQueue::GetInstance().Queue(WorkThread, CompletedCallback, cbData); +} + +void ContentInstance::ContentManagerCreateThumbnail(const picojson::value& args, picojson::object& out) { + LoggerD("entered"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeContentWrite, &out); + common::PlatformResult result = common::PlatformResult(common::ErrorCode::NO_ERROR); + if(ContentManager::getInstance()->isConnected()) { + result = ContentManager::getInstance()->createThumbnail(args); + } else { + result = LogAndCreateResult(common::ErrorCode::UNKNOWN_ERR, "DB Connection is failed."); + } + if (!result) { + LogAndReportError(result, &out, ("Failed to create a thumbnail")); + common::Instance::PostMessage(this, picojson::value(out).serialize().c_str()); + } } void ContentInstance::ContentManagerPlaylistAdd(const picojson::value& args, picojson::object& out) { diff --git a/src/content/content_instance.h b/src/content/content_instance.h index 0025d2b..a631e62 100755 --- a/src/content/content_instance.h +++ b/src/content/content_instance.h @@ -84,6 +84,7 @@ class ContentInstance : public common::ParsedInstance { void ContentManagerPlaylistSetorder(const picojson::value& args, picojson::object& out); void ContentManagerPlaylistMove(const picojson::value& args, picojson::object& out); void ContentManagerAudioGetLyrics(const picojson::value& args, picojson::object& out); + void ContentManagerCreateThumbnail(const picojson::value& args, picojson::object& out); void PlaylistGetName(const picojson::value& args, picojson::object& out); void PlaylistSetName(const picojson::value& args, picojson::object& out); diff --git a/src/content/content_manager.cc b/src/content/content_manager.cc index 6aa319d..28140da 100644 --- a/src/content/content_manager.cc +++ b/src/content/content_manager.cc @@ -36,6 +36,7 @@ using namespace std; using namespace common; +using common::tools::ReportSuccess; using common::tools::ReportError; namespace extension { @@ -660,6 +661,31 @@ static bool playlist_content_member_cb(int playlist_member_id, media_info_h medi return true; } +void CreateThumbnailCallback(media_content_error_e err, const char* path, void* user_data) { + LoggerD("Enter"); + + if (!(ContentManager::getInstance()->getContentInstance())) { + // There is not instance already + LoggerD("There is not instance now"); + return; + } + + unsigned int callbackId = (unsigned int) user_data; + picojson::object out; + + out["callbackId"] = picojson::value(static_cast(callbackId)); + + if (MEDIA_CONTENT_ERROR_NONE == err) { + out["result"] = picojson::value(std::string(path)); + ReportSuccess(out); + } else { + PlatformResult result = ContentManager::getInstance()->convertError(err); + LogAndReportError(result, &out, ("Failed to create a thumbnail")); + } + common::Instance::PostMessage(ContentManager::getInstance()->getContentInstance(), + picojson::value(out).serialize().c_str()); +} + ContentManager::ContentManager() { LoggerD("ContentManager called"); @@ -668,6 +694,7 @@ ContentManager::ContentManager() { } else m_dbConnected = false; + m_contentInstance = nullptr; } ContentManager::~ContentManager() { @@ -685,6 +712,16 @@ ContentManager* ContentManager::getInstance() { return &instance; } +ContentInstance* ContentManager::getContentInstance() { + LoggerD("Enter"); + return m_contentInstance; +} + +void ContentManager::setContentInstance(ContentInstance* const content_instance) { + LoggerD("Enter"); + m_contentInstance = content_instance; +} + bool ContentManager::isConnected() { LoggerD("Enter"); return m_dbConnected; @@ -1596,6 +1633,29 @@ int ContentManager::getNumberOfTracks(int id, int* result) { return MEDIA_CONTENT_ERROR_NONE; } +common::PlatformResult ContentManager::createThumbnail(const picojson::value& args) { + LoggerD("Enter"); + + unsigned int callbackId = static_cast(args.get("callbackId").get()); + std::string id = args.get("id").get(); + + media_info_h media = NULL; + int ret = media_info_get_media_from_db(id.c_str(), &media); + if(MEDIA_CONTENT_ERROR_NONE != ret && nullptr == media) { + return LogAndCreateResult(ErrorCode::ABORT_ERR, "Getting media is failed.", + ("Getting media is failed: %d (%s)", ret, get_error_message(ret))); + } + + ret = media_info_create_thumbnail(media, CreateThumbnailCallback, (void*) callbackId); + media_info_destroy(media); + if(MEDIA_CONTENT_ERROR_NONE != ret) { + return LogAndCreateResult(ErrorCode::ABORT_ERR, "Creating thumbnail failed.", + ("Creating thumbnail failed: %d (%s)", ret, get_error_message(ret))); + } + + return PlatformResult(ErrorCode::NO_ERROR); +} + PlatformResult ContentManager::convertError(int err) { char* error_msg = get_error_message(err); switch (err) { diff --git a/src/content/content_manager.h b/src/content/content_manager.h index 36b52d5..60a177f 100644 --- a/src/content/content_manager.h +++ b/src/content/content_manager.h @@ -43,6 +43,8 @@ class ContentManager { virtual ~ContentManager(); bool isConnected(); static ContentManager* getInstance(); + ContentInstance* getContentInstance(); + void setContentInstance(ContentInstance* const content_instance); void getDirectories(const std::shared_ptr& user_data); void find(const std::shared_ptr& user_data); @@ -74,23 +76,26 @@ class ContentManager { void playlistRemovebatch(const std::shared_ptr& user_data); void playlistSetOrder(const std::shared_ptr& user_data); void playlistMove(const std::shared_ptr& user_data); - int getPlaylistName(int id, std::string* result); int setPlaylistName(int id, const std::string& name); - int getThumbnailUri(int id, std::string* result); - int setThumbnailUri(int id, const std::string& thb_uri); - int getNumberOfTracks(int id, int* result); //playlistSetOrder static common::PlatformResult convertError(int err); + +//thumbnail + int getThumbnailUri(int id, std::string* result); + int setThumbnailUri(int id, const std::string& thb_uri); + common::PlatformResult createThumbnail(const picojson::value& args); + private: //int setContent(media_info_h media, picojson::value content); ContentManager(); private: bool m_dbConnected; + ContentInstance* m_contentInstance; }; diff --git a/src/content/js/manager.js b/src/content/js/manager.js index 009156d..00ffadd 100755 --- a/src/content/js/manager.js +++ b/src/content/js/manager.js @@ -371,4 +371,30 @@ ContentManager.prototype.removePlaylist = function(id, successCallback, errorCal } }; +ContentManager.prototype.createThumbnail = function(content, successCallback, errorCallback) { + var args = validator_.validateArgs(arguments, [ + {name: 'content', type: types_.PLATFORM_OBJECT, values: Content}, + {name: 'successCallback', type: types_.FUNCTION}, + {name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true} + ]); + + var data = { + id: args.content.id + }; + + var callback = function(result) { + if (native_.isFailure(result)) { + native_.callIfPossible(args.errorCallback, native_.getErrorObject(result)); + return; + } + args.successCallback(native_.getResultObject(result)); + }; + + var result = native_.call('ContentManager_createThumbnail', data, callback); + + if (native_.isFailure(result)) { + throw native_.getErrorObject(result); + } +}; + exports = new ContentManager(); -- 2.7.4 From 1764dc0d098a070d9266bd942f2801dd72edf1e7 Mon Sep 17 00:00:00 2001 From: Hyunjin Park Date: Tue, 2 Aug 2016 19:19:13 +0900 Subject: [PATCH 08/16] [version] 1.21 Change-Id: I4d40d76270611195168b3d4a126f5ba6335ac8d2 --- packaging/webapi-plugins.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index 0ca2d5c..b0e257b 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -10,7 +10,7 @@ %define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions} Name: webapi-plugins -Version: 1.20 +Version: 1.21 Release: 0 License: Apache-2.0 and BSD-2.0 and MIT Group: Development/Libraries -- 2.7.4 From d7e8268ab691eeab5a4b7b937ad2044e56e3e344 Mon Sep 17 00:00:00 2001 From: Tomasz Marciniak Date: Tue, 2 Aug 2016 14:55:56 +0200 Subject: [PATCH 09/16] [Notification] Fix for push service daemon notifications. [Verification] Code compiles. TCT pass rate 100% Change-Id: If4f3ea10366ad2982bb3f8faa3c01e04563d5e47 Signed-off-by: Tomasz Marciniak --- src/notification/status_notification.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/notification/status_notification.cc b/src/notification/status_notification.cc index 9b03933..cc0e135 100644 --- a/src/notification/status_notification.cc +++ b/src/notification/status_notification.cc @@ -1108,6 +1108,12 @@ PlatformResult StatusNotification::ToJson(int id, GetImage(noti_handle, NOTIFICATION_IMAGE_TYPE_LIST_5, &progress_type); if (status.IsError()) return status; + + //push service daemon doesn't set progress type + //so use default if notification type is different from "PROGRESS" + if ("PROGRESS" != noti_type_str) { + progress_type = progress_type == kProgressTypeByte ? progress_type : kProgressTypePercentage; + } out["progressType"] = picojson::value(progress_type); double progress_value; -- 2.7.4 From abc4ff1f1f363acea109a2536bd40c3f5d371d7d Mon Sep 17 00:00:00 2001 From: Mateusz Bruno-Kaminski Date: Mon, 18 Jul 2016 13:12:10 +0200 Subject: [PATCH 10/16] [API] Logging warnings for deprecated API elements [Details] Added warnings which are logged when deprecated elements are used. Both in C++ and JavaScript. [Verification] Code compiles without errors and warnings shows up for deprecated API elements. Change-Id: I50bb501a5b29bb59d01ac5c0847ea6dac7203a98 Signed-off-by: Mateusz Bruno-Kaminski --- src/application/application_api.js | 6 ++++++ src/application/application_instance.cc | 4 ++++ src/bluetooth/bluetooth_adapter.cc | 2 ++ src/bluetooth/bluetooth_api.js | 3 +++ src/nfc/nfc_api.js | 3 +++ src/nfc/nfc_instance.cc | 3 +++ src/power/power_api.js | 10 +++++++++- src/power/power_instance.cc | 4 ++++ src/power/power_manager.cc | 15 ++++++++++++++- src/push/push_api.js | 4 ++-- src/systeminfo/systeminfo_api.js | 2 ++ src/systeminfo/systeminfo_instance.cc | 2 ++ src/time/time_api.js | 2 ++ src/time/time_instance.cc | 2 ++ 14 files changed, 58 insertions(+), 4 deletions(-) diff --git a/src/application/application_api.js b/src/application/application_api.js index 7b42f15..77805ef 100755 --- a/src/application/application_api.js +++ b/src/application/application_api.js @@ -564,6 +564,9 @@ var APPLICATION_EVENT_LISTENER = 'ApplicationEventListener'; var applicationEventListener = new ListenerManager(native, APPLICATION_EVENT_LISTENER); ApplicationManager.prototype.addAppInfoEventListener = function() { + console.warn('DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. ' + + 'Use tizen.package.setPackageInfoEventListener() instead.'); + var args = AV.validateMethod(arguments, [ { name : 'eventCallback', @@ -576,6 +579,9 @@ ApplicationManager.prototype.addAppInfoEventListener = function() { }; ApplicationManager.prototype.removeAppInfoEventListener = function() { + console.warn('DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from next release. ' + + 'Use tizen.package.unsetPackageInfoEventListener() instead.'); + var args = AV.validateMethod(arguments, [ { name : 'watchId', diff --git a/src/application/application_instance.cc b/src/application/application_instance.cc index 67ff539..cb8d850 100755 --- a/src/application/application_instance.cc +++ b/src/application/application_instance.cc @@ -159,12 +159,16 @@ void ApplicationInstance::GetAppMetaData(const picojson::value& args, picojson:: void ApplicationInstance::AddAppInfoEventListener(const picojson::value& args, picojson::object& out) { LoggerD("Entered"); + LoggerW("DEPRECATION WARNING: addAppInfoEventListener() is deprecated and will be removed from next release. " + "Use tizen.package.setPackageInfoEventListener() instead."); manager_.StartAppInfoEventListener(&out); } void ApplicationInstance::RemoveAppInfoEventListener(const picojson::value& args, picojson::object& out) { LoggerD("Entered"); + LoggerW("DEPRECATION WARNING: removeAppInfoEventListener() is deprecated and will be removed from next release. " + "Use tizen.package.unsetPackageInfoEventListener() instead."); manager_.StopAppInfoEventListener(); ReportSuccess(out); diff --git a/src/bluetooth/bluetooth_adapter.cc b/src/bluetooth/bluetooth_adapter.cc index e4283d6..396211d 100755 --- a/src/bluetooth/bluetooth_adapter.cc +++ b/src/bluetooth/bluetooth_adapter.cc @@ -516,6 +516,8 @@ void BluetoothAdapter::SetName(const picojson::value& data, picojson::object& ou void BluetoothAdapter::SetPowered(const picojson::value& data, picojson::object& out) { LoggerD("Entered"); + LoggerW("DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. " + "Let the user turn on/off Bluetooth through the Settings application instead."); CHECK_BACKWARD_COMPABILITY_PRIVILEGE_ACCESS(Privilege::kBluetooth, Privilege::kBluetoothAdmin, &out); diff --git a/src/bluetooth/bluetooth_api.js b/src/bluetooth/bluetooth_api.js index 06c5fe9..c1c1864 100755 --- a/src/bluetooth/bluetooth_api.js +++ b/src/bluetooth/bluetooth_api.js @@ -2030,6 +2030,9 @@ BluetoothAdapter.prototype.setName = function() { BluetoothAdapter.prototype.setPowered = function() { console.log('Entered BluetoothAdapter.setPowered()'); + console.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. ' + + 'Let the user turn on/off Bluetooth through the Settings application instead.'); + var args = AV.validateMethod(arguments, [ { name : 'powered', diff --git a/src/nfc/nfc_api.js b/src/nfc/nfc_api.js index 641a4ee..3954049 100644 --- a/src/nfc/nfc_api.js +++ b/src/nfc/nfc_api.js @@ -272,6 +272,9 @@ function NFCAdapter() { } NFCAdapter.prototype.setPowered = function() { + console.warn('DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let the user turn NFC on/off ' + + 'through the Settings application instead.'); + var args = validator_.validateArgs(arguments, [ { name: 'powered', diff --git a/src/nfc/nfc_instance.cc b/src/nfc/nfc_instance.cc index 781f90e..4c0b50e 100644 --- a/src/nfc/nfc_instance.cc +++ b/src/nfc/nfc_instance.cc @@ -205,6 +205,9 @@ void NFCInstance::SetExclusiveMode( void NFCInstance::SetPowered( const picojson::value& args, picojson::object& out) { LoggerD("Entered"); + LoggerW("DEPRECATION WARNING: setPowered() is deprecated and will be removed from next release. Let the user turn NFC on/off " + "through the Settings application instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegeNfcAdmin, &out); PlatformResult result = NFCAdapter::GetInstance()->SetPowered(args); diff --git a/src/power/power_api.js b/src/power/power_api.js index 96c75f0..5be1026 100755 --- a/src/power/power_api.js +++ b/src/power/power_api.js @@ -120,11 +120,15 @@ function PowerManager() { * is desired to be. */ PowerManager.prototype.request = function(resource, state) { - var args = validator_.validateArgs(arguments, [ + var args = validator_.validateArgs(arguments, [ {'name' : 'resource', 'type': types_.ENUM, 'values' : ['SCREEN', 'CPU']}, {'name' : 'state', 'type': types_.ENUM, 'values' : ['SCREEN_OFF', 'SCREEN_DIM', 'SCREEN_NORMAL', 'SCREEN_BRIGHT', 'CPU_AWAKE']} ]); + if (args['state'] && args.state === PowerScreenState['SCREEN_BRIGHT']) { + console.warn('DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release.'); + } + var nativeParam = { }; @@ -273,6 +277,8 @@ PowerManager.prototype.restoreScreenBrightness = function() { * Turns on the screen. */ PowerManager.prototype.turnScreenOn = function() { + console.warn('DEPRECATION WARNING: turnScreenOn() is deprecated and will be removed from next release. Use request() instead.'); + var nativeParam = { }; @@ -288,6 +294,8 @@ PowerManager.prototype.turnScreenOn = function() { * Turns off the screen. */ PowerManager.prototype.turnScreenOff = function() { + console.warn('DEPRECATION WARNING: turnScreenOff() is deprecated and will be removed from next release. Use release() instead.'); + var nativeParam = { }; diff --git a/src/power/power_instance.cc b/src/power/power_instance.cc index a4b566d..8296123 100755 --- a/src/power/power_instance.cc +++ b/src/power/power_instance.cc @@ -173,6 +173,8 @@ void PowerInstance::PowerManagerRestorescreenbrightness(const picojson::value& a void PowerInstance::PowerManagerTurnscreenon(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + LoggerW("DEPRECATION WARNING: turnScreenOn() is deprecated and will be removed from next release. Use request() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegePower, &out); PlatformResult result = PowerManager::GetInstance()->SetScreenState(true); @@ -184,6 +186,8 @@ void PowerInstance::PowerManagerTurnscreenon(const picojson::value& args, picojs void PowerInstance::PowerManagerTurnscreenoff(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + LoggerW("DEPRECATION WARNING: turnScreenOff() is deprecated and will be removed from next release. Use release() instead."); + CHECK_PRIVILEGE_ACCESS(kPrivilegePower, &out); PlatformResult result = PowerManager::GetInstance()->SetScreenState(false); diff --git a/src/power/power_manager.cc b/src/power/power_manager.cc index 865dca4..4bde5f6 100644 --- a/src/power/power_manager.cc +++ b/src/power/power_manager.cc @@ -102,6 +102,12 @@ void PowerManager::OnPlatformStateChangedCB(device_callback_e type, void* value, switch (state) { case DISPLAY_STATE_NORMAL : current = object->bright_state_enabled_ ? POWER_STATE_SCREEN_BRIGHT : POWER_STATE_SCREEN_NORMAL; + + // TODO: Remove log along with removal of deprecation power state + if (POWER_STATE_SCREEN_BRIGHT == current) { + LoggerW("DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release."); + } + break; case DISPLAY_STATE_SCREEN_DIM : current = POWER_STATE_SCREEN_DIM; @@ -187,6 +193,8 @@ PlatformResult PowerManager::Request(PowerResource resource, PowerState state) { } case POWER_STATE_SCREEN_BRIGHT: { + LoggerW("DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release."); + int max_brightness; ret = device_display_get_max_brightness(0, &max_brightness); if (DEVICE_ERROR_NONE != ret) { @@ -220,8 +228,11 @@ PlatformResult PowerManager::Request(PowerResource resource, PowerState state) { ret = device_display_get_state(&platform_state); if (DEVICE_ERROR_NONE != ret) LoggerE("device_display_get_state failed (%d)", ret); - if (platform_state == DISPLAY_STATE_NORMAL) + if (DISPLAY_STATE_NORMAL == platform_state) { + // TODO: Remove log along with removal of deprecation power state + LoggerW("DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release."); BroadcastScreenState(POWER_STATE_SCREEN_BRIGHT); + } break; } case POWER_STATE_SCREEN_OFF: @@ -392,6 +403,8 @@ PlatformResult PowerManager::SetPlatformBrightness(int brightness) { should_be_read_from_cache_ = true; return PlatformResult(ErrorCode::NO_ERROR); } else if (current_state_ == POWER_STATE_SCREEN_BRIGHT) { + LoggerW("DEPRECATION WARNING: SCREEN_BRIGHT is deprecated and will be removed from next release."); + current_brightness_ = brightness; LoggerD("Current state is not normal state the value is saved in cache: %d", brightness); should_be_read_from_cache_ = true; diff --git a/src/push/push_api.js b/src/push/push_api.js index afa1378..e415131 100644 --- a/src/push/push_api.js +++ b/src/push/push_api.js @@ -56,7 +56,7 @@ PushManager.prototype.registerService = function() { values: tizen.ApplicationControl } ]); - console.warn('Method registerService() is deprecated, use register() instead.'); + console.warn('DEPRECATION WARNING: registerService() is deprecated and will be removed from next release. Use register() instead.'); this.register.apply(this, Array.prototype.slice.call(arguments, 1)); }; @@ -89,7 +89,7 @@ PushManager.prototype.register = function() { }; PushManager.prototype.unregisterService = function() { - console.warn('Method unregisterService() is deprecated, use unregister() instead.'); + console.warn('DEPRECATION WARNING: unregisterService() is deprecated and will be removed from next release. Use unregister() instead.'); this.unregister.apply(this, arguments); }; diff --git a/src/systeminfo/systeminfo_api.js b/src/systeminfo/systeminfo_api.js index 7fae0c7..dad6383 100644 --- a/src/systeminfo/systeminfo_api.js +++ b/src/systeminfo/systeminfo_api.js @@ -729,6 +729,8 @@ var SystemInfo = function() { }; SystemInfo.prototype.getCapabilities = function() { + console.warn('DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. Use getCapability() instead.'); + var result = native_.callSync('SystemInfo_getCapabilities', {}); if (native_.isFailure(result)) { throw native_.getErrorObject(result); diff --git a/src/systeminfo/systeminfo_instance.cc b/src/systeminfo/systeminfo_instance.cc index 8f6ad50..15961ec 100644 --- a/src/systeminfo/systeminfo_instance.cc +++ b/src/systeminfo/systeminfo_instance.cc @@ -81,6 +81,8 @@ SysteminfoInstance::~SysteminfoInstance() { void SysteminfoInstance::GetCapabilities(const picojson::value& args, picojson::object& out) { LoggerD("Enter"); + LoggerW("DEPRECATION WARNING: getCapabilities() is deprecated and will be removed from next release. Use getCapability() instead."); + manager_.GetCapabilities(args, &out); } diff --git a/src/time/time_api.js b/src/time/time_api.js index ea6962b..67ae674 100644 --- a/src/time/time_api.js +++ b/src/time/time_api.js @@ -533,6 +533,8 @@ tizen.TZDate.prototype.toString = function() { tizen.TZDate.prototype.getTimezoneAbbreviation = function() { console.log('Entered TZDate.getTimezoneAbbreviation'); + console.warn('DEPRECATION WARNING: getTimezoneAbbreviation() is deprecated and will be removed from next release.'); + var result = native_.callSync('TZDate_getTimezoneAbbreviation', {timezone: String(this._timezoneName), timestamp: String(this._utcTimestamp)}); diff --git a/src/time/time_instance.cc b/src/time/time_instance.cc index c6e9cf2..1e63ece 100644 --- a/src/time/time_instance.cc +++ b/src/time/time_instance.cc @@ -256,6 +256,8 @@ void TimeInstance::TZDate_toString(const picojson::value& args, picojson::object void TimeInstance::TZDate_getTimezoneAbbreviation(const picojson::value& args, picojson::object& out) { LoggerD("Entered"); + LoggerW("DEPRECATION WARNING: getTimezoneAbbreviation() is deprecated and will be removed from next release."); + if (!args.contains("timezone") || !args.contains("timestamp")) { LogAndReportError(PlatformResult(ErrorCode::INVALID_VALUES_ERR, "Invalid parameter passed."), &out, ("Required parameters are missing: \"timezone\", \"timestamp\"")); -- 2.7.4 From 5482ae778f8b3882d4202f3bb094e9ff191a6af1 Mon Sep 17 00:00:00 2001 From: Hyunjin Park Date: Mon, 8 Aug 2016 10:15:02 +0900 Subject: [PATCH 11/16] [version] 1.22 Change-Id: I669b84037a7cd0271a540c6da8b4ce38aa6da15c --- packaging/webapi-plugins.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index b0e257b..c54ace0 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -10,7 +10,7 @@ %define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions} Name: webapi-plugins -Version: 1.21 +Version: 1.22 Release: 0 License: Apache-2.0 and BSD-2.0 and MIT Group: Development/Libraries -- 2.7.4 From c58da703dfe8e54d5fb8b7c3689b822f5a076835 Mon Sep 17 00:00:00 2001 From: Andrzej Popowski Date: Mon, 8 Aug 2016 13:25:23 +0200 Subject: [PATCH 12/16] [Content] - fixing createThumbnail() function Change-Id: I834dc5a5b427b0cc50e48d14b13aed9b84965ae8 Signed-off-by: Andrzej Popowski --- src/content/content_manager.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/content/content_manager.cc b/src/content/content_manager.cc index 28140da..2673604 100644 --- a/src/content/content_manager.cc +++ b/src/content/content_manager.cc @@ -664,16 +664,18 @@ static bool playlist_content_member_cb(int playlist_member_id, media_info_h medi void CreateThumbnailCallback(media_content_error_e err, const char* path, void* user_data) { LoggerD("Enter"); + unsigned int* callbackId = (unsigned int*) user_data; + if (!(ContentManager::getInstance()->getContentInstance())) { // There is not instance already LoggerD("There is not instance now"); + delete callbackId; return; } - unsigned int callbackId = (unsigned int) user_data; picojson::object out; - out["callbackId"] = picojson::value(static_cast(callbackId)); + out["callbackId"] = picojson::value(static_cast(*callbackId)); if (MEDIA_CONTENT_ERROR_NONE == err) { out["result"] = picojson::value(std::string(path)); @@ -682,6 +684,8 @@ void CreateThumbnailCallback(media_content_error_e err, const char* path, void* PlatformResult result = ContentManager::getInstance()->convertError(err); LogAndReportError(result, &out, ("Failed to create a thumbnail")); } + + delete callbackId; common::Instance::PostMessage(ContentManager::getInstance()->getContentInstance(), picojson::value(out).serialize().c_str()); } @@ -1636,23 +1640,27 @@ int ContentManager::getNumberOfTracks(int id, int* result) { common::PlatformResult ContentManager::createThumbnail(const picojson::value& args) { LoggerD("Enter"); - unsigned int callbackId = static_cast(args.get("callbackId").get()); + unsigned int* callbackId = new unsigned int(static_cast(args.get("callbackId").get())); std::string id = args.get("id").get(); media_info_h media = NULL; int ret = media_info_get_media_from_db(id.c_str(), &media); if(MEDIA_CONTENT_ERROR_NONE != ret && nullptr == media) { + delete callbackId; return LogAndCreateResult(ErrorCode::ABORT_ERR, "Getting media is failed.", ("Getting media is failed: %d (%s)", ret, get_error_message(ret))); } - ret = media_info_create_thumbnail(media, CreateThumbnailCallback, (void*) callbackId); + ret = media_info_create_thumbnail(media, CreateThumbnailCallback, /* (void*) callbackId */ nullptr); media_info_destroy(media); if(MEDIA_CONTENT_ERROR_NONE != ret) { + delete callbackId; return LogAndCreateResult(ErrorCode::ABORT_ERR, "Creating thumbnail failed.", ("Creating thumbnail failed: %d (%s)", ret, get_error_message(ret))); } + delete callbackId; + return PlatformResult(ErrorCode::NO_ERROR); } -- 2.7.4 From 0574d8acee1ce5b2d2e13b178dd1cc7c0c754084 Mon Sep 17 00:00:00 2001 From: Hyunjin Park Date: Wed, 10 Aug 2016 07:47:11 +0900 Subject: [PATCH 13/16] [common] apply changed deviced interface [verification] filesystem/systeminfo TC are passed Change-Id: I68c00e2ea569251a772a87af2c33cd29e9a98b67 --- src/common/filesystem/filesystem_provider_deviced.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/filesystem/filesystem_provider_deviced.cc b/src/common/filesystem/filesystem_provider_deviced.cc index 3c22667..e8613a8 100644 --- a/src/common/filesystem/filesystem_provider_deviced.cc +++ b/src/common/filesystem/filesystem_provider_deviced.cc @@ -29,7 +29,7 @@ namespace { static const char* kBus = "org.tizen.system.storage"; -static const char* kBlockIface = "org.tizen.system.storage.Block"; +static const char* kBlockIface = "org.tizen.system.storage.BlockManager"; static const char* kBlackManagerIface = "org.tizen.system.storage.BlockManager"; static const char* kPath = "/Org/Tizen/System/Storage/Block/Manager"; static const char* kDeviceChangedMethod = "DeviceChanged"; -- 2.7.4 From c0b60f0abc8d108fab6e6be0d4f68c0b250945f5 Mon Sep 17 00:00:00 2001 From: Hyunjin Park Date: Wed, 10 Aug 2016 16:12:20 +0900 Subject: [PATCH 14/16] [version] 1.23 Change-Id: I08bdd950d48da08b76c28768ace04c8404dcd7a6 --- packaging/webapi-plugins.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index c54ace0..eb12889 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -10,7 +10,7 @@ %define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions} Name: webapi-plugins -Version: 1.22 +Version: 1.23 Release: 0 License: Apache-2.0 and BSD-2.0 and MIT Group: Development/Libraries -- 2.7.4 From 78ab25f63f094d4b623ebc3fdf3e46672e2551d6 Mon Sep 17 00:00:00 2001 From: Jakub Skowron Date: Tue, 30 Aug 2016 18:39:00 +0200 Subject: [PATCH 15/16] [SystemInfo] Replace deprecated native wifi API with wifi-manager API Using wifi-manager.h instead of wifi.h Verification: TCT systeminfo tests 100% PASS Change-Id: I8a98da28b9bcffe151dac214d51cb56b04d6c4a4 Signed-off-by: Jakub Skowron --- packaging/webapi-plugins.spec | 2 +- src/systeminfo/systeminfo.gyp | 2 +- src/systeminfo/systeminfo_manager.cc | 25 +++--- src/systeminfo/systeminfo_manager.h | 9 +- src/systeminfo/systeminfo_properties_manager.cc | 107 +++++++++++++----------- 5 files changed, 77 insertions(+), 68 deletions(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index eb12889..a973669 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -359,7 +359,7 @@ BuildRequires: pkgconfig(capi-network-connection) BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(capi-system-system-settings) BuildRequires: pkgconfig(capi-network-bluetooth) -BuildRequires: pkgconfig(capi-network-wifi) +BuildRequires: pkgconfig(capi-network-wifi-manager) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(libpcrecpp) BuildRequires: pkgconfig(capi-appfw-application) diff --git a/src/systeminfo/systeminfo.gyp b/src/systeminfo/systeminfo.gyp index 618754a..ae9d39f 100644 --- a/src/systeminfo/systeminfo.gyp +++ b/src/systeminfo/systeminfo.gyp @@ -40,7 +40,7 @@ 'capi-network-connection', 'capi-system-device', 'capi-system-system-settings', - 'capi-network-wifi', + 'capi-network-wifi-manager', 'libtzplatform-config', 'tapi', 'sensor', diff --git a/src/systeminfo/systeminfo_manager.cc b/src/systeminfo/systeminfo_manager.cc index e9272fe..c370439 100644 --- a/src/systeminfo/systeminfo_manager.cc +++ b/src/systeminfo/systeminfo_manager.cc @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include "common/converter.h" #include "common/logger.h" @@ -224,7 +224,7 @@ static void OnBrightnessChangedCb(device_callback_e type, void* value, void* use } } -static void OnWifiLevelChangedCb (wifi_rssi_level_e rssi_level, void *user_data) { +static void OnWifiLevelChangedCb (wifi_manager_rssi_level_e rssi_level, void *user_data) { LoggerD("Entered"); LoggerD("Level %d", rssi_level); SysteminfoManager* manager = static_cast(user_data); @@ -460,7 +460,7 @@ SysteminfoManager::SysteminfoManager(SysteminfoInstance* instance) : instance_(instance), prop_manager_(*this), sensor_handle_(-1), - wifi_level_(WIFI_RSSI_LEVEL_0), + wifi_level_(WIFI_MANAGER_RSSI_LEVEL_0), cpu_load_(0), last_cpu_load_(0), available_capacity_internal_(0), @@ -473,16 +473,16 @@ SysteminfoManager::SysteminfoManager(SysteminfoInstance* instance) connection_handle_(nullptr), async_op_(new AsynchronousOperation()) { LoggerD("Entered"); - int error = wifi_initialize(); - if (WIFI_ERROR_NONE != error) { + int error = wifi_manager_initialize(&this->wifi_manager_handle_); + if (WIFI_MANAGER_ERROR_NONE != error) { std::string log_msg = "Initialize failed: " + std::string(get_error_message(error)); LoggerE("%s", log_msg.c_str()); } else { - LoggerD("WIFI initialization succeed"); + LoggerD("WIFI Manager initialization succeed"); } - error = wifi_set_rssi_level_changed_cb(OnWifiLevelChangedCb, this); - if (WIFI_ERROR_NONE != error) { + error = wifi_manager_set_rssi_level_changed_cb(this->wifi_manager_handle_, OnWifiLevelChangedCb, this); + if (WIFI_MANAGER_ERROR_NONE != error) { std::string log_msg = "Setting wifi listener failed: " + std::string(get_error_message(error)); LoggerE("%s", log_msg.c_str()); @@ -514,7 +514,10 @@ SysteminfoManager::~SysteminfoManager() { connection_destroy(connection_handle_); } - wifi_deinitialize(); + auto error = wifi_manager_deinitialize(this->wifi_manager_handle_); + if (WIFI_MANAGER_ERROR_NONE != error) { + LoggerE( "wifi_manager_deinitialize failed: %s", get_error_message(error) ); + } } void SysteminfoManager::GetCapabilities(const picojson::value& args, picojson::object* out) { @@ -1369,12 +1372,12 @@ PlatformResult SysteminfoManager::GetPropertyCount(const std::string& property, return PlatformResult(ErrorCode::NO_ERROR); } -wifi_rssi_level_e SysteminfoManager::GetWifiLevel() { +wifi_manager_rssi_level_e SysteminfoManager::GetWifiLevel() { LoggerD("Enter"); return wifi_level_; } -void SysteminfoManager::SetWifiLevel(wifi_rssi_level_e level) { +void SysteminfoManager::SetWifiLevel(wifi_manager_rssi_level_e level) { LoggerD("Entered"); wifi_level_ = level; } diff --git a/src/systeminfo/systeminfo_manager.h b/src/systeminfo/systeminfo_manager.h index c34dd4e..69cdc0c 100644 --- a/src/systeminfo/systeminfo_manager.h +++ b/src/systeminfo/systeminfo_manager.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include "common/picojson.h" #include "common/platform_result.h" @@ -53,8 +53,8 @@ class SysteminfoManager { void GetCount(const picojson::value& args, picojson::object* out); common::PlatformResult GetPropertyCount(const std::string& property, unsigned long* count); - wifi_rssi_level_e GetWifiLevel(); - void SetWifiLevel(wifi_rssi_level_e level); + wifi_manager_rssi_level_e GetWifiLevel(); + void SetWifiLevel(wifi_manager_rssi_level_e level); int GetSensorHandle(); int GetChangedTapiIndex(TapiHandle* tapi); @@ -133,7 +133,8 @@ class SysteminfoManager { std::mutex sensor_mutex_; std::vector camera_types_; - wifi_rssi_level_e wifi_level_; + wifi_manager_rssi_level_e wifi_level_; + wifi_manager_h wifi_manager_handle_; double cpu_load_; double last_cpu_load_; unsigned long long available_capacity_internal_; diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc index 33b639d..6acf54f 100644 --- a/src/systeminfo/systeminfo_properties_manager.cc +++ b/src/systeminfo/systeminfo_properties_manager.cc @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -587,28 +588,28 @@ PlatformResult SysteminfoPropertiesManager::ReportNetwork(picojson::object* out, } /// WIFI_NETWORK -static PlatformResult GetIpsWifi(wifi_ap_h wifi_ap_handle, std::string* ip_addr_str, +static PlatformResult GetIpsWifi(wifi_manager_ap_h wifi_ap_handle, std::string* ip_addr_str, std::string* ipv6_addr_str) { LoggerD("Entered"); //getting ipv4 address char* ip_addr = nullptr; - int error = wifi_ap_get_ip_address(wifi_ap_handle, - WIFI_ADDRESS_FAMILY_IPV4, + int error = wifi_manager_ap_get_ip_address(wifi_ap_handle, + WIFI_MANAGER_ADDRESS_FAMILY_IPV4, &ip_addr); - if (WIFI_ERROR_NONE != error) { + if (WIFI_MANAGER_ERROR_NONE != error) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Cannot get ip address", - ("wifi_ap_get_ip_address error: %d (%s)", error, get_error_message(error))); + ("wifi_manager_ap_get_ip_address error: %d (%s)", error, get_error_message(error))); } *ip_addr_str = ip_addr; free(ip_addr); //getting ipv6 address ip_addr = nullptr; - error = wifi_ap_get_ip_address(wifi_ap_handle, - WIFI_ADDRESS_FAMILY_IPV6, + error = wifi_manager_ap_get_ip_address(wifi_ap_handle, + WIFI_MANAGER_ADDRESS_FAMILY_IPV6, &ip_addr); - if (WIFI_ERROR_NONE != error) { + if (WIFI_MANAGER_ERROR_NONE != error) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Cannot get ipv6 address", ("Failed to get ipv6 address: %d (%s)", error, get_error_message(error))); @@ -655,69 +656,73 @@ static PlatformResult GetIpsFromProfile(connection_profile_h profile_handle, std PlatformResult SysteminfoPropertiesManager::ReportWifiNetwork(picojson::object* out) { LoggerD("Entered"); - bool result_status = false; std::string result_ssid; std::string result_ip_address; std::string result_ipv6_address; std::string result_mac_address; double result_signal_strength = 0; - // wifi_initialize() must be called in each thread - int error = wifi_initialize(); - if (WIFI_ERROR_NONE != error) { + // wifi_manager_initialize() must be called in each thread + wifi_manager_h wifi_manager_handle; + int error = wifi_manager_initialize(&wifi_manager_handle); + if (WIFI_MANAGER_ERROR_NONE != error) { std::string log_msg = "Initialize failed: " + std::string(get_error_message(error)); return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, log_msg, - ("wifi_initialize error: %d (%s)", error, get_error_message(error))); - } else { - LoggerD("WIFI initialization succeed"); + ("wifi_manager_initialize error: %d (%s)", error, get_error_message(error))); } + LoggerD("WIFI initialization succeed"); SCOPE_EXIT { - wifi_deinitialize(); + auto error = wifi_manager_deinitialize(wifi_manager_handle); + if (WIFI_MANAGER_ERROR_NONE != error) { + LoggerE( "wifi_manager_deinitialize failed: %s", get_error_message(error) ); + } }; // check if wifi activated bool activated = false; - error = wifi_is_activated(&activated); - if (WIFI_ERROR_NONE != error) { + error = wifi_manager_is_activated(wifi_manager_handle, &activated); + if (WIFI_MANAGER_ERROR_NONE != error) { std::string log_msg = "Checking if wifi is activated failed: " + std::string(get_error_message(error)); return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, log_msg, ("wifi_is_activated error: %d (%s)", error, get_error_message(error))); - } else { - LoggerD("WIFI activated check succeed"); } + LoggerD("WIFI activated check succeed"); - wifi_ap_h wifi_ap_handle = nullptr; + wifi_manager_ap_h wifi_ap_handle = nullptr; + bool result_status = false; if (activated) { LoggerD("Wifi is activated"); - error = wifi_get_connected_ap(&wifi_ap_handle); - if (WIFI_ERROR_NONE != error) { - LoggerD("Error while wifi_get_connnected_ap: %s", get_error_message(error)); - // in case of no connection, ignore error and leave status as false - if (WIFI_ERROR_NO_CONNECTION != error) { - std::string log_msg = "Cannot get connected access point handle: " + - std::string(get_error_message(error)); + error = wifi_manager_get_connected_ap(wifi_manager_handle, &wifi_ap_handle); + switch (error) { + case WIFI_MANAGER_ERROR_NONE: + //if getting connected AP succeed, set status on true + result_status = true; + break; + case WIFI_MANAGER_ERROR_NO_CONNECTION: + LoggerD("No connection while wifi_manager_get_connected_ap: %s", get_error_message(error)); + // in case of no connection, ignore error and leave status as false + break; + default: + // other error + std::string log_msg = "Cannot get connected access point handle: " + std::string(get_error_message(error)); return LogAndCreateResult( - ErrorCode::UNKNOWN_ERR, log_msg, - ("wifi_get_connected_ap error: %d (%s)", error, get_error_message(error))); - } - } else { - //if getting connected AP succeed, set status on true - result_status = true; + ErrorCode::UNKNOWN_ERR, log_msg, + ("wifi_manager_get_connected_ap error: %d (%s)", error, get_error_message(error))); } } if (result_status) { - std::unique_ptr::type, int(*)(wifi_ap_h)> - wifi_ap_handle_ptr(wifi_ap_handle, &wifi_ap_destroy); - // automatically release the memory + std::unique_ptr::type, int(*)(wifi_manager_ap_h)> + wifi_ap_handle_ptr{wifi_ap_handle, &wifi_manager_ap_destroy}; + // automatically release the memory //gathering mac address char* mac = nullptr; - error = wifi_get_mac_address(&mac); - if (WIFI_ERROR_NONE == error && nullptr != mac) { + error = wifi_manager_get_mac_address(wifi_manager_handle, &mac); + if (WIFI_MANAGER_ERROR_NONE == error && nullptr != mac) { SLoggerD("MAC address fetched: %s", mac); result_mac_address = mac; free(mac); @@ -725,12 +730,12 @@ PlatformResult SysteminfoPropertiesManager::ReportWifiNetwork(picojson::object* std::string log_msg = "Failed to get mac address: " + std::string(get_error_message(error)); return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, log_msg, - ("wifi_get_mac_address error: %d (%s)", error, get_error_message(error))); + ("wifi_manager_get_mac_address error: %d (%s)", error, get_error_message(error))); } //refreshing access point information - error = wifi_ap_refresh(wifi_ap_handle); - if (WIFI_ERROR_NONE != error) { + error = wifi_manager_ap_refresh(wifi_ap_handle); + if (WIFI_MANAGER_ERROR_NONE != error) { std::string log_msg = "Failed to refresh access point information: " + std::string(get_error_message(error)); return LogAndCreateResult( @@ -740,8 +745,8 @@ PlatformResult SysteminfoPropertiesManager::ReportWifiNetwork(picojson::object* //gathering ssid char* essid = nullptr; - error = wifi_ap_get_essid(wifi_ap_handle, &essid); - if (WIFI_ERROR_NONE == error) { + error = wifi_manager_ap_get_essid(wifi_ap_handle, &essid); + if (WIFI_MANAGER_ERROR_NONE == error) { result_ssid = essid; free(essid); } else { @@ -751,30 +756,30 @@ PlatformResult SysteminfoPropertiesManager::ReportWifiNetwork(picojson::object* ("wifi_ap_get_essid error: %d (%s)", error, get_error_message(error))); } - //gathering ips + //gathering IPs PlatformResult ret = GetIpsWifi(wifi_ap_handle, &result_ip_address, &result_ipv6_address); if (ret.IsError()) { return ret; } //gathering strength - wifi_rssi_level_e rssi_level = manager_.GetWifiLevel(); + wifi_manager_rssi_level_e rssi_level = manager_.GetWifiLevel(); // this mean that level was not initialized or wifi not connected - if (WIFI_RSSI_LEVEL_0 == rssi_level) { + if (WIFI_MANAGER_RSSI_LEVEL_0 == rssi_level) { // so try to gather rssi level with dedicated function int rssi = 0; - error = wifi_ap_get_rssi(wifi_ap_handle, &rssi); - if (WIFI_ERROR_NONE == error) { + error = wifi_manager_ap_get_rssi(wifi_ap_handle, &rssi); + if (WIFI_MANAGER_ERROR_NONE == error) { result_signal_strength = ((double) abs(rssi))/kWifiSignalStrengthDivideValue; } else { std::string log_msg = "Failed to get signal strength: " + std::string(get_error_message(error)); return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, log_msg, - ("wifi_ap_get_rssi error: %d (%s)", error, get_error_message(error))); + ("wifi_manager_ap_get_rssi error: %d (%s)", error, get_error_message(error))); } } else { - result_signal_strength = ((double) rssi_level)/WIFI_RSSI_LEVEL_4; + result_signal_strength = ((double) rssi_level)/WIFI_MANAGER_RSSI_LEVEL_4; } } //building result object -- 2.7.4 From e3903aaeaef483a8ba85360c1778e8b97b4114d2 Mon Sep 17 00:00:00 2001 From: Hyunjin Park Date: Wed, 7 Sep 2016 19:42:31 -0700 Subject: [PATCH 16/16] Revert "[SystemInfo] Replace deprecated native wifi API with wifi-manager API" This reverts commit 78ab25f63f094d4b623ebc3fdf3e46672e2551d6. Change-Id: Ie7634797434f39ef968dfbc775895e7d480b0cb5 --- packaging/webapi-plugins.spec | 2 +- src/systeminfo/systeminfo.gyp | 2 +- src/systeminfo/systeminfo_manager.cc | 25 +++--- src/systeminfo/systeminfo_manager.h | 9 +- src/systeminfo/systeminfo_properties_manager.cc | 107 +++++++++++------------- 5 files changed, 68 insertions(+), 77 deletions(-) diff --git a/packaging/webapi-plugins.spec b/packaging/webapi-plugins.spec index a973669..eb12889 100644 --- a/packaging/webapi-plugins.spec +++ b/packaging/webapi-plugins.spec @@ -359,7 +359,7 @@ BuildRequires: pkgconfig(capi-network-connection) BuildRequires: pkgconfig(capi-system-device) BuildRequires: pkgconfig(capi-system-system-settings) BuildRequires: pkgconfig(capi-network-bluetooth) -BuildRequires: pkgconfig(capi-network-wifi-manager) +BuildRequires: pkgconfig(capi-network-wifi) BuildRequires: pkgconfig(tapi) BuildRequires: pkgconfig(libpcrecpp) BuildRequires: pkgconfig(capi-appfw-application) diff --git a/src/systeminfo/systeminfo.gyp b/src/systeminfo/systeminfo.gyp index ae9d39f..618754a 100644 --- a/src/systeminfo/systeminfo.gyp +++ b/src/systeminfo/systeminfo.gyp @@ -40,7 +40,7 @@ 'capi-network-connection', 'capi-system-device', 'capi-system-system-settings', - 'capi-network-wifi-manager', + 'capi-network-wifi', 'libtzplatform-config', 'tapi', 'sensor', diff --git a/src/systeminfo/systeminfo_manager.cc b/src/systeminfo/systeminfo_manager.cc index c370439..e9272fe 100644 --- a/src/systeminfo/systeminfo_manager.cc +++ b/src/systeminfo/systeminfo_manager.cc @@ -24,7 +24,7 @@ #include #include #include -#include +#include #include "common/converter.h" #include "common/logger.h" @@ -224,7 +224,7 @@ static void OnBrightnessChangedCb(device_callback_e type, void* value, void* use } } -static void OnWifiLevelChangedCb (wifi_manager_rssi_level_e rssi_level, void *user_data) { +static void OnWifiLevelChangedCb (wifi_rssi_level_e rssi_level, void *user_data) { LoggerD("Entered"); LoggerD("Level %d", rssi_level); SysteminfoManager* manager = static_cast(user_data); @@ -460,7 +460,7 @@ SysteminfoManager::SysteminfoManager(SysteminfoInstance* instance) : instance_(instance), prop_manager_(*this), sensor_handle_(-1), - wifi_level_(WIFI_MANAGER_RSSI_LEVEL_0), + wifi_level_(WIFI_RSSI_LEVEL_0), cpu_load_(0), last_cpu_load_(0), available_capacity_internal_(0), @@ -473,16 +473,16 @@ SysteminfoManager::SysteminfoManager(SysteminfoInstance* instance) connection_handle_(nullptr), async_op_(new AsynchronousOperation()) { LoggerD("Entered"); - int error = wifi_manager_initialize(&this->wifi_manager_handle_); - if (WIFI_MANAGER_ERROR_NONE != error) { + int error = wifi_initialize(); + if (WIFI_ERROR_NONE != error) { std::string log_msg = "Initialize failed: " + std::string(get_error_message(error)); LoggerE("%s", log_msg.c_str()); } else { - LoggerD("WIFI Manager initialization succeed"); + LoggerD("WIFI initialization succeed"); } - error = wifi_manager_set_rssi_level_changed_cb(this->wifi_manager_handle_, OnWifiLevelChangedCb, this); - if (WIFI_MANAGER_ERROR_NONE != error) { + error = wifi_set_rssi_level_changed_cb(OnWifiLevelChangedCb, this); + if (WIFI_ERROR_NONE != error) { std::string log_msg = "Setting wifi listener failed: " + std::string(get_error_message(error)); LoggerE("%s", log_msg.c_str()); @@ -514,10 +514,7 @@ SysteminfoManager::~SysteminfoManager() { connection_destroy(connection_handle_); } - auto error = wifi_manager_deinitialize(this->wifi_manager_handle_); - if (WIFI_MANAGER_ERROR_NONE != error) { - LoggerE( "wifi_manager_deinitialize failed: %s", get_error_message(error) ); - } + wifi_deinitialize(); } void SysteminfoManager::GetCapabilities(const picojson::value& args, picojson::object* out) { @@ -1372,12 +1369,12 @@ PlatformResult SysteminfoManager::GetPropertyCount(const std::string& property, return PlatformResult(ErrorCode::NO_ERROR); } -wifi_manager_rssi_level_e SysteminfoManager::GetWifiLevel() { +wifi_rssi_level_e SysteminfoManager::GetWifiLevel() { LoggerD("Enter"); return wifi_level_; } -void SysteminfoManager::SetWifiLevel(wifi_manager_rssi_level_e level) { +void SysteminfoManager::SetWifiLevel(wifi_rssi_level_e level) { LoggerD("Entered"); wifi_level_ = level; } diff --git a/src/systeminfo/systeminfo_manager.h b/src/systeminfo/systeminfo_manager.h index 69cdc0c..c34dd4e 100644 --- a/src/systeminfo/systeminfo_manager.h +++ b/src/systeminfo/systeminfo_manager.h @@ -23,7 +23,7 @@ #include #include -#include +#include #include "common/picojson.h" #include "common/platform_result.h" @@ -53,8 +53,8 @@ class SysteminfoManager { void GetCount(const picojson::value& args, picojson::object* out); common::PlatformResult GetPropertyCount(const std::string& property, unsigned long* count); - wifi_manager_rssi_level_e GetWifiLevel(); - void SetWifiLevel(wifi_manager_rssi_level_e level); + wifi_rssi_level_e GetWifiLevel(); + void SetWifiLevel(wifi_rssi_level_e level); int GetSensorHandle(); int GetChangedTapiIndex(TapiHandle* tapi); @@ -133,8 +133,7 @@ class SysteminfoManager { std::mutex sensor_mutex_; std::vector camera_types_; - wifi_manager_rssi_level_e wifi_level_; - wifi_manager_h wifi_manager_handle_; + wifi_rssi_level_e wifi_level_; double cpu_load_; double last_cpu_load_; unsigned long long available_capacity_internal_; diff --git a/src/systeminfo/systeminfo_properties_manager.cc b/src/systeminfo/systeminfo_properties_manager.cc index 6acf54f..33b639d 100644 --- a/src/systeminfo/systeminfo_properties_manager.cc +++ b/src/systeminfo/systeminfo_properties_manager.cc @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -588,28 +587,28 @@ PlatformResult SysteminfoPropertiesManager::ReportNetwork(picojson::object* out, } /// WIFI_NETWORK -static PlatformResult GetIpsWifi(wifi_manager_ap_h wifi_ap_handle, std::string* ip_addr_str, +static PlatformResult GetIpsWifi(wifi_ap_h wifi_ap_handle, std::string* ip_addr_str, std::string* ipv6_addr_str) { LoggerD("Entered"); //getting ipv4 address char* ip_addr = nullptr; - int error = wifi_manager_ap_get_ip_address(wifi_ap_handle, - WIFI_MANAGER_ADDRESS_FAMILY_IPV4, + int error = wifi_ap_get_ip_address(wifi_ap_handle, + WIFI_ADDRESS_FAMILY_IPV4, &ip_addr); - if (WIFI_MANAGER_ERROR_NONE != error) { + if (WIFI_ERROR_NONE != error) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Cannot get ip address", - ("wifi_manager_ap_get_ip_address error: %d (%s)", error, get_error_message(error))); + ("wifi_ap_get_ip_address error: %d (%s)", error, get_error_message(error))); } *ip_addr_str = ip_addr; free(ip_addr); //getting ipv6 address ip_addr = nullptr; - error = wifi_manager_ap_get_ip_address(wifi_ap_handle, - WIFI_MANAGER_ADDRESS_FAMILY_IPV6, + error = wifi_ap_get_ip_address(wifi_ap_handle, + WIFI_ADDRESS_FAMILY_IPV6, &ip_addr); - if (WIFI_MANAGER_ERROR_NONE != error) { + if (WIFI_ERROR_NONE != error) { return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, "Cannot get ipv6 address", ("Failed to get ipv6 address: %d (%s)", error, get_error_message(error))); @@ -656,73 +655,69 @@ static PlatformResult GetIpsFromProfile(connection_profile_h profile_handle, std PlatformResult SysteminfoPropertiesManager::ReportWifiNetwork(picojson::object* out) { LoggerD("Entered"); + bool result_status = false; std::string result_ssid; std::string result_ip_address; std::string result_ipv6_address; std::string result_mac_address; double result_signal_strength = 0; - // wifi_manager_initialize() must be called in each thread - wifi_manager_h wifi_manager_handle; - int error = wifi_manager_initialize(&wifi_manager_handle); - if (WIFI_MANAGER_ERROR_NONE != error) { + // wifi_initialize() must be called in each thread + int error = wifi_initialize(); + if (WIFI_ERROR_NONE != error) { std::string log_msg = "Initialize failed: " + std::string(get_error_message(error)); return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, log_msg, - ("wifi_manager_initialize error: %d (%s)", error, get_error_message(error))); + ("wifi_initialize error: %d (%s)", error, get_error_message(error))); + } else { + LoggerD("WIFI initialization succeed"); } - LoggerD("WIFI initialization succeed"); SCOPE_EXIT { - auto error = wifi_manager_deinitialize(wifi_manager_handle); - if (WIFI_MANAGER_ERROR_NONE != error) { - LoggerE( "wifi_manager_deinitialize failed: %s", get_error_message(error) ); - } + wifi_deinitialize(); }; // check if wifi activated bool activated = false; - error = wifi_manager_is_activated(wifi_manager_handle, &activated); - if (WIFI_MANAGER_ERROR_NONE != error) { + error = wifi_is_activated(&activated); + if (WIFI_ERROR_NONE != error) { std::string log_msg = "Checking if wifi is activated failed: " + std::string(get_error_message(error)); return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, log_msg, ("wifi_is_activated error: %d (%s)", error, get_error_message(error))); + } else { + LoggerD("WIFI activated check succeed"); } - LoggerD("WIFI activated check succeed"); - wifi_manager_ap_h wifi_ap_handle = nullptr; - bool result_status = false; + wifi_ap_h wifi_ap_handle = nullptr; if (activated) { LoggerD("Wifi is activated"); - error = wifi_manager_get_connected_ap(wifi_manager_handle, &wifi_ap_handle); - switch (error) { - case WIFI_MANAGER_ERROR_NONE: - //if getting connected AP succeed, set status on true - result_status = true; - break; - case WIFI_MANAGER_ERROR_NO_CONNECTION: - LoggerD("No connection while wifi_manager_get_connected_ap: %s", get_error_message(error)); - // in case of no connection, ignore error and leave status as false - break; - default: - // other error - std::string log_msg = "Cannot get connected access point handle: " + std::string(get_error_message(error)); + error = wifi_get_connected_ap(&wifi_ap_handle); + if (WIFI_ERROR_NONE != error) { + LoggerD("Error while wifi_get_connnected_ap: %s", get_error_message(error)); + // in case of no connection, ignore error and leave status as false + if (WIFI_ERROR_NO_CONNECTION != error) { + std::string log_msg = "Cannot get connected access point handle: " + + std::string(get_error_message(error)); return LogAndCreateResult( - ErrorCode::UNKNOWN_ERR, log_msg, - ("wifi_manager_get_connected_ap error: %d (%s)", error, get_error_message(error))); + ErrorCode::UNKNOWN_ERR, log_msg, + ("wifi_get_connected_ap error: %d (%s)", error, get_error_message(error))); + } + } else { + //if getting connected AP succeed, set status on true + result_status = true; } } if (result_status) { - std::unique_ptr::type, int(*)(wifi_manager_ap_h)> - wifi_ap_handle_ptr{wifi_ap_handle, &wifi_manager_ap_destroy}; - // automatically release the memory + std::unique_ptr::type, int(*)(wifi_ap_h)> + wifi_ap_handle_ptr(wifi_ap_handle, &wifi_ap_destroy); + // automatically release the memory //gathering mac address char* mac = nullptr; - error = wifi_manager_get_mac_address(wifi_manager_handle, &mac); - if (WIFI_MANAGER_ERROR_NONE == error && nullptr != mac) { + error = wifi_get_mac_address(&mac); + if (WIFI_ERROR_NONE == error && nullptr != mac) { SLoggerD("MAC address fetched: %s", mac); result_mac_address = mac; free(mac); @@ -730,12 +725,12 @@ PlatformResult SysteminfoPropertiesManager::ReportWifiNetwork(picojson::object* std::string log_msg = "Failed to get mac address: " + std::string(get_error_message(error)); return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, log_msg, - ("wifi_manager_get_mac_address error: %d (%s)", error, get_error_message(error))); + ("wifi_get_mac_address error: %d (%s)", error, get_error_message(error))); } //refreshing access point information - error = wifi_manager_ap_refresh(wifi_ap_handle); - if (WIFI_MANAGER_ERROR_NONE != error) { + error = wifi_ap_refresh(wifi_ap_handle); + if (WIFI_ERROR_NONE != error) { std::string log_msg = "Failed to refresh access point information: " + std::string(get_error_message(error)); return LogAndCreateResult( @@ -745,8 +740,8 @@ PlatformResult SysteminfoPropertiesManager::ReportWifiNetwork(picojson::object* //gathering ssid char* essid = nullptr; - error = wifi_manager_ap_get_essid(wifi_ap_handle, &essid); - if (WIFI_MANAGER_ERROR_NONE == error) { + error = wifi_ap_get_essid(wifi_ap_handle, &essid); + if (WIFI_ERROR_NONE == error) { result_ssid = essid; free(essid); } else { @@ -756,30 +751,30 @@ PlatformResult SysteminfoPropertiesManager::ReportWifiNetwork(picojson::object* ("wifi_ap_get_essid error: %d (%s)", error, get_error_message(error))); } - //gathering IPs + //gathering ips PlatformResult ret = GetIpsWifi(wifi_ap_handle, &result_ip_address, &result_ipv6_address); if (ret.IsError()) { return ret; } //gathering strength - wifi_manager_rssi_level_e rssi_level = manager_.GetWifiLevel(); + wifi_rssi_level_e rssi_level = manager_.GetWifiLevel(); // this mean that level was not initialized or wifi not connected - if (WIFI_MANAGER_RSSI_LEVEL_0 == rssi_level) { + if (WIFI_RSSI_LEVEL_0 == rssi_level) { // so try to gather rssi level with dedicated function int rssi = 0; - error = wifi_manager_ap_get_rssi(wifi_ap_handle, &rssi); - if (WIFI_MANAGER_ERROR_NONE == error) { + error = wifi_ap_get_rssi(wifi_ap_handle, &rssi); + if (WIFI_ERROR_NONE == error) { result_signal_strength = ((double) abs(rssi))/kWifiSignalStrengthDivideValue; } else { std::string log_msg = "Failed to get signal strength: " + std::string(get_error_message(error)); return LogAndCreateResult( ErrorCode::UNKNOWN_ERR, log_msg, - ("wifi_manager_ap_get_rssi error: %d (%s)", error, get_error_message(error))); + ("wifi_ap_get_rssi error: %d (%s)", error, get_error_message(error))); } } else { - result_signal_strength = ((double) rssi_level)/WIFI_MANAGER_RSSI_LEVEL_4; + result_signal_strength = ((double) rssi_level)/WIFI_RSSI_LEVEL_4; } } //building result object -- 2.7.4