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
870fd9e6
Commit
870fd9e6
authored
Dec 16, 2017
by
Mygod
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move custom-rules.acl to PublicDatabase
Less files to backup. Less constants to keep track of.
parent
4e71722a
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
31 additions
and
30 deletions
+31
-30
mobile/src/androidTest/java/com/github/shadowsocks/acl/AclTest.kt
...rc/androidTest/java/com/github/shadowsocks/acl/AclTest.kt
+1
-2
mobile/src/main/java/com/github/shadowsocks/ConfigBackupHelper.kt
...rc/main/java/com/github/shadowsocks/ConfigBackupHelper.kt
+1
-2
mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt
mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt
+12
-15
mobile/src/main/java/com/github/shadowsocks/acl/CustomRulesFragment.kt
...in/java/com/github/shadowsocks/acl/CustomRulesFragment.kt
+1
-1
mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt
...le/src/main/java/com/github/shadowsocks/bg/BaseService.kt
+2
-3
mobile/src/main/java/com/github/shadowsocks/database/PrivateDatabase.kt
...n/java/com/github/shadowsocks/database/PrivateDatabase.kt
+1
-3
mobile/src/main/java/com/github/shadowsocks/database/PublicDatabase.kt
...in/java/com/github/shadowsocks/database/PublicDatabase.kt
+13
-2
mobile/src/main/res/xml/backup_descriptor.xml
mobile/src/main/res/xml/backup_descriptor.xml
+0
-2
No files found.
mobile/src/androidTest/java/com/github/shadowsocks/acl/AclTest.kt
View file @
870fd9e6
...
@@ -22,7 +22,6 @@ package com.github.shadowsocks.acl
...
@@ -22,7 +22,6 @@ package com.github.shadowsocks.acl
import
org.junit.Assert
import
org.junit.Assert
import
org.junit.Test
import
org.junit.Test
import
java.io.StringReader
class
AclTest
{
class
AclTest
{
companion
object
{
companion
object
{
...
@@ -36,6 +35,6 @@ class AclTest {
...
@@ -36,6 +35,6 @@ class AclTest {
@Test
@Test
fun
parse
()
{
fun
parse
()
{
Assert
.
assertEquals
(
INPUT1
,
Acl
().
fromReader
(
StringReader
(
INPUT1
)).
toString
());
Assert
.
assertEquals
(
INPUT1
,
Acl
().
fromReader
(
INPUT1
.
reader
(
)).
toString
());
}
}
}
}
mobile/src/main/java/com/github/shadowsocks/ConfigBackupHelper.kt
View file @
870fd9e6
...
@@ -22,11 +22,10 @@ package com.github.shadowsocks
...
@@ -22,11 +22,10 @@ package com.github.shadowsocks
import
android.app.backup.BackupAgentHelper
import
android.app.backup.BackupAgentHelper
import
android.app.backup.FileBackupHelper
import
android.app.backup.FileBackupHelper
import
com.github.shadowsocks.acl.Acl
import
com.github.shadowsocks.utils.Key
import
com.github.shadowsocks.utils.Key
@Deprecated
(
"Only used in API level < 23. For 6.0+, Auto Backup for Apps is used."
)
@Deprecated
(
"Only used in API level < 23. For 6.0+, Auto Backup for Apps is used."
)
class
ConfigBackupHelper
:
BackupAgentHelper
()
{
class
ConfigBackupHelper
:
BackupAgentHelper
()
{
override
fun
onCreate
()
=
addHelper
(
"com.github.shadowsocks.database.profile"
,
FileBackupHelper
(
this
,
override
fun
onCreate
()
=
addHelper
(
"com.github.shadowsocks.database.profile"
,
FileBackupHelper
(
this
,
"../databases/"
+
Key
.
DB_PROFILE
,
"../databases/"
+
Key
.
DB_PUBLIC
,
Acl
.
CUSTOM_RULES
+
".acl"
))
"../databases/"
+
Key
.
DB_PROFILE
,
"../databases/"
+
Key
.
DB_PUBLIC
))
}
}
mobile/src/main/java/com/github/shadowsocks/acl/Acl.kt
View file @
870fd9e6
...
@@ -24,11 +24,10 @@ import android.content.Context
...
@@ -24,11 +24,10 @@ import android.content.Context
import
android.support.v7.util.SortedList
import
android.support.v7.util.SortedList
import
android.util.Log
import
android.util.Log
import
com.github.shadowsocks.App.Companion.app
import
com.github.shadowsocks.App.Companion.app
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.utils.Subnet
import
com.github.shadowsocks.utils.Subnet
import
com.github.shadowsocks.utils.asIterable
import
com.github.shadowsocks.utils.asIterable
import
com.j256.ormlite.field.DatabaseField
import
java.io.File
import
java.io.File
import
java.io.FileNotFoundException
import
java.io.Reader
import
java.io.Reader
import
java.net.URL
import
java.net.URL
...
@@ -42,24 +41,26 @@ class Acl {
...
@@ -42,24 +41,26 @@ class Acl {
const
val
GFWLIST
=
"gfwlist"
const
val
GFWLIST
=
"gfwlist"
const
val
CHINALIST
=
"china-list"
const
val
CHINALIST
=
"china-list"
const
val
CUSTOM_RULES
=
"custom-rules"
const
val
CUSTOM_RULES
=
"custom-rules"
const
val
CUSTOM_RULES_FLATTENED
=
"custom-rules-flattened"
val
networkAclParser
=
"^IMPORT_URL\\s*<(.+)>\\s*$"
.
toRegex
()
val
networkAclParser
=
"^IMPORT_URL\\s*<(.+)>\\s*$"
.
toRegex
()
fun
getFile
(
id
:
String
,
context
:
Context
=
app
.
deviceContext
)
=
File
(
context
.
filesDir
,
id
+
".acl"
)
fun
getFile
(
id
:
String
,
context
:
Context
=
app
.
deviceContext
)
=
File
(
context
.
filesDir
,
id
+
".acl"
)
val
customRules
:
Acl
get
()
{
var
customRules
:
Acl
get
()
{
val
acl
=
Acl
()
val
acl
=
Acl
()
try
{
val
str
=
DataStore
.
publicStore
.
getString
(
CUSTOM_RULES
)
?:
return
acl
acl
.
from
Id
(
CUSTOM_RULES
)
acl
.
from
Reader
(
str
.
reader
()
)
if
(!
acl
.
bypass
)
{
if
(!
acl
.
bypass
)
{
acl
.
subnets
.
clear
()
acl
.
subnets
.
clear
()
acl
.
hostnames
.
clear
()
acl
.
hostnames
.
clear
()
}
}
catch
(
_
:
FileNotFoundException
)
{
}
acl
.
bypass
=
true
acl
.
bypass
=
true
}
return
acl
return
acl
}
}
set
(
value
)
=
DataStore
.
publicStore
.
putString
(
CUSTOM_RULES
,
if
((!
value
.
bypass
||
value
.
subnets
.
size
()
==
0
&&
value
.
hostnames
.
size
()
==
0
)
&&
value
.
urls
.
size
()
==
0
)
null
else
value
.
toString
())
fun
save
(
id
:
String
,
acl
:
Acl
)
=
getFile
(
id
).
writeText
(
acl
.
toString
())
fun
save
(
id
:
String
,
acl
:
Acl
)
=
getFile
(
id
).
writeText
(
acl
.
toString
())
}
}
...
@@ -84,13 +85,9 @@ class Acl {
...
@@ -84,13 +85,9 @@ class Acl {
override
fun
compareNonNull
(
o1
:
URL
,
o2
:
URL
):
Int
=
ordering
.
compare
(
o1
,
o2
)
override
fun
compareNonNull
(
o1
:
URL
,
o2
:
URL
):
Int
=
ordering
.
compare
(
o1
,
o2
)
}
}
@DatabaseField
(
generatedId
=
true
)
var
id
=
0
val
hostnames
=
SortedList
(
String
::
class
.
java
,
StringSorter
)
val
hostnames
=
SortedList
(
String
::
class
.
java
,
StringSorter
)
val
subnets
=
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
val
subnets
=
SortedList
(
Subnet
::
class
.
java
,
SubnetSorter
)
val
urls
=
SortedList
(
URL
::
class
.
java
,
URLSorter
)
val
urls
=
SortedList
(
URL
::
class
.
java
,
URLSorter
)
@DatabaseField
var
bypass
=
false
var
bypass
=
false
fun
clear
():
Acl
{
fun
clear
():
Acl
{
...
...
mobile/src/main/java/com/github/shadowsocks/acl/CustomRulesFragment.kt
View file @
870fd9e6
...
@@ -157,7 +157,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
...
@@ -157,7 +157,7 @@ class CustomRulesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
if
(!
savePending
)
{
if
(!
savePending
)
{
savePending
=
true
savePending
=
true
list
.
post
{
list
.
post
{
Acl
.
save
(
Acl
.
CUSTOM_RULES
,
acl
)
Acl
.
customRules
=
acl
savePending
=
false
savePending
=
false
}
}
}
}
...
...
mobile/src/main/java/com/github/shadowsocks/bg/BaseService.kt
View file @
870fd9e6
...
@@ -195,8 +195,7 @@ object BaseService {
...
@@ -195,8 +195,7 @@ object BaseService {
val
aclFile
:
File
?
get
()
{
val
aclFile
:
File
?
get
()
{
val
route
=
profile
!!
.
route
val
route
=
profile
!!
.
route
return
if
(
route
==
Acl
.
ALL
)
null
else
return
if
(
route
==
Acl
.
ALL
)
null
else
Acl
.
getFile
(
route
)
Acl
.
getFile
(
if
(
route
==
Acl
.
CUSTOM_RULES
)
Acl
.
CUSTOM_RULES_FLATTENED
else
route
)
}
}
fun
changeState
(
s
:
Int
,
msg
:
String
?
=
null
)
{
fun
changeState
(
s
:
Int
,
msg
:
String
?
=
null
)
{
...
@@ -378,7 +377,7 @@ object BaseService {
...
@@ -378,7 +377,7 @@ object BaseService {
}
}
if
(
profile
.
route
==
Acl
.
CUSTOM_RULES
)
if
(
profile
.
route
==
Acl
.
CUSTOM_RULES
)
Acl
.
save
(
Acl
.
CUSTOM_RULES
_FLATTENED
,
Acl
.
customRules
.
flatten
(
10
))
Acl
.
save
(
Acl
.
CUSTOM_RULES
,
Acl
.
customRules
.
flatten
(
10
))
data
.
plugin
=
PluginConfiguration
(
profile
.
plugin
?:
""
).
selectedOptions
data
.
plugin
=
PluginConfiguration
(
profile
.
plugin
?:
""
).
selectedOptions
data
.
pluginPath
=
PluginManager
.
init
(
data
.
plugin
)
data
.
pluginPath
=
PluginManager
.
init
(
data
.
plugin
)
...
...
mobile/src/main/java/com/github/shadowsocks/database/PrivateDatabase.kt
View file @
870fd9e6
...
@@ -139,9 +139,7 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
...
@@ -139,9 +139,7 @@ object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25)
}
}
if
(
oldVersion
<
25
)
{
if
(
oldVersion
<
25
)
{
kvPairDao
.
queryBuilder
().
where
().
`in`
(
"key"
,
PublicDatabase
.
onUpgrade
(
database
,
0
,
-
1
)
Key
.
id
,
Key
.
tfo
,
Key
.
serviceMode
,
Key
.
portProxy
,
Key
.
portLocalDns
,
Key
.
portTransproxy
).
query
()
.
forEach
{
PublicDatabase
.
kvPairDao
.
createOrUpdate
(
it
)
}
}
}
}
catch
(
ex
:
Exception
)
{
}
catch
(
ex
:
Exception
)
{
app
.
track
(
ex
)
app
.
track
(
ex
)
...
...
mobile/src/main/java/com/github/shadowsocks/database/PublicDatabase.kt
View file @
870fd9e6
...
@@ -22,6 +22,7 @@ package com.github.shadowsocks.database
...
@@ -22,6 +22,7 @@ package com.github.shadowsocks.database
import
android.database.sqlite.SQLiteDatabase
import
android.database.sqlite.SQLiteDatabase
import
com.github.shadowsocks.App.Companion.app
import
com.github.shadowsocks.App.Companion.app
import
com.github.shadowsocks.acl.Acl
import
com.github.shadowsocks.utils.Key
import
com.github.shadowsocks.utils.Key
import
com.j256.ormlite.android.AndroidDatabaseConnection
import
com.j256.ormlite.android.AndroidDatabaseConnection
import
com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
import
com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
...
@@ -29,7 +30,7 @@ import com.j256.ormlite.dao.Dao
...
@@ -29,7 +30,7 @@ import com.j256.ormlite.dao.Dao
import
com.j256.ormlite.support.ConnectionSource
import
com.j256.ormlite.support.ConnectionSource
import
com.j256.ormlite.table.TableUtils
import
com.j256.ormlite.table.TableUtils
object
PublicDatabase
:
OrmLiteSqliteOpenHelper
(
app
.
deviceContext
,
Key
.
DB_PUBLIC
,
null
,
1
)
{
object
PublicDatabase
:
OrmLiteSqliteOpenHelper
(
app
.
deviceContext
,
Key
.
DB_PUBLIC
,
null
,
2
)
{
@Suppress
(
"UNCHECKED_CAST"
)
@Suppress
(
"UNCHECKED_CAST"
)
val
kvPairDao
:
Dao
<
KeyValuePair
,
String
?
>
by
lazy
{
getDao
(
KeyValuePair
::
class
.
java
)
as
Dao
<
KeyValuePair
,
String
?
>
}
val
kvPairDao
:
Dao
<
KeyValuePair
,
String
?
>
by
lazy
{
getDao
(
KeyValuePair
::
class
.
java
)
as
Dao
<
KeyValuePair
,
String
?
>
}
...
@@ -38,7 +39,17 @@ object PublicDatabase : OrmLiteSqliteOpenHelper(app.deviceContext, Key.DB_PUBLIC
...
@@ -38,7 +39,17 @@ object PublicDatabase : OrmLiteSqliteOpenHelper(app.deviceContext, Key.DB_PUBLIC
}
}
override
fun
onUpgrade
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
?,
override
fun
onUpgrade
(
database
:
SQLiteDatabase
?,
connectionSource
:
ConnectionSource
?,
oldVersion
:
Int
,
newVersion
:
Int
)
{
}
oldVersion
:
Int
,
newVersion
:
Int
)
{
if
(
oldVersion
<
1
)
{
PrivateDatabase
.
kvPairDao
.
queryBuilder
().
where
().
`in`
(
"key"
,
Key
.
id
,
Key
.
tfo
,
Key
.
serviceMode
,
Key
.
portProxy
,
Key
.
portLocalDns
,
Key
.
portTransproxy
).
query
()
.
forEach
{
kvPairDao
.
createOrUpdate
(
it
)
}
}
if
(
oldVersion
<
2
)
{
kvPairDao
.
createOrUpdate
(
KeyValuePair
(
Acl
.
CUSTOM_RULES
).
put
(
Acl
().
fromId
(
Acl
.
CUSTOM_RULES
).
toString
()))
}
}
override
fun
onDowngrade
(
db
:
SQLiteDatabase
?,
oldVersion
:
Int
,
newVersion
:
Int
)
{
override
fun
onDowngrade
(
db
:
SQLiteDatabase
?,
oldVersion
:
Int
,
newVersion
:
Int
)
{
val
connection
=
AndroidDatabaseConnection
(
db
,
true
)
val
connection
=
AndroidDatabaseConnection
(
db
,
true
)
...
...
mobile/src/main/res/xml/backup_descriptor.xml
View file @
870fd9e6
...
@@ -4,7 +4,5 @@
...
@@ -4,7 +4,5 @@
<include
domain=
"database"
path=
"profile.db"
/>
<include
domain=
"database"
path=
"profile.db"
/>
<!-- No device storage yet in Android 6.0 -->
<!-- No device storage yet in Android 6.0 -->
<include
domain=
"database"
path=
"config.db"
/>
<include
domain=
"database"
path=
"config.db"
/>
<include
domain=
"file"
path=
"custom-rules.acl"
/>
<include
domain=
"device_database"
path=
"config.db"
/>
<include
domain=
"device_database"
path=
"config.db"
/>
<include
domain=
"device_file"
path=
"custom-rules.acl"
/>
</full-backup-content>
</full-backup-content>
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