diff options
| author | 2021-01-08 20:02:25 +0000 | |
|---|---|---|
| committer | 2021-01-20 21:30:55 +0000 | |
| commit | cd08bb620dc2ee37de80d7239bc6c0c619551db8 (patch) | |
| tree | 5baa32b4511d1f4c59ff0f8831ea7675abaf0243 | |
| parent | 9e1690609b76f3636c25ad771b446a1e6918d382 (diff) | |
Revert "Revert "Fix permission on TM#isDataEnabled""
This reverts commit 8ce575b256177508d35604f95d5db8c03b09dbfd.
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
| -rw-r--r-- | core/api/current.txt | 2 | ||||
| -rw-r--r-- | telephony/java/android/telephony/TelephonyManager.java | 13 |
2 files changed, 11 insertions, 4 deletions
diff --git a/core/api/current.txt b/core/api/current.txt index 252c33c4efda..c54bdaf96756 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -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); diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index c05e90b28fa8..e9809e78b86e 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -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); } |