mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-15 08:29:24 +00:00
Added VirusTotal API key field
This commit is contained in:
parent
0e2cbdd11e
commit
31ecc86ca6
4 changed files with 53 additions and 9 deletions
|
@ -163,7 +163,6 @@ android {
|
|||
buildConfigField "String", "GPA_URI", localProperties.getProperty("gpa.uri", "\"\"")
|
||||
buildConfigField "String", "INFO_URI", localProperties.getProperty("info.uri", "\"\"")
|
||||
buildConfigField "String", "DEV_DOMAIN", localProperties.getProperty("dev.domain", "\"\"")
|
||||
buildConfigField "String", "VT_APIKEY", localProperties.getProperty("vt.apikey", "\"\"")
|
||||
buildConfigField "String", "FDROID", "\"https://f-droid.org/packages/%s/\""
|
||||
}
|
||||
fdroid {
|
||||
|
@ -180,7 +179,6 @@ android {
|
|||
buildConfigField "String", "GPA_URI", "\"\""
|
||||
buildConfigField "String", "INFO_URI", "\"\""
|
||||
buildConfigField "String", "DEV_DOMAIN", "\"\""
|
||||
buildConfigField "String", "VT_APIKEY", "\"\""
|
||||
buildConfigField "String", "FDROID", "\"https://f-droid.org/packages/%s/\""
|
||||
}
|
||||
play {
|
||||
|
@ -198,7 +196,6 @@ android {
|
|||
buildConfigField "String", "GPA_URI", "\"\""
|
||||
buildConfigField "String", "INFO_URI", "\"\""
|
||||
buildConfigField "String", "DEV_DOMAIN", "\"\""
|
||||
buildConfigField "String", "VT_APIKEY", "\"\""
|
||||
buildConfigField "String", "FDROID", "\"\""
|
||||
}
|
||||
amazon {
|
||||
|
@ -216,7 +213,6 @@ android {
|
|||
buildConfigField "String", "GPA_URI", "\"\""
|
||||
buildConfigField "String", "INFO_URI", "\"\""
|
||||
buildConfigField "String", "DEV_DOMAIN", "\"\""
|
||||
buildConfigField "String", "VT_APIKEY", "\"\""
|
||||
buildConfigField "String", "FDROID", "\"\""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,12 +20,14 @@ package eu.faircode.email;
|
|||
*/
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
|
@ -60,7 +62,10 @@ public class Check {
|
|||
hash = Helper.getHash(is, "SHA-256");
|
||||
}
|
||||
|
||||
if (!TextUtils.isEmpty(BuildConfig.VT_APIKEY)) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String apikey = prefs.getString("vt_apikey", null);
|
||||
|
||||
if (!TextUtils.isEmpty(apikey)) {
|
||||
//hash = "51e31f76c8d70eaeda1aba0e21fc50f44d261b81416c4338ac3f71694a6648b3";
|
||||
URL url = new URL(URI_VT_ENDPOINT + "api/v3/files/" + hash);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
|
@ -68,7 +73,7 @@ public class Check {
|
|||
connection.setReadTimeout(VT_TIMEOUT * 1000);
|
||||
connection.setConnectTimeout(VT_TIMEOUT * 1000);
|
||||
ConnectionHelper.setUserAgent(context, connection);
|
||||
connection.setRequestProperty("x-apikey", BuildConfig.VT_APIKEY);
|
||||
connection.setRequestProperty("x-apikey", apikey);
|
||||
connection.connect();
|
||||
|
||||
try {
|
||||
|
|
|
@ -43,8 +43,11 @@ import android.os.Bundle;
|
|||
import android.os.Debug;
|
||||
import android.os.Environment;
|
||||
import android.provider.Settings;
|
||||
import android.text.Editable;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.style.RelativeSizeSpan;
|
||||
import android.text.style.StyleSpan;
|
||||
import android.util.Pair;
|
||||
|
@ -59,6 +62,7 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
|
@ -120,6 +124,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
private ImageButton ibDeepL;
|
||||
private SwitchCompat swVirusTotal;
|
||||
private TextView tvVirusTotalPrivacy;
|
||||
private EditText etVirusTotal;
|
||||
private SwitchCompat swUpdates;
|
||||
private ImageButton ibChannelUpdated;
|
||||
private SwitchCompat swCheckWeekly;
|
||||
|
@ -220,7 +225,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
private final static String[] RESET_OPTIONS = new String[]{
|
||||
"sort_answers", "shortcuts", "fts",
|
||||
"classification", "class_min_probability", "class_min_difference",
|
||||
"language", "lt_enabled", "deepl_enabled", "vt_enabled",
|
||||
"language", "lt_enabled", "deepl_enabled", "vt_enabled", "vt_apikey",
|
||||
"updates", "weekly", "show_changelog",
|
||||
"crash_reports", "cleanup_attachments",
|
||||
"watchdog", "experiments", "main_log", "protocol", "log_level", "debug", "leak_canary", "test1",
|
||||
|
@ -309,6 +314,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
ibDeepL = view.findViewById(R.id.ibDeepL);
|
||||
swVirusTotal = view.findViewById(R.id.swVirusTotal);
|
||||
tvVirusTotalPrivacy = view.findViewById(R.id.tvVirusTotalPrivacy);
|
||||
etVirusTotal = view.findViewById(R.id.etVirusTotal);
|
||||
swUpdates = view.findViewById(R.id.swUpdates);
|
||||
ibChannelUpdated = view.findViewById(R.id.ibChannelUpdated);
|
||||
swCheckWeekly = view.findViewById(R.id.swWeekly);
|
||||
|
@ -653,6 +659,27 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
}
|
||||
});
|
||||
|
||||
etVirusTotal.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
String apikey = s.toString().trim();
|
||||
if (TextUtils.isEmpty(apikey))
|
||||
prefs.edit().remove("vt_apikey").apply();
|
||||
else
|
||||
prefs.edit().putString("vt_apikey", apikey).apply();
|
||||
}
|
||||
});
|
||||
|
||||
swUpdates.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
|
@ -1670,6 +1697,9 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
if ("last_cleanup".equals(key))
|
||||
setLastCleanup(prefs.getLong(key, -1));
|
||||
|
||||
if ("vt_apikey".equals(key))
|
||||
return;
|
||||
|
||||
setOptions();
|
||||
}
|
||||
|
||||
|
@ -1813,6 +1843,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
|||
swLanguageTool.setChecked(prefs.getBoolean("lt_enabled", false));
|
||||
swDeepL.setChecked(prefs.getBoolean("deepl_enabled", false));
|
||||
swVirusTotal.setChecked(prefs.getBoolean("vt_enabled", false));
|
||||
etVirusTotal.setText(prefs.getString("vt_apikey", null));
|
||||
swUpdates.setChecked(prefs.getBoolean("updates", true));
|
||||
swCheckWeekly.setChecked(prefs.getBoolean("weekly", Helper.hasPlayStore(getContext())));
|
||||
swCheckWeekly.setEnabled(swUpdates.isChecked());
|
||||
|
|
|
@ -416,6 +416,18 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/swVirusTotal" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etVirusTotal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:hint="API key"
|
||||
android:inputType="text"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvVirusTotalPrivacy" />
|
||||
|
||||
<androidx.appcompat.widget.SwitchCompat
|
||||
android:id="@+id/swUpdates"
|
||||
android:layout_width="0dp"
|
||||
|
@ -425,7 +437,7 @@
|
|||
android:text="@string/title_advanced_updates"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/tvVirusTotalPrivacy"
|
||||
app:layout_constraintTop_toBottomOf="@id/etVirusTotal"
|
||||
app:switchPadding="12dp" />
|
||||
|
||||
<ImageButton
|
||||
|
@ -575,7 +587,7 @@
|
|||
android:id="@+id/grpVirusTotal"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="swVirusTotal,tvVirusTotalPrivacy" />
|
||||
app:constraint_referenced_ids="swVirusTotal,tvVirusTotalPrivacy,etVirusTotal" />
|
||||
|
||||
<androidx.constraintlayout.widget.Group
|
||||
android:id="@+id/grpUpdates"
|
||||
|
|
Loading…
Add table
Reference in a new issue