From eb137aebc998cb6869d3679bec409746658d97c6 Mon Sep 17 00:00:00 2001 From: Chalard Jean Date: Tue, 26 Sep 2017 15:45:18 +0900 Subject: [PATCH] Do not throw on call to isTetheringSupported w/o permission ...just return false instead. Test: Made an app to test this. Made sure it doesn't have Test: the required permission. Checked it crashes with Test: SecurityException without this change. Checked that it Test: doesn't with it. Merged-In: Ib5b17a7f68c1327f47fe1f54c0454c51f4226907 Change-Id: Id20d3c240ec5d70d085e0366b92ab3a514f3e7c8 (cherry picked from commit ffacaef81322fcdcaba54ec3c6b6026c23c6ff3c) --- core/java/android/net/ConnectivityManager.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/core/java/android/net/ConnectivityManager.java b/core/java/android/net/ConnectivityManager.java index 583cf32049..0ccebc1c7a 100644 --- a/core/java/android/net/ConnectivityManager.java +++ b/core/java/android/net/ConnectivityManager.java @@ -2084,16 +2084,30 @@ public class ConnectivityManager { * {@code ro.tether.denied} system property, Settings.TETHER_SUPPORTED or * due to device configuration. * + *

If this app does not have permission to use this API, it will always + * return false rather than throw an exception.

+ * + *

If the device has a hotspot provisioning app, the caller is required to hold the + * {@link android.Manifest.permission.TETHER_PRIVILEGED} permission.

+ * + *

Otherwise, this method requires the caller to hold the ability to modify system + * settings as determined by {@link android.provider.Settings.System#canWrite}.

+ * * @return a boolean - {@code true} indicating Tethering is supported. * * {@hide} */ @SystemApi - @RequiresPermission(android.Manifest.permission.TETHER_PRIVILEGED) + @RequiresPermission(anyOf = {android.Manifest.permission.TETHER_PRIVILEGED, + android.Manifest.permission.WRITE_SETTINGS}) public boolean isTetheringSupported() { + String pkgName = mContext.getOpPackageName(); try { - String pkgName = mContext.getOpPackageName(); return mService.isTetheringSupported(pkgName); + } catch (SecurityException e) { + // This API is not available to this caller, but for backward-compatibility + // this will just return false instead of throwing. + return false; } catch (RemoteException e) { throw e.rethrowFromSystemServer(); }