From 1144ebb94cad7de9bee336206b3685641f70af16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Sch=C3=BCrmann?= Date: Mon, 24 Aug 2015 02:37:26 +0200 Subject: API: Fix get sign key, related to OpenPgpKeyPreference bugs --- .../keychain/remote/OpenPgpService.java | 42 ++++++++++++++-------- .../remote/ui/SelectSignKeyIdActivity.java | 25 ++++++------- extern/openpgp-api-lib | 2 +- 3 files changed, 38 insertions(+), 31 deletions(-) diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java index ea016c657..9e6681341 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/OpenPgpService.java @@ -715,28 +715,40 @@ public class OpenPgpService extends RemoteService { } private Intent getSignKeyIdImpl(Intent data) { - String preferredUserId = data.getStringExtra(OpenPgpApi.EXTRA_USER_ID); + // 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! + if (data.hasExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID)) { + long signKeyId = data.getLongExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, + Constants.key.none); - Intent intent = new Intent(getBaseContext(), SelectSignKeyIdActivity.class); - String currentPkg = getCurrentCallingPackage(); - intent.setData(KeychainContract.ApiApps.buildByPackageNameUri(currentPkg)); - intent.putExtra(SelectSignKeyIdActivity.EXTRA_USER_ID, preferredUserId); - intent.putExtra(SelectSignKeyIdActivity.EXTRA_DATA, data); + Intent result = new Intent(); + result.putExtra(OpenPgpApi.EXTRA_SIGN_KEY_ID, signKeyId); + result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_SUCCESS); + return result; + } else { + String preferredUserId = data.getStringExtra(OpenPgpApi.EXTRA_USER_ID); - PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 0, - intent, - PendingIntent.FLAG_CANCEL_CURRENT); + Intent intent = new Intent(getBaseContext(), SelectSignKeyIdActivity.class); + String currentPkg = getCurrentCallingPackage(); + intent.setData(KeychainContract.ApiApps.buildByPackageNameUri(currentPkg)); + intent.putExtra(SelectSignKeyIdActivity.EXTRA_USER_ID, preferredUserId); + intent.putExtra(SelectSignKeyIdActivity.EXTRA_DATA, data); - // return PendingIntent to be executed by client - Intent result = new Intent(); - result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED); - result.putExtra(OpenPgpApi.RESULT_INTENT, pi); + PendingIntent pi = PendingIntent.getActivity(getBaseContext(), 0, + intent, + PendingIntent.FLAG_CANCEL_CURRENT); + + // return PendingIntent to be executed by client + Intent result = new Intent(); + result.putExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED); + result.putExtra(OpenPgpApi.RESULT_INTENT, pi); - return result; + return result; + } } private Intent getKeyIdsImpl(Intent data) { - // if data already contains key ids extra GET_KEY_IDS has been executed again + // if data already contains EXTRA_KEY_IDS, it has been executed again // after user interaction. Then, we just need to return the array again! if (data.hasExtra(OpenPgpApi.EXTRA_KEY_IDS)) { long[] keyIdsArray = data.getLongArrayExtra(OpenPgpApi.EXTRA_KEY_IDS); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdActivity.java index cb9f46f7f..bed49a6f6 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/remote/ui/SelectSignKeyIdActivity.java @@ -40,14 +40,9 @@ public class SelectSignKeyIdActivity extends BaseActivity { private static final int REQUEST_CODE_CREATE_KEY = 0x00008884; - private Uri mAppUri; private String mPreferredUserId; private Intent mData; - private SelectSignKeyIdListFragment mListFragment; - private TextView mActionCreateKey; - private TextView mNone; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -62,15 +57,15 @@ public class SelectSignKeyIdActivity extends BaseActivity { } }); - mActionCreateKey = (TextView) findViewById(R.id.api_select_sign_key_create_key); - mActionCreateKey.setOnClickListener(new View.OnClickListener() { + TextView createKeyButton = (TextView) findViewById(R.id.api_select_sign_key_create_key); + createKeyButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { createKey(mPreferredUserId); } }); - mNone = (TextView) findViewById(R.id.api_select_sign_key_none); - mNone.setOnClickListener(new View.OnClickListener() { + TextView noneButton = (TextView) findViewById(R.id.api_select_sign_key_none); + noneButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // 0 is "none" @@ -82,16 +77,16 @@ public class SelectSignKeyIdActivity extends BaseActivity { }); Intent intent = getIntent(); - mAppUri = intent.getData(); + Uri appUri = intent.getData(); mPreferredUserId = intent.getStringExtra(EXTRA_USER_ID); mData = intent.getParcelableExtra(EXTRA_DATA); - if (mAppUri == null) { + if (appUri == null) { Log.e(Constants.TAG, "Intent data missing. Should be Uri of app!"); finish(); return; } else { - Log.d(Constants.TAG, "uri: " + mAppUri); - startListFragments(savedInstanceState, mAppUri, mData); + Log.d(Constants.TAG, "uri: " + appUri); + startListFragments(savedInstanceState, appUri, mData); } } @@ -113,11 +108,11 @@ public class SelectSignKeyIdActivity extends BaseActivity { } // Create an instance of the fragments - mListFragment = SelectSignKeyIdListFragment.newInstance(dataUri, data); + SelectSignKeyIdListFragment listFragment = SelectSignKeyIdListFragment.newInstance(dataUri, data); // Add the fragment to the 'fragment_container' FrameLayout // NOTE: We use commitAllowingStateLoss() to prevent weird crashes! getSupportFragmentManager().beginTransaction() - .replace(R.id.api_select_sign_key_list_fragment, mListFragment) + .replace(R.id.api_select_sign_key_list_fragment, listFragment) .commitAllowingStateLoss(); // do it immediately! getSupportFragmentManager().executePendingTransactions(); diff --git a/extern/openpgp-api-lib b/extern/openpgp-api-lib index 989aa544b..a5240bebf 160000 --- a/extern/openpgp-api-lib +++ b/extern/openpgp-api-lib @@ -1 +1 @@ -Subproject commit 989aa544b94e99703b3a75ce3c676a9b83ebb91e +Subproject commit a5240bebf4ca0bab13af25ccd8ae30ae413953c0 -- cgit v1.2.3