refactoring
[framework/osp/appwidget-service.git] / src / FShell_AppWidgetContext.cpp
index 5dad3b4..750eb47 100644 (file)
  * @brief      This is the implementation for the _AppWidgetContext class.
  */
 
-#include <stdlib.h>
+#include <provider.h>
 #include <unique_ptr.h>
+
 #include <FBase.h>
 #include <FBaseSysLog.h>
 #include <FSysSystemTime.h>
+#include <FAppApp.h>
 #include <FBase_StringConverter.h>
-#include <FApp_AppControlManager.h>
+#include <FApp_AppManagerImpl.h>
+#include "FShell_AppWidgetManagerImpl.h"
 #include "FShell_AppWidgetManagerService.h"
 #include "FShell_AppWidgetPopupContext.h"
-#include "FShell_AppWidgetContextBase.h"
 #include "FShell_AppWidgetContext.h"
+#include "FShell_AppWidgetContextHelper.h"
+#include "FShell_AppWidgetRemoteBuffer.h"
 
 namespace Tizen { namespace Shell  { namespace App
 {
 
+using namespace std;
 using namespace Tizen::App;
 using namespace Tizen::Base;
 using namespace Tizen::Base::Collection;
 using namespace Tizen::System;
 
+const wchar_t ARG_KEY_INSTANCE_ID[] = L"_InstanceId";
+const wchar_t ARG_KEY_PROVIDER_NAME[] = L"_ProviderName";
+const wchar_t ARG_KEY_USER_INFO[] = L"_UserInfo";
+const wchar_t ARG_KEY_X[] = L"_X";
+const wchar_t ARG_KEY_Y[] = L"_Y";
+const wchar_t ARG_KEY_WIDTH[] = L"_Width";
+const wchar_t ARG_KEY_HEIGHT[] = L"_Height";
+const wchar_t ARG_KEY_POPUP_WIDTH[] = L"_PopupWidth";
+const wchar_t ARG_KEY_POPUP_HEIGHT[] = L"_PopupHeight";
+const wchar_t ARG_KEY_ARGUMENT[] = L"_Argument";
+const wchar_t ARG_KEY_EVENT_TYPE[] = L"_EventType";
+const wchar_t ARG_KEY_TIME_STAMP[] = L"_TimeStamp";
+
 const wchar_t APPWIDGET_ON_ADD[] = L"http://tizen.org/appcontrol/appwidget/add";
 const wchar_t APPWIDGET_ON_REMOVE[] = L"http://tizen.org/appcontrol/appwidget/remove";
 const wchar_t APPWIDGET_ON_UPDATE[] = L"http://tizen.org/appcontrol/appwidget/update";
@@ -47,39 +65,58 @@ const wchar_t APPWIDGET_ON_TOUCH[] = L"http://tizen.org/appcontrol/appwidget/tou
 
 const int UPDATE_PERIOD_MSEC_MIN = 1800000;    // 30min
 
-_AppWidgetContext::_AppWidgetContext(const String& info, const String& providerId, const String& instanceId, int width, int height, int period, int priority)
-       :_AppWidgetContextBase(TYPE_LB, info, providerId, instanceId, width, height, priority)
-       ,__pAppWidgetPopup(null)
-       ,__updateMillis(period)
+
+_AppWidgetContext::_AppWidgetContext(_AppContext* pAppContext, const String& instanceId, const String& providerId, int width, int height, const Tizen::Base::String& userInfo, int period, int priority)
+       :__instanceId(instanceId)
+       ,__providerId(providerId)
+       ,__appId(_AppWidgetHelper::ExtractAppId(providerId))
+       ,__providerName(_AppWidgetHelper::ExtractProviderName(providerId))
+       ,__userInfo(userInfo)
+       ,__width(width)
+       ,__height(height)
+       ,__priority(priority)
+       ,__updateMillis( (period > UPDATE_PERIOD_MSEC_MIN) ? period : UPDATE_PERIOD_MSEC_MIN )
+       ,__ipcClientId(-1)
+       ,__isForeground(true)
+       ,__isRemoteBufferProxyCreated(false)
        ,__lastUpdatedTime(0)
+       ,__hasPendingRequest(false)
+       ,__pAppContext(pAppContext)
+       ,__pAppWidgetPopup(null)
+       ,__pAppWidgetRemoteBuffer(null)
        ,__pPendingTouchEventList(null)
-       , __hasPendingRequest(false)
 {
-       if( __updateMillis > 0)
-       {
-               __updateMillis = (__updateMillis > UPDATE_PERIOD_MSEC_MIN) ? __updateMillis : UPDATE_PERIOD_MSEC_MIN;
-               SysLog(NID_SHELL, "period(%d)", __updateMillis);
+       SysSecureLog(NID_SHELL, "appId(%ls), providerId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d), period(%d)", __appId.GetPointer(), __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority, __updateMillis);
 
+       // for updating period
+       if (__updateMillis > 0)
+       {
                SystemTime::GetTicks(this->__lastUpdatedTime);
 
-               __updateTimer.Construct(*this);
-               __updateTimer.StartAsRepeatable(__updateMillis);
+               result r = __updateTimer.Construct(*this);
+               SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
+
+               r = __updateTimer.StartAsRepeatable(__updateMillis);
+               SysTryReturnVoidResult(NID_SHELL, !IsFailed(r), E_SYSTEM, "");
        }
 
-       __pPendingTouchEventList = new ArrayListT<PendingTouchEvent*>();
+       __pPendingTouchEventList = new (nothrow) ArrayListT<PendingTouchEvent*>();
+       SysTryReturnVoidResult(NID_SHELL, __pPendingTouchEventList, E_OUT_OF_MEMORY, "");
        __pPendingTouchEventList->Construct();
+
+       __pAppWidgetRemoteBuffer = new (nothrow) _AppWidgetRemoteBuffer(providerId, instanceId, TYPE_LB, this);
+       SysTryReturnVoidResult(NID_SHELL, __pAppWidgetRemoteBuffer, E_OUT_OF_MEMORY, "");
 }
 
-_AppWidgetContext::~_AppWidgetContext()
+_AppWidgetContext::~_AppWidgetContext(void)
 {
-       SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
+       SysSecureLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", GetProviderId().GetPointer(), GetInstanceId().GetPointer(), GetWidth(), GetHeight(), GetPriority());
 
        __updateTimer.Cancel();
 
        if (__pAppWidgetPopup)
        {
                SysLog(NID_SHELL, "Destroying dangling AppWidgetPopup instance..");
-               __pAppWidgetPopup->OnPopupDestoyed();
                delete __pAppWidgetPopup;
        }
 
@@ -94,10 +131,21 @@ _AppWidgetContext::~_AppWidgetContext()
                __pPendingTouchEventList->RemoveAll();
                delete __pPendingTouchEventList;
        }
+
+       if (__pAppWidgetRemoteBuffer)
+       {
+               delete __pAppWidgetRemoteBuffer;
+       }
+}
+
+_AppContext*
+_AppWidgetContext::GetAppContext(void) const
+{
+       return __pAppContext;
 }
 
 _AppWidgetPopupContext*
-_AppWidgetContext::GetAppWidgetPopup() const
+_AppWidgetContext::GetAppWidgetPopup(void) const
 {
        return __pAppWidgetPopup;
 }
@@ -105,65 +153,92 @@ _AppWidgetContext::GetAppWidgetPopup() const
 void
 _AppWidgetContext::OnAdded(void)
 {
-       SendAddRequest(__width, __height);
+       SendAddRequest(GetWidth(), GetHeight());
 }
 
-void
-_AppWidgetContext::OnRemoved()
+result
+_AppWidgetContext::OnRemoved(bool isTriggeredByViewer)
 {
-       SendRemoveRequest();
+       if (isTriggeredByViewer)
+       {
+               return SendRemoveRequest();
+       }
+       else
+       {
+               std::unique_ptr<char[]> providerId(_StringConverter::CopyToCharArrayN(GetProviderId()));
+               std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(GetInstanceId()));
+
+               int ret = provider_send_deleted(providerId.get(), id.get());
+               SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "Failed to execute provider_send_deleted.");
+       }
+       return E_SUCCESS;
 }
 
 void
 _AppWidgetContext::OnUpdate(const String& argument)
 {
+       SysLog(NID_SHELL, "argument(%ls)", argument.GetPointer());
        ClearLastResult();
 
-       AppWidgetManagerService* pMgrService = AppWidgetManagerService::GetInstance();
-       SysTryReturnVoidResult(NID_SHELL, pMgrService, E_SYSTEM, "[E_SYSTEM] Failed to get an instance of AppWidgetManagerService.");
+       if (this->IsForeground())
+       {
+               result r = this->SendUpdateRequest(GetWidth(), GetHeight(), argument);
+               SysTryLog(NID_SHELL, !IsFailed(r), "Failed to execute SendUpdateRequest.");
+
+               SystemTime::GetTicks(this->__lastUpdatedTime);
+               SysLog(NID_SHELL, "The last updated time is %lld.", this->__lastUpdatedTime);
 
-       // Queueing the pointer of paused context.
-       if (this->IsPaused())
+               __hasPendingRequest = false;
+               __pendingArgument.Clear();
+       }
+       else
        {
-               // Saving the data
+               // Queueing the pointer of background context.
                if (!argument.IsEmpty())
                {
-                       __pendedArgument = argument;
+                       __pendingArgument = argument;
                }
 
                __hasPendingRequest = true;
-               SysLog(NID_SHELL, "Update is requested but the %ls is paused.", (this->GetAppId()).GetPointer());
+               SysLog(NID_SHELL, "Update is requested but the %ls is background.", (this->GetProviderId()).GetPointer());
        }
-       else
-       {
-               this->SendUpdateRequest(__width, __height, argument);
+}
 
-               SystemTime::GetTicks(this->__lastUpdatedTime);
-               SysLog(NID_SHELL, "The last updated time is %lld.", this->__lastUpdatedTime);
+result
+_AppWidgetContext::OnUpdateAsync(_AppContext* pAppContext, const String& argument)
+{
+       ArrayList* pArray = new (std::nothrow) ArrayList();
+       SysTryReturnResult(NID_SHELL, pArray, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
 
-               __hasPendingRequest = false;
-               __pendedArgument.Clear();
-       }
+       pArray->Construct();
+       pArray->Add(pAppContext);
+       pArray->Add(this);
+       pArray->Add(new String(argument));
+
+       result r = Tizen::App::App::GetInstance()->SendUserEvent(LOCAL_EVENT_REQUEST_UPDATE, pArray);
+       SysTryLog(NID_SHELL, !IsFailed(r), "[%s] Propagated.", GetErrorMessage(r));
+       SysLog(NID_SHELL, "UserEvent(%d) is sent for '%ls.%ls'.", LOCAL_EVENT_REQUEST_UPDATE, GetAppId().GetPointer(), GetProviderName().GetPointer() );
+
+       return E_SUCCESS;
 }
 
 void
 _AppWidgetContext::OnResize(int width, int height)
 {
-       SysLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", __providerId.GetPointer(), __instanceId.GetPointer(), __width, __height, __priority);
+       SysSecureLog(NID_SHELL, "appId(%ls), instanceId(%ls), width(%d), height(%d), priority(%d)", GetProviderId().GetPointer(), GetInstanceId().GetPointer(), GetWidth(), GetHeight(), GetPriority());
 
-       __width = width;
-       __height = height;
-       SendResizeRequest(__width, __height);
+       SetWidth(width);
+       SetHeight(height);
+
+       SendResizeRequest(width, height);
 }
 
 void
-_AppWidgetContext::OnForeground()
+_AppWidgetContext::OnForeground(void)
 {
-       SysLog(NID_SHELL, "OnForeground");
-
-       if (__isForeground)
+       if (IsForeground())
        {
-               SysLog(NID_SHELL, "%ls is already resumed.", (this->GetAppId()).GetPointer());
+               SysLog(NID_SHELL, "%ls is already foreground.", (this->GetAppId()).GetPointer());
                return;
        }
 
@@ -171,52 +246,56 @@ _AppWidgetContext::OnForeground()
 
        if (__hasPendingRequest == true)
        {
-               OnUpdate(__pendedArgument);
+               SysLog(NID_SHELL, "There is pending request.");
+               OnUpdateAsync(__pAppContext, __pendingArgument);
        }
        else
        {
-               if (this->GetPeriod() > 0)
+               if (IsUpdatePeriodExpired() == true)
                {
-                       long long currentTicks = 0;
-                       SystemTime::GetTicks(currentTicks);
-
-                       SysLog(NID_SHELL, "current[%lld] - updatedTime[%lld] = [%lld], period[%d]",
-                                       currentTicks, this->GetLastUpdatedTime(), currentTicks - this->GetLastUpdatedTime(), this->GetPeriod());
-
-                       bool isPeriodExpired = (currentTicks - this->GetLastUpdatedTime()) >= (this->GetPeriod());
-                       if (isPeriodExpired)
-                       {
-                               SysLog(NID_SHELL, "The period is expired.");
-                               OnUpdate(L"");
-                       }
+                       SysLog(NID_SHELL, "The period is expired.");
+                       OnUpdateAsync(__pAppContext, L"");
                }
        }
 }
 
-void
-_AppWidgetContext::OnBackground()
+bool
+_AppWidgetContext::IsUpdatePeriodExpired(void) const
 {
-       SysLog(NID_SHELL, "OnBackground");
-
-       if (!__isForeground)
+       if (this->GetPeriod() <= 0)
        {
-               SysLog(NID_SHELL, "%ls is already paused.", (this->GetAppId()).GetPointer());
-               return;
+               return false;
        }
-       __isForeground = false;
+
+       long long currentTicks = 0;
+       SystemTime::GetTicks(currentTicks);
+
+       SysLog(NID_SHELL, "current[%lld] - last updated time[%lld] = [%lld], period[%d]",
+                       currentTicks, this->GetLastUpdatedTime(), currentTicks - this->GetLastUpdatedTime(), this->GetPeriod());
+
+       bool isPeriodExpired = (currentTicks - this->GetLastUpdatedTime()) >= (this->GetPeriod());
+       return isPeriodExpired;
 }
 
-bool
-_AppWidgetContext::IsPaused(void) const
+void
+_AppWidgetContext::OnBackground(void)
 {
-       return __isForeground ? false : true;
+       if (!IsForeground())
+       {
+               SysLog(NID_SHELL, "%ls is already background.", (this->GetAppId()).GetPointer());
+               return;
+       }
+
+       SysLog(NID_SHELL, "OnBackground");
+       __isForeground = false;
 }
 
 void
 _AppWidgetContext::OnPopupCreated(double x, double y, int width, int height)
 {
-       __pAppWidgetPopup = new (std::nothrow) _AppWidgetPopupContext(__userInfo, __providerId, __instanceId, width, height, __priority, this);
-       __pAppWidgetPopup->SetIpcClientId(__ipcClientId);
+       __pAppWidgetPopup = new (nothrow) _AppWidgetPopupContext(this);
+       SysTryReturnVoidResult(NID_SHELL, __pAppWidgetPopup, E_OUT_OF_MEMORY, "");
+
        __pAppWidgetPopup->OnPopupCreated(x, y, width, height);
 }
 
@@ -227,116 +306,134 @@ _AppWidgetContext::OnPopupDestoyed(void)
 
        if (__pAppWidgetPopup)
        {
-               __pAppWidgetPopup->OnPopupDestoyed();
                delete __pAppWidgetPopup;
                __pAppWidgetPopup = null;
        }
 }
 
 result
-_AppWidgetContext::SendAddRequest(int width, int height)
+_AppWidgetContext::SendAddRequest(int width, int height) const
 {
-       std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN() );
+       std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN());
 
