Refine fetching ACL from cloud
This commit is contained in:
@@ -41,7 +41,6 @@ libraryDependencies ++= Seq(
|
||||
"com.github.kevinsawicki" % "http-request" % "6.0",
|
||||
"com.google.android.gms" % "play-services-ads" % "9.6.1",
|
||||
"com.google.android.gms" % "play-services-analytics" % "9.6.1",
|
||||
"com.google.firebase" % "firebase-core" % "9.6.1",
|
||||
"com.google.firebase" % "firebase-storage" % "9.6.1",
|
||||
"com.j256.ormlite" % "ormlite-android" % "5.0",
|
||||
"com.twofortyfouram" % "android-plugin-api-for-locale" % "1.0.2",
|
||||
|
||||
@@ -39,8 +39,7 @@
|
||||
|
||||
package com.github.shadowsocks
|
||||
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.{File, IOException}
|
||||
import java.util.{Timer, TimerTask}
|
||||
|
||||
import android.app.Service
|
||||
@@ -51,13 +50,11 @@ import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import com.github.kevinsawicki.http.HttpRequest
|
||||
import com.github.shadowsocks.aidl.{IShadowsocksService, IShadowsocksServiceCallback}
|
||||
import com.github.shadowsocks.utils._
|
||||
import com.github.shadowsocks.ShadowsocksApplication.app
|
||||
import com.github.shadowsocks.aidl.{IShadowsocksService, IShadowsocksServiceCallback}
|
||||
import com.github.shadowsocks.database.Profile
|
||||
|
||||
import com.github.shadowsocks.utils._
|
||||
import com.google.firebase.FirebaseApp
|
||||
import com.google.firebase.storage.FileDownloadTask
|
||||
import com.google.firebase.storage.FirebaseStorage
|
||||
|
||||
trait BaseService extends Service {
|
||||
@@ -318,7 +315,7 @@ trait BaseService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
def getAcl(route: String) {
|
||||
def fetchAcl(route: String) {
|
||||
val localAcl = route match {
|
||||
case Route.BYPASS_LAN => "bypass_lan.acl"
|
||||
case Route.BYPASS_CHN => "bypass_chn.acl"
|
||||
@@ -334,11 +331,16 @@ trait BaseService extends Service {
|
||||
val aclRef = storageRef.child(localAcl)
|
||||
|
||||
val task = aclRef.getFile(tempFile)
|
||||
task.addOnSuccessListener((_) => {
|
||||
tempFile.renameTo(cloudAclFile)
|
||||
task.addOnSuccessListener(_ => {
|
||||
if (!tempFile.renameTo(cloudAclFile)) {
|
||||
Log.d("shadowsocks", "Failed to rename acl file")
|
||||
if (!tempFile.delete()) tempFile.deleteOnExit()
|
||||
}
|
||||
return
|
||||
})
|
||||
task.addOnFailureListener((_) => Log.e("shadowsocks", "Unable to download " + localAcl))
|
||||
tempFile.deleteOnExit()
|
||||
task.addOnFailureListener(_ => {
|
||||
Log.e("shadowsocks", "Unable to download " + localAcl)
|
||||
if (!tempFile.delete()) tempFile.deleteOnExit()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ class ShadowsocksNatService extends BaseService {
|
||||
handleConnection()
|
||||
|
||||
// lazily get ACL from cloud
|
||||
getAcl(profile.route)
|
||||
fetchAcl(profile.route)
|
||||
|
||||
changeState(State.CONNECTED)
|
||||
notification = new ShadowsocksNotification(this, profile.name, true)
|
||||
|
||||
@@ -164,7 +164,7 @@ class ShadowsocksVpnService extends VpnService with BaseService {
|
||||
changeState(State.CONNECTED)
|
||||
|
||||
// lazily get ACL from cloud
|
||||
getAcl(profile.route)
|
||||
fetchAcl(profile.route)
|
||||
|
||||
notification = new ShadowsocksNotification(this, profile.name)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user