*
*/
-#include <stdio.h>
#include <stdlib.h>
+#include <system_info.h>
+#include <system_info_type.h>
+#include <tizen.h>
+#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/param.h>
#include <unistd.h>
+#include <vconf.h>
+#include <sqlite3.h>
+#include <db-util.h>
+#include "schema.h"
+#include "cal_server_profile.h"
#include "calendar.h"
#include "cal_typedef.h"
#include "cal_internal.h"
#define CAL_TIMEOUT_FOR_DECLARE 1
#define CAL_TIMEOUT_FOR_DEFAULT 0
+#define CAL_RESET "db/calendar_service/reset_status"
+
GMainLoop* main_loop = NULL;
static int cal_timeout = 0;
static int _cal_server_init(void)
{
+
+
int ret = 0;
#if !GLIB_CHECK_VERSION(2, 35, 0)
g_type_init();
cal_disconnect();
}
+
+static bool bNeedToRemove = false;
+int dbIntegrityCheckCallback(void *pid, int argc, char **argv, char **notUsed2)
+{
+ if (!strncmp(argv[0], "ok", strlen("ok"))) {
+ DBG("db integrity check done - no error");
+ } else {
+ ERR("db integrity check failed : %d , %s", argc, argv[0]);
+ bNeedToRemove = true;
+ }
+ return 0;
+}
+
+
+int checkDb(void)
+{
+ INFO("---------------------[checkDb START]------------------------");
+ if (open_file() == 0)
+ {
+ int r = 0;
+ sqlite3 *db = NULL;
+
+ r = sqlite3_open(CAL_DB_FILE, &db);
+ if (r != SQLITE_OK) {
+ ERR("DB open: [%s], remove", sqlite3_errmsg(db));
+ sqlite3_close(db);
+ if(remove(CAL_DB_FILE)!=0)
+ ERR("Fail to remove the FIle");
+ return -1;
+ }
+
+ r = sqlite3_exec(db, "pragma integrity_check", dbIntegrityCheckCallback, NULL, NULL);
+ if (r == SQLITE_CORRUPT || r == SQLITE_NOTADB) {
+ ERR("SQLITE_ERROR [%d]", r);
+ ERR("SQLITE_ERROR [%d]", r);
+ bNeedToRemove = true;
+ }
+
+ if (bNeedToRemove == true) {
+ sqlite3_close(db);
+ if(remove(CAL_DB_FILE)!=0)
+ ERR("Fail to remove the FIle");
+ else
+ ERR("db deleted");
+
+ bNeedToRemove = false;
+ return -1;
+ }
+ sqlite3_close(db);
+ DBG("DBFILE [%s] pragma intergrity check OK", CAL_DB_FILE);
+ return 0;
+ }
+ INFO("---------------------[checkDb END]------------------------");
+ return -1;
+}
+
+
+
+int deleteDBFile()
+{
+ INFO("---------------------[deleteDBFile START]------------------------");
+ int ret = 0;
+
+ if(checkDb() == 0){
+ ret = remove(CAL_DB_FILE);
+ if (ret != 0)
+ {
+ ERR("Not able to delete DB file");
+ return -1;
+ }
+
+ }
+ else{
+ ERR("deleteDBFile is not progressed : No DB file to remove");
+ return -1;
+ }
+
+
+ INFO("Successfully deleted!!");
+ return 0;
+}
+
+
+
+void checkFactoryReset()
+{
+ INFO("---------------------[service_app_create START]------------------------");
+ int value = 0;
+ if (vconf_get_int(CAL_RESET, &value) == 0)
+ {
+ if (value == 1 || value == 2)
+ {
+ INFO("need to cleanup db %d", value);
+ int ret = 0;
+ ret = deleteDBFile();
+ if(ret != 0)
+ {
+ ERR("Calendar DB delete fail! What should I do?");
+ }
+
+ if(remake_db()!=0)
+ {
+ ERR("Remake of Calendar DB failed! ");
+ }
+
+ ret = vconf_set_int(CAL_RESET, 0);
+ if (ret != 0) {
+ ERR("retry vconf_set_int %d", ret);
+ ret = vconf_set_int(CAL_RESET, 0);
+ if (ret != 0) {
+ ERR("vconf_set_int failed %d", ret);
+ }
+ }
+ }
+ else
+ {
+ ERR("don't need to cleanup db %d", value);
+ }
+ }
+ else
+ {
+ ERR("vconf_get_int failed");
+ }
+ INFO("---------------------[service_app_create END]------------------------");
+}
+
+
+
static int _cal_server_main(void)
{
main_loop = g_main_loop_new(NULL, FALSE);
cal_server_schema_check();
cal_server_update();
+#ifdef TIZEN_PROFILE_TV
+ checkFactoryReset();
+#endif
+
+
+
_cal_server_init();
cal_server_account_init();
return 0;
}
-