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