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

Commit 0320efdd authored by Thomas Nguyen's avatar Thomas Nguyen Committed by Android (Google) Code Review
Browse files

Merge "Cleaning up resources when satellite vendor service or modem crashes" into udc-dev

parents e7969714 c07ef505
Loading
Loading
Loading
Loading
+29 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.content.Context;
import android.content.Context;
import android.os.Looper;
import android.os.Looper;
import android.telephony.Rlog;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;
import android.telephony.satellite.ISatelliteDatagramCallback;
import android.telephony.satellite.ISatelliteDatagramCallback;
import android.telephony.satellite.SatelliteDatagram;
import android.telephony.satellite.SatelliteDatagram;
import android.telephony.satellite.SatelliteManager;
import android.telephony.satellite.SatelliteManager;
@@ -223,6 +224,34 @@ public class DatagramController {
        return mReceivePendingCount;
        return mReceivePendingCount;
    }
    }


    /**
     * This function is used by {@link SatelliteController} to notify {@link DatagramController}
     * that satellite modem state has changed.
     *
     * @param state Current satellite modem state.
     */
    public void onSatelliteModemStateChanged(@SatelliteManager.SatelliteModemState int state) {
        if (state == SatelliteManager.SATELLITE_MODEM_STATE_OFF
                || state == SatelliteManager.SATELLITE_MODEM_STATE_UNAVAILABLE) {
            logd("onSatelliteModemStateChanged: cleaning up resources");
            cleanUpResources();
        }
        mDatagramDispatcher.onSatelliteModemStateChanged(state);
    }

    private void cleanUpResources() {
        if (mReceiveDatagramTransferState
                == SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_RECEIVING) {
            updateReceiveStatus(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                    SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_RECEIVE_FAILED,
                    mReceivePendingCount,
                    SatelliteManager.SATELLITE_REQUEST_ABORTED);
        }
        updateReceiveStatus(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_IDLE, 0,
                SatelliteManager.SATELLITE_ERROR_NONE);
    }

    private void notifyDatagramTransferStateChangedToSessionController() {
    private void notifyDatagramTransferStateChangedToSessionController() {
        SatelliteSessionController sessionController = SatelliteSessionController.getInstance();
        SatelliteSessionController sessionController = SatelliteSessionController.getInstance();
        if (sessionController == null) {
        if (sessionController == null) {
+41 −8
Original line number Original line Diff line number Diff line
@@ -26,6 +26,7 @@ import android.os.Handler;
import android.os.Looper;
import android.os.Looper;
import android.os.Message;
import android.os.Message;
import android.telephony.Rlog;
import android.telephony.Rlog;
import android.telephony.SubscriptionManager;
import android.telephony.satellite.SatelliteDatagram;
import android.telephony.satellite.SatelliteDatagram;
import android.telephony.satellite.SatelliteManager;
import android.telephony.satellite.SatelliteManager;


@@ -277,7 +278,8 @@ public class DatagramDispatcher extends Handler {
                        // Abort sending all the pending datagrams
                        // Abort sending all the pending datagrams
                        mControllerMetricsStats.reportOutgoingDatagramFailCount(
                        mControllerMetricsStats.reportOutgoingDatagramFailCount(
                                argument.datagramType);
                                argument.datagramType);
                        abortSendingPendingDatagrams(argument.subId, error);
                        abortSendingPendingDatagrams(argument.subId,
                                SatelliteManager.SATELLITE_REQUEST_ABORTED);
                    }
                    }
                }
                }
                break;
                break;
@@ -365,6 +367,8 @@ public class DatagramDispatcher extends Handler {


    /**
    /**
     * Send error code to all the pending datagrams
     * Send error code to all the pending datagrams
     *
     * @param pendingDatagramsMap The pending datagrams map to be cleaned up.
     * @param errorCode error code to be returned.
     * @param errorCode error code to be returned.
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mLock")
@@ -374,6 +378,7 @@ public class DatagramDispatcher extends Handler {
        if (pendingDatagramsMap.size() == 0) {
        if (pendingDatagramsMap.size() == 0) {
            return;
            return;
        }
        }
        loge("sendErrorCodeAndCleanupPendingDatagrams: cleaning up resources");


        // Send error code to all the pending datagrams
        // Send error code to all the pending datagrams
        for (Entry<Long, SendSatelliteDatagramArgument> entry :
        for (Entry<Long, SendSatelliteDatagramArgument> entry :
@@ -391,17 +396,15 @@ public class DatagramDispatcher extends Handler {
    /**
    /**
     * Abort sending all the pending datagrams.
     * Abort sending all the pending datagrams.
     *
     *
     * @param subId the subId of the subscription used to send datagram
     * @param subId The subId of the subscription used to send datagram
     * @param error error that resulted in abort.
     * @param errorCode The error code that resulted in abort.
     */
     */
    @GuardedBy("mLock")
    @GuardedBy("mLock")
    private void abortSendingPendingDatagrams(int subId,
    private void abortSendingPendingDatagrams(int subId,
            @SatelliteManager.SatelliteError int error) {
            @SatelliteManager.SatelliteError int errorCode) {
        logd("abortSendingPendingDatagrams()");
        logd("abortSendingPendingDatagrams()");
        sendErrorCodeAndCleanupPendingDatagrams(mPendingEmergencyDatagramsMap,
        sendErrorCodeAndCleanupPendingDatagrams(mPendingEmergencyDatagramsMap, errorCode);
                SatelliteManager.SATELLITE_REQUEST_ABORTED);
        sendErrorCodeAndCleanupPendingDatagrams(mPendingNonEmergencyDatagramsMap, errorCode);
        sendErrorCodeAndCleanupPendingDatagrams(mPendingNonEmergencyDatagramsMap,
                SatelliteManager.SATELLITE_REQUEST_ABORTED);
    }
    }


    /**
    /**
@@ -447,6 +450,36 @@ public class DatagramDispatcher extends Handler {
        sInstance = null;
        sInstance = null;
    }
    }


    /**
     * This function is used by {@link DatagramController} to notify {@link DatagramDispatcher}
     * that satellite modem state has changed.
     *
     * @param state Current satellite modem state.
     */
    public void onSatelliteModemStateChanged(@SatelliteManager.SatelliteModemState int state) {
        if (state == SatelliteManager.SATELLITE_MODEM_STATE_OFF
                || state == SatelliteManager.SATELLITE_MODEM_STATE_UNAVAILABLE) {
            logd("onSatelliteModemStateChanged: cleaning up resources");
            cleanUpResources();
        }
    }

    private void cleanUpResources() {
        synchronized (mLock) {
            mSendingDatagramInProgress = false;
            if (getPendingDatagramCount() > 0) {
                mDatagramController.updateSendStatus(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                        SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_SEND_FAILED,
                        getPendingDatagramCount(), SatelliteManager.SATELLITE_REQUEST_ABORTED);
            }
            mDatagramController.updateSendStatus(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                    SatelliteManager.SATELLITE_DATAGRAM_TRANSFER_STATE_IDLE,
                    0, SatelliteManager.SATELLITE_ERROR_NONE);
            abortSendingPendingDatagrams(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                    SatelliteManager.SATELLITE_REQUEST_ABORTED);
        }
    }

    private static void logd(@NonNull String log) {
    private static void logd(@NonNull String log) {
        Rlog.d(TAG, log);
        Rlog.d(TAG, log);
    }
    }
+17 −12
Original line number Original line Diff line number Diff line
@@ -512,7 +512,7 @@ public class SatelliteController extends Handler {
                        updateSatelliteEnabledState(enabled, "EVENT_IS_SATELLITE_ENABLED_DONE");
                        updateSatelliteEnabledState(enabled, "EVENT_IS_SATELLITE_ENABLED_DONE");
                    }
                    }
                } else if (error == SatelliteManager.SATELLITE_REQUEST_NOT_SUPPORTED) {
                } else if (error == SatelliteManager.SATELLITE_REQUEST_NOT_SUPPORTED) {
                    updateSatelliteSupportedState(false);
                    updateSatelliteSupportedStateWhenSatelliteServiceConnected(false);
                }
                }
                ((ResultReceiver) request.argument).send(error, bundle);
                ((ResultReceiver) request.argument).send(error, bundle);
                break;
                break;
