summaryrefslogtreecommitdiff
path: root/src/factory-reset-util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/factory-reset-util.c')
-rwxr-xr-xsrc/factory-reset-util.c382
1 files changed, 382 insertions, 0 deletions
diff --git a/src/factory-reset-util.c b/src/factory-reset-util.c
new file mode 100755
index 0000000..508ebe2
--- /dev/null
+++ b/src/factory-reset-util.c
@@ -0,0 +1,382 @@
+/*
+ * 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;
+}
+