/* * Copyright (C) 2010 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package android.location; import java.util.HashMap; import android.os.Handler; import android.os.Looper; import android.os.RemoteException; import android.util.Log; /** * This class provides access to the system country detector service. This * service allows applications to obtain the country that the user is in. *
* The country will be detected in order of reliability, like *
* Call the {@link #detectCountry()} to get the available country immediately. *
* To be notified of the future country change, use the * {@link #addCountryListener} *
*
* You do not instantiate this class directly; instead, retrieve it through
* {@link android.content.Context#getSystemService
* Context.getSystemService(Context.COUNTRY_DETECTOR)}.
*
* @hide
*/
public class CountryDetector {
/**
* The class to wrap the ICountryListener.Stub and CountryListener objects
* together. The CountryListener will be notified through the specific
* looper once the country changed and detected.
*/
private final static class ListenerTransport extends ICountryListener.Stub {
private final CountryListener mListener;
private final Handler mHandler;
public ListenerTransport(CountryListener listener, Looper looper) {
mListener = listener;
if (looper != null) {
mHandler = new Handler(looper);
} else {
mHandler = new Handler();
}
}
public void onCountryDetected(final Country country) {
mHandler.post(new Runnable() {
public void run() {
mListener.onCountryDetected(country);
}
});
}
}
private final static String TAG = "CountryDetector";
private final ICountryDetector mService;
private final HashMap