Android Question java.lang.SecurityException: Requires READ_PHONE_STATE

marcick

Well-Known Member
Licensed User
I have recently removed from my app the dangerous "phone" permission and everything works fine on tenths of devices.
I have suddenly this crash on a Android 5.0 device

B4X:
java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10190 nor current process has android.permission.READ_PHONE_STATE
It is generated in this sub:

B4X:
Sub CheckConnection As Boolean
    Dim ph As Phone
    Dim myLAN As ServerSocket
    myLAN.Initialize(0, "")
    If ph.GetDataState <> "CONNECTED" And myLAN.GetMyIP = "127.0.0.1" Then    --->> ERROR HERE
        Return False
    Else
        Return True
    End If
End Sub
TargetSdk is 28 and you see in the picture the permission listed in B4A
Why this sub requires READ_PHONE_STATE and why it happens only on this particular device ?

The user experience the crash only when 3G/4G data is enabled. If they are switched off and it works only with Wi-Fi the app runs ok.
 

Attachments

marcick

Well-Known Member
Licensed User
Yes, strange.
This is all what I have

B4X:
~e:    at java.lang.reflect.Method.invoke(Native Method)
~e:    at java.lang.reflect.Method.invoke(Method.java:372)
~e:    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
~e:    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
~e:    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
~e:    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
~e:    at android.view.View.performClick(View.java:5197)
~e:    at android.view.View$PerformClick.run(View.java:20926)
~e:    at android.os.Handler.handleCallback(Handler.java:739)
~e:    at android.os.Handler.dispatchMessage(Handler.java:95)
~e:    at android.os.Looper.loop(Looper.java:145)
~e:    at android.app.ActivityThread.main(ActivityThread.java:5951)
~e:    at java.lang.reflect.Method.invoke(Native Method)
~e:    at java.lang.reflect.Method.invoke(Method.java:372)
~e:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
~e:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10190 nor current process has android.permission.READ_PHONE_STATE.
    at android.os.Parcel.readException(Parcel.java:1540)
    at android.os.Parcel.readException(Parcel.java:1493)
    at com.android.internal.telephony.ITelephony$Stub$Proxy.getDataState(ITelephony.java:2791)
    at android.telephony.TelephonyManager.getDataState(TelephonyManager.java:2348)
    at anywheresoftware.b4a.phone.Phone.GetDataState(Phone.java:330)
    at it.elettronicablancato.bmap4e.mysub._vvvvvvvv5(mysub.java:257)
    at it.elettronicablancato.bmap4e.main._iconsettings_click(main.java:4285)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:196)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5197)
    at android.view.View$PerformClick.run(View.java:20926)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5951)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183)
 

marcick

Well-Known Member
Licensed User
I wanted so much to get rid of this permission .. when the user see that my app want to manage contacts and calls it is not happy.
I was using it before to read IMEI, but now I use Advertising_ID to identify the device and I no longer need this permission.
Ok, you gave me your answer, thank you. I'll see.
 
Top