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

Commit d7864f4f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add API to monitor selected satellite subscription changed event." into main

parents a7bd5c1c 0f3c5121
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright 2024 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 selected satellite subscription change callback.
 *
 * @hide
 */
oneway interface ISelectedNbIotSatelliteSubscriptionCallback {
    /**
     * Called when the selected satellite subscription has changed.
     *
     * @param selectedSubId The new satellite subscription id.
     */
    void onSelectedNbIotSatelliteSubscriptionChanged(in int selectedSubId);
}
+87 −2
Original line number Diff line number Diff line
@@ -99,16 +99,18 @@ public final class SatelliteManager {
    private static final ConcurrentHashMap<SatelliteSupportedStateCallback,
            ISatelliteSupportedStateCallback> sSatelliteSupportedStateCallbackMap =
            new ConcurrentHashMap<>();

    private static final ConcurrentHashMap<SatelliteCommunicationAllowedStateCallback,
            ISatelliteCommunicationAllowedStateCallback>
            sSatelliteCommunicationAllowedStateCallbackMap =
            new ConcurrentHashMap<>();

    private static final ConcurrentHashMap<SatelliteDisallowedReasonsCallback,
            ISatelliteDisallowedReasonsCallback>
            sSatelliteDisallowedReasonsCallbackMap =
            new ConcurrentHashMap<>();
    private static final ConcurrentHashMap<SelectedNbIotSatelliteSubscriptionCallback,
            ISelectedNbIotSatelliteSubscriptionCallback>
            sSelectedNbIotSatelliteSubscriptionCallbackMap =
            new ConcurrentHashMap<>();

    private final int mSubId;

@@ -2540,6 +2542,89 @@ public final class SatelliteManager {
        }
    }

    /**
     * Registers for selected satellite subscription changed event from the satellite service.
     *
     * @param executor The executor on which the callback will be called.
     * @param callback The callback to handle the selected satellite subscription changed event.
     *
     * @throws SecurityException if the caller doesn't have required permission.
     * @throws IllegalStateException if the Telephony process is not currently available.
     *
     * @hide
     */
    @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
    @SatelliteResult public int registerForSelectedNbIotSatelliteSubscriptionChanged(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull SelectedNbIotSatelliteSubscriptionCallback callback) {
        Objects.requireNonNull(executor);
        Objects.requireNonNull(callback);

        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                ISelectedNbIotSatelliteSubscriptionCallback internalCallback =
                        new ISelectedNbIotSatelliteSubscriptionCallback.Stub() {
                            @Override
                            public void onSelectedNbIotSatelliteSubscriptionChanged(
                                    int selectedSubId) {
                                executor.execute(() -> Binder.withCleanCallingIdentity(
                                        () -> callback.onSelectedNbIotSatelliteSubscriptionChanged(
                                                selectedSubId)));
                            }
                        };
                sSelectedNbIotSatelliteSubscriptionCallbackMap.put(callback, internalCallback);
                return telephony.registerForSelectedNbIotSatelliteSubscriptionChanged(
                        internalCallback);
            } else {
                throw new IllegalStateException("Telephony service is null.");
            }
        } catch (RemoteException ex) {
            loge("registerForSelectedNbIotSatelliteSubscriptionChanged() RemoteException: " + ex);
            ex.rethrowFromSystemServer();
        }
        return SATELLITE_RESULT_REQUEST_FAILED;
    }

    /**
     * Unregisters for selected satellite subscription changed event from the satellite service. If
     * callback was not registered before, the request will be ignored.
     *
     * @param callback The callback that was passed to {@link
     *     #registerForSelectedNbIotSatelliteSubscriptionChanged(Executor,
     *     SelectedNbIotSatelliteSubscriptionCallback)}.
     *
     * @throws SecurityException if the caller doesn't have required permission.
     * @throws IllegalStateException if the Telephony process is not currently available.
     * @hide
     */
    @RequiresPermission(Manifest.permission.SATELLITE_COMMUNICATION)
    public void unregisterForSelectedNbIotSatelliteSubscriptionChanged(
            @NonNull SelectedNbIotSatelliteSubscriptionCallback callback) {
        Objects.requireNonNull(callback);
        ISelectedNbIotSatelliteSubscriptionCallback internalCallback =
                sSelectedNbIotSatelliteSubscriptionCallbackMap.remove(callback);

        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                if (internalCallback != null) {
                    telephony.unregisterForSelectedNbIotSatelliteSubscriptionChanged(
                            internalCallback);
                } else {
                    loge("unregisterForSelectedNbIotSatelliteSubscriptionChanged: " +
                            "No internal callback.");
                }
            } else {
                throw new IllegalStateException("Telephony service is null.");
            }
        } catch (RemoteException ex) {
            loge("unregisterForSelectedNbIotSatelliteSubscriptionChanged() RemoteException: " +
                    ex);
            ex.rethrowFromSystemServer();
        }
    }

    /**
     * Inform whether the device is aligned with the satellite in both real and demo mode.
     *
+31 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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;

/**
 * A callback class for selected satellite subscription changed events.
 *
 * @hide
 */
public interface SelectedNbIotSatelliteSubscriptionCallback {
    /**
     * Called when the selected satellite subscription has changed.
     *
     * @param selectedSubId The new satellite subscription id.
     */
    void onSelectedNbIotSatelliteSubscriptionChanged(int selectedSubId);
}
+25 −0
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
import android.telephony.satellite.ISatelliteProvisionStateCallback;
import android.telephony.satellite.ISatelliteSupportedStateCallback;
import android.telephony.satellite.ISatelliteModemStateCallback;
import android.telephony.satellite.ISelectedNbIotSatelliteSubscriptionCallback;
import android.telephony.satellite.NtnSignalStrength;
import android.telephony.satellite.SatelliteCapabilities;
import android.telephony.satellite.SatelliteDatagram;
@@ -3029,6 +3030,30 @@ interface ITelephony {
            + "android.Manifest.permission.SATELLITE_COMMUNICATION)")
    void requestSelectedNbIotSatelliteSubscriptionId(in ResultReceiver receiver);

    /**
     * Registers for selected satellite subscription changed event from the satellite service.
     *
     * @param executor The executor on which the callback will be called.
     * @param callback The callback to handle the satellite subscription changed event.
     */
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission("
            + "android.Manifest.permission.SATELLITE_COMMUNICATION)")
    int registerForSelectedNbIotSatelliteSubscriptionChanged(
            in ISelectedNbIotSatelliteSubscriptionCallback callback);

    /**
     * Unregisters for selected satellite subscription changed event from the satellite service. If
     * callback was not registered before, the request will be ignored.
     *
     * @param callback The callback that was passed to {@link
     *     #registerForSelectedNbIotSatelliteSubscriptionChanged(Executor,
     *     SelectedNbIotSatelliteSubscriptionCallback)}.
     */
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission("
            + "android.Manifest.permission.SATELLITE_COMMUNICATION)")
    void unregisterForSelectedNbIotSatelliteSubscriptionChanged(
            in ISelectedNbIotSatelliteSubscriptionCallback callback);

    /**
     * Inform whether the device is aligned with the satellite in both real and demo mode.
     *