[PPM] stubs implementation and checkPermission implementation 21/157621/5
authorLukasz Bardeli <l.bardeli@samsung.com>
Wed, 25 Oct 2017 13:18:26 +0000 (15:18 +0200)
committerLukasz Bardeli <l.bardeli@samsung.com>
Wed, 25 Oct 2017 13:18:26 +0000 (15:18 +0200)
[Verification] Code compiles without error

Change-Id: I865ba4c1b60050faa685891283567cdd696bd2fb
Signed-off-by: Lukasz Bardeli <l.bardeli@samsung.com>
packaging/webapi-plugins.spec
src/ppm/ppm.gyp [new file with mode: 0644]
src/ppm/ppm_api.js [new file with mode: 0644]
src/ppm/ppm_extension.cc [new file with mode: 0644]
src/ppm/ppm_extension.h [new file with mode: 0644]
src/ppm/ppm_instance.cc [new file with mode: 0644]
src/ppm/ppm_instance.h [new file with mode: 0644]
src/tizen-wrt.gyp

index 2d2aa0a37c4a1cb30104b101b313c37815b238d3..d108b86166048c17e67b88e9e1279902ca0cca95 100644 (file)
@@ -70,6 +70,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_common_feature_nbs_support                     0
 %define tizen_common_feature_tvinputdevice_support           0
 %define tizen_common_feature_voicecontrol_support            0
+%define tizen_common_feature_ppm_support                     0
 
 
 ####################################################################
@@ -159,6 +160,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_mobile_feature_tvinputdevice_support           0
 
 %define tizen_mobile_feature_voicecontrol_support            1
+%define tizen_mobile_feature_ppm_support                     1
 
 ####################################################################
 #       Wearable Profile :  B2 / TW2                      #
@@ -236,6 +238,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_wearable_feature_tvinputdevice_support           0
 
 %define tizen_wearable_feature_voicecontrol_support            1
+%define tizen_wearable_feature_ppm_support                     1
 
 
 ####################################################################
@@ -292,6 +295,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_tv_feature_inputdevice_support             0
 %define tizen_tv_feature_tvinputdevice_support           1
 %define tizen_tv_feature_voicecontrol_support            1
+%define tizen_tv_feature_ppm_support                     0
 
 # common, or "unified (undefined)"
 %define unified_build   1
@@ -353,6 +357,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_feature_nbs_support                     %{expand:%tizen_%{?profile}_feature_nbs_support}
 %define tizen_feature_tvinputdevice_support           %{expand:%tizen_%{?profile}_feature_tvinputdevice_support}
 %define tizen_feature_voicecontrol_support            %{expand:%tizen_%{?profile}_feature_voicecontrol_support}
+%define tizen_feature_ppm_support                     %{expand:%tizen_%{?profile}_feature_ppm_support}
 %endif
 
 BuildRequires: pkgconfig(security-privilege-manager)
@@ -558,6 +563,10 @@ BuildRequires: pkgconfig(widget_service)
 BuildRequires: pkgconfig(voice-control)
 %endif
 
+%if "%{?tizen_feature_ppm_support}" == "1" || "%{?unified_build}" == "1"
+BuildRequires: pkgconfig(capi-privacy-privilege-manager)
+%endif
+
 Requires:      %{name}-compat = %{version}-%{release}
 %if "%{?unified_build}" == "1"
 Recommends:    %{name}-profile_common = %{version}-%{release}
