Merge "Update privilege check logic" into tizen_2.1
[platform/framework/native/appfw.git] / src / security / FSec_PrivacyManagerImpl.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        FSec_PrivacyManagerImpl.cpp
20  * @brief       This is the implementation for the _PrivacyManagerImpl class.
21  */
22
23 #include <new>
24 #include <privacy_manager_client.h>
25 #include <FSecPrivacyManager.h>
26 #include <FBaseSysLog.h>
27 #include "FSec_PrivacyManagerImpl.h"
28 #include <FBase_StringConverter.h>
29 #include <FSecPrivacyInfo.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 _PrivacyManagerImpl::_PrivacyManagerImpl(void)
39 {
40
41 }
42
43 _PrivacyManagerImpl::~_PrivacyManagerImpl(void)
44 {
45
46 }
47
48 const _PrivacyManagerImpl*
49 _PrivacyManagerImpl::GetInstance(PrivacyManager& privacyManager)
50 {
51         return privacyManager.__pPrivacyManagerImpl;
52 }
53
54
55 bool GetPrivacyAppPackageListNCallback(const char *package_id, void* user_data)
56 {
57         result r = E_SUCCESS;
58         ArrayList* pList = static_cast < ArrayList* >(user_data);
59
60         pList->Add(new String(package_id));
61         return true;
62 }
63
64 Tizen::Base::Collection::IList*
65 _PrivacyManagerImpl::GetPrivacyAppPackageListN(void) const
66 {
67         ArrayList* pPackageIdList = null;
68         int ret = 0;
69
70         pPackageIdList = new ArrayList();
71         pPackageIdList->Construct();
72
73         ret = privacy_manager_client_foreach_privacy_packages(GetPrivacyAppPackageListNCallback, pPackageIdList);
74
75         return pPackageIdList;
76 }
77
78 bool GetPrivacyInfoListNCallback(privacy_info_client_s* pPrivacy_info, void* user_data)
79 {
80         result r = E_SUCCESS;
81         ArrayList* pList = static_cast < ArrayList* >(user_data);
82
83         String pPrivacyId = String(pPrivacy_info->privacy_id);
84         bool isEnabled = pPrivacy_info->is_enabled;
85
86         PrivacyInfo* pPrivacyInfo = new PrivacyInfo();
87         r = pPrivacyInfo->Construct(pPrivacyId, isEnabled);
88
89         pList->Add(pPrivacyInfo);
90         return true;
91 }
92
93 Tizen::Base::Collection::IList*
94 _PrivacyManagerImpl::GetPrivacyInfoListN(const Tizen::App::PackageId& packageId) const
95 {
96         int ret = 0;
97         ArrayList* pPrivacyIdList = null;
98         char* pAppId = null;
99
100         pPrivacyIdList = new ArrayList();
101         pPrivacyIdList->Construct();
102
103         pAppId = _StringConverter::CopyToCharArrayN(packageId);
104
105         ret = privacy_manager_client_foreach_get_privacy_info(pAppId, GetPrivacyInfoListNCallback, (void *)pPrivacyIdList);
106         delete[] pAppId;
107
108         return pPrivacyIdList;
109 }
110
111 result
112 _PrivacyManagerImpl::SetAppPackagePrivacy(const Tizen::App::PackageId& packageId, const PrivacyInfo& privacyInfo)
113 {
114         result r = E_SUCCESS;
115         int ret = 0;
116         char* pPackageId = null;
117         char* pPrivacyId = null;
118
119         bool isEnabled = false;
120
121         pPackageId = _StringConverter::CopyToCharArrayN(packageId);
122         pPrivacyId = _StringConverter::CopyToCharArrayN(privacyInfo.GetId());
123         isEnabled = privacyInfo.IsEnabled();
124
125         ret = privacy_manager_client_set_package_privacy(pPackageId, pPrivacyId, isEnabled);
126
127         delete[] pPackageId;
128         delete[] pPrivacyId;
129         return r;
130 }
131
132 }} // Tizen::Security