2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
23 #include <tizen_type.h>
25 #include <dpm/pil/policy-client.h>
33 Array(std::vector<T> &&list) : list(std::move(list)), it(this->list.begin())
37 Array(const std::vector<T> &list) : list(list), it(this->list.begin())
42 if (it != list.end()) {
49 return it == list.end();
54 typename std::vector<T>::iterator it;
57 EXPORT_API int dpm_password_set_quality(void* handle, int quality)
59 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
60 RET_ON_FAILURE(quality >= 0, DPM_ERROR_INVALID_PARAMETER);
62 DevicePolicyClient &client = GetDevicePolicyClient(handle);
65 Status<int> ret { -1 };
66 ret = client.methodCall<int>("Password::setQuality", quality);
73 EXPORT_API int dpm_password_get_quality(void* handle, int *quality)
75 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
76 RET_ON_FAILURE(quality, DPM_ERROR_INVALID_PARAMETER);
78 DevicePolicyClient &client = GetDevicePolicyClient(handle);
81 Status<int> ret { 0 };
82 ret = client.methodCall<int>("Password::getQuality");
92 return DPM_ERROR_NONE;
95 EXPORT_API int dpm_password_set_minimum_length(void* handle, int value)
97 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
98 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
100 DevicePolicyClient &client = GetDevicePolicyClient(handle);
103 Status<int> ret { 0 };
104 ret = client.methodCall<int>("Password::setMinimumLength", value);
111 EXPORT_API int dpm_password_get_minimum_length(void* handle, int *value)
113 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
114 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
116 DevicePolicyClient &client = GetDevicePolicyClient(handle);
119 Status<int> ret { 0 };
120 ret = client.methodCall<int>("Password::getMinimumLength");
131 return DPM_ERROR_NONE;
134 EXPORT_API int dpm_password_set_min_complex_chars(void* handle, int value)
136 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
137 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
139 DevicePolicyClient &client = GetDevicePolicyClient(handle);
142 Status<int> ret { -1 };
143 ret = client.methodCall<int>("Password::setMinComplexChars", value);
150 EXPORT_API int dpm_password_get_min_complex_chars(void* handle, int *value)
152 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
153 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
155 DevicePolicyClient &client = GetDevicePolicyClient(handle);
158 Status<int> ret { 0 };
159 ret = client.methodCall<int>("Password::getMinComplexChars");
169 return DPM_ERROR_NONE;
172 EXPORT_API int dpm_password_set_maximum_failed_attempts_for_wipe(void* handle, int value)
174 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
175 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
177 DevicePolicyClient &client = GetDevicePolicyClient(handle);
180 Status<int> ret { -1 };
181 ret = client.methodCall<int>("Password::setMaximumFailedForWipe", value);
188 EXPORT_API int dpm_password_get_maximum_failed_attempts_for_wipe(void* handle, int *value)
190 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
191 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
193 DevicePolicyClient &client = GetDevicePolicyClient(handle);
196 Status<int> ret { 0 };
197 ret = client.methodCall<int>("Password::getMaximumFailedForWipe");
207 return DPM_ERROR_NONE;
210 EXPORT_API int dpm_password_set_expires(void* handle, int value)
212 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
213 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
215 DevicePolicyClient &client = GetDevicePolicyClient(handle);
218 Status<int> ret { -1 };
219 ret = client.methodCall<int>("Password::setExpires", value);
226 EXPORT_API int dpm_password_get_expires(void* handle, int *value)
228 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
229 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
231 DevicePolicyClient &client = GetDevicePolicyClient(handle);
234 Status<int> ret { 0 };
235 ret = client.methodCall<int>("Password::getExpires");
245 return DPM_ERROR_NONE;
248 EXPORT_API int dpm_password_set_history(void* handle, int value)
250 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
251 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
253 DevicePolicyClient &client = GetDevicePolicyClient(handle);
256 Status<int> ret { -1 };
257 ret = client.methodCall<int>("Password::setHistory", value);
264 EXPORT_API int dpm_password_get_history(void* handle, int *value)
266 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
267 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
269 DevicePolicyClient &client = GetDevicePolicyClient(handle);
272 Status<int> ret { 0 };
273 ret = client.methodCall<int>("Password::getHistory");
283 return DPM_ERROR_NONE;
286 EXPORT_API int dpm_password_set_pattern(void* handle, const char *pattern)
288 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
289 RET_ON_FAILURE(pattern, DPM_ERROR_INVALID_PARAMETER);
291 DevicePolicyClient &client = GetDevicePolicyClient(handle);
294 Status<int> ret { -1 };
295 ret = client.methodCall<int>("Password::setPattern", pattern);
302 EXPORT_API int dpm_password_reset(void* handle, const char *passwd)
304 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
305 RET_ON_FAILURE(passwd, DPM_ERROR_INVALID_PARAMETER);
307 DevicePolicyClient &client = GetDevicePolicyClient(handle);
310 Status<int> ret { -1 };
311 ret = client.methodCall<int>("Password::reset", passwd);
318 EXPORT_API int dpm_password_enforce_change(void* handle)
320 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
322 DevicePolicyClient &client = GetDevicePolicyClient(handle);
325 Status<int> ret { -1 };
326 ret = client.methodCall<int>("Password::enforceChange");
333 EXPORT_API int dpm_password_set_max_inactivity_time_device_lock(void* handle, int value)
335 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
336 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
338 DevicePolicyClient &client = GetDevicePolicyClient(handle);
341 Status<int> ret { -1 };
342 ret = client.methodCall<int>("Password::setMaxInactivityTimeDeviceLock", value);
349 EXPORT_API int dpm_password_get_max_inactivity_time_device_lock(void* handle, int *value)
351 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
352 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
354 DevicePolicyClient &client = GetDevicePolicyClient(handle);
357 Status<int> ret { 0 };
358 ret = client.methodCall<int>("Password::getMaxInactivityTimeDeviceLock");;
368 return DPM_ERROR_NONE;
371 EXPORT_API int dpm_password_set_status(void* handle, dpm_password_status_e status)
373 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
374 RET_ON_FAILURE(status >= DPM_PASSWORD_STATUS_NORMAL &&
375 status <= DPM_PASSWORD_STATUS_PATTERN_CHANGED,
376 DPM_ERROR_INVALID_PARAMETER);
378 DevicePolicyClient &client = GetDevicePolicyClient(handle);
381 Status<int> ret { -1 };
382 ret = client.methodCall<int>("Password::setStatus", (int)status);
389 EXPORT_API int dpm_password_get_ret(void* handle, dpm_password_status_e *status)
391 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
392 RET_ON_FAILURE(status, DPM_ERROR_INVALID_PARAMETER);
394 DevicePolicyClient &client = GetDevicePolicyClient(handle);
397 Status<int> ret { 0 };
398 ret = client.methodCall<int>("Password::getStatus");
403 *status = (dpm_password_status_e)ret.get();
408 return DPM_ERROR_NONE;
411 EXPORT_API int dpm_password_delete_pattern(void* handle)
413 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
415 DevicePolicyClient &client = GetDevicePolicyClient(handle);
418 Status<int> ret { -1 };
419 ret = client.methodCall<int>("Password::deletePattern");
426 EXPORT_API int dpm_password_get_pattern(void* handle, char **pattern)
428 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
429 RET_ON_FAILURE(pattern, DPM_ERROR_INVALID_PARAMETER);
431 DevicePolicyClient &client = GetDevicePolicyClient(handle);
434 Status<std::string> ret { std::string() };
435 ret = client.methodCall<std::string>("Password::getPattern");
436 *pattern = ::strdup(ret.get().c_str());
441 return DPM_ERROR_NONE;
444 EXPORT_API int dpm_password_set_maximum_character_occurrences(void* handle, int value)
446 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
447 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
449 DevicePolicyClient &client = GetDevicePolicyClient(handle);
452 Status<int> ret { -1 };
453 ret = client.methodCall<int>("Password::setMaximumCharacterOccurrences", value);
460 EXPORT_API int dpm_password_get_maximum_character_occurrences(void* handle, int *value)
462 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
463 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
465 DevicePolicyClient &client = GetDevicePolicyClient(handle);
468 Status<int> ret { 0 };
469 ret = client.methodCall<int>("Password::getMaximumCharacterOccurrences");
479 return DPM_ERROR_NONE;
482 EXPORT_API int dpm_password_set_maximum_numeric_sequence_length(void* handle, int value)
484 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
485 RET_ON_FAILURE(value >= 0, DPM_ERROR_INVALID_PARAMETER);
487 DevicePolicyClient &client = GetDevicePolicyClient(handle);
490 Status<int> ret { -1 };
491 ret = client.methodCall<int>("Password::setMaximumNumericSequenceLength", value);
498 EXPORT_API int dpm_password_get_maximum_numeric_sequence_length(void* handle, int *value)
500 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
501 RET_ON_FAILURE(value, DPM_ERROR_INVALID_PARAMETER);
503 DevicePolicyClient &client = GetDevicePolicyClient(handle);
506 Status<int> ret { 0 };
507 ret = client.methodCall<int>("Password::getMaximumNumericSequenceLength");
517 return DPM_ERROR_NONE;
520 typedef Array<std::string> dpm_password_iterator;
522 EXPORT_API dpm_password_iterator_h dpm_password_create_iterator(void* handle)
524 RET_ON_FAILURE(handle, NULL);
526 DevicePolicyClient &client = GetDevicePolicyClient(handle);
528 Status<std::vector<std::string>> status { std::vector<std::string>() };
529 status = client.methodCall<std::vector<std::string>>("Password::getForbiddenStrings");
531 dpm_password_iterator *iter = new dpm_password_iterator(status.get());
532 return reinterpret_cast<dpm_password_iterator_h>(iter);
535 EXPORT_API int dpm_password_iterator_next(dpm_password_iterator_h iter, const char **result)
537 RET_ON_FAILURE(iter, DPM_ERROR_INVALID_PARAMETER);
538 RET_ON_FAILURE(result, DPM_ERROR_INVALID_PARAMETER);
540 dpm_password_iterator *it = reinterpret_cast<dpm_password_iterator *>(iter);
545 *result = it->next()->c_str();
547 return DPM_ERROR_NONE;
550 EXPORT_API int dpm_password_destroy_iterator(dpm_password_iterator_h iter)
552 RET_ON_FAILURE(iter, DPM_ERROR_INVALID_PARAMETER);
554 delete reinterpret_cast<dpm_password_iterator *>(iter);
556 return DPM_ERROR_NONE;
559 EXPORT_API int dpm_password_set_forbidden_strings(void* handle, const char *strings[], int length)
561 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
563 DevicePolicyClient &client = GetDevicePolicyClient(handle);
564 std::vector<std::string> forbiddenStrings;
566 for (int i = 0; i < length; i++)
567 forbiddenStrings.push_back(strings[i]);
570 Status<int> ret { -1 };
571 ret = client.methodCall<int>("Password::setForbiddenStrings", forbiddenStrings);
578 EXPORT_API int dpm_password_set_recovery(void* handle, int enable)
580 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
582 DevicePolicyClient &client = GetDevicePolicyClient(handle);
585 Status<int> ret { -1 };
586 ret = client.methodCall<int>("Password::setRecovery", enable);
593 EXPORT_API int dpm_password_get_recovery(void* handle, int *enable)
595 RET_ON_FAILURE(handle, DPM_ERROR_INVALID_PARAMETER);
596 RET_ON_FAILURE(enable, DPM_ERROR_INVALID_PARAMETER);
598 DevicePolicyClient &client = GetDevicePolicyClient(handle);
601 Status<int> ret { false };
602 ret = client.methodCall<int>("Password::getRecovery");
612 return DPM_ERROR_NONE;