Fix race in TelephonyScanManager
TelephonyScanManager may sometimes encounter a race condition where Telephony sends it the first scan result before it has saved the returned scan ID. This causes a crash in the app that's requesting the scan. To fix this, synchronize on mScanInfo while requesting the network scan so that the handler in TelephonyScanManager will wait for the scan ID to be saved before processing the first message from Telephony. Bug: 142068098 Test: manual Change-Id: I0b2b4c6dc749e21641843818293941704ed870a6
This commit is contained in:
@@ -104,7 +104,7 @@ public final class TelephonyScanManager {
|
||||
|
||||
private final Looper mLooper;
|
||||
private final Messenger mMessenger;
|
||||
private SparseArray<NetworkScanInfo> mScanInfo = new SparseArray<NetworkScanInfo>();
|
||||
private final SparseArray<NetworkScanInfo> mScanInfo = new SparseArray<NetworkScanInfo>();
|
||||
|
||||
public TelephonyScanManager() {
|
||||
HandlerThread thread = new HandlerThread(TAG);
|
||||
@@ -204,14 +204,16 @@ public final class TelephonyScanManager {
|
||||
try {
|
||||
ITelephony telephony = getITelephony();
|
||||
if (telephony != null) {
|
||||
int scanId = telephony.requestNetworkScan(
|
||||
subId, request, mMessenger, new Binder(), callingPackage);
|
||||
if (scanId == INVALID_SCAN_ID) {
|
||||
Rlog.e(TAG, "Failed to initiate network scan");
|
||||
return null;
|
||||
synchronized (mScanInfo) {
|
||||
int scanId = telephony.requestNetworkScan(
|
||||
subId, request, mMessenger, new Binder(), callingPackage);
|
||||
if (scanId == INVALID_SCAN_ID) {
|
||||
Rlog.e(TAG, "Failed to initiate network scan");
|
||||
return null;
|
||||
}
|
||||
saveScanInfo(scanId, request, executor, callback);
|
||||
return new NetworkScan(scanId, subId);
|
||||
}
|
||||
saveScanInfo(scanId, request, executor, callback);
|
||||
return new NetworkScan(scanId, subId);
|
||||
}
|
||||
} catch (RemoteException ex) {
|
||||
Rlog.e(TAG, "requestNetworkScan RemoteException", ex);
|
||||
@@ -223,9 +225,7 @@ public final class TelephonyScanManager {
|
||||
|
||||
private void saveScanInfo(
|
||||
int id, NetworkScanRequest request, Executor executor, NetworkScanCallback callback) {
|
||||
synchronized (mScanInfo) {
|
||||
mScanInfo.put(id, new NetworkScanInfo(request, executor, callback));
|
||||
}
|
||||
mScanInfo.put(id, new NetworkScanInfo(request, executor, callback));
|
||||
}
|
||||
|
||||
private ITelephony getITelephony() {
|
||||
|
||||
Reference in New Issue
Block a user