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

Commit 1ca93825 authored by Hakjun Choi's avatar Hakjun Choi Committed by Android (Google) Code Review
Browse files

Merge "Add callback into vendor interface to receive modem state change event" into 24D1-dev

parents af67d54f 392a50d4
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 satellite supported state change callback.
 * @hide
 */
oneway interface ISatelliteSupportedStateCallback {
    /**
     * Called when satellite supported state has changed.
     *
     * @param supoprted Whether satellite is supported or not.
     */
    void onSatelliteSupportedStateChanged(in boolean supported);
}
+85 −0
Original line number Diff line number Diff line
@@ -87,6 +87,9 @@ public final class SatelliteManager {
    private static final ConcurrentHashMap<SatelliteCapabilitiesCallback,
            ISatelliteCapabilitiesCallback>
            sSatelliteCapabilitiesCallbackMap = new ConcurrentHashMap<>();
    private static final ConcurrentHashMap<SatelliteSupportedStateCallback,
            ISatelliteSupportedStateCallback> sSatelliteSupportedStateCallbackMap =
            new ConcurrentHashMap<>();

    private final int mSubId;

@@ -2284,6 +2287,88 @@ public final class SatelliteManager {
        return new ArrayList<>();
    }

    /**
     * Registers for the satellite supported state changed.
     *
     * @param executor The executor on which the callback will be called.
     * @param callback The callback to handle the satellite supoprted state changed event.
     *
     * @return The {@link SatelliteResult} result of the operation.
     *
     * @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 registerForSupportedStateChanged(
            @NonNull @CallbackExecutor Executor executor,
            @NonNull SatelliteSupportedStateCallback callback) {
        Objects.requireNonNull(executor);
        Objects.requireNonNull(callback);

        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                ISatelliteSupportedStateCallback internalCallback =
                        new ISatelliteSupportedStateCallback.Stub() {
                            @Override
                            public void onSatelliteSupportedStateChanged(boolean supported) {
                                executor.execute(() -> Binder.withCleanCallingIdentity(
                                        () -> callback.onSatelliteSupportedStateChanged(
                                                supported)));
                            }
                        };
                sSatelliteSupportedStateCallbackMap.put(callback, internalCallback);
                return telephony.registerForSatelliteSupportedStateChanged(
                        mSubId, internalCallback);
            } else {
                throw new IllegalStateException("telephony service is null.");
            }
        } catch (RemoteException ex) {
            loge("registerForSupportedStateChanged() RemoteException: " + ex);
            ex.rethrowAsRuntimeException();
        }
        return SATELLITE_RESULT_REQUEST_FAILED;
    }

    /**
     * Unregisters for the satellite supported state changed.
     * If callback was not registered before, the request will be ignored.
     *
     * @param callback The callback that was passed to
     * {@link #registerForSupportedStateChanged(Executor, SatelliteSupportedStateCallback)}
     *
     * @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)
    @FlaggedApi(Flags.FLAG_OEM_ENABLED_SATELLITE_FLAG)
    public void unregisterForSupportedStateChanged(
            @NonNull SatelliteSupportedStateCallback callback) {
        Objects.requireNonNull(callback);
        ISatelliteSupportedStateCallback internalCallback =
                sSatelliteSupportedStateCallbackMap.remove(callback);

        try {
            ITelephony telephony = getITelephony();
            if (telephony != null) {
                if (internalCallback != null) {
                    telephony.unregisterForSatelliteSupportedStateChanged(mSubId, internalCallback);
                } else {
                    loge("unregisterForSupportedStateChanged: No internal callback.");
                }
            } else {
                throw new IllegalStateException("telephony service is null.");
            }
        } catch (RemoteException ex) {
            loge("unregisterForSupportedStateChanged() RemoteException: " + ex);
            ex.rethrowAsRuntimeException();
        }
    }

    @Nullable private static ITelephony getITelephony() {
        ITelephony binder = ITelephony.Stub.asInterface(TelephonyFrameworkInitializer
                .getTelephonyServiceManager()
+40 −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.FlaggedApi;

import com.android.internal.telephony.flags.Flags;

/**
 * A callback class for monitoring satellite supported state change events.
 *
 * @hide
 */
@FlaggedApi(Flags.FLAG_OEM_ENABLED_SATELLITE_FLAG)
public interface SatelliteSupportedStateCallback {
    /**
     * Called when satellite supported state changes.
     *
     * @param supported The new supported state. {@code true} means satellite is supported,
     * {@code false} means satellite is not supported.
     *
     * @hide
     */
    @FlaggedApi(Flags.FLAG_OEM_ENABLED_SATELLITE_FLAG)
    void onSatelliteSupportedStateChanged(boolean supported);
}
+7 −0
Original line number Diff line number Diff line
@@ -74,4 +74,11 @@ oneway interface ISatelliteListener {
     * @param SatelliteCapabilities The current satellite capabilities.
     */
    void onSatelliteCapabilitiesChanged(in SatelliteCapabilities capabilities);

    /**
     * Called when supported state of satellite has changed
     *
     * @param supported True means satellite service is supported and false means it is not.
     */
    void onSatelliteSupportedStateChanged(in boolean supported);
}
+26 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.telephony.satellite.ISatelliteCapabilitiesCallback;
import android.telephony.satellite.ISatelliteDatagramCallback;
import android.telephony.satellite.ISatelliteTransmissionUpdateCallback;
import android.telephony.satellite.ISatelliteProvisionStateCallback;
import android.telephony.satellite.ISatelliteSupportedStateCallback;
import android.telephony.satellite.ISatelliteModemStateCallback;
import android.telephony.satellite.NtnSignalStrength;
import android.telephony.satellite.SatelliteCapabilities;
@@ -3315,4 +3316,29 @@ interface ITelephony {
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission("
            + "android.Manifest.permission.SATELLITE_COMMUNICATION)")
    List<String> getSatellitePlmnsForCarrier(int subId);

    /**
     * Registers for supported state changed from satellite modem.
     *
     * @param subId The subId of the subscription to register for supported state changed.
     * @param callback The callback to handle the satellite supported state changed event.
     *
     * @return The {@link SatelliteError} result of the operation.
     */
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission("
            + "android.Manifest.permission.SATELLITE_COMMUNICATION)")
    int registerForSatelliteSupportedStateChanged(int subId,
            in ISatelliteSupportedStateCallback callback);

    /**
     * Unregisters for supported state changed from satellite modem.
     * If callback was not registered before, the request will be ignored.
     *
     * @param subId The subId of the subscription to unregister for supported state changed.
     * @param callback The callback that was passed to registerForSatelliteSupportedStateChanged.
     */
    @JavaPassthrough(annotation="@android.annotation.RequiresPermission("
            + "android.Manifest.permission.SATELLITE_COMMUNICATION)")
    void unregisterForSatelliteSupportedStateChanged(int subId,
            in ISatelliteSupportedStateCallback callback);
}