Add AppFW Plugin
authorJinWang An <jinwang.an@samsung.com>
Thu, 1 Aug 2019 08:23:35 +0000 (17:23 +0900)
committerYoungjae Shin <yj99.shin@samsung.com>
Thu, 19 Mar 2020 04:30:19 +0000 (13:30 +0900)
15 files changed:
CMakeLists.txt
appfw/AppfwAction.cpp [new file with mode: 0644]
appfw/AppfwAction.h [new file with mode: 0644]
appfw/AppfwActionLaunch.cpp [new file with mode: 0644]
appfw/AppfwActionLaunch.h [new file with mode: 0644]
appfw/AppfwFactory.cpp [new file with mode: 0644]
appfw/AppfwFactory.h [new file with mode: 0644]
appfw/AppfwPlugin.cpp [new file with mode: 0644]
appfw/CMakeLists.txt [new file with mode: 0644]
bluetooth/BtPlugin.cpp
packaging/modes-plugins.spec
unittests/CMakeLists.txt
unittests/mdsp_appfw_main.cpp [new file with mode: 0644]
wifi/WifiPlugin.cpp
xml/tizen_action_rule.xml [new file with mode: 0644]

index 706e695..5775cfb 100644 (file)
@@ -17,5 +17,6 @@ ENDIF(NOT DEFINED MODES_PLUGIN_DEFAULT_DIR)
 
 ADD_SUBDIRECTORY(wifi)
 ADD_SUBDIRECTORY(vconf)
+ADD_SUBDIRECTORY(appfw)
 ADD_SUBDIRECTORY(bluetooth)
 ADD_SUBDIRECTORY(unittests)
