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

Commit 69e2567a authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 8298157 from 5c69a0f2 to tm-d1-release

Change-Id: I951b942552ed2cc9f8ba25a21867211649d959f8
parents e431ade2 5c69a0f2
Loading
Loading
Loading
Loading
+8 −1
Original line number Original line Diff line number Diff line
@@ -214,6 +214,11 @@ public class DataEvaluation {
        PREFERRED_TRANSPORT_CHANGED,
        PREFERRED_TRANSPORT_CHANGED,
        /** Slice config changed. */
        /** Slice config changed. */
        SLICE_CONFIG_CHANGED,
        SLICE_CONFIG_CHANGED,
        /**
         * Single data network arbitration. On certain RATs, only one data network is allowed at the
         * same time.
         */
        SINGLE_DATA_NETWORK_ARBITRATION,
    }
    }


    /** Disallowed reasons. There could be multiple reasons if it is not allowed. */
    /** Disallowed reasons. There could be multiple reasons if it is not allowed. */
@@ -266,7 +271,9 @@ public class DataEvaluation {
        /** Data network is not in the right state. */
        /** Data network is not in the right state. */
        ILLEGAL_STATE(true),
        ILLEGAL_STATE(true),
        /** VoPS is not supported by the network. */
        /** VoPS is not supported by the network. */
        VOPS_NOT_SUPPORTED(true);
        VOPS_NOT_SUPPORTED(true),
        /** Only one data network is allowed at one time. */
        ONLY_ALLOWED_SINGLE_NETWORK(true);


        private final boolean mIsHardReason;
        private final boolean mIsHardReason;


+17 −0
Original line number Original line Diff line number Diff line
@@ -249,6 +249,7 @@ public class DataNetwork extends StateMachine {
                    TEAR_DOWN_REASON_DATA_PROFILE_NOT_PREFERRED,
                    TEAR_DOWN_REASON_DATA_PROFILE_NOT_PREFERRED,
                    TEAR_DOWN_REASON_NOT_ALLOWED_BY_POLICY,
                    TEAR_DOWN_REASON_NOT_ALLOWED_BY_POLICY,
                    TEAR_DOWN_REASON_ILLEGAL_STATE,
                    TEAR_DOWN_REASON_ILLEGAL_STATE,
                    TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK,
            })
            })
    public @interface TearDownReason {}
    public @interface TearDownReason {}


