Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document how to use TorService with foreground priority via binding #64

Open
eighthave opened this issue Dec 16, 2021 · 7 comments
Open

Comments

@eighthave
Copy link
Member

Android gives "foreground" priority to the activity that is currently visible. Things that are at the foreground priority are the last to be killed. With Service instances, it is possible to set the service to be permanently at the "foreground" priority as long as there is a permanent notification. It is also possible for a Service to get foreground priority if the currently active screen is bound to the Service using BIND_IMPORTANT.

@eighthave
Copy link
Member Author

Android's Binder model means that all the things that need Tor bind to it with BIND_IMPORTANT. That tells Android to keep it alive. Then for letting TorService quit when idle, there is a built-in mechanism to shutdown a Service when nothing is bound to it. The Android docs explicitly recommend bindService for IPC: https://developer.android.com/guide/components/processes-and-threads

More on bound services: https://developer.android.com/guide/components/bound-services

@n8fr8
Copy link
Member

n8fr8 commented Dec 16, 2021

Orbot does this today. OrbotService is the application specific foreground service that then binds to TorService:
https://github.com/guardianproject/orbot/blob/master/orbotservice/src/main/java/org/torproject/android/service/OrbotService.java#L759

@eighthave
Copy link
Member Author

The Chromium docs outline some nice security properties of bound services:
https://chromium.googlesource.com/chromium/src.git/+/refs/heads/main/docs/security/android-ipc.md#binder

@eighthave
Copy link
Member Author

It seems to me that we should be recommending WorkManager here also. Google is putting a lot of work into it to make it the complete background task runner. This is based on this discussion #61 (comment)

WorkManager started out for short lived background tasks, but has been extended to handle foreground and long-lived tasks:

@holywend
Copy link
Contributor

heya I was wondering is there any documentation on implementing torservice on android? I tried the sampleapp, which doesn't work for me as well.

@eighthave
Copy link
Member Author

eighthave commented Oct 11, 2022 via email

@holywend
Copy link
Contributor

@eighthave atm I couldn't even start the sampleapp. even tho I just clone it from the repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants