This repository has been archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run hysteria using a plugin-like method
- Loading branch information
Showing
15 changed files
with
621 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.neko.v2ray.dto | ||
|
||
data class Hysteria2Bean( | ||
val server: String?, | ||
val auth: String?, | ||
val lazy: Boolean? = true, | ||
val socks5: Socks5Bean?, | ||
val tls: TlsBean? | ||
) { | ||
data class Socks5Bean( | ||
val listen: String?, | ||
) | ||
|
||
data class TlsBean( | ||
val sni: String? | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/****************************************************************************** | ||
* * | ||
* Copyright (C) 2021 by nekohasekai <contact-sagernet@sekai.icu> * | ||
* Copyright (C) 2021 by Max Lv <max.c.lv@gmail.com> * | ||
* Copyright (C) 2021 by Mygod Studio <contact-shadowsocks-android@mygod.be> * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
******************************************************************************/ | ||
|
||
package com.neko.v2ray.plugin | ||
|
||
import android.content.pm.ResolveInfo | ||
|
||
class NativePlugin(resolveInfo: ResolveInfo) : ResolvedPlugin(resolveInfo) { | ||
init { | ||
check(resolveInfo.providerInfo != null) | ||
} | ||
|
||
override val componentInfo get() = resolveInfo.providerInfo!! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/****************************************************************************** | ||
* * | ||
* Copyright (C) 2021 by nekohasekai <contact-sagernet@sekai.icu> * | ||
* Copyright (C) 2021 by Max Lv <max.c.lv@gmail.com> * | ||
* Copyright (C) 2021 by Mygod Studio <contact-shadowsocks-android@mygod.be> * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
******************************************************************************/ | ||
|
||
package com.neko.v2ray.plugin | ||
|
||
import android.graphics.drawable.Drawable | ||
|
||
abstract class Plugin { | ||
abstract val id: String | ||
abstract val label: CharSequence | ||
abstract val version: Int | ||
abstract val versionName: String | ||
open val icon: Drawable? get() = null | ||
open val defaultConfig: String? get() = null | ||
open val packageName: String get() = "" | ||
open val directBootAware: Boolean get() = true | ||
|
||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
return id == (other as Plugin).id | ||
} | ||
|
||
override fun hashCode() = id.hashCode() | ||
} |
33 changes: 33 additions & 0 deletions
33
app/src/main/kotlin/com/neko/v2ray/plugin/PluginContract.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/****************************************************************************** | ||
* * | ||
* Copyright (C) 2021 by nekohasekai <contact-sagernet@sekai.icu> * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
******************************************************************************/ | ||
|
||
package com.neko.v2ray.plugin | ||
|
||
object PluginContract { | ||
|
||
const val ACTION_NATIVE_PLUGIN = "io.nekohasekai.sagernet.plugin.ACTION_NATIVE_PLUGIN" | ||
const val EXTRA_ENTRY = "io.nekohasekai.sagernet.plugin.EXTRA_ENTRY" | ||
const val METADATA_KEY_ID = "io.nekohasekai.sagernet.plugin.id" | ||
const val METADATA_KEY_EXECUTABLE_PATH = "io.nekohasekai.sagernet.plugin.executable_path" | ||
const val METHOD_GET_EXECUTABLE = "sagernet:getExecutable" | ||
|
||
const val COLUMN_PATH = "path" | ||
const val COLUMN_MODE = "mode" | ||
const val SCHEME = "plugin" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/****************************************************************************** | ||
* * | ||
* Copyright (C) 2021 by nekohasekai <contact-sagernet@sekai.icu> * | ||
* Copyright (C) 2021 by Max Lv <max.c.lv@gmail.com> * | ||
* Copyright (C) 2021 by Mygod Studio <contact-shadowsocks-android@mygod.be> * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
* * | ||
******************************************************************************/ | ||
|
||
package com.neko.v2ray.plugin | ||
|
||
import android.content.Intent | ||
import android.content.pm.PackageManager | ||
import com.neko.v2ray.AngApplication | ||
|
||
class PluginList : ArrayList<Plugin>() { | ||
init { | ||
addAll( | ||
AngApplication.application.packageManager.queryIntentContentProviders( | ||
Intent(PluginContract.ACTION_NATIVE_PLUGIN), PackageManager.GET_META_DATA) | ||
.filter { it.providerInfo.exported }.map { NativePlugin(it) }) | ||
} | ||
|
||
val lookup = mutableMapOf<String, Plugin>().apply { | ||
for (plugin in this@PluginList.toList()) { | ||
fun check(old: Plugin?) { | ||
if (old != null && old != plugin) { | ||
this@PluginList.remove(old) | ||
} | ||
/* if (old != null && old !== plugin) { | ||
val packages = this@PluginList.filter { it.id == plugin.id } | ||
.joinToString { it.packageName } | ||
val message = "Conflicting plugins found from: $packages" | ||
Toast.makeText(SagerNet.application, message, Toast.LENGTH_LONG).show() | ||
throw IllegalStateException(message) | ||
}*/ | ||
} | ||
check(put(plugin.id, plugin)) | ||
} | ||
} | ||
} |
Oops, something went wrong.