AppControlActivity template 03/150803/3
authorPawel Kurowski <p.kurowski2@samsung.com>
Mon, 18 Sep 2017 13:21:35 +0000 (15:21 +0200)
committerLukasz Oleksak <l.oleksak@samsung.com>
Wed, 20 Sep 2017 11:57:13 +0000 (11:57 +0000)
Two new bindable activities - StartHomeScreenActivity, and StartTaskManagerActivity
One non-bindable activity - StartLockScreenActivity.

Change-Id: I3b978eaeec88fbc30310c571e9639ef07596963a

org.tizen.universal-switch.xml
res/po/en_US.po
src/AppControlActivity.cpp [new file with mode: 0644]
src/MenuBuilder.cpp

index ea691d7..958d4df 100644 (file)
@@ -13,6 +13,7 @@
         <privilege>http://tizen.org/privilege/window.priority.set</privilege>
         <privilege>http://tizen.org/privilege/telephony</privilege>
         <privilege>http://tizen.org/privilege/systemsettings.admin</privilege>
+        <privilege>http://tizen.org/privilege/appmanager.launch</privilege>
     </privileges>
 
 </manifest>
index f634c6e..8a36862 100644 (file)
@@ -382,6 +382,11 @@ msgstr "Turn off Auto scan"
 msgid "IDS_ACTIVITY_NAME_ENABLE_AUTO_SCAN_ACTIVITY"
 msgstr "Turn on Auto scan"
 
+msgid "IDS_ACTIVITY_NAME_START_HOME_SCREEN"
+msgstr "Home screen"
+
+msgid "IDS_ACTIVITY_NAME_START_TASK_MGR"
+msgstr "View recently used apps"
 
 # PROVIDERS
 
diff --git a/src/AppControlActivity.cpp b/src/AppControlActivity.cpp
new file mode 100644 (file)
index 0000000..c11f075
--- /dev/null
@@ -0,0 +1,77 @@
+#include "Activity.hpp"
+#include "UniversalSwitchLog.hpp"
+#include "ActivityFactory.hpp"
+#include "Optional.hpp"
+#include <app.h>
+
+#define CHECK_ERROR(ret) do {                                                  \
+               if (ret != APP_CONTROL_ERROR_NONE) {                    \
+                       DEBUG("app_control failed. err = %d", ret);     \
+               }                                                                                               \
+       } while (false)
+
+#define RETURN_ON_ERROR(ret) do {                                              \
+               if (ret != APP_CONTROL_ERROR_NONE) {                    \
+                       CHECK_ERROR(ret);                                                       \
+                       return true;                                                            \
+               }                                                                                               \
+       } while (false)
+
+namespace
+{
+       enum AppToLaunch {
+               HOME_SCREEN,
+               LOCK_SCREEN,
+               TASK_MGR
+       };
+
+       static constexpr const char *ACTIVITY_TYPE[] = {"START_HOME_SCREEN", "START_LOCK_SCREEN", "START_TASK_MGR"};
+       static constexpr const char *LAUNCH_TYPE[] = {"org.tizen.homescreen-efl", "org.tizen.lockscreen", "org.tizen.task-mgr"};
+}
+
+template <AppToLaunch appToLaunch, bool bindable>
+class AppControlActivity : public Activity, private RegisterActivity<AppControlActivity<appToLaunch, bindable>, bindable>
+{
+public:
+       constexpr static const char *activityType = ACTIVITY_TYPE[appToLaunch];
+       AppControlActivity()
+               : Activity(activityType)
+       {}
+
+       ~AppControlActivity()
+       {
+               if (app_control) {
+                       auto ret = app_control_destroy(*app_control);
+                       CHECK_ERROR(ret);
+               }
+       }
+
+       bool process() override
+       {
+               app_control_h tmp_app_control;
+               auto ret = app_control_create(&tmp_app_control);
+               RETURN_ON_ERROR(ret);
+
+               app_control = tmp_app_control;
+
+               ret = app_control_set_operation(*app_control, APP_CONTROL_OPERATION_DEFAULT);
+               RETURN_ON_ERROR(ret);
+
+               ret = app_control_set_app_id(*app_control, LAUNCH_TYPE[appToLaunch]);
+               RETURN_ON_ERROR(ret);
+
+               ret = app_control_send_launch_request(*app_control, NULL, NULL);
+               RETURN_ON_ERROR(ret);
+
+               return true;
+       }
+protected:
+       Optional<app_control_h> app_control;
+};
+
+class StartHomeScreenActivity : public AppControlActivity<HOME_SCREEN, true> {};
+class StartLockScreenActivity : public AppControlActivity<LOCK_SCREEN, false> {};
+class StartTaskManagerActivity : public AppControlActivity<TASK_MGR, true> {};
+
+#undef RETURN_ON_ERROR
+#undef CHECK_ERROR
\ No newline at end of file
index d756861..93ae8bd 100644 (file)
@@ -88,7 +88,7 @@ MenuMap::MenuMap()
        auto homeScreen                         =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_HOME_SCREEN"},
                                                                                defaultImg,
-                                                                               std::string {},
+                                                                               "START_HOME_SCREEN",
                                                                                VconfKeyType::NONE,
                                                                                std::vector<std::string> {},
                                                                                std::string {},
@@ -107,7 +107,7 @@ MenuMap::MenuMap()
        auto recentApps                         =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_RECENT_APPS"},
                                                                                defaultImg,
-                                                                               std::string {},
+                                                                               "START_TASK_MGR",
                                                                                VconfKeyType::NONE,
                                                                                std::vector<std::string> {},
                                                                                std::string {},
@@ -222,7 +222,8 @@ MenuMap::MenuMap()
                                                                                std::vector<std::string> {VCONF_KEY_SOUND_ENABLED, VCONF_KEY_VIBRATION_ENABLED});
        auto lock                                       =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_LOCK"},
-                                                                               defaultImg);
+                                                                               defaultImg,
+                                                                               "START_LOCK_SCREEN");
        auto captureScreenshot          =       std::make_shared<MenuItem>(
                                                                                std::vector<std::string> {"IDS_CAPTURE_SCREENSHOT"},
                                                                                defaultImg);