com.sonyericsson.extras.liveware.aef.control
Class Control

java.lang.Object
  extended by com.sonyericsson.extras.liveware.aef.control.Control

public class Control
extends java.lang.Object

Control API is a part of the Smart Extension API's

Some of our Smart accessories will support the Control API. The Control API enables the Extension to take total control of the accessory. It takes control over the display, LEDs, vibrator, input events. Because of this, only one Extension can run in this mode at a time.

Topics covered here:

  1. Registration
  2. Extension lifecycle
  3. Controlling the display
  4. Controlling the LEDs
  5. Controlling the vibrator
  6. Key events
  7. Touch events
  8. Displaying content on the accessory display

Registration

Before an Control Extension can use an accessory, it must use the registration API content provider to insert a record in the extension table. It must also register information in the registration table. This must be done for each Host Application that the Extension wants to interact with.

In order to find out what Host Applications are available and what capabilities they support, the Extension should use the Capability API.

Extension lifecycle

After a successful registration the Extension can start communicating with the Host Application. Since a Extension implementing this API takes complete control over the accessory only one Extension can run at a time.

An Extension cannot just start executing whenever it wants, it needs to make sure that no other Extension is running, therefore the Extension can only request to be started, Control.Intents.CONTROL_START_REQUEST_INTENT. When the Host Application is ready to give control to the Extension it will send a Control.Intents.CONTROL_START_INTENT, see figure below.

Extension lifecycle

When the Extension requests to start controlling the accessory the Host Application can either accept the request and give control to the Extension, or if something is not right the Host Application can send a Control.Intents.CONTROL_ERROR_INTENT. See Control.Intents.EXTRA_ERROR_CODE for different error codes that the Host Application can send.

The Control.Intents.CONTROL_RESUME_INTENT is sent when the Extension is visible on the accessory. From this point on the Extension controls everything, the Host Application just forwards the information between the accessory and the Extension.

An Extension can also be paused, either if a high priority Extension needs to run for a while or if the Host Application is in charge of the display state and the display is turned off. In this case the Host Application sends a Control.Intents.CONTROL_PAUSE_INTENT to the Extension. This means that there is no point for the Extension to update the display since it is either turned off or someone else has control over it. If the Extension would break this rule and try to update the display anyway, the Host Application will ignore these calls.

When the Extension is in a paused state it no longer has control over the display/LEDs/ vibrator/key events. As an example one could say that a telephony Extension has high priority. E.g. when a random Extension is running and the user receives a phone call. We want to pause the running Extension and let the telephony Extension display the caller id on the accessory display. When the phone call ends the telephony Extension is done and the other Extension can resume its running, it will then receive a Control.Intents.CONTROL_RESUME_INTENT.

When the Control.Intents.CONTROL_RESUME_INTENT is sent from a Host Application the Extension is once again in charge of everything.

When the user chooses to exit the Extension the Host Application will send a Control.Intents.CONTROL_PAUSE_INTENT followed by a Control.Intents.CONTROL_STOP_INTENT. From this point on the Host Application regains control.

If the Extension would like to stop itself when running, like the telephony Extension, it can send a Control.Intents.CONTROL_STOP_REQUEST_INTENT to the Host Application. The Host Application will then make sure to stop it and send a Control.Intents.CONTROL_STOP_INTENT. If the extension was not already paused the it will be paused before it is stopped and a Control.Intents.CONTROL_PAUSE_INTENT is sent before the Control.Intents.CONTROL_STOP_INTENT. In case another Extension has been paused it will be resumed.

Controlling the display

Extensions implementing this API have the possibility to control the state of the accessory display.The display can be controlled via Control.Intents.CONTROL_SET_SCREEN_STATE_INTENT.

It is important that you program your Extension so that it consumes as little power as possible, both on the phone side and on the accessory. The accessory has a much smaller battery then the phone so use this functionality with caution. When possible, let the Host Application take control of the display state. That way you don't have to bother about the power consumption on the accessory. You can do this by setting the display state to "Auto".

By default when your Extension starts the display state will be set to "Auto", which means that the Host Application controls the on/off/dim behavior. If the Extension wants to control the display state it must explicitly change the state.

If the Extension controls the display state and you get a Control.Intents.CONTROL_STOP_INTENT, meaning your Extension is no longer running, the Host Application will automatically take over the display control.

Note that when in "Auto" mode, the Extension will receive a Control.Intents.CONTROL_PAUSE_INTENT when display is off and a Control.Intents.CONTROL_RESUME_INTENT when the display goes back on.

Controlling the LEDs

The accessory might have one or more LEDs that are used to notify the user about events. The Extension can find information about the LEDs for a certain accessory via the Registration & Capability API.

If the accessory has LEDs, the Extension can control them via the Control API. The LEDs can be controlled via the Control.Intents.CONTROL_LED_INTENT. Note that the Host Application might overtake the control of the LED at any time if it wants to show some important notifications to the user, e.g. when the accessory battery level is low. The Extension is unaware of this so it might still try to control the LEDs but the Host Application will ignore the calls.

Controlling the vibrator

Our accessories might or might not have a vibrator. The Extension can find this out by checking the capabilities of the Host Application via the Registration & Capability API. If the accessory has a vibrator it is controllable via the Control API, Control.Intents.CONTROL_VIBRATE_INTENT.

Key events

The accessory might have several hardware keys. Your extension will receive the key events when one of the keys is pressed. The Control.Intents.CONTROL_KEY_EVENT_INTENT is sent to the Extension when a user presses a key on the accessory.

The Intent carries a few parameters, such as the time stamp of the event, the type of event (press, release and repeat) and also the key code. The accessory might have one or more keypads defined. Extensions can look this up in the Registration & Capabilities API. Each key will have a unique key code for identification. Key codes can be found in the product SDK.

Touch events

Certain accessories might have a touch display. Extensions can find this information using the Registration & Capabilities API. The Control.Intents.CONTROL_TOUCH_EVENT_INTENT is sent to the Extension when a user taps the accessory display.

Displaying content on the accessory display

Since the Extension is controlling the accessory it also controls what is visible on the display. The content visible to the user comes from the Extension. Basically the Extension sends images to be displayed on the accessory display. To find out the dimensions of the display and the color depth it supports the Extension can use the Registration & Capabilities API. The Control.Intents.CONTROL_DISPLAY_DATA_INTENT is sent from the Extension when it wants to update the accessory display. Extensions can also clear the accessory display at any point if they wants to by sending the Control.Intents.CONTROL_CLEAR_DISPLAY_INTENT.

The Extension can send images as raw data (byte array) or it can just send the URI of the image to be displayed. Note that we are using Bluetooth as bearer which means that we can't send that many frames per second (FPS). Refresh rate of the display can be found in the Registration & Capabilities API.


Nested Class Summary
static interface Control.Intents
          Intents sent between Control Extensions and Accessory Host Applications.
static interface Control.KeyCodes
          Interface used to define constants for keycodes
 
Constructor Summary
protected Control()
           
 
Method Summary
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Control

protected Control()