use of com.android.internal.telephony.NitzData in project android_frameworks_opt_telephony by LineageOS.
the class TimeZoneSuggesterImpl method getTimeZoneSuggestion.
@Override
@NonNull
public TelephonyTimeZoneSuggestion getTimeZoneSuggestion(int slotIndex, @Nullable String countryIsoCode, @Nullable TimestampedValue<NitzData> nitzSignal) {
try {
// Check for overriding NITZ-based signals from Android running in an emulator.
TelephonyTimeZoneSuggestion overridingSuggestion = null;
if (nitzSignal != null) {
NitzData nitzData = nitzSignal.getValue();
if (nitzData.getEmulatorHostTimeZone() != null) {
TelephonyTimeZoneSuggestion.Builder builder = new TelephonyTimeZoneSuggestion.Builder(slotIndex).setZoneId(nitzData.getEmulatorHostTimeZone().getID()).setMatchType(TelephonyTimeZoneSuggestion.MATCH_TYPE_EMULATOR_ZONE_ID).setQuality(TelephonyTimeZoneSuggestion.QUALITY_SINGLE_ZONE).addDebugInfo("Emulator time zone override: " + nitzData);
overridingSuggestion = builder.build();
}
}
TelephonyTimeZoneSuggestion suggestion;
if (overridingSuggestion != null) {
suggestion = overridingSuggestion;
} else if (countryIsoCode == null) {
if (nitzSignal == null) {
suggestion = createEmptySuggestion(slotIndex, "getTimeZoneSuggestion: nitzSignal=null, countryIsoCode=null");
} else {
// NITZ only - wait until we have a country.
suggestion = createEmptySuggestion(slotIndex, "getTimeZoneSuggestion:" + " nitzSignal=" + nitzSignal + ", countryIsoCode=null");
}
} else {
// countryIsoCode != null
if (nitzSignal == null) {
if (countryIsoCode.isEmpty()) {
// This is assumed to be a test network with no NITZ data to go on.
suggestion = createEmptySuggestion(slotIndex, "getTimeZoneSuggestion: nitzSignal=null, countryIsoCode=\"\"");
} else {
// Country only
suggestion = findTimeZoneFromNetworkCountryCode(slotIndex, countryIsoCode, mDeviceState.currentTimeMillis());
}
} else {
// nitzSignal != null
if (countryIsoCode.isEmpty()) {
// We have been told we have a country code but it's empty. This is most
// likely because we're on a test network that's using a bogus MCC
// (eg, "001"). Obtain a TimeZone based only on the NITZ parameters: without
// a country it will be arbitrary, but it should at least have the correct
// offset.
suggestion = findTimeZoneForTestNetwork(slotIndex, nitzSignal);
} else {
// We have both NITZ and Country code.
suggestion = findTimeZoneFromCountryAndNitz(slotIndex, countryIsoCode, nitzSignal);
}
}
}
// Ensure the return value is never null.
Objects.requireNonNull(suggestion);
return suggestion;
} catch (RuntimeException e) {
// This would suggest a coding error. Log at a high level and try to avoid leaving the
// device in a bad state by making an "empty" suggestion.
String message = "getTimeZoneSuggestion: Error during lookup: " + " countryIsoCode=" + countryIsoCode + ", nitzSignal=" + nitzSignal + ", e=" + e.getMessage();
TelephonyTimeZoneSuggestion errorSuggestion = createEmptySuggestion(slotIndex, message);
Rlog.w(LOG_TAG, message, e);
return errorSuggestion;
}
}
Aggregations