diff --git a/ril/libril/ril.cpp b/ril/libril/ril.cpp index a2d1e4e5..c4490260 100755 --- a/ril/libril/ril.cpp +++ b/ril/libril/ril.cpp @@ -5656,23 +5656,36 @@ void RIL_onUnsolicitedResponse(int unsolResponse, const void *data, unsolResponseIndex = unsolResponse - RIL_UNSOL_RESPONSE_BASE; pRI = s_unsolResponses; + pRI_elements = (int32_t)NUM_ELEMS(s_unsolResponses); /* Hack to include Samsung responses */ if (unsolResponse > RIL_VENDOR_COMMANDS_OFFSET + RIL_UNSOL_RESPONSE_BASE) { - unsolResponseIndex -= RIL_VENDOR_COMMANDS_OFFSET; pRI = s_unsolResponses_v; + pRI_elements = (int32_t)NUM_ELEMS(s_unsolResponses_v); + + /* + * Some of the vendor response codes cannot be found by calculating their index anymore, + * because they have an even higher offset and are not ordered in the array. + * Example: RIL_UNSOL_SNDMGR_WB_AMR_REPORT = 20017, but it's at index 33 in the vendor + * response array. + * Thus, look through all the vendor URIs (Unsol Response Info) and pick the correct index. + * This has a cost of O(N). + */ + int pRI_index; + for (pRI_index = 0; pRI_index < pRI_elements; pRI_index++) { + if (pRI[pRI_index].requestNumber == unsolResponse) { + unsolResponseIndex = pRI_index; + } + } RLOGD("SAMSUNG: unsolResponse=%d, unsolResponseIndex=%d", unsolResponse, unsolResponseIndex); } - pRI_elements = pRI == s_unsolResponses - ? (int32_t)NUM_ELEMS(s_unsolResponses) : (int32_t)NUM_ELEMS(s_unsolResponses_v); - if (unsolResponseIndex >= 0 && unsolResponseIndex < pRI_elements) { pRI = &pRI[unsolResponseIndex]; } else { - RLOGE("unsolResponseIndex out of bounds: %d, using %s response array", unsolResponseIndex, - pRI == s_unsolResponses ? "AOSP" : "Samsung"); + RLOGE("could not map unsolResponse=%d to %s response array (index=%d)", unsolResponse, + pRI == s_unsolResponses ? "AOSP" : "Samsung", unsolResponseIndex); } if (pRI == NULL || pRI->responseFunction == NULL) {