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 2 weeks 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) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return
}
QuickToggleService.setReady(this, ready)
Log.d("App", "Set Tile Ready: $ready $autoConnect")
Log.d("App", "Set Tile Ready: ready=$ready, autoConnect=$autoConnect")
vpnReady = ready
if (ready && autoConnect) {
startVPN()
@ -232,9 +229,6 @@ class App : Application(), libtailscale.AppContext {
}
fun setTileStatus(status: Boolean) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return
}
QuickToggleService.setStatus(this, status)
}
@ -363,9 +357,6 @@ class App : Application(), libtailscale.AppContext {
}
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 nm: NotificationManagerCompat = NotificationManagerCompat.from(this)
nm.createNotificationChannel(channel)

@ -23,7 +23,7 @@ public class QuickToggleService extends TileService {
// Request code for opening activity.
private static int reqCode = 0;
private static void updateTile() {
private static void updateTile(Context ctx) {
Tile t;
boolean act;
synchronized (lock) {
@ -33,6 +33,10 @@ public class QuickToggleService extends TileService {
if (t == null) {
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.updateTile();
}
@ -41,14 +45,14 @@ public class QuickToggleService extends TileService {
synchronized (lock) {
ready = rdy;
}
updateTile();
updateTile(ctx);
}
static void setStatus(Context ctx, boolean act) {
synchronized (lock) {
active = act;
}
updateTile();
updateTile(ctx);
}
@Override
@ -56,7 +60,7 @@ public class QuickToggleService extends TileService {
synchronized (lock) {
currentTile = getQsTile();
}
updateTile();
updateTile(this.getApplicationContext());
}
@Override

Loading…
Cancel
Save