Minor bugfixes & renamed 'security' to 'cryptography

This commit is contained in:
Christian Basler 2016-01-13 17:28:18 +01:00
parent eb322d94a2
commit abd25f4010
16 changed files with 46 additions and 77 deletions

View File

@ -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'

View File

@ -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,9 +439,10 @@ public class MainActivity extends AppCompatActivity
@Override
public void updateTitle(CharSequence title) {
//noinspection ConstantConditions
if (getSupportActionBar() != null) {
getSupportActionBar().setTitle(title);
}
}
public Label getSelectedLabel() {
return selectedLabel;

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -89,6 +89,7 @@ public class AndroidInventory implements Inventory {
} finally {
c.close();
}
LOG.info("Inventory size: " + result.size());
return result;
}

View File

@ -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;
}

View File

@ -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<byte[]> result = new LinkedList<>();
try (Cursor c = db.query(
TABLE_NAME, projection,
null, null, null, null, null
);
List<byte[]> 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;
}

View File

@ -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))

View File

@ -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

View File

@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M19.35,10.03C18.67,6.59 15.64,4 12,4C9.11,4 6.6,5.64 5.35,8.03C2.34,8.36 0,10.9 0,14A6,6 0,0 0,6 20H19A5,5 0,0 0,24 15C24,12.36 21.95,10.22 19.35,10.03Z"/>
</vector>

View File

@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M20.5,0A2.5,2.5 0,0 1,23 2.5V3A1,1 0,0 1,24 4V8A1,1 0,0 1,23 9H18A1,1 0,0 1,17 8V4A1,1 0,0 1,18 3V2.5A2.5,2.5 0,0 1,20.5 0M12,11L4,6V8L12,13L16.18,10.39C16.69,10.77 17.32,11 18,11H22V18A2,2 0,0 1,20 20H4A2,2 0,0 1,2 18V6A2,2 0,0 1,4 4H15V8C15,8.36 15.06,8.7 15.18,9L12,11M20.5,1A1.5,1.5 0,0 0,19 2.5V3H22V2.5A1.5,1.5 0,0 0,20.5 1Z"/>
</vector>

View File

@ -4,6 +4,6 @@
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M11.71,19C9.93,19 8.5,17.59 8.5,15.86C8.5,14.24 9.53,13.1 11.3,12.74C13.07,12.38 14.9,11.53 15.92,10.16C16.31,11.45 16.5,12.81 16.5,14.2C16.5,16.84 14.36,19 11.71,19M13.5,0.67C13.5,0.67 14.24,3.32 14.24,5.47C14.24,7.53 12.89,9.2 10.83,9.2C8.76,9.2 7.2,7.53 7.2,5.47L7.23,5.1C5.21,7.5 4,10.61 4,14A8,8 0 0,0 12,22A8,8 0 0,0 20,14C20,8.6 17.41,3.8 13.5,0.67Z" />
</vector>

View File

@ -4,6 +4,6 @@
android:viewportWidth="24.0"
android:viewportHeight="24.0">
<path
android:fillColor="#FF000000"
android:fillColor="#FFFFFFFF"
android:pathData="M1,21h22L12,2 1,21zm12,-3h-2v-2h2v2zm0,-4h-2v-4h2v4z"/>
</vector>

View File

@ -52,7 +52,7 @@
<string name="subscribed">Subscribed</string>
<string name="server_pow">Server POW</string>
<string name="server_pow_summary">Trusted node does proof of work</string>
<string name="full_node_warning">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?</string>
<string name="full_node_warning">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?</string>
<string name="about">About Abit</string>
<string name="about_summary">Open source dependencies.</string>
</resources>

View File

@ -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">
<defs
id="defs4" />
<sodipodi:namedview
@ -26,7 +29,7 @@
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="0.35"
inkscape:cx="-330.71429"
inkscape:cx="-602.14286"
inkscape:cy="520"
inkscape:document-units="px"
inkscape:current-layer="layer1"

Before

Width:  |  Height:  |  Size: 3.1 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB