From c1cdf2dedaae212f2c12f64f275e598662605c02 Mon Sep 17 00:00:00 2001 From: Lee Sung Jun Date: Fri, 20 Oct 2017 14:58:44 +0900 Subject: [PATCH] Add DBus Signal to Deviced during booting and setting Change-Id: Icab9f7b5929c2c807a9d311118318a828a7599e3 Signed-off-by: Lee Sung Jun --- plugin/usb.cpp | 83 ++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/plugin/usb.cpp b/plugin/usb.cpp index d2a4ab3..30e9fbc 100644 --- a/plugin/usb.cpp +++ b/plugin/usb.cpp @@ -29,9 +29,11 @@ #include -#define DEVICED_INTERFACE_USB "org.tizen.system.deviced.Usb" -#define DEVICED_PATH_USB "/Org/Tizen/System/DeviceD/Usb" -#define SIGNAL_STATE_CHANGED "StateChanged" +#define DEVICED_SYSNOTI_INTERFACE \ + "org.tizen.system.deviced", \ + "/Org/Tizen/System/DeviceD/SysNoti", \ + "org.tizen.system.deviced.SysNoti", \ + "control" class DebuggingMode : public GlobalPolicy { public: @@ -68,20 +70,54 @@ public: Client() : GlobalPolicy("usb-client") { PolicyEventNotifier::create("usb-client"); + sendDbusSignal(); } bool apply(const DataType& value) { + int ret; int enable = value; - PolicyEventNotifier::emit("usb-client", enable ? "allowed" : "disallowed"); - return true; + + try { + std::string pid(std::to_string(::getpid())); + std::string state(std::to_string(enable)); + dbus::Connection &systemDBus = dbus::Connection::getSystem(); + systemDBus.methodcall(DEVICED_SYSNOTI_INTERFACE, + -1, "(i)", "(sisss)", + "control", 3, pid.c_str(), "1", state.c_str()).get("(i)", &ret); + } catch(runtime::Exception& e) { + ERROR("Failed to enforce usb client"); + return false; + } + + if (ret == 0) { + PolicyEventNotifier::emit("usb-client", enable ? "allowed" : "disallowed"); + return true; + } + + return false; + } + + void sendDbusSignal(void) + { + int ret; + int enable = get().value; + + try { + std::string pid(std::to_string(::getpid())); + std::string state(std::to_string(enable)); + dbus::Connection &systemDBus = dbus::Connection::getSystem(); + systemDBus.methodcall(DEVICED_SYSNOTI_INTERFACE, + -1, "(i)", "(sisss)", + "control", 3, pid.c_str(), "1", state.c_str()).get("(i)", &ret); + } catch(runtime::Exception& e) { + ERROR("Failed to enforce usb client"); + } } }; class Usb : public AbstractPolicyProvider { public: - Usb(); - int setDebuggingState(bool enable); bool getDebuggingState(); @@ -91,19 +127,12 @@ public: int setClientState(bool enable); bool getClientState(); - void addDbusSignalHandler(void); - private: DebuggingMode debugging; Tethering tethering; Client client; }; -Usb::Usb() -{ - addDbusSignalHandler(); -} - int Usb::setDebuggingState(bool enable) { try { @@ -155,32 +184,6 @@ bool Usb::getClientState() return client.get(); } -void Usb::addDbusSignalHandler(void) -{ - dbus::Connection &systemDBus = dbus::Connection::getSystem(); - - auto onUSBConnectionStateChanged = [this](dbus::Variant parameters) { - unsigned int intparam; - - parameters.get("(u)", &intparam); - - if (intparam == 1 && client.get().value == 0) { - try { - Bundle bundle; - bundle.add("id", "usb-client"); - - runtime::User defaultUser(::tzplatform_getenv(TZ_SYS_DEFAULT_USER)); - Launchpad launchpad(defaultUser.getUid()); - launchpad.launch("org.tizen.dpm-syspopup", bundle); - } catch(runtime::Exception& e) { - ERROR(e.what()); - } - } - }; - - systemDBus.subscribeSignal("", DEVICED_PATH_USB, DEVICED_INTERFACE_USB, SIGNAL_STATE_CHANGED, onUSBConnectionStateChanged); -} - extern "C" { #define PRIVILEGE_USB "http://tizen.org/privilege/dpm.usb" -- 2.34.1