API update: boolean to allow/disallow user interaction allow real background pgp operations that will not require user input

This commit is contained in:
Dominik Schürmann 2013-09-16 12:16:54 +02:00
parent 53f33dc3cb
commit 4e23cf2edc
4 changed files with 59 additions and 32 deletions

View File

@ -33,10 +33,13 @@ interface IOpenPgpService {
* User Ids (emails) of recipients
* @param asciiArmor
* Encode for ASCII (Radix-64, 33 percent overhead compared to binary)
* @param allowUserInteraction
* Allows the OpenPGP Provider to handle missing keys by showing activities
* @param callback
* Callback where to return results
*/
oneway void encrypt(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor, in IOpenPgpCallback callback);
oneway void encrypt(in byte[] inputBytes, in String[] encryptionUserIds,
in boolean asciiArmor, in boolean allowUserInteraction, in IOpenPgpCallback callback);
/**
* Sign
@ -45,10 +48,13 @@ interface IOpenPgpService {
* Byte array you want to encrypt
* @param asciiArmor
* Encode for ASCII (Radix-64, 33 percent overhead compared to binary)
* @param allowUserInteraction
* Allows the OpenPGP Provider to handle missing keys by showing activities
* @param callback
* Callback where to return results
*/
oneway void sign(in byte[] inputBytes, in boolean asciiArmor, in IOpenPgpCallback callback);
oneway void sign(in byte[] inputBytes, in boolean asciiArmor, in boolean allowUserInteraction,
in IOpenPgpCallback callback);
/**
* Sign then encrypt
@ -61,10 +67,13 @@ interface IOpenPgpService {
* User Ids (email) of sender
* @param asciiArmor
* Encode for ASCII (Radix-64, 33 percent overhead compared to binary)
* @param allowUserInteraction
* Allows the OpenPGP Provider to handle missing keys by showing activities
* @param callback
* Callback where to return results
*/
oneway void signAndEncrypt(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor, in IOpenPgpCallback callback);
oneway void signAndEncrypt(in byte[] inputBytes, in String[] encryptionUserIds,
in boolean asciiArmor, in boolean allowUserInteraction, in IOpenPgpCallback callback);
/**
* Decrypts and verifies given input bytes. If no signature is present this method
@ -72,9 +81,12 @@ interface IOpenPgpService {
*
* @param inputBytes
* Byte array you want to decrypt and verify
* @param allowUserInteraction
* Allows the OpenPGP Provider to handle missing keys by showing activities
* @param callback
* Callback where to return results
*/
oneway void decryptAndVerify(in byte[] inputBytes, in IOpenPgpCallback callback);
oneway void decryptAndVerify(in byte[] inputBytes, in boolean allowUserInteraction,
in IOpenPgpCallback callback);
}

View File

