fix #47 backup the entire database
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Shadowsocks - A shadowsocks client for Android
|
||||
* Copyright (C) 2014 <max.c.lv@gmail.com>
|
||||
* Copyright (C) 2013 <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))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 ++= "killall -9 pdnsd" ++= "\n"
|
||||
}
|
||||
if (!waitForProcess("shadowsocks")) {
|
||||
sb ++= "kill -9 `cat /data/data/com.github.shadowsocks/shadowsocks.pid`" ++= "\n"
|
||||
sb ++= "killall -9 shadowsocks" ++= "\n"
|
||||
}
|
||||
sb ++= "kill -9 `cat " ++= Path.BASE ++= "pdnsd.pid`" ++= "\n"
|
||||
sb ++= "killall -9 pdnsd" ++= "\n"
|
||||
sb ++= "kill -9 `cat " ++= Path.BASE ++= "shadowsocks.pid`" ++= "\n"
|
||||
sb ++= "killall -9 shadowsocks" ++= "\n"
|
||||
|
||||
Utils.runCommand(sb.toString())
|
||||
}
|
||||
|
||||
|
||||
@@ -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 ++= "killall -9 shadowsocks" ++= "\n"
|
||||
}
|
||||
if (!waitForProcess("tun2socks")) {
|
||||
sb ++= "kill -9 `cat /data/data/com.github.shadowsocks/tun2socks.pid`" ++= "\n"
|
||||
sb ++= "killall -9 tun2socks" ++= "\n"
|
||||
}
|
||||
if (!waitForProcess("pdnsd")) {
|
||||
sb ++= "kill -9 `cat /data/data/com.github.shadowsocks/pdnsd.pid`" ++= "\n"
|
||||
sb ++= "killall -9 pdnsd" ++= "\n"
|
||||
}
|
||||
|
||||
sb ++= "kill -9 `cat " ++= Path.BASE ++= "shadowsocks.pid`" ++= "\n"
|
||||
sb ++= "killall -9 shadowsocks" ++= "\n"
|
||||
sb ++= "kill -9 `cat " ++= Path.BASE ++= "tun2socks.pid`" ++= "\n"
|
||||
sb ++= "killall -9 tun2socks" ++= "\n"
|
||||
sb ++= "kill -9 `cat " ++= Path.BASE ++= "pdnsd.pid`" ++= "\n"
|
||||
sb ++= "killall -9 pdnsd" ++= "\n"
|
||||
|
||||
Utils.runCommand(sb.toString())
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Shadowsocks - A shadowsocks client for Android
|
||||
* Copyright (C) 2014 <max.c.lv@gmail.com>
|
||||
* Copyright (C) 2013 <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)
|
||||
}
|
||||
TableUtils.dropTable(connectionSource, classOf[Profile], true)
|
||||
onCreate(database, connectionSource)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user