Class StepService

All Implemented Interfaces:
ComponentCallbacks, ComponentCallbacks2

public final class StepService extends Service
Sioul in the background: it keeps your devices in step while Sioul is closed (crates/sioul-app/src/steps.rs; docs/android.md, "In the background"). A foreground service in a process of its own (":steps"): Qt's activity ends its whole process when it closes (System.exit in QtActivityBase.onDestroy), which would end a service living there too. It holds Sioul's library without Qt's window, and one quiet notification. - An alarm through Doze (exact while allowed, else inexact) asks Rust for a step: the other devices' news read (Sioul's own pull from the server while it works, else the sync app asked to look, then a quick exchange), do-not-disturb asked of Sioul's own process when it changed (DndReceiver), mail at its rhythm; Rust says when to look next. - A watch on the sharing folder: another device's file written by the sync app brings a step three seconds later, without waiting for the alarm (Rust leaves it out when its pull brought that file already). - The phone is kept awake only while a step runs: a step asked for later (a folder's, a message's) comes by an exact alarm of its own (`later`). - While Sioul's window is on the screen, it exchanges by itself: the steps wait. - While this phone screens calls (Calls.java), its notification offers "Let every call through", for an hour or until turned off, and "Screen calls again"; each step keeps the calls' table in step too. Rust's questions come through call(verb, json) (android/main.cpp), also from Sioul's own process: starting and stopping the service, the stars of the list's people (DndContacts), the battery's exemption, the alarm of do-not-disturb's next end (DndReceiver).
  • Field Details

  • Constructor Details

  • Method Details

    • nativeStep

      static String nativeStep(String reason)
      One step, on the worker thread: {next (seconds), folder, own, line, title, channel, stop}.
    • nativeService

      static void nativeService()
      Tells Rust it runs in the service's process: it never touches Android's modes from here.
    • call

      static String call(Context context, String verb, String json)
      Rust's question (android/main.cpp), from either process. Any thread.
    • kept

      private static SharedPreferences kept(Context context)
      Whether it runs and its words, written by Sioul's own process and read by the service's: read again from the file when it changed (both processes use it, rarely).
    • start

      static boolean start(Context context, JSONObject words)
      The service started, or told new words: {title, channel}. Kept, so that a restart of the phone starts it again with them. False when Android refused (Sioul in the background on Android 12 and later).
    • stop

      static void stop(Context context)
      Stopped, and not started again at the phone's restart.
    • restart

      static void restart(Context context, String reason)
      At the phone's restart or after an update (StepReceiver): started again if it was on.
    • alarm

      static void alarm(Context context)
      An alarm's step (StepReceiver): to the service running, else it starts (an exact alarm allows it).
    • inThisProcess

      static boolean inThisProcess()
      Whether the service runs in this very process (its own, ":steps").
    • runningHere

      static boolean runningHere(Context context)
      Whether the service runs, asked from either process.
    • exempt

      static boolean exempt(Context context)
      Whether Android lets Sioul run in the background, battery optimisation aside.
    • askBattery

      static void askBattery(Context context)
      Android's question to let Sioul run in the background; else its list.
    • onCreate

      public void onCreate()
      Overrides:
      onCreate in class Service
    • onStartCommand

      public int onStartCommand(Intent intent, int flags, int startId)
      Overrides:
      onStartCommand in class Service
    • onDestroy

      public void onDestroy()
      Overrides:
      onDestroy in class Service
    • onBind

      public IBinder onBind(Intent intent)
      Specified by:
      onBind in class Service
    • foreground

      private void foreground()
      The service in the foreground with its notification: at each start, as Android asks.
    • refresh

      private void refresh()
      Its notification changed in place: new words, the do-not-disturb line.
    • note

      private Notification note()
      One quiet notification: the lowest importance, no sound, no badge, hidden on the lock screen.
    • callsWords

    • action

      private static Notification.Action action(Context context, int code, String title, boolean on, int minutes)
      One of the notification's buttons for the calls: on for `minutes` (0: until turned off), or off.
    • note

      static boolean note(Context context, String json)
      The notification's words, {title, text, calls}, told by Rust after each apply in Sioul's own process: to the service running in this process, else to its process (StepReceiver), only while it runs. True when told.
    • told

      static void told(String json)
      The words told (StepReceiver, in this process): the notification changed in place at once when they differ.
    • words

      private void words(String json)
      New words, kept and shown at once when they changed: on the caller's thread, never behind a step, which may wait for the sync app or for mail on the worker's.
    • said

      private void said(JSONObject answer)
      The notification's words from Rust ({at, title, text, channel, calls}): shown again when one changed; words made before those shown (`at`, Unix milliseconds: a step's, finished after a press told newer ones) are left aside.
    • soon

      static void soon(Context context)
      A line written for your computers, from the listener's process: a step soon, while the service runs (else the window's own exchanges, or the next start, send it).
    • soonHere

      static void soonHere()
      `SOON` heard (StepReceiver, in this process): a step `SOON_MS` on, or the one waiting for its alarm then, which shares the line too (`Later.of`); none when a step is about to run.
    • laterHere

      static void laterHere(Context context)
      The alarm of the step asked for later (StepReceiver, in this process): it runs now; the service started again if Android had stopped it.
    • heard

      static void heard(Context context)
      A press of the switch made in Sioul's own process (StepReceiver): a step at once, which sends it.
    • callsPressed

      static void callsPressed(Context context, boolean on, int minutes)
      Expecting a call (once "Let every call through") pressed on the notification (StepReceiver, in this process): kept for the screening at once (Calls.press(android.content.Context, boolean, int)), then a step, in which Rust shares it with your other devices and words the notification again.
    • open

      private static PendingIntent open(Context context)
      A tap: Sioul, as by its icon.
    • step

      void step(String reason, long delay)
      A step: now, on the worker thread, the phone kept awake while it waits there and runs (one asked meanwhile replaces one not started; the one waiting for its alarm goes, this one does its work); or `delay` milliseconds on, by an exact alarm of its own, the phone left to sleep meanwhile (`later`).
    • later

      private void later(String reason, long delay)
      A step asked for later, as `Later.of` joins it to the one waiting: its exact alarm set, or moved (one alarm at a time). Through Doze too (allow-while-idle); Android brings an alarm five seconds on at the soonest.
    • run

      private void run(String reason)
    • windowShown

      private boolean windowShown()
      Whether Sioul's window is on the screen (its own process in the foreground).
    • watchFolder

      private void watchFolder(String folder)
      The sharing folder watched: another device's file written there brings a step.
    • othersFile

      static boolean othersFile(String name, String own)
      Another device's file, by its name in the sharing folder's top: hidden names are files being written; this device's own are its own steps. Pure: android/jvm-checks/StepsCheck.java.
    • takeWritten

      private String takeWritten()
      The names written since the last step, "/" between them, forgotten here (any step reads the folder).
    • schedule

      static void schedule(Context context, long seconds)
      The next step's alarm, `seconds` on: exact through Doze while allowed, else inexact.
    • cancel

      private static void cancel(Context context)
    • cancelLater

      private static void cancelLater(Context context)
      The alarm of a step asked for later, taken away: a step now does its work.
    • laterPending

      private static PendingIntent laterPending(Context context)
    • pending

      private static PendingIntent pending(Context context)
    • word

      private static String word(int which)