bootstrap: ask privacy permissions to user accepted/tizen/unified/20210113.121029 submit/tizen/20210112.115542
authorWonki Kim <wonki_.kim@samsung.com>
Mon, 11 Jan 2021 10:24:00 +0000 (19:24 +0900)
committerWonki Kim <wonki_.kim@samsung.com>
Mon, 11 Jan 2021 12:27:30 +0000 (21:27 +0900)
App can't utilize privacy related information such as location information,
unless user explicitly grants them.

this patch fix this to ask those permissions to user at the first use.
even if user denies, the app runs normally.
however information related a denied permisison can't be retrieved.

Change-Id: Ie1481a2724a65256fe56d4f5a5aeef1565f56dcb

org.tizen.aurum-bootstrap/meson.build
org.tizen.aurum-bootstrap/src/BootstrapServer.cc
packaging/aurum.spec

index 8d414a6..14e8f31 100644 (file)
@@ -57,6 +57,7 @@ bootstrap_svr_dep += [
    dependency('capi-appfw-service-application'),
    dependency('capi-system-system-settings'),
    dependency('capi-base-utils-i18n'),
+   dependency('capi-privacy-privilege-manager'),
 ]
 endif
 
index 5768d2b..aa70fd3 100644 (file)
@@ -2,6 +2,7 @@
 #include <glib.h>
 
 #include <service_app.h>
+#include <privacy_privilege_manager.h>
 
 #include <gio/gio.h>
 #include <grpcpp/grpcpp.h>
@@ -11,6 +12,9 @@
 #include "config.h"
 #include <loguru.hpp>
 
+#define PRIV_MEDIASTORAGE "http://tizen.org/privilege/mediastorage"
+#define PRIV_LOCATION "http://tizen.org/privilege/location"
+
 using namespace grpc;
 
 typedef struct _ServiceContext {
@@ -37,11 +41,69 @@ _grpc_thread_func (gpointer data)
     return NULL;
 }
 
-bool service_app_create(void *data)
+static void
+reponse_cb(ppm_call_cause_e cause, ppm_request_result_e result,
+                                      const char *privilege, void *user_data)
+{
+    if (cause == PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR) {
+        LOG_F(INFO, "PPM Error PRIVACY_PRIVILEGE_MANAGER_CALL_CAUSE_ERROR");
+        return;
+    }
+
+    switch (result) {
+        case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER:
+            LOG_F(INFO, "priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege);
+            break;
+        case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_FOREVER:
+            LOG_F(INFO, "priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege);
+            break;
+        case PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_DENY_ONCE:
+            LOG_F(INFO, "priv:%s PRIVACY_PRIVILEGE_MANAGER_REQUEST_RESULT_ALLOW_FOREVER", privilege);
+            break;
+        default:
+            LOG_F(INFO, "priv:%s default", privilege);
+            break;
+    }
+}
+
+static void
+check_permission(char *path_privilege)
+{
+    ppm_check_result_e result;
+    int ret;
+    LOG_F(INFO, "path_privilege = %s",path_privilege);
+    ret = ppm_check_permission(path_privilege, &result);
+
+    if (ret == PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE) {
+        switch (result) {
+            case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ALLOW:
+                break;
+
+            case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY:
+                LOG_F(INFO, "PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY");
+                ;
+                break;
+
+            case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK:
+                LOG_F(INFO, "PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK");
+                ppm_request_permission(path_privilege, reponse_cb, NULL);
+                break;
+
+            default:
+                break;
+        }
+    } else {
+        LOG_F(INFO, "Error to check permission[0x%x]", ret);
+    }
+}
+
+
+static bool _service_app_create(void *data)
 {
     ServiceContext *ctx = (ServiceContext*)data;
     const char *logPath = "/tmp/ua.log";
 
+
     loguru::g_preamble = false;
     loguru::add_file(logPath, loguru::Append, loguru::Verbosity_MAX);
     LOG_SCOPE_F(INFO, "Log : %s", logPath);
@@ -49,10 +111,13 @@ bool service_app_create(void *data)
     ctx->loop = g_main_loop_new ( NULL , FALSE );
     ctx->thread = g_thread_new("grpc_thread", _grpc_thread_func, ctx);
 
+    check_permission(PRIV_LOCATION);
+    check_permission(PRIV_MEDIASTORAGE);
+
     return true;
 }
 
-void service_app_terminate(void *data)
+static void _service_app_terminate(void *data)
 {
     ServiceContext *ctx = (ServiceContext*)data;
     ctx->server->Shutdown();
@@ -60,7 +125,7 @@ void service_app_terminate(void *data)
     g_thread_join(ctx->thread);
 }
 
-void service_app_control(app_control_h app_control, void *data)
+static void _service_app_control(app_control_h app_control, void *data)
 {
     ServiceContext *ctx = (ServiceContext*)data;
 }
@@ -75,9 +140,9 @@ int main(int argc, char **argv)
     app_event_handler_h handlers[5] = {NULL, };
     ServiceContext ctx = {0,};
 
-    event_callback.create = service_app_create;
-    event_callback.terminate = service_app_terminate;
-    event_callback.app_control = service_app_control;
+    event_callback.create = _service_app_create;
+    event_callback.terminate = _service_app_terminate;
+    event_callback.app_control = _service_app_control;
 
     int result = -1;
 
index 03ddcb0..e47b8c9 100644 (file)
@@ -28,6 +28,7 @@ BuildRequires: pkgconfig(capi-system-device)
 BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(capi-system-system-settings)
 BuildRequires: pkgconfig(capi-base-utils-i18n)
+BuildRequires: pkgconfig(capi-privacy-privilege-manager)
 
 %if 0%{?gendoc:1}
 BuildRequires:  doxygen