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

Commit ebae9208 authored by Junyu Lai's avatar Junyu Lai Committed by Automerger Merge Worker
Browse files

Merge "[MS42.1] Replace PhoneStateListener with DisplayInfoListener" am:...

Merge "[MS42.1] Replace PhoneStateListener with DisplayInfoListener" am: 39cdfe6a am: f58f298b am: ccd568ad

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1937446

Change-Id: I2fc9647e57bb7b0ed07d5afba0ad7395efbdc5f5
parents 8b5f9b10 ccd568ad
Loading
Loading
Loading
Loading
+17 −17
Original line number Original line Diff line number Diff line
@@ -18,14 +18,16 @@ package com.android.server.net;


import static android.net.NetworkTemplate.NETWORK_TYPE_5G_NSA;
import static android.net.NetworkTemplate.NETWORK_TYPE_5G_NSA;
import static android.net.NetworkTemplate.getCollapsedRatType;
import static android.net.NetworkTemplate.getCollapsedRatType;
import static android.telephony.TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_ADVANCED;
import static android.telephony.TelephonyDisplayInfo.OVERRIDE_NETWORK_TYPE_NR_NSA;
import static android.telephony.TelephonyManager.NETWORK_TYPE_LTE;


import android.annotation.NonNull;
import android.annotation.NonNull;
import android.content.Context;
import android.content.Context;
import android.telephony.Annotation;
import android.telephony.Annotation;
import android.telephony.NetworkRegistrationInfo;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SubscriptionManager;
import android.telephony.SubscriptionManager;
import android.telephony.TelephonyCallback;
import android.telephony.TelephonyDisplayInfo;
import android.telephony.TelephonyManager;
import android.telephony.TelephonyManager;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.Log;
import android.util.Log;
@@ -63,7 +65,7 @@ public class NetworkStatsSubscriptionsMonitor extends
    private final Delegate mDelegate;
    private final Delegate mDelegate;


    /**
    /**
     * Receivers that watches for {@link ServiceState} changes for each subscription, to
     * Receivers that watches for {@link TelephonyDisplayInfo} changes for each subscription, to
     * monitor the transitioning between Radio Access Technology(RAT) types for each sub.
     * monitor the transitioning between Radio Access Technology(RAT) types for each sub.
     */
     */
    @NonNull
    @NonNull
@@ -115,13 +117,12 @@ public class NetworkStatsSubscriptionsMonitor extends
                continue;
                continue;
            }
            }


            final RatTypeListener listener =
            final RatTypeListener listener = new RatTypeListener(this, sub.first, sub.second);
                    new RatTypeListener(mExecutor, this, sub.first, sub.second);
            mRatListeners.add(listener);
            mRatListeners.add(listener);


            // Register listener to the telephony manager that associated with specific sub.
            // Register listener to the telephony manager that associated with specific sub.
            mTeleManager.createForSubscriptionId(sub.first)
            mTeleManager.createForSubscriptionId(sub.first)
                    .listen(listener, PhoneStateListener.LISTEN_SERVICE_STATE);
                    .registerTelephonyCallback(mExecutor, listener);
            Log.d(NetworkStatsService.TAG, "RAT type listener registered for sub " + sub.first);
            Log.d(NetworkStatsService.TAG, "RAT type listener registered for sub " + sub.first);
        }
        }


@@ -175,7 +176,7 @@ public class NetworkStatsSubscriptionsMonitor extends


    private void handleRemoveRatTypeListener(@NonNull RatTypeListener listener) {
    private void handleRemoveRatTypeListener(@NonNull RatTypeListener listener) {
        mTeleManager.createForSubscriptionId(listener.mSubId)
        mTeleManager.createForSubscriptionId(listener.mSubId)
                .listen(listener, PhoneStateListener.LISTEN_NONE);
                .unregisterTelephonyCallback(listener);
        Log.d(NetworkStatsService.TAG, "RAT type listener unregistered for sub " + listener.mSubId);
        Log.d(NetworkStatsService.TAG, "RAT type listener unregistered for sub " + listener.mSubId);
        mRatListeners.remove(listener);
        mRatListeners.remove(listener);


@@ -185,7 +186,8 @@ public class NetworkStatsSubscriptionsMonitor extends
                listener.mSubscriberId, TelephonyManager.NETWORK_TYPE_UNKNOWN);
                listener.mSubscriberId, TelephonyManager.NETWORK_TYPE_UNKNOWN);
    }
    }


    static class RatTypeListener extends PhoneStateListener {
    static class RatTypeListener extends TelephonyCallback
            implements TelephonyCallback.DisplayInfoListener {
        // Unique id for the subscription. See {@link SubscriptionInfo#getSubscriptionId}.
        // Unique id for the subscription. See {@link SubscriptionInfo#getSubscriptionId}.
        @NonNull
        @NonNull
        private final int mSubId;
        private final int mSubId;
@@ -199,29 +201,27 @@ public class NetworkStatsSubscriptionsMonitor extends
        @NonNull
        @NonNull
        private final NetworkStatsSubscriptionsMonitor mMonitor;
        private final NetworkStatsSubscriptionsMonitor mMonitor;


        RatTypeListener(@NonNull Executor executor,
        RatTypeListener(@NonNull NetworkStatsSubscriptionsMonitor monitor, int subId,
                @NonNull NetworkStatsSubscriptionsMonitor monitor, int subId,
                @NonNull String subscriberId) {
                @NonNull String subscriberId) {
            super(executor);
            mSubId = subId;
            mSubId = subId;
            mSubscriberId = subscriberId;
            mSubscriberId = subscriberId;
            mMonitor = monitor;
            mMonitor = monitor;
        }
        }


        @Override
        @Override
        public void onServiceStateChanged(@NonNull ServiceState ss) {
        public void onDisplayInfoChanged(TelephonyDisplayInfo displayInfo) {
            // In 5G SA (Stand Alone) mode, the primary cell itself will be 5G hence telephony
            // In 5G SA (Stand Alone) mode, the primary cell itself will be 5G hence telephony
            // would report RAT = 5G_NR.
            // would report RAT = 5G_NR.
            // However, in 5G NSA (Non Stand Alone) mode, the primary cell is still LTE and
            // However, in 5G NSA (Non Stand Alone) mode, the primary cell is still LTE and
            // network allocates a secondary 5G cell so telephony reports RAT = LTE along with
            // network allocates a secondary 5G cell so telephony reports RAT = LTE along with
            // NR state as connected. In such case, attributes the data usage to NR.
            // NR state as connected. In such case, attributes the data usage to NR.
            // See b/160727498.
            // See b/160727498.
            final boolean is5GNsa = (ss.getDataNetworkType() == TelephonyManager.NETWORK_TYPE_LTE
            final boolean is5GNsa = displayInfo.getNetworkType() == NETWORK_TYPE_LTE
                    || ss.getDataNetworkType() == TelephonyManager.NETWORK_TYPE_LTE_CA)
                    && (displayInfo.getOverrideNetworkType() == OVERRIDE_NETWORK_TYPE_NR_NSA
                    && ss.getNrState() == NetworkRegistrationInfo.NR_STATE_CONNECTED;
                    || displayInfo.getOverrideNetworkType() == OVERRIDE_NETWORK_TYPE_NR_ADVANCED);


            final int networkType =
            final int networkType =
                    (is5GNsa ? NETWORK_TYPE_5G_NSA : ss.getDataNetworkType());
                    (is5GNsa ? NETWORK_TYPE_5G_NSA : displayInfo.getNetworkType());
            final int collapsedRatType = getCollapsedRatType(networkType);
            final int collapsedRatType = getCollapsedRatType(networkType);
            if (collapsedRatType == mLastCollapsedRatType) return;
            if (collapsedRatType == mLastCollapsedRatType) return;