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

Commit 8bb97fd1 authored by Aishwarya Mallampati's avatar Aishwarya Mallampati Committed by Android (Google) Code Review
Browse files

Merge "Add new API to notify carrier roaming ntn mode changes." into 24D1-dev

parents 9aad30b7 4ea32ba3
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -318,6 +318,12 @@ public class DefaultPhoneNotifier implements PhoneNotifier {
        mTelephonyRegistryMgr.notifyCallbackModeStopped(sender.getPhoneId(),
                sender.getSubId(), type, reason);
    }

    @Override
    public void notifyCarrierRoamingNtnModeChanged(Phone sender, boolean active) {
        mTelephonyRegistryMgr.notifyCarrierRoamingNtnModeChanged(sender.getSubId(), active);
    }

    /**
     * Convert the {@link Call.State} enum into the PreciseCallState.PRECISE_CALL_STATE_* constants
     * for the public API.
+12 −0
Original line number Diff line number Diff line
@@ -5297,6 +5297,18 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
        mNotifier.notifyCallbackModeStopped(this, type, reason);
    }

    /**
     * Notify carrier roaming non-terrestrial network mode changed
     * @param active {@code true} If the device is connected to carrier roaming
     *                           non-terrestrial network or was connected within the
     *                           {CarrierConfigManager#KEY_SATELLITE_CONNECTION_HYSTERESIS_SEC_INT}
     *                           duration, {code false} otherwise.
     */
    public void notifyCarrierRoamingNtnModeChanged(boolean active) {
        logd("notifyCarrierRoamingNtnModeChanged active:" + active);
        mNotifier.notifyCarrierRoamingNtnModeChanged(this, active);
    }

    public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
        pw.println("Phone: subId=" + getSubId());
        pw.println(" mPhoneId=" + mPhoneId);
