Commit 3c3e5317 authored by Mygod's avatar Mygod

Add backup entry for custom rules

Refine #1069.
parent 1f6d6bbd
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package com.github.shadowsocks package com.github.shadowsocks
import android.app.backup.{BackupAgentHelper, FileBackupHelper, SharedPreferencesBackupHelper} import android.app.backup.{BackupAgentHelper, FileBackupHelper, SharedPreferencesBackupHelper}
import com.github.shadowsocks.acl.Acl
import com.github.shadowsocks.database.DBHelper import com.github.shadowsocks.database.DBHelper
class ShadowsocksBackupAgent extends BackupAgentHelper { class ShadowsocksBackupAgent extends BackupAgentHelper {
...@@ -38,6 +39,7 @@ class ShadowsocksBackupAgent extends BackupAgentHelper { ...@@ -38,6 +39,7 @@ class ShadowsocksBackupAgent extends BackupAgentHelper {
override def onCreate() { override def onCreate() {
val helper = new SharedPreferencesBackupHelper(this, PREFS_DISPLAY) val helper = new SharedPreferencesBackupHelper(this, PREFS_DISPLAY)
addHelper(MY_PREFS_BACKUP_KEY, helper) addHelper(MY_PREFS_BACKUP_KEY, helper)
addHelper(DATABASE, new FileBackupHelper(this, "../databases/" + DBHelper.PROFILE)) addHelper(DATABASE, new FileBackupHelper(this, "../databases/" + DBHelper.PROFILE,
"../" + Acl.CUSTOM_RULES + ".acl"))
} }
} }
...@@ -51,15 +51,15 @@ class Acl { ...@@ -51,15 +51,15 @@ class Acl {
bypass = other.bypass bypass = other.bypass
this this
} }
def fromSource(value: Source): Acl = { def fromSource(value: Source, defaultBypass: Boolean = false): Acl = {
bypassHostnames.clear() bypassHostnames.clear()
proxyHostnames.clear() proxyHostnames.clear()
this.subnets.clear() this.subnets.clear()
bypass = false bypass = defaultBypass
lazy val bypassSubnets = new mutable.SortedList[Subnet]() lazy val bypassSubnets = new mutable.SortedList[Subnet]()
lazy val proxySubnets = new mutable.SortedList[Subnet]() lazy val proxySubnets = new mutable.SortedList[Subnet]()
var hostnames: mutable.SortedList[String] = bypassHostnames var hostnames: mutable.SortedList[String] = if (defaultBypass) proxyHostnames else bypassHostnames
var subnets: mutable.SortedList[Subnet] = bypassSubnets var subnets: mutable.SortedList[Subnet] = if (defaultBypass) proxySubnets else bypassSubnets
for (line <- value.getLines()) (line.indexOf('#') match { for (line <- value.getLines()) (line.indexOf('#') match {
case -1 => line case -1 => line
case index => line.substring(0, index) // trim comments case index => line.substring(0, index) // trim comments
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment