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

Commit 306972ce authored by Jack Yu's avatar Jack Yu
Browse files

Move QosCallbackTracker to the new location

Test: Manual
Bug: 196597630
Merged-In: I251c678de3e639260d7b6e5b1338669d51152cf5
Change-Id: I251c678de3e639260d7b6e5b1338669d51152cf5
parent 1b23ba6c
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.telephony.data.DataCallResponse;
import android.telephony.data.DataProfile;
import android.telephony.data.DataService;
import android.telephony.data.DataServiceCallback;
import android.telephony.data.QosBearerSession;
import android.telephony.data.TrafficDescriptor;
import android.text.TextUtils;
import android.util.IndentingPrintWriter;
@@ -345,6 +346,9 @@ public class DataNetwork extends StateMachine {
    /** The network agent associated with this data network. */
    private @NonNull TelephonyNetworkAgent mNetworkAgent;

    /** QOS callback tracker. This is only created after network connected on WWAN. */
    private @Nullable QosCallbackTracker mQosCallbackTracker;

    /** The data profile used to establish this data network. */
    private final @NonNull DataProfile mDataProfile;

@@ -395,6 +399,9 @@ public class DataNetwork extends StateMachine {
     */
    private @TransportType int mPreferredTransport = AccessNetworkConstants.TRANSPORT_TYPE_INVALID;

    /** The QOS bearer sessions. */
    private @NonNull List<QosBearerSession> mQosBearerSessions = new ArrayList<>();

    /**
     * The network bandwidth.
     */
@@ -779,6 +786,9 @@ public class DataNetwork extends StateMachine {
            mNetworkAgent.markConnected();
            mDataNetworkCallback.invokeFromExecutor(
                    () -> mDataNetworkCallback.onConnected(DataNetwork.this));

            mQosCallbackTracker = new QosCallbackTracker(mNetworkAgent, mPhone);
            mQosCallbackTracker.updateSessions(mQosBearerSessions);
            updateSuspendState();

            mPhone.getDisplayInfoController().registerForTelephonyDisplayInfoChanged(
@@ -1308,6 +1318,11 @@ public class DataNetwork extends StateMachine {
        // updateTcpBufferSizes
        linkProperties.setTcpBufferSizes(getTcpConfig());

        mQosBearerSessions = response.getQosBearerSessions();
        if (mQosCallbackTracker != null) {
            mQosCallbackTracker.updateSessions(mQosBearerSessions);
        }

        if (!linkProperties.equals(mLinkProperties)) {
            mLinkProperties = linkProperties;
            log("sendLinkProperties " + mLinkProperties);
@@ -1649,6 +1664,7 @@ public class DataNetwork extends StateMachine {
        // connection. In this case we assign a slightly higher score of 50. The intention is
        // it will not be replaced by other data networks accidentally in DSDS use case.
        int score = OTHER_NETWORK_SCORE;
        // TODO: Should update the score when attached list changed.
        for (TelephonyNetworkRequest networkRequest : mAttachedNetworkRequestList) {
            if (networkRequest.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                    && networkRequest.getNetworkSpecifier() == null) {
@@ -1916,9 +1932,12 @@ public class DataNetwork extends StateMachine {
        mNetworkAgent.dump(fd, pw, args);

        pw.println("Attached network requests:");
        pw.increaseIndent();
        for (TelephonyNetworkRequest request : mAttachedNetworkRequestList) {
            pw.println(request);
        }
        pw.decreaseIndent();
        pw.println("mQosBearerSessions=" + mQosBearerSessions);

        pw.println("Local logs:");
        pw.increaseIndent();
+54 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 com.android.internal.telephony.data;

import android.annotation.NonNull;
import android.net.NetworkAgent;
import android.net.QosSessionAttributes;

/**
 * The temporary interface that is shared by
 * {@link com.android.internal.telephony.dataconnection.DcNetworkAgent} and
 * {@link com.android.internal.telephony.data.TelephonyNetworkAgent} so they can both interact
 * with {@link QosCallbackTracker}.
 */
// TODO: Remove after DcNetworkAgent is removed.
public interface NotifyQosSessionInterface {
    /**
     * Sends the attributes of Qos Session back to the Application. This method is create for
     * Mockito to mock since
     * {@link NetworkAgent#sendQosSessionAvailable(int, int, QosSessionAttributes)} is
     * {@code final} that can't be mocked.
     *
     * @param qosCallbackId the callback id that the session belongs to.
     * @param sessionId the unique session id across all Qos Sessions.
     * @param attributes the attributes of the Qos Session.
     */
    void notifyQosSessionAvailable(int qosCallbackId, int sessionId,
            @NonNull QosSessionAttributes attributes);

    /**
     * Sends event that the Qos Session was lost. This method is create for Mockito to mock
     * since {@link NetworkAgent#sendQosSessionLost(int, int, int)} is {@code final} that can't be
     * mocked..
     *
     * @param qosCallbackId the callback id that the session belongs to.
     * @param sessionId the unique session id across all Qos Sessions.
     * @param qosSessionType the session type {@code QosSession#QosSessionType}.
     */
    void notifyQosSessionLost(int qosCallbackId, int sessionId, int qosSessionType);
}
+3 −2
Original line number Diff line number Diff line
@@ -17,15 +17,16 @@
package com.android.internal.telephony.dataconnection;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.net.LinkAddress;
import android.net.QosSession;
import android.telephony.TelephonyProtoEnums;
import android.telephony.data.EpsBearerQosSessionAttributes;
import android.telephony.data.EpsQos;
import android.telephony.data.NrQos;
import android.telephony.data.EpsBearerQosSessionAttributes;
import android.telephony.data.NrQosSessionAttributes;
import android.telephony.data.QosBearerFilter;
import android.telephony.data.QosBearerSession;
import android.telephony.TelephonyProtoEnums;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.telephony.metrics.RcsStats;
+78 −10
Original line number Diff line number Diff line
@@ -26,8 +26,10 @@ import android.net.NetworkAgentConfig;
import android.net.NetworkProvider;
import android.net.NetworkScore;
import android.net.QosFilter;
import android.net.QosSessionAttributes;
import android.net.Uri;
import android.os.Looper;
import android.util.ArraySet;
import android.util.IndentingPrintWriter;
import android.util.LocalLog;

@@ -37,6 +39,7 @@ import com.android.telephony.Rlog;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.time.Duration;
import java.util.Set;
import java.util.concurrent.Executor;

/**
@@ -44,7 +47,7 @@ import java.util.concurrent.Executor;
 * for telephony to propagate network related information to the connectivity service. It always
 * has an associated parent {@link DataNetwork}.
 */
public class TelephonyNetworkAgent extends NetworkAgent {
public class TelephonyNetworkAgent extends NetworkAgent implements NotifyQosSessionInterface {
    private final String mLogTag;
    private final Phone mPhone;
    private final LocalLog mLocalLog = new LocalLog(128);
@@ -55,8 +58,12 @@ public class TelephonyNetworkAgent extends NetworkAgent {
    /** This is the id from {@link NetworkAgent#register()}. */
    private final int mId;

    /** The callback that is used to pass information to {@link DataNetwork}. */
    private @NonNull TelephonyNetworkAgentCallback mTelephonyNetworkAgentCallback;
    /**
     * The callbacks that are used to pass information to {@link DataNetwork} and
     * {@link QosCallbackTracker}.
     */
    private final @NonNull Set<TelephonyNetworkAgentCallback> mTelephonyNetworkAgentCallbacks =
            new ArraySet<>();

    /**
     * Telephony network agent callback. This should be only used by {@link DataNetwork}.
@@ -82,9 +89,26 @@ public class TelephonyNetworkAgent extends NetworkAgent {
         *
         * @see NetworkAgent#onValidationStatus(int, Uri)
         */
        public abstract void onValidationStatus(
                @android.telephony.Annotation.ValidationStatus int status,
                @Nullable Uri redirectUri);
        public void onValidationStatus(@android.telephony.Annotation.ValidationStatus int status,
                @Nullable Uri redirectUri) {}

        /**
         * Called when a qos callback is registered with a filter.
         *
         * @param qosCallbackId the id for the callback registered
         * @param filter the filter being registered
         */
        public void onQosCallbackRegistered(int qosCallbackId, @NonNull QosFilter filter) {}

        /**
         * Called when a qos callback is registered with a filter.
         *
         * Any QoS events that are sent with the same callback id after this method is called are a
         * no-op.
         *
         * @param qosCallbackId the id for the callback being unregistered.
         */
        public void onQosCallbackUnregistered(int qosCallbackId) {}
    }

    /**
@@ -107,7 +131,7 @@ public class TelephonyNetworkAgent extends NetworkAgent {
                provider);
        register();
        mDataNetwork = dataNetwork;
        mTelephonyNetworkAgentCallback = callback;
        mTelephonyNetworkAgentCallbacks.add(callback);
        mPhone = phone;
        mId = getNetwork().getNetId();
        mLogTag = "TNA-" + mId;
@@ -144,8 +168,8 @@ public class TelephonyNetworkAgent extends NetworkAgent {
    @Override
    public void onValidationStatus(@android.telephony.Annotation.ValidationStatus int status,
            @Nullable Uri redirectUri) {
        mTelephonyNetworkAgentCallback.invokeFromExecutor(()
                -> mTelephonyNetworkAgentCallback.onValidationStatus(status, redirectUri));
        mTelephonyNetworkAgentCallbacks.forEach(callback -> callback.invokeFromExecutor(
                () -> callback.onValidationStatus(status, redirectUri)));
    }

    /**
@@ -191,7 +215,8 @@ public class TelephonyNetworkAgent extends NetworkAgent {
     */
    @Override
    public void onQosCallbackRegistered(final int qosCallbackId, final @NonNull QosFilter filter) {

        mTelephonyNetworkAgentCallbacks.forEach(callback -> callback.invokeFromExecutor(
                () -> callback.onQosCallbackRegistered(qosCallbackId, filter)));
    }

    /**
@@ -202,7 +227,50 @@ public class TelephonyNetworkAgent extends NetworkAgent {
     *
     * @param qosCallbackId the id for the callback being unregistered.
     */
    @Override
    public void onQosCallbackUnregistered(final int qosCallbackId) {
        mTelephonyNetworkAgentCallbacks.forEach(callback -> callback.invokeFromExecutor(
                () -> callback.onQosCallbackUnregistered(qosCallbackId)));
    }

    /**
     * Sends the attributes of Qos Session back to the Application. This method is create for
     * Mockito to mock since
     * {@link NetworkAgent#sendQosSessionAvailable(int, int, QosSessionAttributes)} is
     * {@code final} that can't be mocked.
     *
     * @param qosCallbackId the callback id that the session belongs to.
     * @param sessionId the unique session id across all Qos Sessions.
     * @param attributes the attributes of the Qos Session.
     */
    @Override
    public void notifyQosSessionAvailable(final int qosCallbackId, final int sessionId,
            @NonNull final QosSessionAttributes attributes) {
        super.sendQosSessionAvailable(qosCallbackId, sessionId, attributes);
    }

    /**
     * Sends event that the Qos Session was lost. This method is create for Mockito to mock
     * since {@link NetworkAgent#sendQosSessionLost(int, int, int)} is {@code final} that can't be
     * mocked..
     *
     * @param qosCallbackId the callback id that the session belongs to.
     * @param sessionId the unique session id across all Qos Sessions.
     * @param qosSessionType the session type {@code QosSession#QosSessionType}.
     */
    @Override
    public void notifyQosSessionLost(final int qosCallbackId,
            final int sessionId, final int qosSessionType) {
        super.sendQosSessionLost(qosCallbackId, sessionId, qosSessionType);
    }

    /**
     * Register the callback for receiving information from {@link TelephonyNetworkAgent}.
     *
     * @param callback The callback.
     */
    public void registerCallback(@NonNull TelephonyNetworkAgentCallback callback) {
        mTelephonyNetworkAgentCallbacks.add(callback);
    }

    /**
+6 −2
Original line number Diff line number Diff line
@@ -45,6 +45,8 @@ import com.android.internal.telephony.DctConstants;
import com.android.internal.telephony.Phone;
import com.android.internal.telephony.RILConstants;
import com.android.internal.telephony.SlidingWindowEventCounter;
import com.android.internal.telephony.data.NotifyQosSessionInterface;
import com.android.internal.telephony.data.QosCallbackTracker;
import com.android.internal.telephony.metrics.TelephonyMetrics;
import com.android.internal.util.IndentingPrintWriter;
import com.android.telephony.Rlog;
@@ -72,7 +74,7 @@ import java.util.concurrent.TimeUnit;
 * {@link DataConnection} so for a short window of time this object might be accessed by two
 * different {@link DataConnection}. Thus each method in this class needs to be synchronized.
 */
public class DcNetworkAgent extends NetworkAgent {
public class DcNetworkAgent extends NetworkAgent implements NotifyQosSessionInterface {
    private final String mTag;

    private final int mId;
@@ -118,7 +120,7 @@ public class DcNetworkAgent extends NetworkAgent {
        } else {
            loge("The connection does not have a valid link properties.");
        }
        mQosCallbackTracker = new QosCallbackTracker(this, mPhone.getPhoneId());
        mQosCallbackTracker = new QosCallbackTracker(this, mPhone);
    }

    private @NetworkType int getNetworkType() {
@@ -412,11 +414,13 @@ public class DcNetworkAgent extends NetworkAgent {
        mQosCallbackExecutor.execute(() -> mQosCallbackTracker.updateSessions(qosBearerSessions));
    }

    @Override
    public void notifyQosSessionAvailable(final int qosCallbackId, final int sessionId,
            @NonNull final QosSessionAttributes attributes) {
        super.sendQosSessionAvailable(qosCallbackId, sessionId, attributes);
    }

    @Override
    public void notifyQosSessionLost(final int qosCallbackId,
            final int sessionId, final int qosSessionType) {
        super.sendQosSessionLost(qosCallbackId, sessionId, qosSessionType);
Loading