Merge from tizen_2.2.1
[platform/framework/native/appfw.git] / src / security / FSecPrivacyManager.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
3 //
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
7 //
8 //     http://www.apache.org/licenses/LICENSE-2.0
9 //
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.
15 //
16
17 /**
18  * @file        FSecPrivacyInfo.cpp
19  * @brief       This is the implementation for the PrivacyInfo class.
20  */
21
22 #include <new>
23 #include <unique_ptr.h>
24 #include <FSecPrivacyManager.h>
25 #include <FBaseSysLog.h>
26 #include <FBaseColIList.h>
27 #include "FSec_PrivacyManagerImpl.h"
28 #include <FSec_AccessController.h>
29
30 using namespace Tizen::Base;
31 using namespace Tizen::Base::Collection;
32 using namespace Tizen::Security;
33
34 namespace Tizen { namespace Security
35 {
36
37 PrivacyManager::PrivacyManager(void)
38         : __pPrivacyManagerImpl(null)
39 {
40
41 }
42
43 PrivacyManager::~PrivacyManager(void)
44 {
45         if (__pPrivacyManagerImpl)
46                 delete __pPrivacyManagerImpl;
47 }
48
49 PrivacyManager*
50 PrivacyManager::GetInstance(void)
51 {
52         static PrivacyManager* pInstance = null;
53         
54         if (pInstance)
55         {
56                 return pInstance;
57         }
58
59         std::unique_ptr< _PrivacyManagerImpl > pImpl(new (std::nothrow) _PrivacyManagerImpl);
60         pInstance  = new (std::nothrow) PrivacyManager;
61
62         pInstance->__pPrivacyManagerImpl = pImpl.release();
63
64         return pInstance;
65 }
66
67 Tizen::Base::Collection::IList*
68 PrivacyManager::GetPrivacyAppPackageListN(void) const
69 {
70         result r = E_SUCCESS;
71
72         r = _AccessController::CheckUserPrivilege(_PRV_PRIVACYMANAGER_READ);
73         SysTryReturn(NID_SEC, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
74
75         return __pPrivacyManagerImpl->GetPrivacyAppPackageListN();
76
77 }
78
79 Tizen::Base::Collection::IList*
80 PrivacyManager::GetPrivacyInfoListN(const Tizen::App::PackageId& packageId) const
81 {
82         result r = E_SUCCESS;
83
84         r = _AccessController::CheckUserPrivilege(_PRV_PRIVACYMANAGER_READ);
85         SysTryReturn(NID_SEC, r == E_SUCCESS, null, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
86
87         return __pPrivacyManagerImpl->GetPrivacyInfoListN(packageId);
88 }
89
90 result
91 PrivacyManager::SetAppPackagePrivacy(const Tizen::App::PackageId& packageId, const PrivacyInfo& privacyInfo)
92 {
93         result r = E_SUCCESS;
94
95         r = _AccessController::CheckUserPrivilege(_PRV_PRIVACYMANAGER_WRITE);
96         SysTryReturnResult(NID_SEC, r == E_SUCCESS, E_PRIVILEGE_DENIED, "The application does not have the privilege to call this method.");
97
98         r = __pPrivacyManagerImpl->SetAppPackagePrivacy(packageId, privacyInfo);
99
100         return r;
101 }
102
103 }} // Tizen::Security