@@ -336,6 +337,9 @@ public class DataNetwork extends StateMachine {
    /** Data network tear down due to illegal state. */
    /** Data network tear down due to illegal state. */
    public static final int TEAR_DOWN_REASON_ILLEGAL_STATE = 28;
    public static final int TEAR_DOWN_REASON_ILLEGAL_STATE = 28;


    /** Data network tear down due to only allowed single network. */
    public static final int TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK = 29;

    @IntDef(prefix = {"BANDWIDTH_SOURCE_"},
    @IntDef(prefix = {"BANDWIDTH_SOURCE_"},
            value = {
            value = {
                    BANDWIDTH_SOURCE_UNKNOWN,
                    BANDWIDTH_SOURCE_UNKNOWN,
@@ -2382,6 +2386,17 @@ public class DataNetwork extends StateMachine {
        return highestPriorityCapability;
        return highestPriorityCapability;
    }
    }


    /**
     * @return The priority of the network. The priority is derived from the highest priority
     * capability of the network.
     */
    public int getPriority() {
        return Arrays.stream(getNetworkCapabilities().getCapabilities()).boxed()
                .map(mDataConfigManager::getNetworkCapabilityPriority)
                .max(Integer::compare)
                .orElse(-1);
    }

    /**
    /**
     * @return The attached network request list.
     * @return The attached network request list.
     */
     */
@@ -2729,6 +2744,8 @@ public class DataNetwork extends StateMachine {
                return "TEAR_DOWN_REASON_NOT_ALLOWED_BY_POLICY";
                return "TEAR_DOWN_REASON_NOT_ALLOWED_BY_POLICY";
            case TEAR_DOWN_REASON_ILLEGAL_STATE:
            case TEAR_DOWN_REASON_ILLEGAL_STATE:
                return "TEAR_DOWN_REASON_ILLEGAL_STATE";
                return "TEAR_DOWN_REASON_ILLEGAL_STATE";
            case TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK:
                return "TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK";
            default:
            default:
                return "UNKNOWN(" + reason + ")";
                return "UNKNOWN(" + reason + ")";
        }
        }
+52 −9
Original line number Original line Diff line number Diff line
@@ -136,9 +136,6 @@ public class DataNetworkController extends Handler {
    /** Event for removing a network request. */
    /** Event for removing a network request. */
    private static final int EVENT_REMOVE_NETWORK_REQUEST = 3;
    private static final int EVENT_REMOVE_NETWORK_REQUEST = 3;


    /** Event for satisfying a single network request. */
    private static final int EVENT_SATISFY_NETWORK_REQUEST = 4;

    /** Re-evaluate all unsatisfied network requests. */
    /** Re-evaluate all unsatisfied network requests. */
    private static final int EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS = 5;
    private static final int EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS = 5;


@@ -546,6 +543,13 @@ public class DataNetworkController extends Handler {
         * capable.
         * capable.
         */
         */
        public void onNrAdvancedCapableByPcoChanged(boolean nrAdvancedCapable) {}
        public void onNrAdvancedCapableByPcoChanged(boolean nrAdvancedCapable) {}

        /**
         * Called when data service is bound.
         *
         * @param transport The transport of the data service.
         */
        public void onDataServiceBound(@TransportType int transport) {}
    }
    }


    /**
    /**
@@ -892,9 +896,6 @@ public class DataNetworkController extends Handler {
            case EVENT_ADD_NETWORK_REQUEST:
            case EVENT_ADD_NETWORK_REQUEST:
                onAddNetworkRequest((TelephonyNetworkRequest) msg.obj);
                onAddNetworkRequest((TelephonyNetworkRequest) msg.obj);
                break;
                break;
            case EVENT_SATISFY_NETWORK_REQUEST:
                onSatisfyNetworkRequest((TelephonyNetworkRequest) msg.obj);
                break;
            case EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS:
            case EVENT_REEVALUATE_UNSATISFIED_NETWORK_REQUESTS:
                DataEvaluationReason reason = (DataEvaluationReason) msg.obj;
                DataEvaluationReason reason = (DataEvaluationReason) msg.obj;
                onReevaluateUnsatisfiedNetworkRequests(reason);
                onReevaluateUnsatisfiedNetworkRequests(reason);
@@ -1037,7 +1038,7 @@ public class DataNetworkController extends Handler {
            return;
            return;
        }
        }
        logv("onAddNetworkRequest: added " + networkRequest);
        logv("onAddNetworkRequest: added " + networkRequest);
        sendMessage(obtainMessage(EVENT_SATISFY_NETWORK_REQUEST, networkRequest));
        onSatisfyNetworkRequest(networkRequest);
    }
    }


    /**
    /**
@@ -1071,6 +1072,12 @@ public class DataNetworkController extends Handler {
                setupDataNetwork(dataProfile, null,
                setupDataNetwork(dataProfile, null,
                        evaluation.getDataAllowedReason());
                        evaluation.getDataAllowedReason());
            }
            }
        } else if (evaluation.contains(DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK)) {
            // Re-evaluate the existing data networks. If this request's priority is higher than
            // the existing data network, the data network will be torn down so this request will
            // get a chance to be satisfied.
            sendMessage(obtainMessage(EVENT_REEVALUATE_EXISTING_DATA_NETWORKS,
                    DataEvaluationReason.SINGLE_DATA_NETWORK_ARBITRATION));
        }
        }
    }
    }


@@ -1137,7 +1144,6 @@ public class DataNetworkController extends Handler {
     */
     */
    private boolean shouldCheckRegistrationState() {
    private boolean shouldCheckRegistrationState() {
        // Always don't check registration state on non-DDS sub.
        // Always don't check registration state on non-DDS sub.
        log("shouldCheckRegistrationState: phoneSwitcher=" + PhoneSwitcher.getInstance());
        if (mPhone.getPhoneId() != PhoneSwitcher.getInstance().getPreferredDataPhoneId()) {
        if (mPhone.getPhoneId() != PhoneSwitcher.getInstance().getPreferredDataPhoneId()) {
            return false;
            return false;
        }
        }
@@ -1149,6 +1155,16 @@ public class DataNetworkController extends Handler {
        return true;
        return true;
    }
    }


    /**
     * @return {@code true} if the network only allows single data network at one time.
     */
    private boolean isOnlySingleDataNetworkAllowed(@TransportType int transport) {
        if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WLAN) return false;

        return mDataConfigManager.getNetworkTypesOnlySupportSingleDataNetwork()
                .contains(getDataNetworkType(transport));
    }

    /**
    /**
     * Evaluate a network request. The goal is to find a suitable {@link DataProfile} that can be
     * Evaluate a network request. The goal is to find a suitable {@link DataProfile} that can be
     * used to setup the data network.
     * used to setup the data network.
@@ -1256,6 +1272,12 @@ public class DataNetworkController extends Handler {
            evaluation.addDataDisallowedReason(DataDisallowedReason.EMERGENCY_CALL);
            evaluation.addDataDisallowedReason(DataDisallowedReason.EMERGENCY_CALL);
        }
        }


        // Check if only one data network is allowed.
        if (isOnlySingleDataNetworkAllowed(transport) && !mDataNetworkList.isEmpty()) {
            evaluation.addDataDisallowedReason(
                    DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK);
        }

        if (!mDataSettingsManager.isDataEnabled(DataUtils.networkCapabilityToApnType(
        if (!mDataSettingsManager.isDataEnabled(DataUtils.networkCapabilityToApnType(
                networkRequest.getApnTypeNetworkCapability()))) {
                networkRequest.getApnTypeNetworkCapability()))) {
            evaluation.addDataDisallowedReason(DataDisallowedReason.DATA_DISABLED);
            evaluation.addDataDisallowedReason(DataDisallowedReason.DATA_DISABLED);
@@ -1433,6 +1455,24 @@ public class DataNetworkController extends Handler {
            evaluation.addDataDisallowedReason(DataDisallowedReason.EMERGENCY_CALL);
            evaluation.addDataDisallowedReason(DataDisallowedReason.EMERGENCY_CALL);
        }
        }


        // Check if there are other network that has higher priority, and only single data network
        // is allowed.
        if (isOnlySingleDataNetworkAllowed(dataNetwork.getTransport())) {
            // If there is network request that has higher priority than this data network, then
            // tear down the network, regardless that network request is satisfied or not.
            if (mAllNetworkRequestList.stream()
                    .filter(request -> dataNetwork.getTransport()
                            == mAccessNetworksManager.getPreferredTransportByNetworkCapability(
                                    request.getApnTypeNetworkCapability()))
                    .anyMatch(request -> request.getPriority() > dataNetwork.getPriority())) {
                evaluation.addDataDisallowedReason(
                        DataDisallowedReason.ONLY_ALLOWED_SINGLE_NETWORK);
            } else {
                log("evaluateDataNetwork: " + dataNetwork + " has the highest priority. "
                        + "No need to tear down");
            }
        }

        // Check if data is disabled
        // Check if data is disabled
        boolean dataDisabled = false;
        boolean dataDisabled = false;
        if (!mDataSettingsManager.isDataEnabled()) {
        if (!mDataSettingsManager.isDataEnabled()) {
@@ -1656,6 +1696,8 @@ public class DataNetworkController extends Handler {
                    return DataNetwork.TEAR_DOWN_REASON_ILLEGAL_STATE;
                    return DataNetwork.TEAR_DOWN_REASON_ILLEGAL_STATE;
                case VOPS_NOT_SUPPORTED:
                case VOPS_NOT_SUPPORTED:
                    return DataNetwork.TEAR_DOWN_REASON_VOPS_NOT_SUPPORTED;
                    return DataNetwork.TEAR_DOWN_REASON_VOPS_NOT_SUPPORTED;
                case ONLY_ALLOWED_SINGLE_NETWORK:
                    return DataNetwork.TEAR_DOWN_ONLY_ALLOWED_SINGLE_NETWORK;
            }
            }
        }
        }
        return 0;
        return 0;
@@ -2342,7 +2384,8 @@ public class DataNetworkController extends Handler {
                }
                }
            }
            }
        } else {
        } else {
            mDataRetryManager.reset();
            mDataNetworkControllerCallbacks.forEach(callback -> callback.invokeFromExecutor(
                    () -> callback.onDataServiceBound(transport)));
        }
        }
        mDataServiceBound.put(transport, bound);
        mDataServiceBound.put(transport, bound);
    }
    }
+107 −16
Original line number Original line Diff line number Diff line
@@ -43,7 +43,9 @@ import android.util.LocalLog;
import android.util.SparseArray;
import android.util.SparseArray;


import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.CommandsInterface;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.data.DataNetworkController.DataNetworkControllerCallback;
import com.android.internal.telephony.data.DataNetworkController.NetworkRequestList;
import com.android.internal.telephony.data.DataNetworkController.NetworkRequestList;
import com.android.internal.telephony.data.DataProfileManager.DataProfileManagerCallback;
import com.android.internal.telephony.data.DataProfileManager.DataProfileManagerCallback;
import com.android.telephony.Rlog;
import com.android.telephony.Rlog;
@@ -76,20 +78,61 @@ public class DataRetryManager extends Handler {
    /** Event for data handover retry. */
    /** Event for data handover retry. */
    private static final int EVENT_DATA_HANDOVER_RETRY = 4;
    private static final int EVENT_DATA_HANDOVER_RETRY = 4;


    /** Event for cancelling all data retries and throttling entries. */
    private static final int EVENT_RESET = 5;

    /** Event for data profile/apn unthrottled. */
    /** Event for data profile/apn unthrottled. */
    private static final int EVENT_DATA_PROFILE_UNTHROTTLED = 6;
    private static final int EVENT_DATA_PROFILE_UNTHROTTLED = 6;


    /** Event for cancelling pending handover retry. */
    /** Event for cancelling pending handover retry. */
    private static final int EVENT_CANCEL_PENDING_HANDOVER_RETRY = 7;
    private static final int EVENT_CANCEL_PENDING_HANDOVER_RETRY = 7;


    /**
     * Event for radio on. This can happen when airplane mode is turned off, or RIL crashes and came
     * back online.
     */
    private static final int EVENT_RADIO_ON = 8;

    /** Event for modem reset. */
    private static final int EVENT_MODEM_RESET = 9;

    /** The maximum entries to preserve. */
    /** The maximum entries to preserve. */
    private static final int MAXIMUM_HISTORICAL_ENTRIES = 100;
    private static final int MAXIMUM_HISTORICAL_ENTRIES = 100;


    @IntDef(prefix = {"RESET_REASON_"},
            value = {
                    RESET_REASON_DATA_PROFILES_CHANGED,
                    RESET_REASON_RADIO_ON,
                    RESET_REASON_MODEM_RESTART,
                    RESET_REASON_DATA_SERVICE_BOUND,
            })
    public @interface RetryResetReason {}

    /** Reset due to data profiles changed. */
    public static final int RESET_REASON_DATA_PROFILES_CHANGED = 1;

    /** Reset due to radio on. This could happen after airplane mode off or RIL restarted. */
    public static final int RESET_REASON_RADIO_ON = 2;

    /** Reset due to modem restarted. */
    public static final int RESET_REASON_MODEM_RESTART = 3;

    /**
     * Reset due to data service bound. This could happen when reboot or when data service crashed
     * and rebound.
     */
    public static final int RESET_REASON_DATA_SERVICE_BOUND = 4;

    /** Reset due to data config changed. */
    public static final int RESET_REASON_DATA_CONFIG_CHANGED = 5;

    /** The phone instance. */
    private final @NonNull Phone mPhone;
    private final @NonNull Phone mPhone;

    /** The RIL instance. */
    private final @NonNull CommandsInterface mRil;

    /** Logging tag. */
    private final @NonNull String mLogTag;
    private final @NonNull String mLogTag;

    /** Local log. */
    private final @NonNull LocalLog mLocalLog = new LocalLog(128);
    private final @NonNull LocalLog mLocalLog = new LocalLog(128);


    /**
    /**
@@ -872,6 +915,7 @@ public class DataRetryManager extends Handler {
            @NonNull Looper looper, @NonNull DataRetryManagerCallback dataRetryManagerCallback) {
            @NonNull Looper looper, @NonNull DataRetryManagerCallback dataRetryManagerCallback) {
        super(looper);
        super(looper);
        mPhone = phone;
        mPhone = phone;
        mRil = phone.mCi;
        mLogTag = "DRM-" + mPhone.getPhoneId();
        mLogTag = "DRM-" + mPhone.getPhoneId();
        mDataRetryManagerCallbacks.add(dataRetryManagerCallback);
        mDataRetryManagerCallbacks.add(dataRetryManagerCallback);


@@ -889,9 +933,18 @@ public class DataRetryManager extends Handler {
        mDataProfileManager.registerCallback(new DataProfileManagerCallback(this::post) {
        mDataProfileManager.registerCallback(new DataProfileManagerCallback(this::post) {
            @Override
            @Override
            public void onDataProfilesChanged() {
            public void onDataProfilesChanged() {
                onReset();
                onReset(RESET_REASON_DATA_PROFILES_CHANGED);
            }
            }
        });
        });
        dataNetworkController.registerDataNetworkControllerCallback(
                new DataNetworkControllerCallback(this::post) {
                    @Override
                    public void onDataServiceBound() {
                        onReset(RESET_REASON_DATA_SERVICE_BOUND);
                    }
                });
        mRil.registerForOn(this, EVENT_RADIO_ON, null);
        mRil.registerForModemReset(this, EVENT_MODEM_RESET, null);
    }
    }


    @Override
    @Override
@@ -917,8 +970,11 @@ public class DataRetryManager extends Handler {
                    log("Handover was cancelled earlier. " + dataHandoverRetryEntry);
                    log("Handover was cancelled earlier. " + dataHandoverRetryEntry);
                }
                }
                break;
                break;
            case EVENT_RESET:
            case EVENT_RADIO_ON:
                onReset();
                onReset(RESET_REASON_RADIO_ON);
                break;
            case EVENT_MODEM_RESET:
                onReset(RESET_REASON_MODEM_RESTART);
                break;
                break;
            case EVENT_DATA_PROFILE_UNTHROTTLED:
            case EVENT_DATA_PROFILE_UNTHROTTLED:
                ar = (AsyncResult) msg.obj;
                ar = (AsyncResult) msg.obj;
@@ -945,20 +1001,13 @@ public class DataRetryManager extends Handler {
     * Called when data config is updated.
     * Called when data config is updated.
     */
     */
    private void onDataConfigUpdated() {
    private void onDataConfigUpdated() {
        reset();
        onReset(RESET_REASON_DATA_CONFIG_CHANGED);
        mDataSetupRetryRuleList = mDataConfigManager.getDataSetupRetryRules();
        mDataSetupRetryRuleList = mDataConfigManager.getDataSetupRetryRules();
        mDataHandoverRetryRuleList = mDataConfigManager.getDataHandoverRetryRules();
        mDataHandoverRetryRuleList = mDataConfigManager.getDataHandoverRetryRules();
        log("onDataConfigUpdated: mDataSetupRetryRuleList=" + mDataSetupRetryRuleList
        log("onDataConfigUpdated: mDataSetupRetryRuleList=" + mDataSetupRetryRuleList
                + ", mDataHandoverRetryRuleList=" + mDataHandoverRetryRuleList);
                + ", mDataHandoverRetryRuleList=" + mDataHandoverRetryRuleList);
    }
    }


    /**
     * Cancel all pending data retries and throttling entries.
     */
    public void reset() {
        sendMessageAtFrontOfQueue(obtainMessage(EVENT_RESET));
    }

    /**
    /**
     * Evaluate if data setup retry is needed or not. If needed, retry will be scheduled
     * Evaluate if data setup retry is needed or not. If needed, retry will be scheduled
     * automatically after evaluation.
     * automatically after evaluation.
@@ -1145,13 +1194,32 @@ public class DataRetryManager extends Handler {
    }
    }


    /** Cancel all retries and throttling entries. */
    /** Cancel all retries and throttling entries. */
    private void onReset() {
    private void onReset(@RetryResetReason int reason) {
        logl("Remove all retry and throttling entries.");
        logl("Remove all retry and throttling entries, reason=" + resetReasonToString(reason));
        removeMessages(EVENT_DATA_SETUP_RETRY);
        removeMessages(EVENT_DATA_SETUP_RETRY);
        removeMessages(EVENT_DATA_HANDOVER_RETRY);
        removeMessages(EVENT_DATA_HANDOVER_RETRY);
        mDataRetryEntries.stream()
        mDataRetryEntries.stream()
                .filter(entry -> entry.getState() == DataRetryEntry.RETRY_STATE_NOT_RETRIED)
                .filter(entry -> entry.getState() == DataRetryEntry.RETRY_STATE_NOT_RETRIED)
                .forEach(entry -> entry.setState(DataRetryEntry.RETRY_STATE_CANCELLED));
                .forEach(entry -> entry.setState(DataRetryEntry.RETRY_STATE_CANCELLED));

        final List<ThrottleStatus> throttleStatusList = new ArrayList<>();
        for (DataThrottlingEntry dataThrottlingEntry : mDataThrottlingEntries) {
            throttleStatusList.addAll(dataThrottlingEntry.dataProfile.getApnSetting().getApnTypes()
                    .stream()
                    .map(apnType -> new ThrottleStatus.Builder()
                            .setApnType(apnType)
                            .setSlotIndex(mPhone.getPhoneId())
                            .setNoThrottle()
                            .setRetryType(dataThrottlingEntry.retryType)
                            .setTransportType(dataThrottlingEntry.transport)
                            .build())
                    .collect(Collectors.toList()));
        }
        if (!throttleStatusList.isEmpty()) {
            mDataRetryManagerCallbacks.forEach(callback -> callback.invokeFromExecutor(
                    () -> callback.onThrottleStatusChanged(throttleStatusList)));
        }

        mDataThrottlingEntries.clear();
        mDataThrottlingEntries.clear();
    }
    }


@@ -1476,6 +1544,29 @@ public class DataRetryManager extends Handler {
        mDataRetryManagerCallbacks.remove(callback);
        mDataRetryManagerCallbacks.remove(callback);
    }
    }


    /**
     * Convert reset reason to string
     *
     * @param reason The reason
     * @return The reason in string format.
     */
    private static @NonNull String resetReasonToString(int reason) {
        switch (reason) {
            case RESET_REASON_DATA_PROFILES_CHANGED:
                return "DATA_PROFILES_CHANGED";
            case RESET_REASON_RADIO_ON:
                return "RADIO_ON";
            case RESET_REASON_MODEM_RESTART:
                return "MODEM_RESTART";
            case RESET_REASON_DATA_SERVICE_BOUND:
                return "DATA_SERVICE_BOUND";
            case RESET_REASON_DATA_CONFIG_CHANGED:
                return "DATA_CONFIG_CHANGED";
            default:
                return "UNKNOWN(" + reason + ")";
        }
    }

    /**
    /**
     * Log debug messages.
     * Log debug messages.
     * @param s debug messages
     * @param s debug messages
+39 −0
Original line number Original line Diff line number Diff line
@@ -22,24 +22,29 @@ import android.annotation.Nullable;
import android.net.KeepalivePacketData;
import android.net.KeepalivePacketData;
import android.net.NetworkAgent;
import android.net.NetworkAgent;
import android.net.NetworkAgentConfig;
import android.net.NetworkAgentConfig;
import android.net.NetworkCapabilities;
import android.net.NetworkProvider;
import android.net.NetworkProvider;
import android.net.NetworkScore;
import android.net.NetworkScore;
import android.net.QosFilter;
import android.net.QosFilter;
import android.net.QosSessionAttributes;
import android.net.QosSessionAttributes;
import android.net.Uri;
import android.net.Uri;
import android.os.Looper;
import android.os.Looper;
import android.telephony.AnomalyReporter;
import android.util.ArraySet;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import android.util.IndentingPrintWriter;
import android.util.LocalLog;
import android.util.LocalLog;


import com.android.internal.telephony.Phone;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.SlidingWindowEventCounter;
import com.android.telephony.Rlog;
import com.android.telephony.Rlog;


import java.io.FileDescriptor;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.io.PrintWriter;
import java.time.Duration;
import java.time.Duration;
import java.util.Set;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;


/**
/**
 * TelephonyNetworkAgent class represents a single PDN (Packet Data Network). It is an agent
 * TelephonyNetworkAgent class represents a single PDN (Packet Data Network). It is an agent
@@ -51,6 +56,13 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
    private final Phone mPhone;
    private final Phone mPhone;
    private final LocalLog mLocalLog = new LocalLog(128);
    private final LocalLog mLocalLog = new LocalLog(128);


    /** Event counter for unwanted network within time window, is used to trigger anomaly report. */
    private static final long NETWORK_UNWANTED_ANOMALY_WINDOW_MS = TimeUnit.MINUTES.toMillis(5);
    private static final int NETWORK_UNWANTED_ANOMALY_NUM_OCCURRENCES =  12;
    private static final SlidingWindowEventCounter sNetworkUnwantedCounter =
            new SlidingWindowEventCounter(NETWORK_UNWANTED_ANOMALY_WINDOW_MS,
                    NETWORK_UNWANTED_ANOMALY_NUM_OCCURRENCES);

    /** The parent data network. */
    /** The parent data network. */
    private final @NonNull DataNetwork mDataNetwork;
    private final @NonNull DataNetwork mDataNetwork;


@@ -172,9 +184,36 @@ public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSess
            log("The agent is already abandoned. Ignored onNetworkUnwanted.");
            log("The agent is already abandoned. Ignored onNetworkUnwanted.");
            return;
            return;
        }
        }

        NetworkCapabilities capabilities = mDataNetwork.getNetworkCapabilities();
        if (capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_IMS)
                || capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)) {
            trackNetworkUnwanted();
        }

        mDataNetwork.tearDown(DataNetwork.TEAR_DOWN_REASON_CONNECTIVITY_SERVICE_UNWANTED);
        mDataNetwork.tearDown(DataNetwork.TEAR_DOWN_REASON_CONNECTIVITY_SERVICE_UNWANTED);
    }
    }


    /**
     * There have been several bugs where a RECONNECT loop kicks off where a DataConnection
     * connects to the Network, ConnectivityService indicates that the Network is unwanted,
     * and then the DataConnection reconnects. By the time we get the bug report it's too late
     * because there have already been hundreds of RECONNECTS.  This is meant to capture the issue
     * when it first starts.
     *
     * The unwanted counter is configured to only take an anomaly report in extreme cases.
     * This is to avoid having the anomaly message show up on several devices.
     *
     */
    private void trackNetworkUnwanted() {
        if (sNetworkUnwantedCounter.addOccurrence()) {
            AnomalyReporter.reportAnomaly(
                    UUID.fromString("9f3bc55b-bfa6-4e26-afaa-5031426a66d1"),
                    "Network Unwanted called 12 times in 5 minutes.");
        }
    }


    /**
    /**
     * @return The unique id of the agent.
     * @return The unique id of the agent.
     */
     */
Loading