Removed unnecessary conditionals from logging statements.

Very important stuff.
This commit is contained in:
akwizgran
2014-03-12 21:00:14 +00:00
parent 375a597dd2
commit b99a503f24
33 changed files with 165 additions and 240 deletions

View File

@@ -2,7 +2,6 @@ package org.briarproject.android;
import static android.content.Intent.FLAG_ACTIVITY_NO_ANIMATION;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static java.util.logging.Level.INFO;
import java.util.concurrent.Executor;
import java.util.logging.Logger;
@@ -88,12 +87,11 @@ public class BriarActivity extends RoboFragmentActivity {
BriarService service = ((BriarBinder) binder).getService();
service.waitForStartup();
// Shut down the service and wait for it to shut down
if(LOG.isLoggable(INFO)) LOG.info("Shutting down service");
LOG.info("Shutting down service");
service.shutdown();
service.waitForShutdown();
} catch(InterruptedException e) {
if(LOG.isLoggable(INFO))
LOG.info("Interrupted while waiting for service");
LOG.warning("Interrupted while waiting for service");
}
finishAndExit();
}
@@ -104,7 +102,7 @@ public class BriarActivity extends RoboFragmentActivity {
runOnUiThread(new Runnable() {
public void run() {
finish();
if(LOG.isLoggable(INFO)) LOG.info("Exiting");
LOG.info("Exiting");
System.exit(0);
}
});
@@ -117,8 +115,7 @@ public class BriarActivity extends RoboFragmentActivity {
lifecycleManager.waitForDatabase();
task.run();
} catch(InterruptedException e) {
if(LOG.isLoggable(INFO))
LOG.info("Interrupted while waiting for database");
LOG.warning("Interrupted while waiting for database");
Thread.currentThread().interrupt();
}
}

View File

