Search code examples
androidsecuritypermissionssecurityexception

SecurityException after Permission has been used


I am having a serious issue with my app. I use the permission android.permission.ACCESS_COARSE_LOCATION in a broadcast receiver and it runs perfectly.

However after a certain amount of time (this seems to be random) the app crashes with the following output:

SecurityException neither user 10086 nor current process has permission android.permission.ACCESS_COARSE_LOCATION

I have included the permission in the Manifest using <uses-permission etc /> and as a attempt to make it more specific when I sendOrderedBroadcast I broadcast the permission as well and have given the permission to the broadcast receiver so that it can receive the broadcast which is does.

But like I say after a while the SecurityException is thrown at the second line of code:

TelephonyManager Tel = (TelephonyManager) vb.getPsrC()
            .getSystemService(Activity.TELEPHONY_SERVICE);
GsmCellLocation cellLocation = (GsmCellLocation) Tel.getCellLocation();

This crash seems to only occur on a test device running Froyo.

On a device running Gingerbread, the app just restarts the service using less memory and does nothing. are these problems related or is the Security Exception mutually exclusive to the app crashing.


Solution

  • Ok, so turns out the culprit is a memory leak. When GREF reached 2001 it crashed and basically emptied it (for lack of a better phrase) causing the app to think that the permission was not given. I fixed it moving the phonelistener into the service.