Handle the privilege permission error for agent methods 55/142955/3
authorDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 8 Aug 2017 04:44:22 +0000 (13:44 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 8 Aug 2017 05:58:48 +0000 (14:58 +0900)
Change-Id: I267ed55df361f145bf0d7e4e6d2bf9dcbcf7defa
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-api/bt-audio.c
bt-api/bt-common.c
bt-api/bt-telephony.c
bt-api/include/bt-common.h

index 949f9774b1a7c94319291f862e8eae19ca7198b4..dd7eef7c5718230899bba4f4020f98bb0f822f47 100644 (file)
@@ -698,12 +698,7 @@ BT_EXPORT_API int bluetooth_hf_answer_call()
                if (err) {
                        BT_ERR("Error = %s", err->message);
                        g_dbus_error_strip_remote_error(err);
-                       if (strcmp(err->message, "Operation not supported") == 0)
-                               ret = BLUETOOTH_ERROR_NOT_IN_OPERATION;
-                       else if (strcmp(err->message, "Operation not allowed") == 0)
-                               ret = BLUETOOTH_ERROR_PERMISSION_DEINED;
-                       else
-                               ret = BLUETOOTH_ERROR_INTERNAL;
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
                return ret;
@@ -718,6 +713,7 @@ BT_EXPORT_API int bluetooth_hf_terminate_call()
 {
        GVariant *reply = NULL;
        GError *err = NULL;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -727,9 +723,11 @@ BT_EXPORT_API int bluetooth_hf_terminate_call()
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
@@ -756,12 +754,7 @@ BT_EXPORT_API int bluetooth_hf_initiate_call(char *number)
                if (err) {
                        BT_ERR("Error = %s", err->message);
                        g_dbus_error_strip_remote_error(err);
-                       if (strcmp(err->message, "NotConnected") == 0)
-                               ret = BLUETOOTH_ERROR_NOT_CONNECTED;
-                       else if (strcmp(err->message, "Operation not allowed") == 0)
-                               ret = BLUETOOTH_ERROR_IN_PROGRESS;
-                       else
-                               ret = BLUETOOTH_ERROR_INTERNAL;
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
                return ret;
@@ -776,6 +769,7 @@ BT_EXPORT_API int bluetooth_hf_voice_recognition(unsigned int status)
        GVariant *reply = NULL;
        GError *err = NULL;
        GVariant *param = NULL;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -786,9 +780,11 @@ BT_EXPORT_API int bluetooth_hf_voice_recognition(unsigned int status)
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
@@ -799,6 +795,7 @@ BT_EXPORT_API int bluetooth_hf_audio_disconnect(void)
 {
        GVariant *reply = NULL;
        GError *err = NULL;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -808,9 +805,11 @@ BT_EXPORT_API int bluetooth_hf_audio_disconnect(void)
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
@@ -822,6 +821,7 @@ BT_EXPORT_API int bluetooth_hf_set_speaker_gain(unsigned int speaker_gain)
        GVariant *reply = NULL;
        GError *err = NULL;
        GVariant *param = NULL;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -832,9 +832,11 @@ BT_EXPORT_API int bluetooth_hf_set_speaker_gain(unsigned int speaker_gain)
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
@@ -846,6 +848,7 @@ BT_EXPORT_API int bluetooth_hf_send_dtmf(char *dtmf)
        GVariant *reply = NULL;
        GError *err = NULL;
        GVariant *param = NULL;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -856,9 +859,11 @@ BT_EXPORT_API int bluetooth_hf_send_dtmf(char *dtmf)
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
@@ -872,6 +877,7 @@ BT_EXPORT_API int bluetooth_hf_send_xsat_cmd(int app_id, char *xsat_cmd)
        GVariant *param = NULL;
        char buffer[200] = {0,};
        char *ptr = buffer;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -889,9 +895,11 @@ BT_EXPORT_API int bluetooth_hf_send_xsat_cmd(int app_id, char *xsat_cmd)
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
@@ -902,6 +910,7 @@ BT_EXPORT_API int bluetooth_hf_release_and_accept(void)
 {
        GVariant *reply = NULL;
        GError *err = NULL;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -911,9 +920,11 @@ BT_EXPORT_API int bluetooth_hf_release_and_accept(void)
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
@@ -924,6 +935,7 @@ BT_EXPORT_API int bluetooth_hf_swap_call(void)
 {
        GVariant *reply = NULL;
        GError *err = NULL;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -933,9 +945,11 @@ BT_EXPORT_API int bluetooth_hf_swap_call(void)
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
@@ -946,6 +960,7 @@ BT_EXPORT_API int bluetooth_hf_release_all_call(void)
 {
        GVariant *reply = NULL;
        GError *err = NULL;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -955,9 +970,11 @@ BT_EXPORT_API int bluetooth_hf_release_all_call(void)
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
@@ -968,6 +985,7 @@ BT_EXPORT_API int bluetooth_hf_join_call(void)
 {
        GVariant *reply = NULL;
        GError *err = NULL;
+       int ret = BLUETOOTH_ERROR_INTERNAL;
 
        BT_CHECK_ENABLED(return);
 
@@ -977,9 +995,11 @@ BT_EXPORT_API int bluetooth_hf_join_call(void)
                BT_ERR("Error returned in method call\n");
                if (err) {
                        BT_ERR("Error = %s", err->message);
+                       g_dbus_error_strip_remote_error(err);
+                       ret = _bt_get_error_value_from_message(err->message);
                        g_clear_error(&err);
                }
-               return BLUETOOTH_ERROR_INTERNAL;
+               return ret;
        }
 
        g_variant_unref(reply);
index a846c80a5b3d6882a9cef4905cb7e89c98353c5b..76448b122e22559d91b705404d21118ad71414e8 100644 (file)
@@ -2095,6 +2095,25 @@ int _bt_get_uuid_specification_name(const char *uuid, char **name)
        return BLUETOOTH_ERROR_NONE;
 }
 
+int _bt_get_error_value_from_message(const char *error_message)
+{
+       if (error_message == NULL) {
+               BT_ERR("Error message NULL");
+               return BLUETOOTH_ERROR_INTERNAL;
+       }
+
+       BT_ERR("Error message = %s", error_message);
+
+       if (g_strrstr(error_message, BT_ERROR_OPERATION_NOT_SUPPORTED))
+               return BLUETOOTH_ERROR_NOT_IN_OPERATION;
+       else if (g_strrstr(error_message, BT_ERROR_OPERATION_NOT_ALLOWED))
+               return BLUETOOTH_ERROR_PERMISSION_DEINED;
+       else if (g_strrstr(error_message, BT_ERROR_ACCESS_DENIED))
+               return BLUETOOTH_ERROR_PERMISSION_DEINED;
+       else
+               return BLUETOOTH_ERROR_INTERNAL;
+}
+
 BT_EXPORT_API int bluetooth_is_supported(void)
 {
        int is_supported = 0;
index f071e10990f1835c665336e25bab0c9dce5bff18..d13c6b7ce8bc9df2dea475d46d8f2049c9aed005 100644 (file)
@@ -1613,6 +1613,7 @@ BT_EXPORT_API int bluetooth_telephony_send_vendor_cmd(const char *cmd)
 {
        GError *error = NULL;
        GVariant *reply, *parameters;
+       int ret = BLUETOOTH_TELEPHONY_ERROR_NONE;
 
        FN_START;
 
@@ -1635,8 +1636,15 @@ BT_EXPORT_API int bluetooth_telephony_send_vendor_cmd(const char *cmd)
 
        g_variant_unref(reply);
 
+       if (error) {
+               g_dbus_error_strip_remote_error(error);
+               ret = __bt_telephony_get_error(error->message);
+               BT_ERR("Error here %d\n", ret);
+               g_error_free(error);
+       }
+
        FN_END;
-       return BLUETOOTH_TELEPHONY_ERROR_NONE;
+       return ret;
 }
 
 BT_EXPORT_API int bluetooth_telephony_start_voice_recognition(void)
@@ -1870,12 +1878,12 @@ BT_EXPORT_API int bluetooth_telephony_call_remote_ringing(unsigned int call_id)
        /*Make sure SCO is already connected */
        ret = __bluetooth_telephony_send_call_status(
                                CSD_CALL_STATUS_MO_ALERTING, call_id, NULL);
-       if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
+
+       if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
                BT_ERR("send call status Failed = [%d]", ret);
-               return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
-       }
+
        FN_END;
-       return BLUETOOTH_TELEPHONY_ERROR_NONE;
+       return ret;
 }
 
 BT_EXPORT_API int bluetooth_telephony_call_answered(unsigned int call_id,
@@ -1899,10 +1907,8 @@ BT_EXPORT_API int bluetooth_telephony_call_answered(unsigned int call_id,
        if (bt_audio) {
                if (!bluetooth_telephony_is_sco_connected()) {
                        ret = bluetooth_telephony_audio_open();
-                       if (ret != 0) {
+                       if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
                                BT_ERR("Audio connection call Failed[%d]", ret);
-                               return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
-                       }
                }
        }
 
@@ -1933,10 +1939,8 @@ BT_EXPORT_API int bluetooth_telephony_call_end(unsigned int call_id)
 
        ret = __bluetooth_telephony_send_call_status(CSD_CALL_STATUS_MT_RELEASE,
                                                                call_id, NULL);
-       if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE) {
+       if (ret != BLUETOOTH_TELEPHONY_ERROR_NONE)
                BT_ERR("send call status Failed = [%d]", ret);
-               return ret;
-       }
 
        FN_END;
        return ret;
@@ -2086,7 +2090,7 @@ BT_EXPORT_API int bluetooth_telephony_indicate_outgoing_call(
        GVariant *param;
        GError *err = NULL;
        const char *path = telephony_info.call_path;
-       int ret;
+       int ret = BLUETOOTH_TELEPHONY_ERROR_NONE;
 
        FN_START;
 
@@ -2120,15 +2124,13 @@ BT_EXPORT_API int bluetooth_telephony_indicate_outgoing_call(
        if (bt_audio) {
                if (!bluetooth_telephony_is_sco_connected()) {
                        ret = bluetooth_telephony_audio_open();
-                       if (ret != 0) {
+                       if (ret != 0)
                                BT_ERR(" Audio connection Failed = %d", ret);
-                               return BLUETOOTH_TELEPHONY_ERROR_INTERNAL;
-                       }
                }
        }
 
        FN_END;
-       return BLUETOOTH_TELEPHONY_ERROR_NONE;
+       return ret;
 }
 
 BT_EXPORT_API int bluetooth_telephony_indicate_incoming_call(
index c4cc514fcd4d3adf80586428a49a2879d608dbd4..9bc365e7b47ac6ab30d1e1a889bcc0913a081b79 100644 (file)
@@ -209,6 +209,22 @@ extern "C" {
 
 #define BT_AGENT_INTERFACE "org.bluez.Agent1"
 
+#define BT_ERROR_INTERNAL "InternalError"
+#define BT_ERROR_NOT_AVAILABLE "NotAvailable"
+#define BT_ERROR_NOT_CONNECTED "NotConnected"
+#define BT_ERROR_NOT_CONNECTION_FAILED "ConnectionFailed"
+#define BT_ERROR_BUSY "InProgress"
+#define BT_ERROR_INVALID_PARAM "InvalidArguments"
+#define BT_ERROR_ALREADY_EXIST "AlreadyExists"
+#define BT_ERROR_ALREADY_CONNECTED "Already Connected"
+#define BT_ERROR_NO_MEMORY "No memory"
+#define BT_ERROR_NO_DATA "No data"
+#define BT_ERROR_I_O_ERROR "I/O error"
+#define BT_ERROR_OPERATION_NOT_AVAILABLE "Operation currently not available"
+#define BT_ERROR_OPERATION_NOT_ALLOWED "Operation not allowed"
+#define BT_ERROR_OPERATION_NOT_SUPPORTED "Operation not supported"
+#define BT_ERROR_INVALID_FILE_DESCRIPTOR "Invalid File Descriptor"
+#define BT_ERROR_ACCESS_DENIED "Rejected send message"
 
 #define BT_MAX_USER_INFO 5
 #define RFKILL_EVENT_SIZE 8
@@ -383,6 +399,7 @@ gboolean _check_uuid_path(char *path, char *uuid);
 
 void _bluetooth_hid_free_hid_info(void);
 
+int _bt_get_error_value_from_message(const char *error_message);
 
 #ifdef __cplusplus
 }