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

Use Content Protection

by Retired ‎02-12-2010 02:46 PM - edited ‎09-16-2010 03:10 PM (2,954 Views)



This article applies to the following:

  • BlackBerry® devices based on Java®
  • BlackBerry® Device Software 3.8 and later
  • BlackBerry® Java® Development Environment (JDE)



In today’s development environment, it is very rare to find an application that does not use some form of persistence. For applications developed for BlackBerry devices that use persistent storage, security can be a concern. In the event of a lost or stolen BlackBerry device, files stored in flash memory can, in theory, be read directly from the flash memory itself. A simple solution is to use content protection to encode data stored on the BlackBerry device to make it unreadable by potential attackers.


Here is an example of how to perform this encoding and decoding:



private Object _name = “John Smith”; // String

public void encodeName() {
name = PersistentContent.encode((String)_name, true, true);

public void decodeName() {
name = PersistentContent. decodeString(_name);



Knowing when to protect data, and being able to protect it, is very important. Protecting data too often can lead to wasted clock cycles; not protecting data often enough can lead to vulnerabilities. Fortunately, the PersistentContentListener interface provides methods that give developers all the information necessary to choose the right time to encode or decode. The two methods this interface offers are as follows:

  • persistentContentModeChanged (int generation)
  • persistentContentStateChanged (int state)

The first method informs the developer when persistent content settings have changed, and the second informs the developer when the security state of the BlackBerry device has changed. An outline of how to implement these methods is given below:



public void persistentContentModeChanged(int generation) {
// check to see if the content protection settings have changed
if(generation != PersistentContent.getModeGeneration()) {
// check to see if a re-encoding is needed
if(PersistentContent.checkEncoding(<someEncodedObject>) == false) {

public void persistentContentStateChanged(int state) {
if(state == PersistentContentListener.PERSISTENT_CONTENT_LOCKING) {
// the handheld is locking, a good time to save and encode our data
} else if(state == PersistentContentListener.PERSISTENT_CONTENT_UNLOCKED) {
// the handheld is unlocking, a good time to load and decode our data
} else if(state == PersistentContentListener.PERSISTENT_CONTENT_LOCKED_SECURE) {
// the handheld has completed the locking operation. This event will
} else if(state == PersistentContentListener.PERSISTENT_CONTENT_LOCKED_INSECURE) {
// the handheld has completed the unlocking operation. This event will


Once the listener is implemented, it can easily be registered with the PersistentContent class (assuming that the calling class implements PersistentContentListener) as follows:





For a full application that utilizes this functionality, see com.rim.samples.device.contacts (included within the BlackBerry JDE samples). This demo requires code signing. For more information, see Controlled APIs and Code Signing.


The following are two important facts about the encode() and decode() methods:

  1. If content is already encoded, it will not be re-encoded (similar behavior for decode).
  2. If content protection is not enabled, calling encode() or decode() has no effect.

Also note that the following two steps must be completed in order to enable content protection:

  1. On the BlackBerry device, click Options > Security and set the Password to Enabled.
  2. On the BlackBerry device, click Options > Security and set Content Protection to Enabled.

Additional Information


For additional information on content protection, see the appropriate Feature and Technical Overview document for BlackBerry Enterprise Server.

Users Online
Currently online: 18 members 786 guests
Please welcome our newest community members: