Commit 06f23085 authored by Mygod's avatar Mygod

Refine remote configs

Previously requests were never delivered because they are in two different processes.
parent cd3abfd7
......@@ -64,7 +64,6 @@ object Core {
val handler by lazy { Handler(Looper.getMainLooper()) }
val packageInfo: PackageInfo by lazy { getPackageInfo(app.packageName) }
val deviceStorage by lazy { if (Build.VERSION.SDK_INT < 24) app else DeviceStorageApp(app) }
val remoteConfig: FirebaseRemoteConfig by lazy { FirebaseRemoteConfig.getInstance() }
val analytics: FirebaseAnalytics by lazy { FirebaseAnalytics.getInstance(deviceStorage) }
val directBootSupported by lazy {
Build.VERSION.SDK_INT >= 24 && app.getSystemService<DevicePolicyManager>()?.storageEncryptionStatus ==
......@@ -97,14 +96,6 @@ object Core {
}
Fabric.with(deviceStorage, Crashlytics()) // multiple processes needs manual set-up
FirebaseApp.initializeApp(deviceStorage)
remoteConfig.setDefaults(R.xml.default_configs)
remoteConfig.fetch().addOnCompleteListener {
if (it.isSuccessful) remoteConfig.activateFetched() else {
Log.e(TAG, "Failed to fetch config")
Crashlytics.logException(it.exception)
}
}
WorkManager.initialize(deviceStorage, androidx.work.Configuration.Builder().build())
// handle data restored/crash
......
......@@ -366,7 +366,7 @@ object BaseService {
.add("sig", String(Base64.encode(mdg.digest(), 0)))
.build()
val request = Request.Builder()
.url(Core.remoteConfig.getString("proxy_url"))
.url(RemoteConfig.proxyUrl)
.post(requestBody)
.build()
......@@ -405,6 +405,7 @@ object BaseService {
startNativeProcesses()
if (profile.route !in arrayOf(Acl.ALL, Acl.CUSTOM_RULES)) AclSyncer.schedule(profile.route)
RemoteConfig.fetch()
data.changeState(CONNECTED)
} catch (_: UnknownHostException) {
......@@ -421,7 +422,10 @@ object BaseService {
}
private val instances = WeakHashMap<Interface, Data>()
internal fun register(instance: Interface) = instances.put(instance, Data(instance))
internal fun register(instance: Interface) {
instances[instance] = Data(instance)
RemoteConfig.fetch()
}
val usingVpnMode: Boolean get() = DataStore.serviceMode == Key.modeVpn
val serviceClass get() = when (DataStore.serviceMode) {
......
/*******************************************************************************
* *
* Copyright (C) 2018 by Max Lv <max.c.lv@gmail.com> *
* Copyright (C) 2018 by Mygod Studio <contact-shadowsocks-android@mygod.be> *
* *
* 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 *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
*******************************************************************************/
package com.github.shadowsocks.bg
import android.util.Log
import androidx.core.os.bundleOf
import com.github.shadowsocks.Core
import com.github.shadowsocks.core.R
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
object RemoteConfig {
private val config = FirebaseRemoteConfig.getInstance().apply { setDefaults(R.xml.default_configs) }
val proxyUrl get() = config.getString("proxy_url")
fun fetch() = config.fetch().addOnCompleteListener {
if (it.isSuccessful) config.activateFetched() else {
val e = it.exception ?: return@addOnCompleteListener
Log.w("RemoteConfig", e)
Core.analytics.logEvent("femote_config_failure", bundleOf(Pair(e.javaClass.simpleName, e.message)))
}
}
}
......@@ -242,11 +242,6 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, OnPre
return true
}
override fun onResume() {
super.onResume()
Core.remoteConfig.fetch()
}
override fun onStart() {
super.onStart()
connection.listeningForBandwidth = true
......
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