Restore waiting for analysis

pull/209/head
M66B 3 years ago
parent 2fc6e5d603
commit 0fa73cc733

@ -39,10 +39,13 @@ public class VirusTotal {
return null; return null;
} }
static Bundle upload(Context context, File file, String apiKey, Runnable analyzing) { static String upload(Context context, File file, String apiKey) {
return null; return null;
} }
static void waitForAnalysis(Context context, String id, String apiKey) {
}
public static class ScanResult implements Parcelable { public static class ScanResult implements Parcelable {
public String name; public String name;
public String category; public String category;

@ -93,8 +93,7 @@ public class VirusTotal {
return result; return result;
} }
static void upload(Context context, File file, String apiKey, Runnable analyzing) static String upload(Context context, File file, String apiKey) throws IOException, JSONException {
throws IOException, JSONException, InterruptedException, TimeoutException {
// Get upload URL // Get upload URL
Pair<Integer, String> response = call(context, "api/v3/files/upload_url", apiKey); Pair<Integer, String> response = call(context, "api/v3/files/upload_url", apiKey);
if (response.first != HttpsURLConnection.HTTP_OK) if (response.first != HttpsURLConnection.HTTP_OK)
@ -103,7 +102,6 @@ public class VirusTotal {
String upload_url = jurl.getString("data"); String upload_url = jurl.getString("data");
// Upload file // Upload file
String id;
String boundary = "----FairEmail." + System.currentTimeMillis(); String boundary = "----FairEmail." + System.currentTimeMillis();
URL url = new URL(upload_url); URL url = new URL(upload_url);
@ -164,16 +162,16 @@ public class VirusTotal {
Log.i("VT response=" + r); Log.i("VT response=" + r);
JSONObject jfile = new JSONObject(r); JSONObject jfile = new JSONObject(r);
JSONObject jdata = jfile.getJSONObject("data"); JSONObject jdata = jfile.getJSONObject("data");
id = jdata.getString("id"); return jdata.getString("id");
} finally { } finally {
connection.disconnect(); connection.disconnect();
} }
}
static void waitForAnalysis(Context context, String id, String apiKey) throws IOException, JSONException, InterruptedException, TimeoutException {
// Get analysis result // Get analysis result
for (int i = 0; i < VT_ANALYSIS_CHECKS; i++) { for (int i = 0; i < VT_ANALYSIS_CHECKS; i++) {
analyzing.run();
Pair<Integer, String> analyses = call(context, "api/v3/analyses/" + id, apiKey); Pair<Integer, String> analyses = call(context, "api/v3/analyses/" + id, apiKey);
if (analyses.first != HttpsURLConnection.HTTP_OK) if (analyses.first != HttpsURLConnection.HTTP_OK)
throw new FileNotFoundException(analyses.second); throw new FileNotFoundException(analyses.second);

@ -594,6 +594,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
protected void onExecuted(Bundle args, Bundle result) { protected void onExecuted(Bundle args, Bundle result) {
List<VirusTotal.ScanResult> scans = result.getParcelableArrayList("scans"); List<VirusTotal.ScanResult> scans = result.getParcelableArrayList("scans");
String label = result.getString("label"); String label = result.getString("label");
String analysis = args.getString("analysis");
int malicious = 0; int malicious = 0;
if (scans != null) if (scans != null)
@ -615,6 +616,11 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
rvScan.setVisibility(scans == null ? View.GONE : View.VISIBLE); rvScan.setVisibility(scans == null ? View.GONE : View.VISIBLE);
btnUpload.setVisibility(scans == null && !TextUtils.isEmpty(apiKey) ? View.VISIBLE : View.GONE); btnUpload.setVisibility(scans == null && !TextUtils.isEmpty(apiKey) ? View.VISIBLE : View.GONE);
tvPrivacy.setVisibility(btnUpload.getVisibility()); tvPrivacy.setVisibility(btnUpload.getVisibility());
if (analysis != null && args.getBoolean("init")) {
args.remove("init");
btnUpload.callOnClick();
}
} }
@Override @Override
@ -642,14 +648,14 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
protected Void onExecute(Context context, Bundle args) throws Throwable { protected Void onExecute(Context context, Bundle args) throws Throwable {
String apiKey = args.getString("apiKey"); String apiKey = args.getString("apiKey");
File file = (File) args.getSerializable("file"); File file = (File) args.getSerializable("file");
VirusTotal.upload(context, file, apiKey, new Runnable() {
private int step = 0; String analysis = args.getString("analysis");
if (analysis == null) {
@Override analysis = VirusTotal.upload(context, file, apiKey);
public void run() { args.putString("analysis", analysis);
postProgress(Integer.toString(++step)); }
} postProgress(analysis);
}); VirusTotal.waitForAnalysis(context, analysis, apiKey);
return null; return null;
} }
@ -708,10 +714,12 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
} }
}); });
if (!TextUtils.isEmpty(apiKey)) if (TextUtils.isEmpty(apiKey))
taskLookup.execute(this, args, "attachment:lookup");
else
pbWait.setVisibility(View.GONE); pbWait.setVisibility(View.GONE);
else {
args.putBoolean("init", true);
taskLookup.execute(this, args, "attachment:lookup");
}
return new AlertDialog.Builder(context) return new AlertDialog.Builder(context)
.setView(view) .setView(view)

Loading…
Cancel
Save