Search in sources :

Example 1 with Country

use of android.location.Country in project android_frameworks_base by ParanoidAndroid.

the class LocationBasedCountryDetector method queryCountryCode.

/**
     * Start a new thread to query the country from Geocoder.
     */
private synchronized void queryCountryCode(final Location location) {
    if (location == null) {
        notifyListener(null);
        return;
    }
    if (mQueryThread != null)
        return;
    mQueryThread = new Thread(new Runnable() {

        @Override
        public void run() {
            String countryIso = null;
            if (location != null) {
                countryIso = getCountryFromLocation(location);
            }
            if (countryIso != null) {
                mDetectedCountry = new Country(countryIso, Country.COUNTRY_SOURCE_LOCATION);
            } else {
                mDetectedCountry = null;
            }
            notifyListener(mDetectedCountry);
            mQueryThread = null;
        }
    });
    mQueryThread.start();
}
Also used : Country(android.location.Country)

Example 2 with Country

use of android.location.Country in project android_frameworks_base by ParanoidAndroid.

the class ComprehensiveCountryDetector method detectCountry.

/**
     * @param notifyChange indicates whether the listener should be notified the change of the
     * country
     * @param startLocationBasedDetection indicates whether the LocationBasedCountryDetector could
     * be started if the current country source is less reliable than the location.
     * @return the current available UserCountry
     */
private Country detectCountry(boolean notifyChange, boolean startLocationBasedDetection) {
    Country country = getCountry();
    runAfterDetectionAsync(mCountry != null ? new Country(mCountry) : mCountry, country, notifyChange, startLocationBasedDetection);
    mCountry = country;
    return mCountry;
}
Also used : Country(android.location.Country)

Example 3 with Country

use of android.location.Country in project android_frameworks_base by ParanoidAndroid.

the class CountryDetectorServiceTest method testNotifyListeners.

public void testNotifyListeners() throws RemoteException {
    CountryDetectorServiceTester serviceTester = new CountryDetectorServiceTester(getContext());
    CountryListenerTester listenerTesterA = new CountryListenerTester();
    CountryListenerTester listenerTesterB = new CountryListenerTester();
    Country country = new Country("US", Country.COUNTRY_SOURCE_NETWORK);
    serviceTester.systemReady();
    waitForSystemReady(serviceTester);
    serviceTester.addCountryListener(listenerTesterA);
    serviceTester.addCountryListener(listenerTesterB);
    serviceTester.notifyReceivers(country);
    assertTrue(serviceTester.isListenerSet());
    assertTrue(listenerTesterA.isNotified());
    assertTrue(listenerTesterB.isNotified());
    serviceTester.removeCountryListener(listenerTesterA);
    serviceTester.removeCountryListener(listenerTesterB);
    assertFalse(serviceTester.isListenerSet());
}
Also used : Country(android.location.Country)

Example 4 with Country

use of android.location.Country in project android_frameworks_base by ParanoidAndroid.

the class ComprehensiveCountryDetectorTest method testStoppingDetector.

public void testStoppingDetector() {
    // Test stopping detector when LocationBasedCountryDetector was started
    final Country resultCountry = new Country(TestCountryDetector.COUNTRY_ISO, Country.COUNTRY_SOURCE_SIM);
    TestCountryDetector countryDetector = new TestCountryDetector() {

        @Override
        protected Country getSimBasedCountry() {
            return resultCountry;
        }
    };
    CountryListenerImpl listener = new CountryListenerImpl();
    countryDetector.setCountryListener(listener);
    Country country = countryDetector.detectCountry();
    assertTrue(sameCountry(country, resultCountry));
    assertTrue(countryDetector.locationBasedDetectorStarted());
    countryDetector.stop();
    // The LocationBasedDetector should be stopped.
    assertTrue(countryDetector.locationBasedDetectorStopped());
    // The location refresh should not running.
    assertTrue(countryDetector.locationRefreshCancelled());
}
Also used : Country(android.location.Country)

Example 5 with Country

use of android.location.Country in project android_frameworks_base by ParanoidAndroid.

the class ComprehensiveCountryDetectorTest method testNoCountryFound.

public void testNoCountryFound() {
    TestCountryDetector countryDetector = new TestCountryDetector();
    CountryListenerImpl listener = new CountryListenerImpl();
    countryDetector.setCountryListener(listener);
    Country country = countryDetector.detectCountry();
    assertTrue(sameCountry(country, null));
    assertTrue(countryDetector.locationBasedDetectorStarted());
    countryDetector.notifyLocationBasedListener(null);
    assertFalse(listener.notified());
    assertTrue(sameCountry(listener.getCountry(), null));
    assertTrue(countryDetector.locationBasedDetectorStopped());
    assertTrue(countryDetector.locationRefreshStarted());
    countryDetector.stop();
    assertTrue(countryDetector.locationRefreshCancelled());
}
Also used : Country(android.location.Country)

Aggregations

Country (android.location.Country)71 CountryListener (android.location.CountryListener)6 ICountryListener (android.location.ICountryListener)6 ComprehensiveCountryDetector (com.android.server.location.ComprehensiveCountryDetector)6 CountryDetector (android.location.CountryDetector)4 Context (android.content.Context)1 StrictMode (android.os.StrictMode)1 LifecycleHandler (com.moez.QKSMS.common.LifecycleHandler)1 PduLoaderManager (com.moez.QKSMS.common.google.PduLoaderManager)1 ThumbnailManager (com.moez.QKSMS.common.google.ThumbnailManager)1