15

recently I’ve started developing for Tizen OS. My application is created only for wearable and only for specific device which is Samsung Gear Sport (Tizen 3.0 on board). Main purpose of this application is to gather complete sensor data over a long period of time. I’m interested in heart rate, and movement sensors in general (gyroscope and accelerometer). Then, this data will be send to cloud server and analysed. Currently I’m considering a WEB application because so far I have found no evidence that WEB API is missing something that exists in native API.

But there is one limitation in Tizen OS that so far I am unable to overcome. My application is put to sleep after a while (10 minutes or so). It is crucial that this app should work in the background for a long time (up to 10 hours). To achieve this, I’ve tried following approaches:

  • Normal Tizen app with background-category: data given by this approach is still too fragmented, for example I got 15 minutes holes where no data was recorded at all. Sometimes there were holes even longer than 30 minutes.
  • Tizen alarms API: alarms did the job in case of keeping the app alive, but with every alarm, app was brought to the front and this is not an acceptable solution. There is an option to silently wake up the app (using app control), but it does not have any callback, so all alarms would have to be scheduled upfront.
  • CPU_AWAKE flag made the system show “this app is using too much energy” popup, and when not answered within 10 minutes or so, system would kill my app nonetheless.
  • Web Workers - this one is only for the sake of argument, web workers are put to sleep along with the application
  • Data recording: I was hoping for something similar to Apple Health Kit, but instead I got something that is not working for HRM at all. Somehow it works for PRESSURE sensor. Tizen allows to start recording for HRM but nothing is recorded after - NotFoundError: Failed to read recorded data. Any other sensor gives TypeMismatchError.
  • Web Service app - this one requires partner-level certification with Samsung, also it’s affected by the background limitations, as the documentation mentions.
  • Watch Face approach with “keep always on” flag set to true in device settings. This solution was the best I’ve tried. Watch face app wakes up every minute to change the time and it also receives sensor data. Unfortunately after more testing it turned out that there were couple holes in the data recorded.

About the battery: none of the above was draining the battery to a point where it became unacceptable. So first I’d like to find a solution that will give me all the sensor data I need, as frequently as possible from at least 10 hours, with no holes in it. And after that, if it turns out that this solution is draining too much battery, I will think about how to optimize it.

And now the question: is it possible to keep my application alive for 10+ hours non stop?

