From 68f628351e1171020b68b16e6e1371c45a8d21e3 Mon Sep 17 00:00:00 2001 From: Sooraj Sasindran Date: Tue, 5 May 2020 10:53:57 -0700 Subject: [PATCH] Make sure to handle exceptions for setDataEnabled Make sure to handle exceptions for setDataEnabledWithReason and isDataEnabledWithReason when they are called within existing APIs Bug: 155765311 Test: build Change-Id: If59deaca05b841c8c896c449445434b4181c9626 --- .../android/telephony/TelephonyManager.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/telephony/java/android/telephony/TelephonyManager.java b/telephony/java/android/telephony/TelephonyManager.java index b3d7e769791c8..312cb1480508c 100644 --- a/telephony/java/android/telephony/TelephonyManager.java +++ b/telephony/java/android/telephony/TelephonyManager.java @@ -9112,7 +9112,11 @@ public class TelephonyManager { @Deprecated @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setDataEnabled(int subId, boolean enable) { - setDataEnabledWithReason(subId, DATA_ENABLED_REASON_USER, enable); + try { + setDataEnabledWithReason(subId, DATA_ENABLED_REASON_USER, enable); + } catch (RuntimeException e) { + Log.e(TAG, "Error calling setDataEnabledWithReason e:" + e); + } } /** @@ -9319,7 +9323,12 @@ public class TelephonyManager { @Deprecated @SystemApi public boolean getDataEnabled(int subId) { - return isDataEnabledWithReason(DATA_ENABLED_REASON_USER); + try { + return isDataEnabledWithReason(DATA_ENABLED_REASON_USER); + } catch (RuntimeException e) { + Log.e(TAG, "Error calling isDataEnabledWithReason e:" + e); + } + return false; } /** @@ -10878,7 +10887,11 @@ public class TelephonyManager { @SystemApi @RequiresPermission(android.Manifest.permission.MODIFY_PHONE_STATE) public void setCarrierDataEnabled(boolean enabled) { - setDataEnabledWithReason(DATA_ENABLED_REASON_CARRIER, enabled); + try { + setDataEnabledWithReason(DATA_ENABLED_REASON_CARRIER, enabled); + } catch (RuntimeException e) { + Log.e(TAG, "Error calling setDataEnabledWithReason e:" + e); + } } /** @@ -10970,7 +10983,11 @@ public class TelephonyManager { @Deprecated @RequiresPermission(Manifest.permission.MODIFY_PHONE_STATE) public void setPolicyDataEnabled(boolean enabled) { - setDataEnabledWithReason(DATA_ENABLED_REASON_POLICY, enabled); + try { + setDataEnabledWithReason(DATA_ENABLED_REASON_POLICY, enabled); + } catch (RuntimeException e) { + Log.e(TAG, "Error calling setDataEnabledWithReason e:" + e); + } } /** @hide */