summaryrefslogtreecommitdiff
path: root/src/factory-reset-util.c
blob: 7564366c558692d88fdb6af840e3dc2733db4ca8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
/*
 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd.
 *
 * Contact: MyoungJune Park <mj2004.park@samsung.com>
 *   Created by Wonil Choi <wonil22.choi@samsung.com>
 *
 * 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>

#if 0
#ifndef TELEPHONY_DISABLE
#include <tapi_common.h>
#include <TapiCommon.h>
#include <ITapiModem.h>
#include <ITapiCfg.h>
#endif
#endif

//#include <Ecore_X.h>
//#include <utilX.h>
#include <appcore-efl.h>

#include "factory-reset-util.h"

#ifndef FACTORY_RESET_FONT_SIZE
#define FACTORY_RESET_FONT_SIZE	34	/* default font size */
#endif

#define FACTORY_RESET_PROCESS_MSG dgettext("factory-reset",\
		"IDS_ST_BODY_PERFORMING_FACTORY_DATA_RESET_PLEASE_WAIT_ING")

static void win_del(void *data, Evas_Object *obj, void *event)
{
	elm_exit();
}

static void main_quit_cb(void *data, Evas_Object *obj,
		const char *emission, const char *source)
{
	elm_exit();
}

static Evas_Object* create_win(const char *name)
{
	Evas_Object *eo;
	//Ecore_X_Window xwin;
	int w, h;

	w = 200;
	h = 400;

	eo = elm_win_add(NULL, name, ELM_WIN_BASIC);
	if (!eo)
		return NULL;

	elm_win_title_set(eo, name);
	elm_win_borderless_set(eo, EINA_TRUE);
	evas_object_smart_callback_add(eo, "delete,request", win_del, NULL);
	//ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
	evas_object_resize(eo, w, h);

	/* For default color */
	//ea_theme_changeable_ui_enabled_set(EINA_TRUE);

#if 0
	/* Get x-window */
	xwin = elm_win_xwindow_get(eo);
	if (xwin == 0) {
		FR_LOGD("elm_win_xwindow_get() failed\n");
		return eo;
	}
#endif

	/* set notification type */
	//ecore_x_netwm_window_type_set(xwin, ECORE_X_WINDOW_TYPE_NOTIFICATION);

	/* set notification's priority */
	//utilx_set_system_notification_level(ecore_x_display_get(), xwin, UTILX_NOTIFICATION_LEVEL_NORMAL);

	return eo;
}

