Since Android 6.0 listening to the PhoneStateListener.LISTEN_DATA_CONNECTION_STATE changes seems to no longer require READ_PHONE_STATE permission
Asked Answered
T

2

9

I'm applying Android 6.0 runtime permissions into an app which listens to carrier data connection state changes. I first tried to just remove the READ_PHONE_STATE from the manifest to check where the app requires the permission. To my surprise the app didn't crash at all.

After this I've tried the same installation on two pre 6.0 devices which did actually crash on it. To me it seems like Android 6.0 does no longer require the permission. Is there any way to confirm this?

The line below is the one on which the pre 6.0 devices crashes:

tm(TelephonyManager).listen(this, PhoneStateListener.LISTEN_DATA_CONNECTION_STATE);
Theoretician answered 30/10, 2015 at 10:29 Comment(0)
A
22

Is there any way to confirm this?

Yes, this commit removes the request of READ_PHONE_STATE when register the event type LISTEN_CALL_STATE, LISTEN_DATA_ACTIVITY and LISTEN_DATA_CONNECTION_STATE:

Do not enforce PHONE_STATE_PERMISSION to register listener PHONE_STATE_PERMISSION should not be required to register to the following event types:
- PhoneStateListener.LISTEN_CALL_STATE
- PhoneStateListener.LISTEN_DATA_ACTIVITY
- PhoneStateListener.LISTEN_DATA_CONNECTION_STATE

In case of LISTEN_CALL_STATE, an empty string should be passed instead of incomingNumber, when caller has no PHONE_STATE_PERMISSION.

Bug: 21588537 Change-Id: I5b6d0308924f7e4cd13a983b8e0c9b3a5bbb119b

The documentation on developer.android.com was updated and correctly shows that the permission are not required.

If your code doesn't need the permission READ_PHONE_STATE for other reason apart from LISTEN_DATA_CONNECTION_STATE you can change your AndroidManifest.xml adding maxSdkVersion to the uses-permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE" android:maxSdkVersion="22" />
Auxin answered 30/10, 2015 at 11:5 Comment(5)
Thanks...it'd be nice if they left a note that it STILL requires permission on Android <6.0 as I released an update adding this functionality and had no idea LISTEN_CALL_STATE requires a permission before Marshmallow.Unamerican
I should add that specifying maxSdkVersion is highly risky, as your app will be uninstalled if the OS is upgraded beyond that version. See (developer.android.com/guide/topics/manifest/uses-sdk-element)Upstairs
@DavidBurström The link you posted is referred to uses-sdk, not uses-permission. They are two different things.Auxin
Thanks, I misread. It might be worth mentioning that the attribute was added in API level 19, but the documentation does not clarify what that means for older devices. Possibly an up-to-date Google Play on an API level 18 or older device will not list the permission in the installation dialog if it is no longer required on the device OS, but that's pure conjecturing.Upstairs
Starting with Android 12, it is required again... developer.android.com/about/versions/12/reference/…Unamerican
L
1

There is no special permission listed for PhoneStateListener.LISTEN_DATA_CONNECTION_STATE in the official android documentation.

http://developer.android.com/reference/android/telephony/PhoneStateListener.html#LISTEN_DATA_CONNECTION_STATE

Lozada answered 30/10, 2015 at 11:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.