global: Fix or suppress most lints/warnings

Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
Samuel Holland 2018-01-08 20:42:58 -06:00
parent dd69a2e778
commit 4f02817ef0
18 changed files with 47 additions and 40 deletions

View File

@ -39,7 +39,6 @@ dependencies {
implementation 'com.google.dagger:dagger:2.14.1' implementation 'com.google.dagger:dagger:2.14.1'
implementation 'net.sourceforge.streamsupport:android-retrofuture:1.6.0' implementation 'net.sourceforge.streamsupport:android-retrofuture:1.6.0'
implementation 'net.sourceforge.streamsupport:android-retrostreams:1.6.0' implementation 'net.sourceforge.streamsupport:android-retrostreams:1.6.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
} }
repositories { repositories {

View File

@ -28,6 +28,7 @@ import java.util.Objects;
@TargetApi(Build.VERSION_CODES.N) @TargetApi(Build.VERSION_CODES.N)
public class QuickTileService extends TileService { public class QuickTileService extends TileService {
private static final String TAG = "WireGuard/" + QuickTileService.class.getSimpleName(); private static final String TAG = "WireGuard/" + QuickTileService.class.getSimpleName();
private final OnStateChangedCallback onStateChangedCallback = new OnStateChangedCallback(); private final OnStateChangedCallback onStateChangedCallback = new OnStateChangedCallback();
private final OnTunnelChangedCallback onTunnelChangedCallback = new OnTunnelChangedCallback(); private final OnTunnelChangedCallback onTunnelChangedCallback = new OnTunnelChangedCallback();
private Tunnel tunnel; private Tunnel tunnel;
@ -62,7 +63,8 @@ public class QuickTileService extends TileService {
tunnelManager.removeOnPropertyChangedCallback(onTunnelChangedCallback); tunnelManager.removeOnPropertyChangedCallback(onTunnelChangedCallback);
} }
private void onToggleFinished(final State state, final Throwable throwable) { private void onToggleFinished(@SuppressWarnings("unused") final State state,
final Throwable throwable) {
if (throwable == null) if (throwable == null)
return; return;
final String error = ExceptionLoggers.unwrap(throwable).getMessage(); final String error = ExceptionLoggers.unwrap(throwable).getMessage();

View File

@ -6,11 +6,12 @@ import com.wireguard.android.fragment.TunnelEditorFragment;
import com.wireguard.android.model.Tunnel; import com.wireguard.android.model.Tunnel;
/** /**
* Created by samuel on 12/29/17. * Standalone activity for creating tunnels.
*/ */
public class TunnelCreatorActivity extends BaseActivity { public class TunnelCreatorActivity extends BaseActivity {
@Override @Override
@SuppressWarnings("UnnecessaryFullyQualifiedName")
protected void onCreate(final Bundle savedInstanceState) { protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
if (getFragmentManager().findFragmentById(android.R.id.content) == null) { if (getFragmentManager().findFragmentById(android.R.id.content) == null) {

View File

@ -28,7 +28,7 @@ public interface Backend {
* *
* @return The set of running tunnel names. * @return The set of running tunnel names.
*/ */
Set<String> enumerate() throws Exception; Set<String> enumerate();
/** /**
* Get the actual state of a tunnel. * Get the actual state of a tunnel.

View File

@ -31,7 +31,7 @@ public interface ConfigStore {
* *
* @return The set of present tunnel names. * @return The set of present tunnel names.
*/ */
Set<String> enumerate() throws Exception; Set<String> enumerate();
/** /**
* Load the configuration for the tunnel given by {@code name}. * Load the configuration for the tunnel given by {@code name}.

View File

@ -59,7 +59,8 @@ public class TunnelEditorFragment extends BaseFragment {
binding.setConfig(localConfig); binding.setConfig(localConfig);
} }
private void onConfigSaved(final Config config, final Throwable throwable) { private void onConfigSaved(@SuppressWarnings("unused") final Config config,
final Throwable throwable) {
final String message; final String message;
if (throwable == null) { if (throwable == null) {
message = getString(R.string.config_save_success, localTunnel.getName()); message = getString(R.string.config_save_success, localTunnel.getName());

View File

@ -15,8 +15,10 @@ import com.wireguard.android.util.AsyncWorker;
import com.wireguard.android.util.ExceptionLoggers; import com.wireguard.android.util.ExceptionLoggers;
import com.wireguard.android.util.ObservableKeyedList; import com.wireguard.android.util.ObservableKeyedList;
import com.wireguard.android.util.ObservableSortedKeyedArrayList; import com.wireguard.android.util.ObservableSortedKeyedArrayList;
import com.wireguard.android.util.ObservableSortedKeyedList;
import com.wireguard.config.Config; import com.wireguard.config.Config;
import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.Set; import java.util.Set;
@ -39,13 +41,12 @@ public final class TunnelManager extends BaseObservable {
private static final String KEY_LAST_USED_TUNNEL = "last_used_tunnel"; private static final String KEY_LAST_USED_TUNNEL = "last_used_tunnel";
private static final String KEY_RESTORE_ON_BOOT = "restore_on_boot"; private static final String KEY_RESTORE_ON_BOOT = "restore_on_boot";
private static final String KEY_RUNNING_TUNNELS = "enabled_configs"; private static final String KEY_RUNNING_TUNNELS = "enabled_configs";
private static final String TAG = "WireGuard/" + TunnelManager.class.getSimpleName();
private final AsyncWorker asyncWorker; private final AsyncWorker asyncWorker;
private final Backend backend; private final Backend backend;
private final ConfigStore configStore; private final ConfigStore configStore;
private final SharedPreferences preferences; private final SharedPreferences preferences;
private final ObservableKeyedList<String, Tunnel> tunnels = private final ObservableSortedKeyedList<String, Tunnel> tunnels =
new ObservableSortedKeyedArrayList<>(COMPARATOR); new ObservableSortedKeyedArrayList<>(COMPARATOR);
private Tunnel lastUsedTunnel; private Tunnel lastUsedTunnel;
@ -139,7 +140,7 @@ public final class TunnelManager extends BaseObservable {
.whenComplete(ExceptionLoggers.E); .whenComplete(ExceptionLoggers.E);
} }
private void onTunnelsLoaded(final Set<String> present, final Set<String> running) { private void onTunnelsLoaded(final Iterable<String> present, final Collection<String> running) {
for (final String name : present) for (final String name : present)
addToList(name, null, running.contains(name) ? State.UP : State.DOWN); addToList(name, null, running.contains(name) ? State.UP : State.DOWN);
final String lastUsedName = preferences.getString(KEY_LAST_USED_TUNNEL, null); final String lastUsedName = preferences.getString(KEY_LAST_USED_TUNNEL, null);

View File

@ -2,6 +2,7 @@ package com.wireguard.android.preference;
import android.content.Context; import android.content.Context;
import android.preference.Preference; import android.preference.Preference;
import android.support.annotation.NonNull;
import android.system.OsConstants; import android.system.OsConstants;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -21,6 +22,7 @@ public class ToolsInstallerPreference extends Preference {
private final ToolsInstaller toolsInstaller; private final ToolsInstaller toolsInstaller;
private State state = State.INITIAL; private State state = State.INITIAL;
@SuppressWarnings({"SameParameterValue", "WeakerAccess"})
public ToolsInstallerPreference(final Context context, final AttributeSet attrs) { public ToolsInstallerPreference(final Context context, final AttributeSet attrs) {
super(context, attrs); super(context, attrs);
final ApplicationComponent applicationComponent = Application.getComponent(); final ApplicationComponent applicationComponent = Application.getComponent();
@ -64,7 +66,7 @@ public class ToolsInstallerPreference extends Preference {
.thenAccept(this::setState); .thenAccept(this::setState);
} }
private void setState(final State state) { private void setState(@NonNull final State state) {
if (this.state == state) if (this.state == state)
return; return;
this.state = state; this.state = state;

View File

@ -9,7 +9,7 @@ import android.widget.TextView;
import com.commonsware.cwac.crossport.design.widget.Snackbar; import com.commonsware.cwac.crossport.design.widget.Snackbar;
/** /**
* Created by samuel on 12/30/17. * Standalone utilities for interacting with the system clipboard.
*/ */
public final class ClipboardUtils { public final class ClipboardUtils {

View File

@ -23,6 +23,7 @@ public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>>
private final Comparator<? super K> comparator; private final Comparator<? super K> comparator;
private final transient KeyList<K, E> keyList = new KeyList<>(this); private final transient KeyList<K, E> keyList = new KeyList<>(this);
@SuppressWarnings("WeakerAccess")
public ObservableSortedKeyedArrayList() { public ObservableSortedKeyedArrayList() {
comparator = null; comparator = null;
} }
@ -178,6 +179,7 @@ public class ObservableSortedKeyedArrayList<K, E extends Keyed<? extends K>>
} }
@Override @Override
@SuppressWarnings("EmptyMethod")
public Spliterator<K> spliterator() { public Spliterator<K> spliterator() {
return super.spliterator(); return super.spliterator();
} }

View File

@ -9,14 +9,14 @@ import com.wireguard.android.Application.ApplicationContext;
import com.wireguard.android.Application.ApplicationScope; import com.wireguard.android.Application.ApplicationScope;
import com.wireguard.android.R; import com.wireguard.android.R;
import java.io.BufferedWriter;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.OutputStreamWriter; import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.Collection;
import java.util.UUID; import java.util.UUID;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -38,11 +38,10 @@ public class RootShell {
private final String exceptionMessage; private final String exceptionMessage;
private final String preamble; private final String preamble;
private Process process;
private BufferedReader stderr;
private BufferedWriter stdin; private BufferedWriter stdin;
private BufferedReader stdout; private BufferedReader stdout;
private BufferedReader stderr;
private Process process;
@Inject @Inject
public RootShell(@ApplicationContext final Context context) { public RootShell(@ApplicationContext final Context context) {
@ -141,7 +140,7 @@ public class RootShell {
* @param command Command to run as root. * @param command Command to run as root.
* @return The exit value of the last command run, or -1 if there was an internal error. * @return The exit value of the last command run, or -1 if there was an internal error.
*/ */
public int run(final List<String> output, final String command) public int run(final Collection<String> output, final String command)
throws ErrnoException, IOException, NoRootException { throws ErrnoException, IOException, NoRootException {
ensureRoot(); ensureRoot();

View File

@ -11,7 +11,11 @@ import com.wireguard.crypto.KeyEncoding;
*/ */
public class KeyInputFilter implements InputFilter { public class KeyInputFilter implements InputFilter {
public static KeyInputFilter newInstance() { private static boolean isAllowed(final char c) {
return Character.isLetterOrDigit(c) || c == '+' || c == '/';
}
public static InputFilter newInstance() {
return new KeyInputFilter(); return new KeyInputFilter();
} }
@ -40,8 +44,4 @@ public class KeyInputFilter implements InputFilter {
} }
return replacement; return replacement;
} }
private boolean isAllowed(final char c) {
return Character.isLetterOrDigit(c) || c == '+' || c == '/';
}
} }

View File

@ -11,7 +11,11 @@ import com.wireguard.android.model.Tunnel;
*/ */
public class NameInputFilter implements InputFilter { public class NameInputFilter implements InputFilter {
public static NameInputFilter newInstance() { private static boolean isAllowed(final char c) {
return Character.isLetterOrDigit(c) || "_=+.-".indexOf(c) >= 0;
}
public static InputFilter newInstance() {
return new NameInputFilter(); return new NameInputFilter();
} }
@ -39,8 +43,4 @@ public class NameInputFilter implements InputFilter {
} }
return replacement; return replacement;
} }
private boolean isAllowed(final char c) {
return Character.isLetterOrDigit(c) || "_=+.-".indexOf(c) >= 0;
}
} }

View File

@ -25,6 +25,7 @@ public class ToggleSwitch extends Switch {
private boolean isRestoringState; private boolean isRestoringState;
private OnBeforeCheckedChangeListener listener; private OnBeforeCheckedChangeListener listener;
@SuppressWarnings({"SameParameterValue", "WeakerAccess"})
public ToggleSwitch(final Context context, final AttributeSet attrs) { public ToggleSwitch(final Context context, final AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} }

View File

@ -6,12 +6,17 @@ package com.wireguard.crypto;
* This is a specialized constant-time base64 implementation that resists side-channel attacks. * This is a specialized constant-time base64 implementation that resists side-channel attacks.
*/ */
public class KeyEncoding { @SuppressWarnings("MagicNumber")
public final class KeyEncoding {
public static final int KEY_LENGTH = 32; public static final int KEY_LENGTH = 32;
public static final int KEY_LENGTH_BASE64 = 44; public static final int KEY_LENGTH_BASE64 = 44;
private static final String KEY_LENGTH_BASE64_EXCEPTION_MESSAGE = private static final String KEY_LENGTH_BASE64_EXCEPTION_MESSAGE =
"WireGuard base64 keys must be 44 characters encoding 32 bytes"; "WireGuard base64 keys must be 44 characters encoding 32 bytes";
private KeyEncoding() {
// Prevent instantiation.
}
private static int decodeBase64(final char[] src, final int src_offset) { private static int decodeBase64(final char[] src, final int src_offset) {
int val = 0; int val = 0;
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {

View File

@ -6,6 +6,7 @@ import java.security.SecureRandom;
* Represents a Curve25519 keypair as used by WireGuard. * Represents a Curve25519 keypair as used by WireGuard.
*/ */
@SuppressWarnings("MagicNumber")
public class Keypair { public class Keypair {
private final byte[] privateKey; private final byte[] privateKey;
private final byte[] publicKey; private final byte[] publicKey;

View File

@ -1,9 +0,0 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportHeight="24"
android:viewportWidth="24">
<path
android:fillColor="#FFFFFF"
android:pathData="M19,13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
</vector>

View File

@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/master_fragment" android:id="@+id/master_fragment"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" /> android:layout_height="match_parent"
tools:ignore="MergeRootFrame" />