Search in sources :

Example 16 with EmergencyNumber

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);
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) GZIPInputStream(java.util.zip.GZIPInputStream) EccInfo(com.android.phone.ecc.nano.ProtobufEccData.EccInfo) EmergencyNumber(android.telephony.emergency.EmergencyNumber) BufferedInputStream(java.io.BufferedInputStream) ProtobufEccData(com.android.phone.ecc.nano.ProtobufEccData)

Example 17 with EmergencyNumber

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;
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) GZIPInputStream(java.util.zip.GZIPInputStream) EccInfo(com.android.phone.ecc.nano.ProtobufEccData.EccInfo) EmergencyNumber(android.telephony.emergency.EmergencyNumber) BufferedInputStream(java.io.BufferedInputStream) File(java.io.File) ProtobufEccData(com.android.phone.ecc.nano.ProtobufEccData)

Example 18 with EmergencyNumber

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;
}
Also used : EmergencyNumber(android.telephony.emergency.EmergencyNumber) HalVersion(com.android.internal.telephony.HalVersion)

Example 19 with EmergencyNumber

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);
}
Also used : TelephonyLog(com.android.internal.telephony.nano.TelephonyProto.TelephonyLog) EmergencyNumber(android.telephony.emergency.EmergencyNumber) TelephonyTest(com.android.internal.telephony.TelephonyTest) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 20 with EmergencyNumber

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));
}
Also used : Field(java.lang.reflect.Field) EmergencyNumber(android.telephony.emergency.EmergencyNumber) SmallTest(android.test.suitebuilder.annotation.SmallTest) Test(org.junit.Test) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

EmergencyNumber (android.telephony.emergency.EmergencyNumber)29 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)6 HalVersion (com.android.internal.telephony.HalVersion)4 TelephonyTest (com.android.internal.telephony.TelephonyTest)4 SmallTest (android.test.suitebuilder.annotation.SmallTest)3 AsyncResult (android.os.AsyncResult)2 ProtobufEccData (com.android.phone.ecc.nano.ProtobufEccData)2 EccInfo (com.android.phone.ecc.nano.ProtobufEccData.EccInfo)2 BufferedInputStream (java.io.BufferedInputStream)2 IOException (java.io.IOException)2 Field (java.lang.reflect.Field)2 GZIPInputStream (java.util.zip.GZIPInputStream)2 PhoneStateListener (android.telephony.PhoneStateListener)1 ServiceState (android.telephony.ServiceState)1 EmergencyNumberTracker (com.android.internal.telephony.emergency.EmergencyNumberTracker)1 TelephonyLog (com.android.internal.telephony.nano.TelephonyProto.TelephonyLog)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 Before (org.junit.Before)1