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