Quick cleanup across the board
- Clean up imports - Adjust method visibility - Drop in NonNull annotations where needed - Prevent potential NPEs from nulled getActivity calls - Remove unused methods Signed-off-by: Harsh Shandilya <me@msfjarvis.dev>
This commit is contained in:
parent
592c5cbbd6
commit
ba862b166b
@ -5,22 +5,18 @@ import android.content.Intent;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.support.v4.util.ArraySet;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.wireguard.android.Application;
|
||||
import com.wireguard.android.model.Tunnel;
|
||||
import com.wireguard.android.model.Tunnel.State;
|
||||
import com.wireguard.android.model.Tunnel.Statistics;
|
||||
import com.wireguard.android.model.TunnelManager;
|
||||
import com.wireguard.config.Config;
|
||||
import com.wireguard.config.IPCidr;
|
||||
import com.wireguard.config.Interface;
|
||||
import com.wireguard.config.Peer;
|
||||
import com.wireguard.crypto.KeyEncoding;
|
||||
|
||||
import java.net.Inet4Address;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.Formatter;
|
||||
import java.util.Set;
|
||||
@ -45,7 +41,7 @@ public final class GoBackend implements Backend {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public void startVpnService() {
|
||||
private void startVpnService() {
|
||||
context.startService(new Intent(context, VpnService.class));
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.wireguard.android.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
@ -33,7 +34,7 @@ public class TunnelDetailFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
|
||||
final Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
binding = TunnelDetailFragmentBinding.inflate(inflater, container, false);
|
||||
|
@ -5,6 +5,7 @@ import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@ -101,7 +102,7 @@ public class TunnelEditorFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
|
||||
final Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
binding = TunnelEditorFragmentBinding.inflate(inflater, container, false);
|
||||
@ -118,6 +119,7 @@ public class TunnelEditorFragment extends BaseFragment {
|
||||
private void onFinished() {
|
||||
// Hide the keyboard; it rarely goes away on its own.
|
||||
final Activity activity = getActivity();
|
||||
if (activity == null) return;
|
||||
final View focusedView = activity.getCurrentFocus();
|
||||
if (focusedView != null) {
|
||||
final Object service = activity.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
@ -174,7 +176,7 @@ public class TunnelEditorFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(final Bundle outState) {
|
||||
public void onSaveInstanceState(@NonNull final Bundle outState) {
|
||||
outState.putParcelable(KEY_LOCAL_CONFIG, localConfig);
|
||||
outState.putString(KEY_ORIGINAL_NAME, originalName);
|
||||
super.onSaveInstanceState(outState);
|
||||
|
@ -9,6 +9,7 @@ import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.provider.OpenableColumns;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.ActionMode;
|
||||
@ -110,7 +111,7 @@ public class TunnelListFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
|
||||
public View onCreateView(@NonNull final LayoutInflater inflater, final ViewGroup container,
|
||||
final Bundle savedInstanceState) {
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
binding = TunnelListFragmentBinding.inflate(inflater, container, false);
|
||||
@ -220,6 +221,7 @@ public class TunnelListFragment extends BaseFragment {
|
||||
@Override
|
||||
public boolean onCreateActionMode(final ActionMode mode, final Menu menu) {
|
||||
actionMode = mode;
|
||||
if (getActivity() != null)
|
||||
resources = getActivity().getResources();
|
||||
tunnelList = binding.tunnelList;
|
||||
mode.getMenuInflater().inflate(R.menu.tunnel_list_action_mode, menu);
|
||||
|
@ -37,8 +37,8 @@ public class Tunnel extends BaseObservable implements Keyed<String> {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public static boolean isNameValid(@NonNull final CharSequence name) {
|
||||
return NAME_PATTERN.matcher(name).matches();
|
||||
public static boolean isNameInvalid(@NonNull final CharSequence name) {
|
||||
return !NAME_PATTERN.matcher(name).matches();
|
||||
}
|
||||
|
||||
public CompletionStage<Void> delete() {
|
||||
|
@ -66,7 +66,7 @@ public final class TunnelManager extends BaseObservable {
|
||||
}
|
||||
|
||||
public CompletionStage<Tunnel> create(@NonNull final String name, final Config config) {
|
||||
if (!Tunnel.isNameValid(name))
|
||||
if (Tunnel.isNameInvalid(name))
|
||||
return CompletableFuture.failedFuture(new IllegalArgumentException("Invalid name"));
|
||||
if (tunnels.containsKey(name)) {
|
||||
final String message = "Tunnel " + name + " already exists";
|
||||
@ -190,7 +190,7 @@ public final class TunnelManager extends BaseObservable {
|
||||
}
|
||||
|
||||
CompletionStage<String> setTunnelName(final Tunnel tunnel, final String name) {
|
||||
if (!Tunnel.isNameValid(name))
|
||||
if (Tunnel.isNameInvalid(name))
|
||||
return CompletableFuture.failedFuture(new IllegalArgumentException("Invalid name"));
|
||||
if (tunnels.containsKey(name)) {
|
||||
final String message = "Tunnel " + name + " already exists";
|
||||
|
@ -30,10 +30,6 @@ public class ToolsInstallerPreference extends Preference {
|
||||
toolsInstaller = applicationComponent.getToolsInstaller();
|
||||
}
|
||||
|
||||
public ToolsInstallerPreference(final Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return getContext().getString(state.messageResourceId);
|
||||
|
@ -22,7 +22,7 @@ public class AsyncWorker {
|
||||
private final Handler handler;
|
||||
|
||||
@Inject
|
||||
public AsyncWorker(final Executor executor, @ApplicationHandler final Handler handler) {
|
||||
AsyncWorker(final Executor executor, @ApplicationHandler final Handler handler) {
|
||||
this.executor = executor;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user