+3 −0
Original line number Diff line number Diff line
@@ -153,4 +153,7 @@ public interface PhoneNotifier {

    /** Notify that simultaneous cellular calling subscriptions have changed */
    void notifySimultaneousCellularCallingSubscriptionsChanged(Set<Integer> subIds);

    /** Notify carrier roaming non-terrestrial network mode changed. **/
    void notifyCarrierRoamingNtnModeChanged(Phone sender, boolean active);
}
+97 −42
Original line number Diff line number Diff line
@@ -209,6 +209,7 @@ public class SatelliteController extends Handler {
    private static final int EVENT_WAIT_FOR_SATELLITE_ENABLING_RESPONSE_TIMED_OUT = 39;
    private static final int EVENT_SATELLITE_CONFIG_DATA_UPDATED = 40;
    private static final int EVENT_SATELLITE_SUPPORTED_STATE_CHANGED = 41;
    private static final int EVENT_NOTIFY_NTN_HYSTERESIS_TIMED_OUT = 42;

    @NonNull private static SatelliteController sInstance;
    @NonNull private final Context mContext;
@@ -356,6 +357,12 @@ public class SatelliteController extends Handler {
    @NonNull private final SparseBooleanArray
            mWasSatelliteConnectedViaCarrier = new SparseBooleanArray();

    @GuardedBy("mSatelliteConnectedLock")
    @NonNull private final SparseBooleanArray mLastNotifiedNtnMode = new SparseBooleanArray();

    @GuardedBy("mSatelliteConnectedLock")
    @NonNull private final SparseBooleanArray mInitialized = new SparseBooleanArray();

    /**
     * Key: Subscription ID; Value: set of
     * {@link android.telephony.NetworkRegistrationInfo.ServiceType}
@@ -364,10 +371,6 @@ public class SatelliteController extends Handler {
    @NonNull private final Map<Integer, List<Integer>>
            mSatModeCapabilitiesForCarrierRoaming = new HashMap<>();

    @GuardedBy("mSatelliteConnectedLock")
    @NonNull private final SparseBooleanArray
            mIsSatelliteConnectedViaCarrierHysteresisTimeExpired = new SparseBooleanArray();

    /**
     * This is used for testing only. When mEnforcedEmergencyCallToSatelliteHandoverType is valid,
     * Telephony will ignore the IMS registration status and cellular availability, and always send
@@ -1384,6 +1387,13 @@ public class SatelliteController extends Handler {
                break;
            }

            case EVENT_NOTIFY_NTN_HYSTERESIS_TIMED_OUT: {
                int phoneId = (int) msg.obj;
                Phone phone = PhoneFactory.getPhone(phoneId);
                updateLastNotifiedNtnModeAndNotify(phone);
                break;
            }

            default:
                Log.w(TAG, "SatelliteControllerHandler: unexpected message code: " +
                        msg.what);
@@ -2749,35 +2759,38 @@ public class SatelliteController extends Handler {
            return false;
        }

        if (!isSatelliteSupportedViaCarrier(phone.getSubId())) {
        int subId = phone.getSubId();
        if (!isSatelliteSupportedViaCarrier(subId)) {
            return false;
        }

        ServiceState serviceState = phone.getServiceState();
        if (serviceState != null && serviceState.isUsingNonTerrestrialNetwork()) {
        if (serviceState == null) {
            return false;
        }

        if (serviceState.isUsingNonTerrestrialNetwork()) {
            return true;
        }

        synchronized (mSatelliteConnectedLock) {
            Boolean isHysteresisTimeExpired =
                    mIsSatelliteConnectedViaCarrierHysteresisTimeExpired.get(
                            phone.getSubId());
            if (isHysteresisTimeExpired != null && isHysteresisTimeExpired) {
        if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) {
            // Device is connected to terrestrial network which has coverage
            resetCarrierRoamingSatelliteModeParams(subId);
            return false;
        }

            Long lastDisconnectedTime =
                    mLastSatelliteDisconnectedTimesMillis.get(phone.getSubId());
        synchronized (mSatelliteConnectedLock) {
            Long lastDisconnectedTime = mLastSatelliteDisconnectedTimesMillis.get(subId);
            long satelliteConnectionHysteresisTime =
                    getSatelliteConnectionHysteresisTimeMillis(phone.getSubId());
                    getSatelliteConnectionHysteresisTimeMillis(subId);
            if (lastDisconnectedTime != null
                    && (getElapsedRealtime() - lastDisconnectedTime)
                    <= satelliteConnectionHysteresisTime) {
                logd("isInSatelliteModeForCarrierRoaming: " + "subId:" + subId
                        + " is connected to satellite within hysteresis time");
                return true;
            } else {
                mIsSatelliteConnectedViaCarrierHysteresisTimeExpired.put(
                        phone.getSubId(), true);
                mSatModeCapabilitiesForCarrierRoaming.remove(phone.getSubId());
                resetCarrierRoamingSatelliteModeParams(subId);
                return false;
            }
        }
@@ -3677,6 +3690,7 @@ public class SatelliteController extends Handler {
        updateEntitlementPlmnListPerCarrier(subId);
        updateSupportedSatelliteServicesForActiveSubscriptions();
        processNewCarrierConfigData(subId);
        resetCarrierRoamingSatelliteModeParams(subId);
    }

    private void processNewCarrierConfigData(int subId) {
@@ -4060,33 +4074,63 @@ public class SatelliteController extends Handler {

    private void handleServiceStateForSatelliteConnectionViaCarrier() {
        for (Phone phone : PhoneFactory.getPhones()) {
            int subId = phone.getSubId();
            ServiceState serviceState = phone.getServiceState();
            if (serviceState != null) {
            if (serviceState == null) {
                continue;
            }

            synchronized (mSatelliteConnectedLock) {
                if (serviceState.isUsingNonTerrestrialNetwork()) {
                        mWasSatelliteConnectedViaCarrier.put(phone.getSubId(), true);
                        mIsSatelliteConnectedViaCarrierHysteresisTimeExpired.put(
                                phone.getSubId(), false);
                    resetCarrierRoamingSatelliteModeParams(subId);
                    mWasSatelliteConnectedViaCarrier.put(subId, true);

                    for (NetworkRegistrationInfo nri
                            : serviceState.getNetworkRegistrationInfoList()) {
                        if (nri.isNonTerrestrialNetwork()) {
                                mSatModeCapabilitiesForCarrierRoaming.put(phone.getSubId(),
                            mSatModeCapabilitiesForCarrierRoaming.put(subId,
                                    nri.getAvailableServices());
                        }
                    }
                } else {
                        Boolean connected = mWasSatelliteConnectedViaCarrier.get(phone.getSubId());
                        if (connected != null && connected) {
                            // The device just got disconnected from a satellite network.
                            mLastSatelliteDisconnectedTimesMillis.put(
                                    phone.getSubId(), getElapsedRealtime());
                            mIsSatelliteConnectedViaCarrierHysteresisTimeExpired.put(
                                    phone.getSubId(), false);
                    Boolean connected = mWasSatelliteConnectedViaCarrier.get(subId);
                    if (serviceState.getState() == ServiceState.STATE_IN_SERVICE) {
                        resetCarrierRoamingSatelliteModeParams(subId);
                    } else if (connected != null && connected) {
                        // The device just got disconnected from a satellite network
                        // and is not connected to any terrestrial network that  has coverage
                        mLastSatelliteDisconnectedTimesMillis.put(subId, getElapsedRealtime());

                        logd("sendMessageDelayed subId:" + subId
                                + " phoneId:" + phone.getPhoneId()
                                + " time:" + getSatelliteConnectionHysteresisTimeMillis(subId));
                        sendMessageDelayed(obtainMessage(EVENT_NOTIFY_NTN_HYSTERESIS_TIMED_OUT,
                                        phone.getPhoneId()),
                                getSatelliteConnectionHysteresisTimeMillis(subId));
                    }
                        mWasSatelliteConnectedViaCarrier.put(phone.getSubId(), false);
                    mWasSatelliteConnectedViaCarrier.put(subId, false);
                }
                updateLastNotifiedNtnModeAndNotify(phone);
            }
        }
    }

    private void updateLastNotifiedNtnModeAndNotify(@Nullable Phone phone) {
        if (!mFeatureFlags.carrierEnabledSatelliteFlag()) return;

        if (phone == null) {
            return;
        }

        int subId = phone.getSubId();
        synchronized (mSatelliteConnectedLock) {
            boolean initialized = mInitialized.get(subId);
            boolean lastNotifiedNtnMode = mLastNotifiedNtnMode.get(subId);
            boolean currNtnMode = isInSatelliteModeForCarrierRoaming(phone);
            if (!initialized || lastNotifiedNtnMode != currNtnMode) {
                if (!initialized) mInitialized.put(subId, true);
                mLastNotifiedNtnMode.put(subId, currNtnMode);
                phone.notifyCarrierRoamingNtnModeChanged(currNtnMode);
            }
        }
    }
@@ -4448,6 +4492,17 @@ public class SatelliteController extends Handler {
                notificationBuilder.build(), UserHandle.ALL);
    }

    private void resetCarrierRoamingSatelliteModeParams(int subId) {
        if (!mFeatureFlags.carrierEnabledSatelliteFlag()) return;

        logd("resetCarrierRoamingSatelliteModeParams subId:" + subId);
        synchronized (mSatelliteConnectedLock) {
            mLastSatelliteDisconnectedTimesMillis.put(subId, null);
            mSatModeCapabilitiesForCarrierRoaming.remove(subId);
            mWasSatelliteConnectedViaCarrier.put(subId, false);
        }
    }

    @NonNull
    private PersistableBundle getPersistableBundle(int subId) {
        synchronized (mCarrierConfigArrayLock) {
+1 −1
Original line number Diff line number Diff line
@@ -361,7 +361,7 @@ public class SatelliteServiceUtils {
     * @return phone associated with {@code subId} or {@code null} if it doesn't exist.
     */
    public static @Nullable Phone getPhone(int subId) {
        return PhoneFactory.getPhone(subId);
        return PhoneFactory.getPhone(SubscriptionManager.getPhoneId(subId));
    }

    private static void logd(@NonNull String log) {
Loading