diff --git a/appfw/AppfwAction.cpp b/appfw/AppfwAction.cpp
new file mode 100644 (file)
index 0000000..97a9c17
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2019 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 "AppfwAction.h"
+#include <modes_errors.h>
+
+MODES_NAMESPACE_USE;
+
+AppfwAction::AppfwAction()
+{
+}
+
+AppfwAction::~AppfwAction()
+{
+}
+
+int AppfwAction::set(const std::string &val)
+{
+       return MODES_ERROR_NOT_SUPPORTED;
+}
+
+void AppfwAction::setName(std::string name)
+{
+       this->name = name;
+}
+
+std::string AppfwAction::getName()
+{
+       return name;
+}
diff --git a/appfw/AppfwAction.h b/appfw/AppfwAction.h
new file mode 100644 (file)
index 0000000..2719ca3
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2019 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.
+ */
+#pragma once
+
+#include <string>
+#include "plugin-def.h"
+
+MODES_NAMESPACE_BEGIN
+
+class AppfwAction {
+public:
+       AppfwAction();
+       virtual ~AppfwAction();
+
+       std::string getName();
+       virtual int set(const std::string &val);
+
+protected:
+       void setName(std::string name);
+
+private:
+       std::string name;
+};
+
+MODES_NAMESPACE_END
+
diff --git a/appfw/AppfwActionLaunch.cpp b/appfw/AppfwActionLaunch.cpp
new file mode 100644 (file)
index 0000000..e6834bc
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2019 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 "AppfwActionLaunch.h"
+
+#include <app_control.h>
+#include <modes_errors.h>
+#include "plugin-log.h"
+
+MODES_NAMESPACE_USE;
+
+const std::string AppfwActionLaunch::NAME = "launch";
+
+AppfwActionLaunch::AppfwActionLaunch()
+{
+       setName(NAME);
+}
+
+int AppfwActionLaunch::set(const std::string &val)
+{
+       DBG("id(%s)", val.c_str());
+
+       app_control_h service;
+       app_control_create(&service);
+       app_control_set_app_id(service, val.c_str());
+       app_control_set_operation(service, APP_CONTROL_OPERATION_DEFAULT);
+       app_control_set_launch_mode(service, APP_CONTROL_LAUNCH_MODE_SINGLE);
+
+       int ret = app_control_send_launch_request(service, NULL, NULL);
+       if (APP_CONTROL_ERROR_NONE != ret) {
+               ERR("app_control_send_launch_request() Fail(%s)", get_error_message(ret));
+               return MODES_ERROR_IO_ERROR;
+       }
+
+       app_control_destroy(service);
+       return MODES_ERROR_NONE;
+}
diff --git a/appfw/AppfwActionLaunch.h b/appfw/AppfwActionLaunch.h
new file mode 100644 (file)
index 0000000..04eaf15
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2019 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.
+ */
+#pragma once
+
+#include <string>
+#include "AppfwAction.h"
+
+MODES_NAMESPACE_BEGIN
+
+class AppfwActionLaunch : public AppfwAction {
+public:
+       AppfwActionLaunch();
+
+       virtual int set(const std::string &val) override;
+
+       static const std::string NAME;
+};
+
+MODES_NAMESPACE_END
diff --git a/appfw/AppfwFactory.cpp b/appfw/AppfwFactory.cpp
new file mode 100644 (file)
index 0000000..c6d1ac8
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2019 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 "AppfwFactory.h"
+#include <modes_errors.h>
+#include "plugin-log.h"
+#include "AppfwActionLaunch.h"
+
+MODES_NAMESPACE_USE;
+
+AppfwFactory::AppfwFactory()
+{
+       actionMap[AppfwActionLaunch::NAME] = APPFW_ACT_LAUNCH;
+}
+
+AppfwAction* AppfwFactory::createAction(const std::string &key)
+{
+       auto search = actionMap.find(key);
+       if (search == actionMap.end()) {
+               ERR("No AppfwAction(%s)", key.c_str());
+               return nullptr;
+       }
+
+       switch (search->second) {
+       case APPFW_ACT_LAUNCH:
+               AppfwActionLaunch *appfwActionLaunch = new AppfwActionLaunch();
+               return appfwActionLaunch;
+               break;
+       }
+
+       return nullptr;
+}
+
+void AppfwFactory::destroyAction(AppfwAction *action)
+{
+       delete action;
+}
diff --git a/appfw/AppfwFactory.h b/appfw/AppfwFactory.h
new file mode 100644 (file)
index 0000000..b65d7e5
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2019 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.
+ */
+#pragma once
+
+#include <string>
+#include <map>
+#include "AppfwAction.h"
+
+MODES_NAMESPACE_BEGIN
+
+class AppfwFactory {
+public:
+       AppfwFactory();
+       ~AppfwFactory() = default;
+
+       AppfwAction* createAction(const std::string &key);
+       void destroyAction(AppfwAction *action);
+private:
+       enum actionKey{
+               APPFW_ACT_LAUNCH
+       };
+
+       std::map<std::string, enum actionKey> actionMap;
+};
+
+MODES_NAMESPACE_END
diff --git a/appfw/AppfwPlugin.cpp b/appfw/AppfwPlugin.cpp
new file mode 100644 (file)
index 0000000..a70de70
--- /dev/null
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2019 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 <string>
+#include <map>
+#include <modes_errors.h>
+#include <Plugin.h>
+#include "plugin-log.h"
+#include "AppfwFactory.h"
+
+MODES_NAMESPACE_USE;
+
+class AppfwPlugin : public Plugin {
+public:
+       AppfwPlugin();
+       ~AppfwPlugin();
+
+       int set(const std::string &key, const std::string &val, std::string *oldVal) override;
+private:
+       AppfwFactory appfwFactory;
+};
+
+extern "C" API Plugin *objectCreate(void)
+{
+       return new AppfwPlugin;
+}
+
+extern "C" API void objectDelete(Plugin *plugin)
+{
+       delete plugin;
+}
+
+AppfwPlugin::AppfwPlugin()
+{
+       setName("appfw");
+}
+
+AppfwPlugin::~AppfwPlugin()
+{
+}
+
+int AppfwPlugin::set(const std::string &key, const std::string &val, std::string *oldVal)
+{
+       AppfwAction *action = appfwFactory.createAction(key);
+       RETVM_IF(nullptr == action, MODES_ERROR_INVALID_PARAMETER, "action(%s) is null", key.c_str());
+
+       DBG("set [%s, %s]", key.c_str(), val.c_str());
+
+       int appfwRet = action->set(val);
+       appfwFactory.destroyAction(action);
+       return appfwRet;
+}
+
diff --git a/appfw/CMakeLists.txt b/appfw/CMakeLists.txt
new file mode 100644 (file)
index 0000000..de7593f
--- /dev/null
@@ -0,0 +1,12 @@
+SET(APPFW_PLUGIN "modes-plugin-appfw")
+
+FILE(GLOB APPFW_SRCS *.cpp)
+
+pkg_check_modules(appfw_pkgs REQUIRED modes dlog capi-base-common capi-appfw-application)
+INCLUDE_DIRECTORIES(${appfw_pkgs_INCLUDE_DIRS})
+LINK_DIRECTORIES(${appfw_pkgs_LIBRARY_DIRS})
+
+ADD_LIBRARY(${APPFW_PLUGIN} SHARED ${APPFW_SRCS})
+TARGET_LINK_LIBRARIES(${APPFW_PLUGIN} ${appfw_pkgs_LIBRARIES})
+SET_TARGET_PROPERTIES(${APPFW_PLUGIN} PROPERTIES NO_SONAME 1 )
+INSTALL(TARGETS ${APPFW_PLUGIN} DESTINATION ${MODES_PLUGIN_DEFAULT_DIR})
index 450e5a6..03a6e6b 100644 (file)
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 #include <string>
-#include <map>
-#include <utility>
 #include <modes_errors.h>
 #include <bluetooth.h>
 #include <Plugin.h>
