Android Question java.lang.SecurityException: Requires READ_PHONE_STATE

Discussion in 'Android Questions' started by marcick, Aug 14, 2019.

  1. marcick

    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

    Code:
    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:

    Code:
    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.
     

    Attached Files:

  2. Erel

    Erel Administrator Staff Member Licensed User

  3. marcick

    marcick Well-Known Member Licensed User

    Yes, strange.
    This is all what I have

    Code:
    ~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)
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    Looks like an OS bug.
    You can add Try / Catch to catch this error. If it is critical for you then request this permission after it fails (make sure to also add it to the manifest editor).
     
  5. marcick

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice