Based on Sudarsana "Babu" Nagineni's work.
Getting and setting for the following properties-
"HOME_SCREEN", "LOCK_SCREEN","INCOMING_CALL","NOTIFICATION_EMAIL"
<a href="networkbearerselection.html"><h5>- Network Bearer Selection Test</h5></a>
<a href="notification.html"><h5>- Notification Test</h5></a>
<a href="system_info.html"><h5>- SystemInfo Test</h5></a>
+<a href="system_setting.html"><h5>- SystemSetting Test</h5></a>
<a href="time.html"><h5>- Time Test</h5></a>
<a href="power.html"><h5>- Power API Test</h5></a>
<a href="bluetooth.html"><h5>- Bluetooth Test</h5></a>
--- /dev/null
+<h1>System Setting API Test</h1>
+<body>
+ <br>
+ <div id="dbg"></div>
+ <br>
+ <button id="button1">Click 1</button><br><br>
+ <button id="button2">Click 2</button><br><br>
+ <button id="button3">Click 3</button><br><br>
+ <button id="button4">Click 4</button><br><br>
+ <button id="button5">Click 5</button><br><br>
+ <button id="button6">Click 6</button><br><br>
+ <button id="button7">Click 7</button><br><br>
+ <button id="button8">Click 8</button><br><br>
+ <pre id="console"></pre>
+ <script src="js/js-test-pre.js"></script>
+</body>
+<script>
+ var api_system_setting = tizen.systemsetting;
+ var output = document.getElementById("output");
+
+ function dbgOut(msg) {
+ el = document.getElementById("dbg");
+ el.innerHTML = msg + "<br/>" + dbg.innerHTML;
+ }
+
+ function handle(button, text, callback) {
+ var b = document.getElementById(button);
+ b.innerText = text;
+ b.addEventListener("click", callback);
+ }
+
+ // Define the set error callback.
+ function errorCallback(error) {
+ dbgOut("Fail to setProperty" + error);
+ }
+
+ // Define the success callback
+ function successCallback() {
+ dbgOut("Success to setProperty");
+ }
+
+ // Define the get success callback
+ function getPropertySuccessCallback(value) {
+ dbgOut("Success to getProperty " + value);
+ }
+
+ handle("button1", "Set home screen", function () {
+ tizen.systemsetting.setProperty("HOME_SCREEN",
+ "/opt/usr/media/Images/image16.jpg", successCallback, errorCallback);
+ });
+ handle("button2", "Set lock screen", function () {
+ tizen.systemsetting.setProperty("LOCK_SCREEN",
+ "/opt/usr/media/Images/image7.jpg", successCallback, errorCallback);
+ });
+ handle("button3", "Set call ringtone", function () {
+ api_system_setting.setProperty("INCOMING_CALL", "test_incoming.mp3",
+ successCallback, errorCallback);
+ });
+ handle("button4", "Set email alert tone ", function () {
+ api_system_setting.setProperty("NOTIFICATION_EMAIL", "test_email.mp3",
+ successCallback, errorCallback);
+ });
+ handle("button5", "Get HOME_SCREEN", function () {
+ api_system_setting.getProperty("HOME_SCREEN", getPropertySuccessCallback,
+ errorCallback);
+ });
+ handle("button6", "Get LOCK_SCREEN", function () {
+ api_system_setting.getProperty("LOCK_SCREEN", getPropertySuccessCallback,
+ errorCallback);
+ });
+ handle("button7", "Get INCOMING_CALL", function () {
+ api_system_setting.getProperty("INCOMING_CALL",
+ getPropertySuccessCallback, errorCallback);
+ });
+ handle("button8", "Get NOTIFICATION_EMAIL", function () {
+ api_system_setting.getProperty("NOTIFICATION_EMAIL",
+ getPropertySuccessCallback, errorCallback);
+ });
+</script>
BuildRequires: pkgconfig(capi-network-connection)
BuildRequires: pkgconfig(capi-system-device)
BuildRequires: pkgconfig(capi-system-power)
+BuildRequires: pkgconfig(capi-system-system-settings)
BuildRequires: pkgconfig(dbus-glib-1)
BuildRequires: pkgconfig(glib-2.0)
BuildRequires: pkgconfig(libudev)
--- /dev/null
+{
+ 'includes':[
+ '../common/common.gypi',
+ ],
+ 'targets': [
+ {
+ 'target_name': 'tizen_systemsetting',
+ 'type': 'loadable_module',
+ 'sources': [
+ 'system_setting_api.js',
+ 'system_setting_context.cc',
+ 'system_setting_context.h',
+ 'system_setting_context_desktop.cc',
+ 'system_setting_context_mobile.cc',
+ ],
+ 'includes': [
+ '../common/pkg-config.gypi',
+ ],
+ 'conditions': [
+ ['extension_host_os=="mobile"', {
+ 'variables': {
+ 'packages': [
+ 'capi-system-system-settings',
+ 'vconf',
+ ]
+ },
+ }],
+ ],
+ },
+ ],
+}
--- /dev/null
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+var systemSettingTypes = {
+ "HOME_SCREEN": 0,
+ "LOCK_SCREEN": 1,
+ "INCOMING_CALL": 2,
+ "NOTIFICATION_EMAIL": 3
+};
+var _callbacks = {};
+var _next_reply_id = 0;
+extension.setMessageListener(function (message) {
+ var m = JSON.parse(message);
+ var _reply_id = m._reply_id;
+ var _error = m._error;
+ var handler = _callbacks[_reply_id];
+ if (handler) {
+ delete m._reply_id;
+ delete m._error;
+ delete _callbacks[_reply_id];
+ if (_error === 0) {
+ handler[0](m._file);
+ } else if (handler[1]) {
+ handler[1](new tizen.WebAPIError(_error));
+ }
+ delete m._file;
+ } else {
+ console.log(
+ 'Invalid reply_id received from xwalk.systemsetting extension:' +
+ _reply_id);
+ }
+});
+
+exports.setProperty = function (type, proposedPath, successCallback, errorCallback) {
+ if (typeof type !== 'string' || typeof proposedPath !== 'string') {
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+ }
+ if (!systemSettingTypes.hasOwnProperty(type) || !successCallback) {
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
+ if (typeof (successCallback) !== "function" ||
+ (errorCallback && typeof (errorCallback) !== "function")) {
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+ }
+ var id = (_next_reply_id++).toString();
+ _callbacks[id] = [successCallback, errorCallback];
+ extension.postMessage(JSON.stringify({
+ "cmd": 'SetProperty',
+ '_type': systemSettingTypes[type],
+ '_file': proposedPath,
+ "_reply_id": id,
+ }));
+}
+
+exports.getProperty = function (type, successCallback, errorCallback) {
+ if (!successCallback) {
+ throw new tizen.WebAPIException(tizen.WebAPIException.INVALID_VALUES_ERR);
+ }
+ if (typeof type !== 'string' || typeof (successCallback) !== "function" ||
+ (errorCallback && typeof (errorCallback) !== "function")) {
+ throw new tizen.WebAPIException(tizen.WebAPIException.TYPE_MISMATCH_ERR);
+ }
+ var id = (_next_reply_id++).toString();
+ _callbacks[id] = [successCallback, errorCallback];
+ extension.postMessage(JSON.stringify({
+ "cmd": 'GetProperty',
+ '_type': systemSettingTypes[type],
+ "_reply_id": id,
+ }));
+}
\ No newline at end of file
--- /dev/null
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "system_setting/system_setting_context.h"
+
+#include <string>
+#include "common/picojson.h"
+
+CXWalkExtension* xwalk_extension_init(int32_t api_version) {
+ return ExtensionAdapter<SystemSettingContext>::Initialize();
+}
+
+SystemSettingContext::SystemSettingContext(ContextAPI* api)
+ : api_(api) {}
+
+SystemSettingContext::~SystemSettingContext() {
+ delete api_;
+}
+
+const char SystemSettingContext::name[] = "tizen.systemsetting";
+
+// This will be generated from system_setting_api.js.
+extern const char kSource_system_setting_api[];
+
+const char* SystemSettingContext::GetJavaScript() {
+ return kSource_system_setting_api;
+}
+
+void SystemSettingContext::HandleMessage(const char* message) {
+ picojson::value v;
+
+ std::string err;
+ picojson::parse(v, message, message + strlen(message), &err);
+ if (!err.empty()) {
+ std::cout << "Ignoring message.\n";
+ return;
+ }
+
+ std::string cmd = v.get("cmd").to_str();
+ if (cmd == "SetProperty")
+ HandleSetProperty(v);
+ else if (cmd == "GetProperty")
+ HandleGetProperty(v);
+}
+
+void SystemSettingContext::OnPropertyHandled(const char* reply_id,
+ const char* value, int ret) {
+ picojson::value::object o;
+ o["_reply_id"] = picojson::value(reply_id);
+ if (value)
+ o["_file"] = picojson::value(value);
+ o["_error"] = picojson::value(static_cast<double>(ret));
+
+ picojson::value v(o);
+ api_->PostMessage(v.serialize().c_str());
+}
--- /dev/null
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef SYSTEM_SETTING_SYSTEM_SETTING_CONTEXT_H_
+#define SYSTEM_SETTING_SYSTEM_SETTING_CONTEXT_H_
+
+#include "common/extension_adapter.h"
+
+namespace picojson {
+class value;
+}
+
+class SystemSettingContext {
+ public:
+ explicit SystemSettingContext(ContextAPI* api);
+ ~SystemSettingContext();
+
+ // ExtensionAdapter implementation.
+ static const char name[];
+ static const char* GetJavaScript();
+ void HandleMessage(const char* message);
+ void HandleSyncMessage(const char* message) {}
+
+ private:
+ enum SystemSettingType {
+ HOME_SCREEN = 0,
+ LOCK_SCREEN = 1,
+ INCOMING_CALL = 2,
+ NOTIFICATION_EMAIL = 3,
+ };
+
+ void HandleSetProperty(const picojson::value& msg);
+ void HandleGetProperty(const picojson::value& msg);
+ void OnPropertyHandled(const char* reply_id, const char* value, int ret);
+
+ ContextAPI* api_;
+};
+
+#endif // SYSTEM_SETTING_SYSTEM_SETTING_CONTEXT_H_
--- /dev/null
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "system_setting/system_setting_context.h"
+#include "common/picojson.h"
+
+void SystemSettingContext::HandleSetProperty(const picojson::value& msg) {
+ SystemSettingType type = static_cast<SystemSettingType>
+ (msg.get("_type").get<double>());
+ const char* value = msg.get("_file").to_str().c_str();
+ const char* reply_id = msg.get("_reply_id").to_str().c_str();
+
+ OnPropertyHandled(reply_id, value, 0);
+}
+
+void SystemSettingContext::HandleGetProperty(const picojson::value& msg) {
+ SystemSettingType type = static_cast<SystemSettingType>
+ (msg.get("_type").get<double>());
+ const char* reply_id = msg.get("_reply_id").to_str().c_str();
+
+ OnPropertyHandled(reply_id, "test.png", 0);
+}
--- /dev/null
+// Copyright (c) 2013 Intel Corporation. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "system_setting/system_setting_context.h"
+
+#include <system_settings.h>
+#include <vconf.h>
+#include "common/picojson.h"
+
+void SystemSettingContext::HandleSetProperty(const picojson::value& msg) {
+ SystemSettingType type = static_cast<SystemSettingType>
+ (msg.get("_type").get<double>());
+ const char* value = msg.get("_file").to_str().c_str();
+ const char* reply_id = msg.get("_reply_id").to_str().c_str();
+ system_settings_key_e key;
+ switch (type) {
+ case HOME_SCREEN:
+ key = SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN;
+ break;
+ case LOCK_SCREEN:
+ key = SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN;
+ break;
+ case INCOMING_CALL:
+ key = SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE;
+ break;
+ case NOTIFICATION_EMAIL:
+ key = SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE;
+ break;
+ default:
+ std::cout<< "Invalid Key : should not reach here";
+ break;
+ }
+
+ int ret = system_settings_set_value_string(key, value);
+ OnPropertyHandled(reply_id, value, ret);
+}
+
+void SystemSettingContext::HandleGetProperty(const picojson::value& msg) {
+ SystemSettingType type = static_cast<SystemSettingType>
+ (msg.get("_type").get<double>());
+ const char* reply_id = msg.get("_reply_id").to_str().c_str();
+ system_settings_key_e key;
+ switch (type) {
+ case HOME_SCREEN:
+ key = SYSTEM_SETTINGS_KEY_WALLPAPER_HOME_SCREEN;
+ break;
+ case LOCK_SCREEN:
+ key = SYSTEM_SETTINGS_KEY_WALLPAPER_LOCK_SCREEN;
+ break;
+ case INCOMING_CALL:
+ key = SYSTEM_SETTINGS_KEY_INCOMING_CALL_RINGTONE;
+ break;
+ case NOTIFICATION_EMAIL:
+ key = SYSTEM_SETTINGS_KEY_EMAIL_ALERT_RINGTONE;
+ break;
+ default:
+ std::cout<< "Invalid Key :should not reach here";
+ break;
+ }
+
+ char* value = NULL;
+ int ret = system_settings_get_value_string(key, &value);
+ OnPropertyHandled(reply_id, value, ret);
+ free(value);
+}
'notification/notification.gyp:*',
'power/power.gyp:*',
'system_info/system_info.gyp:*',
+ 'system_setting/system_setting.gyp:*',
'time/time.gyp:*',
'tizen/tizen.gyp:*',
],