-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vijay Rawat
committed
Jun 26, 2015
0 parents
commit 2c989fe
Showing
34 changed files
with
769 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.gradle | ||
/local.properties | ||
/.idea/workspace.xml | ||
/.idea/libraries | ||
.DS_Store | ||
/build | ||
/captures | ||
/.idea | ||
.DS_Store | ||
/build | ||
app/build | ||
easyproxy/build | ||
*.iml | ||
*.ipr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:1.2.3' | ||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
apply plugin: 'com.android.library' | ||
|
||
android { | ||
compileSdkVersion 22 | ||
buildToolsVersion "22.0.1" | ||
|
||
defaultConfig { | ||
minSdkVersion 9 | ||
targetSdkVersion 22 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/vijay.rawat01/android-sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
13 changes: 13 additions & 0 deletions
13
easyproxy/src/androidTest/java/com/vijayrawatsan/easyproxy/ApplicationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.vijayrawatsan.easyproxy; | ||
|
||
import android.app.Application; | ||
import android.test.ApplicationTestCase; | ||
|
||
/** | ||
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a> | ||
*/ | ||
public class ApplicationTest extends ApplicationTestCase<Application> { | ||
public ApplicationTest() { | ||
super(Application.class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.vijayrawatsan.easyproxy"> | ||
</manifest> |
127 changes: 127 additions & 0 deletions
127
easyproxy/src/main/java/com/vijayrawatsan/easyproxy/EasyProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package com.vijayrawatsan.easyproxy; | ||
|
||
import android.util.Log; | ||
|
||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.Proxy; | ||
import java.net.ProxySelector; | ||
import java.net.SocketAddress; | ||
import java.net.URI; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Created by vijay.rawat01 on 6/26/15. | ||
*/ | ||
public class EasyProxy { | ||
|
||
private static final String TAG = "EASY_PROXY"; | ||
private static final String HTTP = "http"; | ||
private static final String SOCKS = "socket"; | ||
private static boolean sLogEnabled; | ||
private static Map<String, ProxyInfo> sUrlToProxyInfoMap = new HashMap<>(); | ||
private static Set<String> sExcludeSet = new HashSet<>(); | ||
private static Set<UrlProxyInfo> sIncludeSet = new HashSet<>(); | ||
private static ProxyInfo sDefaultProxy; | ||
|
||
public static void init(ProxyInfo defaultProxy) { | ||
init(defaultProxy, false); | ||
} | ||
|
||
public static void init(ProxyInfo defaultProxy, boolean isLogEnabled) { | ||
init(defaultProxy, null, isLogEnabled); | ||
} | ||
|
||
public static void init(ProxyInfo defaultProxy, Set<String> exclude, boolean isLogEnabled) { | ||
init(defaultProxy, exclude, null, isLogEnabled); | ||
} | ||
|
||
public static void init(ProxyInfo defaultProxy, Set<String> exclude, Set<UrlProxyInfo> include, boolean isLogEnabled) { | ||
sLogEnabled = isLogEnabled; | ||
if(exclude != null) { | ||
sExcludeSet = exclude; | ||
} | ||
if(include != null) { | ||
sIncludeSet = include; | ||
} | ||
sDefaultProxy = defaultProxy; | ||
ProxySelector.setDefault(new CustomProxySelector(ProxySelector.getDefault())); | ||
} | ||
|
||
static class CustomProxySelector extends ProxySelector { | ||
private final ProxySelector mDefaultProxySelector; | ||
|
||
public CustomProxySelector(ProxySelector defaultProxySelector) { | ||
this.mDefaultProxySelector = defaultProxySelector; | ||
} | ||
|
||
@Override | ||
public List<Proxy> select(URI uri) { | ||
if (HTTP.equalsIgnoreCase(uri.getScheme()) || SOCKS.equalsIgnoreCase(uri.getScheme())) { | ||
if(isInExcludedSet(uri.toASCIIString())) { | ||
if (isLogEnabled()) { | ||
Log.d(TAG, "Found in excludedSet. Returning default proxy for url : " + uri); | ||
} | ||
if(sDefaultProxy == null) { | ||
return mDefaultProxySelector.select(uri); | ||
} | ||
return Arrays.asList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(sDefaultProxy.getHost(), sDefaultProxy.getPort()))); | ||
} | ||
ProxyInfo proxyForUrl = getProxyForUrl(uri.toASCIIString()); | ||
if(proxyForUrl != null) { | ||
if (isLogEnabled()) { | ||
Log.d(TAG, "Found in includeSet. Returning proxy (" + proxyForUrl.getHost() + ", " + proxyForUrl.getPort() + ") for url : " + uri); | ||
} | ||
return Arrays.asList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyForUrl.getHost(), proxyForUrl.getPort()))); | ||
} | ||
} | ||
if (isLogEnabled()) { | ||
Log.d(TAG, "Not found anywhere. Returning default proxy (which is none generally)."); | ||
} | ||
if(sDefaultProxy == null) { | ||
return mDefaultProxySelector.select(uri); | ||
} | ||
return Arrays.asList(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(sDefaultProxy.getHost(), sDefaultProxy.getPort()))); | ||
} | ||
|
||
@Override | ||
public void connectFailed(URI uri, SocketAddress socketAddress, IOException e) { | ||
//Using DefaultProxySelector Implementation | ||
if (uri == null || socketAddress == null || e == null) { | ||
throw new IllegalArgumentException("Arguments can\'t be null."); | ||
} | ||
} | ||
|
||
private boolean isInExcludedSet(String url) { | ||
for(String regex : sExcludeSet) { | ||
if(url.matches(regex)) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
private ProxyInfo getProxyForUrl(String url) { | ||
ProxyInfo proxyInfo = sUrlToProxyInfoMap.get(url); | ||
if(proxyInfo != null) { | ||
return proxyInfo; | ||
} | ||
for(UrlProxyInfo urlProxyInfo: sIncludeSet) { | ||
if(url.matches(urlProxyInfo.getRegex())) { | ||
sUrlToProxyInfoMap.put(url, urlProxyInfo.getProxyInfo()); | ||
return urlProxyInfo.getProxyInfo(); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
public static boolean isLogEnabled() { | ||
return sLogEnabled; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
easyproxy/src/main/java/com/vijayrawatsan/easyproxy/ProxyInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.vijayrawatsan.easyproxy; | ||
|
||
/** | ||
* Created by vijay.rawat01 on 6/26/15. | ||
*/ | ||
public class ProxyInfo { | ||
private String host; | ||
private int port; | ||
|
||
public ProxyInfo(String host, int port) { | ||
this.host = host; | ||
this.port = port; | ||
} | ||
|
||
public String getHost() { | ||
return host; | ||
} | ||
|
||
public int getPort() { | ||
return port; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ProxyInfo{" + | ||
"host='" + host + '\'' + | ||
", port=" + port + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (!(o instanceof ProxyInfo)) return false; | ||
|
||
ProxyInfo proxyInfo = (ProxyInfo) o; | ||
|
||
if (getPort() != proxyInfo.getPort()) return false; | ||
return getHost().equals(proxyInfo.getHost()); | ||
|
||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
int result = getHost().hashCode(); | ||
result = 31 * result + getPort(); | ||
return result; | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
easyproxy/src/main/java/com/vijayrawatsan/easyproxy/UrlProxyInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.vijayrawatsan.easyproxy; | ||
|
||
/** | ||
* Created by vijay.rawat01 on 6/26/15. | ||
*/ | ||
public class UrlProxyInfo { | ||
private String regex; | ||
private ProxyInfo proxyInfo; | ||
|
||
public UrlProxyInfo(String regex, ProxyInfo proxyInfo) { | ||
this.regex = regex; | ||
this.proxyInfo = proxyInfo; | ||
} | ||
|
||
public String getRegex() { | ||
return regex; | ||
} | ||
|
||
public void setRegex(String regex) { | ||
this.regex = regex; | ||
} | ||
|
||
public ProxyInfo getProxyInfo() { | ||
return proxyInfo; | ||
} | ||
|
||
public void setProxyInfo(ProxyInfo proxyInfo) { | ||
this.proxyInfo = proxyInfo; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "UrlProxyInfo{" + | ||
"regex='" + regex + '\'' + | ||
", proxyInfo=" + proxyInfo + | ||
'}'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<resources> | ||
<string name="app_name">EasyProxy</string> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Project-wide Gradle settings. | ||
|
||
# IDE (e.g. Android Studio) users: | ||
# Gradle settings configured through the IDE *will override* | ||
# any settings specified in this file. | ||
|
||
# For more details on how to configure your build environment visit | ||
# http://www.gradle.org/docs/current/userguide/build_environment.html | ||
|
||
# Specifies the JVM arguments used for the daemon process. | ||
# The setting is particularly useful for tweaking memory settings. | ||
# Default value: -Xmx10248m -XX:MaxPermSize=256m | ||
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 | ||
|
||
# When configured, Gradle will run in incubating parallel mode. | ||
# This option should only be used with decoupled projects. More details, visit | ||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects | ||
# org.gradle.parallel=true |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#Wed Apr 10 15:27:10 PDT 2013 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.2.1-all.zip |
Oops, something went wrong.