Several of the latest Xperia devices, including Xperia Z2, feature a self-contained sensor co-processor. This sensor co-processor makes it possible to continuously collect data in the background, without using the main application processor. This will enable up to ten times lower power consumption when using always-on features in sensors, compared to a system without a sensor co-processor. Learn how to use this in your app!
Sony Xperia Z2, Xperia Z2 Tablet, and prior Xperia devices running on the Qualcomm® Snapdragon™ 800 MSM8974 Quad-core 2.2Ghz CPU platform (Xperia Z1, Xperia Z1 Compact, and Xperia Z Ultra) all share a unique hardware component – a low-power sensor co-processor (also called a “sensor sub-system”). This component enables the possibilities of running always-on sensor features, without having a significant impact on the power consumption.
You can clearly see this in the video above, where we used a digital multimeter to measure the power consumption on Xperia Z2 with the sensor co-processor, while running a pedometer application. As you can see in the video, the power consumption is minimal compared to a device without the sensor co-processor.
In the supported Xperia devices, we currently use the sensor co-processor for a step counter sensor type, which will let apps tracks the user’s steps in the background at all time. The step counter is a “composite sensor”, which means that it is a derivate of one, or more, underlying sensor hardware components.
In the case of Xperia devices, the accelerometer sensor hardware is used for the step counter sensor type. A composite sensor, in this case the step counter, also includes an accompanied computational algorithm which extracts the user’s steps out of the sensor data.
The sensor co-processor framework explained
Now, let’s take a closer look at the system that makes it possible to run always-on sensors in low power mode, just like in the case of the step counter mentioned above. Besides the sensor co-processor hardware, the sensor co-processor framework also depends on the firmware handling all of the activities.
The sensor co-processor framework consists of two main parts. One part of the framework is implemented on the application processor, and another part is implemented on the sensor co-processor.
On a platform with a self-contained sensor co-processor, the application processor implementation only plays a small role in the sensor framework. When it comes to activities related to sensors, the application processor is in charge of loading and booting the sensor co-processor, the activation or deactivation of the requested sensor features, and the handling of collected data. The real action, however, is taking place in the sensor co-processor, where different algorithms interpret raw sensor data into something usable.
Since the sensor co-processor has its own system clock and power rail, it is able to run in its own context, while the rest of the platform blocks are suspended. This makes it possible to realise always-on sensors, and introduce new low-power sensor features with a minimal impact on the system power consumption.
How to use the step counter sensor type in your app
On the newly released Xperia Z2, you can start utilising the power efficient step counter sensor type in your applications already now. For Sony Xperia Z Ultra, Xperia Z1 and Xperia Z1 Compact, the support for the step counter sensor type is implemented through the Android 4.4 update* rolling out from last week.
From the Android 4.4 release for these Xperia devices, the step counter is defined in the Android Sensor Framework. On Google’s Android developer web site you can find a complete step counter API description, as well as a more general description about composite sensors.
To implement a low-power step counter, follow these steps based on the Main.java file, which is part of a StepCounter reference project that is available to download. To follow this instruction, you should already be familiar with Android app development.
- Create a sensor manager instance.
- Register a listener for the STEP_COUNTER sensor type.
- Implement a SensorEvent callback function, onSensorChanged(), which serves the STEP_COUNTER sensor events.
- Make sure to handle the initial step-count value accordingly. As per definition the STEP_COUNTER will reset its value at system restart and increment it as long as there is a client application for it. This means that any application using it needs to track the start-offset itself, see variables mStepsSInceBoot and mLastReport in the java file for an example.
- Discard any OnPause() or other power management handling, this is not needed when having a built-in step counter. The sensor co-processor will be notified when the system goes up or down, and only send events when the system is up.
- During system down, the sensor co-processor will keep tracking steps and send an event as soon as the system is up. No action is needed in your app.
To support devices without the sensor co-processor, however, you will need to maintain a fallback solution of streaming raw accelerometer data instead of using the built-in step counter sensor type.
The introduction of low power sensors provides many exciting opportunities for developers when creating intelligent, context aware applications and features on Sony Xperia devices. Features like dynamic sensor calibration, smart power management, or activity recognition benefits directly from low-power sensors. We hope that this will inspire you to experiment with your own ideas – no matter how small or big they are.
Do you have any questions or comments about the step counter sensor type or sensor co-processor on Sony Xperia devices? Drop us a line below!
* For Xperia Z1, Xperia Z Ultra and Xperia Z1 Compact, the step counter can actually be used already on Android 4.3, but we have to inform you that there is a bug which gives a delay in reporting steps when the device wakes up from standby.