parse string util method, better help text for access screen

This commit is contained in:
Dominik Schürmann 2014-02-15 13:00:47 +01:00
parent 3b0f76bf60
commit 52f1c930eb
13 changed files with 83 additions and 88 deletions

View File

@ -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;

View File

@ -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;

View File

@ -32,6 +32,8 @@ public class OpenPgpConstants {
// (for encrypt method)
public static final String PARAMS_USER_IDS = "user_ids";
public static final String PARAMS_KEY_IDS = "key_ids";
// optional parameter:
public static final String PARAMS_PASSPHRASE = "passphrase";
/* Service Bundle returns */
public static final String RESULT_CODE = "result_code";

View File

@ -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

View File

@ -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");

View File

@ -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()) {

View File

@ -138,7 +138,8 @@ public class OpenPgpService extends RemoteService {
// TODO: asciiArmor?!
private Bundle signImpl(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output, AppSettings appSettings) {
private Bundle signImpl(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output,
AppSettings appSettings) {
try {
// get passphrase from cache, if key has "no" passphrase, this returns an empty String
String passphrase;

View File

@ -383,7 +383,7 @@
<string name="api_settings_revoke">Revoke access</string>
<string name="api_settings_package_name">Package Name</string>
<string name="api_settings_package_signature">SHA-256 of Package Signature</string>
<string name="api_register_text">The following application requests access to OpenPGP Keychain.\n\nAllow access (you can revoke it later)?</string>
<string name="api_register_text">The displayed application requests access to OpenPGP Keychain.\nAllow access?\n\nWARNING: If you do not know why this screen appeared, disallow access! You can revoke access later using the \'Registered Applications\' screen.</string>
<string name="api_register_allow">Allow access</string>
<string name="api_register_disallow">Disallow access</string>
<string name="api_register_error_select_key">Please select a key!</string>

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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");

View File

@ -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()) {