index 4528bac..9c9f7c8 100644 (file)
@@ -13,7 +13,9 @@ BuildRequires: cmake
 BuildRequires: pkgconfig(modes)
 BuildRequires: modes-plugin-devel
 BuildRequires: pkgconfig(dlog)
+BuildRequires: pkgconfig(capi-appfw-application)
 BuildRequires: pkgconfig(capi-base-common)
+BuildRequires: pkgconfig(libxml-2.0)
 BuildRequires: pkgconfig(capi-network-wifi-manager)
 BuildRequires: pkgconfig(capi-network-bluetooth)
 BuildRequires: pkgconfig(vconf)
@@ -31,6 +33,7 @@ The %{name}-unittests pacakge contains programs for checking quality the %{name}
 
 %define modes_plugin_dir %{_libdir}/modes-plugins
 %define modes_test_dir %{_bindir}/%{name}
+%define modes_data_dir %{_datadir}/modes
 
 %prep
 %setup -q
@@ -56,9 +59,13 @@ make %{?_smp_mflags}
 
 %install
 %make_install
+mkdir -p %{buildroot}%{modes_data_dir}/rule
+install -m 0644 xml/*_rule.xml %{buildroot}%{modes_data_dir}/rule/
 
 %check
-#TBD
+pushd xml
+xmllint --noout --schema %{modes_data_dir}/xsd/tizen_action_rule.xsd tizen_action_rule.xml
+popd
 
 %post -p /sbin/ldconfig
 %postun -p /sbin/ldconfig
@@ -66,6 +73,7 @@ make %{?_smp_mflags}
 %files
 %manifest %{name}.manifest
 %{modes_plugin_dir}/*.so
+%{modes_data_dir}/rule/*
 %license LICENSE.APLv2
 
 %files unittests
index 5586836..425c352 100644 (file)
@@ -2,7 +2,7 @@ SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
 SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE")
 ADD_DEFINITIONS("-DMDS_TEST")
 
-pkg_check_modules(test_pkgs REQUIRED modes dlog capi-network-wifi-manager capi-network-bluetooth gmock)
+pkg_check_modules(test_pkgs REQUIRED modes dlog capi-network-wifi-manager capi-network-bluetooth gmock capi-appfw-application)
 INCLUDE_DIRECTORIES(${test_pkgs_INCLUDE_DIRS})
 LINK_DIRECTORIES(${test_pkgs_LIBRARY_DIRS})
 
@@ -21,3 +21,12 @@ SET(BT_SRCS ${BT_SRC_DIR}/BtAction.cpp "mdsp_bt_main.cpp")
 ADD_EXECUTABLE(${BT_PLUGIN_TEST} ${BT_SRCS})
 TARGET_LINK_LIBRARIES(${BT_PLUGIN_TEST} ${test_pkgs_LIBRARIES} dl)
 INSTALL(TARGETS ${BT_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
+#===================================================================#
+SET(APPFW_SRC_DIR "${CMAKE_SOURCE_DIR}/appfw" )
+SET(APPFW_PLUGIN_TEST "modes-gtest-appfw")
+FILE(GLOB APPFW_SRCS ${APPFW_SRC_DIR}/*.cpp)
+SET(APPFW_SRCS ${APPFW_SRCS} "mdsp_appfw_main.cpp")
+
+ADD_EXECUTABLE(${APPFW_PLUGIN_TEST} ${APPFW_SRCS})
+TARGET_LINK_LIBRARIES(${APPFW_PLUGIN_TEST} ${test_pkgs_LIBRARIES} dl)
+INSTALL(TARGETS ${APPFW_PLUGIN_TEST} DESTINATION ${TEST_INSTALL_DIR})
diff --git a/unittests/mdsp_appfw_main.cpp b/unittests/mdsp_appfw_main.cpp
new file mode 100644 (file)
index 0000000..a1f97b0
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2019 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 <glib.h>
+#include <string>
+#include <gtest/gtest.h>
+#include <Plugin.h>
+#include <modes.h>
+#include <modes_errors.h>
+#include "plugin-log.h"
+#include "plugin-def.h"
+
+MODES_NAMESPACE_USE;
+
+extern "C" API Plugin *objectCreate(void);
+extern "C" API void objectDelete(Plugin *plugin);
+
+TEST(PluginTest, setPluginAppfw)
+{
+       int ret;
+       Plugin *plugin = objectCreate();
+
+       ret = plugin->set("launch", std::string("org.tizen.w-stopwatch"), nullptr);
+       EXPECT_EQ(ret, MODES_ERROR_NONE);
+
+       objectDelete(plugin);
+}
+
+int main(int argc, char **argv) {
+       testing::InitGoogleTest(&argc, argv);
+       return RUN_ALL_TESTS();
+}
index f869917..39f0cfd 100644 (file)
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 #include <string>
-#include <map>
-#include <utility>
 #include <modes_errors.h>
 #include <wifi-manager.h>
 #include <Plugin.h>
diff --git a/xml/tizen_action_rule.xml b/xml/tizen_action_rule.xml
new file mode 100644 (file)
index 0000000..4b1b558
--- /dev/null
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<tizenModes xmlns="http://www.tizen.org" version="5.5">
+  <actionRule>
+    <rule name="wifi.power" type="bool" since="5.5" plugin="wifi-manager">
+      <alias name="on">1</alias>
+      <alias name="off">0</alias>
+      <defaultVal>0</defaultVal>
+      <desc>wifi On/Off</desc>
+      <domain>Network &amp; Connectivity</domain>
+    </rule>
+    <rule name="bluetooth.power" type="bool" since="5.5" plugin="bluetooth">
+      <alias name="on">1</alias>
+      <alias name="off">0</alias>
+      <defaultVal>0</defaultVal>
+      <desc>bluetooth On/Off</desc>
+      <domain>Network &amp; Connectivity</domain>
+    </rule>
+    <rule name="bluetooth.audioConnect" type="string" since="5.5" plugin="bluetooth">
+      <defaultVal>0:0:0:0:0:0</defaultVal>
+      <desc>bluetooth Audio Connect</desc>
+      <domain>Network &amp; Connectivity</domain>
+    </rule>
+    <rule name="sensord.changeAccuracy" type="int" since="5.5" plugin="sensor-fw">
+      <defaultVal>100</defaultVal>
+      <conflict>sensord.exactness</conflict>
+      <desc>Sensor Accuracy</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="sensord.exactness" type="int" since="5.5" plugin="sensor-fw">
+      <defaultVal>100</defaultVal>
+      <conflict>sensord.changeAccuracy</conflict>
+      <desc>Sensor Exactness</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="vconf.db.setting.psmode" type="int" since="5.5" plugin="vconf">
+      <alias name="SETTING_PSMODE_NORMAL">0</alias>
+      <alias name="SETTING_PSMODE_POWERFUL">1</alias>
+      <alias name="SETTING_PSMODE_ADVISOR">1</alias>
+      <alias name="SETTING_PSMODE_SURVIVAL">2</alias>
+      <alias name="SETTING_PSMODE_EMERGENCY">2</alias>
+      <alias name="SETTING_PSMODE_WEARABLE">3</alias>
+      <alias name="SETTING_PSMODE_WEARABLE_ENHANCED">4</alias>
+      <alias name="SETTING_PSMODE_MAX">0</alias>
+      <defaultVal>0</defaultVal>
+      <conflict>sensord.changeAccuracy</conflict>
+      <desc>test</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="vconf.db.bluetooth.status" type="int" since="5.5" plugin="vconf">
+      <alias name="VCONFKEY_BT_STATUS_OFF">0</alias>
+      <alias name="VCONFKEY_BT_STATUS_ON">1</alias>
+      <alias name="VCONFKEY_BT_STATUS_BT_VISIBLE">2</alias>
+      <alias name="VCONFKEY_BT_STATUS_TRANSFER">4</alias>
+      <defaultVal>0</defaultVal>
+      <desc>test</desc>
+      <domain>Network &amp; Connectivity</domain>
+    </rule>
+    <rule name="browser.url" type="string" since="5.5" plugin="web">
+      <defaultVal>about:blank</defaultVal>
+      <desc>browser</desc>
+      <domain>Web Framework</domain>
+    </rule>
+    <rule name="display.nightLight" type="int" since="5.5" plugin="display">
+      <defaultVal>70</defaultVal>
+      <conflict>display.autoLight</conflict>
+      <desc>It makes the screen color warmer.</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="appfw.launch" type="string" since="5.5" plugin="appfw">
+      <defaultVal>0</defaultVal>
+      <desc>Launch App</desc>
+      <domain>App Framework</domain>
+    </rule>
+    <rule name="test.printInt" type="int" since="5.5" plugin="test">
+      <defaultVal>0</defaultVal>
+      <desc>It prints integerv value</desc>
+      <domain>System</domain>
+    </rule>
+    <rule name="test.printBool" type="bool" since="5.5" plugin="test">
+      <defaultVal>0</defaultVal>
+      <desc>It prints boolean value</desc>
+      <domain>System</domain>
+    </rule>
+  </actionRule>
+</tizenModes>