Make boot-animation can be built by 'ABS'
[apps/native/boot-animation.git] / src / boot.c
1 /*
2  * Copyright (c) 2009-2015 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <errno.h>
22 #include <fcntl.h>
23 #include <sys/ioctl.h>
24 #include <sys/mman.h>
25 #include <sys/types.h>
26 #include <sys/stat.h>
27 #include <sys/time.h>
28 #include <linux/fb.h>
29 #include <stddef.h>
30 #include <unistd.h>
31
32 #include <pthread.h>
33
34 #include <Elementary.h>
35
36 #include <getopt.h>
37 //#include <mm_sound_private.h>
38 #include <system_settings.h>
39
40 #include <vconf.h>
41
42 #include "animation.h"
43 #include "boot.h"
44 #include "log.h"
45
46 #define XRGB8888 4
47
48 extern char *optarg;
49 extern int optind, opterr, optopt;
50
51 struct args {
52         int argc;
53         char **argv;
54         char *msg;
55 };
56
57
58 static void print_usages(char *argv0)
59 {
60         printf("Usage) %s {--start|--stop}\n"
61                "  Ex:"
62                "    # %s --start\n"
63                "    # %s --stop\n"
64                "    # %s --off\n"
65                "    # %s --offmsg YOUR_MESSAGE\n", argv0, argv0, argv0, argv0,
66                argv0);
67 }
68
69 /* Sound is not supported Since Tizen 4.0 */
70 #if 0
71 static int get_wav_file(int state, char *wavpath)
72 {
73         _D("Get wav file");
74         if (state == TYPE_ON) {
75                 snprintf(wavpath, FILE_PATH_MAX-1, "%s", DEFAULT_POWERON_WAV);
76                 _D("Wav file: %s", wavpath);
77         } else
78                 return -1;
79
80         return 0;
81 }
82 #endif
83
84 static int xready_cb(keynode_t * node, void *user_data)
85 {
86         int c;
87         int argc;
88         char **argv;
89         int type = TYPE_UNKNOWN;
90         struct args *args = user_data;
91         static struct option long_options[] = {
92                 {"start",       no_argument,            0,      's'     },
93                 {"stop",        no_argument,            0,      'p'     },
94                 {"off",         no_argument,            0,      'o'     },
95                 {"offmsg",      required_argument,      0,      'm'     },
96                 {"clear",       no_argument,            0,      'c'     },
97                 {0,             0,                      0,      0       },
98         };
99         static int invoked_flag = 0;
100
101         _D("xready_cb");
102         printf("xready_cb\n");
103
104         if (invoked_flag == 1) {
105                 _E("Already launched");
106                 printf("Error Already launched\n");
107                 return EXIT_FAILURE;
108         }
109
110         invoked_flag = 1;
111
112         argc = args->argc;
113         argv = args->argv;
114
115         int i;
116         for (i = 0; i < argc; i++) {
117             _D("argc %d [%s]", i, argv[i]);
118             printf("argc %d [%s]\n", i, argv[i]);
119         }
120         while ((c = getopt_long(argc, argv, "spom:c", long_options, NULL)) >= 0) {
121
122                 switch (c) {
123                 case 's':
124                         type = TYPE_ON;
125                         continue;
126                 case 'p':
127                         type = TYPE_OFF;
128                         continue;
129                 case 'o':
130                         type = TYPE_OFF_NOEXIT;
131                         continue;
132                 case 'm':
133                         if (args->msg) continue;
134                         type = TYPE_OFF_WITH_MSG;
135                         args->msg = strdup(optarg);
136                         if (!args->msg)
137                                 perror("strdup");
138                         continue;
139                 case 'c':
140                         continue;
141                 default:
142                         type = TYPE_UNKNOWN;
143                         _D("[Boot-ani] unknown arg [%s]", optarg);
144                         printf("[Boot-anim] unknown arg [%s]\n", optarg);
145                         return EXIT_FAILURE;
146                 }
147         }
148
149         /* Sound is not supported Since Tizen 4.0 */
150 #if 0
151         /* check sound profile */
152         char wav_path[256];
153         int soundon = 1;        /* default sound on */
154         if (vconf_get_bool(VCONFKEY_SETAPPL_SOUND_STATUS_BOOL, &soundon) < 0) {
155                 _D("VCONFKEY_SETAPPL_SOUND_STATUS_BOOL ==> FAIL!!");
156                 printf("VCONFKEY_SETAPPL_SOUND_STATUS_BOOL ==> FAIL!!\n");
157         }
158
159         _D("Sound status: %d", soundon);
160         printf("Sound status: %d\n", soundon);
161 #endif
162
163         if (init_animation(type, args->msg) != EXIT_SUCCESS) {
164                 _D("Exit boot-animation");
165                 printf("Exit boot-animation\n");
166                 return EXIT_FAILURE;
167         }
168
169 #if 0
170         if (soundon) {
171                 _D("Sound on!!");
172                 printf("Sound on!!\n");
173                 if (!get_wav_file(type, wav_path)) {
174                         _D("File path: %s", wav_path);
175                         printf("File path: %s\n", wav_path);
176                         mm_sound_boot_ready(3);
177                         mm_sound_boot_play_sound(wav_path);
178                 }
179         }
180 #endif
181         _D("EXIT SUCESS");
182
183         return EXIT_SUCCESS;
184 }
185
186 #if 0
187 static void _boot_ani_ui_set_scale(void)
188 {
189         double root_height = 0.0;
190         double root_width = 0.0;
191         char buf[128] = { 0, };
192         Display *disp;
193         int screen_num;
194
195         disp = XOpenDisplay(NULL);
196         if (disp == NULL)
197                 return;
198
199         screen_num = DefaultScreen(disp);
200
201         root_height = DisplayHeight(disp, screen_num);
202         root_width = DisplayWidth(disp, screen_num);
203
204         XCloseDisplay(disp);
205
206         snprintf(buf, sizeof(buf), "%lf", root_height / BA_DEFAULT_WINDOW_H);
207         //snprintf(buf, sizeof(buf), "%lf", root_width / BA_DEFAULT_WINDOW_W);
208         _D("Boot animation scale : [%s]", buf);
209
210         setenv("ELM_SCALE", buf, 1);
211         setenv("SCALE_FACTOR", buf, 1);
212 }
213 #endif
214
215 int main(int argc, char *argv[])
216 {
217         int fd = 0;
218         struct args args;
219         setenv("HOME", "/home/root", 1);
220
221         if (argc < 2) {
222                 print_usages(argv[0]);
223                 return EXIT_FAILURE;
224         }
225
226         args.argc = argc;
227         args.argv = argv;
228         args.msg = NULL;
229
230 #if 0
231         _boot_ani_ui_set_scale();
232 #endif
233
234         close(1);
235         fd = open("/tmp/myfile.txt", O_CREAT|O_RDWR, S_IRWXU|S_IRWXO);
236         _D("result of open: %d", fd);
237         printf("[%s/%s/%d] fd == %d\n", __FILE__, __func__, __LINE__, fd);
238
239         elm_init(argc, argv);
240
241         if (vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 0) != 0) {
242                 _D("Failed to set finished value to 0\n");
243                 printf("[%s/%s/%d] Failed to set finished value to 0\n", __FILE__, __func__, __LINE__);
244         }
245         if (xready_cb(NULL, &args) != EXIT_SUCCESS) {
246                 vconf_set_int(VCONFKEY_BOOT_ANIMATION_FINISHED, 1);
247                 return 1;
248         }
249
250         elm_run();
251
252         fini_animation();
253
254         if (args.msg)
255                 free(args.msg);
256         return 0;
257 }
258
259 //ELM_MAIN()