-       return SendRequestToApp( __appId, APPWIDGET_ON_ADD, pArgs.get());
+       return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_ADD, pArgs.release());
 }
 
 result
-_AppWidgetContext::SendUpdateRequest(int width, int height, const String& argument)
+_AppWidgetContext::SendUpdateRequest(int width, int height, const String& argument) const
 {
-       std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN() );
+       std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN());
 
-       pArgs->Add(new String(ARG_KEY_ARGUMENT), new String(argument));
+       pArgs->Add(new (nothrow) String(ARG_KEY_ARGUMENT), new (nothrow) String(argument));
 
-       return SendRequestToApp( __appId, APPWIDGET_ON_UPDATE, pArgs.get());
+       return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_UPDATE, pArgs.release());
 }
 
 result
-_AppWidgetContext::SendResizeRequest(int width, int height)
+_AppWidgetContext::SendResizeRequest(int width, int height) const
 {
        std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN() );
 
-       return SendRequestToApp( __appId, APPWIDGET_ON_RESIZE, pArgs.get());
+       return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_RESIZE, pArgs.release());
 }
 
 result
-_AppWidgetContext::SendRemoveRequest()
+_AppWidgetContext::SendRemoveRequest(void) const
 {
-       std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN() );
+       std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN());
 
-       return SendRequestToApp( __appId, APPWIDGET_ON_REMOVE, pArgs.get());
+       return __pAppContext->SendRequestToApp(GetAppId(), APPWIDGET_ON_REMOVE, pArgs.release());
 }
 
 void
 _AppWidgetContext::SendPendingTouchEvent(void)
 {
-       for(int i =0; i< __pPendingTouchEventList->GetCount(); i++)
+       for (int i =0; i< __pPendingTouchEventList->GetCount(); i++)
        {
                PendingTouchEvent* pTouchEvent = null;
                __pPendingTouchEventList->GetAt(i, pTouchEvent);
-               AppWidgetManagerService::GetInstance()->SendTouchEvent(__ipcClientId, __instanceId, pTouchEvent->eventType, pTouchEvent->timeStamp, pTouchEvent->x, pTouchEvent->y);
+               AppWidgetManagerService::GetInstance()->SendTouchEvent(GetClientId(), GetInstanceId(), pTouchEvent->eventType, pTouchEvent->timeStamp, pTouchEvent->x, pTouchEvent->y);
                delete pTouchEvent;
        }
        __pPendingTouchEventList->RemoveAll();
 }
 
