diff options
author | Adithya Abraham Philip <adithyaphilip@gmail.com> | 2015-06-07 02:19:03 +0530 |
---|---|---|
committer | Adithya Abraham Philip <adithyaphilip@gmail.com> | 2015-07-03 20:46:15 +0530 |
commit | 007d02f01b1381d218a248a377e186b4549a5e0e (patch) | |
tree | 7231d735cf25cd9883557307f43e422551a43d0b /OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java | |
parent | a6cb330dafa5fccdd92376502cb6624b9dc72df6 (diff) | |
download | open-keychain-007d02f01b1381d218a248a377e186b4549a5e0e.tar.gz open-keychain-007d02f01b1381d218a248a377e186b4549a5e0e.tar.bz2 open-keychain-007d02f01b1381d218a248a377e186b4549a5e0e.zip |
added proxy support, silent right now
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java')
-rw-r--r-- | OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java new file mode 100644 index 000000000..a24141a69 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/util/ParcelableProxy.java @@ -0,0 +1,98 @@ +/* + * Copyright (C) 2014 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.util; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.net.InetSocketAddress; +import java.net.Proxy; + +/** + * used to simply transport java.net.Proxy objects created using InetSockets between services/activities + */ +public class ParcelableProxy implements Parcelable { + private String mProxyHost; + private int mProxyPort; + private int mProxyType; + + private final int TYPE_HTTP = 1; + private final int TYPE_SOCKS = 2; + + public ParcelableProxy(Proxy proxy) { + InetSocketAddress address = (InetSocketAddress) proxy.address(); + + mProxyHost = address.getHostName(); + mProxyPort = address.getPort(); + + switch (proxy.type()) { + case HTTP: { + mProxyType = TYPE_HTTP; + break; + } + case SOCKS: { + mProxyType = TYPE_SOCKS; + break; + } + } + } + + public Proxy getProxy() { + Proxy.Type type = null; + switch (mProxyType) { + case TYPE_HTTP: + type = Proxy.Type.HTTP; + break; + case TYPE_SOCKS: + type = Proxy.Type.SOCKS; + break; + } + return new Proxy(type, new InetSocketAddress(mProxyHost, mProxyPort)); + } + + protected ParcelableProxy(Parcel in) { + mProxyHost = in.readString(); + mProxyPort = in.readInt(); + mProxyType = in.readInt(); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(mProxyHost); + dest.writeInt(mProxyPort); + dest.writeInt(mProxyType); + } + + @SuppressWarnings("unused") + public static final Parcelable.Creator<ParcelableProxy> CREATOR = new Parcelable.Creator<ParcelableProxy>() { + @Override + public ParcelableProxy createFromParcel(Parcel in) { + return new ParcelableProxy(in); + } + + @Override + public ParcelableProxy[] newArray(int size) { + return new ParcelableProxy[size]; + } + }; +} |