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

Android 8 : app crashes during SMS sending #147

Closed
oleg531 opened this issue Sep 21, 2017 · 25 comments
Closed

Android 8 : app crashes during SMS sending #147

oleg531 opened this issue Sep 21, 2017 · 25 comments

Comments

@oleg531
Copy link

oleg531 commented Sep 21, 2017

Hello!

Recently I updated my Nexus 5x to Android 8.
I am using Ionic 3 (which use under the hood the cordova-sms-plugin) for development
After that, sending SMS starts to cause the app crash (before updating SMS works fine).

Could anyone know what's the reason?

Thanks!

@dbaq
Copy link
Member

dbaq commented Sep 21, 2017

hey @oleg531, can you please check the logcat logs? you probably can find a stacktrace there.

@oleg531
Copy link
Author

oleg531 commented Sep 21, 2017

@dbaq , Thanks for reply!
Here is the part of the output (I thing it's the most meaningful part )

09-22 00:44:50.279 23062 23121 E AndroidRuntime: FATAL EXCEPTION: pool-1-thread-1
09-22 00:44:50.279 23062 23121 E AndroidRuntime: Process: io.ionic.starter, PID: 23062
09-22 00:44:50.279 23062 23121 E AndroidRuntime: java.lang.SecurityException: Neither user 10180 nor current process has android.permission.READ_PHONE_STATE.
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at android.os.Parcel.readException(Parcel.java:1942)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at android.os.Parcel.readException(Parcel.java:1888)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at com.android.internal.telephony.ISms$Stub$Proxy.sendTextForSubscriber(ISms.java:789)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at android.telephony.SmsManager.sendTextMessageInternal(SmsManager.java:329)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at android.telephony.SmsManager.sendTextMessage(SmsManager.java:312)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at com.cordova.plugins.sms.Sms.send(Sms.java:192)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at com.cordova.plugins.sms.Sms.access$400(Sms.java:22)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at com.cordova.plugins.sms.Sms$1.run(Sms.java:102)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
09-22 00:44:50.279 23062 23121 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:764)
09-22 00:44:50.283  3486  6334 W ActivityManager:   Force finishing activity io.ionic.starter/.MainActivity
09-22 00:44:50.291 23062 23062 D CordovaActivity: Paused the activity.
09-22 00:44:50.293  3486  3534 I ActivityManager: Showing crash dialog for package io.ionic.starter u0
09-22 00:44:50.333 11930 19347 W Settings: Setting mobile_data has moved from android.provider.Settings.Secure to android.provider.Settings.Global.
09-22 00:44:50.348  3486 21128 I OpenGLRenderer: Initialized EGL, version 1.4
09-22 00:44:50.348  3486 21128 D OpenGLRenderer: Swap behavior 2
09-22 00:44:50.355  6364  6495 I Adreno  : QUALCOMM build                   : 7142022, Ib5823dd10c
09-22 00:44:50.355  6364  6495 I Adreno  : Build Date                       : 06/23/17
09-22 00:44:50.355  6364  6495 I Adreno  : OpenGL ES Shader Compiler Version: EV031.18.00.00
09-22 00:44:50.355  6364  6495 I Adreno  : Local Branch                     : O11A
09-22 00:44:50.355  6364  6495 I Adreno  : Remote Branch                    :
09-22 00:44:50.355  6364  6495 I Adreno  : Remote Branch                    :
09-22 00:44:50.355  6364  6495 I Adreno  : Reconstruct Branch               :
09-22 00:44:50.358  6364  6495 I vndksupport: sphal namespace is not configured for this process. Loading /vendor/lib64/hw/gralloc.msm8992.so from the current namespace instead.
09-22 00:44:50.362  6364  6495 I Adreno  : PFP: 0x00000000, ME: 0x00000000
09-22 00:44:50.364  6364  6495 I OpenGLRenderer: Initialized EGL, version 1.4
09-22 00:44:50.365  6364  6495 D OpenGLRenderer: Swap behavior 2
09-22 00:44:50.664 23062 23062 D CordovaActivity: Stopped the activity.
09-22 00:44:50.665 23062 23062 D CordovaActivity: CordovaActivity.onDestroy()
09-22 00:44:50.666 23062 23062 D CordovaWebViewImpl: >>> loadUrl(about:blank)
09-22 00:44:50.668 23062 23062 W cr_AwContents: WebView.destroy() called while WebView is still attached to window.
09-22 00:44:50.798 23062 23062 E ActivityThread: Activity io.ionic.starter.MainActivity has leaked IntentReceiver com.cordova.plugins.sms.Sms$2@760a792 that was originally registered here. Are you missing a call to unregisterReceiver()?
09-22 00:44:50.798 23062 23062 E ActivityThread: android.app.IntentReceiverLeaked: Activity io.ionic.starter.MainActivity has leaked IntentReceiver com.cordova.plugins.sms.Sms$2@760a792 that was originally registered here. Are you missing a call to unregisterReceiver()?
09-22 00:44:50.798 23062 23062 E ActivityThread:        at android.app.LoadedApk$ReceiverDispatcher.<init>(LoadedApk.java:1333)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1114)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1405)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1378)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1366)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:603)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at com.cordova.plugins.sms.Sms.send(Sms.java:179)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at com.cordova.plugins.sms.Sms.access$400(Sms.java:22)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at com.cordova.plugins.sms.Sms$1.run(Sms.java:102)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
09-22 00:44:50.798 23062 23062 E ActivityThread:        at java.lang.Thread.run(Thread.java:764)
09-22 00:44:50.825   422   422 E lowmemorykiller: Error writing /proc/23083/oom_score_adj; errno=22
09-22 00:44:50.826  3486 19221 I ActivityManager: Killing 23083:com.android.chrome:sandboxed_process0/u0a180i30 (adj 0): isolated not needed