-result
-_AppWidgetContext::SendTouchEvent(buffer_event eventType, double timeStamp, double x, double y)
+void
+_AppWidgetContext::OnTouchEventReceived(buffer_event event, double timestamp, double x, double y)
 {
-       if( HasValidClientId() && IsRunning() )
+       if (__pAppContext->GetConnectionState() == CONNECTION_STATE_CONNECTED && __isRemoteBufferProxyCreated)
        {
-               SysAssert(IsSharedMemCreated() == true);
-               SysLog(NID_SHELL, "send IPC message");
-               AppWidgetManagerService::GetInstance()->SendTouchEvent(__ipcClientId, __instanceId, eventType, timeStamp, x, y);
+               SysLog(NID_SHELL, "%d, %f, %f", event, x, y);
+               AppWidgetManagerService::GetInstance()->SendTouchEvent(GetClientId(), GetInstanceId(), event, timestamp, x, y);
        }
        else
        {
-               SysLog(NID_SHELL, "request to start AppControl");
-               __pPendingTouchEventList->Add(new PendingTouchEvent(eventType, timeStamp, x, y));
+               __pPendingTouchEventList->Add(new (nothrow) PendingTouchEvent(event, timestamp, x, y));
 
-               std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN() );
+               if( _AppManagerImpl::GetInstance()->IsRunning(this->GetAppId() ) == false ||
+                       ( __pAppContext->GetConnectionState() == CONNECTION_STATE_CONNECTED && __isRemoteBufferProxyCreated == false))
+               {
+                       SysLog(NID_SHELL, "request to start AppControl");
+                       std::unique_ptr<HashMap, AllElementsDeleter> pArgs (CreateRequestArgsN() );
 
-               pArgs->Add(new String(ARG_KEY_EVENT_TYPE), new String(Integer::ToString(eventType)));
-               pArgs->Add(new String(ARG_KEY_TIME_STAMP), new String(Double::ToString(timeStamp)));
-               pArgs->Add(new String(ARG_KEY_X), new String(Double::ToString(x)));
-               pArgs->Add(new String(ARG_KEY_Y), new String(Double::ToString(y)));
+                       // TODO: consider to remove these unused args.
+                       pArgs->Add(new (nothrow) String(ARG_KEY_EVENT_TYPE), new (nothrow) String(Integer::ToString(event)));
+                       pArgs->Add(new (nothrow) String(ARG_KEY_TIME_STAMP), new (nothrow) String(Double::ToString(timestamp)));
+                       pArgs->Add(new (nothrow) String(ARG_KEY_X), new (nothrow) String(Double::ToString(x)));
+                       pArgs->Add(new (nothrow) String(ARG_KEY_Y), new (nothrow) String(Double::ToString(y)));
 
-               return SendRequestToApp( __appId, APPWIDGET_ON_TOUCH, pArgs.get());
+                       _AppWidgetRequestHelper::SendAppControlRequest(GetAppId(), APPWIDGET_ON_TOUCH, pArgs.get());
+               }
        }
