From: Lee Sung Jun Date: Thu, 12 Oct 2017 05:48:10 +0000 (+0900) Subject: Add USB Client policy X-Git-Tag: submit/tizen_4.0/20171129.062733~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b31c2e0be56fdd43b8754fd244d5240d9ce68a81;p=platform%2Fcore%2Fsecurity%2Fdpm-usb.git Add USB Client policy Change-Id: Ia3ed1e51897872bfb823f8525e70c24a62fcba3b Signed-off-by: Lee Sung Jun --- diff --git a/plugin/usb.cpp b/plugin/usb.cpp index db053ee..d2a4ab3 100644 --- a/plugin/usb.cpp +++ b/plugin/usb.cpp @@ -20,6 +20,18 @@ #include #include #include +#include +#include + +#include +#include +#include + +#include + +#define DEVICED_INTERFACE_USB "org.tizen.system.deviced.Usb" +#define DEVICED_PATH_USB "/Org/Tizen/System/DeviceD/Usb" +#define SIGNAL_STATE_CHANGED "StateChanged" class DebuggingMode : public GlobalPolicy { public: @@ -51,19 +63,46 @@ public: } }; +class Client : public GlobalPolicy { +public: + Client() : GlobalPolicy("usb-client") + { + PolicyEventNotifier::create("usb-client"); + } + + bool apply(const DataType& value) + { + int enable = value; + PolicyEventNotifier::emit("usb-client", enable ? "allowed" : "disallowed"); + return true; + } +}; + class Usb : public AbstractPolicyProvider { public: + Usb(); + int setDebuggingState(bool enable); bool getDebuggingState(); int setTetheringState(bool enable); bool getTetheringState(); + int setClientState(bool enable); + bool getClientState(); + + void addDbusSignalHandler(void); + private: DebuggingMode debugging; Tethering tethering; + Client client; }; +Usb::Usb() +{ + addDbusSignalHandler(); +} int Usb::setDebuggingState(bool enable) { @@ -99,6 +138,48 @@ bool Usb::getTetheringState() return tethering.get(); } +int Usb::setClientState(bool enable) +{ + try { + client.set(enable); + } catch (runtime::Exception& e) { + ERROR(e.what()); + return -1; + } + + return 0; +} + +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" { @@ -111,9 +192,11 @@ AbstractPolicyProvider *PolicyFactory(PolicyControlContext& context) context.expose(policy, PRIVILEGE_DEBUGGING, (int)(Usb::setDebuggingState)(bool)); context.expose(policy, PRIVILEGE_USB, (int)(Usb::setTetheringState)(bool)); + context.expose(policy, PRIVILEGE_USB, (int)(Usb::setClientState)(bool)); context.expose(policy, "", (bool)(Usb::getDebuggingState)()); context.expose(policy, "", (bool)(Usb::getTetheringState)()); + context.expose(policy, "", (bool)(Usb::getClientState)()); return policy; }