Search in sources :

Example 11 with Country

use of android.location.Country in project platform_frameworks_base by android.

the class ComprehensiveCountryDetectorTest method testDetectLocationBasedCountry.

public void testDetectLocationBasedCountry() {
    final Country resultCountry = new Country(TestCountryDetector.COUNTRY_ISO, Country.COUNTRY_SOURCE_SIM);
    final Country locationBasedCountry = new Country(TestCountryDetector.COUNTRY_ISO, Country.COUNTRY_SOURCE_LOCATION);
    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.notifyLocationBasedListener(locationBasedCountry);
    assertTrue(listener.notified());
    assertTrue(sameCountry(listener.getCountry(), locationBasedCountry));
    assertTrue(countryDetector.locationBasedDetectorStopped());
    assertTrue(countryDetector.locationRefreshStarted());
    countryDetector.stop();
    assertTrue(countryDetector.locationRefreshCancelled());
}
Also used : Country(android.location.Country)

Example 12 with Country

use of android.location.Country in project platform_frameworks_base by android.

the class ComprehensiveCountryDetectorTest method testLocaleBasedCountry.

public void testLocaleBasedCountry() {
    final Country resultCountry = new Country(TestCountryDetector.COUNTRY_ISO, Country.COUNTRY_SOURCE_LOCALE);
    TestCountryDetector countryDetector = new TestCountryDetector() {

        @Override
        protected Country getLocaleCountry() {
            return resultCountry;
        }
    };
    CountryListenerImpl listener = new CountryListenerImpl();
    countryDetector.setCountryListener(listener);
    Country country = countryDetector.detectCountry();
    assertTrue(sameCountry(country, resultCountry));
    assertFalse(listener.notified());
    assertTrue(countryDetector.locationBasedDetectorStarted());
    assertTrue(countryDetector.locationRefreshStarted());
    countryDetector.stop();
    assertTrue(countryDetector.locationRefreshCancelled());
}
Also used : Country(android.location.Country)

Example 13 with Country

use of android.location.Country in project platform_frameworks_base by android.

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)

Example 14 with Country

use of android.location.Country in project platform_frameworks_base by android.

the class CallerInfo method getCurrentCountryIso.

/**
     * @return The ISO 3166-1 two letters country code of the country the user
     *         is in.
     */
private static String getCurrentCountryIso(Context context, Locale locale) {
    String countryIso = null;
    CountryDetector detector = (CountryDetector) context.getSystemService(Context.COUNTRY_DETECTOR);
    if (detector != null) {
        Country country = detector.detectCountry();
        if (country != null) {
            countryIso = country.getCountryIso();
        } else {
            Rlog.e(TAG, "CountryDetector.detectCountry() returned null.");
        }
    }
    if (countryIso == null) {
        countryIso = locale.getCountry();
        Rlog.w(TAG, "No CountryDetector; falling back to countryIso based on locale: " + countryIso);
    }
    return countryIso;
}
Also used : Country(android.location.Country) CountryDetector(android.location.CountryDetector)

Example 15 with Country

use of android.location.Country in project platform_frameworks_base by android.

the class ComprehensiveCountryDetector method toString.

@Override
public String toString() {
    long currentTime = SystemClock.elapsedRealtime();
    long currentSessionLength = 0;
    StringBuilder sb = new StringBuilder();
    sb.append("ComprehensiveCountryDetector{");
    // The detector hasn't stopped yet --> still running
    if (mStopTime == 0) {
        currentSessionLength = currentTime - mStartTime;
        sb.append("timeRunning=" + currentSessionLength + ", ");
    } else {
        // Otherwise, it has already stopped, so take the last session
        sb.append("lastRunTimeLength=" + (mStopTime - mStartTime) + ", ");
    }
    sb.append("totalCountServiceStateChanges=" + mTotalCountServiceStateChanges + ", ");
    sb.append("currentCountServiceStateChanges=" + mCountServiceStateChanges + ", ");
    sb.append("totalTime=" + (mTotalTime + currentSessionLength) + ", ");
    sb.append("currentTime=" + currentTime + ", ");
    sb.append("countries=");
    for (Country country : mDebugLogs) {
        sb.append("\n   " + country.toString());
    }
    sb.append("}");
    return sb.toString();
}
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