WebsiteBeaver / CordovaCall

Cordova CallKit & ConnectionService plugin for iOS/Android that displays the native call UI for VOIP apps
MIT License
196 stars 91 forks source link

HTC One A9 - Call rejected immediately on Android 6.0 #21

Open abardik opened 6 years ago

abardik commented 6 years ago

Hi, thank you for your plugin. On iOS it works fine. But on Android I have the following sequence of events when notification received:

  1. receiveCall success callback
  2. onReceiveCall
  3. onReject

And than a missed call in notification center. Sometimes 2 and 3 events appears twice in one call. The same behavior in foreground and background mode.

I allowed incoming internet calls in Settings, but there are no applications in Accounts, as you described in docs. So maybe it is a problem. When internet calls have been disallowed, I've been receiving the connection screen, but call has been rejected immediatelly without my interaction, but at least I seen it.

There is a code:

// initialization
function initCordovaCall() {
    if ( cordova.plugins.CordovaCall ) {
        cordovaCall = cordova.plugins.CordovaCall;
        cordovaCall.setIncludeInRecents(true);
        cordovaCall.on('sendCall', function() {
            console.log('onSendCall');
        });
        cordovaCall.on('receiveCall', function() {
            console.log('onReceiveCall');
        });
        cordovaCall.on('answer', function() {
            console.log('onAnswer');
        });
        cordovaCall.on('reject', function() {
            console.log('onReject');
        });
        cordovaCall.on('hangup', function() {
            console.log('onHangup');
        });
    }
}

// push notification handler
push.on('notification', function(data) {
    cordovaCall.setVideo(false);
    cordovaCall.receiveCall('John Doe', '1234567', function() {
        console.log('receiveCall success callback');
    }, function(err) {
        console.log('receiveCall error: ' + err);
    });
});

All permissions for my app are allowed (Camera, Microphone, Phone, Storage). Maybe I need to ask for some other permissions on Android? I use Phonegap Build for this project.

Thank you.

dmarcs commented 6 years ago

@abardik I created a new cordova project and ran your code. Everything seems to be working correctly for me as you can see in the animated gif here:

cordovacall-issue

I added the following code in onDeviceReady

// initialization
function initCordovaCall() {
    if ( cordova.plugins.CordovaCall ) {
        cordovaCall = cordova.plugins.CordovaCall;
        cordovaCall.setIncludeInRecents(true);
        cordovaCall.on('sendCall', function() {
            console.log('onSendCall');
        });
        cordovaCall.on('receiveCall', function() {
            console.log('onReceiveCall');
        });
        cordovaCall.on('answer', function() {
            console.log('onAnswer');
        });
        cordovaCall.on('reject', function() {
            console.log('onReject');
        });
        cordovaCall.on('hangup', function() {
            console.log('onHangup');
        });
    }
}

initCordovaCall();

cordovaCall.setVideo(false);
cordovaCall.receiveCall('John Doe', '1234567', function() {
  console.log('receiveCall success callback');
}, function(err) {
  console.log('receiveCall error: ' + err);
});

This is your code minus the push notification handler. As you can see I ran it on my Emulator using Android Nougat on a Nexus. If you still haven't figured out why it's not working for you, please send a video or gif showing what you see. You don't need to modify the manifest file at all. Try creating a new project like I did and run the code below. If that doesn't work let me know.

abardik commented 6 years ago

@dmarcs thanks, I still hope to find the problem, but for now I didn't. I created a very simple project and call receiveCall on user 'click', so it is not from push now, and even more - it's from the user action. But I have the same result below:

android_call

BTW, when I call it from push handler it is even "better" - I don't see virtual buttons, so I can't even close this window or anything. All I have to do - restart the device. And I didn't see that Calling Accounts from your video. I have only Calls and SIP Accounts in my device:

android_settings

I't Android 6.0 on HTC One A9.

D-Marc1 commented 6 years ago

Try running this on your emulator or on a different Android device. Then we can pinpoint if it's the code, device or a PEBCAK issue

dmarcs commented 6 years ago

bug fixed with dfe99b1

Please upgrade to v1.0.7

cordova plugin rm com.dmarc.cordovacall
cordova plugin add cordova-call
abardik commented 6 years ago

Unfortunatelly, the same result.

