8
votes

I am still a little confused about the new runtime permissions model. Would any of the following required permissions for Parse push notifications (GCM) require a runtime permission ?

<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

<uses-permission android:name="android.permission.WAKE_LOCK" />

<uses-permission android:name="android.permission.VIBRATE" />

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

<uses-permission android:name="android.permission.GET_ACCOUNTS" />

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

 <permission android:protectionLevel="signature"       android:name="com.parse.starter.permission.C2D_MESSAGE" />

<uses-permission android:name="com.parse.starter.permission.C2D_MESSAGE" />
3
you don't need to request the GET_ACCOUNTS permission on 6.0+ to make the parse push to work. It is declared in the Manifest so it can support Android 4.04 and lower. On 6.0+, this permission is declared but does not need to be "granted" - jiawen

3 Answers

5
votes

Among the permissions you listed above, GET_ACCOUNTS requires runtime check because its protection level is dangerous.

But the thing is, while GET_ACCOUNTS permission is no longer needed for GCM to work (starting with 7.5 Play Services, I guess), it's still needed if you're using Parse Push Notifications.

It seems that in order for Parse to provide full compatibility to whole range of android powered devices (i.e. non GCM based devices like Kindle Fires, where GCM isn't supported and they have to fall back to their own persistent socket implementation and of course the devices with 4.0.3 and below), Parse still needs this permission and some other ones.

A guy from Parse mentioned that:

We require it being requested, aka being in AndroidManifest.xml, but don't require it being granted.

the issue is in discussion, you might want to take a look at these topics :

https://github.com/ParsePlatform/Parse-SDK-Android/issues/129 https://parse.com/questions/android-use-only-gcm-dont-require-additional-permissions

1
votes

The GET_ACCOUNTS permission requires the permission to be checked at runtime, since it belongs to the dangerous permissions group (https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous).

The other ones are normal permissions, and will be granted as long as they are declared on the manifest file (https://developer.android.com/guide/topics/security/normal-permissions.html)

If you realize you don't have the permission at runtime, you will need to request it, using the method requestPermissions(Activity yourActivity, String[] permissions, int requestCode). After that an non-customizable dialog will be shown to the user, requesting the permission.

Finally you need to override the onRequestPermissionsResult(int requestCode,String permissions[], int[] grantResults) method on your Activity, checking if the requestCode is the same requestCode you sent on requestPermissions and if the target permission was granted.

There are other cases you need to consider, like when the user does not grant the permission for the first time, and you still wanna ask him/her. In order to known how to handle this cases I suggest you read this: http://developer.android.com/intl/pt-br/training/permissions/requesting.html. It also have sample codes for requesting permissions and checking the results

-3
votes

According to the Android developers documents, as long as you define these permissions in your manifest, the system will automatically grant you these permissions and will not allow the user to revoke them. Therefore, you do not need to check for these permissions on runtime.

https://developer.android.com/preview/features/runtime-permissions.html

This is said at the bottom of the page in the Normal Permissions section.