Remove acquire/release methods 69/71769/9
authorJaemin Ryu <jm77.ryu@samsung.com>
Fri, 27 May 2016 05:19:59 +0000 (14:19 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Mon, 30 May 2016 04:31:30 +0000 (13:31 +0900)
Change-Id: I0b9b40b86ea05e20d0cf52302fde2d0bf9c42bd9
Signed-off-by: Jaemin Ryu <jm77.ryu@samsung.com>
25 files changed:
libs/CMakeLists.txt
libs/bluetooth.cpp
libs/dpm/administration.cpp
libs/dpm/application.cpp
libs/dpm/bluetooth.cpp
libs/dpm/password.cpp
libs/dpm/restriction.cpp
libs/dpm/security.cpp
libs/dpm/storage.cpp
libs/dpm/wifi.cpp
libs/dpm/zone.cpp
libs/location.cpp [new file with mode: 0644]
libs/policy-client.h
libs/restriction.cpp
policy/bluetooth.hxx
policy/location.hxx [new file with mode: 0644]
policy/restriction.hxx
server/bluetooth.cpp
server/location.cpp
zone/cli/zone-admin-cli.cpp
zone/libs/zone/app-proxy.cpp
zone/libs/zone/app-proxy.h
zone/libs/zone/package-proxy.cpp
zone/libs/zone/package-proxy.h
zone/libs/zone/zone.cpp

index 1e644f2..64e8e6b 100755 (executable)
@@ -27,6 +27,7 @@ SET(FOUNDATION          policy-client.cpp
 SET(POLICY              administration.cpp
                         application.cpp
                         bluetooth.cpp
+                        location.cpp
                         restriction.cpp
                         security.cpp
                         storage.cpp
index f000c41..aad6ddc 100644 (file)
@@ -139,4 +139,22 @@ bool BluetoothPolicy::isUuidRestricted()
     }
 }
 
+int BluetoothPolicy::setBluetoothTetheringState(bool enable)
+{
+    try {
+        return context->methodCall<int>("BluetoothPolicy::setBluetoothTetheringState", enable);
+    } catch (runtime::Exception& e) {
+        return -1;
+    }
+}
+
+bool BluetoothPolicy::getBluetoothTetheringState()
+{
+    try {
+        return context->methodCall<bool>("BluetoothPolicy::getBluetoothTetheringState");
+    } catch (runtime::Exception &e) {
+        return -1;
+    }
+}
+
 } // namespace DevicePolicyManager
index b2571b1..dd1618b 100644 (file)
@@ -27,27 +27,24 @@ using namespace DevicePolicyManager;
 
 dpm_admin_policy_h dpm_context_acquire_admin_policy(dpm_context_h handle)
 {
-    assert(handle);
-
-    DevicePolicyContext &client = GetDevicePolicyContext(handle);
-    return client.createPolicyInterface<AdministrationPolicy>();
+       return handle;
 }
 
 int dpm_context_release_admin_policy(dpm_admin_policy_h handle)
 {
-    assert(handle);
-    delete &GetPolicyInterface<AdministrationPolicy>(handle);
     return DPM_ERROR_NONE;
 }
 
 int dpm_admin_register_client(dpm_admin_policy_h handle, const char* name)
 {
-    AdministrationPolicy& admin = GetPolicyInterface<AdministrationPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+       AdministrationPolicy admin = client.createPolicyInterface<AdministrationPolicy>();
     return admin.registerPolicyClient(name);
 }
 
 int dpm_admin_deregister_client(dpm_admin_policy_h handle, const char* name)
 {
-    AdministrationPolicy& admin = GetPolicyInterface<AdministrationPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+       AdministrationPolicy admin = client.createPolicyInterface<AdministrationPolicy>();
     return admin.deregisterPolicyClient(name);
 }
index 95d6305..1352b56 100644 (file)
@@ -24,17 +24,12 @@ using namespace DevicePolicyManager;
 
 dpm_application_policy_h dpm_context_acquire_application_policy(dpm_context_h handle)
 {
-    RET_ON_FAILURE(handle, NULL);
-
-    DevicePolicyContext& client = GetDevicePolicyContext(handle);
-    return client.createPolicyInterface<ApplicationPolicy>();
+       return handle;
 }
 
 int dpm_context_release_application_policy(dpm_context_h context, dpm_application_policy_h handle)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
-
-    delete &GetPolicyInterface<ApplicationPolicy>(handle);
     return DPM_ERROR_NONE;
 }
 
@@ -42,7 +37,8 @@ int dpm_application_set_installation_mode(dpm_application_policy_h handle, int m
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    ApplicationPolicy& application = GetPolicyInterface<ApplicationPolicy>(handle);
+    DevicePolicyContext& client = GetDevicePolicyContext(handle);
+    ApplicationPolicy application = client.createPolicyInterface<ApplicationPolicy>();
     return application.setApplicationInstallationMode(mode);
 }
 
@@ -50,7 +46,8 @@ int dpm_application_set_uninstallation_mode(dpm_application_policy_h handle, int
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    ApplicationPolicy& application = GetPolicyInterface<ApplicationPolicy>(handle);
+    DevicePolicyContext& client = GetDevicePolicyContext(handle);
+    ApplicationPolicy application = client.createPolicyInterface<ApplicationPolicy>();
     return application.setApplicationUninstallationMode(mode);
 }
 
