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

How to - Use SyncManager to avoid extra permission requests after an OS upgrade

by Retired on ‎11-26-2010 10:34 AM (3,005 Views)

When a user updates their BlackBerry® Device Software or transfers phones, there is a period of time where the device applications are installed and the device boots up, but the application databases are not yet restored. Applications which start automatically will be started before the Backup/Restore process has completed restoring their Persistent data. This includes RMS databases and the Application Permissions database.

 

Applications which start automatically and test for their permissions will frequently request permissions from the user again. The result is a poor user experience as the user is prompted to save permissions for each app they had installed, and the prompts are unnecessary. APIs exist to determine if a database restoration is happening, and to allow the application to wait until it is complete before proceeding.

 

The sample application attached does a permission check at the time the device starts. If the permissions are not as desired, the thread waits for a BlackBerry® Desktop Manager database restoration. If one starts in a short timeframe, the thread will wait until the restoration is complete before checking the permission again. After waiting for a sync to start, and complete if so, it will check and request permissions again if necessary.

 

The SyncManager API is what provides the functionality used in this example.

An implementation of the SyncEventListener interface is connected as follows:

SyncManager.getInstance().addSyncEventListener(listener);

 

And removed as so:

SyncManager.getInstance().removeSyncEventListener(listener);

 

The listener implementation itself is given below.

 

private class RestoreEventListener implements SyncEventListener {
	public boolean syncStarted = false;

	public void syncEventOccurred(int eventId, Object object) {
		if (eventId == SyncEventListener.SERIAL_SYNC_STOPPED) {
			System.out.println("Sync Stopped");
			setSyncStopped();
		} else if (eventId == SyncEventListener.SERIAL_SYNC_STARTED) {
			System.out.println("Sync Started");
			setSyncStarted();
		}
	}

	private synchronized void setSyncStarted() {
		syncStarted = true;
		notifyAll();
	}

	private synchronized void setSyncStopped() {
		notifyAll();
	}

	public synchronized void waitOnSyncEnd() {
		boolean waitForEnd = false;
		if (!SyncManager.getInstance().isSerialSyncInProgress()) {
			log("Not Currently restoring, wait for 3min to see if one starts");
			try {
				wait(180000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			if (syncStarted) {
				log("A Sync Event has started, wait for completion");
				waitForEnd = true;
			} else {
				log("No Sync started");
				waitForEnd = false;
			}
		} else {
			log("Currently restoring, wait for completion");
			waitForEnd = true;
		}
		if (waitForEnd) {
			log("Waiting on Sync End");
			try {
				wait(600000);
			} catch (InterruptedException e) {
							e.printStackTrace();
			}
		}

	}

}
Users Online
Currently online: 17 members 1,047 guests
Please welcome our newest community members: