use of android.telephony.emergency.EmergencyNumber 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 android.telephony.emergency.EmergencyNumber 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;
}
use of android.telephony.emergency.EmergencyNumber in project android_frameworks_opt_telephony by LineageOS.
the class EmergencyNumberTracker method isEmergencyNumberFromDatabase.
private boolean isEmergencyNumberFromDatabase(String number) {
if (!mPhone.getHalVersion().greaterOrEqual(new HalVersion(1, 4))) {
return false;
}
number = PhoneNumberUtils.stripSeparators(number);
for (EmergencyNumber num : mEmergencyNumberListFromDatabase) {
if (num.getNumber().equals(number)) {
return true;
}
}
List<EmergencyNumber> emergencyNumberListFromDatabaseWithPrefix = getEmergencyNumberListWithPrefix(mEmergencyNumberListFromDatabase);
for (EmergencyNumber num : emergencyNumberListFromDatabaseWithPrefix) {
if (num.getNumber().equals(number)) {
return true;
}
}
return false;
}
use of android.telephony.emergency.EmergencyNumber in project android_frameworks_opt_telephony by LineageOS.
the class TelephonyMetricsTest method testWriteEmergencyNumberUpdateEvent.
// Test write Emergency Number update event
@Test
@SmallTest
public void testWriteEmergencyNumberUpdateEvent() throws Exception {
EmergencyNumber number = new EmergencyNumber("911", "us", "30", EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, new ArrayList<String>(), EmergencyNumber.EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING, EmergencyNumber.EMERGENCY_CALL_ROUTING_NORMAL);
mMetrics.writeEmergencyNumberUpdateEvent(mPhone.getPhoneId(), number, TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION);
TelephonyLog log = buildProto();
assertEquals(1, log.events.length);
assertEquals(0, log.callSessions.length);
assertEquals(0, log.smsSessions.length);
assertEquals(mPhone.getPhoneId(), log.events[0].phoneId);
assertEquals(TelephonyEvent.Type.EMERGENCY_NUMBER_REPORT, log.events[0].type);
assertEquals("911", log.events[0].updatedEmergencyNumber.address);
assertEquals("30", log.events[0].updatedEmergencyNumber.mnc);
assertEquals(EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, log.events[0].updatedEmergencyNumber.serviceCategoriesBitmask);
assertEquals(0, log.events[0].updatedEmergencyNumber.urns.length);
assertEquals(EmergencyNumber.EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING, log.events[0].updatedEmergencyNumber.numberSourcesBitmask);
assertEquals(EmergencyNumber.EMERGENCY_CALL_ROUTING_NORMAL, log.events[0].updatedEmergencyNumber.routing);
assertEquals(TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION, log.events[0].emergencyNumberDatabaseVersion);
}
use of android.telephony.emergency.EmergencyNumber in project android_frameworks_opt_telephony by LineageOS.
the class PhoneStateListenerTest method testTriggerOutgoingSmsEmergencyNumberChanged.
@Test
@SmallTest
public void testTriggerOutgoingSmsEmergencyNumberChanged() throws Exception {
Field field = PhoneStateListener.class.getDeclaredField("callback");
field.setAccessible(true);
assertNull(mTextedEmergencyNumber);
EmergencyNumber emergencyNumber = new EmergencyNumber("911", "us", "30", EmergencyNumber.EMERGENCY_SERVICE_CATEGORY_UNSPECIFIED, new ArrayList<String>(), EmergencyNumber.EMERGENCY_NUMBER_SOURCE_NETWORK_SIGNALING, EmergencyNumber.EMERGENCY_CALL_ROUTING_NORMAL);
((IPhoneStateListener) field.get(mPhoneStateListenerUT)).onOutgoingEmergencySms(emergencyNumber);
processAllMessages();
assertTrue(mTextedEmergencyNumber.equals(emergencyNumber));
}
Aggregations