ActivityWatch / activitywatch

The best free and open-source automated time tracker. Cross-platform, extensible, privacy-focused.
https://activitywatch.net/
Mozilla Public License 2.0
12.66k stars 565 forks source link

iOS support #751

Open ErikBjare opened 2 years ago

ErikBjare commented 2 years ago

We currently support every major OS, except iOS.

Apple has historically taken a very cautious stance with ScreenTime data they collect, so support for iOS has been practically impossible (although RescueTime and some others offer an iOS app, it's really mostly a companion app).

However, a couple weeks ago someone gave me notice of Apple finally creating a more comprehensive API: https://www.reddit.com/r/QuantifiedSelf/comments/v1jykz/granular_app_tracking_on_iosipados/ibwbu2p/

The actual API: https://developer.apple.com/documentation/deviceactivity/deviceactivitydata

So, looks like this will be possible going forward. I don't personally own an iOS device, nor do I know anything about iOS dev, but going off how we built aw-android, we can probably do something similar for iOS, eventually.

ashutoshsaboo commented 2 years ago

+1 on this! iOS App would be amazing! :) Does it look like this could come anytime soon per your roadmap - say anytime next year? @ErikBjare

alexlyee commented 2 years ago

+1 this would be huge !

zplizzi commented 2 years ago

I looked into this today - this new API is unfortunately quite limited. It doesn't at all give you full app usage data. What it allows you to do is basically just: a) set a time interval to monitor within, b) trigger callbacks when certain apps exceed a configurable time threshold within this interval.

It seems to be designed to allow a limited use-case of parental control apps that set limits on app usage during certain parts of the day, while restricting access to usage data as much as possible outside of that use-case. In theory you could abuse this API by setting really short intervals and adding all the apps on your phone with similarly short thresholds, but it looks like they block that route too (Attempting to monitor too many activities or activities that are too tightly scheduled can cause this method to throw an error). They don't say what the thresholds are, so maybe if they allow eg 15-minute intervals you could still get some useful data from this, but it would be pretty low-quality.

Confirming this conclusion (that this API is mostly useless for our needs) is the fact that I can't find any apps that are able to generate reports on app usage - if it were possible I think someone would have built it by now.

There are other hacky approaches (eg make a VPN and monitor network activity to infer app usage), and it's definitely possible that there's some hacky approach that would be disallowed in an app-store app review but maybe we could use if our users were willing to sideload the app. But I haven't yet found an approach that seemed good enough to bother trying.

alexlyee commented 2 years ago

Thank you for your research!

zplizzi commented 2 years ago

That said, it does seem to be possible to determine if the iOS device is actively in use - I think through (an abuse of) the location API. RescueTime seems to do this. So we could at least develop an AFK watcher for iOS, which imo would still be valuable. And since you're already accessing location data, you could also throw in location info, or an at-home/not-at-home indicator, which could be cool (but probably only updated when the phone is unlocked?).

It's not clear to me if there is a battery impact of always keeping location services on, though. The rescuetime app is broken for me or i would test it, lol.

ErikBjare commented 2 years ago

Ahhh damn. Thanks for digging through this @zplizzi, really appreciate it!

I guess we're back to square one after all. So much for my initial optimism, sorry for any false hopes!

andrewschreiber commented 1 year ago

Looks like Timing supports iOS tracking now

https://timingapp.com/help/screen-time

Their approach is to ask the user to enable ScreenTime sync to Mac, then pull the data from the Mac via the Full Disk Access permission.

ErikBjare commented 1 year ago

@andrewschreiber We've tried doing the same in the past, but it was very unreliable/buggy data: https://github.com/ActivityWatch/aw-import-screentime

andrewschreiber commented 1 year ago

Ah interesting! Wonder if it's improved since last year and/or better on iOS vs Mac (limitations in that readme seem to point to Mac issues)

abegong commented 1 year ago

New AW user here! Tracking detailed usage from my iphone is one of my primary use cases for AW.

I'm playing around with https://github.com/ActivityWatch/aw-import-screentime to see what I can learn. I've got the old script working again, filed a PR and a couple issues.

I'll report back once I've had a chance to see how it actually behaves.

zplizzi commented 1 year ago

FWIW, I've been trying out the Timing app (paid) and its iOS integration, and it's been really good for me so far. Seems to sync pretty quickly (usually have data within a couple hours or less) and no issues with data quality. Here's an example timeline it generates:

image
ErikBjare commented 1 year ago

@zplizzi Really curious how Timing does it? Are they inspecting the database file like aw-import-screentime or something else? A new API? Any idea how long they've had the feature?

zplizzi commented 1 year ago

There's a good many details here: https://timingapp.com/help/screen-time

Finally, grant Timing the "Full Disk Access" permission in System Settings. This is required for Timing to read your Screen Time database.

According to their changelog, looks like it was added on Jan 16 2023.

ErikBjare commented 1 year ago

Ah nice, that's a very extensive resource! But tl;dr seems same approach as aw-import-screentime (parse synced db file).

In my experience that data was very unreliable, but it's possible that it's due to us mishandling the data, which we might be able to fix (although reading the link it seems accepted that it's imperfect, still worth a try).

If someone wants to investigate that, we could make it work. I don't have an iOS device, so difficult for me to test extensively. Comparing the output of aw-import-screentime with Timely would be interesting.

BelKed commented 1 year ago

Comparing the Timing data and the data imported by aw-import-screentime, I can say that the results are quite similar.

One problem is that ActivityWatch reports about 15 minutes less than the Timing app. Another problem I've encountered is that the ActivityWatch Activity view doesn't show the Top Applications.

And judging by the Screen Time view on iPhone, it looks like this morning's data hasn't been synced yet.


Timing view:


ActivityWatch Activity view:
Real device UUID replaced with {uuid} for privacy reasons


ActivityWatch Raw Data (Timeline) view:
Category tag contains only the UUID of the device


ActivityWatch Raw Data (Events) view:
You should definitely check out the open-source Organic Maps app ;)


Screen Time data:

 

ShaySheng commented 3 months ago

https://sspai.com/post/65516

Here is how you can use shortcuts to get the right time data. It was written in Chinese you can translate it into English.