use of android.location.Country in project android_frameworks_base by DirtyUnicorns.
the class ComprehensiveCountryDetector method getCountry.
/**
* Get the country from different sources in order of the reliability.
*/
private Country getCountry() {
Country result = null;
result = getNetworkBasedCountry();
if (result == null) {
result = getLastKnownLocationBasedCountry();
}
if (result == null) {
result = getSimBasedCountry();
}
if (result == null) {
result = getLocaleCountry();
}
addToLogs(result);
return result;
}
use of android.location.Country in project android_frameworks_base by DirtyUnicorns.
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.systemRunning();
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());
}
use of android.location.Country in project android_frameworks_base by DirtyUnicorns.
the class ComprehensiveCountryDetectorTest method testLocationBasedCountryNotFound.
public void testLocationBasedCountryNotFound() {
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.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 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());
}
use of android.location.Country in project android_frameworks_base by AOSPA.
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();
}
Aggregations