#include <string.h>
#include <stdlib.h>
+#include <stdbool.h>
#include <stdio.h>
#include <dirent.h>
#include <unistd.h>
#define WGT_BACKEND_CMD "/usr/bin/wgt-backend"
#define TPK_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-tpk")
#define WGT_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-wgt")
+#define TPK_RW_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-tpk")
+#define WGT_RW_DIR tzplatform_mkpath(TZ_SYS_RO_APP, ".preload-rw-wgt")
-static int _install_preload_pkg(const char *backend, const char *directory)
+static int _install_preload_pkg(const char *backend, const char *directory,
+ bool readonly)
{
DIR *dir;
struct dirent file_info, *result;
pid_t pid = fork();
if (pid == 0) {
execl(backend, backend, "-i", file_path,
- "--preload", (char *)NULL);
+ readonly? "--preload":"--preload-rw",
+ (char *)NULL);
} else if (pid < 0) {
_E("failed to fork and execute %s!", backend);
closedir(dir);
}
/* remove a file after installation */
- ret = remove(file_path);
- if (ret < 0) {
- _E("Failed to remove the file [%s] because [%s]",
- file_path, strerror_r(errno, err_buf,
- sizeof(err_buf)));
- closedir(dir);
- return -1;
+ /* keep rw packages for factory-reset */
+ if (readonly) {
+ ret = remove(file_path);
+ if (ret < 0) {
+ _E("Failed to remove the file [%s] because [%s]",
+ file_path, strerror_r(errno, err_buf,
+ sizeof(err_buf)));
+ closedir(dir);
+ return -1;
+ }
}
}
return -1;
}
- if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_DIR) < 0)
+ if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_DIR, true) < 0)
+ goto error;
+
+ if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_DIR, true) < 0)
+ goto error;
+
+ if (_install_preload_pkg(TPK_BACKEND_CMD, TPK_RW_DIR, false) < 0)
goto error;
- if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_DIR) < 0)
+ if (_install_preload_pkg(WGT_BACKEND_CMD, WGT_RW_DIR, false) < 0)
goto error;
return 0;