I read in comments somewhere about singleTop for ConnectionService and already put it in my config.xml:

<preference name="AndroidLaunchMode" value="singleTop" />

Anywhere, still no luck.

My phone has no SIM card, BTW. Maybe that's a problem? I don't have GSM SIM now, so can't check.

dmarcs commented 6 years ago

You don't need a SIM card. receiveCall worked well on my emulator using Android 6.0 on an HTC Dream. If I have time tonight I'll upload a gif that shows it working correctly.

I have a Motorolla physical device that runs this plugin without any problems, and I don't have a SIM card for it. Try running adb logcat *:E in Terminal, and then run your cordova project. Post the error log once you do that please.

abardik commented 6 years ago

I never used emulators or terminals before, just built a project on Phonegap Build and installed it on the device. So, for "adb logcat" I need to learn and use new stuff. Maybe, there is a faster way to get logs from the Android device?

For now, I use another way to handle calls on Android. When the app receives a push, cordova-plugin-background-mode wakes and unlocks the device and brings the app to the foreground. Then app establishes a connection and shows its call GUI, where user can control the call, turn on/off video, mute/unmute, etc.

dmarcs commented 6 years ago

You should be able to use adb logcat if you just plug your HTC into your computer. You don't need an emulator in order to do this.

Then app establishes a connection and shows its call GUI, where user can control the call, turn on/off video, mute/unmute, etc.

Does this mean that you are able to see the native call UI with receiveCall? I was under the impression that receiveCall didn't do anything on your phone, but it sounds like it is bringing up the native call UI as expected. Is the problem that you can't get receiveCall to do anything if the screen is locked? If you're using cordova-plugin-background-mode, it sounds like that's the problem you're having.

abardik commented 6 years ago

Hi, sorry for the delay, I missed your answer. I ment that the app shows its own UI now, not the native one from cordovaCall. It's ok, because it works without any limitations, I can wakeup and unlock the device, bring the app to front and show my own UI (like Skype does on Android). But I think, that Google will restrict that kind of activity in the near future, like Apple did. So, we need to be prepared to use a native call UI, that's why I need cordovaCall on Android.

Backing to cordovaCall. I can see the native UI when I call receiveCall. But, as you can see on the screenshot earlier, the call is appeared already ended (CALL ENDED on the button). If I call cordovaCall.endCall() after few seconds, the native UI shows me a new screen with a prompt to add a missed contact to my Contact List. So, the UI itself works, I believe. But it appers already ENDED with no possibility to close that ENDED screen.

I tried to insert a SIM card. It unlocked some features in Settings -> Calls, but the app did not propose to add it to Call Accounts, like in your video. Maybe, my problem is absent permissions, somehow.

Also I tried with and without cordova-plugin-background-mode, even from simple empty app with one button click, that calls receiveCall - the same result.

dmarcs commented 6 years ago

@abardik I see. Double check the version of CordovaCall you're using with cordova plugin ls and let me know. Also try installing an emulator, and run it there to see if it's a problem with your code or a bug with CordovaCall. I'm also curious to see if running adb logcat *:E gives you anything.

abardik commented 6 years ago

@dmarcs I'm using the last version (1.0.7 as Phonegap Build says). I don't have Android Studio installed because I'm using Phonegap Build. That's why I can't run adb logcat on my PC. But I'll install Studio and run the emulator on this weekend. For today I'll check it on another HTC and let you now soon.

abardik commented 6 years ago

@dmarcs It's working great on emulator! And it's really better UX than my app's call UI. It requested to add my app to Call Accounts and than I've got an incoming call with native UI. Really good. Now I need to understand how to debug it on my HTC... Let you know later.

abardik commented 6 years ago

@dmarcs I've got a logcat from HTC, but it's huge, so I just copy here a ConnectivityService error. On emulator everything is perfect.