tymbark
  • 1,279
  • 12
  • 20
  • You may check https://developer.tizen.org/forums/web-application-development/retrieve-heart-rate-monitor-data-long-period-time – Iqbal hossain Apr 13 '18 at 06:01
  • 1
    Actually thats my post on tizen dev forum. Still looking for better solution than the alarms. – tymbark Apr 13 '18 at 09:31
  • As per my knowledge, currently may be there is no solution better than this .... if you find please share – Iqbal hossain Apr 13 '18 at 10:06
  • I'm also stuck on this issue. I have a native Tizen app written in C. I'm using the set option for always on on both Accelerometer and HRM and I need to get data for something like 6-8 hours in a row. I have major holes for sometimes 30 mintues and sometimes up to 3-4 hours. Also setting the CPU lock request won't work. If I will keep sending messages between the app and the wearable device using SAP will it still stay alive? – Gilad Eshkoli Apr 14 '18 at 07:08
  • Hi, I think I've found a solution (at least for me when using native Tizen UI apps). Tizen offers Services apps with no UI in order to do background tasks, it is also re-bootable if OS managed to kill it. https://developer.tizen.org/ko/development/guides/native-application/application-management/applications/service-application?langredirect=1 – Gilad Eshkoli Apr 15 '18 at 11:29
  • No, you are right, even when I use the service application there are major "holes" for 30 minutes and more. Any luck with something else? – Gilad Eshkoli Apr 15 '18 at 15:05
  • Hi, currently I'm developing a watch face with alarms that schedule themselves on "timetick" event (in ambient mode). Also watch face "always on" option is enabled. – tymbark Apr 16 '18 at 09:30
  • Well, Watch face with "Always On" is not an option for me. – Gilad Eshkoli Apr 17 '18 at 07:19
  • 3
    **How about contacting the [Tizen App School](http://tizenschool.org/)?** It is a site **created by Tizen developers** for other developers. If you leave a comment for this issue, they may prepare the lecture or the solution for this issue. – msalt.net Apr 17 '18 at 07:33
  • @msalt I've send them a message, thanks for the suggestion – tymbark Apr 17 '18 at 08:59
  • Sorry for going Sidetopic, Would you please share how you woke up Tizen app Silently using appControl? – Md. Armaan-Ul-Islam Apr 17 '18 at 09:05
  • just use `http://tizen.org/appcontrol/operation/main` in appControl instead of `.../default` – tymbark Apr 17 '18 at 12:15
  • Hi @tymbark, I finally made a Service app for the Sensors connections and fetching the data while using an UI application only for showing status and with the CPU_AWAKE request it seems to finally be fine! Another thing is that the battery consumption seems to be like 30-35% for using it for 7-8 hours in a row. – Gilad Eshkoli Apr 25 '18 at 13:50
  • One question please, if you may have knowledge or know any workaround, after 7-8 hours it seems that the SAP is "killed/frozen" and I can't connect to it from an Android phone, ONLY after opening the Gear app and using findPeers() on Android it will finally make a valid connection using SAP. Is there any way to keep that connection alive for good? My consumer is the Android and the provider is the Gear app. – Gilad Eshkoli Apr 25 '18 at 13:52
  • @Gil I have the same problem with app killed after some time. But how come Tizen OS is not complaining about the battery usage with CPU_AWAKE? In my situation if I don't release the CPU in 10 minutes, system shows "this app is using too much power" and kills my app. Currently I'm trying to make it like, request the CPU for 1 minute, then release for 1 minute, then request again... – tymbark Apr 26 '18 at 08:08
  • @tymbark Maybe cause I'm using a Service app and not a regular UI application, which intended to work on background. I don't really know. Documentation is a hell in all regarding Tizen. – Gilad Eshkoli Apr 26 '18 at 15:04
  • @Gil do you have partner level certificate from samsung? Also are you making web or native app? – tymbark Apr 26 '18 at 15:08
  • @tymbark No. No partner level cert. I'm building it native (C). It was not published yet but from Tizen Studio all looks good. – Gilad Eshkoli Apr 26 '18 at 15:18
  • @Gil thanks for the info. I guess native service does not require partner level cert. Can you tell me how good your solution is? Is it working non-stop all the time, getting 1 HR read per second for many hours? – tymbark Apr 26 '18 at 15:22
  • Yes it does,I'm getting ACC 10 times a sec and HRM 1 sample per minute. Do notice that HRM is the battery killer (Green light) – Gilad Eshkoli Apr 26 '18 at 15:25
  • @Gil yes, from my observations it takes up to 50% of battery for 8h of recording – tymbark Apr 26 '18 at 15:27
  • @tymbark, you are right! Saw that too, with sampling only one time in a minute it is reduced to 25-30% max – Gilad Eshkoli Apr 26 '18 at 15:29
  • @tymbark, Anyway I would love to help. If you have any way to keep the SAP connection alive I will be more than happy! – Gilad Eshkoli Apr 26 '18 at 15:30
  • @Gil I've never worked with that, sorry. My app is sending the data directly to the cloud using REST api. If you'd like, you can elaborate your solution for keeping the app alive non stop as the answer for this question. – tymbark Apr 26 '18 at 15:37
  • @Gil Hi, using your hints, I've managed to create service app in native Tizen that runs for a long time, but only for Tizen 2.3.1 version. If I make the target Tizen 3.0, the service is stopped after 10 seconds or so. What about your solution? Which Tizen version are you targeting? – tymbark May 21 '18 at 08:31
  • I'm targetimg 2.3.1, but it runs well on 3.0 (Gear 3) and above – Gilad Eshkoli May 21 '18 at 08:35
  • Its the same for me. Interesting fact is that if I update target version to 3.0, service app is immediately stopped after 10 seconds. – tymbark May 21 '18 at 09:26
  • @tymbark Hey, I'm struggling with the same problem. How's your final approach to this issue looking like? – Roman Samoilenko Aug 15 '18 at 06:15
  • @RomanSamoylenko Hi, we ended up with a mixed solution with watch face and multiple native services also we target Tizen 2.3.1 – tymbark Aug 21 '18 at 09:45
  • Hi @tymbark would you please post your solution here as an answer so that other developers can get help from here? – Shaswati Saha Aug 28 '18 at 09:50

2 Answers2

6

If you target the native Service App API 3.0 get the following:

device_power_request_lock(POWER_LOCK_CPU, 0);
sensor_listener_set_option(listener,  SENSOR_OPTION_ALWAYS_ON);
sensor_listener_set_attribute_int(listener, SENSOR_ATTRIBUTE_PAUSE_POLICY, SENSOR_PAUSE_NONE);

And don't forget to set a Background Category (sensor + location if needed) in the Manifest because otherwise Tizen will kill your app after ~ 10 min.

Of course hardly any of this is properly documented...

Lena
  • 350
  • 4
  • 13
tingel
  • 61
  • 1
  • 2
  • 1
    I could successfully use `device_power_request_lock(POWER_LOCK_DISPLAY, 0);` to leave the display on for a given timeout, but I had to add the privilege `http://tizen.org/privilege/display`, otherwise it would not work for me – go3d May 27 '20 at 23:26
6

I've spend many weeks trying to find the solution to this problem. The closest I got to the all time non stop working application was to create multi package application (also called a hybrid app) that consisted of:

  • WEB application written in JS that was a watch face app
  • Native service application (no UI) written in C

All apps were targeting Tizen API 2.3.1. This is the crucial part because there were multiple problems with 3.0 API like unexpected application kills by the OS or "too much battery usage" prompts that sometimes also resulted in killing my app. Funny thing about the Tizen OS is that when it kills the watch face app due to too much resource usage, the main screen of the watch is just plain black. Unfortunately targeting API 2.3.1 resulted in not being able to use multiple APIs added after this version.

Next thing I've used was device_power_request_lock(POWER_LOCK_CPU, 0); in all the native service apps. I believe that using the older API (2.3.1 instead of 3.0) allowed the application to work much longer without being killed by the system. I think that this is a flaw in this Tizen OS version that I've leveraged.

In the WEB app I've used ScreenStateChangeListener and timetick events to check if the service app is running. If not -> it was started by the WEB application. For communication between service and the watch face I've used preferences listener API. Watch face WEB app was responsible for checking what service is working and what service needs to be woken up or started.

In the end I've ended up using 4 native service applications packaged together with the WEB app. Each service app had its own purpose like filesystem, network, monitoring, etc. Multithreaded service apps were really hard to maintain and often crashed for unknown reason.

tymbark
  • 1,279
  • 12
  • 20
  • Is this still the current state of the nation or did we get any better options for endless running services in the meantime? I'm currently experimenting with various approaches but I have not yet found a satisfying solution. – user1195883 May 30 '20 at 11:43
  • I didn't revisit the subject for a year as now I'm working in different projects. But it still should work for Samsung Gear Sport smartwatch. I didn't check this solution on newest Samsung watches but I think they don't have as good sensors as Gear Sport. – tymbark Jun 01 '20 at 12:01