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

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

Remove phone from telephony network request

The new TelephonyNetworkProvider would be per-device
instead of per-phone. On dual SIM device, the telephony network
provider would be the singleton communicating with connectivity
service and two TelephonyNetworkController.

Therefore we need to remove the phone depdency from
TelephonyNetworkRequest at the provider layer. This is the preliminary
change before adding TelephonyNetworkProvider.

Flag: EXEMPT refactor
Bug: 343370895
Test: atest TelephonyNetworkFactoryTest DataNetworkTest
Test: Basic telephony functionality tests
Change-Id: Ifc562b6e17c5b5d8817d95192b9352ad4544bec8
parent 19e3e18c
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -1299,6 +1299,13 @@ public class DataNetworkController extends Handler {
     * @param networkRequest The network request.
     */
    private void onAddNetworkRequest(@NonNull TelephonyNetworkRequest networkRequest) {
        // TelephonyNetworkRequest at TelephonyNetworkProvider layer does not have config assigned
        // (Because TelephonyNetworkProvider is a singleton across all SIMs. We are not able to
        // retrieve the right carrier config for it.). So as soon as the request arrives
        // DataNetworkController, we need to update the config in the request so it can update
        // some of its config-dependent properties like request priority.
        networkRequest.updateDataConfig(mDataConfigManager);

        // To detect IMS back-to-back release-request anomaly event
        if (mLastImsOperationIsRelease) {
            mLastImsOperationIsRelease = false;
@@ -1746,7 +1753,9 @@ public class DataNetworkController extends Handler {
                // Check if request is unmetered (WiFi or unmetered APN).
                evaluation.addDataAllowedReason(DataAllowedReason.UNMETERED_USAGE);
            } else if (transport == AccessNetworkConstants.TRANSPORT_TYPE_WWAN) {
                if (!networkRequest.isMeteredRequest()) {
                boolean isMeteredRequest = mDataConfigManager.isAnyMeteredCapability(
                        networkRequest.getCapabilities(), mServiceState.getDataRoaming());
                if (!isMeteredRequest) {
                    evaluation.addDataAllowedReason(DataAllowedReason.UNMETERED_USAGE);
                }
            }
+42 −28
Original line number Diff line number Diff line
@@ -137,10 +137,6 @@ public class TelephonyNetworkRequest {
                CAPABILITY_ATTRIBUTE_APN_SETTING | CAPABILITY_ATTRIBUTE_TRAFFIC_DESCRIPTOR_DNN)
    );

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

    /**
     * Native network request from the clients. See {@link NetworkRequest};
     */
@@ -164,8 +160,8 @@ public class TelephonyNetworkRequest {
    /**
     * Data config manager for retrieving data config.
     */
    @NonNull
    private final DataConfigManager mDataConfigManager;
    @Nullable
    private DataConfigManager mDataConfigManager;

    /**
     * The attached data network. Note that the data network could be in any state. {@code null}
@@ -205,7 +201,19 @@ public class TelephonyNetworkRequest {
     */
    public TelephonyNetworkRequest(@NonNull NetworkRequest request, @NonNull Phone phone,
                                   @NonNull FeatureFlags featureFlags) {
        mPhone = phone;
        this(request, featureFlags);
        mDataConfigManager = phone.getDataNetworkController().getDataConfigManager();
        updatePriority();
    }

    /**
     * Constructor
     *
     * @param request The native network request from the clients.
     * @param featureFlags The feature flag
     */
    public TelephonyNetworkRequest(@NonNull NetworkRequest request,
                                   @NonNull FeatureFlags featureFlags) {
        mNativeNetworkRequest = request;
        mFeatureFlags = featureFlags;

@@ -222,7 +230,15 @@ public class TelephonyNetworkRequest {
        // to satisfy it.
        mState = REQUEST_STATE_UNSATISFIED;
        mCreatedTimeMillis = SystemClock.elapsedRealtime();
        mDataConfigManager = phone.getDataNetworkController().getDataConfigManager();
    }

    /**
     * Update the associated data config manager.
     *
     * @param dataConfigManager Data config manager
     */
    public void updateDataConfig(@NonNull DataConfigManager dataConfigManager) {
        mDataConfigManager = dataConfigManager;
        updatePriority();
    }

@@ -315,6 +331,7 @@ public class TelephonyNetworkRequest {
                if (mNativeNetworkRequest.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR)
                        && !mNativeNetworkRequest.hasTransport(
                                NetworkCapabilities.TRANSPORT_SATELLITE)) {
                    if (mDataConfigManager != null) {
                        if (Arrays.stream(getCapabilities()).noneMatch(mDataConfigManager
                                .getForcedCellularTransportCapabilities()::contains)) {
                            // If the request is explicitly for the cellular, then the data profile
@@ -324,6 +341,7 @@ public class TelephonyNetworkRequest {
                                return false;
                            }
                        }
                    }
                } else if (mNativeNetworkRequest.hasTransport(
                        NetworkCapabilities.TRANSPORT_SATELLITE)
                        && !mNativeNetworkRequest.hasTransport(
@@ -371,11 +389,13 @@ public class TelephonyNetworkRequest {
     * Update the priority from data config manager.
     */
    public void updatePriority() {
        if (mDataConfigManager != null) {
            mPriority = Arrays.stream(mNativeNetworkRequest.getCapabilities())
                    .map(mDataConfigManager::getNetworkCapabilityPriority)
                    .max()
                    .orElse(0);
        }
    }

    /**
     * Get the network capability which is APN-type based from the network request. If there are
@@ -387,6 +407,7 @@ public class TelephonyNetworkRequest {
    @NetCapability
    public int getHighestPriorityApnTypeNetworkCapability() {
        if (!hasAttribute(CAPABILITY_ATTRIBUTE_APN_SETTING)) return -1;
        if (mDataConfigManager == null) return -1;
        return Arrays.stream(getCapabilities()).boxed()
                .filter(cap -> DataUtils.networkCapabilityToApnType(cap) != ApnSetting.TYPE_NONE)
                .max(Comparator.comparingInt(mDataConfigManager::getNetworkCapabilityPriority))
@@ -403,6 +424,7 @@ public class TelephonyNetworkRequest {
     */
    @NetCapability
    public int getHighestPrioritySupportedNetworkCapability() {
        if (mDataConfigManager == null) return -1;
        return Arrays.stream(getCapabilities()).boxed()
                .filter(CAPABILITY_ATTRIBUTE_MAP::containsKey)
                .max(Comparator.comparingInt(mDataConfigManager::getNetworkCapabilityPriority))
@@ -486,14 +508,6 @@ public class TelephonyNetworkRequest {
        return 0;
    }

    /**
     * @return {@code true} if this network request can result in bringing up a metered network.
     */
    public boolean isMeteredRequest() {
        return mDataConfigManager.isAnyMeteredCapability(
                getCapabilities(), mPhone.getServiceState().getDataRoaming());
    }

    /**
     * Get Os/App id from the network request.
     *
@@ -547,7 +561,7 @@ public class TelephonyNetworkRequest {
        return "[" + mNativeNetworkRequest + ", mPriority=" + mPriority
                + ", state=" + requestStateToString(mState)
                + ", mAttachedDataNetwork=" + (mAttachedDataNetwork != null
                ? mAttachedDataNetwork.name() : null) + ", isMetered=" + isMeteredRequest()
                ? mAttachedDataNetwork.name() : null)
                + ", created time=" + DataUtils.elapsedTimeToString(mCreatedTimeMillis)
                + ", evaluation result=" + mEvaluation + "]";
    }