Commit 7f4624f3 authored by Mygod's avatar Mygod

Prefer noBackupFilesDir

parent e02f9690
...@@ -116,7 +116,7 @@ object Core { ...@@ -116,7 +116,7 @@ object Core {
for (dir in arrayOf("acl", "overture")) for (dir in arrayOf("acl", "overture"))
try { try {
for (file in assetManager.list(dir)!!) assetManager.open("$dir/$file").use { input -> for (file in assetManager.list(dir)!!) assetManager.open("$dir/$file").use { input ->
File(deviceStorage.filesDir, file).outputStream().use { output -> input.copyTo(output) } File(deviceStorage.noBackupFilesDir, file).outputStream().use { output -> input.copyTo(output) }
} }
} catch (e: IOException) { } catch (e: IOException) {
printLog(e) printLog(e)
......
...@@ -46,7 +46,7 @@ class Acl { ...@@ -46,7 +46,7 @@ class Acl {
val networkAclParser = "^IMPORT_URL\\s*<(.+)>\\s*$".toRegex() val networkAclParser = "^IMPORT_URL\\s*<(.+)>\\s*$".toRegex()
fun getFile(id: String, context: Context = Core.deviceStorage) = File(context.filesDir, "$id.acl") fun getFile(id: String, context: Context = Core.deviceStorage) = File(context.noBackupFilesDir, "$id.acl")
var customRules: Acl var customRules: Acl
get() { get() {
......
...@@ -20,18 +20,14 @@ ...@@ -20,18 +20,14 @@
package com.github.shadowsocks.bg package com.github.shadowsocks.bg
import android.annotation.TargetApi
import android.app.Service import android.app.Service
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.os.Build import android.os.*
import android.os.IBinder
import android.os.RemoteCallbackList
import android.os.SystemClock
import android.util.Base64 import android.util.Base64
import android.util.Log import android.util.Log
import androidx.core.os.UserManagerCompat import androidx.core.content.getSystemService
import androidx.core.os.bundleOf import androidx.core.os.bundleOf
import com.crashlytics.android.Crashlytics import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.Core import com.github.shadowsocks.Core
...@@ -195,9 +191,8 @@ object BaseService { ...@@ -195,9 +191,8 @@ object BaseService {
.put("plugin_opts", plugin.toString()) .put("plugin_opts", plugin.toString())
} }
// sensitive Shadowsocks config is stored in // sensitive Shadowsocks config is stored in
return File(if (UserManagerCompat.isUserUnlocked(app)) app.filesDir else @TargetApi(24) { return File((if (Build.VERSION.SDK_INT < 24 || app.getSystemService<UserManager>()?.isUserUnlocked != true)
Core.deviceStorage.noBackupFilesDir // only API 24+ will be in locked state app else Core.deviceStorage).noBackupFilesDir, CONFIG_FILE).apply {
}, CONFIG_FILE).apply {
shadowsocksConfigFile = this shadowsocksConfigFile = this
writeText(config.toString()) writeText(config.toString())
} }
......
...@@ -70,7 +70,7 @@ class GuardedProcessPool { ...@@ -70,7 +70,7 @@ class GuardedProcessPool {
process = ProcessBuilder(cmd) process = ProcessBuilder(cmd)
.redirectErrorStream(true) .redirectErrorStream(true)
.directory(Core.deviceStorage.filesDir) .directory(Core.deviceStorage.noBackupFilesDir)
.start() .start()
streamLogger(process.inputStream, Log::i) streamLogger(process.inputStream, Log::i)
......
...@@ -52,7 +52,7 @@ object LocalDnsService { ...@@ -52,7 +52,7 @@ object LocalDnsService {
} }
fun buildOvertureConfig(file: String) = file.also { fun buildOvertureConfig(file: String) = file.also {
File(Core.deviceStorage.filesDir, it).writeText(JSONObject().run { File(Core.deviceStorage.noBackupFilesDir, it).writeText(JSONObject().run {
put("BindAddress", "${DataStore.listenAddress}:${DataStore.portLocalDns}") put("BindAddress", "${DataStore.listenAddress}:${DataStore.portLocalDns}")
put("RedirectIPv6Record", true) put("RedirectIPv6Record", true)
put("DomainBase64Decode", false) put("DomainBase64Decode", false)
......
...@@ -29,7 +29,7 @@ import java.nio.ByteBuffer ...@@ -29,7 +29,7 @@ import java.nio.ByteBuffer
import java.nio.ByteOrder import java.nio.ByteOrder
class TrafficMonitorThread : LocalSocketListener("TrafficMonitorThread") { class TrafficMonitorThread : LocalSocketListener("TrafficMonitorThread") {
override val socketFile = File(Core.deviceStorage.filesDir, "stat_path") override val socketFile = File(Core.deviceStorage.noBackupFilesDir, "stat_path")
override fun accept(socket: LocalSocket) { override fun accept(socket: LocalSocket) {
try { try {
......
...@@ -52,7 +52,7 @@ class TransproxyService : Service(), LocalDnsService.Interface { ...@@ -52,7 +52,7 @@ class TransproxyService : Service(), LocalDnsService.Interface {
} }
private fun startRedsocksDaemon() { private fun startRedsocksDaemon() {
File(Core.deviceStorage.filesDir, "redsocks.conf").writeText("""base { File(Core.deviceStorage.noBackupFilesDir, "redsocks.conf").writeText("""base {
log_debug = off; log_debug = off;
log_info = off; log_info = off;
log = stderr; log = stderr;
......
...@@ -74,7 +74,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -74,7 +74,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
} }
private inner class ProtectWorker : LocalSocketListener("ShadowsocksVpnThread") { private inner class ProtectWorker : LocalSocketListener("ShadowsocksVpnThread") {
override val socketFile: File = File(Core.deviceStorage.filesDir, "protect_path") override val socketFile: File = File(Core.deviceStorage.noBackupFilesDir, "protect_path")
override fun accept(socket: LocalSocket) { override fun accept(socket: LocalSocket) {
try { try {
...@@ -259,7 +259,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface { ...@@ -259,7 +259,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
private fun sendFd(fd: Int) { private fun sendFd(fd: Int) {
if (fd == -1) throw IOException("Invalid fd (-1)") if (fd == -1) throw IOException("Invalid fd (-1)")
var tries = 0 var tries = 0
val path = File(Core.deviceStorage.filesDir, "sock_path").absolutePath val path = File(Core.deviceStorage.noBackupFilesDir, "sock_path").absolutePath
while (true) try { while (true) try {
Thread.sleep(30L shl tries) Thread.sleep(30L shl tries)
JniHelper.sendFd(fd, path) JniHelper.sendFd(fd, path)
......
...@@ -163,7 +163,7 @@ object PluginManager { ...@@ -163,7 +163,7 @@ object PluginManager {
var initialized = false var initialized = false
fun entryNotFound(): Nothing = throw IndexOutOfBoundsException("Plugin entry binary not found") fun entryNotFound(): Nothing = throw IndexOutOfBoundsException("Plugin entry binary not found")
val list = ArrayList<String>() val list = ArrayList<String>()
val pluginDir = File(Core.deviceStorage.filesDir, "plugin") val pluginDir = File(Core.deviceStorage.noBackupFilesDir, "plugin")
(cr.query(uri, arrayOf(PluginContract.COLUMN_PATH, PluginContract.COLUMN_MODE), null, null, null) (cr.query(uri, arrayOf(PluginContract.COLUMN_PATH, PluginContract.COLUMN_MODE), null, null, null)
?: return null).use { cursor -> ?: return null).use { cursor ->
if (!cursor.moveToFirst()) entryNotFound() if (!cursor.moveToFirst()) entryNotFound()
......
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