Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
45fc2b45
Commit
45fc2b45
authored
Dec 17, 2012
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add auto start option
parent
17ae4653
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
124 additions
and
77 deletions
+124
-77
AndroidManifest.xml
AndroidManifest.xml
+9
-2
assets/local.js
assets/local.js
+5
-5
pom.xml
pom.xml
+1
-1
res/xml/shadowsocks_preference.xml
res/xml/shadowsocks_preference.xml
+15
-1
src/com/github/shadowsocks/Shadowsocks.java
src/com/github/shadowsocks/Shadowsocks.java
+3
-61
src/com/github/shadowsocks/ShadowsocksReceiver.java
src/com/github/shadowsocks/ShadowsocksReceiver.java
+47
-0
src/com/github/shadowsocks/ShadowsocksService.java
src/com/github/shadowsocks/ShadowsocksService.java
+44
-7
No files found.
AndroidManifest.xml
View file @
45fc2b45
...
@@ -2,12 +2,13 @@
...
@@ -2,12 +2,13 @@
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
package=
"com.github.shadowsocks"
package=
"com.github.shadowsocks"
android:installLocation=
"auto"
android:installLocation=
"auto"
android:versionCode=
"
3
"
android:versionCode=
"
4
"
android:versionName=
"1.
0.2
"
>
android:versionName=
"1.
1
"
>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name=
"android.permission.ACCESS_NETWORK_STATE"
/>
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<uses-permission
android:name=
"android.permission.WAKE_LOCK"
/>
<uses-permission
android:name=
"android.permission.RECEIVE_BOOT_COMPLETED"
/>
<uses-feature
<uses-feature
android:name=
"android.hardware.touchscreen"
android:name=
"android.hardware.touchscreen"
...
@@ -41,6 +42,12 @@
...
@@ -41,6 +42,12 @@
android:name=
".ShadowsocksService"
android:name=
".ShadowsocksService"
android:enabled=
"true"
/>
android:enabled=
"true"
/>
<receiver
android:name=
".ShadowsocksReceiver"
>
<intent-filter>
<action
android:name=
"android.intent.action.BOOT_COMPLETED"
/>
</intent-filter>
</receiver>
</application>
</application>
</manifest>
</manifest>
assets/local.js
View file @
45fc2b45
...
@@ -164,6 +164,11 @@
...
@@ -164,6 +164,11 @@
console
.
log
=
function
()
{};
console
.
log
=
function
()
{};
var
pid
=
""
+
process
.
pid
;
// need to turn into a string
fs
.
writeFile
(
'
/data/data/com.github.shadowsocks/shadowsocks.pid
'
,
pid
,
function
(
err
)
{
// Ignore
});
console
.
log
(
"
calculating ciphers
"
);
console
.
log
(
"
calculating ciphers
"
);
tables
=
getTable
(
KEY
);
tables
=
getTable
(
KEY
);
...
@@ -332,11 +337,6 @@
...
@@ -332,11 +337,6 @@
});
});
});
});
var
pid
=
""
+
process
.
pid
;
// need to turn into a string
fs
.
writeFile
(
'
/data/data/com.github.shadowsocks/shadowsocks.pid
'
,
pid
,
function
(
err
)
{
// Ignore
});
server
.
listen
(
PORT
,
function
()
{
server
.
listen
(
PORT
,
function
()
{
return
console
.
log
(
"
server listening at port
"
+
PORT
);
return
console
.
log
(
"
server listening at port
"
+
PORT
);
});
});
...
...
pom.xml
View file @
45fc2b45
...
@@ -4,7 +4,7 @@
...
@@ -4,7 +4,7 @@
<modelVersion>
4.0.0
</modelVersion>
<modelVersion>
4.0.0
</modelVersion>
<groupId>
com.github.shadowsocks
</groupId>
<groupId>
com.github.shadowsocks
</groupId>
<artifactId>
shadowsocks
</artifactId>
<artifactId>
shadowsocks
</artifactId>
<version>
1.
0.2
</version>
<version>
1.
1
</version>
<packaging>
apk
</packaging>
<packaging>
apk
</packaging>
<name>
Shadowsocks
</name>
<name>
Shadowsocks
</name>
...
...
res/xml/shadowsocks_preference.xml
View file @
45fc2b45
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
<PreferenceCategory
android:title=
"@string/function_cat"
>
<PreferenceCategory
android:title=
"@string/function_cat"
>
<CheckBoxPreference
<CheckBoxPreference
android:key=
"isRunning"
android:key=
"isRunning"
android:disableDependentsState=
"true"
android:summary=
"@string/service_summary"
android:summary=
"@string/service_summary"
android:title=
"@string/service_controller"
>
android:title=
"@string/service_controller"
>
</CheckBoxPreference>
</CheckBoxPreference>
...
@@ -11,24 +12,28 @@
...
@@ -11,24 +12,28 @@
</PreferenceCategory>
</PreferenceCategory>
<PreferenceCategory
android:title=
"@string/proxy_cat"
>
<PreferenceCategory
android:title=
"@string/proxy_cat"
>
<EditTextPreference
<EditTextPreference
android:dependency=
"isRunning"
android:defaultValue=
"127.0.0.1"
android:defaultValue=
"127.0.0.1"
android:key=
"proxy"
android:key=
"proxy"
android:summary=
"@string/proxy_summary"
android:summary=
"@string/proxy_summary"
android:title=
"@string/proxy"
>
android:title=
"@string/proxy"
>
</EditTextPreference>
</EditTextPreference>
<EditTextPreference
<EditTextPreference
android:dependency=
"isRunning"
android:defaultValue=
"1984"
android:defaultValue=
"1984"
android:key=
"remotePort"
android:key=
"remotePort"
android:summary=
"@string/remote_port_summary"
android:summary=
"@string/remote_port_summary"
android:title=
"@string/remote_port"
>
android:title=
"@string/remote_port"
>
</EditTextPreference>
</EditTextPreference>
<EditTextPreference
<EditTextPreference
android:dependency=
"isRunning"
android:defaultValue=
"1080"
android:defaultValue=
"1080"
android:key=
"port"
android:key=
"port"
android:summary=
"@string/port_summary"
android:summary=
"@string/port_summary"
android:title=
"@string/port"
>
android:title=
"@string/port"
>
</EditTextPreference>
</EditTextPreference>
<EditTextPreference
<EditTextPreference
android:dependency=
"isRunning"
android:defaultValue=
""
android:defaultValue=
""
android:key=
"sitekey"
android:key=
"sitekey"
android:summary=
"@string/sitekey_summary"
android:summary=
"@string/sitekey_summary"
...
@@ -37,29 +42,38 @@
...
@@ -37,29 +42,38 @@
</PreferenceCategory>
</PreferenceCategory>
<PreferenceCategory
android:title=
"@string/fearute_cat"
>
<PreferenceCategory
android:title=
"@string/fearute_cat"
>
<CheckBoxPreference
<CheckBoxPreference
android:dependency=
"isRunning"
android:defaultValue=
"true"
android:defaultValue=
"true"
android:key=
"isGFWList"
android:key=
"isGFWList"
android:summary=
"@string/auto_set_gfwlist_summary"
android:summary=
"@string/auto_set_gfwlist_summary"
android:title=
"@string/auto_set_gfwlist"
>
android:title=
"@string/auto_set_gfwlist"
>
</CheckBoxPreference>
</CheckBoxPreference>
<CheckBoxPreference
<CheckBoxPreference
android:dependency=
"isRunning"
android:defaultValue=
"true"
android:defaultValue=
"true"
android:key=
"isGlobalProxy"
android:key=
"isGlobalProxy"
android:summary=
"@string/auto_set_proxy_summary"
android:summary=
"@string/auto_set_proxy_summary"
android:title=
"@string/auto_set_proxy"
>
android:title=
"@string/auto_set_proxy"
>
</CheckBoxPreference>
</CheckBoxPreference>
<CheckBoxPreference
<CheckBoxPreference
android:dependency=
"isRunning"
android:defaultValue=
"false"
android:defaultValue=
"false"
android:key=
"isBypassApps"
android:key=
"isBypassApps"
android:summary=
"@string/bypass_apps_summary"
android:summary=
"@string/bypass_apps_summary"
android:title=
"@string/bypass_apps"
>
android:title=
"@string/bypass_apps"
>
</CheckBoxPreference>
</CheckBoxPreference>
<Preference
<Preference
android:dependency=
"isRunning"
android:key=
"proxyedApps"
android:key=
"proxyedApps"
android:summary=
"@string/proxyed_apps_summary"
android:summary=
"@string/proxyed_apps_summary"
android:title=
"@string/proxyed_apps"
>
android:title=
"@string/proxyed_apps"
>
</Preference>
</Preference>
<CheckBoxPreference
android:dependency=
"isRunning"
android:key=
"isAutoConnect"
android:summary=
"@string/auto_connect_summary"
android:title=
"@string/auto_connect"
>
</CheckBoxPreference>
</PreferenceCategory>
</PreferenceCategory>
...
...
src/com/github/shadowsocks/Shadowsocks.java
View file @
45fc2b45
...
@@ -103,13 +103,10 @@ public class Shadowsocks extends PreferenceActivity implements
...
@@ -103,13 +103,10 @@ public class Shadowsocks extends PreferenceActivity implements
private
static
ProgressDialog
mProgressDialog
=
null
;
private
static
ProgressDialog
mProgressDialog
=
null
;
private
CheckBoxPreference
isGlobalProxyCheck
;
private
EditTextPreference
proxyText
;
private
EditTextPreference
proxyText
;
private
EditTextPreference
portText
;
private
EditTextPreference
portText
;
private
EditTextPreference
remotePortText
;
private
EditTextPreference
remotePortText
;
private
EditTextPreference
sitekeyText
;
private
EditTextPreference
sitekeyText
;
private
CheckBoxPreference
isGFWListCheck
;
private
CheckBoxPreference
isRunningCheck
;
private
Preference
proxyedApps
;
private
Preference
proxyedApps
;
private
CheckBoxPreference
isBypassAppsCheck
;
private
CheckBoxPreference
isBypassAppsCheck
;
...
@@ -159,32 +156,6 @@ public class Shadowsocks extends PreferenceActivity implements
...
@@ -159,32 +156,6 @@ public class Shadowsocks extends PreferenceActivity implements
}
}
private
void
disableAll
()
{
proxyText
.
setEnabled
(
false
);
portText
.
setEnabled
(
false
);
remotePortText
.
setEnabled
(
false
);
sitekeyText
.
setEnabled
(
false
);
proxyedApps
.
setEnabled
(
false
);
isGFWListCheck
.
setEnabled
(
false
);
isBypassAppsCheck
.
setEnabled
(
false
);
isGlobalProxyCheck
.
setEnabled
(
false
);
}
private
void
enableAll
()
{
proxyText
.
setEnabled
(
true
);
portText
.
setEnabled
(
true
);
remotePortText
.
setEnabled
(
true
);
sitekeyText
.
setEnabled
(
true
);
isGlobalProxyCheck
.
setEnabled
(
true
);
isGFWListCheck
.
setEnabled
(
true
);
if
(!
isGlobalProxyCheck
.
isChecked
())
{
proxyedApps
.
setEnabled
(
true
);
isBypassAppsCheck
.
setEnabled
(
true
);
}
}
private
boolean
isTextEmpty
(
String
s
,
String
msg
)
{
private
boolean
isTextEmpty
(
String
s
,
String
msg
)
{
if
(
s
==
null
||
s
.
length
()
<=
0
)
{
if
(
s
==
null
||
s
.
length
()
<=
0
)
{
showAToast
(
msg
);
showAToast
(
msg
);
...
@@ -208,9 +179,6 @@ public class Shadowsocks extends PreferenceActivity implements
...
@@ -208,9 +179,6 @@ public class Shadowsocks extends PreferenceActivity implements
sitekeyText
=
(
EditTextPreference
)
findPreference
(
"sitekey"
);
sitekeyText
=
(
EditTextPreference
)
findPreference
(
"sitekey"
);
proxyedApps
=
findPreference
(
"proxyedApps"
);
proxyedApps
=
findPreference
(
"proxyedApps"
);
isRunningCheck
=
(
CheckBoxPreference
)
findPreference
(
"isRunning"
);
isGlobalProxyCheck
=
(
CheckBoxPreference
)
findPreference
(
"isGlobalProxy"
);
isGFWListCheck
=
(
CheckBoxPreference
)
findPreference
(
"isGFWList"
);
isBypassAppsCheck
=
(
CheckBoxPreference
)
findPreference
(
"isBypassApps"
);
isBypassAppsCheck
=
(
CheckBoxPreference
)
findPreference
(
"isBypassApps"
);
if
(
mProgressDialog
==
null
)
if
(
mProgressDialog
==
null
)
...
@@ -350,23 +318,14 @@ public class Shadowsocks extends PreferenceActivity implements
...
@@ -350,23 +318,14 @@ public class Shadowsocks extends PreferenceActivity implements
SharedPreferences
settings
=
PreferenceManager
SharedPreferences
settings
=
PreferenceManager
.
getDefaultSharedPreferences
(
this
);
.
getDefaultSharedPreferences
(
this
);
if
(
settings
.
getBoolean
(
"isSystemProxy"
,
false
))
{
if
(
settings
.
getBoolean
(
"isGlobalProxy"
,
false
))
{
isGlobalProxyCheck
.
setEnabled
(
false
);
isGFWListCheck
.
setEnabled
(
false
);
proxyedApps
.
setEnabled
(
false
);
proxyedApps
.
setEnabled
(
false
);
isBypassAppsCheck
.
setEnabled
(
false
);
isBypassAppsCheck
.
setEnabled
(
false
);
}
else
{
}
else
{
if
(
settings
.
getBoolean
(
"isGlobalProxy"
,
false
))
{
proxyedApps
.
setEnabled
(
true
);
proxyedApps
.
setEnabled
(
false
);
isBypassAppsCheck
.
setEnabled
(
true
);
isBypassAppsCheck
.
setEnabled
(
false
);
}
else
{
proxyedApps
.
setEnabled
(
true
);
isBypassAppsCheck
.
setEnabled
(
true
);
}
}
}
sitekeyText
.
setEnabled
(
true
);
Editor
edit
=
settings
.
edit
();
Editor
edit
=
settings
.
edit
();
if
(
ShadowsocksService
.
isServiceStarted
())
{
if
(
ShadowsocksService
.
isServiceStarted
())
{
...
@@ -386,14 +345,6 @@ public class Shadowsocks extends PreferenceActivity implements
...
@@ -386,14 +345,6 @@ public class Shadowsocks extends PreferenceActivity implements
edit
.
commit
();
edit
.
commit
();
if
(
settings
.
getBoolean
(
"isRunning"
,
false
))
{
isRunningCheck
.
setChecked
(
true
);
disableAll
();
}
else
{
isRunningCheck
.
setChecked
(
false
);
enableAll
();
}
// Setup the initial values
// Setup the initial values
if
(!
settings
.
getString
(
"sitekey"
,
""
).
equals
(
""
))
if
(!
settings
.
getString
(
"sitekey"
,
""
).
equals
(
""
))
...
@@ -448,15 +399,6 @@ public class Shadowsocks extends PreferenceActivity implements
...
@@ -448,15 +399,6 @@ public class Shadowsocks extends PreferenceActivity implements
}
}
}
}
if
(
key
.
equals
(
"isRunning"
))
{
if
(
settings
.
getBoolean
(
"isRunning"
,
false
))
{
disableAll
();
isRunningCheck
.
setChecked
(
true
);
}
else
{
isRunningCheck
.
setChecked
(
false
);
enableAll
();
}
}
if
(
key
.
equals
(
"remotePort"
))
if
(
key
.
equals
(
"remotePort"
))
if
(
settings
.
getString
(
"remotePort"
,
""
).
equals
(
""
))
if
(
settings
.
getString
(
"remotePort"
,
""
).
equals
(
""
))
...
...
src/com/github/shadowsocks/ShadowsocksReceiver.java
0 → 100644
View file @
45fc2b45
package
com.github.shadowsocks
;
import
android.content.BroadcastReceiver
;
import
android.content.Context
;
import
android.content.Intent
;
import
android.content.SharedPreferences
;
import
android.content.pm.PackageManager
;
import
android.preference.PreferenceManager
;
public
class
ShadowsocksReceiver
extends
BroadcastReceiver
{
private
static
final
String
TAG
=
"Shadowsocks"
;
@Override
public
void
onReceive
(
Context
context
,
Intent
intent
)
{
SharedPreferences
settings
=
PreferenceManager
.
getDefaultSharedPreferences
(
context
);
String
versionName
;
try
{
versionName
=
context
.
getPackageManager
().
getPackageInfo
(
context
.
getPackageName
(),
0
).
versionName
;
}
catch
(
PackageManager
.
NameNotFoundException
e
)
{
versionName
=
"NONE"
;
}
final
boolean
isAutoConnect
=
settings
.
getBoolean
(
"isAutoConnect"
,
false
);
final
boolean
isInstalled
=
settings
.
getBoolean
(
versionName
,
false
);
if
(
isAutoConnect
&&
isInstalled
)
{
final
String
portText
=
settings
.
getString
(
"port"
,
""
);
if
(
portText
==
null
||
portText
.
length
()
<=
0
)
{
return
;
}
try
{
int
port
=
Integer
.
valueOf
(
portText
);
if
(
port
<=
1024
)
{
return
;
}
}
catch
(
Exception
e
)
{
return
;
}
Intent
it
=
new
Intent
(
context
,
ShadowsocksService
.
class
);
context
.
startService
(
it
);
}
}
}
src/com/github/shadowsocks/ShadowsocksService.java
View file @
45fc2b45
...
@@ -56,8 +56,7 @@ import android.preference.PreferenceManager;
...
@@ -56,8 +56,7 @@ import android.preference.PreferenceManager;
import
android.util.Log
;
import
android.util.Log
;
import
com.google.analytics.tracking.android.EasyTracker
;
import
com.google.analytics.tracking.android.EasyTracker
;
import
java.io.DataOutputStream
;
import
java.io.*
;
import
java.io.IOException
;
import
java.lang.ref.WeakReference
;
import
java.lang.ref.WeakReference
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
...
@@ -183,7 +182,22 @@ public class ShadowsocksService extends Service {
...
@@ -183,7 +182,22 @@ public class ShadowsocksService extends Service {
return
isServiceStarted
;
return
isServiceStarted
;
}
}
public
void
startShadowsocksDaemon
()
{
private
int
getPid
(
String
name
)
{
try
{
BufferedReader
reader
=
new
BufferedReader
(
new
FileReader
(
BASE
+
name
+
".pid"
));
final
String
line
=
reader
.
readLine
();
return
Integer
.
valueOf
(
line
);
}
catch
(
FileNotFoundException
e
)
{
Log
.
e
(
TAG
,
"Cannot open pid file: "
+
name
);
}
catch
(
IOException
e
)
{
Log
.
e
(
TAG
,
"Cannot read pid file: "
+
name
);
}
catch
(
NumberFormatException
e
)
{
Log
.
e
(
TAG
,
"Invalid pid"
,
e
);
}
return
-
1
;
}
private
void
startShadowsocksDaemon
()
{
new
Thread
()
{
new
Thread
()
{
@Override
@Override
public
void
run
()
{
public
void
run
()
{
...
@@ -195,9 +209,9 @@ public class ShadowsocksService extends Service {
...
@@ -195,9 +209,9 @@ public class ShadowsocksService extends Service {
}.
start
();
}.
start
();
}
}
p
ublic
void
startDnsDaemon
()
{
p
rivate
void
startDnsDaemon
()
{
final
String
cmd
=
BASE
+
"pdnsd -c "
+
BASE
+
"pdnsd.conf"
;
final
String
cmd
=
BASE
+
"pdnsd -c "
+
BASE
+
"pdnsd.conf"
;
Utils
.
run
Root
Command
(
cmd
);
Utils
.
runCommand
(
cmd
);
}
}
private
String
getVersionName
()
{
private
String
getVersionName
()
{
...
@@ -277,7 +291,26 @@ public class ShadowsocksService extends Service {
...
@@ -277,7 +291,26 @@ public class ShadowsocksService extends Service {
BASE
,
BASE
,
BASE
);
BASE
,
BASE
,
BASE
);
Utils
.
runRootCommand
(
"echo \""
+
conf
+
"\" > "
+
BASE
+
"redsocks.conf\n"
Utils
.
runRootCommand
(
"echo \""
+
conf
+
"\" > "
+
BASE
+
"redsocks.conf\n"
+
cmd
);
+
cmd
);
}
private
boolean
waitForProcess
(
final
String
name
)
{
final
int
pid
=
getPid
(
name
);
if
(
pid
==
-
1
)
return
false
;
Exec
.
hangupProcessGroup
(-
pid
);
Thread
t
=
new
Thread
()
{
@Override
public
void
run
()
{
Exec
.
waitFor
(-
pid
);
Log
.
d
(
TAG
,
"Successfully exit pid: "
+
pid
);
}
};
t
.
start
();
try
{
t
.
join
(
300
);
}
catch
(
InterruptedException
ignored
)
{
}
return
!
t
.
isAlive
();
}
}
/**
/**
...
@@ -436,9 +469,13 @@ public class ShadowsocksService extends Service {
...
@@ -436,9 +469,13 @@ public class ShadowsocksService extends Service {
private
void
onDisconnect
()
{
private
void
onDisconnect
()
{
Utils
.
runRootCommand
(
Utils
.
getIptables
()
+
" -t nat -F OUTPUT"
);
Utils
.
runRootCommand
(
Utils
.
getIptables
()
+
" -t nat -F OUTPUT"
);
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
sb
.
append
(
"kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`"
).
append
(
"\n"
);
sb
.
append
(
"kill -9 `cat /data/data/com.github.shadowsocks/redsocks.pid`"
).
append
(
"\n"
);
sb
.
append
(
"kill -9 `cat /data/data/com.github.shadowsocks/redsocks.pid`"
).
append
(
"\n"
);
sb
.
append
(
"kill -9 `cat /data/data/com.github.shadowsocks/shadowsocks.pid`"
).
append
(
"\n"
);
if
(!
waitForProcess
(
"pdnsd"
))
{
sb
.
append
(
"kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`"
).
append
(
"\n"
);
}
if
(!
waitForProcess
(
"shadowsocks"
))
{
sb
.
append
(
"kill -9 `cat /data/data/com.github.shadowsocks/shadowsocks.pid`"
).
append
(
"\n"
);
}
Utils
.
runRootCommand
(
sb
.
toString
());
Utils
.
runRootCommand
(
sb
.
toString
());
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment