use of android.location.Country in project android_frameworks_base by DirtyUnicorns.
the class ComprehensiveCountryDetectorTest method testDetectNetworkBasedCountry.
public void testDetectNetworkBasedCountry() {
final Country resultCountry = new Country(TestCountryDetector.COUNTRY_ISO, Country.COUNTRY_SOURCE_NETWORK);
TestCountryDetector countryDetector = new TestCountryDetector() {
@Override
protected Country getNetworkBasedCountry() {
return resultCountry;
}
};
CountryListenerImpl listener = new CountryListenerImpl();
countryDetector.setCountryListener(listener);
Country country = countryDetector.detectCountry();
assertTrue(sameCountry(country, resultCountry));
assertFalse(listener.notified());
assertFalse(countryDetector.locationBasedDetectorStarted());
assertFalse(countryDetector.locationRefreshStarted());
countryDetector.stop();
}
use of android.location.Country in project android_frameworks_base by DirtyUnicorns.
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());
}
use of android.location.Country in project android_frameworks_base by DirtyUnicorns.
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());
}
use of android.location.Country in project android_frameworks_base by DirtyUnicorns.
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());
}
use of android.location.Country in project android_frameworks_base by DirtyUnicorns.
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;
}
Aggregations