mirror of
https://github.com/moparisthebest/open-keychain
synced 2024-11-30 04:22:18 -05:00
made key import compatible with CryptoOperationFragment
This commit is contained in:
parent
8777461bc4
commit
35ee21bfab
@ -22,6 +22,7 @@ import android.content.Context;
|
|||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import android.os.Parcelable;
|
||||||
import org.spongycastle.bcpg.ArmoredOutputStream;
|
import org.spongycastle.bcpg.ArmoredOutputStream;
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
@ -46,13 +47,13 @@ import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings;
|
|||||||
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
import org.sufficientlysecure.keychain.provider.KeychainDatabase.Tables;
|
||||||
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
import org.sufficientlysecure.keychain.provider.ProviderHelper;
|
||||||
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
import org.sufficientlysecure.keychain.service.ContactSyncAdapterService;
|
||||||
|
import org.sufficientlysecure.keychain.service.ImportKeyringParcel;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils;
|
||||||
import org.sufficientlysecure.keychain.util.FileHelper;
|
import org.sufficientlysecure.keychain.util.*;
|
||||||
import org.sufficientlysecure.keychain.util.Log;
|
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache;
|
|
||||||
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
import org.sufficientlysecure.keychain.util.ParcelableFileCache.IteratorWithSize;
|
||||||
import org.sufficientlysecure.keychain.util.Preferences;
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
import org.sufficientlysecure.keychain.util.ProgressScaler;
|
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
@ -66,7 +67,13 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.ExecutorCompletionService;
|
||||||
|
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;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,7 +100,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||||||
* <p/>
|
* <p/>
|
||||||
* TODO rework uploadKeyRingToServer
|
* TODO rework uploadKeyRingToServer
|
||||||
*/
|
*/
|
||||||
public class ImportExportOperation extends BaseOperation {
|
public class ImportExportOperation extends BaseOperation<ImportKeyringParcel> {
|
||||||
|
|
||||||
public ImportExportOperation(Context context, ProviderHelper providerHelper, Progressable progressable) {
|
public ImportExportOperation(Context context, ProviderHelper providerHelper, Progressable progressable) {
|
||||||
super(context, providerHelper, progressable);
|
super(context, providerHelper, progressable);
|
||||||
@ -630,15 +637,31 @@ public class ImportExportOperation extends BaseOperation {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ImportKeyResult importKeys(ArrayList<ParcelableKeyRing> keyList, String keyServer, Context context) {
|
@Override
|
||||||
Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(context).getProxyPrefs();
|
public ImportKeyResult execute(ImportKeyringParcel input, CryptoInputParcel cryptoInput) {
|
||||||
|
Proxy proxy = null;
|
||||||
|
|
||||||
Proxy proxy = proxyPrefs.parcelableProxy.getProxy();
|
if (cryptoInput.getParcelableProxy() == null) {
|
||||||
|
// if a proxy is not specified, we retrieve from preferences
|
||||||
|
Preferences.ProxyPrefs proxyPrefs = Preferences.getPreferences(mContext).getProxyPrefs();
|
||||||
|
|
||||||
|
if (proxyPrefs.torEnabled && !OrbotHelper.isOrbotInstalledAndRunning(mContext)) {
|
||||||
|
// is it okay to pass null for log?
|
||||||
|
return new ImportKeyResult(null, RequiredInputParcel.createRequiredOrbotEnable());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
proxy = cryptoInput.getParcelableProxy().getProxy();
|
||||||
|
}
|
||||||
|
|
||||||
|
return importKeys(input.mKeyList, input.mKeyserver, proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImportKeyResult importKeys(ArrayList<ParcelableKeyRing> keyList, String keyServer, Proxy proxy) {
|
||||||
|
|
||||||
ImportKeyResult result = null;
|
ImportKeyResult result = null;
|
||||||
|
|
||||||
if (keyList == null) {// import from file, do serially
|
if (keyList == null) {// import from file, do serially
|
||||||
ParcelableFileCache<ParcelableKeyRing> cache = new ParcelableFileCache<>(context, "key_import.pcl");
|
ParcelableFileCache<ParcelableKeyRing> cache = new ParcelableFileCache<>(mContext, "key_import.pcl");
|
||||||
|
|
||||||
result = serialKeyRingImport(cache, keyServer, proxy);
|
result = serialKeyRingImport(cache, keyServer, proxy);
|
||||||
} else {
|
} else {
|
||||||
|
@ -23,6 +23,7 @@ import android.content.Intent;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.R;
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
|
import org.sufficientlysecure.keychain.ui.LogDisplayActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
import org.sufficientlysecure.keychain.ui.LogDisplayFragment;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify;
|
import org.sufficientlysecure.keychain.ui.util.Notify;
|
||||||
@ -30,7 +31,7 @@ import org.sufficientlysecure.keychain.ui.util.Notify.ActionListener;
|
|||||||
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
|
import org.sufficientlysecure.keychain.ui.util.Notify.Showable;
|
||||||
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
import org.sufficientlysecure.keychain.ui.util.Notify.Style;
|
||||||
|
|
||||||
public class ImportKeyResult extends OperationResult {
|
public class ImportKeyResult extends InputPendingResult {
|
||||||
|
|
||||||
public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret;
|
public final int mNewKeys, mUpdatedKeys, mBadKeys, mSecret;
|
||||||
public final long[] mImportedMasterKeyIds;
|
public final long[] mImportedMasterKeyIds;
|
||||||
@ -79,6 +80,14 @@ public class ImportKeyResult extends OperationResult {
|
|||||||
mImportedMasterKeyIds = source.createLongArray();
|
mImportedMasterKeyIds = source.createLongArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a result with attributes other than the log set to defaults.
|
||||||
|
* This constructor is used when the operation fails (including when there is nothing to import) and only the log
|
||||||
|
* and result code matters.
|
||||||
|
*
|
||||||
|
* @param result the result code
|
||||||
|
* @param log
|
||||||
|
*/
|
||||||
public ImportKeyResult(int result, OperationLog log) {
|
public ImportKeyResult(int result, OperationLog log) {
|
||||||
this(result, log, 0, 0, 0, 0, new long[] { });
|
this(result, log, 0, 0, 0, 0, new long[] { });
|
||||||
}
|
}
|
||||||
@ -94,6 +103,22 @@ public class ImportKeyResult extends OperationResult {
|
|||||||
mImportedMasterKeyIds = importedMasterKeyIds;
|
mImportedMasterKeyIds = importedMasterKeyIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* When extra input is required. Super constructor will set the "data pending" field of mResult.
|
||||||
|
*
|
||||||
|
* @param log
|
||||||
|
* @param requiredInput specifies the extra input required
|
||||||
|
*/
|
||||||
|
public ImportKeyResult(OperationLog log, RequiredInputParcel requiredInput) {
|
||||||
|
super(log, requiredInput);
|
||||||
|
// just supply default values, we won't use them
|
||||||
|
mNewKeys = 0;
|
||||||
|
mUpdatedKeys = 0;
|
||||||
|
mBadKeys = 0;
|
||||||
|
mSecret = 0;
|
||||||
|
mImportedMasterKeyIds = new long[]{};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeToParcel(Parcel dest, int flags) {
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
super.writeToParcel(dest, flags);
|
super.writeToParcel(dest, flags);
|
||||||
|
@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
* Copyright (C) 2015 Adithya Abraham Philip <adithyaphilip@gmail.com>
|
||||||
|
*
|
||||||
|
* 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.os.Parcel;
|
||||||
|
import android.os.Parcelable;
|
||||||
|
import org.sufficientlysecure.keychain.keyimport.ParcelableKeyRing;
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ImportKeyringParcel implements Parcelable {
|
||||||
|
// if null, keys are expected to be read from a cache file in ImportExportOperations
|
||||||
|
public ArrayList<ParcelableKeyRing> mKeyList;
|
||||||
|
public String mKeyserver; // must be set if keys are to be imported from a keyserver
|
||||||
|
|
||||||
|
public ImportKeyringParcel (ArrayList<ParcelableKeyRing> keyList, String keyserver) {
|
||||||
|
mKeyList = keyList;
|
||||||
|
mKeyserver = keyserver;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ImportKeyringParcel(Parcel in) {
|
||||||
|
if (in.readByte() == 0x01) {
|
||||||
|
mKeyList = new ArrayList<>();
|
||||||
|
in.readList(mKeyList, ParcelableKeyRing.class.getClassLoader());
|
||||||
|
} else {
|
||||||
|
mKeyList = null;
|
||||||
|
}
|
||||||
|
mKeyserver = in.readString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
if (mKeyList == null) {
|
||||||
|
dest.writeByte((byte) (0x00));
|
||||||
|
} else {
|
||||||
|
dest.writeByte((byte) (0x01));
|
||||||
|
dest.writeList(mKeyList);
|
||||||
|
}
|
||||||
|
dest.writeString(mKeyserver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Parcelable.Creator<ImportKeyringParcel> CREATOR = new Parcelable.Creator<ImportKeyringParcel>() {
|
||||||
|
@Override
|
||||||
|
public ImportKeyringParcel createFromParcel(Parcel in) {
|
||||||
|
return new ImportKeyringParcel(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ImportKeyringParcel[] newArray(int size) {
|
||||||
|
return new ImportKeyringParcel[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
@ -31,10 +31,7 @@ import android.os.Parcelable;
|
|||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
|
|
||||||
import org.sufficientlysecure.keychain.Constants;
|
import org.sufficientlysecure.keychain.Constants;
|
||||||
import org.sufficientlysecure.keychain.operations.BaseOperation;
|
import org.sufficientlysecure.keychain.operations.*;
|
||||||
import org.sufficientlysecure.keychain.operations.CertifyOperation;
|
|
||||||
import org.sufficientlysecure.keychain.operations.EditKeyOperation;
|
|
||||||
import org.sufficientlysecure.keychain.operations.SignEncryptOperation;
|
|
||||||
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
import org.sufficientlysecure.keychain.operations.results.OperationResult;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
|
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerify;
|
||||||
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
|
import org.sufficientlysecure.keychain.pgp.PgpDecryptVerifyInputParcel;
|
||||||
@ -103,7 +100,11 @@ public class KeychainNewService extends Service implements Progressable {
|
|||||||
op = new EditKeyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
op = new EditKeyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
||||||
} else if (inputParcel instanceof CertifyAction) {
|
} else if (inputParcel instanceof CertifyAction) {
|
||||||
op = new CertifyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
op = new CertifyOperation(outerThis, new ProviderHelper(outerThis), outerThis, mActionCanceled);
|
||||||
} else {
|
} else if (inputParcel instanceof ImportKeyringParcel) {
|
||||||
|
op = new ImportExportOperation(outerThis, new ProviderHelper(outerThis), outerThis,
|
||||||
|
mActionCanceled);
|
||||||
|
}
|
||||||
|
else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,11 +21,7 @@ package org.sufficientlysecure.keychain.service;
|
|||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.*;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.os.Message;
|
|
||||||
import android.os.Messenger;
|
|
||||||
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;
|
||||||
@ -394,8 +390,10 @@ public class KeychainService extends Service implements Progressable {
|
|||||||
ImportExportOperation importExportOperation = new ImportExportOperation(KeychainService.this,
|
ImportExportOperation importExportOperation = new ImportExportOperation(KeychainService.this,
|
||||||
providerHelper, KeychainService.this, mActionCanceled);
|
providerHelper, KeychainService.this, mActionCanceled);
|
||||||
|
|
||||||
ImportKeyResult result =
|
ImportKeyringParcel inputParcel = new ImportKeyringParcel(keyList, keyServer);
|
||||||
importExportOperation.importKeys(keyList, keyServer, KeychainService.this);
|
CryptoInputParcel cryptoInputParcel = new CryptoInputParcel();
|
||||||
|
|
||||||
|
ImportKeyResult result = importExportOperation.execute(inputParcel, cryptoInputParcel);
|
||||||
|
|
||||||
sendMessageToHandler(MessageStatus.OKAY, result);
|
sendMessageToHandler(MessageStatus.OKAY, result);
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ import java.util.Map;
|
|||||||
import android.os.Parcel;
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
|
||||||
|
import org.sufficientlysecure.keychain.util.ParcelableProxy;
|
||||||
import org.sufficientlysecure.keychain.util.Passphrase;
|
import org.sufficientlysecure.keychain.util.Passphrase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,11 +41,20 @@ public class CryptoInputParcel implements Parcelable {
|
|||||||
// used in the crypto operation described by this parcel.
|
// used in the crypto operation described by this parcel.
|
||||||
private HashMap<ByteBuffer, byte[]> mCryptoData = new HashMap<>();
|
private HashMap<ByteBuffer, byte[]> mCryptoData = new HashMap<>();
|
||||||
|
|
||||||
|
// used to specify an explicit proxy for operations that require it
|
||||||
|
private ParcelableProxy mParcelableProxy;
|
||||||
|
|
||||||
public CryptoInputParcel() {
|
public CryptoInputParcel() {
|
||||||
mSignatureTime = new Date();
|
mSignatureTime = new Date();
|
||||||
mPassphrase = null;
|
mPassphrase = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CryptoInputParcel(ParcelableProxy parcelableProxy) {
|
||||||
|
mSignatureTime = new Date();
|
||||||
|
mPassphrase = null;
|
||||||
|
mParcelableProxy = parcelableProxy;
|
||||||
|
}
|
||||||
|
|
||||||
public CryptoInputParcel(Date signatureTime, Passphrase passphrase) {
|
public CryptoInputParcel(Date signatureTime, Passphrase passphrase) {
|
||||||
mSignatureTime = signatureTime == null ? new Date() : signatureTime;
|
mSignatureTime = signatureTime == null ? new Date() : signatureTime;
|
||||||
mPassphrase = passphrase;
|
mPassphrase = passphrase;
|
||||||
@ -74,6 +84,8 @@ public class CryptoInputParcel implements Parcelable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mParcelableProxy = source.readParcelable(getClass().getClassLoader());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -91,6 +103,8 @@ public class CryptoInputParcel implements Parcelable {
|
|||||||
dest.writeByteArray(entry.getKey().array());
|
dest.writeByteArray(entry.getKey().array());
|
||||||
dest.writeByteArray(entry.getValue());
|
dest.writeByteArray(entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dest.writeParcelable(mParcelableProxy, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCryptoData(byte[] hash, byte[] signedHash) {
|
public void addCryptoData(byte[] hash, byte[] signedHash) {
|
||||||
@ -113,6 +127,10 @@ public class CryptoInputParcel implements Parcelable {
|
|||||||
return mPassphrase;
|
return mPassphrase;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ParcelableProxy getParcelableProxy() {
|
||||||
|
return mParcelableProxy;
|
||||||
|
}
|
||||||
|
|
||||||
public static final Creator<CryptoInputParcel> CREATOR = new Creator<CryptoInputParcel>() {
|
public static final Creator<CryptoInputParcel> CREATOR = new Creator<CryptoInputParcel>() {
|
||||||
public CryptoInputParcel createFromParcel(final Parcel source) {
|
public CryptoInputParcel createFromParcel(final Parcel source) {
|
||||||
return new CryptoInputParcel(source);
|
return new CryptoInputParcel(source);
|
||||||
|
@ -12,7 +12,7 @@ import android.os.Parcelable;
|
|||||||
public class RequiredInputParcel implements Parcelable {
|
public class RequiredInputParcel implements Parcelable {
|
||||||
|
|
||||||
public enum RequiredInputType {
|
public enum RequiredInputType {
|
||||||
PASSPHRASE, PASSPHRASE_SYMMETRIC, NFC_SIGN, NFC_DECRYPT, NFC_KEYTOCARD
|
PASSPHRASE, PASSPHRASE_SYMMETRIC, NFC_SIGN, NFC_DECRYPT, NFC_KEYTOCARD, ENABLE_ORBOT
|
||||||
}
|
}
|
||||||
|
|
||||||
public Date mSignatureTime;
|
public Date mSignatureTime;
|
||||||
@ -111,6 +111,10 @@ public class RequiredInputParcel implements Parcelable {
|
|||||||
null, null, req.mSignatureTime, req.mMasterKeyId, req.mSubKeyId);
|
null, null, req.mSignatureTime, req.mMasterKeyId, req.mSubKeyId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static RequiredInputParcel createRequiredOrbotEnable() {
|
||||||
|
return new RequiredInputParcel(RequiredInputType.ENABLE_ORBOT, null, null, null, 0l, 0l);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int describeContents() {
|
public int describeContents() {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -306,8 +306,7 @@ public class ImportKeysActivity extends BaseNfcActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* loads the CloudFragment, which consists of the search bar, search button and settings icon
|
* loads the CloudFragment, which consists of the search bar, search button and settings icon.
|
||||||
* visually.
|
|
||||||
*
|
*
|
||||||
* @param savedInstanceState
|
* @param savedInstanceState
|
||||||
* @param query search query
|
* @param query search query
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2015 Dominik Schürmann <dominik@dominikschuermann.de>
|
||||||
|
* Copyright (C) 2015 Adithya Abraham Philip <adithyaphilip@gmail.com>
|
||||||
|
*
|
||||||
|
* 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.ui;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.support.v4.app.FragmentActivity;
|
||||||
|
import org.sufficientlysecure.keychain.R;
|
||||||
|
import org.sufficientlysecure.keychain.util.Preferences;
|
||||||
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simply encapsulates a dialog. If orbot is not installed, it shows an install dialog, else a dialog to enable orbot.
|
||||||
|
*/
|
||||||
|
public class OrbotRequiredDialogActivity extends FragmentActivity {
|
||||||
|
|
||||||
|
public final static String RESULT_IGNORE_TOR = "ignore_tor";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
|
Runnable ignoreTor = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
Intent data = new Intent();
|
||||||
|
data.putExtra(RESULT_IGNORE_TOR, true);
|
||||||
|
setResult(RESULT_OK, data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (OrbotHelper.isOrbotInRequiredState(R.string.orbot_ignore_tor, ignoreTor,
|
||||||
|
Preferences.getPreferences(this).getProxyPrefs(), this)) {
|
||||||
|
Intent data = new Intent();
|
||||||
|
data.putExtra(RESULT_IGNORE_TOR, false);
|
||||||
|
setResult(RESULT_OK, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -36,8 +36,10 @@ import org.sufficientlysecure.keychain.service.ServiceProgressHandler;
|
|||||||
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
import org.sufficientlysecure.keychain.service.input.CryptoInputParcel;
|
||||||
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
import org.sufficientlysecure.keychain.service.input.RequiredInputParcel;
|
||||||
import org.sufficientlysecure.keychain.ui.NfcOperationActivity;
|
import org.sufficientlysecure.keychain.ui.NfcOperationActivity;
|
||||||
|
import org.sufficientlysecure.keychain.ui.OrbotRequiredDialogActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
import org.sufficientlysecure.keychain.ui.PassphraseDialogActivity;
|
||||||
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
import org.sufficientlysecure.keychain.ui.dialog.ProgressDialogFragment;
|
||||||
|
import org.sufficientlysecure.keychain.util.orbot.OrbotHelper;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -48,6 +50,7 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
|
|||||||
|
|
||||||
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
public static final int REQUEST_CODE_PASSPHRASE = 0x00008001;
|
||||||
public static final int REQUEST_CODE_NFC = 0x00008002;
|
public static final int REQUEST_CODE_NFC = 0x00008002;
|
||||||
|
public static final int REQUEST_ENABLE_ORBOT = 0x00008004;
|
||||||
|
|
||||||
private void initiateInputActivity(RequiredInputParcel requiredInput) {
|
private void initiateInputActivity(RequiredInputParcel requiredInput) {
|
||||||
|
|
||||||
@ -68,6 +71,12 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
|
|||||||
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
|
startActivityForResult(intent, REQUEST_CODE_PASSPHRASE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ENABLE_ORBOT: {
|
||||||
|
Intent intent = new Intent(getActivity(), OrbotRequiredDialogActivity.class);
|
||||||
|
startActivityForResult(intent, REQUEST_ENABLE_ORBOT);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new RuntimeException("Unhandled pending result!");
|
throw new RuntimeException("Unhandled pending result!");
|
||||||
@ -101,6 +110,14 @@ public abstract class CryptoOperationFragment <T extends Parcelable, S extends O
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case REQUEST_ENABLE_ORBOT: {
|
||||||
|
if (resultCode == Activity.RESULT_OK && data != null) {
|
||||||
|
if (data.getBooleanExtra(OrbotRequiredDialogActivity.RESULT_IGNORE_TOR, false)) {
|
||||||
|
cryptoOperation(new CryptoInputParcel());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
default: {
|
default: {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
@ -84,6 +84,10 @@ public class OrbotHelper {
|
|||||||
return isAppInstalled(ORBOT_PACKAGE_NAME, context);
|
return isAppInstalled(ORBOT_PACKAGE_NAME, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isOrbotInstalledAndRunning(Context context) {
|
||||||
|
return isOrbotRunning() && isOrbotInstalled(context);
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isAppInstalled(String uri, Context context) {
|
private static boolean isAppInstalled(String uri, Context context) {
|
||||||
PackageManager pm = context.getPackageManager();
|
PackageManager pm = context.getPackageManager();
|
||||||
|
|
||||||
@ -172,4 +176,15 @@ public class OrbotHelper {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: PHILIP return an Intent to required dialog activity
|
||||||
|
public static Intent getRequiredIntent(Context context) {
|
||||||
|
if (!isOrbotInstalled(context)) {
|
||||||
|
|
||||||
|
}
|
||||||
|
if (!isOrbotRunning()) {
|
||||||
|
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user