mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 19:22:14 -05:00
qr code download, cleanup
This commit is contained in:
parent
0599f0dd4e
commit
e75e3d371d
@ -465,7 +465,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
// actual import afterwards
|
// actual import afterwards
|
||||||
keyRings.add(new ParcelableKeyRing(downloadedKeyBytes, entry.getFingerprintHex()));
|
keyRings.add(new ParcelableKeyRing(downloadedKeyBytes, entry.getFingerprintHex()));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Keyserver.QueryFailedException e) {
|
||||||
sendErrorToHandler(e);
|
sendErrorToHandler(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,6 +36,7 @@ import com.google.zxing.integration.android.IntentResult;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.keyimport.ImportKeysList;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
||||||
import org.sufficientlysecure.keychain.keyimport.Keyserver;
|
import org.sufficientlysecure.keychain.keyimport.Keyserver;
|
||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
@ -84,9 +85,7 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
|
|
||||||
private static final int REQUEST_CODE_SAFE_SLINGER = 1;
|
private static final int REQUEST_CODE_SAFE_SLINGER = 1;
|
||||||
|
|
||||||
|
|
||||||
private static final int LOADER_ID_BYTES = 0;
|
private static final int LOADER_ID_BYTES = 0;
|
||||||
private static final int LOADER_ID_CLOUD = 1;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -209,7 +208,7 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
|
|
||||||
// look if it's fingerprint only
|
// look if it's fingerprint only
|
||||||
if (scannedContent.toLowerCase(Locale.ENGLISH).startsWith(Constants.FINGERPRINT_SCHEME)) {
|
if (scannedContent.toLowerCase(Locale.ENGLISH).startsWith(Constants.FINGERPRINT_SCHEME)) {
|
||||||
loadFromFingerprintUri(Uri.parse(scanResult.getContents()));
|
importKeys(null, getFingerprintFromUri(Uri.parse(scanResult.getContents())));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -231,29 +230,6 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void loadFromFingerprintUri(Uri dataUri) {
|
|
||||||
String query = "0x" + getFingerprintFromUri(dataUri);
|
|
||||||
|
|
||||||
// setCurrentItem does not work directly after onResume (from qr code scanner)
|
|
||||||
// see http://stackoverflow.com/q/19316729
|
|
||||||
// so, reset adapter completely!
|
|
||||||
// if (mViewPager.getAdapter() != null)
|
|
||||||
// mViewPager.setAdapter(null);
|
|
||||||
// mViewPager.setAdapter(mTabsAdapter);
|
|
||||||
// mViewPager.setCurrentItem(TAB_CLOUD);
|
|
||||||
|
|
||||||
// ImportKeysCloudFragment f = (ImportKeysCloudFragment)
|
|
||||||
// getActiveFragment(mViewPager, TAB_CLOUD);
|
|
||||||
|
|
||||||
// search config
|
|
||||||
Preferences prefs = Preferences.getPreferences(this);
|
|
||||||
Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver());
|
|
||||||
|
|
||||||
// search directly
|
|
||||||
// loadCallback(new ImportKeysListFragment.CloudLoaderState(query, cloudPrefs));
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getFingerprintFromUri(Uri dataUri) {
|
private String getFingerprintFromUri(Uri dataUri) {
|
||||||
String fingerprint = dataUri.toString().split(":")[1].toLowerCase(Locale.ENGLISH);
|
String fingerprint = dataUri.toString().split(":")[1].toLowerCase(Locale.ENGLISH);
|
||||||
Log.d(Constants.TAG, "fingerprint: " + fingerprint);
|
Log.d(Constants.TAG, "fingerprint: " + fingerprint);
|
||||||
@ -290,10 +266,6 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
InputData inputData = new InputData(new ByteArrayInputStream(mImportBytes), mImportBytes.length);
|
InputData inputData = new InputData(new ByteArrayInputStream(mImportBytes), mImportBytes.length);
|
||||||
return new ImportKeysListLoader(this, inputData);
|
return new ImportKeysListLoader(this, inputData);
|
||||||
}
|
}
|
||||||
case LOADER_ID_CLOUD: {
|
|
||||||
// ImportKeysListFragment.CloudLoaderState ls = (ImportKeysListFragment.CloudLoaderState) mLoaderState;
|
|
||||||
// return new ImportKeysListCloudLoader(this, ls.mServerQuery, ls.mCloudPrefs);
|
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return null;
|
return null;
|
||||||
@ -305,8 +277,6 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data) {
|
AsyncTaskResultWrapper<ArrayList<ImportKeysListEntry>> data) {
|
||||||
Log.d(Constants.TAG, "data: " + data.getResult());
|
Log.d(Constants.TAG, "data: " + data.getResult());
|
||||||
|
|
||||||
// Exception error = data.getError();
|
|
||||||
|
|
||||||
GetKeyResult getKeyResult = (GetKeyResult) data.getOperationResult();
|
GetKeyResult getKeyResult = (GetKeyResult) data.getOperationResult();
|
||||||
|
|
||||||
LongSparseArray<ParcelableKeyRing> cachedKeyData = null;
|
LongSparseArray<ParcelableKeyRing> cachedKeyData = null;
|
||||||
@ -341,36 +311,12 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
// }
|
// }
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case LOADER_ID_CLOUD:
|
|
||||||
|
|
||||||
if (getKeyResult.success()) {
|
|
||||||
// No error
|
|
||||||
} else {
|
|
||||||
getKeyResult.createNotify(this).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (error == null) {
|
|
||||||
// // No error
|
|
||||||
// } else if (error instanceof Keyserver.QueryTooShortException) {
|
|
||||||
// Notify.showNotify(this, R.string.error_query_too_short, Notify.Style.ERROR);
|
|
||||||
// } else if (error instanceof Keyserver.TooManyResponsesException) {
|
|
||||||
// Notify.showNotify(this, R.string.error_too_many_responses, Notify.Style.ERROR);
|
|
||||||
// } else if (error instanceof Keyserver.QueryTooShortOrTooManyResponsesException) {
|
|
||||||
// Notify.showNotify(this, R.string.error_too_short_or_too_many_responses, Notify.Style.ERROR);
|
|
||||||
// } else if (error instanceof Keyserver.QueryFailedException) {
|
|
||||||
// Log.d(Constants.TAG,
|
|
||||||
// "Unrecoverable keyserver query error: " + error.getLocalizedMessage());
|
|
||||||
// String alert = this.getString(R.string.error_searching_keys);
|
|
||||||
// alert = alert + " (" + error.getLocalizedMessage() + ")";
|
|
||||||
// Notify.showNotify(this, alert, Notify.Style.ERROR);
|
|
||||||
// }
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
importKeys(cachedKeyData);
|
importKeys(cachedKeyData, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -378,10 +324,6 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
switch (loader.getId()) {
|
switch (loader.getId()) {
|
||||||
case LOADER_ID_BYTES:
|
case LOADER_ID_BYTES:
|
||||||
// Clear the data in the adapter.
|
// Clear the data in the adapter.
|
||||||
// mAdapter.clear();
|
|
||||||
break;
|
|
||||||
case LOADER_ID_CLOUD:
|
|
||||||
// Clear the data in the adapter.
|
|
||||||
// mAdapter.clear();
|
// mAdapter.clear();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -419,7 +361,7 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void importKeys(final LongSparseArray<ParcelableKeyRing> keyData) {
|
public void importKeys(final LongSparseArray<ParcelableKeyRing> keyData, String fingerprint) {
|
||||||
// Message is received after importing is done in KeychainIntentService
|
// Message is received after importing is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
||||||
this,
|
this,
|
||||||
@ -454,27 +396,66 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// ImportKeysListFragment.LoaderState ls = mListFragment.getLoaderState();
|
if (keyData != null) {
|
||||||
// if (importMethod == IMPORT_SAFE_SLINGER) {
|
Log.d(Constants.TAG, "importKeys started");
|
||||||
Log.d(Constants.TAG, "importKeys started");
|
|
||||||
|
|
||||||
// Send all information needed to service to import key in other thread
|
// Send all information needed to service to import key in other thread
|
||||||
Intent intent = new Intent(this, KeychainIntentService.class);
|
Intent intent = new Intent(this, KeychainIntentService.class);
|
||||||
|
|
||||||
intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);
|
intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);
|
||||||
|
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
|
|
||||||
// instead of giving the entries by Intent extra, cache them into a
|
// instead of giving the entries by Intent extra, cache them into a
|
||||||
// file to prevent Java Binder problems on heavy imports
|
// file to prevent Java Binder problems on heavy imports
|
||||||
// read FileImportCache for more info.
|
// read FileImportCache for more info.
|
||||||
try {
|
try {
|
||||||
// We parcel this iteratively into a file - anything we can
|
// We parcel this iteratively into a file - anything we can
|
||||||
// display here, we should be able to import.
|
// display here, we should be able to import.
|
||||||
ParcelableFileCache<ParcelableKeyRing> cache =
|
ParcelableFileCache<ParcelableKeyRing> cache =
|
||||||
new ParcelableFileCache<ParcelableKeyRing>(this, "key_import.pcl");
|
new ParcelableFileCache<ParcelableKeyRing>(this, "key_import.pcl");
|
||||||
cache.writeCache(getSelectedData(keyData));
|
cache.writeCache(getSelectedData(keyData));
|
||||||
|
|
||||||
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
|
// Create a new Messenger for the communication back
|
||||||
|
Messenger messenger = new Messenger(saveHandler);
|
||||||
|
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
|
// show progress dialog
|
||||||
|
saveHandler.showProgressDialog(this);
|
||||||
|
|
||||||
|
// start service with intent
|
||||||
|
startService(intent);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(Constants.TAG, "Problem writing cache file", e);
|
||||||
|
Notify.showNotify(this, "Problem writing cache file!", Notify.Style.ERROR);
|
||||||
|
}
|
||||||
|
} else if (fingerprint != null) {
|
||||||
|
|
||||||
|
// search config
|
||||||
|
Preferences prefs = Preferences.getPreferences(this);
|
||||||
|
Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver());
|
||||||
|
|
||||||
|
// Send all information needed to service to query keys in other thread
|
||||||
|
Intent intent = new Intent(this, KeychainIntentService.class);
|
||||||
|
|
||||||
|
intent.setAction(KeychainIntentService.ACTION_DOWNLOAD_AND_IMPORT_KEYS);
|
||||||
|
|
||||||
|
// fill values for this action
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
|
||||||
|
data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, cloudPrefs.keyserver);
|
||||||
|
|
||||||
|
final ImportKeysListEntry keyEntry = new ImportKeysListEntry();
|
||||||
|
keyEntry.setFingerprintHex(fingerprint);
|
||||||
|
keyEntry.setBitStrength(1337);
|
||||||
|
keyEntry.addOrigin(cloudPrefs.keyserver);
|
||||||
|
ArrayList<ImportKeysListEntry> selectedEntries = new ArrayList<ImportKeysListEntry>();
|
||||||
|
selectedEntries.add(keyEntry);
|
||||||
|
|
||||||
|
data.putParcelableArrayList(KeychainIntentService.DOWNLOAD_KEY_LIST, selectedEntries);
|
||||||
|
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
@ -487,43 +468,8 @@ public class AddKeysActivity extends ActionBarActivity implements
|
|||||||
|
|
||||||
// start service with intent
|
// start service with intent
|
||||||
startService(intent);
|
startService(intent);
|
||||||
} catch (IOException e) {
|
} else {
|
||||||
Log.e(Constants.TAG, "Problem writing cache file", e);
|
Notify.showNotify(this, R.string.error_nothing_import, Notify.Style.ERROR);
|
||||||
Notify.showNotify(this, "Problem writing cache file!", Notify.Style.ERROR);
|
|
||||||
}
|
}
|
||||||
// } else if () {
|
|
||||||
|
|
||||||
// }
|
|
||||||
// } else if (ls instanceof ImportKeysListFragment.CloudLoaderState) {
|
|
||||||
// ImportKeysListFragment.CloudLoaderState sls = (ImportKeysListFragment.CloudLoaderState) ls;
|
|
||||||
//
|
|
||||||
// // Send all information needed to service to query keys in other thread
|
|
||||||
// Intent intent = new Intent(this, KeychainIntentService.class);
|
|
||||||
//
|
|
||||||
// intent.setAction(KeychainIntentService.ACTION_DOWNLOAD_AND_IMPORT_KEYS);
|
|
||||||
//
|
|
||||||
// // fill values for this action
|
|
||||||
// Bundle data = new Bundle();
|
|
||||||
//
|
|
||||||
// data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, sls.mCloudPrefs.keyserver);
|
|
||||||
//
|
|
||||||
// // get selected key entries
|
|
||||||
// ArrayList<ImportKeysListEntry> selectedEntries = mListFragment.getSelectedEntries();
|
|
||||||
// data.putParcelableArrayList(KeychainIntentService.DOWNLOAD_KEY_LIST, selectedEntries);
|
|
||||||
//
|
|
||||||
// intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
|
||||||
//
|
|
||||||
// // Create a new Messenger for the communication back
|
|
||||||
// Messenger messenger = new Messenger(saveHandler);
|
|
||||||
// intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
|
||||||
//
|
|
||||||
// // show progress dialog
|
|
||||||
// saveHandler.showProgressDialog(this);
|
|
||||||
//
|
|
||||||
// // start service with intent
|
|
||||||
// startService(intent);
|
|
||||||
// } else {
|
|
||||||
// Notify.showNotify(this, R.string.error_nothing_import, Notify.Style.ERROR);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user