mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Whitespace-only code formatting changes.
This commit is contained in:
@@ -42,11 +42,11 @@ class AndroidExecutorImpl implements AndroidExecutor {
|
||||
}
|
||||
|
||||
private void startIfNecessary() {
|
||||
if(started.getAndSet(true)) return;
|
||||
if (started.getAndSet(true)) return;
|
||||
new Thread(loop, "AndroidExecutor").start();
|
||||
try {
|
||||
startLatch.await();
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while starting executor thread");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
@@ -62,7 +62,7 @@ class AndroidExecutorImpl implements AndroidExecutor {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
if(handler != null) {
|
||||
if (handler != null) {
|
||||
Message m = Message.obtain(handler, SHUTDOWN);
|
||||
handler.sendMessage(m);
|
||||
}
|
||||
|
||||
@@ -94,8 +94,8 @@ Service, EventListener {
|
||||
public void run() {
|
||||
try {
|
||||
settings = db.getSettings();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -108,14 +108,14 @@ Service, EventListener {
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if(e instanceof SettingsUpdatedEvent) loadSettings();
|
||||
if (e instanceof SettingsUpdatedEvent) loadSettings();
|
||||
}
|
||||
|
||||
public void showPrivateMessageNotification(ContactId c) {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Integer count = contactCounts.get(c);
|
||||
if(count == null) contactCounts.put(c, 1);
|
||||
if (count == null) contactCounts.put(c, 1);
|
||||
else contactCounts.put(c, count + 1);
|
||||
privateTotal++;
|
||||
updatePrivateMessageNotification();
|
||||
@@ -128,7 +128,7 @@ Service, EventListener {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Integer count = contactCounts.remove(c);
|
||||
if(count == null) return; // Already cleared
|
||||
if (count == null) return; // Already cleared
|
||||
privateTotal -= count;
|
||||
updatePrivateMessageNotification();
|
||||
} finally {
|
||||
@@ -138,9 +138,9 @@ Service, EventListener {
|
||||
|
||||
// Locking: synchLock
|
||||
private void updatePrivateMessageNotification() {
|
||||
if(privateTotal == 0) {
|
||||
if (privateTotal == 0) {
|
||||
clearPrivateMessageNotification();
|
||||
} else if(!settings.getBoolean("notifyPrivateMessages", true)) {
|
||||
} else if (!settings.getBoolean("notifyPrivateMessages", true)) {
|
||||
return;
|
||||
} else {
|
||||
NotificationCompat.Builder b =
|
||||
@@ -152,12 +152,12 @@ Service, EventListener {
|
||||
privateTotal));
|
||||
boolean sound = settings.getBoolean("notifySound", true);
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
if(sound && !StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
if (sound && !StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
b.setSound(Uri.parse(ringtoneUri));
|
||||
b.setDefaults(getDefaults());
|
||||
b.setOnlyAlertOnce(true);
|
||||
b.setAutoCancel(true);
|
||||
if(contactCounts.size() == 1) {
|
||||
if (contactCounts.size() == 1) {
|
||||
Intent i = new Intent(appContext, ConversationActivity.class);
|
||||
ContactId c = contactCounts.keySet().iterator().next();
|
||||
i.putExtra("briar.CONTACT_ID", c.getInt());
|
||||
@@ -192,9 +192,9 @@ Service, EventListener {
|
||||
int defaults = DEFAULT_LIGHTS;
|
||||
boolean sound = settings.getBoolean("notifySound", true);
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
if(sound && StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
if (sound && StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
defaults |= DEFAULT_SOUND;
|
||||
if(settings.getBoolean("notifyVibration", true))
|
||||
if (settings.getBoolean("notifyVibration", true))
|
||||
defaults |= DEFAULT_VIBRATE;
|
||||
return defaults;
|
||||
}
|
||||
@@ -203,7 +203,7 @@ Service, EventListener {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Integer count = groupCounts.get(g);
|
||||
if(count == null) groupCounts.put(g, 1);
|
||||
if (count == null) groupCounts.put(g, 1);
|
||||
else groupCounts.put(g, count + 1);
|
||||
groupTotal++;
|
||||
updateGroupPostNotification();
|
||||
@@ -216,7 +216,7 @@ Service, EventListener {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Integer count = groupCounts.remove(g);
|
||||
if(count == null) return; // Already cleared
|
||||
if (count == null) return; // Already cleared
|
||||
groupTotal -= count;
|
||||
updateGroupPostNotification();
|
||||
} finally {
|
||||
@@ -226,9 +226,9 @@ Service, EventListener {
|
||||
|
||||
// Locking: synchLock
|
||||
private void updateGroupPostNotification() {
|
||||
if(groupTotal == 0) {
|
||||
if (groupTotal == 0) {
|
||||
clearGroupPostNotification();
|
||||
} else if(!settings.getBoolean("notifyGroupPosts", true)) {
|
||||
} else if (!settings.getBoolean("notifyGroupPosts", true)) {
|
||||
return;
|
||||
} else {
|
||||
NotificationCompat.Builder b =
|
||||
@@ -239,12 +239,12 @@ Service, EventListener {
|
||||
R.plurals.forum_post_notification_text, groupTotal,
|
||||
groupTotal));
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
if(!StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
if (!StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
b.setSound(Uri.parse(ringtoneUri));
|
||||
b.setDefaults(getDefaults());
|
||||
b.setOnlyAlertOnce(true);
|
||||
b.setAutoCancel(true);
|
||||
if(groupCounts.size() == 1) {
|
||||
if (groupCounts.size() == 1) {
|
||||
Intent i = new Intent(appContext, GroupActivity.class);
|
||||
GroupId g = groupCounts.keySet().iterator().next();
|
||||
i.putExtra("briar.GROUP_ID", g.getBytes());
|
||||
|
||||
@@ -45,15 +45,15 @@ public class BriarActivity extends RoboActivity {
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
if(databaseConfig.getEncryptionKey() != null) startAndBindService();
|
||||
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
if (databaseConfig.getEncryptionKey() != null) startAndBindService();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int request, int result, Intent data) {
|
||||
super.onActivityResult(request, result, data);
|
||||
if(request == REQUEST_PASSWORD) {
|
||||
if(result == RESULT_OK) startAndBindService();
|
||||
if (request == REQUEST_PASSWORD) {
|
||||
if (result == RESULT_OK) startAndBindService();
|
||||
else finish();
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ public class BriarActivity extends RoboActivity {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if(databaseConfig.getEncryptionKey() == null && !isFinishing()) {
|
||||
if (databaseConfig.getEncryptionKey() == null && !isFinishing()) {
|
||||
Intent i = new Intent(this, PasswordActivity.class);
|
||||
i.setFlags(FLAG_ACTIVITY_NO_ANIMATION | FLAG_ACTIVITY_SINGLE_TOP);
|
||||
startActivityForResult(i, REQUEST_PASSWORD);
|
||||
@@ -81,7 +81,7 @@ public class BriarActivity extends RoboActivity {
|
||||
}
|
||||
|
||||
private void unbindService() {
|
||||
if(bound) unbindService(serviceConnection);
|
||||
if (bound) unbindService(serviceConnection);
|
||||
}
|
||||
|
||||
protected void signOut() {
|
||||
@@ -97,7 +97,7 @@ public class BriarActivity extends RoboActivity {
|
||||
LOG.info("Shutting down service");
|
||||
service.shutdown();
|
||||
service.waitForShutdown();
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while waiting for service");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
@@ -122,7 +122,7 @@ public class BriarActivity extends RoboActivity {
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
task.run();
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while waiting for database");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
@@ -66,12 +66,12 @@ public class BriarService extends RoboService implements EventListener {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
LOG.info("Created");
|
||||
if(created.getAndSet(true)) {
|
||||
if (created.getAndSet(true)) {
|
||||
LOG.info("Already created");
|
||||
stopSelf();
|
||||
return;
|
||||
}
|
||||
if(databaseConfig.getEncryptionKey() == null) {
|
||||
if (databaseConfig.getEncryptionKey() == null) {
|
||||
LOG.info("No database key");
|
||||
stopSelf();
|
||||
return;
|
||||
@@ -93,14 +93,14 @@ public class BriarService extends RoboService implements EventListener {
|
||||
@Override
|
||||
public void run() {
|
||||
StartResult result = lifecycleManager.startServices();
|
||||
if(result == SUCCESS) {
|
||||
if (result == SUCCESS) {
|
||||
eventBus.addListener(BriarService.this);
|
||||
started = true;
|
||||
} else if(result == ALREADY_RUNNING) {
|
||||
} else if (result == ALREADY_RUNNING) {
|
||||
LOG.info("Already running");
|
||||
stopSelf();
|
||||
} else {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.warning("Startup failed: " + result);
|
||||
showStartupFailureNotification();
|
||||
stopSelf();
|
||||
@@ -147,7 +147,7 @@ public class BriarService extends RoboService implements EventListener {
|
||||
new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(started) {
|
||||
if (started) {
|
||||
eventBus.removeListener(BriarService.this);
|
||||
lifecycleManager.stopServices();
|
||||
}
|
||||
@@ -164,11 +164,11 @@ public class BriarService extends RoboService implements EventListener {
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if(e instanceof MessageAddedEvent) {
|
||||
if (e instanceof MessageAddedEvent) {
|
||||
MessageAddedEvent m = (MessageAddedEvent) e;
|
||||
GroupId g = m.getGroup().getId();
|
||||
ContactId c = m.getContactId();
|
||||
if(c != null) showMessageNotification(g, c);
|
||||
if (c != null) showMessageNotification(g, c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,13 +177,13 @@ public class BriarService extends RoboService implements EventListener {
|
||||
public void run() {
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
if(g.equals(db.getInboxGroupId(c)))
|
||||
if (g.equals(db.getInboxGroupId(c)))
|
||||
notificationManager.showPrivateMessageNotification(c);
|
||||
else notificationManager.showGroupPostNotification(g);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.info("Interruped while waiting for database");
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
@@ -41,6 +41,6 @@ class CrashHandler implements UncaughtExceptionHandler {
|
||||
i.putExtra("briar.PID", android.os.Process.myPid());
|
||||
ctx.startActivity(i);
|
||||
// Pass the exception to the default handler, if any
|
||||
if(delegate != null) delegate.uncaughtException(thread, throwable);
|
||||
if (delegate != null) delegate.uncaughtException(thread, throwable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
progress.setVisibility(GONE);
|
||||
layout.addView(progress);
|
||||
|
||||
if(SHARE_CRASH_REPORTS) {
|
||||
if (SHARE_CRASH_REPORTS) {
|
||||
layout.addView(new HorizontalBorder(this));
|
||||
LinearLayout footer = new LinearLayout(this);
|
||||
footer.setLayoutParams(MATCH_WRAP);
|
||||
@@ -143,7 +143,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if(temp != null) temp.delete();
|
||||
if (temp != null) temp.delete();
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
@@ -165,7 +165,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
protected void onPostExecute(Map<String, String> result) {
|
||||
Context ctx = CrashReportActivity.this;
|
||||
int pad = LayoutUtils.getPadding(ctx);
|
||||
for(Entry<String, String> e : result.entrySet()) {
|
||||
for (Entry<String, String> e : result.entrySet()) {
|
||||
TextView title = new TextView(ctx);
|
||||
title.setTextSize(18);
|
||||
title.setText(e.getKey());
|
||||
@@ -191,9 +191,9 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
String manufacturer = Build.MANUFACTURER;
|
||||
String model = Build.MODEL;
|
||||
String brand = Build.BRAND;
|
||||
if(model.startsWith(manufacturer)) deviceType = capitalize(model);
|
||||
if (model.startsWith(manufacturer)) deviceType = capitalize(model);
|
||||
else deviceType = capitalize(manufacturer) + " " + model;
|
||||
if(!StringUtils.isNullOrEmpty(brand))
|
||||
if (!StringUtils.isNullOrEmpty(brand))
|
||||
deviceType += " (" + capitalize(brand) + ")";
|
||||
statusMap.put("Device type:", deviceType);
|
||||
|
||||
@@ -213,7 +213,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
ActivityManager.MemoryInfo mem = new ActivityManager.MemoryInfo();
|
||||
am.getMemoryInfo(mem);
|
||||
String systemMemory;
|
||||
if(Build.VERSION.SDK_INT >= 16) {
|
||||
if (Build.VERSION.SDK_INT >= 16) {
|
||||
systemMemory = (mem.totalMem / 1024 / 1024) + " MiB total, "
|
||||
+ (mem.availMem / 1024 / 1204) + " MiB free, "
|
||||
+ (mem.threshold / 1024 / 1024) + " MiB threshold";
|
||||
@@ -241,7 +241,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
String internal = (rootTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (rootFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("Internal storage:", internal);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
statusMap.put("Internal storage:", "Unknown");
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
String external = (sdTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (sdFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("External storage:", external);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
statusMap.put("External storage:", "Unknown");
|
||||
}
|
||||
|
||||
@@ -269,26 +269,26 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
Method method = clazz.getDeclaredMethod("getMobileDataEnabled");
|
||||
method.setAccessible(true);
|
||||
mobileEnabled = (Boolean) method.invoke(cm);
|
||||
} catch(ClassNotFoundException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(NoSuchMethodException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(IllegalAccessException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(IllegalArgumentException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InvocationTargetException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
// Is mobile data connected ?
|
||||
boolean mobileConnected = mobile != null && mobile.isConnected();
|
||||
|
||||
String mobileStatus;
|
||||
if(mobileAvailable) mobileStatus = "Available, ";
|
||||
if (mobileAvailable) mobileStatus = "Available, ";
|
||||
else mobileStatus = "Not available, ";
|
||||
if(mobileEnabled) mobileStatus += "enabled, ";
|
||||
if (mobileEnabled) mobileStatus += "enabled, ";
|
||||
else mobileStatus += "not enabled, ";
|
||||
if(mobileConnected) mobileStatus += "connected";
|
||||
if (mobileConnected) mobileStatus += "connected";
|
||||
else mobileStatus += "not connected";
|
||||
statusMap.put("Mobile data:", mobileStatus);
|
||||
|
||||
@@ -303,15 +303,15 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
boolean wifiConnected = wifi != null && wifi.isConnected();
|
||||
|
||||
String wifiStatus;
|
||||
if(wifiAvailable) wifiStatus = "Available, ";
|
||||
if (wifiAvailable) wifiStatus = "Available, ";
|
||||
else wifiStatus = "Not available, ";
|
||||
if(wifiEnabled) wifiStatus += "enabled, ";
|
||||
if (wifiEnabled) wifiStatus += "enabled, ";
|
||||
else wifiStatus += "not enabled, ";
|
||||
if(wifiConnected) wifiStatus += "connected";
|
||||
if (wifiConnected) wifiStatus += "connected";
|
||||
else wifiStatus += "not connected";
|
||||
if(wm != null) {
|
||||
if (wm != null) {
|
||||
WifiInfo wifiInfo = wm.getConnectionInfo();
|
||||
if(wifiInfo != null) {
|
||||
if (wifiInfo != null) {
|
||||
int ip = wifiInfo.getIpAddress(); // Nice API, Google
|
||||
int ip1 = ip & 0xFF;
|
||||
int ip2 = (ip >> 8) & 0xFF;
|
||||
@@ -331,11 +331,11 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
return BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
});
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while getting BluetoothAdapter");
|
||||
Thread.currentThread().interrupt();
|
||||
} catch(ExecutionException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (ExecutionException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
boolean btAvailable = bt != null;
|
||||
// Is Bluetooth enabled?
|
||||
@@ -350,37 +350,37 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
|
||||
String btStatus;
|
||||
if(btAvailable) btStatus = "Available, ";
|
||||
if (btAvailable) btStatus = "Available, ";
|
||||
else btStatus = "Not available, ";
|
||||
if(btEnabled) btStatus += "enabled, ";
|
||||
if (btEnabled) btStatus += "enabled, ";
|
||||
else btStatus += "not enabled, ";
|
||||
if(btConnectable) btStatus += "connectable, ";
|
||||
if (btConnectable) btStatus += "connectable, ";
|
||||
else btStatus += "not connectable, ";
|
||||
if(btDiscoverable) btStatus += "discoverable";
|
||||
if (btDiscoverable) btStatus += "discoverable";
|
||||
else btStatus += "not discoverable";
|
||||
if(bt != null) btStatus += "\nAddress: " + bt.getAddress();
|
||||
if (bt != null) btStatus += "\nAddress: " + bt.getAddress();
|
||||
statusMap.put("Bluetooth:", btStatus);
|
||||
|
||||
// Stack trace
|
||||
if(stack != null) statusMap.put("Stack trace:", stack);
|
||||
if (stack != null) statusMap.put("Stack trace:", stack);
|
||||
|
||||
// All log output from the crashed process
|
||||
if(pid != -1) {
|
||||
if (pid != -1) {
|
||||
StringBuilder log = new StringBuilder();
|
||||
try {
|
||||
Pattern pattern = Pattern.compile(".*\\( *" + pid + "\\).*");
|
||||
Process process = runtime.exec("logcat -d -v time *:I");
|
||||
Scanner scanner = new Scanner(process.getInputStream());
|
||||
while(scanner.hasNextLine()) {
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if(pattern.matcher(line).matches()) {
|
||||
if (pattern.matcher(line).matches()) {
|
||||
log.append(line);
|
||||
log.append('\n');
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
statusMap.put("Debugging log:", log.toString());
|
||||
}
|
||||
@@ -389,9 +389,9 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
}
|
||||
|
||||
private String capitalize(String s) {
|
||||
if(StringUtils.isNullOrEmpty(s)) return s;
|
||||
if (StringUtils.isNullOrEmpty(s)) return s;
|
||||
char first = s.charAt(0);
|
||||
if(Character.isUpperCase(first)) return s;
|
||||
if (Character.isUpperCase(first)) return s;
|
||||
return Character.toUpperCase(first) + s.substring(1);
|
||||
}
|
||||
|
||||
@@ -408,10 +408,10 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
try {
|
||||
File shared = Environment.getExternalStorageDirectory();
|
||||
temp = File.createTempFile("crash", ".txt", shared);
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Writing to " + temp.getPath());
|
||||
PrintStream p = new PrintStream(new FileOutputStream(temp));
|
||||
for(Entry<String, String> e : result.entrySet()) {
|
||||
for (Entry<String, String> e : result.entrySet()) {
|
||||
p.println(e.getKey());
|
||||
p.println(e.getValue());
|
||||
p.println();
|
||||
@@ -419,8 +419,8 @@ public class CrashReportActivity extends Activity implements OnClickListener {
|
||||
p.flush();
|
||||
p.close();
|
||||
sendEmail(Uri.fromFile(temp));
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,11 +59,11 @@ public class DashboardActivity extends BriarActivity {
|
||||
private void handleIntent(Intent i) {
|
||||
boolean failed = i.getBooleanExtra("briar.STARTUP_FAILED", false);
|
||||
long handle = i.getLongExtra("briar.LOCAL_AUTHOR_HANDLE", -1);
|
||||
if(failed) {
|
||||
if (failed) {
|
||||
finish();
|
||||
LOG.info("Exiting");
|
||||
System.exit(0);
|
||||
} else if(handle == -1) {
|
||||
} else if (handle == -1) {
|
||||
// The activity has been launched before
|
||||
showButtons();
|
||||
} else {
|
||||
@@ -72,7 +72,7 @@ public class DashboardActivity extends BriarActivity {
|
||||
LocalAuthor.class);
|
||||
// The reference may be null if the activity has been recreated,
|
||||
// for example due to screen rotation
|
||||
if(a == null) {
|
||||
if (a == null) {
|
||||
showButtons();
|
||||
} else {
|
||||
showSpinner();
|
||||
@@ -192,15 +192,15 @@ public class DashboardActivity extends BriarActivity {
|
||||
long now = System.currentTimeMillis();
|
||||
db.addLocalAuthor(a);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Storing author took " + duration + " ms");
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
showButtons();
|
||||
}
|
||||
});
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ExpiredActivity extends Activity {
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setLayoutParams(MATCH_MATCH);
|
||||
|
||||
@@ -58,11 +58,11 @@ public class PasswordActivity extends RoboActivity {
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
|
||||
SharedPreferences prefs = getSharedPreferences("db", MODE_PRIVATE);
|
||||
String hex = prefs.getString("key", null);
|
||||
if(hex == null || !databaseConfig.databaseExists()) {
|
||||
if (hex == null || !databaseConfig.databaseExists()) {
|
||||
// Storage has been deleted - clean up and return to setup
|
||||
prefs.edit().clear().commit();
|
||||
delete(databaseConfig.getDatabaseDirectory());
|
||||
@@ -121,12 +121,12 @@ public class PasswordActivity extends RoboActivity {
|
||||
}
|
||||
|
||||
private void delete(File f) {
|
||||
if(f.isFile()) f.delete();
|
||||
else if(f.isDirectory()) for(File child : f.listFiles()) delete(child);
|
||||
if (f.isFile()) f.delete();
|
||||
else if (f.isDirectory()) for (File child : f.listFiles()) delete(child);
|
||||
}
|
||||
|
||||
private void validatePassword(final byte[] encrypted, Editable e) {
|
||||
if(progress == null) return; // Not created yet
|
||||
if (progress == null) return; // Not created yet
|
||||
// Hide the soft keyboard
|
||||
Object o = getSystemService(INPUT_METHOD_SERVICE);
|
||||
((InputMethodManager) o).toggleSoftInput(HIDE_IMPLICIT_ONLY, 0);
|
||||
@@ -138,7 +138,7 @@ public class PasswordActivity extends RoboActivity {
|
||||
cryptoExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
byte[] key = crypto.decryptWithPassword(encrypted, password);
|
||||
if(key == null) {
|
||||
if (key == null) {
|
||||
tryAgain();
|
||||
} else {
|
||||
databaseConfig.setEncryptionKey(new SecretKey(key));
|
||||
|
||||
@@ -26,12 +26,12 @@ class ReferenceManagerImpl implements ReferenceManager {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Map<Long, Object> innerMap = outerMap.get(c);
|
||||
if(innerMap == null) {
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (innerMap == null) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("0 handles for " + c.getName());
|
||||
return null;
|
||||
}
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info(innerMap.size() + " handles for " + c.getName());
|
||||
Object o = innerMap.get(handle);
|
||||
return c.cast(o);
|
||||
@@ -45,13 +45,13 @@ class ReferenceManagerImpl implements ReferenceManager {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Map<Long, Object> innerMap = outerMap.get(c);
|
||||
if(innerMap == null) {
|
||||
if (innerMap == null) {
|
||||
innerMap = new HashMap<Long, Object>();
|
||||
outerMap.put(c, innerMap);
|
||||
}
|
||||
long handle = nextHandle++;
|
||||
innerMap.put(handle, reference);
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info(innerMap.size() + " handles for " + c.getName() +
|
||||
" after put");
|
||||
}
|
||||
@@ -65,10 +65,10 @@ class ReferenceManagerImpl implements ReferenceManager {
|
||||
synchLock.lock();
|
||||
try {
|
||||
Map<Long, Object> innerMap = outerMap.get(c);
|
||||
if(innerMap == null) return null;
|
||||
if (innerMap == null) return null;
|
||||
Object o = innerMap.remove(handle);
|
||||
if(innerMap.isEmpty()) outerMap.remove(c);
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (innerMap.isEmpty()) outerMap.remove(c);
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info(innerMap.size() + " handles for " + c.getName() +
|
||||
" after remove");
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ OnClickListener {
|
||||
|
||||
layout.addView(new HorizontalBorder(this));
|
||||
|
||||
if(SHOW_TESTING_ACTIVITY) {
|
||||
if (SHOW_TESTING_ACTIVITY) {
|
||||
LinearLayout footer = new LinearLayout(this);
|
||||
footer.setLayoutParams(MATCH_WRAP);
|
||||
footer.setGravity(CENTER);
|
||||
@@ -215,12 +215,12 @@ OnClickListener {
|
||||
TransportConfig c = db.getConfig(new TransportId("bt"));
|
||||
settings = db.getSettings();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading settings took " + duration + " ms");
|
||||
bluetoothSetting = c.getBoolean("enable", true);
|
||||
displaySettings();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -234,7 +234,7 @@ OnClickListener {
|
||||
progress.setVisibility(GONE);
|
||||
|
||||
int resId;
|
||||
if(bluetoothSetting) resId = R.string.bluetooth_setting_enabled;
|
||||
if (bluetoothSetting) resId = R.string.bluetooth_setting_enabled;
|
||||
else resId = R.string.bluetooth_setting_disabled;
|
||||
enableBluetoothHint.setText(resId);
|
||||
|
||||
@@ -248,9 +248,9 @@ OnClickListener {
|
||||
"notifyVibration", true));
|
||||
|
||||
String text;
|
||||
if(settings.getBoolean("notifySound", true)) {
|
||||
if (settings.getBoolean("notifySound", true)) {
|
||||
String ringtoneName = settings.get("notifyRingtoneName");
|
||||
if(StringUtils.isNullOrEmpty(ringtoneName))
|
||||
if (StringUtils.isNullOrEmpty(ringtoneName))
|
||||
text = getString(R.string.notify_sound_setting_default);
|
||||
else text = ringtoneName;
|
||||
} else {
|
||||
@@ -268,43 +268,43 @@ OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(progress == null) return; // Not created yet
|
||||
if(view == testingButton) {
|
||||
if (progress == null) return; // Not created yet
|
||||
if (view == testingButton) {
|
||||
startActivity(new Intent(this, TestingActivity.class));
|
||||
} else if(view == enableBluetooth || view == enableBluetoothHint) {
|
||||
} else if (view == enableBluetooth || view == enableBluetoothHint) {
|
||||
bluetoothSetting = !bluetoothSetting;
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if(adapter != null) {
|
||||
if(bluetoothSetting) adapter.enable();
|
||||
if (adapter != null) {
|
||||
if (bluetoothSetting) adapter.enable();
|
||||
else adapter.disable();
|
||||
}
|
||||
storeBluetoothSetting();
|
||||
displaySettings();
|
||||
return;
|
||||
} else if(view == notifyPrivateMessages) {
|
||||
} else if (view == notifyPrivateMessages) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean("notifyPrivateMessages",
|
||||
notifyPrivateMessages.isChecked());
|
||||
storeSettings(s);
|
||||
} else if(view == notifyGroupPosts) {
|
||||
} else if (view == notifyGroupPosts) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean("notifyGroupPosts", notifyGroupPosts.isChecked());
|
||||
storeSettings(s);
|
||||
} else if(view == notifyVibration) {
|
||||
} else if (view == notifyVibration) {
|
||||
Settings s = new Settings();
|
||||
s.putBoolean("notifyVibration", notifyVibration.isChecked());
|
||||
storeSettings(s);
|
||||
} else if(view == notifySound || view == notifySoundHint) {
|
||||
} else if (view == notifySound || view == notifySoundHint) {
|
||||
String title = getString(R.string.choose_ringtone_title);
|
||||
Intent i = new Intent(ACTION_RINGTONE_PICKER);
|
||||
i.putExtra(EXTRA_RINGTONE_TYPE, TYPE_NOTIFICATION);
|
||||
i.putExtra(EXTRA_RINGTONE_TITLE, title);
|
||||
i.putExtra(EXTRA_RINGTONE_DEFAULT_URI, DEFAULT_NOTIFICATION_URI);
|
||||
i.putExtra(EXTRA_RINGTONE_SHOW_SILENT, true);
|
||||
if(settings.getBoolean("notifySound", true)) {
|
||||
if (settings.getBoolean("notifySound", true)) {
|
||||
Uri uri;
|
||||
String ringtoneUri = settings.get("notifyRingtoneUri");
|
||||
if(StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
if (StringUtils.isNullOrEmpty(ringtoneUri))
|
||||
uri = DEFAULT_NOTIFICATION_URI;
|
||||
else uri = Uri.parse(ringtoneUri);
|
||||
i.putExtra(EXTRA_RINGTONE_EXISTING_URI, uri);
|
||||
@@ -322,10 +322,10 @@ OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.mergeConfig(new TransportId("bt"), c);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Merging config took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -339,10 +339,10 @@ OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.mergeSettings(settings);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Merging settings took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -352,16 +352,16 @@ OnClickListener {
|
||||
@Override
|
||||
public void onActivityResult(int request, int result, Intent data) {
|
||||
super.onActivityResult(request, result, data);
|
||||
if(request == REQUEST_RINGTONE && result == RESULT_OK) {
|
||||
if (request == REQUEST_RINGTONE && result == RESULT_OK) {
|
||||
Settings s = new Settings();
|
||||
Uri uri = data.getParcelableExtra(EXTRA_RINGTONE_PICKED_URI);
|
||||
if(uri == null) {
|
||||
if (uri == null) {
|
||||
// The user chose silence
|
||||
notifySoundHint.setText(R.string.notify_sound_setting_disabled);
|
||||
s.putBoolean("notifySound", false);
|
||||
s.put("notifyRingtoneName", "");
|
||||
s.put("notifyRingtoneUri", "");
|
||||
} else if(RingtoneManager.isDefault(uri)) {
|
||||
} else if (RingtoneManager.isDefault(uri)) {
|
||||
// The user chose the default
|
||||
notifySoundHint.setText(R.string.notify_sound_setting_default);
|
||||
s.putBoolean("notifySound", true);
|
||||
@@ -381,7 +381,7 @@ OnClickListener {
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if(e instanceof SettingsUpdatedEvent) {
|
||||
if (e instanceof SettingsUpdatedEvent) {
|
||||
LOG.info("Settings updated");
|
||||
loadSettings();
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ OnEditorActionListener {
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setLayoutParams(MATCH_MATCH);
|
||||
@@ -181,8 +181,8 @@ OnEditorActionListener {
|
||||
}
|
||||
|
||||
private void enableOrDisableContinueButton() {
|
||||
if(progress == null) return; // Not created yet
|
||||
if(passwordEntry.getText().length() > 0)
|
||||
if (progress == null) return; // Not created yet
|
||||
if (passwordEntry.getText().length() > 0)
|
||||
strengthMeter.setVisibility(VISIBLE);
|
||||
else strengthMeter.setVisibility(INVISIBLE);
|
||||
String nickname = nicknameEntry.getText().toString();
|
||||
@@ -192,15 +192,15 @@ OnEditorActionListener {
|
||||
boolean passwordsMatch = firstPassword.equals(secondPassword);
|
||||
float strength = strengthEstimator.estimateStrength(firstPassword);
|
||||
strengthMeter.setStrength(strength);
|
||||
if(nicknameLength > MAX_AUTHOR_NAME_LENGTH) {
|
||||
if (nicknameLength > MAX_AUTHOR_NAME_LENGTH) {
|
||||
feedback.setText(R.string.name_too_long);
|
||||
} else if(firstPassword.length() == 0) {
|
||||
} else if (firstPassword.length() == 0) {
|
||||
feedback.setText("");
|
||||
} else if(secondPassword.length() == 0 || passwordsMatch) {
|
||||
if(strength < PasswordStrengthEstimator.WEAK)
|
||||
} else if (secondPassword.length() == 0 || passwordsMatch) {
|
||||
if (strength < PasswordStrengthEstimator.WEAK)
|
||||
feedback.setText(R.string.password_too_weak);
|
||||
else feedback.setText("");
|
||||
} else if(!passwordsMatch) {
|
||||
} else if (!passwordsMatch) {
|
||||
feedback.setText(R.string.passwords_do_not_match);
|
||||
} else {
|
||||
feedback.setText("");
|
||||
@@ -245,7 +245,7 @@ OnEditorActionListener {
|
||||
editor.putString("key", StringUtils.toHexString(encrypted));
|
||||
editor.commit();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Key storage took " + duration + " ms");
|
||||
}
|
||||
|
||||
@@ -253,7 +253,7 @@ OnEditorActionListener {
|
||||
long now = System.currentTimeMillis();
|
||||
byte[] encrypted = crypto.encryptWithPassword(key.getBytes(), password);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Key derivation took " + duration + " ms");
|
||||
return encrypted;
|
||||
}
|
||||
@@ -266,7 +266,7 @@ OnEditorActionListener {
|
||||
LocalAuthor localAuthor = authorFactory.createLocalAuthor(nickname,
|
||||
publicKey, privateKey);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Identity creation took " + duration + " ms");
|
||||
return localAuthor;
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
|
||||
if(PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
if (PREVENT_SCREENSHOTS) getWindow().addFlags(FLAG_SECURE);
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setLayoutParams(MATCH_MATCH);
|
||||
@@ -71,9 +71,9 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
@Override
|
||||
protected void startNextActivity() {
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Guice startup took " + duration + " ms");
|
||||
if(System.currentTimeMillis() >= EXPIRY_DATE) {
|
||||
if (System.currentTimeMillis() >= EXPIRY_DATE) {
|
||||
LOG.info("Expired");
|
||||
startActivity(new Intent(this, ExpiredActivity.class));
|
||||
} else {
|
||||
@@ -81,7 +81,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
String hex = prefs.getString("key", null);
|
||||
Injector i = RoboGuice.getBaseApplicationInjector(getApplication());
|
||||
DatabaseConfig databaseConfig = i.getInstance(DatabaseConfig.class);
|
||||
if(hex != null && databaseConfig.databaseExists()) {
|
||||
if (hex != null && databaseConfig.databaseExists()) {
|
||||
startActivity(new Intent(this, DashboardActivity.class));
|
||||
} else {
|
||||
prefs.edit().clear().commit();
|
||||
@@ -93,7 +93,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private void enableStrictMode() {
|
||||
if(TESTING && Build.VERSION.SDK_INT >= 9) {
|
||||
if (TESTING && Build.VERSION.SDK_INT >= 9) {
|
||||
ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
|
||||
threadPolicy.detectAll();
|
||||
threadPolicy.penaltyLog();
|
||||
@@ -106,7 +106,7 @@ public class SplashScreenActivity extends RoboSplashActivity {
|
||||
}
|
||||
|
||||
private void delete(File f) {
|
||||
if(f.isFile()) f.delete();
|
||||
else if(f.isDirectory()) for(File child : f.listFiles()) delete(child);
|
||||
if (f.isFile()) f.delete();
|
||||
else if (f.isDirectory()) for (File child : f.listFiles()) delete(child);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,12 +153,12 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if(temp != null) temp.delete();
|
||||
if (temp != null) temp.delete();
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(view == refresh) refresh();
|
||||
else if(view == share) share();
|
||||
if (view == refresh) refresh();
|
||||
else if (view == share) share();
|
||||
}
|
||||
|
||||
private void refresh() {
|
||||
@@ -175,7 +175,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
@Override
|
||||
protected void onPostExecute(Map<String, String> result) {
|
||||
int pad = LayoutUtils.getPadding(TestingActivity.this);
|
||||
for(Entry<String, String> e : result.entrySet()) {
|
||||
for (Entry<String, String> e : result.entrySet()) {
|
||||
TextView title = new TextView(TestingActivity.this);
|
||||
title.setTextSize(18);
|
||||
title.setText(e.getKey());
|
||||
@@ -202,9 +202,9 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
String manufacturer = Build.MANUFACTURER;
|
||||
String model = Build.MODEL;
|
||||
String brand = Build.BRAND;
|
||||
if(model.startsWith(manufacturer)) deviceType = capitalize(model);
|
||||
if (model.startsWith(manufacturer)) deviceType = capitalize(model);
|
||||
else deviceType = capitalize(manufacturer) + " " + model;
|
||||
if(!StringUtils.isNullOrEmpty(brand))
|
||||
if (!StringUtils.isNullOrEmpty(brand))
|
||||
deviceType += " (" + capitalize(brand) + ")";
|
||||
statusMap.put("Device type:", deviceType);
|
||||
|
||||
@@ -224,7 +224,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
ActivityManager.MemoryInfo mem = new ActivityManager.MemoryInfo();
|
||||
am.getMemoryInfo(mem);
|
||||
String systemMemory;
|
||||
if(Build.VERSION.SDK_INT >= 16) {
|
||||
if (Build.VERSION.SDK_INT >= 16) {
|
||||
systemMemory = (mem.totalMem / 1024 / 1024) + " MiB total, "
|
||||
+ (mem.availMem / 1024 / 1204) + " MiB free, "
|
||||
+ (mem.threshold / 1024 / 1024) + " MiB threshold";
|
||||
@@ -252,7 +252,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
String internal = (rootTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (rootFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("Internal storage:", internal);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
statusMap.put("Internal storage:", "Unknown");
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
String external = (sdTotal / 1024 / 1024) + " MiB total, "
|
||||
+ (sdFree / 1024 / 1024) + " MiB free";
|
||||
statusMap.put("External storage:", external);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
statusMap.put("External storage:", "Unknown");
|
||||
}
|
||||
|
||||
@@ -280,26 +280,26 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
Method method = clazz.getDeclaredMethod("getMobileDataEnabled");
|
||||
method.setAccessible(true);
|
||||
mobileEnabled = (Boolean) method.invoke(cm);
|
||||
} catch(ClassNotFoundException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(NoSuchMethodException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(IllegalAccessException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(IllegalArgumentException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InvocationTargetException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (ClassNotFoundException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IllegalAccessException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (InvocationTargetException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
// Is mobile data connected ?
|
||||
boolean mobileConnected = mobile != null && mobile.isConnected();
|
||||
|
||||
String mobileStatus;
|
||||
if(mobileAvailable) mobileStatus = "Available, ";
|
||||
if (mobileAvailable) mobileStatus = "Available, ";
|
||||
else mobileStatus = "Not available, ";
|
||||
if(mobileEnabled) mobileStatus += "enabled, ";
|
||||
if (mobileEnabled) mobileStatus += "enabled, ";
|
||||
else mobileStatus += "not enabled, ";
|
||||
if(mobileConnected) mobileStatus += "connected";
|
||||
if (mobileConnected) mobileStatus += "connected";
|
||||
else mobileStatus += "not connected";
|
||||
statusMap.put("Mobile data:", mobileStatus);
|
||||
|
||||
@@ -314,15 +314,15 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
boolean wifiConnected = wifi != null && wifi.isConnected();
|
||||
|
||||
String wifiStatus;
|
||||
if(wifiAvailable) wifiStatus = "Available, ";
|
||||
if (wifiAvailable) wifiStatus = "Available, ";
|
||||
else wifiStatus = "Not available, ";
|
||||
if(wifiEnabled) wifiStatus += "enabled, ";
|
||||
if (wifiEnabled) wifiStatus += "enabled, ";
|
||||
else wifiStatus += "not enabled, ";
|
||||
if(wifiConnected) wifiStatus += "connected";
|
||||
if (wifiConnected) wifiStatus += "connected";
|
||||
else wifiStatus += "not connected";
|
||||
if(wm != null) {
|
||||
if (wm != null) {
|
||||
WifiInfo wifiInfo = wm.getConnectionInfo();
|
||||
if(wifiInfo != null) {
|
||||
if (wifiInfo != null) {
|
||||
int ip = wifiInfo.getIpAddress(); // Nice API, Google
|
||||
int ip1 = ip & 0xFF;
|
||||
int ip2 = (ip >> 8) & 0xFF;
|
||||
@@ -342,11 +342,11 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
return BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
});
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while getting BluetoothAdapter");
|
||||
Thread.currentThread().interrupt();
|
||||
} catch(ExecutionException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (ExecutionException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
boolean btAvailable = bt != null;
|
||||
// Is Bluetooth enabled?
|
||||
@@ -361,26 +361,26 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
bt.getScanMode() == SCAN_MODE_CONNECTABLE_DISCOVERABLE;
|
||||
|
||||
String btStatus;
|
||||
if(btAvailable) btStatus = "Available, ";
|
||||
if (btAvailable) btStatus = "Available, ";
|
||||
else btStatus = "Not available, ";
|
||||
if(btEnabled) btStatus += "enabled, ";
|
||||
if (btEnabled) btStatus += "enabled, ";
|
||||
else btStatus += "not enabled, ";
|
||||
if(btConnectable) btStatus += "connectable, ";
|
||||
if (btConnectable) btStatus += "connectable, ";
|
||||
else btStatus += "not connectable, ";
|
||||
if(btDiscoverable) btStatus += "discoverable";
|
||||
if (btDiscoverable) btStatus += "discoverable";
|
||||
else btStatus += "not discoverable";
|
||||
if(bt != null) btStatus += "\nAddress: " + bt.getAddress();
|
||||
if (bt != null) btStatus += "\nAddress: " + bt.getAddress();
|
||||
statusMap.put("Bluetooth:", btStatus);
|
||||
|
||||
Map<TransportId, TransportProperties> props = Collections.emptyMap();
|
||||
try {
|
||||
lifecycleManager.waitForDatabase();
|
||||
props = db.getLocalProperties();
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.info("Interrupted while waiting for database");
|
||||
Thread.currentThread().interrupt();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
|
||||
Plugin torPlugin = pluginManager.getPlugin(new TransportId("tor"));
|
||||
@@ -388,12 +388,12 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
boolean torPluginRunning = torPlugin != null && torPlugin.isRunning();
|
||||
|
||||
String torPluginStatus;
|
||||
if(torPluginEnabled) torPluginStatus = "Enabled, ";
|
||||
if (torPluginEnabled) torPluginStatus = "Enabled, ";
|
||||
else torPluginStatus = "Not enabled, ";
|
||||
if(torPluginRunning) torPluginStatus += "running";
|
||||
if (torPluginRunning) torPluginStatus += "running";
|
||||
else torPluginStatus += "not running";
|
||||
TransportProperties torProps = props.get(new TransportId("tor"));
|
||||
if(torProps != null)
|
||||
if (torProps != null)
|
||||
torPluginStatus += "\nAddress: " + torProps.get("onion");
|
||||
statusMap.put("Tor plugin:", torPluginStatus);
|
||||
|
||||
@@ -402,12 +402,12 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
boolean lanPluginRunning = lanPlugin != null && lanPlugin.isRunning();
|
||||
|
||||
String lanPluginStatus;
|
||||
if(lanPluginEnabled) lanPluginStatus = "Enabled, ";
|
||||
if (lanPluginEnabled) lanPluginStatus = "Enabled, ";
|
||||
else lanPluginStatus = "Not enabled, ";
|
||||
if(lanPluginRunning) lanPluginStatus += "running";
|
||||
if (lanPluginRunning) lanPluginStatus += "running";
|
||||
else lanPluginStatus += "not running";
|
||||
TransportProperties lanProps = props.get(new TransportId("lan"));
|
||||
if(lanProps != null)
|
||||
if (lanProps != null)
|
||||
lanPluginStatus += "\nAddress: " + lanProps.get("address");
|
||||
statusMap.put("LAN plugin:", lanPluginStatus);
|
||||
|
||||
@@ -416,12 +416,12 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
boolean btPluginRunning = btPlugin != null && btPlugin.isRunning();
|
||||
|
||||
String btPluginStatus;
|
||||
if(btPluginEnabled) btPluginStatus = "Enabled, ";
|
||||
if (btPluginEnabled) btPluginStatus = "Enabled, ";
|
||||
else btPluginStatus = "Not enabled, ";
|
||||
if(btPluginRunning) btPluginStatus += "running";
|
||||
if (btPluginRunning) btPluginStatus += "running";
|
||||
else btPluginStatus += "not running";
|
||||
TransportProperties btProps = props.get(new TransportId("bt"));
|
||||
if(btProps != null)
|
||||
if (btProps != null)
|
||||
btPluginStatus += "\nAddress: " + btProps.get("address");
|
||||
statusMap.put("Bluetooth plugin:", btPluginStatus);
|
||||
|
||||
@@ -432,16 +432,16 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
Pattern pattern = Pattern.compile(".*\\( *" + pid + "\\).*");
|
||||
Process process = runtime.exec("logcat -d -v time *:I");
|
||||
Scanner scanner = new Scanner(process.getInputStream());
|
||||
while(scanner.hasNextLine()) {
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
if(pattern.matcher(line).matches()) {
|
||||
if (pattern.matcher(line).matches()) {
|
||||
log.append(line);
|
||||
log.append('\n');
|
||||
}
|
||||
}
|
||||
scanner.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
statusMap.put("Debugging log:", log.toString());
|
||||
|
||||
@@ -449,9 +449,9 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
}
|
||||
|
||||
private String capitalize(String s) {
|
||||
if(StringUtils.isNullOrEmpty(s)) return s;
|
||||
if (StringUtils.isNullOrEmpty(s)) return s;
|
||||
char first = s.charAt(0);
|
||||
if(Character.isUpperCase(first)) return s;
|
||||
if (Character.isUpperCase(first)) return s;
|
||||
return Character.toUpperCase(first) + s.substring(1);
|
||||
}
|
||||
|
||||
@@ -468,10 +468,10 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
try {
|
||||
File shared = Environment.getExternalStorageDirectory();
|
||||
temp = File.createTempFile("debug", ".txt", shared);
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Writing to " + temp.getPath());
|
||||
PrintStream p = new PrintStream(new FileOutputStream(temp));
|
||||
for(Entry<String, String> e : result.entrySet()) {
|
||||
for (Entry<String, String> e : result.entrySet()) {
|
||||
p.println(e.getKey());
|
||||
p.println(e.getValue());
|
||||
p.println();
|
||||
@@ -479,8 +479,8 @@ public class TestingActivity extends BriarActivity implements OnClickListener {
|
||||
p.flush();
|
||||
p.close();
|
||||
sendEmail(Uri.fromFile(temp));
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,22 +138,22 @@ EventListener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
for(Contact c : db.getContacts()) {
|
||||
for (Contact c : db.getContacts()) {
|
||||
try {
|
||||
GroupId inbox = db.getInboxGroupId(c.getId());
|
||||
Collection<MessageHeader> headers =
|
||||
db.getInboxMessageHeaders(c.getId());
|
||||
displayContact(c, inbox, headers);
|
||||
} catch(NoSuchContactException e) {
|
||||
} catch (NoSuchContactException e) {
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Full load took " + duration + " ms");
|
||||
hideProgressBar();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -181,7 +181,7 @@ EventListener {
|
||||
boolean connected = connectionRegistry.isConnected(c.getId());
|
||||
// Remove the old item, if any
|
||||
ContactListItem item = findItem(c.getId());
|
||||
if(item != null) adapter.remove(item);
|
||||
if (item != null) adapter.remove(item);
|
||||
// Add a new item
|
||||
adapter.add(new ContactListItem(c, connected, inbox, headers));
|
||||
adapter.sort(ContactListItemComparator.INSTANCE);
|
||||
@@ -193,7 +193,7 @@ EventListener {
|
||||
private void hideProgressBar() {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if(adapter.isEmpty()) empty.setVisibility(VISIBLE);
|
||||
if (adapter.isEmpty()) empty.setVisibility(VISIBLE);
|
||||
else list.setVisibility(VISIBLE);
|
||||
loading.setVisibility(GONE);
|
||||
}
|
||||
@@ -202,9 +202,9 @@ EventListener {
|
||||
|
||||
private ContactListItem findItem(ContactId c) {
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
ContactListItem item = adapter.getItem(i);
|
||||
if(item.getContact().getId().equals(c)) return item;
|
||||
if (item.getContact().getId().equals(c)) return item;
|
||||
}
|
||||
return null; // Not found
|
||||
}
|
||||
@@ -243,7 +243,7 @@ EventListener {
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem menuItem) {
|
||||
if(menuItem.getItemId() == MENU_ITEM_DELETE) {
|
||||
if (menuItem.getItemId() == MENU_ITEM_DELETE) {
|
||||
ContextMenuInfo info = menuItem.getMenuInfo();
|
||||
int position = ((AdapterContextMenuInfo) info).position;
|
||||
ContactListItem item = adapter.getItem(position);
|
||||
@@ -259,8 +259,8 @@ EventListener {
|
||||
public void run() {
|
||||
try {
|
||||
db.removeContact(c);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -268,21 +268,21 @@ EventListener {
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if(e instanceof ContactAddedEvent) {
|
||||
if (e instanceof ContactAddedEvent) {
|
||||
loadContacts();
|
||||
} else if(e instanceof ContactConnectedEvent) {
|
||||
} else if (e instanceof ContactConnectedEvent) {
|
||||
setConnected(((ContactConnectedEvent) e).getContactId(), true);
|
||||
} else if(e instanceof ContactDisconnectedEvent) {
|
||||
} else if (e instanceof ContactDisconnectedEvent) {
|
||||
setConnected(((ContactDisconnectedEvent) e).getContactId(), false);
|
||||
} else if(e instanceof ContactRemovedEvent) {
|
||||
} else if (e instanceof ContactRemovedEvent) {
|
||||
LOG.info("Contact removed");
|
||||
removeItem(((ContactRemovedEvent) e).getContactId());
|
||||
} else if(e instanceof MessageAddedEvent) {
|
||||
} else if (e instanceof MessageAddedEvent) {
|
||||
LOG.info("Message added, reloading");
|
||||
ContactId source = ((MessageAddedEvent) e).getContactId();
|
||||
if(source == null) loadContacts();
|
||||
if (source == null) loadContacts();
|
||||
else reloadContact(source);
|
||||
} else if(e instanceof MessageExpiredEvent) {
|
||||
} else if (e instanceof MessageExpiredEvent) {
|
||||
LOG.info("Message expired, reloading");
|
||||
loadContacts();
|
||||
}
|
||||
@@ -296,13 +296,13 @@ EventListener {
|
||||
Collection<MessageHeader> headers =
|
||||
db.getInboxMessageHeaders(c);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Partial load took " + duration + " ms");
|
||||
updateItem(c, headers);
|
||||
} catch(NoSuchContactException e) {
|
||||
} catch (NoSuchContactException e) {
|
||||
removeItem(c);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -314,7 +314,7 @@ EventListener {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ContactListItem item = findItem(c);
|
||||
if(item != null) {
|
||||
if (item != null) {
|
||||
item.setHeaders(headers);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
@@ -326,10 +326,10 @@ EventListener {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ContactListItem item = findItem(c);
|
||||
if(item != null) {
|
||||
if (item != null) {
|
||||
adapter.remove(item);
|
||||
adapter.notifyDataSetChanged();
|
||||
if(adapter.isEmpty()) {
|
||||
if (adapter.isEmpty()) {
|
||||
empty.setVisibility(VISIBLE);
|
||||
list.setVisibility(GONE);
|
||||
}
|
||||
@@ -342,7 +342,7 @@ EventListener {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
ContactListItem item = findItem(c);
|
||||
if(item != null) {
|
||||
if (item != null) {
|
||||
item.setConnected(connected);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -40,12 +40,12 @@ class ContactListAdapter extends ArrayAdapter<ContactListItem> {
|
||||
layout.setOrientation(HORIZONTAL);
|
||||
layout.setGravity(CENTER_VERTICAL);
|
||||
int unread = item.getUnreadCount();
|
||||
if(unread > 0)
|
||||
if (unread > 0)
|
||||
layout.setBackgroundColor(res.getColor(R.color.unread_background));
|
||||
|
||||
ImageView bulb = new ImageView(ctx);
|
||||
bulb.setPadding(pad, pad, pad, pad);
|
||||
if(item.isConnected())
|
||||
if (item.isConnected())
|
||||
bulb.setImageResource(R.drawable.contact_connected);
|
||||
else bulb.setImageResource(R.drawable.contact_disconnected);
|
||||
layout.addView(bulb);
|
||||
@@ -57,11 +57,11 @@ class ContactListAdapter extends ArrayAdapter<ContactListItem> {
|
||||
name.setEllipsize(END);
|
||||
name.setPadding(0, pad, pad, pad);
|
||||
String contactName = item.getContact().getAuthor().getName();
|
||||
if(unread > 0) name.setText(contactName + " (" + unread + ")");
|
||||
if (unread > 0) name.setText(contactName + " (" + unread + ")");
|
||||
else name.setText(contactName);
|
||||
layout.addView(name);
|
||||
|
||||
if(item.isEmpty()) {
|
||||
if (item.isEmpty()) {
|
||||
TextView noMessages = new TextView(ctx);
|
||||
noMessages.setPadding(pad, pad, pad, pad);
|
||||
noMessages.setTextColor(res.getColor(R.color.no_private_messages));
|
||||
|
||||
@@ -27,10 +27,10 @@ class ContactListItem {
|
||||
empty = headers.isEmpty();
|
||||
timestamp = 0;
|
||||
unread = 0;
|
||||
if(!empty) {
|
||||
for(MessageHeader h : headers) {
|
||||
if(h.getTimestamp() > timestamp) timestamp = h.getTimestamp();
|
||||
if(!h.isRead()) unread++;
|
||||
if (!empty) {
|
||||
for (MessageHeader h : headers) {
|
||||
if (h.getTimestamp() > timestamp) timestamp = h.getTimestamp();
|
||||
if (!h.isRead()) unread++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
|
||||
Intent i = getIntent();
|
||||
int id = i.getIntExtra("briar.CONTACT_ID", -1);
|
||||
if(id == -1) throw new IllegalStateException();
|
||||
if (id == -1) throw new IllegalStateException();
|
||||
contactId = new ContactId(id);
|
||||
|
||||
Intent data = new Intent();
|
||||
@@ -206,17 +206,17 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
groupId = db.getInboxGroupId(contactId);
|
||||
group = db.getGroup(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Loading contact and group took "
|
||||
+ duration + " ms");
|
||||
}
|
||||
displayContactName();
|
||||
} catch(NoSuchContactException e) {
|
||||
} catch (NoSuchContactException e) {
|
||||
finishOnUiThread();
|
||||
} catch(NoSuchSubscriptionException e) {
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
finishOnUiThread();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -239,13 +239,13 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
Collection<MessageHeader> headers =
|
||||
db.getInboxMessageHeaders(contactId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading headers took " + duration + " ms");
|
||||
displayHeaders(headers);
|
||||
} catch(NoSuchContactException e) {
|
||||
} catch (NoSuchContactException e) {
|
||||
finishOnUiThread();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -259,16 +259,16 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
setTitle(contactName);
|
||||
sendButton.setEnabled(true);
|
||||
adapter.clear();
|
||||
if(headers.isEmpty()) {
|
||||
if (headers.isEmpty()) {
|
||||
empty.setVisibility(VISIBLE);
|
||||
list.setVisibility(GONE);
|
||||
} else {
|
||||
empty.setVisibility(GONE);
|
||||
list.setVisibility(VISIBLE);
|
||||
for(MessageHeader h : headers) {
|
||||
for (MessageHeader h : headers) {
|
||||
ConversationItem item = new ConversationItem(h);
|
||||
byte[] body = bodyCache.get(h.getId());
|
||||
if(body == null) loadMessageBody(h);
|
||||
if (body == null) loadMessageBody(h);
|
||||
else item.setBody(body);
|
||||
adapter.add(item);
|
||||
}
|
||||
@@ -288,13 +288,13 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
byte[] body = db.getMessageBody(h.getId());
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading message took " + duration + " ms");
|
||||
displayMessageBody(h.getId(), body);
|
||||
} catch(NoSuchMessageException e) {
|
||||
} catch (NoSuchMessageException e) {
|
||||
// The item will be removed when we get the event
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -306,9 +306,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
public void run() {
|
||||
bodyCache.put(m, body);
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
ConversationItem item = adapter.getItem(i);
|
||||
if(item.getHeader().getId().equals(m)) {
|
||||
if (item.getHeader().getId().equals(m)) {
|
||||
item.setBody(body);
|
||||
adapter.notifyDataSetChanged();
|
||||
// Scroll to the bottom
|
||||
@@ -323,9 +323,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
@Override
|
||||
protected void onActivityResult(int request, int result, Intent data) {
|
||||
super.onActivityResult(request, result, data);
|
||||
if(request == REQUEST_READ && result == RESULT_PREV_NEXT) {
|
||||
if (request == REQUEST_READ && result == RESULT_PREV_NEXT) {
|
||||
int position = data.getIntExtra("briar.POSITION", -1);
|
||||
if(position >= 0 && position < adapter.getCount())
|
||||
if (position >= 0 && position < adapter.getCount())
|
||||
displayMessage(position);
|
||||
}
|
||||
}
|
||||
@@ -334,19 +334,19 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
eventBus.removeListener(this);
|
||||
if(isFinishing()) markMessagesRead();
|
||||
if (isFinishing()) markMessagesRead();
|
||||
}
|
||||
|
||||
private void markMessagesRead() {
|
||||
notificationManager.clearPrivateMessageNotification(contactId);
|
||||
List<MessageId> unread = new ArrayList<MessageId>();
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
MessageHeader h = adapter.getItem(i).getHeader();
|
||||
if(!h.isRead()) unread.add(h.getId());
|
||||
if (!h.isRead()) unread.add(h.getId());
|
||||
}
|
||||
if(unread.isEmpty()) return;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (unread.isEmpty()) return;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Marking " + unread.size() + " messages read");
|
||||
markMessagesRead(Collections.unmodifiableList(unread));
|
||||
}
|
||||
@@ -356,12 +356,12 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
for(MessageId m : unread) db.setReadFlag(m, true);
|
||||
for (MessageId m : unread) db.setReadFlag(m, true);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Marking read took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -369,24 +369,24 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if(e instanceof ContactRemovedEvent) {
|
||||
if (e instanceof ContactRemovedEvent) {
|
||||
ContactRemovedEvent c = (ContactRemovedEvent) e;
|
||||
if(c.getContactId().equals(contactId)) {
|
||||
if (c.getContactId().equals(contactId)) {
|
||||
LOG.info("Contact removed");
|
||||
finishOnUiThread();
|
||||
}
|
||||
} else if(e instanceof MessageAddedEvent) {
|
||||
} else if (e instanceof MessageAddedEvent) {
|
||||
GroupId g = ((MessageAddedEvent) e).getGroup().getId();
|
||||
if(g.equals(groupId)) {
|
||||
if (g.equals(groupId)) {
|
||||
LOG.info("Message added, reloading");
|
||||
loadHeaders();
|
||||
}
|
||||
} else if(e instanceof MessageExpiredEvent) {
|
||||
} else if (e instanceof MessageExpiredEvent) {
|
||||
LOG.info("Message expired, reloading");
|
||||
loadHeaders();
|
||||
} else if(e instanceof MessagesAckedEvent) {
|
||||
} else if (e instanceof MessagesAckedEvent) {
|
||||
MessagesAckedEvent m = (MessagesAckedEvent) e;
|
||||
if(m.getContactId().equals(contactId)) {
|
||||
if (m.getContactId().equals(contactId)) {
|
||||
LOG.info("Messages acked");
|
||||
markMessagesDelivered(m.getMessageIds());
|
||||
}
|
||||
@@ -399,21 +399,21 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
Set<MessageId> ackedSet = new HashSet<MessageId>(acked);
|
||||
boolean changed = false;
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
ConversationItem item = adapter.getItem(i);
|
||||
if(ackedSet.contains(item.getHeader().getId())) {
|
||||
if (ackedSet.contains(item.getHeader().getId())) {
|
||||
item.setDelivered(true);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
if(changed) adapter.notifyDataSetChanged();
|
||||
if (changed) adapter.notifyDataSetChanged();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
String message = content.getText().toString();
|
||||
if(message.equals("")) return;
|
||||
if (message.equals("")) return;
|
||||
long timestamp = System.currentTimeMillis();
|
||||
timestamp = Math.max(timestamp, getMinTimestampForNewMessage());
|
||||
createMessage(StringUtils.toUtf8(message), timestamp);
|
||||
@@ -426,9 +426,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
// Don't use an earlier timestamp than the newest message
|
||||
long timestamp = 0;
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
long t = adapter.getItem(i).getHeader().getTimestamp();
|
||||
if(t > timestamp) timestamp = t;
|
||||
if (t > timestamp) timestamp = t;
|
||||
}
|
||||
return timestamp + 1;
|
||||
}
|
||||
@@ -440,9 +440,9 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
Message m = messageFactory.createAnonymousMessage(null,
|
||||
group, "text/plain", timestamp, body);
|
||||
storeMessage(m);
|
||||
} catch(GeneralSecurityException e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -456,10 +456,10 @@ implements EventListener, OnClickListener, OnItemClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.addLocalMessage(m);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Storing message took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,17 +45,17 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
||||
|
||||
LinearLayout layout = new LinearLayout(ctx);
|
||||
layout.setOrientation(VERTICAL);
|
||||
if(header.isLocal()) layout.setPadding(3 * pad, 0, 0, 0);
|
||||
if (header.isLocal()) layout.setPadding(3 * pad, 0, 0, 0);
|
||||
else layout.setPadding(0, 0, 3 * pad, 0);
|
||||
|
||||
int background = res.getColor(R.color.private_message_background);
|
||||
|
||||
View content;
|
||||
if(item.getBody() == null) {
|
||||
if (item.getBody() == null) {
|
||||
TextView ellipsis = new TextView(ctx);
|
||||
ellipsis.setText("\u2026");
|
||||
content = ellipsis;
|
||||
} else if(header.getContentType().equals("text/plain")) {
|
||||
} else if (header.getContentType().equals("text/plain")) {
|
||||
TextView text = new TextView(ctx);
|
||||
text.setText(StringUtils.fromUtf8(item.getBody()));
|
||||
content = text;
|
||||
@@ -69,7 +69,7 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
||||
content.setPadding(pad, pad, pad, 0);
|
||||
layout.addView(content);
|
||||
|
||||
if(header.isLocal()) {
|
||||
if (header.isLocal()) {
|
||||
LinearLayout footer = new LinearLayout(ctx);
|
||||
footer.setLayoutParams(MATCH_WRAP);
|
||||
footer.setOrientation(HORIZONTAL);
|
||||
@@ -82,7 +82,7 @@ class ConversationAdapter extends ArrayAdapter<ConversationItem> {
|
||||
ImageView delivered = new ImageView(ctx);
|
||||
delivered.setPadding(0, 0, pad, 0);
|
||||
delivered.setImageResource(R.drawable.message_delivered);
|
||||
if(!item.isDelivered()) delivered.setVisibility(INVISIBLE);
|
||||
if (!item.isDelivered()) delivered.setVisibility(INVISIBLE);
|
||||
footer.addView(delivered);
|
||||
|
||||
TextView date = new TextView(ctx);
|
||||
|
||||
@@ -11,8 +11,8 @@ class ConversationItemComparator implements Comparator<ConversationItem> {
|
||||
// The oldest message comes first
|
||||
long aTime = a.getHeader().getTimestamp();
|
||||
long bTime = b.getHeader().getTimestamp();
|
||||
if(aTime < bTime) return -1;
|
||||
if(aTime > bTime) return 1;
|
||||
if (aTime < bTime) return -1;
|
||||
if (aTime > bTime) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,27 +68,27 @@ implements OnClickListener {
|
||||
|
||||
Intent i = getIntent();
|
||||
contactName = i.getStringExtra("briar.CONTACT_NAME");
|
||||
if(contactName == null) throw new IllegalStateException();
|
||||
if (contactName == null) throw new IllegalStateException();
|
||||
setTitle(contactName);
|
||||
byte[] b = i.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
localAuthorId = new AuthorId(b);
|
||||
String authorName = i.getStringExtra("briar.AUTHOR_NAME");
|
||||
if(authorName == null) throw new IllegalStateException();
|
||||
if (authorName == null) throw new IllegalStateException();
|
||||
b = i.getByteArrayExtra("briar.MESSAGE_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
messageId = new MessageId(b);
|
||||
b = i.getByteArrayExtra("briar.GROUP_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
groupId = new GroupId(b);
|
||||
String contentType = i.getStringExtra("briar.CONTENT_TYPE");
|
||||
if(contentType == null) throw new IllegalStateException();
|
||||
if (contentType == null) throw new IllegalStateException();
|
||||
timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
|
||||
if(timestamp == -1) throw new IllegalStateException();
|
||||
if (timestamp == -1) throw new IllegalStateException();
|
||||
minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
|
||||
if(minTimestamp == -1) throw new IllegalStateException();
|
||||
if (minTimestamp == -1) throw new IllegalStateException();
|
||||
position = i.getIntExtra("briar.POSITION", -1);
|
||||
if(position == -1) throw new IllegalStateException();
|
||||
if (position == -1) throw new IllegalStateException();
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setLayoutParams(MATCH_WRAP);
|
||||
@@ -118,7 +118,7 @@ implements OnClickListener {
|
||||
header.addView(date);
|
||||
message.addView(header);
|
||||
|
||||
if(contentType.equals("text/plain")) {
|
||||
if (contentType.equals("text/plain")) {
|
||||
// Load and display the message body
|
||||
content = new TextView(this);
|
||||
content.setPadding(pad, 0, pad, pad);
|
||||
@@ -164,7 +164,7 @@ implements OnClickListener {
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if(isFinishing()) markMessageRead();
|
||||
if (isFinishing()) markMessageRead();
|
||||
}
|
||||
|
||||
private void markMessageRead() {
|
||||
@@ -174,10 +174,10 @@ implements OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.setReadFlag(messageId, true);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Marking read took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -191,13 +191,13 @@ implements OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
byte[] body = db.getMessageBody(messageId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading message took " + duration + " ms");
|
||||
displayMessageBody(StringUtils.fromUtf8(body));
|
||||
} catch(NoSuchMessageException e) {
|
||||
} catch (NoSuchMessageException e) {
|
||||
finishOnUiThread();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -213,17 +213,17 @@ implements OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(view == prevButton) {
|
||||
if (view == prevButton) {
|
||||
Intent i = new Intent();
|
||||
i.putExtra("briar.POSITION", position - 1);
|
||||
setResult(RESULT_PREV_NEXT, i);
|
||||
finish();
|
||||
} else if(view == nextButton) {
|
||||
} else if (view == nextButton) {
|
||||
Intent i = new Intent();
|
||||
i.putExtra("briar.POSITION", position + 1);
|
||||
setResult(RESULT_PREV_NEXT, i);
|
||||
finish();
|
||||
} else if(view == replyButton) {
|
||||
} else if (view == replyButton) {
|
||||
Intent i = new Intent(this, WritePrivateMessageActivity.class);
|
||||
i.putExtra("briar.CONTACT_NAME", contactName);
|
||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
||||
|
||||
@@ -35,13 +35,13 @@ public class SelectContactsDialog implements OnMultiChoiceClickListener {
|
||||
}
|
||||
|
||||
public Dialog build(Context ctx) {
|
||||
if(listener == null || contacts == null || selected == null)
|
||||
if (listener == null || contacts == null || selected == null)
|
||||
throw new IllegalStateException();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
||||
int size = contacts.size();
|
||||
String[] names = new String[size];
|
||||
boolean[] checked = new boolean[size];
|
||||
for(int i = 0; i < size; i++) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
Contact c = contacts.get(i);
|
||||
names[i] = c.getAuthor().getName();
|
||||
checked[i] = selected.contains(c.getId());
|
||||
@@ -63,7 +63,7 @@ public class SelectContactsDialog implements OnMultiChoiceClickListener {
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
if(isChecked) selected.add(contacts.get(which).getId());
|
||||
if (isChecked) selected.add(contacts.get(which).getId());
|
||||
else selected.remove(contacts.get(which).getId());
|
||||
}
|
||||
|
||||
|
||||
@@ -78,18 +78,18 @@ implements OnClickListener {
|
||||
|
||||
Intent i = getIntent();
|
||||
contactName = i.getStringExtra("briar.CONTACT_NAME");
|
||||
if(contactName == null) throw new IllegalStateException();
|
||||
if (contactName == null) throw new IllegalStateException();
|
||||
setTitle(contactName);
|
||||
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
groupId = new GroupId(b);
|
||||
b = i.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
|
||||
if(minTimestamp == -1) throw new IllegalStateException();
|
||||
if (minTimestamp == -1) throw new IllegalStateException();
|
||||
localAuthorId = new AuthorId(b);
|
||||
b = i.getByteArrayExtra("briar.PARENT_ID");
|
||||
if(b != null) parentId = new MessageId(b);
|
||||
if (b != null) parentId = new MessageId(b);
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setLayoutParams(MATCH_WRAP);
|
||||
@@ -138,7 +138,7 @@ implements OnClickListener {
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if(localAuthor == null || group == null) loadAuthorAndGroup();
|
||||
if (localAuthor == null || group == null) loadAuthorAndGroup();
|
||||
}
|
||||
|
||||
private void loadAuthorAndGroup() {
|
||||
@@ -149,15 +149,15 @@ implements OnClickListener {
|
||||
localAuthor = db.getLocalAuthor(localAuthorId);
|
||||
group = db.getGroup(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Load took " + duration + " ms");
|
||||
displayLocalAuthor();
|
||||
} catch(NoSuchContactException e) {
|
||||
} catch (NoSuchContactException e) {
|
||||
finishOnUiThread();
|
||||
} catch(NoSuchSubscriptionException e) {
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
finishOnUiThread();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -177,7 +177,7 @@ implements OnClickListener {
|
||||
|
||||
public void onClick(View view) {
|
||||
String message = content.getText().toString();
|
||||
if(message.equals("")) return;
|
||||
if (message.equals("")) return;
|
||||
createMessage(StringUtils.toUtf8(message));
|
||||
Toast.makeText(this, R.string.message_sent_toast, LENGTH_LONG).show();
|
||||
finish();
|
||||
@@ -193,9 +193,9 @@ implements OnClickListener {
|
||||
Message m = messageFactory.createAnonymousMessage(parentId,
|
||||
group, "text/plain", timestamp, body);
|
||||
storeMessage(m);
|
||||
} catch(GeneralSecurityException e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
@@ -209,10 +209,10 @@ implements OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.addLocalMessage(m);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Storing message took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,21 +78,21 @@ implements EventListener, OnItemClickListener {
|
||||
Collection<GroupContacts> available =
|
||||
new ArrayList<GroupContacts>();
|
||||
long now = System.currentTimeMillis();
|
||||
for(Group g : db.getAvailableGroups()) {
|
||||
for (Group g : db.getAvailableGroups()) {
|
||||
try {
|
||||
GroupId id = g.getId();
|
||||
Collection<Contact> c = db.getSubscribers(id);
|
||||
available.add(new GroupContacts(g, c));
|
||||
} catch(NoSuchSubscriptionException e) {
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Load took " + duration + " ms");
|
||||
displayGroups(available);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -102,13 +102,13 @@ implements EventListener, OnItemClickListener {
|
||||
private void displayGroups(final Collection<GroupContacts> available) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if(available.isEmpty()) {
|
||||
if (available.isEmpty()) {
|
||||
LOG.info("No groups available, finishing");
|
||||
finish();
|
||||
} else {
|
||||
setContentView(list);
|
||||
adapter.clear();
|
||||
for(GroupContacts g : available)
|
||||
for (GroupContacts g : available)
|
||||
adapter.add(new AvailableGroupsItem(g));
|
||||
adapter.sort(AvailableGroupsItemComparator.INSTANCE);
|
||||
adapter.notifyDataSetChanged();
|
||||
@@ -124,13 +124,13 @@ implements EventListener, OnItemClickListener {
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if(e instanceof RemoteSubscriptionsUpdatedEvent) {
|
||||
if (e instanceof RemoteSubscriptionsUpdatedEvent) {
|
||||
LOG.info("Remote subscriptions changed, reloading");
|
||||
loadGroups();
|
||||
} else if(e instanceof SubscriptionAddedEvent) {
|
||||
} else if (e instanceof SubscriptionAddedEvent) {
|
||||
LOG.info("Subscription added, reloading");
|
||||
loadGroups();
|
||||
} else if(e instanceof SubscriptionRemovedEvent) {
|
||||
} else if (e instanceof SubscriptionRemovedEvent) {
|
||||
LOG.info("Subscription removed, reloading");
|
||||
loadGroups();
|
||||
}
|
||||
@@ -140,7 +140,7 @@ implements EventListener, OnItemClickListener {
|
||||
long id) {
|
||||
AvailableGroupsItem item = adapter.getItem(position);
|
||||
Collection<ContactId> visible = new ArrayList<ContactId>();
|
||||
for(Contact c : item.getContacts()) visible.add(c.getId());
|
||||
for (Contact c : item.getContacts()) visible.add(c.getId());
|
||||
addSubscription(item.getGroup(), visible);
|
||||
String subscribed = getString(R.string.subscribed_toast);
|
||||
Toast.makeText(this, subscribed, LENGTH_SHORT).show();
|
||||
@@ -153,8 +153,8 @@ implements EventListener, OnItemClickListener {
|
||||
try {
|
||||
db.addGroup(g);
|
||||
db.setVisibility(g.getId(), visible);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ class AvailableGroupsAdapter extends ArrayAdapter<AvailableGroupsItem> {
|
||||
TextView status = new TextView(ctx);
|
||||
status.setPadding(pad, 0, pad, pad);
|
||||
Collection<String> names = new ArrayList<String>();
|
||||
for(Contact c : item.getContacts()) names.add(c.getAuthor().getName());
|
||||
for (Contact c : item.getContacts()) names.add(c.getAuthor().getName());
|
||||
String format = ctx.getString(R.string.shared_by_format);
|
||||
status.setText(String.format(format, StringUtils.join(names, ", ")));
|
||||
layout.addView(status);
|
||||
|
||||
@@ -8,7 +8,7 @@ class AvailableGroupsItemComparator implements Comparator<AvailableGroupsItem> {
|
||||
new AvailableGroupsItemComparator();
|
||||
|
||||
public int compare(AvailableGroupsItem a, AvailableGroupsItem b) {
|
||||
if(a == b) return 0;
|
||||
if (a == b) return 0;
|
||||
String aName = a.getGroup().getName();
|
||||
String bName = b.getGroup().getName();
|
||||
return String.CASE_INSENSITIVE_ORDER.compare(aName, bName);
|
||||
|
||||
@@ -105,7 +105,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
}
|
||||
|
||||
private void enableOrDisableCreateButton() {
|
||||
if(progress == null) return; // Not created yet
|
||||
if (progress == null) return; // Not created yet
|
||||
createForumButton.setEnabled(validateName());
|
||||
}
|
||||
|
||||
@@ -116,7 +116,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
|
||||
private boolean validateName() {
|
||||
int length = StringUtils.toUtf8(nameEntry.getText().toString()).length;
|
||||
if(length > MAX_GROUP_NAME_LENGTH) {
|
||||
if (length > MAX_GROUP_NAME_LENGTH) {
|
||||
feedback.setText(R.string.name_too_long);
|
||||
return false;
|
||||
}
|
||||
@@ -125,9 +125,9 @@ implements OnEditorActionListener, OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(view == createForumButton) {
|
||||
if (view == createForumButton) {
|
||||
hideSoftKeyboard();
|
||||
if(!validateName()) return;
|
||||
if (!validateName()) return;
|
||||
createForumButton.setVisibility(GONE);
|
||||
progress.setVisibility(VISIBLE);
|
||||
storeGroup(nameEntry.getText().toString());
|
||||
@@ -142,11 +142,11 @@ implements OnEditorActionListener, OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.addGroup(g);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Storing group took " + duration + " ms");
|
||||
displayGroup(g);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
finishOnUiThread();
|
||||
}
|
||||
|
||||
@@ -83,10 +83,10 @@ OnClickListener, OnItemClickListener {
|
||||
|
||||
Intent i = getIntent();
|
||||
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
groupId = new GroupId(b);
|
||||
String name = i.getStringExtra("briar.GROUP_NAME");
|
||||
if(name != null) setTitle(name);
|
||||
if (name != null) setTitle(name);
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
layout.setLayoutParams(MATCH_MATCH);
|
||||
@@ -155,13 +155,13 @@ OnClickListener, OnItemClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
group = db.getGroup(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading group " + duration + " ms");
|
||||
displayGroupName();
|
||||
} catch(NoSuchSubscriptionException e) {
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
finishOnUiThread();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -184,13 +184,13 @@ OnClickListener, OnItemClickListener {
|
||||
Collection<MessageHeader> headers =
|
||||
db.getMessageHeaders(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Load took " + duration + " ms");
|
||||
displayHeaders(headers);
|
||||
} catch(NoSuchSubscriptionException e) {
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
finishOnUiThread();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -202,16 +202,16 @@ OnClickListener, OnItemClickListener {
|
||||
public void run() {
|
||||
loading.setVisibility(GONE);
|
||||
adapter.clear();
|
||||
if(headers.isEmpty()) {
|
||||
if (headers.isEmpty()) {
|
||||
empty.setVisibility(VISIBLE);
|
||||
list.setVisibility(GONE);
|
||||
} else {
|
||||
empty.setVisibility(GONE);
|
||||
list.setVisibility(VISIBLE);
|
||||
for(MessageHeader h : headers) {
|
||||
for (MessageHeader h : headers) {
|
||||
GroupItem item = new GroupItem(h);
|
||||
byte[] body = bodyCache.get(h.getId());
|
||||
if(body == null) loadMessageBody(h);
|
||||
if (body == null) loadMessageBody(h);
|
||||
else item.setBody(body);
|
||||
adapter.add(item);
|
||||
}
|
||||
@@ -231,13 +231,13 @@ OnClickListener, OnItemClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
byte[] body = db.getMessageBody(h.getId());
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading message took " + duration + " ms");
|
||||
displayMessage(h.getId(), body);
|
||||
} catch(NoSuchMessageException e) {
|
||||
} catch (NoSuchMessageException e) {
|
||||
// The item will be removed when we get the event
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -249,9 +249,9 @@ OnClickListener, OnItemClickListener {
|
||||
public void run() {
|
||||
bodyCache.put(m, body);
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
GroupItem item = adapter.getItem(i);
|
||||
if(item.getHeader().getId().equals(m)) {
|
||||
if (item.getHeader().getId().equals(m)) {
|
||||
item.setBody(body);
|
||||
adapter.notifyDataSetChanged();
|
||||
// Scroll to the bottom
|
||||
@@ -266,9 +266,9 @@ OnClickListener, OnItemClickListener {
|
||||
@Override
|
||||
protected void onActivityResult(int request, int result, Intent data) {
|
||||
super.onActivityResult(request, result, data);
|
||||
if(request == REQUEST_READ && result == RESULT_PREV_NEXT) {
|
||||
if (request == REQUEST_READ && result == RESULT_PREV_NEXT) {
|
||||
int position = data.getIntExtra("briar.POSITION", -1);
|
||||
if(position >= 0 && position < adapter.getCount())
|
||||
if (position >= 0 && position < adapter.getCount())
|
||||
displayMessage(position);
|
||||
}
|
||||
}
|
||||
@@ -277,19 +277,19 @@ OnClickListener, OnItemClickListener {
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
eventBus.removeListener(this);
|
||||
if(isFinishing()) markMessagesRead();
|
||||
if (isFinishing()) markMessagesRead();
|
||||
}
|
||||
|
||||
private void markMessagesRead() {
|
||||
notificationManager.clearGroupPostNotification(groupId);
|
||||
List<MessageId> unread = new ArrayList<MessageId>();
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
MessageHeader h = adapter.getItem(i).getHeader();
|
||||
if(!h.isRead()) unread.add(h.getId());
|
||||
if (!h.isRead()) unread.add(h.getId());
|
||||
}
|
||||
if(unread.isEmpty()) return;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (unread.isEmpty()) return;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Marking " + unread.size() + " messages read");
|
||||
markMessagesRead(Collections.unmodifiableList(unread));
|
||||
}
|
||||
@@ -299,12 +299,12 @@ OnClickListener, OnItemClickListener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
for(MessageId m : unread) db.setReadFlag(m, true);
|
||||
for (MessageId m : unread) db.setReadFlag(m, true);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Marking read took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -312,17 +312,17 @@ OnClickListener, OnItemClickListener {
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if(e instanceof MessageAddedEvent) {
|
||||
if(((MessageAddedEvent) e).getGroup().getId().equals(groupId)) {
|
||||
if (e instanceof MessageAddedEvent) {
|
||||
if (((MessageAddedEvent) e).getGroup().getId().equals(groupId)) {
|
||||
LOG.info("Message added, reloading");
|
||||
loadHeaders();
|
||||
}
|
||||
} else if(e instanceof MessageExpiredEvent) {
|
||||
} else if (e instanceof MessageExpiredEvent) {
|
||||
LOG.info("Message expired, reloading");
|
||||
loadHeaders();
|
||||
} else if(e instanceof SubscriptionRemovedEvent) {
|
||||
} else if (e instanceof SubscriptionRemovedEvent) {
|
||||
SubscriptionRemovedEvent s = (SubscriptionRemovedEvent) e;
|
||||
if(s.getGroup().getId().equals(groupId)) {
|
||||
if (s.getGroup().getId().equals(groupId)) {
|
||||
LOG.info("Subscription removed");
|
||||
finishOnUiThread();
|
||||
}
|
||||
@@ -330,13 +330,13 @@ OnClickListener, OnItemClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(view == composeButton) {
|
||||
if (view == composeButton) {
|
||||
Intent i = new Intent(this, WriteGroupPostActivity.class);
|
||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
||||
i.putExtra("briar.GROUP_NAME", group.getName());
|
||||
i.putExtra("briar.MIN_TIMESTAMP", getMinTimestampForNewMessage());
|
||||
startActivity(i);
|
||||
} else if(view == shareButton) {
|
||||
} else if (view == shareButton) {
|
||||
Intent i = new Intent(this, ShareGroupActivity.class);
|
||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
||||
i.putExtra("briar.GROUP_NAME", group.getName());
|
||||
@@ -348,9 +348,9 @@ OnClickListener, OnItemClickListener {
|
||||
// Don't use an earlier timestamp than the newest message
|
||||
long timestamp = 0;
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
long t = adapter.getItem(i).getHeader().getTimestamp();
|
||||
if(t > timestamp) timestamp = t;
|
||||
if (t > timestamp) timestamp = t;
|
||||
}
|
||||
return timestamp + 1;
|
||||
}
|
||||
@@ -367,7 +367,7 @@ OnClickListener, OnItemClickListener {
|
||||
i.putExtra("briar.GROUP_NAME", group.getName());
|
||||
i.putExtra("briar.MESSAGE_ID", item.getId().getBytes());
|
||||
Author author = item.getAuthor();
|
||||
if(author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());
|
||||
if (author != null) i.putExtra("briar.AUTHOR_NAME", author.getName());
|
||||
i.putExtra("briar.AUTHOR_STATUS", item.getAuthorStatus().name());
|
||||
i.putExtra("briar.CONTENT_TYPE", item.getContentType());
|
||||
i.putExtra("briar.TIMESTAMP", item.getTimestamp());
|
||||
|
||||
@@ -45,7 +45,7 @@ class GroupAdapter extends ArrayAdapter<GroupItem> {
|
||||
LinearLayout layout = new LinearLayout(ctx);
|
||||
layout.setOrientation(VERTICAL);
|
||||
layout.setGravity(CENTER_HORIZONTAL);
|
||||
if(!header.isRead())
|
||||
if (!header.isRead())
|
||||
layout.setBackgroundColor(res.getColor(R.color.unread_background));
|
||||
|
||||
LinearLayout headerLayout = new LinearLayout(ctx);
|
||||
@@ -55,7 +55,7 @@ class GroupAdapter extends ArrayAdapter<GroupItem> {
|
||||
AuthorView authorView = new AuthorView(ctx);
|
||||
authorView.setLayoutParams(WRAP_WRAP_1);
|
||||
Author author = header.getAuthor();
|
||||
if(author == null) authorView.init(null, header.getAuthorStatus());
|
||||
if (author == null) authorView.init(null, header.getAuthorStatus());
|
||||
else authorView.init(author.getName(), header.getAuthorStatus());
|
||||
headerLayout.addView(authorView);
|
||||
|
||||
@@ -66,12 +66,12 @@ class GroupAdapter extends ArrayAdapter<GroupItem> {
|
||||
headerLayout.addView(date);
|
||||
layout.addView(headerLayout);
|
||||
|
||||
if(item.getBody() == null) {
|
||||
if (item.getBody() == null) {
|
||||
TextView ellipsis = new TextView(ctx);
|
||||
ellipsis.setPadding(pad, 0, pad, pad);
|
||||
ellipsis.setText("\u2026");
|
||||
layout.addView(ellipsis);
|
||||
} else if(header.getContentType().equals("text/plain")) {
|
||||
} else if (header.getContentType().equals("text/plain")) {
|
||||
TextView text = new TextView(ctx);
|
||||
text.setPadding(pad, 0, pad, pad);
|
||||
text.setText(StringUtils.fromUtf8(item.getBody()));
|
||||
|
||||
@@ -10,8 +10,8 @@ class GroupItemComparator implements Comparator<GroupItem> {
|
||||
// The oldest message comes first
|
||||
long aTime = a.getHeader().getTimestamp();
|
||||
long bTime = b.getHeader().getTimestamp();
|
||||
if(aTime < bTime) return -1;
|
||||
if(aTime > bTime) return 1;
|
||||
if (aTime < bTime) return -1;
|
||||
if (aTime > bTime) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,20 +154,20 @@ OnCreateContextMenuListener {
|
||||
public void run() {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
for(Group g : db.getGroups()) {
|
||||
for (Group g : db.getGroups()) {
|
||||
try {
|
||||
displayHeaders(g, db.getMessageHeaders(g.getId()));
|
||||
} catch(NoSuchSubscriptionException e) {
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
// Continue
|
||||
}
|
||||
}
|
||||
int available = db.getAvailableGroups().size();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Full load took " + duration + " ms");
|
||||
displayAvailable(available);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -198,7 +198,7 @@ OnCreateContextMenuListener {
|
||||
loading.setVisibility(GONE);
|
||||
// Remove the old item, if any
|
||||
GroupListItem item = findGroup(id);
|
||||
if(item != null) adapter.remove(item);
|
||||
if (item != null) adapter.remove(item);
|
||||
// Add a new item
|
||||
adapter.add(new GroupListItem(g, headers));
|
||||
adapter.sort(GroupListItemComparator.INSTANCE);
|
||||
@@ -211,9 +211,9 @@ OnCreateContextMenuListener {
|
||||
private void displayAvailable(final int availableCount) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if(adapter.isEmpty()) empty.setVisibility(VISIBLE);
|
||||
if (adapter.isEmpty()) empty.setVisibility(VISIBLE);
|
||||
loading.setVisibility(GONE);
|
||||
if(availableCount == 0) {
|
||||
if (availableCount == 0) {
|
||||
available.setVisibility(GONE);
|
||||
} else {
|
||||
available.setVisibility(VISIBLE);
|
||||
@@ -227,22 +227,22 @@ OnCreateContextMenuListener {
|
||||
|
||||
private GroupListItem findGroup(GroupId g) {
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
GroupListItem item = adapter.getItem(i);
|
||||
if(item.getGroup().getId().equals(g)) return item;
|
||||
if (item.getGroup().getId().equals(g)) return item;
|
||||
}
|
||||
return null; // Not found
|
||||
}
|
||||
|
||||
private void selectFirstUnread() {
|
||||
int firstUnread = -1, count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
if(adapter.getItem(i).getUnreadCount() > 0) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (adapter.getItem(i).getUnreadCount() > 0) {
|
||||
firstUnread = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(firstUnread == -1) list.setSelection(count - 1);
|
||||
if (firstUnread == -1) list.setSelection(count - 1);
|
||||
else list.setSelection(firstUnread);
|
||||
}
|
||||
|
||||
@@ -253,24 +253,24 @@ OnCreateContextMenuListener {
|
||||
}
|
||||
|
||||
public void eventOccurred(Event e) {
|
||||
if(e instanceof MessageAddedEvent) {
|
||||
if (e instanceof MessageAddedEvent) {
|
||||
Group g = ((MessageAddedEvent) e).getGroup();
|
||||
if(groups.containsKey(g.getId())) {
|
||||
if (groups.containsKey(g.getId())) {
|
||||
LOG.info("Message added, reloading");
|
||||
loadHeaders(g);
|
||||
}
|
||||
} else if(e instanceof MessageExpiredEvent) {
|
||||
} else if (e instanceof MessageExpiredEvent) {
|
||||
LOG.info("Message expired, reloading");
|
||||
loadHeaders();
|
||||
} else if(e instanceof RemoteSubscriptionsUpdatedEvent) {
|
||||
} else if (e instanceof RemoteSubscriptionsUpdatedEvent) {
|
||||
LOG.info("Remote subscriptions changed, reloading");
|
||||
loadAvailable();
|
||||
} else if(e instanceof SubscriptionAddedEvent) {
|
||||
} else if (e instanceof SubscriptionAddedEvent) {
|
||||
LOG.info("Group added, reloading");
|
||||
loadHeaders();
|
||||
} else if(e instanceof SubscriptionRemovedEvent) {
|
||||
} else if (e instanceof SubscriptionRemovedEvent) {
|
||||
Group g = ((SubscriptionRemovedEvent) e).getGroup();
|
||||
if(groups.containsKey(g.getId())) {
|
||||
if (groups.containsKey(g.getId())) {
|
||||
LOG.info("Group removed, reloading");
|
||||
loadHeaders();
|
||||
}
|
||||
@@ -285,13 +285,13 @@ OnCreateContextMenuListener {
|
||||
Collection<MessageHeader> headers =
|
||||
db.getMessageHeaders(g.getId());
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Partial load took " + duration + " ms");
|
||||
displayHeaders(g, headers);
|
||||
} catch(NoSuchSubscriptionException e) {
|
||||
} catch (NoSuchSubscriptionException e) {
|
||||
removeGroup(g.getId());
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -302,11 +302,11 @@ OnCreateContextMenuListener {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
GroupListItem item = findGroup(g);
|
||||
if(item != null) {
|
||||
if (item != null) {
|
||||
groups.remove(g);
|
||||
adapter.remove(item);
|
||||
adapter.notifyDataSetChanged();
|
||||
if(adapter.isEmpty()) {
|
||||
if (adapter.isEmpty()) {
|
||||
empty.setVisibility(VISIBLE);
|
||||
list.setVisibility(GONE);
|
||||
} else {
|
||||
@@ -324,11 +324,11 @@ OnCreateContextMenuListener {
|
||||
long now = System.currentTimeMillis();
|
||||
int available = db.getAvailableGroups().size();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading available took " + duration + " ms");
|
||||
displayAvailable(available);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -336,9 +336,9 @@ OnCreateContextMenuListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(view == available) {
|
||||
if (view == available) {
|
||||
startActivity(new Intent(this, AvailableGroupsActivity.class));
|
||||
} else if(view == newGroupButton) {
|
||||
} else if (view == newGroupButton) {
|
||||
startActivity(new Intent(this, CreateGroupActivity.class));
|
||||
}
|
||||
}
|
||||
@@ -361,7 +361,7 @@ OnCreateContextMenuListener {
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem menuItem) {
|
||||
if(menuItem.getItemId() == MENU_ITEM_UNSUBSCRIBE) {
|
||||
if (menuItem.getItemId() == MENU_ITEM_UNSUBSCRIBE) {
|
||||
ContextMenuInfo info = menuItem.getMenuInfo();
|
||||
int position = ((AdapterContextMenuInfo) info).position;
|
||||
GroupListItem item = adapter.getItem(position);
|
||||
@@ -379,10 +379,10 @@ OnCreateContextMenuListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.removeGroup(g);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Removing group took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class GroupListAdapter extends ArrayAdapter<GroupListItem> {
|
||||
LinearLayout layout = new LinearLayout(ctx);
|
||||
layout.setOrientation(HORIZONTAL);
|
||||
int unread = item.getUnreadCount();
|
||||
if(unread > 0)
|
||||
if (unread > 0)
|
||||
layout.setBackgroundColor(res.getColor(R.color.unread_background));
|
||||
|
||||
TextView name = new TextView(ctx);
|
||||
@@ -47,11 +47,11 @@ class GroupListAdapter extends ArrayAdapter<GroupListItem> {
|
||||
name.setEllipsize(END);
|
||||
name.setPadding(pad, pad, pad, pad);
|
||||
String groupName = item.getGroup().getName();
|
||||
if(unread > 0) name.setText(groupName + " (" + unread + ")");
|
||||
if (unread > 0) name.setText(groupName + " (" + unread + ")");
|
||||
else name.setText(groupName);
|
||||
layout.addView(name);
|
||||
|
||||
if(item.isEmpty()) {
|
||||
if (item.isEmpty()) {
|
||||
TextView noPosts = new TextView(ctx);
|
||||
noPosts.setPadding(pad, 0, pad, pad);
|
||||
noPosts.setTextColor(res.getColor(R.color.no_posts));
|
||||
|
||||
@@ -17,7 +17,7 @@ class GroupListItem {
|
||||
GroupListItem(Group group, Collection<MessageHeader> headers) {
|
||||
this.group = group;
|
||||
empty = headers.isEmpty();
|
||||
if(empty) {
|
||||
if (empty) {
|
||||
authorName = null;
|
||||
contentType = null;
|
||||
timestamp = 0;
|
||||
@@ -26,15 +26,15 @@ class GroupListItem {
|
||||
MessageHeader newest = null;
|
||||
long timestamp = 0;
|
||||
int unread = 0;
|
||||
for(MessageHeader h : headers) {
|
||||
if(h.getTimestamp() > timestamp) {
|
||||
for (MessageHeader h : headers) {
|
||||
if (h.getTimestamp() > timestamp) {
|
||||
timestamp = h.getTimestamp();
|
||||
newest = h;
|
||||
}
|
||||
if(!h.isRead()) unread++;
|
||||
if (!h.isRead()) unread++;
|
||||
}
|
||||
Author a = newest.getAuthor();
|
||||
if(a == null) authorName = null;
|
||||
if (a == null) authorName = null;
|
||||
else authorName = a.getName();
|
||||
contentType = newest.getContentType();
|
||||
this.timestamp = newest.getTimestamp();
|
||||
|
||||
@@ -8,11 +8,11 @@ class GroupListItemComparator implements Comparator<GroupListItem> {
|
||||
new GroupListItemComparator();
|
||||
|
||||
public int compare(GroupListItem a, GroupListItem b) {
|
||||
if(a == b) return 0;
|
||||
if (a == b) return 0;
|
||||
// The item with the newest message comes first
|
||||
long aTime = a.getTimestamp(), bTime = b.getTimestamp();
|
||||
if(aTime > bTime) return -1;
|
||||
if(aTime < bTime) return 1;
|
||||
if (aTime > bTime) return -1;
|
||||
if (aTime < bTime) return 1;
|
||||
// Break ties by group name
|
||||
String aName = a.getGroup().getName();
|
||||
String bName = b.getGroup().getName();
|
||||
|
||||
@@ -16,7 +16,7 @@ public class NoContactsDialog {
|
||||
}
|
||||
|
||||
public Dialog build(Context ctx) {
|
||||
if(listener == null) throw new IllegalStateException();
|
||||
if (listener == null) throw new IllegalStateException();
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
|
||||
builder.setMessage(R.string.no_contacts_prompt);
|
||||
builder.setPositiveButton(R.string.add_button,
|
||||
|
||||
@@ -66,25 +66,25 @@ implements OnClickListener {
|
||||
|
||||
Intent i = getIntent();
|
||||
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
groupId = new GroupId(b);
|
||||
groupName = i.getStringExtra("briar.GROUP_NAME");
|
||||
if(groupName == null) throw new IllegalStateException();
|
||||
if (groupName == null) throw new IllegalStateException();
|
||||
setTitle(groupName);
|
||||
b = i.getByteArrayExtra("briar.MESSAGE_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
messageId = new MessageId(b);
|
||||
String contentType = i.getStringExtra("briar.CONTENT_TYPE");
|
||||
if(contentType == null) throw new IllegalStateException();
|
||||
if (contentType == null) throw new IllegalStateException();
|
||||
timestamp = i.getLongExtra("briar.TIMESTAMP", -1);
|
||||
if(timestamp == -1) throw new IllegalStateException();
|
||||
if (timestamp == -1) throw new IllegalStateException();
|
||||
minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
|
||||
if(minTimestamp == -1) throw new IllegalStateException();
|
||||
if (minTimestamp == -1) throw new IllegalStateException();
|
||||
position = i.getIntExtra("briar.POSITION", -1);
|
||||
if(position == -1) throw new IllegalStateException();
|
||||
if (position == -1) throw new IllegalStateException();
|
||||
String authorName = i.getStringExtra("briar.AUTHOR_NAME");
|
||||
String s = i.getStringExtra("briar.AUTHOR_STATUS");
|
||||
if(s == null) throw new IllegalStateException();
|
||||
if (s == null) throw new IllegalStateException();
|
||||
Author.Status authorStatus = Author.Status.valueOf(s);
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
@@ -115,7 +115,7 @@ implements OnClickListener {
|
||||
header.addView(date);
|
||||
message.addView(header);
|
||||
|
||||
if(contentType.equals("text/plain")) {
|
||||
if (contentType.equals("text/plain")) {
|
||||
// Load and display the message body
|
||||
content = new TextView(this);
|
||||
content.setPadding(pad, 0, pad, pad);
|
||||
@@ -161,7 +161,7 @@ implements OnClickListener {
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
if(isFinishing()) markMessageRead();
|
||||
if (isFinishing()) markMessageRead();
|
||||
}
|
||||
|
||||
private void markMessageRead() {
|
||||
@@ -171,10 +171,10 @@ implements OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.setReadFlag(messageId, true);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Marking read took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -188,13 +188,13 @@ implements OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
byte[] body = db.getMessageBody(messageId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading message took " + duration + " ms");
|
||||
displayMessageBody(StringUtils.fromUtf8(body));
|
||||
} catch(NoSuchMessageException e) {
|
||||
} catch (NoSuchMessageException e) {
|
||||
finishOnUiThread();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -210,17 +210,17 @@ implements OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(view == prevButton) {
|
||||
if (view == prevButton) {
|
||||
Intent i = new Intent();
|
||||
i.putExtra("briar.POSITION", position - 1);
|
||||
setResult(RESULT_PREV_NEXT, i);
|
||||
finish();
|
||||
} else if(view == nextButton) {
|
||||
} else if (view == nextButton) {
|
||||
Intent i = new Intent();
|
||||
i.putExtra("briar.POSITION", position + 1);
|
||||
setResult(RESULT_PREV_NEXT, i);
|
||||
finish();
|
||||
} else if(view == replyButton) {
|
||||
} else if (view == replyButton) {
|
||||
Intent i = new Intent(this, WriteGroupPostActivity.class);
|
||||
i.putExtra("briar.GROUP_ID", groupId.getBytes());
|
||||
i.putExtra("briar.GROUP_NAME", groupName);
|
||||
|
||||
@@ -62,10 +62,10 @@ SelectContactsDialog.Listener {
|
||||
|
||||
Intent i = getIntent();
|
||||
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
groupId = new GroupId(b);
|
||||
groupName = i.getStringExtra("briar.GROUP_NAME");
|
||||
if(groupName == null) throw new IllegalStateException();
|
||||
if (groupName == null) throw new IllegalStateException();
|
||||
setTitle(groupName);
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
@@ -109,14 +109,14 @@ SelectContactsDialog.Listener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(view == shareWithAll) {
|
||||
if (view == shareWithAll) {
|
||||
changed = true;
|
||||
} else if(view == shareWithSome) {
|
||||
} else if (view == shareWithSome) {
|
||||
changed = true;
|
||||
if(contacts == null) loadVisibility();
|
||||
if (contacts == null) loadVisibility();
|
||||
else displayVisibility();
|
||||
} else if(view == shareButton) {
|
||||
if(changed) {
|
||||
} else if (view == shareButton) {
|
||||
if (changed) {
|
||||
// Replace the button with a progress bar
|
||||
shareButton.setVisibility(GONE);
|
||||
progress.setVisibility(VISIBLE);
|
||||
@@ -136,11 +136,11 @@ SelectContactsDialog.Listener {
|
||||
contacts = db.getContacts();
|
||||
selected = db.getVisibility(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Load took " + duration + " ms");
|
||||
displayVisibility();
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -150,7 +150,7 @@ SelectContactsDialog.Listener {
|
||||
private void displayVisibility() {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if(contacts.isEmpty()) {
|
||||
if (contacts.isEmpty()) {
|
||||
NoContactsDialog builder = new NoContactsDialog();
|
||||
builder.setListener(ShareGroupActivity.this);
|
||||
builder.build(ShareGroupActivity.this).show();
|
||||
@@ -171,12 +171,12 @@ SelectContactsDialog.Listener {
|
||||
try {
|
||||
long now = System.currentTimeMillis();
|
||||
db.setVisibleToAll(groupId, all);
|
||||
if(!all) db.setVisibility(groupId, selected);
|
||||
if (!all) db.setVisibility(groupId, selected);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Update took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
finishOnUiThread();
|
||||
|
||||
@@ -89,19 +89,19 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
|
||||
Intent i = getIntent();
|
||||
byte[] b = i.getByteArrayExtra("briar.GROUP_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
groupId = new GroupId(b);
|
||||
String groupName = i.getStringExtra("briar.GROUP_NAME");
|
||||
if(groupName == null) throw new IllegalStateException();
|
||||
if (groupName == null) throw new IllegalStateException();
|
||||
setTitle(groupName);
|
||||
minTimestamp = i.getLongExtra("briar.MIN_TIMESTAMP", -1);
|
||||
if(minTimestamp == -1) throw new IllegalStateException();
|
||||
if (minTimestamp == -1) throw new IllegalStateException();
|
||||
b = i.getByteArrayExtra("briar.PARENT_ID");
|
||||
if(b != null) parentId = new MessageId(b);
|
||||
if (b != null) parentId = new MessageId(b);
|
||||
|
||||
if(state != null) {
|
||||
if (state != null) {
|
||||
b = state.getByteArray("briar.LOCAL_AUTHOR_ID");
|
||||
if(b != null) localAuthorId = new AuthorId(b);
|
||||
if (b != null) localAuthorId = new AuthorId(b);
|
||||
}
|
||||
|
||||
LinearLayout layout = new LinearLayout(this);
|
||||
@@ -169,11 +169,11 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
Collection<LocalAuthor> localAuthors = db.getLocalAuthors();
|
||||
group = db.getGroup(groupId);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Load took " + duration + " ms");
|
||||
displayAuthorsAndGroup(localAuthors);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -184,18 +184,18 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
final Collection<LocalAuthor> localAuthors) {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
if(localAuthors.isEmpty()) throw new IllegalStateException();
|
||||
if (localAuthors.isEmpty()) throw new IllegalStateException();
|
||||
adapter.clear();
|
||||
for(LocalAuthor a : localAuthors)
|
||||
for (LocalAuthor a : localAuthors)
|
||||
adapter.add(new LocalAuthorItem(a));
|
||||
adapter.sort(LocalAuthorItemComparator.INSTANCE);
|
||||
adapter.notifyDataSetChanged();
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
LocalAuthorItem item = adapter.getItem(i);
|
||||
if(item == LocalAuthorItem.ANONYMOUS) continue;
|
||||
if(item == LocalAuthorItem.NEW) continue;
|
||||
if(item.getLocalAuthor().getId().equals(localAuthorId)) {
|
||||
if (item == LocalAuthorItem.ANONYMOUS) continue;
|
||||
if (item == LocalAuthorItem.NEW) continue;
|
||||
if (item.getLocalAuthor().getId().equals(localAuthorId)) {
|
||||
localAuthor = item.getLocalAuthor();
|
||||
spinner.setSelection(i);
|
||||
break;
|
||||
@@ -210,7 +210,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle state) {
|
||||
super.onSaveInstanceState(state);
|
||||
if(localAuthorId != null) {
|
||||
if (localAuthorId != null) {
|
||||
byte[] b = localAuthorId.getBytes();
|
||||
state.putByteArray("briar.LOCAL_AUTHOR_ID", b);
|
||||
}
|
||||
@@ -219,9 +219,9 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
@Override
|
||||
protected void onActivityResult(int request, int result, Intent data) {
|
||||
super.onActivityResult(request, result, data);
|
||||
if(request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
|
||||
if (request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
|
||||
byte[] b = data.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
localAuthorId = new AuthorId(b);
|
||||
loadAuthorsAndGroup();
|
||||
}
|
||||
@@ -230,10 +230,10 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
LocalAuthorItem item = adapter.getItem(position);
|
||||
if(item == LocalAuthorItem.ANONYMOUS) {
|
||||
if (item == LocalAuthorItem.ANONYMOUS) {
|
||||
localAuthor = null;
|
||||
localAuthorId = null;
|
||||
} else if(item == LocalAuthorItem.NEW) {
|
||||
} else if (item == LocalAuthorItem.NEW) {
|
||||
localAuthor = null;
|
||||
localAuthorId = null;
|
||||
Intent i = new Intent(this, CreateIdentityActivity.class);
|
||||
@@ -250,9 +250,9 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(group == null) throw new IllegalStateException();
|
||||
if (group == null) throw new IllegalStateException();
|
||||
String message = content.getText().toString();
|
||||
if(message.equals("")) return;
|
||||
if (message.equals("")) return;
|
||||
createMessage(StringUtils.toUtf8(message));
|
||||
Toast.makeText(this, R.string.post_sent_toast, LENGTH_LONG).show();
|
||||
finish();
|
||||
@@ -266,7 +266,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
timestamp = Math.max(timestamp, minTimestamp);
|
||||
Message m;
|
||||
try {
|
||||
if(localAuthor == null) {
|
||||
if (localAuthor == null) {
|
||||
m = messageFactory.createAnonymousMessage(parentId,
|
||||
group, "text/plain", timestamp, body);
|
||||
} else {
|
||||
@@ -277,9 +277,9 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
group, localAuthor, authorKey, "text/plain",
|
||||
timestamp, body);
|
||||
}
|
||||
} catch(GeneralSecurityException e) {
|
||||
} catch (GeneralSecurityException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
storeMessage(m);
|
||||
@@ -294,10 +294,10 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.addLocalMessage(m);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Storing message took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
}
|
||||
|
||||
private void enableOrDisableCreateButton() {
|
||||
if(progress == null) return; // Not created yet
|
||||
if (progress == null) return; // Not created yet
|
||||
createIdentityButton.setEnabled(validateNickname());
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
private boolean validateNickname() {
|
||||
String nickname = nicknameEntry.getText().toString();
|
||||
int length = StringUtils.toUtf8(nickname).length;
|
||||
if(length > MAX_AUTHOR_NAME_LENGTH) {
|
||||
if (length > MAX_AUTHOR_NAME_LENGTH) {
|
||||
feedback.setText(R.string.name_too_long);
|
||||
return false;
|
||||
}
|
||||
@@ -135,7 +135,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
|
||||
public void onClick(View view) {
|
||||
hideSoftKeyboard();
|
||||
if(!validateNickname()) return;
|
||||
if (!validateNickname()) return;
|
||||
// Replace the button with a progress bar
|
||||
createIdentityButton.setVisibility(GONE);
|
||||
progress.setVisibility(VISIBLE);
|
||||
@@ -160,10 +160,10 @@ implements OnEditorActionListener, OnClickListener {
|
||||
long now = System.currentTimeMillis();
|
||||
db.addLocalAuthor(a);
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Storing author took " + duration + " ms");
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
setResultAndFinish(a);
|
||||
|
||||
@@ -11,18 +11,18 @@ public class LocalAuthorItemComparator implements Comparator<LocalAuthorItem> {
|
||||
new LocalAuthorItemComparator();
|
||||
|
||||
public int compare(LocalAuthorItem a, LocalAuthorItem b) {
|
||||
if(a == b) return 0;
|
||||
if (a == b) return 0;
|
||||
// NEW comes after everything else
|
||||
if(a == NEW) return 1;
|
||||
if(b == NEW) return -1;
|
||||
if (a == NEW) return 1;
|
||||
if (b == NEW) return -1;
|
||||
// ANONYMOUS comes after everything else except NEW
|
||||
if(a == ANONYMOUS) return 1;
|
||||
if(b == ANONYMOUS) return -1;
|
||||
if (a == ANONYMOUS) return 1;
|
||||
if (b == ANONYMOUS) return -1;
|
||||
// Sort items in order of creation, so the oldest item is the default
|
||||
long aCreated = a.getLocalAuthor().getTimeCreated();
|
||||
long bCreated = b.getLocalAuthor().getTimeCreated();
|
||||
if(aCreated < bCreated) return -1;
|
||||
if(aCreated > bCreated) return 1;
|
||||
if (aCreated < bCreated) return -1;
|
||||
if (aCreated > bCreated) return 1;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ implements SpinnerAdapter {
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
if(list.isEmpty()) return 0;
|
||||
if (list.isEmpty()) return 0;
|
||||
return includeAnonymous ? list.size() + 2 : list.size() + 1;
|
||||
}
|
||||
|
||||
@@ -54,19 +54,19 @@ implements SpinnerAdapter {
|
||||
int pad = LayoutUtils.getPadding(ctx);
|
||||
name.setPadding(pad, pad, pad, pad);
|
||||
LocalAuthorItem item = getItem(position);
|
||||
if(item == ANONYMOUS) name.setText(R.string.anonymous);
|
||||
else if(item == NEW) name.setText(R.string.new_identity_item);
|
||||
if (item == ANONYMOUS) name.setText(R.string.anonymous);
|
||||
else if (item == NEW) name.setText(R.string.new_identity_item);
|
||||
else name.setText(item.getLocalAuthor().getName());
|
||||
return name;
|
||||
}
|
||||
|
||||
public LocalAuthorItem getItem(int position) {
|
||||
if(includeAnonymous) {
|
||||
if(position == list.size()) return ANONYMOUS;
|
||||
if(position == list.size() + 1) return NEW;
|
||||
if (includeAnonymous) {
|
||||
if (position == list.size()) return ANONYMOUS;
|
||||
if (position == list.size() + 1) return NEW;
|
||||
return list.get(position);
|
||||
} else {
|
||||
if(position == list.size()) return NEW;
|
||||
if (position == list.size()) return NEW;
|
||||
return list.get(position);
|
||||
}
|
||||
}
|
||||
@@ -81,8 +81,8 @@ implements SpinnerAdapter {
|
||||
name.setSingleLine();
|
||||
name.setEllipsize(END);
|
||||
LocalAuthorItem item = getItem(position);
|
||||
if(item == ANONYMOUS) name.setText(R.string.anonymous);
|
||||
else if(item == NEW) name.setText(R.string.new_identity_item);
|
||||
if (item == ANONYMOUS) name.setText(R.string.anonymous);
|
||||
else if (item == NEW) name.setText(R.string.new_identity_item);
|
||||
else name.setText(item.getLocalAuthor().getName());
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -60,34 +60,34 @@ implements InvitationListener {
|
||||
@Override
|
||||
public void onCreate(Bundle state) {
|
||||
super.onCreate(state);
|
||||
if(state == null) {
|
||||
if (state == null) {
|
||||
// This is a new activity
|
||||
setView(new ChooseIdentityView(this));
|
||||
} else {
|
||||
// Restore the activity's state
|
||||
byte[] b = state.getByteArray("briar.LOCAL_AUTHOR_ID");
|
||||
if(b != null) localAuthorId = new AuthorId(b);
|
||||
if (b != null) localAuthorId = new AuthorId(b);
|
||||
taskHandle = state.getLong("briar.TASK_HANDLE", -1);
|
||||
task = referenceManager.getReference(taskHandle,
|
||||
InvitationTask.class);
|
||||
if(task == null) {
|
||||
if (task == null) {
|
||||
// No background task - we must be in an initial or final state
|
||||
localInvitationCode = state.getInt("briar.LOCAL_CODE");
|
||||
remoteInvitationCode = state.getInt("briar.REMOTE_CODE");
|
||||
connectionFailed = state.getBoolean("briar.FAILED");
|
||||
contactName = state.getString("briar.CONTACT_NAME");
|
||||
if(contactName != null) {
|
||||
if (contactName != null) {
|
||||
localCompared = remoteCompared = true;
|
||||
localMatched = remoteMatched = true;
|
||||
}
|
||||
// Set the appropriate view for the state
|
||||
if(localInvitationCode == -1) {
|
||||
if (localInvitationCode == -1) {
|
||||
setView(new ChooseIdentityView(this));
|
||||
} else if(remoteInvitationCode == -1) {
|
||||
} else if (remoteInvitationCode == -1) {
|
||||
setView(new InvitationCodeView(this));
|
||||
} else if(connectionFailed) {
|
||||
} else if (connectionFailed) {
|
||||
setView(new ConnectionFailedView(this));
|
||||
} else if(contactName == null) {
|
||||
} else if (contactName == null) {
|
||||
setView(new CodesDoNotMatchView(this));
|
||||
} else {
|
||||
showToastAndFinish();
|
||||
@@ -108,22 +108,22 @@ implements InvitationListener {
|
||||
remoteMatched = s.getRemoteMatched();
|
||||
contactName = s.getContactName();
|
||||
// Set the appropriate view for the state
|
||||
if(localInvitationCode == -1) {
|
||||
if (localInvitationCode == -1) {
|
||||
setView(new ChooseIdentityView(this));
|
||||
} else if(remoteInvitationCode == -1) {
|
||||
} else if (remoteInvitationCode == -1) {
|
||||
setView(new InvitationCodeView(this));
|
||||
} else if(connectionFailed) {
|
||||
} else if (connectionFailed) {
|
||||
setView(new ConnectionFailedView(this));
|
||||
} else if(connected && localConfirmationCode == -1) {
|
||||
} else if (connected && localConfirmationCode == -1) {
|
||||
setView(new ConnectedView(this));
|
||||
} else if(localConfirmationCode == -1) {
|
||||
} else if (localConfirmationCode == -1) {
|
||||
setView(new ConnectionView(this));
|
||||
} else if(!localCompared) {
|
||||
} else if (!localCompared) {
|
||||
setView(new ConfirmationCodeView(this));
|
||||
} else if(!remoteCompared) {
|
||||
} else if (!remoteCompared) {
|
||||
setView(new WaitForContactView(this));
|
||||
} else if(localMatched && remoteMatched) {
|
||||
if(contactName == null) {
|
||||
} else if (localMatched && remoteMatched) {
|
||||
if (contactName == null) {
|
||||
setView(new ContactDetailsView(this));
|
||||
} else {
|
||||
showToastAndFinish();
|
||||
@@ -135,7 +135,7 @@ implements InvitationListener {
|
||||
}
|
||||
}
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if(adapter != null) bluetoothWasEnabled = adapter.isEnabled();
|
||||
if (adapter != null) bluetoothWasEnabled = adapter.isEnabled();
|
||||
}
|
||||
|
||||
private void showToastAndFinish() {
|
||||
@@ -159,11 +159,11 @@ implements InvitationListener {
|
||||
long now = System.currentTimeMillis();
|
||||
TransportConfig c = db.getConfig(new TransportId("bt"));
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading setting took " + duration + " ms");
|
||||
enableBluetooth = c.getBoolean("enable", true);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -173,7 +173,7 @@ implements InvitationListener {
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle state) {
|
||||
super.onSaveInstanceState(state);
|
||||
if(localAuthorId != null) {
|
||||
if (localAuthorId != null) {
|
||||
byte[] b = localAuthorId.getBytes();
|
||||
state.putByteArray("briar.LOCAL_AUTHOR_ID", b);
|
||||
}
|
||||
@@ -181,26 +181,26 @@ implements InvitationListener {
|
||||
state.putInt("briar.REMOTE_CODE", remoteInvitationCode);
|
||||
state.putBoolean("briar.FAILED", connectionFailed);
|
||||
state.putString("briar.CONTACT_NAME", contactName);
|
||||
if(task != null) state.putLong("briar.TASK_HANDLE", taskHandle);
|
||||
if (task != null) state.putLong("briar.TASK_HANDLE", taskHandle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if(task != null) task.removeListener(this);
|
||||
if(!bluetoothWasEnabled && !enableBluetooth) {
|
||||
if (task != null) task.removeListener(this);
|
||||
if (!bluetoothWasEnabled && !enableBluetooth) {
|
||||
BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if(adapter != null) adapter.disable();
|
||||
if (adapter != null) adapter.disable();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int request, int result, Intent data) {
|
||||
if(request == REQUEST_BLUETOOTH) {
|
||||
if(result != RESULT_CANCELED) reset(new InvitationCodeView(this));
|
||||
} else if(request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
|
||||
if (request == REQUEST_BLUETOOTH) {
|
||||
if (result != RESULT_CANCELED) reset(new InvitationCodeView(this));
|
||||
} else if (request == REQUEST_CREATE_IDENTITY && result == RESULT_OK) {
|
||||
byte[] b = data.getByteArrayExtra("briar.LOCAL_AUTHOR_ID");
|
||||
if(b == null) throw new IllegalStateException();
|
||||
if (b == null) throw new IllegalStateException();
|
||||
localAuthorId = new AuthorId(b);
|
||||
setView(new ChooseIdentityView(this));
|
||||
}
|
||||
@@ -232,11 +232,11 @@ implements InvitationListener {
|
||||
long now = System.currentTimeMillis();
|
||||
Collection<LocalAuthor> authors = db.getLocalAuthors();
|
||||
long duration = System.currentTimeMillis() - now;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Loading authors took " + duration + " ms");
|
||||
displayLocalAuthors(authors);
|
||||
} catch(DbException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
@@ -248,7 +248,7 @@ implements InvitationListener {
|
||||
runOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
AddContactView view = AddContactActivity.this.view;
|
||||
if(view instanceof ChooseIdentityView)
|
||||
if (view instanceof ChooseIdentityView)
|
||||
((ChooseIdentityView) view).displayLocalAuthors(authors);
|
||||
}
|
||||
});
|
||||
@@ -263,7 +263,7 @@ implements InvitationListener {
|
||||
}
|
||||
|
||||
int getLocalInvitationCode() {
|
||||
if(localInvitationCode == -1)
|
||||
if (localInvitationCode == -1)
|
||||
localInvitationCode = crypto.generateInvitationCode();
|
||||
return localInvitationCode;
|
||||
}
|
||||
@@ -273,8 +273,8 @@ implements InvitationListener {
|
||||
}
|
||||
|
||||
void remoteInvitationCodeEntered(int code) {
|
||||
if(localAuthorId == null) throw new IllegalStateException();
|
||||
if(localInvitationCode == -1) throw new IllegalStateException();
|
||||
if (localAuthorId == null) throw new IllegalStateException();
|
||||
if (localInvitationCode == -1) throw new IllegalStateException();
|
||||
remoteInvitationCode = code;
|
||||
setView(new ConnectionView(this));
|
||||
task = invitationTaskFactory.createTask(localAuthorId,
|
||||
@@ -293,10 +293,10 @@ implements InvitationListener {
|
||||
|
||||
void remoteConfirmationCodeEntered(int code) {
|
||||
localCompared = true;
|
||||
if(code == remoteConfirmationCode) {
|
||||
if (code == remoteConfirmationCode) {
|
||||
localMatched = true;
|
||||
if(remoteMatched) setView(new ContactDetailsView(this));
|
||||
else if(remoteCompared) setView(new CodesDoNotMatchView(this));
|
||||
if (remoteMatched) setView(new ContactDetailsView(this));
|
||||
else if (remoteCompared) setView(new CodesDoNotMatchView(this));
|
||||
else setView(new WaitForContactView(this));
|
||||
task.localConfirmationSucceeded();
|
||||
} else {
|
||||
@@ -353,7 +353,7 @@ implements InvitationListener {
|
||||
public void run() {
|
||||
remoteCompared = true;
|
||||
remoteMatched = true;
|
||||
if(localMatched)
|
||||
if (localMatched)
|
||||
setView(new ContactDetailsView(AddContactActivity.this));
|
||||
}
|
||||
});
|
||||
@@ -364,7 +364,7 @@ implements InvitationListener {
|
||||
public void run() {
|
||||
remoteCompared = true;
|
||||
remoteMatched = false;
|
||||
if(localMatched)
|
||||
if (localMatched)
|
||||
setView(new CodesDoNotMatchView(AddContactActivity.this));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -80,17 +80,17 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
// FIXME: The interaction between views and the container is horrible
|
||||
void displayLocalAuthors(Collection<LocalAuthor> authors) {
|
||||
adapter.clear();
|
||||
for(LocalAuthor a : authors) adapter.add(new LocalAuthorItem(a));
|
||||
for (LocalAuthor a : authors) adapter.add(new LocalAuthorItem(a));
|
||||
adapter.sort(LocalAuthorItemComparator.INSTANCE);
|
||||
adapter.notifyDataSetChanged();
|
||||
// If a local author has been selected, select it again
|
||||
AuthorId localAuthorId = container.getLocalAuthorId();
|
||||
if(localAuthorId == null) return;
|
||||
if (localAuthorId == null) return;
|
||||
int count = adapter.getCount();
|
||||
for(int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
LocalAuthorItem item = adapter.getItem(i);
|
||||
if(item == NEW) continue;
|
||||
if(item.getLocalAuthor().getId().equals(localAuthorId)) {
|
||||
if (item == NEW) continue;
|
||||
if (item.getLocalAuthor().getId().equals(localAuthorId)) {
|
||||
spinner.setSelection(i);
|
||||
return;
|
||||
}
|
||||
@@ -100,7 +100,7 @@ implements OnItemSelectedListener, OnClickListener {
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position,
|
||||
long id) {
|
||||
LocalAuthorItem item = adapter.getItem(position);
|
||||
if(item == NEW) {
|
||||
if (item == NEW) {
|
||||
container.setLocalAuthorId(null);
|
||||
Intent i = new Intent(container, CreateIdentityActivity.class);
|
||||
container.startActivityForResult(i, REQUEST_CREATE_IDENTITY);
|
||||
|
||||
@@ -55,7 +55,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
@Override
|
||||
protected void onTextChanged(CharSequence text, int start,
|
||||
int lengthBefore, int lengthAfter) {
|
||||
if(continueButton != null)
|
||||
if (continueButton != null)
|
||||
continueButton.setEnabled(getText().length() == 6);
|
||||
}
|
||||
};
|
||||
@@ -78,12 +78,12 @@ implements OnEditorActionListener, OnClickListener {
|
||||
}
|
||||
|
||||
public boolean onEditorAction(TextView textView, int actionId, KeyEvent e) {
|
||||
if(!validateAndReturnCode()) codeEntry.setText("");
|
||||
if (!validateAndReturnCode()) codeEntry.setText("");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onClick(View view) {
|
||||
if(!validateAndReturnCode()) codeEntry.setText("");
|
||||
if (!validateAndReturnCode()) codeEntry.setText("");
|
||||
}
|
||||
|
||||
private boolean validateAndReturnCode() {
|
||||
@@ -91,7 +91,7 @@ implements OnEditorActionListener, OnClickListener {
|
||||
int remoteCode;
|
||||
try {
|
||||
remoteCode = Integer.parseInt(remoteCodeString);
|
||||
} catch(NumberFormatException e) {
|
||||
} catch (NumberFormatException e) {
|
||||
return false;
|
||||
}
|
||||
// Hide the soft keyboard
|
||||
|
||||
@@ -14,11 +14,11 @@ public class AndroidUtils {
|
||||
@SuppressWarnings("deprecation")
|
||||
public static Collection<String> getSupportedArchitectures() {
|
||||
List<String> abis = new ArrayList<String>();
|
||||
if(Build.VERSION.SDK_INT >= 21) {
|
||||
for(String abi : Build.SUPPORTED_ABIS) abis.add(abi);
|
||||
} else if(Build.VERSION.SDK_INT >= 8) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
for (String abi : Build.SUPPORTED_ABIS) abis.add(abi);
|
||||
} else if (Build.VERSION.SDK_INT >= 8) {
|
||||
abis.add(Build.CPU_ABI);
|
||||
if(Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
|
||||
if (Build.CPU_ABI2 != null) abis.add(Build.CPU_ABI2);
|
||||
} else {
|
||||
abis.add(Build.CPU_ABI);
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public class AuthorView extends RelativeLayout {
|
||||
nameView.setSingleLine();
|
||||
nameView.setEllipsize(END);
|
||||
nameView.setPadding(pad, pad, pad, pad);
|
||||
if(name == null) nameView.setText(R.string.anonymous);
|
||||
if (name == null) nameView.setText(R.string.anonymous);
|
||||
else nameView.setText(name);
|
||||
LayoutParams leftOf = CommonLayoutParams.relative();
|
||||
leftOf.addRule(ALIGN_PARENT_LEFT);
|
||||
|
||||
@@ -52,12 +52,12 @@ public class StrengthMeter extends ProgressBar {
|
||||
}
|
||||
|
||||
public void setStrength(float strength) {
|
||||
if(strength < 0 || strength > 1) throw new IllegalArgumentException();
|
||||
if (strength < 0 || strength > 1) throw new IllegalArgumentException();
|
||||
int colour;
|
||||
if(strength < WEAK) colour = RED;
|
||||
else if(strength < QUITE_WEAK) colour = ORANGE;
|
||||
else if(strength < QUITE_STRONG) colour = YELLOW;
|
||||
else if(strength < STRONG) colour = LIME;
|
||||
if (strength < WEAK) colour = RED;
|
||||
else if (strength < QUITE_WEAK) colour = ORANGE;
|
||||
else if (strength < QUITE_STRONG) colour = YELLOW;
|
||||
else if (strength < STRONG) colour = LIME;
|
||||
else colour = GREEN;
|
||||
bar.getPaint().setColor(colour);
|
||||
setProgress((int) (strength * MAX));
|
||||
|
||||
@@ -115,13 +115,13 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
return BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
});
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IOException("Interrupted while getting BluetoothAdapter");
|
||||
} catch(ExecutionException e) {
|
||||
} catch (ExecutionException e) {
|
||||
throw new IOException(e.toString());
|
||||
}
|
||||
if(adapter == null) {
|
||||
if (adapter == null) {
|
||||
LOG.info("Bluetooth is not supported");
|
||||
return false;
|
||||
}
|
||||
@@ -133,11 +133,11 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
receiver = new BluetoothStateReceiver();
|
||||
appContext.registerReceiver(receiver, filter);
|
||||
// If Bluetooth is enabled, bind a socket - otherwise enable it
|
||||
if(adapter.isEnabled()) {
|
||||
if (adapter.isEnabled()) {
|
||||
bind();
|
||||
} else if(callback.getConfig().getBoolean("enable", true)) {
|
||||
} else if (callback.getConfig().getBoolean("enable", true)) {
|
||||
wasDisabled = true;
|
||||
if(adapter.enable()) LOG.info("Enabling Bluetooth");
|
||||
if (adapter.enable()) LOG.info("Enabling Bluetooth");
|
||||
else LOG.info("Could not enable Bluetooth");
|
||||
} else {
|
||||
LOG.info("Not enabling Bluetooth");
|
||||
@@ -148,8 +148,8 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
private void bind() {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
if(!isRunning()) return;
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (!isRunning()) return;
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Local address " + adapter.getAddress());
|
||||
// Advertise the Bluetooth address to contacts
|
||||
TransportProperties p = new TransportProperties();
|
||||
@@ -159,13 +159,13 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
BluetoothServerSocket ss = null;
|
||||
try {
|
||||
ss = InsecureBluetooth.listen(adapter, "RFCOMM", getUuid());
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
tryToClose(ss);
|
||||
return;
|
||||
}
|
||||
if(!isRunning()) {
|
||||
if (!isRunning()) {
|
||||
tryToClose(ss);
|
||||
return;
|
||||
}
|
||||
@@ -179,7 +179,7 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
private UUID getUuid() {
|
||||
String uuid = callback.getLocalProperties().get("uuid");
|
||||
if(uuid == null) {
|
||||
if (uuid == null) {
|
||||
byte[] random = new byte[UUID_BYTES];
|
||||
secureRandom.nextBytes(random);
|
||||
uuid = UUID.nameUUIDFromBytes(random).toString();
|
||||
@@ -192,23 +192,23 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
private void tryToClose(BluetoothServerSocket ss) {
|
||||
try {
|
||||
if(ss != null) ss.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
if (ss != null) ss.close();
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void acceptContactConnections() {
|
||||
while(isRunning()) {
|
||||
while (isRunning()) {
|
||||
BluetoothSocket s;
|
||||
try {
|
||||
s = socket.accept();
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
// This is expected when the socket is closed
|
||||
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
return;
|
||||
}
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
String address = s.getRemoteDevice().getAddress();
|
||||
LOG.info("Connection from " + address);
|
||||
}
|
||||
@@ -222,11 +222,11 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
public void stop() {
|
||||
running = false;
|
||||
if(receiver != null) appContext.unregisterReceiver(receiver);
|
||||
if (receiver != null) appContext.unregisterReceiver(receiver);
|
||||
tryToClose(socket);
|
||||
// Disable Bluetooth if we enabled it and it's still enabled
|
||||
if(wasDisabled && adapter.isEnabled()) {
|
||||
if(adapter.disable()) LOG.info("Disabling Bluetooth");
|
||||
if (wasDisabled && adapter.isEnabled()) {
|
||||
if (adapter.disable()) LOG.info("Disabling Bluetooth");
|
||||
else LOG.info("Could not disable Bluetooth");
|
||||
}
|
||||
}
|
||||
@@ -244,22 +244,22 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
}
|
||||
|
||||
public void poll(Collection<ContactId> connected) {
|
||||
if(!isRunning()) return;
|
||||
if (!isRunning()) return;
|
||||
// Try to connect to known devices in parallel
|
||||
Map<ContactId, TransportProperties> remote =
|
||||
callback.getRemoteProperties();
|
||||
for(Entry<ContactId, TransportProperties> e : remote.entrySet()) {
|
||||
for (Entry<ContactId, TransportProperties> e : remote.entrySet()) {
|
||||
final ContactId c = e.getKey();
|
||||
if(connected.contains(c)) continue;
|
||||
if (connected.contains(c)) continue;
|
||||
final String address = e.getValue().get("address");
|
||||
if(StringUtils.isNullOrEmpty(address)) continue;
|
||||
if (StringUtils.isNullOrEmpty(address)) continue;
|
||||
final String uuid = e.getValue().get("uuid");
|
||||
if(StringUtils.isNullOrEmpty(uuid)) continue;
|
||||
if (StringUtils.isNullOrEmpty(uuid)) continue;
|
||||
ioExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
if(!running) return;
|
||||
if (!running) return;
|
||||
BluetoothSocket s = connect(address, uuid);
|
||||
if(s != null)
|
||||
if (s != null)
|
||||
callback.outgoingConnectionCreated(c, wrapSocket(s));
|
||||
}
|
||||
});
|
||||
@@ -268,8 +268,8 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
private BluetoothSocket connect(String address, String uuid) {
|
||||
// Validate the address
|
||||
if(!BluetoothAdapter.checkBluetoothAddress(address)) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
if (!BluetoothAdapter.checkBluetoothAddress(address)) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.warning("Invalid address " + address);
|
||||
return null;
|
||||
}
|
||||
@@ -277,8 +277,8 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
UUID u;
|
||||
try {
|
||||
u = UUID.fromString(uuid);
|
||||
} catch(IllegalArgumentException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.warning("Invalid UUID " + uuid);
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.warning("Invalid UUID " + uuid);
|
||||
return null;
|
||||
}
|
||||
// Try to connect
|
||||
@@ -286,12 +286,12 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
BluetoothSocket s = null;
|
||||
try {
|
||||
s = InsecureBluetooth.createSocket(d, u);
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + address);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + address);
|
||||
s.connect();
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + address);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Connected to " + address);
|
||||
return s;
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(INFO))
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Failed to connect to " + address);
|
||||
tryToClose(s);
|
||||
return null;
|
||||
@@ -300,22 +300,22 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
private void tryToClose(BluetoothSocket s) {
|
||||
try {
|
||||
if(s != null) s.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
if (s != null) s.close();
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public DuplexTransportConnection createConnection(ContactId c) {
|
||||
if(!isRunning()) return null;
|
||||
if (!isRunning()) return null;
|
||||
TransportProperties p = callback.getRemoteProperties().get(c);
|
||||
if(p == null) return null;
|
||||
if (p == null) return null;
|
||||
String address = p.get("address");
|
||||
if(StringUtils.isNullOrEmpty(address)) return null;
|
||||
if (StringUtils.isNullOrEmpty(address)) return null;
|
||||
String uuid = p.get("uuid");
|
||||
if(StringUtils.isNullOrEmpty(uuid)) return null;
|
||||
if (StringUtils.isNullOrEmpty(uuid)) return null;
|
||||
BluetoothSocket s = connect(address, uuid);
|
||||
if(s == null) return null;
|
||||
if (s == null) return null;
|
||||
return new DroidtoothTransportConnection(this, s);
|
||||
}
|
||||
|
||||
@@ -325,17 +325,17 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
|
||||
public DuplexTransportConnection createInvitationConnection(PseudoRandom r,
|
||||
long timeout) {
|
||||
if(!isRunning()) return null;
|
||||
if (!isRunning()) return null;
|
||||
// Use the invitation codes to generate the UUID
|
||||
byte[] b = r.nextBytes(UUID_BYTES);
|
||||
UUID uuid = UUID.nameUUIDFromBytes(b);
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Invitation UUID " + uuid);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Invitation UUID " + uuid);
|
||||
// Bind a server socket for receiving invitation connections
|
||||
BluetoothServerSocket ss = null;
|
||||
try {
|
||||
ss = InsecureBluetooth.listen(adapter, "RFCOMM", uuid);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
tryToClose(ss);
|
||||
return null;
|
||||
}
|
||||
@@ -347,8 +347,8 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
// Wait for an incoming or outgoing connection
|
||||
try {
|
||||
BluetoothSocket s = socketLatch.waitForReference(timeout);
|
||||
if(s != null) return new DroidtoothTransportConnection(this, s);
|
||||
} catch(InterruptedException e) {
|
||||
if (s != null) return new DroidtoothTransportConnection(this, s);
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while exchanging invitations");
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
@@ -363,19 +363,19 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
@Override
|
||||
public void onReceive(Context ctx, Intent intent) {
|
||||
int state = intent.getIntExtra(EXTRA_STATE, 0);
|
||||
if(state == STATE_ON) {
|
||||
if (state == STATE_ON) {
|
||||
LOG.info("Bluetooth enabled");
|
||||
bind();
|
||||
} else if(state == STATE_OFF) {
|
||||
} else if (state == STATE_OFF) {
|
||||
LOG.info("Bluetooth disabled");
|
||||
tryToClose(socket);
|
||||
}
|
||||
int scanMode = intent.getIntExtra(EXTRA_SCAN_MODE, 0);
|
||||
if(scanMode == SCAN_MODE_NONE) {
|
||||
if (scanMode == SCAN_MODE_NONE) {
|
||||
LOG.info("Scan mode: None");
|
||||
} else if(scanMode == SCAN_MODE_CONNECTABLE) {
|
||||
} else if (scanMode == SCAN_MODE_CONNECTABLE) {
|
||||
LOG.info("Scan mode: Connectable");
|
||||
} else if(scanMode == SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
} else if (scanMode == SCAN_MODE_CONNECTABLE_DISCOVERABLE) {
|
||||
LOG.info("Scan mode: Discoverable");
|
||||
}
|
||||
}
|
||||
@@ -397,29 +397,29 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
@Override
|
||||
public void run() {
|
||||
long end = clock.currentTimeMillis() + timeout;
|
||||
while(!finished(end)) {
|
||||
while (!finished(end)) {
|
||||
// Discover nearby devices
|
||||
LOG.info("Discovering nearby devices");
|
||||
List<String> addresses;
|
||||
try {
|
||||
long now = clock.currentTimeMillis();
|
||||
addresses = discoverDevices(end - now);
|
||||
} catch(InterruptedException e) {
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while discovering devices");
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
}
|
||||
if(addresses.isEmpty()) {
|
||||
if (addresses.isEmpty()) {
|
||||
LOG.info("No devices discovered");
|
||||
continue;
|
||||
}
|
||||
// Connect to any device with the right UUID
|
||||
for(String address : addresses) {
|
||||
if(finished(end)) return;
|
||||
for (String address : addresses) {
|
||||
if (finished(end)) return;
|
||||
BluetoothSocket s = connect(address, uuid);
|
||||
if(s != null) {
|
||||
if (s != null) {
|
||||
LOG.info("Outgoing connection");
|
||||
if(!socketLatch.set(s)) {
|
||||
if (!socketLatch.set(s)) {
|
||||
LOG.info("Closing redundant connection");
|
||||
tryToClose(s);
|
||||
}
|
||||
@@ -455,13 +455,13 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
@Override
|
||||
public void onReceive(Context ctx, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if(action.equals(DISCOVERY_FINISHED)) {
|
||||
if (action.equals(DISCOVERY_FINISHED)) {
|
||||
LOG.info("Discovery finished");
|
||||
ctx.unregisterReceiver(this);
|
||||
finished.countDown();
|
||||
} else if(action.equals(FOUND)) {
|
||||
} else if (action.equals(FOUND)) {
|
||||
BluetoothDevice d = intent.getParcelableExtra(EXTRA_DEVICE);
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Discovered device: " + d.getAddress());
|
||||
addresses.add(d.getAddress());
|
||||
}
|
||||
@@ -491,13 +491,13 @@ class DroidtoothPlugin implements DuplexPlugin {
|
||||
try {
|
||||
BluetoothSocket s = serverSocket.accept();
|
||||
LOG.info("Incoming connection");
|
||||
if(!socketLatch.set(s)) {
|
||||
if (!socketLatch.set(s)) {
|
||||
LOG.info("Closing redundant connection");
|
||||
s.close();
|
||||
}
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
// This is expected when the socket is closed
|
||||
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,8 +49,8 @@ class DroidtoothTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
public void dispose(boolean exception, boolean recognised)
|
||||
throws IOException {
|
||||
if(halfClosed.getAndSet(true) || exception)
|
||||
if(!closed.getAndSet(true)) socket.close();
|
||||
if (halfClosed.getAndSet(true) || exception)
|
||||
if (!closed.getAndSet(true)) socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ class DroidtoothTransportConnection implements DuplexTransportConnection {
|
||||
}
|
||||
|
||||
public void dispose(boolean exception) throws IOException {
|
||||
if(halfClosed.getAndSet(true) || exception)
|
||||
if(!closed.getAndSet(true)) socket.close();
|
||||
if (halfClosed.getAndSet(true) || exception)
|
||||
if (!closed.getAndSet(true)) socket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class InsecureBluetooth {
|
||||
@SuppressLint("NewApi")
|
||||
static BluetoothServerSocket listen(BluetoothAdapter adapter, String name,
|
||||
UUID uuid) throws IOException {
|
||||
if(Build.VERSION.SDK_INT >= 10) {
|
||||
if (Build.VERSION.SDK_INT >= 10) {
|
||||
LOG.info("Listening with new API");
|
||||
return adapter.listenUsingInsecureRfcommWithServiceRecord(name,
|
||||
uuid);
|
||||
@@ -42,13 +42,13 @@ class InsecureBluetooth {
|
||||
+ ".RfcommChannelPicker";
|
||||
Class<?> channelPickerClass = null;
|
||||
Class<?>[] children = BluetoothAdapter.class.getDeclaredClasses();
|
||||
for(Class<?> c : children) {
|
||||
if(c.getCanonicalName().equals(className)) {
|
||||
for (Class<?> c : children) {
|
||||
if (c.getCanonicalName().equals(className)) {
|
||||
channelPickerClass = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(channelPickerClass == null)
|
||||
if (channelPickerClass == null)
|
||||
throw new IOException("Can't find channel picker class");
|
||||
Constructor<?> constructor =
|
||||
channelPickerClass.getDeclaredConstructor(UUID.class);
|
||||
@@ -58,7 +58,7 @@ class InsecureBluetooth {
|
||||
channelPickerClass.getDeclaredMethod("nextChannel");
|
||||
nextChannel.setAccessible(true);
|
||||
int channel = (Integer) nextChannel.invoke(channelPicker);
|
||||
if(channel == -1) throw new IOException("No available channels");
|
||||
if (channel == -1) throw new IOException("No available channels");
|
||||
// Listen on the channel
|
||||
BluetoothServerSocket socket = listen(channel);
|
||||
// Add a service record
|
||||
@@ -72,7 +72,7 @@ class InsecureBluetooth {
|
||||
addRfcommServiceRecord.setAccessible(true);
|
||||
int handle = (Integer) addRfcommServiceRecord.invoke(mService, name,
|
||||
new ParcelUuid(uuid), channel, new Binder());
|
||||
if(handle == -1) {
|
||||
if (handle == -1) {
|
||||
socket.close();
|
||||
throw new IOException("Can't register SDP record for " + name);
|
||||
}
|
||||
@@ -84,16 +84,16 @@ class InsecureBluetooth {
|
||||
setCloseHandler.setAccessible(true);
|
||||
setCloseHandler.invoke(socket, mHandler, handle);
|
||||
return socket;
|
||||
} catch(NoSuchMethodException e) {
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(NoSuchFieldException e) {
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(IllegalAccessException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(InstantiationException e) {
|
||||
} catch (InstantiationException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(InvocationTargetException e) {
|
||||
if(e.getCause() instanceof IOException) {
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof IOException) {
|
||||
throw (IOException) e.getCause();
|
||||
} else {
|
||||
throw new IOException(e.toString());
|
||||
@@ -116,21 +116,21 @@ class InsecureBluetooth {
|
||||
mSocket.getClass().getDeclaredMethod("bindListen");
|
||||
bindListen.setAccessible(true);
|
||||
int errno = (Integer) bindListen.invoke(mSocket);
|
||||
if(errno != 0) {
|
||||
if (errno != 0) {
|
||||
socket.close();
|
||||
throw new IOException("Can't bind: errno " + errno);
|
||||
}
|
||||
return socket;
|
||||
} catch(NoSuchMethodException e) {
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(NoSuchFieldException e) {
|
||||
} catch (NoSuchFieldException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(IllegalAccessException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(InstantiationException e) {
|
||||
} catch (InstantiationException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(InvocationTargetException e) {
|
||||
if(e.getCause() instanceof IOException) {
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof IOException) {
|
||||
throw (IOException) e.getCause();
|
||||
} else {
|
||||
throw new IOException(e.toString());
|
||||
@@ -141,7 +141,7 @@ class InsecureBluetooth {
|
||||
@SuppressLint("NewApi")
|
||||
static BluetoothSocket createSocket(BluetoothDevice device, UUID uuid)
|
||||
throws IOException {
|
||||
if(Build.VERSION.SDK_INT >= 10) {
|
||||
if (Build.VERSION.SDK_INT >= 10) {
|
||||
LOG.info("Creating socket with new API");
|
||||
return device.createInsecureRfcommSocketToServiceRecord(uuid);
|
||||
}
|
||||
@@ -154,14 +154,14 @@ class InsecureBluetooth {
|
||||
constructor.setAccessible(true);
|
||||
return constructor.newInstance(TYPE_RFCOMM, -1, false, true, device,
|
||||
-1, new ParcelUuid(uuid));
|
||||
} catch(NoSuchMethodException e) {
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(IllegalAccessException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(InstantiationException e) {
|
||||
} catch (InstantiationException e) {
|
||||
throw new IOException(e.toString());
|
||||
} catch(InvocationTargetException e) {
|
||||
if(e.getCause() instanceof IOException) {
|
||||
} catch (InvocationTargetException e) {
|
||||
if (e.getCause() instanceof IOException) {
|
||||
throw (IOException) e.getCause();
|
||||
} else {
|
||||
throw new IOException(e.toString());
|
||||
|
||||
@@ -45,7 +45,7 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||
@Override
|
||||
public void stop() {
|
||||
running = false;
|
||||
if(networkStateReceiver != null)
|
||||
if (networkStateReceiver != null)
|
||||
appContext.unregisterReceiver(networkStateReceiver);
|
||||
tryToClose(socket);
|
||||
}
|
||||
@@ -54,13 +54,13 @@ class AndroidLanTcpPlugin extends LanTcpPlugin {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context ctx, Intent i) {
|
||||
if(!running) return;
|
||||
if (!running) return;
|
||||
Object o = ctx.getSystemService(CONNECTIVITY_SERVICE);
|
||||
ConnectivityManager cm = (ConnectivityManager) o;
|
||||
NetworkInfo net = cm.getActiveNetworkInfo();
|
||||
if(net != null && net.getType() == TYPE_WIFI && net.isConnected()) {
|
||||
if (net != null && net.getType() == TYPE_WIFI && net.isConnected()) {
|
||||
LOG.info("Connected to Wi-Fi");
|
||||
if(socket == null || socket.isClosed()) bind();
|
||||
if (socket == null || socket.isClosed()) bind();
|
||||
} else {
|
||||
LOG.info("Not connected to Wi-Fi");
|
||||
tryToClose(socket);
|
||||
|
||||
@@ -100,7 +100,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
this.maxLatency = maxLatency;
|
||||
this.maxIdleTime = maxIdleTime;
|
||||
this.pollingInterval = pollingInterval;
|
||||
if(maxIdleTime > Integer.MAX_VALUE / 2)
|
||||
if (maxIdleTime > Integer.MAX_VALUE / 2)
|
||||
socketTimeout = Integer.MAX_VALUE;
|
||||
else socketTimeout = maxIdleTime * 2;
|
||||
torDirectory = appContext.getDir("tor", MODE_PRIVATE);
|
||||
@@ -131,16 +131,16 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
try {
|
||||
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
|
||||
LOG.info("Tor is already running");
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
LOG.info("Tor is not running");
|
||||
startProcess = true;
|
||||
// Install the binary, possibly overwriting an older version
|
||||
if(!installBinary()) {
|
||||
if (!installBinary()) {
|
||||
LOG.warning("Could not install Tor binary");
|
||||
return false;
|
||||
}
|
||||
// Install the GeoIP database and config file if necessary
|
||||
if(!isConfigInstalled() && !installConfig()) {
|
||||
if (!isConfigInstalled() && !installConfig()) {
|
||||
LOG.info("Could not install Tor config");
|
||||
return false;
|
||||
}
|
||||
@@ -160,31 +160,31 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
Process torProcess;
|
||||
try {
|
||||
torProcess = Runtime.getRuntime().exec(cmd, env, torDirectory);
|
||||
} catch(SecurityException e1) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e1.toString(), e1);
|
||||
} catch (SecurityException e1) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e1.toString(), e1);
|
||||
return false;
|
||||
}
|
||||
// Log the process's standard output until it detaches
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
Scanner stdout = new Scanner(torProcess.getInputStream());
|
||||
while(stdout.hasNextLine()) LOG.info(stdout.nextLine());
|
||||
while (stdout.hasNextLine()) LOG.info(stdout.nextLine());
|
||||
stdout.close();
|
||||
}
|
||||
try {
|
||||
// Wait for the process to detach or exit
|
||||
int exit = torProcess.waitFor();
|
||||
if(exit != 0) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
if (exit != 0) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.warning("Tor exited with value " + exit);
|
||||
return false;
|
||||
}
|
||||
// Wait for the auth cookie file to be created/updated
|
||||
if(!latch.await(COOKIE_TIMEOUT, MILLISECONDS)) {
|
||||
if (!latch.await(COOKIE_TIMEOUT, MILLISECONDS)) {
|
||||
LOG.warning("Auth cookie not created");
|
||||
if(LOG.isLoggable(INFO)) listFiles(torDirectory);
|
||||
if (LOG.isLoggable(INFO)) listFiles(torDirectory);
|
||||
return false;
|
||||
}
|
||||
} catch(InterruptedException e1) {
|
||||
} catch (InterruptedException e1) {
|
||||
LOG.warning("Interrupted while starting Tor");
|
||||
Thread.currentThread().interrupt();
|
||||
return false;
|
||||
@@ -203,9 +203,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
controlConnection.setEventHandler(this);
|
||||
controlConnection.setEvents(Arrays.asList(EVENTS));
|
||||
// If Tor was already running, find out whether it's bootstrapped
|
||||
if(!startProcess) {
|
||||
if (!startProcess) {
|
||||
String phase = controlConnection.getInfo("status/bootstrap-phase");
|
||||
if(phase != null && phase.contains("PROGRESS=100")) {
|
||||
if (phase != null && phase.contains("PROGRESS=100")) {
|
||||
LOG.info("Tor has already bootstrapped");
|
||||
bootstrapped = true;
|
||||
}
|
||||
@@ -228,13 +228,13 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
out = new FileOutputStream(torFile);
|
||||
copy(in, out);
|
||||
// Make the Tor binary executable
|
||||
if(!setExecutable(torFile)) {
|
||||
if (!setExecutable(torFile)) {
|
||||
LOG.warning("Could not make Tor binary executable");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
tryToClose(in);
|
||||
tryToClose(out);
|
||||
return false;
|
||||
@@ -260,8 +260,8 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
// Create a file to indicate that installation succeeded
|
||||
doneFile.createNewFile();
|
||||
return true;
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
tryToClose(in);
|
||||
tryToClose(out);
|
||||
return false;
|
||||
@@ -269,12 +269,12 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
}
|
||||
|
||||
private InputStream getTorInputStream() throws IOException {
|
||||
if(LOG.isLoggable(INFO))
|
||||
if (LOG.isLoggable(INFO))
|
||||
LOG.info("Installing Tor binary for " + architecture);
|
||||
String filename = "tor-" + architecture + ".zip";
|
||||
InputStream in = appContext.getResources().getAssets().open(filename);
|
||||
ZipInputStream zin = new ZipInputStream(in);
|
||||
if(zin.getNextEntry() == null) throw new IOException();
|
||||
if (zin.getNextEntry() == null) throw new IOException();
|
||||
return zin;
|
||||
}
|
||||
|
||||
@@ -282,7 +282,7 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
String filename = "geoip.zip";
|
||||
InputStream in = appContext.getResources().getAssets().open(filename);
|
||||
ZipInputStream zin = new ZipInputStream(in);
|
||||
if(zin.getNextEntry() == null) throw new IOException();
|
||||
if (zin.getNextEntry() == null) throw new IOException();
|
||||
return zin;
|
||||
}
|
||||
|
||||
@@ -292,9 +292,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
|
||||
private void copy(InputStream in, OutputStream out) throws IOException {
|
||||
byte[] buf = new byte[4096];
|
||||
while(true) {
|
||||
while (true) {
|
||||
int read = in.read(buf);
|
||||
if(read == -1) break;
|
||||
if (read == -1) break;
|
||||
out.write(buf, 0, read);
|
||||
}
|
||||
in.close();
|
||||
@@ -303,19 +303,19 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
private boolean setExecutable(File f) {
|
||||
if(Build.VERSION.SDK_INT >= 9) {
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
return f.setExecutable(true, true);
|
||||
} else {
|
||||
String[] command = { "chmod", "700", f.getAbsolutePath() };
|
||||
try {
|
||||
return Runtime.getRuntime().exec(command).waitFor() == 0;
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InterruptedException e) {
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while executing chmod");
|
||||
Thread.currentThread().interrupt();
|
||||
} catch(SecurityException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (SecurityException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -323,22 +323,22 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
|
||||
private void tryToClose(InputStream in) {
|
||||
try {
|
||||
if(in != null) in.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
if (in != null) in.close();
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void tryToClose(OutputStream out) {
|
||||
try {
|
||||
if(out != null) out.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
if (out != null) out.close();
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void listFiles(File f) {
|
||||
if(f.isDirectory()) for(File child : f.listFiles()) listFiles(child);
|
||||
if (f.isDirectory()) for (File child : f.listFiles()) listFiles(child);
|
||||
else LOG.info(f.getAbsolutePath());
|
||||
}
|
||||
|
||||
@@ -347,9 +347,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
FileInputStream in = new FileInputStream(f);
|
||||
try {
|
||||
int offset = 0;
|
||||
while(offset < b.length) {
|
||||
while (offset < b.length) {
|
||||
int read = in.read(b, offset, b.length - offset);
|
||||
if(read == -1) throw new EOFException();
|
||||
if (read == -1) throw new EOFException();
|
||||
offset += read;
|
||||
}
|
||||
return b;
|
||||
@@ -364,19 +364,19 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
// If there's already a port number stored in config, reuse it
|
||||
String portString = callback.getConfig().get("port");
|
||||
int port;
|
||||
if(StringUtils.isNullOrEmpty(portString)) port = 0;
|
||||
if (StringUtils.isNullOrEmpty(portString)) port = 0;
|
||||
else port = Integer.parseInt(portString);
|
||||
// Bind a server socket to receive connections from Tor
|
||||
ServerSocket ss = null;
|
||||
try {
|
||||
ss = new ServerSocket();
|
||||
ss.bind(new InetSocketAddress("127.0.0.1", port));
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING))
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
tryToClose(ss);
|
||||
}
|
||||
if(!running) {
|
||||
if (!running) {
|
||||
tryToClose(ss);
|
||||
return;
|
||||
}
|
||||
@@ -400,15 +400,15 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
|
||||
private void tryToClose(ServerSocket ss) {
|
||||
try {
|
||||
if(ss != null) ss.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
if (ss != null) ss.close();
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void publishHiddenService(String port) {
|
||||
if(!running) return;
|
||||
if(!hostnameFile.exists()) {
|
||||
if (!running) return;
|
||||
if (!hostnameFile.exists()) {
|
||||
LOG.info("Creating hidden service");
|
||||
try {
|
||||
// Watch for the hostname file being created/updated
|
||||
@@ -424,15 +424,15 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
controlConnection.setConf(config);
|
||||
controlConnection.saveConf();
|
||||
// Wait for the hostname file to be created/updated
|
||||
if(!latch.await(HOSTNAME_TIMEOUT, MILLISECONDS)) {
|
||||
if (!latch.await(HOSTNAME_TIMEOUT, MILLISECONDS)) {
|
||||
LOG.warning("Hidden service not created");
|
||||
if(LOG.isLoggable(INFO)) listFiles(torDirectory);
|
||||
if (LOG.isLoggable(INFO)) listFiles(torDirectory);
|
||||
return;
|
||||
}
|
||||
if(!running) return;
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch(InterruptedException e) {
|
||||
if (!running) return;
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (InterruptedException e) {
|
||||
LOG.warning("Interrupted while creating hidden service");
|
||||
Thread.currentThread().interrupt();
|
||||
return;
|
||||
@@ -441,24 +441,24 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
// Publish the hidden service's onion hostname in transport properties
|
||||
try {
|
||||
String hostname = new String(read(hostnameFile), "UTF-8").trim();
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Hidden service " + hostname);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Hidden service " + hostname);
|
||||
TransportProperties p = new TransportProperties();
|
||||
p.put("onion", hostname);
|
||||
callback.mergeLocalProperties(p);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void acceptContactConnections(ServerSocket ss) {
|
||||
while(running) {
|
||||
while (running) {
|
||||
Socket s;
|
||||
try {
|
||||
s = ss.accept();
|
||||
s.setSoTimeout(socketTimeout);
|
||||
} catch(IOException e) {
|
||||
} catch (IOException e) {
|
||||
// This is expected when the socket is closed
|
||||
if(LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
if (LOG.isLoggable(INFO)) LOG.info(e.toString());
|
||||
return;
|
||||
}
|
||||
LOG.info("Connection received");
|
||||
@@ -468,9 +468,9 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
}
|
||||
|
||||
private void enableNetwork(boolean enable) throws IOException {
|
||||
if(!running) return;
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Enabling network: " + enable);
|
||||
if(!enable) circuitBuilt.set(false);
|
||||
if (!running) return;
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Enabling network: " + enable);
|
||||
if (!enable) circuitBuilt.set(false);
|
||||
networkEnabled = enable;
|
||||
controlConnection.setConf("DisableNetwork", enable ? "0" : "1");
|
||||
}
|
||||
@@ -478,21 +478,21 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
public void stop() throws IOException {
|
||||
running = false;
|
||||
tryToClose(socket);
|
||||
if(networkStateReceiver != null)
|
||||
if (networkStateReceiver != null)
|
||||
appContext.unregisterReceiver(networkStateReceiver);
|
||||
try {
|
||||
LOG.info("Stopping Tor");
|
||||
if(controlSocket == null)
|
||||
if (controlSocket == null)
|
||||
controlSocket = new Socket("127.0.0.1", CONTROL_PORT);
|
||||
if(controlConnection == null) {
|
||||
if (controlConnection == null) {
|
||||
controlConnection = new TorControlConnection(controlSocket);
|
||||
controlConnection.authenticate(read(cookieFile));
|
||||
}
|
||||
controlConnection.setConf("DisableNetwork", "1");
|
||||
controlConnection.shutdownTor("TERM");
|
||||
controlSocket.close();
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,41 +509,41 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
}
|
||||
|
||||
public void poll(Collection<ContactId> connected) {
|
||||
if(!isRunning()) return;
|
||||
for(ContactId c : callback.getRemoteProperties().keySet())
|
||||
if(!connected.contains(c)) connectAndCallBack(c);
|
||||
if (!isRunning()) return;
|
||||
for (ContactId c : callback.getRemoteProperties().keySet())
|
||||
if (!connected.contains(c)) connectAndCallBack(c);
|
||||
}
|
||||
|
||||
private void connectAndCallBack(final ContactId c) {
|
||||
ioExecutor.execute(new Runnable() {
|
||||
public void run() {
|
||||
DuplexTransportConnection d = createConnection(c);
|
||||
if(d != null) callback.outgoingConnectionCreated(c, d);
|
||||
if (d != null) callback.outgoingConnectionCreated(c, d);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public DuplexTransportConnection createConnection(ContactId c) {
|
||||
if(!isRunning()) return null;
|
||||
if (!isRunning()) return null;
|
||||
TransportProperties p = callback.getRemoteProperties().get(c);
|
||||
if(p == null) return null;
|
||||
if (p == null) return null;
|
||||
String onion = p.get("onion");
|
||||
if(StringUtils.isNullOrEmpty(onion)) return null;
|
||||
if(!ONION.matcher(onion).matches()) {
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Invalid hostname: " + onion);
|
||||
if (StringUtils.isNullOrEmpty(onion)) return null;
|
||||
if (!ONION.matcher(onion).matches()) {
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Invalid hostname: " + onion);
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Connecting to " + onion);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Connecting to " + onion);
|
||||
controlConnection.forgetHiddenService(onion.substring(0, 16));
|
||||
Socks5Proxy proxy = new Socks5Proxy("127.0.0.1", SOCKS_PORT);
|
||||
proxy.resolveAddrLocally(false);
|
||||
Socket s = new SocksSocket(proxy, onion, 80);
|
||||
s.setSoTimeout(socketTimeout);
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Connected to " + onion);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Connected to " + onion);
|
||||
return new TorTransportConnection(this, s);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(INFO)) LOG.info("Could not connect to " + onion);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(INFO)) LOG.info("Could not connect to " + onion);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -558,16 +558,16 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
}
|
||||
|
||||
public void circuitStatus(String status, String id, String path) {
|
||||
if(status.equals("BUILT") && !circuitBuilt.getAndSet(true)) {
|
||||
if (status.equals("BUILT") && !circuitBuilt.getAndSet(true)) {
|
||||
LOG.info("First circuit built");
|
||||
if(isRunning()) callback.pollNow();
|
||||
if (isRunning()) callback.pollNow();
|
||||
}
|
||||
}
|
||||
|
||||
public void streamStatus(String status, String id, String target) {}
|
||||
|
||||
public void orConnStatus(String status, String orName) {
|
||||
if(LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
|
||||
if (LOG.isLoggable(INFO)) LOG.info("OR connection " + status);
|
||||
}
|
||||
|
||||
public void bandwidthUsed(long read, long written) {}
|
||||
@@ -575,10 +575,10 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
public void newDescriptors(List<String> orList) {}
|
||||
|
||||
public void message(String severity, String msg) {
|
||||
if(LOG.isLoggable(INFO)) LOG.info(severity + " " + msg);
|
||||
if(severity.equals("NOTICE") && msg.startsWith("Bootstrapped 100%")) {
|
||||
if (LOG.isLoggable(INFO)) LOG.info(severity + " " + msg);
|
||||
if (severity.equals("NOTICE") && msg.startsWith("Bootstrapped 100%")) {
|
||||
bootstrapped = true;
|
||||
if(isRunning()) callback.pollNow();
|
||||
if (isRunning()) callback.pollNow();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -604,26 +604,26 @@ class TorPlugin implements DuplexPlugin, EventHandler {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context ctx, Intent i) {
|
||||
if(!running) return;
|
||||
if (!running) return;
|
||||
boolean online = !i.getBooleanExtra(EXTRA_NO_CONNECTIVITY, false);
|
||||
if(online) {
|
||||
if (online) {
|
||||
// Some devices fail to set EXTRA_NO_CONNECTIVITY, double check
|
||||
Object o = ctx.getSystemService(CONNECTIVITY_SERVICE);
|
||||
ConnectivityManager cm = (ConnectivityManager) o;
|
||||
NetworkInfo net = cm.getActiveNetworkInfo();
|
||||
if(net == null || !net.isConnected()) online = false;
|
||||
if (net == null || !net.isConnected()) online = false;
|
||||
}
|
||||
String country = locationUtils.getCurrentCountry();
|
||||
if(LOG.isLoggable(INFO)) {
|
||||
if (LOG.isLoggable(INFO)) {
|
||||
LOG.info("Online: " + online);
|
||||
if("".equals(country)) LOG.info("Country code unknown");
|
||||
if ("".equals(country)) LOG.info("Country code unknown");
|
||||
else LOG.info("Country code: " + country);
|
||||
}
|
||||
boolean blocked = TorNetworkMetadata.isTorProbablyBlocked(country);
|
||||
try {
|
||||
enableNetwork(online && !blocked);
|
||||
} catch(IOException e) {
|
||||
if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
} catch (IOException e) {
|
||||
if (LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,21 +40,21 @@ public class TorPluginFactory implements DuplexPluginFactory {
|
||||
public DuplexPlugin createPlugin(DuplexPluginCallback callback) {
|
||||
// Check that we have a Tor binary for this architecture
|
||||
String architecture = null;
|
||||
for(String abi : AndroidUtils.getSupportedArchitectures()) {
|
||||
if(abi.startsWith("x86")) {
|
||||
for (String abi : AndroidUtils.getSupportedArchitectures()) {
|
||||
if (abi.startsWith("x86")) {
|
||||
architecture = "x86";
|
||||
break;
|
||||
} else if(abi.startsWith("armeabi")) {
|
||||
} else if (abi.startsWith("armeabi")) {
|
||||
architecture = "arm";
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(architecture == null) {
|
||||
if (architecture == null) {
|
||||
LOG.info("Tor is not supported on this architecture");
|
||||
return null;
|
||||
}
|
||||
// Use position-independent executable for SDK >= 16
|
||||
if(Build.VERSION.SDK_INT >= 16) architecture += "-pie";
|
||||
if (Build.VERSION.SDK_INT >= 16) architecture += "-pie";
|
||||
return new TorPlugin(ioExecutor,appContext, locationUtils, callback,
|
||||
architecture, MAX_LATENCY, MAX_IDLE_TIME, POLLING_INTERVAL);
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ class TorTransportConnection implements DuplexTransportConnection {
|
||||
|
||||
public void dispose(boolean exception, boolean recognised)
|
||||
throws IOException {
|
||||
if(halfClosed.getAndSet(true) || exception)
|
||||
if(!closed.getAndSet(true)) socket.close();
|
||||
if (halfClosed.getAndSet(true) || exception)
|
||||
if (!closed.getAndSet(true)) socket.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,8 +72,8 @@ class TorTransportConnection implements DuplexTransportConnection {
|
||||
}
|
||||
|
||||
public void dispose(boolean exception) throws IOException {
|
||||
if(halfClosed.getAndSet(true) || exception)
|
||||
if(!closed.getAndSet(true)) socket.close();
|
||||
if (halfClosed.getAndSet(true) || exception)
|
||||
if (!closed.getAndSet(true)) socket.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class AndroidFileUtils implements FileUtils {
|
||||
@SuppressLint("NewApi")
|
||||
@SuppressWarnings("deprecation")
|
||||
public long getTotalSpace(File f) throws IOException {
|
||||
if(Build.VERSION.SDK_INT >= 9) return f.getTotalSpace();
|
||||
if (Build.VERSION.SDK_INT >= 9) return f.getTotalSpace();
|
||||
StatFs s = new StatFs(f.getAbsolutePath());
|
||||
// These deprecated methods are the best thing available for SDK < 9
|
||||
return (long) s.getBlockCount() * s.getBlockSize();
|
||||
@@ -23,7 +23,7 @@ public class AndroidFileUtils implements FileUtils {
|
||||
@SuppressLint("NewApi")
|
||||
@SuppressWarnings("deprecation")
|
||||
public long getFreeSpace(File f) throws IOException {
|
||||
if(Build.VERSION.SDK_INT >= 9) return f.getUsableSpace();
|
||||
if (Build.VERSION.SDK_INT >= 9) return f.getUsableSpace();
|
||||
StatFs s = new StatFs(f.getAbsolutePath());
|
||||
// These deprecated methods are the best thing available for SDK < 9
|
||||
return (long) s.getAvailableBlocks() * s.getBlockSize();
|
||||
|
||||
@@ -47,14 +47,14 @@ class AndroidLocationUtils implements LocationUtils {
|
||||
@SuppressLint("DefaultLocale")
|
||||
public String getCurrentCountry() {
|
||||
String countryCode = getCountryFromPhoneNetwork();
|
||||
if(!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
|
||||
if (!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
|
||||
// Disabled because it involves a network call; requires
|
||||
// ACCESS_FINE_LOCATION
|
||||
// countryCode = getCountryFromLocation();
|
||||
// if(!TextUtils.isEmpty(countryCode)) return countryCode;
|
||||
// if (!TextUtils.isEmpty(countryCode)) return countryCode;
|
||||
LOG.info("Falling back to SIM card country");
|
||||
countryCode = getCountryFromSimCard();
|
||||
if(!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
|
||||
if (!TextUtils.isEmpty(countryCode)) return countryCode.toUpperCase();
|
||||
LOG.info("Falling back to user-defined locale");
|
||||
return Locale.getDefault().getCountry();
|
||||
}
|
||||
|
||||
@@ -15,10 +15,10 @@ class AndroidSeedProvider extends LinuxSeedProvider {
|
||||
out.writeInt(android.os.Process.myTid());
|
||||
out.writeInt(android.os.Process.myUid());
|
||||
String fingerprint = Build.FINGERPRINT;
|
||||
if(fingerprint != null) out.writeUTF(fingerprint);
|
||||
if(Build.VERSION.SDK_INT >= 9) {
|
||||
if (fingerprint != null) out.writeUTF(fingerprint);
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
String serial = Build.SERIAL;
|
||||
if(serial != null) out.writeUTF(serial);
|
||||
if (serial != null) out.writeUTF(serial);
|
||||
}
|
||||
super.writeToEntropyPool(out);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user