msm8974-common: libril: Encode MCC with 3 digit in CellIdentity
Bug: 145809537 Test: ril::util::mcc::test Change-Id: Ie0b9d0a56530cc7a2146e9955d392867634d2b8b
This commit is contained in:
parent
4f09b93962
commit
725f9e8f33
2 changed files with 81 additions and 8 deletions
71
ril/include/telephony/ril_mcc.h
Normal file
71
ril/include/telephony/ril_mcc.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef RIL_MCC_H
|
||||
#define RIL_MCC_H
|
||||
|
||||
#include <climits>
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
||||
namespace ril {
|
||||
namespace util {
|
||||
namespace mcc {
|
||||
|
||||
/**
|
||||
* Decode an integer mcc and encode as 3 digit string
|
||||
*
|
||||
* @param an integer mcc, its range should be in 0 to 999.
|
||||
*
|
||||
* @return string representation of an encoded MCC or an empty string
|
||||
* if the MCC is not a valid MCC value.
|
||||
*/
|
||||
static inline std::string decode(int mcc) {
|
||||
char mccStr[4] = {0};
|
||||
if (mcc > 999 || mcc < 0) return "";
|
||||
|
||||
snprintf(mccStr, sizeof(mccStr), "%03d", mcc);
|
||||
return mccStr;
|
||||
}
|
||||
|
||||
// echo -e "#include \"hardware/ril/include/telephony/ril_mcc.h\"\nint main()"\
|
||||
// "{ return ril::util::mcc::test(); }" > ril_test.cpp \
|
||||
// && g++ -o /tmp/ril_test -DTEST_RIL_MCC ril_test.cpp; \
|
||||
// rm ril_test.cpp; /tmp/ril_test && [ $? ] && echo "passed"
|
||||
#ifdef TEST_RIL_MCC
|
||||
static int test() {
|
||||
const struct mcc_ints { const int in; const char * out; } legacy_mccs[] = {
|
||||
{INT_MAX, ""},
|
||||
{1, "001"},
|
||||
{11, "011"},
|
||||
{111, "111"},
|
||||
{0, "000"},
|
||||
{9999, ""},
|
||||
{-12, ""},
|
||||
};
|
||||
|
||||
for (int i=0; i < sizeof(legacy_mccs) / sizeof(struct mcc_ints); i++) {
|
||||
if (decode(legacy_mccs[i].in).compare(legacy_mccs[i].out)) return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif /* !defined(RIL_MCC_H) */
|
|
@ -28,6 +28,7 @@
|
|||
#include <hwbinder/ProcessState.h>
|
||||
#include <telephony/ril.h>
|
||||
#include <telephony/ril_mnc.h>
|
||||
#include <telephony/ril_mcc.h>
|
||||
#include <ril_service.h>
|
||||
#include <hidl/HidlTransportSupport.h>
|
||||
#include <utils/SystemClock.h>
|
||||
|
@ -3575,7 +3576,7 @@ void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 &
|
|||
case RIL_CELL_INFO_TYPE_GSM: {
|
||||
cellIdentity.cellIdentityGsm.resize(1);
|
||||
cellIdentity.cellIdentityGsm[0].mcc =
|
||||
std::to_string(rilCellIdentity.cellIdentityGsm.mcc);
|
||||
ril::util::mcc::decode(rilCellIdentity.cellIdentityGsm.mcc);
|
||||
cellIdentity.cellIdentityGsm[0].mnc =
|
||||
ril::util::mnc::decode(rilCellIdentity.cellIdentityGsm.mnc);
|
||||
|
||||
|
@ -3593,7 +3594,7 @@ void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 &
|
|||
case RIL_CELL_INFO_TYPE_WCDMA: {
|
||||
cellIdentity.cellIdentityWcdma.resize(1);
|
||||
cellIdentity.cellIdentityWcdma[0].mcc =
|
||||
std::to_string(rilCellIdentity.cellIdentityWcdma.mcc);
|
||||
ril::util::mcc::decode(rilCellIdentity.cellIdentityWcdma.mcc);
|
||||
cellIdentity.cellIdentityWcdma[0].mnc =
|
||||
ril::util::mnc::decode(rilCellIdentity.cellIdentityWcdma.mnc);
|
||||
|
||||
|
@ -3622,7 +3623,7 @@ void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 &
|
|||
case RIL_CELL_INFO_TYPE_LTE: {
|
||||
cellIdentity.cellIdentityLte.resize(1);
|
||||
cellIdentity.cellIdentityLte[0].mcc =
|
||||
std::to_string(rilCellIdentity.cellIdentityLte.mcc);
|
||||
ril::util::mcc::decode(rilCellIdentity.cellIdentityLte.mcc);
|
||||
cellIdentity.cellIdentityLte[0].mnc =
|
||||
ril::util::mnc::decode(rilCellIdentity.cellIdentityLte.mnc);
|
||||
|
||||
|
@ -3640,7 +3641,7 @@ void fillCellIdentityResponse(CellIdentity &cellIdentity, RIL_CellIdentity_v16 &
|
|||
case RIL_CELL_INFO_TYPE_TD_SCDMA: {
|
||||
cellIdentity.cellIdentityTdscdma.resize(1);
|
||||
cellIdentity.cellIdentityTdscdma[0].mcc =
|
||||
std::to_string(rilCellIdentity.cellIdentityTdscdma.mcc);
|
||||
ril::util::mcc::decode(rilCellIdentity.cellIdentityTdscdma.mcc);
|
||||
cellIdentity.cellIdentityTdscdma[0].mnc =
|
||||
ril::util::mnc::decode(rilCellIdentity.cellIdentityTdscdma.mnc);
|
||||
|
||||
|
@ -8095,7 +8096,7 @@ void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<Ce
|
|||
records[i].gsm.resize(1);
|
||||
CellInfoGsm *cellInfoGsm = &records[i].gsm[0];
|
||||
cellInfoGsm->cellIdentityGsm.mcc =
|
||||
std::to_string(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
|
||||
ril::util::mcc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mcc);
|
||||
cellInfoGsm->cellIdentityGsm.mnc =
|
||||
ril::util::mnc::decode(rillCellInfo->CellInfo.gsm.cellIdentityGsm.mnc);
|
||||
cellInfoGsm->cellIdentityGsm.lac =
|
||||
|
@ -8119,7 +8120,7 @@ void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<Ce
|
|||
records[i].wcdma.resize(1);
|
||||
CellInfoWcdma *cellInfoWcdma = &records[i].wcdma[0];
|
||||
cellInfoWcdma->cellIdentityWcdma.mcc =
|
||||
std::to_string(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
|
||||
ril::util::mcc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mcc);
|
||||
cellInfoWcdma->cellIdentityWcdma.mnc =
|
||||
ril::util::mnc::decode(rillCellInfo->CellInfo.wcdma.cellIdentityWcdma.mnc);
|
||||
cellInfoWcdma->cellIdentityWcdma.lac =
|
||||
|
@ -8167,7 +8168,7 @@ void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<Ce
|
|||
records[i].lte.resize(1);
|
||||
CellInfoLte *cellInfoLte = &records[i].lte[0];
|
||||
cellInfoLte->cellIdentityLte.mcc =
|
||||
std::to_string(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
|
||||
ril::util::mcc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mcc);
|
||||
cellInfoLte->cellIdentityLte.mnc =
|
||||
ril::util::mnc::decode(rillCellInfo->CellInfo.lte.cellIdentityLte.mnc);
|
||||
cellInfoLte->cellIdentityLte.ci =
|
||||
|
@ -8197,7 +8198,8 @@ void convertRilCellInfoListToHal(void *response, size_t responseLen, hidl_vec<Ce
|
|||
records[i].tdscdma.resize(1);
|
||||
CellInfoTdscdma *cellInfoTdscdma = &records[i].tdscdma[0];
|
||||
cellInfoTdscdma->cellIdentityTdscdma.mcc =
|
||||
std::to_string(rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
|
||||
ril::util::mcc::decode(
|
||||
rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mcc);
|
||||
cellInfoTdscdma->cellIdentityTdscdma.mnc =
|
||||
ril::util::mnc::decode(
|
||||
rillCellInfo->CellInfo.tdscdma.cellIdentityTdscdma.mnc);
|
||||
|
|
Loading…
Add table
Reference in a new issue