2 // Copyright (c) 2013 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FApp_DataControlManager.cpp
19 * @brief This is the implementation for the _DataControlManager class.
23 #include <unique_ptr.h>
28 #include <security-server.h>
30 #include <FBaseInteger.h>
31 #include <FBaseSysLog.h>
32 #include <FBaseColIEnumerator.h>
34 #include <FBase_StringConverter.h>
35 #include <FAppPkg_PackageManagerImpl.h>
36 #include "FApp_DataControlManager.h"
39 using namespace Tizen::Base;
40 using namespace Tizen::Base::Collection;
41 using namespace Tizen::App::Package;
43 namespace Tizen { namespace App
46 _DataControlManager* _DataControlManager::__pDataControlManagerInstance = null;
48 _DataControlManager::_DataControlManager(void)
49 : __pDataControlRequestList(null)
50 , __pProviderList(null)
53 __pDataControlRequestList = new (std::nothrow) HashMap(SingleObjectDeleter);
54 SysTryReturnVoidResult(NID_APP, __pDataControlRequestList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
55 __pDataControlRequestList->Construct();
57 __pProviderList = new (std::nothrow) LinkedList(SingleObjectDeleter);
58 SysTryReturnVoidResult(NID_APP, __pProviderList != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
61 _DataControlManager::~_DataControlManager(void)
63 delete __pDataControlRequestList;
64 delete __pProviderList;
68 _DataControlManager::InitSingleton(void)
70 _DataControlManager* pInst = new (std::nothrow) _DataControlManager();
71 SysTryReturnVoidResult(NID_APP, pInst != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
73 __pDataControlManagerInstance = pInst;
75 std::atexit(DestroySingleton);
80 _DataControlManager::DestroySingleton(void)
82 delete __pDataControlManagerInstance;
86 _DataControlManager::GetInstance(void)
88 static pthread_once_t onceBlock = PTHREAD_ONCE_INIT;
90 if (__pDataControlManagerInstance == null)
93 pthread_once(&onceBlock, InitSingleton);
94 result r = GetLastResult();
97 onceBlock = PTHREAD_ONCE_INIT;
98 SysPropagate(NID_APP, r);
102 return __pDataControlManagerInstance;
106 _DataControlManager::GetRequestCount(void) const
108 return __pDataControlRequestList->GetCount();
112 _DataControlManager::AddRequestInfo(Integer* pReqId, _DataControlRequestInfo* pReqInfo)
114 //SysLog(NID_APP, "DataControl request list count: %d", __pDataControlRequestList->GetCount());
115 return __pDataControlRequestList->Add(pReqId, pReqInfo);
118 _DataControlRequestInfo*
119 _DataControlManager::GetRequestInfo(Integer& reqId)
121 result r = E_SUCCESS;
123 Object* pObj = __pDataControlRequestList->GetValue(reqId);
124 SysTryReturn(NID_APP, pObj != null, null, GetLastResult(), "[%s] Propagating to caller...", GetErrorMessage(GetLastResult()));
126 _DataControlRequestInfo* pReqInfo = dynamic_cast< _DataControlRequestInfo* >(pObj);
127 SysTryReturn(NID_APP, pReqInfo != null, null, r, "[E_SYSTEM] invalid request info");
133 _DataControlManager::RemoveRequestInfo(Integer& reqId)
135 __pDataControlRequestList->Remove(reqId);
139 _DataControlManager::RemoveAllRequests(void)
141 __pDataControlRequestList->RemoveAll();
145 _DataControlManager::GetUniqueId(void)
148 //__sync_fetch_and_add(&__uniqueId, 1);
149 g_atomic_int_inc(&__uniqueId);
154 _DataControlManager::Cache(const AppId& appId)
156 __pProviderList->Add(new (std::nothrow) String(appId));
160 _DataControlManager::IsCached(const AppId& appId)
162 unique_ptr< IEnumerator > pEnum(__pProviderList->GetEnumeratorN());
163 while (pEnum->MoveNext() == E_SUCCESS)
165 String* pCachedAppId = dynamic_cast< String* >(pEnum->GetCurrent());
166 if (pCachedAppId != null && pCachedAppId->Equals(appId) == true)
175 _DataControlManager::AllowAccess(const AppId& appId)
177 //if (IsCached(appId) == false)
179 const PackageId& pkgId = _PackageManagerImpl::GetPackageIdByAppId(appId);
180 unique_ptr< char[] > pPkgId(_StringConverter::CopyToCharArrayN(pkgId));
181 SysTryReturnResult(NID_APP, pPkgId != null, E_SYSTEM, "The method cannot proceed due to a severe system error.");
183 int ret = security_server_app_give_access(pPkgId.get(), -1);
184 SysTryReturnResult(NID_APP, ret == 0, E_SYSTEM,
185 "Failed to call security_server_app_give_access(), provider: %s, ret: %d", pPkgId.get(), ret);
190 SysLog(NID_APP, "[DC_CALLER_SEND] Allow %ls to access", appId.GetPointer());