Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4f4a1971 authored by yinxu's avatar yinxu
Browse files

Handles the RIL error from the CommandException

In RadioResponse.java, all the RIL errors will be converted into
CommandException and sent back to the caller with the callback message.
So the AsyncResult in the callback message of 'EVENT_START_NETWORK_SCAN_DONE'
and 'EVENT_START_NETWORK_SCAN_DONE' will either contains a NetworkScanResult
without any exception, or contains an exception without any NetworkScanResult.
So if there is any error when trying to start/stop a scan, the error
code must be extracted from the CommandException.

Cherry-picked cleanly from:
https://android-review.git.corp.google.com/#/c/415900/

Test: Telephony sanity tests
Merged-in: I9766b7fd530e9146e6d9867478ed79ad8f7ba1fc
Change-Id: I9766b7fd530e9146e6d9867478ed79ad8f7ba1fc
(cherry picked from commit a234d03c)
parent 9a0052ac
Loading
Loading
Loading
Loading
+51 −12
Original line number Original line Diff line number Diff line
@@ -237,6 +237,39 @@ public final class NetworkScanRequestTracker {
            }
            }
        }
        }


        private int commandExceptionErrorToScanError(CommandException.Error error) {
            switch (error) {
                case RADIO_NOT_AVAILABLE:
                    Log.e(TAG, "commandExceptionErrorToScanError: RADIO_NOT_AVAILABLE");
                    return NetworkScan.ERROR_MODEM_ERROR;
                case REQUEST_NOT_SUPPORTED:
                    Log.e(TAG, "commandExceptionErrorToScanError: REQUEST_NOT_SUPPORTED");
                    return NetworkScan.ERROR_UNSUPPORTED;
                case NO_MEMORY:
                    Log.e(TAG, "commandExceptionErrorToScanError: NO_MEMORY");
                    return NetworkScan.ERROR_MODEM_ERROR;
                case INTERNAL_ERR:
                    Log.e(TAG, "commandExceptionErrorToScanError: INTERNAL_ERR");
                    return NetworkScan.ERROR_MODEM_ERROR;
                case MODEM_ERR:
                    Log.e(TAG, "commandExceptionErrorToScanError: MODEM_ERR");
                    return NetworkScan.ERROR_MODEM_ERROR;
                case OPERATION_NOT_ALLOWED:
                    Log.e(TAG, "commandExceptionErrorToScanError: OPERATION_NOT_ALLOWED");
                    return NetworkScan.ERROR_MODEM_ERROR;
                case INVALID_ARGUMENTS:
                    Log.e(TAG, "commandExceptionErrorToScanError: INVALID_ARGUMENTS");
                    return NetworkScan.ERROR_INVALID_SCAN;
                case DEVICE_IN_USE:
                    Log.e(TAG, "commandExceptionErrorToScanError: DEVICE_IN_USE");
                    return NetworkScan.ERROR_MODEM_BUSY;
                default:
                    Log.e(TAG, "commandExceptionErrorToScanError: Unexpected CommandExceptionError "
                            +  error);
                    return NetworkScan.ERROR_RIL_ERROR;
            }
        }

        private void doStartScan(NetworkScanRequestInfo nsri) {
        private void doStartScan(NetworkScanRequestInfo nsri) {
            if (nsri == null) {
            if (nsri == null) {
                Log.e(TAG, "CMD_START_NETWORK_SCAN: nsri is null");
                Log.e(TAG, "CMD_START_NETWORK_SCAN: nsri is null");
@@ -272,17 +305,18 @@ public final class NetworkScanRequestTracker {
                return;
                return;
            }
            }
            if (ar.exception == null && ar.result != null) {
            if (ar.exception == null && ar.result != null) {
                NetworkScanResult nsr = (NetworkScanResult) ar.result;
                if (nsr.scanError == NetworkScan.SUCCESS) {
                // Register for the scan results if the scan started successfully.
                // Register for the scan results if the scan started successfully.
                nsri.mPhone.mCi.registerForNetworkScanResult(mHandler,
                nsri.mPhone.mCi.registerForNetworkScanResult(mHandler,
                        EVENT_RECEIVE_NETWORK_SCAN_RESULT, nsri);
                        EVENT_RECEIVE_NETWORK_SCAN_RESULT, nsri);
                } else {
                    deleteScanAndMayNotify(nsri, rilErrorToScanError(nsr.scanError), true);
                }
            } else {
            } else {
                logEmptyResultOrException(ar);
                logEmptyResultOrException(ar);
                deleteScanAndMayNotify(nsri, NetworkScan.ERROR_RIL_ERROR, true);
                if (ar.exception != null) {
                    CommandException.Error error =
                            ((CommandException) (ar.exception)).getCommandError();
                    deleteScanAndMayNotify(nsri, commandExceptionErrorToScanError(error), true);
                } else {
                    Log.wtf(TAG, "EVENT_START_NETWORK_SCAN_DONE: ar.exception can not be null!");
                }
            }
            }
        }
        }


@@ -342,11 +376,16 @@ public final class NetworkScanRequestTracker {
                return;
                return;
            }
            }
            if (ar.exception == null && ar.result != null) {
            if (ar.exception == null && ar.result != null) {
                NetworkScanResult nsr = (NetworkScanResult) ar.result;
                deleteScanAndMayNotify(nsri, NetworkScan.SUCCESS, true);
                deleteScanAndMayNotify(nsri, rilErrorToScanError(nsr.scanError), true);
            } else {
            } else {
                logEmptyResultOrException(ar);
                logEmptyResultOrException(ar);
                deleteScanAndMayNotify(nsri, NetworkScan.ERROR_RIL_ERROR, true);
                if (ar.exception != null) {
                    CommandException.Error error =
                            ((CommandException) (ar.exception)).getCommandError();
                    deleteScanAndMayNotify(nsri, commandExceptionErrorToScanError(error), true);
                } else {
                    Log.wtf(TAG, "EVENT_STOP_NETWORK_SCAN_DONE: ar.exception can not be null!");
                }
            }
            }
            nsri.mPhone.mCi.unregisterForNetworkScanResult(mHandler);
            nsri.mPhone.mCi.unregisterForNetworkScanResult(mHandler);
        }
        }
+6 −2
Original line number Original line Diff line number Diff line
@@ -1531,8 +1531,12 @@ public class RadioResponse extends IRadioResponse.Stub {
        RILRequest rr = mRil.processResponse(responseInfo);
        RILRequest rr = mRil.processResponse(responseInfo);


        if (rr != null) {
        if (rr != null) {
            NetworkScanResult nsr = new NetworkScanResult(0, responseInfo.error, null);
            NetworkScanResult nsr = null;
            if (responseInfo.error == RadioError.NONE) {
                nsr = new NetworkScanResult(
                        NetworkScanResult.SCAN_STATUS_PARTIAL, RadioError.NONE, null);
                sendMessageResponse(rr.mResult, nsr);
                sendMessageResponse(rr.mResult, nsr);
            }
            mRil.processResponseDone(rr, responseInfo, nsr);
            mRil.processResponseDone(rr, responseInfo, nsr);
        }
        }
    }
    }