Fix the coverity issues
[platform/core/connectivity/bluetooth-frwk.git] / bt-core / bt-core-dbus-handler.c
index 41f15b0..04c1297 100644 (file)
 #define BT_HPS_INTERFACE_NAME "org.projectx.httpproxy_service"
 #endif
 
-#ifdef TIZEN_FEATURE_BT_OTP
-#define BT_OTP_SERVICE_NAME    "org.projectx.otp"
-#define BT_OTP_OBJECT_PATH     "/org/projectx/otp"
-#define BT_OTP_INTERFACE_NAME  "org.projectx.otp_service"
-#endif
-
 static GDBusConnection *service_gconn;
 static GDBusProxy *service_gproxy;
 #ifdef TIZEN_FEATURE_BT_HPS
 static GDBusProxy *hps_gproxy;
 #endif
-
-#ifdef TIZEN_FEATURE_BT_OTP
-static GDBusProxy *otp_gproxy;
-#endif
+static gboolean factory_test_mode;
 
 void _bt_core_fill_garray_from_variant(GVariant *var, GArray *param)
 {
@@ -208,69 +199,6 @@ GDBusProxy *_bt_core_gdbus_get_hps_proxy(void)
 }
 #endif
 
-#ifdef TIZEN_FEATURE_BT_OTP
-static GDBusProxy *_bt_core_gdbus_init_otp_proxy(void)
-{
-       GDBusProxy *proxy;
-       GError *err = NULL;
-       GDBusConnection *conn;
-
-       BT_DBG(" ");
-
-       conn = _bt_core_get_gdbus_connection();
-       if (!conn)
-               return NULL;
-
-       proxy =  g_dbus_proxy_new_sync(conn,
-                       G_DBUS_PROXY_FLAGS_NONE, NULL,
-                       BT_OTP_SERVICE_NAME,
-                       BT_OTP_OBJECT_PATH,
-                       BT_OTP_INTERFACE_NAME,
-                       NULL, &err);
-       if (proxy == NULL) {
-               if (err) {
-                        BT_ERR("Unable to create proxy: %s", err->message);
-                        g_clear_error(&err);
-               }
-               return NULL;
-       }
-
-       otp_gproxy = proxy;
-
-       return proxy;
-}
-
-GDBusProxy *_bt_core_gdbus_get_otp_proxy(void)
-{
-       return (otp_gproxy) ? otp_gproxy : _bt_core_gdbus_init_otp_proxy();
-}
-
-int _bt_core_stop_otp(void)
-{
-       GVariant *variant = NULL;
-       unsigned char enabled;
-       GError *err = NULL;
-       BT_DBG(" ");
-
-       otp_gproxy = _bt_core_gdbus_get_otp_proxy();
-       if (!otp_gproxy) {
-               BT_DBG("Couldn't get service proxy");
-               return -1;
-       }
-
-       variant = g_dbus_proxy_call_sync(otp_gproxy, "disable",
-                               NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err);
-       if (err) {
-               BT_ERR("Error : %s" , err->message);
-               g_clear_error(&err);
-       }
-       if (variant) {
-               g_variant_get(variant, "(y)", &enabled);
-               BT_ERR("OTP disabled status 0x%x", enabled);
-       }
-       return 0;
-}
-#endif
 void _bt_core_gdbus_deinit_proxys(void)
 {
        BT_DBG("");
@@ -287,13 +215,6 @@ void _bt_core_gdbus_deinit_proxys(void)
        }
 #endif
 
