Commit 41405f91 authored by Mygod's avatar Mygod

Show more information on conflicting plugins

Because one of you feckers just cannot learn to be decent.
parent 93bce703
......@@ -22,6 +22,7 @@ package com.github.shadowsocks.plugin
import android.content.Intent
import android.content.pm.PackageManager
import android.widget.Toast
import com.github.shadowsocks.Core.app
class PluginList : ArrayList<Plugin>() {
......@@ -33,7 +34,14 @@ class PluginList : ArrayList<Plugin>() {
val lookup = mutableMapOf<String, Plugin>().apply {
for (plugin in this@PluginList) {
fun check(old: Plugin?) = check(old == null || old === plugin)
fun check(old: Plugin?) {
if (old != null && old !== plugin) {
val packages = this@PluginList.filter { it.id == plugin.id }.joinToString { it.packageName }
val message = "Conflicting plugins found from: $packages"
Toast.makeText(app, message, Toast.LENGTH_LONG).show()
throw IllegalStateException(message)
}
}
check(put(plugin.id, plugin))
for (alias in plugin.idAliases) check(put(alias, plugin))
}
......
......@@ -33,6 +33,7 @@ import android.net.Uri
import android.os.Build
import android.system.Os
import android.util.Base64
import android.widget.Toast
import androidx.core.os.bundleOf
import com.github.shadowsocks.Core
import com.github.shadowsocks.Core.app
......@@ -143,6 +144,11 @@ object PluginManager {
val providers = app.packageManager.queryIntentContentProviders(
Intent(PluginContract.ACTION_NATIVE_PLUGIN, buildUri(configuration.selected)), flags)
if (providers.isEmpty()) return null
if (providers.size > 1) {
Toast.makeText(app,
"Conflicting plugins found from: ${providers.joinToString { it.providerInfo.packageName }}",
Toast.LENGTH_LONG).show()
}
val provider = providers.single().providerInfo
val options = configuration.getOptions { provider.loadString(PluginContract.METADATA_KEY_DEFAULT_CONFIG) }
var failure: Throwable? = null
......
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