#include <tzplatform_config.h>
-#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<DataSetInt> {
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();
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 {
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"