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

Commit e26c107b authored by Sooraj Sasindran's avatar Sooraj Sasindran Committed by Android (Google) Code Review
Browse files

Merge "Update satellite callbacks and APIs"

parents 051c79a2 325b6dd1
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -16,19 +16,16 @@

package android.telephony.satellite;

import android.telephony.satellite.PointingInfo;
import android.telephony.satellite.SatelliteDatagram;

/**
 * Interface for satellite state listener.
 * Interface for satellite datagrams callback.
 * @hide
 */
oneway interface ISatelliteStateListener {
    void onSatelliteProvisionStateChanged(in boolean provisioned);
    void onSatellitePositionUpdate(in PointingInfo pointingInfo);
    void onMessageTransferStateUpdate(in int state, in int sendPendingCount,
            in int receivePendingCount, in int errorCode);
    void onSatelliteModemStateChange(in int state);
    void onPendingDatagramCount(in int count);
oneway interface ISatelliteDatagramCallback {
    /**
     * Called when there are incoming datagrams to be received.
     * @param datagrams Array of datagrams to be received over satellite.
     */
    void onSatelliteDatagrams(in SatelliteDatagram[] datagrams);
}
+43 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telephony.satellite;

import android.telephony.satellite.PointingInfo;

/**
 * Interface for position update and datagram transfer state change callback.
 * @hide
 */
oneway interface ISatellitePositionUpdateCallback {
    /**
     * Called when satellite datagram transfer state changes.
     *
     * @param state The new datagram transfer state.
     * @param sendPendingCount The number of datagrams that are currently being sent.
     * @param receivePendingCount The number of datagrams that are currently being received.
     * @param errorCode If datagram transfer failed, the reason for failure.
     */
    void onDatagramTransferStateUpdate(in int state, in int sendPendingCount,
            in int receivePendingCount, in int errorCode);

    /**
     * Called when the satellite position changes.
     *
     * @param pointingInfo The pointing info containing the satellite location.
     */
    void onSatellitePositionUpdate(in PointingInfo pointingInfo);
}
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telephony.satellite;

/**
 * Interface for satellite provision state callback.
 * @hide
 */
oneway interface ISatelliteProvisionStateCallback {
    /**
     * Indicates that the satellite provision state has changed.
     *
     * @param provisioned True means the service is provisioned and false means it is not.
     */
    void onSatelliteProvisionStateChanged(in boolean provisioned);
}
+37 −0
Original line number Diff line number Diff line
/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telephony.satellite;

/**
 * Interface for satellite state change callback.
 * @hide
 */
oneway interface ISatelliteStateCallback {
    /**
     * Indicates that the satellite has pending datagrams for the device to be pulled.
     *
     * @param count Number of pending datagrams.
     */
    void onPendingDatagramCount(in int count);

    /**
     * Indicates that the satellite modem state has changed.
     *
     * @param state The current satellite modem state.
     */
    void onSatelliteModemStateChange(in int state);
}
+0 −193
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.telephony.satellite;

import android.annotation.NonNull;
import android.os.Binder;

import java.lang.ref.WeakReference;
import java.util.concurrent.Executor;

/**
 * A callback class for monitoring changes in specific satellite service states on the device,
 * including provision state, position update, message transfer state and others.
 * <p>
 * To register a callback, use a {@link SatelliteCallback} which implements the interested
 * interfaces. For example,
 * FakeSatelliteProvisionStateCallback extends {@link SatelliteCallback} implements
 * {@link SatelliteCallback.SatelliteProvisionStateListener}.
 * <p>
 * Then override the methods for the state that you wish to receive updates for, and
 * pass your SatelliteCallback object to the corresponding register function like
 * {@link SatelliteManager#registerForSatelliteProvisionStateChanged}.
 * <p>
 *
 * @hide
 */
public class SatelliteCallback {
    private ISatelliteStateListener mCallbackStub;

    /**
     * The SatelliteCallback needs an executor to execute the callback interfaces.
     */
    public void init(@NonNull Executor executor) {
        if (executor == null) {
            throw new IllegalArgumentException("SatelliteCallback executor must be non-null");
        }
        mCallbackStub = new ISatelliteStateListenerStub(this, executor);
    }

    public ISatelliteStateListener getCallbackStub() {
        return mCallbackStub;
    }

    /**
     * Interface for satellite provision state change listener.
     */
    public interface SatelliteProvisionStateListener {
        /**
         * Called when satellite provision state changes.
         *
         * @param provisioned The new provision state. {@code true} means satellite is provisioned
         *                    {@code false} means satellite is not provisioned.
         */
        void onSatelliteProvisionStateChanged(boolean provisioned);
    }

    /**
     * Interface for position update and message transfer state change listener.
     */
    public interface SatellitePositionUpdateListener {
        /**
         * Called when the satellite position changes.
         *
         * @param pointingInfo The pointing info containing the satellite location.
         */
        void onSatellitePositionUpdate(@NonNull PointingInfo pointingInfo);

        /**
         * Called when satellite message transfer state changes.
         *
         * @param state The new message transfer state.
         * @param sendPendingCount The number of messages that are currently being sent.
         * @param receivePendingCount The number of messages that are currently being received.
         * @param errorCode If message transfer failed, the reason for failure.
         */
        void onMessageTransferStateUpdate(
                @SatelliteManager.SatelliteMessageTransferState int state, int sendPendingCount,
                int receivePendingCount, @SatelliteManager.SatelliteError int errorCode);
    }

    /**
     * Interface for satellite state change listener.
     */
    public interface SatelliteStateListener {
        /**
         * Called when satellite state changes.
         * @param state The new satellite modem state.
         */
        void onSatelliteModemStateChange(@SatelliteManager.SatelliteModemState int state);

        /**
         * Called when there are pending datagrams to be received from satellite.
         * @param count pending datagram count.
         */
        void onPendingDatagramCount(int count);
    }

    /**
     * Interface for satellite datagram listener.
     */
    public interface SatelliteDatagramListener {
        /**
         * Called when there are incoming datagrams to be received.
         * @param datagrams array of datagrams to be received over satellite.
         */
        void onSatelliteDatagrams(SatelliteDatagram[] datagrams);
    }

    private static class ISatelliteStateListenerStub extends ISatelliteStateListener.Stub {
        private WeakReference<SatelliteCallback> mSatelliteCallbackWeakRef;
        private Executor mExecutor;

        ISatelliteStateListenerStub(SatelliteCallback satelliteCallback, Executor executor) {
            mSatelliteCallbackWeakRef = new WeakReference<>(satelliteCallback);
            mExecutor = executor;
        }

        public void onSatelliteProvisionStateChanged(boolean provisioned) {
            SatelliteProvisionStateListener listener =
                    (SatelliteProvisionStateListener) mSatelliteCallbackWeakRef.get();
            if (listener == null) return;

            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> listener.onSatelliteProvisionStateChanged(provisioned)));
        }

        public void onSatellitePositionUpdate(@NonNull PointingInfo pointingInfo) {
            SatellitePositionUpdateListener listener =
                    (SatellitePositionUpdateListener) mSatelliteCallbackWeakRef.get();
            if (listener == null) return;

            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> listener.onSatellitePositionUpdate(pointingInfo)));
        }

        public void onMessageTransferStateUpdate(
                @SatelliteManager.SatelliteMessageTransferState int state, int sendPendingCount,
                int receivePendingCount, @SatelliteManager.SatelliteError int errorCode) {
            SatellitePositionUpdateListener listener =
                    (SatellitePositionUpdateListener) mSatelliteCallbackWeakRef.get();
            if (listener == null) return;

            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> listener.onMessageTransferStateUpdate(
                            state, sendPendingCount, receivePendingCount, errorCode)));
        }


        @Override
        public void onSatelliteModemStateChange(@SatelliteManager.SatelliteModemState int state) {
            SatelliteStateListener listener =
                    (SatelliteStateListener) mSatelliteCallbackWeakRef.get();
            if (listener == null) return;

            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> listener.onSatelliteModemStateChange(state)));
        }

        @Override
        public void onPendingDatagramCount(int count) {
            SatelliteStateListener listener =
                    (SatelliteStateListener) mSatelliteCallbackWeakRef.get();
            if (listener == null) return;

            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> listener.onPendingDatagramCount(count)));
        }

        @Override
        public void onSatelliteDatagrams(SatelliteDatagram[] datagrams) {
            SatelliteDatagramListener listener =
                    (SatelliteDatagramListener) mSatelliteCallbackWeakRef.get();
            if (listener == null) return;

            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> listener.onSatelliteDatagrams(datagrams)));
        }
    }
}
Loading