This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Security and the fly likes checkPermission without SecurityException? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Security
Bookmark "checkPermission without SecurityException?" Watch "checkPermission without SecurityException?" New topic
Author

checkPermission without SecurityException?

Johan Nagels
Greenhorn

Joined: Jan 12, 2004
Posts: 9
Is there a way to check for a permission without running the risk of an Exception being thrown?
I would like to be able to check the permissions and change the GUI accordingly, but I don't like the idea of catching a lot of Exceptions.

Johan
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41123
    
  45
You could encapsulate the checking and try/catch in a method which just returns a boolean. The SecurityManager.checkPermission(Permission) method would help with this.


Ping & DNS - my free Android networking tools app
Johan Nagels
Greenhorn

Joined: Jan 12, 2004
Posts: 9
Thanks for the reply.
But that's what I would like to avoid: creating the exception takes up unnecessary cpu. I would prefer to have a method that does not cause/use an excaption at all.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41123
    
  45
You could perform those checks once at startup, and store the results as booleans for later use.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: checkPermission without SecurityException?
 
Similar Threads
Question for Micheal Yuan and Thomas Heute, Polymorphic Page Navigation
String to number
Are instant messengers allowed in your office?
Enumerations in java world ( jdk 1.5)
com.sun.java.swing