Update change log and spec for wrt-plugins-tizen_0.2.72
[framework/web/wrt-plugins-tizen.git] / src / standards / Tizen / Alarm / JSAlarmManager.cpp
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <dpl/log/log.h>
19 #include <vector>
20 #include <app.h>
21 #include <time.h>
22 #include <CommonsJavaScript/Converter.h>
23 #include <CommonsJavaScript/Validator.h>
24 #include <CommonsJavaScript/JSUtils.h>
25 #include <CommonsJavaScript/JSDOMExceptionFactory.h>
26 #include <Tizen/Common/SecurityExceptions.h>
27 #include <Commons/Exception.h>
28 #include <Commons/Regex.h>
29 #include <Tizen/Common/JSTizenExceptionFactory.h>
30 #include <Tizen/Common/JSTizenException.h>
31 #include <Tizen/Application/JSApplicationService.h>
32 #include <API/Application/ApplicationService.h>
33 #include <Tizen/Application/ApplicationConverter.h>
34
35 #include <ail.h>
36
37 #include "plugin_config.h"
38 #include "AlarmConverter.h"
39 #include "JSAlarmAbsolute.h"
40 #include "AlarmAbsolute.h"
41 #include "JSAlarmRelative.h"
42 #include "AlarmRelative.h"
43 #include "JSAlarmManager.h"
44
45 namespace TizenApis {
46 namespace Tizen1_0 {
47 namespace Alarm {
48
49 using namespace WrtDeviceApis::Commons;
50 using namespace WrtDeviceApis::CommonsJavaScript;
51 using namespace TizenApis::Commons;
52 using namespace TizenApis::Api::Alarm;
53
54 static bool alarm_iterate_callback(int alarm_id, void *user_data)
55 {
56     std::vector<int> *alarmIds = reinterpret_cast<std::vector<int>*>(user_data);
57    
58     alarmIds->push_back(alarm_id);
59     return true;
60 }
61
62 JSClassRef JSAlarmManager::m_jsClassRef = NULL;
63
64 JSClassDefinition JSAlarmManager::m_jsClassInfo = {
65         0,
66         kJSClassAttributeNone,
67         TIZEN_ALARM_INTERFACE,
68         NULL,
69         m_property,
70         m_function,
71         initialize,
72         finalize,
73         NULL, //hasProperty,
74         NULL, //getProperty,
75         NULL, //setProperty,
76         NULL, //deleteProperty,Geolocation
77         NULL, //getPropertyNames,
78         NULL,
79         NULL, // constructor
80         hasInstance,
81         NULL
82 };
83
84 JSStaticFunction JSAlarmManager::m_function[] = {    
85         { ALARM_FUNCTION_API_ADD, JSAlarmManager::add,kJSPropertyAttributeNone },
86         { ALARM_FUNCTION_API_REMOVE, JSAlarmManager::remove,kJSPropertyAttributeNone },
87         { ALARM_FUNCTION_API_REMOVE_ALL, JSAlarmManager::removeAll,kJSPropertyAttributeNone },
88         { ALARM_FUNCTION_API_GET_ALL, JSAlarmManager::getAll,kJSPropertyAttributeNone },
89         { ALARM_FUNCTION_API_GET, JSAlarmManager::get,kJSPropertyAttributeNone },
90         { 0, 0, 0 }
91 };
92
93 JSStaticValue JSAlarmManager::m_property[] = {
94                 { TIZEN_ALARM_CONSTANT_PERIOD_MINUTE, getMin, NULL, kJSPropertyAttributeReadOnly },
95                 { TIZEN_ALARM_CONSTANT_PERIOD_HOUR, getHour, NULL, kJSPropertyAttributeReadOnly },
96                 { TIZEN_ALARM_CONSTANT_PERIOD_DAY, getDay, NULL, kJSPropertyAttributeReadOnly },
97                 { TIZEN_ALARM_CONSTANT_PERIOD_WEEK, getWeek, NULL, kJSPropertyAttributeReadOnly },
98                 { 0, 0, 0, 0 }
99 };
100
101 const JSClassRef JSAlarmManager::getClassRef() 
102 {
103     if (!m_jsClassRef) {
104         m_jsClassRef = JSClassCreate(&m_jsClassInfo);
105     }
106     return m_jsClassRef;
107 }
108
109 const JSClassDefinition* JSAlarmManager::getClassInfo() 
110 {
111     return &m_jsClassInfo;
112 }
113
114 JSContextRef JSAlarmManager::gContext = NULL;
115
116 void JSAlarmManager::initialize(JSContextRef ctx, JSObjectRef object) 
117 {
118     gContext = ctx;
119     LogInfo("GContext = " << gContext);
120 }
121
122 void JSAlarmManager::finalize(JSObjectRef object) 
123 {
124 }
125
126 bool JSAlarmManager::hasInstance(JSContextRef context, JSObjectRef constructor, JSValueRef possibleInstance, JSValueRef* exception) {
127     return JSValueIsObjectOfClass(context, possibleInstance, getClassRef());
128 }
129
130 JSValueRef JSAlarmManager::add(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
131 {
132         service_h service;
133         struct tm startDate;
134         int delay = 0;
135         int alarm_id;
136         std::string applicationId;
137         std::string page;
138
139         AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_ADD);
140         TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
141
142         Validator check(ctx, exception);
143         AlarmConverter converter(ctx);
144         TizenApis::Tizen1_0::Application::ApplicationConverter applicationConverter(ctx);
145
146         Try {
147                 if(argumentCount < 2) {
148             ThrowMsg(ConversionException, "Wrong parameter type.");
149                 }
150
151                 if(argumentCount >= 2) {
152             if( JSValueIsNull(ctx, arguments[1]) || JSValueIsUndefined(ctx, arguments[1]) ) {
153                 ThrowMsg(InvalidArgumentException, "Wrong application id.");
154             }
155                         applicationId = converter.toString(arguments[1]);
156                         LogDebug("package:[" << applicationId << "]");
157                 }
158
159                 if(JSValueIsObjectOfClass(ctx, arguments[0], JSAlarmAbsolute::getClassRef())) {
160                         // AlarmAbsolute obj
161                         JSObjectRef alarmObj = JSValueToObject(ctx, arguments[0], exception);
162                         JSAlarmAbsolutePriv *priv = static_cast<JSAlarmAbsolutePriv*>(JSObjectGetPrivate(alarmObj));
163                         if (!priv) {
164                                 ThrowMsg(ConversionException, "Object is null.");
165                         }
166                         AlarmAbsolutePtr alarmPtr = priv->getObject();
167                         if (!alarmPtr) {
168                                 ThrowMsg(ConversionException, "Private object is null.");
169                         }
170
171                         startDate = alarmPtr->getDate();
172                         service = alarmPtr->getService();
173
174                         if(argumentCount >=3) {
175                                 // It's service object
176                                 if(JSValueIsObjectOfClass(ctx, arguments[2], TizenApis::Tizen1_0::Application::JSApplicationService::getClassRef())) {
177                                         TizenApis::Api::Application::ApplicationServicePtr appService = applicationConverter.toApplicationService(arguments[2]);
178                                         if(converter.toAlarmService(service, appService) == false) {
179                                                 ThrowMsg(ConversionException, "Wrong parameter type.");
180                                         }
181                                 } else if (JSValueIsNull(ctx, arguments[2]) || JSValueIsUndefined(ctx, arguments[2])) {
182                     service_set_operation(service, SERVICE_OPERATION_DEFAULT);
183                                 } else {
184                                         ThrowMsg(UnsupportedException, "Third parameter not supported yet.");
185                                 }
186                         } else {
187                                 service_set_operation(service, SERVICE_OPERATION_DEFAULT);
188                         }
189
190                         LogDebug("applicationId:[" << applicationId << "]");
191                         service_set_app_id(service, applicationId.c_str());
192
193                         AbsoluteRecurrence::Type alarmType = alarmPtr->getRecurrenceType();
194
195                         int err = ALARM_ERROR_NONE;
196                         if(alarmType == AbsoluteRecurrence::ByDayValue) {
197                                 int bydayValue = converter.toNativeAlarmValue(alarmPtr->getByDayRecurrence());
198                                 LogInfo("Native bydayValue = " << bydayValue);
199                                 err = alarm_schedule_with_recurrence_week_flag(service, &startDate, bydayValue, &alarm_id);
200                         } else if(alarmType == AbsoluteRecurrence::Interval) {
201                                 int interval = alarmPtr->getInterval();
202                                 err = alarm_schedule_at_date(service, &startDate, interval, &alarm_id);
203                         } else {
204                                 err = alarm_schedule_at_date(service, &startDate, 0, &alarm_id);
205                         }
206
207                         if(err == ALARM_ERROR_NONE) {
208                                 alarmPtr->setId(alarm_id);
209                         }else{
210                                 LogDebug("err:[" << err << "]");
211                                 ThrowMsg(PlatformException, "Alarm scheduling failed.");
212                         }
213                 } else if(JSValueIsObjectOfClass(ctx, arguments[0], JSAlarmRelative::getClassRef())) {
214                         JSObjectRef alarmObj = JSValueToObject(ctx, arguments[0], exception);
215                         JSAlarmRelativePriv *priv = static_cast<JSAlarmRelativePriv*>(JSObjectGetPrivate(alarmObj));
216                         if (!priv) {
217                                 ThrowMsg(ConversionException, "Object is null.");
218                         }
219
220                         AlarmRelativePtr alarmPtr = priv->getObject();
221                         if (!alarmPtr) {
222                                 ThrowMsg(ConversionException, "Private object is null.");
223                         }
224
225                         delay = alarmPtr->getDelay();
226                         int interval = alarmPtr->getPeriod();
227                         service = alarmPtr->getService();
228
229                         if(argumentCount >=3) {
230                                 // It's service object
231                                 if(JSValueIsObjectOfClass(ctx, arguments[2], TizenApis::Tizen1_0::Application::JSApplicationService::getClassRef())) {
232                                         TizenApis::Api::Application::ApplicationServicePtr appService = applicationConverter.toApplicationService(arguments[2]);
233                                         if(converter.toAlarmService(service, appService) == false) {
234                                                 ThrowMsg(ConversionException, "Wrong third parameter type.");
235                                         }
236                                 } else if (JSValueIsNull(ctx, arguments[2]) || JSValueIsUndefined(ctx, arguments[2])) {
237                     service_set_operation(service, SERVICE_OPERATION_DEFAULT);
238                                 } else {
239                                         ThrowMsg(UnsupportedException, "Third parameter not supported yet.");
240                                 }
241                         } else {
242                                 service_set_operation(service, SERVICE_OPERATION_DEFAULT);
243                         }
244
245                         LogDebug("applicationId:[" << applicationId << "]");
246                         service_set_app_id(service, applicationId.c_str());
247
248                         int err = alarm_schedule_after_delay(service, delay, interval, &alarm_id);
249
250                         if(err == ALARM_ERROR_NONE) {
251                                 alarmPtr->setId(alarm_id);
252                         }else{
253                                 LogDebug("err:[" << err << "]");
254                         }
255                 } else {
256                         ThrowMsg(ConversionException, "Wrong first parameter type.");
257                 }
258         } Catch(ConversionException) {
259                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
260                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
261         } Catch(UnsupportedException) {
262                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
263                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
264         } Catch(InvalidArgumentException) {
265                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
266                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
267         } Catch(Exception) {
268                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
269                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
270         }
271
272         return JSValueMakeUndefined(ctx);
273 }
274
275 JSValueRef JSAlarmManager::remove(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
276 {
277     int err;
278
279     AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_REMOVE);
280     TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
281     
282     Converter converter(ctx);
283     JSValueRef value;
284     int id;
285
286     Try {
287         if(argumentCount < 1 ) {
288             value = JSValueMakeUndefined(ctx);
289             id = converter.toInt(value);
290         } else {
291             id = converter.toInt(arguments[0]);
292         }
293
294         if(id <= 0) {
295             ThrowMsg(InvalidArgumentException, "Invalid id value.");
296         }
297
298         err = alarm_cancel(id);
299
300         if(err != ALARM_ERROR_NONE)
301         {
302             if(err == ALARM_ERROR_INVALID_PARAMETER) {
303                                 ThrowMsg(NotFoundException, "Alarm not found.");
304             }
305             else {
306                 ThrowMsg(PlatformException, "Unknown error occurred.");
307             }
308         }
309         } Catch(ConversionException) {
310                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
311                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
312         } Catch(UnsupportedException) {
313                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
314                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
315         } Catch(InvalidArgumentException) {
316                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
317                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
318         } Catch (NotFoundException) {
319                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
320                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
321         } Catch(Exception) {
322                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
323                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
324         }
325
326     return JSValueMakeUndefined(ctx);
327 }
328
329 JSValueRef JSAlarmManager::removeAll(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
330 {
331     LogError("GContext = " << gContext);
332     AceSecurityStatus status = ALARM_CHECK_ACCESS(
333             ALARM_FUNCTION_API_REMOVE_ALL);
334     TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
335
336         int returnVal = alarm_cancel_all();
337         if (ALARM_ERROR_NONE!=returnVal) {
338                 LogInfo("Error while removing all alarms: "<<returnVal);
339         }
340
341     return JSValueMakeUndefined(ctx);
342 }
343
344 JSValueRef JSAlarmManager::getAll(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
345 {
346     AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_GET_ALL);
347     TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
348
349     int error;
350     AlarmConverter converter(ctx);
351     std::vector<int> alarmIds; 
352
353     Try {
354             error = alarm_foreach_registered_alarm(alarm_iterate_callback, &alarmIds);
355         if(error != ALARM_ERROR_NONE)
356         {
357                         LogInfo("Error occurred while getting all alarms: "<<error);
358                         ThrowMsg(PlatformException, "Unknown error occurred.");
359         }
360
361         JSObjectRef jsResult = JSCreateArrayObject(ctx, 0, NULL);
362
363         LogInfo("Natvie alarms id size = " << alarmIds.size());
364         for(unsigned int i = 0; i < alarmIds.size(); i++)
365         { 
366             service_h handle = NULL;
367             char* alarmType = NULL;
368             error = alarm_get_service(alarmIds.at(i), &handle);
369                         if(ALARM_ERROR_NONE!=error) {
370                                 LogInfo("Getting service failed: "<<error);
371                         }
372
373                         error =service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType);
374             if(SERVICE_ERROR_NONE!=error) {
375                                 LogInfo("Getting data failed: "<<error);
376                     service_destroy(handle);
377                                 continue;
378             }
379
380                 LogInfo("Alarm id: " << alarmIds.at(i));
381             LogInfo("Alarm Type: " << alarmType);
382
383             if(!strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE)) {
384                 LogInfo("Enter getAll Natvie alarm id = " << alarmIds.at(i));
385                 AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle));
386                 LogInfo("Success to make Native alarmPtr");
387                 
388                 if(converter.toAlarmAbsolutePtr(alarmIds.at(i), handle, privateData) == false) {
389                     ThrowMsg(ConversionException, "Absolute alarm conversion failed.");
390                 }
391
392                 JSValueRef obj = JSAlarmAbsolute::createJSObject(ctx, privateData);
393                 if(!JSSetArrayElement(ctx, jsResult, i, obj)) 
394                 {
395                    ThrowMsg(UnknownException, "JS array creation failed.");
396                 }
397             } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) {
398                 AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle));
399                 if(converter.toAlarmRelativePtr(alarmIds.at(i), handle, privateData) == false) {
400                     ThrowMsg(ConversionException, "Relative alarm conversion failed.");
401                 }
402                 JSValueRef obj = JSAlarmRelative::createJSObject(ctx, privateData);
403                 if(!JSSetArrayElement(ctx, jsResult, i, obj)) 
404                 {
405                                         ThrowMsg(UnknownException, "JS array creation failed.");
406                 }
407             }
408             service_destroy(handle);
409         }
410         return jsResult;
411
412         } Catch(ConversionException) {
413                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
414                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
415         } Catch(UnsupportedException) {
416                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
417                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
418         } Catch(InvalidArgumentException) {
419                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
420                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
421         } Catch (NotFoundException) {
422                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
423                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
424         } Catch(Exception) {
425                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
426                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
427         }
428 }
429
430 JSValueRef JSAlarmManager::get(JSContextRef ctx, JSObjectRef object, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
431 {
432     AceSecurityStatus status = ALARM_CHECK_ACCESS(ALARM_FUNCTION_API_GET);
433     TIZEN_SYNC_ACCESS_HANDLER(status, ctx, exception);
434
435     int alarmId;
436     JSValueRef value;
437     AlarmConverter converter(ctx);
438
439     Try {    
440         if(argumentCount <1) {
441             value = JSValueMakeUndefined(ctx);            
442             ThrowMsg(ConversionException, "Wrong parameter type.");
443         } else {
444             alarmId = converter.toInt(arguments[0]);
445         }
446
447         service_h handle = NULL;
448         char* alarmType = NULL;
449         int error = alarm_get_service(alarmId, &handle);
450         if(error != ALARM_ERROR_NONE) {
451             ThrowMsg(NotFoundException, "Alarm not found");
452         }
453
454                 error =service_get_extra_data(handle, ALARM_TYPE_KEY, &alarmType);
455                 if(SERVICE_ERROR_NONE!=error) {
456                         LogInfo("Getting data failed: "<<error);
457                         service_destroy(handle);
458             ThrowMsg(PlatformException, "Unknown error occurred.");
459                 }
460
461         if(!strcmp(alarmType, ALARM_TYPE_ABSOLUTE_VALUE)) 
462         {
463             AlarmAbsolutePtr privateData = AlarmAbsolutePtr(new AlarmAbsolute(handle));
464             if(converter.toAlarmAbsolutePtr(alarmId, handle, privateData) == false) {
465                 ThrowMsg(ConversionException, "Absolute alarm conversion failed.");
466             }
467             
468             return JSAlarmAbsolute::createJSObject(ctx, privateData);
469
470         } else if( !strcmp(alarmType, ALARM_TYPE_RELATIVE_VALUE)) {
471             AlarmRelativePtr privateData = AlarmRelativePtr(new AlarmRelative(handle));
472             if(converter.toAlarmRelativePtr(alarmId, handle, privateData) == false) {
473                 ThrowMsg(ConversionException, "Relative alarm conversion failed.");
474             }
475             return JSAlarmRelative::createJSObject(ctx, privateData);    
476         }
477         } Catch(ConversionException) {
478                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
479                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::TYPE_MISMATCH_ERROR, _rethrown_exception.GetMessage());
480         } Catch(UnsupportedException) {
481                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
482                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_SUPPORTED_ERROR, _rethrown_exception.GetMessage());
483         } Catch(InvalidArgumentException) {
484                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
485                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::INVALID_VALUES_ERROR, _rethrown_exception.GetMessage());
486         } Catch (NotFoundException) {
487                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
488                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::NOT_FOUND_ERROR, _rethrown_exception.GetMessage());
489         } Catch(Exception) {
490                 LogWarning("Exception: "<<_rethrown_exception.GetMessage());
491                 return JSTizenExceptionFactory::postException(ctx, exception, JSTizenException::UNKNOWN_ERROR, _rethrown_exception.GetMessage());
492         }
493
494     return JSValueMakeUndefined(ctx);
495 }
496
497 JSValueRef JSAlarmManager::getMin(JSContextRef ctx,
498                 JSObjectRef object,
499                 JSStringRef propertyName,
500                 JSValueRef* exception)
501 {
502     Converter converter(ctx);
503     return converter.toJSValueRef(60);
504 }
505
506
507 JSValueRef JSAlarmManager::getHour(JSContextRef ctx,
508                 JSObjectRef object,
509                 JSStringRef propertyName,
510                 JSValueRef* exception)
511 {
512     Converter converter(ctx);
513     return converter.toJSValueRef(3600);
514 }
515
516 JSValueRef JSAlarmManager::getDay(JSContextRef ctx,
517                 JSObjectRef object,
518                 JSStringRef propertyName,
519                 JSValueRef* exception)
520 {
521     Converter converter(ctx);
522     return converter.toJSValueRef(86400);
523 }
524
525 JSValueRef JSAlarmManager::getWeek(JSContextRef ctx,
526                 JSObjectRef object,
527                 JSStringRef propertyName,
528                 JSValueRef* exception)
529 {
530     Converter converter(ctx);
531     return converter.toJSValueRef(604800);
532 }
533
534 static ail_cb_ret_e appinfoCallback(const ail_appinfo_h appinfo, void *user_data)
535 {
536         if (appinfo == NULL || user_data == NULL) {
537                 return AIL_CB_RET_CANCEL;
538         }
539
540         char** pkgStrPtr = (char**)user_data;
541         char* tmpStr = NULL;
542         ail_error_e ret;
543
544         ret = ail_appinfo_get_str(appinfo, AIL_PROP_PACKAGE_STR, &tmpStr);
545         if (ret != AIL_ERROR_OK) {
546                 return AIL_CB_RET_CONTINUE;
547         }
548
549         if (tmpStr != NULL) {
550                 *pkgStrPtr = strdup(tmpStr);
551         }
552         return AIL_CB_RET_CANCEL;
553 }
554
555 // get package name by id
556 char* JSAlarmManager::getPackageById(const char* appId)
557 {
558         LogDebug("<<< appId:[" << appId << "]");
559
560         ail_filter_h filter;
561         ail_error_e ret;
562         char* pkg = NULL;
563
564         if (appId == NULL) {
565                 return NULL;
566         }
567
568
569         ret = ail_filter_new(&filter);
570         if (ret != AIL_ERROR_OK) {
571                 return NULL;
572         }
573
574         ret = ail_filter_add_str(filter, AIL_PROP_X_SLP_PACKAGEID_STR , appId);
575         if (ret != AIL_ERROR_OK) {
576                 ail_filter_destroy(filter);
577                 return NULL;
578         }
579
580         ail_filter_list_appinfo_foreach(filter, appinfoCallback, &pkg);
581         ail_filter_destroy(filter);
582
583         LogDebug(">>> pkg:[" << pkg << "]");
584         return pkg;
585 }
586
587 } // Alarm
588 } // Tizen1_0 
589 } // TizenApis
590