From cd08bb620dc2ee37de80d7239bc6c0c619551db8 Mon Sep 17 00:00:00 2001 From: Nathan Harold Date: Fri, 8 Jan 2021 20:02:25 +0000 Subject: [PATCH] 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 --- core/api/current.txt | 2 +- .../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 252c33c4efda9..c54bdaf967569 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 c05e90b28fa82..e9809e78b86e9 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); }