private request codes, pass params through methods and pending intents, getKeyIds method

This commit is contained in:
Dominik Schürmann
2014-02-15 01:06:03 +01:00
parent 21ba41edae
commit 494a5fa414
8 changed files with 220 additions and 135 deletions

View File

@@ -159,7 +159,7 @@ public class OpenPgpProviderActivity extends Activity {
mCiphertext.setText(os.toString("UTF-8")); mCiphertext.setText(os.toString("UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); Log.e(Constants.TAG, "UnsupportedEncodingException", e);
} }
break; break;
} }
@@ -170,7 +170,7 @@ public class OpenPgpProviderActivity extends Activity {
REQUEST_CODE_SIGN, null, REQUEST_CODE_SIGN, null,
0, 0, 0); 0, 0, 0);
} catch (IntentSender.SendIntentException e) { } catch (IntentSender.SendIntentException e) {
e.printStackTrace(); Log.e(Constants.TAG, "SendIntentException", e);
} }
break; break;
} }
@@ -198,7 +198,7 @@ public class OpenPgpProviderActivity extends Activity {
mCiphertext.setText(os.toString("UTF-8")); mCiphertext.setText(os.toString("UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); Log.e(Constants.TAG, "UnsupportedEncodingException", e);
} }
break; break;
} }
@@ -209,7 +209,7 @@ public class OpenPgpProviderActivity extends Activity {
REQUEST_CODE_ENCRYPT, null, REQUEST_CODE_ENCRYPT, null,
0, 0, 0); 0, 0, 0);
} catch (IntentSender.SendIntentException e) { } catch (IntentSender.SendIntentException e) {
e.printStackTrace(); Log.e(Constants.TAG, "SendIntentException", e);
} }
break; break;
} }
@@ -237,7 +237,7 @@ public class OpenPgpProviderActivity extends Activity {
mCiphertext.setText(os.toString("UTF-8")); mCiphertext.setText(os.toString("UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); Log.e(Constants.TAG, "UnsupportedEncodingException", e);
} }
break; break;
} }
@@ -248,7 +248,7 @@ public class OpenPgpProviderActivity extends Activity {
REQUEST_CODE_SIGN_AND_ENCRYPT, null, REQUEST_CODE_SIGN_AND_ENCRYPT, null,
0, 0, 0); 0, 0, 0);
} catch (IntentSender.SendIntentException e) { } catch (IntentSender.SendIntentException e) {
e.printStackTrace(); Log.e(Constants.TAG, "SendIntentException", e);
} }
break; break;
} }
@@ -275,7 +275,7 @@ public class OpenPgpProviderActivity extends Activity {
mMessage.setText(os.toString("UTF-8")); mMessage.setText(os.toString("UTF-8"));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
e.printStackTrace(); Log.e(Constants.TAG, "UnsupportedEncodingException", e);
} }
break; break;
} }
@@ -286,7 +286,7 @@ public class OpenPgpProviderActivity extends Activity {
REQUEST_CODE_DECRYPT_AND_VERIFY, null, REQUEST_CODE_DECRYPT_AND_VERIFY, null,
0, 0, 0); 0, 0, 0);
} catch (IntentSender.SendIntentException e) { } catch (IntentSender.SendIntentException e) {
e.printStackTrace(); Log.e(Constants.TAG, "SendIntentException", e);
} }
break; break;
} }
@@ -297,7 +297,8 @@ public class OpenPgpProviderActivity extends Activity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data); super.onActivityResult(requestCode, resultCode, data);
Log.d(Constants.TAG, "onActivityResult"); Log.d(Constants.TAG, "onActivityResult");
switch (requestCode) { switch (requestCode) {
case REQUEST_CODE_SIGN: { case REQUEST_CODE_SIGN: {
@@ -305,7 +306,7 @@ public class OpenPgpProviderActivity extends Activity {
// try to sign again after password caching // try to sign again after password caching
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
sign(new Bundle()); sign(data.getExtras());
} }
break; break;
} }

View File

@@ -64,4 +64,15 @@ interface IOpenPgpService {
*/ */
Bundle decryptAndVerify(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output); Bundle decryptAndVerify(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
/**
* Retrieves key ids based on given user ids (=emails)
*
* params:
* String[] user_ids
*
* result:
* long[] key_ids
*/
Bundle getKeyIds(in Bundle params);
} }

View File

@@ -35,6 +35,7 @@ public class OpenPgpApi {
private static final int OPERATION_ENCRYPT = 1; private static final int OPERATION_ENCRYPT = 1;
private static final int OPERATION_SIGN_ENCRYPT = 2; private static final int OPERATION_SIGN_ENCRYPT = 2;
private static final int OPERATION_DECRYPT_VERIFY = 3; private static final int OPERATION_DECRYPT_VERIFY = 3;
private static final int OPERATION_GET_KEY_IDS = 4;
public OpenPgpApi(IOpenPgpService service) { public OpenPgpApi(IOpenPgpService service) {
this.mService = service; this.mService = service;
@@ -88,6 +89,10 @@ public class OpenPgpApi {
executeApiAsync(OPERATION_DECRYPT_VERIFY, params, is, os, callback); executeApiAsync(OPERATION_DECRYPT_VERIFY, params, is, os, callback);
} }
public Bundle getKeyIds(Bundle params) {
return executeApi(OPERATION_GET_KEY_IDS, params, null, null);
}
public interface IOpenPgpCallback { public interface IOpenPgpCallback {
void onReturn(final Bundle result); void onReturn(final Bundle result);
} }
@@ -124,24 +129,6 @@ public class OpenPgpApi {
private Bundle executeApi(int operationId, Bundle params, InputStream is, OutputStream os) { private Bundle executeApi(int operationId, Bundle params, InputStream is, OutputStream os) {
try { try {
// send the input and output pfds
ParcelFileDescriptor input = ParcelFileDescriptorUtil.pipeFrom(is,
new ParcelFileDescriptorUtil.IThreadListener() {
@Override
public void onThreadFinished(Thread thread) {
Log.d(OpenPgpConstants.TAG, "Copy to service finished");
}
});
ParcelFileDescriptor output = ParcelFileDescriptorUtil.pipeTo(os,
new ParcelFileDescriptorUtil.IThreadListener() {
@Override
public void onThreadFinished(Thread thread) {
Log.d(OpenPgpConstants.TAG, "Service finished writing!");
}
});
params.putInt(OpenPgpConstants.PARAMS_API_VERSION, OpenPgpConstants.API_VERSION); params.putInt(OpenPgpConstants.PARAMS_API_VERSION, OpenPgpConstants.API_VERSION);
// default result is error // default result is error
@@ -150,25 +137,49 @@ public class OpenPgpApi {
result.putParcelable(OpenPgpConstants.RESULT_ERRORS, result.putParcelable(OpenPgpConstants.RESULT_ERRORS,
new OpenPgpError(OpenPgpError.GENERIC_ERROR, "This should never happen!")); new OpenPgpError(OpenPgpError.GENERIC_ERROR, "This should never happen!"));
// blocks until result is ready if (operationId == OPERATION_GET_KEY_IDS) {
switch (operationId) { result = mService.getKeyIds(params);
case OPERATION_SIGN: return result;
result = mService.sign(params, input, output); } else {
break; // send the input and output pfds
case OPERATION_ENCRYPT: ParcelFileDescriptor input = ParcelFileDescriptorUtil.pipeFrom(is,
result = mService.encrypt(params, input, output); new ParcelFileDescriptorUtil.IThreadListener() {
break;
case OPERATION_SIGN_ENCRYPT:
result = mService.signAndEncrypt(params, input, output);
break;
case OPERATION_DECRYPT_VERIFY:
result = mService.decryptAndVerify(params, input, output);
break;
}
// close() is required to halt the TransferThread
output.close();
return result; @Override
public void onThreadFinished(Thread thread) {
Log.d(OpenPgpConstants.TAG, "Copy to service finished");
}
});
ParcelFileDescriptor output = ParcelFileDescriptorUtil.pipeTo(os,
new ParcelFileDescriptorUtil.IThreadListener() {
@Override
public void onThreadFinished(Thread thread) {
Log.d(OpenPgpConstants.TAG, "Service finished writing!");
}
});
// blocks until result is ready
switch (operationId) {
case OPERATION_SIGN:
result = mService.sign(params, input, output);
break;
case OPERATION_ENCRYPT:
result = mService.encrypt(params, input, output);
break;
case OPERATION_SIGN_ENCRYPT:
result = mService.signAndEncrypt(params, input, output);
break;
case OPERATION_DECRYPT_VERIFY:
result = mService.decryptAndVerify(params, input, output);
break;
}
// close() is required to halt the TransferThread
output.close();
return result;
}
} catch (Exception e) { } catch (Exception e) {
Log.e(OpenPgpConstants.TAG, "Exception", e); Log.e(OpenPgpConstants.TAG, "Exception", e);
Bundle result = new Bundle(); Bundle result = new Bundle();

View File

@@ -87,12 +87,12 @@ public class ParcelFileDescriptorUtil {
try { try {
mIn.close(); mIn.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e(OpenPgpConstants.TAG, "TransferThread" + getId(), e);
} }
try { try {
mOut.close(); mOut.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e(OpenPgpConstants.TAG, "TransferThread" + getId(), e);
} }
} }
if (mListener != null) { if (mListener != null) {

View File

@@ -46,6 +46,9 @@ import java.util.ArrayList;
public class OpenPgpService extends RemoteService { public class OpenPgpService extends RemoteService {
private static final int PRIVATE_REQUEST_CODE_PASSPHRASE = 551;
private static final int PRIVATE_REQUEST_CODE_USER_IDS = 552;
/** /**
* Search database for key ids based on emails. * Search database for key ids based on emails.
@@ -95,7 +98,7 @@ public class OpenPgpService extends RemoteService {
intent.putExtra(RemoteServiceActivity.EXTRA_MISSING_USER_IDS, missingUserIds); intent.putExtra(RemoteServiceActivity.EXTRA_MISSING_USER_IDS, missingUserIds);
intent.putExtra(RemoteServiceActivity.EXTRA_DUBLICATE_USER_IDS, dublicateUserIds); intent.putExtra(RemoteServiceActivity.EXTRA_DUBLICATE_USER_IDS, dublicateUserIds);
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 42, intent, 0); PendingIntent pi = PendingIntent.getActivity(getBaseContext(), PRIVATE_REQUEST_CODE_USER_IDS, intent, 0);
// return PendingIntent to be executed by client // return PendingIntent to be executed by client
Bundle result = new Bundle(); Bundle result = new Bundle();
@@ -120,7 +123,7 @@ public class OpenPgpService extends RemoteService {
Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class); Intent intent = new Intent(getBaseContext(), RemoteServiceActivity.class);
intent.setAction(RemoteServiceActivity.ACTION_CACHE_PASSPHRASE); intent.setAction(RemoteServiceActivity.ACTION_CACHE_PASSPHRASE);
intent.putExtra(RemoteServiceActivity.EXTRA_SECRET_KEY_ID, keyId); intent.putExtra(RemoteServiceActivity.EXTRA_SECRET_KEY_ID, keyId);
PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 42, intent, 0); PendingIntent pi = PendingIntent.getActivity(getBaseContext(), PRIVATE_REQUEST_CODE_PASSPHRASE, intent, 0);
// return PendingIntent to be executed by client // return PendingIntent to be executed by client
Bundle result = new Bundle(); Bundle result = new Bundle();
@@ -130,6 +133,46 @@ public class OpenPgpService extends RemoteService {
return result; return result;
} }
// TODO: asciiArmor?!
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 = PassphraseCacheService.getCachedPassphrase(getContext(), appSettings.getKeyId());
if (passphrase == null) {
// get PendingIntent for passphrase input, add it to given params and return to client
Bundle passphraseBundle = getPassphraseBundleIntent(appSettings.getKeyId());
params.putAll(passphraseBundle);
return params;
}
// Get Input- and OutputStream from ParcelFileDescriptor
InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(input);
OutputStream os = new ParcelFileDescriptor.AutoCloseOutputStream(output);
try {
long inputLength = is.available();
InputData inputData = new InputData(is, inputLength);
PgpOperation operation = new PgpOperation(getContext(), null, inputData, os);
operation.signText(appSettings.getKeyId(), passphrase, appSettings.getHashAlgorithm(),
Preferences.getPreferences(this).getForceV3Signatures());
} finally {
is.close();
os.close();
}
Bundle result = new Bundle();
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_SUCCESS);
return result;
} catch (Exception e) {
Bundle result = new Bundle();
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
result.putParcelable(OpenPgpConstants.RESULT_ERRORS,
new OpenPgpError(OpenPgpError.GENERIC_ERROR, e.getMessage()));
return result;
}
}
private Bundle encryptAndSignImpl(Bundle params, ParcelFileDescriptor input, private Bundle encryptAndSignImpl(Bundle params, ParcelFileDescriptor input,
ParcelFileDescriptor output, AppSettings appSettings, ParcelFileDescriptor output, AppSettings appSettings,
boolean sign) { boolean sign) {
@@ -143,13 +186,14 @@ public class OpenPgpService extends RemoteService {
// get key ids based on given user ids // get key ids based on given user ids
String[] userIds = params.getStringArray(OpenPgpConstants.PARAMS_USER_IDS); String[] userIds = params.getStringArray(OpenPgpConstants.PARAMS_USER_IDS);
Bundle result = getKeyIdsFromEmails(userIds); Bundle result = getKeyIdsFromEmails(userIds);
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_USER_INTERACTION_REQUIRED);
if (result.getInt(OpenPgpConstants.RESULT_CODE, 0) == OpenPgpConstants.RESULT_CODE_SUCCESS) { if (result.getInt(OpenPgpConstants.RESULT_CODE, 0) == OpenPgpConstants.RESULT_CODE_SUCCESS) {
keyIds = result.getLongArray(OpenPgpConstants.PARAMS_KEY_IDS); keyIds = result.getLongArray(OpenPgpConstants.PARAMS_KEY_IDS);
} else { } else {
// non-unique result, we need user interaction! // if not success -> result contains a PendingIntent for user interaction
return result; // return all old params with the new PendingIntent to client!
params.putAll(result);
return params;
} }
} }
@@ -170,7 +214,10 @@ public class OpenPgpService extends RemoteService {
String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(),
appSettings.getKeyId()); appSettings.getKeyId());
if (passphrase == null) { if (passphrase == null) {
return getPassphraseBundleIntent(appSettings.getKeyId()); // get PendingIntent for passphrase input, add it to given params and return to client
Bundle passphraseBundle = getPassphraseBundleIntent(appSettings.getKeyId());
params.putAll(passphraseBundle);
return params;
} }
operation.signAndEncrypt(asciiArmor, appSettings.getCompression(), keyIds, null, operation.signAndEncrypt(asciiArmor, appSettings.getCompression(), keyIds, null,
@@ -198,42 +245,6 @@ public class OpenPgpService extends RemoteService {
} }
} }
// TODO: asciiArmor?!
private Bundle signImpl(ParcelFileDescriptor input, ParcelFileDescriptor output, AppSettings appSettings) {
try {
// get passphrase from cache, if key has "no" passphrase, this returns an empty String
String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), appSettings.getKeyId());
if (passphrase == null) {
return getPassphraseBundleIntent(appSettings.getKeyId());
}
// Get Input- and OutputStream from ParcelFileDescriptor
InputStream is = new ParcelFileDescriptor.AutoCloseInputStream(input);
OutputStream os = new ParcelFileDescriptor.AutoCloseOutputStream(output);
try {
long inputLength = is.available();
InputData inputData = new InputData(is, inputLength);
PgpOperation operation = new PgpOperation(getContext(), null, inputData, os);
operation.signText(appSettings.getKeyId(), passphrase, appSettings.getHashAlgorithm(),
Preferences.getPreferences(this).getForceV3Signatures());
} finally {
is.close();
os.close();
}
Bundle result = new Bundle();
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_SUCCESS);
return result;
} catch (Exception e) {
Bundle result = new Bundle();
result.putInt(OpenPgpConstants.RESULT_CODE, OpenPgpConstants.RESULT_CODE_ERROR);
result.putParcelable(OpenPgpConstants.RESULT_ERRORS,
new OpenPgpError(OpenPgpError.GENERIC_ERROR, e.getMessage()));
return result;
}
}
private Bundle decryptAndVerifyImpl(Bundle params, ParcelFileDescriptor input, private Bundle decryptAndVerifyImpl(Bundle params, ParcelFileDescriptor input,
ParcelFileDescriptor output, AppSettings appSettings) { ParcelFileDescriptor output, AppSettings appSettings) {
try { try {
@@ -323,11 +334,14 @@ public class OpenPgpService extends RemoteService {
// //
// Log.d(Constants.TAG, "secretKeyId " + secretKeyId); // Log.d(Constants.TAG, "secretKeyId " + secretKeyId);
// NOTE: currently this only gets the passphrase for the saved key // NOTE: currently this only gets the passphrase for the saved key
String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), appSettings.getKeyId()); String passphrase = PassphraseCacheService.getCachedPassphrase(getContext(), appSettings.getKeyId());
if (passphrase == null) { if (passphrase == null) {
return getPassphraseBundleIntent(appSettings.getKeyId()); // get PendingIntent for passphrase input, add it to given params and return to client
} Bundle passphraseBundle = getPassphraseBundleIntent(appSettings.getKeyId());
params.putAll(passphraseBundle);
return params;
}
// } // }
// build InputData and write into OutputStream // build InputData and write into OutputStream
@@ -390,6 +404,15 @@ public class OpenPgpService extends RemoteService {
} }
} }
private Bundle getKeyIdsImpl(Bundle params) {
// get key ids based on given user ids
String[] userIds = params.getStringArray(OpenPgpConstants.PARAMS_USER_IDS);
Bundle result = getKeyIdsFromEmails(userIds);
params.putAll(result);
return params;
}
/** /**
* Checks that params != null and API version fits * Checks that params != null and API version fits
* *
@@ -430,7 +453,7 @@ public class OpenPgpService extends RemoteService {
return errorResult; return errorResult;
} }
return signImpl(input, output, appSettings); return signImpl(params, input, output, appSettings);
} }
@Override @Override
@@ -459,10 +482,27 @@ public class OpenPgpService extends RemoteService {
@Override @Override
public Bundle decryptAndVerify(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output) { public Bundle decryptAndVerify(Bundle params, ParcelFileDescriptor input, ParcelFileDescriptor output) {
final AppSettings appSettings = getAppSettings();
return null; Bundle errorResult = validateParamsAndVersion(params);
if (errorResult != null) {
return errorResult;
}
return decryptAndVerifyImpl(params, input, output, appSettings);
} }
@Override
public Bundle getKeyIds(Bundle params) {
Bundle errorResult = validateParamsAndVersion(params);
if (errorResult != null) {
return errorResult;
}
return getKeyIdsImpl(params);
}
// TODO: old example for checkAndEnqueue!
// @Override // @Override
// public void getKeyIds(final String[] userIds, final boolean allowUserInteraction, // public void getKeyIds(final String[] userIds, final boolean allowUserInteraction,
// final IOpenPgpKeyIdsCallback callback) throws RemoteException { // final IOpenPgpKeyIdsCallback callback) throws RemoteException {

View File

@@ -64,4 +64,15 @@ interface IOpenPgpService {
*/ */
Bundle decryptAndVerify(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output); Bundle decryptAndVerify(in Bundle params, in ParcelFileDescriptor input, in ParcelFileDescriptor output);
/**
* Retrieves key ids based on given user ids (=emails)
*
* params:
* String[] user_ids
*
* result:
* long[] key_ids
*/
Bundle getKeyIds(in Bundle params);
} }

View File

@@ -35,6 +35,7 @@ public class OpenPgpApi {
private static final int OPERATION_ENCRYPT = 1; private static final int OPERATION_ENCRYPT = 1;
private static final int OPERATION_SIGN_ENCRYPT = 2; private static final int OPERATION_SIGN_ENCRYPT = 2;
private static final int OPERATION_DECRYPT_VERIFY = 3; private static final int OPERATION_DECRYPT_VERIFY = 3;
private static final int OPERATION_GET_KEY_IDS = 4;
public OpenPgpApi(IOpenPgpService service) { public OpenPgpApi(IOpenPgpService service) {
this.mService = service; this.mService = service;
@@ -88,6 +89,10 @@ public class OpenPgpApi {
executeApiAsync(OPERATION_DECRYPT_VERIFY, params, is, os, callback); executeApiAsync(OPERATION_DECRYPT_VERIFY, params, is, os, callback);
} }
public Bundle getKeyIds(Bundle params) {
return executeApi(OPERATION_GET_KEY_IDS, params, null, null);
}
public interface IOpenPgpCallback { public interface IOpenPgpCallback {
void onReturn(final Bundle result); void onReturn(final Bundle result);
} }
@@ -124,24 +129,6 @@ public class OpenPgpApi {
private Bundle executeApi(int operationId, Bundle params, InputStream is, OutputStream os) { private Bundle executeApi(int operationId, Bundle params, InputStream is, OutputStream os) {
try { try {
// send the input and output pfds
ParcelFileDescriptor input = ParcelFileDescriptorUtil.pipeFrom(is,
new ParcelFileDescriptorUtil.IThreadListener() {
@Override
public void onThreadFinished(Thread thread) {
Log.d(OpenPgpConstants.TAG, "Copy to service finished");
}
});
ParcelFileDescriptor output = ParcelFileDescriptorUtil.pipeTo(os,
new ParcelFileDescriptorUtil.IThreadListener() {
@Override
public void onThreadFinished(Thread thread) {
Log.d(OpenPgpConstants.TAG, "Service finished writing!");
}
});
params.putInt(OpenPgpConstants.PARAMS_API_VERSION, OpenPgpConstants.API_VERSION); params.putInt(OpenPgpConstants.PARAMS_API_VERSION, OpenPgpConstants.API_VERSION);
// default result is error // default result is error
@@ -150,25 +137,49 @@ public class OpenPgpApi {
result.putParcelable(OpenPgpConstants.RESULT_ERRORS, result.putParcelable(OpenPgpConstants.RESULT_ERRORS,
new OpenPgpError(OpenPgpError.GENERIC_ERROR, "This should never happen!")); new OpenPgpError(OpenPgpError.GENERIC_ERROR, "This should never happen!"));
// blocks until result is ready if (operationId == OPERATION_GET_KEY_IDS) {
switch (operationId) { result = mService.getKeyIds(params);
case OPERATION_SIGN: return result;
result = mService.sign(params, input, output); } else {
break; // send the input and output pfds
case OPERATION_ENCRYPT: ParcelFileDescriptor input = ParcelFileDescriptorUtil.pipeFrom(is,
result = mService.encrypt(params, input, output); new ParcelFileDescriptorUtil.IThreadListener() {
break;
case OPERATION_SIGN_ENCRYPT:
result = mService.signAndEncrypt(params, input, output);
break;
case OPERATION_DECRYPT_VERIFY:
result = mService.decryptAndVerify(params, input, output);
break;
}
// close() is required to halt the TransferThread
output.close();
return result; @Override
public void onThreadFinished(Thread thread) {
Log.d(OpenPgpConstants.TAG, "Copy to service finished");
}
});
ParcelFileDescriptor output = ParcelFileDescriptorUtil.pipeTo(os,
new ParcelFileDescriptorUtil.IThreadListener() {
@Override
public void onThreadFinished(Thread thread) {
Log.d(OpenPgpConstants.TAG, "Service finished writing!");
}
});
// blocks until result is ready
switch (operationId) {
case OPERATION_SIGN:
result = mService.sign(params, input, output);
break;
case OPERATION_ENCRYPT:
result = mService.encrypt(params, input, output);
break;
case OPERATION_SIGN_ENCRYPT:
result = mService.signAndEncrypt(params, input, output);
break;
case OPERATION_DECRYPT_VERIFY:
result = mService.decryptAndVerify(params, input, output);
break;
}
// close() is required to halt the TransferThread
output.close();
return result;
}
} catch (Exception e) { } catch (Exception e) {
Log.e(OpenPgpConstants.TAG, "Exception", e); Log.e(OpenPgpConstants.TAG, "Exception", e);
Bundle result = new Bundle(); Bundle result = new Bundle();

View File

@@ -87,12 +87,12 @@ public class ParcelFileDescriptorUtil {
try { try {
mIn.close(); mIn.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e(OpenPgpConstants.TAG, "TransferThread" + getId(), e);
} }
try { try {
mOut.close(); mOut.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); Log.e(OpenPgpConstants.TAG, "TransferThread" + getId(), e);
} }
} }
if (mListener != null) { if (mListener != null) {