-#ifdef TIZEN_FEATURE_BT_OTP
-       if (otp_gproxy) {
-               g_object_unref(otp_gproxy);
-               otp_gproxy = NULL;
-       }
-#endif
-
        if (service_gconn) {
                g_object_unref(service_gconn);
                service_gconn = NULL;
@@ -317,49 +238,35 @@ int _bt_core_service_request(int service_type, int service_function,
        GError *error = NULL;
        GArray *in_param5 = NULL;
 
-       int retry = 5;
-
        proxy = _bt_core_gdbus_get_service_proxy();
        if (!proxy)
                return BLUETOOTH_ERROR_INTERNAL;
        in_param5 = g_array_new(TRUE, TRUE, sizeof(gchar));
 
-       while (--retry >= 0) {
-               param1 = g_variant_new_from_data((const GVariantType *)"ay",
-                                       in_param1->data, in_param1->len,
-                                       TRUE, NULL, NULL);
-               param2 = g_variant_new_from_data((const GVariantType *)"ay",
-                                       in_param2->data, in_param2->len,
-                                       TRUE, NULL, NULL);
-               param3 = g_variant_new_from_data((const GVariantType *)"ay",
-                                       in_param3->data, in_param3->len,
-                                       TRUE, NULL, NULL);
-               param4 = g_variant_new_from_data((const GVariantType *)"ay",
-                                       in_param4->data, in_param4->len,
-                                       TRUE, NULL, NULL);
-               param5 = g_variant_new_from_data((const GVariantType *)"ay",
-                                       in_param5->data, in_param5->len,
-                                       TRUE, NULL, NULL);
-
-               ret = g_dbus_proxy_call_sync(proxy, "service_request",
-                                       g_variant_new("(iii@ay@ay@ay@ay@ay)",
-                                               service_type, service_function,
-                                               BT_SYNC_REQ, param1,
-                                               param2, param3,
-                                               param4, param5),
-                                       G_DBUS_CALL_FLAGS_NONE, 2000,
-                                       NULL, &error);
-               if (ret == NULL && error != NULL) {
-                       if (error->code == G_IO_ERROR_TIMED_OUT) {
-                               BT_ERR("D-Bus Timed out.");
-                               g_clear_error(&error);
-                               continue;
-                       }
-               }
-
-               break;
-       }
-
+       param1 = g_variant_new_from_data((const GVariantType *)"ay",
+                               in_param1->data, in_param1->len,
+                               TRUE, NULL, NULL);
+       param2 = g_variant_new_from_data((const GVariantType *)"ay",
+                               in_param2->data, in_param2->len,
+                               TRUE, NULL, NULL);
+       param3 = g_variant_new_from_data((const GVariantType *)"ay",
+                               in_param3->data, in_param3->len,
+                               TRUE, NULL, NULL);
+       param4 = g_variant_new_from_data((const GVariantType *)"ay",
+                               in_param4->data, in_param4->len,
+                               TRUE, NULL, NULL);
+       param5 = g_variant_new_from_data((const GVariantType *)"ay",
+                               in_param5->data, in_param5->len,
+                               TRUE, NULL, NULL);
+
+       ret = g_dbus_proxy_call_sync(proxy, "service_request",
+                               g_variant_new("(iii@ay@ay@ay@ay@ay)",
+                                       service_type, service_function,
+                                       BT_SYNC_REQ, param1,
+                                       param2, param3,
+                                       param4, param5),
+                               G_DBUS_CALL_FLAGS_NONE, 10000,
+                               NULL, &error);
        g_array_free(in_param5, TRUE);
 
        if (ret == NULL) {
@@ -465,8 +372,14 @@ static void __bt_core_dbus_method(GDBusConnection *connection,
 
                g_variant_get(parameters, "(&s&s)", &type, &arg);
                ret = _bt_core_factory_test_mode(type, arg);
-               g_dbus_method_invocation_return_value(invocation,
+               factory_test_mode = TRUE;
+
+               if (ret == TRUE)
+                       g_dbus_method_invocation_return_value(invocation,
                                g_variant_new("(i)", ret));
+               else
+                       _bt_core_terminate();
+
                 return;
        } else {
                ret = FALSE;
@@ -527,8 +440,6 @@ static void __handle_name_owner_changed(const char *name)
 {
        gboolean flight_mode_status;
 
-       BT_DBG("");
-
        flight_mode_status = _bt_core_is_flight_mode_enabled();
 
        if (flight_mode_status == FALSE && _bt_is_flightmode_request() == TRUE) {
@@ -538,8 +449,8 @@ static void __handle_name_owner_changed(const char *name)
 
        if ((g_strcmp0(name, "org.bluez") == 0) ||
                (g_strcmp0(name, "org.projectx.bt") == 0)) {
-               BT_DBG("%s is terminated", name);
-               if (_bt_check_terminating_condition() == TRUE) {
+               BT_INFO("%s is terminated", name);
+               if (_bt_check_terminating_condition() == TRUE && factory_test_mode == FALSE) {
                        _bt_disable_adapter();
                        _bt_disable_adapter_le();
                        _bt_core_terminate();
@@ -640,7 +551,7 @@ gboolean _bt_core_register_dbus(void)
                                NULL, "org.freedesktop.DBus.ObjectManager",
                                "InterfacesAdded", NULL, NULL,
                                0, __bt_core_event_filter, NULL, NULL);
-       sig_id2 = g_dbus_connection_signal_subscribe(conn,
+       sig_id3 = g_dbus_connection_signal_subscribe(conn,
                                NULL, "org.freedesktop.DBus.ObjectManager",
                                "InterfacesRemoved", NULL,
                                NULL, 0, __bt_core_event_filter, NULL, NULL);