Revert "Add pkg-mgr plugin and modify some code Modify plugin"
[platform/core/security/privacy-manager.git] / client / src / PrivacyManager.cpp
1 /*\r
2  * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved\r
3  *\r
4  *    Licensed under the Apache License, Version 2.0 (the "License");\r
5  *    you may not use this file except in compliance with the License.\r
6  *    You may obtain a copy of the License at\r
7  *\r
8  *        http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  *    Unless required by applicable law or agreed to in writing, software\r
11  *    distributed under the License is distributed on an "AS IS" BASIS,\r
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  *    See the License for the specific language governing permissions and\r
14  *    limitations under the License.\r
15  */\r
16 \r
17 #include <PrivacyManager.h>\r
18 #include <SocketClient.h>\r
19 #include <PrivacyIdInfo.h>\r
20 #include <algorithm> \r
21 #include <memory>\r
22 #include <Utils.h>\r
23 \r
24 std::mutex PrivacyManager::m_singletonMutex;\r
25 PrivacyManager* PrivacyManager::m_pInstance = NULL;\r
26 const std::string PrivacyManager::INTERFACE_NAME("PrivacyInfoService");\r
27 \r
28 PrivacyManager::PrivacyManager(void)\r
29 {\r
30         std::unique_ptr<SocketClient> pSocketClient(new SocketClient(INTERFACE_NAME));\r
31         m_pSocketClient = std::move(pSocketClient);\r
32 }\r
33 \r
34 PrivacyManager*\r
35 PrivacyManager::getInstance(void)\r
36 {\r
37         std::lock_guard<std::mutex> guard(m_singletonMutex);\r
38         if (m_pInstance == NULL)\r
39                 m_pInstance = new PrivacyManager();\r
40         return m_pInstance;\r
41 }\r
42 \r
43 int\r
44 PrivacyManager::addAppPackagePrivacyInfo(const std::string pkgId, const std::list < std::string >& pList)\r
45 {\r
46         int result;\r
47 \r
48         std::list < std::string > privacyList;\r
49 \r
50         result = PrivacyIdInfo::getPrivacyIdListFromPrivilegeList(pList, privacyList);\r
51         if (result != PRIV_MGR_ERROR_SUCCESS )\r
52                 return result;\r
53 \r
54         if (privacyList.size() == 0)\r
55                 return PRIV_MGR_ERROR_SUCCESS;\r
56 \r
57         m_pSocketClient->connect();\r
58         m_pSocketClient->call("addPrivacyInfo", pkgId, privacyList, &result);\r
59         m_pSocketClient->disconnect();\r
60 \r
61         return result;\r
62 }\r
63 \r
64 int\r
65 PrivacyManager::removeAppPackagePrivacyInfo(const std::string pkgId)\r
66 {\r
67         int result;\r
68         m_pSocketClient->connect();\r
69         m_pSocketClient->call("removePrivacyInfo", pkgId, pkgId, &result);\r
70         m_pSocketClient->disconnect();\r
71 \r
72         return result;\r
73 }\r
74 \r
75 int\r
76 PrivacyManager::setPrivacySetting(const std::string pkgId, const std::string privacyId, bool isEnabled)\r
77 {\r
78         int result;\r
79         m_pSocketClient->connect();\r
80         m_pSocketClient->call("setPrivacySetting", pkgId, privacyId, isEnabled, &result);\r
81         m_pSocketClient->disconnect();\r
82 \r
83         return result;\r
84 }\r
85         \r
86 int\r
87 PrivacyManager::getPrivacyAppPackages(std::list < std::string >& pList)\r
88 {\r
89         int result, size;\r
90         std::string temp1;\r
91         SocketClient* p = new SocketClient(INTERFACE_NAME);\r
92         p->connect();\r
93         p->call("getPrivacyAppPackages", &result, &size, &pList);\r
94         p->disconnect();\r
95 \r
96         return result;\r
97 }\r
98 \r
99 int\r
100 PrivacyManager::getAppPackagePrivacyInfo(const std::string pkgId, std::list < std::pair <std::string, bool > > & list)\r
101 {\r
102 \r
103         std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
104 \r
105         int result;\r
106         pSocketClient->connect();\r
107         pSocketClient->call("getAppPackagePrivacyInfo", pkgId, &result, &list);\r
108 \r
109         pSocketClient->disconnect();\r
110 \r
111         for (std::list < std::pair <std::string, bool > >::const_iterator iter = list.begin(); iter != list.end(); ++iter){\r
112                 LOGD(" %s : %d", iter->first.c_str(), iter->second);\r
113         }\r
114 \r
115         return result;\r
116 }\r
117 \r
118 int\r
119 PrivacyManager::isUserPrompted(const std::string pkgId, bool& isPrompted)\r
120 {\r
121         LOGI("enter");\r
122 \r
123         std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
124 \r
125         int result;\r
126         pSocketClient->connect();\r
127         pSocketClient->call("isUserPrompted", pkgId, &result, &isPrompted);\r
128         pSocketClient->disconnect();\r
129 \r
130         LOGI("leave");\r
131 \r
132         return result;\r
133 }\r
134 \r
135 int\r
136 PrivacyManager::setUserPrompted(const std::string pkgId, bool prompted)\r
137 {\r
138         LOGI("enter");\r
139 \r
140         std::unique_ptr <SocketClient> pSocketClient (new SocketClient(INTERFACE_NAME));\r
141 \r
142         int result;\r
143         pSocketClient->connect();\r
144         pSocketClient->call("setUserPrompted", pkgId, prompted, &result);\r
145         pSocketClient->disconnect();\r
146         LOGI("leave");\r
147 \r
148         return result;\r
149 }