From 91214761892fcfeedaadb5651f05c9ddce6469b8 Mon Sep 17 00:00:00 2001
From: Pawel Kowalski
Date: Tue, 2 Oct 2018 15:38:29 +0200
Subject: [PATCH] [PPMTester] Unify and improve logging
Change-Id: Ic8c6be5a8b0afa9321152f88d7cb07e0abecc856
---
test/apps/capi/PPMTester/src/ppmtester.c | 132 ++++++++++---------------------
test/apps/capi/PPMTester/src/ppmtester.h | 43 ++++------
2 files changed, 58 insertions(+), 117 deletions(-)
diff --git a/test/apps/capi/PPMTester/src/ppmtester.c b/test/apps/capi/PPMTester/src/ppmtester.c
index 9ff2391..58a5c15 100644
--- a/test/apps/capi/PPMTester/src/ppmtester.c
+++ b/test/apps/capi/PPMTester/src/ppmtester.c
@@ -28,7 +28,7 @@ static void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info
ui_app_exit();
}
-void print_msg(Evas_Object *obj, const char* msg, ...)
+void msg_print(Evas_Object *obj, const char* msg, ...)
{
va_list args;
va_start(args, msg);
@@ -57,13 +57,32 @@ void log_msg(appdata_s *ad, const char* msg, ...)
const char* separator = "";
- print_msg(ad->msg_box, buffer);
- print_msg(ad->msg_box, separator);
+ msg_print(ad->msg_box, buffer);
+ msg_print(ad->msg_box, separator);
dlog_print(DLOG_INFO, LOG_TAG, buffer);
dlog_print(DLOG_INFO, LOG_TAG, separator);
}
+void log_result(appdata_s *ad, ppm_request_result_e result, const char *privilege)
+{
+ switch (result)
+ {
+ case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER:
+ log_msg(ad, "A user granted permission to use the %s privilege for an indefinite period of time.", privilege);
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_FOREVER:
+ log_msg(ad, "A user did not grant permission to use the %s privilege for an indefinite period of time.", privilege);
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_ONCE:
+ log_msg(ad, "A user did not grant permission to use the %s privilege once.", privilege);
+ break;
+ default:
+ log_msg(ad, "Unknown result (%d) for the %s privilege.", result, privilege);
+ break;
+ }
+}
+
static void _btn_clear_cb(void *data, Evas_Object *btn, void *event_info)
{
appdata_s *ad = data;
@@ -170,64 +189,21 @@ Evas_Object *_new_button(appdata_s *ad, Evas_Object *display, const char *name,
return bt;
}
-void log_privilege(appdata_s *ad, const char* privilege, const char* msg)
-{
- if (msg == NULL)
- return;
- if (privilege != NULL)
- {
- print_msg(ad->msg_box, "----------
Privilege: %s
Message: %s", privilege, msg);
- dlog_print(DLOG_INFO, LOG_TAG, "----------\nPrivilege: %s\nMessage: %s", privilege, msg);
- }
- else
- {
- print_msg(ad->msg_box, "----------
Message: %s", msg);
- dlog_print(DLOG_INFO, LOG_TAG, "----------\\nMessage: %s", msg);
- }
-}
-
-void log_result(appdata_s *ad, ppm_request_result_e result, const char *privilege)
-{
- switch (result)
- {
- case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER:
- log_privilege(ad, privilege, "A user granted permission to use a privilege for an indefinite period of time.");
- break;
- case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_FOREVER:
- log_privilege(ad, privilege, "A user did not grant permission to use a privilege for an indefinite period of time.");
- break;
- case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_ONCE:
- log_privilege(ad, privilege, "A user did not grant permission to use a privilege once.");
- break;
- default:
- {
- char msg[BUFFER_SIZE];
- snprintf(msg, BUFFER_SIZE, "unknown result: %d", result);
- log_privilege(ad, privilege, "Unknown result: ");
- break;
- }
- }
-}
-
void ppm_popup_response_cb_function(ppm_call_cause_e cause, ppm_request_result_e result, const char *privilege, void *user_data)
{
appdata_s *ad = user_data;
switch (cause)
{
case PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ANSWER:
- log_privilege(ad, privilege, "Callback was called with a valid answer.");
+ log_msg(ad, "Callback for the %s privilege was called with a valid answer.", privilege);
log_result(ad, result, privilege);
break;
case PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR:
- log_privilege(ad, privilege, "Callback was called because of an error.");
+ log_msg(ad, "Callback for the %s privilege was called because of an error.", privilege);
break;
default:
- {
- char msg[BUFFER_SIZE];
- snprintf(msg, BUFFER_SIZE, "Unknown cause: %d", cause);
- log_privilege(ad, privilege, msg);
+ log_msg(ad, "Callback for the %s privilege was called because of an unknown cause: %d.", privilege, cause);
break;
- }
}
}
@@ -244,26 +220,22 @@ void ppm_popup_multiple_response_cb_function(ppm_call_cause_e cause,
case PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ANSWER:
for (int it = 0; it < privileges_count; ++it)
{
- log_privilege(ad, privileges[it], "Callback was called with a valid answer.");
+ log_msg(ad, "Callback for the %s privilege was called with a valid answer.", privileges[it]);
log_result(ad, results[it], privileges[it]);
}
break;
case PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR:
for (int it = 0; it < privileges_count; ++it)
{
- log_privilege(ad, privileges[it], "Callback was called because of an error.");
+ log_msg(ad, "Callback for the %s privilege was called because of an error.", privileges[it]);
}
break;
default:
- {
- char msg[BUFFER_SIZE];
- snprintf(msg, BUFFER_SIZE, "Unknown cause: %d", cause);
for (int it = 0; it < privileges_count; ++it)
{
- log_privilege(ad, privileges[it], msg);
+ log_msg(ad, "Callback for the %s privilege was called because of an unknown cause: %d.", privileges[it], cause);
}
break;
- }
}
if (second_request)
{
@@ -316,14 +288,13 @@ void check_privilege(appdata_s *ad, const char* privilege)
switch (result) // Allow, deny or ask.
{
case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ALLOW:
- log_privilege(ad, privilege, "An application has permission to use a privilege.");
+ log_msg(ad, "An application has permission to use the %s privilege.", privilege);
break;
case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY:
- log_privilege(ad, privilege, "An application doesn't have permission to use a privilege.");
+ log_msg(ad, "An application doesn't have permission to use the %s privilege.", privilege);
break;
case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK:
- {
- log_privilege(ad, privilege, "A user has to be asked whether to grant permission to use a privilege.");
+ log_msg(ad, "A user has to be asked whether to grant permission to use the %s privilege.", privilege);
int ret_popup = ppm_request_permission(privilege, ppm_popup_response_cb_function, ad);
if (ret_popup != PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE)
{
@@ -331,14 +302,9 @@ void check_privilege(appdata_s *ad, const char* privilege)
return;
}
break;
- }
default:
- {
- char msg[BUFFER_SIZE];
- snprintf(msg, BUFFER_SIZE, "Unknown result: %d", result);
- log_privilege(ad, privilege, msg);
+ log_msg(ad, "Unknown result (%d) for the %s privilege.", result, privilege);
break;
- }
}
}
@@ -366,7 +332,7 @@ void check_app_privilege(appdata_s *ad, const char* app_id, const char* privileg
log_msg(ad, "A user has to be asked whether to grant a permission to use the privilege %s for the following application: %s.", privilege, app_id);
break;
default:
- log_msg(ad, "Unknown result (%d) for %s privilege and %s app.", result, privilege, app_id);
+ log_msg(ad, "Unknown result (%d) for the %s privilege and the %s app.", result, privilege, app_id);
break;
}
}
@@ -376,8 +342,7 @@ void check_privileges(appdata_s *ad, const char** privileges, size_t privileges_
ppm_check_result_e* results = malloc(sizeof(ppm_check_result_e) * privileges_count);
if (!results)
{
- print_msg(ad->msg_box, "----------
unable to allocate memory for check_results.");
- dlog_print(DLOG_INFO, LOG_TAG, "----------\nunable to allocate memory for check_results.");
+ log_msg(ad, "Unable to allocate memory for check_results.");
return;
}
@@ -400,8 +365,7 @@ void check_privileges(appdata_s *ad, const char** privileges, size_t privileges_
}
if (!privs_to_ask)
{
- print_msg(ad->msg_box, "----------
unable to allocate memory for privileges to ask.");
- dlog_print(DLOG_INFO, LOG_TAG, "----------\nunable to allocate memory for privileges to ask.");
+ log_msg(ad, "Unable to allocate memory for privileges to ask.");
free(results);
return;
}
@@ -411,31 +375,21 @@ void check_privileges(appdata_s *ad, const char** privileges, size_t privileges_
switch (results[it]) // Allow, deny or ask.
{
case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ALLOW:
- {
- log_privilege(ad, privileges[it], "An application has permission to use a privilege.");
+ log_msg(ad, "An application has permission to use the %s privilege.", privileges[it]);
break;
- }
case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY:
- {
- log_privilege(ad, privileges[it], "An application doesn't have permission to use a privilege.");
+ log_msg(ad, "An application doesn't have permission to use the %s privilege.", privileges[it]);
break;
- }
case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK:
- {
- log_privilege(ad, privileges[it], "A user has to be asked whether to grant permission to use a privilege.");
+ log_msg(ad, "A user has to be asked whether to grant permission to use the %s privilege.", privileges[it]);
if (!request_privs_ignore_ask_status)
{
privs_to_ask[askable_privs_it++] = (char*)privileges[it];
}
break;
- }
default:
- {
- char msg[BUFFER_SIZE];
- snprintf(msg, BUFFER_SIZE, "Unknown result: %d", results[it]);
- log_privilege(ad, privileges[it], msg);
+ log_msg("Unknown result (%d) for the %s privilege.", results[it], privileges[it]);
break;
- }
}
}
free(results);
@@ -455,7 +409,7 @@ void check_privileges(appdata_s *ad, const char** privileges, size_t privileges_
{
for (int it = 0; it < askable_privs_it; ++it)
{
- log_privilege(ad, privs_to_ask[it], "Unable to request permissions");
+ log_msg(ad, "Unable to request permission for the %s privilege.", privs_to_ask[it]);
}
}
if (!request_privs_ignore_ask_status)
@@ -490,13 +444,13 @@ void check_app_privileges(appdata_s *ad, const char* app_id, const char** privi
switch (results[it]) // Allow, deny or ask.
{
case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ALLOW:
- log_msg(ad, "The application %s has a permission to use the following privilege: %s.", app_id, privileges[it]);
+ log_msg(ad, "The application %s has a permission to use the %s privilege.", app_id, privileges[it]);
break;
case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY:
- log_msg(ad, "The application %s doesn't have a permission to use the following privilege: %s.", app_id, privileges[it]);
+ log_msg(ad, "The application %s doesn't have a permission to use the %s privilege.", app_id, privileges[it]);
break;
case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK:
- log_msg(ad, "A user has to be asked whether to grant a permission to use the privilege %s for the following application: %s.", privileges[it], app_id);
+ log_msg(ad, "A user has to be asked whether to grant a permission to use the %s privilege for the %s application.", privileges[it], app_id);
break;
default:
log_msg(ad, "Unknown result (%d) for %s privilege and %s app.", results[it], privileges[it], app_id);
diff --git a/test/apps/capi/PPMTester/src/ppmtester.h b/test/apps/capi/PPMTester/src/ppmtester.h
index 68ce8d5..db8f4a1 100644
--- a/test/apps/capi/PPMTester/src/ppmtester.h
+++ b/test/apps/capi/PPMTester/src/ppmtester.h
@@ -17,6 +17,7 @@
/**
* @file ppmtester.h
* @author Ernest Borowski
+ * @author Pawel Kowalski
* @brief The header of testing application of the PPM CAPI.
*/
@@ -100,13 +101,13 @@ const other_privileges_s privacies_for_request_in_response_callback = {
static void win_delete_request_cb(void *data, Evas_Object *obj, void *event_info);
/**
- * @brief Prints massage into the message box.
+ * @brief Prints message into the message box.
*
* @param[in] obj The message box.
* @param[in] msg The text message that is written to the message box.
* @param[in] ... Additional arguments declared in the text message.
*/
-void print_msg(Evas_Object *obj, const char* msg, ...);
+void msg_print(Evas_Object *obj, const char* msg, ...);
/**
* @brief Prints massage into the message box and into the dlogutil logger.
@@ -118,6 +119,18 @@ void print_msg(Evas_Object *obj, const char* msg, ...);
void log_msg(appdata_s *ad, const char* msg, ...);
/**
+ * @brief Logs result from ppm_check_pemission(s) callback.
+ *
+ * @details In order to read a message using dlogutil, type in the emulator's
+ * terminal: dlogutil ppmtester. The 'ppmtester' flag is set using LOG_TAG constant.
+ *
+ * @param[in] ad The structure with GUI elements.
+ * @param[in] result The result of request.
+ * @param[in] privilege A privilege that is to be logged.
+ */
+void log_result(appdata_s *ad, ppm_request_result_e result, const char *privilege);
+
+/**
* @brief Clears the message box.
*
* @param[in] data User specific data.
@@ -139,32 +152,6 @@ Eina_Bool _pop_cb(void *data, Elm_Object_Item *item);
Evas_Object *_new_button(appdata_s *ad, Evas_Object *display, const char *name, void *cb);
/**
- * @brief Writes text into dlogutil and into GUI.
- *
- * @details In order to read a message using dlogutil,
- * type in the emulator's terminal: dlogutil ppmtester
- * The 'ppmtester' flag is set using LOG_TAG constant.
- *
- * @param[in] ad The structure with GUI elements.
- * @param[in] privilege A privilege that is to be logged.
- * @param[in] msg A text that is to be written.
- */
-void log_privilege(appdata_s *ad, const char* privilege, const char* msg);
-
-/**
- * @brief Logs result from ppm_check_pemission(s) callback
- *
- * @details In order to read a message using dlogutil,
- * type in the emulator's terminal: dlogutil ppmtester
- * The 'ppmtester' flag is set using LOG_TAG constant.
- *
- * @param[in] ad The structure with GUI elements.
- * @param[in] result The result of request.
- * @param[in] privilege A privilege that is to be logged.
- */
-void log_result(appdata_s *ad, ppm_request_result_e result, const char *privilege);
-
-/**
* @brief Based on ppm_popup_response_cb prototype from privacy-privilege-manager.h.
*
* @param[in] cause A value representing the reason why this callback
--
2.7.4