@@ -58,7 +55,8 @@ int dpm_application_get_installation_mode(dpm_application_policy_h handle, int *
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    ApplicationPolicy& application = GetPolicyInterface<ApplicationPolicy>(handle);
+    DevicePolicyContext& client = GetDevicePolicyContext(handle);
+    ApplicationPolicy application = client.createPolicyInterface<ApplicationPolicy>();
     int ret = application.getApplicationInstallationMode();
     if (ret < 0) {
         return -1;
@@ -72,7 +70,8 @@ int dpm_application_get_uninstallation_mode(dpm_application_policy_h handle, int
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(mode, DPM_ERROR_INVALID_PARAMETER);
 
-    ApplicationPolicy& application = GetPolicyInterface<ApplicationPolicy>(handle);
+    DevicePolicyContext& client = GetDevicePolicyContext(handle);
+    ApplicationPolicy application = client.createPolicyInterface<ApplicationPolicy>();
     int ret = application.getApplicationUninstallationMode();
     if (ret < 0) {
         return -1;
@@ -86,7 +85,8 @@ int dpm_application_set_package_state(dpm_application_policy_h handle, const cha
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(pkgid, DPM_ERROR_INVALID_PARAMETER);
 
-    ApplicationPolicy& application = GetPolicyInterface<ApplicationPolicy>(handle);
+    DevicePolicyContext& client = GetDevicePolicyContext(handle);
+    ApplicationPolicy application = client.createPolicyInterface<ApplicationPolicy>();
     return application.setApplicationState(pkgid, state);
 }
 
@@ -96,7 +96,8 @@ int dpm_application_get_package_state(dpm_application_policy_h handle, const cha
     RET_ON_FAILURE(pkgid, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-    ApplicationPolicy& application = GetPolicyInterface<ApplicationPolicy>(handle);
+    DevicePolicyContext& client = GetDevicePolicyContext(handle);
+    ApplicationPolicy application = client.createPolicyInterface<ApplicationPolicy>();
     int ret = application.getApplicationState(pkgid);
     if (ret < 0) {
         return -1;
@@ -110,7 +111,8 @@ int dpm_application_add_package_to_blacklist(dpm_application_policy_h handle, co
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(pkgid, DPM_ERROR_INVALID_PARAMETER);
 
-    ApplicationPolicy& application = GetPolicyInterface<ApplicationPolicy>(handle);
+    DevicePolicyContext& client = GetDevicePolicyContext(handle);
+    ApplicationPolicy application = client.createPolicyInterface<ApplicationPolicy>();
     return application.addPackageToBlacklist(pkgid);
 }
 
@@ -119,7 +121,8 @@ int dpm_application_remove_package_from_blacklist(dpm_application_policy_h handl
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(pkgid, DPM_ERROR_INVALID_PARAMETER);
 
-    ApplicationPolicy& application = GetPolicyInterface<ApplicationPolicy>(handle);
+    DevicePolicyContext& client = GetDevicePolicyContext(handle);
+    ApplicationPolicy application = client.createPolicyInterface<ApplicationPolicy>();
     return application.removePackageFromBlacklist(pkgid);
 }
 
@@ -129,7 +132,8 @@ int dpm_application_check_package_is_blacklisted(dpm_application_policy_h handle
     RET_ON_FAILURE(pkgid, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(blacklisted, DPM_ERROR_INVALID_PARAMETER);
 
-    ApplicationPolicy& application = GetPolicyInterface<ApplicationPolicy>(handle);
+    DevicePolicyContext& client = GetDevicePolicyContext(handle);
+    ApplicationPolicy application = client.createPolicyInterface<ApplicationPolicy>();
     int ret = application.checkPackageIsBlacklisted(pkgid);
     if (ret < 0) {
         return -1;
index 8ad172b..f897df5 100644 (file)
@@ -24,17 +24,12 @@ using namespace DevicePolicyManager;
 
 dpm_bluetooth_policy_h dpm_context_acquire_bluetooth_policy(dpm_context_h handle)
 {
-    RET_ON_FAILURE(handle, NULL);
-
-    DevicePolicyContext &client = GetDevicePolicyContext(handle);
-    return client.createPolicyInterface<BluetoothPolicy>();
+       return handle;
 }
 
 int dpm_context_release_bluetooth_policy(dpm_context_h context, dpm_bluetooth_policy_h handle)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
-
-    delete &GetPolicyInterface<BluetoothPolicy>(handle);
     return DPM_ERROR_NONE;
 }
 
@@ -43,7 +38,8 @@ int dpm_bluetooth_add_device_to_blacklist(dpm_bluetooth_policy_h handle, const c
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(mac, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     return bluetooth.addDeviceToBlacklist(mac);
 }
 
@@ -52,7 +48,8 @@ int dpm_bluetooth_remove_device_from_blacklist(dpm_bluetooth_policy_h handle, co
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(mac, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     return bluetooth.removeDeviceFromBlacklist(mac);
 }
 
@@ -60,7 +57,8 @@ int dpm_bluetooth_set_device_restriction(dpm_bluetooth_policy_h handle, const in
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     return bluetooth.setDeviceRestriction(enable);
 }
 
@@ -68,7 +66,8 @@ int dpm_bluetooth_is_device_restricted(dpm_bluetooth_policy_h handle, int *state
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     int ret = bluetooth.isDeviceRestricted();
     if (ret < 0) {
         return -1;
@@ -82,7 +81,8 @@ int dpm_bluetooth_add_uuid_to_blacklist(dpm_bluetooth_policy_h handle, const cha
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(uuid, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     return bluetooth.addUuidToBlacklist(uuid);
 }
 
@@ -91,7 +91,8 @@ int dpm_bluetooth_remove_uuid_from_blacklist(dpm_bluetooth_policy_h handle, cons
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(uuid, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     return bluetooth.removeUuidFromBlacklist(uuid);
 }
 
@@ -99,7 +100,8 @@ int dpm_bluetooth_set_uuid_restriction(dpm_bluetooth_policy_h handle, const int
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     return bluetooth.setUuidRestriction(enable);
 }
 
@@ -107,7 +109,8 @@ int dpm_bluetooth_is_uuid_restricted(dpm_bluetooth_policy_h handle, int *state)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     int ret = bluetooth.isUuidRestricted();
     if (ret < 0) {
         return -1;
index 7422def..37c2939 100644 (file)
@@ -27,18 +27,13 @@ using namespace DevicePolicyManager;
 
 dpm_password_policy_h dpm_context_acquire_password_policy(dpm_context_h handle)
 {
-    RET_ON_FAILURE(handle, NULL);
-
-    DevicePolicyContext &client = GetDevicePolicyContext(handle);
-    return client.createPolicyInterface<PasswordPolicy>();
+       return handle;
 }
 
 int dpm_context_release_password_policy(dpm_context_h context, dpm_password_policy_h handle)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
-
-    delete &GetPolicyInterface<PasswordPolicy>(handle);
-    return 0;
+    return DPM_ERROR_NONE;
 }
 
 int dpm_password_set_quality(dpm_password_policy_h handle, dpm_password_quality_e quality)
@@ -47,7 +42,8 @@ int dpm_password_set_quality(dpm_password_policy_h handle, dpm_password_quality_
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setPasswordPolicyQuality(quality) == 0)
         ret = DPM_ERROR_NONE;
@@ -64,7 +60,8 @@ int dpm_password_get_quality(dpm_password_policy_h handle, dpm_password_quality_
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     password_quality = password.getPasswordPolicyQuality();
     switch (password_quality) {
@@ -105,7 +102,8 @@ int dpm_password_set_minimum_length(dpm_password_policy_h handle, const int valu
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setPasswordPolicyMinimumLength(value) == 0)
         ret = DPM_ERROR_NONE;
@@ -122,7 +120,8 @@ int dpm_password_get_minimum_length(dpm_password_policy_h handle, int *value)
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     *value = password.getPasswordPolicyMinimumLength();
     if (*value >= 0)
@@ -139,7 +138,8 @@ int dpm_password_set_min_complex_chars(dpm_password_policy_h handle, const int v
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setMinPasswordPolicyComplexChars(value) == 0)
         ret = DPM_ERROR_NONE;
@@ -155,7 +155,8 @@ int dpm_password_get_min_complex_chars(dpm_password_policy_h handle, int *value)
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     *value = password.getMinPasswordPolicyComplexChars();
     if (*value >= 0)
@@ -172,7 +173,8 @@ int dpm_password_set_maximum_failed_attempts_for_wipe(dpm_password_policy_h hand
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setMaximumFailedPasswordPolicyForWipe(value) == 0)
         ret = DPM_ERROR_NONE;
@@ -189,7 +191,8 @@ int dpm_password_get_maximum_failed_attempts_for_wipe(dpm_password_policy_h hand
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     *value = password.getMaximumFailedPasswordPolicyForWipe();
     if (*value >= 0)
@@ -206,7 +209,8 @@ int dpm_password_set_expires(dpm_password_policy_h handle, const int value)
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setPasswordPolicyExpires(value) == 0)
         ret = DPM_ERROR_NONE;
@@ -222,7 +226,8 @@ int dpm_password_get_expires(dpm_password_policy_h handle, int *value)
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     *value = password.getPasswordPolicyExpires();
     if (*value >= 0)
@@ -239,7 +244,8 @@ int dpm_password_set_history(dpm_password_policy_h handle, const int value)
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setPasswordPolicyHistory(value) == 0)
         ret = DPM_ERROR_NONE;
@@ -255,7 +261,8 @@ int dpm_password_get_history(dpm_password_policy_h handle, int *value)
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     *value = password.getPasswordPolicyHistory();
     if (*value >= 0)
@@ -273,7 +280,8 @@ int dpm_password_set_pattern(dpm_password_policy_h handle, const char *pattern)
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(pattern, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setPasswordPolicyPattern(pattern) == 0)
         ret = DPM_ERROR_NONE;
@@ -290,7 +298,8 @@ int dpm_password_reset(dpm_password_policy_h handle, const char *passwd)
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(passwd, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.resetPasswordPolicy(passwd) == 0)
         ret = DPM_ERROR_NONE;
@@ -306,7 +315,8 @@ int dpm_password_enforce_change(dpm_password_policy_h handle)
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.enforcePasswordPolicyChange() == 0)
         ret = DPM_ERROR_NONE;
@@ -322,7 +332,8 @@ int dpm_password_set_max_inactivity_time_device_lock(dpm_password_policy_h handl
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setMaxInactivityTimeDeviceLock(value) == 0)
         ret = DPM_ERROR_NONE;
@@ -339,7 +350,8 @@ int dpm_password_get_max_inactivity_time_device_lock(dpm_password_policy_h handl
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     *value = password.getMaxInactivityTimeDeviceLock();
 
@@ -357,7 +369,8 @@ int dpm_password_set_status(dpm_password_policy_h handle, dpm_password_status_e
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setPasswordPolicyStatus(status) == 0)
         ret = DPM_ERROR_NONE;
@@ -373,7 +386,8 @@ int dpm_password_delete_pattern(dpm_password_policy_h handle)
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.deletePasswordPolicyPattern() == 0)
         ret = DPM_ERROR_NONE;
@@ -390,7 +404,8 @@ int dpm_password_get_pattern(dpm_password_policy_h handle, char **pattern)
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(*pattern, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.getPasswordPolicyPattern().size() > 0) {
         *pattern = ::strdup(password.getPasswordPolicyPattern().c_str());
@@ -407,7 +422,8 @@ int dpm_password_set_maximum_character_occurrences(dpm_password_policy_h handle,
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setMaximumCharacterOccurrences(value) == 0)
         ret = DPM_ERROR_NONE;
@@ -424,9 +440,10 @@ int dpm_password_get_maximum_character_occurrences(dpm_password_policy_h handle,
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
-    *value = password.getMaximumCharacterOccurrences();
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
+    *value = password.getMaximumCharacterOccurrences();
     if (*value >= 0)
         ret = DPM_ERROR_NONE;
     else
@@ -441,7 +458,8 @@ int dpm_password_set_maximum_numeric_sequence_length(dpm_password_policy_h handl
 
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
     if (password.setMaximumNumericSequenceLength(value) == 0)
         ret = DPM_ERROR_NONE;
@@ -458,9 +476,10 @@ int dpm_password_get_maximum_numeric_sequence_length(dpm_password_policy_h handl
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
 
-    PasswordPolicy &password = GetPolicyInterface<PasswordPolicy>(handle);
-    *value = password.getMaximumNumericSequenceLength();
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    PasswordPolicy password = client.createPolicyInterface<PasswordPolicy>();
 
+    *value = password.getMaximumNumericSequenceLength();
     if (*value >= 0)
         ret = DPM_ERROR_NONE;
     else
index b90d820..9805e44 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "restriction.h"
 #include "restriction.hxx"
+#include "location.hxx"
 #include "bluetooth.hxx"
 
 #include "debug.h"
@@ -25,17 +26,12 @@ using namespace DevicePolicyManager;
 
 dpm_restriction_policy_h dpm_context_acquire_restriction_policy(dpm_context_h handle)
 {
-    RET_ON_FAILURE(handle, NULL);
-
-    DevicePolicyContext &client = GetDevicePolicyContext(handle);
-    return client.createPolicyInterface<RestrictionPolicy>();
+       return handle;
 }
 
 int dpm_context_release_restriction_policy(dpm_context_h context, dpm_restriction_policy_h handle)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
-
-    delete &GetPolicyInterface<RestrictionPolicy>(handle);
     return DPM_ERROR_NONE;
 }
 
@@ -43,8 +39,9 @@ int dpm_restriction_set_camera_state(dpm_restriction_policy_h handle, int enable
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restrict = GetPolicyInterface<RestrictionPolicy>(handle);
-       return restrict.setCameraState(enable);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
+       return restriction.setCameraState(enable);
 }
 
 int dpm_restriction_get_camera_state(dpm_restriction_policy_h handle, int *state)
@@ -52,7 +49,8 @@ int dpm_restriction_get_camera_state(dpm_restriction_policy_h handle, int *state
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        int ret = restriction.getCameraState();
     if (ret < 0) {
         return -1;
@@ -66,15 +64,17 @@ int dpm_restriction_set_microphone_state(dpm_restriction_policy_h handle, int en
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
-         return restriction.setMicrophoneState(enable);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
+    return restriction.setMicrophoneState(enable);
 }
 
 int dpm_restriction_get_microphone_state(dpm_restriction_policy_h handle, int *state)
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        int ret = restriction.getMicrophoneState();
     if (ret < 0) {
         return -1;
@@ -87,8 +87,9 @@ int dpm_restriction_set_location_state(dpm_restriction_policy_h handle, int enab
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
-    return restriction.setLocationState(enable);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    LocationPolicy location = client.createPolicyInterface<LocationPolicy>();
+    return location.setLocationState(enable);
 }
 
 int dpm_restriction_get_location_state(dpm_restriction_policy_h handle, int *state)
@@ -96,8 +97,9 @@ int dpm_restriction_get_location_state(dpm_restriction_policy_h handle, int *sta
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
-    int ret = restriction.getLocationState();
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    LocationPolicy location = client.createPolicyInterface<LocationPolicy>();
+    int ret = location.getLocationState();
     if (ret < 0) {
         return -1;
     }
@@ -110,7 +112,8 @@ int dpm_restriction_set_usb_debugging_state(dpm_restriction_policy_h handle, int
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        return restriction.setUsbDebuggingState(enable);
 }
 
@@ -119,7 +122,8 @@ int dpm_restriction_get_usb_debugging_state(dpm_restriction_policy_h handle, int
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        int ret = restriction.getUsbDebuggingState();
     if (ret < 0) {
         return -1;
@@ -132,7 +136,8 @@ int dpm_restriction_set_usb_tethering_state(dpm_restriction_policy_h handle, int
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
     return restriction.setUsbTetheringState(enable);
 }
 
@@ -141,7 +146,8 @@ int dpm_restriction_get_usb_tethering_state(dpm_restriction_policy_h handle, int
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
     int ret = restriction.getUsbTetheringState();
     if (ret < 0) {
         return -1;
@@ -154,7 +160,8 @@ int dpm_restriction_set_settings_changes_state(dpm_restriction_policy_h handle,
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        return restriction.setSettingsChangesState(enable);
 }
 
@@ -163,7 +170,8 @@ int dpm_restriction_get_settings_changes_state(dpm_restriction_policy_h handle,
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        int ret = restriction.getSettingsChangesState();
     if (ret < 0) {
         return -1;
@@ -177,7 +185,8 @@ int dpm_restriction_set_external_storage_state(dpm_restriction_policy_h handle,
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        return restriction.setExternalStorageState(enable);
 }
 
@@ -186,7 +195,8 @@ int dpm_restriction_get_external_storage_state(dpm_restriction_policy_h handle,
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        int ret = restriction.getExternalStorageState();
     if (ret < 0) {
         return 0;
@@ -199,7 +209,8 @@ int dpm_restriction_set_clipboard_state(dpm_restriction_policy_h handle, int ena
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        return restriction.setClipboardState(enable);
 }
 
@@ -208,7 +219,8 @@ int dpm_restriction_get_clipboard_state(dpm_restriction_policy_h handle, int *st
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
        RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-       RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
        int ret = restriction.getClipboardState();
     if (ret < 0) {
         return -1;
@@ -221,7 +233,8 @@ int dpm_restriction_set_wifi_state(dpm_restriction_policy_h handle, int enable)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
     return restriction.setWifiState(enable);
 }
 
@@ -230,7 +243,8 @@ int dpm_restriction_get_wifi_state(dpm_restriction_policy_h handle, int *state)
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
     int ret = restriction.getWifiState();
     if (ret < 0) {
         return -1;
@@ -243,7 +257,8 @@ int dpm_restriction_set_wifi_hotspot_state(dpm_restriction_policy_h handle, int
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
     return restriction.setWifiHotspotState(enable);
 }
 
@@ -252,7 +267,8 @@ int dpm_restriction_get_wifi_hotspot_state(dpm_restriction_policy_h handle, int
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    RestrictionPolicy restriction = client.createPolicyInterface<RestrictionPolicy>();
     int ret = restriction.getWifiHotspotState();
     if (ret < 0) {
         return -1;
@@ -265,8 +281,9 @@ int dpm_restriction_set_bluetooth_tethering_state(dpm_restriction_policy_h handl
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
-    return restriction.setBluetoothTetheringState(enable);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
+    return bluetooth.setBluetoothTetheringState(enable);
 }
 
 int dpm_restriction_get_bluetooth_tethering_state(dpm_restriction_policy_h handle, int *state)
@@ -274,8 +291,9 @@ int dpm_restriction_get_bluetooth_tethering_state(dpm_restriction_policy_h handl
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-    RestrictionPolicy& restriction = GetPolicyInterface<RestrictionPolicy>(handle);
-    int ret = restriction.getBluetoothTetheringState();
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
+    int ret = bluetooth.getBluetoothTetheringState();
     if (ret < 0) {
         return -1;
     }
@@ -287,7 +305,8 @@ int dpm_restriction_set_bluetooth_mode_change_state(dpm_restriction_policy_h han
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     return bluetooth.setModeChangeState(enable);
 }
 
@@ -296,7 +315,8 @@ int dpm_restriction_get_bluetooth_mode_change_state(dpm_restriction_policy_h han
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     int ret = bluetooth.getModeChangeState();
     if (ret < 0) {
         return -1;
@@ -310,7 +330,8 @@ int dpm_restriction_set_bluetooth_desktop_connectivity_state(dpm_restriction_pol
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     return bluetooth.setDesktopConnectivityState(enable);
 }
 
@@ -319,7 +340,8 @@ int dpm_restriction_get_bluetooth_desktop_connectivity_state(dpm_restriction_pol
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
 
-    BluetoothPolicy& bluetooth = GetPolicyInterface<BluetoothPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    BluetoothPolicy bluetooth = client.createPolicyInterface<BluetoothPolicy>();
     int ret = bluetooth.getDesktopConnectivityState();
     if (ret < 0) {
         return -1;
index 47dd273..3900af8 100644 (file)
@@ -24,16 +24,11 @@ using namespace DevicePolicyManager;
 
 dpm_security_policy_h dpm_context_acquire_security_policy(dpm_context_h handle)
 {
-    RET_ON_FAILURE(handle, NULL);
-
-    DevicePolicyContext &client = GetDevicePolicyContext(handle);
-    return client.createPolicyInterface<SecurityPolicy>();
+       return handle;
 }
 
 int dpm_context_release_security_policy(dpm_context_h context, dpm_security_policy_h handle)
 {
-    RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
-    delete &GetPolicyInterface<SecurityPolicy>(handle);
     return DPM_ERROR_NONE;
 }
 
@@ -41,7 +36,8 @@ int dpm_security_lockout_device(dpm_security_policy_h handle)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    SecurityPolicy& security = GetPolicyInterface<SecurityPolicy>(handle);
+       DevicePolicyContext &context = GetDevicePolicyContext(handle);
+       SecurityPolicy security = context.createPolicyInterface<SecurityPolicy>();
     return security.lockoutDevice();
 }
 
@@ -49,7 +45,8 @@ int dpm_security_lockout_screen(dpm_security_policy_h handle)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    SecurityPolicy& security = GetPolicyInterface<SecurityPolicy>(handle);
+       DevicePolicyContext &context = GetDevicePolicyContext(handle);
+       SecurityPolicy security = context.createPolicyInterface<SecurityPolicy>();
     return security.lockoutScreen();
 }
 
@@ -57,7 +54,8 @@ int dpm_security_set_internal_storage_encryption(dpm_security_policy_h handle, c
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    SecurityPolicy& security = GetPolicyInterface<SecurityPolicy>(handle);
+       DevicePolicyContext &context = GetDevicePolicyContext(handle);
+       SecurityPolicy security = context.createPolicyInterface<SecurityPolicy>();
     return security.setInternalStorageEncryption(encrypt);
 }
 
@@ -66,7 +64,8 @@ int dpm_security_is_internal_storage_encrypted(dpm_security_policy_h handle, int
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-    SecurityPolicy& security = GetPolicyInterface<SecurityPolicy>(handle);
+       DevicePolicyContext &context = GetDevicePolicyContext(handle);
+       SecurityPolicy security = context.createPolicyInterface<SecurityPolicy>();
     int ret = security.isInternalStorageEncrypted();
     if (ret < 0) {
         return -1;
@@ -79,7 +78,8 @@ int dpm_security_set_external_storage_encryption(dpm_security_policy_h handle, c
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    SecurityPolicy& security = GetPolicyInterface<SecurityPolicy>(handle);
+       DevicePolicyContext &context = GetDevicePolicyContext(handle);
+       SecurityPolicy security = context.createPolicyInterface<SecurityPolicy>();
     return security.setExternalStorageEncryption(encrypt);
 }
 
@@ -88,7 +88,8 @@ int dpm_security_is_external_storage_encrypted(dpm_security_policy_h handle, int
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(state, DPM_ERROR_INVALID_PARAMETER);
 
-    SecurityPolicy& security = GetPolicyInterface<SecurityPolicy>(handle);
+       DevicePolicyContext &context = GetDevicePolicyContext(handle);
+       SecurityPolicy security = context.createPolicyInterface<SecurityPolicy>();
     int ret = security.isExternalStorageEncrypted();
     if (ret < 0) {
         return -1;
index a489f1c..9859c36 100644 (file)
@@ -24,16 +24,12 @@ using namespace DevicePolicyManager;
 
 dpm_storage_policy_h dpm_context_acquire_storage_policy(dpm_context_h handle)
 {
-       RET_ON_FAILURE(handle, NULL);
-
-    DevicePolicyContext &client = GetDevicePolicyContext(handle);
-    return client.createPolicyInterface<StoragePolicy>();
+       return handle;
 }
 
 int dpm_context_release_storage_policy(dpm_storage_policy_h handle)
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
-    delete &GetPolicyInterface<StoragePolicy>(handle);
     return DPM_ERROR_NONE;
 }
 
@@ -41,6 +37,7 @@ int dpm_storage_wipe_data(dpm_storage_policy_h handle, const dpm_wipe_type_e typ
 {
        RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-       StoragePolicy& storagePolicy = GetPolicyInterface<StoragePolicy>(handle);
-       return storagePolicy.wipeData(type);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    StoragePolicy storage = client.createPolicyInterface<StoragePolicy>();
+       return storage.wipeData(type);
 }
index d13565c..d184e8b 100644 (file)
@@ -24,17 +24,12 @@ using namespace DevicePolicyManager;
 
 dpm_wifi_policy_h dpm_context_acquire_wifi_policy(dpm_context_h handle)
 {
-    RET_ON_FAILURE(handle, NULL);
-
-    DevicePolicyContext &client = GetDevicePolicyContext(handle);
-    return client.createPolicyInterface<WifiPolicy>();
+       return handle;
 }
 
 int dpm_context_release_wifi_policy(dpm_context_h context, dpm_wifi_policy_h handle)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
-
-    delete &GetPolicyInterface<WifiPolicy>(handle);
     return DPM_ERROR_NONE;
 }
 
@@ -42,7 +37,8 @@ int dpm_wifi_set_profile_change_restriction(dpm_wifi_policy_h handle, int enable
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    WifiPolicy& wifi = GetPolicyInterface<WifiPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    WifiPolicy wifi = client.createPolicyInterface<WifiPolicy>();
     return wifi.setProfileChangeRestriction(enable);
 }
 
@@ -51,7 +47,8 @@ int dpm_wifi_is_profile_change_restricted(dpm_wifi_policy_h handle, int *enable)
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
 
-    WifiPolicy& wifi = GetPolicyInterface<WifiPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    WifiPolicy wifi = client.createPolicyInterface<WifiPolicy>();
     *enable = wifi.isProfileChangeRestricted();
 
     return DPM_ERROR_NONE;
@@ -61,7 +58,8 @@ int dpm_wifi_set_network_access_restriction(dpm_wifi_policy_h handle, int enable
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
 
-    WifiPolicy& wifi = GetPolicyInterface<WifiPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    WifiPolicy wifi = client.createPolicyInterface<WifiPolicy>();
     return wifi.setNetworkAccessRestriction(enable);
 }
 
@@ -70,7 +68,8 @@ int dpm_wifi_is_network_access_restricted(dpm_wifi_policy_h handle, int *enable)
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
 
-    WifiPolicy& wifi = GetPolicyInterface<WifiPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    WifiPolicy wifi = client.createPolicyInterface<WifiPolicy>();
     *enable = wifi.isNetworkAccessRestricted();
 
     return DPM_ERROR_NONE;
@@ -81,7 +80,8 @@ int dpm_wifi_add_ssid_to_blocklist(dpm_wifi_policy_h handle, const char* ssid)
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(ssid, DPM_ERROR_INVALID_PARAMETER);
 
-    WifiPolicy& wifi = GetPolicyInterface<WifiPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    WifiPolicy wifi = client.createPolicyInterface<WifiPolicy>();
     return wifi.addSsidToBlocklist(ssid);
 }
 
@@ -90,6 +90,7 @@ int dpm_wifi_remove_ssid_from_blocklist(dpm_wifi_policy_h handle, const char* ss
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(ssid, DPM_ERROR_INVALID_PARAMETER);
 
-    WifiPolicy& wifi = GetPolicyInterface<WifiPolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    WifiPolicy wifi = client.createPolicyInterface<WifiPolicy>();
     return wifi.removeSsidFromBlocklist(ssid);
 }
index 7ef5023..101eebb 100644 (file)
@@ -25,18 +25,13 @@ using namespace DevicePolicyManager;
 
 dpm_zone_policy_h dpm_context_acquire_zone_policy(dpm_context_h handle)
 {
-    RET_ON_FAILURE(handle, NULL);
-
-    DevicePolicyContext &client = GetDevicePolicyContext(handle);
-    return client.createPolicyInterface<ZonePolicy>();
+       return handle;
 }
 
 int dpm_context_release_zone_policy(dpm_context_h context, dpm_zone_policy_h handle)
 {
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
-
-    delete &GetPolicyInterface<ZonePolicy>(handle);
-    return 0;
+    return DPM_ERROR_NONE;
 }
 
 int dpm_zone_create(dpm_zone_policy_h handle, const char* name, const char* pkgname)
@@ -45,7 +40,8 @@ int dpm_zone_create(dpm_zone_policy_h handle, const char* name, const char* pkgn
     RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(pkgname, DPM_ERROR_INVALID_PARAMETER);
 
-    ZonePolicy& zone = GetPolicyInterface<ZonePolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    ZonePolicy zone = client.createPolicyInterface<ZonePolicy>();
     return zone.createZone(name, pkgname);
 }
 
@@ -54,7 +50,8 @@ int dpm_zone_destroy(dpm_zone_policy_h handle, const char* name)
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(name, DPM_ERROR_INVALID_PARAMETER);
 
-    ZonePolicy& zone = GetPolicyInterface<ZonePolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    ZonePolicy zone = client.createPolicyInterface<ZonePolicy>();
     return zone.removeZone(name);
 }
 
@@ -64,7 +61,8 @@ dpm_zone_iterator_h dpm_zone_create_iterator(dpm_zone_policy_h handle)
 {
     RET_ON_FAILURE(handle, NULL);
 
-    ZonePolicy& zone = GetPolicyInterface<ZonePolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    ZonePolicy zone = client.createPolicyInterface<ZonePolicy>();
 
     return reinterpret_cast<dpm_zone_iterator_h>(new dpm_zone_iterator(zone.getZoneList()));
 }
@@ -99,7 +97,8 @@ int dpm_zone_foreach_name(dpm_zone_policy_h handle,
     RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(callback, DPM_ERROR_INVALID_PARAMETER);
 
-    ZonePolicy& zone = GetPolicyInterface<ZonePolicy>(handle);
+    DevicePolicyContext &client = GetDevicePolicyContext(handle);
+    ZonePolicy zone = client.createPolicyInterface<ZonePolicy>();
     std::vector<std::string> list = zone.getZoneList();
     for (std::vector<std::string>::iterator it = list.begin();
          it != list.end(); it++) {
diff --git a/libs/location.cpp b/libs/location.cpp
new file mode 100644 (file)
index 0000000..b530bea
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#include "location.hxx"
+#include "audit/logger.h"
+
+namespace DevicePolicyManager {
+
+LocationPolicy::LocationPolicy(PolicyControlContext& ctxt)
+       : context(ctxt)
+{
+}
+
+LocationPolicy::~LocationPolicy()
+{
+}
+
+int LocationPolicy::setLocationState(int enable)
+{
+       try {
+               return context->methodCall<int>("LocationPolicy::setLocationState", enable);
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+int LocationPolicy::getLocationState()
+{
+       try {
+               return context->methodCall<int>("LocationPolicy::getLocationState");
+       } catch (runtime::Exception& e) {
+               return -1;
+       }
+}
+
+} //namespace DevicePolicyManager
index 04cadbd..7786ff1 100644 (file)
@@ -44,9 +44,9 @@ public:
     int unsubscribeSignal(int subscriberId);
 
     template<typename Policy, typename... Args>
-    Policy* createPolicyInterface(Args&&... args) noexcept
+    Policy createPolicyInterface(Args&&... args) noexcept
     {
-        return new Policy(getPolicyControlContext(), std::forward<Args>(args)...);
+        return Policy(getPolicyControlContext(), std::forward<Args>(args)...);
     }
 
 private:
@@ -58,11 +58,5 @@ private:
     PolicyControlContext client;
 };
 
-template<typename Policy>
-Policy& GetPolicyInterface(void* handle)
-{
-    return *reinterpret_cast<Policy*>(handle);
-}
-
 DevicePolicyContext& GetDevicePolicyContext(void* handle);
 #endif //__POLICY_CLIENT_H__
index 3ae91d4..b0217ce 100644 (file)
@@ -154,24 +154,6 @@ int RestrictionPolicy::getExternalStorageState()
        }
 }
 
-int RestrictionPolicy::setLocationState(int enable)
-{
-       try {
-               return context->methodCall<int>("RestrictionPolicy::setLocationState", enable);
-       } catch (runtime::Exception& e) {
-               return -1;
-       }
-}
-
-int RestrictionPolicy::getLocationState()
-{
-       try {
-               return context->methodCall<int>("RestrictionPolicy::getLocationState");
-       } catch (runtime::Exception& e) {
-               return -1;
-       }
-}
-
 int RestrictionPolicy::setWifiState(bool enable)
 {
     try {
@@ -208,22 +190,4 @@ bool RestrictionPolicy::getWifiHotspotState()
     }
 }
 
-int RestrictionPolicy::setBluetoothTetheringState(bool enable)
-{
-    try {
-        return context->methodCall<int>("RestrictionPolicy::setBluetoothTetheringState", enable);
-    } catch (runtime::Exception& e) {
-        return -1;
-    }
-}
-
-bool RestrictionPolicy::getBluetoothTetheringState()
-{
-    try {
-        return context->methodCall<bool>("RestrictionPolicy::getBluetoothTetheringState");
-    } catch (runtime::Exception &e) {
-        return -1;
-    }
-}
-
 } //namespace DevicePolicyManager
index 814b99d..4ab30a3 100644 (file)
@@ -49,6 +49,9 @@ public:
     int setUuidRestriction(const bool enable);
     bool isUuidRestricted();
 
+    int setBluetoothTetheringState(bool enable);
+    bool getBluetoothTetheringState();
+
 private:
     PolicyControlContext& context;
 };
diff --git a/policy/location.hxx b/policy/location.hxx
new file mode 100644 (file)
index 0000000..c401d57
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License
+ */
+
+#ifndef __LOCATION_POLICY__
+#define __LOCATION_POLICY__
+
+#include "data-type.h"
+#include "policy-context.hxx"
+
+namespace DevicePolicyManager {
+
+class LocationPolicy {
+public:
+       LocationPolicy(PolicyControlContext& ctxt);
+       ~LocationPolicy();
+
+       int setLocationState(int enable);
+       int getLocationState();
+
+private:
+       PolicyControlContext& context;
+};
+
+} // namespace DevicePolicyManager
+
+#endif /* __LOCATION_POLICY__ */
index e6d5087..81c0e39 100644 (file)
@@ -50,18 +50,12 @@ public:
        int setExternalStorageState(int enable);
        int getExternalStorageState();
 
-       int setLocationState(int enable);
-       int getLocationState();
-
        int setWifiState(bool enable);
        bool getWifiState();
 
        int setWifiHotspotState(bool enable);
        bool getWifiHotspotState();
 
-       int setBluetoothTetheringState(bool enable);
-       bool getBluetoothTetheringState();
-
 private:
        PolicyControlContext& context;
 };
index 6fcde5f..67e093d 100644 (file)
@@ -77,34 +77,8 @@ void bluetoothAdapterStateChangedCb(int result, bt_adapter_state_e state, void *
 } // namespace
 
 
-#define CONSTRUCTOR __attribute__ ((constructor))
-
 namespace DevicePolicyManager {
 
-extern RestrictionPolicy restrictionPolicy;
-
-static void CONSTRUCTOR ContributeRestrictionPolicy()
-{
-    PolicyControlContext& context = Server::instance();
-
-    context.registerParametricMethod(&restrictionPolicy, (int)(RestrictionPolicy::setBluetoothTetheringState)(bool));
-    context.registerNonparametricMethod(&restrictionPolicy, (bool)(RestrictionPolicy::getBluetoothTetheringState));
-
-    context.createNotification("bluetooth-tethering");
-}
-
-int RestrictionPolicy::setBluetoothTetheringState(bool enable)
-{
-    SetPolicyAllowed(context, "bluetooth-tethering", enable);
-    return 0;
-}
-
-bool RestrictionPolicy::getBluetoothTetheringState()
-{
-    return IsPolicyAllowed(context, "bluetooth-tethering");
-}
-
-
 BluetoothPolicy::BluetoothPolicy(PolicyControlContext& ctxt) :
     context(ctxt)
 {
@@ -122,8 +96,12 @@ BluetoothPolicy::BluetoothPolicy(PolicyControlContext& ctxt) :
     ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::removeUuidFromBlacklist)(std::string));
     ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::setUuidRestriction)(bool));
     ctxt.registerNonparametricMethod(this, (bool)(BluetoothPolicy::isUuidRestricted));
+    ctxt.registerParametricMethod(this, (int)(BluetoothPolicy::setBluetoothTetheringState)(bool));
+    ctxt.registerNonparametricMethod(this, (bool)(BluetoothPolicy::getBluetoothTetheringState));
+
 
     ctxt.createNotification("bluetooth");
+    ctxt.createNotification("bluetooth-tethering");
     ctxt.createNotification("bluetooth-desktop-connectivity");
     ctxt.createNotification("bluetooth-uuid-restriction");
     ctxt.createNotification("bluetooth-device-restriction");
@@ -149,6 +127,17 @@ BluetoothPolicy::~BluetoothPolicy()
     bt_deinitialize();
 }
 
+int BluetoothPolicy::setBluetoothTetheringState(bool enable)
+{
+    SetPolicyAllowed(context, "bluetooth-tethering", enable);
+    return 0;
+}
+
+bool BluetoothPolicy::getBluetoothTetheringState()
+{
+    return IsPolicyAllowed(context, "bluetooth-tethering");
+}
+
 int BluetoothPolicy::setModeChangeState(const bool enable)
 {
     int ret = BLUETOOTH_DPM_RESULT_SUCCESS;
index 6976ec7..b6f1364 100644 (file)
 
 #include <location_batch.h>
 
-#include "restriction.hxx"
+#include "location.hxx"
+
 #include "policy-helper.h"
 #include "audit/logger.h"
 
-#define CONSTRUCTOR __attribute__ ((constructor))
-
 namespace DevicePolicyManager {
 
-extern RestrictionPolicy restrictionPolicy;
-
-static void CONSTRUCTOR ContributeRestrictionPolicy()
+LocationPolicy::LocationPolicy(PolicyControlContext& ctxt) :
+    context(ctxt)
 {
-       PolicyControlContext& context = Server::instance();
-
-       context.registerParametricMethod(&restrictionPolicy, (int)(RestrictionPolicy::setLocationState)(int));
-       context.registerNonparametricMethod(&restrictionPolicy, (int)(RestrictionPolicy::getLocationState));
+       context.registerParametricMethod(this, (int)(LocationPolicy::setLocationState)(int));
+       context.registerNonparametricMethod(this, (int)(LocationPolicy::getLocationState));
 
        context.createNotification("location");
 }
 
-int RestrictionPolicy::setLocationState(int enable)
+LocationPolicy::~LocationPolicy()
+{
+}
+
+int LocationPolicy::setLocationState(int enable)
 {
     if (location_manager_enable_restriction(!enable) != LOCATIONS_ERROR_NONE)
-       return -1;
+           return -1;
 
     SetPolicyAllowed(context, "location", enable);
     return 0;
 }
 
-int RestrictionPolicy::getLocationState()
+int LocationPolicy::getLocationState()
 {
     return IsPolicyAllowed(context, "location");
 }
 
+LocationPolicy locationPolicy(Server::instance());
 
 } // namespace DevicePolicyManager
index 1f9b7f5..9a6a21a 100644 (file)
@@ -74,8 +74,9 @@ static inline void usage(const std::string name)
               << "Options :" << std::endl
               << "   -a, --attach=zone  execute command in the zone" << std::endl
               << "   -p, --pkginfo=zone show all packages in the zone" << std::endl
-              << "   -n, --appinfo=zone show all applications in the zone" << std::endl
-              << "   -m, --monitor      monitor all zone related events" << std::endl
+              << "   -q, --appinfo=zone show all applications in the zone" << std::endl
+              << "   -m, --zone-monitor monitor all zone events" << std::endl
+              << "   -n, --pkg-monitor  monitor all package events in the zone" << std::endl
               << "   -l, --list         show all zone instances" << std::endl
               << "   -h, --help         show this" << std::endl
               << std::endl;
@@ -236,8 +237,8 @@ int showPkgInfo(const std::string& name)
     zone_package_proxy_h pkgProxy;
 
     zone_manager_create(&zoneMgr);
-    zone_package_proxy_create(zoneMgr, &pkgProxy);
-    zone_package_proxy_foreach_package_info(pkgProxy, name.c_str(), packgeListCallback, &num);
+    zone_package_proxy_create(zoneMgr, name.c_str(), &pkgProxy);
+    zone_package_proxy_foreach_package_info(pkgProxy, packgeListCallback, &num);
     std::cout << num << " packages are found" << std::endl;
     zone_package_proxy_destroy(pkgProxy);
     zone_manager_destroy(zoneMgr);
@@ -294,8 +295,8 @@ int showAppInfo(const std::string& name)
     zone_app_proxy_h appMgr;
 
     zone_manager_create(&zoneMgr);
-    zone_app_proxy_create(zoneMgr, &appMgr);
-    zone_app_proxy_foreach_app_info(appMgr, name.c_str(), applicationListCallback, &num);
+    zone_app_proxy_create(zoneMgr, name.c_str(), &appMgr);
+    zone_app_proxy_foreach_app_info(appMgr, applicationListCallback, &num);
     std::cout << num << " applications are found" << std::endl;
     zone_app_proxy_destroy(appMgr);
     zone_manager_destroy(zoneMgr);
@@ -303,6 +304,13 @@ int showAppInfo(const std::string& name)
     return 0;
 }
 
+GMainLoop *gmainloop = NULL;
+
+void monitorSigHandler(int sig)
+{
+    g_main_loop_quit(gmainloop);
+}
+
 void zoneCallback(const char* name, const char* object, void *user_data)
 {
     std::cout << "--- Zone event ---" << std::endl;
@@ -311,7 +319,36 @@ void zoneCallback(const char* name, const char* object, void *user_data)
     std::cout << std::endl;
 }
 
-void packageEventCallback(const char *zone, const char *type,
+int monitorEvent()
+{
+    int zoneCallbackId[2];
+    zone_manager_h zoneMgr;
+    zone_manager_create(&zoneMgr);
+
+    zone_manager_add_event_cb(zoneMgr, "created", zoneCallback,
+                                (void*)"created", &zoneCallbackId[0]);
+    zone_manager_add_event_cb(zoneMgr, "removed", zoneCallback,
+                                (void*)"removed", &zoneCallbackId[1]);
+
+    std::cout << "=== Monitoring start ===" << std::endl << std::endl;
+
+    signal(SIGINT, monitorSigHandler);
+
+    gmainloop = g_main_loop_new(NULL, FALSE);
+    g_main_loop_run(gmainloop);
+    g_main_loop_unref(gmainloop);
+
+    zone_manager_remove_event_cb(zoneMgr, zoneCallbackId[0]);
+    zone_manager_remove_event_cb(zoneMgr, zoneCallbackId[1]);
+
+    std::cout << "===  Monitoring end  ===" << std::endl;
+
+    zone_manager_destroy(zoneMgr);
+
+    return 0;
+}
+
+void packageEventCallback(const char *type,
                           const char *package,
                           package_manager_event_type_e event_type,
                           package_manager_event_state_e event_state,
@@ -319,7 +356,6 @@ void packageEventCallback(const char *zone, const char *type,
                           void *user_data)
 {
     std::cout << "--- Package event ---" << std::endl;
-    std::cout << "Zone : " << zone <<std::endl;
     std::cout << "Pacakge : " << package << std::endl;
     std::cout << "Pacakge type : " << type << std::endl;
 
@@ -356,27 +392,13 @@ void packageEventCallback(const char *zone, const char *type,
     std::cout << std::endl;
 }
 
-GMainLoop *gmainloop = NULL;
-
-void monitorSigHandler(int sig)
+int monitorPkgEvent(const std::string& name)
 {
-    g_main_loop_quit(gmainloop);
-}
-
-int monitorEvent()
-{
-    int zoneCallbackId;
-
     zone_manager_h zoneMgr;
     zone_package_proxy_h pkgProxy;
 
     zone_manager_create(&zoneMgr);
-    zone_package_proxy_create(zoneMgr, &pkgProxy);
-
-    zone_manager_add_event_cb(zoneMgr, "created", zoneCallback,
-                                (void*)"created", &zoneCallbackId);
-    zone_manager_add_event_cb(zoneMgr, "removed", zoneCallback,
-                                (void*)"removed", &zoneCallbackId);
+    zone_package_proxy_create(zoneMgr, name.c_str(), &pkgProxy);
 
     zone_package_proxy_set_event_cb(pkgProxy, packageEventCallback, NULL);
 
@@ -389,7 +411,6 @@ int monitorEvent()
     g_main_loop_unref(gmainloop);
 
     zone_package_proxy_unset_event_cb(pkgProxy);
-    zone_manager_remove_event_cb(zoneMgr, zoneCallbackId);
 
     std::cout << "===  Monitoring end  ===" << std::endl;
 
@@ -407,8 +428,9 @@ int main(int argc, char* argv[])
         {"attach", required_argument, 0, 'a'},
         {"list", no_argument, 0, 'l'},
         {"pkginfo", required_argument, 0, 'p'},
-        {"appinfo", required_argument, 0, 'n'},
-        {"monitor", no_argument, 0, 'm'},
+        {"appinfo", required_argument, 0, 'q'},
+        {"zone-monitor", no_argument, 0, 'm'},
+        {"pkg-monitor", no_argument, 0, 'n'},
         {"help", no_argument, 0, 'h'},
         {0, 0, 0, 0}
     };
@@ -418,7 +440,7 @@ int main(int argc, char* argv[])
         return EXIT_SUCCESS;
     }
 
-    while ((opt = getopt_long(argc, argv, "a:p:n:mlh", options, &index)) != -1) {
+    while ((opt = getopt_long(argc, argv, "a:p:q:mn:lh", options, &index)) != -1) {
         switch (opt) {
         case 'a':
             ret = attachToZone(optarg, optind >= argc ? NULL : argv + optind);
@@ -426,12 +448,15 @@ int main(int argc, char* argv[])
         case 'p':
             ret = showPkgInfo(optarg);
             break;
-        case 'n':
+        case 'q':
             ret = showAppInfo(optarg);
             break;
         case 'm':
             ret = monitorEvent();
             break;
+        case 'n':
+            ret = monitorPkgEvent(optarg);
+            break;
         case 'l':
             ret = showZoneInstances();
             break;
index 82055a9..c5fd4e2 100644 (file)
 
 using namespace DevicePolicyManager;
 
-inline ZoneAppProxy* getManager(zone_app_proxy_h handle)
+struct zone_app_proxy_s {
+    ZoneAppProxy proxy;
+    std::string zoneName;
+};
+
+static inline zone_app_proxy_s* getInstance(zone_app_proxy_h handle)
 {
-    return reinterpret_cast<ZoneAppProxy*>(handle);
+    return reinterpret_cast<zone_app_proxy_s *>(handle);
 }
 
 static app_info_h make_app_info_handle(const ZoneAppProxy::AppInfo& info)
@@ -73,14 +78,18 @@ static app_info_h make_app_info_handle(const ZoneAppProxy::AppInfo& info)
     return reinterpret_cast<app_info_h>(appinfo);
 }
 
-int zone_app_proxy_create(zone_manager_h manager, zone_app_proxy_h *handle)
+int zone_app_proxy_create(zone_manager_h manager, const char* name, zone_app_proxy_h *handle)
 {
     RET_ON_FAILURE(manager, ZONE_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
 
-    auto& client = GetDevicePolicyContext(manager);
-    *handle = reinterpret_cast<zone_app_proxy_h*>(client.createPolicyInterface<ZoneAppProxy>());
+    zone_app_proxy_s* instance = new zone_app_proxy_s {
+        GetDevicePolicyContext(manager).createPolicyInterface<ZoneAppProxy>(),
+        name
+    };
 
+    *handle = reinterpret_cast<zone_app_proxy_h>(instance);
     return ZONE_ERROR_NONE;
 }
 
@@ -93,16 +102,18 @@ int zone_app_proxy_destroy(zone_app_proxy_h handle)
     return ZONE_ERROR_NONE;
 }
 
-int zone_app_proxy_get_app_info(zone_app_proxy_h handle, const char* name, const char* app_id, app_info_h* app_info)
+int zone_app_proxy_get_app_info(zone_app_proxy_h handle, const char* app_id, app_info_h* app_info)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
-    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(app_id, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(app_info, ZONE_ERROR_INVALID_PARAMETER);
 
-    const auto info = getManager(handle)->getAppInfo(name, app_id);
-    app_info_h ret = make_app_info_handle(info);
+    auto instance = getInstance(handle);
+    auto& proxy = instance->proxy;
+    const std::string& name = instance->zoneName;
 
+    const auto info = proxy.getAppInfo(name, app_id);
+    app_info_h ret = make_app_info_handle(info);
     if (ret == NULL) {
         return ZONE_ERROR_INVALID_PARAMETER;
     }
@@ -112,17 +123,19 @@ int zone_app_proxy_get_app_info(zone_app_proxy_h handle, const char* name, const
     return ZONE_ERROR_NONE;
 }
 
-int zone_app_proxy_foreach_app_info(zone_app_proxy_h handle, const char* name, app_manager_app_info_cb callback, void *user_data)
+int zone_app_proxy_foreach_app_info(zone_app_proxy_h handle, app_manager_app_info_cb callback, void *user_data)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
-    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(callback, ZONE_ERROR_INVALID_PARAMETER);
 
-    auto manager = getManager(handle);
-    for (const auto& appid : manager->getAppList(name)) {
-        app_info_h info_h = make_app_info_handle(manager->getAppInfo(name, appid));
-        int ret = callback(info_h, user_data);
-        app_info_destroy(info_h);
+    auto instance = getInstance(handle);
+    auto& proxy = instance->proxy;
+    const std::string& name = instance->zoneName;
+
+    for (const auto& appid : proxy.getAppList(name)) {
+        app_info_h info = make_app_info_handle(proxy.getAppInfo(name, appid));
+        int ret = callback(info, user_data);
+        app_info_destroy(info);
         if (!ret) {
             continue;
         }
@@ -131,22 +144,28 @@ int zone_app_proxy_foreach_app_info(zone_app_proxy_h handle, const char* name, a
     return ZONE_ERROR_NONE;
 }
 
-int zone_app_proxy_launch(zone_app_proxy_h handle, const char* name, const char* app_id)
+int zone_app_proxy_launch(zone_app_proxy_h handle, const char* app_id)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
-    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(app_id, ZONE_ERROR_INVALID_PARAMETER);
 
-    return getManager(handle)->launch(name, app_id);
+    auto instance = getInstance(handle);
+    auto& proxy = instance->proxy;
+    const std::string& name = instance->zoneName;
+
+    return proxy.launch(name, app_id);
 }
 
-int zone_app_proxy_is_running(zone_app_proxy_h handle, const char* name, const char* app_id, int *result)
+int zone_app_proxy_is_running(zone_app_proxy_h handle, const char* app_id, int *result)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
-    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(app_id, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(result, ZONE_ERROR_INVALID_PARAMETER);
 
-    *result = getManager(handle)->isRunning(name, app_id);
+    auto instance = getInstance(handle);
+    auto& proxy = instance->proxy;
+    const std::string& name = instance->zoneName;
+
+    *result = proxy.isRunning(name, app_id);
     return ZONE_ERROR_NONE;
 }
index cddd9c5..50c0241 100644 (file)
@@ -50,6 +50,7 @@ typedef void* zone_app_proxy_h;
  *              the zone application manager APIs.
  * @since_tizen 3.0
  * @param[in]   manager The zone manager handle
+ * @param[in]   name The zone name
  * @param[out]  handle The zone app proxy handle
  * @return      #ZONE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ZONE_ERROR_NONE Successful
@@ -59,7 +60,7 @@ typedef void* zone_app_proxy_h;
  * @see         zone_app_proxy_create()
  * @see         get_last_result()
  */
-ZONE_API int zone_app_proxy_create(zone_manager_h manager, zone_app_proxy_h* handle);
+ZONE_API int zone_app_proxy_create(zone_manager_h manager, const char* name, zone_app_proxy_h* handle);
 
 /**
  * @brief       Releases the zone application manager handle
@@ -83,7 +84,6 @@ ZONE_API int zone_app_proxy_destroy(zone_app_proxy_h handle);
  *              information of the application in the zone
  * @since_tizen 3.0
  * @param[in]   handle The zone application manager handle
- * @param[in]   name The zone name
  * @param[in]   appid The application ID
  * @return      Zone application handle on success, otherwise NULL
  * @remark      The specific error code can be obtained by using the
@@ -98,7 +98,7 @@ ZONE_API int zone_app_proxy_destroy(zone_app_proxy_h handle);
  * @see         application_manager_get_application_info()
  * @see         get_last_result()
  */
-ZONE_API int zone_app_proxy_get_app_info(zone_app_proxy_h handle, const char* name, const char* appid, app_info_h* app_info);
+ZONE_API int zone_app_proxy_get_app_info(zone_app_proxy_h handle, const char* appid, app_info_h* app_info);
 
 /**
  * @brief       Retrieves all the handles of the application in the zone.
@@ -106,7 +106,6 @@ ZONE_API int zone_app_proxy_get_app_info(zone_app_proxy_h handle, const char* na
  *              ID with traversing the installed application list in the zone.
  * @since_tizen 3.0
  * @param[in]   handle The zone application manager handle
- * @param[in]   name The zone name
  * @param[in]   callback The iteration callback function
  * @param[in]   user_data The user data passed to the callback function
  * @return      #ZONE_ERROR_NONE on success, otherwise a negative value
@@ -118,7 +117,7 @@ ZONE_API int zone_app_proxy_get_app_info(zone_app_proxy_h handle, const char* na
  * @see         zone_app_proxy_create()
  * @see         application_manager_foreach_app_info()
  */
-ZONE_API int zone_app_proxy_foreach_app_info(zone_app_proxy_h handle, const char* name, app_manager_app_info_cb callback, void *user_data);
+ZONE_API int zone_app_proxy_foreach_app_info(zone_app_proxy_h handle, app_manager_app_info_cb callback, void *user_data);
 
 /**
  * @brief       Launch the application located at the given path into the zone.
@@ -126,7 +125,6 @@ ZONE_API int zone_app_proxy_foreach_app_info(zone_app_proxy_h handle, const char
  *              zone.
  * @since_tizen 3.0
  * @param[in]   handle The zone application manager handle
- * @param[in]   name The zone name
  * @param[in]   appid The application ID to be launched
  * @return      #ZONE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ZONE_ERROR_NONE Successful
@@ -148,7 +146,7 @@ ZONE_API int zone_app_proxy_foreach_app_info(zone_app_proxy_h handle, const char
  * @see         zone_is_running_app()
  * @see         app_control_send_launch_request()
  */
-ZONE_API int zone_app_proxy_launch(zone_app_proxy_h handle, const char* name, const char* appid);
+ZONE_API int zone_app_proxy_launch(zone_app_proxy_h handle, const char* appid);
 
 /**
  * @brief       Resume the application located at the given path into the zone.
@@ -156,7 +154,6 @@ ZONE_API int zone_app_proxy_launch(zone_app_proxy_h handle, const char* name, co
  *              zone.
  * @since_tizen 3.0
  * @param[in]   handle The zone application manager handle
- * @param[in]   name The zone name
  * @param[in]   appid The application ID to be resumed
  * @return      #ZONE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ZONE_ERROR_NONE Successful
@@ -177,7 +174,7 @@ ZONE_API int zone_app_proxy_launch(zone_app_proxy_h handle, const char* name, co
  * @see         zone_terminate_app()
  * @see         zone_is_running_app()
  */
-ZONE_API int zone_app_proxy_resume(zone_app_proxy_h handle, const char* name, const char* appid);
+ZONE_API int zone_app_proxy_resume(zone_app_proxy_h handle, const char* appid);
 
 /**
  * @brief       Terminate the application located at the given path into the zone.
@@ -185,7 +182,6 @@ ZONE_API int zone_app_proxy_resume(zone_app_proxy_h handle, const char* name, co
  *              the zone.
  * @since_tizen 3.0
  * @param[in]   handle The zone application manager handle
- * @param[in]   name The zone name
  * @param[in]   appid The application ID to be terminated
  * @return      #ZONE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ZONE_ERROR_NONE Successful
@@ -207,7 +203,7 @@ ZONE_API int zone_app_proxy_resume(zone_app_proxy_h handle, const char* name, co
  * @see         zone_is_running_app()
  * @see         app_control_send_terminate_request()
  */
-ZONE_API int zone_app_proxy_terminate(zone_app_proxy_h handle, const char* name, const char* appid);
+ZONE_API int zone_app_proxy_terminate(zone_app_proxy_h handle, const char* appid);
 
 /**
  * @brief       Checks whether the application in the zone is running.
@@ -215,7 +211,6 @@ ZONE_API int zone_app_proxy_terminate(zone_app_proxy_h handle, const char* name,
  *              is running.
  * @since_tizen 3.0
  * @param[in]   handle The zone application manager handle
- * @param[in]   name The zone name
  * @param[in]   appid The application ID
  * @param[out]  result true if the application is running,
  *              otherwise false if the application is not running
@@ -232,7 +227,7 @@ ZONE_API int zone_app_proxy_terminate(zone_app_proxy_h handle, const char* name,
  * @see         zone_launch_app()
  * @see         zone_terminate_app()
  */
-ZONE_API int zone_app_proxy_is_running(zone_app_proxy_h handle, const char* name, const char* appid, int* result);
+ZONE_API int zone_app_proxy_is_running(zone_app_proxy_h handle, const char* appid, int* result);
 
 /**
  * @}
index 3610dca..125d2ba 100644 (file)
 
 using namespace DevicePolicyManager;
 
-typedef struct zone_package_proxy_s {
-    std::unique_ptr<ZonePackageProxy> pManager;
+struct zone_package_proxy_s {
+    ZonePackageProxy proxy;
+    std::string zoneName;
     pkgmgr_client* pNativeHandle;
-    zone_package_proxy_event_cb pCallback;
+    package_manager_event_cb pCallback;
     void *pCallbackUserData;
-} zone_package_proxy_s;
+};
 
 static inline zone_package_proxy_s* getInstance(zone_package_proxy_h handle)
 {
     return reinterpret_cast<zone_package_proxy_s *>(handle);
 }
 
-static inline ZonePackageProxy* getProxy(zone_package_proxy_h handle)
-{
-    return getInstance(handle)->pManager.get();
-}
-
 static int packageEventHandler(uid_t target_uid, int req_id,
                                const char *pkg_type, const char *pkg_name,
                                const char *key, const char *val,
@@ -58,8 +54,8 @@ static int packageEventHandler(uid_t target_uid, int req_id,
 {
     static auto event_type = (package_manager_event_type_e)-1;
     auto event_state = PACKAGE_MANAGER_EVENT_STATE_FAILED;
-    std::string keystr = key, zone_name;
     auto instance = getInstance(data);
+    std::string keystr = key;
     int progress = 0;
 
     if (target_uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER))
@@ -67,7 +63,9 @@ static int packageEventHandler(uid_t target_uid, int req_id,
 
     try {
         runtime::User pkgOwner(target_uid);
-        zone_name = pkgOwner.getName();
+        if (pkgOwner.getName() == instance->zoneName) {
+            return PACKAGE_MANAGER_ERROR_NONE;
+        }
     } catch (runtime::Exception &e) {
         return PACKAGE_MANAGER_ERROR_NONE;
     }
@@ -104,7 +102,7 @@ static int packageEventHandler(uid_t target_uid, int req_id,
         progress = 100;
     }
 
-    instance->pCallback(zone_name.c_str(), pkg_type, pkg_name,
+    instance->pCallback(pkg_type, pkg_name,
                         event_type, event_state, progress,
                         PACKAGE_MANAGER_ERROR_NONE,
                         instance->pCallbackUserData);
@@ -174,17 +172,17 @@ static package_info_h make_package_info_handle(const ZonePackageProxy::PackageIn
     return reinterpret_cast<package_info_h>(packageinfo);
 }
 
-int zone_package_proxy_create(zone_manager_h manager, zone_package_proxy_h *handle)
+int zone_package_proxy_create(zone_manager_h manager, const char* name, zone_package_proxy_h *handle)
 {
     RET_ON_FAILURE(manager, ZONE_ERROR_INVALID_PARAMETER);
+    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
 
-    zone_package_proxy_s* instance = new zone_package_proxy_s;
-
-    instance->pManager.reset(GetDevicePolicyContext(manager).
-                                createPolicyInterface<ZonePackageProxy>());
-
-    instance->pNativeHandle = ::pkgmgr_client_new(PC_LISTENING);
+    zone_package_proxy_s* instance = new zone_package_proxy_s {
+        GetDevicePolicyContext(manager).
+                                createPolicyInterface<ZonePackageProxy>(),
+        name, ::pkgmgr_client_new(PC_LISTENING), NULL, NULL
+    };
 
     *handle = reinterpret_cast<zone_package_proxy_h>(instance);
     return ZONE_ERROR_NONE;
@@ -203,14 +201,17 @@ int zone_package_proxy_destroy(zone_package_proxy_h handle)
     return ZONE_ERROR_NONE;
 }
 
-int zone_package_proxy_get_package_info(zone_package_proxy_h handle, const char* name, const char* package_id, package_info_h* package_info)
+int zone_package_proxy_get_package_info(zone_package_proxy_h handle, const char* package_id, package_info_h* package_info)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
-    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(package_id, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(package_info, ZONE_ERROR_INVALID_PARAMETER);
 
-    const auto& info = getProxy(handle)->getPackageInfo(name, package_id);
+    auto instance = getInstance(handle);
+    auto& proxy = instance->proxy;
+    const std::string& name = instance->zoneName;
+
+    const auto& info = proxy.getPackageInfo(name, package_id);
     package_info_h ret = make_package_info_handle(info);
 
     if (ret == NULL) {
@@ -222,15 +223,17 @@ int zone_package_proxy_get_package_info(zone_package_proxy_h handle, const char*
     return ZONE_ERROR_NONE;
 }
 
-int zone_package_proxy_foreach_package_info(zone_package_proxy_h handle, const char* name, package_manager_package_info_cb callback, void *user_data)
+int zone_package_proxy_foreach_package_info(zone_package_proxy_h handle, package_manager_package_info_cb callback, void *user_data)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
-    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(callback, ZONE_ERROR_INVALID_PARAMETER);
 
-    auto manager = getProxy(handle);
-    for (const auto& pkgid : manager->getPackageList(name)) {
-        package_info_h info_h = make_package_info_handle(manager->getPackageInfo(name, pkgid));
+    auto instance = getInstance(handle);
+    auto& proxy = instance->proxy;
+    const std::string& name = instance->zoneName;
+
+    for (const auto& pkgid : proxy.getPackageList(name)) {
+        package_info_h info_h = make_package_info_handle(proxy.getPackageInfo(name, pkgid));
         int ret = callback(info_h, user_data);
         package_info_destroy(info_h);
         if (!ret) {
@@ -245,8 +248,10 @@ int zone_package_proxy_set_event_status(zone_package_proxy_h handle, int status_
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
 
+    auto instance = getInstance(handle);
+
     int ret;
-    ret = pkgmgrinfo_client_set_status_type(getInstance(handle)->pNativeHandle, status_type);
+    ret = pkgmgrinfo_client_set_status_type(instance->pNativeHandle, status_type);
 
     if (ret != PACKAGE_MANAGER_ERROR_NONE)
         return ZONE_ERROR_INVALID_PARAMETER;
@@ -254,7 +259,7 @@ int zone_package_proxy_set_event_status(zone_package_proxy_h handle, int status_
     return ZONE_ERROR_NONE;
 }
 
-int zone_package_proxy_set_event_cb(zone_package_proxy_h handle, zone_package_proxy_event_cb callback, void *user_data)
+int zone_package_proxy_set_event_cb(zone_package_proxy_h handle, package_manager_event_cb callback, void *user_data)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(callback, ZONE_ERROR_INVALID_PARAMETER);
@@ -267,7 +272,7 @@ int zone_package_proxy_set_event_cb(zone_package_proxy_h handle, zone_package_pr
     int ret;
     ret = pkgmgr_client_listen_status(instance->pNativeHandle, packageEventHandler, handle);
 
-    if (ret != PACKAGE_MANAGER_ERROR_NONE)
+    if (ret < 0)
         return ZONE_ERROR_INVALID_PARAMETER;
 
     return ZONE_ERROR_NONE;
@@ -277,29 +282,37 @@ int zone_package_proxy_unset_event_cb(zone_package_proxy_h handle)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
 
+    auto instance = getInstance(handle);
+
     int ret;
-    ret = pkgmgr_client_remove_listen_status(getInstance(handle)->pNativeHandle);
+    ret = pkgmgr_client_remove_listen_status(instance->pNativeHandle);
 
-    if (ret != PACKAGE_MANAGER_ERROR_NONE)
+    if (ret < 0)
         return ZONE_ERROR_INVALID_PARAMETER;
 
     return ZONE_ERROR_NONE;
 }
 
-int zone_package_proxy_install(zone_package_proxy_h handle, const char* name, const char* package_path)
+int zone_package_proxy_install(zone_package_proxy_h handle, const char* package_path)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
-    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(package_path, ZONE_ERROR_INVALID_PARAMETER);
 
-    return getProxy(handle)->install(name, package_path);
+    auto instance = getInstance(handle);
+    auto& proxy = instance->proxy;
+    const std::string& name = instance->zoneName;
+
+    return proxy.install(name, package_path);
 }
 
-int zone_package_proxy_uninstall(zone_package_proxy_h handle, const char* name, const char* package_id)
+int zone_package_proxy_uninstall(zone_package_proxy_h handle, const char* package_id)
 {
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
-    RET_ON_FAILURE(name, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(package_id, ZONE_ERROR_INVALID_PARAMETER);
 
-    return getProxy(handle)->uninstall(name, package_id);
+    auto instance = getInstance(handle);
+    auto& proxy = instance->proxy;
+    const std::string& name = instance->zoneName;
+
+    return proxy.uninstall(name, package_id);
 }
index 61070ff..1f7e545 100644 (file)
@@ -50,6 +50,7 @@ typedef void* zone_package_proxy_h;
  *              the zone package_manager APIs.
  * @since_tizen 3.0
  * @param[in]   manager The zone manager handle
+ * @param[in]   name The zone name
  * @param[out]  handle The zone package proxy handle
  * @return      #ZONE_ERROR_NONE on success, otherwise a negative value
  * @retval      #ZONE_ERROR_NONE Successful
@@ -59,7 +60,7 @@ typedef void* zone_package_proxy_h;
  * @see         zone_package_proxy_destroy()
  * @see         get_last_result()
  */
-ZONE_API int zone_package_proxy_create(zone_manager_h manager, zone_package_proxy_h *handle);
+ZONE_API int zone_package_proxy_create(zone_manager_h manager, const char* name, zone_package_proxy_h *handle);
 
 /**
  * @brief       Releases the zone package proxy handle.
@@ -82,7 +83,6 @@ ZONE_API int zone_package_proxy_destroy(zone_package_proxy_h handle);
  *              information of the pacakge in the zone.
  * @since_tizen 3.0
  * @param[in]   handle The zone package proxy handle
- * @param[in]   name The zone name
  * @param[in]   pakcage_id The package ID
  * @return      Zone package information handle on success, otherwise NULL
  * @remark      The specific error code can be obtained by using the
@@ -98,7 +98,7 @@ ZONE_API int zone_package_proxy_destroy(zone_package_proxy_h handle);
  * @see         package_manager_destroy()
  * @see         get_last_result()
  */
-ZONE_API int zone_package_proxy_get_package_info(zone_package_proxy_h handle, const char* name, const char* pakcage_id, package_info_h* package_info);
+ZONE_API int zone_package_proxy_get_package_info(zone_package_proxy_h handle, const char* pakcage_id, package_info_h* package_info);
 
 /**
  * @brief       Retrieves all the IDs of the installed package in the zone.
@@ -107,7 +107,6 @@ ZONE_API int zone_package_proxy_get_package_info(zone_package_proxy_h handle, co
  *              package list in the zone.
  * @since_tizen 3.0
  * @param[in]   handle The zone package proxy handle
- * @param[in]   name The zone name
  * @param[in]   callback The iteration callback function
  * @param[in]   user_data The user data passed to the callback function
  * @return      #ZONE_ERROR_NONE on success, otherwise a negative value
@@ -119,7 +118,7 @@ ZONE_API int zone_package_proxy_get_package_info(zone_package_proxy_h handle, co
  * @see         zone_package_proxy_destroy()
  * @see         package_manager_foreach_package_info()
  */
-ZONE_API int zone_package_proxy_foreach_package_info(zone_package_proxy_h handle, const char* name, package_manager_package_info_cb callback, void *user_data);
+ZONE_API int zone_package_proxy_foreach_package_info(zone_package_proxy_h handle, package_manager_package_info_cb callback, void *user_data);
 
 /**
  * @brief       Installs the package located at the given path into the zone.
@@ -145,7 +144,7 @@ ZONE_API int zone_package_proxy_foreach_package_info(zone_package_proxy_h handle
  * @see         zone_package_proxy_uninstall()
  * @see         package_manager_request_install()
  */
-ZONE_API int zone_package_proxy_install(zone_package_proxy_h handle, const char* name, const char* package_path);
+ZONE_API int zone_package_proxy_install(zone_package_proxy_h handle, const char* package_path);
 
 /**
  * @brief       Uinstalls the package with the given ID from the zone.
@@ -171,7 +170,7 @@ ZONE_API int zone_package_proxy_install(zone_package_proxy_h handle, const char*
  * @see         zone_package_proxy_install()
  * @see         package_manager_request_uninstall()
  */
-ZONE_API int zone_package_proxy_uninstall(zone_package_proxy_h handle, const char* name, const char* pakcage_id);
+ZONE_API int zone_package_proxy_uninstall(zone_package_proxy_h handle, const char* pakcage_id);
 
 /**
  * @brief       Sets the event status that presents the package has been
@@ -194,42 +193,11 @@ ZONE_API int zone_package_proxy_uninstall(zone_package_proxy_h handle, const cha
  * @see         zone_package_proxy_uninstall()
  * @see         zone_package_proxy_set_event_cb()
  * @see         zone_package_proxy_unset_event_cb()
+ * @see         package_manager_set_event_status()
  */
 ZONE_API int zone_package_proxy_set_event_status(zone_package_proxy_h handle, int status_type);
 
 /**
- * @brief       Called when the package in the zone is installed, uninstalled or
- *              updated, and the progress of the request to the package manager
- *              changes.
- * @since_tizen 3.0
- * @param[in]   zone The name of zone that the package is in
- * @param[in]   type The type of the package to be installed, uninstalled or
- *              updated
- * @param[in]   package The name of the package to be installed, uninstalled or
- *              updated
- * @param[in]   event_type The type of the request to the package manager
- * @param[in]   event_state The current state of the request to the package
-                manager
- * @param[in]   progress The progress for the request that is being processed by
- *              the package manager. The range of progress is from @c 0 to
- *              @c 100.
- * @param[in]   error The error code when the package manager failed to process
- *              the request
- * @param[in]   user_data The user data passed from zone_package_proxy_set_event_cb()
- *
- * @see zone_package_proxy_set_event_cb()
- * @see zone_package_proxy_unset_event_cb()
- */
-typedef void (*zone_package_proxy_event_cb) (
-                const char *zone,
-                const char *type,
-                const char *package,
-                package_manager_event_type_e event_type,
-                package_manager_event_state_e event_state,
-                int progress,
-                package_manager_error_e error,
-                void *user_data);
-/**
  * @brief       Registers a callback function for package event.
  * @details     This API sets a callback function to be invoked when the package
  *              has been installed, uninstalled or updated.
@@ -248,8 +216,9 @@ typedef void (*zone_package_proxy_event_cb) (
  * @see         zone_package_proxy_set_event_status()
  * @see         zone_package_proxy_unset_event_cb()
  * @see         package_manager_event_cb()
+ * @see         package_manager_set_event_cb()
  */
-ZONE_API int zone_package_proxy_set_event_cb(zone_package_proxy_h handle, zone_package_proxy_event_cb callback, void *user_data);
+ZONE_API int zone_package_proxy_set_event_cb(zone_package_proxy_h handle, package_manager_event_cb callback, void *user_data);
 
 /**
  * @brief       Unregisters the callback function.
@@ -269,7 +238,7 @@ ZONE_API int zone_package_proxy_set_event_cb(zone_package_proxy_h handle, zone_p
  * @see         zone_package_proxy_uninstall()
  * @see         zone_package_proxy_set_event_status()
  * @see         zone_package_proxy_set_event_cb()
- * @see         package_manager_event_cb()
+ * @see         package_manager_unset_event_cb()
  */
 ZONE_API int zone_package_proxy_unset_event_cb(zone_package_proxy_h handle);
 
index c800196..ace6c7f 100644 (file)
@@ -58,8 +58,8 @@ int zone_manager_add_event_cb(zone_manager_h handle, const char* event, zone_eve
     RET_ON_FAILURE(event, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(callback, ZONE_ERROR_INVALID_PARAMETER);
 
-    auto& context = GetDevicePolicyContext(handle);
-    int ret = context.subscribeSignal(std::string("ZonePolicy::") +event,
+    DevicePolicyContext &context = GetDevicePolicyContext(handle);
+    int ret = context.subscribeSignal(std::string("ZonePolicy::") + event,
                                       callback, user_data);
     if (ret < 0)
         return ZONE_ERROR_INVALID_PARAMETER;
@@ -73,7 +73,7 @@ int zone_manager_remove_event_cb(zone_manager_h handle, int callback_id)
     RET_ON_FAILURE(handle, ZONE_ERROR_INVALID_PARAMETER);
     RET_ON_FAILURE(callback_id >= 0, ZONE_ERROR_INVALID_PARAMETER);
 
-    auto& context = *reinterpret_cast<DevicePolicyContext*>(handle);
+    DevicePolicyContext &context = GetDevicePolicyContext(handle);
     int ret =  context.unsubscribeSignal(callback_id);
     if (ret)
         return ZONE_ERROR_INVALID_PARAMETER;