Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, find all places in code to request permissions

I am working on an application for pre-Marshmallow devices. The source code was not written by me and the project itself is quite big. I am currently making the app to request permissions when needed.

The question is: How to find all places in code where permission should be requested? I am using Android Studio.

EDIT
Some people suggest to change api to 23 and just run the app and see the places where it crashes. The problem is that the app does not crash in every place.

For example, running this code without a permission will crash the app:

TelephonyManager manager = (TelephonyManager) context
            .getSystemService(Context.TELEPHONY_SERVICE);

While this one just returns an empty array, instead of crashing.

final String[] SELF_PROJECTION = new String[]{
    ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,};
Cursor cursor = context.getContentResolver()
    .query(ContactsContract.Profile.CONTENT_URI, SELF_PROJECTION, null, null, null);

Also, Android Lint does not show these places. I'm not sure if it should be.

like image 457
geNia Avatar asked Feb 19 '16 19:02

geNia


1 Answers

According to the developer page regarding security permissions :

In almost all cases, however, a permission failure will be printed to the system log.

So run the app and search the log for "permissions" or similar.

Use unit testing to ensure coverage of all the places in the code where permissions may be required.

like image 77
rothloup Avatar answered Sep 20 '22 14:09

rothloup