[ManualNetworkSelect] Improve error handling

1. [batch mode] Support graceful app stop behavior
   Avoid thread crash when UI abort the request.
2. [incremental mode] Stop search UI earlier when error during API access
   Generate error instead of keeping UI in progressing
   when fail to access Telephony API

Bug: 139398483
Bug: 140448617
Test: atest NetworkScanHelperTest
Change-Id: I429f3aa2ef692c27100514faa413b16dbd2459d7
This commit is contained in:
Bonian Chen
2019-09-23 11:29:54 +08:00
committed by Andy Chou
parent fe790ec76d
commit 1b64578f3c
2 changed files with 248 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ import com.google.common.util.concurrent.SettableFuture;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.Executor;
import java.util.stream.Collectors;
@@ -177,6 +178,9 @@ public class NetworkScanHelper {
@Override
public void onFailure(Throwable t) {
if (t instanceof CancellationException) {
return;
}
int errCode = Integer.parseInt(t.getMessage());
onError(errCode);
}
@@ -184,10 +188,16 @@ public class NetworkScanHelper {
mExecutor.execute(new NetworkScanSyncTask(
mTelephonyManager, (SettableFuture) mNetworkScanFuture));
} else if (type == NETWORK_SCAN_TYPE_INCREMENTAL_RESULTS) {
if (mNetworkScanRequester != null) {
return;
}
mNetworkScanRequester = mTelephonyManager.requestNetworkScan(
NETWORK_SCAN_REQUEST,
mExecutor,
mInternalNetworkScanCallback);
if (mNetworkScanRequester == null) {
onError(NetworkScan.ERROR_RADIO_INTERFACE_ERROR);
}
}
}
@@ -199,7 +209,7 @@ public class NetworkScanHelper {
public void stopNetworkQuery() {
if (mNetworkScanRequester != null) {
mNetworkScanRequester.stopScan();
mNetworkScanFuture = null;
mNetworkScanRequester = null;
}
if (mNetworkScanFuture != null) {