ipn: provide subtitle in QuickToggleService (#357)

Fixes ENG-3443

Provides a "Connected" / "Not connected" subtitle in the Tailscale quick tile.

Also drops unnecessary SDK version checks in App.kt.

Signed-off-by: Andrea Gottardo <andrea@gottardo.me>
pull/354/head
Andrea Gottardo 7 months ago committed by GitHub
parent 1c0aef5418
commit 427e2d29b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -220,11 +220,8 @@ class App : Application(), libtailscale.AppContext {
} }
fun setTileReady(ready: Boolean) { fun setTileReady(ready: Boolean) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return
}
QuickToggleService.setReady(this, ready) QuickToggleService.setReady(this, ready)
Log.d("App", "Set Tile Ready: $ready $autoConnect") Log.d("App", "Set Tile Ready: ready=$ready, autoConnect=$autoConnect")
vpnReady = ready vpnReady = ready
if (ready && autoConnect) { if (ready && autoConnect) {
startVPN() startVPN()
@ -232,9 +229,6 @@ class App : Application(), libtailscale.AppContext {
} }
fun setTileStatus(status: Boolean) { fun setTileStatus(status: Boolean) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return
}
QuickToggleService.setStatus(this, status) QuickToggleService.setStatus(this, status)
} }
@ -363,9 +357,6 @@ class App : Application(), libtailscale.AppContext {
} }
fun createNotificationChannel(id: String?, name: String?, importance: Int) { fun createNotificationChannel(id: String?, name: String?, importance: Int) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
return
}
val channel = NotificationChannel(id, name, importance) val channel = NotificationChannel(id, name, importance)
val nm: NotificationManagerCompat = NotificationManagerCompat.from(this) val nm: NotificationManagerCompat = NotificationManagerCompat.from(this)
nm.createNotificationChannel(channel) nm.createNotificationChannel(channel)

@ -23,7 +23,7 @@ public class QuickToggleService extends TileService {
// Request code for opening activity. // Request code for opening activity.
private static int reqCode = 0; private static int reqCode = 0;
private static void updateTile() { private static void updateTile(Context ctx) {
Tile t; Tile t;
boolean act; boolean act;
synchronized (lock) { synchronized (lock) {
@ -33,6 +33,10 @@ public class QuickToggleService extends TileService {
if (t == null) { if (t == null) {
return; return;
} }
t.setLabel("Tailscale");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
t.setSubtitle(act ? ctx.getString(R.string.connected) : ctx.getString(R.string.not_connected));
}
t.setState(act ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE); t.setState(act ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE);
t.updateTile(); t.updateTile();
} }
@ -41,14 +45,14 @@ public class QuickToggleService extends TileService {
synchronized (lock) { synchronized (lock) {
ready = rdy; ready = rdy;
} }
updateTile(); updateTile(ctx);
} }
static void setStatus(Context ctx, boolean act) { static void setStatus(Context ctx, boolean act) {
synchronized (lock) { synchronized (lock) {
active = act; active = act;
} }
updateTile(); updateTile(ctx);
} }
@Override @Override
@ -56,7 +60,7 @@ public class QuickToggleService extends TileService {
synchronized (lock) { synchronized (lock) {
currentTile = getQsTile(); currentTile = getQsTile();
} }
updateTile(); updateTile(this.getApplicationContext());
} }
@Override @Override

Loading…
Cancel
Save