Merge "Replace NetworkQueryService with NetworkScanHelper" am: 5f0a7111ef
am: 7ca6530361
Change-Id: I0caccd8f31dfd4b17c59450b35e9bc262b1ae040
diff --git a/src/com/android/phone/GsmUmtsOptions.java b/src/com/android/phone/GsmUmtsOptions.java
index a3f5cfb..3e45173 100644
--- a/src/com/android/phone/GsmUmtsOptions.java
+++ b/src/com/android/phone/GsmUmtsOptions.java
@@ -54,7 +54,7 @@
private PreferenceScreen mPrefScreen;
public GsmUmtsOptions(PreferenceFragment prefFragment, PreferenceScreen prefScreen,
- final int subId, INetworkQueryService queryService) {
+ final int subId) {
final Context context = prefFragment.getContext();
mPrefFragment = prefFragment;
mPrefScreen = prefScreen;
@@ -68,12 +68,12 @@
mNetworkOperator.initialize();
- update(subId, queryService);
+ update(subId);
}
- // Unlike mPrefFragment or mPrefScreen, subId or queryService may change during lifecycle of
- // GsmUmtsOptions. When that happens, we update GsmUmtsOptions with new parameters.
- protected void update(final int subId, INetworkQueryService queryService) {
+ // Unlike mPrefFragment or mPrefScreen, subId may change during lifecycle of GsmUmtsOptions.
+ // When that happens, we update GsmUmtsOptions with new parameters.
+ protected void update(final int subId) {
boolean addAPNExpand = true;
boolean addNetworkOperatorsCategory = true;
boolean addCarrierSettings = true;
@@ -151,7 +151,7 @@
if (addNetworkOperatorsCategory) {
mPrefScreen.addPreference(mNetworkOperator);
- mNetworkOperator.update(subId, queryService);
+ mNetworkOperator.update(subId);
} else {
mPrefScreen.removePreference(mNetworkOperator);
}
diff --git a/src/com/android/phone/MobileNetworkSettings.java b/src/com/android/phone/MobileNetworkSettings.java
index 5d90258..9d78ed3 100644
--- a/src/com/android/phone/MobileNetworkSettings.java
+++ b/src/com/android/phone/MobileNetworkSettings.java
@@ -24,12 +24,10 @@
import android.app.Fragment;
import android.app.FragmentManager;
import android.content.BroadcastReceiver;
-import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
-import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.ContentObserver;
@@ -38,7 +36,6 @@
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
-import android.os.IBinder;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.SystemProperties;
@@ -469,53 +466,6 @@
private final PhoneCallStateListener mPhoneStateListener = new PhoneCallStateListener();
- /**
- * Service connection code for the NetworkQueryService.
- * Handles the work of binding to a local object so that we can make
- * the appropriate service calls.
- */
-
- /** Local service interface */
- private INetworkQueryService mNetworkQueryService = null;
-
- private void setNetworkQueryService() {
- mButtonNetworkSelect = (NetworkSelectListPreference) getPreferenceScreen()
- .findPreference(NetworkOperators.BUTTON_NETWORK_SELECT_KEY);
- if (mButtonNetworkSelect != null) {
- mButtonNetworkSelect.setNetworkQueryService(mNetworkQueryService);
- }
-
- }
- /** Service connection */
- private final ServiceConnection mNetworkQueryServiceConnection = new ServiceConnection() {
-
- /** Handle the task of binding the local object to the service */
- public void onServiceConnected(ComponentName className, IBinder service) {
- if (DBG) log("connection created, binding local service.");
- mNetworkQueryService = ((NetworkQueryService.LocalBinder) service).getService();
- setNetworkQueryService();
- }
-
- /** Handle the task of cleaning up the local binding */
- public void onServiceDisconnected(ComponentName className) {
- if (DBG) log("connection disconnected, cleaning local binding.");
- mNetworkQueryService = null;
- setNetworkQueryService();
- }
- };
-
- private void bindNetworkQueryService() {
- getContext().startService(new Intent(getContext(), NetworkQueryService.class));
- getContext().bindService(new Intent(getContext(), NetworkQueryService.class).setAction(
- NetworkQueryService.ACTION_LOCAL_BINDER),
- mNetworkQueryServiceConnection, Context.BIND_AUTO_CREATE);
- }
-
- private void unbindNetworkQueryService() {
- // unbind the service.
- getContext().unbindService(mNetworkQueryServiceConnection);
- }
-
@Override
public void onPositiveButtonClick(DialogFragment dialog) {
mTelephonyManager.setDataRoamingEnabled(true);
@@ -843,8 +793,6 @@
mExpandAdvancedFields = true;
}
- bindNetworkQueryService();
-
addPreferencesFromResource(R.xml.network_setting_fragment);
mButton4glte = (SwitchPreference)findPreference(BUTTON_4G_LTE_KEY);
@@ -948,7 +896,6 @@
@Override
public void onDestroy() {
super.onDestroy();
- unbindNetworkQueryService();
if (mMobileDataPref != null) {
mMobileDataPref.dispose();
}
@@ -1123,7 +1070,7 @@
if (phoneType == PhoneConstants.PHONE_TYPE_CDMA) {
updateCdmaOptions(this, prefSet, mSubId);
} else if (phoneType == PhoneConstants.PHONE_TYPE_GSM) {
- updateGsmUmtsOptions(this, prefSet, phoneSubId, mNetworkQueryService);
+ updateGsmUmtsOptions(this, prefSet, phoneSubId);
} else {
throw new IllegalStateException("Unexpected phone type: " + phoneType);
}
@@ -1139,7 +1086,7 @@
mButtonPreferredNetworkMode.setOnPreferenceChangeListener(this);
updateCdmaOptions(this, prefSet, mSubId);
- updateGsmUmtsOptions(this, prefSet, phoneSubId, mNetworkQueryService);
+ updateGsmUmtsOptions(this, prefSet, phoneSubId);
} else {
prefSet.removePreference(mButtonPreferredNetworkMode);
updateEnabledNetworksEntries();
@@ -1353,8 +1300,7 @@
mButtonEnabledNetworks.setEntryValues(
R.array.enabled_networks_values);
}
- updateGsmUmtsOptions(this, getPreferenceScreen(), mSubId,
- mNetworkQueryService);
+ updateGsmUmtsOptions(this, getPreferenceScreen(), mSubId);
} else {
throw new IllegalStateException("Unexpected phone type: " + phoneType);
}
@@ -2092,7 +2038,7 @@
return;
}
- updateGsmUmtsOptions(this, prefSet, mSubId, mNetworkQueryService);
+ updateGsmUmtsOptions(this, prefSet, mSubId);
PreferenceCategory networkOperatorCategory =
(PreferenceCategory) prefSet.findPreference(
@@ -2245,14 +2191,14 @@
}
private void updateGsmUmtsOptions(PreferenceFragment prefFragment,
- PreferenceScreen prefScreen, final int subId, INetworkQueryService queryService) {
+ PreferenceScreen prefScreen, final int subId) {
// We don't want to re-create GsmUmtsOptions if already exists. Otherwise, the
// preferences inside it will also be re-created which causes unexpected behavior.
// For example, the open dialog gets dismissed or detached after pause / resume.
if (mGsmUmtsOptions == null) {
- mGsmUmtsOptions = new GsmUmtsOptions(prefFragment, prefScreen, subId, queryService);
+ mGsmUmtsOptions = new GsmUmtsOptions(prefFragment, prefScreen, subId);
} else {
- mGsmUmtsOptions.update(subId, queryService);
+ mGsmUmtsOptions.update(subId);
}
}
diff --git a/src/com/android/phone/NetworkOperators.java b/src/com/android/phone/NetworkOperators.java
index 6d798b0..938ca34 100644
--- a/src/com/android/phone/NetworkOperators.java
+++ b/src/com/android/phone/NetworkOperators.java
@@ -94,12 +94,11 @@
}
/**
- * Update NetworkOperators instance if like subId or queryService are updated.
+ * Update NetworkOperators instance if like subId is updated.
*
* @param subId Corresponding subscription ID of this network.
- * @param queryService The service to do network queries.
*/
- protected void update(final int subId, INetworkQueryService queryService) {
+ protected void update(final int subId) {
mSubId = subId;
mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(mSubId);
@@ -118,7 +117,7 @@
}
} else {
if (mNetworkSelect != null) {
- mNetworkSelect.initialize(mSubId, queryService, this, mProgressDialog);
+ mNetworkSelect.initialize(mSubId, this, mProgressDialog);
}
}
getNetworkSelectionMode();
diff --git a/src/com/android/phone/NetworkSelectListPreference.java b/src/com/android/phone/NetworkSelectListPreference.java
index a2a1080..df3f44a 100644
--- a/src/com/android/phone/NetworkSelectListPreference.java
+++ b/src/com/android/phone/NetworkSelectListPreference.java
@@ -24,7 +24,6 @@
import android.os.Message;
import android.os.Parcel;
import android.os.Parcelable;
-import android.os.RemoteException;
import android.preference.ListPreference;
import android.preference.Preference;
import android.telephony.CellInfo;
@@ -39,15 +38,19 @@
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
+import android.widget.Toast;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.OperatorInfo;
+import com.android.phone.NetworkScanHelper.NetworkScanCallback;
import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
/**
@@ -65,16 +68,20 @@
private static final int EVENT_MANUALLY_NETWORK_SELECTION_DONE = 1;
private static final int EVENT_NETWORK_SCAN_RESULTS = 2;
private static final int EVENT_NETWORK_SCAN_COMPLETED = 3;
+ private static final int EVENT_NETWORK_SCAN_ERROR = 4;
//dialog ids
private static final int DIALOG_NETWORK_SELECTION = 100;
private static final int DIALOG_NETWORK_LIST_LOAD = 200;
+ private final ExecutorService mNetworkScanExecutor = Executors.newFixedThreadPool(1);
+
private List<CellInfo> mCellInfoList;
private CellInfo mCellInfo;
private int mSubId;
private TelephonyManager mTelephonyManager;
+ private NetworkScanHelper mNetworkScanHelper;
private NetworkOperators mNetworkOperators;
private List<String> mForbiddenPlmns;
@@ -114,11 +121,7 @@
switch (msg.what) {
case EVENT_MANUALLY_NETWORK_SELECTION_DONE:
if (DBG) logd("hideProgressPanel");
- try {
- dismissProgressBar();
- } catch (IllegalArgumentException e) {
- }
- setEnabled(true);
+ dismissProgressDialog();
boolean isSuccessed = (boolean) msg.obj;
if (isSuccessed) {
@@ -139,72 +142,51 @@
results.removeIf(cellInfo -> cellInfo == null);
mCellInfoList = new ArrayList<>(results);
if (DBG) logd("CALLBACK_SCAN_RESULTS" + mCellInfoList.toString());
-
break;
case EVENT_NETWORK_SCAN_COMPLETED:
- try {
- if (mNetworkQueryService != null) {
- mNetworkQueryService.unregisterCallback(mCallback);
- }
- } catch (RemoteException e) {
- loge("onComplete: exception from unregisterCallback " + e);
- }
if (DBG) logd("scan complete, load the cellInfosList");
- // Modify UI to indicate users that the scan has completed.
+ dismissProgressDialog();
networksListLoaded();
+ break;
+ case EVENT_NETWORK_SCAN_ERROR:
+ dismissProgressDialog();
+ displayNetworkQueryFailed();
+ mNetworkOperators.getNetworkSelectionMode();
+ break;
}
return;
}
};
- INetworkQueryService mNetworkQueryService = null;
- /**
- * This implementation of INetworkQueryServiceCallback is used to receive
- * callback notifications from the network query service.
- */
- private final INetworkQueryServiceCallback mCallback = new INetworkQueryServiceCallback.Stub() {
-
- /** Returns the scan results to the user, this callback will be called only one time. */
+ private final NetworkScanHelper.NetworkScanCallback mCallback = new NetworkScanCallback() {
public void onResults(List<CellInfo> results) {
if (DBG) logd("get scan results: " + results.toString());
Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_RESULTS, results);
msg.sendToTarget();
}
- /**
- * Informs the user that the scan has stopped.
- *
- * This callback will be called when the scan is finished or cancelled by the user.
- * The related NetworkScanRequest will be deleted after this callback.
- */
public void onComplete() {
if (DBG) logd("network scan completed.");
Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_COMPLETED);
msg.sendToTarget();
}
- /**
- * This callback will not be called, since the old Scan API won't send this callback.
- */
- public void onError(int error) {}
+ public void onError(int error) {
+ if (DBG) logd("network scan error.");
+ Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_ERROR);
+ msg.sendToTarget();
+ }
};
@Override
//implemented for DialogInterface.OnCancelListener
public void onCancel(DialogInterface dialog) {
if (DBG) logd("user manually close the dialog");
- // request that the service stop the query with this callback object.
- try {
- if (mNetworkQueryService != null) {
- mNetworkQueryService.stopNetworkQuery();
- mNetworkQueryService.unregisterCallback(mCallback);
- }
- // If cancelled, we query NetworkSelectMode and update states of AutoSelect button.
- mNetworkOperators.getNetworkSelectionMode();
- } catch (RemoteException e) {
- loge("onCancel: exception from stopNetworkQuery " + e);
- }
+ mNetworkScanHelper.stopNetworkQuery();
+
+ // If cancelled, we query NetworkSelectMode and update states of AutoSelect button.
+ mNetworkOperators.getNetworkSelectionMode();
}
@Override
@@ -216,23 +198,17 @@
}
}
- // This method is provided besides initialize() because bind to network query service
- // may be binded after initialize(). In that case this method needs to be called explicitly
- // to set mNetworkQueryService. Otherwise mNetworkQueryService will remain null.
- public void setNetworkQueryService(INetworkQueryService queryService) {
- mNetworkQueryService = queryService;
- }
-
// This initialize method needs to be called for this preference to work properly.
- protected void initialize(int subId, INetworkQueryService queryService,
- NetworkOperators networkOperators, ProgressDialog progressDialog) {
+ protected void initialize(int subId, NetworkOperators networkOperators,
+ ProgressDialog progressDialog) {
mSubId = subId;
- mNetworkQueryService = queryService;
mNetworkOperators = networkOperators;
// This preference should share the same progressDialog with networkOperators category.
mProgressDialog = progressDialog;
mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(mSubId);
+ mNetworkScanHelper = new NetworkScanHelper(
+ mTelephonyManager, mCallback, mNetworkScanExecutor);
setSummary(mTelephonyManager.getNetworkOperatorName());
@@ -246,79 +222,32 @@
}
private void destroy() {
- try {
- dismissProgressBar();
- } catch (IllegalArgumentException e) {
- loge("onDestroy: exception from dismissProgressBar " + e);
+ dismissProgressDialog();
+
+ if (mNetworkScanHelper != null) {
+ mNetworkScanHelper.stopNetworkQuery();
}
- try {
- if (mNetworkQueryService != null) {
- // used to un-register callback
- mNetworkQueryService.unregisterCallback(mCallback);
- }
- } catch (RemoteException e) {
- loge("onDestroy: exception from unregisterCallback " + e);
- }
+ mNetworkScanExecutor.shutdown();
}
private void displayEmptyNetworkList() {
- String status = getContext().getResources().getString(R.string.empty_networks_list);
-
- final PhoneGlobals app = PhoneGlobals.getInstance();
- app.notificationMgr.postTransientNotification(
- NotificationMgr.NETWORK_SELECTION_NOTIFICATION, status);
+ Toast.makeText(getContext(), R.string.empty_networks_list, Toast.LENGTH_LONG).show();
}
- private void displayNetworkSelectionInProgress() {
- showProgressDialog(DIALOG_NETWORK_SELECTION);
- }
-
- private void displayNetworkQueryFailed(int error) {
- String status = getContext().getResources().getString(R.string.network_query_error);
-
- try {
- dismissProgressBar();
- } catch (IllegalArgumentException e1) {
- // do nothing
- }
-
- final PhoneGlobals app = PhoneGlobals.getInstance();
- app.notificationMgr.postTransientNotification(
- NotificationMgr.NETWORK_SELECTION_NOTIFICATION, status);
+ private void displayNetworkQueryFailed() {
+ Toast.makeText(getContext(), R.string.network_query_error, Toast.LENGTH_LONG).show();
}
private void loadNetworksList() {
if (DBG) logd("load networks list...");
- try {
- if (mNetworkQueryService != null) {
- mNetworkQueryService.startNetworkQuery(
- mCallback, mSubId, false /* isIncrementalResult */);
- } else {
- displayNetworkQueryFailed(NetworkQueryService.QUERY_EXCEPTION);
- }
- } catch (RemoteException e) {
- loge("loadNetworksList: exception from startNetworkQuery " + e);
- displayNetworkQueryFailed(NetworkQueryService.QUERY_EXCEPTION);
- }
+ mNetworkScanHelper.startNetworkScan(
+ NetworkScanHelper.NETWORK_SCAN_TYPE_WAIT_FOR_ALL_RESULTS);
}
private void networksListLoaded() {
if (DBG) logd("networks list loaded");
- // update the state of the preferences.
- if (DBG) logd("hideProgressPanel");
-
- // Always try to dismiss the dialog because activity may
- // be moved to background after dialog is shown.
- try {
- dismissProgressBar();
- } catch (IllegalArgumentException e) {
- // It's not a error in following scenario, we just ignore it.
- // "Load list" dialog will not show, if NetworkQueryService is
- // connected after this activity is moved to background.
- loge("Fail to dismiss network load list dialog " + e);
- }
mNetworkOperators.getNetworkSelectionMode();
if (mCellInfoList != null) {
// create a preference for each item in the list.
@@ -346,9 +275,13 @@
}
}
- private void dismissProgressBar() {
+ private void dismissProgressDialog() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
- mProgressDialog.dismiss();
+ try {
+ mProgressDialog.dismiss();
+ } catch (IllegalArgumentException ex) {
+ loge("Can't close the progress dialog " + ex);
+ }
}
}
@@ -357,7 +290,7 @@
mProgressDialog = new ProgressDialog(getContext());
} else {
// Dismiss progress bar if it's showing now.
- dismissProgressBar();
+ dismissProgressDialog();
}
switch (id) {
diff --git a/src/com/android/phone/NetworkSelectSetting.java b/src/com/android/phone/NetworkSelectSetting.java
index 81e545e..c6e754c 100644
--- a/src/com/android/phone/NetworkSelectSetting.java
+++ b/src/com/android/phone/NetworkSelectSetting.java
@@ -17,17 +17,12 @@
import android.app.ActionBar;
import android.app.Activity;
-import android.content.ComponentName;
import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
-import android.os.IBinder;
import android.os.Message;
-import android.os.RemoteException;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
@@ -47,6 +42,7 @@
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.telephony.OperatorInfo;
+import com.android.phone.NetworkScanHelper.NetworkScanCallback;
import com.android.settingslib.utils.ThreadUtils;
import java.util.ArrayList;
@@ -54,6 +50,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
/**
* "Choose network" settings UI for the Phone app.
@@ -86,6 +84,8 @@
private TelephonyManager mTelephonyManager;
private List<String> mForbiddenPlmns;
private boolean mShow4GForLTE;
+ private NetworkScanHelper mNetworkScanHelper;
+ private final ExecutorService mNetworkScanExecutor = Executors.newFixedThreadPool(1);
private final Runnable mUpdateNetworkOperatorsRunnable = () -> {
updateNetworkOperatorsPreferenceCategory();
@@ -118,6 +118,8 @@
mStatusMessagePreference = new Preference(getContext());
mSelectedNetworkOperatorPreference = null;
mTelephonyManager = TelephonyManager.from(getContext()).createForSubscriptionId(mSubId);
+ mNetworkScanHelper = new NetworkScanHelper(
+ mTelephonyManager, mCallback, mNetworkScanExecutor);
try {
Context con = getActivity().createPackageContext("com.android.systemui", 0);
int id = con.getResources().getIdentifier("config_show4GForLTE",
@@ -173,7 +175,7 @@
@Override
protected void onPostExecute(List<String> result) {
mForbiddenPlmns = result;
- bindNetworkQueryService();
+ loadNetworksList();
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@@ -261,8 +263,6 @@
if (DBG) logd("onStop");
getView().removeCallbacks(mUpdateNetworkOperatorsRunnable);
stopNetworkQuery();
- // Unbind the NetworkQueryService
- unbindNetworkQueryService();
}
private final Handler mHandler = new Handler() {
@@ -321,52 +321,23 @@
private void loadNetworksList() {
if (DBG) logd("load networks list...");
setProgressBarVisible(true);
- try {
- if (mNetworkQueryService != null) {
- if (DBG) logd("start network query");
- mNetworkQueryService
- .startNetworkQuery(mCallback, mSubId, true /* is incremental result */);
- } else {
- if (DBG) logd("unable to start network query, mNetworkQueryService is null");
- addMessagePreference(R.string.network_query_error);
- }
- } catch (RemoteException e) {
- loge("loadNetworksList: exception from startNetworkQuery " + e);
- addMessagePreference(R.string.network_query_error);
- }
+ mNetworkScanHelper.startNetworkScan(
+ NetworkScanHelper.NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS);
}
- /**
- * This implementation of INetworkQueryServiceCallback is used to receive
- * callback notifications from the network query service.
- */
- private final INetworkQueryServiceCallback mCallback = new INetworkQueryServiceCallback.Stub() {
-
- /** Returns the scan results to the user, this callback will be called at lease one time. */
+ private final NetworkScanHelper.NetworkScanCallback mCallback = new NetworkScanCallback() {
public void onResults(List<CellInfo> results) {
if (DBG) logd("get scan results.");
Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_RESULTS, results);
msg.sendToTarget();
}
- /**
- * Informs the user that the scan has stopped.
- *
- * This callback will be called when the scan is finished or cancelled by the user.
- * The related NetworkScanRequest will be deleted after this callback.
- */
public void onComplete() {
if (DBG) logd("network scan completed.");
Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_COMPLETED);
msg.sendToTarget();
}
- /**
- * Informs the user that there is some error about the scan.
- *
- * This callback will be called whenever there is any error about the scan, and the scan
- * will be terminated. onComplete() will NOT be called.
- */
public void onError(int error) {
if (DBG) logd("get onError callback with error code: " + error);
Message msg = mHandler.obtainMessage(EVENT_NETWORK_SCAN_ERROR, error, 0 /* arg2 */);
@@ -374,9 +345,6 @@
}
};
- /**
- * Updates network operators from {@link INetworkQueryServiceCallback#onResults()}.
- */
private void updateNetworkOperators() {
if (DBG) logd("updateNetworkOperators");
if (getActivity() != null) {
@@ -581,66 +549,18 @@
return new ArrayList<>(map.values());
}
- /**
- * Service connection code for the NetworkQueryService.
- * Handles the work of binding to a local object so that we can make
- * the appropriate service calls.
- */
-
- /** Local service interface */
- private INetworkQueryService mNetworkQueryService = null;
- /** Flag indicating whether we have called bind on the service. */
- boolean mShouldUnbind;
-
- /** Service connection */
- private final ServiceConnection mNetworkQueryServiceConnection = new ServiceConnection() {
-
- /** Handle the task of binding the local object to the service */
- public void onServiceConnected(ComponentName className, IBinder service) {
- if (DBG) logd("connection created, binding local service.");
- mNetworkQueryService = ((NetworkQueryService.LocalBinder) service).getService();
- // Load the network list only when the service is well connected.
- loadNetworksList();
- }
-
- /** Handle the task of cleaning up the local binding */
- public void onServiceDisconnected(ComponentName className) {
- if (DBG) logd("connection disconnected, cleaning local binding.");
- mNetworkQueryService = null;
- }
- };
-
- private void bindNetworkQueryService() {
- if (DBG) logd("bindNetworkQueryService");
- getContext().bindService(new Intent(getContext(), NetworkQueryService.class).setAction(
- NetworkQueryService.ACTION_LOCAL_BINDER),
- mNetworkQueryServiceConnection, Context.BIND_AUTO_CREATE);
- mShouldUnbind = true;
- }
-
- private void unbindNetworkQueryService() {
- if (DBG) logd("unbindNetworkQueryService");
- if (mShouldUnbind) {
- if (DBG) logd("mShouldUnbind is true");
- // unbind the service.
- getContext().unbindService(mNetworkQueryServiceConnection);
- mShouldUnbind = false;
- }
- }
-
private void stopNetworkQuery() {
- // Stop the network query process
- try {
- if (mNetworkQueryService != null) {
- if (DBG) logd("Stop network query");
- mNetworkQueryService.stopNetworkQuery();
- mNetworkQueryService.unregisterCallback(mCallback);
- }
- } catch (RemoteException e) {
- loge("Exception from stopNetworkQuery " + e);
+ if (mNetworkScanHelper != null) {
+ mNetworkScanHelper.stopNetworkQuery();
}
}
+ @Override
+ public void onDestroy() {
+ mNetworkScanExecutor.shutdown();
+ super.onDestroy();
+ }
+
private void logd(String msg) {
Log.d(TAG, msg);
}