Loading src/java/com/android/internal/telephony/LocaleTracker.java +42 −6 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ public class LocaleTracker extends Handler { /** Event to trigger get cell info from the modem */ private static final int EVENT_GET_CELL_INFO = 1; /** Event to trigger update operator numeric */ private static final int EVENT_UPDATE_OPERATOR_NUMERIC = 2; // Todo: Read this from Settings. /** The minimum delay to get cell info from the modem */ private static final long CELL_INFO_MIN_DELAY_MS = 2 * SECOND_IN_MILLIS; Loading Loading @@ -115,6 +118,9 @@ public class LocaleTracker extends Handler { updateLocale(); } break; case EVENT_UPDATE_OPERATOR_NUMERIC: updateOperatorNumericSync((String) msg.obj); break; default: throw new IllegalStateException("Unexpected message arrives. msg = " + msg.what); } Loading Loading @@ -201,11 +207,14 @@ public class LocaleTracker extends Handler { } /** * Update MCC/MNC from network service state. * Update MCC/MNC from network service state synchronously. Note if this is called from phone * process's main thread and if the update operation requires getting cell info from the modem, * the cached cell info will be used to determine the locale. If the cached cell info is not * acceptable, use {@link #updateOperatorNumericAsync(String)} instead. * * @param operatorNumeric MCC/MNC of the operator */ public synchronized void updateOperatorNumeric(String operatorNumeric) { public synchronized void updateOperatorNumericSync(String operatorNumeric) { // Check if the operator numeric changes. String msg = "updateOperatorNumeric. mcc/mnc=" + operatorNumeric; if (DBG) log(msg); Loading @@ -223,11 +232,28 @@ public class LocaleTracker extends Handler { log("Operator numeric unavailable. Get latest cell info from the modem."); } getCellInfo(); } else { // If operator numeric is available, that means we camp on network. So reset the // fail cell info count. mFailCellInfoCount = 0; } updateLocale(); } } /** * Update MCC/MNC from network service state asynchronously. The update operation will run * in locale tracker's handler's thread, which can get cell info synchronously from service * state tracker. Note that the country code will not be available immediately after calling * this method. * * @param operatorNumeric MCC/MNC of the operator */ public void updateOperatorNumericAsync(String operatorNumeric) { if (DBG) log("updateOperatorNumericAsync. mcc/mnc=" + operatorNumeric); sendMessage(obtainMessage(EVENT_UPDATE_OPERATOR_NUMERIC, operatorNumeric)); } /** * Get the delay time to get cell info from modem. The delay time grows exponentially to prevent * battery draining. Loading @@ -250,10 +276,18 @@ public class LocaleTracker extends Handler { * Get cell info from the modem. */ private void getCellInfo() { String msg; if (!mPhone.getServiceStateTracker().getDesiredPowerState()) { msg = "Radio is off. No need to get cell info."; if (DBG) log(msg); mLocalLog.log(msg); return; } // Get all cell info. Passing null to use default worksource, which indicates the original // request is from telephony internally. mCellInfo = mPhone.getAllCellInfo(null); String msg = "getCellInfo: cell info=" + mCellInfo; msg = "getCellInfo: cell info=" + mCellInfo; if (DBG) log(msg); mLocalLog.log(msg); if (mCellInfo == null || mCellInfo.size() == 0) { Loading @@ -275,7 +309,7 @@ public class LocaleTracker extends Handler { private void updateLocale() { // If MCC is available from network service state, use it first. String mcc = null; String countryIso = null; String countryIso = ""; if (!TextUtils.isEmpty(mOperatorNumeric)) { try { mcc = mOperatorNumeric.substring(0, 3); Loading @@ -297,7 +331,9 @@ public class LocaleTracker extends Handler { log(msg); mLocalLog.log(msg); if (!Objects.equals(countryIso, mCurrentCountryIso)) { log("updateLocale: Change the current country to " + countryIso); msg = "updateLocale: Change the current country to " + countryIso; log(msg); mLocalLog.log(msg); mCurrentCountryIso = countryIso; TelephonyManager.setTelephonyProperty(mPhone.getPhoneId(), Loading src/java/com/android/internal/telephony/ServiceStateTracker.java +4 −3 Original line number Diff line number Diff line Loading @@ -2855,8 +2855,9 @@ public class ServiceStateTracker extends Handler { if (isInvalidOperatorNumeric(operatorNumeric)) { if (DBG) log("operatorNumeric " + operatorNumeric + " is invalid"); // Passing empty string is important for the first update. The initial value of // operator numeric in locale tracker is null. mLocaleTracker.updateOperatorNumeric(""); // operator numeric in locale tracker is null. The async update will allow getting // cell info from the modem instead of using the cached one. mLocaleTracker.updateOperatorNumericAsync(""); mNitzState.handleNetworkUnavailable(); } else if (mSS.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN) { // If the device is on IWLAN, modems manufacture a ServiceState with the MCC/MNC of Loading @@ -2868,7 +2869,7 @@ public class ServiceStateTracker extends Handler { setOperatorIdd(operatorNumeric); } mLocaleTracker.updateOperatorNumeric(operatorNumeric); mLocaleTracker.updateOperatorNumericSync(operatorNumeric); String countryIsoCode = mLocaleTracker.getCurrentCountry(); // Update Time Zone. Loading Loading
src/java/com/android/internal/telephony/LocaleTracker.java +42 −6 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ public class LocaleTracker extends Handler { /** Event to trigger get cell info from the modem */ private static final int EVENT_GET_CELL_INFO = 1; /** Event to trigger update operator numeric */ private static final int EVENT_UPDATE_OPERATOR_NUMERIC = 2; // Todo: Read this from Settings. /** The minimum delay to get cell info from the modem */ private static final long CELL_INFO_MIN_DELAY_MS = 2 * SECOND_IN_MILLIS; Loading Loading @@ -115,6 +118,9 @@ public class LocaleTracker extends Handler { updateLocale(); } break; case EVENT_UPDATE_OPERATOR_NUMERIC: updateOperatorNumericSync((String) msg.obj); break; default: throw new IllegalStateException("Unexpected message arrives. msg = " + msg.what); } Loading Loading @@ -201,11 +207,14 @@ public class LocaleTracker extends Handler { } /** * Update MCC/MNC from network service state. * Update MCC/MNC from network service state synchronously. Note if this is called from phone * process's main thread and if the update operation requires getting cell info from the modem, * the cached cell info will be used to determine the locale. If the cached cell info is not * acceptable, use {@link #updateOperatorNumericAsync(String)} instead. * * @param operatorNumeric MCC/MNC of the operator */ public synchronized void updateOperatorNumeric(String operatorNumeric) { public synchronized void updateOperatorNumericSync(String operatorNumeric) { // Check if the operator numeric changes. String msg = "updateOperatorNumeric. mcc/mnc=" + operatorNumeric; if (DBG) log(msg); Loading @@ -223,11 +232,28 @@ public class LocaleTracker extends Handler { log("Operator numeric unavailable. Get latest cell info from the modem."); } getCellInfo(); } else { // If operator numeric is available, that means we camp on network. So reset the // fail cell info count. mFailCellInfoCount = 0; } updateLocale(); } } /** * Update MCC/MNC from network service state asynchronously. The update operation will run * in locale tracker's handler's thread, which can get cell info synchronously from service * state tracker. Note that the country code will not be available immediately after calling * this method. * * @param operatorNumeric MCC/MNC of the operator */ public void updateOperatorNumericAsync(String operatorNumeric) { if (DBG) log("updateOperatorNumericAsync. mcc/mnc=" + operatorNumeric); sendMessage(obtainMessage(EVENT_UPDATE_OPERATOR_NUMERIC, operatorNumeric)); } /** * Get the delay time to get cell info from modem. The delay time grows exponentially to prevent * battery draining. Loading @@ -250,10 +276,18 @@ public class LocaleTracker extends Handler { * Get cell info from the modem. */ private void getCellInfo() { String msg; if (!mPhone.getServiceStateTracker().getDesiredPowerState()) { msg = "Radio is off. No need to get cell info."; if (DBG) log(msg); mLocalLog.log(msg); return; } // Get all cell info. Passing null to use default worksource, which indicates the original // request is from telephony internally. mCellInfo = mPhone.getAllCellInfo(null); String msg = "getCellInfo: cell info=" + mCellInfo; msg = "getCellInfo: cell info=" + mCellInfo; if (DBG) log(msg); mLocalLog.log(msg); if (mCellInfo == null || mCellInfo.size() == 0) { Loading @@ -275,7 +309,7 @@ public class LocaleTracker extends Handler { private void updateLocale() { // If MCC is available from network service state, use it first. String mcc = null; String countryIso = null; String countryIso = ""; if (!TextUtils.isEmpty(mOperatorNumeric)) { try { mcc = mOperatorNumeric.substring(0, 3); Loading @@ -297,7 +331,9 @@ public class LocaleTracker extends Handler { log(msg); mLocalLog.log(msg); if (!Objects.equals(countryIso, mCurrentCountryIso)) { log("updateLocale: Change the current country to " + countryIso); msg = "updateLocale: Change the current country to " + countryIso; log(msg); mLocalLog.log(msg); mCurrentCountryIso = countryIso; TelephonyManager.setTelephonyProperty(mPhone.getPhoneId(), Loading
src/java/com/android/internal/telephony/ServiceStateTracker.java +4 −3 Original line number Diff line number Diff line Loading @@ -2855,8 +2855,9 @@ public class ServiceStateTracker extends Handler { if (isInvalidOperatorNumeric(operatorNumeric)) { if (DBG) log("operatorNumeric " + operatorNumeric + " is invalid"); // Passing empty string is important for the first update. The initial value of // operator numeric in locale tracker is null. mLocaleTracker.updateOperatorNumeric(""); // operator numeric in locale tracker is null. The async update will allow getting // cell info from the modem instead of using the cached one. mLocaleTracker.updateOperatorNumericAsync(""); mNitzState.handleNetworkUnavailable(); } else if (mSS.getRilDataRadioTechnology() != ServiceState.RIL_RADIO_TECHNOLOGY_IWLAN) { // If the device is on IWLAN, modems manufacture a ServiceState with the MCC/MNC of Loading @@ -2868,7 +2869,7 @@ public class ServiceStateTracker extends Handler { setOperatorIdd(operatorNumeric); } mLocaleTracker.updateOperatorNumeric(operatorNumeric); mLocaleTracker.updateOperatorNumericSync(operatorNumeric); String countryIsoCode = mLocaleTracker.getCurrentCountry(); // Update Time Zone. Loading