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

Commit cd08bb62 authored by Nathan Harold's avatar Nathan Harold
Browse files

Revert "Revert "Fix permission on TM#isDataEnabled""

This reverts commit 8ce575b2.

Bug: 176163590
Bug: 148500541
Test: manual smoke test on low-end device and aosp_crosshatch builds.
Reason for revert: Reapplying with a fix for the exceptions.

The exceptions were caused by an undocumented behavior difference in the APIs that just blindly catch runtime exceptions. The cause of the runtime exceptions is that people are calling isDataEnabled() before telephony is running; however, until a "better" fix is available, this API will apply the existing behavior of just catching the runtime exceptions (which is terrible, but it's the plan of record in the code today).

Change-Id: I9fbe7126ee7039dfb0b383f83017458a3525db66
parent 9e169060
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -41090,7 +41090,7 @@ package android.telephony {
    method @Deprecated public String iccTransmitApduLogicalChannel(int, int, int, int, int, int, String);
    method public boolean isConcurrentVoiceAndDataSupported();
    method @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_NETWORK_STATE, android.Manifest.permission.READ_PHONE_STATE, "android.permission.READ_PRIVILEGED_PHONE_STATE"}) public boolean isDataConnectionAllowed();
    method @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_NETWORK_STATE, android.Manifest.permission.MODIFY_PHONE_STATE}) public boolean isDataEnabled();
    method @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_NETWORK_STATE, android.Manifest.permission.MODIFY_PHONE_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isDataEnabled();
    method @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_NETWORK_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isDataEnabledForReason(int);
    method @RequiresPermission(anyOf={android.Manifest.permission.ACCESS_NETWORK_STATE, android.Manifest.permission.READ_PHONE_STATE}) public boolean isDataRoamingEnabled();
    method public boolean isEmergencyNumber(@NonNull String);
+10 −3
Original line number Diff line number Diff line
@@ -9438,9 +9438,16 @@ public class TelephonyManager {
     * @return true if mobile data is enabled.
     */
    @RequiresPermission(anyOf = {android.Manifest.permission.ACCESS_NETWORK_STATE,
            android.Manifest.permission.MODIFY_PHONE_STATE})
            android.Manifest.permission.MODIFY_PHONE_STATE,
            android.Manifest.permission.READ_PHONE_STATE})
    public boolean isDataEnabled() {
        return getDataEnabled(getSubId(SubscriptionManager.getDefaultDataSubscriptionId()));
        try {
            return isDataEnabledForReason(DATA_ENABLED_REASON_USER);
        } catch (IllegalStateException ise) {
            // TODO(b/176163590): Remove this catch once TelephonyManager is booting safely.
            Log.e(TAG, "Error calling #isDataEnabled, returning default (false).", ise);
            return false;
        }
    }
    /**
@@ -9685,7 +9692,7 @@ public class TelephonyManager {
    @SystemApi
    public boolean getDataEnabled(int subId) {
        try {
            return isDataEnabledForReason(DATA_ENABLED_REASON_USER);
            return isDataEnabledForReason(subId, DATA_ENABLED_REASON_USER);
        } catch (RuntimeException e) {
            Log.e(TAG, "Error calling isDataEnabledForReason e:" + e);
        }