Commit 7f4624f3 authored by Mygod's avatar Mygod

Prefer noBackupFilesDir

parent e02f9690
......@@ -116,7 +116,7 @@ object Core {
for (dir in arrayOf("acl", "overture"))
try {
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) {
printLog(e)
......
......@@ -46,7 +46,7 @@ class Acl {
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
get() {
......
......@@ -20,18 +20,14 @@
package com.github.shadowsocks.bg
import android.annotation.TargetApi
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.Build
import android.os.IBinder
import android.os.RemoteCallbackList
import android.os.SystemClock
import android.os.*
import android.util.Base64
import android.util.Log
import androidx.core.os.UserManagerCompat
import androidx.core.content.getSystemService
import androidx.core.os.bundleOf
import com.crashlytics.android.Crashlytics
import com.github.shadowsocks.Core
......@@ -195,9 +191,8 @@ object BaseService {
.put("plugin_opts", plugin.toString())
}
// sensitive Shadowsocks config is stored in
return File(if (UserManagerCompat.isUserUnlocked(app)) app.filesDir else @TargetApi(24) {
Core.deviceStorage.noBackupFilesDir // only API 24+ will be in locked state
}, CONFIG_FILE).apply {
return File((if (Build.VERSION.SDK_INT < 24 || app.getSystemService<UserManager>()?.isUserUnlocked != true)
app else Core.deviceStorage).noBackupFilesDir, CONFIG_FILE).apply {
shadowsocksConfigFile = this
writeText(config.toString())
}
......
......@@ -70,7 +70,7 @@ class GuardedProcessPool {
process = ProcessBuilder(cmd)
.redirectErrorStream(true)
.directory(Core.deviceStorage.filesDir)
.directory(Core.deviceStorage.noBackupFilesDir)
.start()
streamLogger(process.inputStream, Log::i)
......
......@@ -52,7 +52,7 @@ object LocalDnsService {
}
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("RedirectIPv6Record", true)
put("DomainBase64Decode", false)
......
......@@ -29,7 +29,7 @@ import java.nio.ByteBuffer
import java.nio.ByteOrder
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) {
try {
......
......@@ -52,7 +52,7 @@ class TransproxyService : Service(), LocalDnsService.Interface {
}
private fun startRedsocksDaemon() {
File(Core.deviceStorage.filesDir, "redsocks.conf").writeText("""base {
File(Core.deviceStorage.noBackupFilesDir, "redsocks.conf").writeText("""base {
log_debug = off;
log_info = off;
log = stderr;
......
......@@ -74,7 +74,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
}
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) {
try {
......@@ -259,7 +259,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
private fun sendFd(fd: Int) {
if (fd == -1) throw IOException("Invalid fd (-1)")
var tries = 0
val path = File(Core.deviceStorage.filesDir, "sock_path").absolutePath
val path = File(Core.deviceStorage.noBackupFilesDir, "sock_path").absolutePath
while (true) try {
Thread.sleep(30L shl tries)
JniHelper.sendFd(fd, path)
......
......@@ -163,7 +163,7 @@ object PluginManager {
var initialized = false
fun entryNotFound(): Nothing = throw IndexOutOfBoundsException("Plugin entry binary not found")
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)
?: return null).use { cursor ->
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