Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
com.ccwangluo.accelerator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sheteng
com.ccwangluo.accelerator
Commits
e9524620
Commit
e9524620
authored
May 08, 2019
by
Mygod
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into q-beta
parents
fa6eee94
8889d8e0
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
31 changed files
with
585 additions
and
303 deletions
+585
-303
build.gradle
build.gradle
+0
-1
core/build.gradle
core/build.gradle
+1
-2
core/src/main/java/com/github/shadowsocks/VpnRequestActivity.kt
...rc/main/java/com/github/shadowsocks/VpnRequestActivity.kt
+1
-0
core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt
...rc/main/java/com/github/shadowsocks/bg/LocalDnsService.kt
+4
-1
core/src/main/java/com/github/shadowsocks/database/Profile.kt
.../src/main/java/com/github/shadowsocks/database/Profile.kt
+1
-1
core/src/main/java/com/github/shadowsocks/net/HostsFile.kt
core/src/main/java/com/github/shadowsocks/net/HostsFile.kt
+39
-0
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
...rc/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
+22
-10
core/src/main/java/com/github/shadowsocks/preference/DataStore.kt
.../main/java/com/github/shadowsocks/preference/DataStore.kt
+1
-1
core/src/main/java/com/github/shadowsocks/preference/EditTextPreferenceModifiers.kt
...hub/shadowsocks/preference/EditTextPreferenceModifiers.kt
+45
-0
core/src/main/java/com/github/shadowsocks/preference/HostsSummaryProvider.kt
...com/github/shadowsocks/preference/HostsSummaryProvider.kt
+33
-0
core/src/main/java/com/github/shadowsocks/preference/OnPreferenceDataStoreChangeListener.kt
...owsocks/preference/OnPreferenceDataStoreChangeListener.kt
+1
-1
core/src/main/java/com/github/shadowsocks/utils/Constants.kt
core/src/main/java/com/github/shadowsocks/utils/Constants.kt
+1
-0
core/src/main/java/com/github/shadowsocks/utils/Utils.kt
core/src/main/java/com/github/shadowsocks/utils/Utils.kt
+3
-0
core/src/main/res/values/strings.xml
core/src/main/res/values/strings.xml
+4
-1
gradle.properties
gradle.properties
+1
-1
mobile/build.gradle
mobile/build.gradle
+2
-2
mobile/src/main/java/com/github/shadowsocks/App.kt
mobile/src/main/java/com/github/shadowsocks/App.kt
+0
-5
mobile/src/main/java/com/github/shadowsocks/GlobalSettingsPreferenceFragment.kt
...om/github/shadowsocks/GlobalSettingsPreferenceFragment.kt
+57
-18
mobile/src/main/java/com/github/shadowsocks/MainActivity.kt
mobile/src/main/java/com/github/shadowsocks/MainActivity.kt
+1
-1
mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt
...main/java/com/github/shadowsocks/ProfileConfigFragment.kt
+40
-33
mobile/src/main/java/com/github/shadowsocks/preference/BottomSheetPreferenceDialogFragment.kt
...owsocks/preference/BottomSheetPreferenceDialogFragment.kt
+5
-0
mobile/src/main/java/com/github/shadowsocks/preference/BrowsableEditTextPreferenceDialogFragment.kt
...s/preference/BrowsableEditTextPreferenceDialogFragment.kt
+50
-0
mobile/src/main/java/com/github/shadowsocks/preference/IconListPreference.kt
...a/com/github/shadowsocks/preference/IconListPreference.kt
+9
-6
mobile/src/main/java/com/github/shadowsocks/preference/PluginConfigurationDialogFragment.kt
...adowsocks/preference/PluginConfigurationDialogFragment.kt
+8
-2
mobile/src/main/res/layout/preference_dialog_password.xml
mobile/src/main/res/layout/preference_dialog_password.xml
+44
-0
mobile/src/main/res/xml/pref_global.xml
mobile/src/main/res/xml/pref_global.xml
+38
-46
mobile/src/main/res/xml/pref_profile.xml
mobile/src/main/res/xml/pref_profile.xml
+68
-74
plugin/src/main/res/values/strings.xml
plugin/src/main/res/values/strings.xml
+2
-0
tv/build.gradle
tv/build.gradle
+1
-1
tv/src/main/java/com/github/shadowsocks/tv/MainPreferenceFragment.kt
.../java/com/github/shadowsocks/tv/MainPreferenceFragment.kt
+55
-40
tv/src/main/res/xml/pref_main.xml
tv/src/main/res/xml/pref_main.xml
+48
-56
No files found.
build.gradle
View file @
e9524620
...
...
@@ -8,7 +8,6 @@ buildscript {
minSdkVersion
=
21
sdkVersion
=
28
compileSdkVersion
=
'android-Q'
preferencexVersion
=
'1.0.0'
junitVersion
=
'4.12'
androidTestVersion
=
'1.1.1'
androidEspressoVersion
=
'3.1.1'
...
...
core/build.gradle
View file @
e9524620
...
...
@@ -48,13 +48,12 @@ dependencies {
api
project
(
':plugin'
)
api
"androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
api
"androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycleVersion"
api
'androidx.preference:preference:1.
0.0
'
api
'androidx.preference:preference:1.
1.0-alpha05
'
api
"androidx.room:room-runtime:$roomVersion"
api
'androidx.work:work-runtime-ktx:2.0.1'
api
'com.crashlytics.sdk.android:crashlytics:2.10.0'
api
'com.google.firebase:firebase-config:17.0.0'
api
'com.google.firebase:firebase-core:16.0.9'
api
"com.takisoft.preferencex:preferencex:$preferencexVersion"
api
'dnsjava:dnsjava:2.1.8'
api
'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.2.1'
api
'org.connectbot.jsocks:jsocks:1.0.0'
...
...
core/src/main/java/com/github/shadowsocks/VpnRequestActivity.kt
View file @
e9524620
...
...
@@ -63,6 +63,7 @@ class VpnRequestActivity : AppCompatActivity() {
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
if
(
requestCode
!=
REQUEST_CONNECT
)
return
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
if
(
resultCode
==
RESULT_OK
)
Core
.
startService
()
else
{
Toast
.
makeText
(
this
,
R
.
string
.
vpn_permission_denied
,
Toast
.
LENGTH_LONG
).
show
()
Crashlytics
.
log
(
Log
.
ERROR
,
TAG
,
"Failed to start VpnService from onActivityResult: $data"
)
...
...
core/src/main/java/com/github/shadowsocks/bg/LocalDnsService.kt
View file @
e9524620
...
...
@@ -23,10 +23,12 @@ package com.github.shadowsocks.bg
import
com.github.shadowsocks.Core.app
import
com.github.shadowsocks.acl.Acl
import
com.github.shadowsocks.core.R
import
com.github.shadowsocks.net.HostsFile
import
com.github.shadowsocks.net.LocalDnsServer
import
com.github.shadowsocks.net.Socks5Endpoint
import
com.github.shadowsocks.net.Subnet
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.utils.Key
import
kotlinx.coroutines.CoroutineScope
import
java.net.InetSocketAddress
import
java.net.URI
...
...
@@ -49,7 +51,8 @@ object LocalDnsService {
val
dns
=
URI
(
"dns://${profile.remoteDns}"
)
LocalDnsServer
(
this
::
resolver
,
Socks5Endpoint
(
dns
.
host
,
if
(
dns
.
port
<
0
)
53
else
dns
.
port
),
DataStore
.
proxyAddress
).
apply
{
DataStore
.
proxyAddress
,
HostsFile
(
DataStore
.
publicStore
.
getString
(
Key
.
hosts
)
?:
""
)).
apply
{
tcp
=
!
profile
.
udpdns
when
(
profile
.
route
)
{
Acl
.
BYPASS_CHN
,
Acl
.
BYPASS_LAN_CHN
,
Acl
.
GFWLIST
,
Acl
.
CUSTOM_RULES
->
{
...
...
core/src/main/java/com/github/shadowsocks/database/Profile.kt
View file @
e9524620
...
...
@@ -87,7 +87,7 @@ data class Profile(
if
(
match
!=
null
)
{
val
profile
=
Profile
()
feature
?.
copyFeatureSettingsTo
(
profile
)
profile
.
method
=
match
.
groupValues
[
1
].
toLowerCase
()
profile
.
method
=
match
.
groupValues
[
1
].
toLowerCase
(
Locale
.
ENGLISH
)
profile
.
password
=
match
.
groupValues
[
2
]
profile
.
host
=
match
.
groupValues
[
3
]
profile
.
remotePort
=
match
.
groupValues
[
4
].
toInt
()
...
...
core/src/main/java/com/github/shadowsocks/net/HostsFile.kt
0 → 100644
View file @
e9524620
/*******************************************************************************
* *
* Copyright (C) 2019 by Max Lv <max.c.lv@gmail.com> *
* Copyright (C) 2019 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.github.shadowsocks.net
import
com.github.shadowsocks.utils.computeIfAbsentCompat
import
com.github.shadowsocks.utils.parseNumericAddress
import
java.net.InetAddress
class
HostsFile
(
input
:
String
=
""
)
{
private
val
map
=
mutableMapOf
<
String
,
MutableSet
<
InetAddress
>>()
init
{
for
(
line
in
input
.
lineSequence
())
{
val
entries
=
line
.
substringBefore
(
'#'
).
splitToSequence
(
' '
,
'\t'
).
filter
{
it
.
isNotEmpty
()
}
val
address
=
entries
.
firstOrNull
()
?.
parseNumericAddress
()
?:
continue
for
(
hostname
in
entries
.
drop
(
1
))
map
.
computeIfAbsentCompat
(
hostname
)
{
LinkedHashSet
(
1
)
}.
add
(
address
)
}
}
val
configuredHostnames
get
()
=
map
.
size
fun
resolve
(
hostname
:
String
)
=
map
[
hostname
]
?.
shuffled
()
?:
emptyList
()
}
core/src/main/java/com/github/shadowsocks/net/LocalDnsServer.kt
View file @
e9524620
...
...
@@ -43,7 +43,9 @@ import java.nio.channels.SocketChannel
* https://github.com/shadowsocks/overture/tree/874f22613c334a3b78e40155a55479b7b69fee04
*/
class
LocalDnsServer
(
private
val
localResolver
:
suspend
(
String
)
->
Array
<
InetAddress
>,
private
val
remoteDns
:
Socks5Endpoint
,
private
val
proxy
:
SocketAddress
)
:
CoroutineScope
{
private
val
remoteDns
:
Socks5Endpoint
,
private
val
proxy
:
SocketAddress
,
private
val
hosts
:
HostsFile
)
:
CoroutineScope
{
/**
* Forward all requests to remote and ignore localResolver.
*/
...
...
@@ -70,7 +72,18 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
if
(
request
.
header
.
getFlag
(
Flags
.
RD
.
toInt
()))
header
.
setFlag
(
Flags
.
RD
.
toInt
())
request
.
question
?.
also
{
addRecord
(
it
,
Section
.
QUESTION
)
}
}
private
fun
cookDnsResponse
(
request
:
Message
,
results
:
Iterable
<
InetAddress
>)
=
ByteBuffer
.
wrap
(
prepareDnsResponse
(
request
).
apply
{
header
.
setFlag
(
Flags
.
RA
.
toInt
())
// recursion available
for
(
address
in
results
)
addRecord
(
when
(
address
)
{
is
Inet4Address
->
ARecord
(
question
.
name
,
DClass
.
IN
,
TTL
,
address
)
is
Inet6Address
->
AAAARecord
(
question
.
name
,
DClass
.
IN
,
TTL
,
address
)
else
->
throw
IllegalStateException
(
"Unsupported address $address"
)
},
Section
.
ANSWER
)
}.
toWire
())
}
private
val
monitor
=
ChannelMonitor
()
override
val
coroutineContext
=
SupervisorJob
()
+
CoroutineExceptionHandler
{
_
,
t
->
printLog
(
t
)
}
...
...
@@ -101,10 +114,16 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
return
super
visorScope
{
val
remote
=
async
{
withTimeout
(
TIMEOUT
)
{
forward
(
packet
)
}
}
try
{
if
(
forwardOnly
||
request
.
header
.
opcode
!=
Opcode
.
QUERY
)
return
@supervisorScope
remote
.
await
()
if
(
request
.
header
.
opcode
!=
Opcode
.
QUERY
)
return
@supervisorScope
remote
.
await
()
val
question
=
request
.
question
if
(
question
?.
type
!=
Type
.
A
)
return
@supervisorScope
remote
.
await
()
val
host
=
question
.
name
.
toString
(
true
)
val
hostsResults
=
hosts
.
resolve
(
host
)
if
(
hostsResults
.
isNotEmpty
())
{
remote
.
cancel
()
return
@supervisorScope
cookDnsResponse
(
request
,
hostsResults
)
}
if
(
forwardOnly
)
return
@supervisorScope
remote
.
await
()
if
(
remoteDomainMatcher
?.
containsMatchIn
(
host
)
==
true
)
return
@supervisorScope
remote
.
await
()
val
localResults
=
try
{
withTimeout
(
TIMEOUT
)
{
localResolver
(
host
)
}
...
...
@@ -117,14 +136,7 @@ class LocalDnsServer(private val localResolver: suspend (String) -> Array<InetAd
if
(
localResults
.
isEmpty
())
return
@supervisorScope
remote
.
await
()
if
(
localIpMatcher
.
isEmpty
()
||
localIpMatcher
.
any
{
subnet
->
localResults
.
any
(
subnet
::
matches
)
})
{
remote
.
cancel
()
ByteBuffer
.
wrap
(
prepareDnsResponse
(
request
).
apply
{
header
.
setFlag
(
Flags
.
RA
.
toInt
())
// recursion available
for
(
address
in
localResults
)
addRecord
(
when
(
address
)
{
is
Inet4Address
->
ARecord
(
question
.
name
,
DClass
.
IN
,
TTL
,
address
)
is
Inet6Address
->
AAAARecord
(
question
.
name
,
DClass
.
IN
,
TTL
,
address
)
else
->
throw
IllegalStateException
(
"Unsupported address $address"
)
},
Section
.
ANSWER
)
}.
toWire
())
cookDnsResponse
(
request
,
localResults
.
asIterable
())
}
else
remote
.
await
()
}
catch
(
e
:
Exception
)
{
remote
.
cancel
()
...
...
core/src/main/java/com/github/shadowsocks/preference/DataStore.kt
View file @
e9524620
...
...
@@ -42,7 +42,7 @@ object DataStore : OnPreferenceDataStoreChangeListener {
publicStore
.
registerChangeListener
(
this
)
}
override
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
?
)
{
override
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
)
{
when
(
key
)
{
Key
.
id
->
if
(
directBootAware
)
DirectBoot
.
update
()
}
...
...
core/src/main/java/com/github/shadowsocks/preference/EditTextPreferenceModifiers.kt
0 → 100644
View file @
e9524620
/*******************************************************************************
* *
* Copyright (C) 2019 by Max Lv <max.c.lv@gmail.com> *
* Copyright (C) 2019 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.github.shadowsocks.preference
import
android.graphics.Typeface
import
android.text.InputFilter
import
android.view.inputmethod.EditorInfo
import
android.widget.EditText
import
androidx.preference.EditTextPreference
object
EditTextPreferenceModifiers
{
object
Monospace
:
EditTextPreference
.
OnBindEditTextListener
{
override
fun
onBindEditText
(
editText
:
EditText
)
{
editText
.
typeface
=
Typeface
.
MONOSPACE
}
}
object
Port
:
EditTextPreference
.
OnBindEditTextListener
{
private
val
portLengthFilter
=
arrayOf
(
InputFilter
.
LengthFilter
(
5
))
override
fun
onBindEditText
(
editText
:
EditText
)
{
editText
.
inputType
=
EditorInfo
.
TYPE_CLASS_NUMBER
editText
.
filters
=
portLengthFilter
editText
.
setSingleLine
()
}
}
}
core/src/main/java/com/github/shadowsocks/preference/HostsSummaryProvider.kt
0 → 100644
View file @
e9524620
/*******************************************************************************
* *
* Copyright (C) 2019 by Max Lv <max.c.lv@gmail.com> *
* Copyright (C) 2019 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.github.shadowsocks.preference
import
androidx.preference.EditTextPreference
import
androidx.preference.Preference
import
com.github.shadowsocks.core.R
import
com.github.shadowsocks.net.HostsFile
object
HostsSummaryProvider
:
Preference
.
SummaryProvider
<
EditTextPreference
>
{
override
fun
provideSummary
(
preference
:
EditTextPreference
?):
CharSequence
{
val
count
=
HostsFile
(
preference
!!
.
text
?:
""
).
configuredHostnames
return
preference
.
context
.
resources
.
getQuantityString
(
R
.
plurals
.
hosts_summary
,
count
,
count
)
}
}
core/src/main/java/com/github/shadowsocks/preference/OnPreferenceDataStoreChangeListener.kt
View file @
e9524620
...
...
@@ -23,5 +23,5 @@ package com.github.shadowsocks.preference
import
androidx.preference.PreferenceDataStore
interface
OnPreferenceDataStoreChangeListener
{
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
?
)
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
)
}
core/src/main/java/com/github/shadowsocks/utils/Constants.kt
View file @
e9524620
...
...
@@ -65,6 +65,7 @@ object Key {
const
val
dirty
=
"profileDirty"
const
val
tfo
=
"tcp_fastopen"
const
val
hosts
=
"hosts"
const
val
assetUpdateTime
=
"assetUpdateTime"
// TV specific values
...
...
core/src/main/java/com/github/shadowsocks/utils/Utils.kt
View file @
e9524620
...
...
@@ -61,6 +61,9 @@ fun String?.parseNumericAddress(): InetAddress? = Os.inet_pton(OsConstants.AF_IN
if
(
BuildCompat
.
isAtLeastQ
())
it
else
parseNumericAddress
.
invoke
(
null
,
this
)
as
InetAddress
}
fun
<
K
,
V
>
MutableMap
<
K
,
V
>.
computeIfAbsentCompat
(
key
:
K
,
value
:
()
->
V
)
=
if
(
Build
.
VERSION
.
SDK_INT
>=
24
)
computeIfAbsent
(
key
)
{
value
()
}
else
this
[
key
]
?:
value
().
also
{
put
(
key
,
it
)
}
fun
HttpURLConnection
.
disconnectFromMain
()
{
if
(
Build
.
VERSION
.
SDK_INT
>=
26
)
disconnect
()
else
GlobalScope
.
launch
(
Dispatchers
.
IO
)
{
disconnect
()
}
}
...
...
core/src/main/res/values/strings.xml
View file @
e9524620
...
...
@@ -61,6 +61,10 @@
<string
name=
"tcp_fastopen_summary"
>
Toggling might require ROOT permission
</string>
<string
name=
"tcp_fastopen_summary_unsupported"
>
Unsupported kernel version: %s
<
3.7.1
</string>
<string
name=
"tcp_fastopen_failure"
>
Toggle failed
</string>
<plurals
name=
"hosts_summary"
>
<item
quantity=
"one"
>
1 hostname configured
</item>
<item
quantity=
"other"
>
%d hostnames configured
</item>
</plurals>
<string
name=
"udp_dns"
>
Send DNS over UDP
</string>
<string
name=
"udp_dns_summary"
>
Requires UDP forwarding on server side
</string>
<string
name=
"udp_fallback"
>
UDP Fallback
</string>
...
...
@@ -82,7 +86,6 @@
<!-- alert category -->
<string
name=
"profile_empty"
>
Please select a profile
</string>
<string
name=
"proxy_empty"
>
Proxy/Password should not be empty
</string>
<string
name=
"file_manager_missing"
>
Please install a file manager like MiXplorer
</string>
<string
name=
"connect"
>
Connect
</string>
<!-- menu category -->
...
...
gradle.properties
View file @
e9524620
...
...
@@ -10,7 +10,7 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier
=
true
#
android.enableR8.fullMode=true
android.enableR8.fullMode
=
true
android.useAndroidX
=
true
# When configured, Gradle will run in incubating parallel mode.
...
...
mobile/build.gradle
View file @
e9524620
...
...
@@ -55,11 +55,11 @@ androidExtensions {
dependencies
{
implementation
project
(
':core'
)
implementation
"androidx.browser:browser:1.0.0"
implementation
'androidx.browser:browser:1.0.0'
implementation
'androidx.constraintlayout:constraintlayout:1.1.3'
implementation
'com.google.android.gms:play-services-vision:17.0.2'
implementation
'com.google.firebase:firebase-ads:17.2.0'
implementation
"com.takisoft.preferencex:preferencex-simplemenu:$preferencexVersion"
implementation
'com.takisoft.preferencex:preferencex-simplemenu:1.0.0'
implementation
'com.twofortyfouram:android-plugin-api-for-locale:1.0.4'
implementation
'net.glxn.qrgen:android:2.0'
implementation
'xyz.belvi.mobilevision:barcodescanner:2.0.3'
...
...
mobile/src/main/java/com/github/shadowsocks/App.kt
View file @
e9524620
...
...
@@ -23,17 +23,12 @@ package com.github.shadowsocks
import
android.app.Application
import
android.content.res.Configuration
import
androidx.appcompat.app.AppCompatDelegate
import
com.github.shadowsocks.preference.BottomSheetPreferenceDialogFragment
import
com.github.shadowsocks.preference.IconListPreference
import
com.takisoft.preferencex.PreferenceFragmentCompat
class
App
:
Application
()
{
override
fun
onCreate
()
{
super
.
onCreate
()
Core
.
init
(
this
,
MainActivity
::
class
)
AppCompatDelegate
.
setCompatVectorFromResourcesEnabled
(
true
)
PreferenceFragmentCompat
.
registerPreferenceFragment
(
IconListPreference
::
class
.
java
,
BottomSheetPreferenceDialogFragment
::
class
.
java
)
}
override
fun
onConfigurationChanged
(
newConfig
:
Configuration
)
{
...
...
mobile/src/main/java/com/github/shadowsocks/GlobalSettingsPreferenceFragment.kt
View file @
e9524620
...
...
@@ -20,24 +20,37 @@
package
com.github.shadowsocks
import
android.app.Activity
import
android.content.Intent
import
android.os.Build
import
android.os.Bundle
import
androidx.preference.EditTextPreference
import
androidx.preference.Preference
import
androidx.preference.PreferenceFragmentCompat
import
androidx.preference.SwitchPreference
import
com.github.shadowsocks.bg.BaseService
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.utils.DirectBoot
import
com.github.shadowsocks.utils.Key
import
com.github.shadowsocks.net.TcpFastOpen
import
com.github.shadowsocks.preference.BrowsableEditTextPreferenceDialogFragment
import
com.github.shadowsocks.preference.EditTextPreferenceModifiers
import
com.github.shadowsocks.preference.HostsSummaryProvider
import
com.github.shadowsocks.utils.readableMessage
import
com.github.shadowsocks.utils.remove
import
com.takisoft.preferencex.PreferenceFragmentCompat
class
GlobalSettingsPreferenceFragment
:
PreferenceFragmentCompat
()
{
override
fun
onCreatePreferencesFix
(
savedInstanceState
:
Bundle
?,
rootKey
:
String
?)
{
companion
object
{
private
const
val
REQUEST_BROWSE
=
1
}
private
val
hosts
by
lazy
{
findPreference
<
EditTextPreference
>(
Key
.
hosts
)
!!
}
override
fun
onCreatePreferences
(
savedInstanceState
:
Bundle
?,
rootKey
:
String
?)
{
preferenceManager
.
preferenceDataStore
=
DataStore
.
publicStore
DataStore
.
initGlobal
()
addPreferencesFromResource
(
R
.
xml
.
pref_global
)
val
boot
=
findPreference
(
Key
.
isAutoConnect
)
as
SwitchPreference
val
boot
=
findPreference
<
SwitchPreference
>(
Key
.
isAutoConnect
)
!!
boot
.
setOnPreferenceChangeListener
{
_
,
value
->
BootReceiver
.
enabled
=
value
as
Boolean
true
...
...
@@ -45,13 +58,13 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
boot
.
isChecked
=
BootReceiver
.
enabled
if
(
Build
.
VERSION
.
SDK_INT
>=
24
)
boot
.
setSummary
(
R
.
string
.
auto_connect_summary_v24
)
val
canToggleLocked
=
findPreference
(
Key
.
directBootAware
)
val
canToggleLocked
=
findPreference
<
Preference
>(
Key
.
directBootAware
)
!!
if
(
Build
.
VERSION
.
SDK_INT
>=
24
)
canToggleLocked
.
setOnPreferenceChangeListener
{
_
,
newValue
->
if
(
Core
.
directBootSupported
&&
newValue
as
Boolean
)
DirectBoot
.
update
()
else
DirectBoot
.
clean
()
true
}
else
canToggleLocked
.
remove
()
val
tfo
=
findPreference
(
Key
.
tfo
)
as
SwitchPreference
val
tfo
=
findPreference
<
SwitchPreference
>(
Key
.
tfo
)
!!
tfo
.
isChecked
=
DataStore
.
tcpFastOpen
tfo
.
setOnPreferenceChangeListener
{
_
,
value
->
if
(
value
as
Boolean
&&
!
TcpFastOpen
.
sendEnabled
)
{
...
...
@@ -68,10 +81,15 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
tfo
.
summary
=
getString
(
R
.
string
.
tcp_fastopen_summary_unsupported
,
System
.
getProperty
(
"os.version"
))
}
val
serviceMode
=
findPreference
(
Key
.
serviceMode
)
val
portProxy
=
findPreference
(
Key
.
portProxy
)
val
portLocalDns
=
findPreference
(
Key
.
portLocalDns
)
val
portTransproxy
=
findPreference
(
Key
.
portTransproxy
)
hosts
.
onBindEditTextListener
=
EditTextPreferenceModifiers
.
Monospace
hosts
.
summaryProvider
=
HostsSummaryProvider
val
serviceMode
=
findPreference
<
Preference
>(
Key
.
serviceMode
)
!!
val
portProxy
=
findPreference
<
EditTextPreference
>(
Key
.
portProxy
)
!!
portProxy
.
onBindEditTextListener
=
EditTextPreferenceModifiers
.
Port
val
portLocalDns
=
findPreference
<
EditTextPreference
>(
Key
.
portLocalDns
)
!!
portLocalDns
.
onBindEditTextListener
=
EditTextPreferenceModifiers
.
Port
val
portTransproxy
=
findPreference
<
EditTextPreference
>(
Key
.
portTransproxy
)
!!
portTransproxy
.
onBindEditTextListener
=
EditTextPreferenceModifiers
.
Port
val
onServiceModeChange
=
Preference
.
OnPreferenceChangeListener
{
_
,
newValue
->
val
(
enabledLocalDns
,
enabledTransproxy
)
=
when
(
newValue
as
String
?)
{
Key
.
modeProxy
->
Pair
(
false
,
false
)
...
...
@@ -79,20 +97,18 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
Key
.
modeTransproxy
->
Pair
(
true
,
true
)
else
->
throw
IllegalArgumentException
(
"newValue: $newValue"
)
}
hosts
.
isEnabled
=
enabledLocalDns
portLocalDns
.
isEnabled
=
enabledLocalDns
portTransproxy
.
isEnabled
=
enabledTransproxy
true
}
val
listener
:
(
BaseService
.
State
)
->
Unit
=
{
if
(
it
==
BaseService
.
State
.
Stopped
)
{
tfo
.
isEnabled
=
true
serviceMode
.
isEnabled
=
true
portProxy
.
isEnabled
=
true
onServiceModeChange
.
onPreferenceChange
(
null
,
DataStore
.
serviceMode
)
}
else
{
tfo
.
isEnabled
=
false
serviceMode
.
isEnabled
=
false
portProxy
.
isEnabled
=
false
val
stopped
=
it
==
BaseService
.
State
.
Stopped
tfo
.
isEnabled
=
stopped
serviceMode
.
isEnabled
=
stopped
portProxy
.
isEnabled
=
stopped
if
(
stopped
)
onServiceModeChange
.
onPreferenceChange
(
null
,
DataStore
.
serviceMode
)
else
{
hosts
.
isEnabled
=
false
portLocalDns
.
isEnabled
=
false
portTransproxy
.
isEnabled
=
false
}
...
...
@@ -102,6 +118,29 @@ class GlobalSettingsPreferenceFragment : PreferenceFragmentCompat() {
serviceMode
.
onPreferenceChangeListener
=
onServiceModeChange
}
override
fun
onDisplayPreferenceDialog
(
preference
:
Preference
?)
{
if
(
preference
==
hosts
)
BrowsableEditTextPreferenceDialogFragment
().
apply
{
setKey
(
hosts
.
key
)
setTargetFragment
(
this
@GlobalSettingsPreferenceFragment
,
REQUEST_BROWSE
)
}.
show
(
fragmentManager
?:
return
,
hosts
.
key
)
else
super
.
onDisplayPreferenceDialog
(
preference
)
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
when
(
requestCode
)
{
REQUEST_BROWSE
->
{
if
(
resultCode
!=
Activity
.
RESULT_OK
)
return
val
activity
=
activity
as
MainActivity
try
{
// we read and persist all its content here to avoid content URL permission issues
hosts
.
text
=
activity
.
contentResolver
.
openInputStream
(
data
!!
.
data
!!
)
!!
.
bufferedReader
().
readText
()
}
catch
(
e
:
RuntimeException
)
{
activity
.
snackbar
(
e
.
readableMessage
).
show
()
}
}
else
->
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
}
}
override
fun
onDestroy
()
{
MainActivity
.
stateListener
=
null
super
.
onDestroy
()
...
...
mobile/src/main/java/com/github/shadowsocks/MainActivity.kt
View file @
e9524620
...
...
@@ -209,7 +209,7 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Callback, OnPref
else
ImportProfilesDialogFragment
().
withArg
(
ProfilesArg
(
profiles
)).
show
(
supportFragmentManager
,
null
)
}
override
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
?
)
{
override
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
)
{
when
(
key
)
{
Key
.
serviceMode
->
handler
.
post
{
connection
.
disconnect
(
this
)
...
...
mobile/src/main/java/com/github/shadowsocks/ProfileConfigFragment.kt
View file @
e9524620
...
...
@@ -29,27 +29,21 @@ import android.os.Bundle
import
android.os.Parcelable
import
android.view.MenuItem
import
androidx.appcompat.app.AlertDialog
import
androidx.core.os.bundleOf
import
androidx.preference.Preference
import
androidx.preference.PreferenceDataStore
import
androidx.preference.SwitchPreference
import
androidx.preference.*
import
com.github.shadowsocks.Core.app
import
com.github.shadowsocks.database.Profile
import
com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.plugin.*
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.preference.IconListPreference
import
com.github.shadowsocks.preference.OnPreferenceDataStoreChangeListener
import
com.github.shadowsocks.preference.PluginConfigurationDialogFragment
import
com.github.shadowsocks.preference.*
import
com.github.shadowsocks.utils.*
import
com.google.android.material.snackbar.Snackbar
import
com.takisoft.preferencex.EditTextPreference
import
com.takisoft.preferencex.PreferenceFragmentCompat
import
kotlinx.android.parcel.Parcelize
class
ProfileConfigFragment
:
PreferenceFragmentCompat
(),
Preference
.
OnPreferenceChangeListener
,
OnPreferenceDataStoreChangeListener
{
companion
object
{
companion
object
PasswordSummaryProvider
:
Preference
.
SummaryProvider
<
EditTextPreference
>
{
override
fun
provideSummary
(
preference
:
EditTextPreference
?)
=
"\u2022"
.
repeat
(
preference
?.
text
?.
length
?:
0
)
private
const
val
REQUEST_CODE_PLUGIN_CONFIGURE
=
1
const
val
REQUEST_UNSAVED_CHANGES
=
2
}
...
...
@@ -75,27 +69,29 @@ class ProfileConfigFragment : PreferenceFragmentCompat(),
private
lateinit
var
receiver
:
BroadcastReceiver
private
lateinit
var
udpFallback
:
Preference
override
fun
onCreatePreferences
Fix
(
savedInstanceState
:
Bundle
?,
rootKey
:
String
?)
{
override
fun
onCreatePreferences
(
savedInstanceState
:
Bundle
?,
rootKey
:
String
?)
{
preferenceManager
.
preferenceDataStore
=
DataStore
.
privateStore
val
activity
=
requireActivity
()
profileId
=
activity
.
intent
.
getLongExtra
(
Action
.
EXTRA_PROFILE_ID
,
-
1L
)
addPreferencesFromResource
(
R
.
xml
.
pref_profile
)
findPreference
<
EditTextPreference
>(
Key
.
remotePort
)
!!
.
onBindEditTextListener
=
EditTextPreferenceModifiers
.
Port
findPreference
<
EditTextPreference
>(
Key
.
password
)
!!
.
summaryProvider
=
PasswordSummaryProvider
val
serviceMode
=
DataStore
.
serviceMode
findPreference
(
Key
.
remoteDns
)
.
isEnabled
=
serviceMode
!=
Key
.
modeProxy
findPreference
(
Key
.
ipv6
)
!!
.
isEnabled
=
serviceMode
==
Key
.
modeVpn
isProxyApps
=
findPreference
(
Key
.
proxyApps
)
as
SwitchPreference
findPreference
<
Preference
>(
Key
.
remoteDns
)
!!
.
isEnabled
=
serviceMode
!=
Key
.
modeProxy
findPreference
<
Preference
>
(
Key
.
ipv6
)
!!
.
isEnabled
=
serviceMode
==
Key
.
modeVpn
isProxyApps
=
findPreference
(
Key
.
proxyApps
)
!!
isProxyApps
.
isEnabled
=
serviceMode
==
Key
.
modeVpn
isProxyApps
.
setOnPreferenceClickListener
{
startActivity
(
Intent
(
activity
,
AppManager
::
class
.
java
))
isProxyApps
.
isChecked
=
true
false
}
findPreference
(
Key
.
metered
)
!!
.
apply
{
findPreference
<
Preference
>
(
Key
.
metered
)
!!
.
apply
{
if
(
Build
.
VERSION
.
SDK_INT
>=
28
)
isEnabled
=
serviceMode
==
Key
.
modeVpn
else
remove
()
}
findPreference
(
Key
.
udpdns
)
.
isEnabled
=
serviceMode
!=
Key
.
modeProxy
plugin
=
findPreference
(
Key
.
plugin
)
as
IconListPreference
pluginConfigure
=
findPreference
(
Key
.
pluginConfigure
)
as
EditTextPreference
findPreference
<
Preference
>(
Key
.
udpdns
)
!!
.
isEnabled
=
serviceMode
!=
Key
.
modeProxy
plugin
=
findPreference
(
Key
.
plugin
)
!!
pluginConfigure
=
findPreference
(
Key
.
pluginConfigure
)
!!
plugin
.
unknownValueSummary
=
getString
(
R
.
string
.
plugin_unknown
)
plugin
.
setOnPreferenceChangeListener
{
_
,
newValue
->
pluginConfiguration
=
PluginConfiguration
(
pluginConfiguration
.
pluginsOptions
,
newValue
as
String
)
...
...
@@ -108,10 +104,11 @@ class ProfileConfigFragment : PreferenceFragmentCompat(),
}
true
}
pluginConfigure
.
onBindEditTextListener
=
EditTextPreferenceModifiers
.
Monospace
pluginConfigure
.
onPreferenceChangeListener
=
this
initPlugins
()
receiver
=
Core
.
listenForPackageChanges
(
false
)
{
initPlugins
()
}
udpFallback
=
findPreference
(
Key
.
udpFallback
)
udpFallback
=
findPreference
(
Key
.
udpFallback
)
!!
DataStore
.
privateStore
.
registerChangeListener
(
this
)
}
...
...
@@ -124,14 +121,16 @@ class ProfileConfigFragment : PreferenceFragmentCompat(),
pluginConfiguration
=
PluginConfiguration
(
DataStore
.
plugin
)
plugin
.
value
=
pluginConfiguration
.
selected
plugin
.
init
()
plugin
.
checkSummary
()
pluginConfigure
.
isEnabled
=
pluginConfiguration
.
selected
.
isNotEmpty
()
pluginConfigure
.
text
=
pluginConfiguration
.
selectedOptions
.
toString
()
}
private
fun
showPluginEditor
()
=
displayPreferenceDialog
(
PluginConfigurationDialogFragment
(),
Key
.
pluginConfigure
,
bundleOf
(
Pair
(
"key"
,
Key
.
pluginConfigure
),
Pair
(
PluginConfigurationDialogFragment
.
PLUGIN_ID_FRAGMENT_TAG
,
pluginConfiguration
.
selected
)))
private
fun
showPluginEditor
()
{
PluginConfigurationDialogFragment
().
apply
{
setArg
(
Key
.
pluginConfigure
,
pluginConfiguration
.
selected
)
setTargetFragment
(
this
@ProfileConfigFragment
,
0
)
}.
show
(
fragmentManager
?:
return
,
Key
.
pluginConfigure
)
}
private
fun
saveAndExit
()
{
val
profile
=
ProfileManager
.
getProfile
(
profileId
)
?:
Profile
()
...
...
@@ -163,18 +162,26 @@ class ProfileConfigFragment : PreferenceFragmentCompat(),
false
}
override
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
?
)
{
if
(
key
!=
Key
.
proxyApps
&&
findPreference
(
key
)
!=
null
)
DataStore
.
dirty
=
true
override
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
)
{
if
(
key
!=
Key
.
proxyApps
&&
findPreference
<
Preference
>
(
key
)
!=
null
)
DataStore
.
dirty
=
true
}
override
fun
onDisplayPreferenceDialog
(
preference
:
Preference
)
{
if
(
preference
.
key
==
Key
.
pluginConfigure
)
{
val
intent
=
PluginManager
.
buildIntent
(
pluginConfiguration
.
selected
,
PluginContract
.
ACTION_CONFIGURE
)
if
(
intent
.
resolveActivity
(
requireContext
().
packageManager
)
==
null
)
showPluginEditor
()
else
startActivityForResult
(
intent
.
putExtra
(
PluginContract
.
EXTRA_OPTIONS
,
pluginConfiguration
.
selectedOptions
.
toString
()),
REQUEST_CODE_PLUGIN_CONFIGURE
)
}
else
super
.
onDisplayPreferenceDialog
(
preference
)
when
(
preference
.
key
)
{
Key
.
plugin
->
BottomSheetPreferenceDialogFragment
().
apply
{
setArg
(
Key
.
plugin
)
setTargetFragment
(
this
@ProfileConfigFragment
,
0
)
}.
show
(
fragmentManager
?:
return
,
Key
.
plugin
)
Key
.
pluginConfigure
->
{
val
intent
=
PluginManager
.
buildIntent
(
pluginConfiguration
.
selected
,
PluginContract
.
ACTION_CONFIGURE
)
if
(
intent
.
resolveActivity
(
requireContext
().
packageManager
)
==
null
)
showPluginEditor
()
else
{
startActivityForResult
(
intent
.
putExtra
(
PluginContract
.
EXTRA_OPTIONS
,
pluginConfiguration
.
selectedOptions
.
toString
()),
REQUEST_CODE_PLUGIN_CONFIGURE
)
}
}
else
->
super
.
onDisplayPreferenceDialog
(
preference
)
}
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
...
...
mobile/src/main/java/com/github/shadowsocks/preference/BottomSheetPreferenceDialogFragment.kt
View file @
e9524620
...
...
@@ -32,6 +32,7 @@ import android.view.View
import
android.view.ViewGroup
import
android.widget.ImageView
import
android.widget.TextView
import
androidx.core.os.bundleOf
import
androidx.core.view.isVisible
import
androidx.preference.PreferenceDialogFragmentCompat
import
androidx.recyclerview.widget.DefaultItemAnimator
...
...
@@ -97,6 +98,10 @@ class BottomSheetPreferenceDialogFragment : PreferenceDialogFragmentCompat() {
}
}
fun
setArg
(
key
:
String
)
{
arguments
=
bundleOf
(
PreferenceDialogFragmentCompat
.
ARG_KEY
to
key
)
}
private
val
preference
by
lazy
{
getPreference
()
as
IconListPreference
}
private
var
clickedIndex
=
-
1
...
...
mobile/src/main/java/com/github/shadowsocks/preference/BrowsableEditTextPreferenceDialogFragment.kt
0 → 100644
View file @
e9524620
/*******************************************************************************
* *
* Copyright (C) 2019 by Max Lv <max.c.lv@gmail.com> *
* Copyright (C) 2019 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.github.shadowsocks.preference
import
android.content.ActivityNotFoundException
import
android.content.Intent
import
androidx.appcompat.app.AlertDialog
import
androidx.core.os.bundleOf
import
androidx.preference.EditTextPreferenceDialogFragmentCompat
import
com.github.shadowsocks.MainActivity
import
com.github.shadowsocks.R
class
BrowsableEditTextPreferenceDialogFragment
:
EditTextPreferenceDialogFragmentCompat
()
{
fun
setKey
(
key
:
String
)
{
arguments
=
bundleOf
(
Pair
(
ARG_KEY
,
key
))
}
override
fun
onPrepareDialogBuilder
(
builder
:
AlertDialog
.
Builder
)
{
super
.
onPrepareDialogBuilder
(
builder
)
builder
.
setNeutralButton
(
R
.
string
.
browse
)
{
_
,
_
->
val
activity
=
activity
as
MainActivity
try
{
targetFragment
!!
.
startActivityForResult
(
Intent
(
Intent
.
ACTION_GET_CONTENT
).
apply
{
addCategory
(
Intent
.
CATEGORY_OPENABLE
)
type
=
"*/*"
},
targetRequestCode
)
return
@setNeutralButton
}
catch
(
_
:
ActivityNotFoundException
)
{
}
catch
(
_
:
SecurityException
)
{
}
activity
.
snackbar
(
activity
.
getString
(
R
.
string
.
file_manager_missing
)).
show
()
}
}
}
mobile/src/main/java/com/github/shadowsocks/preference/IconListPreference.kt
View file @
e9524620
...
...
@@ -26,6 +26,14 @@ import android.util.AttributeSet
import
androidx.preference.ListPreference
class
IconListPreference
(
context
:
Context
,
attrs
:
AttributeSet
?
=
null
)
:
ListPreference
(
context
,
attrs
)
{
companion
object
FallbackProvider
:
SummaryProvider
<
IconListPreference
>
{
override
fun
provideSummary
(
preference
:
IconListPreference
?):
CharSequence
?
{
val
i
=
preference
?.
selectedEntry
return
if
(
i
!=
null
&&
i
<
0
)
preference
.
unknownValueSummary
?.
format
(
preference
.
value
)
else
preference
?.
entry
}
}
var
entryIcons
:
Array
<
Drawable
?
>?
=
null
val
selectedEntry
:
Int
get
()
=
entryValues
.
indexOf
(
value
)
val
entryIcon
:
Drawable
?
get
()
=
entryIcons
?.
getOrNull
(
selectedEntry
)
...
...
@@ -49,7 +57,6 @@ class IconListPreference(context: Context, attrs: AttributeSet? = null) : ListPr
val
listener
=
listener
if
(
listener
==
null
||
listener
.
onPreferenceChange
(
preference
,
newValue
))
{
value
=
newValue
.
toString
()
checkSummary
()
if
(
entryIcons
!=
null
)
icon
=
entryIcon
true
}
else
false
...
...
@@ -60,13 +67,9 @@ class IconListPreference(context: Context, attrs: AttributeSet? = null) : ListPr
// a.recycle()
}
fun
checkSummary
()
{
val
unknownValueSummary
=
unknownValueSummary
if
(
unknownValueSummary
!=
null
)
summary
=
if
(
selectedEntry
<
0
)
unknownValueSummary
.
format
(
value
)
else
"%s"
}
fun
init
()
{
icon
=
entryIcon
summaryProvider
=
FallbackProvider
}
override
fun
onSetInitialValue
(
defaultValue
:
Any
?)
{
super
.
onSetInitialValue
(
defaultValue
)
...
...
mobile/src/main/java/com/github/shadowsocks/preference/PluginConfigurationDialogFragment.kt
View file @
e9524620
...
...
@@ -23,17 +23,23 @@ package com.github.shadowsocks.preference
import
android.view.View
import
android.widget.EditText
import
androidx.appcompat.app.AlertDialog
import
androidx.core.os.bundleOf
import
androidx.preference.EditTextPreferenceDialogFragmentCompat
import
androidx.preference.PreferenceDialogFragmentCompat
import
com.github.shadowsocks.ProfileConfigActivity
import
com.github.shadowsocks.plugin.PluginContract
import
com.github.shadowsocks.plugin.PluginManager
import
com.takisoft.preferencex.EditTextPreferenceDialogFragmentCompat
class
PluginConfigurationDialogFragment
:
EditTextPreferenceDialogFragmentCompat
()
{
companion
object
{
const
val
PLUGIN_ID_FRAGMENT_TAG
=
private
const
val
PLUGIN_ID_FRAGMENT_TAG
=
"com.github.shadowsocks.preference.PluginConfigurationDialogFragment.PLUGIN_ID"
}
fun
setArg
(
key
:
String
,
plugin
:
String
)
{
arguments
=
bundleOf
(
PreferenceDialogFragmentCompat
.
ARG_KEY
to
key
,
PLUGIN_ID_FRAGMENT_TAG
to
plugin
)
}
private
lateinit
var
editText
:
EditText
override
fun
onPrepareDialogBuilder
(
builder
:
AlertDialog
.
Builder
)
{
...
...
mobile/src/main/res/layout/preference_dialog_password.xml
0 → 100644
View file @
e9524620
<?xml version="1.0" encoding="utf-8"?>
<!-- Based on: https://android.googlesource.com/platform/frameworks/support/+/9b8fb51/preference/res/layout/preference_dialog_edittext.xml -->
<ScrollView
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_marginTop=
"48dp"
android:layout_marginBottom=
"48dp"
android:overScrollMode=
"ifContentScrolls"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<TextView
android:id=
"@android:id/message"
style=
"?android:attr/textAppearanceSmall"
android:layout_marginLeft=
"24dp"
android:layout_marginRight=
"24dp"
android:layout_marginStart=
"24dp"
android:layout_marginEnd=
"24dp"
android:layout_marginBottom=
"48dp"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:textColor=
"?android:attr/textColorSecondary"
/>
<com.google.android.material.textfield.TextInputLayout
android:orientation=
"vertical"
android:layout_marginLeft=
"20dp"
android:layout_marginRight=
"20dp"
android:layout_marginStart=
"20dp"
android:layout_marginEnd=
"20dp"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
app:passwordToggleEnabled=
"true"
>
<com.google.android.material.textfield.TextInputEditText
android:id=
"@android:id/edit"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:singleLine=
"true"
android:inputType=
"textPassword"
android:typeface=
"monospace"
/>
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
</ScrollView>
mobile/src/main/res/xml/pref_global.xml
View file @
e9524620
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:key=
"settings_screen"
app:initialExpandedChildrenCount=
"3"
>
<SwitchPreference
android:key=
"isAutoConnect"
android:persistent=
"false"
android:summary=
"@string/auto_connect_summary"
android:title=
"@string/auto_connect"
/>
<PreferenceScreen
xmlns:app=
"http://schemas.android.com/apk/res-auto"
app:initialExpandedChildrenCount=
"4"
>
<SwitchPreference
a
ndroid:key=
"directBootAware
"
a
ndroid:icon=
"@drawable/ic_action_lock
"
a
ndroid:summary=
"@string/direct_boot_aware
_summary"
a
ndroid:title=
"@string/direct_boot_aware
"
/>
a
pp:key=
"isAutoConnect
"
a
pp:persistent=
"false
"
a
pp:summary=
"@string/auto_connect
_summary"
a
pp:title=
"@string/auto_connect
"
/>
<SwitchPreference
android:key=
"tcp_fastopen"
android:icon=
"@drawable/ic_action_offline_bolt"
android:summary=
"@string/tcp_fastopen_summary"
android:title=
"TCP Fast Open"
/>
app:key=
"directBootAware"
app:icon=
"@drawable/ic_action_lock"
app:summary=
"@string/direct_boot_aware_summary"
app:title=
"@string/direct_boot_aware"
/>
<SwitchPreference
app:key=
"tcp_fastopen"
app:icon=
"@drawable/ic_action_offline_bolt"
app:summary=
"@string/tcp_fastopen_summary"
app:title=
"TCP Fast Open"
/>
<EditTextPreference
app:key=
"hosts"
app:title=
"hosts"
/>
<SimpleMenuPreference
android:key=
"serviceMode"
android:entries=
"@array/service_modes"
android:entryValues=
"@array/service_mode_values"
android:defaultValue=
"vpn"
android:summary=
"%s"
android:title=
"@string/service_mode"
/>
<AutoSummaryEditTextPreference
android:key=
"portProxy"
android:inputType=
"number"
android:maxLength=
"5"
app:pref_summaryHasText=
"%s"
android:singleLine=
"true"
android:title=
"@string/port_proxy"
/>
<AutoSummaryEditTextPreference
android:key=
"portLocalDns"
android:icon=
"@drawable/ic_action_dns"
android:inputType=
"number"
android:maxLength=
"5"
app:pref_summaryHasText=
"%s"
android:singleLine=
"true"
android:title=
"@string/port_local_dns"
/>
<AutoSummaryEditTextPreference
android:key=
"portTransproxy"
android:inputType=
"number"
android:maxLength=
"5"
app:pref_summaryHasText=
"%s"
android:singleLine=
"true"
android:title=
"@string/port_transproxy"
/>
<com.takisoft.preferencex.SimpleMenuPreference
app:key=
"serviceMode"
app:entries=
"@array/service_modes"
app:entryValues=
"@array/service_mode_values"
app:defaultValue=
"vpn"
app:title=
"@string/service_mode"
app:useSimpleSummaryProvider=
"true"
/>
<EditTextPreference
app:key=
"portProxy"
app:title=
"@string/port_proxy"
app:useSimpleSummaryProvider=
"true"
/>
<EditTextPreference
app:key=
"portLocalDns"
app:icon=
"@drawable/ic_action_dns"
app:title=
"@string/port_local_dns"
app:useSimpleSummaryProvider=
"true"
/>
<EditTextPreference
app:key=
"portTransproxy"
app:title=
"@string/port_transproxy"
app:useSimpleSummaryProvider=
"true"
/>
</PreferenceScreen>
mobile/src/main/res/xml/pref_profile.xml
View file @
e9524620
...
...
@@ -2,99 +2,93 @@
<PreferenceScreen
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
>
<
AutoSummary
EditTextPreference
a
ndroid
:key=
"profileName"
app:
pref_summaryHasText=
"%s
"
a
ndroid:title=
"@string/profile_nam
e"
/>
<EditTextPreference
a
pp
:key=
"profileName"
app:
title=
"@string/profile_name
"
a
pp:useSimpleSummaryProvider=
"tru
e"
/>
<PreferenceCategory
a
ndroid
:title=
"@string/proxy_cat"
>
a
pp
:title=
"@string/proxy_cat"
>
<AutoSummaryEditTextPreference
android:key=
"proxy"
app:pref_summaryHasText=
"%s"
android:singleLine=
"true"
android:title=
"@string/proxy"
/>
<AutoSummaryEditTextPreference
android:key=
"remotePortNum"
android:inputType=
"number"
android:maxLength=
"5"
app:pref_summaryHasText=
"%s"
android:singleLine=
"true"
android:title=
"@string/remote_port"
/>
<AutoSummaryEditTextPreference
android:inputType=
"textPassword"
android:typeface=
"monospace"
app:pref_summaryPasswordSubstituteLength=
"0"
android:key=
"sitekey"
app:pref_summaryHasText=
"%s"
android:singleLine=
"true"
android:title=
"@string/sitekey"
/>
<SimpleMenuPreference
android:key=
"encMethod"
android:icon=
"@drawable/ic_notification_enhanced_encryption"
android:entries=
"@array/enc_method_entry"
android:entryValues=
"@array/enc_method_value"
android:summary=
"%s"
android:title=
"@string/enc_method"
/>
<EditTextPreference
app:key=
"proxy"
app:singleLine=
"true"
app:title=
"@string/proxy"
app:useSimpleSummaryProvider=
"true"
/>
<EditTextPreference
app:key=
"remotePortNum"
app:title=
"@string/remote_port"
app:useSimpleSummaryProvider=
"true"
/>
<EditTextPreference
app:dialogLayout=
"@layout/preference_dialog_password"
app:key=
"sitekey"
app:title=
"@string/sitekey"
/>
<com.takisoft.preferencex.SimpleMenuPreference
app:key=
"encMethod"
app:icon=
"@drawable/ic_notification_enhanced_encryption"
app:entries=
"@array/enc_method_entry"
app:entryValues=
"@array/enc_method_value"
app:title=
"@string/enc_method"
app:useSimpleSummaryProvider=
"true"
/>
</PreferenceCategory>
<PreferenceCategory
a
ndroid
:title=
"@string/feature_cat"
>
a
pp
:title=
"@string/feature_cat"
>
<SimpleMenuPreference
a
ndroid
:key=
"route"
a
ndroid
:entries=
"@array/route_entry"
a
ndroid
:entryValues=
"@array/route_value"
a
ndroid:summary=
"%s
"
a
ndroid:title=
"@string/route_list
"
/>
<
com.takisoft.preferencex.
SimpleMenuPreference
a
pp
:key=
"route"
a
pp
:entries=
"@array/route_entry"
a
pp
:entryValues=
"@array/route_value"
a
pp:title=
"@string/route_list
"
a
pp:useSimpleSummaryProvider=
"true
"
/>
<SwitchPreference
a
ndroid
:key=
"isIpv6"
a
ndroid
:icon=
"@drawable/ic_image_looks_6"
a
ndroid
:summary=
"@string/ipv6_summary"
a
ndroid
:title=
"@string/ipv6"
/>
a
pp
:key=
"isIpv6"
a
pp
:icon=
"@drawable/ic_image_looks_6"
a
pp
:summary=
"@string/ipv6_summary"
a
pp
:title=
"@string/ipv6"
/>
<SwitchPreference
a
ndroid
:key=
"isProxyApps"
a
ndroid
:icon=
"@drawable/ic_navigation_apps"
a
ndroid
:summary=
"@string/proxied_apps_summary"
a
ndroid
:title=
"@string/proxied_apps"
/>
a
pp
:key=
"isProxyApps"
a
pp
:icon=
"@drawable/ic_navigation_apps"
a
pp
:summary=
"@string/proxied_apps_summary"
a
pp
:title=
"@string/proxied_apps"
/>
<SwitchPreference
a
ndroid
:key=
"metered"
a
ndroid
:icon=
"@drawable/ic_device_data_usage"
a
ndroid
:summary=
"@string/metered_summary"
a
ndroid
:title=
"@string/metered"
/>
<
AutoSummary
EditTextPreference
a
ndroid
:key=
"remoteDns"
a
ndroid
:icon=
"@drawable/ic_action_dns"
a
ndroid
:title=
"@string/remote_dns"
app:
pref_summaryHasText=
"%s
"
/>
a
pp
:key=
"metered"
a
pp
:icon=
"@drawable/ic_device_data_usage"
a
pp
:summary=
"@string/metered_summary"
a
pp
:title=
"@string/metered"
/>
<EditTextPreference
a
pp
:key=
"remoteDns"
a
pp
:icon=
"@drawable/ic_action_dns"
a
pp
:title=
"@string/remote_dns"
app:
useSimpleSummaryProvider=
"true
"
/>
<SwitchPreference
android:key=
"isUdpDns"
android:summary=
"@string/udp_dns_summary"
android:title=
"@string/udp_dns"
/>
app:key=
"isUdpDns"
app:icon=
"@drawable/ic_action_dns"
app:summary=
"@string/udp_dns_summary"
app:title=
"@string/udp_dns"
/>
</PreferenceCategory>
<PreferenceCategory
a
ndroid
:title=
"@string/plugin"
>
a
pp
:title=
"@string/plugin"
>
<com.github.shadowsocks.preference.IconListPreference
a
ndroid
:key=
"plugin"
a
ndroid
:persistent=
"false"
a
ndroid:summary=
"%s
"
a
ndroid:title=
"@string/plugin
"
/>
<
AutoSummary
EditTextPreference
a
ndroid
:key=
"plugin.configure"
a
ndroid
:icon=
"@drawable/ic_action_settings"
a
ndroid
:persistent=
"false"
a
ndroid
:singleLine=
"true"
app:
pref_summaryHasText=
"%s
"
a
ndroid:title=
"@string/plugin_configur
e"
/>
a
pp
:key=
"plugin"
a
pp
:persistent=
"false"
a
pp:title=
"@string/plugin
"
a
pp:useSimpleSummaryProvider=
"true
"
/>
<EditTextPreference
a
pp
:key=
"plugin.configure"
a
pp
:icon=
"@drawable/ic_action_settings"
a
pp
:persistent=
"false"
a
pp
:singleLine=
"true"
app:
title=
"@string/plugin_configure
"
a
pp:useSimpleSummaryProvider=
"tru
e"
/>
<Preference
a
ndroid
:key=
"udpFallback"
a
ndroid
:title=
"@string/udp_fallback"
a
ndroid
:summary=
"@string/plugin_disabled"
>
a
pp
:key=
"udpFallback"
a
pp
:title=
"@string/udp_fallback"
a
pp
:summary=
"@string/plugin_disabled"
>
<intent
android:targetPackage=
"com.github.shadowsocks"
android:targetClass=
"com.github.shadowsocks.UdpFallbackProfileActivity"
/>
</Preference>
...
...
plugin/src/main/res/values/strings.xml
View file @
e9524620
...
...
@@ -6,4 +6,6 @@
<string
name=
"yes"
>
Yes
</string>
<string
name=
"no"
>
No
</string>
<string
name=
"apply"
>
Apply
</string>
<string
name=
"browse"
>
Browse…
</string>
<string
name=
"file_manager_missing"
>
Please install a file manager like MiXplorer
</string>
</resources>
tv/build.gradle
View file @
e9524620
...
...
@@ -51,7 +51,7 @@ android {
dependencies
{
implementation
project
(
':core'
)
implementation
fileTree
(
dir:
'libs'
,
include:
[
'*.jar'
])
implementation
"androidx.leanback:leanback-preference:1.1.0-alpha0
1
"
implementation
"androidx.leanback:leanback-preference:1.1.0-alpha0
2
"
}
apply
plugin:
'com.google.gms.google-services'
...
...
tv/src/main/java/com/github/shadowsocks/tv/MainPreferenceFragment.kt
View file @
e9524620
...
...
@@ -35,10 +35,7 @@ import androidx.leanback.preference.LeanbackPreferenceFragmentCompat
import
androidx.lifecycle.Observer
import
androidx.lifecycle.ViewModelProviders
import
androidx.lifecycle.get
import
androidx.preference.ListPreference
import
androidx.preference.Preference
import
androidx.preference.PreferenceDataStore
import
androidx.preference.SwitchPreference
import
androidx.preference.*
import
com.crashlytics.android.Crashlytics
import
com.github.shadowsocks.BootReceiver
import
com.github.shadowsocks.Core
...
...
@@ -50,6 +47,8 @@ import com.github.shadowsocks.database.ProfileManager
import
com.github.shadowsocks.net.HttpsTest
import
com.github.shadowsocks.net.TcpFastOpen
import
com.github.shadowsocks.preference.DataStore
import
com.github.shadowsocks.preference.EditTextPreferenceModifiers
import
com.github.shadowsocks.preference.HostsSummaryProvider
import
com.github.shadowsocks.preference.OnPreferenceDataStoreChangeListener
import
com.github.shadowsocks.utils.Key
import
com.github.shadowsocks.utils.datas
...
...
@@ -62,18 +61,20 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
private
const
val
REQUEST_CONNECT
=
1
private
const
val
REQUEST_REPLACE_PROFILES
=
2
private
const
val
REQUEST_EXPORT_PROFILES
=
3
private
const
val
REQUEST_HOSTS
=
4
private
const
val
TAG
=
"MainPreferenceFragment"
}
private
lateinit
var
fab
:
ListPreference
private
lateinit
var
stats
:
Preference
private
lateinit
var
controlImport
:
Preference
private
lateinit
var
hosts
:
EditTextPreference
private
lateinit
var
serviceMode
:
Preference
private
lateinit
var
tfo
:
SwitchPreference
private
lateinit
var
shareOverLan
:
Preference
private
lateinit
var
portProxy
:
Preference
private
lateinit
var
portLocalDns
:
Preference
private
lateinit
var
portTransproxy
:
Preference
private
lateinit
var
portProxy
:
EditText
Preference
private
lateinit
var
portLocalDns
:
EditText
Preference
private
lateinit
var
portTransproxy
:
EditText
Preference
private
val
onServiceModeChange
=
Preference
.
OnPreferenceChangeListener
{
_
,
newValue
->
val
(
enabledLocalDns
,
enabledTransproxy
)
=
when
(
newValue
as
String
?)
{
Key
.
modeProxy
->
Pair
(
false
,
false
)
...
...
@@ -81,6 +82,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
Key
.
modeTransproxy
->
Pair
(
true
,
true
)
else
->
throw
IllegalArgumentException
(
"newValue: $newValue"
)
}
hosts
.
isEnabled
=
enabledLocalDns
portLocalDns
.
isEnabled
=
enabledLocalDns
portTransproxy
.
isEnabled
=
enabledTransproxy
true
...
...
@@ -121,19 +123,13 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
})
if
(
msg
!=
null
)
Toast
.
makeText
(
context
,
getString
(
R
.
string
.
vpn_error
,
msg
),
Toast
.
LENGTH_SHORT
).
show
()
this
.
state
=
state
if
(
state
==
BaseService
.
State
.
Stopped
)
{
controlImport
.
isEnabled
=
true
tfo
.
isEnabled
=
true
serviceMode
.
isEnabled
=
true
shareOverLan
.
isEnabled
=
true
portProxy
.
isEnabled
=
true
onServiceModeChange
.
onPreferenceChange
(
null
,
DataStore
.
serviceMode
)
}
else
{
controlImport
.
isEnabled
=
false
tfo
.
isEnabled
=
false
serviceMode
.
isEnabled
=
false
shareOverLan
.
isEnabled
=
false
portProxy
.
isEnabled
=
false
val
stopped
=
state
==
BaseService
.
State
.
Stopped
controlImport
.
isEnabled
=
stopped
tfo
.
isEnabled
=
stopped
serviceMode
.
isEnabled
=
stopped
shareOverLan
.
isEnabled
=
stopped
portProxy
.
isEnabled
=
stopped
if
(
stopped
)
onServiceModeChange
.
onPreferenceChange
(
null
,
DataStore
.
serviceMode
)
else
{
portLocalDns
.
isEnabled
=
false
portTransproxy
.
isEnabled
=
false
}
...
...
@@ -156,12 +152,12 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
preferenceManager
.
preferenceDataStore
=
DataStore
.
publicStore
DataStore
.
initGlobal
()
addPreferencesFromResource
(
R
.
xml
.
pref_main
)
fab
=
findPreference
(
Key
.
id
)
as
ListPreference
fab
=
findPreference
(
Key
.
id
)
!!
populateProfiles
()
stats
=
findPreference
(
Key
.
controlStats
)
controlImport
=
findPreference
(
Key
.
controlImport
)
stats
=
findPreference
(
Key
.
controlStats
)
!!
controlImport
=
findPreference
(
Key
.
controlImport
)
!!
(
findPreference
(
Key
.
isAutoConnect
)
as
SwitchPreference
)
.
apply
{
findPreference
<
SwitchPreference
>(
Key
.
isAutoConnect
)
!!
.
apply
{
setOnPreferenceChangeListener
{
_
,
value
->
BootReceiver
.
enabled
=
value
as
Boolean
true
...
...
@@ -169,7 +165,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
isChecked
=
BootReceiver
.
enabled
}
tfo
=
findPreference
(
Key
.
tfo
)
as
SwitchPreference
tfo
=
findPreference
(
Key
.
tfo
)
!!
tfo
.
isChecked
=
DataStore
.
tcpFastOpen
tfo
.
setOnPreferenceChangeListener
{
_
,
value
->
if
(
value
as
Boolean
&&
!
TcpFastOpen
.
sendEnabled
)
{
...
...
@@ -186,19 +182,18 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
tfo
.
summary
=
getString
(
R
.
string
.
tcp_fastopen_summary_unsupported
,
System
.
getProperty
(
"os.version"
))
}
serviceMode
=
findPreference
(
Key
.
serviceMode
)
shareOverLan
=
findPreference
(
Key
.
shareOverLan
)
portProxy
=
findPreference
(
Key
.
portProxy
)
portLocalDns
=
findPreference
(
Key
.
portLocalDns
)
portTransproxy
=
findPreference
(
Key
.
portTransproxy
)
hosts
=
findPreference
(
Key
.
hosts
)
!!
hosts
.
summaryProvider
=
HostsSummaryProvider
serviceMode
=
findPreference
(
Key
.
serviceMode
)
!!
shareOverLan
=
findPreference
(
Key
.
shareOverLan
)
!!
portProxy
=
findPreference
(
Key
.
portProxy
)
!!
portProxy
.
onBindEditTextListener
=
EditTextPreferenceModifiers
.
Port
portLocalDns
=
findPreference
(
Key
.
portLocalDns
)
!!
portLocalDns
.
onBindEditTextListener
=
EditTextPreferenceModifiers
.
Port
portTransproxy
=
findPreference
(
Key
.
portTransproxy
)
!!
portTransproxy
.
onBindEditTextListener
=
EditTextPreferenceModifiers
.
Port
serviceMode
.
onPreferenceChangeListener
=
onServiceModeChange
findPreference
(
Key
.
about
).
apply
{
summary
=
getString
(
R
.
string
.
about_title
,
BuildConfig
.
VERSION_NAME
)
setOnPreferenceClickListener
{
Toast
.
makeText
(
requireContext
(),
"https://shadowsocks.org/android"
,
Toast
.
LENGTH_SHORT
).
show
()
true
}
}
findPreference
<
Preference
>(
Key
.
about
)
!!
.
summary
=
getString
(
R
.
string
.
about_title
,
BuildConfig
.
VERSION_NAME
)
tester
=
ViewModelProviders
.
of
(
this
).
get
()
changeState
(
BaseService
.
State
.
Idle
)
// reset everything to init state
...
...
@@ -236,7 +231,7 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
}
}
override
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
?
)
{
override
fun
onPreferenceDataStoreChanged
(
store
:
PreferenceDataStore
,
key
:
String
)
{
when
(
key
)
{
Key
.
serviceMode
->
handler
.
post
{
connection
.
disconnect
(
requireContext
())
...
...
@@ -274,15 +269,25 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
},
REQUEST_EXPORT_PROFILES
)
true
}
Key
.
about
->
{
Toast
.
makeText
(
requireContext
(),
"https://shadowsocks.org/android"
,
Toast
.
LENGTH_SHORT
).
show
()
true
}
else
->
super
.
onPreferenceTreeClick
(
preference
)
}
private
fun
startFilesForResult
(
intent
:
Intent
,
requestCode
:
Int
)
{
override
fun
onDisplayPreferenceDialog
(
preference
:
Preference
?)
{
if
(
preference
!=
hosts
||
startFilesForResult
(
Intent
(
Intent
.
ACTION_GET_CONTENT
).
setType
(
"*/*"
),
REQUEST_HOSTS
))
super
.
onDisplayPreferenceDialog
(
preference
)
}
private
fun
startFilesForResult
(
intent
:
Intent
,
requestCode
:
Int
):
Boolean
{
try
{
startActivityForResult
(
intent
.
addCategory
(
Intent
.
CATEGORY_OPENABLE
),
requestCode
)
return
return
false
}
catch
(
_
:
ActivityNotFoundException
)
{
}
catch
(
_
:
SecurityException
)
{
}
Toast
.
makeText
(
requireContext
(),
R
.
string
.
file_manager_missing
,
Toast
.
LENGTH_SHORT
).
show
()
return
true
}
override
fun
onActivityResult
(
requestCode
:
Int
,
resultCode
:
Int
,
data
:
Intent
?)
{
...
...
@@ -317,6 +322,16 @@ class MainPreferenceFragment : LeanbackPreferenceFragmentCompat(), ShadowsocksCo
Toast
.
makeText
(
context
,
e
.
readableMessage
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
REQUEST_HOSTS
->
{
if
(
resultCode
!=
Activity
.
RESULT_OK
)
return
val
context
=
requireContext
()
try
{
// we read and persist all its content here to avoid content URL permission issues
hosts
.
text
=
context
.
contentResolver
.
openInputStream
(
data
!!
.
data
!!
)
!!
.
bufferedReader
().
readText
()
}
catch
(
e
:
RuntimeException
)
{
Toast
.
makeText
(
context
,
e
.
readableMessage
,
Toast
.
LENGTH_SHORT
).
show
()
}
}
else
->
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
)
}
}
...
...
tv/src/main/res/xml/pref_main.xml
View file @
e9524620
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
android:title=
"@string/app_name"
>
<PreferenceScreen
xmlns:app=
"http://schemas.android.com/apk/res-auto"
app:title=
"@string/app_name"
>
<!-- profileId is stored in privateStore so its value needs to be populated manually -->
<ListPreference
a
ndroid
:key=
"profileId"
a
ndroid
:title=
"@string/connect"
a
ndroid:summary=
"%s
"
a
ndroid:persistent=
"fals
e"
/>
a
pp
:key=
"profileId"
a
pp
:title=
"@string/connect"
a
pp:persistent=
"false
"
a
pp:useSimpleSummaryProvider=
"tru
e"
/>
<Preference
a
ndroid
:key=
"control.stats"
a
ndroid
:title=
"@string/connection_test_pending"
a
ndroid
:summary=
"@string/stat_summary"
/>
a
pp
:key=
"control.stats"
a
pp
:title=
"@string/connection_test_pending"
a
pp
:summary=
"@string/stat_summary"
/>
<Preference
a
ndroid
:key=
"control.import"
a
ndroid
:title=
"@string/action_replace_file"
/>
a
pp
:key=
"control.import"
a
pp
:title=
"@string/action_replace_file"
/>
<Preference
a
ndroid
:key=
"control.export"
a
ndroid
:title=
"@string/action_export_file"
/>
a
pp
:key=
"control.export"
a
pp
:title=
"@string/action_export_file"
/>
<PreferenceCategory
a
ndroid
:key=
"settings"
a
ndroid
:title=
"@string/settings"
app:initialExpandedChildrenCount=
"
2
"
>
a
pp
:key=
"settings"
a
pp
:title=
"@string/settings"
app:initialExpandedChildrenCount=
"
3
"
>
<SwitchPreference
a
ndroid
:key=
"isAutoConnect"
a
ndroid
:persistent=
"false"
a
ndroid
:summary=
"@string/auto_connect_summary"
a
ndroid
:title=
"@string/auto_connect"
/>
a
pp
:key=
"isAutoConnect"
a
pp
:persistent=
"false"
a
pp
:summary=
"@string/auto_connect_summary"
a
pp
:title=
"@string/auto_connect"
/>
<SwitchPreference
android:key=
"tcp_fastopen"
android:summary=
"@string/tcp_fastopen_summary"
android:title=
"TCP Fast Open"
/>
app:key=
"tcp_fastopen"
app:summary=
"@string/tcp_fastopen_summary"
app:title=
"TCP Fast Open"
/>
<EditTextPreference
app:key=
"hosts"
app:title=
"hosts"
/>
<ListPreference
a
ndroid
:key=
"serviceMode"
a
ndroid
:entries=
"@array/service_modes"
a
ndroid
:entryValues=
"@array/service_mode_values"
a
ndroid
:defaultValue=
"vpn"
a
ndroid:summary=
"%s
"
a
ndroid:title=
"@string/service_mod
e"
/>
a
pp
:key=
"serviceMode"
a
pp
:entries=
"@array/service_modes"
a
pp
:entryValues=
"@array/service_mode_values"
a
pp
:defaultValue=
"vpn"
a
pp:title=
"@string/service_mode
"
a
pp:useSimpleSummaryProvider=
"tru
e"
/>
<SwitchPreference
android:key=
"shareOverLan"
android:title=
"@string/share_over_lan"
/>
<com.takisoft.preferencex.AutoSummaryEditTextPreference
android:key=
"portProxy"
android:inputType=
"number"
android:maxLength=
"5"
app:pref_summaryHasText=
"%s"
android:singleLine=
"true"
android:title=
"@string/port_proxy"
/>
<com.takisoft.preferencex.AutoSummaryEditTextPreference
android:key=
"portLocalDns"
android:inputType=
"number"
android:maxLength=
"5"
app:pref_summaryHasText=
"%s"
android:singleLine=
"true"
android:title=
"@string/port_local_dns"
/>
<com.takisoft.preferencex.AutoSummaryEditTextPreference
android:key=
"portTransproxy"
android:inputType=
"number"
android:maxLength=
"5"
app:pref_summaryHasText=
"%s"
android:singleLine=
"true"
android:title=
"@string/port_transproxy"
/>
app:key=
"shareOverLan"
app:title=
"@string/share_over_lan"
/>
<EditTextPreference
app:key=
"portProxy"
app:title=
"@string/port_proxy"
app:useSimpleSummaryProvider=
"true"
/>
<EditTextPreference
app:key=
"portLocalDns"
app:title=
"@string/port_local_dns"
app:useSimpleSummaryProvider=
"true"
/>
<EditTextPreference
app:key=
"portTransproxy"
app:title=
"@string/port_transproxy"
app:useSimpleSummaryProvider=
"true"
/>
</PreferenceCategory>
<Preference
a
ndroid
:key=
"about"
a
ndroid
:title=
"@string/about"
/>
a
pp
:key=
"about"
a
pp
:title=
"@string/about"
/>
</PreferenceScreen>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment