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
6acbae0c
Commit
6acbae0c
authored
Oct 12, 2016
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move copyAssets to BaseService
Fix #926.
parent
97d31cb9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
76 deletions
+50
-76
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+1
-0
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
+4
-71
src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala
...scala/com/github/shadowsocks/ShadowsocksApplication.scala
+45
-1
src/main/scala/com/github/shadowsocks/utils/Utils.scala
src/main/scala/com/github/shadowsocks/utils/Utils.scala
+0
-4
No files found.
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
6acbae0c
...
...
@@ -280,6 +280,7 @@ trait BaseService extends Service {
super
.
onCreate
()
FirebaseApp
.
initializeApp
(
this
)
app
.
refreshContainerHolder
app
.
updateAssets
()
}
// Service of shadowsocks should always be started explicitly
...
...
src/main/scala/com/github/shadowsocks/Shadowsocks.scala
View file @
6acbae0c
...
...
@@ -38,17 +38,14 @@
*/
package
com.github.shadowsocks
import
java.io.
{
FileOutputStream
,
IOException
,
InputStream
,
OutputStream
}
import
java.lang.System.currentTimeMillis
import
java.net.
{
HttpURLConnection
,
URL
}
import
java.util.Date
import
java.util.Hashtable
import
java.util.Locale
import
java.util
import
java.util.
{
Date
,
Locale
}
import
android.app.backup.BackupManager
import
android.app.
{
Activity
,
ProgressDialog
}
import
android.content._
import
android.content.res.AssetManager
import
android.graphics.Typeface
import
android.net.VpnService
import
android.os._
...
...
@@ -89,15 +86,13 @@ object Typefaces {
}
private
final
val
TAG
=
"Typefaces"
private
final
val
cache
=
new
Hashtable
[
String
,
Typeface
]
private
final
val
cache
=
new
util
.
Hashtable
[
String
,
Typeface
]
}
object
Shadowsocks
{
// Constants
private
final
val
TAG
=
"Shadowsocks"
private
final
val
REQUEST_CONNECT
=
1
private
val
EXECUTABLES
=
Array
(
Executable
.
PDNSD
,
Executable
.
REDSOCKS
,
Executable
.
SS_TUNNEL
,
Executable
.
SS_LOCAL
,
Executable
.
TUN2SOCKS
,
Executable
.
KCPTUN
)
}
class
Shadowsocks
extends
AppCompatActivity
with
ServiceBoundContext
{
...
...
@@ -187,14 +182,6 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
snackbar
.
setAction
(
R
.
string
.
switch_to_vpn
,
(
_
=>
preferences
.
natSwitch
.
setChecked
(
false
))
:
View.OnClickListener
)
snackbar
.
show
}
if
(
app
.
settings
.
getInt
(
Key
.
currentVersionCode
,
-
1
)
!=
BuildConfig
.
VERSION_CODE
)
{
app
.
editor
.
putInt
(
Key
.
currentVersionCode
,
BuildConfig
.
VERSION_CODE
).
apply
()
recovery
()
updateCurrentProfile
()
}
}
override
def
onServiceDisconnected
()
{
...
...
@@ -241,53 +228,6 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
}
}
private
def
copyAssets
(
path
:
String
)
{
val
assetManager
:
AssetManager
=
getAssets
var
files
:
Array
[
String
]
=
null
try
{
files
=
assetManager
.
list
(
path
)
}
catch
{
case
e
:
IOException
=>
Log
.
e
(
TAG
,
e
.
getMessage
)
app
.
track
(
e
)
}
if
(
files
!=
null
)
{
for
(
file
<-
files
)
{
var
in
:
InputStream
=
null
var
out
:
OutputStream
=
null
try
{
if
(
path
.
length
>
0
)
{
in
=
assetManager
.
open
(
path
+
"/"
+
file
)
}
else
{
in
=
assetManager
.
open
(
file
)
}
out
=
new
FileOutputStream
(
getApplicationInfo
.
dataDir
+
"/"
+
file
)
copyFile
(
in
,
out
)
in
.
close
()
in
=
null
out
.
flush
()
out
.
close
()
out
=
null
}
catch
{
case
ex
:
Exception
=>
Log
.
e
(
TAG
,
ex
.
getMessage
)
app
.
track
(
ex
)
}
}
}
}
private
def
copyFile
(
in
:
InputStream
,
out
:
OutputStream
)
{
val
buffer
:
Array
[
Byte
]
=
new
Array
[
Byte
](
1024
)
var
read
:
Int
=
0
while
(
{
read
=
in
.
read
(
buffer
)
read
}
!=
-
1
)
{
out
.
write
(
buffer
,
0
,
read
)
}
}
def
crashRecovery
()
{
val
cmd
=
new
ArrayBuffer
[
String
]()
...
...
@@ -526,14 +466,7 @@ class Shadowsocks extends AppCompatActivity with ServiceBoundContext {
def
reset
()
{
crashRecovery
()
copyAssets
(
System
.
getABI
)
copyAssets
(
"acl"
)
val
ab
=
new
ArrayBuffer
[
String
]
for
(
executable
<-
EXECUTABLES
)
{
ab
.
append
(
"chmod 755 "
+
getApplicationInfo
.
dataDir
+
"/"
+
executable
)
}
Shell
.
SH
.
run
(
ab
.
toArray
)
app
.
copyAssets
()
}
def
recovery
()
{
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksApplication.scala
View file @
6acbae0c
...
...
@@ -39,6 +39,7 @@
package
com.github.shadowsocks
import
java.io.
{
FileOutputStream
,
IOException
,
InputStream
,
OutputStream
}
import
java.util
import
java.util.Locale
import
java.util.concurrent.TimeUnit
...
...
@@ -51,16 +52,22 @@ import android.preference.PreferenceManager
import
android.support.v7.app.AppCompatDelegate
import
android.util.Log
import
com.github.shadowsocks.database.
{
DBHelper
,
ProfileManager
}
import
com.github.shadowsocks.utils.
{
Key
,
TcpFastOpen
,
Utils
}
import
com.github.shadowsocks.utils.CloseUtils._
import
com.github.shadowsocks.utils.
{
Executable
,
Key
,
TcpFastOpen
,
Utils
}
import
com.google.android.gms.analytics.
{
GoogleAnalytics
,
HitBuilders
,
StandardExceptionParser
}
import
com.google.android.gms.common.api.ResultCallback
import
com.google.android.gms.tagmanager.
{
ContainerHolder
,
TagManager
}
import
com.j256.ormlite.logger.LocalLog
import
eu.chainfire.libsuperuser.Shell
import
scala.collection.mutable.ArrayBuffer
object
ShadowsocksApplication
{
var
app
:
ShadowsocksApplication
=
_
private
final
val
TAG
=
"ShadowsocksApplication"
private
val
EXECUTABLES
=
Array
(
Executable
.
PDNSD
,
Executable
.
REDSOCKS
,
Executable
.
SS_TUNNEL
,
Executable
.
SS_LOCAL
,
Executable
.
TUN2SOCKS
,
Executable
.
KCPTUN
)
// The ones in Locale doesn't have script included
private
final
lazy
val
SIMPLIFIED_CHINESE
=
...
...
@@ -184,4 +191,41 @@ class ShadowsocksApplication extends Application {
val
holder
=
app
.
containerHolder
if
(
holder
!=
null
)
holder
.
refresh
()
}
private
def
copyStream
(
in
:
InputStream
,
out
:
OutputStream
)
{
val
buffer
=
new
Array
[
Byte
](
1024
)
while
(
true
)
{
val
count
=
in
.
read
(
buffer
)
if
(
count
<
0
)
return
else
out
.
write
(
buffer
,
0
,
count
)
}
}
private
def
copyAssets
(
path
:
String
)
{
val
assetManager
=
getAssets
var
files
:
Array
[
String
]
=
null
try
files
=
assetManager
.
list
(
path
)
catch
{
case
e
:
IOException
=>
Log
.
e
(
TAG
,
e
.
getMessage
)
app
.
track
(
e
)
}
if
(
files
!=
null
)
for
(
file
<-
files
)
autoClose
(
assetManager
.
open
(
if
(
path
.
nonEmpty
)
path
+
'/'
+
file
else
file
))(
in
=>
autoClose
(
new
FileOutputStream
(
getApplicationInfo
.
dataDir
+
'/'
+
file
))(
out
=>
copyStream
(
in
,
out
)))
}
def
copyAssets
()
{
copyAssets
(
System
.
getABI
)
copyAssets
(
"acl"
)
val
ab
=
new
ArrayBuffer
[
String
]
for
(
executable
<-
EXECUTABLES
)
{
ab
.
append
(
"chmod 755 "
+
getApplicationInfo
.
dataDir
+
"/"
+
executable
)
}
Shell
.
SH
.
run
(
ab
.
toArray
)
editor
.
putInt
(
Key
.
currentVersionCode
,
BuildConfig
.
VERSION_CODE
).
apply
()
}
def
updateAssets
()
=
if
(
settings
.
getInt
(
Key
.
currentVersionCode
,
-
1
)
!=
BuildConfig
.
VERSION_CODE
)
copyAssets
()
}
src/main/scala/com/github/shadowsocks/utils/Utils.scala
View file @
6acbae0c
...
...
@@ -54,7 +54,6 @@ import android.view.{Gravity, View, Window}
import
android.widget.Toast
import
com.github.shadowsocks.ShadowsocksApplication.app
import
com.github.shadowsocks.
{
BuildConfig
,
ShadowsocksRunnerService
}
import
eu.chainfire.libsuperuser.Shell
import
org.xbill.DNS._
import
scala.collection.JavaConversions._
...
...
@@ -245,9 +244,6 @@ object Utils {
}
def
startSsService
(
context
:
Context
)
{
val
isInstalled
=
app
.
settings
.
getInt
(
Key
.
currentVersionCode
,
-
1
)
==
BuildConfig
.
VERSION_CODE
if
(!
isInstalled
)
return
val
intent
=
new
Intent
(
context
,
classOf
[
ShadowsocksRunnerService
])
context
.
startService
(
intent
)
}
...
...
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