extract creation of error result intent into method
This commit is contained in:
@@ -189,11 +189,7 @@ public class OpenPgpService extends Service {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(Constants.TAG, "signImpl", e);
|
Log.d(Constants.TAG, "signImpl", e);
|
||||||
Intent result = new Intent();
|
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, e.getMessage());
|
||||||
result.putExtra(OpenPgpApi.RESULT_ERROR,
|
|
||||||
new OpenPgpError(OpenPgpError.GENERIC_ERROR, e.getMessage()));
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,11 +243,8 @@ public class OpenPgpService extends Service {
|
|||||||
if (keyIdResult.hasKeySelectionPendingIntent()) {
|
if (keyIdResult.hasKeySelectionPendingIntent()) {
|
||||||
if ((keyIdResultStatus == KeyIdResultStatus.MISSING || keyIdResultStatus == KeyIdResultStatus.NO_KEYS ||
|
if ((keyIdResultStatus == KeyIdResultStatus.MISSING || keyIdResultStatus == KeyIdResultStatus.NO_KEYS ||
|
||||||
keyIdResultStatus == KeyIdResultStatus.NO_KEYS_ERROR) && isOpportunistic) {
|
keyIdResultStatus == KeyIdResultStatus.NO_KEYS_ERROR) && isOpportunistic) {
|
||||||
Intent result = new Intent();
|
return createErrorResultIntent(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS,
|
||||||
result.putExtra(OpenPgpApi.RESULT_ERROR,
|
"missing keys in opportunistic mode");
|
||||||
new OpenPgpError(OpenPgpError.OPPORTUNISTIC_MISSING_KEYS, "missing keys in opportunistic mode"));
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent result = new Intent();
|
Intent result = new Intent();
|
||||||
@@ -301,11 +294,7 @@ public class OpenPgpService extends Service {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(Constants.TAG, "encryptAndSignImpl", e);
|
Log.d(Constants.TAG, "encryptAndSignImpl", e);
|
||||||
Intent result = new Intent();
|
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, e.getMessage());
|
||||||
result.putExtra(OpenPgpApi.RESULT_ERROR,
|
|
||||||
new OpenPgpError(OpenPgpError.GENERIC_ERROR, e.getMessage()));
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,18 +378,12 @@ public class OpenPgpService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String errorMsg = getString(pgpResult.getLog().getLast().mType.getMsgId());
|
String errorMsg = getString(pgpResult.getLog().getLast().mType.getMsgId());
|
||||||
Intent result = new Intent();
|
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, errorMsg);
|
||||||
result.putExtra(OpenPgpApi.RESULT_ERROR, new OpenPgpError(OpenPgpError.GENERIC_ERROR, errorMsg));
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(Constants.TAG, "decryptAndVerifyImpl", e);
|
Log.e(Constants.TAG, "decryptAndVerifyImpl", e);
|
||||||
Intent result = new Intent();
|
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, e.getMessage());
|
||||||
result.putExtra(OpenPgpApi.RESULT_ERROR, new OpenPgpError(OpenPgpError.GENERIC_ERROR, e.getMessage()));
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -536,14 +519,19 @@ public class OpenPgpService extends Service {
|
|||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(Constants.TAG, "getKeyImpl", e);
|
Log.d(Constants.TAG, "getKeyImpl", e);
|
||||||
Intent result = new Intent();
|
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, e.getMessage());
|
||||||
result.putExtra(OpenPgpApi.RESULT_ERROR,
|
|
||||||
new OpenPgpError(OpenPgpError.GENERIC_ERROR, e.getMessage()));
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
private Intent createErrorResultIntent(int errorCode, String errorMsg) {
|
||||||
|
Intent result = new Intent();
|
||||||
|
result.putExtra(OpenPgpApi.RESULT_ERROR,
|
||||||
|
new OpenPgpError(errorCode, errorMsg));
|
||||||
|
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private Intent getSignKeyIdImpl(Intent data) {
|
private Intent getSignKeyIdImpl(Intent data) {
|
||||||
// if data already contains EXTRA_SIGN_KEY_ID, it has been executed again
|
// if data already contains EXTRA_SIGN_KEY_ID, it has been executed again
|
||||||
// after user interaction. Then, we just need to return the long again!
|
// after user interaction. Then, we just need to return the long again!
|
||||||
@@ -613,18 +601,11 @@ public class OpenPgpService extends Service {
|
|||||||
} else {
|
} else {
|
||||||
// should not happen normally...
|
// should not happen normally...
|
||||||
String errorMsg = getString(pgpResult.getLog().getLast().mType.getMsgId());
|
String errorMsg = getString(pgpResult.getLog().getLast().mType.getMsgId());
|
||||||
Intent result = new Intent();
|
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, errorMsg);
|
||||||
result.putExtra(OpenPgpApi.RESULT_ERROR, new OpenPgpError(OpenPgpError.GENERIC_ERROR, errorMsg));
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d(Constants.TAG, "backupImpl", e);
|
Log.d(Constants.TAG, "backupImpl", e);
|
||||||
Intent result = new Intent();
|
return createErrorResultIntent(OpenPgpError.GENERIC_ERROR, e.getMessage());
|
||||||
result.putExtra(OpenPgpApi.RESULT_ERROR,
|
|
||||||
new OpenPgpError(OpenPgpError.GENERIC_ERROR, e.getMessage()));
|
|
||||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user