Skip to content
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

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

Closed
3 tasks done
dev3whistlebiz opened this issue Mar 26, 2024 · 31 comments
Assignees

Comments

@dev3whistlebiz
Copy link

Issue

Inbound call on android is crashing the app.

Pre-submission Checklist

  • I have verified that the issue occurs with the latest release and is not marked as a known issue in the CHANGELOG.md.
  • I reviewed the Common Issues and open GitHub issues and verified that this report represents a potentially new issue.
  • I am not sharing any Personally Identifiable Information (PII)
    or sensitive account information (API keys, credentials, etc.) when reporting this issue.

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.

  • Device: Pixel 7
  • OS: Android

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 dev3whistlebiz changed the title java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord targetSDK=34 requires permissions: all of the permissions allOf=true java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord targetSDK=34 requires permissions Mar 26, 2024
@dev3whistlebiz dev3whistlebiz changed the title java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord targetSDK=34 requires permissions Version 1.0.0 Error: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord targetSDK=34 requires permissions Mar 26, 2024
@dev3whistlebiz
Copy link
Author

Any updates?

@dev3whistlebiz
Copy link
Author

Hey, any updates on this one?

@mhuynh5757
Copy link
Collaborator

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
Copy link
Author

dev3whistlebiz commented Apr 4, 2024

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
Copy link
Collaborator

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

@dev3whistlebiz
Copy link
Author

dev3whistlebiz commented Apr 4, 2024

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
Copy link
Author

Hello, any updates on this one?

@afalls-twilio
Copy link
Collaborator

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

@afalls-twilio
Copy link
Collaborator

afalls-twilio commented Apr 8, 2024

@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
Copy link
Author

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
Copy link
Collaborator

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
Copy link

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

@sshodges
Copy link

@dev3whistlebiz did you manage to find a work around?

@dev3whistlebiz
Copy link
Author

dev3whistlebiz commented Apr 24, 2024

@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
Copy link

@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

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
Copy link

liemdo commented May 13, 2024

We also have this error which is affecting many users.

@mhuynh5757
Copy link
Collaborator

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
Copy link

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
Copy link

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

@Victor-Sun
Copy link

Victor-Sun commented Jul 11, 2024

Hello I am getting this issue as well.
Google just released a new requirement that apps must target API 34 or we will not be able to publish apps on google play. (August 24th deadline)
I have tried patching the package but it doesn't work either.

This is the error that I got:

 ERROR  Your app just crashed. See the error below.
java.lang.RuntimeException: Unable to start service com.twiliovoicereactnative.IncomingCallNotificationService@fd1469c with Intent { act=ACTION_OUTGOING_CALL cmp=xxx/com.twiliovoicereactnative.IncomingCallNotificationService (has extras) }: android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{df46454 15772:xxx/u0a474} targetSDK=34
  android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5100)
  android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:2432)
  android.os.Handler.dispatchMessage(Handler.java:107)
  android.os.Looper.loopOnce(Looper.java:232)
  android.os.Looper.loop(Looper.java:317)
  android.app.ActivityThread.main(ActivityThread.java:8592)
  java.lang.reflect.Method.invoke(Native Method)
  com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)
Caused by android.app.MissingForegroundServiceTypeException: Starting FGS without a type  callerApp=ProcessRecord{df46454 15772:xxx/u0a474} targetSDK=34
  android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:53)
  android.app.MissingForegroundServiceTypeException$1.createFromParcel(MissingForegroundServiceTypeException.java:49)
  android.os.Parcel.readParcelableInternal(Parcel.java:5016)
  android.os.Parcel.readParcelable(Parcel.java:4998)
  android.os.Parcel.createExceptionOrNull(Parcel.java:3178)
  android.os.Parcel.createException(Parcel.java:3167)
  android.os.Parcel.readException(Parcel.java:3150)
  android.os.Parcel.readException(Parcel.java:3092)
  android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:6960)
  android.app.Service.startForeground(Service.java:776)
  com.twiliovoicereactnative.IncomingCallNotificationService.handleOutgoingCall(IncomingCallNotificationService.java:147)
  com.twiliovoicereactnative.IncomingCallNotificationService.onStartCommand(IncomingCallNotificationService.java:76)
  android.app.ActivityThread.handleServiceArgs(ActivityThread.java:5082)
  android.app.ActivityThread.-$$Nest$mhandleServiceArgs(Unknown Source:0)
  android.app.ActivityThread$H.handleMessage(ActivityThread.java:2432)
  android.os.Handler.dispatchMessage(Handler.java:107)
  android.os.Looper.loopOnce(Looper.java:232)
  android.os.Looper.loop(Looper.java:317)
  android.app.ActivityThread.main(ActivityThread.java:8592)
  java.lang.reflect.Method.invoke(Native Method)
  com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580)
  com.android.internal.os.ZygoteInit.main(ZygoteInit.java:878)

@Victor-Sun
Copy link

Victor-Sun commented Jul 17, 2024

@mhuynh5757 Do you know if there is a timeline for this? As currently google is planning on deprecating API 33 (Won't be able to push to the app store) in August and requiring API 34.
When I try to build using the current code which would be the 1.0.1-dev I get the error described in this issue: #348

@vlassius
Copy link

vlassius commented Jul 24, 2024

same error

<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MICROPHONE"/>

  startForeground(NOTIFICATION_ID_FOREGROUND_SERVICE,
                        prepareNotification(),
                        FOREGROUND_SERVICE_TYPE_MICROPHONE );

java.lang.RuntimeException: Unable to start service com.mais.appmais.serviceAssistente.ServiceAssistente@2a04ad9 with Intent { act=start cmp=com.mais.appmais/.serviceAssistente.ServiceAssistente }: java.lang.SecurityException: Starting FGS with type microphone callerApp=ProcessRecord{2c3308b 13436:com.mais.appmais/u0a190} 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

@mhuynh5757
Copy link
Collaborator

Hi all, thanks for bringing this to our attention. I'll discuss creating a release with the team.

@Victor-Sun do you experience that error even after following the new Android integration documentation?

@Victor-Sun
Copy link

Hi all, thanks for bringing this to our attention. I'll discuss creating a release with the team.

@Victor-Sun do you experience that error even after following the new Android integration documentation?

Hi @mhuynh5757 Yes I receive the same error

@liemdo
Copy link

liemdo commented Aug 13, 2024

Is there a workaround for this issue? Android phones crash because of this error.

@mhuynh5757
Copy link
Collaborator

Hey @Victor-Sun I tested the release candidate 1.1.0-rc1 on Android API 34 and I'm seeing the error that you're describing. If I'm understanding you correctly, it's not the same issue as the original one posted in this issue, correct? If so, please feel free to create another issue.

@mhuynh5757
Copy link
Collaborator

@liemdo are you also referring to the permissions error described originally in this Github Issue?

@mhuynh5757
Copy link
Collaborator

Hey all, version 1.1.0 of the SDK is now live! Please update at your earliest convenience. It should solve this issue, especially regarding Android API 34 support. I'm going to close this issue for now, if you have further need of assistance please open a new issue.

@beeeshaaal
Copy link

For the future reference:
Any one of these permissions need to be granted before starting the foreground service.
[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]

@df13954
Copy link

df13954 commented Dec 13, 2024

For the future reference: Any one of these permissions need to be granted before starting the foreground service. [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]

These permissions indicate that they are system applications and do not exist in the Manifest class when applying for permissions. How should I apply for them?

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