@ -139,7 +139,7 @@ public class OpenPgpProviderActivity extends Activity {
try {
mCryptoServiceConnection.getService().encrypt(inputBytes,
mEncryptUserIds.getText().toString().split(","), true, encryptCallback);
mEncryptUserIds.getText().toString().split(","), true, true, encryptCallback);
} catch (RemoteException e) {
Log.e(Constants.TAG, "CryptoProviderDemo", e);
}
@ -149,7 +149,7 @@ public class OpenPgpProviderActivity extends Activity {
byte[] inputBytes = mMessage.getText().toString().getBytes();
try {
mCryptoServiceConnection.getService().sign(inputBytes, true, encryptCallback);
mCryptoServiceConnection.getService().sign(inputBytes, true, true, encryptCallback);
} catch (RemoteException e) {
Log.e(Constants.TAG, "CryptoProviderDemo", e);
}
@ -160,7 +160,7 @@ public class OpenPgpProviderActivity extends Activity {
try {
mCryptoServiceConnection.getService().signAndEncrypt(inputBytes,
mEncryptUserIds.getText().toString().split(","), true, encryptCallback);
mEncryptUserIds.getText().toString().split(","), true, true, encryptCallback);
} catch (RemoteException e) {
Log.e(Constants.TAG, "CryptoProviderDemo", e);
}
@ -170,7 +170,7 @@ public class OpenPgpProviderActivity extends Activity {
byte[] inputBytes = mCiphertext.getText().toString().getBytes();
try {
mCryptoServiceConnection.getService().decryptAndVerify(inputBytes,
mCryptoServiceConnection.getService().decryptAndVerify(inputBytes, true,
decryptAndVerifyCallback);
} catch (RemoteException e) {
Log.e(Constants.TAG, "CryptoProviderDemo", e);
@ -228,8 +228,8 @@ public class OpenPgpProviderActivity extends Activity {
if (!providerList.isEmpty()) {
// add "disable OpenPGP provider"
providerList.add(0, new OpenPgpProviderElement(null, "Disable OpenPGP Provider", getResources()
.getDrawable(android.R.drawable.ic_menu_close_clear_cancel)));
providerList.add(0, new OpenPgpProviderElement(null, "Disable OpenPGP Provider",
getResources().getDrawable(android.R.drawable.ic_menu_close_clear_cancel)));
// Init ArrayAdapter with OpenPGP Providers
ListAdapter adapter = new ArrayAdapter<OpenPgpProviderElement>(this,

View File

@ -33,10 +33,13 @@ interface IOpenPgpService {
* User Ids (emails) of recipients
* @param asciiArmor
* Encode for ASCII (Radix-64, 33 percent overhead compared to binary)
* @param allowUserInteraction
* Allows the OpenPGP Provider to handle missing keys by showing activities
* @param callback
* Callback where to return results
*/
oneway void encrypt(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor, in IOpenPgpCallback callback);
oneway void encrypt(in byte[] inputBytes, in String[] encryptionUserIds,
in boolean asciiArmor, in boolean allowUserInteraction, in IOpenPgpCallback callback);
/**
* Sign
@ -45,10 +48,13 @@ interface IOpenPgpService {
* Byte array you want to encrypt
* @param asciiArmor
* Encode for ASCII (Radix-64, 33 percent overhead compared to binary)
* @param allowUserInteraction
* Allows the OpenPGP Provider to handle missing keys by showing activities
* @param callback
* Callback where to return results
*/
oneway void sign(in byte[] inputBytes, in boolean asciiArmor, in IOpenPgpCallback callback);
oneway void sign(in byte[] inputBytes, in boolean asciiArmor, in boolean allowUserInteraction,
in IOpenPgpCallback callback);
/**
* Sign then encrypt
@ -61,10 +67,13 @@ interface IOpenPgpService {
* User Ids (email) of sender
* @param asciiArmor
* Encode for ASCII (Radix-64, 33 percent overhead compared to binary)
* @param allowUserInteraction
* Allows the OpenPGP Provider to handle missing keys by showing activities
* @param callback
* Callback where to return results
*/
oneway void signAndEncrypt(in byte[] inputBytes, in String[] encryptionUserIds, in boolean asciiArmor, in IOpenPgpCallback callback);
oneway void signAndEncrypt(in byte[] inputBytes, in String[] encryptionUserIds,
in boolean asciiArmor, in boolean allowUserInteraction, in IOpenPgpCallback callback);
/**
* Decrypts and verifies given input bytes. If no signature is present this method
@ -72,9 +81,12 @@ interface IOpenPgpService {
*
* @param inputBytes
* Byte array you want to decrypt and verify
* @param allowUserInteraction
* Allows the OpenPGP Provider to handle missing keys by showing activities
* @param callback
* Callback where to return results
*/
oneway void decryptAndVerify(in byte[] inputBytes, in IOpenPgpCallback callback);
oneway void decryptAndVerify(in byte[] inputBytes, in boolean allowUserInteraction,
in IOpenPgpCallback callback);
}

View File

@ -217,8 +217,8 @@ public class OpenPgpService extends RemoteService {
};
private synchronized void encryptAndSignSafe(byte[] inputBytes, String[] encryptionUserIds,
boolean asciiArmor, IOpenPgpCallback callback, AppSettings appSettings, boolean sign)
throws RemoteException {
boolean asciiArmor, boolean allowUserInteraction, IOpenPgpCallback callback,
AppSettings appSettings, boolean sign) throws RemoteException {
try {
// build InputData and write into OutputStream
InputStream inputStream = new ByteArrayInputStream(inputBytes);
@ -269,8 +269,8 @@ public class OpenPgpService extends RemoteService {
}
// TODO: asciiArmor?!
private void signSafe(byte[] inputBytes, IOpenPgpCallback callback, AppSettings appSettings)
throws RemoteException {
private void signSafe(byte[] inputBytes, boolean allowUserInteraction,
IOpenPgpCallback callback, AppSettings appSettings) throws RemoteException {
try {
Log.d(Constants.TAG, "current therad id: " + Thread.currentThread().getId());
@ -309,8 +309,8 @@ public class OpenPgpService extends RemoteService {
}
}
private synchronized void decryptAndVerifySafe(byte[] inputBytes, IOpenPgpCallback callback,
AppSettings appSettings) throws RemoteException {
private synchronized void decryptAndVerifySafe(byte[] inputBytes, boolean allowUserInteraction,
IOpenPgpCallback callback, AppSettings appSettings) throws RemoteException {
try {
// TODO: this is not really needed
// checked if it is text with BEGIN and END tags
@ -459,7 +459,8 @@ public class OpenPgpService extends RemoteService {
@Override
public void encrypt(final byte[] inputBytes, final String[] encryptionUserIds,
final boolean asciiArmor, final IOpenPgpCallback callback) throws RemoteException {
final boolean asciiArmor, final boolean allowUserInteraction,
final IOpenPgpCallback callback) throws RemoteException {
final AppSettings settings = getAppSettings();
@ -468,8 +469,8 @@ public class OpenPgpService extends RemoteService {
@Override
public void run() {
try {
encryptAndSignSafe(inputBytes, encryptionUserIds, asciiArmor, callback,
settings, false);
encryptAndSignSafe(inputBytes, encryptionUserIds, asciiArmor,
allowUserInteraction, callback, settings, false);
} catch (RemoteException e) {
Log.e(Constants.TAG, "OpenPgpService", e);
}
@ -481,7 +482,8 @@ public class OpenPgpService extends RemoteService {
@Override
public void signAndEncrypt(final byte[] inputBytes, final String[] encryptionUserIds,
final boolean asciiArmor, final IOpenPgpCallback callback) throws RemoteException {
final boolean asciiArmor, final boolean allowUserInteraction,
final IOpenPgpCallback callback) throws RemoteException {
final AppSettings settings = getAppSettings();
@ -490,8 +492,8 @@ public class OpenPgpService extends RemoteService {
@Override
public void run() {
try {
encryptAndSignSafe(inputBytes, encryptionUserIds, asciiArmor, callback,
settings, true);
encryptAndSignSafe(inputBytes, encryptionUserIds, asciiArmor,
allowUserInteraction, callback, settings, true);
} catch (RemoteException e) {
Log.e(Constants.TAG, "OpenPgpService", e);
}
@ -503,7 +505,8 @@ public class OpenPgpService extends RemoteService {
@Override
public void sign(final byte[] inputBytes, boolean asciiArmor,
final IOpenPgpCallback callback) throws RemoteException {
final boolean allowUserInteraction, final IOpenPgpCallback callback)
throws RemoteException {
final AppSettings settings = getAppSettings();
Runnable r = new Runnable() {
@ -511,7 +514,7 @@ public class OpenPgpService extends RemoteService {
@Override
public void run() {
try {
signSafe(inputBytes, callback, settings);
signSafe(inputBytes, allowUserInteraction, callback, settings);
} catch (RemoteException e) {
Log.e(Constants.TAG, "OpenPgpService", e);
}
@ -523,8 +526,8 @@ public class OpenPgpService extends RemoteService {
}
@Override
public void decryptAndVerify(final byte[] inputBytes, final IOpenPgpCallback callback)
throws RemoteException {
public void decryptAndVerify(final byte[] inputBytes, final boolean allowUserInteraction,
final IOpenPgpCallback callback) throws RemoteException {
final AppSettings settings = getAppSettings();
@ -533,7 +536,7 @@ public class OpenPgpService extends RemoteService {
@Override
public void run() {
try {
decryptAndVerifySafe(inputBytes, callback, settings);
decryptAndVerifySafe(inputBytes, allowUserInteraction, callback, settings);
} catch (RemoteException e) {
Log.e(Constants.TAG, "OpenPgpService", e);
}