mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-27 11:12:15 -05:00
shifted multi-threading to own service
added multi-threaded cloud import, restored KeychainIntentService eliminated code duplication in multi-threaded import
This commit is contained in:
parent
19775c399b
commit
9f5581463f
@ -697,6 +697,9 @@
|
|||||||
<service
|
<service
|
||||||
android:name=".service.KeychainIntentService"
|
android:name=".service.KeychainIntentService"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
|
<service
|
||||||
|
android:name=".service.CloudImportService"
|
||||||
|
android:exported="false" />
|
||||||
|
|
||||||
<provider
|
<provider
|
||||||
android:name=".provider.KeychainProvider"
|
android:name=".provider.KeychainProvider"
|
||||||
|
@ -0,0 +1,387 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2012-2013 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.sufficientlysecure.keychain.service;
|
||||||
|
|
||||||
|
import android.app.Service;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
|
import android.os.Message;
|
||||||
|
import android.os.Messenger;
|
||||||
|
import android.os.RemoteException;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.operations.ImportExportOperation;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||||
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
|
import org.sufficientlysecure.keychain.pgp.Progressable;
|
||||||
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.SynchronousQueue;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When this service is started it will initiate a multi-threaded key import and when done it will
|
||||||
|
* shut itself down.
|
||||||
|
*/
|
||||||
|
public class CloudImportService extends Service implements Progressable {
|
||||||
|
|
||||||
|
//required as extras from intent
|
||||||
|
public static final String EXTRA_MESSENGER = "messenger";
|
||||||
|
public static final String EXTRA_DATA = "data";
|
||||||
|
|
||||||
|
//required by data bundle
|
||||||
|
public static final String IMPORT_KEY_LIST = "import_key_list";
|
||||||
|
public static final String IMPORT_KEY_SERVER = "import_key_server";
|
||||||
|
|
||||||
|
// indicates a request to cancel the import
|
||||||
|
public static final String ACTION_CANCEL = Constants.INTENT_PREFIX + "CANCEL";
|
||||||
|
|
||||||
|
//tells the spawned threads whether the user has requested a cancel
|
||||||
|
private static AtomicBoolean mActionCancelled = new AtomicBoolean(false);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IBinder onBind(Intent intent) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to accumulate the results of individual key imports
|
||||||
|
*/
|
||||||
|
private class KeyImportAccumulator {
|
||||||
|
private OperationResult.OperationLog mImportLog = new OperationResult.OperationLog();
|
||||||
|
private int mTotalKeys;
|
||||||
|
private int mImportedKeys = 0;
|
||||||
|
private Progressable mImportProgressable;
|
||||||
|
ArrayList<Long> mImportedMasterKeyIds = new ArrayList<Long>();
|
||||||
|
private int mBadKeys = 0;
|
||||||
|
private int mNewKeys = 0;
|
||||||
|
private int mUpdatedKeys = 0;
|
||||||
|
private int mSecret = 0;
|
||||||
|
private int mResultType = 0;
|
||||||
|
|
||||||
|
public KeyImportAccumulator(int totalKeys) {
|
||||||
|
mTotalKeys = totalKeys;
|
||||||
|
//ignore updates from ImportExportOperation for now
|
||||||
|
mImportProgressable = new Progressable() {
|
||||||
|
@Override
|
||||||
|
public void setProgress(String message, int current, int total) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProgress(int resourceId, int current, int total) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setProgress(int current, int total) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setPreventCancel() {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Progressable getImportProgressable() {
|
||||||
|
return mImportProgressable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalKeys() {
|
||||||
|
return mTotalKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getImportedKeys() {
|
||||||
|
return mImportedKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public synchronized void accumulateKeyImport(ImportKeyResult result) {
|
||||||
|
mImportedKeys++;
|
||||||
|
mImportLog.addAll(result.getLog().toList());//accumulates log
|
||||||
|
mBadKeys += result.mBadKeys;
|
||||||
|
mNewKeys += result.mNewKeys;
|
||||||
|
mUpdatedKeys += result.mUpdatedKeys;
|
||||||
|
mSecret += result.mSecret;
|
||||||
|
|
||||||
|
long[] masterKeyIds = result.getImportedMasterKeyIds();
|
||||||
|
for (int i = 0; i < masterKeyIds.length; i++) {
|
||||||
|
mImportedMasterKeyIds.add(masterKeyIds[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// if any key import has been cancelled, set result type to cancelled
|
||||||
|
// resultType is added to in getConsolidatedKayImport to account for remaining factors
|
||||||
|
mResultType |= result.getResult() & ImportKeyResult.RESULT_CANCELLED;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns accumulated result of all imports so far
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public ImportKeyResult getConsolidatedImportKeyResult() {
|
||||||
|
|
||||||
|
// adding required information to mResultType
|
||||||
|
// special case,no keys requested for import
|
||||||
|
if (mBadKeys == 0 && mNewKeys == 0 && mUpdatedKeys == 0) {
|
||||||
|
mResultType = ImportKeyResult.RESULT_FAIL_NOTHING;
|
||||||
|
} else {
|
||||||
|
if (mNewKeys > 0) {
|
||||||
|
mResultType |= ImportKeyResult.RESULT_OK_NEWKEYS;
|
||||||
|
}
|
||||||
|
if (mUpdatedKeys > 0) {
|
||||||
|
mResultType |= ImportKeyResult.RESULT_OK_UPDATED;
|
||||||
|
}
|
||||||
|
if (mBadKeys > 0) {
|
||||||
|
mResultType |= ImportKeyResult.RESULT_WITH_ERRORS;
|
||||||
|
if (mNewKeys == 0 && mUpdatedKeys == 0) {
|
||||||
|
mResultType |= ImportKeyResult.RESULT_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (mImportLog.containsWarnings()) {
|
||||||
|
mResultType |= ImportKeyResult.RESULT_WARNINGS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long masterKeyIds[] = new long[mImportedMasterKeyIds.size()];
|
||||||
|
for (int i = 0; i < masterKeyIds.length; i++) {
|
||||||
|
masterKeyIds[i] = mImportedMasterKeyIds.get(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new ImportKeyResult(mResultType, mImportLog, mNewKeys, mUpdatedKeys, mBadKeys,
|
||||||
|
mSecret, masterKeyIds);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isImportFinished() {
|
||||||
|
return mTotalKeys == mImportedKeys;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private KeyImportAccumulator mKeyImportAccumulator;
|
||||||
|
|
||||||
|
Messenger mMessenger;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
|
|
||||||
|
if (ACTION_CANCEL.equals(intent.getAction())) {
|
||||||
|
mActionCancelled.set(true);
|
||||||
|
return Service.START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
|
mActionCancelled.set(false);//we haven't been cancelled, yet
|
||||||
|
|
||||||
|
Bundle extras = intent.getExtras();
|
||||||
|
|
||||||
|
mMessenger = (Messenger) extras.get(EXTRA_MESSENGER);
|
||||||
|
|
||||||
|
Bundle data = extras.getBundle(EXTRA_DATA);
|
||||||
|
|
||||||
|
final String keyServer = data.getString(IMPORT_KEY_SERVER);
|
||||||
|
//keyList being null (in case key list to be reaad from cache) is checked by importKeys
|
||||||
|
final ArrayList<ParcelableKeyRing> keyList = data.getParcelableArrayList(IMPORT_KEY_LIST);
|
||||||
|
|
||||||
|
// Adding keys to the ThreadPoolExecutor takes time, we don't want to block the main thread
|
||||||
|
Thread baseImportThread = new Thread(new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
importKeys(keyList, keyServer);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
baseImportThread.start();
|
||||||
|
return Service.START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void importKeys(ArrayList<ParcelableKeyRing> keyList, final String keyServer) {
|
||||||
|
ParcelableFileCache<ParcelableKeyRing> cache =
|
||||||
|
new ParcelableFileCache<>(this, "key_import.pcl");
|
||||||
|
int totKeys = 0;
|
||||||
|
Iterator<ParcelableKeyRing> keyListIterator = null;
|
||||||
|
//either keyList or cache must be null, no guarantees otherwise
|
||||||
|
if (keyList == null) {//export from cache, copied from ImportExportOperation.importKeyRings
|
||||||
|
|
||||||
|
try {
|
||||||
|
ParcelableFileCache.IteratorWithSize<ParcelableKeyRing> it = cache.readCache();
|
||||||
|
keyListIterator = it;
|
||||||
|
totKeys = it.getSize();
|
||||||
|
} catch (IOException e) {
|
||||||
|
|
||||||
|
// Special treatment here, we need a lot
|
||||||
|
OperationResult.OperationLog log = new OperationResult.OperationLog();
|
||||||
|
log.add(OperationResult.LogType.MSG_IMPORT, 0, 0);
|
||||||
|
log.add(OperationResult.LogType.MSG_IMPORT_ERROR_IO, 0, 0);
|
||||||
|
|
||||||
|
keyImportFailed(new ImportKeyResult(ImportKeyResult.RESULT_ERROR, log));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
keyListIterator = keyList.iterator();
|
||||||
|
totKeys = keyList.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (keyListIterator != null) {
|
||||||
|
mKeyImportAccumulator = new KeyImportAccumulator(totKeys);
|
||||||
|
setProgress(0, totKeys);
|
||||||
|
|
||||||
|
final int maxThreads = 200;
|
||||||
|
ExecutorService importExecutor = new ThreadPoolExecutor(0, maxThreads,
|
||||||
|
30L, TimeUnit.SECONDS,
|
||||||
|
new SynchronousQueue<Runnable>());
|
||||||
|
|
||||||
|
while (keyListIterator.hasNext()) {
|
||||||
|
|
||||||
|
final ParcelableKeyRing pkRing = keyListIterator.next();
|
||||||
|
|
||||||
|
Runnable importOperationRunnable = new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
ImportKeyResult result = null;
|
||||||
|
try {
|
||||||
|
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||||
|
CloudImportService.this,
|
||||||
|
new ProviderHelper(CloudImportService.this),
|
||||||
|
mKeyImportAccumulator.getImportProgressable(),
|
||||||
|
mActionCancelled);
|
||||||
|
|
||||||
|
ArrayList<ParcelableKeyRing> list = new ArrayList<>();
|
||||||
|
list.add(pkRing);
|
||||||
|
result = importExportOperation.importKeyRings(list,
|
||||||
|
keyServer);
|
||||||
|
} finally {
|
||||||
|
// in the off-chance that importKeyRings does something to crash the
|
||||||
|
// thread before it can call singleKeyRingImportCompleted, our imported
|
||||||
|
// key count will go wrong. This will cause the service to never die,
|
||||||
|
// and the progress dialog to stay displayed. The finally block was
|
||||||
|
// originally meant to ensure singleKeyRingImportCompleted was called,
|
||||||
|
// and checks for null were to be introduced, but in such a scenario,
|
||||||
|
// knowing an uncaught error exists in importKeyRings is more important.
|
||||||
|
|
||||||
|
// if a null gets passed, something wrong is happening. We want a crash.
|
||||||
|
|
||||||
|
singleKeyRingImportCompleted(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
importExecutor.execute(importOperationRunnable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private synchronized void singleKeyRingImportCompleted(ImportKeyResult result) {
|
||||||
|
// increase imported key count and accumulate log and bad, new etc. key counts from result
|
||||||
|
mKeyImportAccumulator.accumulateKeyImport(result);
|
||||||
|
|
||||||
|
setProgress(mKeyImportAccumulator.getImportedKeys(), mKeyImportAccumulator.getTotalKeys());
|
||||||
|
|
||||||
|
if (mKeyImportAccumulator.isImportFinished()) {
|
||||||
|
ContactSyncAdapterService.requestSync();
|
||||||
|
|
||||||
|
sendMessageToHandler(ServiceProgressHandler.MessageStatus.OKAY,
|
||||||
|
mKeyImportAccumulator.getConsolidatedImportKeyResult());
|
||||||
|
|
||||||
|
stopSelf();//we're done here
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void keyImportFailed(ImportKeyResult result) {
|
||||||
|
sendMessageToHandler(ServiceProgressHandler.MessageStatus.OKAY, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageToHandler(ServiceProgressHandler.MessageStatus status, Integer arg2, Bundle data) {
|
||||||
|
|
||||||
|
Message msg = Message.obtain();
|
||||||
|
assert msg != null;
|
||||||
|
msg.arg1 = status.ordinal();
|
||||||
|
if (arg2 != null) {
|
||||||
|
msg.arg2 = arg2;
|
||||||
|
}
|
||||||
|
if (data != null) {
|
||||||
|
msg.setData(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
mMessenger.send(msg);
|
||||||
|
} catch (RemoteException e) {
|
||||||
|
Log.w(Constants.TAG, "Exception sending message, Is handler present?", e);
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
Log.w(Constants.TAG, "Messenger is null!", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageToHandler(ServiceProgressHandler.MessageStatus status, OperationResult data) {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putParcelable(OperationResult.EXTRA_RESULT, data);
|
||||||
|
sendMessageToHandler(status, null, bundle);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageToHandler(ServiceProgressHandler.MessageStatus status, Bundle data) {
|
||||||
|
sendMessageToHandler(status, null, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageToHandler(ServiceProgressHandler.MessageStatus status) {
|
||||||
|
sendMessageToHandler(status, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set progress of ProgressDialog by sending message to handler on UI thread
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public synchronized void setProgress(String message, int progress, int max) {
|
||||||
|
Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
|
||||||
|
+ max);
|
||||||
|
|
||||||
|
Bundle data = new Bundle();
|
||||||
|
if (message != null) {
|
||||||
|
data.putString(ServiceProgressHandler.DATA_MESSAGE, message);
|
||||||
|
}
|
||||||
|
data.putInt(ServiceProgressHandler.DATA_PROGRESS, progress);
|
||||||
|
data.putInt(ServiceProgressHandler.DATA_PROGRESS_MAX, max);
|
||||||
|
|
||||||
|
sendMessageToHandler(ServiceProgressHandler.MessageStatus.UPDATE_PROGRESS, null, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void setProgress(int resourceId, int progress, int max) {
|
||||||
|
setProgress(getString(resourceId), progress, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void setProgress(int progress, int max) {
|
||||||
|
setProgress(null, progress, max);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void setPreventCancel() {
|
||||||
|
sendMessageToHandler(ServiceProgressHandler.MessageStatus.PREVENT_CANCEL);
|
||||||
|
}
|
||||||
|
}
|
@ -21,11 +21,11 @@ package org.sufficientlysecure.keychain.service;
|
|||||||
import android.app.IntentService;
|
import android.app.IntentService;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
|
||||||
import com.textuality.keybase.lib.Proof;
|
import com.textuality.keybase.lib.Proof;
|
||||||
import com.textuality.keybase.lib.prover.Prover;
|
import com.textuality.keybase.lib.prover.Prover;
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
|||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException;
|
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler.MessageStatus;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus;
|
||||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||||
import org.sufficientlysecure.keychain.util.InputData;
|
import org.sufficientlysecure.keychain.util.InputData;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@ -74,9 +74,7 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import de.measite.minidns.Client;
|
import de.measite.minidns.Client;
|
||||||
@ -203,127 +201,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
Messenger mMessenger;
|
Messenger mMessenger;
|
||||||
|
|
||||||
// this attribute can possibly merged with the one above? not sure...
|
// this attribute can possibly merged with the one above? not sure...
|
||||||
private static AtomicBoolean sActionCanceled = new AtomicBoolean(false);
|
private AtomicBoolean mActionCanceled = new AtomicBoolean(false);
|
||||||
|
|
||||||
/**
|
|
||||||
* accumulates the results from a multi-threaded key import from a keyserver and
|
|
||||||
* consolidates them into a single ImportKeyResult, besides keeping count of keys imported and
|
|
||||||
* total keys to be imported. Also provides the Progressable used by these threads, which
|
|
||||||
* currently ignores updates
|
|
||||||
*/
|
|
||||||
private class KeyImportAccumulator {
|
|
||||||
private OperationLog mImportLog = new OperationLog();
|
|
||||||
private int mTotalKeys;
|
|
||||||
private int mImportedKeys = 0;
|
|
||||||
private Progressable mImportProgressable;
|
|
||||||
ArrayList<Long> mImportedMasterKeyIds = new ArrayList<Long>();
|
|
||||||
private int mBadKeys = 0;
|
|
||||||
private int mNewKeys = 0;
|
|
||||||
private int mUpdatedKeys = 0;
|
|
||||||
private int mSecret = 0;
|
|
||||||
private int mResultType = 0;
|
|
||||||
|
|
||||||
public KeyImportAccumulator(int totalKeys) {
|
|
||||||
mTotalKeys = totalKeys;
|
|
||||||
//ignore updates from ImportExportOperation for now
|
|
||||||
mImportProgressable = new Progressable() {
|
|
||||||
@Override
|
|
||||||
public void setProgress(String message, int current, int total) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setProgress(int resourceId, int current, int total) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setProgress(int current, int total) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setPreventCancel() {
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Progressable getImportProgressable() {
|
|
||||||
return mImportProgressable;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getTotalKeys() {
|
|
||||||
return mTotalKeys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getImportedKeys() {
|
|
||||||
return mImportedKeys;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized void accumulateKeyImport(ImportKeyResult result) {
|
|
||||||
mImportedKeys++;
|
|
||||||
mImportLog.addAll(result.getLog().toList());//accumulates log
|
|
||||||
mBadKeys += result.mBadKeys;
|
|
||||||
mNewKeys += result.mNewKeys;
|
|
||||||
mUpdatedKeys += result.mUpdatedKeys;
|
|
||||||
mSecret += result.mSecret;
|
|
||||||
|
|
||||||
long[] masterKeyIds = result.getImportedMasterKeyIds();
|
|
||||||
for (int i = 0; i < masterKeyIds.length; i++) {
|
|
||||||
mImportedMasterKeyIds.add(masterKeyIds[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// if any key import has been cancelled, set result type to cancelled
|
|
||||||
// resultType is added to in getConsolidatedKayImport to account for remaining factors
|
|
||||||
mResultType |= result.getResult() & ImportKeyResult.RESULT_CANCELLED;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* returns accumulated result of all imports so far
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
public ImportKeyResult getConsolidatedImportKeyResult() {
|
|
||||||
|
|
||||||
// adding required information to mResultType
|
|
||||||
// special case,no keys requested for import
|
|
||||||
if (mBadKeys == 0 && mNewKeys == 0 && mUpdatedKeys == 0) {
|
|
||||||
mResultType = ImportKeyResult.RESULT_FAIL_NOTHING;
|
|
||||||
} else {
|
|
||||||
if (mNewKeys > 0) {
|
|
||||||
mResultType |= ImportKeyResult.RESULT_OK_NEWKEYS;
|
|
||||||
}
|
|
||||||
if (mUpdatedKeys > 0) {
|
|
||||||
mResultType |= ImportKeyResult.RESULT_OK_UPDATED;
|
|
||||||
}
|
|
||||||
if (mBadKeys > 0) {
|
|
||||||
mResultType |= ImportKeyResult.RESULT_WITH_ERRORS;
|
|
||||||
if (mNewKeys == 0 && mUpdatedKeys == 0) {
|
|
||||||
mResultType |= ImportKeyResult.RESULT_ERROR;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mImportLog.containsWarnings()) {
|
|
||||||
mResultType |= ImportKeyResult.RESULT_WARNINGS;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
long masterKeyIds[] = new long[mImportedMasterKeyIds.size()];
|
|
||||||
for (int i = 0; i < masterKeyIds.length; i++) {
|
|
||||||
masterKeyIds[i] = mImportedMasterKeyIds.get(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ImportKeyResult(mResultType, mImportLog, mNewKeys, mUpdatedKeys, mBadKeys,
|
|
||||||
mSecret, masterKeyIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isImportFinished() {
|
|
||||||
return mTotalKeys == mImportedKeys;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private KeyImportAccumulator mKeyImportAccumulator;
|
|
||||||
|
|
||||||
public KeychainIntentService() {
|
public KeychainIntentService() {
|
||||||
super("KeychainIntentService");
|
super("KeychainIntentService");
|
||||||
@ -338,7 +216,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
|
|
||||||
// We have not been cancelled! (yet)
|
// We have not been cancelled! (yet)
|
||||||
sActionCanceled.set(false);
|
mActionCanceled.set(false);
|
||||||
|
|
||||||
Bundle extras = intent.getExtras();
|
Bundle extras = intent.getExtras();
|
||||||
if (extras == null) {
|
if (extras == null) {
|
||||||
@ -364,7 +242,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
|
|
||||||
Log.logDebugBundle(data, "EXTRA_DATA");
|
Log.logDebugBundle(data, "EXTRA_DATA");
|
||||||
|
|
||||||
final ProviderHelper providerHelper = new ProviderHelper(this);
|
ProviderHelper providerHelper = new ProviderHelper(this);
|
||||||
|
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
|
|
||||||
@ -377,7 +255,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
String keyServerUri = data.getString(UPLOAD_KEY_SERVER);
|
String keyServerUri = data.getString(UPLOAD_KEY_SERVER);
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
CertifyOperation op = new CertifyOperation(this, providerHelper, this, sActionCanceled);
|
CertifyOperation op = new CertifyOperation(this, providerHelper, this, mActionCanceled);
|
||||||
CertifyResult result = op.certify(parcel, keyServerUri);
|
CertifyResult result = op.certify(parcel, keyServerUri);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
@ -517,12 +395,12 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
}
|
}
|
||||||
|
|
||||||
Bundle resultData = new Bundle();
|
Bundle resultData = new Bundle();
|
||||||
resultData.putString(KeychainIntentServiceHandler.DATA_MESSAGE, "OK");
|
resultData.putString(ServiceProgressHandler.DATA_MESSAGE, "OK");
|
||||||
|
|
||||||
// these help the handler construct a useful human-readable message
|
// these help the handler construct a useful human-readable message
|
||||||
resultData.putString(KeychainIntentServiceHandler.KEYBASE_PROOF_URL, prover.getProofUrl());
|
resultData.putString(ServiceProgressHandler.KEYBASE_PROOF_URL, prover.getProofUrl());
|
||||||
resultData.putString(KeychainIntentServiceHandler.KEYBASE_PRESENCE_URL, prover.getPresenceUrl());
|
resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_URL, prover.getPresenceUrl());
|
||||||
resultData.putString(KeychainIntentServiceHandler.KEYBASE_PRESENCE_LABEL, prover.getPresenceLabel());
|
resultData.putString(ServiceProgressHandler.KEYBASE_PRESENCE_LABEL, prover.getPresenceLabel());
|
||||||
sendMessageToHandler(MessageStatus.OKAY, resultData);
|
sendMessageToHandler(MessageStatus.OKAY, resultData);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
sendErrorToHandler(e);
|
sendErrorToHandler(e);
|
||||||
@ -595,7 +473,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
Passphrase passphrase = data.getParcelable(EDIT_KEYRING_PASSPHRASE);
|
Passphrase passphrase = data.getParcelable(EDIT_KEYRING_PASSPHRASE);
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
EditKeyOperation op = new EditKeyOperation(this, providerHelper, this, sActionCanceled);
|
EditKeyOperation op = new EditKeyOperation(this, providerHelper, this, mActionCanceled);
|
||||||
EditKeyResult result = op.execute(saveParcel, passphrase);
|
EditKeyResult result = op.execute(saveParcel, passphrase);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
@ -609,7 +487,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
long keyRingId = data.getInt(EXPORT_KEY_RING_MASTER_KEY_ID);
|
long keyRingId = data.getInt(EXPORT_KEY_RING_MASTER_KEY_ID);
|
||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
PromoteKeyOperation op = new PromoteKeyOperation(this, providerHelper, this, sActionCanceled);
|
PromoteKeyOperation op = new PromoteKeyOperation(this, providerHelper, this, mActionCanceled);
|
||||||
PromoteKeyResult result = op.execute(keyRingId);
|
PromoteKeyResult result = op.execute(keyRingId);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
@ -642,68 +520,26 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ACTION_IMPORT_KEYRING: {
|
case ACTION_IMPORT_KEYRING: {
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
final String keyServer = data.getString(IMPORT_KEY_SERVER);
|
String keyServer = data.getString(IMPORT_KEY_SERVER);
|
||||||
ArrayList<ParcelableKeyRing> list = data.getParcelableArrayList(IMPORT_KEY_LIST);
|
ArrayList<ParcelableKeyRing> list = data.getParcelableArrayList(IMPORT_KEY_LIST);
|
||||||
ParcelableFileCache<ParcelableKeyRing> cache =
|
ParcelableFileCache<ParcelableKeyRing> cache =
|
||||||
new ParcelableFileCache<>(this, "key_import.pcl");
|
new ParcelableFileCache<>(this, "key_import.pcl");
|
||||||
int totKeys = 0;
|
|
||||||
Iterator<ParcelableKeyRing> keyListIterator = null;
|
|
||||||
//either list or cache must be null, no guarantees otherwise
|
|
||||||
if (list == null) {//export from cache, copied from ImportExportOperation.importKeyRings
|
|
||||||
|
|
||||||
try {
|
|
||||||
ParcelableFileCache.IteratorWithSize<ParcelableKeyRing> it = cache.readCache();
|
|
||||||
keyListIterator = it;
|
|
||||||
totKeys = it.getSize();
|
|
||||||
} catch (IOException e) {
|
|
||||||
|
|
||||||
// Special treatment here, we need a lot
|
|
||||||
OperationLog log = new OperationLog();
|
|
||||||
log.add(OperationResult.LogType.MSG_IMPORT, 0, 0);
|
|
||||||
log.add(OperationResult.LogType.MSG_IMPORT_ERROR_IO, 0, 0);
|
|
||||||
|
|
||||||
keyImportFailed(new ImportKeyResult(ImportKeyResult.RESULT_ERROR, log));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
keyListIterator = list.iterator();
|
|
||||||
totKeys = list.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (keyListIterator != null) {
|
|
||||||
mKeyImportAccumulator = new KeyImportAccumulator(totKeys);
|
|
||||||
setProgress(0, totKeys);
|
|
||||||
|
|
||||||
final int maxThreads = 200;
|
|
||||||
ExecutorService importExecutor = new ThreadPoolExecutor(0, maxThreads,
|
|
||||||
30L, TimeUnit.SECONDS,
|
|
||||||
new SynchronousQueue<Runnable>());
|
|
||||||
|
|
||||||
while (keyListIterator.hasNext()) {
|
|
||||||
final ParcelableKeyRing pkRing = keyListIterator.next();
|
|
||||||
Runnable importOperationRunnable = new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
// Operation
|
// Operation
|
||||||
ImportExportOperation importExportOperation = new ImportExportOperation(
|
ImportExportOperation importExportOperation = new ImportExportOperation(
|
||||||
KeychainIntentService.this,
|
this, providerHelper, this, mActionCanceled);
|
||||||
new ProviderHelper(KeychainIntentService.this),
|
// Either list or cache must be null, no guarantees otherwise.
|
||||||
mKeyImportAccumulator.getImportProgressable(),
|
ImportKeyResult result = list != null
|
||||||
sActionCanceled);
|
? importExportOperation.importKeyRings(list, keyServer)
|
||||||
|
: importExportOperation.importKeyRings(cache, keyServer);
|
||||||
|
|
||||||
ArrayList<ParcelableKeyRing> list = new ArrayList<>();
|
// Result
|
||||||
list.add(pkRing);
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
ImportKeyResult result = importExportOperation.importKeyRings(list,
|
|
||||||
keyServer);
|
|
||||||
singleKeyRingImportCompleted(result);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
importExecutor.execute(importOperationRunnable);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
case ACTION_SIGN_ENCRYPT: {
|
case ACTION_SIGN_ENCRYPT: {
|
||||||
|
|
||||||
@ -712,7 +548,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
|
|
||||||
// Operation
|
// Operation
|
||||||
SignEncryptOperation op = new SignEncryptOperation(
|
SignEncryptOperation op = new SignEncryptOperation(
|
||||||
this, new ProviderHelper(this), this, sActionCanceled);
|
this, new ProviderHelper(this), this, mActionCanceled);
|
||||||
SignEncryptResult result = op.execute(inputParcel);
|
SignEncryptResult result = op.execute(inputParcel);
|
||||||
|
|
||||||
// Result
|
// Result
|
||||||
@ -748,23 +584,6 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void singleKeyRingImportCompleted(ImportKeyResult result) {
|
|
||||||
mKeyImportAccumulator.accumulateKeyImport(result);
|
|
||||||
|
|
||||||
setProgress(mKeyImportAccumulator.getImportedKeys(), mKeyImportAccumulator.getTotalKeys());
|
|
||||||
|
|
||||||
if (mKeyImportAccumulator.isImportFinished()) {
|
|
||||||
ContactSyncAdapterService.requestSync();
|
|
||||||
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY,
|
|
||||||
mKeyImportAccumulator.getConsolidatedImportKeyResult());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void keyImportFailed(ImportKeyResult result) {
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void sendProofError(List<String> log, String label) {
|
private void sendProofError(List<String> log, String label) {
|
||||||
String msg = null;
|
String msg = null;
|
||||||
label = (label == null) ? "" : label + ": ";
|
label = (label == null) ? "" : label + ": ";
|
||||||
@ -777,7 +596,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
|
|
||||||
private void sendProofError(String msg) {
|
private void sendProofError(String msg) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putString(KeychainIntentServiceHandler.DATA_ERROR, msg);
|
bundle.putString(ServiceProgressHandler.DATA_ERROR, msg);
|
||||||
sendMessageToHandler(MessageStatus.OKAY, bundle);
|
sendMessageToHandler(MessageStatus.OKAY, bundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -794,7 +613,7 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
Log.d(Constants.TAG, "KeychainIntentService Exception: ", e);
|
Log.d(Constants.TAG, "KeychainIntentService Exception: ", e);
|
||||||
|
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
data.putString(KeychainIntentServiceHandler.DATA_ERROR, message);
|
data.putString(ServiceProgressHandler.DATA_ERROR, message);
|
||||||
sendMessageToHandler(MessageStatus.EXCEPTION, null, data);
|
sendMessageToHandler(MessageStatus.EXCEPTION, null, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -836,30 +655,30 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
/**
|
/**
|
||||||
* Set progress of ProgressDialog by sending message to handler on UI thread
|
* Set progress of ProgressDialog by sending message to handler on UI thread
|
||||||
*/
|
*/
|
||||||
public synchronized void setProgress(String message, int progress, int max) {
|
public void setProgress(String message, int progress, int max) {
|
||||||
Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
|
Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
|
||||||
+ max);
|
+ max);
|
||||||
|
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
data.putString(KeychainIntentServiceHandler.DATA_MESSAGE, message);
|
data.putString(ServiceProgressHandler.DATA_MESSAGE, message);
|
||||||
}
|
}
|
||||||
data.putInt(KeychainIntentServiceHandler.DATA_PROGRESS, progress);
|
data.putInt(ServiceProgressHandler.DATA_PROGRESS, progress);
|
||||||
data.putInt(KeychainIntentServiceHandler.DATA_PROGRESS_MAX, max);
|
data.putInt(ServiceProgressHandler.DATA_PROGRESS_MAX, max);
|
||||||
|
|
||||||
sendMessageToHandler(MessageStatus.UPDATE_PROGRESS, null, data);
|
sendMessageToHandler(MessageStatus.UPDATE_PROGRESS, null, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setProgress(int resourceId, int progress, int max) {
|
public void setProgress(int resourceId, int progress, int max) {
|
||||||
setProgress(getString(resourceId), progress, max);
|
setProgress(getString(resourceId), progress, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void setProgress(int progress, int max) {
|
public void setProgress(int progress, int max) {
|
||||||
setProgress(null, progress, max);
|
setProgress(null, progress, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void setPreventCancel() {
|
public void setPreventCancel() {
|
||||||
sendMessageToHandler(MessageStatus.PREVENT_CANCEL);
|
sendMessageToHandler(MessageStatus.PREVENT_CANCEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,10 +743,8 @@ public class KeychainIntentService extends IntentService implements Progressable
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
// onStartCommand will be run on the thread which starts the service
|
|
||||||
// cancel operation is introduced here as it must not be queued up
|
|
||||||
if (ACTION_CANCEL.equals(intent.getAction())) {
|
if (ACTION_CANCEL.equals(intent.getAction())) {
|
||||||
sActionCanceled.set(true);
|
mActionCanceled.set(true);
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
}
|
}
|
||||||
return super.onStartCommand(intent, flags, startId);
|
return super.onStartCommand(intent, flags, startId);
|
||||||
|
@ -30,7 +30,7 @@ import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class KeychainIntentServiceHandler extends Handler {
|
public class ServiceProgressHandler extends Handler {
|
||||||
|
|
||||||
// possible messages sent from this service to handler on ui
|
// possible messages sent from this service to handler on ui
|
||||||
public static enum MessageStatus{
|
public static enum MessageStatus{
|
||||||
@ -67,28 +67,34 @@ public class KeychainIntentServiceHandler extends Handler {
|
|||||||
Activity mActivity;
|
Activity mActivity;
|
||||||
ProgressDialogFragment mProgressDialogFragment;
|
ProgressDialogFragment mProgressDialogFragment;
|
||||||
|
|
||||||
public KeychainIntentServiceHandler(Activity activity) {
|
public ServiceProgressHandler(Activity activity) {
|
||||||
this.mActivity = activity;
|
this.mActivity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeychainIntentServiceHandler(Activity activity,
|
public ServiceProgressHandler(Activity activity,
|
||||||
ProgressDialogFragment progressDialogFragment) {
|
ProgressDialogFragment progressDialogFragment) {
|
||||||
this.mActivity = activity;
|
this.mActivity = activity;
|
||||||
this.mProgressDialogFragment = progressDialogFragment;
|
this.mProgressDialogFragment = progressDialogFragment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeychainIntentServiceHandler(Activity activity, String progressDialogMessage,
|
public ServiceProgressHandler(Activity activity,
|
||||||
int progressDialogStyle) {
|
String progressDialogMessage,
|
||||||
this(activity, progressDialogMessage, progressDialogStyle, false);
|
int progressDialogStyle,
|
||||||
|
ProgressDialogFragment.ServiceType serviceType) {
|
||||||
|
this(activity, progressDialogMessage, progressDialogStyle, false, serviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeychainIntentServiceHandler(Activity activity, String progressDialogMessage,
|
public ServiceProgressHandler(Activity activity,
|
||||||
int progressDialogStyle, boolean cancelable) {
|
String progressDialogMessage,
|
||||||
|
int progressDialogStyle,
|
||||||
|
boolean cancelable,
|
||||||
|
ProgressDialogFragment.ServiceType serviceType) {
|
||||||
this.mActivity = activity;
|
this.mActivity = activity;
|
||||||
this.mProgressDialogFragment = ProgressDialogFragment.newInstance(
|
this.mProgressDialogFragment = ProgressDialogFragment.newInstance(
|
||||||
progressDialogMessage,
|
progressDialogMessage,
|
||||||
progressDialogStyle,
|
progressDialogStyle,
|
||||||
cancelable);
|
cancelable,
|
||||||
|
serviceType);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showProgressDialog(FragmentActivity activity) {
|
public void showProgressDialog(FragmentActivity activity) {
|
@ -55,9 +55,10 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|||||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
import org.sufficientlysecure.keychain.service.CertifyActionsParcel;
|
||||||
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
import org.sufficientlysecure.keychain.service.CertifyActionsParcel.CertifyAction;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
|
import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner;
|
||||||
import org.sufficientlysecure.keychain.ui.widget.KeySpinner;
|
import org.sufficientlysecure.keychain.ui.widget.KeySpinner;
|
||||||
@ -388,8 +389,12 @@ public class CertifyKeyFragment extends LoaderFragment
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Message is received after signing is done in KeychainIntentService
|
// Message is received after signing is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getString(R.string.progress_certifying), ProgressDialog.STYLE_SPINNER, true) {
|
getActivity(),
|
||||||
|
getString(R.string.progress_certifying),
|
||||||
|
ProgressDialog.STYLE_SPINNER,
|
||||||
|
true,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -26,7 +26,8 @@ import android.support.v4.app.FragmentActivity;
|
|||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We can not directly create a dialog on the application context.
|
* We can not directly create a dialog on the application context.
|
||||||
@ -49,10 +50,11 @@ public class ConsolidateDialogActivity extends FragmentActivity {
|
|||||||
|
|
||||||
private void consolidateRecovery(boolean recovery) {
|
private void consolidateRecovery(boolean recovery) {
|
||||||
// Message is received after importing is done in KeychainIntentService
|
// Message is received after importing is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
this,
|
this,
|
||||||
getString(R.string.progress_importing),
|
getString(R.string.progress_importing),
|
||||||
ProgressDialog.STYLE_HORIZONTAL) {
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -39,16 +39,15 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
|||||||
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
import org.sufficientlysecure.keychain.pgp.KeyRing;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
import org.sufficientlysecure.keychain.ui.CreateKeyActivity.FragAction;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public class CreateKeyFinalFragment extends Fragment {
|
public class CreateKeyFinalFragment extends Fragment {
|
||||||
@ -195,10 +194,11 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
||||||
intent.setAction(KeychainIntentService.ACTION_EDIT_KEYRING);
|
intent.setAction(KeychainIntentService.ACTION_EDIT_KEYRING);
|
||||||
|
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getActivity(),
|
getActivity(),
|
||||||
getString(R.string.progress_building_key),
|
getString(R.string.progress_building_key),
|
||||||
ProgressDialog.STYLE_HORIZONTAL) {
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
@ -267,8 +267,11 @@ public class CreateKeyFinalFragment extends Fragment {
|
|||||||
|
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getString(R.string.progress_uploading), ProgressDialog.STYLE_HORIZONTAL) {
|
getActivity(),
|
||||||
|
getString(R.string.progress_uploading),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -38,8 +38,9 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService.IOType;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService.IOType;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteFileDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
import org.sufficientlysecure.keychain.util.FileHelper;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@ -197,8 +198,11 @@ public class DecryptFilesFragment extends DecryptFragment {
|
|||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after decrypting is done in KeychainIntentService
|
// Message is received after decrypting is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getString(R.string.progress_decrypting), ProgressDialog.STYLE_HORIZONTAL) {
|
getActivity(),
|
||||||
|
getString(R.string.progress_decrypting),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
@ -271,8 +275,11 @@ public class DecryptFilesFragment extends DecryptFragment {
|
|||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after decrypting is done in KeychainIntentService
|
// Message is received after decrypting is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getString(R.string.progress_decrypting), ProgressDialog.STYLE_HORIZONTAL) {
|
getActivity(),
|
||||||
|
getString(R.string.progress_decrypting),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -37,7 +37,8 @@ import org.sufficientlysecure.keychain.compatibility.ClipboardReflection;
|
|||||||
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService.IOType;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService.IOType;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.ShareHelper;
|
import org.sufficientlysecure.keychain.util.ShareHelper;
|
||||||
@ -167,8 +168,11 @@ public class DecryptTextFragment extends DecryptFragment {
|
|||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after encrypting is done in KeychainIntentService
|
// Message is received after encrypting is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(getActivity(),
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getString(R.string.progress_decrypting), ProgressDialog.STYLE_HORIZONTAL) {
|
getActivity(),
|
||||||
|
getString(R.string.progress_decrypting),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -50,7 +50,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.UserPackets;
|
|||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper.NotFoundException;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
|
||||||
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
import org.sufficientlysecure.keychain.service.SaveKeyringParcel.ChangeUnlockParcel;
|
||||||
@ -59,12 +59,7 @@ import org.sufficientlysecure.keychain.ui.adapter.SubkeysAdapter;
|
|||||||
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAddedAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.SubkeysAddedAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAddedAdapter;
|
import org.sufficientlysecure.keychain.ui.adapter.UserIdsAddedAdapter;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.AddSubkeyDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.*;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.AddUserIdDialogFragment;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyDialogFragment;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.EditSubkeyExpiryDialogFragment;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.EditUserIdDialogFragment;
|
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.SetPassphraseDialogFragment;
|
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
@ -597,11 +592,12 @@ public class EditKeyFragment extends LoaderFragment implements
|
|||||||
private void saveInDatabase(Passphrase passphrase) {
|
private void saveInDatabase(Passphrase passphrase) {
|
||||||
Log.d(Constants.TAG, "mSaveKeyringParcel:\n" + mSaveKeyringParcel.toString());
|
Log.d(Constants.TAG, "mSaveKeyringParcel:\n" + mSaveKeyringParcel.toString());
|
||||||
|
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getActivity(),
|
getActivity(),
|
||||||
getString(R.string.progress_saving),
|
getString(R.string.progress_saving),
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
true) {
|
true,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -31,7 +31,8 @@ import org.sufficientlysecure.keychain.operations.results.PgpSignEncryptResult;
|
|||||||
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
import org.sufficientlysecure.keychain.operations.results.SignEncryptResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
import org.sufficientlysecure.keychain.pgp.SignEncryptParcel;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -123,8 +124,11 @@ public abstract class EncryptActivity extends BaseActivity {
|
|||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after encrypting is done in KeychainIntentService
|
// Message is received after encrypting is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(this,
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
|
||||||
getString(R.string.progress_encrypting), ProgressDialog.STYLE_HORIZONTAL) {
|
this,
|
||||||
|
getString(R.string.progress_encrypting),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -35,8 +35,9 @@ import org.sufficientlysecure.keychain.keyimport.ImportKeysListEntry;
|
|||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.CloudImportService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
@ -294,12 +295,13 @@ public class ImportKeysActivity extends BaseActivity {
|
|||||||
* Import keys with mImportData
|
* Import keys with mImportData
|
||||||
*/
|
*/
|
||||||
public void importKeys() {
|
public void importKeys() {
|
||||||
// Message is received after importing is done in KeychainIntentService
|
// Message is received after importing is done in CloudImportService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
this,
|
this,
|
||||||
getString(R.string.progress_importing),
|
getString(R.string.progress_importing),
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
true) {
|
true,
|
||||||
|
ProgressDialogFragment.ServiceType.CLOUD_IMPORT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
@ -342,9 +344,7 @@ public class ImportKeysActivity extends BaseActivity {
|
|||||||
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, CloudImportService.class);
|
||||||
|
|
||||||
intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);
|
|
||||||
|
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
@ -362,11 +362,11 @@ public class ImportKeysActivity extends BaseActivity {
|
|||||||
new ParcelableFileCache<>(this, "key_import.pcl");
|
new ParcelableFileCache<>(this, "key_import.pcl");
|
||||||
cache.writeCache(selectedEntries);
|
cache.writeCache(selectedEntries);
|
||||||
|
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(CloudImportService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
// Create a new Messenger for the communication back
|
||||||
Messenger messenger = new Messenger(saveHandler);
|
Messenger messenger = new Messenger(saveHandler);
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(CloudImportService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
saveHandler.showProgressDialog(this);
|
saveHandler.showProgressDialog(this);
|
||||||
@ -382,14 +382,12 @@ public class ImportKeysActivity extends BaseActivity {
|
|||||||
ImportKeysListFragment.CloudLoaderState sls = (ImportKeysListFragment.CloudLoaderState) ls;
|
ImportKeysListFragment.CloudLoaderState sls = (ImportKeysListFragment.CloudLoaderState) ls;
|
||||||
|
|
||||||
// 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, CloudImportService.class);
|
||||||
|
|
||||||
intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);
|
|
||||||
|
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
|
|
||||||
data.putString(KeychainIntentService.IMPORT_KEY_SERVER, sls.mCloudPrefs.keyserver);
|
data.putString(CloudImportService.IMPORT_KEY_SERVER, sls.mCloudPrefs.keyserver);
|
||||||
|
|
||||||
// get selected key entries
|
// get selected key entries
|
||||||
ArrayList<ParcelableKeyRing> keys = new ArrayList<>();
|
ArrayList<ParcelableKeyRing> keys = new ArrayList<>();
|
||||||
@ -402,13 +400,13 @@ public class ImportKeysActivity extends BaseActivity {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data.putParcelableArrayList(KeychainIntentService.IMPORT_KEY_LIST, keys);
|
data.putParcelableArrayList(CloudImportService.IMPORT_KEY_LIST, keys);
|
||||||
|
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(CloudImportService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
// Create a new Messenger for the communication back
|
||||||
Messenger messenger = new Messenger(saveHandler);
|
Messenger messenger = new Messenger(saveHandler);
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(CloudImportService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
saveHandler.showProgressDialog(this);
|
saveHandler.showProgressDialog(this);
|
||||||
|
@ -42,7 +42,8 @@ import org.sufficientlysecure.keychain.operations.results.ImportKeyResult;
|
|||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.SingletonResult;
|
import org.sufficientlysecure.keychain.operations.results.SingletonResult;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
import org.sufficientlysecure.keychain.util.IntentIntegratorSupportV4;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
@ -213,11 +214,12 @@ public class ImportKeysProxyActivity extends FragmentActivity {
|
|||||||
private void startImportService (ArrayList<ParcelableKeyRing> keyRings) {
|
private void startImportService (ArrayList<ParcelableKeyRing> keyRings) {
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainIntentService
|
// Message is received after importing is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
|
||||||
this,
|
this,
|
||||||
getString(R.string.progress_importing),
|
getString(R.string.progress_importing),
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
true) {
|
true,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -20,7 +20,6 @@ package org.sufficientlysecure.keychain.ui;
|
|||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@ -59,7 +58,6 @@ import com.getbase.floatingactionbutton.FloatingActionsMenu;
|
|||||||
|
|
||||||
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.ImportKeysListEntry;
|
|
||||||
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
|
import org.sufficientlysecure.keychain.operations.results.ConsolidateResult;
|
||||||
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
|
import org.sufficientlysecure.keychain.operations.results.DeleteResult;
|
||||||
@ -70,9 +68,11 @@ import org.sufficientlysecure.keychain.provider.KeychainContract;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
import org.sufficientlysecure.keychain.provider.KeychainDatabase;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
|
import org.sufficientlysecure.keychain.service.CloudImportService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Highlighter;
|
import org.sufficientlysecure.keychain.ui.util.Highlighter;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State;
|
||||||
@ -572,7 +572,7 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updateAllKeys() {
|
private void updateAllKeys() {
|
||||||
Context context = this.getActivity();
|
Context context = getActivity();
|
||||||
|
|
||||||
ProviderHelper providerHelper = new ProviderHelper(context);
|
ProviderHelper providerHelper = new ProviderHelper(context);
|
||||||
|
|
||||||
@ -591,11 +591,12 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
keyList.add(keyEntry);
|
keyList.add(keyEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(
|
||||||
getActivity(),
|
getActivity(),
|
||||||
getString(R.string.progress_importing),
|
getString(R.string.progress_updating),
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
true) {
|
true,
|
||||||
|
ProgressDialogFragment.ServiceType.CLOUD_IMPORT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
@ -613,15 +614,13 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
result.createNotify(KeyListFragment.this.getActivity()).show();
|
result.createNotify(getActivity()).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// 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(getActivity(), KeychainIntentService.class);
|
Intent intent = new Intent(getActivity(), CloudImportService.class);
|
||||||
|
|
||||||
intent.setAction(KeychainIntentService.ACTION_IMPORT_KEYRING);
|
|
||||||
|
|
||||||
// fill values for this action
|
// fill values for this action
|
||||||
Bundle data = new Bundle();
|
Bundle data = new Bundle();
|
||||||
@ -631,16 +630,16 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
Preferences prefs = Preferences.getPreferences(getActivity());
|
Preferences prefs = Preferences.getPreferences(getActivity());
|
||||||
Preferences.CloudSearchPrefs cloudPrefs =
|
Preferences.CloudSearchPrefs cloudPrefs =
|
||||||
new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver());
|
new Preferences.CloudSearchPrefs(true, true, prefs.getPreferredKeyserver());
|
||||||
data.putString(KeychainIntentService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);
|
data.putString(CloudImportService.IMPORT_KEY_SERVER, cloudPrefs.keyserver);
|
||||||
}
|
}
|
||||||
|
|
||||||
data.putParcelableArrayList(KeychainIntentService.IMPORT_KEY_LIST, keyList);
|
data.putParcelableArrayList(CloudImportService.IMPORT_KEY_LIST, keyList);
|
||||||
|
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(CloudImportService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Create a new Messenger for the communication back
|
// Create a new Messenger for the communication back
|
||||||
Messenger messenger = new Messenger(serviceHandler);
|
Messenger messenger = new Messenger(serviceHandler);
|
||||||
intent.putExtra(KeychainIntentService.EXTRA_MESSENGER, messenger);
|
intent.putExtra(CloudImportService.EXTRA_MESSENGER, messenger);
|
||||||
|
|
||||||
// show progress dialog
|
// show progress dialog
|
||||||
serviceHandler.showProgressDialog(getActivity());
|
serviceHandler.showProgressDialog(getActivity());
|
||||||
@ -651,10 +650,11 @@ public class KeyListFragment extends LoaderFragment
|
|||||||
|
|
||||||
private void consolidate() {
|
private void consolidate() {
|
||||||
// Message is received after importing is done in KeychainIntentService
|
// Message is received after importing is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getActivity(),
|
getActivity(),
|
||||||
getString(R.string.progress_importing),
|
getString(R.string.progress_importing),
|
||||||
ProgressDialog.STYLE_HORIZONTAL) {
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -39,7 +39,8 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
||||||
@ -123,11 +124,12 @@ public class SafeSlingerActivity extends BaseActivity {
|
|||||||
final FragmentActivity activity = SafeSlingerActivity.this;
|
final FragmentActivity activity = SafeSlingerActivity.this;
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainIntentService
|
// Message is received after importing is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
activity,
|
activity,
|
||||||
getString(R.string.progress_importing),
|
getString(R.string.progress_importing),
|
||||||
ProgressDialog.STYLE_HORIZONTAL,
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
true) {
|
true,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -36,7 +36,8 @@ import org.sufficientlysecure.keychain.R;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
|
||||||
@ -107,8 +108,11 @@ public class UploadKeyActivity extends BaseActivity {
|
|||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after uploading is done in KeychainIntentService
|
// Message is received after uploading is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this,
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getString(R.string.progress_uploading), ProgressDialog.STYLE_HORIZONTAL) {
|
this,
|
||||||
|
getString(R.string.progress_uploading),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -63,8 +63,8 @@ import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
import org.sufficientlysecure.keychain.provider.KeychainContract;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler.MessageStatus;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler.MessageStatus;
|
||||||
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
import org.sufficientlysecure.keychain.service.PassphraseCacheService;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.FormattingUtils;
|
||||||
@ -387,7 +387,7 @@ public class ViewKeyActivity extends BaseActivity implements
|
|||||||
|
|
||||||
private void startCertifyIntent(Intent intent) {
|
private void startCertifyIntent(Intent intent) {
|
||||||
// Message is received after signing is done in KeychainIntentService
|
// Message is received after signing is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(this) {
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(this) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
@ -562,7 +562,7 @@ public class ViewKeyActivity extends BaseActivity implements
|
|||||||
entries.add(keyEntry);
|
entries.add(keyEntry);
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainIntentService
|
// Message is received after importing is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler serviceHandler = new KeychainIntentServiceHandler(this) {
|
ServiceProgressHandler serviceHandler = new ServiceProgressHandler(this) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -50,12 +50,12 @@ import org.sufficientlysecure.keychain.Constants;
|
|||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Hashtable;
|
import java.util.Hashtable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -362,23 +362,26 @@ public class ViewKeyTrustFragment extends LoaderFragment implements
|
|||||||
|
|
||||||
// Create a new Messenger for the communication back after proof work is done
|
// Create a new Messenger for the communication back after proof work is done
|
||||||
//
|
//
|
||||||
KeychainIntentServiceHandler handler = new KeychainIntentServiceHandler(getActivity(),
|
ServiceProgressHandler handler = new ServiceProgressHandler(
|
||||||
getString(R.string.progress_verifying_signature), ProgressDialog.STYLE_HORIZONTAL) {
|
getActivity(),
|
||||||
|
getString(R.string.progress_verifying_signature),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
|
||||||
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
if (message.arg1 == MessageStatus.OKAY.ordinal()) {
|
||||||
Bundle returnData = message.getData();
|
Bundle returnData = message.getData();
|
||||||
String msg = returnData.getString(KeychainIntentServiceHandler.DATA_MESSAGE);
|
String msg = returnData.getString(ServiceProgressHandler.DATA_MESSAGE);
|
||||||
SpannableStringBuilder ssb = new SpannableStringBuilder();
|
SpannableStringBuilder ssb = new SpannableStringBuilder();
|
||||||
|
|
||||||
if ((msg != null) && msg.equals("OK")) {
|
if ((msg != null) && msg.equals("OK")) {
|
||||||
|
|
||||||
//yay
|
//yay
|
||||||
String proofUrl = returnData.getString(KeychainIntentServiceHandler.KEYBASE_PROOF_URL);
|
String proofUrl = returnData.getString(ServiceProgressHandler.KEYBASE_PROOF_URL);
|
||||||
String presenceUrl = returnData.getString(KeychainIntentServiceHandler.KEYBASE_PRESENCE_URL);
|
String presenceUrl = returnData.getString(ServiceProgressHandler.KEYBASE_PRESENCE_URL);
|
||||||
String presenceLabel = returnData.getString(KeychainIntentServiceHandler.KEYBASE_PRESENCE_LABEL);
|
String presenceLabel = returnData.getString(ServiceProgressHandler.KEYBASE_PRESENCE_LABEL);
|
||||||
|
|
||||||
String proofLabel;
|
String proofLabel;
|
||||||
switch (proof.getType()) {
|
switch (proof.getType()) {
|
||||||
@ -429,7 +432,7 @@ public class ViewKeyTrustFragment extends LoaderFragment implements
|
|||||||
ssb.append(" ").append(getString(R.string.keybase_contained_signature));
|
ssb.append(" ").append(getString(R.string.keybase_contained_signature));
|
||||||
} else {
|
} else {
|
||||||
// verification failed!
|
// verification failed!
|
||||||
msg = returnData.getString(KeychainIntentServiceHandler.DATA_ERROR);
|
msg = returnData.getString(ServiceProgressHandler.DATA_ERROR);
|
||||||
ssb.append(getString(R.string.keybase_proof_failure));
|
ssb.append(getString(R.string.keybase_proof_failure));
|
||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
msg = getString(R.string.keybase_unknown_proof_failure);
|
msg = getString(R.string.keybase_unknown_proof_failure);
|
||||||
|
@ -37,7 +37,7 @@ import org.sufficientlysecure.keychain.pgp.KeyRing;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -135,9 +135,12 @@ public class DeleteKeyDialogFragment extends DialogFragment {
|
|||||||
intent.setAction(KeychainIntentService.ACTION_DELETE);
|
intent.setAction(KeychainIntentService.ACTION_DELETE);
|
||||||
|
|
||||||
// Message is received after importing is done in KeychainIntentService
|
// Message is received after importing is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler saveHandler = new KeychainIntentServiceHandler(
|
ServiceProgressHandler saveHandler = new ServiceProgressHandler(
|
||||||
getActivity(), getString(R.string.progress_deleting),
|
getActivity(),
|
||||||
ProgressDialog.STYLE_HORIZONTAL, true) {
|
getString(R.string.progress_deleting),
|
||||||
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
true,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
@ -32,23 +32,43 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.service.CloudImportService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
|
import org.sufficientlysecure.keychain.util.Log;
|
||||||
|
|
||||||
public class ProgressDialogFragment extends DialogFragment {
|
public class ProgressDialogFragment extends DialogFragment {
|
||||||
private static final String ARG_MESSAGE = "message";
|
private static final String ARG_MESSAGE = "message";
|
||||||
private static final String ARG_STYLE = "style";
|
private static final String ARG_STYLE = "style";
|
||||||
private static final String ARG_CANCELABLE = "cancelable";
|
private static final String ARG_CANCELABLE = "cancelable";
|
||||||
|
private static final String ARG_SERVICE_TYPE = "service_class";
|
||||||
|
|
||||||
|
public static enum ServiceType {
|
||||||
|
KEYCHAIN_INTENT,
|
||||||
|
CLOUD_IMPORT
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceType mServiceType;
|
||||||
|
|
||||||
boolean mCanCancel = false, mPreventCancel = false, mIsCancelled = false;
|
boolean mCanCancel = false, mPreventCancel = false, mIsCancelled = false;
|
||||||
|
|
||||||
/** Creates new instance of this fragment */
|
/**
|
||||||
public static ProgressDialogFragment newInstance(String message, int style, boolean cancelable) {
|
* creates a new instance of this fragment
|
||||||
|
* @param message the message to be displayed initially above the progress bar
|
||||||
|
* @param style the progress bar style, as defined in ProgressDialog (horizontal or spinner)
|
||||||
|
* @param cancelable should we let the user cancel this operation
|
||||||
|
* @param serviceType which Service this progress dialog is meant for
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static ProgressDialogFragment newInstance(String message, int style, boolean cancelable,
|
||||||
|
ServiceType serviceType) {
|
||||||
ProgressDialogFragment frag = new ProgressDialogFragment();
|
ProgressDialogFragment frag = new ProgressDialogFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putString(ARG_MESSAGE, message);
|
args.putString(ARG_MESSAGE, message);
|
||||||
args.putInt(ARG_STYLE, style);
|
args.putInt(ARG_STYLE, style);
|
||||||
args.putBoolean(ARG_CANCELABLE, cancelable);
|
args.putBoolean(ARG_CANCELABLE, cancelable);
|
||||||
|
args.putSerializable(ARG_SERVICE_TYPE, serviceType);
|
||||||
|
|
||||||
frag.setArguments(args);
|
frag.setArguments(args);
|
||||||
|
|
||||||
@ -106,6 +126,7 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
String message = getArguments().getString(ARG_MESSAGE);
|
String message = getArguments().getString(ARG_MESSAGE);
|
||||||
int style = getArguments().getInt(ARG_STYLE);
|
int style = getArguments().getInt(ARG_STYLE);
|
||||||
mCanCancel = getArguments().getBoolean(ARG_CANCELABLE);
|
mCanCancel = getArguments().getBoolean(ARG_CANCELABLE);
|
||||||
|
mServiceType = (ServiceType) getArguments().getSerializable(ARG_SERVICE_TYPE);
|
||||||
|
|
||||||
dialog.setMessage(message);
|
dialog.setMessage(message);
|
||||||
dialog.setProgressStyle(style);
|
dialog.setProgressStyle(style);
|
||||||
@ -175,9 +196,22 @@ public class ProgressDialogFragment extends DialogFragment {
|
|||||||
// send a cancel message. note that this message will be handled by
|
// send a cancel message. note that this message will be handled by
|
||||||
// KeychainIntentService.onStartCommand, which runs in this thread,
|
// KeychainIntentService.onStartCommand, which runs in this thread,
|
||||||
// not the service one, and will not queue up a command.
|
// not the service one, and will not queue up a command.
|
||||||
Intent intent = new Intent(getActivity(), KeychainIntentService.class);
|
Intent serviceIntent = null;
|
||||||
intent.setAction(KeychainIntentService.ACTION_CANCEL);
|
|
||||||
getActivity().startService(intent);
|
switch (mServiceType) {
|
||||||
|
case CLOUD_IMPORT:
|
||||||
|
serviceIntent = new Intent(getActivity(), CloudImportService.class);
|
||||||
|
break;
|
||||||
|
case KEYCHAIN_INTENT:
|
||||||
|
serviceIntent = new Intent(getActivity(), KeychainIntentService.class);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//should never happen, unless we forget to include a ServiceType enum case
|
||||||
|
Log.e(Constants.TAG, "Unrecognized ServiceType at ProgressDialogFragment");
|
||||||
|
}
|
||||||
|
|
||||||
|
serviceIntent.setAction(KeychainIntentService.ACTION_CANCEL);
|
||||||
|
getActivity().startService(serviceIntent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -19,9 +19,7 @@ package org.sufficientlysecure.keychain.util;
|
|||||||
|
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.Messenger;
|
import android.os.Messenger;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
@ -29,11 +27,9 @@ import android.support.v4.app.FragmentActivity;
|
|||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
import org.sufficientlysecure.keychain.operations.results.ExportResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.exception.PgpKeyNotFoundException;
|
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
import org.sufficientlysecure.keychain.service.KeychainIntentService;
|
||||||
import org.sufficientlysecure.keychain.service.KeychainIntentServiceHandler;
|
import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.DeleteKeyDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@ -102,9 +98,10 @@ public class ExportHelper {
|
|||||||
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
intent.putExtra(KeychainIntentService.EXTRA_DATA, data);
|
||||||
|
|
||||||
// Message is received after exporting is done in KeychainIntentService
|
// Message is received after exporting is done in KeychainIntentService
|
||||||
KeychainIntentServiceHandler exportHandler = new KeychainIntentServiceHandler(mActivity,
|
ServiceProgressHandler exportHandler = new ServiceProgressHandler(mActivity,
|
||||||
mActivity.getString(R.string.progress_exporting),
|
mActivity.getString(R.string.progress_exporting),
|
||||||
ProgressDialog.STYLE_HORIZONTAL) {
|
ProgressDialog.STYLE_HORIZONTAL,
|
||||||
|
ProgressDialogFragment.ServiceType.KEYCHAIN_INTENT) {
|
||||||
public void handleMessage(Message message) {
|
public void handleMessage(Message message) {
|
||||||
// handle messages by standard KeychainIntentServiceHandler first
|
// handle messages by standard KeychainIntentServiceHandler first
|
||||||
super.handleMessage(message);
|
super.handleMessage(message);
|
||||||
|
Loading…
Reference in New Issue
Block a user