Passthrough of data Intent in methods of ApiPendingIntentFactory instead of constructor
This commit is contained in:
@@ -41,25 +41,23 @@ import java.util.ArrayList;
|
||||
public class ApiPendingIntentFactory {
|
||||
|
||||
Context mContext;
|
||||
private Intent mPendingIntentData;
|
||||
|
||||
public ApiPendingIntentFactory(Context context, Intent data) {
|
||||
public ApiPendingIntentFactory(Context context) {
|
||||
mContext = context;
|
||||
mPendingIntentData = data;
|
||||
}
|
||||
|
||||
PendingIntent requiredInputPi(RequiredInputParcel requiredInput,
|
||||
PendingIntent requiredInputPi(Intent data, RequiredInputParcel requiredInput,
|
||||
CryptoInputParcel cryptoInput) {
|
||||
|
||||
switch (requiredInput.mType) {
|
||||
case NFC_MOVE_KEY_TO_CARD:
|
||||
case NFC_DECRYPT:
|
||||
case NFC_SIGN: {
|
||||
return createNfcOperationPendingIntent(requiredInput, cryptoInput);
|
||||
return createNfcOperationPendingIntent(data, requiredInput, cryptoInput);
|
||||
}
|
||||
|
||||
case PASSPHRASE: {
|
||||
return createPassphrasePendingIntent(requiredInput, cryptoInput);
|
||||
return createPassphrasePendingIntent(data, requiredInput, cryptoInput);
|
||||
}
|
||||
|
||||
default:
|
||||
@@ -67,25 +65,25 @@ public class ApiPendingIntentFactory {
|
||||
}
|
||||
}
|
||||
|
||||
private PendingIntent createNfcOperationPendingIntent(RequiredInputParcel requiredInput, CryptoInputParcel cryptoInput) {
|
||||
private PendingIntent createNfcOperationPendingIntent(Intent data, RequiredInputParcel requiredInput, CryptoInputParcel cryptoInput) {
|
||||
Intent intent = new Intent(mContext, RemoteSecurityTokenOperationActivity.class);
|
||||
// pass params through to activity that it can be returned again later to repeat pgp operation
|
||||
intent.putExtra(RemoteSecurityTokenOperationActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
||||
intent.putExtra(RemoteSecurityTokenOperationActivity.EXTRA_CRYPTO_INPUT, cryptoInput);
|
||||
|
||||
return createInternal(intent);
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
private PendingIntent createPassphrasePendingIntent(RequiredInputParcel requiredInput, CryptoInputParcel cryptoInput) {
|
||||
private PendingIntent createPassphrasePendingIntent(Intent data, RequiredInputParcel requiredInput, CryptoInputParcel cryptoInput) {
|
||||
Intent intent = new Intent(mContext, RemotePassphraseDialogActivity.class);
|
||||
// pass params through to activity that it can be returned again later to repeat pgp operation
|
||||
intent.putExtra(RemotePassphraseDialogActivity.EXTRA_REQUIRED_INPUT, requiredInput);
|
||||
intent.putExtra(RemotePassphraseDialogActivity.EXTRA_CRYPTO_INPUT, cryptoInput);
|
||||
|
||||
return createInternal(intent);
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
PendingIntent createSelectPublicKeyPendingIntent(long[] keyIdsArray, ArrayList<String> missingEmails,
|
||||
PendingIntent createSelectPublicKeyPendingIntent(Intent data, long[] keyIdsArray, ArrayList<String> missingEmails,
|
||||
ArrayList<String> duplicateEmails, boolean noUserIdsCheck) {
|
||||
Intent intent = new Intent(mContext, RemoteSelectPubKeyActivity.class);
|
||||
intent.putExtra(RemoteSelectPubKeyActivity.EXTRA_SELECTED_MASTER_KEY_IDS, keyIdsArray);
|
||||
@@ -93,58 +91,58 @@ public class ApiPendingIntentFactory {
|
||||
intent.putExtra(RemoteSelectPubKeyActivity.EXTRA_MISSING_EMAILS, missingEmails);
|
||||
intent.putExtra(RemoteSelectPubKeyActivity.EXTRA_DUPLICATE_EMAILS, duplicateEmails);
|
||||
|
||||
return createInternal(intent);
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
PendingIntent createImportFromKeyserverPendingIntent(long masterKeyId) {
|
||||
PendingIntent createImportFromKeyserverPendingIntent(Intent data, long masterKeyId) {
|
||||
Intent intent = new Intent(mContext, RemoteImportKeysActivity.class);
|
||||
intent.setAction(RemoteImportKeysActivity.ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT);
|
||||
intent.putExtra(RemoteImportKeysActivity.EXTRA_KEY_ID, masterKeyId);
|
||||
|
||||
return createInternal(intent);
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
PendingIntent createSelectAllowedKeysPendingIntent(String packageName) {
|
||||
PendingIntent createSelectAllowedKeysPendingIntent(Intent data, String packageName) {
|
||||
Intent intent = new Intent(mContext, SelectAllowedKeysActivity.class);
|
||||
intent.setData(KeychainContract.ApiApps.buildByPackageNameUri(packageName));
|
||||
|
||||
return createInternal(intent);
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
PendingIntent createShowKeyPendingIntent(long masterKeyId) {
|
||||
PendingIntent createShowKeyPendingIntent(Intent data, long masterKeyId) {
|
||||
Intent intent = new Intent(mContext, ViewKeyActivity.class);
|
||||
intent.setData(KeychainContract.KeyRings.buildGenericKeyRingUri(masterKeyId));
|
||||
|
||||
return createInternal(intent);
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
PendingIntent createSelectSignKeyIdPendingIntent(String packageName, String preferredUserId) {
|
||||
PendingIntent createSelectSignKeyIdPendingIntent(Intent data, String packageName, String preferredUserId) {
|
||||
Intent intent = new Intent(mContext, SelectSignKeyIdActivity.class);
|
||||
intent.setData(KeychainContract.ApiApps.buildByPackageNameUri(packageName));
|
||||
intent.putExtra(SelectSignKeyIdActivity.EXTRA_USER_ID, preferredUserId);
|
||||
|
||||
return createInternal(intent);
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
PendingIntent createAccountCreationPendingIntent(String packageName, String accountName) {
|
||||
PendingIntent createAccountCreationPendingIntent(Intent data, String packageName, String accountName) {
|
||||
Intent intent = new Intent(mContext, RemoteCreateAccountActivity.class);
|
||||
intent.putExtra(RemoteCreateAccountActivity.EXTRA_PACKAGE_NAME, packageName);
|
||||
intent.putExtra(RemoteCreateAccountActivity.EXTRA_ACC_NAME, accountName);
|
||||
|
||||
return createInternal(intent);
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
PendingIntent createErrorPendingIntent(String errorMessage) {
|
||||
PendingIntent createErrorPendingIntent(Intent data, String errorMessage) {
|
||||
Intent intent = new Intent(mContext, RemoteErrorActivity.class);
|
||||
intent.putExtra(RemoteErrorActivity.EXTRA_ERROR_MESSAGE, errorMessage);
|
||||
|
||||
return createInternal(intent);
|
||||
return createInternal(data, intent);
|
||||
}
|
||||
|
||||
private PendingIntent createInternal(Intent intent) {
|
||||
private PendingIntent createInternal(Intent data, Intent intent) {
|
||||
// re-attach "data" for pass through. It will be used later to repeat pgp operation
|
||||
intent.putExtra(RemoteSecurityTokenOperationActivity.EXTRA_DATA, mPendingIntentData);
|
||||
intent.putExtra(RemoteSecurityTokenOperationActivity.EXTRA_DATA, data);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
//noinspection ResourceType, looks like lint is missing FLAG_IMMUTABLE
|
||||
@@ -158,11 +156,11 @@ public class ApiPendingIntentFactory {
|
||||
}
|
||||
}
|
||||
|
||||
PendingIntent createRegisterPendingIntent(String packageName, byte[] packageCertificate) {
|
||||
PendingIntent createRegisterPendingIntent(Intent data, String packageName, byte[] packageCertificate) {
|
||||
Intent intent = new Intent(mContext, RemoteRegisterActivity.class);
|
||||
intent.putExtra(RemoteRegisterActivity.EXTRA_PACKAGE_NAME, packageName);
|
||||
intent.putExtra(RemoteRegisterActivity.EXTRA_PACKAGE_SIGNATURE, packageCertificate);
|
||||
intent.putExtra(RemoteRegisterActivity.EXTRA_DATA, mPendingIntentData);
|
||||
intent.putExtra(RemoteRegisterActivity.EXTRA_DATA, data);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
//noinspection ResourceType, looks like lint is missing FLAG_IMMUTABLE
|
||||
|
||||
@@ -72,7 +72,7 @@ public class ApiPermissionHelper {
|
||||
* @return null if caller is allowed, or a Bundle with a PendingIntent
|
||||
*/
|
||||
protected Intent isAllowed(Intent data) {
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(mContext, data);
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(mContext);
|
||||
|
||||
try {
|
||||
if (isCallerAllowed()) {
|
||||
@@ -95,7 +95,8 @@ public class ApiPermissionHelper {
|
||||
}
|
||||
Log.e(Constants.TAG, "Not allowed to use service! return PendingIntent for registration!");
|
||||
|
||||
PendingIntent pi = piFactory.createRegisterPendingIntent(packageName, packageCertificate);
|
||||
PendingIntent pi = piFactory.createRegisterPendingIntent(data,
|
||||
packageName, packageCertificate);
|
||||
|
||||
// return PendingIntent to be executed by client
|
||||
Intent result = new Intent();
|
||||
@@ -107,7 +108,7 @@ public class ApiPermissionHelper {
|
||||
} catch (WrongPackageCertificateException e) {
|
||||
Log.e(Constants.TAG, "wrong signature!", e);
|
||||
|
||||
PendingIntent pi = piFactory.createErrorPendingIntent(mContext.getString(R.string.api_error_wrong_signature));
|
||||
PendingIntent pi = piFactory.createErrorPendingIntent(data, mContext.getString(R.string.api_error_wrong_signature));
|
||||
|
||||
// return PendingIntent to be executed by client
|
||||
Intent result = new Intent();
|
||||
@@ -175,9 +176,10 @@ public class ApiPermissionHelper {
|
||||
String packageName = getCurrentCallingPackage();
|
||||
Log.d(Constants.TAG, "getCreateAccountIntent accountName: " + accountName);
|
||||
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(mContext, data);
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(mContext);
|
||||
|
||||
PendingIntent pi = piFactory.createAccountCreationPendingIntent(packageName, accountName);
|
||||
PendingIntent pi = piFactory.createAccountCreationPendingIntent(data,
|
||||
packageName, accountName);
|
||||
|
||||
// return PendingIntent to be executed by client
|
||||
Intent result = new Intent();
|
||||
|
||||
@@ -143,9 +143,9 @@ public class OpenPgpService extends Service {
|
||||
if (noUserIdsCheck || missingUserIdsCheck || duplicateUserIdsCheck) {
|
||||
// allow the user to verify pub key selection
|
||||
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext(), data);
|
||||
PendingIntent pi = piFactory.createSelectPublicKeyPendingIntent(keyIdsArray, missingEmails,
|
||||
duplicateEmails, noUserIdsCheck);
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext());
|
||||
PendingIntent pi = piFactory.createSelectPublicKeyPendingIntent(data, keyIdsArray,
|
||||
missingEmails, duplicateEmails, noUserIdsCheck);
|
||||
|
||||
// return PendingIntent to be executed by client
|
||||
Intent result = new Intent();
|
||||
@@ -226,10 +226,11 @@ public class OpenPgpService extends Service {
|
||||
PgpSignEncryptResult pgpResult = pse.execute(pseInput, inputParcel, inputData, outputStream);
|
||||
|
||||
if (pgpResult.isPending()) {
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext(), data);
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext());
|
||||
|
||||
RequiredInputParcel requiredInput = pgpResult.getRequiredInputParcel();
|
||||
PendingIntent pIntent = piFactory.requiredInputPi(requiredInput, pgpResult.mCryptoInputParcel);
|
||||
PendingIntent pIntent = piFactory.requiredInputPi(data,
|
||||
requiredInput, pgpResult.mCryptoInputParcel);
|
||||
|
||||
// return PendingIntent to be executed by client
|
||||
Intent result = new Intent();
|
||||
@@ -363,10 +364,11 @@ public class OpenPgpService extends Service {
|
||||
PgpSignEncryptResult pgpResult = op.execute(pseInput, inputParcel, inputData, outputStream);
|
||||
|
||||
if (pgpResult.isPending()) {
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext(), data);
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext());
|
||||
|
||||
RequiredInputParcel requiredInput = pgpResult.getRequiredInputParcel();
|
||||
PendingIntent pIntent = piFactory.requiredInputPi(requiredInput, pgpResult.mCryptoInputParcel);
|
||||
PendingIntent pIntent = piFactory.requiredInputPi(data,
|
||||
requiredInput, pgpResult.mCryptoInputParcel);
|
||||
|
||||
// return PendingIntent to be executed by client
|
||||
Intent result = new Intent();
|
||||
@@ -436,12 +438,13 @@ public class OpenPgpService extends Service {
|
||||
|
||||
DecryptVerifyResult pgpResult = op.execute(input, cryptoInput, inputData, outputStream);
|
||||
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext(), data);
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext());
|
||||
|
||||
if (pgpResult.isPending()) {
|
||||
// prepare and return PendingIntent to be executed by client
|
||||
RequiredInputParcel requiredInput = pgpResult.getRequiredInputParcel();
|
||||
PendingIntent pIntent = piFactory.requiredInputPi(requiredInput, pgpResult.mCryptoInputParcel);
|
||||
PendingIntent pIntent = piFactory.requiredInputPi(data,
|
||||
requiredInput, pgpResult.mCryptoInputParcel);
|
||||
|
||||
Intent result = new Intent();
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT, pIntent);
|
||||
@@ -459,7 +462,8 @@ public class OpenPgpService extends Service {
|
||||
case OpenPgpSignatureResult.RESULT_KEY_MISSING: {
|
||||
// If signature key is missing we return a PendingIntent to retrieve the key
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT,
|
||||
piFactory.createImportFromKeyserverPendingIntent(signatureResult.getKeyId()));
|
||||
piFactory.createImportFromKeyserverPendingIntent(data,
|
||||
signatureResult.getKeyId()));
|
||||
break;
|
||||
}
|
||||
case OpenPgpSignatureResult.RESULT_VALID_CONFIRMED:
|
||||
@@ -468,7 +472,8 @@ public class OpenPgpService extends Service {
|
||||
case OpenPgpSignatureResult.RESULT_INVALID_KEY_EXPIRED:
|
||||
case OpenPgpSignatureResult.RESULT_INVALID_INSECURE: {
|
||||
// If signature key is known, return PendingIntent to show key
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT, piFactory.createShowKeyPendingIntent(signatureResult.getKeyId()));
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT,
|
||||
piFactory.createShowKeyPendingIntent(data, signatureResult.getKeyId()));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@@ -542,7 +547,8 @@ public class OpenPgpService extends Service {
|
||||
// allow user to select allowed keys
|
||||
Intent result = new Intent();
|
||||
String packageName = mApiPermissionHelper.getCurrentCallingPackage();
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT, piFactory.createSelectAllowedKeysPendingIntent(packageName));
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT,
|
||||
piFactory.createSelectAllowedKeysPendingIntent(data, packageName));
|
||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
|
||||
return result;
|
||||
}
|
||||
@@ -566,7 +572,7 @@ public class OpenPgpService extends Service {
|
||||
|
||||
private Intent getKeyImpl(Intent data, OutputStream outputStream) {
|
||||
try {
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext(), data);
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext());
|
||||
|
||||
long masterKeyId = data.getLongExtra(OpenPgpApi.EXTRA_KEY_ID, 0);
|
||||
|
||||
@@ -597,14 +603,16 @@ public class OpenPgpService extends Service {
|
||||
}
|
||||
|
||||
// also return PendingIntent that opens the key view activity
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT, piFactory.createShowKeyPendingIntent(masterKeyId));
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT,
|
||||
piFactory.createShowKeyPendingIntent(data, masterKeyId));
|
||||
|
||||
return result;
|
||||
} catch (ProviderHelper.NotFoundException e) {
|
||||
// If keys are not in db we return an additional PendingIntent
|
||||
// to retrieve the missing key
|
||||
Intent result = new Intent();
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT, piFactory.createImportFromKeyserverPendingIntent(masterKeyId));
|
||||
result.putExtra(OpenPgpApi.RESULT_INTENT,
|
||||
piFactory.createImportFromKeyserverPendingIntent(data, masterKeyId));
|
||||
result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED);
|
||||
return result;
|
||||
}
|
||||
@@ -633,8 +641,8 @@ public class OpenPgpService extends Service {
|
||||
String currentPkg = mApiPermissionHelper.getCurrentCallingPackage();
|
||||
String preferredUserId = data.getStringExtra(OpenPgpApi.EXTRA_USER_ID);
|
||||
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext(), data);
|
||||
PendingIntent pi = piFactory.createSelectSignKeyIdPendingIntent(currentPkg, preferredUserId);
|
||||
ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(getBaseContext());
|
||||
PendingIntent pi = piFactory.createSelectSignKeyIdPendingIntent(data, currentPkg, preferredUserId);
|
||||
|
||||
// return PendingIntent to be executed by client
|
||||
Intent result = new Intent();
|
||||
|
||||
Reference in New Issue
Block a user