%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
####################################################################
%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 #
%define tizen_wearable_feature_tvinputdevice_support 0
%define tizen_wearable_feature_voicecontrol_support 1
+%define tizen_wearable_feature_ppm_support 1
####################################################################
%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
%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)
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}
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
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
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
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
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
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
--- /dev/null
+{
+ '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'
+ ]
+ },
+ }],
+ ],
+ },
+ ],
+}
--- /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.
+ */
+
+
+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
--- /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.
+ */
+
+#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;
+}
--- /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.
+ */
+
+#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_
--- /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.
+ */
+
+#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
--- /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.
+ */
+
+#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_
],
},
],
+ [
+ 'tizen_feature_ppm_support==1', {
+ 'dependencies': [
+ 'ppm/ppm.gyp:*',
+ ],
+ },
+ ],
], # end conditions
},
], # end targets