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
97b107eb
Commit
97b107eb
authored
Feb 18, 2014
by
Max Lv
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix #47 backup the entire database
parent
cf60b54d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
84 deletions
+25
-84
src/main/scala/com/github/shadowsocks/BaseService.scala
src/main/scala/com/github/shadowsocks/BaseService.scala
+0
-16
src/main/scala/com/github/shadowsocks/ShadowsocksBackupAgent.scala
...scala/com/github/shadowsocks/ShadowsocksBackupAgent.scala
+3
-5
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
.../scala/com/github/shadowsocks/ShadowsocksNatService.scala
+6
-27
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
.../scala/com/github/shadowsocks/ShadowsocksVpnService.scala
+8
-30
src/main/scala/com/github/shadowsocks/database/DBHelper.scala
...main/scala/com/github/shadowsocks/database/DBHelper.scala
+8
-6
No files found.
src/main/scala/com/github/shadowsocks/BaseService.scala
View file @
97b107eb
...
...
@@ -105,22 +105,6 @@ trait BaseService {
})
}
def
getPid
(
name
:
String
)
:
Int
=
{
try
{
val
reader
:
BufferedReader
=
new
BufferedReader
(
new
FileReader
(
Path
.
BASE
+
name
+
".pid"
))
val
line
=
reader
.
readLine
return
Integer
.
valueOf
(
line
)
}
catch
{
case
e
:
FileNotFoundException
=>
Log
.
e
(
getTag
,
"Cannot open pid file: "
+
name
)
case
e
:
IOException
=>
Log
.
e
(
getTag
,
"Cannot read pid file: "
+
name
)
case
e
:
NumberFormatException
=>
Log
.
e
(
getTag
,
"Invalid pid"
,
e
)
}
-
1
}
def
initSoundVibrateLights
(
notification
:
Notification
)
{
notification
.
sound
=
null
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksBackupAgent.scala
View file @
97b107eb
/*
* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 201
4
<max.c.lv@gmail.com>
* Copyright (C) 201
3
<max.c.lv@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
...
...
@@ -41,9 +41,7 @@ package com.github.shadowsocks
import
android.app.backup.
{
FileBackupHelper
,
SharedPreferencesBackupHelper
,
BackupAgentHelper
}
import
android.content.Context
case
class
DbBackupHelper
(
context
:
Context
,
dbName
:
String
)
extends
FileBackupHelper
(
context
,
context
.
getDatabasePath
(
dbName
).
getAbsolutePath
)
import
com.github.shadowsocks.database.DBHelper
class
ShadowsocksBackupAgent
extends
BackupAgentHelper
{
...
...
@@ -60,6 +58,6 @@ class ShadowsocksBackupAgent extends BackupAgentHelper {
override
def
onCreate
()
{
val
helper
=
new
SharedPreferencesBackupHelper
(
this
,
PREFS_DISPLAY
)
addHelper
(
MY_PREFS_BACKUP_KEY
,
helper
)
addHelper
(
DATABASE
,
new
DbBackupHelper
(
this
,
"profile.db"
))
addHelper
(
DATABASE
,
new
FileBackupHelper
(
this
,
"../databases/"
+
DBHelper
.
PROFILE
))
}
}
src/main/scala/com/github/shadowsocks/ShadowsocksNatService.scala
View file @
97b107eb
...
...
@@ -152,24 +152,6 @@ class ShadowsocksNatService extends Service with BaseService {
Utils
.
runRootCommand
(
cmd
)
}
def
waitForProcess
(
name
:
String
)
:
Boolean
=
{
val
pid
:
Int
=
getPid
(
name
)
if
(
pid
==
-
1
)
return
false
Exec
.
hangupProcessGroup
(-
pid
)
val
t
:
Thread
=
new
Thread
{
override
def
run
()
{
Exec
.
waitFor
(-
pid
)
}
}
t
.
start
()
try
{
t
.
join
(
300
)
}
catch
{
case
ignored
:
InterruptedException
=>
}
!
t
.
isAlive
}
/** Called when the activity is first created. */
def
handleConnection
:
Boolean
=
{
...
...
@@ -292,20 +274,17 @@ class ShadowsocksNatService extends Service with BaseService {
val
sb
=
new
StringBuilder
sb
++=
"kill -9 `cat
/data/data/com.github.shadowsocks/
redsocks.pid`"
++=
"\n"
sb
++=
"kill -9 `cat
"
++=
Path
.
BASE
++=
"
redsocks.pid`"
++=
"\n"
sb
++=
"killall -9 redsocks"
++=
"\n"
Utils
.
runRootCommand
(
sb
.
toString
())
sb
.
clear
()
if
(!
waitForProcess
(
"pdnsd"
))
{
sb
++=
"kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`"
++=
"\n"
sb
++=
"kill -9 `cat "
++=
Path
.
BASE
++=
"pdnsd.pid`"
++=
"\n"
sb
++=
"killall -9 pdnsd"
++=
"\n"
}
if
(!
waitForProcess
(
"shadowsocks"
))
{
sb
++=
"kill -9 `cat /data/data/com.github.shadowsocks/shadowsocks.pid`"
++=
"\n"
sb
++=
"kill -9 `cat "
++=
Path
.
BASE
++=
"shadowsocks.pid`"
++=
"\n"
sb
++=
"killall -9 shadowsocks"
++=
"\n"
}
Utils
.
runCommand
(
sb
.
toString
())
}
...
...
src/main/scala/com/github/shadowsocks/ShadowsocksVpnService.scala
View file @
97b107eb
...
...
@@ -117,24 +117,6 @@ class ShadowsocksVpnService extends VpnService with BaseService {
version
}
def
waitForProcess
(
name
:
String
)
:
Boolean
=
{
val
pid
:
Int
=
getPid
(
name
)
if
(
pid
==
-
1
)
return
false
Exec
.
hangupProcessGroup
(-
pid
)
val
t
:
Thread
=
new
Thread
{
override
def
run
()
{
Exec
.
waitFor
(-
pid
)
}
}
t
.
start
()
try
{
t
.
join
(
300
)
}
catch
{
case
ignored
:
InterruptedException
=>
}
!
t
.
isAlive
}
def
startVpn
()
{
val
proxy_address
=
config
.
proxy
...
...
@@ -272,18 +254,14 @@ class ShadowsocksVpnService extends VpnService with BaseService {
def
killProcesses
()
{
val
sb
=
new
StringBuilder
if
(!
waitForProcess
(
"shadowsocks"
))
{
sb
++=
"kill -9 `cat /data/data/com.github.shadowsocks/
shadowsocks.pid`"
++=
"\n"
sb
++=
"kill -9 `cat "
++=
Path
.
BASE
++=
"
shadowsocks.pid`"
++=
"\n"
sb
++=
"killall -9 shadowsocks"
++=
"\n"
}
if
(!
waitForProcess
(
"tun2socks"
))
{
sb
++=
"kill -9 `cat /data/data/com.github.shadowsocks/tun2socks.pid`"
++=
"\n"
sb
++=
"kill -9 `cat "
++=
Path
.
BASE
++=
"tun2socks.pid`"
++=
"\n"
sb
++=
"killall -9 tun2socks"
++=
"\n"
}
if
(!
waitForProcess
(
"pdnsd"
))
{
sb
++=
"kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`"
++=
"\n"
sb
++=
"kill -9 `cat "
++=
Path
.
BASE
++=
"pdnsd.pid`"
++=
"\n"
sb
++=
"killall -9 pdnsd"
++=
"\n"
}
Utils
.
runCommand
(
sb
.
toString
())
}
...
...
src/main/scala/com/github/shadowsocks/database/DBHelper.scala
View file @
97b107eb
/*
* Shadowsocks - A shadowsocks client for Android
* Copyright (C) 201
4
<max.c.lv@gmail.com>
* Copyright (C) 201
3
<max.c.lv@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
...
...
@@ -46,7 +46,11 @@ import com.j256.ormlite.support.ConnectionSource
import
com.j256.ormlite.table.TableUtils
import
com.j256.ormlite.dao.Dao
class
DBHelper
(
val
context
:
Context
)
extends
OrmLiteSqliteOpenHelper
(
context
,
"profile.db"
,
null
,
7
)
{
object
DBHelper
{
val
PROFILE
=
"profile.db"
}
class
DBHelper
(
val
context
:
Context
)
extends
OrmLiteSqliteOpenHelper
(
context
,
DBHelper
.
PROFILE
,
null
,
7
)
{
lazy
val
profileDao
:
Dao
[
Profile
,
Int
]
=
getDao
(
classOf
[
Profile
])
...
...
@@ -55,9 +59,7 @@ class DBHelper(val context: Context) extends OrmLiteSqliteOpenHelper(context, "p
}
def
onUpgrade
(
database
:
SQLiteDatabase
,
connectionSource
:
ConnectionSource
,
oldVersion
:
Int
,
newVersion
:
Int
)
{
if
(
newVersion
!=
oldVersion
)
{
TableUtils
.
dropTable
(
connectionSource
,
classOf
[
Profile
],
true
)
onCreate
(
database
,
connectionSource
)
}
}
}
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