@dbaq
Copy link
Member

dbaq commented Sep 21, 2017

Thanks for the stacktrace.

It looks like the a permission issue:
Neither user 10180 nor current process has android.permission.READ_PHONE_STATE.

In your config.xml, do you have READ_PHONE_STATE?

@oleg531
Copy link
Author

oleg531 commented Sep 24, 2017

No, I haven't.
It looks like the cordova-SMS-plugin use some functions, which required permissions READ_PHONE_STATE in Android 8.

Possible it could help, I found it on official Android 8 behavior changes:

Build.SERIAL is deprecated. Apps needing to know the hardware serial number should instead use the new Build.getSerial() method, which requires the READ_PHONE_STATE permission.

Have you any idea about it?

@oleg531
Copy link
Author

oleg531 commented Sep 24, 2017

I solved my problem.

By Ionic 3, I explicitly granted permissions READ_PHONE_STATE (using official documentation) .

Anyway, it looks like, since Android 8 cordova-SMS-plugin begin required READ_PHONE_STATE permission.

I do not know is it a bug or not, because I do not have a rich experience in writing android app.
So please decide what you will do with this issue (I mean just close or not).

@dbaq Thank you for helping and giving me the right direction!

@vegetablesalad
Copy link

vegetablesalad commented Sep 26, 2017

I have the same problem. But I don't think that :

cordova-SMS-plugin use some functions, which required permissions READ_PHONE_STATE in Android 8

is the case.

It throws error
at com.cordova.plugins.sms.Sms.send(Sms.java:192)

so its exactly where sendTextMessage is called. And sendTextMessage shouldn't need any additional permissions beside SEND_SMS

@oleg531
Copy link
Author

oleg531 commented Sep 26, 2017

@vegetablesalad So, you mean it is a bug in cordova-sms-plugin? Or it is just relate only to my case and some permissions on my own phone after Android 8 upgrading?

@vegetablesalad
Copy link

vegetablesalad commented Sep 27, 2017

@oleg531
No it looks like its a bug or undocumented change in Android 8.
I recreated simple pure android application that just sends SMS, and it encounters the same error.
Works fine on everything below Android 8.

Here is stack overflow post, please up vote.
Here is report in google issue

@dbaq
Copy link
Member

dbaq commented Sep 27, 2017

@oleg531, @vegetablesalad,

