diff options
author | Dominik Schürmann <dominik@dominikschuermann.de> | 2016-02-15 17:43:18 +0100 |
---|---|---|
committer | Dominik Schürmann <dominik@dominikschuermann.de> | 2016-02-22 15:06:45 +0100 |
commit | d1eacf9b277c679fac7d873d5fe42c5493498f09 (patch) | |
tree | 3af101dc4dcaae261f426dbc9890ebcbfabf13b6 /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ApiPermissionHelper.java | |
parent | 15488c544584f5515c83c9fbcf4d09055ba7af3d (diff) | |
download | open-keychain-d1eacf9b277c679fac7d873d5fe42c5493498f09.tar.gz open-keychain-d1eacf9b277c679fac7d873d5fe42c5493498f09.tar.bz2 open-keychain-d1eacf9b277c679fac7d873d5fe42c5493498f09.zip |
Move PendingIntent creation into factory
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ApiPermissionHelper.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ApiPermissionHelper.java | 44 |
1 files changed, 12 insertions, 32 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ApiPermissionHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ApiPermissionHelper.java index e2011e059..34dab6ec1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ApiPermissionHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ApiPermissionHelper.java @@ -18,11 +18,6 @@ package org.sufficientlysecure.keychain.remote; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; - import android.annotation.SuppressLint; import android.app.PendingIntent; import android.content.Context; @@ -40,11 +35,13 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.ProviderHelper; -import org.sufficientlysecure.keychain.remote.ui.RemoteCreateAccountActivity; -import org.sufficientlysecure.keychain.remote.ui.RemoteErrorActivity; -import org.sufficientlysecure.keychain.remote.ui.RemoteRegisterActivity; import org.sufficientlysecure.keychain.util.Log; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; + /** * Abstract service class for remote APIs that handle app registration and user input. @@ -75,6 +72,8 @@ 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); + try { if (isCallerAllowed()) { return null; @@ -96,14 +95,7 @@ public class ApiPermissionHelper { } Log.e(Constants.TAG, "Not allowed to use service! return PendingIntent for registration!"); - 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, data); - - PendingIntent pi = PendingIntent.getActivity(mContext, 0, - intent, - PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT); + PendingIntent pi = piFactory.register(packageName, packageCertificate); // return PendingIntent to be executed by client Intent result = new Intent(); @@ -115,14 +107,7 @@ public class ApiPermissionHelper { } catch (WrongPackageCertificateException e) { Log.e(Constants.TAG, "wrong signature!", e); - Intent intent = new Intent(mContext, RemoteErrorActivity.class); - intent.putExtra(RemoteErrorActivity.EXTRA_ERROR_MESSAGE, - mContext.getString(R.string.api_error_wrong_signature)); - intent.putExtra(RemoteErrorActivity.EXTRA_DATA, data); - - PendingIntent pi = PendingIntent.getActivity(mContext, 0, - intent, - PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent pi = piFactory.error(mContext.getString(R.string.api_error_wrong_signature)); // return PendingIntent to be executed by client Intent result = new Intent(); @@ -187,20 +172,15 @@ public class ApiPermissionHelper { } /** - * Deprecated API + * @deprecated */ protected Intent getCreateAccountIntent(Intent data, String accountName) { String packageName = getCurrentCallingPackage(); Log.d(Constants.TAG, "getCreateAccountIntent accountName: " + accountName); - Intent intent = new Intent(mContext, RemoteCreateAccountActivity.class); - intent.putExtra(RemoteCreateAccountActivity.EXTRA_PACKAGE_NAME, packageName); - intent.putExtra(RemoteCreateAccountActivity.EXTRA_ACC_NAME, accountName); - intent.putExtra(RemoteCreateAccountActivity.EXTRA_DATA, data); + ApiPendingIntentFactory piFactory = new ApiPendingIntentFactory(mContext, data); - PendingIntent pi = PendingIntent.getActivity(mContext, 0, - intent, - PendingIntent.FLAG_CANCEL_CURRENT); + PendingIntent pi = piFactory.createAccount(packageName, accountName); // return PendingIntent to be executed by client Intent result = new Intent(); |