INCLUDE_DIRECTORIES(SYSTEM ${PRIVACY_PRIVILEGE_MANAGER_DEP_INCLUDE_DIRS})
INCLUDE_DIRECTORIES(
+ ${ASKUSER_PATH}/ipc-lib
${PRIVACY_PRIVILEGE_MANAGER_PATH}/include
${ASKUSER_PATH}/client/include
)
)
SET(PRIVACY_PRIVILEGE_MANAGER_SOURCES_TEST_SOURCES
- ${PRIVACY_PRIVILEGE_MANAGER_PATH}/test/privacy_privilege_manager_test.c
+ ${PRIVACY_PRIVILEGE_MANAGER_PATH}/test/privacy_privilege_manager_test.cpp
)
ADD_LIBRARY(${TARGET_PRIVACY_PRIVILEGE_MANAGER_CAPI_LIB} SHARED ${PRIVACY_PRIVILEGE_MANAGER_SOURCES})
TARGET_LINK_LIBRARIES(
${TARGET_PRIVACY_PRIVILEGE_MANAGER_CAPI_LIB}
${TARGET_ASKUSER_NOTIFICATION_CLIENT_LIB}
+ ${TARGET_ASKUSER_NOTIFICATION_LIB}
${PRIVACY_PRIVILEGE_MANAGER_DEP_LIBRARIES}
)
+++ /dev/null
-/*
- * Copyright (c) 2017 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
- */
-
-/**
- * @file privacy_privilege_manager.c
- * @author Piotr Sawicki <p.sawicki2@partner.samsung.com>
- * @version 1.0
- * @brief This file contains test of CAPI for Privacy Privilege Manager
- */
-
-#include <glib.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <privacy_privilege_manager.h>
-
-const char *result_to_str(ppm_popup_result_e result)
-{
- switch (result) {
- case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESULT_ALLOW_FOREVER:
- return "ALLOW_FOREVER";
- case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESULT_DENY_FOREVER:
- return "DENY_FOREVER";
- case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESULT_DENY_ONCE:
- return "DENY_ONCE";
- }
-
- return "UNKNOWN";
-}
-
-void popup_response_cb(ppm_call_cause_e cause, ppm_popup_result_e result, void *user_data)
-{
- int id = (int) user_data;
-
- printf("resp_id: %d ", id);
- switch (cause) {
- case PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ANSWER:
- printf("popup answer: %s\n", result_to_str(result));
- break;
- case PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR:
- printf("popup cause PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR\n");
- break;
- }
-
- printf(">");
- fflush(stdout);
-}
-
-static void print_help()
-{
- printf("0 <privilege> - check privilege status\n");
- printf("1 <privilege> - send popup request\n");
- printf("h - print help\n");
- printf("q - quit\n");
- printf(">");
- fflush(stdout);
-}
-
-static void print_error(ppm_error_e error)
-{
- switch (error) {
- case PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE:
- break;
- case PRIVACY_PRIVILEGE_MANAGER_ERROR_IO_ERROR:
- printf("I/O error\n");
- break;
- case PRIVACY_PRIVILEGE_MANAGER_ERROR_INVALID_PARAMETER:
- printf("Invalid parameters\n");
- break;
- case PRIVACY_PRIVILEGE_MANAGER_ERROR_OUT_OF_MEMORY:
- printf("Out of memory\n");
- case PRIVACY_PRIVILEGE_MANAGER_ERROR_UNKNOWN:
- printf("Unknown error\n");
- break;
- }
-}
-
-static void print_check_result(ppm_check_result_e result)
-{
- printf("res: ");
-
- switch (result) {
- case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ALLOW:
- printf("ALLOW\n");
- break;
- case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY:
- printf("DENY\n");
- break;
- case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK:
- printf("ASK\n");
- break;
- }
-
- printf(">");
- fflush(stdout);
-}
-
-gboolean main_loop_cb(GIOChannel *channel, GIOCondition cond, gpointer user_data)
-{
- int ret;
- char buffer[4096];
- ppm_check_result_e result;
-
- (void) channel; (void) cond; (void) user_data;
-
- ret = read(0, buffer, sizeof(buffer));
- if (ret < 0) {
- printf("read from stdin failed\n");
- exit(1);
- }
-
- buffer[ret - 1] = '\0';
- int id = rand() % 1024;
-
- switch (buffer[0]) {
- case '0':
- if (strlen(buffer) < 3) {
- print_help();
- break;
- }
- ret = ppm_check_privilege(&buffer[2], &result);
- if (ret == PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE) {
- print_check_result(result);
- }
- else {
- print_error(ret);
- }
- break;
- case '1':
- if (strlen(buffer) < 3) {
- print_help();
- break;
- }
- buffer[ret - 1] = '\0';
- print_error(ppm_popup_request(&buffer[2], popup_response_cb, (void *)id));
- break;
- case 'q':
- exit(0);
- case 'h':
- default:
- print_help();
- break;
- }
-
- return TRUE;
-}
-
-int main(int argc, char **argv)
-{
- (void) argc; (void) argv;
-
- srand(time(0));
- print_help();
-
- GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
-
- GIOChannel *channel = g_io_channel_unix_new(0);
- g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL, main_loop_cb, NULL);
-
- g_main_loop_run(mainloop);
-
- return 0;
-}
--- /dev/null
+/*
+ * Copyright (c) 2017 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
+ */
+
+/**
+ * @file privacy_privilege_manager.c
+ * @author Piotr Sawicki <p.sawicki2@partner.samsung.com>
+ * @version 1.0
+ * @brief This file contains test of CAPI for Privacy Privilege Manager
+ */
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <privacy_privilege_manager.h>
+
+const char *result_to_str(ppm_popup_result_e result)
+{
+ switch (result) {
+ case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESULT_ALLOW_FOREVER:
+ return "ALLOW_FOREVER";
+ case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESULT_DENY_FOREVER:
+ return "DENY_FOREVER";
+ case PRIVACY_PRIVILEGE_MANAGER_POPUP_RESULT_DENY_ONCE:
+ return "DENY_ONCE";
+ }
+
+ return "UNKNOWN";
+}
+
+void popup_response_cb(ppm_call_cause_e cause, ppm_popup_result_e result, void *user_data)
+{
+ int id = (int) user_data;
+
+ printf("resp_id: %d ", id);
+ switch (cause) {
+ case PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ANSWER:
+ printf("popup answer: %s\n", result_to_str(result));
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR:
+ printf("popup cause PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR\n");
+ break;
+ }
+
+ printf(">");
+ fflush(stdout);
+}
+
+static void print_help()
+{
+ printf("0 <privilege> - check privilege status\n");
+ printf("1 <privilege> - send popup request\n");
+ printf("h - print help\n");
+ printf("q - quit\n");
+ printf(">");
+ fflush(stdout);
+}
+
+static void print_error(ppm_error_e error)
+{
+ switch (error) {
+ case PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE:
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_ERROR_IO_ERROR:
+ printf("I/O error\n");
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_ERROR_INVALID_PARAMETER:
+ printf("Invalid parameters\n");
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_ERROR_OUT_OF_MEMORY:
+ printf("Out of memory\n");
+ case PRIVACY_PRIVILEGE_MANAGER_ERROR_UNKNOWN:
+ printf("Unknown error\n");
+ break;
+ }
+}
+
+static void print_check_result(ppm_check_result_e result)
+{
+ printf("res: ");
+
+ switch (result) {
+ case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ALLOW:
+ printf("ALLOW\n");
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY:
+ printf("DENY\n");
+ break;
+ case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK:
+ printf("ASK\n");
+ break;
+ }
+
+ printf(">");
+ fflush(stdout);
+}
+
+gboolean main_loop_cb(GIOChannel *channel, GIOCondition cond, gpointer user_data)
+{
+ int ret;
+ char buffer[4096];
+ ppm_check_result_e result;
+ ppm_error_e err;
+
+ (void) channel; (void) cond; (void) user_data;
+
+ ret = read(0, buffer, sizeof(buffer));
+ if (ret < 0) {
+ printf("read from stdin failed\n");
+ exit(1);
+ }
+
+ buffer[ret - 1] = '\0';
+ int id = rand() % 1024;
+
+ switch (buffer[0]) {
+ case '0':
+ if (strlen(buffer) < 3) {
+ print_help();
+ break;
+ }
+ err = static_cast<ppm_error_e>(ppm_check_privilege(&buffer[2], &result));
+ if (err == PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE) {
+ print_check_result(result);
+ }
+ else {
+ print_error(err);
+ }
+ break;
+ case '1':
+ if (strlen(buffer) < 3) {
+ print_help();
+ break;
+ }
+ buffer[ret - 1] = '\0';
+ err = static_cast<ppm_error_e>(ppm_popup_request(&buffer[2], popup_response_cb, (void *)id));
+ print_error(err);
+ break;
+ case 'q':
+ exit(0);
+ case 'h':
+ default:
+ print_help();
+ break;
+ }
+
+ return TRUE;
+}
+
+int main(int argc, char **argv)
+{
+ (void) argc; (void) argv;
+
+ srand(time(0));
+ print_help();
+
+ GMainLoop *mainloop = g_main_loop_new(NULL, FALSE);
+
+ GIOChannel *channel = g_io_channel_unix_new(0);
+ GIOCondition condition = static_cast<GIOCondition>(G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL);
+ g_io_add_watch(channel, condition, main_loop_cb, NULL);
+
+ g_main_loop_run(mainloop);
+
+ return 0;
+}