Add app_launcher binary to provide this feature 11/29211/4 accepted/tizen/common/20141023.130915 submit/tizen_common/20141023.083752
authorBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Wed, 22 Oct 2014 14:43:53 +0000 (16:43 +0200)
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>
Thu, 23 Oct 2014 08:26:15 +0000 (10:26 +0200)
Usage : app_launcher
-h --help Display this usage information.
-l --list Display installed apps list
-S --status Display running apps list
-s [tizen application ID] --start Launch application with tizen application ID
-k [tizen application ID] --kill Kill application with tizen application ID
-r [tizen application ID] --is-running Check whether application is running by tizen application ID,
If application is running, 0(zero) will be returned.
-d --debug Activate debug mode
BUG-Tizen:TC-1883

Change-Id: Iea647fc6cb24e22c1537c6322dcac6f66cd487ad
Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
CMakeLists.txt
am_daemon/amd_request.c
app_launcher.c [new file with mode: 0755]
packaging/aul.spec

index 63d1f6f..44deeae 100644 (file)
@@ -130,6 +130,14 @@ INSTALL(TARGETS ${LAUNCH_AGENT} DESTINATION bin)
 
 
 
+SET(APP_LAUNCHER "app_launcher")
+add_executable(${APP_LAUNCHER}
+               app_launcher.c
+        )
+SET(APP_LAUNCHER_LIBRARY ${APP_LAUNCHER} aul_mods app-checker-server rua glib-2.0 bundle ail aul)
+target_link_libraries(${APP_LAUNCHER_LIBRARY} ${pkgs_LDFLAGS})
+INSTALL(TARGETS app_launcher DESTINATION bin)
+
 # pkgconfig file
 CONFIGURE_FILE(aul.pc.in aul.pc @ONLY)
 CONFIGURE_FILE(legacy/preload_list.txt.in legacy/preload_list.txt @ONLY)
index 349cfd3..2eeb23f 100755 (executable)
@@ -390,6 +390,8 @@ static gboolean __request_handler(gpointer data)
                        __send_result_to_client(clifd, ret);
                        break;
                case APP_DEAD_SIGNAL:
+                       _E("APP_DEAD_SIGNAL");
+
                        kb = bundle_decode(pkt->data, pkt->len);
                        ret=__handle_dead_signal(kb,clifd,&cr);
                        break;
