Unverified Commit 95a740c3 authored by Max Lv's avatar Max Lv Committed by GitHub

Merge pull request #2585 from shadowsocks/plugin-2.0.0

Plugin 2.0.0
parents 1783420a 02e11818
......@@ -40,6 +40,7 @@ import java.io.File
import java.io.IOException
import java.net.*
import java.security.MessageDigest
import org.json.JSONArray
/**
* This class sets up environment for ss-local.
......@@ -102,8 +103,10 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
this.configFile = configFile
val config = profile.toJson()
plugin?.let { (path, opts) ->
if (service.isVpnService) opts["V"] = ""
plugin?.let { (path, opts, isV2) ->
if (service.isVpnService) {
if (isV2) opts["__android_vpn"] = "" else config.put("plugin_args", JSONArray(arrayOf("-V")))
}
config.put("plugin", path).put("plugin_opts", opts.toString())
}
config.put("local_address", DataStore.listenAddress)
......
......@@ -118,9 +118,15 @@ object PluginManager {
.build()
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
@Throws(Throwable::class)
fun init(configuration: PluginConfiguration): Pair<String, PluginOptions>? {
fun init(configuration: PluginConfiguration): InitResult? {
if (configuration.selected.isEmpty()) return null
var throwable: Throwable? = null
......@@ -136,7 +142,7 @@ object PluginManager {
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
if (Build.VERSION.SDK_INT >= 24) {
flags = flags or PackageManager.MATCH_DIRECT_BOOT_UNAWARE or PackageManager.MATCH_DIRECT_BOOT_AWARE
......@@ -152,9 +158,11 @@ object PluginManager {
}
val provider = providers.single().providerInfo
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
try {
initNativeFaster(provider)?.also { return it to options }
initNativeFaster(provider)?.also { return InitResult(it, options, isV2) }
} catch (t: Throwable) {
Timber.w("Initializing native plugin faster mode failed")
failure = t
......@@ -165,7 +173,7 @@ object PluginManager {
authority(provider.authority)
}.build()
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) {
Timber.w("Initializing native plugin fast mode failed")
failure?.also { t.addSuppressed(it) }
......@@ -173,7 +181,7 @@ object PluginManager {
}
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) {
failure?.also { t.addSuppressed(it) }
throw t
......
Subproject commit 988e69d4dab676df9a61daf692765c353f5eb6f9
Subproject commit 91142cb57d142402b44cfa3923b025fe68e36f9b
* 2.0.0:
* Deprecated passing `-V` and `--fast-open` to plugin.
Please find `__android_vpn` option passed via plugin options.
* Dependency updates:
- `androidx.core:core-ktx:1.3.2`;
- `androidx.drawerlayout:drawerlayout:1.1.1`;
- `com.google.android.material:material:1.2.1`;
- `org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10`.
* 1.3.4:
* Optional new metadata `com.github.shadowsocks.plugin.id.aliases` for plugin ID aliases;
(see doc for `PluginContract.METADATA_KEY_ID_ALIASES` and main documentation "Plugin ID Aliasing" for more information)
......
......@@ -45,12 +45,10 @@ First you need to get your native binary compiling on Android platform.
* [Sample project for C](https://github.com/shadowsocks/simple-obfs-android/tree/4f82c4a4e415d666e70a7e2e60955cb0d85c1615);
* [Sample project for Go](https://github.com/shadowsocks/v2ray-plugin-android/tree/172bd4cec0276112828614482fb646b79dbf1540).
In addition to functionalities of a normal plugin, it has to support these additional flags that
may get passed through arguments:
In addition to functionalities of a normal plugin, it has to support these additional options:
* `-V`: VPN mode. In this case, the plugin should pass all file descriptors that needs protecting
from VPN connections (i.e. its traffic will not be forwarded through the VPN) through an
ancillary message to `./protect_path`.
* `__android_vpn`: VPN mode.
In this case, the plugin should pass all file descriptors that needs protecting from VPN connections (i.e. its traffic will not be forwarded through the VPN) through an ancillary message to `./protect_path`.
### Implement a binary provider
......
GROUP=com.github.shadowsocks
VERSION_NAME=1.3.4
VERSION_CODE=14
VERSION_NAME=2.0.0
VERSION_CODE=15
POM_ARTIFACT_ID=plugin
POM_NAME=Shadowsocks Plugin
......
......@@ -3,6 +3,6 @@
<application
android:theme="@style/Theme.Shadowsocks">
<meta-data android:name="com.github.shadowsocks.plugin.version"
android:value="1.3.4"/>
android:value="2.0.0"/>
</application>
</manifest>
......@@ -72,6 +72,13 @@ object PluginContract {
</host_name> */
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.
*
......
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