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

Commit 4fcec830 authored by Thomas Nguyen's avatar Thomas Nguyen Committed by Aishwarya Mallampati
Browse files

Add satellite provision APIs

Bug: 266013384
Test: atest android.telephony.cts.SatelliteManagerTest

Change-Id: I36d000adab8d9b96672be4ff1ab90f046a83c423
parent 42d58582
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -19,10 +19,11 @@ package android.telephony.satellite;
import android.telephony.satellite.PointingInfo;

/**
 * Callback for position updates from the satellite service.
 * Interface for satellite state listener.
 * @hide
 */
oneway interface ISatellitePositionUpdateCallback {
oneway interface ISatelliteStateListener {
    void onSatelliteProvisionStateChanged(in int[] features, in boolean provisioned);
    void onSatellitePositionUpdate(in PointingInfo pointingInfo);
    void onMessageTransferStateUpdate(in int state);
}
+132 −0
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 android.telephony.satellite.stub.SatelliteImplBase;

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 features The list of provisioned features.
         * @param provisioned The new provision state. {@code true} means satellite is provisioned
         *                    {@code false} means satellite is not provisioned.
         */
        void onSatelliteProvisionStateChanged(
                @SatelliteImplBase.Feature int[] features, boolean provisioned);
    }

    /**
     * Interface for position update 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.
         */
        void onMessageTransferStateUpdate(
                @SatelliteManager.SatelliteMessageTransferState int state);
    }

    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(
                @SatelliteImplBase.Feature int[] features, boolean provisioned) {
            SatelliteProvisionStateListener listener =
                    (SatelliteProvisionStateListener) mSatelliteCallbackWeakRef.get();
            if (listener == null) return;

            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> listener.onSatelliteProvisionStateChanged(features, 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) {
            SatellitePositionUpdateListener listener =
                    (SatellitePositionUpdateListener) mSatelliteCallbackWeakRef.get();
            if (listener == null) return;

            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> listener.onMessageTransferStateUpdate(state)));
        }
    }
}
+356 −120

File changed.

Preview size limit exceeded, changes collapsed.

+23 −0
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 com.android.internal.telephony;

// Copies consumer pattern for an operation that requires an int array result from another
// process to finish.
oneway interface IIntArrayConsumer {
    void accept(in int[] result);
}
 No newline at end of file
+43 −5
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.ComponentName;
import android.content.Intent;
import android.content.IntentSender;
import android.os.Bundle;
import android.os.ICancellationSignal;
import android.os.IBinder;
import android.os.Messenger;
import android.os.ParcelFileDescriptor;
@@ -66,13 +67,14 @@ import android.telephony.ims.aidl.IImsRcsFeature;
import android.telephony.ims.aidl.IImsRegistration;
import android.telephony.ims.aidl.IImsRegistrationCallback;
import android.telephony.ims.aidl.IRcsConfigCallback;
import android.telephony.satellite.ISatellitePositionUpdateCallback;
import android.telephony.satellite.ISatelliteStateListener;
import com.android.ims.internal.IImsServiceFeatureCallback;
import com.android.internal.telephony.CellNetworkScanResult;
import com.android.internal.telephony.IBooleanConsumer;
import com.android.internal.telephony.ICallForwardingInfoCallback;
import com.android.internal.telephony.IccLogicalChannelRequest;
import com.android.internal.telephony.IImsStateCallback;
import com.android.internal.telephony.IIntArrayConsumer;
import com.android.internal.telephony.IIntegerConsumer;
import com.android.internal.telephony.INumberVerificationCallback;
import com.android.internal.telephony.OperatorInfo;
@@ -2702,16 +2704,52 @@ interface ITelephony {
    /**
     * Start receiving satellite pointing updates.
     */
    int startSatellitePositionUpdates(int subId, int callbackId,
            in ISatellitePositionUpdateCallback callback);
    int startSatellitePositionUpdates(int subId, in ISatelliteStateListener callback);

    /**
     * Stop receiving satellite pointing updates.
     */
    int stopSatellitePositionUpdates(int subId, int callbackId);
    int stopSatellitePositionUpdates(int subId, ISatelliteStateListener callback);

    /**
     * Get maximum number of characters per text message on satellite.
     */
    int getMaxCharactersPerSatelliteTextMessage(int subId, IIntegerConsumer internalCallback);

    /**
     * Register the subscription with a satellite provider.
     * This is needed to register the subscription if the provider allows dynamic registration.
     *
     * @param subId The subId of the subscription to be provisioned.
     * @param features List of features to be provisioned.
     * @param callback The callback to get the error code of the request.
     * @return The signal transport used by callers to cancel the provision request.
     */
    ICancellationSignal provisionSatelliteService(int subId, in int[] features,
            in IIntegerConsumer callback);

    /**
     * Register for the satellite provision state change.
     *
     * @param subId The subId of the subscription to be provisioned.
     * @param callback The callback to handle the satellite provision state changed event.
     */
    int registerForSatelliteProvisionStateChanged(int subId, ISatelliteStateListener callback);

    /**
     * Unregister for the satellite provision state change.
     *
     * @param subId The subId of the subscription associated with the satellite service.
     * @param callback The callback that was passed to
     *                   registerForSatelliteProvisionStateChanged.
     */
    int unregisterForSatelliteProvisionStateChanged(int subId, ISatelliteStateListener callback);

    /**
     * Get the list of provisioned satellite features.
     *
     * @param subId The subId of the subscription to be provisioned.
     * @param callback The callback to get the list of provisioned satellite features.
     */
    int getProvisionedSatelliteFeatures(int subId, IIntArrayConsumer callback);
}
Loading