Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 43
Registered: ‎11-30-2011
My Device: Dev Alpha, 8520
My Carrier: Vodafone

Application control screen (ApplicationPermissionsManager.invokePermissionsRequest) getting suppressed?!?

Okay, so this is what's happening.

From my BG application, I'm checking whether I have all the permissions I need for my app. If not, I pushGlobalScreen() a screen.

 

public static void verifyPermissions() throws InterruptedException
{
	ApplicationPermissions currentAppPermissions = ApplicationPermissionsManager.getInstance().getApplicationPermissions();
	if((currentAppPermissions.containsPermissionKey(ApplicationPermissions.PERMISSION_PHONE) && currentAppPermissions.getPermission(ApplicationPermissions.PERMISSION_PHONE) == currentAppPermissions.VALUE_ALLOW) && (currentAppPermissions.containsPermissionKey(ApplicationPermissions.PERMISSION_ORGANIZER_DATA) && currentAppPermissions.getPermission(ApplicationPermissions.PERMISSION_ORGANIZER_DATA) == currentAppPermissions.VALUE_ALLOW)
			&& (currentAppPermissions.containsPermissionKey(ApplicationPermissions.PERMISSION_LOCATION_DATA) && currentAppPermissions.getPermission(ApplicationPermissions.PERMISSION_LOCATION_DATA) == currentAppPermissions.VALUE_ALLOW)
			&& (currentAppPermissions.containsPermissionKey(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) && currentAppPermissions.getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) == currentAppPermissions.VALUE_ALLOW))
	{
		return;
	}
	
	// if the bgapp started while the phone was booting, it needs to wait a
	// bit
	while(ApplicationManager.getApplicationManager().inStartup())
	{
		Thread.sleep(500);
	}
	
	Ui.getUiEngine().pushGlobalScreen(new PermissionsScreen(), 0, UiEngine.GLOBAL_SHOW_LOWER);
}

 

In the PermissionsScreen, I have a giant wall of text explaining why I need all the permissions, and a little button which calls ApplicationPermissionsManager.invokePermissionsRequest and closes the screen.

public PermissionsScreen()
{
	super(Screen.DEFAULT_CLOSE);
	setTitle("Anti Theft");
	add(txtLeWallOfText);
	ButtonField btn = new ButtonField("Proceed", FIELD_HCENTER | ButtonField.CONSUME_CLICK | ButtonField.NEVER_DIRTY);
	btn.setChangeListener(new FieldChangeListener()
	{
		public void fieldChanged(Field field, int context)
		{
			boolean granted = askPermissions();
			if(!granted)
			{
				Dialog d = new Dialog(Dialog.D_OK, "Warning!", 0, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Dialog.FIELD_HCENTER | Dialog.DEFAULT_CLOSE);
				d.add(new LabelField("All required permissions were not granted! The application may not function normally!"));
				d.doModal();
			}
			close();
		}
	});
	add(btn);
}

private boolean askPermissions()
{
	ApplicationPermissions requiredPermissions = new ApplicationPermissions();
	requiredPermissions.addPermission(ApplicationPermissions.PERMISSION_PHONE);
	requiredPermissions.addPermission(ApplicationPermissions.PERMISSION_ORGANIZER_DATA);
	requiredPermissions.addPermission(ApplicationPermissions.PERMISSION_LOCATION_DATA);
	requiredPermissions.addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
	
	ReasonProvider reason = new ReasonProvider()
	{
		public String getMessage(int permissionID)
		{
			switch(permissionID)
			{
			case ApplicationPermissions.PERMISSION_INPUT_SIMULATION:
				return "My Awesome Reason #1";
			case ApplicationPermissions.PERMISSION_LOCATION_DATA:
				return "My Awesome Reason #2";
			case ApplicationPermissions.PERMISSION_ORGANIZER_DATA:
				return "My Awesome Reason #3";
			case ApplicationPermissions.PERMISSION_PHONE:
				return "My Awesome Reason #4";
			default:
				return null;
			}
		}
	};
	ApplicationPermissionsManager.getInstance().addReasonProvider(ApplicationDescriptor.currentApplicationDescriptor(), reason);
	
	return ApplicationPermissionsManager.getInstance().invokePermissionsRequest(requiredPermissions);
}

 

Now, what happens (on an actual 9800 Torch, not a simulator) is that when I click on btnProceed, the application control screen gets pushed UNDER this screen. The docs say that the app control screen gets pushed on top of the current app, and even though PermissionsScreen is pushed globally, it's pushed as GLOBAL_SHOW_LOWER which should not affect the display of the app control screen.

Is this a loophole or something? Because this is totally WTF, and can possibly have really nasty implications (getting the app control screen with getScreenBelow(), setting everything to ALLOW and saving while the user doesn't even know what's happening).

 

Can anyone explain this behaviour?



I've got 99 problems and eclipse is all of them


Twitter

BlackBerry Development Advisor
Posts: 15,696
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Application control screen (ApplicationPermissionsManager.invokePermissionsRequest) getting suppressed?!?

Is PermissionsScreen a PopupScreen (or any type of screen that extends it)?

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Highlighted
Contributor
Posts: 43
Registered: ‎11-30-2011
My Device: Dev Alpha, 8520
My Carrier: Vodafone

Re: Application control screen (ApplicationPermissionsManager.invokePermissionsRequest) getting suppressed?!?

Nah, it extends MainScreen.

For now, I am just working by calling close() before askPermissions() so the app control screen is not obscured, but the fact that it got obscured in the first place honestly baffles me.


I've got 99 problems and eclipse is all of them


Twitter