From 0d9e55773d25685c3407614c13b8416c6c72faae Mon Sep 17 00:00:00 2001 From: yinxu Date: Thu, 15 Mar 2018 11:39:15 -0700 Subject: Use AsyncTask.SERIAL_EXECUTOR as the default executor for scan Because there will be multiple callbacks for each scan and they must be invoked with the same order as they are received by the platform, we should use AsyncTask.SERIAL_EXECUTOR instead of AsyncTask.THREAD_POOL_EXECUTOR as the default executor. This is a clean cherry-pick from: https://android-review.googlesource.com/#/c/platform/frameworks/base/+/640804/ Bug:74840070 Test: Unit Test, CTS Test Change-Id: I7333940dad38f7e400a4124486bdb21cea0d5220 Merged-in: I7333940dad38f7e400a4124486bdb21cea0d5220 (cherry picked from commit 2e8d5ed7768f905e77780c3d7e8a88d07e5d91b3) --- telephony/java/android/telephony/TelephonyManager.java | 7 +++++-- .../java/android/telephony/TelephonyScanManager.java | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index 7add893e3ff4..a138e81c6ffb 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -5465,7 +5465,10 @@ public class TelephonyManager { * app has carrier privileges (see {@link #hasCarrierPrivileges}). * * @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. * @return A NetworkScan obj which contains a callback which can be used to stop the scan. */ @@ -5491,7 +5494,7 @@ public class TelephonyManager { @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public NetworkScan requestNetworkScan( NetworkScanRequest request, TelephonyScanManager.NetworkScanCallback callback) { - return requestNetworkScan(request, AsyncTask.THREAD_POOL_EXECUTOR, callback); + return requestNetworkScan(request, AsyncTask.SERIAL_EXECUTOR, callback); } /** diff --git a/telephony/java/android/telephony/TelephonyScanManager.java b/telephony/java/android/telephony/TelephonyScanManager.java index 99e2db883e52..96ff33255b53 100644 --- a/telephony/java/android/telephony/TelephonyScanManager.java +++ b/telephony/java/android/telephony/TelephonyScanManager.java @@ -137,8 +137,10 @@ public final class TelephonyScanManager { for (int i = 0; i < parcelables.length; i++) { ci[i] = (CellInfo) parcelables[i]; } - executor.execute(() -> - callback.onResults((List) Arrays.asList(ci))); + executor.execute(() ->{ + Rlog.d(TAG, "onResults: " + ci.toString()); + callback.onResults((List) Arrays.asList(ci)); + }); } catch (Exception e) { Rlog.e(TAG, "Exception in networkscan callback onResults", e); } @@ -146,14 +148,20 @@ public final class TelephonyScanManager { case CALLBACK_SCAN_ERROR: try { final int errorCode = message.arg1; - executor.execute(() -> callback.onError(errorCode)); + executor.execute(() -> { + Rlog.d(TAG, "onError: " + errorCode); + callback.onError(errorCode); + }); } catch (Exception e) { Rlog.e(TAG, "Exception in networkscan callback onError", e); } break; case CALLBACK_SCAN_COMPLETE: try { - executor.execute(() -> callback.onComplete()); + executor.execute(() -> { + Rlog.d(TAG, "onComplete"); + callback.onComplete(); + }); mScanInfo.remove(message.arg2); } catch (Exception e) { Rlog.e(TAG, "Exception in networkscan callback onComplete", e); -- cgit v1.2.3-59-g8ed1b