mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
cbad85984f
commit
3f05dc8994
|
@ -2080,7 +2080,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
if ((EntityMessage.PGP_SIGNONLY.equals(encrypt) ||
|
||||
EntityMessage.PGP_ENCRYPTONLY.equals(encrypt) ||
|
||||
EntityMessage.PGP_SIGNENCRYPT.equals(encrypt))
|
||||
&& !Helper.isOpenKeychainInstalled(context)) {
|
||||
&& !PgpHelper.isOpenKeychainInstalled(context)) {
|
||||
encrypt = EntityMessage.ENCRYPT_NONE;
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
|
@ -5603,7 +5603,7 @@ public class FragmentCompose extends FragmentBase {
|
|||
|
||||
if (EntityMessage.PGP_SIGNONLY.equals(ref.ui_encrypt) ||
|
||||
EntityMessage.PGP_SIGNENCRYPT.equals(ref.ui_encrypt)) {
|
||||
if (Helper.isOpenKeychainInstalled(context) &&
|
||||
if (PgpHelper.isOpenKeychainInstalled(context) &&
|
||||
selected.sign_key != null &&
|
||||
PgpHelper.hasPgpKey(context, recipients, true))
|
||||
data.draft.ui_encrypt = ref.ui_encrypt;
|
||||
|
|
|
@ -291,12 +291,12 @@ public class FragmentDialogSend extends FragmentDialogBase {
|
|||
if ((encryptValues[position] == EntityMessage.PGP_SIGNONLY ||
|
||||
encryptValues[position] == EntityMessage.PGP_ENCRYPTONLY ||
|
||||
encryptValues[position] == EntityMessage.PGP_SIGNENCRYPT) &&
|
||||
Helper.isOpenKeychainInstalled(context)) {
|
||||
PgpHelper.isOpenKeychainInstalled(context)) {
|
||||
tvEncrypt.setPaintFlags(tvEncrypt.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG);
|
||||
tvEncrypt.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String pkg = Helper.getOpenKeychainPackage(v.getContext());
|
||||
String pkg = PgpHelper.getPackageName(v.getContext());
|
||||
PackageManager pm = v.getContext().getPackageManager();
|
||||
v.getContext().startActivity(pm.getLaunchIntentForPackage(pkg));
|
||||
}
|
||||
|
|
|
@ -134,8 +134,6 @@ import com.google.android.material.bottomnavigation.BottomNavigationView;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.textfield.TextInputLayout;
|
||||
|
||||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -691,27 +689,6 @@ public class Helper {
|
|||
}
|
||||
}
|
||||
|
||||
static String getOpenKeychainPackage(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return prefs.getString("openpgp_provider", Helper.PGP_OPENKEYCHAIN_PACKAGE);
|
||||
}
|
||||
|
||||
static boolean isOpenKeychainInstalled(Context context) {
|
||||
String provider = getOpenKeychainPackage(context);
|
||||
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
|
||||
intent.setPackage(provider);
|
||||
List<ResolveInfo> ris = pm.queryIntentServices(intent, 0);
|
||||
|
||||
return (ris != null && ris.size() > 0);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static boolean isInstalled(Context context, String pkg) {
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
|
|
|
@ -3355,8 +3355,8 @@ public class Log {
|
|||
size += write(os, "\r\n");
|
||||
|
||||
size += write(os, String.format("%s=%b\r\n",
|
||||
Helper.getOpenKeychainPackage(context),
|
||||
Helper.isOpenKeychainInstalled(context)));
|
||||
PgpHelper.getPackageName(context),
|
||||
PgpHelper.isOpenKeychainInstalled(context)));
|
||||
|
||||
try {
|
||||
int maxKeySize = javax.crypto.Cipher.getMaxAllowedKeyLength("AES");
|
||||
|
|
|
@ -25,9 +25,14 @@ import static org.openintents.openpgp.util.OpenPgpApi.RESULT_CODE_USER_INTERACTI
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.os.OperationCanceledException;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.openintents.openpgp.IOpenPgpService2;
|
||||
import org.openintents.openpgp.util.OpenPgpApi;
|
||||
import org.openintents.openpgp.util.OpenPgpServiceConnection;
|
||||
|
@ -115,7 +120,7 @@ public class PgpHelper {
|
|||
}
|
||||
|
||||
private static OpenPgpServiceConnection getConnection(Context context, long timeout) {
|
||||
final String pkg = Helper.getOpenKeychainPackage(context);
|
||||
final String pkg = PgpHelper.getPackageName(context);
|
||||
Log.i("PGP binding to " + pkg + " timeout=" + timeout);
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
|
@ -153,4 +158,25 @@ public class PgpHelper {
|
|||
|
||||
return pgpService;
|
||||
}
|
||||
|
||||
static String getPackageName(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return prefs.getString("openpgp_provider", Helper.PGP_OPENKEYCHAIN_PACKAGE);
|
||||
}
|
||||
|
||||
static boolean isOpenKeychainInstalled(Context context) {
|
||||
String provider = getPackageName(context);
|
||||
|
||||
try {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
Intent intent = new Intent(OpenPgpApi.SERVICE_INTENT_2);
|
||||
intent.setPackage(provider);
|
||||
List<ResolveInfo> ris = pm.queryIntentServices(intent, 0);
|
||||
|
||||
return (ris != null && ris.size() > 0);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue