Remove equal to distinguish pass or failure more stricktly
[platform/core/system/system-popup.git] / src / usb / usbotg-mobile.c
old mode 100755 (executable)
new mode 100644 (file)
index f3ba464..6c70b67
@@ -1,7 +1,7 @@
 /*
  *  system-popup
  *
- * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -53,7 +53,7 @@ static const struct popup_ops storage_removed_unsafe_ops;
 static void remove_otg_popup(const struct popup_ops *ops, char *path)
 {
        int len;
-       char *popup_path;
+       char *popup_path = NULL;
 
        if (ops == &storage_mounted_ops)
                popup_path = added_path;
@@ -107,7 +107,7 @@ static void launch_app(int type)
 {
        app_control_h app_control;
 
-       int ret, i, type_len;
+       int ret = -1, i, type_len;
 
        type_len = ARRAY_SIZE(app_type);
        for (i = 0 ; i < ARRAY_SIZE(app_type) ; i++) {
@@ -115,7 +115,7 @@ static void launch_app(int type)
                        break;
        }
        if (i == type_len) {
-               _E("Invalid type (%d)", type);
+               _E("Invalid type(%d).", type);
                return;
        }
 
@@ -123,17 +123,29 @@ static void launch_app(int type)
        if (ret != APP_CONTROL_ERROR_NONE)
                return;
 
-       ret = app_control_set_operation(app_control, APP_CONTROL_OPERATION_VIEW);
+       if (type == 0)
+               ret = app_control_set_app_id(app_control, MYFILES_APPNAME);
+       else if (type == 1)
+               ret = app_control_set_app_id(app_control, GALLERY_APPNAME);
+       else {
+               _E("No matched type(%d).", type);
+               goto out;
+       }
+
        if (ret != APP_CONTROL_ERROR_NONE) {
-               (void)app_control_destroy(app_control);
-               return;
+               _E("Failed to set app id.");
+               goto out;
        }
 
        ret = app_control_send_launch_request(app_control, NULL, NULL);
        if (ret != APP_CONTROL_ERROR_NONE)
-               _E("Failed to send launch request");
+               _E("Fail to send launch request.");
 
-       (void)app_control_destroy(app_control);
+out:
+       if (app_control) {
+               (void)app_control_destroy(app_control);
+               app_control = NULL;
+       }
 }
 
 static void storage_browse(const struct popup_ops *ops)
@@ -163,60 +175,42 @@ static void storage_unmount(const struct popup_ops *ops)
                        DEVICED_IFACE_USBHOST,
                        SIGNAL_NAME_UNMOUNT, "s", param);
        if (ret < 0)
-               _E("FAIL: broadcast_dbus_signal()");
+               _E("Failed to broadcast_dbus_signal().");
 
        memset(removed_path, 0, sizeof(removed_path));
 
        terminate_if_no_popup();
-       
 }
 
 static int storage_mounted_launch(bundle *b, const struct popup_ops *ops)
 {
-       int ret;
-       struct object_ops *obj;
        char *path;
 
        if (!ops)
                return -1;
 
-       ret = get_object_by_ops(ops, &obj);
-       if (ret < 0) {
-               _E("Failed to get object (%d)", ret);
-               return -2;
-       }
-
-       path = (char *)bundle_get_val(obj->b, USB_MOUNT_PATH);
+       path = (char *)bundle_get_val(b, USB_MOUNT_PATH);
        if (!path) {
-               _E("Failed to get mount path");
-               return -3;
+               _E("Failed to get mount path.");
+               return -2;
        }
 
-       _I("USB storage mount path (%s)", path);
+       _I("USB storage mount path(%s).", path);
        snprintf(added_path, sizeof(added_path), "%s", path);
        return 0;
 }
 
 static int unmount_storage_launch(bundle *b, const struct popup_ops *ops)
 {
-       int ret;
-       struct object_ops *obj;
        char *path;
 
        if (!ops)
                return -1;
 
-       ret = get_object_by_ops(ops, &obj);
-       _D("ops = %s obj = %s",ops, obj);       
-       if (ret < 0) {
-               _E("Failed to get object (%d)", ret);
-               return -2;
-       }
-
-       path = (char *)bundle_get_val(obj->b, USB_MOUNT_PATH);
+       path = (char *)bundle_get_val(b, USB_MOUNT_PATH);
        if (!path) {
-               _E("Failed to get mount path");
-               return -3;
+               _E("Failed to get mount path.");
+               return -2;
        }
 
        remove_otg_popup(&storage_mounted_ops, path);
@@ -234,7 +228,7 @@ static int storage_unmounted(bundle *b, const struct popup_ops *ops)
 
        path = (char *)bundle_get_val(b, USB_MOUNT_PATH);
        if (!path) {
-               _E("Failed to get mount path");
+               _E("Failed to get mount path.");
                return -ENOENT;
        }
 
@@ -254,6 +248,7 @@ static int camera_removed(bundle *b, const struct popup_ops *ops)
 
 static const struct popup_ops storage_mounted_ops = {
        .name                   = "usbotg_storage_mounted",
+       .pattern                = FEEDBACK_PATTERN_LOWBATT,
        .show                   = load_simple_popup,
        .title                  = "IDS_ST_BODY_USB_STORAGE_ABB",
        .content                = "IDS_USB_BODY_BROWSE_STORAGE_CONNECTED_VIA_USB_Q",
@@ -281,6 +276,7 @@ static const struct popup_ops unmount_storage_ops = {
 
 static const struct popup_ops camera_added_ops = {
        .name                   = "usbotg_camera_added",
+       .pattern                = FEEDBACK_PATTERN_LOWBATT,
        .show                   = load_simple_popup,
        .title                  = "IDS_CAM_HEADER_CAMERA_M_APPLICATION",
        .content                = "IDS_USB_BODY_BROWSE_CAMERA_CONNECTED_VIA_USB_Q",
@@ -296,6 +292,7 @@ static const struct popup_ops camera_removed_ops = {
 
 static const struct popup_ops storage_mount_failed_ops = {
        .name                   = "usbotg_storage_mount_failed",
+       .pattern                = FEEDBACK_PATTERN_LOWBATT,
        .show                   = load_simple_popup,
        .title                  = "IDS_COM_HEADER_ATTENTION",
        .content                = "IDS_COM_BODY_USB_STORAGE_BLANK_OR_HAS_UNSUPPORTED_FILE_SYSTEM",