001// SPDX-License-Identifier: GPL-3.0-or-later 002// Copyright © 2026 Aurélien Pierre 003 004package com.aurelienpierre.sioul; 005 006import android.content.Intent; 007import android.service.quicksettings.Tile; 008import android.service.quicksettings.TileService; 009 010/** 011 * "Do not disturb (Sioul)" among the quick settings: Sioul's switch, on every 012 * device (docs/do-not-disturb.md), pressed without opening Sioul. Lit while 013 * Sioul's do-not-disturb holds on this phone, as Rust said at its last apply 014 * ({@link PauseMode#sioulOn}); a tap turns it off when it holds, else on until 015 * turned off, through DndReceiver in Sioul's own process. Beside Android's 016 * own tile, which Sioul hears too: both say the same once Sioul applied. 017 */ 018public final class DndTile extends TileService 019{ 020 @Override 021 public void onStartListening() 022 { 023 show(PauseMode.sioulOn(this)); 024 } 025 026 @Override 027 public void onTileAdded() 028 { 029 show(PauseMode.sioulOn(this)); 030 } 031 032 @Override 033 public void onClick() 034 { 035 // Shown at once as asked; Rust's apply says the rest (PauseMode.flags). 036 show(!PauseMode.sioulOn(this)); 037 sendBroadcast(new Intent(this, DndReceiver.class).setAction(DndReceiver.TOGGLE)); 038 } 039 040 private void show(boolean on) 041 { 042 Tile tile = getQsTile(); 043 if (tile == null) 044 return; 045 tile.setState(on ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); 046 tile.updateTile(); 047 } 048}