Java Code Examples for org.openintents.openpgp.OpenPgpError

The following examples show how to use org.openintents.openpgp.OpenPgpError. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: andOTP   Source File: BackupActivity.java    License: MIT License 5 votes vote down vote up
public void handleOpenPGPResult(Intent result, ByteArrayOutputStream os, Uri file, int requestCode) {
    if (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR) == OpenPgpApi.RESULT_CODE_SUCCESS) {
        if (requestCode == Constants.INTENT_BACKUP_ENCRYPT_PGP) {
            if (os != null)
                doBackupEncrypted(file, outputStreamToString(os));
        } else if (requestCode == Constants.INTENT_BACKUP_DECRYPT_PGP) {
            if (os != null) {
                if (settings.getOpenPGPVerify()) {
                    OpenPgpSignatureResult sigResult = result.getParcelableExtra(OpenPgpApi.RESULT_SIGNATURE);

                    if (sigResult.getResult() == OpenPgpSignatureResult.RESULT_VALID_KEY_CONFIRMED) {
                        restoreEntries(outputStreamToString(os));
                    } else {
                        Toast.makeText(this, R.string.backup_toast_openpgp_not_verified, Toast.LENGTH_LONG).show();
                    }
                } else {
                    restoreEntries(outputStreamToString(os));
                }
            }
        }
    } else if (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR) == OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED) {
        PendingIntent pi = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);

        // Small hack to keep the target file even after user interaction
        if (requestCode == Constants.INTENT_BACKUP_ENCRYPT_PGP) {
            encryptTargetFile = file;
        } else if (requestCode == Constants.INTENT_BACKUP_DECRYPT_PGP) {
            decryptSourceFile = file;
        }

        try {
            startIntentSenderForResult(pi.getIntentSender(), requestCode, null, 0, 0, 0);
        } catch (IntentSender.SendIntentException e) {
            e.printStackTrace();
        }
    } else if (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR) == OpenPgpApi.RESULT_CODE_ERROR) {
        OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
        Toast.makeText(this, String.format(getString(R.string.backup_toast_openpgp_error), error.getMessage()), Toast.LENGTH_LONG).show();
    }
}
 
Example 2
Source Project: Pix-Art-Messenger   Source File: PgpEngine.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static void logError(Account account, OpenPgpError error) {
    if (error != null) {
        error.describeContents();
        Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId() + " class=" + error.getClass().getName());
    } else {
        Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error with no message");
    }
}
 
Example 3
Source Project: openpgp-api   Source File: OpenPgpApiActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void handleError(final OpenPgpError error) {
    runOnUiThread(new Runnable() {

        @Override
        public void run() {
            Toast.makeText(OpenPgpApiActivity.this,
                    "onError id:" + error.getErrorId() + "\n\n" + error.getMessage(),
                    Toast.LENGTH_LONG).show();
            Log.e(Constants.TAG, "onError getErrorId:" + error.getErrorId());
            Log.e(Constants.TAG, "onError getMessage:" + error.getMessage());
        }
    });
}
 
Example 4
Source Project: openpgp-api   Source File: OpenPgpKeyPreference.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onReturn(Intent result) {
    switch (result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
        case OpenPgpApi.RESULT_CODE_SUCCESS: {

            long keyId = result.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, NO_KEY);
            save(keyId);

            break;
        }
        case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED: {

            PendingIntent pi = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
            try {
                Activity act = (Activity) getContext();
                act.startIntentSenderFromChild(
                        act, pi.getIntentSender(),
                        requestCode, null, 0, 0, 0);
            } catch (IntentSender.SendIntentException e) {
                Log.e(OpenPgpApi.TAG, "SendIntentException", e);
            }
            break;
        }
        case OpenPgpApi.RESULT_CODE_ERROR: {
            OpenPgpError error = result.getParcelableExtra(OpenPgpApi.RESULT_ERROR);
            Log.e(OpenPgpApi.TAG, "RESULT_CODE_ERROR: " + error.getMessage());

            break;
        }
    }
}
 
Example 5
Source Project: Conversations   Source File: PgpEngine.java    License: GNU General Public License v3.0 5 votes vote down vote up
private static void logError(Account account, OpenPgpError error) {
	if (error != null) {
		error.describeContents();
		Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error '" + error.getMessage() + "' code=" + error.getErrorId()+" class="+error.getClass().getName());
	} else {
		Log.d(Config.LOGTAG, account.getJid().asBareJid().toString() + ": OpenKeychain error with no message");
	}
}