Modify Password and Restriction API 41/101041/12
authorSungjun, Lee <sjun221.lee@samsung.com>
Wed, 30 Nov 2016 06:58:48 +0000 (15:58 +0900)
committerSungjun, Lee <sjun221.lee@samsung.com>
Fri, 2 Dec 2016 08:24:21 +0000 (17:24 +0900)
Change-Id: I588ca784ec92520183a148ad8a9d083fb6d61d42
Signed-off-by: Sungjun, Lee <sjun221.lee@samsung.com>
18 files changed:
libs/common.cmake
libs/dpm/password.cpp
libs/dpm/password.h
libs/dpm/password_internal.h [new file with mode: 0644]
libs/dpm/restriction.cpp
libs/dpm/restriction.h
libs/ivi.cmake
libs/mobile.cmake
libs/password.cpp
libs/restriction.cpp
libs/wearable.cmake
policy/password.hxx
policy/restriction.hxx
server/password.cpp
server/policy-manager.cpp
server/restriction.cpp
tests/password.c
tests/restriction.c

index 5502e91..97e995c 100644 (file)
@@ -23,5 +23,6 @@ SET(POLICY      ${POLICY}
 
 SET(CAPI        ${CAPI}
                                dpm/password.h
+                               dpm/password_internal.h
                                dpm/zone.h
 )
index 3337d9c..c2029b4 100644 (file)
@@ -18,6 +18,7 @@
 #include <cassert>
 
 #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<PasswordPolicy>();
+
+       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<PasswordPolicy>();
+
+       int ret = password.getRecovery();
+       if (ret < 0) {
+               return -1;
+       }
+
+       *enable = ret;
+
+       return DPM_ERROR_NONE;
+}
index e5d2a60..dd1c6b0 100644 (file)
@@ -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 (file)
index 0000000..a02274d
--- /dev/null
@@ -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 <dpm/device-policy-manager.h>
+
+#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__ */
+
index 74f809c..463d547 100644 (file)
@@ -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<RestrictionPolicy>();
-       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<RestrictionPolicy>();
-       int ret = restriction.getMessagingState();
+       int ret = restriction.getMessagingState(sim_id);
        if (ret < 0) {
                return -1;
        }
index ed2cd51..65d015b 100644 (file)
@@ -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
index 5502e91..97e995c 100644 (file)
@@ -23,5 +23,6 @@ SET(POLICY      ${POLICY}
 
 SET(CAPI        ${CAPI}
                                dpm/password.h
+                               dpm/password_internal.h
                                dpm/zone.h
 )
index 5502e91..97e995c 100644 (file)
@@ -23,5 +23,6 @@ SET(POLICY      ${POLICY}
 
 SET(CAPI        ${CAPI}
                                dpm/password.h
+                               dpm/password_internal.h
                                dpm/zone.h
 )
index 27a37bb..1d2e0c3 100644 (file)
@@ -269,4 +269,22 @@ std::vector<std::string> PasswordPolicy::getForbiddenStrings()
                return error;
        }
 }
+
+int PasswordPolicy::setRecovery(int enable)
+{
+       try {
+               return context->methodCall<int>("PasswordPolicy::setRecovery", enable);
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
+
+int PasswordPolicy::getRecovery()
+{
+       try {
+               return context->methodCall<int>("PasswordPolicy::getRecovery");
+       } catch (runtime::Exception &e) {
+               return -1;
+       }
+}
 } /* namespace DevicePolicyManager */
index 307c597..30056d3 100644 (file)
@@ -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<int>("RestrictionPolicy::setMessagingState", enable);
+               return context->methodCall<int>("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<int>("RestrictionPolicy::getMessagingState");
+               return context->methodCall<int>("RestrictionPolicy::getMessagingState", sim_id);
        } catch (runtime::Exception& e) {
                return -1;
        }
index 3070ec0..4aad437 100644 (file)
@@ -21,4 +21,5 @@ SET(POLICY      ${POLICY}
 
 SET(CAPI        ${CAPI}
                                dpm/password.h
+                               dpm/password_internal.h
 )
index 7c148c3..332df33 100644 (file)
@@ -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<std::string> &forbiddenStrings);
        std::vector<std::string> getForbiddenStrings();
+       int setRecovery(int enable);
+       int getRecovery();
 
 private:
        PolicyControlContext &context;
index ffaba33..e2ce163 100644 (file)
@@ -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();
index b543ed7..ddd257a 100644 (file)
@@ -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<std::string>));
+       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<std::string>)(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<std::string> 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*/
index 17926ae..d67cbbe 100644 (file)
@@ -77,6 +77,7 @@ std::unordered_map<std::string, ManagedPolicy> 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),
index dd287a0..ed481c2 100644 (file)
@@ -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");
 }
index ff963c7..b6b946c 100644 (file)
@@ -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) {
index 9b62ceb..101fae3 100644 (file)
@@ -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);