Methods Summary |
---|
public void | addCountryListener(android.location.ICountryListener listener)Add the ICountryListener into the listener list.
if (!mSystemReady) {
throw new RemoteException();
}
addListener(listener);
|
private void | addListener(android.location.ICountryListener listener)
synchronized (mReceivers) {
Receiver r = new Receiver(listener);
try {
listener.asBinder().linkToDeath(r, 0);
mReceivers.put(listener.asBinder(), r);
if (mReceivers.size() == 1) {
Slog.d(TAG, "The first listener is added");
setCountryListener(mLocationBasedDetectorListener);
}
} catch (RemoteException e) {
Slog.e(TAG, "linkToDeath failed:", e);
}
}
|
public android.location.Country | detectCountry()
if (!mSystemReady) {
return null; // server not yet active
} else {
return mCountryDetector.detectCountry();
}
|
protected void | dump(java.io.FileDescriptor fd, java.io.PrintWriter fout, java.lang.String[] args)
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.DUMP, TAG);
if (!DEBUG) return;
try {
final Printer p = new PrintWriterPrinter(fout);
p.println("CountryDetectorService state:");
p.println(" Number of listeners=" + mReceivers.keySet().size());
if (mCountryDetector == null) {
p.println(" ComprehensiveCountryDetector not initialized");
} else {
p.println(" " + mCountryDetector.toString());
}
} catch (Exception e) {
Slog.e(TAG, "Failed to dump CountryDetectorService: ", e);
}
|
private void | initialize()
mCountryDetector = new ComprehensiveCountryDetector(mContext);
mLocationBasedDetectorListener = new CountryListener() {
public void onCountryDetected(final Country country) {
mHandler.post(new Runnable() {
public void run() {
notifyReceivers(country);
}
});
}
};
|
boolean | isSystemReady()
return mSystemReady;
|
protected void | notifyReceivers(android.location.Country country)
synchronized(mReceivers) {
for (Receiver receiver : mReceivers.values()) {
try {
receiver.getListener().onCountryDetected(country);
} catch (RemoteException e) {
// TODO: Shall we remove the receiver?
Slog.e(TAG, "notifyReceivers failed:", e);
}
}
}
|
public void | removeCountryListener(android.location.ICountryListener listener)Remove the ICountryListener from the listener list.
if (!mSystemReady) {
throw new RemoteException();
}
removeListener(listener.asBinder());
|
private void | removeListener(android.os.IBinder key)
synchronized (mReceivers) {
mReceivers.remove(key);
if (mReceivers.isEmpty()) {
setCountryListener(null);
Slog.d(TAG, "No listener is left");
}
}
|
public void | run()
mHandler = new Handler();
initialize();
mSystemReady = true;
|
protected void | setCountryListener(android.location.CountryListener listener)
mHandler.post(new Runnable() {
@Override
public void run() {
mCountryDetector.setCountryListener(listener);
}
});
|
void | systemRunning()
// Shall we wait for the initialization finish.
BackgroundThread.getHandler().post(this);
|