qr code download, cleanup

This commit is contained in:
Dominik Schürmann 2014-10-04 21:40:28 +02:00
parent 0599f0dd4e
commit e75e3d371d
2 changed files with 63 additions and 117 deletions

View File

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

View File

@ -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,8 +396,7 @@ 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
@ -491,39 +432,44 @@ public class AddKeysActivity extends ActionBarActivity implements
Log.e(Constants.TAG, "Problem writing cache file", e); Log.e(Constants.TAG, "Problem writing cache file", e);
Notify.showNotify(this, "Problem writing cache file!", Notify.Style.ERROR); Notify.showNotify(this, "Problem writing cache file!", Notify.Style.ERROR);
} }
// } else if () { } else if (fingerprint != null) {
// } // search config
// } else if (ls instanceof ImportKeysListFragment.CloudLoaderState) { Preferences prefs = Preferences.getPreferences(this);
// ImportKeysListFragment.CloudLoaderState sls = (ImportKeysListFragment.CloudLoaderState) ls; Preferences.CloudSearchPrefs cloudPrefs = new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver());
//
// // Send all information needed to service to query keys in other thread // Send all information needed to service to query keys in other thread
// Intent intent = new Intent(this, KeychainIntentService.class); Intent intent = new Intent(this, KeychainIntentService.class);
//
// intent.setAction(KeychainIntentService.ACTION_DOWNLOAD_AND_IMPORT_KEYS); intent.setAction(KeychainIntentService.ACTION_DOWNLOAD_AND_IMPORT_KEYS);
//
// // fill values for this action // fill values for this action
// Bundle data = new Bundle(); Bundle data = new Bundle();
//
// data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, sls.mCloudPrefs.keyserver); data.putString(KeychainIntentService.DOWNLOAD_KEY_SERVER, cloudPrefs.keyserver);
//
// // get selected key entries final ImportKeysListEntry keyEntry = new ImportKeysListEntry();
// ArrayList<ImportKeysListEntry> selectedEntries = mListFragment.getSelectedEntries(); keyEntry.setFingerprintHex(fingerprint);
// data.putParcelableArrayList(KeychainIntentService.DOWNLOAD_KEY_LIST, selectedEntries); keyEntry.setBitStrength(1337);
// keyEntry.addOrigin(cloudPrefs.keyserver);
// intent.putExtra(KeychainIntentService.EXTRA_DATA, data); ArrayList<ImportKeysListEntry> selectedEntries = new ArrayList<ImportKeysListEntry>();
// selectedEntries.add(keyEntry);
// // Create a new Messenger for the communication back
// Messenger messenger = new Messenger(saveHandler); data.putParcelableArrayList(KeychainIntentService.DOWNLOAD_KEY_LIST, selectedEntries);
// intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
// intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
// // show progress dialog
// saveHandler.showProgressDialog(this); // Create a new Messenger for the communication back
// Messenger messenger = new Messenger(saveHandler);
// // start service with intent intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
// startService(intent);
// } else { // show progress dialog
// Notify.showNotify(this, R.string.error_nothing_import, Notify.Style.ERROR); saveHandler.showProgressDialog(this);
// }
// start service with intent
startService(intent);
} else {
Notify.showNotify(this, R.string.error_nothing_import, Notify.Style.ERROR);
}
} }
} }