OSDN Git Service

DO NOT MERGE: Check number of attributes before writing to a buffer
[android-x86/system-bt.git] / btif / src / btif_rc.c
index acb56ca..28a2499 100644 (file)
 #include <hardware/bluetooth.h>
 #include <hardware/bt_rc.h>
 
-/**
- * TODO(eisenbach): cutils/properties.h is only being used to pull-in runtime
- * settings on Android. Remove this conditional include once we have a generic
- * way to obtain system properties.
- */
-#if !defined(OS_GENERIC)
-#include <cutils/properties.h>
-#endif  /* !defined(OS_GENERIC) */
-
 #include "avrc_defs.h"
 #include "bta_api.h"
 #include "bta_av_api.h"
 #include "bt_common.h"
 #include "device/include/interop.h"
 #include "uinput.h"
+#include "bdaddr.h"
 #include "osi/include/list.h"
+#include "osi/include/properties.h"
 #include "btu.h"
+#include "log/log.h"
 #define RC_INVALID_TRACK_ID (0xFFFFFFFFFFFFFFFFULL)
+
 /*****************************************************************************
 **  Constants & Macros
 ******************************************************************************/
@@ -285,6 +280,7 @@ static void btif_rc_upstreams_rsp_evt(UINT16 event, tAVRC_RESPONSE *pavrc_resp,
 #endif
 static void rc_start_play_status_timer(void);
 static bool absolute_volume_disabled(void);
+static char const* key_id_to_str(uint16_t id);
 
 /*****************************************************************************
 **  Static variables
@@ -322,7 +318,9 @@ int send_event (int fd, uint16_t type, uint16_t code, int32_t value)
     event.code  = code;
     event.value = value;
 
-    return write(fd, &event, sizeof(event));
+    ssize_t ret;
+    OSI_NO_INTR(ret = write(fd, &event, sizeof(event)));
+    return (int)ret;
 }
 
 void send_key (int fd, uint16_t key, int pressed)
@@ -335,7 +333,7 @@ void send_key (int fd, uint16_t key, int pressed)
         return;
     }
 
-    BTIF_TRACE_DEBUG("AVRCP: Send key %d (%d) fd=%d", key, pressed, fd);
+    LOG_INFO(LOG_TAG, "AVRCP: Send key %s (%d) fd=%d", key_id_to_str(key), pressed, fd);
     send_event(fd, EV_KEY, key, pressed);
     send_event(fd, EV_SYN, SYN_REPORT, 0);
 }
@@ -379,7 +377,9 @@ int uinput_create(char *name)
     dev.id.product = 0x0000;
     dev.id.version = 0x0000;
 
-    if (write(fd, &dev, sizeof(dev)) < 0) {
+    ssize_t ret;
+    OSI_NO_INTR(ret = write(fd, &dev, sizeof(dev)));
+    if (ret < 0) {
         BTIF_TRACE_ERROR("%s Unable to write device information", __FUNCTION__);
         close(fd);
         return -1;
@@ -459,7 +459,9 @@ void handle_rc_ctrl_features(BD_ADDR bd_addr)
              * update.
              */
             btif_rc_cb.rc_features_processed = TRUE;
-            getcapabilities_cmd (AVRC_CAP_COMPANY_ID);
+
+            if (btif_av_is_sink_enabled())
+                getcapabilities_cmd (AVRC_CAP_COMPANY_ID);
         }
         BTIF_TRACE_DEBUG("%s Update rc features to CTRL %d", __FUNCTION__, rc_features);
         HAL_CBACK(bt_rc_ctrl_callbacks, getrcfeatures_cb, &rc_addr, rc_features);
@@ -473,10 +475,18 @@ void handle_rc_features(BD_ADDR bd_addr)
     {
     btrc_remote_features_t rc_features = BTRC_FEAT_NONE;
     bt_bdaddr_t rc_addr;
+
     bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
+    bt_bdaddr_t avdtp_addr  = btif_av_get_addr();
 
-    if (interop_match(INTEROP_DISABLE_ABSOLUTE_VOLUME, &rc_addr)
-        || absolute_volume_disabled())
+    bdstr_t addr1, addr2;
+    BTIF_TRACE_DEBUG("%s: AVDTP Address: %s AVCTP address: %s", __func__,
+                     bdaddr_to_string(&avdtp_addr, addr1, sizeof(addr1)),
+                     bdaddr_to_string(&rc_addr, addr2, sizeof(addr2)));
+
+    if (interop_match_addr(INTEROP_DISABLE_ABSOLUTE_VOLUME, &rc_addr)
+        || absolute_volume_disabled()
+        || bdcmp(avdtp_addr.address, rc_addr.address))
         btif_rc_cb.rc_features &= ~BTA_AV_FEAT_ADV_CTRL;
 
     if (btif_rc_cb.rc_features & BTA_AV_FEAT_BROWSE)
@@ -735,22 +745,6 @@ void handle_rc_passthrough_cmd ( tBTA_AV_REMOTE_CMD *p_remote_cmd)
         pressed = 1;
     }
 
