apptentive / apptentive-android

Apptentive Android SDK
http://www.apptentive.com
BSD 3-Clause "New" or "Revised" License
65 stars 64 forks source link

Android 11 doesn't allow access to Network Type without dangerous permission #208

Closed simonsickle closed 3 years ago

simonsickle commented 3 years ago

Starting in Android SDK 30, TelephonyManager.getNetworkType() is depreciated and replaced by TelephonyManager.getDataNetworkType().

To use getDataNetworkType() the application must have either carrier permissions (as in, be a cell phone carrier such as AT&T or Verizon Wireless) or request READ_PHONE_STATE which is a dangerous permission requiring user approval.

This only applies to apps built against SDK 30, which we currently have done in order to support APIs. This means as a workaround, if you can target SDK <= 29 for your build then you will not see this issue.

Expected AppTentive surveys and dialogs should be shown on Android 11 when the app consuming the library is targeting SDK 30.

Actual AppTentive surveys and dialogs are not shown due to exception while trying to access the network type when on an Android 11 device and the build targets SDK 30.

Fix Unless used elsewhere for functionality outside of analytics, TelephonyManager.getNetworkType() should be included in a try/catch to allow the library to continue working on newer devices. See https://github.com/apptentive/apptentive-android/blob/master/apptentive/src/main/java/com/apptentive/android/sdk/storage/DeviceManager.java#L73

CaseyApptentive commented 3 years ago

Hi @simonsickle . Thanks for reaching out. This is on my engineering team's roadmap right now, and we're working on a solution. We've historically collected network type to make available as a targeting option for things like Surveys (e.g. show x Survey only to your customers that are on T-Mobile's network). We may have to change that moving forward.

Stay tuned and I'll update you as soon as we have a fix.

simonsickle commented 3 years ago

I have a pull request ready, https://github.com/apptentive/apptentive-android/pull/209, which fixes Android 11 and allows apps requiring the network type to still request it from the user.

weeeBox commented 3 years ago

Fixed in 5.5.4