#include <dpm/pil/policy-model.h>
#include <dpm/pil/policy-storage.h>
#include <dpm/pil/policy-event.h>
+#include <dpm/pil/app-bundle.h>
+#include <dpm/pil/launchpad.h>
+
+#include <klay/auth/user.h>
+#include <klay/dbus/variant.h>
+#include <klay/dbus/connection.h>
+
+#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"
class DebuggingMode : public GlobalPolicy<DataSetInt> {
public:
}
};
+class Client : public GlobalPolicy<DataSetInt> {
+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)
{
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" {
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;
}