001// SPDX-License-Identifier: GPL-3.0-or-later
002// Copyright © 2026 Aurélien Pierre
003
004package com.aurelienpierre.sioul;
005
006import android.content.BroadcastReceiver;
007import android.content.Context;
008import android.content.Intent;
009
010/**
011 * The background service's alarm, and the phone's restart or Sioul's update
012 * (StepService, in the same process ":steps"): a step for the service
013 * running, else the service started again, if it was on. An exact alarm
014 * lets an app start its foreground service from the background; so do the
015 * restart and the update; the alarm of a step asked for later (a folder's,
016 * a message's: LATER). Also the notification's "Let every call through"
017 * (Calls.java), sent by it alone; and its words, told by Sioul's own process
018 * after each apply (NOTE_WORDS), shown at once.
019 */
020public final class StepReceiver extends BroadcastReceiver
021{
022    @Override
023    public void onReceive(Context context, Intent intent)
024    {
025        String action = intent.getAction();
026        if (action == null)
027            return;
028        Context app = context.getApplicationContext();
029        switch (action) {
030        case StepService.STEP:
031            StepService.alarm(app);
032            break;
033        case StepService.CALLS:
034            StepService.callsPressed(app, intent.getBooleanExtra("on", false), intent.getIntExtra("minutes", 0));
035            break;
036        case StepService.HEARD:
037            StepService.heard(app);
038            break;
039        case StepService.NOTE_WORDS:
040            StepService.told(intent.getStringExtra("words"));
041            break;
042        case StepService.SOON:
043            StepService.soonHere();
044            break;
045        case StepService.LATER:
046            StepService.laterHere(app);
047            break;
048        case Intent.ACTION_BOOT_COMPLETED:
049        case Intent.ACTION_MY_PACKAGE_REPLACED:
050            StepService.restart(app, "restart");
051            break;
052        default:
053            break;
054        }
055    }
056}