From: Pawel Wasowski
Date: Thu, 15 Jul 2021 13:03:15 +0000 (+0200)
Subject: [Alarm] Don't raise an error when an alarm without TYPE is found
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ffa465259c1de75d896c618e40429e44d5e44702;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Alarm] Don't raise an error when an alarm without TYPE is found
tizen.alarm.get() and tizen.alarm.getAll() used to fail when alarms
without "TYPE" property in related app_control existed.
This commit returns such alarms as JS Alarm objects.
[Verification] tct-alarm-tizen-tests (auto): 100 %
I've tested in Chrome DevTools debugger, that when an alarm without
"type" property comes to JS, a valid "Alarm" object is created
(I don't provide any test code snippet, because it required stopping
app in the debugger).
Change-Id: I4b5bcea75509f454bd17b787c080417849720f5a
Signed-off-by: Pawel Wasowski
---
diff --git a/src/alarm/alarm_api.js b/src/alarm/alarm_api.js
index 98b4c7be..78f35252 100755
--- a/src/alarm/alarm_api.js
+++ b/src/alarm/alarm_api.js
@@ -222,7 +222,7 @@ AlarmManager.prototype.get = function() {
result.period,
InternalData_(result)
);
- } else {
+ } else if ('AlarmAbsolute' === result.type) {
var date = new Date(
result.year,
result.month,
@@ -233,6 +233,8 @@ AlarmManager.prototype.get = function() {
);
alarm = new tizen.AlarmAbsolute(date, result.second, InternalData_(result));
+ } else {
+ alarm = new Alarm(InternalData_(result));
}
_warningLogs.allow();
return alarm;
@@ -310,9 +312,11 @@ AlarmManager.prototype.getAll = function() {
data.forEach(function(i) {
if ('AlarmRelative' === i.type) {
md.push(new tizen.AlarmRelative(i.delay, i.period, InternalData_(i)));
- } else {
+ } else if ('AlarmAbsolute' === i.type) {
var date = new Date(i.year, i.month, i.day, i.hour, i.min, i.sec);
md.push(new tizen.AlarmAbsolute(date, i.second, InternalData_(i)));
+ } else {
+ md.push(new Alarm(InternalData_(i)));
}
});
_warningLogs.allow();
diff --git a/src/alarm/alarm_manager.cc b/src/alarm/alarm_manager.cc
index d0d83f46..dfcdbaa7 100644
--- a/src/alarm/alarm_manager.cc
+++ b/src/alarm/alarm_manager.cc
@@ -63,7 +63,7 @@ const char* kAlarmTypeValueAbsolute = "ABSOLUTE";
const char* kAlarmTypeValueRelative = "RELATIVE";
const char* kAlarmRelativeDelayKey = "RELATIVE_DELAY";
-}
+} // namespace
AlarmManager::AlarmManager() {
ScopeLogger();
@@ -554,14 +554,18 @@ PlatformResult AlarmManager::GetAlarm(int id, picojson::object& obj) {
}
}
+ obj.insert(std::make_pair("id", picojson::value(std::to_string(id))));
+
ret = app_control_get_extra_data(app_control, kAlarmKeyType, &alarm_type);
if (APP_CONTROL_ERROR_NONE != ret) {
- return LogAndCreateResult(ErrorCode::UNKNOWN_ERR, "Unknown error occurred.",
- ("Getting data failed: %d (%s)", ret, get_error_message(ret)));
+ // This is not always an error.
+ // Sometimes an application adds an alarm without alarm type set in appcontrol's extra data
+ // (possibly, when the alarm is set by a C service app, which doesn't set this value in extra
+ // data). In such cases, we return the alarm as an "Alarm" JS object, having only ID
+ LoggerW("Getting extra data (%s) failed: [%d](%s)", kAlarmKeyType, ret, get_error_message(ret));
+ return PlatformResult(ErrorCode::NO_ERROR);
}
- obj.insert(std::make_pair("id", picojson::value(std::to_string(id))));
-
if (!strcmp(alarm_type, kAlarmTypeValueAbsolute)) {
struct tm date;
memset(&date, 0, sizeof(tm));