Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b3524df5a | ||
|
|
16672a1dae | ||
|
|
daa9d9f8c3 | ||
|
|
db9790eeb9 | ||
|
|
e268719a1a | ||
|
|
fa41164e82 | ||
|
|
36c72e20f5 | ||
|
|
3190ff5e68 | ||
|
|
b74de9e03e | ||
|
|
2e40df3d73 | ||
|
|
102e2afa12 | ||
|
|
05c0c0bab9 | ||
|
|
64c48a34ae | ||
|
|
b9517f0703 | ||
|
|
72f4586acb | ||
|
|
3d6daccbb1 | ||
|
|
33a8967f30 | ||
|
|
762da4c62f | ||
|
|
8e83272fa7 | ||
|
|
d17d791b3b | ||
|
|
63ae014581 | ||
|
|
95e1eee59f | ||
|
|
98df31c258 | ||
|
|
04092bf8e0 | ||
|
|
5e56bfec89 | ||
|
|
635105ca05 | ||
|
|
d5fd487ff9 | ||
|
|
89c5d94275 | ||
|
|
0b98a2d4e7 | ||
|
|
1bc851dac0 | ||
|
|
37ea3d3f02 | ||
|
|
518e25d205 | ||
|
|
43e2731604 | ||
|
|
84c12e705f | ||
|
|
77ea376b46 | ||
|
|
68f3f8b20d | ||
|
|
7226f8aab4 | ||
|
|
36b46d6f32 | ||
|
|
7687a19cc1 |
@@ -36,6 +36,7 @@ The exclamation mark in the Wi-Fi/cellular icon appears because the system fails
|
||||
* Samsung and/or Brevent: [#1410](https://github.com/shadowsocks/shadowsocks-android/issues/1410)
|
||||
* Another Samsung: [#1712](https://github.com/shadowsocks/shadowsocks-android/issues/1712)
|
||||
* Don't install this app on SD card because of permission issues: [#1124 (comment)](https://github.com/shadowsocks/shadowsocks-android/issues/1124#issuecomment-307556453)
|
||||
* `INTERACT_ACROSS_USERS` permission missing: [#1184](https://github.com/shadowsocks/shadowsocks-android/issues/1184)
|
||||
|
||||
### How to pause Shadowsocks service?
|
||||
|
||||
|
||||
+7
-6
@@ -4,16 +4,17 @@ apply plugin: 'com.github.ben-manes.versions'
|
||||
|
||||
buildscript {
|
||||
ext {
|
||||
kotlinVersion = '1.2.31'
|
||||
kotlinVersion = '1.2.41'
|
||||
minSdkVersion = 21
|
||||
sdkVersion = 27
|
||||
buildToolsVersion = '27.0.3'
|
||||
supportLibraryVersion = '27.1.0'
|
||||
takisoftFixVersion = '27.1.0.0'
|
||||
supportLibraryVersion = '27.1.1'
|
||||
takisoftFixVersion = '27.1.1.1'
|
||||
roomVersion = '1.1.0'
|
||||
playServicesVersion = '12.0.1'
|
||||
junitVersion = '4.12'
|
||||
androidTestVersion = '1.0.1'
|
||||
androidEspressoVersion = '3.0.1'
|
||||
androidTestVersion = '1.0.2'
|
||||
androidEspressoVersion = '3.0.2'
|
||||
}
|
||||
|
||||
repositories {
|
||||
@@ -22,7 +23,7 @@ buildscript {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.0'
|
||||
classpath 'com.android.tools.build:gradle:3.1.2'
|
||||
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
|
||||
classpath 'com.google.gms:google-services:3.2.1'
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
|
||||
|
||||
Submodule core/src/main/jni/shadowsocks-libev updated: a4c9059ffe...a9d56518bb
+12
-12
@@ -30,18 +30,6 @@ MKDIR %TARGET%\arm64-v8a>nul 2>nul
|
||||
|
||||
SET CC=%ANDROID_ARM_TOOLCHAIN%\bin\arm-linux-androideabi-gcc.exe
|
||||
|
||||
REM Check environment availability
|
||||
IF NOT EXIST %CC% (
|
||||
ECHO "gcc not found"
|
||||
EXIT 1
|
||||
)
|
||||
|
||||
WHERE python.exe
|
||||
IF "%ERRORLEVEL%" == 1 (
|
||||
ECHO "python not found"
|
||||
EXIT 1
|
||||
)
|
||||
|
||||
IF NOT EXIST %ANDROID_ARM_CC% (
|
||||
ECHO "Make standalone toolchain for ARM arch"
|
||||
python.exe %ANDROID_NDK_HOME%\build\tools\make_standalone_toolchain.py --arch arm ^
|
||||
@@ -60,6 +48,18 @@ IF NOT EXIST %ANDROID_X86_CC% (
|
||||
--api %MIN_API% --install-dir %ANDROID_X86_TOOLCHAIN%
|
||||
)
|
||||
|
||||
REM Check environment availability
|
||||
IF NOT EXIST %CC% (
|
||||
ECHO "gcc not found"
|
||||
EXIT 1
|
||||
)
|
||||
|
||||
WHERE python.exe
|
||||
IF "%ERRORLEVEL%" == 1 (
|
||||
ECHO "python not found"
|
||||
EXIT 1
|
||||
)
|
||||
|
||||
IF NOT EXIST %DIR%\go\bin\go.exe (
|
||||
ECHO "Build the custom go"
|
||||
|
||||
|
||||
+12
-5
@@ -4,6 +4,7 @@ import java.util.regex.Pattern
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'kotlin-android'
|
||||
apply plugin: 'kotlin-kapt'
|
||||
|
||||
def getCurrentFlavor() {
|
||||
String task = getGradle().getStartParameter().getTaskRequests().toString()
|
||||
@@ -21,11 +22,16 @@ android {
|
||||
applicationId "com.github.shadowsocks"
|
||||
minSdkVersion rootProject.minSdkVersion
|
||||
targetSdkVersion rootProject.sdkVersion
|
||||
versionCode 4050500
|
||||
versionName "4.5.5"
|
||||
versionCode 4060000
|
||||
versionName "4.6.0"
|
||||
testApplicationId "com.github.shadowsocks.test"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
resConfigs "fa", "fr", "ja", "ko", "ru", "zh-rCN", "zh-rTW"
|
||||
javaCompileOptions {
|
||||
annotationProcessorOptions {
|
||||
arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
|
||||
}
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
debug {
|
||||
@@ -54,6 +60,7 @@ android {
|
||||
|
||||
dependencies {
|
||||
implementation project(':core')
|
||||
implementation "android.arch.persistence.room:runtime:$roomVersion"
|
||||
implementation "com.android.support:customtabs:$supportLibraryVersion"
|
||||
implementation "com.android.support:design:$supportLibraryVersion"
|
||||
implementation "com.android.support:gridlayout-v7:$supportLibraryVersion"
|
||||
@@ -63,16 +70,16 @@ dependencies {
|
||||
implementation "com.google.android.gms:play-services-analytics:$playServicesVersion"
|
||||
implementation "com.google.android.gms:play-services-vision:$playServicesVersion"
|
||||
implementation "com.google.firebase:firebase-config:$playServicesVersion"
|
||||
implementation 'com.j256.ormlite:ormlite-android:5.1'
|
||||
implementation 'com.mikepenz:materialdrawer:6.0.6'
|
||||
implementation 'com.mikepenz:materialdrawer:6.0.7'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.10.0'
|
||||
implementation "com.takisoft.fix:preference-v7-simplemenu:$takisoftFixVersion"
|
||||
implementation 'com.twofortyfouram:android-plugin-api-for-locale:1.0.2'
|
||||
implementation 'dnsjava:dnsjava:2.1.8'
|
||||
implementation 'eu.chainfire:libsuperuser:1.0.0.201704021214'
|
||||
implementation 'net.glxn.qrgen:android:2.0'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
|
||||
implementation 'xyz.belvi.mobilevision:barcodescanner:2.0.3'
|
||||
kapt "android.arch.persistence.room:compiler:$roomVersion"
|
||||
testImplementation "android.arch.persistence.room:testing:$roomVersion"
|
||||
testImplementation "junit:junit:$junitVersion"
|
||||
androidTestImplementation "com.android.support.test:runner:$androidTestVersion"
|
||||
androidTestImplementation "com.android.support.test.espresso:espresso-core:$androidEspressoVersion"
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 26,
|
||||
"identityHash": "a69accf94393d71abdb60873d4ea74a2",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "Profile",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `host` TEXT NOT NULL, `remotePort` INTEGER NOT NULL, `password` TEXT NOT NULL, `method` TEXT NOT NULL, `route` TEXT NOT NULL, `remoteDns` TEXT NOT NULL, `proxyApps` INTEGER NOT NULL, `bypass` INTEGER NOT NULL, `udpdns` INTEGER NOT NULL, `ipv6` INTEGER NOT NULL, `individual` TEXT NOT NULL, `tx` INTEGER NOT NULL, `rx` INTEGER NOT NULL, `userOrder` INTEGER NOT NULL, `plugin` TEXT)",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "id",
|
||||
"columnName": "id",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "name",
|
||||
"columnName": "name",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
},
|
||||
{
|
||||
"fieldPath": "host",
|
||||
"columnName": "host",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "remotePort",
|
||||
"columnName": "remotePort",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "password",
|
||||
"columnName": "password",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "method",
|
||||
"columnName": "method",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "route",
|
||||
"columnName": "route",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "remoteDns",
|
||||
"columnName": "remoteDns",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "proxyApps",
|
||||
"columnName": "proxyApps",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "bypass",
|
||||
"columnName": "bypass",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "udpdns",
|
||||
"columnName": "udpdns",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "ipv6",
|
||||
"columnName": "ipv6",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "individual",
|
||||
"columnName": "individual",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "tx",
|
||||
"columnName": "tx",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "rx",
|
||||
"columnName": "rx",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "userOrder",
|
||||
"columnName": "userOrder",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "plugin",
|
||||
"columnName": "plugin",
|
||||
"affinity": "TEXT",
|
||||
"notNull": false
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"id"
|
||||
],
|
||||
"autoGenerate": true
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
},
|
||||
{
|
||||
"tableName": "KeyValuePair",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `valueType` INTEGER NOT NULL, `value` BLOB NOT NULL, PRIMARY KEY(`key`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "key",
|
||||
"columnName": "key",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "valueType",
|
||||
"columnName": "valueType",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "BLOB",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"key"
|
||||
],
|
||||
"autoGenerate": false
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"a69accf94393d71abdb60873d4ea74a2\")"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"formatVersion": 1,
|
||||
"database": {
|
||||
"version": 3,
|
||||
"identityHash": "f1aab1fb633378621635c344dbc8ac7b",
|
||||
"entities": [
|
||||
{
|
||||
"tableName": "KeyValuePair",
|
||||
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`key` TEXT NOT NULL, `valueType` INTEGER NOT NULL, `value` BLOB NOT NULL, PRIMARY KEY(`key`))",
|
||||
"fields": [
|
||||
{
|
||||
"fieldPath": "key",
|
||||
"columnName": "key",
|
||||
"affinity": "TEXT",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "valueType",
|
||||
"columnName": "valueType",
|
||||
"affinity": "INTEGER",
|
||||
"notNull": true
|
||||
},
|
||||
{
|
||||
"fieldPath": "value",
|
||||
"columnName": "value",
|
||||
"affinity": "BLOB",
|
||||
"notNull": true
|
||||
}
|
||||
],
|
||||
"primaryKey": {
|
||||
"columnNames": [
|
||||
"key"
|
||||
],
|
||||
"autoGenerate": false
|
||||
},
|
||||
"indices": [],
|
||||
"foreignKeys": []
|
||||
}
|
||||
],
|
||||
"setupQueries": [
|
||||
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
|
||||
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, \"f1aab1fb633378621635c344dbc8ac7b\")"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -72,7 +72,7 @@
|
||||
|
||||
<activity
|
||||
android:name=".VpnRequestActivity"
|
||||
android:theme="@style/Theme.Translucent"
|
||||
android:theme="@style/Theme.AppCompat.Translucent"
|
||||
android:excludeFromRecents="true"
|
||||
android:taskAffinity=""
|
||||
android:launchMode="singleTask"/>
|
||||
|
||||
@@ -2,7 +2,7 @@ package com.github.shadowsocks.aidl;
|
||||
|
||||
interface IShadowsocksServiceCallback {
|
||||
oneway void stateChanged(int state, String profileName, String msg);
|
||||
oneway void trafficUpdated(int profileId, long txRate, long rxRate, long txTotal, long rxTotal);
|
||||
oneway void trafficUpdated(long profileId, long txRate, long rxRate, long txTotal, long rxTotal);
|
||||
// Traffic data has persisted to database, listener should refetch their data from database
|
||||
oneway void trafficPersisted(int profileId);
|
||||
oneway void trafficPersisted(long profileId);
|
||||
}
|
||||
|
||||
@@ -5634,9 +5634,7 @@
|
||||
(^|\.)blogs\.libraryinformationtechnology\.com$
|
||||
(^|\.)blogs\.tampabay\.com$
|
||||
(^|\.)blogs\.yahoo\.co\.jp$
|
||||
(^|\.)blogspot\.com$
|
||||
(^|\.)blogspot\.hk$
|
||||
(^|\.)blogspot\.jp$
|
||||
(^|\.)blogspot(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,2}$
|
||||
(^|\.)blogtd\.net$
|
||||
(^|\.)blogtd\.org$
|
||||
(^|\.)bloodshed\.net$
|
||||
@@ -6875,61 +6873,8 @@
|
||||
(^|\.)goodtv\.com\.tw$
|
||||
(^|\.)goodtv\.tv$
|
||||
(^|\.)goofind\.com$
|
||||
(^|\.)google\.ae$
|
||||
(^|\.)google\.am$
|
||||
(^|\.)google\.as$
|
||||
(^|\.)google\.at$
|
||||
(^|\.)google\.az$
|
||||
(^|\.)google\.ba$
|
||||
(^|\.)google\.be$
|
||||
(^|\.)google\.bg$
|
||||
(^|\.)google\.ca$
|
||||
(^|\.)google\.calstate\.edu$
|
||||
(^|\.)google\.cd$
|
||||
(^|\.)google\.ci$
|
||||
(^|\.)google\.co\.id$
|
||||
(^|\.)google\.co\.jp$
|
||||
(^|\.)google\.co\.kr$
|
||||
(^|\.)google\.co\.ma$
|
||||
(^|\.)google\.co\.uk$
|
||||
(^|\.)google\.com$
|
||||
(^|\.)google\.de$
|
||||
(^|\.)google\.dj$
|
||||
(^|\.)google\.dk$
|
||||
(^|\.)google\.es$
|
||||
(^|\.)google\.fi$
|
||||
(^|\.)google\.fm$
|
||||
(^|\.)google\.fr$
|
||||
(^|\.)google\.gg$
|
||||
(^|\.)google\.gl$
|
||||
(^|\.)google\.gr$
|
||||
(^|\.)google\.ie$
|
||||
(^|\.)google\.is$
|
||||
(^|\.)google\.it$
|
||||
(^|\.)google\.jo$
|
||||
(^|\.)google\.kz$
|
||||
(^|\.)google\.lv$
|
||||
(^|\.)google\.mn$
|
||||
(^|\.)google\.ms$
|
||||
(^|\.)google\.nl$
|
||||
(^|\.)google\.no$
|
||||
(^|\.)google\.nu$
|
||||
(^|\.)google\.ro$
|
||||
(^|\.)google\.ru$
|
||||
(^|\.)google\.rw$
|
||||
(^|\.)google\.sc$
|
||||
(^|\.)google\.sh$
|
||||
(^|\.)google\.sk$
|
||||
(^|\.)google\.sm$
|
||||
(^|\.)google\.sn$
|
||||
(^|\.)google\.tk$
|
||||
(^|\.)google\.tm$
|
||||
(^|\.)google\.to$
|
||||
(^|\.)google\.tt$
|
||||
(^|\.)google\.vu$
|
||||
(^|\.)google\.ws$
|
||||
(^|\.)googleapis\.cn$
|
||||
(^|\.)googleapis\.com$
|
||||
(^|\.)google(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,2}$
|
||||
(^|\.)googleapis(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,2}$
|
||||
(^|\.)googleapps\.com$
|
||||
(^|\.)googlearth\.com$
|
||||
(^|\.)googleartproject\.com$
|
||||
|
||||
@@ -5648,9 +5648,7 @@
|
||||
(^|\.)blogs\.libraryinformationtechnology\.com$
|
||||
(^|\.)blogs\.tampabay\.com$
|
||||
(^|\.)blogs\.yahoo\.co\.jp$
|
||||
(^|\.)blogspot\.com$
|
||||
(^|\.)blogspot\.hk$
|
||||
(^|\.)blogspot\.jp$
|
||||
(^|\.)blogspot(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,2}$
|
||||
(^|\.)blogtd\.net$
|
||||
(^|\.)blogtd\.org$
|
||||
(^|\.)bloodshed\.net$
|
||||
@@ -6889,61 +6887,8 @@
|
||||
(^|\.)goodtv\.com\.tw$
|
||||
(^|\.)goodtv\.tv$
|
||||
(^|\.)goofind\.com$
|
||||
(^|\.)google\.ae$
|
||||
(^|\.)google\.am$
|
||||
(^|\.)google\.as$
|
||||
(^|\.)google\.at$
|
||||
(^|\.)google\.az$
|
||||
(^|\.)google\.ba$
|
||||
(^|\.)google\.be$
|
||||
(^|\.)google\.bg$
|
||||
(^|\.)google\.ca$
|
||||
(^|\.)google\.calstate\.edu$
|
||||
(^|\.)google\.cd$
|
||||
(^|\.)google\.ci$
|
||||
(^|\.)google\.co\.id$
|
||||
(^|\.)google\.co\.jp$
|
||||
(^|\.)google\.co\.kr$
|
||||
(^|\.)google\.co\.ma$
|
||||
(^|\.)google\.co\.uk$
|
||||
(^|\.)google\.com$
|
||||
(^|\.)google\.de$
|
||||
(^|\.)google\.dj$
|
||||
(^|\.)google\.dk$
|
||||
(^|\.)google\.es$
|
||||
(^|\.)google\.fi$
|
||||
(^|\.)google\.fm$
|
||||
(^|\.)google\.fr$
|
||||
(^|\.)google\.gg$
|
||||
(^|\.)google\.gl$
|
||||
(^|\.)google\.gr$
|
||||
(^|\.)google\.ie$
|
||||
(^|\.)google\.is$
|
||||
(^|\.)google\.it$
|
||||
(^|\.)google\.jo$
|
||||
(^|\.)google\.kz$
|
||||
(^|\.)google\.lv$
|
||||
(^|\.)google\.mn$
|
||||
(^|\.)google\.ms$
|
||||
(^|\.)google\.nl$
|
||||
(^|\.)google\.no$
|
||||
(^|\.)google\.nu$
|
||||
(^|\.)google\.ro$
|
||||
(^|\.)google\.ru$
|
||||
(^|\.)google\.rw$
|
||||
(^|\.)google\.sc$
|
||||
(^|\.)google\.sh$
|
||||
(^|\.)google\.sk$
|
||||
(^|\.)google\.sm$
|
||||
(^|\.)google\.sn$
|
||||
(^|\.)google\.tk$
|
||||
(^|\.)google\.tm$
|
||||
(^|\.)google\.to$
|
||||
(^|\.)google\.tt$
|
||||
(^|\.)google\.vu$
|
||||
(^|\.)google\.ws$
|
||||
(^|\.)googleapis\.cn$
|
||||
(^|\.)googleapis\.com$
|
||||
(^|\.)google(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,2}$
|
||||
(^|\.)googleapis(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,2}$
|
||||
(^|\.)googleapps\.com$
|
||||
(^|\.)googlearth\.com$
|
||||
(^|\.)googleartproject\.com$
|
||||
|
||||
@@ -561,9 +561,7 @@
|
||||
(^|\.)blogs\.libraryinformationtechnology\.com$
|
||||
(^|\.)blogs\.tampabay\.com$
|
||||
(^|\.)blogs\.yahoo\.co\.jp$
|
||||
(^|\.)blogspot\.com$
|
||||
(^|\.)blogspot\.hk$
|
||||
(^|\.)blogspot\.jp$
|
||||
(^|\.)blogspot(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,2}$
|
||||
(^|\.)blogtd\.net$
|
||||
(^|\.)blogtd\.org$
|
||||
(^|\.)bloodshed\.net$
|
||||
@@ -1802,61 +1800,8 @@
|
||||
(^|\.)goodtv\.com\.tw$
|
||||
(^|\.)goodtv\.tv$
|
||||
(^|\.)goofind\.com$
|
||||
(^|\.)google\.ae$
|
||||
(^|\.)google\.am$
|
||||
(^|\.)google\.as$
|
||||
(^|\.)google\.at$
|
||||
(^|\.)google\.az$
|
||||
(^|\.)google\.ba$
|
||||
(^|\.)google\.be$
|
||||
(^|\.)google\.bg$
|
||||
(^|\.)google\.ca$
|
||||
(^|\.)google\.calstate\.edu$
|
||||
(^|\.)google\.cd$
|
||||
(^|\.)google\.ci$
|
||||
(^|\.)google\.co\.id$
|
||||
(^|\.)google\.co\.jp$
|
||||
(^|\.)google\.co\.kr$
|
||||
(^|\.)google\.co\.ma$
|
||||
(^|\.)google\.co\.uk$
|
||||
(^|\.)google\.com$
|
||||
(^|\.)google\.de$
|
||||
(^|\.)google\.dj$
|
||||
(^|\.)google\.dk$
|
||||
(^|\.)google\.es$
|
||||
(^|\.)google\.fi$
|
||||
(^|\.)google\.fm$
|
||||
(^|\.)google\.fr$
|
||||
(^|\.)google\.gg$
|
||||
(^|\.)google\.gl$
|
||||
(^|\.)google\.gr$
|
||||
(^|\.)google\.ie$
|
||||
(^|\.)google\.is$
|
||||
(^|\.)google\.it$
|
||||
(^|\.)google\.jo$
|
||||
(^|\.)google\.kz$
|
||||
(^|\.)google\.lv$
|
||||
(^|\.)google\.mn$
|
||||
(^|\.)google\.ms$
|
||||
(^|\.)google\.nl$
|
||||
(^|\.)google\.no$
|
||||
(^|\.)google\.nu$
|
||||
(^|\.)google\.ro$
|
||||
(^|\.)google\.ru$
|
||||
(^|\.)google\.rw$
|
||||
(^|\.)google\.sc$
|
||||
(^|\.)google\.sh$
|
||||
(^|\.)google\.sk$
|
||||
(^|\.)google\.sm$
|
||||
(^|\.)google\.sn$
|
||||
(^|\.)google\.tk$
|
||||
(^|\.)google\.tm$
|
||||
(^|\.)google\.to$
|
||||
(^|\.)google\.tt$
|
||||
(^|\.)google\.vu$
|
||||
(^|\.)google\.ws$
|
||||
(^|\.)googleapis\.cn$
|
||||
(^|\.)googleapis\.com$
|
||||
(^|\.)google(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,2}$
|
||||
(^|\.)googleapis(\.[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?){1,2}$
|
||||
(^|\.)googleapps\.com$
|
||||
(^|\.)googlearth\.com$
|
||||
(^|\.)googleartproject\.com$
|
||||
|
||||
@@ -1,17 +1,3 @@
|
||||
0.0.0.0/8
|
||||
10.0.0.0/8
|
||||
100.64.0.0/10
|
||||
127.0.0.0/8
|
||||
169.254.0.0/16
|
||||
172.16.0.0/12
|
||||
192.0.0.0/29
|
||||
192.0.2.0/24
|
||||
192.88.99.0/24
|
||||
192.168.0.0/16
|
||||
198.18.0.0/15
|
||||
198.51.100.0/24
|
||||
203.0.113.0/24
|
||||
224.0.0.0/3
|
||||
1.0.1.0/24
|
||||
1.0.2.0/23
|
||||
1.0.8.0/21
|
||||
|
||||
@@ -57,7 +57,6 @@ import com.google.android.gms.analytics.StandardExceptionParser
|
||||
import com.google.android.gms.analytics.Tracker
|
||||
import com.google.firebase.FirebaseApp
|
||||
import com.google.firebase.remoteconfig.FirebaseRemoteConfig
|
||||
import com.j256.ormlite.logger.LocalLog
|
||||
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompat
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
@@ -92,7 +91,7 @@ class App : Application() {
|
||||
val currentProfile: Profile? get() =
|
||||
if (DataStore.directBootAware) DirectBoot.getDeviceProfile() else ProfileManager.getProfile(DataStore.profileId)
|
||||
|
||||
fun switchProfile(id: Int): Profile {
|
||||
fun switchProfile(id: Long): Profile {
|
||||
val result = ProfileManager.getProfile(id) ?: ProfileManager.createProfile()
|
||||
DataStore.profileId = result.id
|
||||
return result
|
||||
@@ -116,8 +115,8 @@ class App : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
app = this
|
||||
if (!BuildConfig.DEBUG) System.setProperty(LocalLog.LOCAL_LOG_LEVEL_PROPERTY, "ERROR")
|
||||
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
|
||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
|
||||
PreferenceFragmentCompat.registerPreferenceFragment(IconListPreference::class.java,
|
||||
BottomSheetPreferenceDialogFragment::class.java)
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@ import android.support.v7.app.AlertDialog
|
||||
import android.support.v7.app.AppCompatActivity
|
||||
import android.support.v7.content.res.AppCompatResources
|
||||
import android.support.v7.preference.PreferenceDataStore
|
||||
import android.text.format.Formatter
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
@@ -49,7 +50,6 @@ import com.github.shadowsocks.aidl.IShadowsocksService
|
||||
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
|
||||
import com.github.shadowsocks.bg.BaseService
|
||||
import com.github.shadowsocks.bg.Executable
|
||||
import com.github.shadowsocks.bg.TrafficMonitor
|
||||
import com.github.shadowsocks.database.Profile
|
||||
import com.github.shadowsocks.database.ProfileManager
|
||||
import com.github.shadowsocks.preference.DataStore
|
||||
@@ -116,10 +116,10 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, Drawe
|
||||
override fun stateChanged(state: Int, profileName: String?, msg: String?) {
|
||||
app.handler.post { changeState(state, msg, true) }
|
||||
}
|
||||
override fun trafficUpdated(profileId: Int, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
override fun trafficUpdated(profileId: Long, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
app.handler.post { updateTraffic(profileId, txRate, rxRate, txTotal, rxTotal) }
|
||||
}
|
||||
override fun trafficPersisted(profileId: Int) {
|
||||
override fun trafficPersisted(profileId: Long) {
|
||||
app.handler.post { ProfilesFragment.instance?.onTrafficPersisted(profileId) }
|
||||
}
|
||||
}
|
||||
@@ -148,11 +148,11 @@ class MainActivity : AppCompatActivity(), ShadowsocksConnection.Interface, Drawe
|
||||
ProfilesFragment.instance?.profilesAdapter?.notifyDataSetChanged() // refresh button enabled state
|
||||
stateListener?.invoke(state)
|
||||
}
|
||||
fun updateTraffic(profileId: Int, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
txText.text = TrafficMonitor.formatTraffic(txTotal)
|
||||
rxText.text = TrafficMonitor.formatTraffic(rxTotal)
|
||||
txRateText.text = getString(R.string.speed, TrafficMonitor.formatTraffic(txRate))
|
||||
rxRateText.text = getString(R.string.speed, TrafficMonitor.formatTraffic(rxRate))
|
||||
fun updateTraffic(profileId: Long, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
txText.text = Formatter.formatFileSize(this, txTotal)
|
||||
rxText.text = Formatter.formatFileSize(this, rxTotal)
|
||||
txRateText.text = getString(R.string.speed, Formatter.formatFileSize(this, txRate))
|
||||
rxRateText.text = getString(R.string.speed, Formatter.formatFileSize(this, rxRate))
|
||||
val child = supportFragmentManager.findFragmentById(R.id.fragment_holder) as ToolbarFragment?
|
||||
if (state != BaseService.STOPPING)
|
||||
child?.onTrafficUpdated(profileId, txRate, rxRate, txTotal, rxTotal)
|
||||
|
||||
@@ -56,7 +56,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
|
||||
private const val REQUEST_CODE_PLUGIN_CONFIGURE = 1
|
||||
}
|
||||
|
||||
private var profileId = -1
|
||||
private var profileId = -1L
|
||||
private lateinit var isProxyApps: SwitchPreference
|
||||
private lateinit var plugin: IconListPreference
|
||||
private lateinit var pluginConfigure: EditTextPreference
|
||||
@@ -66,7 +66,7 @@ class ProfileConfigFragment : PreferenceFragmentCompatDividers(), Toolbar.OnMenu
|
||||
override fun onCreatePreferencesFix(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
preferenceManager.preferenceDataStore = DataStore.privateStore
|
||||
val activity = requireActivity()
|
||||
profileId = activity.intent.getIntExtra(Action.EXTRA_PROFILE_ID, -1)
|
||||
profileId = activity.intent.getLongExtra(Action.EXTRA_PROFILE_ID, -1L)
|
||||
addPreferencesFromResource(R.xml.pref_profile)
|
||||
if (Build.VERSION.SDK_INT >= 25 && activity.getSystemService(UserManager::class.java).isDemoUser) {
|
||||
findPreference(Key.host).summary = "shadowsocks.example.org"
|
||||
|
||||
@@ -33,13 +33,13 @@ import android.support.design.widget.Snackbar
|
||||
import android.support.v4.app.DialogFragment
|
||||
import android.support.v7.widget.*
|
||||
import android.support.v7.widget.helper.ItemTouchHelper
|
||||
import android.text.format.Formatter
|
||||
import android.view.*
|
||||
import android.widget.ImageView
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.TextView
|
||||
import com.github.shadowsocks.App.Companion.app
|
||||
import com.github.shadowsocks.bg.BaseService
|
||||
import com.github.shadowsocks.bg.TrafficMonitor
|
||||
import com.github.shadowsocks.database.Profile
|
||||
import com.github.shadowsocks.database.ProfileManager
|
||||
import com.github.shadowsocks.plugin.PluginConfiguration
|
||||
@@ -68,7 +68,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
BaseService.CONNECTED, BaseService.STOPPED -> true
|
||||
else -> false
|
||||
}
|
||||
private fun isProfileEditable(id: Int) = when ((activity as MainActivity).state) {
|
||||
private fun isProfileEditable(id: Long) = when ((activity as MainActivity).state) {
|
||||
BaseService.CONNECTED -> id != DataStore.profileId
|
||||
BaseService.STOPPED -> true
|
||||
else -> false
|
||||
@@ -123,7 +123,10 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
private var adView: AdView? = null
|
||||
|
||||
init {
|
||||
edit.setOnClickListener { startConfig(item) }
|
||||
edit.setOnClickListener {
|
||||
item = ProfileManager.getProfile(item.id)!!
|
||||
startConfig(item)
|
||||
}
|
||||
TooltipCompat.setTooltipText(edit, edit.contentDescription)
|
||||
itemView.setOnClickListener(this)
|
||||
val share = itemView.findViewById<View>(R.id.share)
|
||||
@@ -156,10 +159,11 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
text2.visibility = View.VISIBLE
|
||||
text2.text = t2.joinToString("\n")
|
||||
}
|
||||
val context = requireContext()
|
||||
if (tx <= 0 && rx <= 0) traffic.visibility = View.GONE else {
|
||||
traffic.visibility = View.VISIBLE
|
||||
traffic.text = getString(R.string.traffic,
|
||||
TrafficMonitor.formatTraffic(tx), TrafficMonitor.formatTraffic(rx))
|
||||
Formatter.formatFileSize(context, tx), Formatter.formatFileSize(context, rx))
|
||||
}
|
||||
|
||||
if (item.id == DataStore.profileId) {
|
||||
@@ -176,7 +180,6 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
val params = LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
|
||||
ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
params.gravity = Gravity.CENTER_HORIZONTAL
|
||||
val context = requireContext()
|
||||
adView = AdView(context)
|
||||
adView.layoutParams = params
|
||||
adView.adUnitId = "ca-app-pub-9097031975646651/7760346322"
|
||||
@@ -278,17 +281,17 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
for ((_, item) in actions) ProfileManager.delProfile(item.id)
|
||||
}
|
||||
|
||||
fun refreshId(id: Int) {
|
||||
fun refreshId(id: Long) {
|
||||
val index = profiles.indexOfFirst { it.id == id }
|
||||
if (index >= 0) notifyItemChanged(index)
|
||||
}
|
||||
fun deepRefreshId(id: Int) {
|
||||
fun deepRefreshId(id: Long) {
|
||||
val index = profiles.indexOfFirst { it.id == id }
|
||||
if (index < 0) return
|
||||
profiles[index] = ProfileManager.getProfile(id)!!
|
||||
notifyItemChanged(index)
|
||||
}
|
||||
fun removeId(id: Int) {
|
||||
fun removeId(id: Long) {
|
||||
val index = profiles.indexOfFirst { it.id == id }
|
||||
if (index < 0) return
|
||||
profiles.removeAt(index)
|
||||
@@ -301,7 +304,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
|
||||
val profilesAdapter by lazy { ProfilesAdapter() }
|
||||
private lateinit var undoManager: UndoSnackbarManager<Profile>
|
||||
private var bandwidthProfile: Int = 0
|
||||
private var bandwidthProfile = 0L
|
||||
private var txTotal: Long = 0L
|
||||
private var rxTotal: Long = 0L
|
||||
|
||||
@@ -321,8 +324,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
toolbar.inflateMenu(R.menu.profile_manager_menu)
|
||||
toolbar.setOnMenuItemClickListener(this)
|
||||
|
||||
if (ProfileManager.getFirstProfile() == null)
|
||||
DataStore.profileId = ProfileManager.createProfile().id
|
||||
if (!ProfileManager.isNotEmpty()) DataStore.profileId = ProfileManager.createProfile().id
|
||||
val profilesList = view.findViewById<RecyclerView>(R.id.list)
|
||||
val layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
|
||||
profilesList.layoutManager = layoutManager
|
||||
@@ -375,7 +377,9 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
Snackbar.LENGTH_LONG).show()
|
||||
return true
|
||||
}
|
||||
} catch (_: Exception) { }
|
||||
} catch (exc: Exception) {
|
||||
exc.printStackTrace()
|
||||
}
|
||||
Snackbar.make(requireActivity().findViewById(R.id.snackbar), R.string.action_import_err,
|
||||
Snackbar.LENGTH_LONG).show()
|
||||
true
|
||||
@@ -396,8 +400,8 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onTrafficUpdated(profileId: Int, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
if (profileId != -1) { // ignore resets from MainActivity
|
||||
override fun onTrafficUpdated(profileId: Long, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
if (profileId != -1L) { // ignore resets from MainActivity
|
||||
if (bandwidthProfile != profileId) {
|
||||
onTrafficPersisted(bandwidthProfile)
|
||||
bandwidthProfile = profileId
|
||||
@@ -407,7 +411,7 @@ class ProfilesFragment : ToolbarFragment(), Toolbar.OnMenuItemClickListener {
|
||||
profilesAdapter.refreshId(profileId)
|
||||
}
|
||||
}
|
||||
fun onTrafficPersisted(profileId: Int) {
|
||||
fun onTrafficPersisted(profileId: Long) {
|
||||
txTotal = 0
|
||||
rxTotal = 0
|
||||
if (bandwidthProfile != profileId) {
|
||||
|
||||
@@ -38,7 +38,7 @@ open class ToolbarFragment : Fragment() {
|
||||
activity.drawer.setToolbar(activity, toolbar, true)
|
||||
}
|
||||
|
||||
open fun onTrafficUpdated(profileId: Int, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) { }
|
||||
open fun onTrafficUpdated(profileId: Long, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) { }
|
||||
|
||||
open fun onBackPressed(): Boolean = false
|
||||
}
|
||||
|
||||
@@ -38,13 +38,13 @@ class AclSyncJob(private val route: String) : Job() {
|
||||
return when (parts[0]) {
|
||||
TAG -> AclSyncJob(parts[1])
|
||||
else -> {
|
||||
Log.w(TAG, "Unknown job tag: " + tag)
|
||||
Log.w(TAG, "Unknown job tag: $tag")
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun schedule(route: String): Int = JobRequest.Builder(TAG + ':' + route)
|
||||
fun schedule(route: String): Int = JobRequest.Builder("$TAG:$route")
|
||||
.setExecutionWindow(TimeUnit.SECONDS.toMillis(10), TimeUnit.DAYS.toMillis(28))
|
||||
.setRequirementsEnforced(true)
|
||||
.setRequiredNetworkType(JobRequest.NetworkType.UNMETERED)
|
||||
|
||||
@@ -50,7 +50,7 @@ import okhttp3.Request
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.net.UnknownHostException
|
||||
import java.net.*
|
||||
import java.security.MessageDigest
|
||||
import java.util.*
|
||||
import java.util.concurrent.TimeUnit
|
||||
@@ -76,7 +76,7 @@ object BaseService {
|
||||
@Volatile var state = STOPPED
|
||||
@Volatile var plugin = PluginOptions()
|
||||
@Volatile var pluginPath: String? = null
|
||||
var sslocalProcess: GuardedProcess? = null
|
||||
val processes = GuardedProcessPool()
|
||||
|
||||
var timer: Timer? = null
|
||||
var trafficMonitorThread: TrafficMonitorThread? = null
|
||||
@@ -274,7 +274,7 @@ object BaseService {
|
||||
|
||||
if (TcpFastOpen.sendEnabled) cmd += "--fast-open"
|
||||
|
||||
data.sslocalProcess = GuardedProcess(cmd).start()
|
||||
data.processes.start(cmd)
|
||||
}
|
||||
|
||||
fun createNotification(profileName: String): ServiceNotification
|
||||
@@ -285,11 +285,7 @@ object BaseService {
|
||||
else startService(Intent(this, javaClass))
|
||||
}
|
||||
|
||||
fun killProcesses() {
|
||||
val data = data
|
||||
data.sslocalProcess?.destroy()
|
||||
data.sslocalProcess = null
|
||||
}
|
||||
fun killProcesses() = data.processes.killAll()
|
||||
|
||||
fun stopRunner(stopService: Boolean, msg: String? = null) {
|
||||
// channge the state
|
||||
@@ -368,10 +364,6 @@ object BaseService {
|
||||
try {
|
||||
if (profile.host == "198.199.101.152") {
|
||||
val client = OkHttpClient.Builder()
|
||||
.dns {
|
||||
listOf((Dns.resolve(it, false) ?: throw UnknownHostException())
|
||||
.parseNumericAddress())
|
||||
}
|
||||
.connectTimeout(10, TimeUnit.SECONDS)
|
||||
.writeTimeout(10, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
@@ -406,7 +398,7 @@ object BaseService {
|
||||
killProcesses()
|
||||
|
||||
if (!profile.host.isNumericAddress())
|
||||
profile.host = Dns.resolve(profile.host, true) ?: throw UnknownHostException()
|
||||
profile.host = InetAddress.getByName(profile.host).hostAddress ?: throw UnknownHostException()
|
||||
|
||||
startNativeProcesses()
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* *
|
||||
* Copyright (C) 2017 by Max Lv <max.c.lv@gmail.com> *
|
||||
* Copyright (C) 2017 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.bg
|
||||
|
||||
import android.util.Log
|
||||
import com.github.shadowsocks.App.Companion.app
|
||||
import com.github.shadowsocks.BuildConfig
|
||||
import org.xbill.DNS.*
|
||||
import java.io.IOException
|
||||
import java.net.*
|
||||
|
||||
object Dns {
|
||||
private const val TAG = "Dns"
|
||||
|
||||
private val hasIPv6Support get() = try {
|
||||
val result = NetworkInterface.getNetworkInterfaces().asSequence().flatMap { it.inetAddresses.asSequence() }
|
||||
.any { it is Inet6Address && !it.isLoopbackAddress && !it.isLinkLocalAddress }
|
||||
if (result && BuildConfig.DEBUG) Log.d(TAG, "IPv6 address detected")
|
||||
result
|
||||
} catch (ex: SocketException) {
|
||||
Log.e(TAG, "Failed to get interfaces' addresses.", ex)
|
||||
app.track(ex)
|
||||
false
|
||||
}
|
||||
|
||||
private fun resolve(host: String, addrType: Int): String? {
|
||||
try {
|
||||
val lookup = Lookup(host, addrType)
|
||||
val resolver = SimpleResolver("208.67.220.220")
|
||||
resolver.setTCP(true)
|
||||
resolver.setPort(443)
|
||||
resolver.setTimeout(5)
|
||||
lookup.setResolver(resolver)
|
||||
val records = (lookup.run() ?: return null).toMutableList()
|
||||
records.shuffle()
|
||||
for (r in records) {
|
||||
when (addrType) {
|
||||
Type.A -> return (r as ARecord).address.hostAddress
|
||||
Type.AAAA -> return (r as AAAARecord).address.hostAddress
|
||||
}
|
||||
}
|
||||
} catch (_: IOException) { }
|
||||
return null
|
||||
}
|
||||
private fun resolve(host: String): String? = try {
|
||||
InetAddress.getByName(host).hostAddress
|
||||
} catch (_: UnknownHostException) {
|
||||
null
|
||||
}
|
||||
fun resolve(host: String, enableIPv6: Boolean): String? =
|
||||
(if (enableIPv6 && hasIPv6Support) resolve(host, Type.AAAA) else null)
|
||||
?: resolve(host, Type.A)
|
||||
?: resolve(host)
|
||||
}
|
||||
+62
-46
@@ -31,34 +31,37 @@ import com.github.shadowsocks.utils.thread
|
||||
import java.io.File
|
||||
import java.io.IOException
|
||||
import java.io.InputStream
|
||||
import java.util.concurrent.Semaphore
|
||||
import java.util.concurrent.ArrayBlockingQueue
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
|
||||
class GuardedProcess(private val cmd: List<String>) {
|
||||
class GuardedProcessPool {
|
||||
companion object {
|
||||
private const val TAG = "GuardedProcess"
|
||||
private const val TAG = "GuardedProcessPool"
|
||||
private val dummy = IOException()
|
||||
}
|
||||
|
||||
private lateinit var guardThread: Thread
|
||||
@Volatile
|
||||
private var isDestroyed = false
|
||||
@Volatile
|
||||
private lateinit var process: Process
|
||||
private val name = File(cmd.first()).nameWithoutExtension
|
||||
private inner class Guard(private val cmd: List<String>, private val onRestartCallback: (() -> Unit)?) {
|
||||
val cmdName = File(cmd.first()).nameWithoutExtension
|
||||
val excQueue = ArrayBlockingQueue<IOException>(1) // ArrayBlockingQueue doesn't want null
|
||||
private var pushed = false
|
||||
|
||||
private fun streamLogger(input: InputStream, logger: (String, String) -> Int) = thread("StreamLogger-$name") {
|
||||
try {
|
||||
input.bufferedReader().useLines { it.forEach { logger(TAG, it) } }
|
||||
} catch (_: IOException) { } // ignore
|
||||
}
|
||||
private fun streamLogger(input: InputStream, logger: (String, String) -> Int) =
|
||||
thread("StreamLogger-$cmdName") {
|
||||
try {
|
||||
input.bufferedReader().useLines { it.forEach { logger(TAG, it) } }
|
||||
} catch (_: IOException) { } // ignore
|
||||
}
|
||||
private fun pushException(ioException: IOException?) {
|
||||
if (pushed) return
|
||||
excQueue.put(ioException ?: dummy)
|
||||
pushed = true
|
||||
}
|
||||
|
||||
fun start(onRestartCallback: (() -> Unit)? = null): GuardedProcess {
|
||||
val semaphore = Semaphore(1)
|
||||
semaphore.acquire()
|
||||
var ioException: IOException? = null
|
||||
guardThread = thread("GuardThread-$name") {
|
||||
fun looper(host: HashSet<Thread>) {
|
||||
var process: Process? = null
|
||||
try {
|
||||
var callback: (() -> Unit)? = null
|
||||
while (!isDestroyed) {
|
||||
while (guardThreads.get() === host) {
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, "start process: " + Commandline.toString(cmd))
|
||||
val startTime = SystemClock.elapsedRealtime()
|
||||
|
||||
@@ -72,44 +75,57 @@ class GuardedProcess(private val cmd: List<String>) {
|
||||
|
||||
if (callback == null) callback = onRestartCallback else callback()
|
||||
|
||||
semaphore.release()
|
||||
pushException(null)
|
||||
process.waitFor()
|
||||
|
||||
synchronized(this) {
|
||||
if (SystemClock.elapsedRealtime() - startTime < 1000) {
|
||||
Log.w(TAG, "process exit too fast, stop guard: " + Commandline.toString(cmd))
|
||||
isDestroyed = true
|
||||
}
|
||||
if (SystemClock.elapsedRealtime() - startTime < 1000) {
|
||||
Log.w(TAG, "process exit too fast, stop guard: $cmdName")
|
||||
}
|
||||
}
|
||||
} catch (_: InterruptedException) {
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, "thread interrupt, destroy process: " + Commandline.toString(cmd))
|
||||
destroyProcess()
|
||||
if (BuildConfig.DEBUG) Log.d(TAG, "thread interrupt, destroy process: $cmdName")
|
||||
} catch (e: IOException) {
|
||||
ioException = e
|
||||
pushException(e)
|
||||
} finally {
|
||||
semaphore.release()
|
||||
if (process != null) {
|
||||
if (Build.VERSION.SDK_INT < 24) @Suppress("DEPRECATION") {
|
||||
JniHelper.sigtermCompat(process)
|
||||
JniHelper.waitForCompat(process, 500)
|
||||
}
|
||||
process.destroy()
|
||||
process.waitFor() // ensure the process is destroyed
|
||||
}
|
||||
pushException(null)
|
||||
}
|
||||
}
|
||||
semaphore.acquire()
|
||||
if (ioException != null) throw ioException!!
|
||||
}
|
||||
|
||||
/**
|
||||
* This is an indication of which thread pool is being active.
|
||||
* Reading/writing this collection still needs an additional lock to prevent concurrent modification.
|
||||
*/
|
||||
private val guardThreads = AtomicReference<HashSet<Thread>>(HashSet())
|
||||
|
||||
fun start(cmd: List<String>, onRestartCallback: (() -> Unit)? = null): GuardedProcessPool {
|
||||
val guard = Guard(cmd, onRestartCallback)
|
||||
val guardThreads = guardThreads.get()
|
||||
synchronized(guardThreads) {
|
||||
guardThreads.add(thread("GuardThread-${guard.cmdName}") {
|
||||
guard.looper(guardThreads)
|
||||
})
|
||||
}
|
||||
val ioException = guard.excQueue.take()
|
||||
if (ioException !== dummy) throw ioException
|
||||
return this
|
||||
}
|
||||
|
||||
fun destroy() {
|
||||
isDestroyed = true
|
||||
guardThread.interrupt()
|
||||
destroyProcess()
|
||||
try {
|
||||
guardThread.join()
|
||||
} catch (_: InterruptedException) { }
|
||||
}
|
||||
|
||||
private fun destroyProcess() {
|
||||
if (Build.VERSION.SDK_INT < 24) @Suppress("DEPRECATION") {
|
||||
JniHelper.sigtermCompat(process)
|
||||
JniHelper.waitForCompat(process, 500)
|
||||
fun killAll() {
|
||||
val guardThreads = guardThreads.getAndSet(HashSet())
|
||||
synchronized(guardThreads) {
|
||||
guardThreads.forEach { it.interrupt() }
|
||||
try {
|
||||
guardThreads.forEach { it.join() }
|
||||
} catch (_: InterruptedException) { }
|
||||
}
|
||||
process.destroy()
|
||||
}
|
||||
}
|
||||
@@ -28,19 +28,9 @@ import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
import java.io.File
|
||||
import java.net.Inet6Address
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* This object also uses WeakMap to simulate the effects of multi-inheritance, but more lightweight.
|
||||
*/
|
||||
object LocalDnsService {
|
||||
interface Interface : BaseService.Interface {
|
||||
var overtureProcess: GuardedProcess?
|
||||
get() = overtureProcesses[this]
|
||||
set(value) {
|
||||
if (value == null) overtureProcesses.remove(this) else overtureProcesses[this] = value
|
||||
}
|
||||
|
||||
override fun startNativeProcesses() {
|
||||
super.startNativeProcesses()
|
||||
val data = data
|
||||
@@ -72,11 +62,11 @@ object LocalDnsService {
|
||||
.put("MinimumTTL", 120)
|
||||
.put("CacheSize", 4096)
|
||||
val remoteDns = JSONArray(profile.remoteDns.split(",")
|
||||
.mapIndexed { i, dns -> makeDns("UserDef-$i", dns.trim() + ":53", 9) })
|
||||
.mapIndexed { i, dns -> makeDns("UserDef-$i", dns.trim() + ":53", 12) })
|
||||
val localDns = JSONArray(arrayOf(
|
||||
makeDns("Primary-1", "208.67.222.222:443", 3, false),
|
||||
makeDns("Primary-2", "119.29.29.29:53", 3, false),
|
||||
makeDns("Primary-3", "114.114.114.114:53", 3, false)
|
||||
makeDns("Primary-1", "208.67.222.222:443", 9, false),
|
||||
makeDns("Primary-2", "119.29.29.29:53", 9, false),
|
||||
makeDns("Primary-3", "114.114.114.114:53", 9, false)
|
||||
))
|
||||
|
||||
when (profile.route) {
|
||||
@@ -96,18 +86,10 @@ object LocalDnsService {
|
||||
return file
|
||||
}
|
||||
|
||||
if (!profile.udpdns) overtureProcess = GuardedProcess(buildAdditionalArguments(arrayListOf(
|
||||
if (!profile.udpdns) data.processes.start(buildAdditionalArguments(arrayListOf(
|
||||
File(app.applicationInfo.nativeLibraryDir, Executable.OVERTURE).absolutePath,
|
||||
"-c", buildOvertureConfig("overture.conf")
|
||||
))).start()
|
||||
}
|
||||
|
||||
override fun killProcesses() {
|
||||
super.killProcesses()
|
||||
overtureProcess?.destroy()
|
||||
overtureProcess = null
|
||||
)))
|
||||
}
|
||||
}
|
||||
|
||||
private val overtureProcesses = WeakHashMap<Interface, GuardedProcess>()
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ import android.os.Build
|
||||
import android.os.PowerManager
|
||||
import android.support.v4.app.NotificationCompat
|
||||
import android.support.v4.content.ContextCompat
|
||||
import android.text.format.Formatter
|
||||
import com.github.shadowsocks.MainActivity
|
||||
import com.github.shadowsocks.R
|
||||
import com.github.shadowsocks.aidl.IShadowsocksServiceCallback
|
||||
@@ -53,16 +54,16 @@ class ServiceNotification(private val service: BaseService.Interface, profileNam
|
||||
private val callback by lazy {
|
||||
object : IShadowsocksServiceCallback.Stub() {
|
||||
override fun stateChanged(state: Int, profileName: String?, msg: String?) { } // ignore
|
||||
override fun trafficUpdated(profileId: Int, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
override fun trafficUpdated(profileId: Long, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) {
|
||||
service as Context
|
||||
val txr = service.getString(R.string.speed, TrafficMonitor.formatTraffic(txRate))
|
||||
val rxr = service.getString(R.string.speed, TrafficMonitor.formatTraffic(rxRate))
|
||||
val txr = service.getString(R.string.speed, Formatter.formatFileSize(service, txRate))
|
||||
val rxr = service.getString(R.string.speed, Formatter.formatFileSize(service, rxRate))
|
||||
builder.setContentText("$txr↑\t$rxr↓")
|
||||
style.bigText(service.getString(R.string.stat_summary).format(Locale.ENGLISH, txr, rxr,
|
||||
TrafficMonitor.formatTraffic(txTotal), TrafficMonitor.formatTraffic(rxTotal)))
|
||||
Formatter.formatFileSize(service, txTotal), Formatter.formatFileSize(service, rxTotal)))
|
||||
show()
|
||||
}
|
||||
override fun trafficPersisted(profileId: Int) { }
|
||||
override fun trafficPersisted(profileId: Long) { }
|
||||
}
|
||||
}
|
||||
private val lockReceiver = broadcastReceiver { _, intent -> update(intent.action) }
|
||||
|
||||
@@ -64,8 +64,8 @@ class TileService : BaseTileService(), ShadowsocksConnection.Interface {
|
||||
tile.label = label ?: getString(R.string.app_name)
|
||||
tile.updateTile()
|
||||
}
|
||||
override fun trafficUpdated(profileId: Int, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) { }
|
||||
override fun trafficPersisted(profileId: Int) { }
|
||||
override fun trafficUpdated(profileId: Long, txRate: Long, rxRate: Long, txTotal: Long, rxTotal: Long) { }
|
||||
override fun trafficPersisted(profileId: Long) { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -21,9 +21,6 @@
|
||||
package com.github.shadowsocks.bg
|
||||
|
||||
import android.os.SystemClock
|
||||
import com.github.shadowsocks.App.Companion.app
|
||||
import com.github.shadowsocks.R
|
||||
import java.text.DecimalFormat
|
||||
|
||||
object TrafficMonitor {
|
||||
// Bytes per second
|
||||
@@ -41,19 +38,6 @@ object TrafficMonitor {
|
||||
@Volatile
|
||||
private var dirty = true
|
||||
|
||||
private val units = arrayOf("KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "BB", "NB", "DB", "CB")
|
||||
private val numberFormat = DecimalFormat("@@@")
|
||||
fun formatTraffic(size: Long): String {
|
||||
var n = size.toDouble()
|
||||
var i = -1
|
||||
while (n >= 999.5) {
|
||||
n /= 1024
|
||||
++i
|
||||
}
|
||||
return if (i < 0) "$size ${app.resources.getQuantityString(R.plurals.bytes, size.toInt())}"
|
||||
else "${numberFormat.format(n)} ${units[i]}"
|
||||
}
|
||||
|
||||
fun updateRate(): Boolean {
|
||||
val now = SystemClock.elapsedRealtime()
|
||||
val delta = now - timestampLast
|
||||
|
||||
@@ -40,18 +40,14 @@ class TransproxyService : Service(), LocalDnsService.Interface {
|
||||
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int =
|
||||
super<LocalDnsService.Interface>.onStartCommand(intent, flags, startId)
|
||||
|
||||
private var sstunnelProcess: GuardedProcess? = null
|
||||
private var redsocksProcess: GuardedProcess? = null
|
||||
|
||||
private fun startDNSTunnel() {
|
||||
val cmd = arrayListOf(File(applicationInfo.nativeLibraryDir, Executable.SS_TUNNEL).absolutePath,
|
||||
data.processes.start(listOf(File(applicationInfo.nativeLibraryDir, Executable.SS_TUNNEL).absolutePath,
|
||||
"-t", "10",
|
||||
"-b", "127.0.0.1",
|
||||
"-u",
|
||||
"-l", DataStore.portLocalDns.toString(), // ss-tunnel listens on the same port as overture
|
||||
"-L", data.profile!!.remoteDns.split(",").first().trim() + ":53",
|
||||
"-c", data.shadowsocksConfigFile!!.absolutePath) // config is already built by BaseService.Interface
|
||||
sstunnelProcess = GuardedProcess(cmd).start()
|
||||
"-c", data.shadowsocksConfigFile!!.absolutePath)) // config is already built by BaseService.Interface
|
||||
}
|
||||
|
||||
private fun startRedsocksDaemon() {
|
||||
@@ -70,10 +66,8 @@ redsocks {
|
||||
type = socks5;
|
||||
}
|
||||
""")
|
||||
redsocksProcess = GuardedProcess(arrayListOf(
|
||||
File(applicationInfo.nativeLibraryDir, Executable.REDSOCKS).absolutePath,
|
||||
"-c", "redsocks.conf")
|
||||
).start()
|
||||
data.processes.start(listOf(
|
||||
File(applicationInfo.nativeLibraryDir, Executable.REDSOCKS).absolutePath, "-c", "redsocks.conf"))
|
||||
}
|
||||
|
||||
override fun startNativeProcesses() {
|
||||
@@ -81,12 +75,4 @@ redsocks {
|
||||
super.startNativeProcesses()
|
||||
if (data.profile!!.udpdns) startDNSTunnel()
|
||||
}
|
||||
|
||||
override fun killProcesses() {
|
||||
super.killProcesses()
|
||||
sstunnelProcess?.destroy()
|
||||
sstunnelProcess = null
|
||||
redsocksProcess?.destroy()
|
||||
redsocksProcess = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ import android.net.VpnService as BaseVpnService
|
||||
class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
||||
companion object {
|
||||
private const val VPN_MTU = 1500
|
||||
private const val PRIVATE_VLAN = "26.26.26.%s"
|
||||
private const val PRIVATE_VLAN = "172.19.0.%s"
|
||||
private const val PRIVATE_VLAN6 = "fdfe:dcba:9876::%s"
|
||||
|
||||
private val getInt: Method = FileDescriptor::class.java.getDeclaredMethod("getInt$")
|
||||
@@ -116,7 +116,6 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
||||
|
||||
private var conn: ParcelFileDescriptor? = null
|
||||
private var worker: ProtectWorker? = null
|
||||
private var tun2socksProcess: GuardedProcess? = null
|
||||
private var underlyingNetwork: Network? = null
|
||||
@TargetApi(28)
|
||||
set(value) {
|
||||
@@ -155,8 +154,6 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
||||
worker?.stopThread()
|
||||
worker = null
|
||||
super.killProcesses()
|
||||
tun2socksProcess?.destroy()
|
||||
tun2socksProcess = null
|
||||
conn?.close()
|
||||
conn = null
|
||||
}
|
||||
@@ -256,7 +253,7 @@ class VpnService : BaseVpnService(), LocalDnsService.Interface {
|
||||
cmd += "--dnsgw"
|
||||
cmd += "127.0.0.1:${DataStore.portLocalDns}"
|
||||
}
|
||||
tun2socksProcess = GuardedProcess(cmd).start { sendFd(fd) }
|
||||
data.processes.start(cmd) { sendFd(fd) }
|
||||
return fd
|
||||
}
|
||||
|
||||
|
||||
@@ -20,37 +20,54 @@
|
||||
|
||||
package com.github.shadowsocks.database
|
||||
|
||||
import com.j256.ormlite.field.DataType
|
||||
import com.j256.ormlite.field.DatabaseField
|
||||
import android.arch.persistence.room.*
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
@Entity
|
||||
class KeyValuePair() {
|
||||
companion object {
|
||||
const val TYPE_UNINITIALIZED = 0
|
||||
const val TYPE_BOOLEAN = 1
|
||||
const val TYPE_FLOAT = 2
|
||||
@Deprecated("Use TYPE_LONG.")
|
||||
const val TYPE_INT = 3
|
||||
const val TYPE_LONG = 4
|
||||
const val TYPE_STRING = 5
|
||||
const val TYPE_STRING_SET = 6
|
||||
}
|
||||
|
||||
@DatabaseField(id = true)
|
||||
var key: String? = ""
|
||||
@DatabaseField
|
||||
@android.arch.persistence.room.Dao
|
||||
interface Dao {
|
||||
@Query("SELECT * FROM `KeyValuePair` WHERE `key` = :key")
|
||||
operator fun get(key: String): KeyValuePair?
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun put(value: KeyValuePair): Long
|
||||
|
||||
@Query("DELETE FROM `KeyValuePair` WHERE `key` = :key")
|
||||
fun delete(key: String): Int
|
||||
}
|
||||
|
||||
@PrimaryKey
|
||||
var key: String = ""
|
||||
var valueType: Int = TYPE_UNINITIALIZED
|
||||
@DatabaseField(dataType = DataType.BYTE_ARRAY)
|
||||
var value: ByteArray = ByteArray(0)
|
||||
|
||||
val boolean: Boolean?
|
||||
get() = if (valueType == TYPE_BOOLEAN) ByteBuffer.wrap(value).get() != 0.toByte() else null
|
||||
val float: Float?
|
||||
get() = if (valueType == TYPE_FLOAT) ByteBuffer.wrap(value).float else null
|
||||
@Suppress("DEPRECATION")
|
||||
@Deprecated("Use long.", ReplaceWith("long"))
|
||||
val int: Int?
|
||||
get() = if (valueType == TYPE_INT) ByteBuffer.wrap(value).int else null
|
||||
val long: Long?
|
||||
get() = if (valueType == TYPE_LONG) ByteBuffer.wrap(value).long else null
|
||||
val long: Long? get() = when (valueType) {
|
||||
@Suppress("DEPRECATION")
|
||||
TYPE_INT -> ByteBuffer.wrap(value).int.toLong()
|
||||
TYPE_LONG -> ByteBuffer.wrap(value).long
|
||||
else -> null
|
||||
}
|
||||
val string: String?
|
||||
get() = if (valueType == TYPE_STRING) String(value) else null
|
||||
val stringSet: Set<String>?
|
||||
@@ -65,7 +82,8 @@ class KeyValuePair() {
|
||||
result
|
||||
} else null
|
||||
|
||||
constructor(key: String?) : this() {
|
||||
@Ignore
|
||||
constructor(key: String) : this() {
|
||||
this.key = key
|
||||
}
|
||||
|
||||
@@ -80,6 +98,8 @@ class KeyValuePair() {
|
||||
this.value = ByteBuffer.allocate(4).putFloat(value).array()
|
||||
return this
|
||||
}
|
||||
@Suppress("DEPRECATION")
|
||||
@Deprecated("Use long.")
|
||||
fun put(value: Int): KeyValuePair {
|
||||
valueType = TYPE_INT
|
||||
this.value = ByteBuffer.allocate(4).putInt(value).array()
|
||||
|
||||
@@ -20,137 +20,39 @@
|
||||
|
||||
package com.github.shadowsocks.database
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.support.v7.preference.PreferenceManager
|
||||
import android.text.TextUtils
|
||||
import android.arch.persistence.db.SupportSQLiteDatabase
|
||||
import android.arch.persistence.room.Database
|
||||
import android.arch.persistence.room.Room
|
||||
import android.arch.persistence.room.RoomDatabase
|
||||
import com.github.shadowsocks.App.Companion.app
|
||||
import com.github.shadowsocks.database.migration.RecreateSchemaMigration
|
||||
import com.github.shadowsocks.utils.Key
|
||||
import com.j256.ormlite.android.AndroidDatabaseConnection
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
|
||||
import com.j256.ormlite.dao.Dao
|
||||
import com.j256.ormlite.support.ConnectionSource
|
||||
import com.j256.ormlite.table.TableUtils
|
||||
|
||||
object PrivateDatabase : OrmLiteSqliteOpenHelper(app, Key.DB_PROFILE, null, 25) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val profileDao: Dao<Profile, Int> by lazy { getDao(Profile::class.java) as Dao<Profile, Int> }
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val kvPairDao: Dao<KeyValuePair, String?> by lazy { getDao(KeyValuePair::class.java) as Dao<KeyValuePair, String?> }
|
||||
|
||||
override fun onCreate(database: SQLiteDatabase?, connectionSource: ConnectionSource?) {
|
||||
TableUtils.createTable(connectionSource, Profile::class.java)
|
||||
TableUtils.createTable(connectionSource, KeyValuePair::class.java)
|
||||
}
|
||||
|
||||
private fun recreate(database: SQLiteDatabase?, connectionSource: ConnectionSource?) {
|
||||
TableUtils.dropTable<Profile, Int>(connectionSource, Profile::class.java, true)
|
||||
TableUtils.dropTable<KeyValuePair, String?>(connectionSource, KeyValuePair::class.java, true)
|
||||
onCreate(database, connectionSource)
|
||||
}
|
||||
|
||||
override fun onUpgrade(database: SQLiteDatabase?, connectionSource: ConnectionSource?,
|
||||
oldVersion: Int, newVersion: Int) {
|
||||
if (oldVersion < 7) {
|
||||
recreate(database, connectionSource)
|
||||
return
|
||||
@Database(entities = [Profile::class, KeyValuePair::class], version = 26)
|
||||
abstract class PrivateDatabase : RoomDatabase() {
|
||||
companion object {
|
||||
private val instance by lazy {
|
||||
Room.databaseBuilder(app, PrivateDatabase::class.java, Key.DB_PROFILE)
|
||||
.addMigrations(
|
||||
Migration26
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.allowMainThreadQueries()
|
||||
.build()
|
||||
}
|
||||
|
||||
try {
|
||||
if (oldVersion < 8) {
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN udpdns SMALLINT;")
|
||||
}
|
||||
if (oldVersion < 9) {
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN route VARCHAR DEFAULT 'all';")
|
||||
} else if (oldVersion < 19) {
|
||||
profileDao.executeRawNoArgs("UPDATE `profile` SET route = 'all' WHERE route IS NULL;")
|
||||
}
|
||||
if (oldVersion < 11) {
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN ipv6 SMALLINT;")
|
||||
}
|
||||
if (oldVersion < 12) {
|
||||
profileDao.executeRawNoArgs("BEGIN TRANSACTION;")
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` RENAME TO `tmp`;")
|
||||
TableUtils.createTable(connectionSource, Profile::class.java)
|
||||
profileDao.executeRawNoArgs(
|
||||
"INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route," +
|
||||
" proxyApps, bypass, udpdns, ipv6, individual) " +
|
||||
"SELECT id, name, host, localPort, remotePort, password, method, route, 1 - global," +
|
||||
" bypass, udpdns, ipv6, individual FROM `tmp`;")
|
||||
profileDao.executeRawNoArgs("DROP TABLE `tmp`;")
|
||||
profileDao.executeRawNoArgs("COMMIT;")
|
||||
} else if (oldVersion < 13) {
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN tx LONG;")
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN rx LONG;")
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN date VARCHAR;")
|
||||
}
|
||||
|
||||
if (oldVersion < 15) {
|
||||
if (oldVersion >= 12) profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN userOrder LONG;")
|
||||
var i = 0L
|
||||
val apps by lazy { app.packageManager.getInstalledApplications(0) }
|
||||
for (profile in profileDao.queryForAll()) {
|
||||
if (oldVersion < 14) {
|
||||
val uidSet = profile.individual.split('|').filter(TextUtils::isDigitsOnly)
|
||||
.map(String::toInt).toSet()
|
||||
profile.individual = apps.filter { uidSet.contains(it.uid) }
|
||||
.joinToString("\n") { it.packageName }
|
||||
}
|
||||
profile.userOrder = i
|
||||
profileDao.update(profile)
|
||||
i += 1
|
||||
}
|
||||
}
|
||||
|
||||
if (oldVersion < 16) {
|
||||
profileDao.executeRawNoArgs(
|
||||
"UPDATE `profile` SET route = 'bypass-lan-china' WHERE route = 'bypass-china'")
|
||||
}
|
||||
|
||||
if (oldVersion < 21) {
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN remoteDns VARCHAR DEFAULT '8.8.8.8';")
|
||||
}
|
||||
|
||||
if (oldVersion < 17) {
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` ADD COLUMN plugin VARCHAR;")
|
||||
} else if (oldVersion < 22) {
|
||||
// upgrade kcptun to SIP003 plugin
|
||||
profileDao.executeRawNoArgs("BEGIN TRANSACTION;")
|
||||
profileDao.executeRawNoArgs("ALTER TABLE `profile` RENAME TO `tmp`;")
|
||||
TableUtils.createTable(connectionSource, Profile::class.java)
|
||||
profileDao.executeRawNoArgs(
|
||||
"INSERT INTO `profile`(id, name, host, localPort, remotePort, password, method, route, " +
|
||||
"remoteDns, proxyApps, bypass, udpdns, ipv6, individual, tx, rx, date, userOrder, " +
|
||||
"plugin) " +
|
||||
"SELECT id, name, host, localPort, " +
|
||||
"CASE WHEN kcp = 1 THEN kcpPort ELSE remotePort END, password, method, route, " +
|
||||
"remoteDns, proxyApps, bypass, udpdns, ipv6, individual, tx, rx, date, userOrder, " +
|
||||
"CASE WHEN kcp = 1 THEN 'kcptun ' || kcpcli ELSE NULL END FROM `tmp`;")
|
||||
profileDao.executeRawNoArgs("DROP TABLE `tmp`;")
|
||||
profileDao.executeRawNoArgs("COMMIT;")
|
||||
}
|
||||
|
||||
if (oldVersion < 23) {
|
||||
profileDao.executeRawNoArgs("BEGIN TRANSACTION;")
|
||||
TableUtils.createTable(connectionSource, KeyValuePair::class.java)
|
||||
profileDao.executeRawNoArgs("COMMIT;")
|
||||
val old = PreferenceManager.getDefaultSharedPreferences(app)
|
||||
PublicDatabase.kvPairDao.createOrUpdate(KeyValuePair(Key.id).put(old.getInt(Key.id, 0)))
|
||||
PublicDatabase.kvPairDao.createOrUpdate(KeyValuePair(Key.tfo).put(old.getBoolean(Key.tfo, false)))
|
||||
}
|
||||
|
||||
if (oldVersion < 25) {
|
||||
PublicDatabase.onUpgrade(database, 0, -1)
|
||||
}
|
||||
} catch (ex: Exception) {
|
||||
app.track(ex)
|
||||
recreate(database, connectionSource)
|
||||
}
|
||||
val profileDao get() = instance.profileDao()
|
||||
val kvPairDao get() = instance.keyValuePairDao()
|
||||
}
|
||||
abstract fun profileDao(): Profile.Dao
|
||||
abstract fun keyValuePairDao(): KeyValuePair.Dao
|
||||
|
||||
override fun onDowngrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
|
||||
val connection = AndroidDatabaseConnection(db, true)
|
||||
connectionSource.saveSpecialConnection(connection)
|
||||
recreate(db, connectionSource)
|
||||
connectionSource.clearSpecialConnection(connection)
|
||||
private object Migration26 : RecreateSchemaMigration(25, 26, "Profile",
|
||||
"(`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `name` TEXT, `host` TEXT NOT NULL, `remotePort` INTEGER NOT NULL, `password` TEXT NOT NULL, `method` TEXT NOT NULL, `route` TEXT NOT NULL, `remoteDns` TEXT NOT NULL, `proxyApps` INTEGER NOT NULL, `bypass` INTEGER NOT NULL, `udpdns` INTEGER NOT NULL, `ipv6` INTEGER NOT NULL, `individual` TEXT NOT NULL, `tx` INTEGER NOT NULL, `rx` INTEGER NOT NULL, `userOrder` INTEGER NOT NULL, `plugin` TEXT)",
|
||||
"`id`, `name`, `host`, `remotePort`, `password`, `method`, `route`, `remoteDns`, `proxyApps`, `bypass`, `udpdns`, `ipv6`, `individual`, `tx`, `rx`, `userOrder`, `plugin`") {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
super.migrate(database)
|
||||
PublicDatabase.Migration3.migrate(database)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
package com.github.shadowsocks.database
|
||||
|
||||
import android.arch.persistence.room.*
|
||||
import android.net.Uri
|
||||
import android.util.Base64
|
||||
import android.util.Log
|
||||
@@ -27,13 +28,12 @@ import com.github.shadowsocks.plugin.PluginConfiguration
|
||||
import com.github.shadowsocks.preference.DataStore
|
||||
import com.github.shadowsocks.utils.Key
|
||||
import com.github.shadowsocks.utils.parsePort
|
||||
import com.j256.ormlite.field.DataType
|
||||
import com.j256.ormlite.field.DatabaseField
|
||||
import java.io.Serializable
|
||||
import java.net.URI
|
||||
import java.net.URISyntaxException
|
||||
import java.util.*
|
||||
|
||||
@Entity
|
||||
class Profile : Serializable {
|
||||
companion object {
|
||||
private const val TAG = "ShadowParser"
|
||||
@@ -93,61 +93,50 @@ class Profile : Serializable {
|
||||
}.filterNotNull()
|
||||
}
|
||||
|
||||
@DatabaseField(generatedId = true)
|
||||
var id: Int = 0
|
||||
@android.arch.persistence.room.Dao
|
||||
interface Dao {
|
||||
@Query("SELECT * FROM `Profile` WHERE `id` = :id")
|
||||
operator fun get(id: Long): Profile?
|
||||
|
||||
@DatabaseField
|
||||
@Query("SELECT * FROM `Profile` ORDER BY `userOrder`")
|
||||
fun list(): List<Profile>
|
||||
|
||||
@Query("SELECT MAX(`userOrder`) + 1 FROM `Profile`")
|
||||
fun nextOrder(): Long?
|
||||
|
||||
@Query("SELECT 1 FROM `Profile` LIMIT 1")
|
||||
fun isNotEmpty(): Boolean
|
||||
|
||||
@Insert
|
||||
fun create(value: Profile): Long
|
||||
|
||||
@Update
|
||||
fun update(value: Profile): Int
|
||||
|
||||
@Query("DELETE FROM `Profile` WHERE `id` = :id")
|
||||
fun delete(id: Long): Int
|
||||
}
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Long = 0
|
||||
var name: String? = ""
|
||||
|
||||
@DatabaseField
|
||||
var host: String = "198.199.101.152"
|
||||
|
||||
@DatabaseField
|
||||
var remotePort: Int = 8388
|
||||
|
||||
@DatabaseField
|
||||
var password: String = "u1rRWTssNv0p"
|
||||
|
||||
@DatabaseField
|
||||
var method: String = "aes-256-cfb"
|
||||
|
||||
@DatabaseField
|
||||
var route: String = "all"
|
||||
|
||||
@DatabaseField
|
||||
var remoteDns: String = "8.8.8.8"
|
||||
|
||||
@DatabaseField
|
||||
var proxyApps: Boolean = false
|
||||
|
||||
@DatabaseField
|
||||
var bypass: Boolean = false
|
||||
|
||||
@DatabaseField
|
||||
var udpdns: Boolean = false
|
||||
|
||||
@DatabaseField
|
||||
var ipv6: Boolean = true
|
||||
|
||||
@DatabaseField(dataType = DataType.LONG_STRING)
|
||||
var individual: String = ""
|
||||
|
||||
@DatabaseField
|
||||
var tx: Long = 0
|
||||
|
||||
@DatabaseField
|
||||
var rx: Long = 0
|
||||
|
||||
@DatabaseField
|
||||
val date: Date = Date()
|
||||
|
||||
@DatabaseField
|
||||
var userOrder: Long = 0
|
||||
|
||||
@DatabaseField
|
||||
var plugin: String? = null
|
||||
|
||||
// not persisted in db, only used by direct boot
|
||||
@Ignore // not persisted in db, only used by direct boot
|
||||
var dirty: Boolean = false
|
||||
|
||||
val formattedAddress get() = (if (host.contains(":")) "[%s]:%d" else "%s:%d").format(host, remotePort)
|
||||
|
||||
@@ -50,10 +50,8 @@ object ProfileManager {
|
||||
profile.individual = oldProfile.individual
|
||||
profile.udpdns = oldProfile.udpdns
|
||||
}
|
||||
val last = PrivateDatabase.profileDao.queryRaw(PrivateDatabase.profileDao.queryBuilder()
|
||||
.selectRaw("MAX(userOrder)").prepareStatementString()).firstResult
|
||||
if (last != null && last.size == 1 && last[0] != null) profile.userOrder = last[0].toLong() + 1
|
||||
PrivateDatabase.profileDao.createOrUpdate(profile)
|
||||
profile.userOrder = PrivateDatabase.profileDao.nextOrder() ?: 0
|
||||
profile.id = PrivateDatabase.profileDao.create(profile)
|
||||
ProfilesFragment.instance?.profilesAdapter?.add(profile)
|
||||
return profile
|
||||
}
|
||||
@@ -62,11 +60,11 @@ object ProfileManager {
|
||||
* Note: It's caller's responsibility to update DirectBoot profile if necessary.
|
||||
*/
|
||||
@Throws(SQLException::class)
|
||||
fun updateProfile(profile: Profile) = PrivateDatabase.profileDao.update(profile)
|
||||
fun updateProfile(profile: Profile) = check(PrivateDatabase.profileDao.update(profile) == 1)
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getProfile(id: Int): Profile? = try {
|
||||
PrivateDatabase.profileDao.queryForId(id)
|
||||
fun getProfile(id: Long): Profile? = try {
|
||||
PrivateDatabase.profileDao[id]
|
||||
} catch (ex: SQLException) {
|
||||
if (ex.cause is SQLiteCantOpenDatabaseException) throw IOException(ex)
|
||||
Log.e(TAG, "getProfile", ex)
|
||||
@@ -75,25 +73,25 @@ object ProfileManager {
|
||||
}
|
||||
|
||||
@Throws(SQLException::class)
|
||||
fun delProfile(id: Int) {
|
||||
PrivateDatabase.profileDao.deleteById(id)
|
||||
fun delProfile(id: Long) {
|
||||
check(PrivateDatabase.profileDao.delete(id) == 1)
|
||||
ProfilesFragment.instance?.profilesAdapter?.removeId(id)
|
||||
if (id == DataStore.profileId && DataStore.directBootAware) DirectBoot.clean()
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getFirstProfile(): Profile? = try {
|
||||
PrivateDatabase.profileDao.query(PrivateDatabase.profileDao.queryBuilder().limit(1L).prepare()).singleOrNull()
|
||||
fun isNotEmpty(): Boolean = try {
|
||||
PrivateDatabase.profileDao.isNotEmpty()
|
||||
} catch (ex: SQLException) {
|
||||
if (ex.cause is SQLiteCantOpenDatabaseException) throw IOException(ex)
|
||||
Log.e(TAG, "getFirstProfile", ex)
|
||||
Log.e(TAG, "isNotEmpty", ex)
|
||||
app.track(ex)
|
||||
null
|
||||
false
|
||||
}
|
||||
|
||||
@Throws(IOException::class)
|
||||
fun getAllProfiles(): List<Profile>? = try {
|
||||
PrivateDatabase.profileDao.query(PrivateDatabase.profileDao.queryBuilder().orderBy("userOrder", true).prepare())
|
||||
PrivateDatabase.profileDao.list()
|
||||
} catch (ex: SQLException) {
|
||||
if (ex.cause is SQLiteCantOpenDatabaseException) throw IOException(ex)
|
||||
Log.e(TAG, "getAllProfiles", ex)
|
||||
|
||||
@@ -20,42 +20,31 @@
|
||||
|
||||
package com.github.shadowsocks.database
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase
|
||||
import android.arch.persistence.room.Database
|
||||
import android.arch.persistence.room.Room
|
||||
import android.arch.persistence.room.RoomDatabase
|
||||
import com.github.shadowsocks.App.Companion.app
|
||||
import com.github.shadowsocks.acl.Acl
|
||||
import com.github.shadowsocks.database.migration.RecreateSchemaMigration
|
||||
import com.github.shadowsocks.utils.Key
|
||||
import com.j256.ormlite.android.AndroidDatabaseConnection
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper
|
||||
import com.j256.ormlite.dao.Dao
|
||||
import com.j256.ormlite.support.ConnectionSource
|
||||
import com.j256.ormlite.table.TableUtils
|
||||
|
||||
object PublicDatabase : OrmLiteSqliteOpenHelper(app.deviceContext, Key.DB_PUBLIC, null, 2) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val kvPairDao: Dao<KeyValuePair, String?> by lazy { getDao(KeyValuePair::class.java) as Dao<KeyValuePair, String?> }
|
||||
|
||||
override fun onCreate(database: SQLiteDatabase?, connectionSource: ConnectionSource?) {
|
||||
TableUtils.createTable(connectionSource, KeyValuePair::class.java)
|
||||
}
|
||||
|
||||
override fun onUpgrade(database: SQLiteDatabase?, connectionSource: ConnectionSource?,
|
||||
oldVersion: Int, newVersion: Int) {
|
||||
if (oldVersion < 1) {
|
||||
PrivateDatabase.kvPairDao.queryBuilder().where().`in`("key",
|
||||
Key.id, Key.tfo, Key.serviceMode, Key.portProxy, Key.portLocalDns, Key.portTransproxy).query()
|
||||
.forEach { kvPairDao.createOrUpdate(it) }
|
||||
@Database(entities = [(KeyValuePair::class)], version = 3)
|
||||
abstract class PublicDatabase : RoomDatabase() {
|
||||
companion object {
|
||||
private val instance by lazy {
|
||||
Room.databaseBuilder(app.deviceContext, PublicDatabase::class.java, Key.DB_PUBLIC)
|
||||
.allowMainThreadQueries()
|
||||
.addMigrations(
|
||||
Migration3
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
|
||||
if (oldVersion < 2) {
|
||||
kvPairDao.createOrUpdate(KeyValuePair(Acl.CUSTOM_RULES).put(Acl().fromId(Acl.CUSTOM_RULES).toString()))
|
||||
}
|
||||
val kvPairDao get() = instance.keyValuePairDao()
|
||||
}
|
||||
abstract fun keyValuePairDao(): KeyValuePair.Dao
|
||||
|
||||
override fun onDowngrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
|
||||
val connection = AndroidDatabaseConnection(db, true)
|
||||
connectionSource.saveSpecialConnection(connection)
|
||||
TableUtils.dropTable<KeyValuePair, String?>(connectionSource, KeyValuePair::class.java, true)
|
||||
onCreate(db, connectionSource)
|
||||
connectionSource.clearSpecialConnection(connection)
|
||||
}
|
||||
internal object Migration3 : RecreateSchemaMigration(2, 3, "KeyValuePair",
|
||||
"(`key` TEXT NOT NULL, `valueType` INTEGER NOT NULL, `value` BLOB NOT NULL, PRIMARY KEY(`key`))",
|
||||
"`key`, `valueType`, `value`")
|
||||
}
|
||||
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*******************************************************************************
|
||||
* *
|
||||
* Copyright (C) 2018 by Max Lv <max.c.lv@gmail.com> *
|
||||
* Copyright (C) 2018 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.database.migration
|
||||
|
||||
import android.arch.persistence.db.SupportSQLiteDatabase
|
||||
import android.arch.persistence.room.migration.Migration
|
||||
|
||||
open class RecreateSchemaMigration(oldVersion: Int, newVersion: Int, private val table: String,
|
||||
private val schema: String, private val keys: String) :
|
||||
Migration(oldVersion, newVersion) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("CREATE TABLE `tmp` $schema")
|
||||
database.execSQL("INSERT INTO `tmp` ($keys) SELECT $keys FROM `$table`")
|
||||
database.execSQL("DROP TABLE `$table`")
|
||||
database.execSQL("ALTER TABLE `tmp` RENAME TO `$table`")
|
||||
}
|
||||
}
|
||||
@@ -29,9 +29,9 @@ import com.github.shadowsocks.utils.Key
|
||||
import com.github.shadowsocks.utils.parsePort
|
||||
|
||||
object DataStore {
|
||||
val publicStore = OrmLitePreferenceDataStore(PublicDatabase.kvPairDao)
|
||||
val publicStore = RoomPreferenceDataStore(PublicDatabase.kvPairDao)
|
||||
// privateStore will only be used as temp storage for ProfileConfigFragment
|
||||
val privateStore = OrmLitePreferenceDataStore(PrivateDatabase.kvPairDao)
|
||||
val privateStore = RoomPreferenceDataStore(PrivateDatabase.kvPairDao)
|
||||
|
||||
// hopefully hashCode = mHandle doesn't change, currently this is true from KitKat to Nougat
|
||||
private val userIndex by lazy { Binder.getCallingUserHandle().hashCode() }
|
||||
@@ -43,10 +43,10 @@ object DataStore {
|
||||
} else parsePort(publicStore.getString(key), default + userIndex)
|
||||
}
|
||||
|
||||
var profileId: Int
|
||||
get() = publicStore.getInt(Key.id) ?: 0
|
||||
var profileId: Long
|
||||
get() = publicStore.getLong(Key.id) ?: 0
|
||||
set(value) {
|
||||
publicStore.putInt(Key.id, value)
|
||||
publicStore.putLong(Key.id, value)
|
||||
if (DataStore.directBootAware) DirectBoot.update()
|
||||
}
|
||||
val canToggleLocked: Boolean get() = publicStore.getBoolean(Key.directBootAware) == true
|
||||
|
||||
@@ -1,82 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* *
|
||||
* Copyright (C) 2017 by Max Lv <max.c.lv@gmail.com> *
|
||||
* Copyright (C) 2017 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.support.v7.preference.PreferenceDataStore
|
||||
import com.github.shadowsocks.database.KeyValuePair
|
||||
import com.j256.ormlite.dao.Dao
|
||||
import java.util.HashSet
|
||||
|
||||
@Suppress("MemberVisibilityCanPrivate", "unused")
|
||||
open class OrmLitePreferenceDataStore(private val kvPairDao: Dao<KeyValuePair, String?>) : PreferenceDataStore() {
|
||||
fun getBoolean(key: String?) = kvPairDao.queryForId(key)?.boolean
|
||||
fun getFloat(key: String?) = kvPairDao.queryForId(key)?.float
|
||||
fun getInt(key: String?) = kvPairDao.queryForId(key)?.int
|
||||
fun getLong(key: String?) = kvPairDao.queryForId(key)?.long
|
||||
fun getString(key: String?) = kvPairDao.queryForId(key)?.string
|
||||
fun getStringSet(key: String?) = kvPairDao.queryForId(key)?.stringSet
|
||||
|
||||
override fun getBoolean(key: String?, defValue: Boolean) = getBoolean(key) ?: defValue
|
||||
override fun getFloat(key: String?, defValue: Float) = getFloat(key) ?: defValue
|
||||
override fun getInt(key: String?, defValue: Int) = getInt(key) ?: defValue
|
||||
override fun getLong(key: String?, defValue: Long) = getLong(key) ?: defValue
|
||||
override fun getString(key: String?, defValue: String?) = getString(key) ?: defValue
|
||||
override fun getStringSet(key: String?, defValue: MutableSet<String>?) = getStringSet(key) ?: defValue
|
||||
|
||||
fun putBoolean(key: String?, value: Boolean?) = if (value == null) remove(key) else putBoolean(key, value)
|
||||
fun putFloat(key: String?, value: Float?) = if (value == null) remove(key) else putFloat(key, value)
|
||||
fun putInt(key: String?, value: Int?) = if (value == null) remove(key) else putInt(key, value)
|
||||
fun putLong(key: String?, value: Long?) = if (value == null) remove(key) else putLong(key, value)
|
||||
override fun putBoolean(key: String?, value: Boolean) {
|
||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putFloat(key: String?, value: Float) {
|
||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putInt(key: String?, value: Int) {
|
||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putLong(key: String?, value: Long) {
|
||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putString(key: String?, value: String?) = if (value == null) remove(key) else {
|
||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(value))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putStringSet(key: String?, values: MutableSet<String>?) = if (values == null) remove(key) else {
|
||||
kvPairDao.createOrUpdate(KeyValuePair(key).put(values))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
|
||||
fun remove(key: String?) {
|
||||
kvPairDao.deleteById(key)
|
||||
fireChangeListener(key)
|
||||
}
|
||||
|
||||
private val listeners = HashSet<OnPreferenceDataStoreChangeListener>()
|
||||
private fun fireChangeListener(key: String?) = listeners.forEach { it.onPreferenceDataStoreChanged(this, key) }
|
||||
fun registerChangeListener(listener: OnPreferenceDataStoreChangeListener) = listeners.add(listener)
|
||||
fun unregisterChangeListener(listener: OnPreferenceDataStoreChangeListener) = listeners.remove(listener)
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
/*******************************************************************************
|
||||
* *
|
||||
* Copyright (C) 2017 by Max Lv <max.c.lv@gmail.com> *
|
||||
* Copyright (C) 2017 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.support.v7.preference.PreferenceDataStore
|
||||
import com.github.shadowsocks.database.KeyValuePair
|
||||
import java.util.HashSet
|
||||
|
||||
@Suppress("MemberVisibilityCanBePrivate", "unused")
|
||||
open class RoomPreferenceDataStore(private val kvPairDao: KeyValuePair.Dao) : PreferenceDataStore() {
|
||||
fun getBoolean(key: String) = kvPairDao[key]?.boolean
|
||||
fun getFloat(key: String) = kvPairDao[key]?.float
|
||||
fun getInt(key: String) = kvPairDao[key]?.long?.toInt()
|
||||
fun getLong(key: String) = kvPairDao[key]?.long
|
||||
fun getString(key: String) = kvPairDao[key]?.string
|
||||
fun getStringSet(key: String) = kvPairDao[key]?.stringSet
|
||||
|
||||
override fun getBoolean(key: String, defValue: Boolean) = getBoolean(key) ?: defValue
|
||||
override fun getFloat(key: String, defValue: Float) = getFloat(key) ?: defValue
|
||||
override fun getInt(key: String, defValue: Int) = getInt(key) ?: defValue
|
||||
override fun getLong(key: String, defValue: Long) = getLong(key) ?: defValue
|
||||
override fun getString(key: String, defValue: String?) = getString(key) ?: defValue
|
||||
override fun getStringSet(key: String, defValue: MutableSet<String>?) = getStringSet(key) ?: defValue
|
||||
|
||||
fun putBoolean(key: String, value: Boolean?) = if (value == null) remove(key) else putBoolean(key, value)
|
||||
fun putFloat(key: String, value: Float?) = if (value == null) remove(key) else putFloat(key, value)
|
||||
fun putInt(key: String, value: Int?) = if (value == null) remove(key) else putLong(key, value.toLong())
|
||||
fun putLong(key: String, value: Long?) = if (value == null) remove(key) else putLong(key, value)
|
||||
override fun putBoolean(key: String, value: Boolean) {
|
||||
kvPairDao.put(KeyValuePair(key).put(value))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putFloat(key: String, value: Float) {
|
||||
kvPairDao.put(KeyValuePair(key).put(value))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putInt(key: String, value: Int) {
|
||||
kvPairDao.put(KeyValuePair(key).put(value.toLong()))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putLong(key: String, value: Long) {
|
||||
kvPairDao.put(KeyValuePair(key).put(value))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putString(key: String, value: String?) = if (value == null) remove(key) else {
|
||||
kvPairDao.put(KeyValuePair(key).put(value))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
override fun putStringSet(key: String, values: MutableSet<String>?) = if (values == null) remove(key) else {
|
||||
kvPairDao.put(KeyValuePair(key).put(values))
|
||||
fireChangeListener(key)
|
||||
}
|
||||
|
||||
fun remove(key: String) {
|
||||
kvPairDao.delete(key)
|
||||
fireChangeListener(key)
|
||||
}
|
||||
|
||||
private val listeners = HashSet<OnPreferenceDataStoreChangeListener>()
|
||||
private fun fireChangeListener(key: String) = listeners.forEach { it.onPreferenceDataStoreChanged(this, key) }
|
||||
fun registerChangeListener(listener: OnPreferenceDataStoreChangeListener) = listeners.add(listener)
|
||||
fun unregisterChangeListener(listener: OnPreferenceDataStoreChangeListener) = listeners.remove(listener)
|
||||
}
|
||||
@@ -36,12 +36,17 @@ class Settings(bundle: Bundle?) {
|
||||
}
|
||||
|
||||
var switchOn: Boolean = bundle?.getBoolean(KEY_SWITCH_ON, true) ?: true
|
||||
var profileId: Int = bundle?.getInt(KEY_PROFILE_ID, -1) ?: -1
|
||||
var profileId: Long
|
||||
|
||||
init {
|
||||
profileId = bundle?.getLong(KEY_PROFILE_ID, -1L) ?: -1L
|
||||
if (profileId < 0) profileId = (bundle?.getInt(KEY_PROFILE_ID, -1) ?: -1).toLong()
|
||||
}
|
||||
|
||||
fun toIntent(context: Context): Intent {
|
||||
val bundle = Bundle()
|
||||
if (!switchOn) bundle.putBoolean(KEY_SWITCH_ON, false)
|
||||
if (profileId >= 0) bundle.putInt(KEY_PROFILE_ID, profileId)
|
||||
if (profileId >= 0) bundle.putLong(KEY_PROFILE_ID, profileId)
|
||||
val profile = ProfileManager.getProfile(profileId)
|
||||
return Intent().putExtra(ApiIntent.EXTRA_BUNDLE, bundle).putExtra(ApiIntent.EXTRA_STRING_BLURB,
|
||||
if (profile != null) context.getString(if (switchOn) R.string.start_service else R.string.stop_service,
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
android:layout_height="match_parent"
|
||||
android:padding="16dp">
|
||||
<Spinner android:id="@+id/template_selector"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:paddingStart="12dp"
|
||||
android:paddingEnd="12dp">
|
||||
android:paddingEnd="12dp"
|
||||
android:focusable="true">
|
||||
<ImageView android:id="@android:id/icon"
|
||||
android:layout_width="52dp"
|
||||
android:layout_height="52dp"/>
|
||||
|
||||
@@ -20,10 +20,6 @@
|
||||
<string name="traffic">%s↑\t%s↓</string>
|
||||
<string name="stat_summary">Sent: \t\t\t\t\t%3$s\t↑\t%1$s\nReceived: \t%4$s\t↓\t%2$s</string>
|
||||
<string name="speed">%s/s</string>
|
||||
<plurals name="bytes">
|
||||
<item quantity="one">Byte</item>
|
||||
<item quantity="other">Bytes</item>
|
||||
</plurals>
|
||||
<string name="connection_test_pending">Check Connectivity</string>
|
||||
<string name="connection_test_testing">Testing…</string>
|
||||
<string name="connection_test_available">Success: %dms latency</string>
|
||||
|
||||
@@ -1,15 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<style name="Theme.Translucent" parent="Theme.AppCompat.Dialog">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowFrame">@null</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:windowAnimationStyle">@null</item>
|
||||
<item name="android:backgroundDimEnabled">false</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowCloseOnTouchOutside">false</item>
|
||||
</style>
|
||||
<style name="StyledScrollerTextAppearance" parent="@android:style/TextAppearance">
|
||||
<item name="android:textSize">24sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
|
||||
@@ -29,7 +29,8 @@ class KeyValuePairTest {
|
||||
val kvp = KeyValuePair()
|
||||
Assert.assertEquals(true, kvp.put(true).boolean)
|
||||
Assert.assertEquals(3f, kvp.put(3f).float)
|
||||
Assert.assertEquals(3, kvp.put(3).int)
|
||||
@Suppress("DEPRECATION")
|
||||
Assert.assertEquals(3L, kvp.put(3).long)
|
||||
Assert.assertEquals(3L, kvp.put(3L).long)
|
||||
Assert.assertEquals("3", kvp.put("3").string)
|
||||
val set = (0 until 3).map(Int::toString).toSet()
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
* 0.1.1:
|
||||
* Rewritten in Kotlin;
|
||||
* Fix assert not working;
|
||||
* Min API 21;
|
||||
* Update support library version to 27.1.1.
|
||||
* 0.0.4:
|
||||
* Enlarge text size of number pickers;
|
||||
* Update support library version to 26.0.0.
|
||||
|
||||
+3
-3
@@ -10,8 +10,8 @@ android {
|
||||
defaultConfig {
|
||||
minSdkVersion rootProject.minSdkVersion
|
||||
targetSdkVersion rootProject.sdkVersion
|
||||
versionCode 5
|
||||
versionName "0.1.0"
|
||||
versionCode 6
|
||||
versionName "0.1.1"
|
||||
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -26,7 +26,7 @@ android {
|
||||
dependencies {
|
||||
api "com.android.support:preference-v14:$supportLibraryVersion"
|
||||
api "com.takisoft.fix:preference-v7:$takisoftFixVersion"
|
||||
api "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlinVersion"
|
||||
api "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion"
|
||||
testImplementation "junit:junit:$junitVersion"
|
||||
androidTestImplementation "com.android.support.test:runner:$androidTestVersion"
|
||||
androidTestImplementation "com.android.support.test.espresso:espresso-core:$androidEspressoVersion"
|
||||
|
||||
+2
-1
@@ -153,7 +153,8 @@ This corresponds to `com.github.shadowsocks.plugin.NativePluginProvider` in the
|
||||
...
|
||||
<provider android:name=".BinaryProvider"
|
||||
android:exported="true"
|
||||
android:authorities="$FULLY_QUALIFIED_NAME_OF_YOUR_CONTENTPROVIDER">
|
||||
android:authorities="$FULLY_QUALIFIED_NAME_OF_YOUR_CONTENTPROVIDER"
|
||||
tools:ignore="ExportedContentProvider">
|
||||
<intent-filter>
|
||||
<action android:name="com.github.shadowsocks.plugin.ACTION_NATIVE_PLUGIN"/>
|
||||
</intent-filter>
|
||||
|
||||
@@ -11,4 +11,15 @@
|
||||
<item name="preferenceCategory_marginBottom">8dp</item>
|
||||
<item name="windowActionModeOverlay">true</item>
|
||||
</style>
|
||||
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.Dialog">
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:windowFrame">@null</item>
|
||||
<item name="android:windowContentOverlay">@null</item>
|
||||
<item name="android:windowAnimationStyle">@null</item>
|
||||
<item name="android:backgroundDimEnabled">false</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowCloseOnTouchOutside">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user