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;
|
||||
final TunnelManager tunnelManager = Application.getComponent().getTunnelManager();
|
||||
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);
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,6 @@ public final class WgQuickBackend implements Backend {
|
||||
|
||||
@Override
|
||||
public State getState(final Tunnel tunnel) {
|
||||
Log.v(TAG, "Requested state for tunnel " + tunnel.getName());
|
||||
return enumerate().contains(tunnel.getName()) ? State.UP : State.DOWN;
|
||||
}
|
||||
|
||||
@ -75,12 +74,12 @@ public final class WgQuickBackend implements Backend {
|
||||
|
||||
@Override
|
||||
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);
|
||||
if (state == State.TOGGLE)
|
||||
state = originalState == State.UP ? State.DOWN : State.UP;
|
||||
if (state == originalState)
|
||||
return originalState;
|
||||
Log.d(TAG, "Changing tunnel " + tunnel.getName() + " to state " + state);
|
||||
toolsInstaller.ensureToolsAvailable();
|
||||
final int result;
|
||||
if (state == State.UP) {
|
||||
|
@ -8,6 +8,7 @@ import com.wireguard.config.Config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@ -31,6 +32,7 @@ public final class FileConfigStore implements ConfigStore {
|
||||
|
||||
@Override
|
||||
public Config create(final String name, final Config config) throws IOException {
|
||||
Log.d(TAG, "Creating configuration for tunnel " + name);
|
||||
final File file = fileFor(name);
|
||||
if (!file.createNewFile()) {
|
||||
final String message = "Configuration file " + file.getName() + " already exists";
|
||||
@ -44,6 +46,7 @@ public final class FileConfigStore implements ConfigStore {
|
||||
|
||||
@Override
|
||||
public void delete(final String name) throws IOException {
|
||||
Log.d(TAG, "Deleting configuration for tunnel " + name);
|
||||
final File file = fileFor(name);
|
||||
if (!file.delete())
|
||||
throw new IOException("Cannot delete configuration file " + file.getName());
|
||||
@ -70,11 +73,11 @@ public final class FileConfigStore implements ConfigStore {
|
||||
|
||||
@Override
|
||||
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);
|
||||
if (!file.isFile()) {
|
||||
final String message = "Configuration file " + file.getName() + " not found";
|
||||
throw new IllegalStateException(message);
|
||||
throw new FileNotFoundException(message);
|
||||
}
|
||||
try (FileOutputStream stream = new FileOutputStream(file, false)) {
|
||||
stream.write(config.toString().getBytes(StandardCharsets.UTF_8));
|
||||
|
@ -41,7 +41,7 @@ public final class TunnelController {
|
||||
else
|
||||
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;
|
||||
}
|
||||
tunnel.setState(State.of(checked)).whenComplete((state, throwable) -> {
|
||||
@ -51,15 +51,16 @@ public final class TunnelController {
|
||||
if (throwable instanceof ErrnoException
|
||||
&& ((ErrnoException) throwable).errno == OsConstants.ENODEV) {
|
||||
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)
|
||||
.setMessage(Html.fromHtml(message))
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setTitle(R.string.not_supported_title)
|
||||
.setTitle(title)
|
||||
.show();
|
||||
// Make links work.
|
||||
((TextView) dialog.findViewById(android.R.id.message))
|
||||
.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
Log.e(TAG, "WireGuard not supported");
|
||||
Log.e(TAG, title, throwable);
|
||||
} else {
|
||||
final String error = ExceptionLoggers.unwrap(throwable).getMessage();
|
||||
final int messageResId = checked ? R.string.error_up : R.string.error_down;
|
||||
|
@ -93,7 +93,7 @@ public final class ToolsInstaller {
|
||||
synchronized (this) {
|
||||
if (areToolsAvailable == null) {
|
||||
if (areInstalled() == OsConstants.EALREADY) {
|
||||
Log.d(TAG, "Tools are installed to /system");
|
||||
Log.d(TAG, "Tools are installed to the system partition");
|
||||
areToolsAvailable = true;
|
||||
} else if (areSymlinked() == OsConstants.EALREADY) {
|
||||
Log.d(TAG, "Tools were already symlinked into our private binary dir");
|
||||
|
Loading…
Reference in New Issue
Block a user