+}
+
+result
+_AppWidgetContext::SyncRemoteBuffer(int width, int height)
+{
+       std::unique_ptr<char[]> providerId(_StringConverter::CopyToCharArrayN(GetProviderId()));
+       std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(GetInstanceId()));
+       std::unique_ptr<char[]> content_info(_StringConverter::CopyToCharArrayN(GetUserInfo()));
+
+       int ret = provider_send_updated(providerId.get(), id.get(), width, height, GetPriority(), content_info.get(), null);
+       SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
+
+       SendPendingTouchEvent();
+       SysLog(NID_SHELL, "Done");
        return E_SUCCESS;
 }
 
 result
-_AppWidgetContext::SendRequestToApp(const AppId& appId, const String& operation, HashMap* pArgs)
+_AppWidgetContext::SyncRemoteBufferForPD(void) const
 {
-       return _AppWidgetContextBase::SendRequestToApp(appId, operation, pArgs);
+       _AppWidgetPopupContext* pPopupContext = GetAppWidgetPopup();
+       SysSecureTryReturnResult(NID_SHELL, pPopupContext , E_SYSTEM, "pPopupContext is null for (%ls)", GetProviderId().GetPointer());
+
+       return pPopupContext->SyncRemoteBuffer();
 }
 
 result
-_AppWidgetContext::RequestUpdateRemote(int width, int height)
+_AppWidgetContext::SendAccessStatus(int accessStatus) const
 {
-       std::unique_ptr<char[]> packageName(_StringConverter::CopyToCharArrayN(__providerId));
-       std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(__instanceId));
-       std::unique_ptr<char[]> content_info(_StringConverter::CopyToCharArrayN(__userInfo));
+       std::unique_ptr<char[]> providerId(_StringConverter::CopyToCharArrayN(GetProviderId()));
+       std::unique_ptr<char[]> id(_StringConverter::CopyToCharArrayN(GetInstanceId()));
 
