2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
18 #include <sys/types.h>
19 #include <sys/inotify.h>
25 #include <tzplatform_config.h>
26 #include <klay/auth/user.h>
27 #include <krate/krate.h>
29 #include <dpm/pil/policy-context.h>
30 #include <dpm/pil/policy-model.h>
31 #include <dpm/pil/policy-storage.h>
32 #include <dpm/pil/app-bundle.h>
33 #include <dpm/pil/launchpad.h>
35 #define NAME_PATTERN "^[A-Za-z_][A-Za-z0-9_.-]*"
39 std::regex krateNamePattern(NAME_PATTERN);
41 bool foreachKrateCallback(const char* name, void* user_data)
43 auto pList = (std::vector<std::string>*)user_data;
44 pList->push_back(name);
48 bool isAllowedName(const std::string& name)
50 if (!std::regex_match(name, krateNamePattern)) {
56 runtime::User user(name);
58 } catch (runtime::Exception& e) {
68 class Zone : public AbstractPolicyProvider {
70 int create(const std::string& name, const std::string& setupWizAppid);
71 int remove(const std::string& name);
72 int getState(const std::string& name);
73 std::vector<std::string> enumerate(int state);
76 int Zone::create(const std::string& name, const std::string& setupWizAppid)
78 if (!isAllowedName(name)) {
84 bundle.add("id", "krate-create");
85 bundle.add("user-data", name);
87 Launchpad launchpad(rmi::Service::getPeerUid());
88 launchpad.launch("org.tizen.dpm-syspopup", bundle);
89 } catch (runtime::Exception& e) {
97 int Zone::remove(const std::string& name)
99 if (getState(name) == 0) {
105 bundle.add("id", "krate-remove");
106 bundle.add("user-data", name);
108 Launchpad launchpad(rmi::Service::getPeerUid());
109 launchpad.launch("org.tizen.dpm-syspopup", bundle);
110 } catch (runtime::Exception& e) {
118 int Zone::getState(const std::string& name)
120 krate_state_e state = (krate_state_e)0;
121 krate_manager_h krate_manager;
123 krate_manager_create(&krate_manager);
124 krate_manager_get_krate_state(krate_manager, name.c_str(), &state);
125 krate_manager_destroy(krate_manager);
130 std::vector<std::string> Zone::enumerate(int state)
132 std::vector<std::string> list;
133 krate_manager_h krate_manager;
135 krate_manager_create(&krate_manager);
136 krate_manager_foreach_name(krate_manager, (krate_state_e)state, foreachKrateCallback, &list);
137 krate_manager_destroy(krate_manager);
144 #define PRIVILEGE "http://tizen.org/privilege/dpm.zone"
146 AbstractPolicyProvider *PolicyFactory(PolicyControlContext& context)
148 Zone *policy = new Zone();
150 context.expose(policy, PRIVILEGE, (int)(Zone::create)(std::string, std::string));
151 context.expose(policy, PRIVILEGE, (int)(Zone::remove)(std::string));
152 context.expose(policy, "", (int)(Zone::getState)(std::string));
153 context.expose(policy, "", (std::vector<std::string>)(Zone::enumerate)(int));