iZettle / sdk-android

Add card payments from Zettle to your own app
https://developer.zettle.com/docs/android-sdk
24 stars 20 forks source link

SecurityException when calling getNetworkCapabilities() on Android 11 in release-1.14.15 #40

Closed planetcoops closed 2 years ago

planetcoops commented 2 years ago

Expected Behavior

No crash

Current Behavior

Crash with stack:

java.lang.RuntimeException: at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6759) at android.app.ActivityThread.access$1400 (ActivityThread.java:244) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1952) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:223) at android.app.ActivityThread.main (ActivityThread.java:7700) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:612) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:997) Caused by: java.lang.SecurityException: at android.os.Parcel.createExceptionOrNull (Parcel.java:2373) at android.os.Parcel.createException (Parcel.java:2357) at android.os.Parcel.readException (Parcel.java:2340) at android.os.Parcel.readException (Parcel.java:2282) at android.net.IConnectivityManager$Stub$Proxy.getNetworkCapabilities (IConnectivityManager.java:2456) at android.net.ConnectivityManager.getNetworkCapabilities (ConnectivityManager.java:1417) at com.izettle.android.commons.network.NetworkImplV21. (NetworkImplV21.java:199) at com.izettle.android.commons.network.NetworkImplV21. (NetworkImplV21.java:190) at com.izettle.android.commons.network.Network$Companion.create (Network.java:111) at com.izettle.payments.android.sdk.IZettleSDK$Instance.init (IZettleSDK.java:139) at com.izettle.payments.android.sdk.IZettleSDK$Instance.init (IZettleSDK.java:113) at com.planetcoops.android.taximeter.TaximeterApplication.onCreate (TaximeterApplication.java:88) at android.app.Instrumentation.callApplicationOnCreate (Instrumentation.java:1192) at android.app.ActivityThread.handleBindApplication (ActivityThread.java:6754) at android.app.ActivityThread.access$1400 (ActivityThread.java:244) at android.app.ActivityThread$H.handleMessage (ActivityThread.java:1952) at android.os.Handler.dispatchMessage (Handler.java:106) at android.os.Looper.loop (Looper.java:223) at android.app.ActivityThread.main (ActivityThread.java:7700) at java.lang.reflect.Method.invoke (Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:612) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:997) Caused by: android.os.RemoteException: at android.app.AppOpsManager.checkPackage (AppOpsManager.java:7757) at com.android.server.MtkConnectivityService.getNetworkCapabilities (MtkConnectivityService.java:1724) at android.net.IConnectivityManager$Stub.onTransact (IConnectivityManager.java:978) at android.os.Binder.execTransactInternal (Binder.java:1154) at android.os.Binder.execTransact (Binder.java:1123)

Steps to Reproduce

Appears to crash on Android 11 when calling the iZettle SDK's init. The SecurityException is thrown when calling the ConnectivityManager's getNetworkCapabilites() and the issue is described here, https://stackoverflow.com/questions/67886957/securityexception-when-calling-getnetworkcapabilities-on-android-11

It would appear to be intermittent so catching the exception and retrying might be a way to workaround the issue?

Context

Nokia 2.4 running Android 11 SDK 1.14.15

Failure Logs

-

bobzettle commented 2 years ago

Hi, thank you for the report.

It seems like it's an Android bug and will be fixed when the devices receive an OS patch. But I will add to our backlog to handle the exception better, we just need to resolve how to proceed first.

planetcoops commented 2 years ago

The underlying bug was resolved by Google in Android 12 (S) but understand that some devices may never receive an update from 11 to 12. Catching the exception and retrying another couple of times before re-throwing may mitigate the problem.

bobzettle commented 2 years ago

This issue is adressed in the next release. The SDK will handle the unexpected exception better and we haven't spotted any unexpected behavior.

bobzettle commented 2 years ago

A fix is released in version 1.24.0