Restore waiting for analysis

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

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

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

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

Loading…
Cancel
Save