aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-01-23 15:54:22 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-01-23 16:12:26 +0100
commite9236dd25e38f28d978405d2e519544a47f25edf (patch)
tree4ea188b53ad88d4023ac36085292826f53ad2328
parentMatch lowercase asus phones for fab hack (diff)
downloadwireguard-android-e9236dd25e38f28d978405d2e519544a47f25edf.tar.xz
wireguard-android-e9236dd25e38f28d978405d2e519544a47f25edf.zip
Rework timer in tunnel detail
-rw-r--r--app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java26
1 files changed, 11 insertions, 15 deletions
diff --git a/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java b/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
index f28a7b6..353a5df 100644
--- a/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
+++ b/app/src/main/java/com/wireguard/android/fragment/TunnelDetailFragment.java
@@ -34,18 +34,6 @@ public class TunnelDetailFragment extends BaseFragment {
@Nullable private Timer timer;
@Nullable private State lastState = State.TOGGLE;
- private static class StatsTimerTask extends TimerTask {
- final TunnelDetailFragment tdf;
- private StatsTimerTask(final TunnelDetailFragment tdf) {
- this.tdf = tdf;
- }
-
- @Override
- public void run() {
- tdf.updateStats();
- }
- }
-
@Override
public void onCreate(@Nullable final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -70,7 +58,12 @@ public class TunnelDetailFragment extends BaseFragment {
public void onResume() {
super.onResume();
timer = new Timer();
- timer.scheduleAtFixedRate(new StatsTimerTask(this), 0, 1000);
+ timer.scheduleAtFixedRate(new TimerTask() {
+ @Override
+ public void run() {
+ updateStats();
+ }
+ }, 0, 1000);
}
@Override
@@ -127,11 +120,14 @@ public class TunnelDetailFragment extends BaseFragment {
private void updateStats() {
if (binding == null || !isResumed())
return;
- final State state = binding.getTunnel().getState();
+ final Tunnel tunnel = binding.getTunnel();
+ if (tunnel == null)
+ return;
+ final State state = tunnel.getState();
if (state != State.UP && lastState == state)
return;
lastState = state;
- binding.getTunnel().getStatisticsAsync().whenComplete((statistics, throwable) -> {
+ tunnel.getStatisticsAsync().whenComplete((statistics, throwable) -> {
if (throwable != null) {
for (int i = 0; i < binding.peersLayout.getChildCount(); ++i) {
final TunnelDetailPeerBinding peer = DataBindingUtil.getBinding(binding.peersLayout.getChildAt(i));