@@ -706,6 +715,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_widget_service_support=%{?tizen_mobile
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_wi_fi_support=%{?tizen_mobile_feature_wi_fi_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_tvinputdevice_support=%{?tizen_mobile_feature_tvinputdevice_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_voicecontrol_support=%{?tizen_mobile_feature_voicecontrol_support}"
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_mobile_feature_ppm_support}"
 
 ./tools/gyp/gyp $GYP_OPTIONS src/tizen-wrt.gyp
 
@@ -792,6 +802,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_widget_service_support=%{?tizen_mobile
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_wi_fi_support=%{?tizen_mobile_feature_wi_fi_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_tvinputdevice_support=%{?tizen_mobile_feature_tvinputdevice_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_voicecontrol_support=%{?tizen_mobile_feature_voicecontrol_support}"
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_mobile_feature_ppm_support}"
 
 ./tools/gyp/gyp $GYP_OPTIONS src/tizen-wrt.gyp
 
@@ -857,6 +868,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_widget_service_support=%{?tizen_wearab
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_wi_fi_support=%{?tizen_wearable_feature_wi_fi_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_tvinputdevice_support=%{?tizen_wearable_feature_tvinputdevice_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_voicecontrol_support=%{?tizen_wearable_feature_voicecontrol_support}"
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_wearable_feature_ppm_support}"
 
 ./tools/gyp/gyp $GYP_OPTIONS src/tizen-wrt.gyp
 
@@ -938,6 +950,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_widget_service_support=%{?tizen_wearab
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_wi_fi_support=%{?tizen_wearable_feature_wi_fi_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_tvinputdevice_support=%{?tizen_wearable_feature_tvinputdevice_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_voicecontrol_support=%{?tizen_wearable_feature_voicecontrol_support}"
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_wearable_feature_ppm_support}"
 
 ./tools/gyp/gyp $GYP_OPTIONS src/tizen-wrt.gyp
 
@@ -1003,6 +1016,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_widget_service_support=%{?tizen_tv_fea
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_wi_fi_support=%{?tizen_tv_feature_wi_fi_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_tvinputdevice_support=%{?tizen_tv_feature_tvinputdevice_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_voicecontrol_support=%{?tizen_tv_feature_voicecontrol_support}"
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_tv_feature_ppm_support}"
 
 ./tools/gyp/gyp $GYP_OPTIONS src/tizen-wrt.gyp
 
@@ -1073,6 +1087,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_widget_service_support=%{?tizen_common
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_wi_fi_support=%{?tizen_common_feature_wi_fi_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_tvinputdevice_support=%{?tizen_common_feature_tvinputdevice_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_voicecontrol_support=%{?tizen_common_feature_voicecontrol_support}"
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_ppm_support=%{?tizen_common_feature_ppm_support}"
 
 ./tools/gyp/gyp $GYP_OPTIONS src/tizen-wrt.gyp
 
diff --git a/src/ppm/ppm.gyp b/src/ppm/ppm.gyp
new file mode 100644 (file)
index 0000000..6af4ad1
--- /dev/null
@@ -0,0 +1,30 @@
+{
+  'includes':[
+    '../common/common.gypi',
+  ],
+  'targets': [
+    {
+      'target_name': 'tizen_ppm',
+      'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
+      'sources': [
+        'ppm_api.js',
+        'ppm_extension.cc',
+        'ppm_extension.h',
+        'ppm_instance.cc',
+        'ppm_instance.h',
+      ],
+      'conditions': [
+        ['tizen == 1', {
+          'variables': {
+            'packages': [
+              'capi-privacy-privilege-manager'
+            ]
+          },
+        }],
+      ],
+    },
+  ],
+}
diff --git a/src/ppm/ppm_api.js b/src/ppm/ppm_api.js
new file mode 100644 (file)
index 0000000..fa0cd6f
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * 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.
+ */
+
+
+var validator_ = xwalk.utils.validator;
+var type_ = xwalk.utils.type;
+var types_ = validator_.Types;
+var native_ = new xwalk.utils.NativeManager(extension);
+
+var PermissionRequestResult = {
+    ALLOW_FOREVER: 'ALLOW_FOREVER',
+    DENY_FOREVER: 'DENY_FOREVER',
+    DENY_ONCE: 'DENY_ONCE'
+};
+
+function PPMManager() {
+}
+
+PPMManager.prototype.checkPermission = function() {
+  var args = validator_.validateArgs(arguments, [
+      { name: 'privilege', type: types_.STRING }
+  ]);
+
+  var callArgs = {
+      privilege: args.privilege
+  };
+
+  var result = native_.callSync('PPMManager_checkPermission', callArgs);
+
+  if (native_.isFailure(result)) {
+    throw native_.getErrorObject(result);
+  }
+
+  return native_.getResultObject(result);
+};
+
+PPMManager.prototype.requestPermission = function() {
+    var args = validator_.validateArgs(arguments, [
+        { name: 'privilege', type: types_.STRING },
+        { name: 'successCallback', type: types_.FUNCTION },
+        { name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true }
+    ]);
+
+    var callback = function(result) {
+        if (native_.isFailure(result)) {
+            native_.callIfPossible(args.errorCallback, native_.getErrorObject(result));
+        } else {
+            // TODO fill with proper data
+            args.successCallback(result.result);
+        }
+    };
+
+    var callArgs = {
+        privilege: args.privilege
+    };
+
+    var result = native_.call('PPMManager_requestPermission', callArgs, callback);
+
+    if (native_.isFailure(result)) {
+      throw native_.getErrorObject(result);
+    }
+};
+
+// Exports
+exports = new PPMManager();
\ No newline at end of file
diff --git a/src/ppm/ppm_extension.cc b/src/ppm/ppm_extension.cc
new file mode 100644 (file)
index 0000000..c1d098b
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+#include "ppm/ppm_extension.h"
+
+#include "ppm/ppm_instance.h"
+
+// This will be generated from ppm_api.js
+extern const char kSource_ppm_api[];
+
+common::Extension* CreateExtension() {
+  return new PPMExtension;
+}
+
+PPMExtension::PPMExtension() {
+  SetExtensionName("tizen.ppm");
+  SetJavaScriptAPI(kSource_ppm_api);
+}
+
+PPMExtension::~PPMExtension() {
+}
+
+common::Instance* PPMExtension::CreateInstance() {
+  return new extension::ppm::PPMInstance;
+}
diff --git a/src/ppm/ppm_extension.h b/src/ppm/ppm_extension.h
new file mode 100644 (file)
index 0000000..8df16c6
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.
+ */
+
+#ifndef PPM_PPM_EXTENSION_H_
+#define PPM_PPM_EXTENSION_H_
+
+#include "common/extension.h"
+
+class PPMExtension : public common::Extension {
+ public:
+  PPMExtension();
+  virtual ~PPMExtension();
+
+ private:
+  virtual common::Instance* CreateInstance();
+};
+
+#endif  // PPM_PPM_EXTENSION_H_
diff --git a/src/ppm/ppm_instance.cc b/src/ppm/ppm_instance.cc
new file mode 100644 (file)
index 0000000..e09fa8c
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * 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.
+ */
+
+#include "ppm/ppm_instance.h"
+
+#include <memory>
+
+#include "common/logger.h"
+#include "common/picojson.h"
+#include "common/task-queue.h"
+
+namespace extension {
+namespace ppm {
+
+namespace {
+const std::string kPPMCheckResultAllow = "PPM_ALLOW";
+const std::string kPPMCheckResultDeny = "PPM_DENY";
+const std::string kPPMCheckResultAsk = "PPM_ASK";
+}
+
+PPMInstance::PPMInstance() {
+  ScopeLogger();
+  using std::placeholders::_1;
+  using std::placeholders::_2;
+
+#define REGISTER(c, x) RegisterSyncHandler(c, std::bind(&PPMInstance::x, this, _1, _2));
+
+  REGISTER("PPMManager_checkPermission", checkPermission);
+  REGISTER("PPMManager_requestPermission", requestPermission);
+
+#undef REGISTER
+}
+
+PPMInstance::~PPMInstance() {
+  ScopeLogger();
+}
+
+common::PlatformResult PPMInstance::convertError(int err,
+                                                 const std::string& message) {
+  ScopeLogger();
+
+  char* error = nullptr;
+  if (message.empty()) {
+    error = get_error_message(err);
+  } else {
+    error = (char*)message.c_str();
+  }
+
+  switch(err) {
+    case PRIVACY_PRIVILEGE_MANAGER_ERROR_INVALID_PARAMETER:
+      return common::PlatformResult(common::ErrorCode::INVALID_VALUES_ERR, error);
+    case PRIVACY_PRIVILEGE_MANAGER_ERROR_IO_ERROR:
+    case PRIVACY_PRIVILEGE_MANAGER_ERROR_ALREADY_IN_PROGRESS:
+    case PRIVACY_PRIVILEGE_MANAGER_ERROR_OUT_OF_MEMORY:
+    case PRIVACY_PRIVILEGE_MANAGER_ERROR_UNKNOWN:
+      return common::PlatformResult(common::ErrorCode::ABORT_ERR, message);
+    default:
+      return common::PlatformResult(common::ErrorCode::ABORT_ERR, "Unknown error.");
+  }
+}
+
+std::string PPMInstance::CheckResultToString(ppm_check_result_e result) {
+  ScopeLogger();
+
+  switch(result) {
+    case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ALLOW:
+      return kPPMCheckResultAllow;
+    case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY:
+      return kPPMCheckResultDeny;
+    case PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_ASK:
+      return kPPMCheckResultAsk;
+    default:
+      return kPPMCheckResultDeny;
+  }
+}
+
+void PPMInstance::checkPermission(const picojson::value& args, picojson::object& out) {
+  ScopeLogger();
+  const std::string& privilege = args.get("privilege").get<std::string>();
+  LoggerD("Checking privilege: %s ", privilege.c_str());
+
+  ppm_check_result_e result = PRIVACY_PRIVILEGE_MANAGER_CHECK_RESULT_DENY;
+
+  int ret = ppm_check_permission(privilege.c_str(), &result);
+
+  if (PRIVACY_PRIVILEGE_MANAGER_ERROR_NONE != ret) {
+    LogAndReportError(convertError(ret), &out, ("checkPermission error: %d (%s)",
+                                                ret, get_error_message(ret)));
+    return;
+  }
+
+  ReportSuccess(picojson::value(CheckResultToString(result)),out);
+}
+
+void PPMInstance::requestPermission(const picojson::value& args, picojson::object& out) {
+  ScopeLogger();
+
+  const double callback_id = args.get("callbackId").get<double>();
+
+  const std::string& privilege = args.get("privilege").get<std::string>();
+  LoggerD("Requesting privilege: %s ", privilege.c_str());
+
+  auto get = [this, privilege,
+              callback_id](const std::shared_ptr<picojson::value>& response) -> void {
+    ScopeLogger("Entered into asynchronous function, get");
+
+    picojson::object& obj = response->get<picojson::object>();
+
+    ReportSuccess(obj);
+    obj.insert(std::make_pair("callbackId", picojson::value(callback_id)));
+    Instance::PostMessage(this, response->serialize().c_str());
+  };
+
+  auto data = std::shared_ptr<picojson::value>(new picojson::value(picojson::object()));
+
+  common::TaskQueue::GetInstance().Async<picojson::value>(get, data);
+}
+
+}  // namespace ppm
+}  // namespace extension
diff --git a/src/ppm/ppm_instance.h b/src/ppm/ppm_instance.h
new file mode 100644 (file)
index 0000000..1c135b5
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * 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.
+ */
+
+#ifndef PPM_PPM_INSTANCE_H_
+#define PPM_PPM_INSTANCE_H_
+
+#include <string>
+
+#include "common/extension.h"
+#include "common/platform_result.h"
+#include "common/platform_exception.h"
+
+#include <privacy_privilege_manager.h>
+
+namespace extension {
+namespace ppm {
+
+class PPMInstance : public common::ParsedInstance {
+ public:
+  PPMInstance();
+  virtual ~PPMInstance();
+
+ private:
+  void checkPermission(const picojson::value& args, picojson::object& out);
+  void requestPermission(const picojson::value& args, picojson::object& out);
+
+  static common::PlatformResult convertError(int err,
+                                             const std::string& message = "");
+  static std::string CheckResultToString(ppm_check_result_e result);
+};
+
+}  // namespace ppm
+}  // namespace extension
+
+#endif  // PPM_PPM_INSTANCE_H_
index 410e44a257ea3c47deb5dbf87fac779f39841966..196dce85a8be5cf6a5f810bd39e4115536eb3911 100755 (executable)
             ],
           },
         ],
+        [
+          'tizen_feature_ppm_support==1', {
+            'dependencies': [
+              'ppm/ppm.gyp:*',
+            ],
+          },
+        ],
       ], # end conditions
     },
   ], # end targets