--- /dev/null
+//
+// 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;
+}
--- /dev/null
+//
+// 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_