4 * Copyright (c) 2014, Intel Corporation.
6 * Contact: Baptiste DURAND <baptiste.durand@open.eurogiciel.org>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
26 #include <sys/types.h>
37 static GMainLoop *mainloop = NULL;
41 char applicationId[256];
45 static bundle *create_internal_bundle()
49 char arg[1024] = {0, };
53 bundle_add(kb, AUL_K_DEBUG, "1");
57 int launch(char* appid,int debug_option)
63 pid = aul_open_app(appid);
65 kb = create_internal_bundle();
67 printf("bundle creation fail\n");
70 pid = aul_launch_app(appid, kb);
77 static int __launch_app_dead_handler(int pid, void *data)
79 int listen_pid = (int) data;
82 g_main_loop_quit(mainloop);
87 static gboolean run_func(void *data)
91 struct launch_arg* launch_arg_data = NULL;
92 launch_arg_data = (struct launch_arg*)data;
93 if ((pid = launch((char*)launch_arg_data->applicationId,launch_arg_data->flag_debug)) > 0) {
94 printf("... successfully launched whit debug %d\n",launch_arg_data->flag_debug);
96 printf("... launch failed\n");
98 g_main_loop_quit(mainloop);
108 void print_usage(char *program)
110 printf("Usage : %s [ ... ]\n", program);
112 " -h --help Display this usage information.\n"
113 " -l --list Display installed apps list\n"
114 " -S --status Display running apps list\n"
115 " -s [tizen application ID] --start Launch widget with tizen application ID\n"
116 " -k [tizen application ID] --kill Kill widget with tizen application ID\n"
117 " -r [tizen application ID] --is-running Check whether application is running by tizen application ID,\n"
118 " If widget is running, 0(zero) will be returned.\n"
119 " -d --debug Activate debug mode\n"
124 ail_cb_ret_e appinfo_list_appid_namefunc(const ail_appinfo_h appinfo, void *user_data)
126 char* package_str_name = NULL;
127 char* package_str_appid = NULL;
128 char* package_str_x_package_type = NULL;
129 ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_APPID_STR, &package_str_appid);
130 ail_appinfo_get_str(appinfo, AIL_PROP_NAME_STR, &package_str_name);
131 ail_appinfo_get_str(appinfo, AIL_PROP_X_SLP_PACKAGETYPE_STR, &package_str_x_package_type);
133 printf("\t'%s'\t '%s'\t %s\n",package_str_name, package_str_appid, package_str_x_package_type);
134 return AIL_CB_RET_CONTINUE;
141 printf("\tApplication List for user %lu\n", (long)getuid());
142 printf("\tUser's Application \n");
143 printf("\t Name \t AppID \t Type \n");
144 printf("\t=================================================\n");
145 if ( ail_filter_list_usr_appinfo_foreach(NULL, appinfo_list_appid_namefunc, NULL, getuid() ) != AIL_ERROR_OK )
147 printf("\t=================================================\n");
153 int iterfunc_status(const aul_app_info *info, void *data)
155 printf("\t %s (%d)\n",info->appid, info->pid);
161 int iterfunc_kill(const aul_app_info *info, void *data)
165 if(strcmp(info->appid,data) == 0) {
166 aul_kill_pid(info->pid);
167 printf("\t Kill pkg_name: %s (%d)\n", info->appid,info->pid);
172 int IsAppInstalled(char *appid)
178 if (ail_filter_new(&f) != AIL_ERROR_OK)
180 if (ail_filter_add_str(f, AIL_PROP_X_SLP_APPID_STR, appid) != AIL_ERROR_OK) {
181 ail_filter_destroy(f);
184 if (ail_filter_count_usr_appinfo(f, &res, getuid()) != AIL_ERROR_OK) {
185 ail_filter_destroy(f);
191 int main(int argc, char **argv)
193 bool isDebugMode = false;
194 bool dispHelp = false;
195 bool dispList = false;
196 bool dispRunList = false;
197 int next_opt, opt_idx = 0;
200 struct launch_arg args;
201 static struct option long_options[] = {
202 { "help", no_argument, 0, 'h' },
203 { "list", no_argument, 0, 'l' },
204 { "status", no_argument, 0, 'S' },
205 { "start", required_argument, 0, 's' },
206 { "kill", required_argument, 0, 'k' },
207 { "is-running", required_argument, 0, 'r' },
208 { "debug", no_argument, 0, 'd' },
211 memset(&args,0,sizeof(struct launch_arg));
214 next_opt = getopt_long(argc,
223 print_usage(argv[0]);
233 printf("Fail to display the list of installed applications");
243 printf("\t pkg_name (PID)\n");
244 if (aul_app_get_running_app_info(iterfunc_status, NULL)) {
245 printf("Fail to display the list of Running applications");
254 if(strlen(optarg) > 255) {
255 print_usage(argv[0]);
258 strcpy(args.applicationId, optarg);
270 print_usage(argv[0]);
273 } while (next_opt != -1);
276 print_usage(argv[0]);
279 printf("Wrong option: ");
280 while (optind < argc)
281 printf("%s ", argv[optind++]);
283 print_usage(argv[0]);
285 if ((op == 's') || (op == 'k') || (op == 'r')) {
286 if (IsAppInstalled(args.applicationId) <= 0) {
287 printf("The app with ID: %s is not avaible for the user %d \n", args.applicationId, getuid());
293 if (strlen(args.applicationId) <= 0) {
294 printf("result: %s\n", "failed");
297 aul_launch_init(NULL, NULL);
298 g_idle_add(run_func, args.applicationId);
299 mainloop = g_main_loop_new(NULL, FALSE);
301 printf("failed to create glib main loop\n");
304 g_main_loop_run(mainloop);
306 } else if (op == 'k') {
307 bool isRunning = false;
308 isRunning = aul_app_is_running(args.applicationId);
309 if (true == isRunning) {
310 aul_app_get_running_app_info(iterfunc_kill, args.applicationId);
312 printf("result: %s\n", "App isn't running");
315 } else if (op == 'r') {
316 bool isRunning = aul_app_is_running(args.applicationId);
317 if (true == isRunning) {
318 printf("result: %s\n", "running");
321 printf("result: %s\n", "not running");