BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-13-2008, 06:26 AM   #1
josimapi
New Member
 
Join Date: Oct 2008
Model: 8820
PIN: N/A
Carrier: Vodafone
Posts: 7
Default Best way of changing application permissions

Please Login to Remove!

Hello,

I know this has been answered many times in the forums, but I just wanted to know if the next piece of code is a good way to check and change the permissions of my application.

Code:
	public static void changeApplicationPermissions() {		
		try {
			Vector vNewPermissions;
			for(int i=0; i < 3; i++)
			{
				vNewPermissions = this.checkApplicationPermissions();
				if(vNewPermissions != null)				
					this.modifyApplicationPermissions(vNewPermissions);					
				
				if((vNewPermissions != null) && (i == 2))
				{
					BBUtilities.launchDialogScreen("MyApplication is not able to work because it doesn't have enough permissions to work correctly." +
					"\MyApplication will be closed.");					
					System.exit(0);
				}
				else
					break;
			}				
		} catch (final MyApplication e1) {
			UiApplication.getUiApplication().invokeLater(new Runnable() {
				public void run() {
					Dialog.alert(e1.getMessage());
					System.exit(0);
				}
			});
			return;
		} catch (Exception e) {
			System.out.println(e.getMessage());
		}
	}
	
	public static final Vector checkApplicationPermissions() throws MyApplicationException
	{		
		try
		{			
			ApplicationPermissions permissions = ApplicationPermissionsManager.getInstance().getApplicationPermissions();
			Vector permissionsToChange = null;			
			int[] p;						
			int i;			
			
			p = new int[] { ApplicationPermissions.PERMISSION_AUTHENTICATOR_API,
							ApplicationPermissions.PERMISSION_CHANGE_DEVICE_SETTINGS,
							ApplicationPermissions.PERMISSION_CODE_MODULE_MANAGEMENT,
							ApplicationPermissions.PERMISSION_EMAIL,
							ApplicationPermissions.PERMISSION_EVENT_INJECTOR,
							ApplicationPermissions.PERMISSION_EXTERNAL_CONNECTIONS,							
							ApplicationPermissions.PERMISSION_FILE_API,
							ApplicationPermissions.PERMISSION_INTERNAL_CONNECTIONS,
							ApplicationPermissions.PERMISSION_HANDHELD_KEYSTORE,
							ApplicationPermissions.PERMISSION_LOCAL_CONNECTIONS,
							ApplicationPermissions.PERMISSION_PHONE	
						};		
			
			for(i = 0; i< p.length; i++)
			{				
				if(permissions.containsPermissionKey(p[i]))					
					if(permissions.getPermission(p[i]) != ApplicationPermissions.VALUE_ALLOW)
					{
						if(permissionsToChange == null)
							permissionsToChange = new Vector();						
						permissionsToChange.addElement(new Integer(p[i]));
					}
			}
			
			return permissionsToChange;
			
		}catch (Exception e) {		
			throw new MyApplicationException("MyApplication doesn't have enough permissions to work correctly.\MyApplication will be closed."+e.getMessage());
		}
	}	

	public static final boolean modifyApplicationPermissions(Vector vNewPermissions) throws MyApplicationException
	{		
		try{
			ApplicationPermissions permissions = ApplicationPermissionsManager.getInstance().getApplicationPermissions();
			for(int i = 0 ; i < vNewPermissions.size(); i++)
				permissions.addPermission(((Integer)vNewPermissions.elementAt(i)).intValue());				
			return ApplicationPermissionsManager.getInstance().invokePermissionsRequest(permissions);
		}catch (Exception e) {
			throw new MyApplicationException("MyApplication doesn't have enough permissions to work correctly.\MyApplication will be closed.");
		}		
	}
Do you think is better to change the permissions when the user launches the application than letting the BB prompts the user when a resource without permission is going to be used?

Does someone know which is the best way of doing this? Because I still don't have this clear enough and haven't found info related with it...

Thank you!
Offline  
Old 10-15-2008, 05:30 AM   #2
josimapi
New Member
 
Join Date: Oct 2008
Model: 8820
PIN: N/A
Carrier: Vodafone
Posts: 7
Default

I cannot believe that nobody has done something similar to this, my only question is how should I change permissions of the application. With my solution I have a bug because for those permissions that I don't want to be allowed BB automatically change them to DENY, which is a bit weird...

Am I doing something wrong?
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


New Siemens 6ES7138-4DF11-0AB0 Electronics Module for ET200S 6ES7 138-4DF11-0AB0 picture

New Siemens 6ES7138-4DF11-0AB0 Electronics Module for ET200S 6ES7 138-4DF11-0AB0

$468.00



SIEMENS SINAMICS CONTROL UNIT CU320-2 DPSIEMENS 6SL3 040-1MA00-0AA0 NEW Sealed picture

SIEMENS SINAMICS CONTROL UNIT CU320-2 DPSIEMENS 6SL3 040-1MA00-0AA0 NEW Sealed

$768.00



New Factory Sealed SIEMENS 6SL3210-1KE15-8UF2 6SL3 210-1KE15-8UF2 In Box picture

New Factory Sealed SIEMENS 6SL3210-1KE15-8UF2 6SL3 210-1KE15-8UF2 In Box

$850.20



1PC New Siemens 3RW4047-1BB14 Siemens 3RW40471BB14 In Box Expedited Shipping # picture

1PC New Siemens 3RW4047-1BB14 Siemens 3RW40471BB14 In Box Expedited Shipping #

$1100.00



6SE7090-0XX84-0AB0 New Original SIEMENS PLC 6SE7 090-0XX84-0AB0 Fast Shipping picture

6SE7090-0XX84-0AB0 New Original SIEMENS PLC 6SE7 090-0XX84-0AB0 Fast Shipping

$299.00



1PCS New Siemens 6ES7314-6CF02-0AB0 Simatic 6ES7 314-6CF02-0AB0 Fast Ship picture

1PCS New Siemens 6ES7314-6CF02-0AB0 Simatic 6ES7 314-6CF02-0AB0 Fast Ship

$599.33







Copyright © 2004-2016 BlackBerryForums.com.
The names RIM © and BlackBerry © are registered Trademarks of BlackBerry Inc.