02-23 23:50:03.392 4725-4725/? E/ActivityThread: Activity com.android.phone.InCallScreen has leaked ServiceConnection com.htc.lib1.lockscreen.reminder.HtcReminderManagerImpl$1@b5a5432 that was originally bound here android.app.ServiceConnectionLeaked: Activity com.android.phone.InCallScreen has leaked ServiceConnection com.htc.lib1.lockscreen.reminder.HtcReminderManagerImpl$1@b5a5432 that was originally bound here at android.app.LoadedApk$ServiceDispatcher.<init>(LoadedApk.java:1148) at android.app.LoadedApk.getServiceDispatcher(LoadedApk.java:1042) at android.app.ContextImpl.bindServiceCommon(ContextImpl.java:1311) at android.app.ContextImpl.bindService(ContextImpl.java:1294) at com.htc.lib1.lockscreen.reminder.HtcReminderManagerImpl.bindReminderService(HtcReminderManagerImpl.java:89) at com.htc.lib1.lockscreen.reminder.HtcReminderManagerImpl.checkServiceStatus(HtcReminderManagerImpl.java:217) at com.htc.lib1.lockscreen.reminder.HtcReminderManagerImpl.setReminderManager(HtcReminderManagerImpl.java:116) at com.htc.lib1.lockscreen.reminder.HtcReminderManager.<init>(HtcReminderManager.java:38) at com.android.phone.InCallScreen$HtcReminderManagerWrapper.createReminderManager(InCallScreen.java:974) at com.android.phone.InCallScreen$HtcReminderManagerWrapper.registerViewMode(InCallScreen.java:915) at com.android.phone.InCallScreen.handleCallStateChange(InCallScreen.java:12888) at com.android.phone.InCallScreen.handleNewRingingCall(InCallScreen.java:12876) at com.android.incallui.InCallPresenter.onHtcCallStateChange(InCallPresenter.java:1379) at com.android.incallui.InCallPresenter.onCallListChange(InCallPresenter.java:344) at com.android.incallui.InCallPresenter.setActivity(InCallPresenter.java:323) at com.android.phone.InCallScreen.onStart(InCallScreen.java:2791) at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1288) at android.app.Activity.performStart(Activity.java:6264) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2443) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2540) at android.app.ActivityThread.access$900(ActivityThread.java:150) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1390) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:168) at android.app.ActivityThread.main(ActivityThread.java:5781) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:687) 02-23 23:50:03.482 3807-4104/? E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ id=130, legacyType=-1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED] ]

dmarcs commented 6 years ago

Thanks for testing it on the emulator and for the logcat. I don't see anything obvious in the logs. This is a really tough problem, but I'll continue to think about it.

abardik commented 6 years ago

I think, it's not about a plugin or an app. It's about the particular device model, probably.

If it can help, the last time I ran it on HTC, there were a lot of these errors:

E/ConnectivityService: RemoteException caught trying to send a callback msg for NetworkRequest [ id=130, legacyType=-1, [ Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED] ]

dmarcs commented 6 years ago

Yeah that's what it seems like, but I'll leave this issue open in case I'm able to think of a way to fix it. I don't think that error has anything to do with it, but since you're getting so many it's possible. I'll have to look into it more, but it's good that at least you have a working solution for now.

abardik commented 6 years ago

Yes, thank you. I'll try to find other Android devices to check more.

greaterking commented 6 years ago

Confirming the same issue on ...when I test receive call ..nothing happens but that error....were you able ever to resolve?

HTC Android version: 5.0.2

Cordova info: Node version: v8.11.3 Cordova version: 8.0.0

D-Marc1 commented 6 years ago

@greaterking This plugin requires Marshmallow and up, as that's when ConnectionService was introduced.

greaterking commented 6 years ago

Ok thanks ...I missed that some how.

On Wed, Aug 8, 2018 at 6:10 PM Daniel Marcus notifications@github.com wrote:

@greaterking https://github.com/greaterking This plugin requires Marshmallow and up, as that's when ConnectionService was introduced.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/WebsiteBeaver/CordovaCall/issues/21#issuecomment-411569456, or mute the thread https://github.com/notifications/unsubscribe-auth/ADF6F0TaNVj0uHKE_ZZJJ_nrnDHfS0PGks5uO2HlgaJpZM4R8ow2 .

-- Ralph Theart

sido420 commented 6 years ago

I'm facing a similar issue on Android 7.1.1 on ASUS device. I tried with and without a SIM.

What happens is that on receiveCall() I get the option to choose to set calling accounts and upon clicking on "Calling Accounts" option I'm taken to the "Calling accounts" settings page. There I see a SIP Settings menu with the following options:

