Tizen Service Application not running normally in background without being connected to Tizen Studio

1.3k Views Asked by At

I am trying to build a native tizen app which will detect activity and collect sensor data periodically to upload to a remote http server.

For this I have developed two things.
1. A Native UI Application to Start/Stop the
2. A Service application

I am developing the project in tizen studio with a samsung gear fit 2 pro connected via remote device manager over wifi.

When I run my app it works fine while my device is connected to sdb. But when I disconnect the device it starts doing non-deterministic behavior. For example, while it's connected to tizen studio, App records data for first 15s of every 60s and on the 16th second it uploads that file to server. It also starts on callback of activity change.
But as soon as the device is disconnected, that interval is not maintained properly i.e. sensors read data after 30 minutes(that also varies) and even frequency of data collection for every second is reduced dramatically. But if the UI app is in foreground then again everything is okay.

So, my app works normally if it's foreground or it's in foreground/background and device is connected to sdb on pc.

How can I make my service to run always in background irrespective of device's connection to tizen sdb on PC?

N.B. Data Upload is done using libcurl and that uses a timeout of 5s for connection and on failure it skips uploading. Ecore Timer is used but timer should not be a problem as I have tested by running sensor always but frequency decrease issue still persists. Sensor starting options in service app are as follows

sensor_get_default_sensor(sensor_type, &sensor);
sensor_create_listener(sensor, &listener[sensor_type]);
sensor_listener_set_event_cb(listener[sensor_type], 1000 / SENSOR_FREQ, example_sensor_callback, vc);
sensor_listener_set_option(listener[sensor_type], SENSOR_OPTION_ALWAYS_ON);
sensor_listener_start(listener[sensor_type]);
3

There are 3 best solutions below

1
On

There might be a problem in binding the service app with UI app.

2
On

I think a background-category element is helpful for this problem. According to the guide, background-category allow apps to run in the background.

So, you need to modify the manifest file, here's an example.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns="http://tizen.org/ns/packages" api-version="2.4" package="org.tizen.test" version="1.0.0">
   <ui-application appid="org.tizen.test" exec="text" type="capp" multiple="false" taskmanage="true" nodisplay="false">
      <icon>rest.png</icon>
      <label>rest</label>
      <!--For API version 2.4 or higher-->
      <background-category value="media"/>
      <background-category value="download"/>
      <background-category value="background-network"/>
   </ui-application>
   <service-application appid="org.tizen.test-service" exec="test-service" multiple="false" type="capp"/>
      <background-category value="background-network"/>
      <background-category value="location"/>
   </service-application>
</manifest>

The value can be set to media, download, background-network, location, sensor, iot-communication and I think, In this case, the value should be a sensor.

1
On

See the related issues here and here.

It seems to me that the CPU is going to SLEEP state and hinders your recording. To prevent this, use

device_power_request_lock(POWER_LOCK_CPU, 0);

before starting the sensor listener. After you are done, release the lock with

device_power_release_lock(POWER_LOCK_CPU);

Depending on which Tizen version you are targeting, you may also (need to) use

sensor_listener_set_attribute_int(listener[sensor_type], SENSOR_ATTRIBUTE_PAUSE_POLICY, SENSOR_PAUSE_NONE);

which was introduced as a replacement of

sensor_listener_set_option(listener[sensor_type], SENSOR_OPTION_ALWAYS_ON);

in Tizen API 3.0.

This can be found in the API here, here, and here.