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

Commit 2d073a09 authored by Thomas Nguyen's avatar Thomas Nguyen Committed by Automerger Merge Worker
Browse files

Add implementation of SatelliteSessionController am: fd3cb835

parents f461ef44 fd3cb835
Loading
Loading
Loading
Loading
+91 −43
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ import android.telephony.satellite.SatelliteDatagram;
import android.telephony.satellite.SatelliteManager;
import android.util.Log;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.IIntegerConsumer;
@@ -96,7 +95,7 @@ public class SatelliteController extends Handler {
    @NonNull private static SatelliteController sInstance;
    @NonNull private final Context mContext;
    @NonNull private final SatelliteModemInterface mSatelliteModemInterface;
    @NonNull private final SatelliteSessionController mSatelliteSessionController;
    @NonNull private SatelliteSessionController mSatelliteSessionController;
    @NonNull private final PointingAppController mPointingAppController;
    @NonNull private final DatagramController mDatagramController;
    private final CommandsInterface mCi;
@@ -127,6 +126,9 @@ public class SatelliteController extends Handler {
    private final Object mIsSatelliteSupportedLock = new Object();
    private final ResultReceiver mSatelliteSupportedReceiver;
    private boolean mIsDemoModeEnabled = false;
    private Boolean mIsSatelliteEnabled = null;
    private final Object mIsSatelliteEnabledLock = new Object();
    private final ResultReceiver mSatelliteEnabledReceiver;
    private boolean mNeedsSatellitePointing = false;
    private final Object mNeedsSatellitePointingLock = new Object();

@@ -159,7 +161,7 @@ public class SatelliteController extends Handler {
     * @param context The Context for the SatelliteController.
     * @param looper The looper for the handler. It does not run on main thread.
     */
    @VisibleForTesting
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected SatelliteController(@NonNull Context context, @NonNull Looper looper) {
        super(looper);
        mContext = context;
@@ -169,10 +171,6 @@ public class SatelliteController extends Handler {
        // to the satellite service and HAL interface.
        mSatelliteModemInterface = SatelliteModemInterface.make(mContext);

        // Create the SatelliteSessionController singleton,
        // which is used to manage all the data during a satellite session.
        mSatelliteSessionController = SatelliteSessionController.make(mContext);

        // Create the PointingUIController singleton,
        // which is used to manage interactions with PointingUI app.
        mPointingAppController = PointingAppController.make(mContext);
@@ -181,22 +179,8 @@ public class SatelliteController extends Handler {
        // which is used to send and receive satellite datagrams.
        mDatagramController = DatagramController.make(mContext, looper);

        mSatelliteSupportedReceiver = new ResultReceiver(this) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
                        && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
                    synchronized (mIsSatelliteSupportedLock) {
                        mIsSatelliteSupported = resultData.getBoolean(
                                SatelliteManager.KEY_SATELLITE_SUPPORTED);
                    }
                } else {
                    synchronized (mIsSatelliteSupportedLock) {
                        mIsSatelliteSupported = null;
                    }
                }
            }
        };
        mSatelliteEnabledReceiver = createSatelliteEnabledResultReceiver();
        mSatelliteSupportedReceiver = createSatelliteSupportedResultReceiver(looper);
        //TODO: reenable below code
        //requestIsSatelliteSupported(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
        //        mSatelliteSupportedReceiver);
@@ -356,13 +340,6 @@ public class SatelliteController extends Handler {
                    int state = (int) ar.result;
                    logd("Received EVENT_SATELLITE_MODEM_STATE_CHANGE for subId=" + mSubId
                            + ", state=" + state);
                    mListeners.values().forEach(listener -> {
                        try {
                            listener.onSatelliteModemStateChanged(state);
                        } catch (RemoteException e) {
                            logd("EVENT_SATELLITE_MODEM_STATE_CHANGE RemoteException: " + e);
                        }
                    });
                    break;
                }
                case EVENT_PENDING_DATAGRAMS: {
@@ -544,6 +521,8 @@ public class SatelliteController extends Handler {
                        mPointingAppController.startPointingUI(false);
                    }
                    mIsDemoModeEnabled = argument.enableDemoMode;
                    updateSatelliteEnabledState(
                            argument.enableSatellite, "EVENT_SET_SATELLITE_ENABLED_DONE");
                }
                argument.callback.accept(error);
                // TODO: if error is ERROR_NONE, request satellite capabilities
@@ -624,10 +603,6 @@ public class SatelliteController extends Handler {
                            mIsSatelliteSupported = supported;
                        }
                    }
                } else {
                    synchronized (mIsSatelliteSupportedLock) {
                        mIsSatelliteSupported = null;
                    }
                }
                ((ResultReceiver) request.argument).send(error, bundle);
                break;
@@ -866,8 +841,17 @@ public class SatelliteController extends Handler {
            return;
        }

        Phone phone = SatelliteServiceUtils.getPhone();
        sendRequest(CMD_IS_SATELLITE_ENABLED, result, phone);
        synchronized (mIsSatelliteEnabledLock) {
            if (mIsSatelliteEnabled != null) {
                /* We have already successfully queried the satellite modem. */
                Bundle bundle = new Bundle();
                bundle.putBoolean(SatelliteManager.KEY_SATELLITE_ENABLED, mIsSatelliteEnabled);
                result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
                return;
            }
        }

        sendRequest(CMD_IS_SATELLITE_ENABLED, result, SatelliteServiceUtils.getPhone());
    }

    /**
@@ -908,13 +892,12 @@ public class SatelliteController extends Handler {
                /* We have already successfully queried the satellite modem. */
                Bundle bundle = new Bundle();
                bundle.putBoolean(SatelliteManager.KEY_SATELLITE_SUPPORTED, mIsSatelliteSupported);
                result.send(SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE, bundle);
                result.send(SatelliteManager.SATELLITE_ERROR_NONE, bundle);
                return;
            }
        }

        Phone phone = SatelliteServiceUtils.getPhone();
        sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, phone);
        sendRequestAsync(CMD_IS_SATELLITE_SUPPORTED, result, SatelliteServiceUtils.getPhone());
    }

    /**
@@ -1163,9 +1146,15 @@ public class SatelliteController extends Handler {
     */
    @SatelliteManager.SatelliteError public int registerForSatelliteModemStateChanged(int subId,
            @NonNull ISatelliteStateCallback callback) {
        final int validSubId = SatelliteServiceUtils.getValidSatelliteSubId(subId, mContext);
        Phone phone = SatelliteServiceUtils.getPhone();
        if (mSatelliteSessionController != null) {
            mSatelliteSessionController.registerForSatelliteModemStateChanged(callback);
        } else {
            loge("registerForSatelliteModemStateChanged: mSatelliteSessionController"
                    + " is not initialized yet");
            return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
        }

        final int validSubId = SatelliteServiceUtils.getValidSatelliteSubId(subId, mContext);
        SatelliteStateListenerHandler satelliteStateListenerHandler =
                mSatelliteStateListenerHandlers.get(validSubId);
        if (satelliteStateListenerHandler == null) {
@@ -1178,6 +1167,12 @@ public class SatelliteController extends Handler {
                mSatelliteModemInterface.registerForPendingDatagrams(satelliteStateListenerHandler,
                        SatelliteStateListenerHandler.EVENT_PENDING_DATAGRAMS, null);
            } else {
                Phone phone = SatelliteServiceUtils.getPhone();
                if (phone == null) {
                    loge("registerForSatelliteModemStateChanged: satellite phone is "
                            + "not initialized yet");
                    return SatelliteManager.SATELLITE_INVALID_TELEPHONY_STATE;
                }
                phone.registerForSatelliteModemStateChanged(satelliteStateListenerHandler,
                        SatelliteStateListenerHandler.EVENT_SATELLITE_MODEM_STATE_CHANGE, null);
                phone.registerForPendingDatagramCount(satelliteStateListenerHandler,
@@ -1218,6 +1213,13 @@ public class SatelliteController extends Handler {
                }
            }
        }

        if (mSatelliteSessionController != null) {
            mSatelliteSessionController.unregisterForSatelliteModemStateChanged(callback);
        } else {
            loge("registerForSatelliteModemStateChanged: mSatelliteSessionController"
                    + " is not initialized yet");
        }
    }

    /**
@@ -1504,7 +1506,7 @@ public class SatelliteController extends Handler {
     * @param subId The subscription id.
     * @return true if satellite is provisioned on the given subscription else return false.
     */
    @VisibleForTesting
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected boolean isSatelliteProvisioned(int subId) {
        final long identity = Binder.clearCallingIdentity();
        try {
@@ -1550,6 +1552,52 @@ public class SatelliteController extends Handler {
        }
    }

    private ResultReceiver createSatelliteSupportedResultReceiver(@NonNull Looper looper) {
        return new ResultReceiver(this) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
                        && resultData.containsKey(SatelliteManager.KEY_SATELLITE_SUPPORTED)) {
                    synchronized (mIsSatelliteSupportedLock) {
                        mIsSatelliteSupported = resultData.getBoolean(
                                SatelliteManager.KEY_SATELLITE_SUPPORTED);
                    }
                }
                mSatelliteSessionController = SatelliteSessionController.make(mContext, looper,
                        mIsSatelliteSupported != null ? mIsSatelliteSupported : false);
                if (mIsSatelliteSupported != null && mIsSatelliteSupported) {
                    requestIsSatelliteEnabled(SubscriptionManager.DEFAULT_SUBSCRIPTION_ID,
                            mSatelliteEnabledReceiver);
                }
            }
        };
    }

    private ResultReceiver createSatelliteEnabledResultReceiver() {
        return new ResultReceiver(this) {
            @Override
            protected void onReceiveResult(int resultCode, Bundle resultData) {
                if (resultCode == SatelliteManager.SATELLITE_ERROR_NONE
                        && resultData.containsKey(SatelliteManager.KEY_SATELLITE_ENABLED)) {
                    updateSatelliteEnabledState(resultData.getBoolean(
                            SatelliteManager.KEY_SATELLITE_ENABLED),
                            "SatelliteEnabledResultReceiver.onReceiveResult");
                }
            }
        };
    }

    private void updateSatelliteEnabledState(boolean enabled, String caller) {
        synchronized (mIsSatelliteEnabledLock) {
            mIsSatelliteEnabled = enabled;
        }
        if (mSatelliteSessionController != null) {
            mSatelliteSessionController.onSatelliteEnabledStateChanged(enabled);
        } else {
            loge(caller + ": mSatelliteSessionController is not initialized yet");
        }
    }

    private static void logd(@NonNull String log) {
        Rlog.d(TAG, log);
    }
