Remove build warning and add temporary getter of privacy name
[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         ArrayList* pList = static_cast < ArrayList* >(user_data);
58
59         pList->Add(new String(package_id));
60         return true;
61 }
62
63 Tizen::Base::Collection::IList*
64 _PrivacyManagerImpl::GetPrivacyAppPackageListN(void) const
65 {
66         ArrayList* pPackageIdList = null;
67         int ret = 0;
68
69         pPackageIdList = new ArrayList();
70         pPackageIdList->Construct();
71
72         ret = privacy_manager_client_foreach_privacy_packages(GetPrivacyAppPackageListNCallback, pPackageIdList);
73
74         return pPackageIdList;
75 }
76
77 bool GetPrivacyInfoListNCallback(privacy_info_client_s* pPrivacy_info, void* user_data)
78 {
79         result r = E_SUCCESS;
80         ArrayList* pList = static_cast < ArrayList* >(user_data);
81
82         String pPrivacyId = String(pPrivacy_info->privacy_id);
83         bool isEnabled = pPrivacy_info->is_enabled;
84
85         PrivacyInfo* pPrivacyInfo = new PrivacyInfo();
86         r = pPrivacyInfo->Construct(pPrivacyId, isEnabled);
87
88         pList->Add(pPrivacyInfo);
89         return true;
90 }
91
92 Tizen::Base::Collection::IList*
93 _PrivacyManagerImpl::GetPrivacyInfoListN(const Tizen::App::PackageId& packageId) const
94 {
95         int ret = 0;
96         ArrayList* pPrivacyIdList = null;
97         char* pAppId = null;
98
99         pPrivacyIdList = new ArrayList();
100         pPrivacyIdList->Construct();
101
102         pAppId = _StringConverter::CopyToCharArrayN(packageId);
103
104         ret = privacy_manager_client_foreach_get_privacy_info(pAppId, GetPrivacyInfoListNCallback, (void *)pPrivacyIdList);
105         delete[] pAppId;
106
107         return pPrivacyIdList;
108 }
109
110 result
111 _PrivacyManagerImpl::SetAppPackagePrivacy(const Tizen::App::PackageId& packageId, const PrivacyInfo& privacyInfo)
112 {
113         result r = E_SUCCESS;
114         int ret = 0;
115         char* pPackageId = null;
116         char* pPrivacyId = null;
117
118         bool isEnabled = false;
119
120         pPackageId = _StringConverter::CopyToCharArrayN(packageId);
121         pPrivacyId = _StringConverter::CopyToCharArrayN(privacyInfo.GetId());
122         isEnabled = privacyInfo.IsEnabled();
123
124         ret = privacy_manager_client_set_package_privacy(pPackageId, pPrivacyId, isEnabled);
125
126         delete[] pPackageId;
127         delete[] pPrivacyId;
128         return r;
129 }
130
131 }} // Tizen::Security