Replace tag manager with firebase config

This commit is contained in:
Max Lv
2017-04-23 23:11:44 +08:00
parent 6df8f14fb2
commit 6636cf815d
7 changed files with 77 additions and 44 deletions
@@ -127,9 +127,8 @@ trait BaseService extends Service {
def connect() {
profile.name = profile.getName // save original name before it's (possibly) overwritten by IP addresses
if (profile.host == "198.199.101.152") {
val holder = app.containerHolder
val container = holder.getContainer
val url = container.getString("proxy_url")
val config = app.remoteConfig
val url = config.getString("proxy_url")
val sig = Utils.getSignature(this)
val client = new OkHttpClient.Builder()
@@ -276,7 +275,7 @@ trait BaseService extends Service {
override def onCreate() {
super.onCreate()
app.refreshContainerHolder()
app.remoteConfig.fetch()
app.updateAssets()
}
@@ -301,23 +300,12 @@ trait BaseService extends Service {
}
}
def getBlackList: String = {
val default = getString(R.string.black_list)
try {
val container = app.containerHolder.getContainer
val update = container.getString("black_list_lite")
val list = if (update == null || update.isEmpty) default else update
"exclude = " + list + ";"
} catch {
case _: Exception => "exclude = " + default + ";"
}
}
protected def buildPluginCommandLine(): ArrayBuffer[String] = {
val result = ArrayBuffer(pluginPath)
if (TcpFastOpen.sendEnabled) result += "--fast-open"
result
}
protected final def buildShadowsocksConfig(file: String): String = {
val config = new JSONObject()
.put("server", profile.host)
@@ -390,7 +390,6 @@ class MainActivity extends Activity with ServiceBoundContext with Drawer.OnDrawe
protected override def onResume() {
super.onResume()
app.refreshContainerHolder()
state match {
case State.STOPPING | State.CONNECTING =>
case _ => hideCircle()
@@ -38,9 +38,12 @@ import com.github.shadowsocks.acl.DonaldTrump
import com.github.shadowsocks.database.{DBHelper, Profile, ProfileManager}
import com.github.shadowsocks.utils.CloseUtils._
import com.github.shadowsocks.utils._
import com.google.android.gms.tasks.OnCompleteListener
import com.google.android.gms.tasks.Task
import com.google.android.gms.analytics.{GoogleAnalytics, HitBuilders, StandardExceptionParser, Tracker}
import com.google.android.gms.common.api.ResultCallback
import com.google.android.gms.tagmanager.{ContainerHolder, TagManager}
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
import com.google.firebase.FirebaseApp
import com.j256.ormlite.logger.LocalLog
import eu.chainfire.libsuperuser.Shell
@@ -61,8 +64,7 @@ object ShadowsocksApplication {
class ShadowsocksApplication extends Application {
import ShadowsocksApplication._
final val SIG_FUNC = "getSignature"
var containerHolder: ContainerHolder = _
lazy val remoteConfig = FirebaseRemoteConfig.getInstance()
lazy val tracker: Tracker = GoogleAnalytics.getInstance(this).newTracker(R.xml.tracker)
lazy val settings: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(this)
lazy val editor: SharedPreferences.Editor = settings.edit
@@ -149,35 +151,23 @@ class ShadowsocksApplication extends Application {
if (!BuildConfig.DEBUG) java.lang.System.setProperty(LocalLog.LOCAL_LOG_LEVEL_PROPERTY, "ERROR")
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
checkChineseLocale(getResources.getConfiguration)
val tm = TagManager.getInstance(this)
val pending = tm.loadContainerPreferNonDefault("GTM-NT8WS8", R.raw.gtm_default_container)
val callback = new ResultCallback[ContainerHolder] {
override def onResult(holder: ContainerHolder) {
if (!holder.getStatus.isSuccess) {
return
}
containerHolder = holder
val container = holder.getContainer
container.registerFunctionCallMacroCallback(SIG_FUNC,
(functionName: String, parameters: util.Map[String, AnyRef]) => {
if (functionName == SIG_FUNC) {
Utils.getSignature(getApplicationContext)
}
null
})
}
}
pending.setResultCallback(callback, 2, TimeUnit.SECONDS)
FirebaseApp.initializeApp(this)
remoteConfig.fetch(60)
.addOnCompleteListener(new OnCompleteListener[Void]() {
def onComplete(task: Task[Void]) {
if (task.isSuccessful()) {
remoteConfig.activateFetched()
}
}
})
JobManager.create(this).addJobCreator(DonaldTrump)
TcpFastOpen.enabled(settings.getBoolean(Key.tfo, TcpFastOpen.sendEnabled))
}
def refreshContainerHolder() {
val holder = app.containerHolder
if (holder != null) holder.refresh()
}
def crashRecovery() {
val cmd = new ArrayBuffer[String]()