Merge pull request #600 from thi/rename-progressdialogupdater

Rename progressdialogupdater
This commit is contained in:
Dominik Schürmann 2014-04-29 19:50:30 +02:00
commit 5c145cf44d
8 changed files with 57 additions and 54 deletions

View file

@ -52,12 +52,12 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyDataDecryptorFactoryBuilder;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.Progressable;
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.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
@ -79,7 +79,7 @@ public class PgpDecryptVerify {
private InputData mData; private InputData mData;
private OutputStream mOutStream; private OutputStream mOutStream;
private ProgressDialogUpdater mProgressDialogUpdater; private Progressable mProgressable;
private boolean mAllowSymmetricDecryption; private boolean mAllowSymmetricDecryption;
private String mPassphrase; private String mPassphrase;
private Set<Long> mAllowedKeyIds; private Set<Long> mAllowedKeyIds;
@ -91,7 +91,7 @@ public class PgpDecryptVerify {
this.mData = builder.mData; this.mData = builder.mData;
this.mOutStream = builder.mOutStream; this.mOutStream = builder.mOutStream;
this.mProgressDialogUpdater = builder.mProgressDialogUpdater; this.mProgressable = builder.mProgressable;
this.mAllowSymmetricDecryption = builder.mAllowSymmetricDecryption; this.mAllowSymmetricDecryption = builder.mAllowSymmetricDecryption;
this.mPassphrase = builder.mPassphrase; this.mPassphrase = builder.mPassphrase;
this.mAllowedKeyIds = builder.mAllowedKeyIds; this.mAllowedKeyIds = builder.mAllowedKeyIds;
@ -105,7 +105,7 @@ public class PgpDecryptVerify {
private OutputStream mOutStream; private OutputStream mOutStream;
// optional // optional
private ProgressDialogUpdater mProgressDialogUpdater = null; private Progressable mProgressable = null;
private boolean mAllowSymmetricDecryption = true; private boolean mAllowSymmetricDecryption = true;
private String mPassphrase = null; private String mPassphrase = null;
private Set<Long> mAllowedKeyIds = null; private Set<Long> mAllowedKeyIds = null;
@ -118,8 +118,8 @@ public class PgpDecryptVerify {
this.mOutStream = outStream; this.mOutStream = outStream;
} }
public Builder progressDialogUpdater(ProgressDialogUpdater progressDialogUpdater) { public Builder progressable(Progressable progressable) {
this.mProgressDialogUpdater = progressDialogUpdater; this.mProgressable = progressable;
return this; return this;
} }
@ -151,14 +151,14 @@ public class PgpDecryptVerify {
} }
public void updateProgress(int message, int current, int total) { public void updateProgress(int message, int current, int total) {
if (mProgressDialogUpdater != null) { if (mProgressable != null) {
mProgressDialogUpdater.setProgress(message, current, total); mProgressable.setProgress(message, current, total);
} }
} }
public void updateProgress(int current, int total) { public void updateProgress(int current, int total) {
if (mProgressDialogUpdater != null) { if (mProgressable != null) {
mProgressDialogUpdater.setProgress(current, total); mProgressable.setProgress(current, total);
} }
} }

View file

@ -24,8 +24,8 @@ import android.content.pm.PackageManager.NameNotFoundException;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -140,11 +140,11 @@ public class PgpHelper {
* TODO: Does this really help on flash storage? * TODO: Does this really help on flash storage?
* *
* @param context * @param context
* @param progress * @param progressable
* @param file * @param file
* @throws IOException * @throws IOException
*/ */
public static void deleteFileSecurely(Context context, ProgressDialogUpdater progress, File file) public static void deleteFileSecurely(Context context, Progressable progressable, File file)
throws IOException { throws IOException {
long length = file.length(); long length = file.length();
SecureRandom random = new SecureRandom(); SecureRandom random = new SecureRandom();
@ -155,8 +155,8 @@ public class PgpHelper {
int pos = 0; int pos = 0;
String msg = context.getString(R.string.progress_deleting_securely, file.getName()); String msg = context.getString(R.string.progress_deleting_securely, file.getName());
while (pos < length) { while (pos < length) {
if (progress != null) { if (progressable != null) {
progress.setProgress(msg, (int) (100 * pos / length), 100); progressable.setProgress(msg, (int) (100 * pos / length), 100);
} }
random.nextBytes(data); random.nextBytes(data);
raf.write(data); raf.write(data);

View file

@ -32,6 +32,7 @@ import org.spongycastle.openpgp.PGPSecretKeyRing;
import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator; import org.spongycastle.openpgp.operator.jcajce.JcaKeyFingerprintCalculator;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralException;
import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.ProviderHelper;
import org.sufficientlysecure.keychain.service.KeychainIntentService; import org.sufficientlysecure.keychain.service.KeychainIntentService;
@ -41,7 +42,6 @@ import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.KeyServer.AddKeyException; import org.sufficientlysecure.keychain.util.KeyServer.AddKeyException;
import org.sufficientlysecure.keychain.util.KeychainServiceListener; import org.sufficientlysecure.keychain.util.KeychainServiceListener;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -52,7 +52,7 @@ import java.util.List;
public class PgpImportExport { public class PgpImportExport {
private Context mContext; private Context mContext;
private ProgressDialogUpdater mProgress; private Progressable mProgressable;
private KeychainServiceListener mKeychainServiceListener; private KeychainServiceListener mKeychainServiceListener;
@ -63,37 +63,37 @@ public class PgpImportExport {
public static final int RETURN_BAD = -2; public static final int RETURN_BAD = -2;
public static final int RETURN_UPDATED = 1; public static final int RETURN_UPDATED = 1;
public PgpImportExport(Context context, ProgressDialogUpdater progress) { public PgpImportExport(Context context, Progressable progressable) {
super(); super();
this.mContext = context; this.mContext = context;
this.mProgress = progress; this.mProgressable = progressable;
this.mProviderHelper = new ProviderHelper(context); this.mProviderHelper = new ProviderHelper(context);
} }
public PgpImportExport(Context context, public PgpImportExport(Context context,
ProgressDialogUpdater progress, KeychainServiceListener keychainListener) { Progressable progressable, KeychainServiceListener keychainListener) {
super(); super();
this.mContext = context; this.mContext = context;
this.mProgress = progress; this.mProgressable = progressable;
this.mProviderHelper = new ProviderHelper(context); this.mProviderHelper = new ProviderHelper(context);
this.mKeychainServiceListener = keychainListener; this.mKeychainServiceListener = keychainListener;
} }
public void updateProgress(int message, int current, int total) { public void updateProgress(int message, int current, int total) {
if (mProgress != null) { if (mProgressable != null) {
mProgress.setProgress(message, current, total); mProgressable.setProgress(message, current, total);
} }
} }
public void updateProgress(String message, int current, int total) { public void updateProgress(String message, int current, int total) {
if (mProgress != null) { if (mProgressable != null) {
mProgress.setProgress(message, current, total); mProgressable.setProgress(message, current, total);
} }
} }
public void updateProgress(int current, int total) { public void updateProgress(int current, int total) {
if (mProgress != null) { if (mProgressable != null) {
mProgress.setProgress(current, total); mProgressable.setProgress(current, total);
} }
} }

View file

@ -48,11 +48,11 @@ import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyDecryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder; import org.spongycastle.openpgp.operator.jcajce.JcePBESecretKeyEncryptorBuilder;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.Progressable;
import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException; import org.sufficientlysecure.keychain.pgp.exception.PgpGeneralMsgIdException;
import org.sufficientlysecure.keychain.service.SaveKeyringParcel; import org.sufficientlysecure.keychain.service.SaveKeyringParcel;
import org.sufficientlysecure.keychain.util.IterableIterator; import org.sufficientlysecure.keychain.util.IterableIterator;
import org.sufficientlysecure.keychain.util.Primes; import org.sufficientlysecure.keychain.util.Primes;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
@ -75,11 +75,11 @@ import java.util.TimeZone;
* <p/> * <p/>
* Note that no android specific stuff should be done here, ie no imports from com.android. * Note that no android specific stuff should be done here, ie no imports from com.android.
* <p/> * <p/>
* All operations support progress reporting to a ProgressDialogUpdater passed on initialization. * All operations support progress reporting to a Progressable passed on initialization.
* This indicator may be null. * This indicator may be null.
*/ */
public class PgpKeyOperation { public class PgpKeyOperation {
private ProgressDialogUpdater mProgress; private Progressable mProgress;
private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[]{ private static final int[] PREFERRED_SYMMETRIC_ALGORITHMS = new int[]{
SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192, SymmetricKeyAlgorithmTags.AES_256, SymmetricKeyAlgorithmTags.AES_192,
@ -91,7 +91,7 @@ public class PgpKeyOperation {
CompressionAlgorithmTags.ZLIB, CompressionAlgorithmTags.BZIP2, CompressionAlgorithmTags.ZLIB, CompressionAlgorithmTags.BZIP2,
CompressionAlgorithmTags.ZIP}; CompressionAlgorithmTags.ZIP};
public PgpKeyOperation(ProgressDialogUpdater progress) { public PgpKeyOperation(Progressable progress) {
super(); super();
this.mProgress = progress; this.mProgress = progress;
} }

View file

@ -42,11 +42,11 @@ import org.spongycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder;
import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator; import org.spongycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.R;
import org.sufficientlysecure.keychain.pgp.Progressable;
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.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
@ -69,7 +69,7 @@ public class PgpSignEncrypt {
private InputData mData; private InputData mData;
private OutputStream mOutStream; private OutputStream mOutStream;
private ProgressDialogUpdater mProgress; private Progressable mProgressable;
private boolean mEnableAsciiArmorOutput; private boolean mEnableAsciiArmorOutput;
private int mCompressionId; private int mCompressionId;
private long[] mEncryptionMasterKeyIds; private long[] mEncryptionMasterKeyIds;
@ -99,7 +99,7 @@ public class PgpSignEncrypt {
this.mData = builder.mData; this.mData = builder.mData;
this.mOutStream = builder.mOutStream; this.mOutStream = builder.mOutStream;
this.mProgress = builder.mProgress; this.mProgressable = builder.mProgressable;
this.mEnableAsciiArmorOutput = builder.mEnableAsciiArmorOutput; this.mEnableAsciiArmorOutput = builder.mEnableAsciiArmorOutput;
this.mCompressionId = builder.mCompressionId; this.mCompressionId = builder.mCompressionId;
this.mEncryptionMasterKeyIds = builder.mEncryptionMasterKeyIds; this.mEncryptionMasterKeyIds = builder.mEncryptionMasterKeyIds;
@ -121,7 +121,7 @@ public class PgpSignEncrypt {
private OutputStream mOutStream; private OutputStream mOutStream;
// optional // optional
private ProgressDialogUpdater mProgress = null; private Progressable mProgressable = null;
private boolean mEnableAsciiArmorOutput = false; private boolean mEnableAsciiArmorOutput = false;
private int mCompressionId = Constants.choice.compression.none; private int mCompressionId = Constants.choice.compression.none;
private long[] mEncryptionMasterKeyIds = null; private long[] mEncryptionMasterKeyIds = null;
@ -141,8 +141,8 @@ public class PgpSignEncrypt {
this.mOutStream = outStream; this.mOutStream = outStream;
} }
public Builder progress(ProgressDialogUpdater progress) { public Builder progressable(Progressable progressable) {
this.mProgress = progress; this.mProgressable = progressable;
return this; return this;
} }
@ -219,14 +219,14 @@ public class PgpSignEncrypt {
} }
public void updateProgress(int message, int current, int total) { public void updateProgress(int message, int current, int total) {
if (mProgress != null) { if (mProgressable != null) {
mProgress.setProgress(message, current, total); mProgressable.setProgress(message, current, total);
} }
} }
public void updateProgress(int current, int total) { public void updateProgress(int current, int total) {
if (mProgress != null) { if (mProgressable != null) {
mProgress.setProgress(current, total); mProgressable.setProgress(current, total);
} }
} }

View file

@ -15,9 +15,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
package org.sufficientlysecure.keychain.util; package org.sufficientlysecure.keychain.pgp;
public interface ProgressDialogUpdater { public interface Progressable {
void setProgress(String message, int current, int total); void setProgress(String message, int current, int total);
void setProgress(int resourceId, int current, int total); void setProgress(int resourceId, int current, int total);

View file

@ -47,6 +47,7 @@ import org.sufficientlysecure.keychain.pgp.PgpImportExport;
import org.sufficientlysecure.keychain.pgp.PgpKeyHelper; import org.sufficientlysecure.keychain.pgp.PgpKeyHelper;
import org.sufficientlysecure.keychain.pgp.PgpKeyOperation; import org.sufficientlysecure.keychain.pgp.PgpKeyOperation;
import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt; import org.sufficientlysecure.keychain.pgp.PgpSignEncrypt;
import org.sufficientlysecure.keychain.pgp.Progressable;
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.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
@ -57,7 +58,6 @@ import org.sufficientlysecure.keychain.util.HkpKeyServer;
import org.sufficientlysecure.keychain.util.InputData; import org.sufficientlysecure.keychain.util.InputData;
import org.sufficientlysecure.keychain.util.KeychainServiceListener; import org.sufficientlysecure.keychain.util.KeychainServiceListener;
import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Log;
import org.sufficientlysecure.keychain.util.ProgressDialogUpdater;
import org.sufficientlysecure.keychain.util.ProgressScaler; import org.sufficientlysecure.keychain.util.ProgressScaler;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
@ -79,7 +79,7 @@ import java.util.List;
* after doing them. * after doing them.
*/ */
public class KeychainIntentService extends IntentService public class KeychainIntentService extends IntentService
implements ProgressDialogUpdater, KeychainServiceListener { implements Progressable, KeychainServiceListener {
/* extras that can be given by intent */ /* extras that can be given by intent */
public static final String EXTRA_MESSENGER = "messenger"; public static final String EXTRA_MESSENGER = "messenger";
@ -313,7 +313,7 @@ public class KeychainIntentService extends IntentService
new ProviderHelper(this), new ProviderHelper(this),
PgpHelper.getFullVersion(this), PgpHelper.getFullVersion(this),
inputData, outStream); inputData, outStream);
builder.progress(this); builder.progressable(this);
builder.enableAsciiArmorOutput(useAsciiArmor) builder.enableAsciiArmorOutput(useAsciiArmor)
.compressionId(compressionId) .compressionId(compressionId)
@ -457,7 +457,7 @@ public class KeychainIntentService extends IntentService
} }
}, },
inputData, outStream); inputData, outStream);
builder.progressDialogUpdater(this); builder.progressable(this);
builder.allowSymmetricDecryption(true) builder.allowSymmetricDecryption(true)
.passphrase(passphrase); .passphrase(passphrase);
@ -925,10 +925,10 @@ public class KeychainIntentService extends IntentService
} }
/** /**
* Set progressDialogUpdater of ProgressDialog by sending message to handler on UI thread * Set progress of ProgressDialog by sending message to handler on UI thread
*/ */
public 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 progressDialogUpdater=" + progress + ", max=" Log.d(Constants.TAG, "Send message by setProgress with progress=" + progress + ", max="
+ max); + max);
Bundle data = new Bundle(); Bundle data = new Bundle();

View file

@ -17,15 +17,18 @@
package org.sufficientlysecure.keychain.util; package org.sufficientlysecure.keychain.util;
/** This is a simple class that wraps a ProgressDialogUpdater, scaling the progress import org.sufficientlysecure.keychain.pgp.Progressable;
/**
* This is a simple class that wraps a Progressable, scaling the progress
* values into a specified range. * values into a specified range.
*/ */
public class ProgressScaler implements ProgressDialogUpdater { public class ProgressScaler implements Progressable {
final ProgressDialogUpdater mWrapped; final Progressable mWrapped;
final int mFrom, mTo, mMax; final int mFrom, mTo, mMax;
public ProgressScaler(ProgressDialogUpdater wrapped, int from, int to, int max) { public ProgressScaler(Progressable wrapped, int from, int to, int max) {
this.mWrapped = wrapped; this.mWrapped = wrapped;
this.mFrom = from; this.mFrom = from;
this.mTo = to; this.mTo = to;
@ -33,7 +36,7 @@ public class ProgressScaler implements ProgressDialogUpdater {
} }
/** /**
* Set progressDialogUpdater of ProgressDialog by sending message to handler on UI thread * Set progress of ProgressDialog by sending message to handler on UI thread
*/ */
public void setProgress(String message, int progress, int max) { public void setProgress(String message, int progress, int max) {
mWrapped.setProgress(message, mFrom + progress * (mTo - mFrom) / max, mMax); mWrapped.setProgress(message, mFrom + progress * (mTo - mFrom) / max, mMax);