Pass imported master key ids via result parcel
This commit is contained in:
@@ -120,10 +120,12 @@ public class PgpImportExport {
|
|||||||
// If there aren't even any keys, do nothing here.
|
// If there aren't even any keys, do nothing here.
|
||||||
if (entries == null || !entries.hasNext()) {
|
if (entries == null || !entries.hasNext()) {
|
||||||
return new ImportKeyResult(
|
return new ImportKeyResult(
|
||||||
ImportKeyResult.RESULT_FAIL_NOTHING, mProviderHelper.getLog(), 0, 0, 0, 0);
|
ImportKeyResult.RESULT_FAIL_NOTHING, mProviderHelper.getLog(), 0, 0, 0, 0,
|
||||||
|
new long[]{});
|
||||||
}
|
}
|
||||||
|
|
||||||
int newKeys = 0, oldKeys = 0, badKeys = 0, secret = 0;
|
int newKeys = 0, oldKeys = 0, badKeys = 0, secret = 0;
|
||||||
|
ArrayList<Long> importedMasterKeyIds = new ArrayList<Long>();
|
||||||
|
|
||||||
int position = 0;
|
int position = 0;
|
||||||
double progSteps = 100.0 / num;
|
double progSteps = 100.0 / num;
|
||||||
@@ -165,11 +167,13 @@ public class PgpImportExport {
|
|||||||
badKeys += 1;
|
badKeys += 1;
|
||||||
} else if (result.updated()) {
|
} else if (result.updated()) {
|
||||||
oldKeys += 1;
|
oldKeys += 1;
|
||||||
|
importedMasterKeyIds.add(key.getMasterKeyId());
|
||||||
} else {
|
} else {
|
||||||
newKeys += 1;
|
newKeys += 1;
|
||||||
if (key.isSecret()) {
|
if (key.isSecret()) {
|
||||||
secret += 1;
|
secret += 1;
|
||||||
}
|
}
|
||||||
|
importedMasterKeyIds.add(key.getMasterKeyId());
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -210,8 +214,14 @@ public class PgpImportExport {
|
|||||||
resultType |= ImportKeyResult.RESULT_CANCELLED;
|
resultType |= ImportKeyResult.RESULT_CANCELLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ImportKeyResult(resultType, log, newKeys, oldKeys, badKeys, secret);
|
// convert to long array
|
||||||
|
long[] importedMasterKeyIdsArray = new long[importedMasterKeyIds.size()];
|
||||||
|
for (int i = 0; i < importedMasterKeyIds.size(); ++i) {
|
||||||
|
importedMasterKeyIdsArray[i] = importedMasterKeyIds.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ImportKeyResult(resultType, log, newKeys, oldKeys, badKeys, secret,
|
||||||
|
importedMasterKeyIdsArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bundle exportKeyRings(ArrayList<Long> publicKeyRingMasterIds,
|
public Bundle exportKeyRings(ArrayList<Long> publicKeyRingMasterIds,
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
|||||||
public class ImportKeyResult extends OperationResult {
|
public class ImportKeyResult extends OperationResult {
|
||||||
|
|
||||||
public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret;
|
public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret;
|
||||||
|
public final long[] mImportedMasterKeyIds;
|
||||||
|
|
||||||
// At least one new key
|
// At least one new key
|
||||||
public static final int RESULT_OK_NEWKEYS = 8;
|
public static final int RESULT_OK_NEWKEYS = 8;
|
||||||
@@ -69,21 +70,28 @@ public class ImportKeyResult extends OperationResult {
|
|||||||
return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING;
|
return (mResult & RESULT_FAIL_NOTHING) == RESULT_FAIL_NOTHING;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long[] getImportedMasterKeyIds() {
|
||||||
|
return mImportedMasterKeyIds;
|
||||||
|
}
|
||||||
|
|
||||||
public ImportKeyResult(Parcel source) {
|
public ImportKeyResult(Parcel source) {
|
||||||
super(source);
|
super(source);
|
||||||
mNewKeys = source.readInt();
|
mNewKeys = source.readInt();
|
||||||
mUpdatedKeys = source.readInt();
|
mUpdatedKeys = source.readInt();
|
||||||
mBadKeys = source.readInt();
|
mBadKeys = source.readInt();
|
||||||
mSecret = source.readInt();
|
mSecret = source.readInt();
|
||||||
|
mImportedMasterKeyIds = source.createLongArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImportKeyResult(int result, OperationLog log,
|
public ImportKeyResult(int result, OperationLog log,
|
||||||
int newKeys, int updatedKeys, int badKeys, int secret) {
|
int newKeys, int updatedKeys, int badKeys, int secret,
|
||||||
|
long[] importedMasterKeyIds) {
|
||||||
super(result, log);
|
super(result, log);
|
||||||
mNewKeys = newKeys;
|
mNewKeys = newKeys;
|
||||||
mUpdatedKeys = updatedKeys;
|
mUpdatedKeys = updatedKeys;
|
||||||
mBadKeys = badKeys;
|
mBadKeys = badKeys;
|
||||||
mSecret = secret;
|
mSecret = secret;
|
||||||
|
mImportedMasterKeyIds = importedMasterKeyIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,6 +101,7 @@ public class ImportKeyResult extends OperationResult {
|
|||||||
dest.writeInt(mUpdatedKeys);
|
dest.writeInt(mUpdatedKeys);
|
||||||
dest.writeInt(mBadKeys);
|
dest.writeInt(mBadKeys);
|
||||||
dest.writeInt(mSecret);
|
dest.writeInt(mSecret);
|
||||||
|
dest.writeLongArray(mImportedMasterKeyIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Creator<ImportKeyResult> CREATOR = new Creator<ImportKeyResult>() {
|
public static Creator<ImportKeyResult> CREATOR = new Creator<ImportKeyResult>() {
|
||||||
@@ -162,8 +171,8 @@ public class ImportKeyResult extends OperationResult {
|
|||||||
color = Style.RED;
|
color = Style.RED;
|
||||||
if (isFailNothing()) {
|
if (isFailNothing()) {
|
||||||
str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0
|
str = activity.getString((resultType & ImportKeyResult.RESULT_CANCELLED) > 0
|
||||||
? R.string.import_error_nothing_cancelled
|
? R.string.import_error_nothing_cancelled
|
||||||
: R.string.import_error_nothing);
|
: R.string.import_error_nothing);
|
||||||
} else {
|
} else {
|
||||||
str = activity.getResources().getQuantityString(R.plurals.import_error, mBadKeys);
|
str = activity.getResources().getQuantityString(R.plurals.import_error, mBadKeys);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
View mActionSafeSlinger;
|
View mActionSafeSlinger;
|
||||||
ImageView mActionSafeSlingerIcon;
|
ImageView mActionSafeSlingerIcon;
|
||||||
View mActionQrCode;
|
View mActionQrCode;
|
||||||
|
View mActionNfc;
|
||||||
View mActionSearchCloud;
|
View mActionSearchCloud;
|
||||||
|
|
||||||
ProviderHelper mProviderHelper;
|
ProviderHelper mProviderHelper;
|
||||||
@@ -103,6 +104,7 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
mActionSafeSlingerIcon.setColorFilter(getResources().getColor(R.color.tertiary_text_light),
|
mActionSafeSlingerIcon.setColorFilter(getResources().getColor(R.color.tertiary_text_light),
|
||||||
PorterDuff.Mode.SRC_IN);
|
PorterDuff.Mode.SRC_IN);
|
||||||
mActionQrCode = findViewById(R.id.add_keys_qr_code);
|
mActionQrCode = findViewById(R.id.add_keys_qr_code);
|
||||||
|
mActionNfc = findViewById(R.id.add_keys_nfc);
|
||||||
mActionSearchCloud = findViewById(R.id.add_keys_search_cloud);
|
mActionSearchCloud = findViewById(R.id.add_keys_search_cloud);
|
||||||
|
|
||||||
mSafeSlingerKeySpinner.setOnKeyChangedListener(new KeySpinner.OnKeyChangedListener() {
|
mSafeSlingerKeySpinner.setOnKeyChangedListener(new KeySpinner.OnKeyChangedListener() {
|
||||||
@@ -126,6 +128,16 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
mActionNfc.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
// show nfc help
|
||||||
|
Intent intent = new Intent(AddKeysActivity.this, HelpActivity.class);
|
||||||
|
intent.putExtra(HelpActivity.EXTRA_SELECTED_TAB, HelpActivity.TAB_NFC);
|
||||||
|
startActivityForResult(intent, 0);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
mActionSearchCloud.setOnClickListener(new View.OnClickListener() {
|
mActionSearchCloud.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@@ -183,8 +195,7 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
getSupportLoaderManager().restartLoader(LOADER_ID_BYTES, null, this);
|
getSupportLoaderManager().restartLoader(LOADER_ID_BYTES, null, this);
|
||||||
break;
|
break;
|
||||||
case ExchangeActivity.RESULT_EXCHANGE_CANCELED:
|
case ExchangeActivity.RESULT_EXCHANGE_CANCELED:
|
||||||
// handle canceled result
|
// do nothing
|
||||||
// ...
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -291,29 +302,13 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLoadFinished(Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> loader, AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data) {
|
public void onLoadFinished(Loader<AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>>> loader,
|
||||||
|
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data) {
|
||||||
Log.d(Constants.TAG, "data: " + data.getResult());
|
Log.d(Constants.TAG, "data: " + data.getResult());
|
||||||
|
|
||||||
// swap in the real data!
|
|
||||||
// mAdapter.setData(data.getResult());
|
|
||||||
// mAdapter.notifyDataSetChanged();
|
|
||||||
//
|
|
||||||
// setListAdapter(mAdapter);
|
|
||||||
//
|
|
||||||
// // The list should now be shown.
|
|
||||||
// if (isResumed()) {
|
|
||||||
// setListShown(true);
|
|
||||||
// } else {
|
|
||||||
// setListShownNoAnimation(true);
|
|
||||||
// }
|
|
||||||
|
|
||||||
Exception error = data.getError();
|
Exception error = data.getError();
|
||||||
|
|
||||||
// free old cached key data
|
LongSparseArray<ParcelableKeyRing> cachedKeyData = null;
|
||||||
// mCachedKeyData = null;
|
|
||||||
LongSparseArray<ParcelableKeyRing> mCachedKeyData = null;
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: Use parcels!!!!!!!!!!!!!!!
|
// TODO: Use parcels!!!!!!!!!!!!!!!
|
||||||
switch (loader.getId()) {
|
switch (loader.getId()) {
|
||||||
@@ -321,8 +316,8 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
|
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
// No error
|
// No error
|
||||||
mCachedKeyData = ((ImportKeysListLoader) loader).getParcelableRings();
|
cachedKeyData = ((ImportKeysListLoader) loader).getParcelableRings();
|
||||||
Log.d(Constants.TAG, "no error!:" + mCachedKeyData);
|
Log.d(Constants.TAG, "no error!:" + cachedKeyData);
|
||||||
|
|
||||||
} else if (error instanceof ImportKeysListLoader.NoValidKeysException) {
|
} else if (error instanceof ImportKeysListLoader.NoValidKeysException) {
|
||||||
Notify.showNotify(this, R.string.error_import_no_valid_keys, Notify.Style.ERROR);
|
Notify.showNotify(this, R.string.error_import_no_valid_keys, Notify.Style.ERROR);
|
||||||
@@ -361,7 +356,7 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
importKeys(mCachedKeyData);
|
importKeys(cachedKeyData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -434,21 +429,11 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: start certify with received keys
|
finish();
|
||||||
|
Intent certifyIntent = new Intent(); // TODO: certify
|
||||||
// if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_RESULT.equals(getIntent().getAction())
|
certifyIntent.putExtra(ImportKeyResult.EXTRA_RESULT, result);
|
||||||
// || ACTION_IMPORT_KEY_FROM_FILE_AND_RETURN.equals(getIntent().getAction())) {
|
certifyIntent.putExtra("key ids", result.getImportedMasterKeyIds()); // TODO: extra
|
||||||
// Intent intent = new Intent();
|
startActivity(certifyIntent);
|
||||||
// intent.putExtra(ImportKeyResult.EXTRA_RESULT, result);
|
|
||||||
// ImportKeysActivity.this.setResult(RESULT_OK, intent);
|
|
||||||
// ImportKeysActivity.this.finish();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if (ACTION_IMPORT_KEY_FROM_KEYSERVER_AND_RETURN_TO_SERVICE.equals(getIntent().getAction())) {
|
|
||||||
// ImportKeysActivity.this.setResult(RESULT_OK, mPendingIntentData);
|
|
||||||
// ImportKeysActivity.this.finish();
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
result.createNotify(AddKeysActivity.this).show();
|
result.createNotify(AddKeysActivity.this).show();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:text="Secure Exchange" />
|
android:text="@string/add_keys_section_secure_exchange" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -35,7 +35,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:text="My key:"
|
android:text="@string/add_keys_my_key"
|
||||||
android:paddingRight="8dp" />
|
android:paddingRight="8dp" />
|
||||||
|
|
||||||
<org.sufficientlysecure.keychain.ui.widget.ExchangeKeySpinner
|
<org.sufficientlysecure.keychain.ui.widget.ExchangeKeySpinner
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
android:layout_width="0dip"
|
android:layout_width="0dip"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:text="Start exchange"
|
android:text="@string/add_keys_start_exchange"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:gravity="center_vertical" />
|
android:gravity="center_vertical" />
|
||||||
|
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="32dp"
|
||||||
android:text="Secure add" />
|
android:text="@string/add_keys_section_secure_add" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/add_keys_qr_code"
|
android:id="@+id/add_keys_qr_code"
|
||||||
@@ -99,11 +99,32 @@
|
|||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
style="@style/SelectableItem"
|
style="@style/SelectableItem"
|
||||||
android:text="QR Code"
|
android:text="@string/add_keys_qr_code"
|
||||||
android:drawableRight="@drawable/ic_action_qr_code"
|
android:drawableRight="@drawable/ic_action_qr_code"
|
||||||
android:drawablePadding="8dp"
|
android:drawablePadding="8dp"
|
||||||
android:gravity="center_vertical" />
|
android:gravity="center_vertical" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:id="@+id/view_key_action_certify_divider"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dip"
|
||||||
|
android:background="?android:attr/listDivider" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/add_keys_nfc"
|
||||||
|
android:paddingLeft="8dp"
|
||||||
|
android:paddingRight="8dp"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
|
android:clickable="true"
|
||||||
|
style="@style/SelectableItem"
|
||||||
|
android:text="@string/add_keys_nfc"
|
||||||
|
android:drawableRight="@drawable/ic_action_nfc"
|
||||||
|
android:drawablePadding="8dp"
|
||||||
|
android:gravity="center_vertical" />
|
||||||
|
|
||||||
<View
|
<View
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="1dip"
|
android:layout_height="1dip"
|
||||||
@@ -115,7 +136,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="32dp"
|
android:layout_marginTop="32dp"
|
||||||
android:text="Import (untrusted)" />
|
android:text="@string/add_keys_section_import" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/add_keys_search_cloud"
|
android:id="@+id/add_keys_search_cloud"
|
||||||
@@ -127,7 +148,7 @@
|
|||||||
android:minHeight="?android:attr/listPreferredItemHeight"
|
android:minHeight="?android:attr/listPreferredItemHeight"
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
style="@style/SelectableItem"
|
style="@style/SelectableItem"
|
||||||
android:text="Search cloud"
|
android:text="@string/add_keys_cloud"
|
||||||
android:drawableRight="@drawable/ic_action_search"
|
android:drawableRight="@drawable/ic_action_search"
|
||||||
android:drawablePadding="8dp"
|
android:drawablePadding="8dp"
|
||||||
android:gravity="center_vertical" />
|
android:gravity="center_vertical" />
|
||||||
|
|||||||
@@ -284,6 +284,17 @@
|
|||||||
<string name="decrypt_result_decrypted_and_signature_uncertified">"Successfully decrypted and valid signature (uncertified)"</string>
|
<string name="decrypt_result_decrypted_and_signature_uncertified">"Successfully decrypted and valid signature (uncertified)"</string>
|
||||||
<string name="decrypt_result_decrypted_and_signature_certified">"Successfully decrypted and valid signature (certified)"</string>
|
<string name="decrypt_result_decrypted_and_signature_certified">"Successfully decrypted and valid signature (certified)"</string>
|
||||||
|
|
||||||
|
<!-- Add keys -->
|
||||||
|
<string name="add_keys_section_secure_exchange">"Secure Exchange"</string>
|
||||||
|
<string name="add_keys_section_secure_add">"Secure Add"</string>
|
||||||
|
<string name="add_keys_section_import">"Import (untrusted)"</string>
|
||||||
|
<string name="add_keys_my_key">"My key:"</string>
|
||||||
|
<string name="add_keys_start_exchange">"Start exchange"</string>
|
||||||
|
<string name="add_keys_qr_code">"Scan QR Code"</string>
|
||||||
|
<string name="add_keys_nfc">"Receive via NFC"</string>
|
||||||
|
<string name="add_keys_cloud">"Search cloud"</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- progress dialogs, usually ending in '…' -->
|
<!-- progress dialogs, usually ending in '…' -->
|
||||||
<string name="progress_done">"Done."</string>
|
<string name="progress_done">"Done."</string>
|
||||||
<string name="progress_cancel">"Cancel"</string>
|
<string name="progress_cancel">"Cancel"</string>
|
||||||
|
|||||||
Reference in New Issue
Block a user