global: Clean up error logging
Signed-off-by: Samuel Holland <samuel@sholland.org>
This commit is contained in:
parent
a1d955ef62
commit
daacc06a0d
@ -18,10 +18,10 @@ public class BootShutdownReceiver extends BroadcastReceiver {
|
|||||||
return;
|
return;
|
||||||
final TunnelManager tunnelManager = Application.getComponent().getTunnelManager();
|
final TunnelManager tunnelManager = Application.getComponent().getTunnelManager();
|
||||||
if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
|
if (Intent.ACTION_BOOT_COMPLETED.equals(action)) {
|
||||||
Log.d(TAG, "Broadcast receiver restoring state (boot)");
|
Log.i(TAG, "Broadcast receiver restoring state (boot)");
|
||||||
tunnelManager.restoreState().whenComplete(ExceptionLoggers.D);
|
tunnelManager.restoreState().whenComplete(ExceptionLoggers.D);
|
||||||
} else if (Intent.ACTION_SHUTDOWN.equals(action)) {
|
} else if (Intent.ACTION_SHUTDOWN.equals(action)) {
|
||||||
Log.d(TAG, "Broadcast receiver saving state (shutdown)");
|
Log.i(TAG, "Broadcast receiver saving state (shutdown)");
|
||||||
tunnelManager.saveState();
|
tunnelManager.saveState();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,6 @@ public final class WgQuickBackend implements Backend {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public State getState(final Tunnel tunnel) {
|
public State getState(final Tunnel tunnel) {
|
||||||
Log.v(TAG, "Requested state for tunnel " + tunnel.getName());
|
|
||||||
return enumerate().contains(tunnel.getName()) ? State.UP : State.DOWN;
|
return enumerate().contains(tunnel.getName()) ? State.UP : State.DOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,12 +74,12 @@ public final class WgQuickBackend implements Backend {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public State setState(final Tunnel tunnel, State state) throws Exception {
|
public State setState(final Tunnel tunnel, State state) throws Exception {
|
||||||
Log.v(TAG, "Requested state change to " + state + " for tunnel " + tunnel.getName());
|
|
||||||
final State originalState = getState(tunnel);
|
final State originalState = getState(tunnel);
|
||||||
if (state == State.TOGGLE)
|
if (state == State.TOGGLE)
|
||||||
state = originalState == State.UP ? State.DOWN : State.UP;
|
state = originalState == State.UP ? State.DOWN : State.UP;
|
||||||
if (state == originalState)
|
if (state == originalState)
|
||||||
return originalState;
|
return originalState;
|
||||||
|
Log.d(TAG, "Changing tunnel " + tunnel.getName() + " to state " + state);
|
||||||
toolsInstaller.ensureToolsAvailable();
|
toolsInstaller.ensureToolsAvailable();
|
||||||
final int result;
|
final int result;
|
||||||
if (state == State.UP) {
|
if (state == State.UP) {
|
||||||
|
@ -8,6 +8,7 @@ import com.wireguard.config.Config;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@ -31,6 +32,7 @@ public final class FileConfigStore implements ConfigStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Config create(final String name, final Config config) throws IOException {
|
public Config create(final String name, final Config config) throws IOException {
|
||||||
|
Log.d(TAG, "Creating configuration for tunnel " + name);
|
||||||
final File file = fileFor(name);
|
final File file = fileFor(name);
|
||||||
if (!file.createNewFile()) {
|
if (!file.createNewFile()) {
|
||||||
final String message = "Configuration file " + file.getName() + " already exists";
|
final String message = "Configuration file " + file.getName() + " already exists";
|
||||||
@ -44,6 +46,7 @@ public final class FileConfigStore implements ConfigStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void delete(final String name) throws IOException {
|
public void delete(final String name) throws IOException {
|
||||||
|
Log.d(TAG, "Deleting configuration for tunnel " + name);
|
||||||
final File file = fileFor(name);
|
final File file = fileFor(name);
|
||||||
if (!file.delete())
|
if (!file.delete())
|
||||||
throw new IOException("Cannot delete configuration file " + file.getName());
|
throw new IOException("Cannot delete configuration file " + file.getName());
|
||||||
@ -70,11 +73,11 @@ public final class FileConfigStore implements ConfigStore {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Config save(final String name, final Config config) throws IOException {
|
public Config save(final String name, final Config config) throws IOException {
|
||||||
Log.d(TAG, "Requested save config for tunnel " + name);
|
Log.d(TAG, "Saving configuration for tunnel " + name);
|
||||||
final File file = fileFor(name);
|
final File file = fileFor(name);
|
||||||
if (!file.isFile()) {
|
if (!file.isFile()) {
|
||||||
final String message = "Configuration file " + file.getName() + " not found";
|
final String message = "Configuration file " + file.getName() + " not found";
|
||||||
throw new IllegalStateException(message);
|
throw new FileNotFoundException(message);
|
||||||
}
|
}
|
||||||
try (FileOutputStream stream = new FileOutputStream(file, false)) {
|
try (FileOutputStream stream = new FileOutputStream(file, false)) {
|
||||||
stream.write(config.toString().getBytes(StandardCharsets.UTF_8));
|
stream.write(config.toString().getBytes(StandardCharsets.UTF_8));
|
||||||
|
@ -41,7 +41,7 @@ public final class TunnelController {
|
|||||||
else
|
else
|
||||||
tunnel = null;
|
tunnel = null;
|
||||||
if (tunnel == null) {
|
if (tunnel == null) {
|
||||||
Log.e(TAG, "setChecked() from a null tunnel", new IllegalStateException());
|
Log.e(TAG, "setChecked() from a null tunnel", new IllegalStateException("No tunnel"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tunnel.setState(State.of(checked)).whenComplete((state, throwable) -> {
|
tunnel.setState(State.of(checked)).whenComplete((state, throwable) -> {
|
||||||
@ -51,15 +51,16 @@ public final class TunnelController {
|
|||||||
if (throwable instanceof ErrnoException
|
if (throwable instanceof ErrnoException
|
||||||
&& ((ErrnoException) throwable).errno == OsConstants.ENODEV) {
|
&& ((ErrnoException) throwable).errno == OsConstants.ENODEV) {
|
||||||
final String message = context.getString(R.string.not_supported_message);
|
final String message = context.getString(R.string.not_supported_message);
|
||||||
|
final String title = context.getString(R.string.not_supported_title);
|
||||||
final AlertDialog dialog = new AlertDialog.Builder(context)
|
final AlertDialog dialog = new AlertDialog.Builder(context)
|
||||||
.setMessage(Html.fromHtml(message))
|
.setMessage(Html.fromHtml(message))
|
||||||
.setPositiveButton(R.string.ok, null)
|
.setPositiveButton(R.string.ok, null)
|
||||||
.setTitle(R.string.not_supported_title)
|
.setTitle(title)
|
||||||
.show();
|
.show();
|
||||||
// Make links work.
|
// Make links work.
|
||||||
((TextView) dialog.findViewById(android.R.id.message))
|
((TextView) dialog.findViewById(android.R.id.message))
|
||||||
.setMovementMethod(LinkMovementMethod.getInstance());
|
.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
Log.e(TAG, "WireGuard not supported");
|
Log.e(TAG, title, throwable);
|
||||||
} else {
|
} else {
|
||||||
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
|
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
|
||||||
final int messageResId = checked ? R.string.error_up : R.string.error_down;
|
final int messageResId = checked ? R.string.error_up : R.string.error_down;
|
||||||
|
@ -93,7 +93,7 @@ public final class ToolsInstaller {
|
|||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
if (areToolsAvailable == null) {
|
if (areToolsAvailable == null) {
|
||||||
if (areInstalled() == OsConstants.EALREADY) {
|
if (areInstalled() == OsConstants.EALREADY) {
|
||||||
Log.d(TAG, "Tools are installed to /system");
|
Log.d(TAG, "Tools are installed to the system partition");
|
||||||
areToolsAvailable = true;
|
areToolsAvailable = true;
|
||||||
} else if (areSymlinked() == OsConstants.EALREADY) {
|
} else if (areSymlinked() == OsConstants.EALREADY) {
|
||||||
Log.d(TAG, "Tools were already symlinked into our private binary dir");
|
Log.d(TAG, "Tools were already symlinked into our private binary dir");
|
||||||
|
Loading…
Reference in New Issue
Block a user