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

Commit c9092789 authored by Jack Yu's avatar Jack Yu Committed by Gerrit Code Review
Browse files

Merge "Fixed TelephonyManager.isDataConnectivityPossible"

parents fa4d40f9 d2600c05
Loading
Loading
Loading
Loading
+7 −6
Original line number Diff line number Diff line
@@ -3684,14 +3684,15 @@ public abstract class Phone extends Handler implements PhoneInternalInterface {
    }

    /**
     * Report on whether data connectivity is allowed for given APN type.
     * Report on whether data connectivity is allowed for internet.
     *
     * @param apnType APN type
     *
     * @return True if data is allowed to be established.
     * @return {@code true} if internet data is allowed to be established.
     */
    public boolean isDataAllowed(@ApnType int apnType) {
        return isDataAllowed(apnType, null);
    public boolean isDataAllowed() {
        if (isUsingNewDataStack()) {
            return getDataNetworkController().isInternetDataAllowed();
        }
        return isDataAllowed(ApnSetting.TYPE_DEFAULT, null);
    }

    /**
+3 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.internal.telephony.data;
import android.annotation.CurrentTimeMillisLong;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.telephony.TelephonyManager;
import android.telephony.data.DataProfile;

import com.android.internal.annotations.VisibleForTesting;
@@ -219,6 +220,8 @@ public class DataEvaluation {
         * same time.
         */
        SINGLE_DATA_NETWORK_ARBITRATION,
        /** Query from {@link TelephonyManager#isDataConnectivityPossible()}. */
        EXTERNAL_QUERY,
    }

    /** Disallowed reasons. There could be multiple reasons if it is not allowed. */
+21 −0
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.net.NetworkAgent;
import android.net.NetworkCapabilities;
import android.net.NetworkPolicyManager;
import android.net.NetworkPolicyManager.SubscriptionCallback;
import android.net.NetworkRequest;
import android.net.Uri;
import android.os.AsyncResult;
import android.os.Handler;
@@ -1220,6 +1221,26 @@ public class DataNetworkController extends Handler {
                .contains(getDataNetworkType(transport));
    }

    /**
     * Evaluate if telephony frameworks would allow data setup for internet in current environment.
     *
     * @return {@code true} if the environment is allowed for internet data. {@code false} if not
     * allowed. For example, if SIM is absent, or airplane mode is on, then data is NOT allowed.
     * This API does not reflect the currently internet data network status. It's possible there is
     * no internet data due to weak cellular signal or network side issue, but internet data is
     * still allowed in this case.
     */
    public boolean isInternetDataAllowed() {
        TelephonyNetworkRequest internetRequest = new TelephonyNetworkRequest(
                new NetworkRequest.Builder()
                        .addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET)
                        .addTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
                        .build(), mPhone);
        DataEvaluation evaluation = evaluateNetworkRequest(internetRequest,
                DataEvaluationReason.EXTERNAL_QUERY);
        return !evaluation.containsDisallowedReasons();
    }

    /**
     * Evaluate a network request. The goal is to find a suitable {@link DataProfile} that can be
     * used to setup the data network.
+1 −1
Original line number Diff line number Diff line
@@ -471,7 +471,7 @@ abstract class ImsPhoneBase extends Phone {
    }

    @Override
    public boolean isDataAllowed(int apnType) {
    public boolean isDataAllowed() {
        return false;
    }