-       int ret = provider_send_updated(packageName.get(), id.get(), width, height, __priority, content_info.get(), null);
-       SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_updated");
+       int ret = provider_send_access_status(providerId.get(), id.get(), accessStatus);
+       SysTryReturnResult(NID_SHELL, ret >= 0 , E_SYSTEM, "[E_SYSTEM] failed to provider_send_access_status");
 
-       SendPendingTouchEvent();
-       SysLog(NID_SHELL, "Done");
        return E_SUCCESS;
 }
 
 Tizen::Base::Collection::HashMap*
-_AppWidgetContext::CreateRequestArgsN(void)
+_AppWidgetContext::CreateRequestArgsN(void) const
 {
-       HashMap* pArgs = new (std::nothrow) HashMap(SingleObjectDeleter);
+       HashMap* pArgs = new (nothrow) HashMap(SingleObjectDeleter);
        pArgs->Construct();
-       pArgs->Add(new String(ARG_KEY_INSTANCE_ID), new String(__instanceId));
-       pArgs->Add(new String(ARG_KEY_PROVIDER_NAME), new String(__providerName));
-       pArgs->Add(new String(ARG_KEY_USER_INFO), new String(__userInfo));
-       pArgs->Add(new String(ARG_KEY_WIDTH), new String(Integer::ToString(__width)));
-       pArgs->Add(new String(ARG_KEY_HEIGHT), new String(Integer::ToString(__height)));
+
+       pArgs->Add(new (nothrow) String(ARG_KEY_INSTANCE_ID), new (nothrow) String(GetInstanceId()));
+       pArgs->Add(new (nothrow) String(ARG_KEY_PROVIDER_NAME), new (nothrow) String(GetProviderName()));
+       pArgs->Add(new (nothrow) String(ARG_KEY_USER_INFO), new (nothrow) String(GetUserInfo()));
+       pArgs->Add(new (nothrow) String(ARG_KEY_WIDTH), new (nothrow) String(Integer::ToString(GetWidth())));
+       pArgs->Add(new (nothrow) String(ARG_KEY_HEIGHT), new (nothrow) String(Integer::ToString(GetHeight())));
 
        return pArgs;
 }
