Add AlarmEx fo smartswitch.
authorHokwon Song <hokwon.song@samsung.com>
Tue, 1 Oct 2013 13:52:58 +0000 (22:52 +0900)
committerHokwon Song <hokwon.song@samsung.com>
Tue, 1 Oct 2013 14:39:24 +0000 (23:39 +0900)
Change-Id: I7885c9fcad262f4a12bfb1bf7619cff114afcfab
Signed-off-by: Hokwon Song <hokwon.song@samsung.com>
CMakeLists.txt
inc/CommonService.h
packaging/osp-common-service.spec
src/CommonService.cpp
src/system/CMakeLists.txt
src/system/FSys_AlarmExStub.cpp [new file with mode: 0644]
src/system/FSys_AlarmExStub.h [new file with mode: 0644]
src/system/FSys_DeviceManagerStub.cpp
src/system/FSys_PowerManagerStub.cpp

index 61ff8ea..6d78efb 100644 (file)
@@ -92,6 +92,8 @@ TARGET_LINK_LIBRARIES(${this_target} "-lcapi-system-info" )
 TARGET_LINK_LIBRARIES(${this_target} "-lcapi-network-wifi" )
 TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp-server -losp-appfw-server")
 TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib/osp-server -losp-system-server")
+TARGET_LINK_LIBRARIES(${this_target} "-L/usr/lib -lkies_alarm")
+TARGET_LINK_LIBRARIES(${this_target} "-lsmack" )
 TARGET_LINK_LIBRARIES(${this_target} "-ldl")
 
 INSTALL(TARGETS ${this_target} DESTINATION ../usr/apps/${APPID}/bin)
index 9203505..99b62ee 100644 (file)
@@ -35,6 +35,7 @@ class _SettingService;
 class _RuntimeInfoStub;
 class _DeviceManagerStub;
 class _PowerManagerStub;
+class _AlarmExStub;
 }}
 
 namespace Tizen { namespace Messaging
@@ -70,6 +71,7 @@ private:
        Tizen::System::_RuntimeInfoStub* __pRuntimeInfoStub;
        Tizen::System::_DeviceManagerStub* __pDeviceManagerStub;
        Tizen::System::_PowerManagerStub* __pPowerManagerStub;
+       Tizen::System::_AlarmExStub* __pAlarmExStub;
        std::unique_ptr<Tizen::Messaging::_MessagingIpcStub>__pMessagingIpcStub;
 };
 
index c496712..48d7438 100644 (file)
@@ -33,6 +33,9 @@ BuildRequires:        pkgconfig(email-service)
 BuildRequires: pkgconfig(msg-service)
 BuildRequires: pkgconfig(osp-shell)
 BuildRequires: pkgconfig(osp-messaging)
+BuildRequires:  pkgconfig(kies_alarm)
+BuildRequires:  pkgconfig(alarm-service)
+BuildRequires:  pkgconfig(alarm-engine)
 BuildRequires: osp-messaging-internal-devel
 # runtime requires
 Requires: chromium
index 2951a1f..16969fa 100644 (file)
@@ -25,6 +25,7 @@
 #include "FSys_RuntimeInfoStub.h"
 #include "FSys_DeviceManagerStub.h"
 #include "FSys_PowerManagerStub.h"
+#include "FSys_AlarmExStub.h"
 #include "FMsg_MessagingIpcStub.h"
 
 using namespace std;
@@ -40,6 +41,7 @@ CommonService::CommonService(void)
        , __pRuntimeInfoStub(null)
        , __pDeviceManagerStub(null)
        , __pPowerManagerStub(null)
+       , __pAlarmExStub(null)
        , __pMessagingIpcStub(null)
 {
 }
@@ -122,5 +124,8 @@ CommonService::InitializeServices(void)
 
        __pSystemInfoService = _SystemInfoService::GetInstance();
        SysLogException(NID_SYS, E_SUCCESS, "System done");
+
+       __pAlarmExStub = _AlarmExStub::GetInstance();
+       SysLogException(NID_SYS, E_SUCCESS, "AlarmEx done");
 }
 
index 66daee0..9d5864b 100644 (file)
@@ -19,12 +19,22 @@ SET (${this_target}_SOURCE_FILES
        FSys_DeviceManagerStub.cpp
        FSys_PowerManagerStub.cpp
        FSys_SystemServiceIpcEventForAsync.cpp
+       FSys_AlarmExStub.cpp
 )
 
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
+INCLUDE(FindPkgConfig)
+pkg_check_modules(pkgs REQUIRED
+        kies_alarm
+        alarm-engine
+        alarm-service
+)
 
 ## SET EXTRA COMPILER FLAGS