diff --git a/app_launcher.c b/app_launcher.c
new file mode 100755 (executable)
index 0000000..f59d1a4
--- /dev/null
@@ -0,0 +1,322 @@
+/*
+ *  app_launcher
+ *
+ * Copyright (c) 2014, Intel Corporation.
+ *
+ * Contact: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
+ *
+ * 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 <stdio.h>
+#include <getopt.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <string.h>
+#include <glib.h>
+#include <ail.h>
+#include "aul.h"
+
+
+static char **gargv;
+static int gargc;
+bundle *kb = NULL;
+
+static GMainLoop *mainloop = NULL;
+
+
+struct launch_arg {
+    char applicationId[256];
+    int flag_debug;
+} launch_arg;
+
+static bundle *create_internal_bundle()
+{
+    bundle *kb;
+    int i;
+    char arg[1024] = {0, };
+    char* val_array[128];
+
+    kb = bundle_create();
+    bundle_add(kb, AUL_K_DEBUG, "1");
+    return kb;
+}
+
+int launch(char* appid,int debug_option)
+{
+    int pid = -1;
+
+
+    if(!debug_option)
+        pid = aul_open_app(appid);
+    else {
+        kb = create_internal_bundle();
+        if (NULL == kb) {
+            printf("bundle creation fail\n");
+            return -1;
+        }
+        pid = aul_launch_app(appid, kb);
+    }
+    return pid;
+}
+
+
+
+static int __launch_app_dead_handler(int pid, void *data)
+{
+    int listen_pid = (int) data;
+
+    if(listen_pid == pid)
+        g_main_loop_quit(mainloop);
+
+    return 0;
+}
+
+static gboolean run_func(void *data)
+{
+    int pid = -1;
+    char *str = NULL;
+    struct launch_arg* launch_arg_data = NULL;
+    launch_arg_data = (struct launch_arg*)data;
+    if ((pid = launch((char*)launch_arg_data->applicationId,launch_arg_data->flag_debug)) > 0) {
+        printf("... successfully launched\n");
+    } else {
+        printf("... launch failed\n");
+    }
+    g_main_loop_quit(mainloop);
+    if (kb) {
+        bundle_free(kb);
+        kb = NULL;
+    }
+
+    return TRUE;
+}
+
+
+void print_usage(char *program)
+{
+    printf("Usage : %s [ ... ]\n", program);
+    printf(
+        "   -h                        --help              Display this usage information.\n"
+        "   -l                        --list              Display installed apps list\n"
+        "   -S                        --status            Display running apps list\n"
+        "   -s [tizen application ID] --start             Launch widget with tizen application ID\n"
+        "   -k [tizen application ID] --kill              Kill widget with tizen application ID\n"
+        "   -r [tizen application ID] --is-running        Check whether application is running by tizen application ID,\n"
+        "                                                 If widget is running, 0(zero) will be returned.\n"
+        "   -d                        --debug             Activate debug mode\n"
+        );
+}
+
+
+ail_cb_ret_e appinfo_list_appid_namefunc(const ail_appinfo_h appinfo,  void *user_data)
+{
+    char* package_str_name = NULL;
+    char* package_str_appid = NULL;
+    char* package_str_x_package_type = NULL;
+    ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_APPID_STR, &package_str_appid);
+    ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &package_str_name);
+    ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_PACKAGETYPE_STR, &package_str_x_package_type);
+
+    printf("\t'%s'\t '%s'\t %s\n",package_str_name, package_str_appid, package_str_x_package_type);
+    return AIL_CB_RET_CONTINUE;
+}
+
+
+int listApp()
+{
+    int ret = 0;
+    printf("\tApplication List for user %lu\n", (long)getuid());
+    printf("\tUser's Application \n");
+    printf("\t Name \t AppID  \t Type \n");
+    printf("\t=================================================\n");
+    if ( ail_filter_list_usr_appinfo_foreach(NULL, appinfo_list_appid_namefunc, NULL, getuid() ) != AIL_ERROR_OK )
+        ret = -1;
+    printf("\t=================================================\n");
+    return ret;
+}
+
+
+
+int iterfunc_status(const aul_app_info *info, void *data)
+{
+    printf("\t  %s (%d)\n",info->appid, info->pid);
+    return 0;
+}
+
+
+
+int iterfunc_kill(const aul_app_info *info, void *data)
+{
+    if(!data)
+        return 0;
+    if(strcmp(info->appid,data) == 0) {
+        aul_kill_pid(info->pid);
+    printf("\t Kill pkg_name: %s (%d)\n", info->appid,info->pid);
+    }
+    return 0;
+}
+
+int IsAppInstalled(char *appid)
+{
+    ail_filter_h f;
+    int res = 0;
+    if(!appid)
+        return 0;
+    if (ail_filter_new(&f) != AIL_ERROR_OK)
+        return -1;
+    if (ail_filter_add_str(f, AIL_PROP_X_SLP_APPID_STR, appid) != AIL_ERROR_OK) {
+        ail_filter_destroy(f);
+        return -1;
+    }
+    if (ail_filter_count_usr_appinfo(f, &res, getuid()) != AIL_ERROR_OK) {
+        ail_filter_destroy(f);
+        return -1;
+    }
+    return res;
+}
+
+int main(int argc, char **argv)
+{
+    bool isDebugMode = false;
+    bool dispHelp = false;
+    bool dispList = false;
+    bool dispRunList = false;
+    int next_opt, opt_idx = 0;
+    char op = '\0';
+    int ret = 0;
+    struct launch_arg  args;
+    static struct option long_options[] = {
+            { "help", no_argument, 0, 'h' },
+            { "list", no_argument, 0, 'l' },
+            { "status", no_argument, 0, 'S' },
+            { "start", required_argument, 0, 's' },
+            { "kill", required_argument, 0, 'k' },
+            { "is-running", required_argument, 0, 'r' },
+            { "debug", no_argument, 0, 'd' },
+            { 0, 0, 0, 0 }
+    };
+
+    do {
+            next_opt = getopt_long(argc,
+                                   argv,
+                                   "hlSs:k:r:d",
+                                   long_options,
+                                   &opt_idx);
+
+            switch (next_opt) {
+            case 'h':
+                if (!dispHelp) {
+                    print_usage(argv[0]);
+                    dispHelp = true;
+                }
+                break;
+
+            case 'l':
+                if (dispList) {
+                    break;
+                }
+                if (listApp()) {
+                    printf("Fail to display the list of installed applications");
+                    return -1;
+                }
+                dispList = true;
+                break;
+
+            case 'S':
+                if (dispRunList) {
+                    break;
+                }
+                printf("\t pkg_name (PID)\n");
+                if (aul_app_get_running_app_info(iterfunc_status, NULL)) {
+                    printf("Fail to display the list of Running applications");
+                    return -1;
+                }
+                dispRunList = true;
+                break;
+
+            case 's':
+            case 'k':
+            case 'r':
+                strncpy(args.applicationId, optarg, strlen(optarg));
+                op = next_opt;
+                break;
+
+            case 'd':
+                args.flag_debug = 1;
+                break;
+
+            case -1:
+                break;
+
+            default:
+               print_usage(argv[0]);
+               break;
+            }
+        } while (next_opt != -1);
+
+        if (argc == 1)
+            print_usage(argv[0]);
+
+        if (optind < argc) {
+            printf("Wrong option: ");
+            while (optind < argc)
+               printf("%s ", argv[optind++]);
+            printf("\n");
+            print_usage(argv[0]);
+        }
+        if ((op == 's') || (op == 'k') || (op == 'r')) {
+          if (IsAppInstalled(args.applicationId) <= 0) {
+                printf("The app with ID: %s is not avaible for the user %d \n", args.applicationId, getuid());
+                return -1;
+          }
+        }
+
+        if (op == 's') {
+            if (strlen(args.applicationId) <= 0) {
+                printf("result: %s\n", "failed");
+                return -1;
+            }
+            aul_launch_init(NULL, NULL);
+            g_idle_add(run_func, args.applicationId);
+            mainloop = g_main_loop_new(NULL, FALSE);
+            if (!mainloop) {
+                printf("failed to create glib main loop\n");
+                exit(EXIT_FAILURE);
+            }
+            g_main_loop_run(mainloop);
+            return 0;
+        } else if (op == 'k') {
+            bool isRunning = false;
+            isRunning = aul_app_is_running(args.applicationId);
+            if (true == isRunning) {
+                aul_app_get_running_app_info(iterfunc_kill, args.applicationId);
+            } else {
+                printf("result: %s\n", "App isn't running");
+                return 0;
+            }
+        } else if (op == 'r') {
+            bool isRunning = aul_app_is_running(args.applicationId);
+            if (true == isRunning) {
+                printf("result: %s\n", "running");
+                return 0;
+            } else {
+                printf("result: %s\n", "not running");
+                return -1;
+            }
+        }
+    return 0;
+}
+
index e186c6f..3b4ac62 100644 (file)
@@ -44,6 +44,14 @@ Requires:   %{name} = %{version}-%{release}
 %description devel
 Application utility library (devel)
 
+%package test
+Summary:    App utility test tools 
+Group:      Development/Libraries
+Requires:   %{name} = %{version}-%{release}
+
+%description test
+Application utility library (test tools)
+
 
 %prep
 %setup -q
@@ -106,16 +114,13 @@ systemctl daemon-reload
 %attr(0644,root,root) %{_libdir}/libaul.so.0
 %attr(0644,root,root) %{_libdir}/libaul.so.0.1.0
 %{_sysconfdir}/init.d/launchpad_run
-%attr(0755,root,root) %{_bindir}/aul_service.sh
-%attr(0755,root,root) %{_bindir}/aul_service_test.sh
 %attr(0755,root,root) %{_sysconfdir}/rc.d/rc3.d/S34launchpad_run
 %attr(0755,root,root) %{_sysconfdir}/rc.d/rc4.d/S80launchpad_run
 %config(noreplace) %attr(0644,root,%{TZ_SYS_USER_GROUP}) %{TZ_SYS_DB}/.mida.db
 %config(noreplace) %attr(0644,root,%{TZ_SYS_USER_GROUP}) %{TZ_SYS_DB}/.mida.db-journal
 %attr(0755,root,root) %{_bindir}/aul_mime.sh
 %{_bindir}/aul_test
-%{_bindir}/launch_app
-%{_bindir}/open_app
+%{_bindir}/app_launcher
 %{_bindir}/amd_session_agent
 %{_datadir}/aul/miregex/*
 %{_datadir}/aul/service/*
@@ -129,6 +134,13 @@ systemctl daemon-reload
 %{_bindir}/daemon-manager-release-agent
 %{_bindir}/daemon-manager-launch-agent
 
+
+%files  test
+%{_bindir}/launch_app
+%{_bindir}/open_app
+%attr(0755,root,root) %{_bindir}/aul_service.sh
+%attr(0755,root,root) %{_bindir}/aul_service_test.sh
+
 %files devel
 %{_includedir}/aul/*.h
 %{_libdir}/*.so