@@ -550,7 +550,7 @@ public class SatelliteController extends Handler {
                        boolean supported = (boolean) ar.result;
                        boolean supported = (boolean) ar.result;
                        if (DBG) logd("isSatelliteSupported: " + supported);
                        if (DBG) logd("isSatelliteSupported: " + supported);
                        bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
                        bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, supported);
                        updateSatelliteSupportedState(supported);
                        updateSatelliteSupportedStateWhenSatelliteServiceConnected(supported);
                    }
                    }
                }
                }
                ((ResultReceiver) request.argument).send(error, bundle);
                ((ResultReceiver) request.argument).send(error, bundle);
@@ -1481,8 +1481,11 @@ public class SatelliteController extends Handler {
     * {@link SatelliteController} that the satellite vendor service was just connected.
     * {@link SatelliteController} that the satellite vendor service was just connected.
     * <p>
     * <p>
     * {@link SatelliteController} will send requests to satellite modem to check whether it support
     * {@link SatelliteController} will send requests to satellite modem to check whether it support
     * satellite, whether it is powered on, and whether it is provisioned.
     * satellite and whether it is provisioned. {@link SatelliteController} will use these cached
     * {@link SatelliteController} will use these cached values to serve requests from its clients.
     * values to serve requests from its clients.
     * <p>
     * Because satellite vendor service might have just come back from a crash, we need to disable
     * the satellite modem so that resources will be cleaned up and internal states will be reset.
     */
     */
    void onSatelliteServiceConnected() {
    void onSatelliteServiceConnected() {
        if (mSatelliteModemInterface.isSatelliteServiceSupported()) {
        if (mSatelliteModemInterface.isSatelliteServiceSupported()) {
@@ -1684,7 +1687,7 @@ public class SatelliteController extends Handler {
        }
        }
    }
    }


    private void updateSatelliteSupportedState(boolean supported) {
    private void updateSatelliteSupportedStateWhenSatelliteServiceConnected(boolean supported) {
        synchronized (mIsSatelliteSupportedLock) {
        synchronized (mIsSatelliteSupportedLock) {
            mIsSatelliteSupported = supported;
            mIsSatelliteSupported = supported;
        }
        }
@@ -1695,18 +1698,19 @@ public class SatelliteController extends Handler {
            registerForPendingDatagramCount();
            registerForPendingDatagramCount();
            registerForSatelliteModemStateChanged();
            registerForSatelliteModemStateChanged();


            requestIsSatelliteEnabled(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                    new ResultReceiver(this) {
                        @Override
                        protected void onReceiveResult(int resultCode, Bundle resultData) {
                            logd("requestIsSatelliteEnabled: resultCode=" + resultCode);
                        }
                    });
            requestIsSatelliteProvisioned(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
            requestIsSatelliteProvisioned(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                    new ResultReceiver(this) {
                    new ResultReceiver(this) {
                        @Override
                        @Override
                        protected void onReceiveResult(int resultCode, Bundle resultData) {
                        protected void onReceiveResult(int resultCode, Bundle resultData) {
                            logd("requestIsSatelliteProvisioned: resultCode=" + resultCode);
                            logd("requestIsSatelliteProvisioned: resultCode=" + resultCode);
                            requestSatelliteEnabled(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                                    false, false,
                                    new IIntegerConsumer.Stub() {
                                        @Override
                                        public void accept(int result) {
                                            logd("requestSatelliteEnabled: result=" + result);
                                        }
                                    });
                        }
                        }
                    });
                    });
            requestSatelliteCapabilities(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
            requestSatelliteCapabilities(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
@@ -1861,6 +1865,7 @@ public class SatelliteController extends Handler {
            updateSatelliteEnabledState(
            updateSatelliteEnabledState(
                    false, "handleEventSatelliteModemStateChanged");
                    false, "handleEventSatelliteModemStateChanged");
        }
        }
        mDatagramController.onSatelliteModemStateChanged(state);
    }
    }


    private static void logd(@NonNull String log) {
    private static void logd(@NonNull String log) {