I've tried playing with all 3 options but as soon as I click back button on this page, I'm taken back to my app and receiveCalls() failure callback gets called. There, I get the error message "You need to accept phone account permissions in order to send and receive calls".

09-08 21:55:47.582  2456  3024 E Telecom : [TELECOM][]: Could not parse subId1 AppName
09-08 21:55:47.582  2456  3024 E Telecom : java.lang.NumberFormatException: For input string: "AppName"
09-08 21:55:47.582  2456  3024 E Telecom :  at java.lang.Integer.parseInt(Integer.java:521)
09-08 21:55:47.582  2456  3024 E Telecom :  at java.lang.Integer.parseInt(Integer.java:556)
09-08 21:55:47.582  2456  3024 E Telecom :  at com.android.server.telecom.PhoneAccountRegistrar$6.compare(PhoneAccountRegistrar.java:943)
09-08 21:55:47.582  2456  3024 E Telecom :  at com.android.server.telecom.PhoneAccountRegistrar$6.compare(PhoneAccountRegistrar.java:934)
09-08 21:55:47.582  2456  3024 E Telecom :  at java.util.TimSort.countRunAndMakeAscending(TimSort.java:351)
09-08 21:55:47.582  2456  3024 E Telecom :  at java.util.TimSort.sort(TimSort.java:216)
09-08 21:55:47.582  2456  3024 E Telecom :  at java.util.Arrays.sort(Arrays.java:1523)
09-08 21:55:47.582  2456  3024 E Telecom :  at java.util.Collections.sort(Collections.java:238)
09-08 21:55:47.582  2456  3024 E Telecom :  at com.android.server.telecom.PhoneAccountRegistrar.getPhoneAccountHandles(PhoneAccountRegistrar.java:933)
09-08 21:55:47.582  2456  3024 E Telecom :  at com.android.server.telecom.PhoneAccountRegistrar.getCallCapablePhoneAccounts(PhoneAccountRegistrar.java:603)
09-08 21:55:47.582  2456  3024 E Telecom :  at com.android.server.telecom.TelecomServiceImpl$1.getCallCapablePhoneAccounts(TelecomServiceImpl.java:197)
09-08 21:55:47.582  2456  3024 E Telecom :  at com.android.internal.telecom.ITelecomService$Stub.onTransact(ITelecomService.java:114)
09-08 21:55:47.582  2456  3024 E Telecom :  at android.os.Binder.execTransact(Binder.java:565)
09-08 21:55:47.715  3415  3433 E PageMarkerHandler: get page marker context failed
09-08 21:55:47.716  3415  3433 E MessengerService: n crash in FocusAppReceiverThread: 0
09-08 21:55:47.716  3415  3433 E MessengerService: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ContentResolver android.content.Context.getContentResolver()' on a null object reference
09-08 21:55:47.716  3415  3433 E MessengerService:  at com.asus.focusapplistener.b.n.a(Unknown Source)
09-08 21:55:47.716  3415  3433 E MessengerService:  at com.asus.focusapplistener.b.n.a(Unknown Source)
09-08 21:55:47.716  3415  3433 E MessengerService:  at com.asus.focusapplistener.MessengerService$g.handleMessage(Unknown Source)
09-08 21:55:47.716  3415  3433 E MessengerService:  at android.os.Handler.dispatchMessage(Handler.java:102)
09-08 21:55:47.716  3415  3433 E MessengerService:  at android.os.Looper.loop(Looper.java:159)
09-08 21:55:47.716  3415  3433 E MessengerService:  at android.os.HandlerThread.run(HandlerThread.java:61)
09-08 21:55:47.961  2163  2308 E libnav  : CablComputeBacklightLevel(): UpdateType = DifferentSceneUpdate
09-08 21:55:49.062  3415  3433 E PageMarkerHandler: get page marker context failed
09-08 21:55:49.063  3415  3433 E MessengerService: n crash in FocusAppReceiverThread: 0
09-08 21:55:49.063  3415  3433 E MessengerService: java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.ContentResolver android.content.Context.getContentResolver()' on a null object reference
09-08 21:55:49.063  3415  3433 E MessengerService:  at com.asus.focusapplistener.b.n.a(Unknown Source)
09-08 21:55:49.063  3415  3433 E MessengerService:  at com.asus.focusapplistener.b.n.a(Unknown Source)
09-08 21:55:49.063  3415  3433 E MessengerService:  at com.asus.focusapplistener.MessengerService$g.handleMessage(Unknown Source)
09-08 21:55:49.063  3415  3433 E MessengerService:  at android.os.Handler.dispatchMessage(Handler.java:102)
09-08 21:55:49.063  3415  3433 E MessengerService:  at android.os.Looper.loop(Looper.java:159)
09-08 21:55:49.063  3415  3433 E MessengerService:  at android.os.HandlerThread.run(HandlerThread.java:61)
09-08 21:55:49.482  2163  2308 E libnav  : CablComputeBacklightLevel(): UpdateType = DifferentSceneUpdate
sido420 commented 6 years ago

