Skip to content

[Android >= 33] firebase request permessions causing app crash #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kefahB opened this issue Oct 27, 2022 · 5 comments
Closed

[Android >= 33] firebase request permessions causing app crash #144

kefahB opened this issue Oct 27, 2022 · 5 comments

Comments

@kefahB
Copy link
Contributor

kefahB commented Oct 27, 2022

Hi @triniwiz :)

Firebase crash the app on requesting permissions, It working fine before upgrading to NS 8.3.5!

  System.err: An uncaught Exception occurred on "main" thread.
  System.err: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=1001, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.cocarz/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onRequestPermissionsResult failed
  System.err: Error: java.lang.ArrayIndexOutOfBoundsException: int[] offset=0 length=1 src.length=0
  System.err:
  System.err: StackTrace:
  System.err: java.lang.RuntimeException: Failure delivering result ResultInfo{who=@android:requestPermissions:, request=1001, result=-1, data=Intent { act=android.content.pm.action.REQUEST_PERMISSIONS (has extras) }} to activity {com.cocarz/com.tns.NativeScriptActivity}: com.tns.NativeScriptException: Calling js method onRequestPermissionsResult failed
  System.err: Error: java.lang.ArrayIndexOutOfBoundsException: int[] offset=0 length=1 src.length=0
  System.err: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5347)
  System.err: 	at android.app.ActivityThread.handleSendResult(ActivityThread.java:5386)
  System.err: 	at android.app.servertransaction.ActivityResultItem.execute(ActivityResultItem.java:67)
  System.err: 	at android.app.servertransaction.ActivityTransactionItem.execute(ActivityTransactionItem.java:45)
  System.err: 	at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
  System.err: 	at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
  System.err: 	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2308)
  System.err: 	at android.os.Handler.dispatchMessage(Handler.java:106)
  System.err: 	at android.os.Looper.loopOnce(Looper.java:201)
  System.err: 	at android.os.Looper.loop(Looper.java:288)
  System.err: 	at android.app.ActivityThread.main(ActivityThread.java:7898)
  System.err: 	at java.lang.reflect.Method.invoke(Native Method)
  System.err: 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
  System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
  System.err: Caused by: com.tns.NativeScriptException: Calling js method onRequestPermissionsResult failed
  System.err: Error: java.lang.ArrayIndexOutOfBoundsException: int[] offset=0 length=1 src.length=0
  System.err: 	at com.tns.Runtime.callJSMethodNative(Native Method)
  System.err: 	at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1302)
  System.err: 	at com.tns.Runtime.callJSMethodImpl(Runtime.java:1188)
  System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:1175)
  System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:1153)
  System.err: 	at com.tns.Runtime.callJSMethod(Runtime.java:1149)
  System.err: 	at com.tns.NativeScriptActivity.onRequestPermissionsResult(NativeScriptActivity.java:71)
  System.err: 	at android.app.Activity.dispatchRequestPermissionsResult(Activity.java:8759)
  System.err: 	at android.app.Activity.dispatchActivityResult(Activity.java:8617)
  System.err: 	at android.app.ActivityThread.deliverResults(ActivityThread.java:5340)
  System.err: 	... 13 more
  System.err: Caused by: java.lang.ArrayIndexOutOfBoundsException: int[] offset=0 length=1 src.length=0
  System.err: 	... 23 more
@kefahB kefahB changed the title [Android] firebase request permessions causing app crash [Android >= 33] firebase request permessions causing app crash Oct 28, 2022
@kefahB
Copy link
Contributor Author

kefahB commented Oct 28, 2022

@NathanWalker @triniwiz

this line causing the crash more specifically this event.grantResults[0] .. according to the Android docs grantResults is an int value not array.

But even though the permission was not granted!

@kefahB
Copy link
Contributor Author

kefahB commented Oct 28, 2022

Strange think that the docs say's that grantResults can be either PackageManager.PERMISSION_GRANTE or PackageManager.PERMISSION_DENIED Never null. but the result on the console is [I@bd26b67

@triniwiz
Copy link
Member

Seems like an error on my part 😫

@kefahB
Copy link
Contributor Author

kefahB commented Oct 28, 2022

Oh sorry wait .. I am confusing, you are right .. it is array but in the parameters table it is marked as int

public void onRequestPermissionsResult (int requestCode, 
                [String[]](https://developer.android.com/reference/java/lang/String) permissions, 
                int[] grantResults)



Parameters
--
requestCode | int: The request code passed in requestPermissions(java.lang.String[], int).
permissions | String: The requested permissions. Never null.
grantResults | int: The grant results for the corresponding permissions which is either PackageManager.PERMISSION_GRANTED or PackageManager.PERMISSION_DENIED. Never null.

Parameters
requestCode	int: The request code passed in [requestPermissions(java.lang.String[], int)](https://developer.android.com/reference/android/app/Activity#requestPermissions(java.lang.String[],%20int)).
permissions	String: The requested permissions. Never null.
grantResults	int: The grant results for the corresponding permissions which is either [PackageManager.PERMISSION_GRANTED](https://developer.android.com/reference/android/content/pm/PackageManager#PERMISSION_GRANTED) or [PackageManager.PERMISSION_DENIED](https://developer.android.com/reference/android/content/pm/PackageManager#PERMISSION_DENIED). Never null.

@kefahB
Copy link
Contributor Author

kefahB commented Oct 28, 2022

The final result that is an empty array .. for that the app crash with Error: java.lang.ArrayIndexOutOfBoundsException.

to prevent the crash we should add this but the permission not granted! because the plugin doesn't popup the UI until you exit the app or finishing the app and restarting again !! (please not: if I modify the app and restart it from livesync it doesn't open the permission dialog) the app should be finished or killed

the docs tel:

Note: It is possible that the permissions request interaction with the user is interrupted. In this case you will receive empty permissions and results arrays which should be treated as a cancellation.

if (event.requestCode === 1001) {
      if(event.grantResults.length > 0) {
          if (event.grantResults[0] === android.content.pm.PackageManager.PERMISSION_GRANTED) {
              resolve(0);
          }
          else {
              reject(1);
          }
      }
      else {
          reject(1);
      }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants