Skip to content

Commit

Permalink
improvements to libProofMode use and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
n8fr8 committed Jun 1, 2018
1 parent 2ca0475 commit 3987efe
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 42 deletions.
16 changes: 16 additions & 0 deletions android-libproofmode/build.gradle
Expand Up @@ -40,4 +40,20 @@ dependencies {

compile project(':java-opentimestamps')


}

apply plugin: 'maven'

uploadArchives {
repositories.mavenDeployer {
def deployPath = file(getProperty('aar.deployPath'))
repository(url: "file://${deployPath.absolutePath}")
pom.project {
groupId 'org.witness'
artifactId 'android-libproofmode'
version "0.0.1"
}
}
}

@@ -0,0 +1,56 @@
package org.witness.proofmode;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import org.spongycastle.jce.provider.BouncyCastleProvider;
import org.witness.proofmode.service.MediaListenerService;
import org.witness.proofmode.service.MediaWatcher;
import org.witness.proofmode.service.PhotosContentJob;
import org.witness.proofmode.service.VideosContentJob;
import org.witness.proofmode.util.SafetyNetCheck;

import java.io.File;
import java.security.Security;

public class ProofMode {


public final static String PROOF_FILE_TAG = ".proof.csv";
public final static String OPENPGP_FILE_TAG = ".asc";

static {
Security.addProvider(new BouncyCastleProvider());
}

private static boolean mInit = false;

public synchronized static void init (Context context)
{
if (mInit)
return;

if (android.os.Build.VERSION.SDK_INT >= 24) {
PhotosContentJob.scheduleJob(context);
VideosContentJob.scheduleJob(context);
}
else
{
context.startService(new Intent(context, MediaListenerService.class));
}

SafetyNetCheck.buildGoogleApiClient(context);

mInit = true;
}

public static void generateProof (Context context, Uri uri)
{
Intent intent = new Intent();
intent.setData(uri);
new MediaWatcher().handleIntent(context, intent, true);
}


}
Expand Up @@ -290,6 +290,12 @@ public void createDetachedSignature (File media, File mediaSig, String password)

}

public void createDetachedSignature (InputStream media, OutputStream mediaSig, String password) throws Exception
{
DetachedSignatureProcessor.createSignature(pgpSec, media, mediaSig, password.toCharArray(), true);

}


public synchronized void initCrypto (Context context, String password)
{
Expand Down
Expand Up @@ -70,7 +70,6 @@ public boolean handleIntent (final Context context, Intent intent, boolean force
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

boolean doProof = prefs.getBoolean("doProof", true);
boolean autoNotarize = prefs.getBoolean("autoNotarize", true);

if (intent.getAction() != null) {
if (intent.getAction().equals(Intent.ACTION_UMS_CONNECTED)) {
Expand All @@ -80,8 +79,6 @@ public boolean handleIntent (final Context context, Intent intent, boolean force
}
}

Timber.d("Received intent. doProof is %b and autoNotarize is %b",doProof,autoNotarize);

if (doProof || forceDoProof) {

if (!isExternalStorageWritable()) {
Expand Down Expand Up @@ -120,6 +117,7 @@ public boolean handleIntent (final Context context, Intent intent, boolean force

final boolean showDeviceIds = prefs.getBoolean("trackDeviceId",true);
final boolean showLocation = prefs.getBoolean("trackLocation",true);
final boolean autoNotarize = prefs.getBoolean("autoNotarize", true);
final boolean showMobileNetwork = prefs.getBoolean("trackMobileNetwork",false);


Expand Down
22 changes: 2 additions & 20 deletions app/src/main/java/org/witness/proofmode/ProofModeApp.java
Expand Up @@ -24,11 +24,6 @@ public class ProofModeApp extends MultiDexApplication {

public final static String TAG = "ProofMode";

private static boolean mInit = false;

static {
Security.addProvider(new BouncyCastleProvider());
}

@Override
public void onCreate() {
Expand All @@ -37,29 +32,16 @@ public void onCreate() {
init(this);
}

public synchronized static void init (Context context)
public static void init (Context context)
{
if (mInit)
return;

if (BuildConfig.DEBUG) {
Timber.plant(new Timber.DebugTree());
} else {
Timber.plant(new CrashReportingTree());
}

if (android.os.Build.VERSION.SDK_INT >= 24) {
PhotosContentJob.scheduleJob(context);
VideosContentJob.scheduleJob(context);
}
else
{
context.startService(new Intent(context, MediaListenerService.class));
}

SafetyNetCheck.buildGoogleApiClient(context);

mInit = true;
ProofMode.init(context);
}

/** A tree which logs important information for crash reporting. */
Expand Down
24 changes: 5 additions & 19 deletions app/src/main/java/org/witness/proofmode/ShareProofActivity.java
Expand Up @@ -3,7 +3,6 @@
import android.Manifest;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.LabeledIntent;
import android.content.pm.PackageManager;
Expand All @@ -13,52 +12,43 @@
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import org.witness.proofmode.crypto.HashUtils;
import org.witness.proofmode.crypto.PgpUtils;
import org.witness.proofmode.notarization.TimeBeatNotarizationProvider;
import org.witness.proofmode.service.MediaListenerService;
import org.witness.proofmode.service.MediaWatcher;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

import timber.log.Timber;
import static org.witness.proofmode.ProofMode.OPENPGP_FILE_TAG;
import static org.witness.proofmode.ProofMode.PROOF_FILE_TAG;

public class ShareProofActivity extends AppCompatActivity {

private final static String PROOF_FILE_TAG = ".proof.csv";
private final static String OPENPGP_FILE_TAG = ".asc";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -375,9 +365,7 @@ private void generateProof (Uri mediaUri)

new AsyncTask<Void, Void, String>() {
protected String doInBackground(Void... params) {
Intent intent = new Intent();
intent.setData(Uri.fromFile(new File(mediaPath)));
new MediaWatcher().handleIntent(ShareProofActivity.this, intent, true);
ProofMode.generateProof(ShareProofActivity.this,Uri.fromFile(new File(mediaPath)));
return "message";
}

Expand All @@ -398,9 +386,7 @@ protected void onPostExecute(String msg) {

new AsyncTask<Void, Void, String>() {
protected String doInBackground(Void... params) {
Intent intent = new Intent();
intent.setData(Uri.fromFile(new File(tmpMediaPath)));
new MediaWatcher().handleIntent(ShareProofActivity.this, intent, true);
ProofMode.generateProof(ShareProofActivity.this,Uri.fromFile(new File(tmpMediaPath)));
return "message";
}

Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Expand Up @@ -17,3 +17,4 @@ org.gradle.jvmargs=-Xmx1536M
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
aar.deployPath=/media/n8fr8/nate128/dev/repos/gpmaven

0 comments on commit 3987efe

Please sign in to comment.