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

Commit e866fda5 authored by Jack Yu's avatar Jack Yu
Browse files

Fixed infinite loop in retry manager

Added a safer check to detect the case when all APNs
are permanently failed. The complexity changes from
O(N) to O(N^2). Most of the time N=1 and was never
greater than 3, so this should not affect the performance.

Fix: 157187054
Test: RetryManager unit tests
Change-Id: I74af173c5d10b4f4f7b26d8d931e9b920297f37e
parent f8462eb1
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telephony;

import android.annotation.Nullable;
import android.compat.annotation.UnsupportedAppUsage;
import android.content.Context;
import android.os.PersistableBundle;
@@ -487,10 +488,9 @@ public class RetryManager {

    /**
     * Get the next APN setting for data call setup.
     * @return APN setting to try
     * @return APN setting to try. {@code null} if cannot find any APN,
     */
    public ApnSetting getNextApnSetting() {

    public @Nullable ApnSetting getNextApnSetting() {
        if (mWaitingApns == null || mWaitingApns.size() == 0) {
            log("Waiting APN list is null or empty.");
            return null;
@@ -517,8 +517,10 @@ public class RetryManager {
                break;
            }

            // If we've already cycled through all the APNs, that means there is no APN we can try
            if (index == mCurrentApnIndex) return null;
            // If all APNs have permanently failed, bail out.
            if (mWaitingApns.stream().allMatch(ApnSetting::getPermanentFailed)) {
                return null;
            }
        }

        mCurrentApnIndex = index;
@@ -566,9 +568,8 @@ public class RetryManager {
                break;
            }

            // If we've already cycled through all the APNs, that means all APNs have
            // permanently failed
            if (index == mCurrentApnIndex) {
            // If all APNs have permanently failed, bail out.
            if (mWaitingApns.stream().allMatch(ApnSetting::getPermanentFailed)) {
                log("All APNs have permanently failed.");
                return NO_RETRY;
            }
+3 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.internal.telephony.dataconnection;

import android.annotation.Nullable;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.os.Message;
@@ -225,10 +226,10 @@ public class ApnContext {

    /**
     * Get the next available APN to try.
     * @return APN setting which will be used for data call setup. Return null if there is no
     * @return APN setting which will be used for data call setup.{@code null} if there is no
     * APN can be retried.
     */
    public ApnSetting getNextApnSetting() {
    public @Nullable ApnSetting getNextApnSetting() {
        return mRetryManager.getNextApnSetting();
    }