Experiment: virus total lookup

This commit is contained in:
M66B 2022-07-21 19:03:44 +02:00
parent 9949c8e7f5
commit a4f358eedf
5 changed files with 81 additions and 3 deletions

View File

@ -48,7 +48,11 @@ import androidx.recyclerview.widget.DiffUtil;
import androidx.recyclerview.widget.ListUpdateCallback;
import androidx.recyclerview.widget.RecyclerView;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -79,6 +83,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
private TextView tvSize;
private ImageView ivStatus;
private ImageButton ibSave;
private ImageButton ibScan;
private TextView tvType;
private TextView tvError;
private ProgressBar progressbar;
@ -93,6 +98,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
tvSize = itemView.findViewById(R.id.tvSize);
ivStatus = itemView.findViewById(R.id.ivStatus);
ibSave = itemView.findViewById(R.id.ibSave);
ibScan = itemView.findViewById(R.id.ibScan);
tvType = itemView.findViewById(R.id.tvType);
ivDisposition = itemView.findViewById(R.id.ivDisposition);
tvError = itemView.findViewById(R.id.tvError);
@ -103,6 +109,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
view.setOnClickListener(this);
ibDelete.setOnClickListener(this);
ibSave.setOnClickListener(this);
ibScan.setOnClickListener(this);
view.setOnLongClickListener(this);
}
@ -110,6 +117,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
view.setOnClickListener(null);
ibDelete.setOnClickListener(null);
ibSave.setOnClickListener(null);
ibScan.setOnClickListener(null);
view.setOnLongClickListener(null);
}
@ -168,6 +176,7 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
}
ibSave.setVisibility(attachment.available ? View.VISIBLE : View.GONE);
ibScan.setVisibility(attachment.available && !BuildConfig.PLAY_STORE_RELEASE ? View.VISIBLE : View.GONE);
if (attachment.progress != null)
progressbar.setProgress(attachment.progress);
@ -201,10 +210,13 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
if (attachment == null)
return;
if (view.getId() == R.id.ibDelete)
int id = view.getId();
if (id == R.id.ibDelete)
onDelete(attachment);
else if (view.getId() == R.id.ibSave)
else if (id == R.id.ibSave)
onSave(attachment);
else if (id == R.id.ibScan)
onScan(attachment);
else {
if (attachment.available)
onShare(attachment);
@ -299,6 +311,47 @@ public class AdapterAttachment extends RecyclerView.Adapter<AdapterAttachment.Vi
.putExtra("type", attachment.getMimeType()));
}
private void onScan(EntityAttachment attachment) {
Bundle args = new Bundle();
args.putLong("id", attachment.id);
new SimpleTask<String>() {
@Override
protected String onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityAttachment attachment = db.attachment().getAttachment(id);
if (attachment == null)
return null;
MessageDigest digest = MessageDigest.getInstance("SHA-256");
try (InputStream is = new BufferedInputStream(new FileInputStream(attachment.getFile(context)))) {
int count;
byte[] buffer = new byte[1024];
while ((count = is.read(buffer)) != -1)
digest.update(buffer, 0, count);
}
return Helper.hex(digest.digest());
}
@Override
protected void onExecuted(Bundle args, String hash) {
if (hash == null)
return;
Uri uri = Uri.parse(Helper.URI_VIRUS_TOTAL + "gui/file/" + hash);
Helper.view(context, uri, false);
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
}.execute(context, owner, args, "attachment:scan");
}
private void onShare(EntityAttachment attachment) {
String title = (attachment.name == null ? attachment.cid : attachment.name);
Helper.share(context, attachment.getFile(context), attachment.getMimeType(), title);

View File

@ -201,6 +201,7 @@ public class Helper {
static final String DONTKILL_URI = "https://dontkillmyapp.com/";
static final String URI_SUPPORT_RESET_OPEN = "https://support.google.com/pixelphone/answer/6271667";
static final String URI_SUPPORT_CONTACT_GROUP = "https://support.google.com/contacts/answer/30970";
static final String URI_VIRUS_TOTAL = "https://www.virustotal.com/";
// https://developer.android.com/distribute/marketing-tools/linking-to-google-play#PerformingSearch
private static final String PLAY_STORE_SEARCH = "https://play.google.com/store/search";

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M19.3,16.9c0.4,-0.7 0.7,-1.5 0.7,-2.4c0,-2.5 -2,-4.5 -4.5,-4.5S11,12 11,14.5s2,4.5 4.5,4.5c0.9,0 1.7,-0.3 2.4,-0.7l3.2,3.2l1.4,-1.4L19.3,16.9zM15.5,17c-1.4,0 -2.5,-1.1 -2.5,-2.5s1.1,-2.5 2.5,-2.5s2.5,1.1 2.5,2.5S16.9,17 15.5,17zM12,20v2C6.48,22 2,17.52 2,12C2,6.48 6.48,2 12,2c4.84,0 8.87,3.44 9.8,8h-2.07c-0.64,-2.46 -2.4,-4.47 -4.73,-5.41V5c0,1.1 -0.9,2 -2,2h-2v2c0,0.55 -0.45,1 -1,1H8v2h2v3H9l-4.79,-4.79C4.08,10.79 4,11.38 4,12C4,16.41 7.59,20 12,20z"/>
</vector>

View File

@ -79,10 +79,23 @@
android:padding="6dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="@+id/tvType"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintEnd_toStartOf="@+id/ibScan"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_save_alt_24" />
<ImageButton
android:id="@+id/ibScan"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/title_legend_scan"
android:padding="6dp"
android:scaleType="fitCenter"
app:layout_constraintBottom_toBottomOf="@+id/tvType"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/twotone_travel_explore_24" />
<TextView
android:id="@+id/tvType"
android:layout_width="0dp"

View File

@ -1840,6 +1840,7 @@
<string name="title_legend_sync_state">Synchronization state</string>
<string name="title_legend_download_state">Download state</string>
<string name="title_legend_save">Save</string>
<string name="title_legend_scan">Scan</string>
<string name="title_legend_delete">Delete</string>
<string name="title_legend_count">Count</string>
<string name="title_legend_folder_type">Folder type</string>