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 ...@@ -40,6 +40,7 @@ import java.io.File
import java.io.IOException import java.io.IOException
import java.net.* import java.net.*
import java.security.MessageDigest import java.security.MessageDigest
import org.json.JSONArray
/** /**
* This class sets up environment for ss-local. * This class sets up environment for ss-local.
...@@ -102,8 +103,10 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro ...@@ -102,8 +103,10 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
this.configFile = configFile this.configFile = configFile
val config = profile.toJson() val config = profile.toJson()
plugin?.let { (path, opts) -> plugin?.let { (path, opts, isV2) ->
if (service.isVpnService) opts["V"] = "" 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("plugin", path).put("plugin_opts", opts.toString())
} }
config.put("local_address", DataStore.listenAddress) config.put("local_address", DataStore.listenAddress)
......
...@@ -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
......
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: * 1.3.4:
* Optional new metadata `com.github.shadowsocks.plugin.id.aliases` for plugin ID aliases; * 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) (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. ...@@ -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 C](https://github.com/shadowsocks/simple-obfs-android/tree/4f82c4a4e415d666e70a7e2e60955cb0d85c1615);
* [Sample project for Go](https://github.com/shadowsocks/v2ray-plugin-android/tree/172bd4cec0276112828614482fb646b79dbf1540). * [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 In addition to functionalities of a normal plugin, it has to support these additional options:
may get passed through arguments:
* `-V`: VPN mode. In this case, the plugin should pass all file descriptors that needs protecting * `__android_vpn`: VPN mode.
from VPN connections (i.e. its traffic will not be forwarded through the VPN) through an 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`.
ancillary message to `./protect_path`.
### Implement a binary provider ### Implement a binary provider
......
GROUP=com.github.shadowsocks GROUP=com.github.shadowsocks
VERSION_NAME=1.3.4 VERSION_NAME=2.0.0
VERSION_CODE=14 VERSION_CODE=15
POM_ARTIFACT_ID=plugin POM_ARTIFACT_ID=plugin
POM_NAME=Shadowsocks Plugin POM_NAME=Shadowsocks Plugin
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
<application <application
android:theme="@style/Theme.Shadowsocks"> android:theme="@style/Theme.Shadowsocks">
<meta-data android:name="com.github.shadowsocks.plugin.version" <meta-data android:name="com.github.shadowsocks.plugin.version"
android:value="1.3.4"/> android:value="2.0.0"/>
</application> </application>
</manifest> </manifest>
...@@ -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