-    /* If this is Play/Pause command (press or release)  before processing, check the following
-     * a voice call has ended recently
-     * the remote device is not of type headset
-     * If the above conditions meet, drop the Play/Pause command
-     * This fix is to interop with certain carkits which sends an automatic  PLAY  or PAUSE
-     * commands right after call ends
-     */
-    if ((p_remote_cmd->rc_id == BTA_AV_RC_PLAY || p_remote_cmd->rc_id == BTA_AV_RC_PAUSE)&&
-       (btif_hf_call_terminated_recently() == TRUE) &&
-       (check_cod( (const bt_bdaddr_t*)&(btif_rc_cb.rc_addr), COD_AV_HEADSETS) != TRUE))
-    {
-        BTIF_TRACE_DEBUG("%s:Dropping the play/Pause command received right after call end cmd:%d",
-                           __FUNCTION__,p_remote_cmd->rc_id);
-        return;
-    }
-
     if (p_remote_cmd->rc_id == BTA_AV_RC_FAST_FOR || p_remote_cmd->rc_id == BTA_AV_RC_REWIND) {
         HAL_CBACK(bt_rc_callbacks, passthrough_cmd_cb, p_remote_cmd->rc_id, pressed);
         return;
@@ -2100,8 +2094,8 @@ static void btif_rc_status_cmd_timeout_handler(UNUSED_ATTR uint16_t event,
         break;
 
     case AVRC_PDU_GET_PLAY_STATUS:
-        avrc_response.get_caps.status = BTIF_RC_STS_TIMEOUT;
-        handle_get_capability_response(&meta_msg, &avrc_response.get_caps);
+        avrc_response.get_play_status.status = BTIF_RC_STS_TIMEOUT;
+        handle_get_playstatus_response(&meta_msg, &avrc_response.get_play_status);
         break;
     }
     release_transaction(p_context->rc_status_cmd.label);
@@ -2771,6 +2765,12 @@ static void handle_app_cur_val_response (tBTA_AV_META_MSG *pmeta_msg, tAVRC_GET_
     bdcpy(rc_addr.address, btif_rc_cb.rc_addr);
 
     app_settings.num_attr = p_rsp->num_val;
+
+    if (app_settings.num_attr > BTRC_MAX_APP_SETTINGS) {
+        android_errorWriteLog(0x534e4554, "73824150");
+        app_settings.num_attr = BTRC_MAX_APP_SETTINGS;
+    }
+
     for (xx = 0; xx < app_settings.num_attr; xx++)
     {
         app_settings.attr_ids[xx] = p_rsp->p_vals[xx].attr_id;
@@ -4246,20 +4246,23 @@ static void sleep_ms(period_ms_t timeout_ms) {
     delay.tv_sec = timeout_ms / 1000;
     delay.tv_nsec = 1000 * 1000 * (timeout_ms % 1000);
 
-    int err;
-    do {
-        err = nanosleep(&delay, &delay);
-    } while (err == -1 && errno == EINTR);
+    OSI_NO_INTR(nanosleep(&delay, &delay));
 }
 
 static bool absolute_volume_disabled() {
-#if !defined(OS_GENERIC)
     char volume_disabled[PROPERTY_VALUE_MAX] = {0};
-    property_get("persist.bluetooth.disableabsvol", volume_disabled, "false");
+    osi_property_get("persist.bluetooth.disableabsvol", volume_disabled, "false");
     if (strncmp(volume_disabled, "true", 4) == 0) {
         BTIF_TRACE_WARNING("%s: Absolute volume disabled by property", __func__);
         return true;
     }
-#endif  /* !defined(OS_GENERIC) */
     return false;
 }
+
+static char const* key_id_to_str(uint16_t id) {
+    for (int i = 0; key_map[i].name != NULL; i++) {
+        if (id == key_map[i].mapped_id)
+            return key_map[i].name;
+    }
+    return "UNKNOWN KEY";
+}