mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-14 19:59:05 +01:00
Reorganised Guice modules. Contribute entropy to pool on Linux/Android.
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package org.briarproject.system;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import android.os.Build;
|
||||
import android.os.StatFs;
|
||||
|
||||
class AndroidFileUtils implements FileUtils {
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public long getFreeSpace(File f) throws IOException {
|
||||
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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.briarproject.system;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
class AndroidSeedProvider extends LinuxSeedProvider {
|
||||
|
||||
@Override
|
||||
void writeToEntropyPool(DataOutputStream out) throws IOException {
|
||||
out.writeInt(android.os.Process.myPid());
|
||||
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) {
|
||||
String serial = Build.SERIAL;
|
||||
if(serial != null) out.writeUTF(serial);
|
||||
}
|
||||
super.writeToEntropyPool(out);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.briarproject.system;
|
||||
|
||||
import org.briarproject.api.system.Clock;
|
||||
import org.briarproject.api.system.FileUtils;
|
||||
import org.briarproject.api.system.SeedProvider;
|
||||
import org.briarproject.api.system.Timer;
|
||||
|
||||
import com.google.inject.AbstractModule;
|
||||
|
||||
public class AndroidSystemModule extends AbstractModule {
|
||||
|
||||
protected void configure() {
|
||||
bind(Clock.class).to(SystemClock.class);
|
||||
bind(Timer.class).to(SystemTimer.class);
|
||||
bind(SeedProvider.class).to(AndroidSeedProvider.class);
|
||||
bind(FileUtils.class).to(AndroidFileUtils.class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user