sync with master
[platform/framework/native/appfw.git] / src / security / FSecPrivacyManager.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 /**
19  * @file        FSecPrivacyInfo.cpp
20  * @brief       This is the implementation for the PrivacyInfo class.
21  */
22
23 #include <new>
24 #include <unique_ptr.h>
25 #include <FSecPrivacyManager.h>
26 #include <FBaseSysLog.h>
27 #include <FBaseColIList.h>
28 #include "FSec_PrivacyManagerImpl.h"
29 #include <FSec_AccessController.h>
30
31 using namespace Tizen::Base;
32 using namespace Tizen::Base::Collection;
33 using namespace Tizen::Security;
34
35 namespace Tizen { namespace Security
36 {
37
38 PrivacyManager::PrivacyManager(void)
39         : __pPrivacyManagerImpl(null)
40 {
41
42 }
43
44 PrivacyManager::~PrivacyManager(void)
45 {
46         if (__pPrivacyManagerImpl)
47                 delete __pPrivacyManagerImpl;
48 }
49
50 PrivacyManager*
51 PrivacyManager::GetInstance(void)
52 {
53         static PrivacyManager* pInstance = null;
54         
55         if (pInstance)
56         {
57                 return pInstance;
58         }
59
60         std::unique_ptr< _PrivacyManagerImpl > pImpl(new (std::nothrow) _PrivacyManagerImpl);
61         pInstance  = new (std::nothrow) PrivacyManager;
62
63         pInstance->__pPrivacyManagerImpl = pImpl.release();
64
65         return pInstance;
66 }
67
68 Tizen::Base::Collection::IList*
69 PrivacyManager::GetPrivacyAppPackageListN(void) const
70 {
71         result r = E_SUCCESS;
72
73         r = _AccessController::CheckUserPrivilege(_PRV_PRIVACYMANAGER_READ);
74         SysTryReturn(NID_SEC, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
75
76         return __pPrivacyManagerImpl->GetPrivacyAppPackageListN();
77
78 }
79
80 Tizen::Base::Collection::IList*
81 PrivacyManager::GetPrivacyInfoListN(const Tizen::App::PackageId& packageId) const
82 {
83         result r = E_SUCCESS;
84
85         r = _AccessController::CheckUserPrivilege(_PRV_PRIVACYMANAGER_READ);
86         SysTryReturn(NID_SEC, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
87
88         return __pPrivacyManagerImpl->GetPrivacyInfoListN(packageId);
89 }
90
91 result
92 PrivacyManager::SetAppPackagePrivacy(const Tizen::App::PackageId& packageId, const PrivacyInfo& privacyInfo)
93 {
94         result r = E_SUCCESS;
95
96         r = _AccessController::CheckUserPrivilege(_PRV_PRIVACYMANAGER_WRITE);
97         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
98
99         r = __pPrivacyManagerImpl->SetAppPackagePrivacy(packageId, privacyInfo);
100
101         return r;
102 }
103
104 }} // Tizen::Security