Merge "Use AsyncTask.SERIAL_EXECUTOR as the default executor for scan" am: cdbf930883

am: a93e4124b5

Change-Id: I0f67a737f418d105658763e21974dc60216aee1a
This commit is contained in:
yinxu
2018-03-16 19:52:11 +00:00
committed by android-build-merger
2 changed files with 17 additions and 6 deletions

View File

@@ -5474,7 +5474,10 @@ public class TelephonyManager {
* app has carrier privileges (see {@link #hasCarrierPrivileges}). * app has carrier privileges (see {@link #hasCarrierPrivileges}).
* *
* @param request Contains all the RAT with bands/channels that need to be scanned. * @param request Contains all the RAT with bands/channels that need to be scanned.
* @param executor The executor through which the callback should be invoked. * @param executor The executor through which the callback should be invoked. Since the scan
* request may trigger multiple callbacks and they must be invoked in the same order as
* they are received by the platform, the user should provide an executor which executes
* tasks one at a time in serial order. For example AsyncTask.SERIAL_EXECUTOR.
* @param callback Returns network scan results or errors. * @param callback Returns network scan results or errors.
* @return A NetworkScan obj which contains a callback which can be used to stop the scan. * @return A NetworkScan obj which contains a callback which can be used to stop the scan.
*/ */
@@ -5500,7 +5503,7 @@ public class TelephonyManager {
@RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE)
public NetworkScan requestNetworkScan( public NetworkScan requestNetworkScan(
NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback) { NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback) {
return requestNetworkScan(request, AsyncTask.THREAD_POOL_EXECUTOR, callback); return requestNetworkScan(request, AsyncTask.SERIAL_EXECUTOR, callback);
} }
/** /**

View File

@@ -137,8 +137,10 @@ public final class TelephonyScanManager {
for (int i = 0; i < parcelables.length; i++) { for (int i = 0; i < parcelables.length; i++) {
ci[i] = (CellInfo) parcelables[i]; ci[i] = (CellInfo) parcelables[i];
} }
executor.execute(() -> executor.execute(() ->{
callback.onResults((List<CellInfo>) Arrays.asList(ci))); Rlog.d(TAG, "onResults: " + ci.toString());
callback.onResults((List<CellInfo>) Arrays.asList(ci));
});
} catch (Exception e) { } catch (Exception e) {
Rlog.e(TAG, "Exception in networkscan callback onResults", e); Rlog.e(TAG, "Exception in networkscan callback onResults", e);
} }
@@ -146,14 +148,20 @@ public final class TelephonyScanManager {
case CALLBACK_SCAN_ERROR: case CALLBACK_SCAN_ERROR:
try { try {
final int errorCode = message.arg1; final int errorCode = message.arg1;
executor.execute(() -> callback.onError(errorCode)); executor.execute(() -> {
Rlog.d(TAG, "onError: " + errorCode);
callback.onError(errorCode);
});
} catch (Exception e) { } catch (Exception e) {
Rlog.e(TAG, "Exception in networkscan callback onError", e); Rlog.e(TAG, "Exception in networkscan callback onError", e);
} }
break; break;
case CALLBACK_SCAN_COMPLETE: case CALLBACK_SCAN_COMPLETE:
try { try {
executor.execute(() -> callback.onComplete()); executor.execute(() -> {
Rlog.d(TAG, "onComplete");
callback.onComplete();
});
mScanInfo.remove(message.arg2); mScanInfo.remove(message.arg2);
} catch (Exception e) { } catch (Exception e) {
Rlog.e(TAG, "Exception in networkscan callback onComplete", e); Rlog.e(TAG, "Exception in networkscan callback onComplete", e);