From d44d0d6230ed2c657de5326f24435817000d2ee0 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 14 Jun 2019 11:20:14 +0200 Subject: [PATCH] Fixed warnings --- .../email/FragmentOptionsConnection.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java index 8dce2b9a4c..282c07f9c4 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsConnection.java @@ -141,6 +141,9 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre super.onResume(); ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm == null) + return; + NetworkRequest.Builder builder = new NetworkRequest.Builder(); builder.addCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET); cm.registerNetworkCallback(builder.build(), networkCallback); @@ -149,19 +152,22 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre @Override public void onPause() { ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); + if (cm == null) + return; + cm.unregisterNetworkCallback(networkCallback); super.onPause(); } @Override - public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { + public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) { inflater.inflate(R.menu.menu_options, menu); super.onCreateOptionsMenu(menu, inflater); } @Override - public boolean onOptionsItemSelected(MenuItem item) { + public boolean onOptionsItemSelected(@NonNull MenuItem item) { switch (item.getItemId()) { case R.id.menu_default: onMenuDefault(); @@ -198,17 +204,17 @@ public class FragmentOptionsConnection extends FragmentBase implements SharedPre private ConnectivityManager.NetworkCallback networkCallback = new ConnectivityManager.NetworkCallback() { @Override - public void onAvailable(Network network) { + public void onAvailable(@NonNull Network network) { showConnectionType(); } @Override - public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) { + public void onCapabilitiesChanged(@NonNull Network network, @NonNull NetworkCapabilities networkCapabilities) { showConnectionType(); } @Override - public void onLost(Network network) { + public void onLost(@NonNull Network network) { showConnectionType(); } };