Any updates on this? Do I need a new ticket for my issue?

This is one of the last things stopping from a launch.

abardik commented 6 years ago

I tested it on HTC U11 (Android 8.0.0). Everything is fine, as well as on an emulator. And there is still the same error on HTC One A9, and no Call Accounts in Settings, just SIP Accounts. I think, it's a device, not a plugin. Somehow, on some devices this service is not imlpemented properly or disabled for some manufacturer's reasons. For I decided to use wakeup-unlock-foreground and show my own call UI instead of CordovaCall, unfortunatelly.

abardik commented 5 years ago

Hi again! Some new facts about this issue. It's still the same behavior on HTC A9 after upgrade to 1.1.6. In receiveCall error callback I see the following message: "You need to accept phone account permissions in order to send and receive calls". I checked the actual permissions my app has:

Permissions: android.permission.INTERNET android.permission.CAMERA android.permission.RECORD_AUDIO android.permission.MODIFY_AUDIO_SETTINGS android.permission.READ_CONTACTS android.permission.WRITE_CONTACTS android.permission.GET_ACCOUNTS android.permission.READ_PHONE_STATE android.permission.CALL_PHONE android.permission.ADD_VOICEMAIL android.permission.USE_SIP android.permission.PROCESS_OUTGOING_CALLS android.permission.READ_CALL_LOG android.permission.WRITE_CALL_LOG android.permission.READ_EXTERNAL_STORAGE android.permission.WRITE_EXTERNAL_STORAGE android.permission.ACCESS_NETWORK_STATE android.permission.WAKE_LOCK android.permission.VIBRATE android.permission.ACCESS_WIFI_STATE android.permission.BLUETOOTH android.permission.BIND_TELECOM_CONNECTION_SERVICE android.permission.MANAGE_OWN_CALLS com.sec.android.provider.badge.permission.READ com.sec.android.provider.badge.permission.WRITE com.htc.launcher.permission.READ_SETTINGS com.htc.launcher.permission.UPDATE_SHORTCUT com.sonyericsson.home.permission.BROADCAST_BADGE com.sonymobile.home.permission.PROVIDER_INSERT_BADGE com.anddoes.launcher.permission.UPDATE_COUNT com.majeur.launcher.permission.UPDATE_BADGE com.huawei.android.launcher.permission.CHANGE_BADGE com.huawei.android.launcher.permission.READ_SETTINGS com.huawei.android.launcher.permission.WRITE_SETTINGS android.permission.READ_APP_BADGE com.oppo.launcher.permission.READ_SETTINGS com.oppo.launcher.permission.WRITE_SETTINGS me.everything.badger.permission.BADGE_COUNT_READ me.everything.badger.permission.BADGE_COUNT_WRITE com.google.android.c2dm.permission.RECEIVE com.inremote.client.permission.C2D_MESSAGE

Uses features: android.hardware.bluetooth android.hardware.camera android.hardware.faketouch android.hardware.microphone android.hardware.telephony android.hardware.wifi

SDK: Minimum OS version: Jelly Bean 4.1, 4.1.1 Target OS version: Oreo 8.0

Maybe it can help somehow to find out what's going on, because your plugin works just excellent on iOS and other Androids, and I would be happy to wipe my own call UI out and remove a background plugin, which I need to use to wake up and unlock the device to show that UI.

Thank you again for this plugin!

jorhel commented 4 years ago

Hello. i Find this article from the topic: https://www.xda-developers.com/google-restriction-sms-call-log-permissions/