-SET(EXTRA_CFLAGS  "${EXTRA_CFLAGS} -fPIC" )
+FOREACH(flag ${pkgs_CFLAGS})
+        SET(EXTRA_CFLAGS  "${EXTRA_CFLAGS} ${flag} -fPIC" )
+ENDFOREACH(flag)
+
+SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden")
 
 ## SET C COMPILER FLAGS
 SET(CMAKE_C_FLAGS "${OSP_DEBUG_FLAGS} ${OSP_OPT_FLAGS} ${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} ${OSP_COMPILER_FLAGS}")
diff --git a/src/system/FSys_AlarmExStub.cpp b/src/system/FSys_AlarmExStub.cpp
new file mode 100644 (file)
index 0000000..1131030
--- /dev/null
@@ -0,0 +1,251 @@
+//
+// Open Service Platform
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file        FSys_AlarmExStub.cpp
+ * @brief      This is the implementation for the _AlarmExStub class.
+ */
+#include <unistd.h>
+#include <errno.h>
+#include <sys/smack.h>
+#include <FBaseSysLog.h>
+#include <FIo_IpcServer.h>
+#include <FIoFile.h>
+#include <FIo_AppServiceIpcMessages.h>
+#include <FSec_AccessController.h>
+extern "C"{
+#include <kies_alarm.h> //It should be changed after update kies_alarm.h by SLP
+}
+
+#include "FBase_StringConverter.h"
+#include "FSys_AlarmExStub.h"
+
+using namespace std;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Io;
+using namespace Tizen::System;
+using namespace Tizen::Security;
+
+namespace {
+       static const wchar_t* ALARM_EX_SERVICE_PRIVILEGE = L"http://developer.samsung.com/tizen/privilege/smartswitch.alarminfomanager";
+       static const wchar_t* ALARM_EX_SERVICE_ID = L"osp.sys.ipcserver.alarmex";
+       static const wchar_t* _ALARM_EX_EXPORT_DATA = L"osp.system.command.alarmex.export.data";
+       static const wchar_t* _ALARM_EX_IMPORT_DATA = L"osp.system.command.alarmex.import.data";
+       static const int _ALARM_EX_COMMAND_ID = 1;
+       static const int _ALARM_EX_ARGUMENT_ID = 2;
+       static const int _ALARM_ERROR_FAILURE = -1;
+       static const int _ALARM_ERROR_SUCCESS = 0;
+       static const int _ALARM_ERROR_DATA_NOT_FOUND = 1;
+       static const int _ALARM_ERROR_INVALID_DATA = 2;
+       static const int _ALARM_ERROR_PRIVILEGE_DENIED = 3;
+}
+
+_AlarmExStub* _AlarmExStub::__pAlarmExStub = null;
+
+_AlarmExStub::_AlarmExStub(void)
+       : __pIpcServer(null)
+       , __serviceId(ALARM_EX_SERVICE_ID)
+{
+}
+
+_AlarmExStub::~_AlarmExStub(void)
+{
+       if (__pIpcServer)
+       {
+               __pIpcServer->Stop();
+       }
+}
+
+_AlarmExStub*
+_AlarmExStub::GetInstance()
+{
+       static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
+
+       if (__pAlarmExStub == null)
+       {
+               pthread_once(&onceBlock, InitSingleton);
+       }
+       return __pAlarmExStub;
+}
+
+void
+_AlarmExStub::InitSingleton(void)
+{
+       std::unique_ptr< _AlarmExStub > pAlarmExStub(new (std::nothrow) _AlarmExStub());
+       SysTryReturn(NID_SYS, pAlarmExStub, ,E_OUT_OF_MEMORY, "It is not enough memory.");
+       result r = pAlarmExStub->Construct();
+       SysTryReturn(NID_SYS, !IsFailed(r), , r, "[%s] It is failed to get AlarmExCommunicationStub.", GetErrorMessage(r));
+       __pAlarmExStub = pAlarmExStub.release();
+       atexit(DestroySingleton);
+}
+
+
+void
+_AlarmExStub::DestroySingleton(void)
+{
+       delete __pAlarmExStub;
+}
+
+result
+_AlarmExStub::Construct(void)
+{
+       unique_ptr<_IpcServer> pIpcServer(new (std::nothrow) _IpcServer());
+       SysTryReturnResult(NID_SYS, pIpcServer, E_OUT_OF_MEMORY, "Memory is insufficient.");
+
+       result r = pIpcServer->Construct(String(ALARM_EX_SERVICE_ID), *this, true);
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to construct.");
+
+       r = pIpcServer->Start();
+       SysTryReturnResult(NID_SYS, r == E_SUCCESS, r, "It is failed to start.");
+
+       __pIpcServer = move(pIpcServer);
+
+       return E_SUCCESS;
+}
+
+
+result
+_AlarmExStub::ExportToFile(const String &path)
+{
+       result r = E_SUCCESS;
+       SysLog(NID_SYS, "ExportToFile");
+       int error = -1;
+       char* pSmackLable = _StringConverter::CopyToCharArrayN(__clientPackageId);
+       char* pPath = _StringConverter::CopyToCharArrayN(path);
+       error = alarm_backup(pPath);
+       SysLog(NID_SYS, "alarm_backup returns [%d]", error);
+
+       if (error == 0)
+        {
+                r = E_SUCCESS;
+               int errorCode = chown(pPath, 5000, 5000);
+               SysTryCatch(NID_SYS, errorCode == 0, r = E_SYSTEM, E_SYSTEM, "It is failed to change permission.");
+               SysTryCatch(NID_SYS, smack_setlabel(pPath, pSmackLable, SMACK_LABEL_IPIN) == 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] SMACK labeling failed");
+        }
+        else if (error == 1)
+       {
+               r = E_DATA_NOT_FOUND;
+       }
+       else
+        {
+                r = E_FAILURE;
+        }
+CATCH:
+       delete pSmackLable;
+        delete pPath;
+
+       return r;
+}
+
+result
+_AlarmExStub::ImportFromFile(const String &path)
+{
+       result r = E_SUCCESS;
+       SysLog(NID_SYS, "ImportFromFile");
+       int error = -1;
+       char* pPath = _StringConverter::CopyToCharArrayN(path);
+       error = alarm_restore(pPath);
+       SysLog(NID_SYS, "alarm_restore returns [%d]", error);
+       delete pPath;
+
+       if (error == 0)
+       {
+               r = E_SUCCESS;
+       }
+       else if (error == 1)
+        {
+                r = E_DATA_NOT_FOUND;
+        }
+       else
+       {
+               r = E_FAILURE;
+       }
+       return r;
+}
+void
+_AlarmExStub::OnIpcRequestReceived(_IpcServer& server, const IPC::Message& message)
+{
+       __clientPackageId = server.GetClientPackageId();
+       SysLog(NID_SYS, "client app id [%ls]", __clientPackageId.GetPointer());
+
+       IPC_BEGIN_MESSAGE_MAP(_AlarmExStub, message)
+               IPC_MESSAGE_HANDLER_EX(IoService_Request, &server, OnRequestOccured)
+       IPC_END_MESSAGE_MAP_EX()
+}
+
+bool
+_AlarmExStub::OnRequestOccured(const ArrayList& request, ArrayList* response)
+{
+       result r = E_SUCCESS;
+
+       __command = *((String*)request.GetAt(_ALARM_EX_COMMAND_ID));
+       __argument = *((String*)request.GetAt(_ALARM_EX_ARGUMENT_ID));
+
+       SysTryCatch(NID_SYS, File::IsFileExist(L"/opt/usr/etc/alarmex"), r = E_SYSTEM, E_SYSTEM, "It is not enable alarm ex.");
+
+//     r =  _AccessController::CheckPrivilege(__clientPackageId, ALARM_EX_SERVICE_PRIVILEGE);
+//     SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_PRIVILEGE_DENIED , E_PRIVILEGE_DENIED, "[%s] error occurs.", GetErrorMessage(r));
+
+       SysLog(NID_SYS, "Request AlarmEX: [%ls] path [%ls].", __command.GetPointer(), __argument.GetPointer());
+
+       if (__command == _ALARM_EX_EXPORT_DATA)
+       {
+               r = ExportToFile(__argument);
+       }
+       else if(__command == _ALARM_EX_IMPORT_DATA)
+       {
+               r = ImportFromFile(__argument);
+       }
+       else
+       {
+               SysLogException(NID_SYS, E_SYSTEM, "Required Command[%ls] is not proccess on _AlarmEx.", __command.GetPointer());
+               r = E_SYSTEM;
+       }
+
+CATCH:
+       SysLog(NID_SYS, "Alarm result [%s]", GetErrorMessage(r));
+       __result = "";
+       if (r == E_SUCCESS)
+       {
+               __result.Append(_ALARM_ERROR_SUCCESS);
+       }
+       else if (r == E_INVALID_DATA)
+       {
+               __result.Append(_ALARM_ERROR_INVALID_DATA);
+       }
+       else if (r == E_PRIVILEGE_DENIED)
+       {
+               __result.Append(_ALARM_ERROR_PRIVILEGE_DENIED);
+       }
+       else if (r == E_DATA_NOT_FOUND)
+       {
+               __result.Append(_ALARM_ERROR_DATA_NOT_FOUND);
+       }
+       else
+       {
+               __result.Append(_ALARM_ERROR_FAILURE);
+       }
+
+       response->Add(__serviceId);
+       response->Add(__command);
+       response->Add(__result);
+
+       ArrayList* temp = const_cast<ArrayList*>(&request);
+       temp->RemoveAll(true);
+       return true;
+}
diff --git a/src/system/FSys_AlarmExStub.h b/src/system/FSys_AlarmExStub.h
new file mode 100644 (file)
index 0000000..dbf70d7
--- /dev/null
@@ -0,0 +1,76 @@
+//
+// Open Service Platform
+// Copyright (c) 2013 Samsung Electronics Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the License);
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//     http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+
+/**
+ * @file        FSys_AlarmExStub.h
+ * @brief      This is the header file of the _AlarmExStub class.
+ *
+ * This header file contains the declarations of the _AlarmExStub class.
+ */
+
+#ifndef _FSYS_ALARM_EX_STUB_H_
+#define _FSYS_ALARM_EX_STUB_H_
+
+#include <unique_ptr.h>
+#include <FBase.h>
+#include <FSystem.h>
+#include <FIo_IIpcServerEventListener.h>
+
+namespace Tizen { namespace System
+{
+class _OSP_EXPORT_ _AlarmExStub
+       : public Tizen::Base::Object
+       , public Tizen::Io::_IIpcServerEventListener
+{
+public:
+       static _AlarmExStub* GetInstance(void);
+       virtual ~_AlarmExStub(void);
+
+private:
+       static void InitSingleton(void);
+       static void DestroySingleton(void);
+
+       _AlarmExStub(void);
+       result Construct(void);
+
+       result ExportToFile(const Tizen::Base::String &path);
+       result ImportFromFile(const Tizen::Base::String &path);
+
+       _AlarmExStub(const _AlarmExStub& rhs);
+       _AlarmExStub& operator =(const _AlarmExStub& rhs);
+
+       bool OnRequestOccured(const Tizen::Base::Collection::ArrayList& request, Tizen::Base::Collection::ArrayList* response);
+
+       virtual void OnIpcServerStarted(const Tizen::Io::_IpcServer& server) {}
+       virtual void OnIpcServerStopped(const Tizen::Io::_IpcServer& server) {}
+       virtual void OnIpcClientConnected(const Tizen::Io::_IpcServer& server, int clientId) {}
+       virtual void OnIpcClientDisconnected(const Tizen::Io::_IpcServer&server, int clientId) {}
+       virtual void OnIpcRequestReceived(Tizen::Io::_IpcServer& server, const IPC::Message& message);
+
+private:
+       std::unique_ptr<Tizen::Io::_IpcServer> __pIpcServer;
+       static _AlarmExStub* __pAlarmExStub;
+       Tizen::App::AppId                       __clientPackageId;
+       Tizen::Base::String     __serviceId;
+       Tizen::Base::String     __command;
+       Tizen::Base::String     __argument;
+       Tizen::Base::String     __result;
+}; // _AlarmExStub
+
+}} // Tizen::System
+
+#endif // _FSYS_ALARM_EX_STUB_H_
index 5a34635..d5e1593 100644 (file)
@@ -25,7 +25,6 @@
 #include <FIo_IpcServer.h>
 #include <FIo_AppServiceIpcMessages.h>
 #include <FSystem.h>
-
 #include "FApp_AppManagerImpl.h"
 #include "FSys_DeviceManagerStub.h"
 
index c379669..eb0799c 100644 (file)
@@ -23,7 +23,6 @@
 #include <FIo_IpcServer.h>
 #include <FIo_AppServiceIpcMessages.h>
 #include <FIoRegistry.h>
-
 #include "FApp_AppManagerImpl.h"
 #include "FSys_PowerManagerStub.h"
 #include "FSys_PowerManager.h"
@@ -37,7 +36,6 @@ using namespace Tizen::App;
 
 namespace {
        static const wchar_t* POWER_MANAGER_SERVICE_ID = L"osp.sys.ipcserver.powermanager";
-       static const wchar_t* POWER_MANAGER_SERVICE_MUTEX_ID = L"osp.sys.ipcserver.devicemanager";
        static const wchar_t* _POWER_BRIGHTNESS_CHANGE = L"osp.system.command.power.change.brightness";
        static const wchar_t* _POWER_BRIGHTNESS_RESTORE = L"osp.system.command.power.restore.brightness";
        static const int _POWER_COMMAND_ID = 1;