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
17 #include <system_info.h>
18 #include <klay/filesystem.h>
20 #include <klay/dbus/signal.h>
21 #include <klay/audit/logger.h>
23 #include "policy-client.h"
27 #define VCONFKEY_DPM_MODE_STATE "db/dpm/mode_state"
31 const std::string SIGNAL_OBJECT_PATH = "/org/tizen/DevicePolicyManger/PIL";
32 const std::string SIGNAL_EVENT_INTERFACE = "org.tizen.DevicePolicyManager.PIL.Event";
34 const std::string POLICY_MANAGER_ADDRESS = "/tmp/.device-policy-manager.sock";
39 DevicePolicyClient::DevicePolicyClient() noexcept :
40 clientAddress(POLICY_MANAGER_ADDRESS)
42 mainloop.reset(new ScopedGMainLoop);
45 DevicePolicyClient::~DevicePolicyClient() noexcept
50 int DevicePolicyClient::subscribeSignal(const std::string& name,
51 const SignalHandler& handler,
54 if (!getMaintenanceMode())
58 auto dispatch = [name, handler, data](dbus::Variant variant) {
60 variant.get("(s)", &state);
62 handler(name.c_str(), state, data);
65 dbus::signal::Receiver receiver(SIGNAL_OBJECT_PATH, SIGNAL_EVENT_INTERFACE);
66 return receiver.subscribe(name, dispatch);
67 } catch (runtime::Exception& e) {
73 int DevicePolicyClient::unsubscribeSignal(int id) noexcept
75 if (!getMaintenanceMode())
79 dbus::signal::Receiver receiver(SIGNAL_OBJECT_PATH, SIGNAL_EVENT_INTERFACE);
80 receiver.unsubscribe(id);
82 } catch (runtime::Exception& e) {
88 int DevicePolicyClient::getMaintenanceMode()
92 ::vconf_get_bool(VCONFKEY_DPM_MODE_STATE, &value);