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

Commit a4335f08 authored by Shuo Qian's avatar Shuo Qian Committed by Gerrit Code Review
Browse files

Merge "Make hidden API isDataCapable for Telephony"

parents ee667903 3ba4afa5
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -9601,6 +9601,7 @@ package android.telephony {
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isAnyRadioPoweredOn();
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isApplicationOnUicc(int);
    method public boolean isCurrentSimOperator(@NonNull String, int, @Nullable String);
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isDataConnectionEnabled();
    method public boolean isDataConnectivityPossible();
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isDataEnabledForApn(int);
    method @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE) public boolean isEmergencyAssistanceEnabled();
+1 −1
Original line number Diff line number Diff line
@@ -661,7 +661,7 @@ public class MobileSignalController extends SignalController<
    }

    boolean isDataDisabled() {
        return !mPhone.isDataCapable();
        return !mPhone.isDataConnectionEnabled();
    }

    @VisibleForTesting
+1 −1
Original line number Diff line number Diff line
@@ -173,7 +173,7 @@ public class NetworkControllerBaseTest extends SysuiTestCase {
    protected void setupNetworkController() {
        // For now just pretend to be the data sim, so we can test that too.
        mSubId = SubscriptionManager.DEFAULT_SUBSCRIPTION_ID;
        when(mMockTm.isDataCapable()).thenReturn(true);
        when(mMockTm.isDataConnectionEnabled()).thenReturn(true);
        setDefaultSubId(mSubId);
        setSubscriptions(mSubId);
        mMobileSignalController = mNetworkController.mMobileSignalControllers.get(mSubId);
+6 −6
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
    @Test
    public void testNoInternetIcon_withDefaultSub() {
        setupNetworkController();
        when(mMockTm.isDataCapable()).thenReturn(false);
        when(mMockTm.isDataConnectionEnabled()).thenReturn(false);
        setupDefaultSignal();
        updateDataConnectionState(TelephonyManager.DATA_CONNECTED, 0);
        setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false);
@@ -138,7 +138,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
    @Test
    public void testDataDisabledIcon_withDefaultSub() {
        setupNetworkController();
        when(mMockTm.isDataCapable()).thenReturn(false);
        when(mMockTm.isDataConnectionEnabled()).thenReturn(false);
        setupDefaultSignal();
        updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0);
        setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false);
@@ -152,7 +152,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
    @Test
    public void testNonDefaultSIM_showsFullSignal_connected() {
        setupNetworkController();
        when(mMockTm.isDataCapable()).thenReturn(false);
        when(mMockTm.isDataConnectionEnabled()).thenReturn(false);
        setupDefaultSignal();
        setDefaultSubId(mSubId + 1);
        updateDataConnectionState(TelephonyManager.DATA_CONNECTED, 0);
@@ -167,7 +167,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
    @Test
    public void testNonDefaultSIM_showsFullSignal_disconnected() {
        setupNetworkController();
        when(mMockTm.isDataCapable()).thenReturn(false);
        when(mMockTm.isDataConnectionEnabled()).thenReturn(false);
        setupDefaultSignal();
        setDefaultSubId(mSubId + 1);
        updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0);
@@ -438,7 +438,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
    @Test
    public void testDataDisabledIcon_UserNotSetup() {
        setupNetworkController();
        when(mMockTm.isDataCapable()).thenReturn(false);
        when(mMockTm.isDataConnectionEnabled()).thenReturn(false);
        setupDefaultSignal();
        updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED, 0);
        setConnectivityViaBroadcast(NetworkCapabilities.TRANSPORT_CELLULAR, false, false);
@@ -453,7 +453,7 @@ public class NetworkControllerDataTest extends NetworkControllerBaseTest {
    @Test
    public void testAlwaysShowDataRatIcon() {
        setupDefaultSignal();
        when(mMockTm.isDataCapable()).thenReturn(false);
        when(mMockTm.isDataConnectionEnabled()).thenReturn(false);
        updateDataConnectionState(TelephonyManager.DATA_DISCONNECTED,
                TelephonyManager.NETWORK_TYPE_GSM);

+28 −11
Original line number Diff line number Diff line
@@ -45,6 +45,7 @@ import android.compat.annotation.UnsupportedAppUsage;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.NetworkStats;
@@ -444,13 +445,9 @@ public class TelephonyManager {
            case UNKNOWN:
                modemCount = MODEM_COUNT_SINGLE_MODEM;
                // check for voice and data support, 0 if not supported
                if (!isVoiceCapable() && !isSmsCapable() && mContext != null) {
                    ConnectivityManager cm = (ConnectivityManager) mContext
                            .getSystemService(Context.CONNECTIVITY_SERVICE);
                    if (cm != null && !cm.isNetworkSupported(ConnectivityManager.TYPE_MOBILE)) {
                if (!isVoiceCapable() && !isSmsCapable() && !isDataCapable()) {
                    modemCount = MODEM_COUNT_NO_MODEM;
                }
                }
                break;
            case DSDS:
            case DSDA:
@@ -10950,12 +10947,21 @@ public class TelephonyManager {
    }

    /**
     * Checks whether cellular data connection is enabled in the device.
     *
     * Whether cellular data connection is enabled, meaning upon request whether will try to setup
     * metered data connection considering all factors below:
     * 1) User turned on data setting {@link #isDataEnabled}.
     * 2) Carrier allows data to be on.
     * 3) Network policy.
     * And possibly others.
     *
     * @return {@code true} if the overall data connection is capable; {@code false} if not.
     * @hide
     * It's similar to isDataEnabled, but unlike isDataEnabled, this API also evaluates
     * carrierDataEnabled, policyDataEnabled etc to give a final decision of whether mobile data is
     * capable of using.
     */
    public boolean isDataCapable() {
    @SystemApi
    @RequiresPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE)
    public boolean isDataConnectionEnabled() {
        boolean retVal = false;
        try {
            int subId = getSubId(SubscriptionManager.getDefaultDataSubscriptionId());
@@ -10963,12 +10969,23 @@ public class TelephonyManager {
            if (telephony != null)
                retVal = telephony.isDataEnabled(subId);
        } catch (RemoteException e) {
            Log.e(TAG, "Error calling ITelephony#isDataEnabled", e);
            Log.e(TAG, "Error isDataConnectionEnabled", e);
        } catch (NullPointerException e) {
        }
        return retVal;
    }

    /**
     * Checks if FEATURE_TELEPHONY_DATA is enabled.
     *
     * @hide
     */
    public boolean isDataCapable() {
        if (mContext == null) return true;
        return mContext.getResources().getBoolean(
                com.android.internal.R.bool.config_mobile_data_capable);
    }

    /**
     * In this mode, modem will not send specified indications when screen is off.
     * @hide