Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin 2.0.0 #2585

Merged
merged 6 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,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_arg", "-V")
}
config.put("plugin", path).put("plugin_opts", opts.toString())
}
config.put("local_address", DataStore.listenAddress)
Expand Down
18 changes: 13 additions & 5 deletions core/src/main/java/com/github/shadowsocks/plugin/PluginManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -165,15 +173,15 @@ 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) }
failure = t
}

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
Expand Down
8 changes: 8 additions & 0 deletions plugin/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
* 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)
Expand Down
8 changes: 3 additions & 5 deletions plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions plugin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
Expand Down
2 changes: 1 addition & 1 deletion plugin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down