Snap for 11273583 from 504453903e0be36bf8d5e0db0d3a4178aa2d26d0 to mainline-wifi-release

Change-Id: I22de87e091daabf9a116bfa5cdf4a922abf52a9a
diff --git a/android/app/res/values-hi/strings.xml b/android/app/res/values-hi/strings.xml
index 03c8c3c..ddc21ef 100644
--- a/android/app/res/values-hi/strings.xml
+++ b/android/app/res/values-hi/strings.xml
@@ -77,7 +77,7 @@
     <string name="unknown_file_desc" msgid="9185609398960437760">"इस प्रकार की फ़ाइल प्रबंधित करने के लिए कोई ऐप्लिकेशन नहीं है. \n"</string>
     <string name="not_exist_file" msgid="5097565588949092486">"कोई फ़ाइल नहीं"</string>
     <string name="not_exist_file_desc" msgid="250802392160941265">"फ़ाइल मौजूद नहीं है. \n"</string>
-    <string name="enabling_progress_title" msgid="5262637688863903594">"कृपया प्रतीक्षा करें..."</string>
+    <string name="enabling_progress_title" msgid="5262637688863903594">"कृपया इंतज़ार करें..."</string>
     <string name="enabling_progress_content" msgid="685427201206684584">"ब्लूटूथ चालू कर रहा है…"</string>
     <string name="bt_toast_1" msgid="8791691594887576215">"फ़ाइल मिलेगी. सूचना पैनल में प्रगति देखें."</string>
     <string name="bt_toast_2" msgid="2041575937953174042">"फ़ाइल पाई नहीं जा सकती."</string>
diff --git a/system/stack/gatt/att_protocol.cc b/system/stack/gatt/att_protocol.cc
index 3b68753..1a9612f 100644
--- a/system/stack/gatt/att_protocol.cc
+++ b/system/stack/gatt/att_protocol.cc
@@ -287,79 +287,46 @@
 static BT_HDR* attp_build_value_cmd(uint16_t payload_size, uint8_t op_code,
                                     uint16_t handle, uint16_t offset,
                                     uint16_t len, uint8_t* p_data) {
-  uint8_t *p, *pp, *p_pair_len;
-  size_t pair_len;
-  size_t size_now = 1;
-
-  #define CHECK_SIZE() do {                      \
-    if (size_now > payload_size) {               \
-      LOG(ERROR) << "payload size too small";    \
-      osi_free(p_buf);                           \
-      return nullptr;                            \
-    }                                            \
-  } while (false)
-
+  uint8_t *p, *pp, pair_len, *p_pair_len;
   BT_HDR* p_buf =
       (BT_HDR*)osi_malloc(sizeof(BT_HDR) + payload_size + L2CAP_MIN_OFFSET);
 
   p = pp = (uint8_t*)(p_buf + 1) + L2CAP_MIN_OFFSET;
-
-  CHECK_SIZE();
   UINT8_TO_STREAM(p, op_code);
   p_buf->offset = L2CAP_MIN_OFFSET;
+  p_buf->len = 1;
 
   if (op_code == GATT_RSP_READ_BY_TYPE) {
     p_pair_len = p;
     pair_len = len + 2;
-    size_now += 1;
-    CHECK_SIZE();
-    // this field will be backfilled in the end of this function
+    UINT8_TO_STREAM(p, pair_len);
+    p_buf->len += 1;
   }
-
   if (op_code != GATT_RSP_READ_BLOB && op_code != GATT_RSP_READ) {
-    size_now += 2;
-    CHECK_SIZE();
     UINT16_TO_STREAM(p, handle);
+    p_buf->len += 2;
   }
 
   if (op_code == GATT_REQ_PREPARE_WRITE || op_code == GATT_RSP_PREPARE_WRITE) {
-    size_now += 2;
-    CHECK_SIZE();
     UINT16_TO_STREAM(p, offset);
+    p_buf->len += 2;
   }
 
-  if (len > 0 && p_data != NULL && payload_size > size_now) {
+  if (len > 0 && p_data != NULL) {
     /* ensure data not exceed MTU size */
-    if (payload_size - size_now < len) {
-      len = payload_size - size_now;
+    if (payload_size - p_buf->len < len) {
+      len = payload_size - p_buf->len;
       /* update handle value pair length */
-      if (op_code == GATT_RSP_READ_BY_TYPE) {
-        pair_len = (len + 2);
-      }
+      if (op_code == GATT_RSP_READ_BY_TYPE) *p_pair_len = (len + 2);
 
       LOG(WARNING) << StringPrintf(
           "attribute value too long, to be truncated to %d", len);
     }
 
-    size_now += len;
-    CHECK_SIZE();
     ARRAY_TO_STREAM(p, p_data, len);
+    p_buf->len += len;
   }
 
-  // backfill pair len field
-  if (op_code == GATT_RSP_READ_BY_TYPE) {
-    if (pair_len > UINT8_MAX) {
-      LOG(ERROR) << "pair_len greater than" << UINT8_MAX;
-      osi_free(p_buf);
-      return nullptr;
-    }
-
-    *p_pair_len = (uint8_t) pair_len;
-  }
-
-  #undef CHECK_SIZE
-
-  p_buf->len = (uint16_t) size_now;
   return p_buf;
 }