YAACC - UPNP Client and Server
Loading...
Searching...
No Matches
de.yaacc.snapcast.client.SnapcastClientPower Class Reference

Task 12C: the one switch of the phone's own Snapcast client, without Android. More...

Collaboration diagram for de.yaacc.snapcast.client.SnapcastClientPower:
Collaboration graph

Classes

enum  Outcome
 What a call came to. More...
 
class  RestoreResult
 What a restore came to: the decision, and the outcome of the start when one was made (null when skipped).
 
interface  Session
 The service of the client; SnapcastClientRuntime and SnapcastClientService in the app. More...
 
enum  Shown
 What the switch and the dialog show. More...
 
class  State
 The state to show: where the client is, and how its last session ended.
 
interface  Store
 The persisted settings and the state; SharedPreferences in the app. More...
 

Public Member Functions

 SnapcastClientPower (Store store, Session session, Consumer< String > log)
 
 SnapcastClientPower (Store store, Session session, Consumer< String > log, java.util.function.LongSupplier clock)
 
boolean isOn ()
 
boolean offered ()
 
Outcome setOn (boolean on)
 The switch, the checkbox, the dialog: sets the state and starts or stops the session.
 
synchronized Outcome applyOption ()
 The rule for the client changed (support, services or the client switch went off or on, issue #330): a session that runs while the client is not allowed any more ends, and the client connects when it is allowed again and was switched on.
 
synchronized RestoreResult restore (SnapcastClientRestore.Point point, boolean exitHold)
 The application starts the client again from the state (SnapcastClientRestore).
 
State state ()
 What to show now.
 
boolean isPoweredOn ()
 What the power button of the card shows (tasks 12.4 part 2 and 12.16): on while a session starts, runs or reconnects, while a restart on another server waits, and for a moment after a start was handed to the service (the session shows its first phase a moment later); off when the client is switched off, and also when it is switched on but has no session (it gave up, or a start was refused: a tap starts it again).
 
Outcome chooseServer (String hostText)
 The user chose a server on the card of the client (task 12.10): it is remembered as the one the next start uses.
 
void markEndingSeen ()
 The switch or the dialog showed the last ending: it is not unseen any more.
 

Static Public Member Functions

static boolean isBackgroundStartRefusal (Throwable error)
 Whether the exception is the platform's refusal of a foreground service start from the background (ForegroundServiceStartNotAllowedException, API 31): by the class name, also in the chain of causes, because the class does not exist on older platforms or on the JVM.
 

Detailed Description

Task 12C: the one switch of the phone's own Snapcast client, without Android.

The state "switched on" is ONE persisted boolean (SnapcastClient#KEY_SWITCHED_ON); this class is the only place that writes it. The switch on the first page, the checkbox of the settings, the listen test dialog and (next run) the power button of the card all go through setOn; the application restores from it at the start (restore).

  • On: the state is written first (it follows the intent and stays on whatever happens next), then the session is started through the existing start path. The option and the saved server are checked on EVERY start; a refusal or a failure is returned as an Outcome (the caller shows its reason) and the reason is kept as the last ending, so that the switch and the dialog show "stopped" with it. No retry loop.
  • Off: the state is cleared and the session is stopped through the existing stop path (the service records the end as a stop by the user and releases its locks).
  • Nothing else ever clears the state: not the exit, the sleep timer, the idle timer, the end of the process, a failure of the session or a refused start.

Nothing here is logged but class names and fixed words: never the address, never the message of an exception.

Constructor & Destructor Documentation

◆ SnapcastClientPower()

de.yaacc.snapcast.client.SnapcastClientPower.SnapcastClientPower ( Store store,
Session session,
Consumer< String > log,
java.util.function.LongSupplier clock )
Parameters
clockmilliseconds, only differences are used (a fake in the tests)

Member Function Documentation

◆ applyOption()

synchronized Outcome de.yaacc.snapcast.client.SnapcastClientPower.applyOption ( )

The rule for the client changed (support, services or the client switch went off or on, issue #330): a session that runs while the client is not allowed any more ends, and the client connects when it is allowed again and was switched on.

What the user chose on the card is the intent and is never written here. Idempotent.

Referenced by de.yaacc.snapcast.SnapcastServices.install().

Here is the caller graph for this function:

◆ chooseServer()

Outcome de.yaacc.snapcast.client.SnapcastClientPower.chooseServer ( String hostText)

The user chose a server on the card of the client (task 12.10): it is remembered as the one the next start uses.

While the client is on and connected to another server, the session ends and starts again on it (one restart; the state stays on; the same server restarts nothing); while it is off, nothing starts. The option is checked again and the address is validated like on every start. No automatic failover: this is the only way the server changes.

Parameters
hostTextthe text of one of the known servers (host or host:port)
Here is the call graph for this function:

◆ isOn()

boolean de.yaacc.snapcast.client.SnapcastClientPower.isOn ( )
Returns
the persisted state: the user wants the client on

◆ offered()

boolean de.yaacc.snapcast.client.SnapcastClientPower.offered ( )
Returns
whether the switch is offered at all: the option is on and a valid server is known (SnapcastClientServerChoice)
Here is the call graph for this function:

◆ restore()

synchronized RestoreResult de.yaacc.snapcast.client.SnapcastClientPower.restore ( SnapcastClientRestore.Point point,
boolean exitHold )

The application starts the client again from the state (SnapcastClientRestore).

Never clears the state.

Parameters
exitHoldthe process was created right after an explicit exit and waits for the user

Referenced by de.yaacc.snapcast.client.SnapcastClientPowers.restore().

Here is the caller graph for this function:

◆ setOn()

Outcome de.yaacc.snapcast.client.SnapcastClientPower.setOn ( boolean on)

The switch, the checkbox, the dialog: sets the state and starts or stops the session.

Call from the main thread.

Returns
Outcome#STOPPED for off; Outcome#STARTED or Outcome#ALREADY_ACTIVE for on, or the refusal

The documentation for this class was generated from the following file: