简体   繁体   English

Tizen 服务应用程序在未连接到 Tizen Studio 的情况下无法在后台正常运行

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

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.我正在尝试构建一个本机 tizen 应用程序,它将定期检测活动并收集传感器数据以上传到远程 http 服务器。

For this I have developed two things.为此,我开发了两件事。
1. A Native UI Application to Start/Stop the 1. 一个本地 UI 应用程序来启动/停止
2. A Service application 2.一个服务应用程序

I am developing the project in tizen studio with a samsung gear fit 2 pro connected via remote device manager over wifi.我正在使用通过 wifi 上的远程设备管理器连接的samsung gear fit 2 pro在 tizen studio 中开发项目。

When I run my app it works fine while my device is connected to sdb.当我运行我的应用程序时,它在我的设备连接到 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.例如,当它连接到 tizen studio 时,App 会记录每 60 秒的前 15 秒的数据,并在第 16 秒将该文件上传到服务器。 It also starts on callback of activity change.它还从活动更改的回调开始。
But as soon as the device is disconnected, that interval is not maintained properly ie sensors read data after 30 minutes(that also varies) and even frequency of data collection for every second is reduced dramatically.但是,一旦设备断开连接,该间隔就无法正确维持,即传感器在 30 分钟后读取数据(这也会有所不同),甚至每秒收集数据的频率也会大大降低。 But if the UI app is in foreground then again everything is okay.但是如果 UI 应用程序在前台,那么一切都很好。

So, my app works normally if it's foreground or it's in foreground/background and device is connected to sdb on pc.因此,如果我的应用程序处于前台或处于前台/后台并且设备连接到 pc 上的 sdb,则我的应用程序可以正常工作。

How can I make my service to run always in background irrespective of device's connection to tizen sdb on PC?无论设备与 PC 上的 tizen sdb 的连接如何,如何让我的服务始终在后台运行?

NB Data Upload is done using libcurl and that uses a timeout of 5s for connection and on failure it skips uploading. NB 数据上传是使用 libcurl 完成的,它使用 5 秒的超时进行连接,失败时会跳过上传。 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.使用了 Ecore 定时器,但定时器应该不是问题,因为我已经通过运行传感器进行了测试,但频率降低问题仍然存在。 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]);

See the related issues here and here .请参阅此处此处的相关问题。

It seems to me that the CPU is going to SLEEP state and hinders your recording.在我看来,CPU 将进入 SLEEP state 并阻碍您的录制。 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根据您所针对的 Tizen 版本,您还可能(需要)使用

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.在 Tizen API 3.0 中。

This can be found in the API here , here , and here .这可以在 API 此处此处此处找到

There might be a problem in binding the service app with UI app.将服务应用程序与 UI 应用程序绑定可能会出现问题。

I think a background-category element is helpful for this problem.我认为背景类别元素有助于解决这个问题。 According to the guide , background-category allow apps to run in the background.根据指南,background-category 允许应用程序在后台运行。

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.该值可以设置为媒体、下载、后台网络、位置、传感器、物联网通信,我认为,在这种情况下,该值应该是传感器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM