API: Fix get sign key, related to OpenPgpKeyPreference bugs

This commit is contained in:
Dominik Schürmann 2015-08-24 02:37:26 +02:00
parent db5040a061
commit 1144ebb94c
3 changed files with 38 additions and 31 deletions

View file

@ -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 result;
// 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;
}
}
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);

View file

@ -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();

@ -1 +1 @@
Subproject commit 989aa544b94e99703b3a75ce3c676a9b83ebb91e
Subproject commit a5240bebf4ca0bab13af25ccd8ae30ae413953c0