Commit 52d0d7ed authored by Mygod's avatar Mygod

Add isV2 to PluginManager.InitResult

parent 6563e0ba
...@@ -118,9 +118,15 @@ object PluginManager { ...@@ -118,9 +118,15 @@ object PluginManager {
.build() .build()
fun buildIntent(id: String, action: String): Intent = Intent(action, buildUri(id)) fun buildIntent(id: String, action: String): Intent = Intent(action, buildUri(id))
data class InitResult(
val path: String,
val options: PluginOptions,
val isV2: Boolean = false,
)
// the following parts are meant to be used by :bg // the following parts are meant to be used by :bg
@Throws(Throwable::class) @Throws(Throwable::class)
fun init(configuration: PluginConfiguration): Pair<String, PluginOptions>? { fun init(configuration: PluginConfiguration): InitResult? {
if (configuration.selected.isEmpty()) return null if (configuration.selected.isEmpty()) return null
var throwable: Throwable? = null var throwable: Throwable? = null
...@@ -136,7 +142,7 @@ object PluginManager { ...@@ -136,7 +142,7 @@ object PluginManager {
throw throwable ?: PluginNotFoundException(configuration.selected) throw throwable ?: PluginNotFoundException(configuration.selected)
} }
private fun initNative(configuration: PluginConfiguration): Pair<String, PluginOptions>? { private fun initNative(configuration: PluginConfiguration): InitResult? {
var flags = PackageManager.GET_META_DATA var flags = PackageManager.GET_META_DATA
if (Build.VERSION.SDK_INT >= 24) { if (Build.VERSION.SDK_INT >= 24) {
flags = flags or PackageManager.MATCH_DIRECT_BOOT_UNAWARE or PackageManager.MATCH_DIRECT_BOOT_AWARE flags = flags or PackageManager.MATCH_DIRECT_BOOT_UNAWARE or PackageManager.MATCH_DIRECT_BOOT_AWARE
...@@ -152,9 +158,11 @@ object PluginManager { ...@@ -152,9 +158,11 @@ object PluginManager {
} }
val provider = providers.single().providerInfo val provider = providers.single().providerInfo
val options = configuration.getOptions { provider.loadString(PluginContract.METADATA_KEY_DEFAULT_CONFIG) } val options = configuration.getOptions { provider.loadString(PluginContract.METADATA_KEY_DEFAULT_CONFIG) }
val isV2 = (provider.applicationInfo.metaData?.getString(PluginContract.METADATA_KEY_VERSION)
?.substringBefore('.')?.toIntOrNull() ?: 0) >= 2
var failure: Throwable? = null var failure: Throwable? = null
try { try {
initNativeFaster(provider)?.also { return it to options } initNativeFaster(provider)?.also { return InitResult(it, options, isV2) }
} catch (t: Throwable) { } catch (t: Throwable) {
Timber.w("Initializing native plugin faster mode failed") Timber.w("Initializing native plugin faster mode failed")
failure = t failure = t
...@@ -165,7 +173,7 @@ object PluginManager { ...@@ -165,7 +173,7 @@ object PluginManager {
authority(provider.authority) authority(provider.authority)
}.build() }.build()
try { try {
return initNativeFast(app.contentResolver, options, uri)?.let { it to options } return initNativeFast(app.contentResolver, options, uri)?.let { InitResult(it, options, isV2) }
} catch (t: Throwable) { } catch (t: Throwable) {
Timber.w("Initializing native plugin fast mode failed") Timber.w("Initializing native plugin fast mode failed")
failure?.also { t.addSuppressed(it) } failure?.also { t.addSuppressed(it) }
...@@ -173,7 +181,7 @@ object PluginManager { ...@@ -173,7 +181,7 @@ object PluginManager {
} }
try { try {
return initNativeSlow(app.contentResolver, options, uri)?.let { it to options } return initNativeSlow(app.contentResolver, options, uri)?.let { InitResult(it, options, isV2) }
} catch (t: Throwable) { } catch (t: Throwable) {
failure?.also { t.addSuppressed(it) } failure?.also { t.addSuppressed(it) }
throw t throw t
......
...@@ -72,6 +72,13 @@ object PluginContract { ...@@ -72,6 +72,13 @@ object PluginContract {
</host_name> */ </host_name> */
const val EXTRA_HELP_MESSAGE = "com.github.shadowsocks.plugin.EXTRA_HELP_MESSAGE" const val EXTRA_HELP_MESSAGE = "com.github.shadowsocks.plugin.EXTRA_HELP_MESSAGE"
/**
* The metadata key to retrieve plugin version. Required for plugin applications.
*
* Constant Value: "com.github.shadowsocks.plugin.version"
*/
const val METADATA_KEY_VERSION = "com.github.shadowsocks.plugin.version"
/** /**
* The metadata key to retrieve plugin id. Required for plugins. * The metadata key to retrieve plugin id. Required for plugins.
* *
......
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