I am confused, the READ_PHONE_STATE permissions should be in your config.xml (https://github.com/cordova-sms/cordova-sms-plugin/blob/master/plugin.xml#L29).

@vegetablesalad
Copy link

@dbaq android uses permission from manifest only below version 5.1.1. Above this version you have to get permission at runtime. Anyway that is not the issue. Issue is that according to documentation we shouldn't need READ_PHONE_STATE to call sendTextMessage()

@lijithwv
Copy link

Hi,

Anybody got an update on this issue?

Anyone tried fixing it using the suggestion by @oleg531 ?

@vegetablesalad
Copy link

@lijithwv you can follow this issue at stack overflow. There you can also find link to google issue tracker.

Basically short story is that android 8.0 has bug with sendTextMessage, it asks for READ_PHONE_STATE permission. You have only two options - ask for extra permission or don't use it. It is reportedly fixed in android 8.1, but i can't confirm it. Google has no official response on this and is continuing as if nothing happened. I just removed SMS sending from my application, not to fall for this in future releases.

@RikdeBoer
Copy link

RikdeBoer commented Dec 3, 2017

I'm seeing the issue of the app crashing when sending an SMS on a Motorola Moto G5, Android 7.0 -- the javascript console shows no errors with the device hooked up to Chrome://inspect, in debug mode.
The same code ran fine in the past, on other Android phones using versions 5 and 6.

My workaround (not a proper solution) for the moment is to use an "intent" with the value of "INTENT", rather than empty, "". This means that instead of the app instantly sending the pre-prepared SMS text, it will open the phone's native SMS dialog, where the user can edit the SMS before sending (or not sending) it.

Ultimately this is not what I want, I much prefer the option of intent == "" to work, whereby the SMS is sent immediately, but on my Motorola Android 7.0 it crashes the app.

I'm using pure command-line cordova, not Ionic or PhoneGap.

@Genaro-Coronel-Gtz
Copy link

I have the same issue, app crash on Android 8. In previous versions works fine.

@Pixy123
Copy link

Pixy123 commented Aug 9, 2018

just tested on Android 8.0 and plugin 0.1.13 . It crash. Problem it's on permission READ_PHONE_STATE. You can ask confirm permission from plugin like already happens with permission SEND_SMS ?

@dbaq
Copy link
Member

dbaq commented Aug 9, 2018

I'd say that because it is a specific issue to android 8.0 only. It is not necessary for me to update the plugin to add extra methods. If you are facing this issue, you can request the READ_PHONE_STATE with a simple plugin like https://github.com/NeoLSN/cordova-plugin-android-permissions.

If the community wants me to add the READ_PHONE_STATE permission request in this plugin, please let me know by commenting below.

@vegetablesalad
Copy link

Perhaps that could be the correct path, it doesn't look that google will push a update to fix this issue. But it should ask permission only for android 8.

@MrDrProfX
Copy link

MrDrProfX commented Aug 29, 2018

For me, I forgot to use INTENT (native android messaging, which is what I wanted).
From the docs:

//CONFIGURATION
var options = {
    replaceLineBreaks: false, // true to replace \n by a new line, false by default
    android: {
        intent: 'INTENT'  // send SMS with the native android SMS messaging
        //intent: '' // send SMS without open any other app
    }
};

var success = function () { alert('Message sent successfully'); };
var error = function (e) { alert('Message Failed:' + e); };
sms.send(number, message, options, success, error);

@mredbishop
Copy link

This now crashes on Android 7, 8 and 9 for us. Is there any more information on why this is happening?

Cheers,

Ed

@vegetablesalad
Copy link

@mredbishop with the exact same error? I haven't noticed that this issue persists in other Android versions. I have moved away from sending sms from app, so I'v been out of the loop.

@mredbishop
Copy link

@vegetablesalad Not 100% on Android 7 as that was reported by a third party but Android 8, 8.1 and 9 we tested and reproduced this. I forked the repository yesterday (Friday 2nd Nov) and fixed it by requesting the required READ_PHONE_STATE permission on top of the original SMS_SEND permission. It's all working for us now, and in fact we shipped an update to our product with it in yesterday and our users are reporting it resolved.

@vegetablesalad
Copy link

@mredbishop I hope you did that only for affected android versions.

@dbaq
Copy link
Member

dbaq commented Nov 5, 2018

@mredbishop do you mind opening a pull request? that would be really great. Thanks.

@mredbishop
Copy link

mredbishop commented Nov 6, 2018

@vegetablesalad that would be rather difficult as I don't know what versions of Android it affects other than the ones I've tested and had reports from. It happens on every version of Android we've tested here.

@dbaq I could, but as vegetablesalad points out this probably isn't required for all versions of Android so there is probably a more elegant solution to the problem. I would say for most people it would be very simple, as you pointed out, to use the cordova-plugin-android-permissions.

@dbaq
Copy link
Member

dbaq commented Nov 18, 2018

Related to #183 somehow. Please read this one as well.

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

No branches or pull requests

9 participants