static Evas_Object* load_edj(Evas_Object *parent, const char *file,
		const char *group)
{
	Evas_Object *eo;
	int r;

	eo = elm_layout_add(parent);
	if (eo) {
		r = elm_layout_file_set(eo, file, group);
		if (!r) {
			evas_object_del(eo);
			return NULL;
		}

		evas_object_size_hint_weight_set(eo,
				EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	}

	return eo;
}

#if 0
static Evas_Object* _create_progressbar(Evas_Object* parent)
{
	Evas_Object *progressbar;
	Evas_Object *layout = parent;

	/* pending_list style */
	progressbar = elm_progressbar_add(layout);
	elm_object_style_set(progressbar, "pending");
	elm_progressbar_horizontal_set(progressbar, EINA_TRUE);
	evas_object_size_hint_align_set(progressbar, EVAS_HINT_FILL, EVAS_HINT_FILL);
	evas_object_size_hint_weight_set(progressbar, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_progressbar_pulse(progressbar, EINA_TRUE);
	elm_object_part_content_set(layout, "pending_pbar", progressbar);
	evas_object_show(progressbar);

	return layout;
}
#endif

static Evas_Object* _create_label(Evas_Object* parent)
{
	Evas_Object *label, *layout = parent;
	char mesg[1024];

	if (parent == NULL)
		return NULL;

	snprintf(mesg, sizeof(mesg),
			"<align=center><font color=#C7C7C7><font_size=%d>%s",
			FACTORY_RESET_FONT_SIZE, FACTORY_RESET_PROCESS_MSG);

	label = elm_label_add(layout);
	elm_label_line_wrap_set(label, ELM_WRAP_MIXED);
	evas_object_size_hint_align_set(label, EVAS_HINT_FILL, EVAS_HINT_FILL);
	evas_object_size_hint_weight_set(label, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_object_part_content_set(layout, "txt_mesg", label);
	elm_object_text_set(label, mesg);
	evas_object_show(label);

	return layout;
}

static int app_create(void *data)
{
	struct appdata *ad = data;
	Evas_Object *win;
	Evas_Object *ly;
	int r;

	/* create window */
	win = create_win(PACKAGE);
	if (win == NULL)
		return -1;
	ad->win = win;

	elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_HIDE);
	evas_object_show(win);

	/* load edje */
	ly = load_edj(win, EDJ_FILE, GRP_MAIN);
	if (ly == NULL)
		return -1;
	elm_win_resize_object_add(win, ly);
	edje_object_signal_callback_add(elm_layout_edje_get(ly),
			"EXIT", "*", main_quit_cb, NULL);
	ad->ly_main = ly;

	/* init internationalization */
	r = appcore_set_i18n(PACKAGE, LOCALEDIR);
	if (r)
		return -1;

	//_create_progressbar(ly);
	_create_label(ly);

	evas_object_show(ly);
	evas_object_show(win);

	return 0;
}

static int app_terminate(void *data)
{
	struct appdata *ad = data;

	if (ad->ly_main)
		evas_object_del(ad->ly_main);

	if (ad->win)
		evas_object_del(ad->win);

	return 0;
}

static int app_pause(void *data)
{
	return 0;
}

static int app_resume(void *data)
{
	return 0;
}

static int app_reset(bundle *b, void *data)
{
	struct appdata *ad = data;

	if (ad->win)
		elm_win_activate(ad->win);

	return 0;
}

#if 0
#ifndef TELEPHONY_DISABLE
#define CP_OFF_TIMEOUT		15
static Ecore_Timer *timer_id;

static void cp_shutdown_exit(TapiHandle *handle, const char *noti_id,
		void *data, void *user_data)
{
	tel_deinit(handle);
	ecore_main_loop_quit();
}

static void tapi_response(TapiHandle *handle, int result,
		void *data, void *user_data)
{
	if (result != TAPI_API_SUCCESS) {
		tel_deinit(handle);
		ecore_main_loop_quit();
	}
}

static Eina_Bool timeout_exit(void *data)
{
	perror("no notification from telephony!!");
	ecore_main_loop_quit();
	return EINA_TRUE;
}

static int cp_shutdown(void)
{
	int ret = 0;
	TapiHandle *tapi_handle = 0;

	tapi_handle = tel_init(0);

	if (tapi_handle == NULL)
		return -1;

	FR_LOGD("CP shutdown\n");

	ret = tel_register_noti_event(tapi_handle, TAPI_NOTI_MODEM_POWER,
			cp_shutdown_exit, NULL);
	if (ret != TAPI_API_SUCCESS)
		goto out;

	ret = tel_process_power_command(tapi_handle, TAPI_PHONE_POWER_OFF,
			tapi_response, NULL);
	if (ret != TAPI_API_SUCCESS)
		goto out;

	timer_id = ecore_timer_add(CP_OFF_TIMEOUT, timeout_exit, NULL);
	if (timer_id == NULL)
		ret = -1;
out:
	if (ret < 0) {
		tel_deinit(tapi_handle);
		return -1;
	}
	return 0;
}

/* reset modem configs */
static int cp_resetcfg(int reset_config)
{
	int ret = 0;

	ret = tel_sec_init();
	if (ret != TAPI_SEC_API_SUCCESS)
		return -1;
	/*
	 * Full reset: Initialize all configuration data.
	 * Factory reset (AT+FACTORST=0,0): except IMEI(or ESN, MEID), RF
	 *   calibration date, MAC address.
	 * Service reset (Settings -> Back up and reset -> Factory data reset):
	 *   except IMEI(or ESN, MEID), RF calibration date, MAC address, Life
	 *   time.
	 * Custom reset: except IMEI(or ESN, MEID), RF calibration date, MAC
	 *   address, Life time, connection settings, WAP settings.
	 */
	/* we use the Service reset currently. (except verizon) */
	ret = tel_set_cfg_default_configuration(reset_config);
	FR_LOGD("request cp reset with the flag value: %d\n", reset_config);
	tel_sec_deinit();
	return ret;
}
#else /* TELEPHONY_DISABLE */
static int cp_shutdown(void)
{
	return -1;
} /* in order to avoid main loop */

static int cp_resetcfg(int reset_config)
{
	return 0;
}
#endif /* TELEPHONY_DISABLE */

#endif


int main(int argc, char *argv[])
{
	struct appdata ad;
	struct appcore_ops ops = {
		.create = app_create,
		.terminate = app_terminate,
		.pause = app_pause,
		.resume = app_resume,
		.reset = app_reset,
	};
	int opt;
	int index = -1;
	struct option options[] = {
		{"displayui", 0, 0, 0},
		{"svcrstcp", 0, 0, 0}, /* modem service reset */
		{"ftrrstcp", 0, 0, 0}, /* modem factory reset */
		{"", 0, 0, 0},
		{"", 0, 0, 0},
		{0, 0, 0, 0}
	};


	opt = getopt_long(argc, argv, "", options, &index);
	if (opt == -1)
		return 0;

	switch (index) {
	case 0:
		memset(&ad, 0x0, sizeof(struct appdata));
		ops.data = &ad;
		return appcore_efl_main(PACKAGE, &argc, &argv, &ops);
	case 1:
		ecore_init();
		//cp_resetcfg(TAPI_CFG_DEFAULT_SERVICE);
		//if ( cp_shutdown() == 0) ecore_main_loop_begin();
		ecore_shutdown();
		break;
	case 2:
		ecore_init();
		//cp_resetcfg(TAPI_CFG_DEFAULT_FACTORY);
		//if ( cp_shutdown() == 0) ecore_main_loop_begin();
		ecore_shutdown();
		break;
		break;
	case 3:

		break;
	case 4:

		break;
	default:
		;
	}

	return 0;
}