use of com.android.phone.ecc.nano.ProtobufEccData.EccInfo in project android_frameworks_opt_telephony by LineageOS.
the class EmergencyNumberTracker method cacheEmergencyDatabaseByCountry.
private void cacheEmergencyDatabaseByCountry(String countryIso) {
BufferedInputStream inputStream = null;
ProtobufEccData.AllInfo allEccMessages = null;
int assetsDatabaseVersion = INVALID_DATABASE_VERSION;
// Read the Asset emergency number database
List<EmergencyNumber> updatedAssetEmergencyNumberList = new ArrayList<>();
try {
inputStream = new BufferedInputStream(mPhone.getContext().getAssets().open(EMERGENCY_NUMBER_DB_ASSETS_FILE));
allEccMessages = ProtobufEccData.AllInfo.parseFrom(readInputStreamToByteArray(new GZIPInputStream(inputStream)));
assetsDatabaseVersion = allEccMessages.revision;
logd(countryIso + " asset emergency database is loaded. Ver: " + assetsDatabaseVersion + " Phone Id: " + mPhone.getPhoneId());
for (ProtobufEccData.CountryInfo countryEccInfo : allEccMessages.countries) {
if (countryEccInfo.isoCode.equals(countryIso.toUpperCase())) {
for (ProtobufEccData.EccInfo eccInfo : countryEccInfo.eccs) {
updatedAssetEmergencyNumberList.add(convertEmergencyNumberFromEccInfo(eccInfo, countryIso));
}
}
}
EmergencyNumber.mergeSameNumbersInEmergencyNumberList(updatedAssetEmergencyNumberList);
} catch (IOException ex) {
loge("Cache asset emergency database failure: " + ex);
} finally {
// close quietly by catching non-runtime exceptions.
if (inputStream != null) {
try {
inputStream.close();
} catch (RuntimeException rethrown) {
throw rethrown;
} catch (Exception ignored) {
}
}
}
// Cache OTA emergency number database
int otaDatabaseVersion = cacheOtaEmergencyNumberDatabase();
// Use a valid database that has higher version.
if (otaDatabaseVersion == INVALID_DATABASE_VERSION && assetsDatabaseVersion == INVALID_DATABASE_VERSION) {
loge("No database available. Phone Id: " + mPhone.getPhoneId());
return;
} else if (assetsDatabaseVersion > otaDatabaseVersion) {
logd("Using Asset Emergency database. Version: " + assetsDatabaseVersion);
mCurrentDatabaseVersion = assetsDatabaseVersion;
mEmergencyNumberListFromDatabase = updatedAssetEmergencyNumberList;
} else {
logd("Using Ota Emergency database. Version: " + otaDatabaseVersion);
}
}
use of com.android.phone.ecc.nano.ProtobufEccData.EccInfo in project android_frameworks_opt_telephony by LineageOS.
the class EmergencyNumberTracker method cacheOtaEmergencyNumberDatabase.
private int cacheOtaEmergencyNumberDatabase() {
FileInputStream fileInputStream = null;
BufferedInputStream inputStream = null;
ProtobufEccData.AllInfo allEccMessages = null;
int otaDatabaseVersion = INVALID_DATABASE_VERSION;
// Read the OTA emergency number database
List<EmergencyNumber> updatedOtaEmergencyNumberList = new ArrayList<>();
try {
// If OTA File partition is not available, try to reload the default one.
if (mOverridedOtaDbParcelFileDescriptor == null) {
fileInputStream = new FileInputStream(new File(Environment.getDataDirectory(), EMERGENCY_NUMBER_DB_OTA_FILE_PATH));
} else {
File file = ParcelFileDescriptor.getFile(mOverridedOtaDbParcelFileDescriptor.getFileDescriptor());
fileInputStream = new FileInputStream(new File(file.getAbsolutePath()));
}
inputStream = new BufferedInputStream(fileInputStream);
allEccMessages = ProtobufEccData.AllInfo.parseFrom(readInputStreamToByteArray(new GZIPInputStream(inputStream)));
logd(mCountryIso + " ota emergency database is loaded. Ver: " + otaDatabaseVersion);
otaDatabaseVersion = allEccMessages.revision;
for (ProtobufEccData.CountryInfo countryEccInfo : allEccMessages.countries) {
if (countryEccInfo.isoCode.equals(mCountryIso.toUpperCase())) {
for (ProtobufEccData.EccInfo eccInfo : countryEccInfo.eccs) {
updatedOtaEmergencyNumberList.add(convertEmergencyNumberFromEccInfo(eccInfo, mCountryIso));
}
}
}
EmergencyNumber.mergeSameNumbersInEmergencyNumberList(updatedOtaEmergencyNumberList);
} catch (IOException ex) {
loge("Cache ota emergency database IOException: " + ex);
} finally {
// Close quietly by catching non-runtime exceptions.
if (inputStream != null) {
try {
inputStream.close();
} catch (RuntimeException rethrown) {
throw rethrown;
} catch (Exception ignored) {
}
}
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (RuntimeException rethrown) {
throw rethrown;
} catch (Exception ignored) {
}
}
}
// Use a valid database that has higher version.
if (otaDatabaseVersion != INVALID_DATABASE_VERSION && mCurrentDatabaseVersion < otaDatabaseVersion) {
mCurrentDatabaseVersion = otaDatabaseVersion;
mEmergencyNumberListFromDatabase = updatedOtaEmergencyNumberList;
}
return otaDatabaseVersion;
}
Aggregations