@@ -3,7 +3,6 @@ package org.briarproject.android;
import static android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static android.content.Intent.FLAG_ACTIVITY_SINGLE_TOP;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import java.util.concurrent.CountDownLatch;
@@ -61,14 +60,14 @@ public class BriarService extends RoboService implements EventListener {
@Override
public void onCreate() {
super.onCreate();
if(LOG.isLoggable(INFO)) LOG.info("Created");
LOG.info("Created");
if(created.getAndSet(true)) {
if(LOG.isLoggable(INFO)) LOG.info("Already created");
LOG.info("Already created");
stopSelf();
return;
}
if(databaseConfig.getEncryptionKey() == null) {
if(LOG.isLoggable(INFO)) LOG.info("No database key");
LOG.info("No database key");
stopSelf();
return;
}
@@ -92,7 +91,7 @@ public class BriarService extends RoboService implements EventListener {
db.addListener(BriarService.this);
started = true;
} else {
if(LOG.isLoggable(INFO)) LOG.info("Startup failed");
LOG.info("Startup failed");
showStartupFailureNotification();
stopSelf();
}
@@ -130,7 +129,7 @@ public class BriarService extends RoboService implements EventListener {
@Override
public void onDestroy() {
super.onDestroy();
if(LOG.isLoggable(INFO)) LOG.info("Destroyed");
LOG.info("Destroyed");
stopForeground(true);
notificationManager.clearNotifications();
// Stop the services in a background thread
@@ -167,8 +166,7 @@ public class BriarService extends RoboService implements EventListener {
if(LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
} catch(InterruptedException e) {
if(LOG.isLoggable(INFO))
LOG.info("Interruped while waiting for database");
LOG.info("Interruped while waiting for database");
Thread.currentThread().interrupt();
}
}

View File

@@ -61,7 +61,7 @@ public class DashboardActivity extends BriarActivity {
long handle = i.getLongExtra("briar.LOCAL_AUTHOR_HANDLE", -1);
if(failed) {
finish();
if(LOG.isLoggable(INFO)) LOG.info("Exiting");
LOG.info("Exiting");
System.exit(0);
} else if(handle == -1) {
// The activity has been launched before

View File

@@ -64,7 +64,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
if(LOG.isLoggable(INFO))
LOG.info("Guice startup took " + duration + " ms");
if(System.currentTimeMillis() >= EXPIRY_DATE) {
if(LOG.isLoggable(INFO)) LOG.info("Expired");
LOG.info("Expired");
startActivity(new Intent(this, ExpiredActivity.class));
} else {
SharedPreferences prefs = getSharedPreferences("db", MODE_PRIVATE);

View File

@@ -233,15 +233,15 @@ ConnectionListener {
loadContacts();
} else if(e instanceof ContactRemovedEvent) {
// Reload the conversation, expecting NoSuchContactException
if(LOG.isLoggable(INFO)) LOG.info("Contact removed, reloading");
LOG.info("Contact removed, reloading");
reloadContact(((ContactRemovedEvent) e).getContactId());
} else if(e instanceof MessageAddedEvent) {
if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
LOG.info("Message added, reloading");
ContactId source = ((MessageAddedEvent) e).getContactId();
if(source == null) loadContacts();
else reloadContact(source);
} else if(e instanceof MessageExpiredEvent) {
if(LOG.isLoggable(INFO)) LOG.info("Message expired, reloading");
LOG.info("Message expired, reloading");
loadContacts();
}
}

View File

@@ -369,17 +369,17 @@ implements EventListener, OnClickListener, OnItemClickListener {
if(e instanceof ContactRemovedEvent) {
ContactRemovedEvent c = (ContactRemovedEvent) e;
if(c.getContactId().equals(contactId)) {
if(LOG.isLoggable(INFO)) LOG.info("Contact removed");
LOG.info("Contact removed");
finishOnUiThread();
}
} else if(e instanceof MessageAddedEvent) {
GroupId g = ((MessageAddedEvent) e).getGroup().getId();
if(g.equals(groupId)) {
if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
LOG.info("Message added, reloading");
loadHeaders();
}
} else if(e instanceof MessageExpiredEvent) {
if(LOG.isLoggable(INFO)) LOG.info("Message expired, reloading");
LOG.info("Message expired, reloading");
loadHeaders();
}
}

View File

@@ -299,16 +299,16 @@ OnClickListener, OnItemClickListener {
public void eventOccurred(Event e) {
if(e instanceof MessageAddedEvent) {
if(((MessageAddedEvent) e).getGroup().getId().equals(groupId)) {
if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
LOG.info("Message added, reloading");
loadHeaders();
}
} else if(e instanceof MessageExpiredEvent) {
if(LOG.isLoggable(INFO)) LOG.info("Message expired, reloading");
LOG.info("Message expired, reloading");
loadHeaders();
} else if(e instanceof SubscriptionRemovedEvent) {
SubscriptionRemovedEvent s = (SubscriptionRemovedEvent) e;
if(s.getGroup().getId().equals(groupId)) {
if(LOG.isLoggable(INFO)) LOG.info("Subscription removed");
LOG.info("Subscription removed");
finishOnUiThread();
}
}

View File

@@ -262,24 +262,23 @@ implements EventListener, OnClickListener, OnItemClickListener {
if(e instanceof MessageAddedEvent) {
Group g = ((MessageAddedEvent) e).getGroup();
if(groups.containsKey(g.getId())) {
if(LOG.isLoggable(INFO)) LOG.info("Message added, reloading");
LOG.info("Message added, reloading");
loadHeaders(g);
}
} else if(e instanceof MessageExpiredEvent) {
if(LOG.isLoggable(INFO)) LOG.info("Message expired, reloading");
LOG.info("Message expired, reloading");
loadHeaders();
} else if(e instanceof RemoteSubscriptionsUpdatedEvent) {
if(LOG.isLoggable(INFO))
LOG.info("Remote subscriptions changed, reloading");
LOG.info("Remote subscriptions changed, reloading");
loadAvailable();
} else if(e instanceof SubscriptionAddedEvent) {
if(LOG.isLoggable(INFO)) LOG.info("Group added, reloading");
LOG.info("Group added, reloading");
loadHeaders();
} else if(e instanceof SubscriptionRemovedEvent) {
Group g = ((SubscriptionRemovedEvent) e).getGroup();
if(groups.containsKey(g.getId())) {
// Reload the group, expecting NoSuchSubscriptionException
if(LOG.isLoggable(INFO)) LOG.info("Group removed, reloading");
LOG.info("Group removed, reloading");
loadHeaders(g);
}
}

View File

@@ -116,14 +116,13 @@ implements EventListener, OnItemClickListener {
public void eventOccurred(Event e) {
if(e instanceof RemoteSubscriptionsUpdatedEvent) {
if(LOG.isLoggable(INFO))
LOG.info("Remote subscriptions changed, reloading");
LOG.info("Remote subscriptions changed, reloading");
loadGroups();
} else if(e instanceof SubscriptionAddedEvent) {
if(LOG.isLoggable(INFO)) LOG.info("Group added, reloading");
LOG.info("Group added, reloading");
loadGroups();
} else if(e instanceof SubscriptionRemovedEvent) {
if(LOG.isLoggable(INFO)) LOG.info("Group removed, reloading");
LOG.info("Group removed, reloading");
loadGroups();
}
}

View File

@@ -115,7 +115,7 @@ class DroidtoothPlugin implements DuplexPlugin {
throw new IOException(e.toString());
}
if(adapter == null) {
if(LOG.isLoggable(INFO)) LOG.info("Bluetooth is not supported");
LOG.info("Bluetooth is not supported");
return false;
}
running = true;
@@ -156,12 +156,12 @@ class DroidtoothPlugin implements DuplexPlugin {
private boolean enableBluetooth() {
if(adapter.isEnabled()) return true;
if(!callback.getConfig().getBoolean("enable", true)) {
if(LOG.isLoggable(INFO)) LOG.info("Not enabling Bluetooth");
LOG.info("Not enabling Bluetooth");
return false;
}
wasDisabled = true;
// Try to enable the adapter and wait for the result
if(LOG.isLoggable(INFO)) LOG.info("Enabling Bluetooth");
LOG.info("Enabling Bluetooth");
IntentFilter filter = new IntentFilter(ACTION_STATE_CHANGED);
BluetoothStateReceiver receiver = new BluetoothStateReceiver();
appContext.registerReceiver(receiver, filter);
@@ -171,12 +171,11 @@ class DroidtoothPlugin implements DuplexPlugin {
if(LOG.isLoggable(INFO)) LOG.info("Enabled: " + enabled);
return enabled;
} else {
if(LOG.isLoggable(INFO)) LOG.info("Could not enable Bluetooth");
LOG.info("Could not enable Bluetooth");
return false;
}
} catch(InterruptedException e) {
if(LOG.isLoggable(INFO))
LOG.info("Interrupted while enabling Bluetooth");
LOG.warning("Interrupted while enabling Bluetooth");
Thread.currentThread().interrupt();
return false;
}
@@ -233,7 +232,7 @@ class DroidtoothPlugin implements DuplexPlugin {
private void disableBluetooth() {
if(!adapter.isEnabled()) return;
// Try to disable the adapter and wait for the result
if(LOG.isLoggable(INFO)) LOG.info("Disabling Bluetooth");
LOG.info("Disabling Bluetooth");
IntentFilter filter = new IntentFilter(ACTION_STATE_CHANGED);
BluetoothStateReceiver receiver = new BluetoothStateReceiver();
appContext.registerReceiver(receiver, filter);
@@ -242,12 +241,10 @@ class DroidtoothPlugin implements DuplexPlugin {
boolean enabled = receiver.waitForStateChange();
if(LOG.isLoggable(INFO)) LOG.info("Enabled: " + enabled);
} else {
if(LOG.isLoggable(INFO))
LOG.info("Could not disable Bluetooth");
LOG.info("Could not disable Bluetooth");
}
} catch(InterruptedException e) {
if(LOG.isLoggable(INFO))
LOG.info("Interrupted while disabling Bluetooth");
LOG.warning("Interrupted while disabling Bluetooth");
Thread.currentThread().interrupt();
}
}
@@ -372,8 +369,7 @@ class DroidtoothPlugin implements DuplexPlugin {
BluetoothSocket s = socketLatch.waitForReference(timeout);
if(s != null) return new DroidtoothTransportConnection(this, s);
} catch(InterruptedException e) {
if(LOG.isLoggable(INFO))
LOG.info("Interrupted while exchanging invitations");
LOG.warning("Interrupted while exchanging invitations");
Thread.currentThread().interrupt();
} finally {
// Closing the socket will terminate the listener thread
@@ -425,13 +421,12 @@ class DroidtoothPlugin implements DuplexPlugin {
long end = now + timeout;
while(now < end && running && !socketLatch.isSet()) {
// Discover nearby devices
if(LOG.isLoggable(INFO)) LOG.info("Discovering nearby devices");
LOG.info("Discovering nearby devices");
List<String> addresses;
try {
addresses = discoverDevices(end - now);
} catch(InterruptedException e) {
if(LOG.isLoggable(INFO))
LOG.info("Interrupted while discovering devices");
LOG.warning("Interrupted while discovering devices");
return;
}
// Connect to any device with the right UUID
@@ -440,11 +435,9 @@ class DroidtoothPlugin implements DuplexPlugin {
if(now < end && running && !socketLatch.isSet()) {
BluetoothSocket s = connect(address, uuid);
if(s == null) continue;
if(LOG.isLoggable(INFO))
LOG.info("Outgoing connection");
LOG.info("Outgoing connection");
if(!socketLatch.set(s)) {
if(LOG.isLoggable(INFO))
LOG.info("Closing redundant connection");
LOG.info("Closing redundant connection");
tryToClose(s);
}
return;
@@ -505,10 +498,9 @@ class DroidtoothPlugin implements DuplexPlugin {
public void run() {
try {
BluetoothSocket s = serverSocket.accept();
if(LOG.isLoggable(INFO)) LOG.info("Incoming connection");
LOG.info("Incoming connection");
if(!socketLatch.set(s)) {
if(LOG.isLoggable(INFO))
LOG.info("Closing redundant connection");
LOG.info("Closing redundant connection");
s.close();
}
} catch(IOException e) {

View File

@@ -1,7 +1,5 @@
package org.briarproject.plugins.droidtooth;
import static java.util.logging.Level.INFO;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
@@ -33,12 +31,12 @@ class InsecureBluetooth {
static BluetoothServerSocket listen(BluetoothAdapter adapter, String name,
UUID uuid) throws IOException {
if(Build.VERSION.SDK_INT >= 10) {
if(LOG.isLoggable(INFO)) LOG.info("Listening with new API");
LOG.info("Listening with new API");
return adapter.listenUsingInsecureRfcommWithServiceRecord(name,
uuid);
}
try {
if(LOG.isLoggable(INFO)) LOG.info("Listening via reflection");
LOG.info("Listening via reflection");
// Find an available channel
String className = BluetoothAdapter.class.getCanonicalName()
+ ".RfcommChannelPicker";
@@ -144,11 +142,11 @@ class InsecureBluetooth {
static BluetoothSocket createSocket(BluetoothDevice device, UUID uuid)
throws IOException {
if(Build.VERSION.SDK_INT >= 10) {
if(LOG.isLoggable(INFO)) LOG.info("Creating socket with new API");
LOG.info("Creating socket with new API");
return device.createInsecureRfcommSocketToServiceRecord(uuid);
}
try {
if(LOG.isLoggable(INFO)) LOG.info("Creating socket via reflection");
LOG.info("Creating socket via reflection");
Constructor<BluetoothSocket> constructor =
BluetoothSocket.class.getDeclaredConstructor(int.class,
int.class, boolean.class, boolean.class,

View File

@@ -122,23 +122,23 @@ class TorPlugin implements DuplexPlugin, EventHandler {
boolean startProcess = false;
try {
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
if(LOG.isLoggable(INFO)) LOG.info("Tor is already running");
LOG.info("Tor is already running");
if(readPidFile() == -1) {
controlSocket.close();
killZombieProcess();
startProcess = true;
}
} catch(IOException e) {
if(LOG.isLoggable(INFO)) LOG.info("Tor is not running");
LOG.info("Tor is not running");
startProcess = true;
}
if(startProcess) {
// Install the binary, GeoIP database and config file if necessary
if(!isInstalled() && !install()) {
if(LOG.isLoggable(INFO)) LOG.info("Could not install Tor");
LOG.info("Could not install Tor");
return false;
}
if(LOG.isLoggable(INFO)) LOG.info("Starting Tor");
LOG.info("Starting Tor");
// Watch for the auth cookie file being created/updated
cookieFile.getParentFile().mkdirs();
cookieFile.createNewFile();
@@ -172,14 +172,12 @@ class TorPlugin implements DuplexPlugin, EventHandler {
}
// Wait for the auth cookie file to be created/updated
if(!latch.await(COOKIE_TIMEOUT, MILLISECONDS)) {
if(LOG.isLoggable(WARNING))
LOG.warning("Auth cookie not created");
LOG.warning("Auth cookie not created");
listFiles(torDirectory);
return false;
}
} catch(InterruptedException e1) {
if(LOG.isLoggable(WARNING))
LOG.warning("Interrupted while starting Tor");
LOG.warning("Interrupted while starting Tor");
return false;
}
// Now we should be able to connect to the new process
@@ -236,8 +234,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
copy(in, out);
// Make the Tor binary executable
if(!setExecutable(torFile)) {
if(LOG.isLoggable(WARNING))
LOG.warning("Could not make Tor executable");
LOG.warning("Could not make Tor executable");
return false;
}
// Create a file to indicate that installation succeeded
@@ -291,8 +288,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
} catch(IOException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch(InterruptedException e) {
if(LOG.isLoggable(WARNING))
LOG.warning("Interrupted while executing chmod");
LOG.warning("Interrupted while executing chmod");
Thread.currentThread().interrupt();
} catch(SecurityException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
@@ -343,9 +339,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
try {
return Integer.parseInt(new String(read(pidFile), "UTF-8").trim());
} catch(IOException e) {
if(LOG.isLoggable(WARNING)) LOG.warning("Could not read PID file");
LOG.warning("Could not read PID file");
} catch(NumberFormatException e) {
if(LOG.isLoggable(WARNING)) LOG.warning("Could not parse PID file");
LOG.warning("Could not parse PID file");
}
return -1;
}
@@ -383,20 +379,18 @@ class TorPlugin implements DuplexPlugin, EventHandler {
found = true;
}
}
if(!found) if(LOG.isLoggable(INFO)) LOG.info("No zombies found");
if(!found) LOG.info("No zombies found");
scanner.close();
} catch(IOException e) {
if(LOG.isLoggable(WARNING))
LOG.warning("Could not parse ps output");
LOG.warning("Could not parse ps output");
} catch(SecurityException e) {
if(LOG.isLoggable(WARNING)) LOG.warning("Could not execute ps");
LOG.warning("Could not execute ps");
}
}
private void killTorProcess() {
if(tor != null) {
if(LOG.isLoggable(INFO))
LOG.info("Killing Tor via destroy()");
LOG.info("Killing Tor via destroy()");
tor.destroy();
}
if(pid != -1) {
@@ -452,7 +446,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
private void publishHiddenService(final String port) {
if(!running) return;
if(!hostnameFile.exists()) {
if(LOG.isLoggable(INFO)) LOG.info("Creating hidden service");
LOG.info("Creating hidden service");
try {
// Watch for the hostname file being created/updated
hostnameFile.getParentFile().mkdirs();
@@ -468,8 +462,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
controlConnection.saveConf();
// Wait for the hostname file to be created/updated
if(!latch.await(HOSTNAME_TIMEOUT, MILLISECONDS)) {
if(LOG.isLoggable(WARNING))
LOG.warning("Hidden service not created");
LOG.warning("Hidden service not created");
listFiles(torDirectory);
return;
}
@@ -477,8 +470,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
} catch(IOException e) {
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
} catch(InterruptedException e) {
if(LOG.isLoggable(WARNING))
LOG.warning("Interrupted while creating hidden service");
LOG.warning("Interrupted while creating hidden service");
}
}
// Publish the hidden service's onion hostname in transport properties
@@ -504,7 +496,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
tryToClose(ss);
return;
}
if(LOG.isLoggable(INFO)) LOG.info("Connection received");
LOG.info("Connection received");
TorTransportConnection conn = new TorTransportConnection(this, s);
callback.incomingConnectionCreated(conn);
if(!running) return;
@@ -524,7 +516,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
if(networkStateReceiver != null)
appContext.unregisterReceiver(networkStateReceiver);
try {
if(LOG.isLoggable(INFO)) LOG.info("Stopping Tor");
LOG.info("Stopping Tor");
if(controlSocket == null)
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
if(controlConnection == null) {