From 327f474a033cb3150dc5ebe816a1cc05b6ccc1ba Mon Sep 17 00:00:00 2001 From: "Sungjun, Lee" Date: Wed, 30 Nov 2016 15:58:48 +0900 Subject: [PATCH] Modify Password and Restriction API Change-Id: I588ca784ec92520183a148ad8a9d083fb6d61d42 Signed-off-by: Sungjun, Lee --- libs/common.cmake | 1 + libs/dpm/password.cpp | 33 ++++++++++++++++-- libs/dpm/password.h | 27 +++++++++----- libs/dpm/password_internal.h | 35 +++++++++++++++++++ libs/dpm/restriction.cpp | 8 ++--- libs/dpm/restriction.h | 6 ++-- libs/ivi.cmake | 1 + libs/mobile.cmake | 1 + libs/password.cpp | 18 ++++++++++ libs/restriction.cpp | 8 ++--- libs/wearable.cmake | 1 + policy/password.hxx | 11 ++++++ policy/restriction.hxx | 4 +-- server/password.cpp | 83 ++++++++++++++++++++++++++++++++------------ server/policy-manager.cpp | 1 + server/restriction.cpp | 8 ++--- tests/password.c | 2 +- tests/restriction.c | 56 +++++++++++++++++++++++++++++- 18 files changed, 253 insertions(+), 51 deletions(-) create mode 100644 libs/dpm/password_internal.h diff --git a/libs/common.cmake b/libs/common.cmake index 5502e91..97e995c 100644 --- a/libs/common.cmake +++ b/libs/common.cmake @@ -23,5 +23,6 @@ SET(POLICY ${POLICY} SET(CAPI ${CAPI} dpm/password.h + dpm/password_internal.h dpm/zone.h ) diff --git a/libs/dpm/password.cpp b/libs/dpm/password.cpp index 3337d9c..c2029b4 100644 --- a/libs/dpm/password.cpp +++ b/libs/dpm/password.cpp @@ -18,6 +18,7 @@ #include #include "password.h" +#include "password_internal.h" #include "password.hxx" #include "array.h" @@ -26,7 +27,7 @@ using namespace DevicePolicyManager; -EXPORT_API int dpm_password_set_quality(device_policy_manager_h handle, dpm_password_quality_e quality) +EXPORT_API int dpm_password_set_quality(device_policy_manager_h handle, int quality) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); @@ -36,7 +37,7 @@ EXPORT_API int dpm_password_set_quality(device_policy_manager_h handle, dpm_pass return password.setQuality(quality); } -EXPORT_API int dpm_password_get_quality(device_policy_manager_h handle, dpm_password_quality_e *quality) +EXPORT_API int dpm_password_get_quality(device_policy_manager_h handle, int *quality) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(quality, DPM_ERROR_INVALID_PARAMETER); @@ -428,3 +429,31 @@ EXPORT_API int dpm_password_set_forbidden_strings(device_policy_manager_h handle return password.setForbiddenStrings(forbiddenStrings); } + +EXPORT_API int dpm_password_set_recovery(device_policy_manager_h handle, int enable) +{ + RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); + + DevicePolicyContext &client = GetDevicePolicyContext(handle); + PasswordPolicy password = client.createPolicyInterface(); + + return password.setRecovery(enable); +} + +EXPORT_API int dpm_password_get_recovery(device_policy_manager_h handle, int *enable) +{ + RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER); + + DevicePolicyContext &client = GetDevicePolicyContext(handle); + PasswordPolicy password = client.createPolicyInterface(); + + int ret = password.getRecovery(); + if (ret < 0) { + return -1; + } + + *enable = ret; + + return DPM_ERROR_NONE; +} diff --git a/libs/dpm/password.h b/libs/dpm/password.h index e5d2a60..dd1c6b0 100644 --- a/libs/dpm/password.h +++ b/libs/dpm/password.h @@ -52,11 +52,20 @@ typedef enum { * @since_tizen 3.0 */ typedef enum { - DPM_PASSWORD_STATUS_NORMAL, /**< Password normal status */ - DPM_PASSWORD_STATUS_CHANGED, /**< Password successfully changed */ - DPM_PASSWORD_STATUS_NOT_CHANGED, /**< Password not changed */ - DPM_PASSWORD_STATUS_CHANGE_REQUIRED , /**< Password change required */ - DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED, /**< Password Max Attempts Exceeded*/ + DPM_PASSWORD_STATUS_NORMAL, /**< Password normal status */ + DPM_PASSWORD_STATUS_CHANGED, /**< Password successfully changed */ + DPM_PASSWORD_STATUS_NOT_CHANGED, /**< Password not changed */ + DPM_PASSWORD_STATUS_CHANGE_REQUIRED , /**< Password change required */ + DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED, /**< Password Max Attempts Exceeded*/ + + DPM_PASSWORD_STATUS_EXPIRED, /**< Password expired */ + DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_FAILED, /**< Device unlock failed by Password Recovery */ + DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_SUCCEEDED,/**< Device unlock succeeded by Password Recovery */ + + DPM_PASSWORD_STATUS_QUALITY_CHANGED, /**< Password quality successfully changed */ + DPM_PASSWORD_STATUS_MIN_LENGTH_CHANGED, /**< Password min_length successfully changed */ + DPM_PASSWORD_STATUS_COMPLEX_CHAR_CHANGED, /**< Password complex_char successfully changed */ + DPM_PASSWORD_STATUS_PATTERN_CHANGED /**< Password pattern successfully changed */ } dpm_password_status_e; /** @@ -69,7 +78,7 @@ typedef enum { * @privlevel partner * @privilege %http://tizen.org/privilege/dpm.password * @param[in] handle Device policy manager handle - * @param[in] quality Password quality type + * @param[in] quality Password quality type, values of #dpm_password_quality_e combined with bitwise 'or' * @return #DPM_ERROR_NONE on success, otherwise a negative value * @retval #DPM_ERROR_NONE Successful * @retval #DPM_ERROR_INVALID_PARAMETER Invalid parameter @@ -79,14 +88,14 @@ typedef enum { * @pre The handle must be created by dpm_manager_create(). * @see dpm_manager_create() */ -int dpm_password_set_quality(device_policy_manager_h handle, dpm_password_quality_e quality); +int dpm_password_set_quality(device_policy_manager_h handle, int quality); /** * @brief Gets password quality. * @details An administrator can get the password restrictions it is imposing. * @since_tizen 3.0 * @param[in] handle Device policy manager handle - * @param[out] quality Password quality type + * @param[out] quality Password quality type, values of #dpm_password_quality_e combined with bitwise 'or' * @return #DPM_ERROR_NONE on success, otherwise a negative value * @retval #DPM_ERROR_NONE Successful * @retval #DPM_ERROR_INVALID_PARAMETER Invalid parameter @@ -94,7 +103,7 @@ int dpm_password_set_quality(device_policy_manager_h handle, dpm_password_qualit * @pre The handle must be created by dpm_manager_create(). * @see dpm_manager_create() */ -int dpm_password_get_quality(device_policy_manager_h handle, dpm_password_quality_e *quality); +int dpm_password_get_quality(device_policy_manager_h handle, int *quality); /** * @partner diff --git a/libs/dpm/password_internal.h b/libs/dpm/password_internal.h new file mode 100644 index 0000000..a02274d --- /dev/null +++ b/libs/dpm/password_internal.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015 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 __CAPI_PASSWORD_INTERNAL_POLICY_H__ +#define __CAPI_PASSWORD_INTERNAL_POLICY_H__ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int dpm_password_set_recovery(device_policy_manager_h handle, int enable); +int dpm_password_get_recovery(device_policy_manager_h handle, int *enable); + + +#ifdef __cplusplus +} +#endif + +#endif /* __CAPI_PASSWORD_INTERNAL_POLICY_H__ */ + diff --git a/libs/dpm/restriction.cpp b/libs/dpm/restriction.cpp index 74f809c..463d547 100644 --- a/libs/dpm/restriction.cpp +++ b/libs/dpm/restriction.cpp @@ -366,23 +366,23 @@ EXPORT_API int dpm_restriction_get_popimap_email_state(device_policy_manager_h h return DPM_ERROR_NONE; } -EXPORT_API int dpm_restriction_set_messaging_state(device_policy_manager_h handle, int allow) +EXPORT_API int dpm_restriction_set_messaging_state(device_policy_manager_h handle, const char *sim_id, int allow) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); DevicePolicyContext &client = GetDevicePolicyContext(handle); RestrictionPolicy restriction = client.createPolicyInterface(); - return restriction.setMessagingState(allow); + return restriction.setMessagingState(sim_id, allow); } -EXPORT_API int dpm_restriction_get_messaging_state(device_policy_manager_h handle, int *is_allowed) +EXPORT_API int dpm_restriction_get_messaging_state(device_policy_manager_h handle, const char *sim_id, int *is_allowed) { RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER); RET_ON_FAILURE(is_allowed, DPM_ERROR_INVALID_PARAMETER); DevicePolicyContext &client = GetDevicePolicyContext(handle); RestrictionPolicy restriction = client.createPolicyInterface(); - int ret = restriction.getMessagingState(); + int ret = restriction.getMessagingState(sim_id); if (ret < 0) { return -1; } diff --git a/libs/dpm/restriction.h b/libs/dpm/restriction.h index ed2cd51..65d015b 100644 --- a/libs/dpm/restriction.h +++ b/libs/dpm/restriction.h @@ -581,6 +581,7 @@ int dpm_restriction_get_bluetooth_pairing_state(device_policy_manager_h handle, * @privlevel partner * @privilege %http://tizen.org/privilege/dpm.message * @param[in] handle Device policy manager handle + * @param[in] sim_id SIM identifier * @param[in] allow If true, allow the use of SMS or text messaging, * if false, disallow the use of SMS or text messaging. * @return #DPM_ERROR_NONE on success, otherwise a negative value @@ -592,7 +593,7 @@ int dpm_restriction_get_bluetooth_pairing_state(device_policy_manager_h handle, * @pre The handle must be created by dpm_manager_create(). * @see dpm_restriction_get_messaging_state() */ -int dpm_restriction_set_messaging_state(device_policy_manager_h handle, int allow); +int dpm_restriction_set_messaging_state(device_policy_manager_h handle, const char *sim_id, int allow); /** * @brief Checks whether the text messaging is allowed or not. @@ -600,6 +601,7 @@ int dpm_restriction_set_messaging_state(device_policy_manager_h handle, int allo * is enabled or not. * @since_tizen 3.0 * @param[in] handle Device policy manager handle + * @param[in] sim_id SIM identifier * @param[out] is_allowed true if the messaging is allowed, false otherwise. * @return #DPM_ERROR_NONE on success, otherwise a negative value * @retval #DPM_ERROR_NONE Successful @@ -608,7 +610,7 @@ int dpm_restriction_set_messaging_state(device_policy_manager_h handle, int allo * @pre The handle must be created by dpm_manager_create(). * @see dpm_restriction_set_messaging_state() */ -int dpm_restriction_get_messaging_state(device_policy_manager_h handle, int *is_allowed); +int dpm_restriction_get_messaging_state(device_policy_manager_h handle, const char *sim_id, int *is_allowed); /** * @partner diff --git a/libs/ivi.cmake b/libs/ivi.cmake index 5502e91..97e995c 100644 --- a/libs/ivi.cmake +++ b/libs/ivi.cmake @@ -23,5 +23,6 @@ SET(POLICY ${POLICY} SET(CAPI ${CAPI} dpm/password.h + dpm/password_internal.h dpm/zone.h ) diff --git a/libs/mobile.cmake b/libs/mobile.cmake index 5502e91..97e995c 100644 --- a/libs/mobile.cmake +++ b/libs/mobile.cmake @@ -23,5 +23,6 @@ SET(POLICY ${POLICY} SET(CAPI ${CAPI} dpm/password.h + dpm/password_internal.h dpm/zone.h ) diff --git a/libs/password.cpp b/libs/password.cpp index 27a37bb..1d2e0c3 100644 --- a/libs/password.cpp +++ b/libs/password.cpp @@ -269,4 +269,22 @@ std::vector PasswordPolicy::getForbiddenStrings() return error; } } + +int PasswordPolicy::setRecovery(int enable) +{ + try { + return context->methodCall("PasswordPolicy::setRecovery", enable); + } catch (runtime::Exception &e) { + return -1; + } +} + +int PasswordPolicy::getRecovery() +{ + try { + return context->methodCall("PasswordPolicy::getRecovery"); + } catch (runtime::Exception &e) { + return -1; + } +} } /* namespace DevicePolicyManager */ diff --git a/libs/restriction.cpp b/libs/restriction.cpp index 307c597..30056d3 100644 --- a/libs/restriction.cpp +++ b/libs/restriction.cpp @@ -152,19 +152,19 @@ int RestrictionPolicy::getPopImapEmailState() } } -int RestrictionPolicy::setMessagingState(int enable) +int RestrictionPolicy::setMessagingState(const std::string &sim_id, int enable) { try { - return context->methodCall("RestrictionPolicy::setMessagingState", enable); + return context->methodCall("RestrictionPolicy::setMessagingState", sim_id, enable); } catch (runtime::Exception& e) { return -1; } } -int RestrictionPolicy::getMessagingState() +int RestrictionPolicy::getMessagingState(const std::string &sim_id) { try { - return context->methodCall("RestrictionPolicy::getMessagingState"); + return context->methodCall("RestrictionPolicy::getMessagingState", sim_id); } catch (runtime::Exception& e) { return -1; } diff --git a/libs/wearable.cmake b/libs/wearable.cmake index 3070ec0..4aad437 100644 --- a/libs/wearable.cmake +++ b/libs/wearable.cmake @@ -21,4 +21,5 @@ SET(POLICY ${POLICY} SET(CAPI ${CAPI} dpm/password.h + dpm/password_internal.h ) diff --git a/policy/password.hxx b/policy/password.hxx index 7c148c3..332df33 100644 --- a/policy/password.hxx +++ b/policy/password.hxx @@ -38,6 +38,15 @@ public: DPM_PASSWORD_STATUS_NOT_CHANGED, /**< Password not changed */ DPM_PASSWORD_STATUS_CHANGE_REQUIRED , /**< Password change required */ DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED, /**< Password Max Attempts Exceeded*/ + + DPM_PASSWORD_STATUS_EXPIRED, /**< Password expired */ + DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_FAILED, /**< Device unlock failed by Password Recovery */ + DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_SUCCEEDED,/**< Device unlock succeeded by Password Recovery */ + + DPM_PASSWORD_STATUS_QUALITY_CHANGED, /**< Password quality successfully changed */ + DPM_PASSWORD_STATUS_MIN_LENGTH_CHANGED, /**< Password min_length successfully changed */ + DPM_PASSWORD_STATUS_COMPLEX_CHAR_CHANGED, /**< Password complex_char successfully changed */ + DPM_PASSWORD_STATUS_PATTERN_CHANGED, /**< Password pattern successfully changed */ DPM_PASSWORD_STATUS_MAX } PasswordPolicyStatus; @@ -71,6 +80,8 @@ public: int getMaximumNumericSequenceLength(); int setForbiddenStrings(const std::vector &forbiddenStrings); std::vector getForbiddenStrings(); + int setRecovery(int enable); + int getRecovery(); private: PolicyControlContext &context; diff --git a/policy/restriction.hxx b/policy/restriction.hxx index ffaba33..e2ce163 100644 --- a/policy/restriction.hxx +++ b/policy/restriction.hxx @@ -49,8 +49,8 @@ public: int setPopImapEmailState(int enable); int getPopImapEmailState(); - int setMessagingState(int enable); - int getMessagingState(); + int setMessagingState(const std::string& sim_id, int enable); + int getMessagingState(const std::string& sim_id); int setBrowserState(int enable); int getBrowserState(); diff --git a/server/password.cpp b/server/password.cpp index b543ed7..ddd257a 100644 --- a/server/password.cpp +++ b/server/password.cpp @@ -90,6 +90,7 @@ PasswordPolicy::PasswordPolicy(PolicyControlContext &ctxt) : ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMaximumCharacterOccurrences)(int)); ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setMaximumNumericSequenceLength)(int)); ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setForbiddenStrings)(std::vector)); + ctxt.registerParametricMethod(this, DPM_PRIVILEGE_PASSWORD, (int)(PasswordPolicy::setRecovery)(int)); ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getStatus)); ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getQuality)); @@ -103,6 +104,7 @@ PasswordPolicy::PasswordPolicy(PolicyControlContext &ctxt) : ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMaximumCharacterOccurrences)); ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getMaximumNumericSequenceLength)); ctxt.registerNonparametricMethod(this, "", (std::vector)(PasswordPolicy::getForbiddenStrings)); + ctxt.registerNonparametricMethod(this, "", (int)(PasswordPolicy::getRecovery)); ctxt.createNotification("password"); } @@ -114,19 +116,23 @@ PasswordPolicy::~PasswordPolicy() int PasswordPolicy::setQuality(int quality) { try { - PasswordManager::QualityType type = getPasswordQualityType(quality); + int authQuality = DPM_PASSWORD_QUALITY_UNSPECIFIED; + if (quality & DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD) { + authQuality = quality - DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD; + } + PasswordManager::QualityType type = getPasswordQualityType(authQuality); if (!setPasswordPolicy(context, "password-quality", quality)) { return 0; } - if (quality == DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD) { + if (quality & DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD) { setPasswordPolicy(context, "password-minimum-length", SIMPLE_PASSWORD_LENGTH); } PasswordManager passwordManager(context.getPeerUid()); passwordManager.setQuality(type); - if (quality == DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD) { + if (quality & DPM_PASSWORD_QUALITY_SIMPLE_PASSWORD) { passwordManager.setMinimumLength(SIMPLE_PASSWORD_LENGTH); } passwordManager.enforce(); @@ -333,29 +339,45 @@ int PasswordPolicy::setStatus(int status) return -1; } - if (status == DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED) { - ERROR("Max Attempts Exceeded."); + switch (status) { + case DPM_PASSWORD_STATUS_CHANGED: + context.notify("password", "DPM_PASSWORD_STATUS_CHANGED"); + break; + case DPM_PASSWORD_STATUS_NOT_CHANGED: + context.notify("password", "DPM_PASSWORD_STATUS_NOT_CHANGED"); + break; + case DPM_PASSWORD_STATUS_CHANGE_REQUIRED: + context.notify("password", "DPM_PASSWORD_STATUS_CHANGE_REQUIRED"); + break; + case DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED: context.notify("password", "DPM_PASSWORD_STATUS_MAX_ATTEMPTS_EXCEEDED"); - return -1; + break; + case DPM_PASSWORD_STATUS_EXPIRED: + context.notify("password", "DPM_PASSWORD_STATUS_EXPIRED"); + break; + case DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_FAILED: + context.notify("password", "DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_FAILED"); + break; + case DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_SUCCEEDED: + context.notify("password", "DPM_PASSWORD_STATUS_RECOVERY_PASSWORD_SUCCEEDED"); + break; + case DPM_PASSWORD_STATUS_QUALITY_CHANGED: + context.notify("password", "DPM_PASSWORD_STATUS_QUALITY_CHANGED"); + break; + case DPM_PASSWORD_STATUS_MIN_LENGTH_CHANGED: + context.notify("password", "DPM_PASSWORD_STATUS_MIN_LENGTH_CHANGED"); + break; + case DPM_PASSWORD_STATUS_COMPLEX_CHAR_CHANGED: + context.notify("password", "DPM_PASSWORD_STATUS_COMPLEX_CHAR_CHANGED"); + break; + case DPM_PASSWORD_STATUS_PATTERN_CHANGED: + context.notify("password", "DPM_PASSWORD_STATUS_PATTERN_CHANGED"); + break; } - if (PasswordStatus == DPM_PASSWORD_STATUS_CHANGE_REQUIRED) { - if (status == DPM_PASSWORD_STATUS_CHANGED) { - PasswordStatus = DPM_PASSWORD_STATUS_NORMAL; - context.notify("password", "DPM_PASSWORD_STATUS_NORMAL"); - return 0; - } else if (status == DPM_PASSWORD_STATUS_NOT_CHANGED) { - return 0; - } - } else if (PasswordStatus == DPM_PASSWORD_STATUS_NORMAL) { - if (status == DPM_PASSWORD_STATUS_CHANGE_REQUIRED) { - PasswordStatus = status; - context.notify("password", "DPM_PASSWORD_STATUS_CHANGE_REQUIRED"); - return 0; - } - } + PasswordStatus = status; - return -1; + return 0; } int PasswordPolicy::getStatus() @@ -451,6 +473,23 @@ std::vector PasswordPolicy::getForbiddenStrings() return ForbiddenStrings; } +int PasswordPolicy::setRecovery(int enable) +{ + try { + SetPolicyEnabled(context, "password-recovery", enable); + } catch (runtime::Exception &e) { + ERROR("Failed to set recovery"); + return -1; + } + + return 0; +} + +int PasswordPolicy::getRecovery() +{ + return getPasswordPolicy(context, "password-recovery"); +} + DEFINE_POLICY(PasswordPolicy); } /* namespace DevicePolicyManager*/ diff --git a/server/policy-manager.cpp b/server/policy-manager.cpp index 17926ae..d67cbbe 100644 --- a/server/policy-manager.cpp +++ b/server/policy-manager.cpp @@ -77,6 +77,7 @@ std::unordered_map managedPolicyMap = { DEFINE_GLOBAL_POLICY("password-numeric-sequences-length", INT_MAX, MinimizeIntegerComparator), DEFINE_GLOBAL_POLICY("password-maximum-character-occurrences", INT_MAX, MinimizeIntegerComparator), DEFINE_GLOBAL_POLICY("password-quality", 0, MaximizeIntegerComparator), + DEFINE_GLOBAL_POLICY("password-recovery", 0, RestrictionComparator), DEFINE_GLOBAL_POLICY("bluetooth", 1, StateComparator), DEFINE_GLOBAL_POLICY("bluetooth-tethering", 1, StateComparator), DEFINE_GLOBAL_POLICY("bluetooth-desktop-connectivity", 1, StateComparator), diff --git a/server/restriction.cpp b/server/restriction.cpp index dd287a0..ed481c2 100644 --- a/server/restriction.cpp +++ b/server/restriction.cpp @@ -68,7 +68,8 @@ RestrictionPolicy::RestrictionPolicy(PolicyControlContext& ctxt) : context.registerParametricMethod(this, DPM_PRIVILEGE_USB, (int)(RestrictionPolicy::setUsbTetheringState)(int)); context.registerParametricMethod(this, DPM_PRIVILEGE_STORAGE, (int)(RestrictionPolicy::setExternalStorageState)(int)); context.registerParametricMethod(this, DPM_PRIVILEGE_EMAIL, (int)(RestrictionPolicy::setPopImapEmailState)(int)); - context.registerParametricMethod(this, DPM_PRIVILEGE_MESSAGING, (int)(RestrictionPolicy::setMessagingState)(int)); + context.registerParametricMethod(this, DPM_PRIVILEGE_MESSAGING, (int)(RestrictionPolicy::setMessagingState)(std::string, int)); + context.registerParametricMethod(this, "", (int)(RestrictionPolicy::getMessagingState)(std::string)); context.registerParametricMethod(this, DPM_PRIVILEGE_BROWSER, (int)(RestrictionPolicy::setBrowserState)(int)); context.registerNonparametricMethod(this, "", (int)(RestrictionPolicy::getCameraState)); @@ -78,7 +79,6 @@ RestrictionPolicy::RestrictionPolicy(PolicyControlContext& ctxt) : context.registerNonparametricMethod(this, "", (int)(RestrictionPolicy::getUsbTetheringState)); context.registerNonparametricMethod(this, "", (int)(RestrictionPolicy::getExternalStorageState)); context.registerNonparametricMethod(this, "", (int)(RestrictionPolicy::getPopImapEmailState)); - context.registerNonparametricMethod(this, "", (int)(RestrictionPolicy::getMessagingState)); context.registerNonparametricMethod(this, "", (int)(RestrictionPolicy::getBrowserState)); context.createNotification(restrictionNotifications); @@ -243,7 +243,7 @@ int RestrictionPolicy::getPopImapEmailState() return context.getPolicy("popimap-email"); } -int RestrictionPolicy::setMessagingState(int enable) +int RestrictionPolicy::setMessagingState(const std::string& sim_id, int enable) { try { SetPolicyAllowed(context, "messaging", enable); @@ -254,7 +254,7 @@ int RestrictionPolicy::setMessagingState(int enable) return 0; } -int RestrictionPolicy::getMessagingState() +int RestrictionPolicy::getMessagingState(const std::string& sim_id) { return context.getPolicy("messaging"); } diff --git a/tests/password.c b/tests/password.c index ff963c7..b6b946c 100644 --- a/tests/password.c +++ b/tests/password.c @@ -64,7 +64,7 @@ static int password_set_password_quality(struct testcase *tc) static int password_get_password_quality(struct testcase *tc) { device_policy_manager_h handle; - dpm_password_quality_e quality = DPM_PASSWORD_QUALITY_UNSPECIFIED; + int quality = DPM_PASSWORD_QUALITY_UNSPECIFIED; handle = dpm_manager_create(); if (handle == NULL) { diff --git a/tests/restriction.c b/tests/restriction.c index 9b62ceb..101fae3 100644 --- a/tests/restriction.c +++ b/tests/restriction.c @@ -78,6 +78,61 @@ struct testcase restriction_testcase_##__name__ = { \ .handler = restriction_##__name__ \ } + +static int restriction_messaging(struct testcase *tc) +{ + device_policy_manager_h handle; + int state, enable = false; + handle = dpm_manager_create(); + if (handle == NULL) { + printf("Failed to create client handle\n"); + return TEST_FAILED; + } + if (dpm_restriction_get_messaging_state(NULL, "SIM1", &state) == 0) { + printf("NULL handle test in getter failed\n"); + dpm_context_destroy(handle); + return TEST_FAILED; + } + if (dpm_restriction_get_messaging_state(handle, "SIM1", NULL) == 0) { + printf("NULL param test failed\n"); + dpm_context_destroy(handle); + return TEST_FAILED; + } + if (dpm_restriction_set_messaging_state(NULL, "SIM1", false) == 0) { + printf("NULL handle test in setter failed\n"); + dpm_context_destroy(handle); + return TEST_FAILED; + } + if (dpm_restriction_get_messaging_state(handle, "SIM1", &state) != 0) { + printf("Policy query failed\n"); + dpm_context_destroy(handle); + return TEST_FAILED; + } + enable = !state; + if (dpm_restriction_set_messaging_state(handle, "SIM1", enable) != 0) { + printf("Policy enforce failed\n"); + dpm_context_destroy(handle); + return TEST_FAILED; + } + dpm_restriction_get_messaging_state(handle, "SIM1", &enable); + if (enable != !state) { + printf("Policy check failed\n"); + dpm_context_destroy(handle); + return TEST_FAILED; + } + if (dpm_restriction_set_messaging_state(handle, "SIM1", state) != 0) { + printf("Policy recovery failed\n"); + dpm_context_destroy(handle); + return TEST_FAILED; + } + dpm_context_destroy(handle); + return TEST_SUCCESSED; +} +struct testcase restriction_testcase_messaging = { + .description = "restriction_testcase_messaging", + .handler = restriction_messaging +}; + DEFINE_RESTRICTION_TESTCASE(clipboard); DEFINE_RESTRICTION_TESTCASE(wifi); DEFINE_RESTRICTION_TESTCASE(wifi_hotspot); @@ -86,7 +141,6 @@ DEFINE_RESTRICTION_TESTCASE(usb_tethering); DEFINE_RESTRICTION_TESTCASE(bluetooth_mode_change); DEFINE_RESTRICTION_TESTCASE(bluetooth_desktop_connectivity); DEFINE_RESTRICTION_TESTCASE(bluetooth_pairing); -DEFINE_RESTRICTION_TESTCASE(messaging); DEFINE_RESTRICTION_TESTCASE(popimap_email); DEFINE_RESTRICTION_TESTCASE(browser); DEFINE_RESTRICTION_TESTCASE(camera); -- 2.7.4