[Alarm] Don't raise an error when an alarm without TYPE is found 46/261346/2 accepted/tizen/6.0/unified/20210719.020743 submit/tizen_6.0/20210716.123335
authorPawel Wasowski <p.wasowski2@samsung.com>
Thu, 15 Jul 2021 13:03:15 +0000 (15:03 +0200)
committerPawel Wasowski <p.wasowski2@samsung.com>
Fri, 16 Jul 2021 07:06:33 +0000 (09:06 +0200)
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 <p.wasowski2@samsung.com>
src/alarm/alarm_api.js
src/alarm/alarm_manager.cc

index d7ff0da..d11b057 100755 (executable)
@@ -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();
index a898f3b..4bd5212 100644 (file)
@@ -63,7 +63,7 @@ const char* kAlarmTypeValueAbsolute = "ABSOLUTE";
 const char* kAlarmTypeValueRelative = "RELATIVE";
 
 const char* kAlarmRelativeDelayKey = "RELATIVE_DELAY";
-}
+}  // namespace
 
 AlarmManager::AlarmManager() {
   ScopeLogger();
@@ -570,14 +570,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));