Skip to content

Commit 95a740c

Browse files
authored
Merge pull request #2585 from shadowsocks/plugin-2.0.0
Plugin 2.0.0
2 parents 1783420 + 02e1181 commit 95a740c

File tree

8 files changed

+40
-16
lines changed

8 files changed

+40
-16
lines changed

core/src/main/java/com/github/shadowsocks/bg/ProxyInstance.kt

+5-2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import java.io.File
4040
import java.io.IOException
4141
import java.net.*
4242
import java.security.MessageDigest
43+
import org.json.JSONArray
4344

4445
/**
4546
* This class sets up environment for ss-local.
@@ -102,8 +103,10 @@ class ProxyInstance(val profile: Profile, private val route: String = profile.ro
102103

103104
this.configFile = configFile
104105
val config = profile.toJson()
105-
plugin?.let { (path, opts) ->
106-
if (service.isVpnService) opts["V"] = ""
106+
plugin?.let { (path, opts, isV2) ->
107+
if (service.isVpnService) {
108+
if (isV2) opts["__android_vpn"] = "" else config.put("plugin_args", JSONArray(arrayOf("-V")))
109+
}
107110
config.put("plugin", path).put("plugin_opts", opts.toString())
108111
}
109112
config.put("local_address", DataStore.listenAddress)

core/src/main/java/com/github/shadowsocks/plugin/PluginManager.kt

+13-5
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,15 @@ object PluginManager {
118118
.build()
119119
fun buildIntent(id: String, action: String): Intent = Intent(action, buildUri(id))
120120

121+
data class InitResult(
122+
val path: String,
123+
val options: PluginOptions,
124+
val isV2: Boolean = false,
125+
)
126+
121127
// the following parts are meant to be used by :bg
122128
@Throws(Throwable::class)
123-
fun init(configuration: PluginConfiguration): Pair<String, PluginOptions>? {
129+
fun init(configuration: PluginConfiguration): InitResult? {
124130
if (configuration.selected.isEmpty()) return null
125131
var throwable: Throwable? = null
126132

@@ -136,7 +142,7 @@ object PluginManager {
136142
throw throwable ?: PluginNotFoundException(configuration.selected)
137143
}
138144

139-
private fun initNative(configuration: PluginConfiguration): Pair<String, PluginOptions>? {
145+
private fun initNative(configuration: PluginConfiguration): InitResult? {
140146
var flags = PackageManager.GET_META_DATA
141147
if (Build.VERSION.SDK_INT >= 24) {
142148
flags = flags or PackageManager.MATCH_DIRECT_BOOT_UNAWARE or PackageManager.MATCH_DIRECT_BOOT_AWARE
@@ -152,9 +158,11 @@ object PluginManager {
152158
}
153159
val provider = providers.single().providerInfo
154160
val options = configuration.getOptions { provider.loadString(PluginContract.METADATA_KEY_DEFAULT_CONFIG) }
161+
val isV2 = provider.applicationInfo.metaData?.getString(PluginContract.METADATA_KEY_VERSION)
162+
?.substringBefore('.')?.toIntOrNull() ?: 0 >= 2
155163
var failure: Throwable? = null
156164
try {
157-
initNativeFaster(provider)?.also { return it to options }
165+
initNativeFaster(provider)?.also { return InitResult(it, options, isV2) }
158166
} catch (t: Throwable) {
159167
Timber.w("Initializing native plugin faster mode failed")
160168
failure = t
@@ -165,15 +173,15 @@ object PluginManager {
165173
authority(provider.authority)
166174
}.build()
167175
try {
168-
return initNativeFast(app.contentResolver, options, uri)?.let { it to options }
176+
return initNativeFast(app.contentResolver, options, uri)?.let { InitResult(it, options, isV2) }
169177
} catch (t: Throwable) {
170178
Timber.w("Initializing native plugin fast mode failed")
171179
failure?.also { t.addSuppressed(it) }
172180
failure = t
173181
}
174182

175183
try {
176-
return initNativeSlow(app.contentResolver, options, uri)?.let { it to options }
184+
return initNativeSlow(app.contentResolver, options, uri)?.let { InitResult(it, options, isV2) }
177185
} catch (t: Throwable) {
178186
failure?.also { t.addSuppressed(it) }
179187
throw t

plugin/CHANGES.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
* 2.0.0:
2+
* Deprecated passing `-V` and `--fast-open` to plugin.
3+
Please find `__android_vpn` option passed via plugin options.
4+
* Dependency updates:
5+
- `androidx.core:core-ktx:1.3.2`;
6+
- `androidx.drawerlayout:drawerlayout:1.1.1`;
7+
- `com.google.android.material:material:1.2.1`;
8+
- `org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.10`.
19
* 1.3.4:
210
* Optional new metadata `com.github.shadowsocks.plugin.id.aliases` for plugin ID aliases;
311
(see doc for `PluginContract.METADATA_KEY_ID_ALIASES` and main documentation "Plugin ID Aliasing" for more information)

plugin/README.md

+3-5
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,10 @@ First you need to get your native binary compiling on Android platform.
4545
* [Sample project for C](https://github.com/shadowsocks/simple-obfs-android/tree/4f82c4a4e415d666e70a7e2e60955cb0d85c1615);
4646
* [Sample project for Go](https://github.com/shadowsocks/v2ray-plugin-android/tree/172bd4cec0276112828614482fb646b79dbf1540).
4747

48-
In addition to functionalities of a normal plugin, it has to support these additional flags that
49-
may get passed through arguments:
48+
In addition to functionalities of a normal plugin, it has to support these additional options:
5049

51-
* `-V`: VPN mode. In this case, the plugin should pass all file descriptors that needs protecting
52-
from VPN connections (i.e. its traffic will not be forwarded through the VPN) through an
53-
ancillary message to `./protect_path`.
50+
* `__android_vpn`: VPN mode.
51+
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`.
5452

5553
### Implement a binary provider
5654

plugin/gradle.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
GROUP=com.github.shadowsocks
2-
VERSION_NAME=1.3.4
3-
VERSION_CODE=14
2+
VERSION_NAME=2.0.0
3+
VERSION_CODE=15
44

55
POM_ARTIFACT_ID=plugin
66
POM_NAME=Shadowsocks Plugin

plugin/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<application
44
android:theme="@style/Theme.Shadowsocks">
55
<meta-data android:name="com.github.shadowsocks.plugin.version"
6-
android:value="1.3.4"/>
6+
android:value="2.0.0"/>
77
</application>
88
</manifest>

plugin/src/main/java/com/github/shadowsocks/plugin/PluginContract.kt

+7
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ object PluginContract {
7272
</host_name> */
7373
const val EXTRA_HELP_MESSAGE = "com.github.shadowsocks.plugin.EXTRA_HELP_MESSAGE"
7474

75+
/**
76+
* The metadata key to retrieve plugin version. Required for plugin applications.
77+
*
78+
* Constant Value: "com.github.shadowsocks.plugin.version"
79+
*/
80+
const val METADATA_KEY_VERSION = "com.github.shadowsocks.plugin.version"
81+
7582
/**
7683
* The metadata key to retrieve plugin id. Required for plugins.
7784
*

0 commit comments

Comments
 (0)