@@ -344,7 +441,6 @@ _AppWidgetContext::CreateRequestArgsN(void)
 int
 _AppWidgetContext::GetPeriod(void) const
 {
-       SysLog(NID_SHELL, "GetPeriod[%d]", __updateMillis);
        return __updateMillis;
 }
 
@@ -354,15 +450,139 @@ _AppWidgetContext::GetLastUpdatedTime(void) const
        return __lastUpdatedTime;
 }
 
+int
+_AppWidgetContext::GetClientId(void) const
+{
+       return GetAppContext()->GetClientId();
+}
+
+int
+_AppWidgetContext::GetWidth(void) const
+{
+       return __width;
+}
+
+void
+_AppWidgetContext::SetWidth(int width)
+{
+       __width = width;
+}
+
+int
+_AppWidgetContext::GetHeight(void) const
+{
+       return __height;
+}
+
+void
+_AppWidgetContext::SetHeight(int height)
+{
+       __height = height;
+}
+
+String
+_AppWidgetContext::GetProviderId(void) const
+{
+       return __providerId;
+}
+
+/*void
+_AppWidgetContext::SetProviderId(const String& providerId)
+{
+       __providerId = providerId;
+}*/
+
+String
+_AppWidgetContext::GetAppId(void) const
+{
+       return __appId;
+}
+
+int
+_AppWidgetContext::GetPriority(void) const
+{
+       return __priority;
+}
+
+/*void
+_AppWidgetContext::SetPriority(int priority)
+{
+       __priority = priority;
+}*/
+
+String
+_AppWidgetContext::GetProviderName(void) const
+{
+       return __providerName;
+}
+
+bool
+_AppWidgetContext::IsForeground(void) const
+{
+       return __isForeground;
+}
+
+String
+_AppWidgetContext::GetUserInfo(void) const
+{
+       return __userInfo;
+}
+
+/*void
+_AppWidgetContext::SetUserInfo(const String& userInfo)
+{
+       __userInfo = userInfo;
+}*/
+
+String
+_AppWidgetContext::GetInstanceId(void) const
+{
+       return __instanceId;
+}
+
 void
 _AppWidgetContext::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
 {
        if (&timer == &__updateTimer)
        {
-               SysLog(NID_SHELL, "update timer is expired for appWidget app(%ls)..", __providerId.GetPointer());
+               SysLog(NID_SHELL, "update timer is expired for appWidget app(%ls).", GetProviderId().GetPointer());
                OnUpdate(L"");
        }
 }
 
