Why would sendTextMessage require READ_PHONE_STATE permission?

后端 未结 3 1572
情话喂你
情话喂你 2021-02-20 06:42

My app sent home this stack trace which seems as though something very wrong is going on under the hood.

phone_model=SKY IM-A630K, android_version=2.1-update1

         


        
3条回答
  •  醉梦人生
    2021-02-20 07:16

    I now see that in Lollipop (API 21), even using a benign function like SmsManager.getDefault().divideMessage(String) - requires the READ_PHONE_STATE permission. I am sure that it was not required before, and that it is an OS issue, since I tested it on Nexus 5 devices before, and after upgrade to Lollipop. Before, when running KitKat, SMS worked just fine without the READ_PHONE_STATE permission. And after, it was required.

    The reason is that, I guess, telephony functions try to make wise decisions about, well, everything. So a simple task like splitting an SMS (not even sending it) runs all the way to the SmsManager to query it about the phone state.

    I think it is a design bug. And as you said above, it can, and should scare users. Why on earth do they have so many ambiguous permissions on Android?

    This is my stack trace, just for fun:

    java.lang.SecurityException: Requires READ_PHONE_STATE: Neither user 10078 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.IPhoneSubInfo$Stub$Proxy.getGroupIdLevel1(IPhoneSubInfo.java:465)
    at android.telephony.TelephonyManager.getGroupIdLevel1(TelephonyManager.java:1666)
    at android.telephony.SmsMessage.hasEmsSupport(SmsMessage.java:776)
    at com.android.internal.telephony.gsm.SmsMessage.calculateLength(SmsMessage.java:808)
    at android.telephony.SmsMessage.fragmentText(SmsMessage.java:322)
    at android.telephony.SmsManager.divideMessage(SmsManager.java:328)
    at mobi.chatfish.utils.CFCommunications.sendSMSDirect(CFCommunications.java:138)
    

提交回复
热议问题