Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 32d54dc2 authored by Shuo Qian's avatar Shuo Qian Committed by Gerrit Code Review
Browse files

Merge "Replace LocaleTracker with CountryDetector"

parents 440ee1da 9e296a06
Loading
Loading
Loading
Loading
+0 −10
Original line number Original line Diff line number Diff line
@@ -417,16 +417,6 @@ public class LocaleTracker extends Handler {
            mLocalLog.log(msg);
            mLocalLog.log(msg);
            mCurrentCountryIso = countryIso;
            mCurrentCountryIso = countryIso;


            // Inform EmergencyNumberTrack with the change of current Country ISO
            if (mPhone != null && mPhone.getEmergencyNumberTracker() != null) {
                mPhone.getEmergencyNumberTracker().updateEmergencyNumberDatabaseCountryChange(
                        getCurrentCountry());
                log("Notified EmergencyNumberTracker");
            } else {
                loge("Cannot notify EmergencyNumberTracker. Phone is null? "
                        + Boolean.toString(mPhone == null));
            }

            TelephonyManager.setTelephonyProperty(mPhone.getPhoneId(),
            TelephonyManager.setTelephonyProperty(mPhone.getPhoneId(),
                    TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, mCurrentCountryIso);
                    TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY, mCurrentCountryIso);


+31 −3
Original line number Original line Diff line number Diff line
@@ -16,6 +16,10 @@


package com.android.internal.telephony.emergency;
package com.android.internal.telephony.emergency;


import android.content.Context;
import android.location.Country;
import android.location.CountryDetector;
import android.location.CountryListener;
import android.os.AsyncResult;
import android.os.AsyncResult;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
@@ -70,6 +74,7 @@ public class EmergencyNumberTracker extends Handler {


    private final CommandsInterface mCi;
    private final CommandsInterface mCi;
    private final Phone mPhone;
    private final Phone mPhone;
    private CountryDetector mCountryDetector;
    private String mCountryIso;
    private String mCountryIso;


    private static final String EMERGENCY_NUMBER_DB_ASSETS_FILE = "eccdata";
    private static final String EMERGENCY_NUMBER_DB_ASSETS_FILE = "eccdata";
@@ -97,6 +102,17 @@ public class EmergencyNumberTracker extends Handler {
    public EmergencyNumberTracker(Phone phone, CommandsInterface ci) {
    public EmergencyNumberTracker(Phone phone, CommandsInterface ci) {
        mPhone = phone;
        mPhone = phone;
        mCi = ci;
        mCi = ci;
        if (mPhone != null) {
            mCountryDetector = (CountryDetector) mPhone.getContext().getSystemService(
                    Context.COUNTRY_DETECTOR);
            if (mCountryDetector != null) {
                mCountryDetector.addCountryListener(new CountryListener() {
                    public void onCountryDetected(Country country) {
                        updateEmergencyNumberDatabaseCountryChange(country.getCountryIso());
                    }
                }, getLooper());
            }
        }
        initializeDatabaseEmergencyNumberList();
        initializeDatabaseEmergencyNumberList();
        mCi.registerForEmergencyNumberList(this, EVENT_UNSOL_EMERGENCY_NUMBER_LIST, null);
        mCi.registerForEmergencyNumberList(this, EVENT_UNSOL_EMERGENCY_NUMBER_LIST, null);
    }
    }
@@ -143,11 +159,23 @@ public class EmergencyNumberTracker extends Handler {
    }
    }


    private void initializeDatabaseEmergencyNumberList() {
    private void initializeDatabaseEmergencyNumberList() {
        // If country iso has been cached when listener is set, don't need to cache the initial
        // country iso and initial database.
        if (mCountryIso == null) {
            mCountryIso = getInitialCountryIso().toLowerCase();
            mCountryIso = getInitialCountryIso().toLowerCase();
            cacheEmergencyDatabaseByCountry(mCountryIso);
            cacheEmergencyDatabaseByCountry(mCountryIso);
        }
        }
    }


    private String getInitialCountryIso() {
    private String getInitialCountryIso() {
        Country country = null;
        if (mCountryDetector != null) {
            country = mCountryDetector.detectCountry();
            if (country != null) {
                return country.getCountryIso();
            }
        }
        // Fallback to Telephony's country detector if there are issues with CountryDetector
        if (mPhone != null) {
        if (mPhone != null) {
            ServiceStateTracker sst = mPhone.getServiceStateTracker();
            ServiceStateTracker sst = mPhone.getServiceStateTracker();
            if (sst != null) {
            if (sst != null) {
@@ -216,7 +244,7 @@ public class EmergencyNumberTracker extends Handler {
                    mPhone.getContext().getAssets().open(EMERGENCY_NUMBER_DB_ASSETS_FILE));
                    mPhone.getContext().getAssets().open(EMERGENCY_NUMBER_DB_ASSETS_FILE));
            allEccMessages = ProtobufEccData.AllInfo.parseFrom(readInputStreamToByteArray(
            allEccMessages = ProtobufEccData.AllInfo.parseFrom(readInputStreamToByteArray(
                    new GZIPInputStream(inputStream)));
                    new GZIPInputStream(inputStream)));
            logd("Emergency database is loaded. ");
            logd(countryIso + " emergency database is loaded. ");
            for (ProtobufEccData.CountryInfo countryEccInfo : allEccMessages.countries) {
            for (ProtobufEccData.CountryInfo countryEccInfo : allEccMessages.countries) {
                if (countryEccInfo.isoCode.equals(countryIso.toUpperCase())) {
                if (countryEccInfo.isoCode.equals(countryIso.toUpperCase())) {
                    for (ProtobufEccData.EccInfo eccInfo : countryEccInfo.eccs) {
                    for (ProtobufEccData.EccInfo eccInfo : countryEccInfo.eccs) {
+2 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.telephony.emergency;
package com.android.internal.telephony.emergency;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.doReturn;


import android.os.AsyncResult;
import android.os.AsyncResult;
import android.os.HandlerThread;
import android.os.HandlerThread;
@@ -58,6 +59,7 @@ public class EmergencyNumberTrackerTest extends TelephonyTest {
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        logd("EmergencyNumberTrackerTest +Setup!");
        logd("EmergencyNumberTrackerTest +Setup!");
        super.setUp("EmergencyNumberTrackerTest");
        super.setUp("EmergencyNumberTrackerTest");
        doReturn(mContext).when(mPhone).getContext();
        initializeEmergencyNumberListTestSamples();
        initializeEmergencyNumberListTestSamples();
        mHandlerThread = new EmergencyNumberTrackerTestHandler("EmergencyNumberTrackerTestHandler");
        mHandlerThread = new EmergencyNumberTrackerTestHandler("EmergencyNumberTrackerTestHandler");
        mHandlerThread.start();
        mHandlerThread.start();