-} } } // Tizen::Shell::App
+void
+_AppWidgetContext::OnDisconnected(void)
+{
+       SysSecureLog(NID_SHELL, "%ls, %ls", GetInstanceId().GetPointer(), GetProviderId().GetPointer());
+
+       __isRemoteBufferProxyCreated = false;
+       if (GetAppWidgetPopup())
+       {
+               OnPopupDestoyed();
+       }
+}
+
+int
+_AppWidgetContext::AcquireRemoteBuffer(int w, int h) const
+{
+       int id = __pAppWidgetRemoteBuffer->Acquire(w, h);
+       if (id != -1)
+       {
+               __isRemoteBufferProxyCreated = true;
+       }
+       return id;
+}
+
+int
+_AppWidgetContext::AcquireRemoteBufferForPD(int w, int h) const
+{
+       _AppWidgetPopupContext* pPopupContext = GetAppWidgetPopup();
+       SysSecureTryReturnResult(NID_SHELL, pPopupContext , E_SYSTEM, "pPopupContext is null for (%ls)", GetProviderId().GetPointer());
+
+       int bufferId = pPopupContext->AcquireRemoteBuffer(w, h);
+       SysSecureTryReturnResult(NID_SHELL, bufferId != -1, E_SYSTEM, "Failed to AcquireRemoteBuffer for (%ls)", GetProviderId().GetPointer());
+
+       return bufferId;
+}
 
+}}}  // Tizen::Shell::App