+static int __tep_mount(char *mnt_path[])
+{
+ DBusMessage *msg;
+ int func_ret = 0;
+ int rv = 0;
+ struct stat link_buf = {0,};
+
+ static DBusConnection *conn = NULL;
+
+ if (!conn) {
+ conn = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
+ if (!conn) {
+ _E("dbus_bus_get error");
+ return -1;
+ }
+ }
+
+ rv = lstat(mnt_path[0], &link_buf);
+ if (rv == 0) {
+ rv = unlink(mnt_path[0]);
+ if (rv)
+ _E("Unable tp remove link file %s", mnt_path[0]);
+ }
+
+ msg = dbus_message_new_method_call(TEP_BUS_NAME, TEP_OBJECT_PATH,
+ TEP_INTERFACE_NAME, TEP_MOUNT_METHOD);
+ if (!msg) {
+ _E("dbus_message_new_method_call(%s:%s-%s)", TEP_OBJECT_PATH,
+ TEP_INTERFACE_NAME, TEP_MOUNT_METHOD);
+ return -1;
+ }
+
+ if (!dbus_message_append_args(msg,
+ DBUS_TYPE_STRING, &mnt_path[0],
+ DBUS_TYPE_STRING, &mnt_path[1],
+ DBUS_TYPE_INVALID)) {
+ _E("Ran out of memory while constructing args\n");
+ func_ret = -1;
+ goto func_out;
+ }
+
+ if (dbus_connection_send(conn, msg, NULL) == FALSE) {
+ _E("dbus_connection_send error");
+ func_ret = -1;
+ goto func_out;
+ }
+func_out :
+ dbus_message_unref(msg);
+ return func_ret;
+}
+
+static void __send_mount_request(const struct appinfo *ai, const char *tep_name,
+ bundle *kb)
+{
+ SECURE_LOGD("tep name is: %s", tep_name);
+ char *mnt_path[2] = {NULL, };
+ const char *installed_storage = NULL;
+ char tep_path[PATH_MAX] = {0, };
+ const char *path_app_root = NULL;
+
+ const char *global = appinfo_get_value(ai, AIT_GLOBAL);
+ const char *pkgid = appinfo_get_value(ai, AIT_PKGID);
+ installed_storage = appinfo_get_value(ai, AIT_STORAGE_TYPE);
+
+ if (global && strcmp("true", global) == 0)
+ path_app_root = PATH_GLOBAL_APP_ROOT;
+ else
+ path_app_root = PATH_APP_ROOT;
+
+ if (installed_storage != NULL) {
+ SECURE_LOGD("storage: %s", installed_storage);
+ if (strncmp(installed_storage, "internal", 8) == 0) {
+ snprintf(tep_path, PATH_MAX, "%s/%s/res/%s", path_app_root, pkgid,
+ tep_name);
+ mnt_path[1] = strdup(tep_path);
+ snprintf(tep_path, PATH_MAX, "%s/%s/res/tep", path_app_root, pkgid);
+ mnt_path[0] = strdup(tep_path);
+ } else if (strncmp(installed_storage, "external", 8) == 0) {
+ snprintf(tep_path, PATH_MAX, "%step/%s", PREFIX_EXTERNAL_STORAGE_PATH,
+ tep_name);
+ mnt_path[1] = strdup(tep_path);
+ snprintf(tep_path, PATH_MAX, "%step/tep-access",
+ PREFIX_EXTERNAL_STORAGE_PATH); /* TODO : keeping tep/tep-access for now for external storage */
+ mnt_path[0] = strdup(tep_path);
+ }
+
+ if (mnt_path[0] && mnt_path[1]) {
+ bundle_add(kb, AUL_TEP_PATH, mnt_path[0]);
+ int ret = -1;
+ ret = aul_is_tep_mount_dbus_done(mnt_path[0]);
+ if (ret != 1) {
+ ret = __tep_mount(mnt_path);
+ if (ret < 0)
+ _E("dbus error %d", ret);
+ }
+ }
+ if (mnt_path[0])
+ free(mnt_path[0]);
+ if (mnt_path[1])
+ free(mnt_path[1]);
+ }
+}
+