From abd25f4010394abc30462c73c08229445aba5525 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Wed, 13 Jan 2016 17:28:18 +0100 Subject: [PATCH] Minor bugfixes & renamed 'security' to 'cryptography --- app/build.gradle | 4 ++-- .../ch/dissem/apps/abit/MainActivity.java | 6 +++-- ...Security.java => AndroidCryptography.java} | 6 ++--- .../apps/abit/listener/WifiReceiver.java | 22 ++++++++----------- .../repository/AndroidAddressRepository.java | 14 ++++-------- .../abit/repository/AndroidInventory.java | 1 + .../repository/AndroidMessageRepository.java | 21 +++++------------- .../AndroidProofOfWorkRepository.java | 16 +++++--------- .../dissem/apps/abit/service/Singleton.java | 4 ++-- .../abit/synchronization/SyncService.java | 12 ---------- .../drawable/ic_notification_full_node.xml | 2 +- .../drawable/ic_notification_new_message.xml | 2 +- .../ic_notification_proof_of_work.xml | 2 +- .../res/drawable/ic_notification_warning.xml | 2 +- app/src/main/res/values/strings.xml | 2 +- store/icon.svg | 7 ++++-- 16 files changed, 46 insertions(+), 77 deletions(-) rename app/src/main/java/ch/dissem/apps/abit/adapter/{AndroidSecurity.java => AndroidCryptography.java} (86%) diff --git a/app/build.gradle b/app/build.gradle index 1b733ab..f66586f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -7,7 +7,7 @@ android { defaultConfig { applicationId "ch.dissem.apps.abit" - minSdkVersion 15 + minSdkVersion 19 targetSdkVersion 23 versionCode 1 versionName "1.0" @@ -37,7 +37,7 @@ dependencies { compile 'ch.dissem.jabit:jabit-domain:0.2.1-SNAPSHOT' compile 'ch.dissem.jabit:jabit-networking:0.2.1-SNAPSHOT' - compile 'ch.dissem.jabit:jabit-security-spongy:0.2.1-SNAPSHOT' + compile 'ch.dissem.jabit:jabit-cryptography-spongy:0.2.1-SNAPSHOT' compile 'ch.dissem.jabit:jabit-extensions:0.2.1-SNAPSHOT' compile 'org.slf4j:slf4j-android:1.7.12' diff --git a/app/src/main/java/ch/dissem/apps/abit/MainActivity.java b/app/src/main/java/ch/dissem/apps/abit/MainActivity.java index 1d2a418..5bda190 100644 --- a/app/src/main/java/ch/dissem/apps/abit/MainActivity.java +++ b/app/src/main/java/ch/dissem/apps/abit/MainActivity.java @@ -43,6 +43,7 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Objects; import ch.dissem.apps.abit.listener.ActionBarListener; import ch.dissem.apps.abit.listener.ListSelectionListener; @@ -438,8 +439,9 @@ public class MainActivity extends AppCompatActivity @Override public void updateTitle(CharSequence title) { - //noinspection ConstantConditions - getSupportActionBar().setTitle(title); + if (getSupportActionBar() != null) { + getSupportActionBar().setTitle(title); + } } public Label getSelectedLabel() { diff --git a/app/src/main/java/ch/dissem/apps/abit/adapter/AndroidSecurity.java b/app/src/main/java/ch/dissem/apps/abit/adapter/AndroidCryptography.java similarity index 86% rename from app/src/main/java/ch/dissem/apps/abit/adapter/AndroidSecurity.java rename to app/src/main/java/ch/dissem/apps/abit/adapter/AndroidCryptography.java index e495ff1..8aed5be 100644 --- a/app/src/main/java/ch/dissem/apps/abit/adapter/AndroidSecurity.java +++ b/app/src/main/java/ch/dissem/apps/abit/adapter/AndroidCryptography.java @@ -16,7 +16,7 @@ import ch.dissem.bitmessage.entity.payload.Broadcast; import ch.dissem.bitmessage.entity.valueobject.Label; import ch.dissem.bitmessage.factory.Factory; import ch.dissem.bitmessage.ports.ProofOfWorkEngine; -import ch.dissem.bitmessage.security.sc.SpongySecurity; +import ch.dissem.bitmessage.cryptography.sc.SpongyCryptography; import ch.dissem.bitmessage.utils.UnixTime; import static ch.dissem.apps.abit.util.Constants.PREFERENCE_SERVER_POW; @@ -27,8 +27,8 @@ import static ch.dissem.bitmessage.utils.UnixTime.DAY; /** * @author Christian Basler */ -public class AndroidSecurity extends SpongySecurity { - public AndroidSecurity() { +public class AndroidCryptography extends SpongyCryptography { + public AndroidCryptography() { PRNGFixes.apply(); } } diff --git a/app/src/main/java/ch/dissem/apps/abit/listener/WifiReceiver.java b/app/src/main/java/ch/dissem/apps/abit/listener/WifiReceiver.java index ca34809..74df713 100644 --- a/app/src/main/java/ch/dissem/apps/abit/listener/WifiReceiver.java +++ b/app/src/main/java/ch/dissem/apps/abit/listener/WifiReceiver.java @@ -5,11 +5,6 @@ import android.content.Context; import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; -import android.net.wifi.SupplicantState; -import android.net.wifi.WifiManager; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import ch.dissem.apps.abit.service.Singleton; import ch.dissem.apps.abit.util.Preferences; @@ -20,20 +15,21 @@ public class WifiReceiver extends BroadcastReceiver { public void onReceive(Context ctx, Intent intent) { if (Preferences.isWifiOnly(ctx)) { BitmessageContext bmc = Singleton.getBitmessageContext(ctx); - ConnectivityManager conMan = (ConnectivityManager) ctx.getSystemService(Context - .CONNECTIVITY_SERVICE); - NetworkInfo netInfo = conMan.getActiveNetworkInfo(); - if (netInfo != null && netInfo.getType() != ConnectivityManager.TYPE_WIFI - && !bmc.isRunning()) { + if (!isConnectedToWifi(ctx) && bmc.isRunning()) { bmc.shutdown(); } } } public static boolean isConnectedToWifi(Context ctx) { - WifiManager wifiManager = (WifiManager) ctx.getSystemService(Context.WIFI_SERVICE); - SupplicantState state = wifiManager.getConnectionInfo().getSupplicantState(); - return state == SupplicantState.COMPLETED; + NetworkInfo netInfo = getNetworkInfo(ctx); + return netInfo != null && netInfo.getType() == ConnectivityManager.TYPE_WIFI; + } + + private static NetworkInfo getNetworkInfo(Context ctx) { + ConnectivityManager conMan = (ConnectivityManager) ctx.getSystemService(Context + .CONNECTIVITY_SERVICE); + return conMan.getActiveNetworkInfo(); } } \ No newline at end of file diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidAddressRepository.java b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidAddressRepository.java index abf123a..997270b 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidAddressRepository.java +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidAddressRepository.java @@ -121,12 +121,11 @@ public class AndroidAddressRepository implements AddressRepository { }; SQLiteDatabase db = sql.getReadableDatabase(); - Cursor c = db.query( + try (Cursor c = db.query( TABLE_NAME, projection, where, null, null, null, null - ); - try { + )) { c.moveToFirst(); while (!c.isAfterLast()) { BitmessageAddress address; @@ -158,8 +157,6 @@ public class AndroidAddressRepository implements AddressRepository { } } catch (IOException e) { LOG.error(e.getMessage(), e); - } finally { - c.close(); } return result; } @@ -179,13 +176,10 @@ public class AndroidAddressRepository implements AddressRepository { private boolean exists(BitmessageAddress address) { SQLiteDatabase db = sql.getReadableDatabase(); - Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM Address WHERE address='" + address - .getAddress() + "'", null); - try { + try (Cursor cursor = db.rawQuery("SELECT COUNT(*) FROM Address WHERE address='" + address + .getAddress() + "'", null)) { cursor.moveToFirst(); return cursor.getInt(0) > 0; - } finally { - cursor.close(); } } diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidInventory.java b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidInventory.java index 56ece70..86aa1f7 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidInventory.java +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidInventory.java @@ -89,6 +89,7 @@ public class AndroidInventory implements Inventory { } finally { c.close(); } + LOG.info("Inventory size: " + result.size()); return result; } diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java index f33c91b..a186fd3 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java @@ -108,20 +108,17 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont }; SQLiteDatabase db = sql.getReadableDatabase(); - Cursor c = db.query( + try (Cursor c = db.query( LBL_TABLE_NAME, projection, where, null, null, null, LBL_COLUMN_ORDER - ); - try { + )) { c.moveToFirst(); while (!c.isAfterLast()) { result.add(getLabel(c)); c.moveToNext(); } - } finally { - c.close(); } return result; } @@ -174,16 +171,13 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont where = ""; } SQLiteDatabase db = sql.getReadableDatabase(); - Cursor c = db.query( + try (Cursor c = db.query( TABLE_NAME, new String[]{COLUMN_ID}, where + "id IN (SELECT message_id FROM Message_Label WHERE label_id IN (" + "SELECT id FROM Label WHERE type = '" + Label.Type.UNREAD.name() + "'))", null, null, null, null - ); - try { + )) { return c.getColumnCount(); - } finally { - c.close(); } } @@ -245,13 +239,12 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont }; SQLiteDatabase db = sql.getReadableDatabase(); - Cursor c = db.query( + try (Cursor c = db.query( TABLE_NAME, projection, where, null, null, null, COLUMN_RECEIVED + " DESC" - ); - try { + )) { c.moveToFirst(); while (!c.isAfterLast()) { byte[] iv = c.getBlob(c.getColumnIndex(COLUMN_IV)); @@ -277,8 +270,6 @@ public class AndroidMessageRepository implements MessageRepository, InternalCont } } catch (IOException e) { LOG.error(e.getMessage(), e); - } finally { - c.close(); } return result; } diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidProofOfWorkRepository.java b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidProofOfWorkRepository.java index 2273df0..6a96eee 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidProofOfWorkRepository.java +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidProofOfWorkRepository.java @@ -52,12 +52,11 @@ public class AndroidProofOfWorkRepository implements ProofOfWorkRepository { }; SQLiteDatabase db = sql.getReadableDatabase(); - Cursor c = db.query( + try (Cursor c = db.query( TABLE_NAME, projection, "initial_hash = X'" + Strings.hex(initialHash) + "'", null, null, null, null - ); - try { + )) { c.moveToFirst(); if (!c.isAfterLast()) { int version = c.getInt(c.getColumnIndex(COLUMN_VERSION)); @@ -69,8 +68,6 @@ public class AndroidProofOfWorkRepository implements ProofOfWorkRepository { c.getLong(c.getColumnIndex(COLUMN_EXTRA_BYTES)) ); } - } finally { - c.close(); } throw new RuntimeException("Object requested that we don't have. Initial hash: " + Strings.hex(initialHash)); @@ -85,20 +82,17 @@ public class AndroidProofOfWorkRepository implements ProofOfWorkRepository { }; SQLiteDatabase db = sql.getReadableDatabase(); - Cursor c = db.query( + List result = new LinkedList<>(); + try (Cursor c = db.query( TABLE_NAME, projection, null, null, null, null, null - ); - List result = new LinkedList<>(); - try { + )) { c.moveToFirst(); while (!c.isAfterLast()) { byte[] initialHash = c.getBlob(c.getColumnIndex(COLUMN_INITIAL_HASH)); result.add(initialHash); c.moveToNext(); } - } finally { - c.close(); } return result; } diff --git a/app/src/main/java/ch/dissem/apps/abit/service/Singleton.java b/app/src/main/java/ch/dissem/apps/abit/service/Singleton.java index 51d9311..9c60ecf 100644 --- a/app/src/main/java/ch/dissem/apps/abit/service/Singleton.java +++ b/app/src/main/java/ch/dissem/apps/abit/service/Singleton.java @@ -4,7 +4,7 @@ import android.content.Context; import java.util.List; -import ch.dissem.apps.abit.adapter.AndroidSecurity; +import ch.dissem.apps.abit.adapter.AndroidCryptography; import ch.dissem.apps.abit.adapter.SwitchingProofOfWorkEngine; import ch.dissem.apps.abit.listener.MessageListener; import ch.dissem.apps.abit.pow.ServerPowEngine; @@ -47,7 +47,7 @@ public class Singleton { new ServerPowEngine(ctx), new ServicePowEngine(ctx) )) - .security(new AndroidSecurity()) + .cryptography(new AndroidCryptography()) .nodeRegistry(new MemoryNodeRegistry()) .inventory(new AndroidInventory(sqlHelper)) .addressRepo(new AndroidAddressRepository(sqlHelper)) diff --git a/app/src/main/java/ch/dissem/apps/abit/synchronization/SyncService.java b/app/src/main/java/ch/dissem/apps/abit/synchronization/SyncService.java index b3abcaf..1f92159 100644 --- a/app/src/main/java/ch/dissem/apps/abit/synchronization/SyncService.java +++ b/app/src/main/java/ch/dissem/apps/abit/synchronization/SyncService.java @@ -7,18 +7,6 @@ import android.os.IBinder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import ch.dissem.apps.abit.listener.MessageListener; -import ch.dissem.apps.abit.notification.NetworkNotification; -import ch.dissem.apps.abit.repository.AndroidInventory; -import ch.dissem.apps.abit.repository.SqlHelper; -import ch.dissem.apps.abit.service.Singleton; -import ch.dissem.bitmessage.BitmessageContext; -import ch.dissem.bitmessage.networking.DefaultNetworkHandler; -import ch.dissem.bitmessage.ports.MemoryNodeRegistry; -import ch.dissem.bitmessage.security.sc.SpongySecurity; - -import static ch.dissem.apps.abit.notification.NetworkNotification.ONGOING_NOTIFICATION_ID; - /** * Define a Service that returns an IBinder for the * sync adapter class, allowing the sync adapter framework to call diff --git a/app/src/main/res/drawable/ic_notification_full_node.xml b/app/src/main/res/drawable/ic_notification_full_node.xml index 4790d6e..c7dff84 100644 --- a/app/src/main/res/drawable/ic_notification_full_node.xml +++ b/app/src/main/res/drawable/ic_notification_full_node.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/app/src/main/res/drawable/ic_notification_new_message.xml b/app/src/main/res/drawable/ic_notification_new_message.xml index 395fdb0..1def467 100644 --- a/app/src/main/res/drawable/ic_notification_new_message.xml +++ b/app/src/main/res/drawable/ic_notification_new_message.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/app/src/main/res/drawable/ic_notification_proof_of_work.xml b/app/src/main/res/drawable/ic_notification_proof_of_work.xml index c64f014..fda3f15 100644 --- a/app/src/main/res/drawable/ic_notification_proof_of_work.xml +++ b/app/src/main/res/drawable/ic_notification_proof_of_work.xml @@ -4,6 +4,6 @@ android:viewportHeight="24.0" android:viewportWidth="24.0"> diff --git a/app/src/main/res/drawable/ic_notification_warning.xml b/app/src/main/res/drawable/ic_notification_warning.xml index 0510991..3185242 100644 --- a/app/src/main/res/drawable/ic_notification_warning.xml +++ b/app/src/main/res/drawable/ic_notification_warning.xml @@ -4,6 +4,6 @@ android:viewportWidth="24.0" android:viewportHeight="24.0"> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5746bbd..fa2c9df 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -52,7 +52,7 @@ Subscribed Server POW Trusted node does proof of work - Running a full Bitmessage uses a lot of traffic, which could be expensive on a mobile network. Are you sure you want to start a full node? + Running a full Bitmessage node uses a lot of traffic, which could be expensive on a mobile network. Are you sure you want to start a full node? About Abit Open source dependencies. diff --git a/store/icon.svg b/store/icon.svg index 6e6d83b..ef7a4a6 100644 --- a/store/icon.svg +++ b/store/icon.svg @@ -15,7 +15,10 @@ id="svg2" version="1.1" inkscape:version="0.91 r13725" - sodipodi:docname="icon.svg"> + sodipodi:docname="icon.svg" + inkscape:export-filename="C:\Users\chrig\Documents\Projekte\Abit\store\icon.png" + inkscape:export-xdpi="90" + inkscape:export-ydpi="90">