Fixed the code for alarm registration 57/14657/1
authorJiban Prakash <p.jiban@samsung.com>
Wed, 13 Nov 2013 08:39:15 +0000 (17:39 +0900)
committerKeebong <keebong.bahn@samsung.com>
Thu, 9 Jan 2014 07:55:04 +0000 (16:55 +0900)
Change-Id: Ia0e51d1d52352701a65b46ac9f983c79e0b7db63
Signed-off-by: Jiban Prakash <p.jiban@samsung.com>
plugins/alarm-condition-handler/AlarmConditionHandler.cpp
plugins/alarm-condition-handler/AlarmConditionHandler.h

index bc89754..e955985 100644 (file)
@@ -148,7 +148,7 @@ _AlarmConditionHandler::Convert(_AppLaunchCondition& appLaunchCondition, struct
        else if(buf.StartsWith(L"DateTime", 0) == true)
        {
                ret = sscanf(convertedString.get(), "DateTime='%d/%d/%d %d:%d:%d'%s", &(pConvertedTime->tm_mon), &(pConvertedTime->tm_mday), &(pConvertedTime->tm_year), &(pConvertedTime->tm_hour), &(pConvertedTime->tm_min), &(pConvertedTime->tm_sec), garbage);
-               SysTryReturnResult(NID_SYS, ret == 6, E_INVALID_FORMAT, "The specified condition format is not compatible.");   
+               SysTryReturnResult(NID_SYS, ret == 6, E_INVALID_FORMAT, "The specified condition format is not compatible.");
        }
        else
        {
@@ -178,7 +178,7 @@ _AlarmConditionHandler::Convert(Tizen::Base::String& appLaunchCondition, struct
        SysTryReturnResult(NID_SYS, ret == E_SUCCESS, E_INVALID_CONDITION, "It is not valid date time.");
        alarmDayOfWeek = alarmDayOfWeek/3;
        week = weekFlag[alarmDayOfWeek];
-       
+
        unique_ptr<char[]> convertedString(_StringConverter::CopyToCharArrayN(buf));
        SysTryReturnResult(NID_SYS, convertedString.get() != null, E_OUT_OF_MEMORY, "Memory allocation failure.");
 
@@ -194,10 +194,10 @@ _AlarmConditionHandler::Convert(Tizen::Base::String& appLaunchCondition, struct
        int todayDayOfWeek;
        std::unique_ptr<Tizen::Locales::Calendar> pCalendar(Tizen::Locales::Calendar::CreateInstanceN(Tizen::Locales::CALENDAR_GREGORIAN));
        SysTryReturnResult(NID_SYS, pCalendar != NULL, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
-       
+
        pCalendar->SetTime(currentTime);
        todayDayOfWeek = pCalendar->GetTimeField(TIME_FIELD_DAY_OF_WEEK);
-       
+
        if(alarmDayOfWeek == todayDayOfWeek)
        {
                if(alarmTime < currentTime)
@@ -212,7 +212,7 @@ _AlarmConditionHandler::Convert(Tizen::Base::String& appLaunchCondition, struct
                alarmTime.AddDays(days);
        }
        SysLog(NID_SYS, "Alarm time is %ls", alarmTime.ToString().GetPointer());
-       
+
        pConvertedTime->tm_year = alarmTime.GetYear();
        pConvertedTime->tm_mon = alarmTime.GetMonth();
        pConvertedTime->tm_mday = alarmTime.GetDay();
@@ -249,7 +249,7 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
 
                int count = 0;
                count = strTok.GetTokenCount();
-               
+
                for (int index = 0; index < count; index++)
                {
                        String tokenValue;
@@ -259,10 +259,10 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
                        tokenValue.Trim();
                        r = Convert(tokenValue, &expireTime, week);
                        SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_INVALID_FORMAT, "It is not valid date time format.");
-                       
+
                        r =  validateCheck.SetValue(expireTime.tm_year, expireTime.tm_mon, expireTime.tm_mday, expireTime.tm_hour, expireTime.tm_min, expireTime.tm_sec);
                        SysTryReturnResult(NID_SYS, r == E_SUCCESS, E_INVALID_CONDITION, "It is not valid date time.");
-                       
+
                        DateTime currentTime;
                        SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
 
@@ -273,7 +273,7 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
                        expireTime.tm_min = validateCheck.GetMinute();
                        expireTime.tm_sec = validateCheck.GetSecond();
 
-                       SysTryReturnResult(NID_SYS, validateCheck > currentTime, E_INVALID_CONDITION, "Required time does not greater than current time. (%ls/%ls)", validateCheck.ToString().GetPointer(), currentTime.ToString().GetPointer()); 
+                       SysTryReturnResult(NID_SYS, validateCheck > currentTime, E_INVALID_CONDITION, "Required time does not greater than current time. (%ls/%ls)", validateCheck.ToString().GetPointer(), currentTime.ToString().GetPointer());
 
                        expireTime.tm_year -= _ADJUST_YEAR_FOR_TM;
                        expireTime.tm_mon -= _ADJUST_MONTH_FOR_TM;
@@ -289,7 +289,7 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
 
                        ret = service_set_package(service, packageName);
                        SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to create service for %s", packageName);
-                       
+
                        ret = alarm_schedule_with_recurrence_week_flag(service, &expireTime, week, &reservedAlarmId);
                    SysTryCatch(NID_SYS, ret == ALARM_ERROR_NONE, r = E_SYSTEM, r, "It is failed to set the Alarm time for %s", packageName);
 
@@ -305,7 +305,6 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
                                SysLogException(NID_SYS, E_SYSTEM, "It is failed to register requested condition.");
                                r = E_SYSTEM;
                        }
-                       
                }
        }
        else
@@ -320,7 +319,7 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
                SystemTime::GetCurrentTime(TIME_MODE_WALL, currentTime);
 
                if(appLaunchCondition.GetConditionString().StartsWith(L"DueTime", 0) == true)
-               {               
+               {
                        SysTryReturnResult(NID_SYS, period >= ALARM_PERIOD_MIN && period <= ALARM_PERIOD_MAX, E_INVALID_CONDITION, "Required period is not valid. (%d)", period);
                        SysTryReturnResult(NID_SYS, validateCheck.GetYear() >= (int)(1970), E_INVALID_FORMAT, "It is not valid date time format.");
 
@@ -331,7 +330,7 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
                        {
                                TimeSpan diffTimeSpan = currentTimeSpan - expireTimeSpan;
                                long long minutes = diffTimeSpan.GetTicks()/(long long)(1000)/(long long)(60);
-                               
+
                                int quotient = (int)((long long)minutes/period);
                                int remainder = minutes % period;
 
@@ -342,7 +341,7 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
 
                                validateCheck.AddMinutes(quotient * period);
                        }
-                       
+
                        SysLog(NID_SYS, "Correct time is %ls", validateCheck.ToString().GetPointer());
                        expireTime.tm_year = validateCheck.GetYear();
                        expireTime.tm_mon = validateCheck.GetMonth();
@@ -350,10 +349,9 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
                        expireTime.tm_hour = validateCheck.GetHour();
                        expireTime.tm_min = validateCheck.GetMinute();
                        expireTime.tm_sec = validateCheck.GetSecond();
-                       
                }
 
-               SysTryReturnResult(NID_SYS, validateCheck > currentTime, E_INVALID_CONDITION, "Required time does not greater thancurrent time. (%ls/%ls)", validateCheck.ToString().GetPointer(), currentTime.ToString().GetPointer()); 
+               SysTryReturnResult(NID_SYS, validateCheck > currentTime, E_INVALID_CONDITION, "Required time does not greater thancurrent time. (%ls/%ls)", validateCheck.ToString().GetPointer(), currentTime.ToString().GetPointer());
 
                expireTime.tm_year -= _ADJUST_YEAR_FOR_TM;
                expireTime.tm_mon -= _ADJUST_MONTH_FOR_TM;
@@ -369,7 +367,7 @@ _AlarmConditionHandler::Register( _AppLaunchCondition& appLaunchCondition)
 
                ret = service_set_package(service, packageName);
                SysTryCatch(NID_SYS, ret == SERVICE_ERROR_NONE, r = E_SYSTEM, r, "It is failed to create service for %s", packageName);
-               
+
                ret = alarm_schedule_at_date(service, &expireTime, period * _SECOND_OF_MINUTE, &reservedAlarmId);
                SysTryCatch(NID_SYS, ret == ALARM_ERROR_NONE, r = E_SYSTEM, r, "It is failed to set the Alarm time for %s", packageName);
 
@@ -466,7 +464,7 @@ _AlarmConditionHandler::Unregister( _AppLaunchCondition& appLaunchCondition)
 
        delete pEnum;
        garbageCollector.RemoveAll(true);
-               
+
        return r;
 }
 
@@ -484,7 +482,7 @@ _AlarmConditionHandler::GetAppLaunchCondition(int alarmId)
                SysLog(NID_SYS, "Reserved condition list is empty");
                return null;
        }
-       
+
        while(pMapEnum->MoveNext() == E_SUCCESS)
        {
                pKey = static_cast<Integer *>(pMapEnum->GetKey());
@@ -538,8 +536,20 @@ _AlarmConditionHandler::SettingEventCb(keynode_t* node, void* userData)
 
                        AppId appId(pAppLaunchCondition->GetAppId());
                        String condition(pAppLaunchCondition->GetConditionString());
+                       IList* pArgs = pAppLaunchCondition->GetLaunchArgs();
+
+                       std::unique_ptr<Tizen::Base::Collection::ArrayList> pArguments(new (std::nothrow) ArrayList(SingleObjectDeleter));
+                       SysTryCatch(NID_APP, pArguments != null, r = E_OUT_OF_MEMORY, r,  "failed to allocate 'pArguments'!");
+
+                       pArguments->Construct();
+
+                       for (int i = 0; i < pArgs->GetCount() ; i++)
+                       {
+                               r = pArguments->Add(* new (std::nothrow) String(* static_cast<const String*>(pArgs->GetAt(i))));
+                               SysTryCatch(NID_APP, !IsFailed(r), , r, "[%s]", GetErrorMessage(r));
+                       }
 
-                       pNewAppLaunchCondition = pAlarmCondHandler->GetAppLaunchConditionN(*(new AppId(appId)), *(new String(condition)));
+                       pNewAppLaunchCondition = pAlarmCondHandler->GetAppLaunchConditionN(*(new AppId(appId)), *(new String(condition)), pArguments.release());
                        SysTryCatch(NID_SYS, pNewAppLaunchCondition != null, r = E_OUT_OF_MEMORY, r, "It is failed to create pAppLaunchCondition");
 
                        updateList.Add(pKey, pNewAppLaunchCondition);
@@ -591,14 +601,14 @@ _AlarmConditionHandler::GetAlarmConditionListN(void)
 }
 
 _AppLaunchCondition*
-_AlarmConditionHandler::GetAppLaunchConditionN(const AppId& appId, const Tizen::Base::String& condition)
+_AlarmConditionHandler::GetAppLaunchConditionN(const AppId& appId, const Tizen::Base::String& condition, const IList* pArgs)
 {
        result r = E_SYSTEM;
 
        _AppLaunchCondition* pAppLaunchCondition = new (std::nothrow) _AppLaunchCondition();
        SysTryCatch(NID_SYS, pAppLaunchCondition != null, r = E_OUT_OF_MEMORY, r, "It is failed to create pAppLaunchCondition");
 
-       r = pAppLaunchCondition->Construct(appId, condition, null, AppManager::LAUNCH_OPTION_DEFAULT, null);
+       r = pAppLaunchCondition->Construct(appId, condition, pArgs, AppManager::LAUNCH_OPTION_DEFAULT, null);
        SysTryCatch(NID_SYS, !IsFailed(r), , r, "It is failed to pAppLaunchCondition->Constructor");
 
        return pAppLaunchCondition;
index a838d94..f8e5421 100644 (file)
@@ -49,7 +49,7 @@ public:
        result Convert(Tizen::App::_AppLaunchCondition& appLaunchCondition, struct tm* pConvertedTime, int& period);
        result Convert(Tizen::Base::String& appLaunchCondition, struct tm* pConvertedTime, int& week);
        Tizen::Base::Collection::IMapEnumerator* GetAlarmConditionListN(void);
-       Tizen::App::_AppLaunchCondition* GetAppLaunchConditionN(const Tizen::App::AppId& appId, const Tizen::Base::String& condition);
+       Tizen::App::_AppLaunchCondition* GetAppLaunchConditionN(const Tizen::App::AppId& appId, const Tizen::Base::String& condition, const Tizen::Base::Collection::IList* pArgs);
 
 private:
        _AlarmConditionHandler(void);