浏览代码

Fixes & Update README

世界 4 年之前
父节点
当前提交
7158d29db6

+ 1 - 0
.idea/dictionaries/sekai.xml

@@ -4,6 +4,7 @@
       <w>aead</w>
       <w>downlink</w>
       <w>gson</w>
+      <w>nekohasekai</w>
       <w>shadowsocks</w>
       <w>snackbar</w>
       <w>uplink</w>

+ 8 - 0
AUTHORS

@@ -0,0 +1,8 @@
+SagerNet was originally created in late 2021, by
+nekohasekai <[email protected]>.
+
+Here is an inevitably incomplete list of MUCH-APPRECIATED CONTRIBUTORS --
+people who have submitted patches, fixed bugs, added translations, and
+generally made shadowsocks-android that much better:
+
+https://github.com/nekohasekai/SagerNet/graphs/contributors

+ 0 - 10
README

@@ -1,10 +0,0 @@
-SagerNet
-============
-
-The universal proxy toolchain for Android, written in Kotlin.
-
-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/.

+ 36 - 0
README.md

@@ -0,0 +1,36 @@
+# SagerNet for Android
+
+[![API](https://img.shields.io/badge/API-23%2B-brightgreen.svg?style=flat)](https://android-arsenal.com/api?level=23)
+[![Releases](https://img.shields.io/github/downloads/nekohasekai/SagerNet/total.svg)](https://github.com/nekohasekai/SagerNet/releases)
+[![Language: Kotlin](https://img.shields.io/github/languages/top/nekohasekai/SagerNet.svg)](https://github.com/nekohasekai/SagerNet/search?l=kotlin)
+[![License: GPL-3.0](https://img.shields.io/badge/license-GPL--3.0-orange.svg)](https://www.gnu.org/licenses/gpl-3.0)
+
+The universal proxy toolchain for Android, written in Kotlin.
+
+## OPEN SOURCE LICENSES
+
+<ul>
+    <li><a href="https://github.com/shadowsocks/shadowsocks-android">shadowsocks-android</a>: GPL 3.0</li>
+    <li><a href="https://github.com/nekohasekai/AndroidLibV2rayLite">AndroidLibV2rayLite</a>: LGPL 3.0</li>
+</ul>
+
+### LICENSE
+
+```
+Copyright (C) 2021 by nekohasekai <[email protected]>
+Copyright (C) 2017-2021 by Max Lv <[email protected]>
+Copyright (C) 2017-2021 by Mygod Studio <[email protected]>
+
+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/>.
+```

+ 10 - 0
app/build.gradle

@@ -3,6 +3,7 @@ plugins {
     id "kotlin-android"
     id "kotlin-kapt"
     id "kotlin-parcelize"
+    id "com.jaredsburrows.license"
 }
 
 def keystorePwd = null
@@ -120,6 +121,15 @@ android {
 
 }
 
+licenseReport {
+    generateCsvReport = false
+    generateJsonReport = false
+    generateHtmlReport = true
+    copyHtmlReportToAssets = true
+    copyJsonReportToAssets = false
+    copyCsvReportToAssets = false
+}
+
 dependencies {
 
     implementation fileTree(dir: "libs")

+ 1 - 1
app/src/main/java/io/nekohasekai/sagernet/bg/VpnService.kt

@@ -203,7 +203,7 @@ class VpnService : BaseVpnService(), BaseService.Interface {
                 VPN_MTU.toString(),
                 "--sock-path",
                 File(SagerNet.deviceStorage.noBackupFilesDir, "sock_path").canonicalPath,
-                "--loglevel", "debug")
+                "--loglevel", "warning")
         if (DataStore.enableLocalDNS) {
             cmd += "--dnsgw"
             cmd += "127.0.0.1:${DataStore.localDNSPort}"

+ 1 - 1
app/src/main/java/io/nekohasekai/sagernet/database/DataStore.kt

@@ -58,7 +58,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
     var routeMode by configurationStore.string(Key.ROUTE_MODE) { RouteMode.ALL }
     var allowAccess by configurationStore.boolean(Key.ALLOW_ACCESS)
 
-    var enableLocalDNS by configurationStore.boolean(Key.ENABLE_LOCAL_DNS)
+    var enableLocalDNS by configurationStore.boolean(Key.ENABLE_LOCAL_DNS) { true }
     var remoteDNS by configurationStore.string(Key.REMOTE_DNS) { "1.1.1.1" }
     var domesticDns by configurationStore.string(Key.DOMESTIC_DNS) { "9.9.9.11" }
 

+ 11 - 9
app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/VMessFmt.kt

@@ -44,6 +44,8 @@ fun buildV2rayConfig(proxy: ProxyEntity): V2rayConfig {
     val bind = if (DataStore.allowAccess) "0.0.0.0" else "127.0.0.1"
     val remoteDns = DataStore.remoteDNS.split(",")
     val domesticDns = DataStore.domesticDns.split(',')
+    val enableLocalDNS = DataStore.enableLocalDNS
+    val routeMode = DataStore.routeMode
 
     val bean = proxy.requireBean()
 
@@ -61,9 +63,9 @@ fun buildV2rayConfig(proxy: ProxyEntity): V2rayConfig {
                 }
             })
 
-            if (DataStore.enableLocalDNS) {
-                when (DataStore.routeMode) {
-                    RouteMode.BYPASS_LAN, RouteMode.BYPASS_LAN_CHINA -> {
+            if (enableLocalDNS) {
+                when (routeMode) {
+                    RouteMode.BYPASS_CHINA, RouteMode.BYPASS_LAN_CHINA -> {
                         servers.add(DnsObject.StringOrServerObject().apply {
                             valueY = DnsObject.ServerObject().apply {
                                 address = domesticDns.first()
@@ -105,7 +107,7 @@ fun buildV2rayConfig(proxy: ProxyEntity): V2rayConfig {
                     SocksInboundConfigurationObject().apply {
                         auth = "noauth"
                         udp = true
-                        userLevel = 0
+                        userLevel = 8
                     })
             }
         )
@@ -121,7 +123,7 @@ fun buildV2rayConfig(proxy: ProxyEntity): V2rayConfig {
                 settings = LazyInboundConfigurationObject(
                     HTTPInboundConfigurationObject().apply {
                         allowTransparent = true
-                        userLevel = 0
+                        userLevel = 8
                     })
             }
         }
@@ -129,7 +131,7 @@ fun buildV2rayConfig(proxy: ProxyEntity): V2rayConfig {
         outbounds = mutableListOf()
         outbounds.add(
             OutboundObject().apply {
-                tag = "out"
+                tag = TAG_AGENT
                 if (bean is SOCKSBean) {
                     protocol = "socks"
                     settings = LazyOutboundConfigurationObject(
@@ -236,7 +238,7 @@ fun buildV2rayConfig(proxy: ProxyEntity): V2rayConfig {
                 }
             }
 
-            rules.add(RoutingObject.RuleObject().apply {
+           /* rules.add(RoutingObject.RuleObject().apply {
                 inboundTag = mutableListOf(TAG_SOCKS)
 
                 if (requireHttp) {
@@ -245,7 +247,7 @@ fun buildV2rayConfig(proxy: ProxyEntity): V2rayConfig {
 
                 outboundTag = TAG_AGENT
                 type = "field"
-            })
+            })*/
         }
 
         if (DataStore.enableLocalDNS) {
@@ -285,7 +287,7 @@ fun buildV2rayConfig(proxy: ProxyEntity): V2rayConfig {
                 routing.rules.add(0, RoutingObject.RuleObject().apply {
                     type = "field"
                     outboundTag = TAG_AGENT
-                    ip = arrayListOf(remoteDns.first())
+                    ip = listOf(remoteDns.first())
                     port = "53"
                 })
             }

+ 3 - 1
app/src/main/java/io/nekohasekai/sagernet/ui/AppManagerActivity.kt

@@ -54,6 +54,7 @@ import com.google.android.material.chip.Chip
 import com.google.android.material.chip.ChipGroup
 import com.google.android.material.snackbar.Snackbar
 import com.google.android.material.textfield.TextInputEditText
+import com.google.android.material.textfield.TextInputLayout
 import com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView
 import io.nekohasekai.sagernet.R
 import io.nekohasekai.sagernet.SagerNet
@@ -396,7 +397,8 @@ class AppManagerActivity : AppCompatActivity() {
 
                 onMainDispatcher {
                     text.text = (txt + " " + app.packageName + "\n\n" +
-                            chinaApps.map { it.second }.reversed().joinToString("\n", postfix = "\n")).trim()
+                            chinaApps.map { it.second }.reversed()
+                                .joinToString("\n", postfix = "\n")).trim()
                 }
 
                 val dex = File(app.applicationInfo.publicSourceDir)

+ 22 - 53
app/src/main/java/io/nekohasekai/sagernet/ui/SettingsPreferenceFragment.kt

@@ -30,7 +30,6 @@ import androidx.preference.PreferenceFragmentCompat
 import androidx.preference.SwitchPreference
 import io.nekohasekai.sagernet.Key
 import io.nekohasekai.sagernet.R
-import io.nekohasekai.sagernet.RouteMode
 import io.nekohasekai.sagernet.bg.BaseService
 import io.nekohasekai.sagernet.database.DataStore
 import io.nekohasekai.sagernet.database.preference.EditTextPreferenceModifiers
@@ -91,63 +90,33 @@ class SettingsPreferenceFragment : PreferenceFragmentCompat() {
 
             val listener: (BaseService.State) -> Unit = {
                 val stopped = it == BaseService.State.Stopped
-
-                runOnDefaultDispatcher {
-                    val sMode = DataStore.serviceMode
-
-                    listView.post {
-                        persistAcrossReboot.isEnabled = stopped
-                        directBootAware.isEnabled = stopped
-                        serviceMode.isEnabled = stopped
-                        portSocks5.isEnabled = stopped
-                        requireHttp.isEnabled = stopped
-                        portHttp.isEnabled = stopped
-                        forceShadowsocksRust.isEnabled = stopped
-
-                        isProxyApps.isEnabled = sMode == Key.MODE_VPN && stopped
-                        metedNetwork.isEnabled = sMode == Key.MODE_VPN && stopped
-
-                        routeMode.isEnabled = stopped
-                        allowAccess.isEnabled = stopped
-                        remoteDns.isEnabled = stopped
-                        portLocalDns.isEnabled = stopped
-                        domesticDns.isEnabled = stopped
-                        ipv6Route.isEnabled = stopped
-                        preferIpv6.isEnabled = stopped
-                    }
-
-                    when (DataStore.routeMode) {
-                        RouteMode.BYPASS_CHINA, RouteMode.BYPASS_LAN_CHINA -> {
-                            listView.post {
-                                enableLocalDns.isChecked = true
-                                enableLocalDns.isEnabled = false
-                            }
-                        }
-                        else -> {
-                            listView.post {
-                                enableLocalDns.isEnabled = stopped
-                            }
-                        }
-                    }
+                val sMode = DataStore.serviceMode
+
+                listView.post {
+                    persistAcrossReboot.isEnabled = stopped
+                    directBootAware.isEnabled = stopped
+                    serviceMode.isEnabled = stopped
+                    portSocks5.isEnabled = stopped
+                    requireHttp.isEnabled = stopped
+                    portHttp.isEnabled = stopped
+                    forceShadowsocksRust.isEnabled = stopped
+
+                    isProxyApps.isEnabled = sMode == Key.MODE_VPN && stopped
+                    metedNetwork.isEnabled = sMode == Key.MODE_VPN && stopped
+
+                    routeMode.isEnabled = stopped
+                    allowAccess.isEnabled = stopped
+                    remoteDns.isEnabled = stopped
+                    enableLocalDns.isEnabled = stopped
+                    portLocalDns.isEnabled = stopped
+                    domesticDns.isEnabled = stopped
+                    ipv6Route.isEnabled = stopped
+                    preferIpv6.isEnabled = stopped
                 }
             }
 
             listener((activity as MainActivity).state)
             MainActivity.stateListener = listener
-            routeMode.onPreferenceChangeListener =
-                Preference.OnPreferenceChangeListener { _, newValue ->
-                    when (newValue) {
-                        RouteMode.BYPASS_CHINA, RouteMode.BYPASS_LAN_CHINA -> listView.post {
-                            enableLocalDns.isChecked = true
-                            enableLocalDns.isEnabled = false
-                            DataStore.enableLocalDNS = true
-                        }
-                        else -> listView.post {
-                            enableLocalDns.isEnabled = true
-                        }
-                    }
-                    true
-                }
             serviceMode.onPreferenceChangeListener =
                 Preference.OnPreferenceChangeListener { _, newValue ->
                     listView.post {

+ 11 - 11
app/src/main/res/menu/per_app_proxy_menu.xml

@@ -1,21 +1,21 @@
-<menu
-    xmlns:android="http://schemas.android.com/apk/res/android"
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">
-    <item android:id="@+id/action_scan_china_apps"
-          android:title="@string/action_scan_china_apps"
-          android:alphabeticShortcut="a"
-          app:alphabeticModifiers="CTRL|SHIFT"
-          app:showAsAction="never"/>
+    <item
+        android:id="@+id/action_scan_china_apps"
+        android:title="@string/action_scan_china_apps"
+        app:showAsAction="never" />
+    <item
+        android:id="@+id/action_revert_selections"
+        android:title="@string/revert_selections"
+        app:showAsAction="never" />
     <item
         android:id="@+id/action_export_clipboard"
-        android:alphabeticShortcut="c"
         android:icon="?attr/actionModeCopyDrawable"
         android:title="@string/action_export"
-        app:showAsAction="ifRoom"/>
+        app:showAsAction="ifRoom" />
     <item
         android:id="@+id/action_import_clipboard"
-        android:alphabeticShortcut="v"
         android:icon="?attr/actionModePasteDrawable"
         android:title="@string/action_import"
-        app:showAsAction="ifRoom"/>
+        app:showAsAction="ifRoom" />
 </menu>

+ 2 - 0
app/src/main/res/values/strings.xml

@@ -84,11 +84,13 @@
     <string name="off">Off</string>
     <string name="search_apps">Search…</string>
     <string name="scanning">Scanning…</string>
+    <string name="revert_selections">Revert selections</string>
 
     <string name="proxied_apps_mode">Mode</string>
     <string name="bypass_apps">Bypass</string>
     <string name="bypass_apps_summary">Enable this option to bypass selected apps</string>
     <string name="show_system_apps">Show system apps</string>
+    <string name="show_search">Show search</string>
 
     <string name="auto_connect">Auto Connect</string>
     <string name="auto_connect_summary">Enable SagerNet on startup/app update if it was running before</string>

+ 1 - 0
build.gradle

@@ -12,6 +12,7 @@ buildscript {
         classpath "com.android.tools.build:gradle:4.1.3"
         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
         classpath "gradle.plugin.org.mozilla.rust-android-gradle:plugin:0.8.3"
+        classpath 'com.jaredsburrows:gradle-license-plugin:0.8.90'
     }
 }