_SystemService::_SystemService()
: _ICommunicationRequestListener()
, __pCommunicationDispatcher(null)
+ , __pPowerManager(null)
{
result r = E_SUCCESS;
_AppManagerImpl* pAppManagerImpl = null;
r = __pCommunicationDispatcher->AddCommunicationEventListener(*this);
SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, E_SYSTEM, "It is failed to add event listener");
+ __pPowerManager = _PowerManager::GetInstance();
+ SysTryCatch(NID_SYS, __pPowerManager != null, r = E_SYSTEM, E_SYSTEM, "_pPowerManager initiate is failed");
+
pAppManagerImpl = _AppManagerImpl::GetInstance();
SysTryCatch(NID_SYS, pAppManagerImpl != null, r = E_SYSTEM, E_SYSTEM, "It is failed to get _AppManagerImpl class.");
void
_SystemService::OnActiveAppChanged(const AppId& appId)
{
+ AppId smallAppId;
+
+ result r = E_SUCCESS;
+ r = appId.SubString(0, 10, smallAppId);
+
+ if(__pPowerManager != null && r == E_SUCCESS)
+ {
+ __pPowerManager->OnActiveAppChanged(smallAppId);
+ }
}
void
}
}
}
+ else if(command->Contains(_SYSTEM_COMMAND_POWER) == true)
+ {
+ if(__pPowerManager != null)
+ {
+ __pPowerManager->OnRequestOccured(appId, request, response);
+ return;
+ }
+ }
else if(*command == _SYSTEM_COMMAND_CHANGE_TIME)
{
SysLog(NID_SYS, "Change system time");
_SystemService::OnApplicationTerminated(const AppId& appId, int pid)
{
SysLog(NID_SYS, "Application (%ls) is terminated.", appId.GetPointer());
+ if(__pPowerManager != null)
+ {
+ __pPowerManager->OnApplicationTerminated(appId);
+ }
}
--- /dev/null
+//
+// Copyright (c) 2012 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_PowerManager.cpp
+ * @brief This is the implementation file for _PowerManager class.
+ */
+#include <unique_ptr.h>
+#include <new>
+
+#include <device.h>
+#include <system_info.h>
+
+#include <FBaseSysLog.h>
+
+#include "FSys_PowerManager.h"
+
+using namespace std;
+
+using namespace Tizen::App;
+using namespace Tizen::Base;
+using namespace Tizen::Base::Collection;
+using namespace Tizen::Base::Utility;
+using namespace Tizen::Io;
+
+namespace {
+ 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;
+ static const wchar_t* _POWER_OK = L"osp.system.result.ok";
+ static const wchar_t* _POWER_ERROR = L"osp.system.result.error";
+}
+
+namespace Tizen { namespace System
+{
+
+_PowerManager* _PowerManager::__pPowerManager = null;
+
+_PowerManager::_PowerManager()
+{
+ __appBrightnessList.Construct();
+}
+
+_PowerManager::~_PowerManager()
+{
+ __appBrightnessList.RemoveAll(true);
+}
+
+_PowerManager*
+_PowerManager::GetInstance()
+{
+
+ if(__pPowerManager == null)
+ {
+ __pPowerManager = new (std::nothrow) _PowerManager();
+ }
+
+ return __pPowerManager;
+}
+
+result
+_PowerManager::ChangeBrightness(void)
+{
+
+ int ret = DEVICE_ERROR_NONE;
+ result r = E_OBJ_NOT_FOUND;
+
+ SysLog(NID_SYS, "Current Active App is [%ls]", __activeAppId.GetPointer());
+
+ if(__appBrightnessList.GetCount() > 0)
+ {
+ Integer* brightness = (Integer*)__appBrightnessList.GetValue(__activeAppId);
+
+ if(brightness != null)
+ {
+ SysLog(NID_SYS, "Brightness is [%d]", brightness->ToInt());
+ ret = device_set_brightness(0, brightness->ToInt());
+ if(ret == DEVICE_ERROR_NONE)
+ {
+ r = E_SUCCESS;
+ }
+ else
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "It is failed to change brightness.");
+ r = E_SYSTEM;
+ }
+ }
+ }
+
+ if(r == E_OBJ_NOT_FOUND)
+ {
+ SysLog(NID_SYS, "Current Active App does not have brightness.");
+ ret = device_set_brightness_from_settings(0);
+ r = E_SUCCESS;
+ }
+
+ return r;
+}
+
+result
+_PowerManager::OnActiveAppChanged(const AppId& appId)
+{
+ result r = E_SUCCESS;
+
+ if(__activeAppId != appId)
+ {
+ __activeAppId = appId;
+ r = ChangeBrightness();
+ }
+ else
+ {
+ SysLog(NID_SYS, "Current App[%ls] is already a");
+ }
+
+ return r;
+}
+
+result
+_PowerManager::OnApplicationTerminated(const AppId& appId)
+{
+ result r = E_SUCCESS;
+ String requiredAppId;
+ appId.SubString(0, 10, requiredAppId);
+
+ __appBrightnessList.Remove(requiredAppId, true);
+ r = ChangeBrightness();
+
+ return r;
+}
+
+result
+_PowerManager::OnRequestOccured(AppId appId, ArrayList* request, ArrayList* response)
+{
+ result r = E_SUCCESS;
+
+ String* command = (String*)request->GetAt(_POWER_COMMAND_ID);
+
+ SysTryCatch(NID_SYS, command != null, r = E_SYSTEM, r, "command is empty.");
+
+ if(*command == _POWER_BRIGHTNESS_CHANGE)
+ {
+ SysTryCatch(NID_SYS, __activeAppId == appId, r = E_SUCCESS, r, "It is not active application[%ls]. Current Active App is [%ls].", appId.GetPointer(), __activeAppId.GetPointer());
+ int brightness = 0;
+ String* brightnessBuffer = (String*)request->GetAt(_POWER_COMMAND_ID + 1);
+ Integer::Parse(*brightnessBuffer, brightness);
+
+ __appBrightnessList.Remove(appId, true);
+
+ unique_ptr<Integer> pBrightness(new (std::nothrow) Integer(brightness));
+ unique_ptr<String> pAppId(new (std::nothrow) String(appId));
+
+ r = __appBrightnessList.Add(*pAppId, *pBrightness);
+ SysTryCatch(NID_SYS, r == E_SUCCESS, r = E_SYSTEM, r, "It is failed to add requested App Id(%ls) and Brightness(%d) on the managed app list.", pAppId->GetPointer(), pBrightness->ToInt());
+ pAppId.release();
+ pBrightness.release();
+ r = ChangeBrightness();
+ }
+ else if(*command == _POWER_BRIGHTNESS_RESTORE)
+ {
+ __appBrightnessList.Remove(appId, true);
+ r = ChangeBrightness();
+ }
+ else
+ {
+ SysLogException(NID_SYS, E_SYSTEM, "Required command[%ls] is not proccess on _PowerManager.", command->GetPointer());
+ r = E_SYSTEM;
+ }
+
+CATCH:
+ unique_ptr<String> resultId(new (std::nothrow) String());
+
+ SysTryReturnResult(NID_SYS, resultId != null, E_SYSTEM, "It is failed to allocate memory for response message creating.");
+
+ if(r == E_SUCCESS)
+ {
+ resultId->Append(_POWER_OK);
+ }
+ else
+ {
+ resultId->Append(_POWER_ERROR);
+ }
+
+ response->Add(*resultId.release());
+
+ return r;
+}
+
+} } // Tizen::System
--- /dev/null
+//
+// Copyright (c) 2012 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_PowerManager.h
+ * @brief This is the header file for the _PowerManager class.
+ */
+
+#ifndef _FSYS_SERVICE_SYS_POWER_MANAGER_H_
+#define _FSYS_SERVICE_SYS_POWER_MANAGER_H_
+
+#include <FApp.h>
+#include <FBase.h>
+
+namespace Tizen { namespace System
+{
+
+class _PowerManager
+{
+public:
+ result OnRequestOccured(Tizen::App::AppId appId, Tizen::Base::Collection::ArrayList* request, Tizen::Base::Collection::ArrayList* response);
+ result OnActiveAppChanged(const Tizen::App::AppId& appId);
+ result OnApplicationTerminated(const Tizen::App::AppId& appId);
+
+public:
+ static _PowerManager* GetInstance(void);
+
+private:
+ _PowerManager();
+ ~_PowerManager();
+ result ChangeBrightness(void);
+
+private:
+ Tizen::App::AppId __activeAppId;
+ Tizen::Base::Collection::HashMap __appBrightnessList;
+
+ static _PowerManager* __pPowerManager;
+};
+
+} } // Tizen::System
+
+#endif // _FSYS_SERVICE_SYS_POWER_MANAGER_H_