+25 −10
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.telephony.satellite.stub.SatelliteService;
import android.text.TextUtils;
import android.util.Pair;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.ExponentialBackoff;
import com.android.internal.telephony.IBooleanConsumer;
import com.android.internal.telephony.IIntegerConsumer;
@@ -59,7 +60,8 @@ public class SatelliteModemInterface {

    @NonNull private static SatelliteModemInterface sInstance;
    @NonNull private final Context mContext;
    @NonNull private final ExponentialBackoff mExponentialBackoff;
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    @NonNull protected final ExponentialBackoff mExponentialBackoff;
    @NonNull private final Object mLock = new Object();
    /**
     * {@code true} to use the vendor satellite service and {@code false} to use the HAL.
@@ -161,7 +163,8 @@ public class SatelliteModemInterface {
     * @param context The Context for the SatelliteModemInterface.
     * @param looper The Looper to run binding retry on.
     */
    private SatelliteModemInterface(@NonNull Context context, @NonNull Looper looper) {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected SatelliteModemInterface(@NonNull Context context, @NonNull Looper looper) {
        mContext = context;
        mExponentialBackoff = new ExponentialBackoff(REBIND_INITIAL_DELAY, REBIND_MAXIMUM_DELAY,
                REBIND_MULTIPLIER, looper, () -> {
@@ -198,7 +201,8 @@ public class SatelliteModemInterface {
                com.android.internal.R.string.config_satellite_service_package));
    }

    private void bindService() {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected void bindService() {
        synchronized (mLock) {
            if (mIsBinding || mIsBound) return;
            mIsBinding = true;
@@ -241,7 +245,8 @@ public class SatelliteModemInterface {
        }
    }

    private void unbindService() {
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected void unbindService() {
        disconnectSatelliteService();
        mContext.unbindService(mSatelliteServiceConnection);
        mSatelliteServiceConnection = null;
@@ -427,7 +432,7 @@ public class SatelliteModemInterface {
     * @param message The Message to send to result of the operation to.
     */
    public void requestSatelliteListeningEnabled(boolean enable, int timeout,
            @NonNull Message message) {
            @Nullable Message message) {
        if (mSatelliteService != null) {
            try {
                mSatelliteService.requestSatelliteListeningEnabled(enable, timeout,
@@ -436,17 +441,26 @@ public class SatelliteModemInterface {
                            public void accept(int result) {
                                int error = SatelliteServiceUtils.fromSatelliteError(result);
                                logd("requestSatelliteListeningEnabled: " + error);
                                Binder.withCleanCallingIdentity(() ->
                                        sendMessageWithResult(message, null, error));
                                Binder.withCleanCallingIdentity(() -> {
                                    if (message != null) {
                                        sendMessageWithResult(message, null, error);
                                    }
                                });
                            }
                        });
            } catch (RemoteException e) {
                loge("requestSatelliteListeningEnabled: RemoteException " + e);
                sendMessageWithResult(message, null, SatelliteManager.SATELLITE_SERVICE_ERROR);
                if (message != null) {
                    sendMessageWithResult(
                            message, null, SatelliteManager.SATELLITE_SERVICE_ERROR);
                }
            }
        } else {
            loge("requestSatelliteListeningEnabled: Satellite service is unavailable.");
            sendMessageWithResult(message, null, SatelliteManager.SATELLITE_REQUEST_NOT_SUPPORTED);
            if (message != null) {
                sendMessageWithResult(message, null,
                        SatelliteManager.SATELLITE_REQUEST_NOT_SUPPORTED);
            }
        }
    }

@@ -935,7 +949,8 @@ public class SatelliteModemInterface {
        return mIsSatelliteServiceSupported;
    }

    private static void sendMessageWithResult(@NonNull Message message, @Nullable Object result,
    @VisibleForTesting(visibility = VisibleForTesting.Visibility.PRIVATE)
    protected static void sendMessageWithResult(@NonNull Message message, @Nullable Object result,
            @SatelliteManager.SatelliteError int error) {
        SatelliteException exception = error == SatelliteManager.SATELLITE_ERROR_NONE
                ? null : new SatelliteException(error);
+404 −18

File changed.

Preview size limit exceeded, changes collapsed.

+468 −0

File added.

Preview size limit exceeded, changes collapsed.