aboutsummaryrefslogtreecommitdiffstats
path: root/libraries
diff options
context:
space:
mode:
authorDominik Schürmann <dominik@dominikschuermann.de>2014-02-15 13:00:47 +0100
committerDominik Schürmann <dominik@dominikschuermann.de>2014-02-15 13:00:47 +0100
commit52f1c930ebe98251fb9d3b34b2725087f2917f64 (patch)
treeee5543854ced499c282892223674bd9b4c73266f /libraries
parent3b0f76bf60028603140c3fd8a956241b315a6b18 (diff)
downloadopen-keychain-52f1c930ebe98251fb9d3b34b2725087f2917f64.tar.gz
open-keychain-52f1c930ebe98251fb9d3b34b2725087f2917f64.tar.bz2
open-keychain-52f1c930ebe98251fb9d3b34b2725087f2917f64.zip
parse string util method, better help text for access screen
Diffstat (limited to 'libraries')
-rw-r--r--libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl2
-rw-r--r--libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl2
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java39
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java5
-rw-r--r--libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java34
5 files changed, 39 insertions, 43 deletions
diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl
index 7f867653d..0fbea0a8c 100644
--- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl
+++ b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpError.aidl
@@ -16,5 +16,7 @@
package org.openintents.openpgp;
+import org.openintents.openpgp.OpenPgpError;
+
// Declare OpenPgpError so AIDL can find it and knows that it implements the parcelable protocol.
parcelable OpenPgpError; \ No newline at end of file
diff --git a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl
index d1d138b30..dfc7e0992 100644
--- a/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl
+++ b/libraries/keychain-api-library/src/main/aidl/org/openintents/openpgp/OpenPgpSignatureResult.aidl
@@ -16,5 +16,7 @@
package org.openintents.openpgp;
+import org.openintents.openpgp.OpenPgpSignatureResult;
+
// Declare OpenPgpSignatureResult so AIDL can find it and knows that it implements the parcelable protocol.
parcelable OpenPgpSignatureResult; \ No newline at end of file
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
index ea287a7a9..e29794e87 100644
--- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpListPreference.java
@@ -16,16 +16,11 @@
package org.openintents.openpgp.util;
-import java.util.ArrayList;
-import java.util.List;
-
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
-import android.content.pm.ServiceInfo;
import android.graphics.drawable.Drawable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
@@ -35,6 +30,9 @@ import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;
+import java.util.ArrayList;
+import java.util.List;
+
public class OpenPgpListPreference extends DialogPreference {
ArrayList<OpenPgpProviderEntry> mProviderList = new ArrayList<OpenPgpProviderEntry>();
private String mSelectedPackage;
@@ -42,8 +40,8 @@ public class OpenPgpListPreference extends DialogPreference {
public OpenPgpListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
- List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(
- new Intent(OpenPgpConstants.SERVICE_INTENT), PackageManager.GET_META_DATA);
+ Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT);
+ List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0);
if (!resInfo.isEmpty()) {
for (ResolveInfo resolveInfo : resInfo) {
if (resolveInfo.serviceInfo == null)
@@ -54,12 +52,7 @@ public class OpenPgpListPreference extends DialogPreference {
.getPackageManager()));
Drawable icon = resolveInfo.serviceInfo.loadIcon(context.getPackageManager());
- // get api version
- ServiceInfo si = resolveInfo.serviceInfo;
- int apiVersion = si.metaData.getInt("api_version");
-
- mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon,
- apiVersion));
+ mProviderList.add(new OpenPgpProviderEntry(packageName, simpleName, icon));
}
}
}
@@ -75,10 +68,8 @@ public class OpenPgpListPreference extends DialogPreference {
* @param simpleName
* @param icon
*/
- public void addProvider(int position, String packageName, String simpleName, Drawable icon,
- int apiVersion) {
- mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon,
- apiVersion));
+ public void addProvider(int position, String packageName, String simpleName, Drawable icon) {
+ mProviderList.add(position, new OpenPgpProviderEntry(packageName, simpleName, icon));
}
@Override
@@ -99,15 +90,6 @@ public class OpenPgpListPreference extends DialogPreference {
int dp10 = (int) (10 * getContext().getResources().getDisplayMetrics().density + 0.5f);
tv.setCompoundDrawablePadding(dp10);
- // disable if it has the wrong api_version
- if (mProviderList.get(position).apiVersion == OpenPgpConstants.API_VERSION) {
- tv.setEnabled(true);
- } else {
- tv.setEnabled(false);
- tv.setText(tv.getText() + " (API v" + mProviderList.get(position).apiVersion
- + ", needs v" + OpenPgpConstants.API_VERSION + ")");
- }
-
return v;
}
};
@@ -183,14 +165,11 @@ public class OpenPgpListPreference extends DialogPreference {
private String packageName;
private String simpleName;
private Drawable icon;
- private int apiVersion;
- public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon,
- int apiVersion) {
+ public OpenPgpProviderEntry(String packageName, String simpleName, Drawable icon) {
this.packageName = packageName;
this.simpleName = simpleName;
this.icon = icon;
- this.apiVersion = apiVersion;
}
@Override
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java
index 780b4606b..8e8812faa 100644
--- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpServiceConnection.java
@@ -61,11 +61,12 @@ public class OpenPgpServiceConnection {
/**
* If not already bound, bind!
- *
+ *
* @return
*/
public boolean bindToService() {
- if (mService == null && !mBound) { // if not already connected
+ // if not already connected
+ if (mService == null && !mBound) {
try {
Log.d(OpenPgpConstants.TAG, "not bound yet");
diff --git a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java
index 6dbf76897..ffecaceba 100644
--- a/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java
+++ b/libraries/keychain-api-library/src/main/java/org/openintents/openpgp/util/OpenPgpUtils.java
@@ -17,6 +17,7 @@
package org.openintents.openpgp.util;
import java.util.List;
+import java.util.regex.Matcher;
import java.util.regex.Pattern;
import android.content.Context;
@@ -24,22 +25,33 @@ import android.content.Intent;
import android.content.pm.ResolveInfo;
public class OpenPgpUtils {
- private Context context;
- public static Pattern PGP_MESSAGE = Pattern.compile(
- ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*", Pattern.DOTALL);
+ public static final Pattern PGP_MESSAGE = Pattern.compile(
+ ".*?(-----BEGIN PGP MESSAGE-----.*?-----END PGP MESSAGE-----).*",
+ Pattern.DOTALL);
- public static Pattern PGP_SIGNED_MESSAGE = Pattern
- .compile(
- ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
- Pattern.DOTALL);
+ public static final Pattern PGP_SIGNED_MESSAGE = Pattern.compile(
+ ".*?(-----BEGIN PGP SIGNED MESSAGE-----.*?-----BEGIN PGP SIGNATURE-----.*?-----END PGP SIGNATURE-----).*",
+ Pattern.DOTALL);
- public OpenPgpUtils(Context context) {
- super();
- this.context = context;
+ public static final int PARSE_RESULT_NO_PGP = -1;
+ public static final int PARSE_RESULT_MESSAGE = 0;
+ public static final int PARSE_RESULT_SIGNED_MESSAGE = 1;
+
+ public static int parseMessage(String message) {
+ Matcher matcherSigned = PGP_SIGNED_MESSAGE.matcher(message);
+ Matcher matcherMessage = PGP_MESSAGE.matcher(message);
+
+ if (matcherMessage.matches()) {
+ return PARSE_RESULT_MESSAGE;
+ } else if (matcherSigned.matches()) {
+ return PARSE_RESULT_SIGNED_MESSAGE;
+ } else {
+ return PARSE_RESULT_NO_PGP;
+ }
}
- public boolean isAvailable() {
+ public static boolean isAvailable(Context context) {
Intent intent = new Intent(OpenPgpConstants.SERVICE_INTENT);
List<ResolveInfo> resInfo = context.getPackageManager().queryIntentServices(intent, 0);
if (!resInfo.isEmpty()) {