twilio / twilio-voice-react-native

Other
62 stars 22 forks source link

Version 1.0.0 Error: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord targetSDK=34 requires permissions #349

Open dev3whistlebiz opened 3 months ago

dev3whistlebiz commented 3 months ago

Issue

Inbound call on android is crashing the app.

Pre-submission Checklist

Description

A clear and concise description of what the issue is. Using expo with react native. On inbound call android is not showing the call and the application is crashing.

Reproduction Steps

  1. Open application.
  2. Background the application.
  3. Receive a call.
  4. Application stopped working, error was thrown.

Expected Behavior

A clear and concise description of what you expected to happen.

  1. Open application.
  2. Background the application.
  3. Receive a call.
  4. Application showed notification.
  5. Call can be accepted/declined.

Actual Behavior

What actually happens.

  1. Open application.
  2. Background the application.
  3. Receive a call.
  4. Application stopped working.
  5. In terminal error is shown as below: ` Your app just crashed. See the error below.

java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord ... targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_MICROPHONE] any of the permissions allOf=false [android.permission.CAPTURE_AUDIO_HOTWORD, android.permission.CAPTURE_AUDIO_OUTPUT, android.permission.CAPTURE_MEDIA_OUTPUT, android.permission.CAPTURE_TUNER_AUDIO_INPUT, android.permission.CAPTURE_VOICE_COMMUNICATION_OUTPUT, android.permission.RECORD_AUDIO] and the app must be in the eligible state/exemptions to access the foreground only permission

android.os.Parcel.createExceptionOrNull(Parcel.java:3182) android.os.Parcel.createException(Parcel.java:3166) android.os.Parcel.readException(Parcel.java:3149) android.os.Parcel.readException(Parcel.java:3091) android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6861) android.app.Service.startForeground(Service.java:862) com.twiliovoicereactnative.VoiceService.foregroundNotification(VoiceService.java:317) com.twiliovoicereactnative.VoiceService.createOrReplaceNotification(VoiceService.java:307) com.twiliovoicereactnative.VoiceService.incomingCall(VoiceService.java:166) com.twiliovoicereactnative.VoiceService.-$$Nest$mincomingCall(Unknown Source:0) com.twiliovoicereactnative.VoiceService$VoiceServiceAPI.incomingCall(VoiceService.java:73) com.twiliovoicereactnative.VoiceFirebaseMessagingService.onCallInvite(VoiceFirebaseMessagingService.java:65) com.twilio.voice.CallInviteProxy.lambda$onCallInvite$0$com-twilio-voice-CallInviteProxy(CallInviteProxy.java:82)
com.twilio.voice.CallInviteProxy$$ExternalSyntheticLambda2.run(Unknown Source:4) android.os.Handler.handleCallback(Handler.java:959) android.os.Handler.dispatchMessage(Handler.java:100) android.os.Looper.loopOnce(Looper.java:232) android.os.Looper.loop(Looper.java:317) android.app.ActivityThread.main(ActivityThread.java:8501) java.lang.reflect.Method.invoke(Native Method) com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552) com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878) Caused by android.os.RemoteException: Remote stack trace: at com.android.server.am.ActiveServices.validateForegroundServiceType(ActiveServices.java:2685) at com.android.server.am.ActiveServices.setServiceForegroundInnerLocked(ActiveServices.java:2375) at com.android.server.am.ActiveServices.setServiceForegroundLocked(ActiveServices.java:1704) at com.android.server.am.ActivityManagerService.setServiceForeground(ActivityManagerService.java:13684)
at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:3430) › Stopped server `

Reproduction Frequency

Is the reproducibility of the issue deterministic? If not, what percentage of the time does the issue occur? In how many attempts was the issue observed?

100%

Screenshots

If applicable, add screenshots to help explain your problem.

Software and Device Information

Please complete the following information.

Additional Context

Add any other context about the problem here.

Manifest.xml has all the permissions that are specified in the error. Those permissions are granted. I am aware of targetSdk 34-th permissions updates regarding android:foregroundServiceType and I set it to microphone.

dev3whistlebiz commented 3 months ago

Any updates?

dev3whistlebiz commented 3 months ago

Hey, any updates on this one?

mhuynh5757 commented 3 months ago

Hi @dev3whistlebiz sorry for the delayed response. Is this an application of your own where you're implementing our SDK, or are you using the Test App that's part of this repo? If you could reproduce this in our Test App (located in the test/app folder) that would help us tremendously.

dev3whistlebiz commented 3 months ago

Hello @mhuynh5757. Thanks for the response. I am implementing your SDK in my application which, unfortunately I cannot share details of, but all the permissions stated in error are defined and accepted (by me on mobile device while testing).

mhuynh5757 commented 3 months ago

Hi @dev3whistlebiz could you try to reproduce this with the Test App that's a part of this repo?

dev3whistlebiz commented 3 months ago

Hello @mhuynh5757, I might try later but for your information I am using Expo. Thanks for response, I am looking forward for any updates!

dev3whistlebiz commented 3 months ago

Hello, any updates on this one?

afalls-twilio commented 3 months ago

@dev3whistlebiz for now, set your target SDK to 33, we will take a look at this and get back to you

afalls-twilio commented 2 months ago

@dev3whistlebiz Our current SDK is targeting API 33, if you want to use API 34, the way to handle this is to add the following to your application's manifest.. <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/> and it should work.

dev3whistlebiz commented 2 months ago

Hello, @afalls-twilio, thanks for the response. Unfortunately, Expo 50 uses API 34, so it is not possible to use 33-rd one. I've tried <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/> before and it was not working as well, no changes. Do you know when it can be possibly resolved? Any feedback would be very much appreciated!!

mhuynh5757 commented 2 months ago

The fix should be complete and merged to main, however we don't have a timeline for the next release. If you are willing to try installing the library through source, it may fix your issue.

sshodges commented 2 months ago

@mhuynh5757 any idea when this is going to be released? getting the same error (Expo, API 34)

sshodges commented 2 months ago

@dev3whistlebiz did you manage to find a work around?

dev3whistlebiz commented 2 months ago

@sshodges you can make use of expo plugins and modify manifest by adding there "android:foregroundServiceType": "microphone",. So you will need to call withAndroidManifest, retrieve config and update it as following:

module.exports = function withIntentActivity(config) {

  return withAndroidManifest(config, config => {

    config.modResults = addAttributesToMainActivity(config.modResults);
    return config;

  });

};

Where addAttributesToMainActivity is your own function which modifies manifest to have property mentioned above (in my case it was push notifications service). See simplified version below:

manifest.application = manifest.application.map(element => {
    const existPushNotificationService = element.service?.some(
      s => s.$["android:name"] === <YOUR NOTIFICATIONS SERVICE NAME>,
    );

    if (!existPushNotificationService ) {
      if (!element.service?.length) {
        element.service = [];
      }

      element.service = [
        ...element.service,
        {
          $: {
             // other fields here
            "android:name": <YOUR NOTIFICATIONS SERVICE NAME>,
       -> "android:foregroundServiceType": "microphone",
          },
        },
      ];
    }

    return element;
  });

You can start from this template, modify it and see if it works. Please note that this is just workaround. I am also looking forward for release of the fix.

sshodges commented 2 months ago

@dev3whistlebiz this doesn't seem to be working for me, have you written a custom Foreground Service? i was targeting the com.twiliovoicereactnative.VoiceService. Seems like the manifest has the FOREGROUND_SERVICE_MICROPHONE permission, but still same error. I guess it could be that the SDK still targeting API 33

Jobaer-hassan-orangetoolz commented 2 months ago

is there any update on this? i am facing the same issue on this.

  1. open the application
  2. background it
  3. call initiated
  4. app crashes and throw error like this

@mhuynh5757 @afalls-twilio do you guys have some timeline when the next release on live targeting api 34?

liemdo commented 1 month ago

We also have this error which is affecting many users.

mhuynh5757 commented 1 month ago

Hi all, apologies for the lack of communication. We are still working on creating a release that includes this fix. Thanks for your patience.

disolaterX commented 1 month ago

Hi all, apologies for the lack of communication. We are still working on creating a release that includes this fix. Thanks for your patience.

have you figured out the exact way to fix this yet ? If yes then can you share it on android level what is the issue.

Thanks in advance.

sshodges commented 1 month ago

I am still looking for a fix as well, can't release the android version of app until this is fixed