├── LICENSE ├── README.md ├── app ├── .gitignore ├── CMakeLists.txt ├── build.gradle ├── libs │ ├── arm64-v8a │ │ ├── libpdnsd.so │ │ ├── libproxychains4.so │ │ ├── libredsocks.so │ │ ├── libssr-local.so │ │ └── libtun2socks.so │ ├── armeabi-v7a │ │ ├── libpdnsd.so │ │ ├── libproxychains4.so │ │ ├── libredsocks.so │ │ ├── libssr-local.so │ │ └── libtun2socks.so │ ├── x86 │ │ ├── libpdnsd.so │ │ ├── libproxychains4.so │ │ ├── libredsocks.so │ │ ├── libssr-local.so │ │ └── tun2socks.so │ └── x86_64 │ │ ├── libpdnsd.so │ │ ├── libproxychains4.so │ │ ├── libredsocks.so │ │ ├── libssr-local.so │ │ └── tun2socks.so ├── proguard-rules.pro └── src │ └── main │ ├── AndroidManifest.xml │ ├── aidl │ └── co │ │ └── tgbot │ │ └── peekfun │ │ └── aidl │ │ ├── IShadowsocksService.aidl │ │ └── IShadowsocksServiceCallback.aidl │ ├── assets │ ├── acl │ │ ├── ACL4SSR-backcn-banAD.acl │ │ ├── ACL4SSR-banAD.acl │ │ ├── ACL4SSR-fullgfwlist.acl │ │ ├── ACL4SSR-gfwlist-banAD.acl │ │ ├── ACL4SSR-gfwlist-user.rule │ │ ├── ACL4SSR-nobanAD.acl │ │ ├── ACL4SSR-onlybanAD.acl │ │ ├── bypass-china.acl │ │ ├── bypass-lan-china.acl │ │ ├── bypass-lan.acl │ │ ├── china-list.acl │ │ └── gfwlist.acl │ ├── fonts │ │ └── Iceland.ttf │ └── pages │ │ └── about.html │ ├── cpp │ ├── ancillary │ │ ├── ancillary.h │ │ ├── fd_recv.c │ │ └── fd_send.c │ ├── cpufeatures │ │ ├── cpu-features.c │ │ └── cpu-features.h │ └── system.cpp │ ├── java │ └── co │ │ └── tgbot │ │ └── peekfun │ │ ├── AppManager.java │ │ ├── BaseService.java │ │ ├── BaseVpnService.java │ │ ├── BootReceiver.java │ │ ├── GuardedProcess.java │ │ ├── ProfileManagerActivity.java │ │ ├── QuickToggleShortcut.java │ │ ├── ScannerActivity.java │ │ ├── ServiceBoundContext.java │ │ ├── ServiceBoundService.java │ │ ├── Shadowsocks.java │ │ ├── ShadowsocksApplication.java │ │ ├── ShadowsocksBackupAgent.java │ │ ├── ShadowsocksNotification.java │ │ ├── ShadowsocksQuickSwitchActivity.java │ │ ├── ShadowsocksRunnerActivity.java │ │ ├── ShadowsocksRunnerService.java │ │ ├── ShadowsocksSettings.java │ │ ├── ShadowsocksTileService.java │ │ ├── ShadowsocksVpnService.java │ │ ├── ShadowsocksVpnThread.java │ │ ├── System.java │ │ ├── TaskerActivity.java │ │ ├── TaskerReceiver.java │ │ ├── database │ │ ├── DBHelper.java │ │ ├── Profile.java │ │ ├── ProfileManager.java │ │ ├── SSRSub.java │ │ └── SSRSubManager.java │ │ ├── job │ │ ├── AclSyncJob.java │ │ ├── DonaldTrump.java │ │ └── SSRSubUpdateJob.java │ │ ├── network │ │ ├── ping │ │ │ ├── PingCallback.kt │ │ │ └── PingHelper.kt │ │ ├── request │ │ │ ├── RequestCallback.kt │ │ │ └── RequestHelper.kt │ │ └── ssrsub │ │ │ ├── SubUpdateCallback.kt │ │ │ └── SubUpdateHelper.kt │ │ ├── preferences │ │ ├── DropDownPreference.java │ │ ├── NumberPickerPreference.java │ │ ├── PasswordEditTextPreference.java │ │ ├── SummaryDialogPreference.java │ │ ├── SummaryEditTextPreference.java │ │ └── SummaryPreference.java │ │ ├── utils │ │ ├── Constants.java │ │ ├── IOUtils.java │ │ ├── Parser.java │ │ ├── TaskerSettings.java │ │ ├── TcpFastOpen.java │ │ ├── ToastUtils.java │ │ ├── TrafficMonitor.java │ │ ├── TrafficMonitorThread.java │ │ ├── Typefaces.java │ │ ├── Utils.java │ │ └── VayLog.java │ │ └── widget │ │ ├── FloatingActionMenuBehavior.java │ │ └── UndoSnackbarManager.java │ └── res │ ├── drawable-anydpi-v21 │ ├── ic_action_settings.xml │ ├── ic_navigation_close.xml │ ├── ic_qu_camera_launcher.xml │ └── ic_qu_shadowsocks_launcher.xml │ ├── drawable-hdpi │ ├── ic_action_settings.png │ ├── ic_navigation_close.png │ └── ic_stat_shadowsocks.png │ ├── drawable-mdpi │ ├── ic_action_settings.png │ ├── ic_navigation_close.png │ └── ic_stat_shadowsocks.png │ ├── drawable-v21 │ └── background_stat.xml │ ├── drawable-xhdpi │ ├── ic_action_settings.png │ ├── ic_navigation_close.png │ └── ic_stat_shadowsocks.png │ ├── drawable-xxhdpi │ ├── ic_action_settings.png │ ├── ic_navigation_close.png │ └── ic_stat_shadowsocks.png │ ├── drawable-xxxhdpi │ ├── ic_action_settings.png │ └── ic_navigation_close.png │ ├── drawable │ ├── background_stat.xml │ ├── ic_arrow_drop_down.xml │ ├── ic_click.xml │ ├── ic_click_white.xml │ ├── ic_content_add.xml │ ├── ic_content_copy.xml │ ├── ic_content_create.xml │ ├── ic_content_paste.xml │ ├── ic_device_nfc.xml │ ├── ic_down.xml │ ├── ic_http.xml │ ├── ic_image_camera_alt.xml │ ├── ic_rss.xml │ ├── ic_social_share.xml │ ├── ic_start_busy.xml │ ├── ic_start_connected.xml │ ├── ic_start_idle.xml │ └── ic_tcp.xml │ ├── layout-w400dp │ └── layout_main_stat_title.xml │ ├── layout │ ├── layout_apps.xml │ ├── layout_apps_item.xml │ ├── layout_edittext.xml │ ├── layout_front_proxy.xml │ ├── layout_main.xml │ ├── layout_main_stat_title.xml │ ├── layout_profiles.xml │ ├── layout_profiles_item.xml │ ├── layout_quick_switch.xml │ ├── layout_scanner.xml │ ├── layout_ssr_sub.xml │ ├── layout_ssr_sub_item.xml │ ├── layout_tasker.xml │ └── toolbar_light_dark.xml │ ├── menu │ ├── app_manager_menu.xml │ └── profile_manager_menu.xml │ ├── mipmap-hdpi │ └── ic_launcher.png │ ├── mipmap-mdpi │ └── ic_launcher.png │ ├── mipmap-xhdpi │ └── ic_launcher.png │ ├── mipmap-xxhdpi │ └── ic_launcher.png │ ├── mipmap-xxxhdpi │ └── ic_launcher.png │ ├── raw │ └── gtm_default_container │ ├── values-ja-v21 │ └── strings.xml │ ├── values-ja │ └── strings.xml │ ├── values-ru-v21 │ └── strings.xml │ ├── values-ru │ └── strings.xml │ ├── values-v21 │ ├── dimen.xml │ ├── strings.xml │ └── styles.xml │ ├── values-zh-rCN-v21 │ └── strings.xml │ ├── values-zh-rCN │ └── strings.xml │ ├── values-zh-rTW-v21 │ └── strings.xml │ ├── values-zh-rTW │ └── strings.xml │ ├── values │ ├── arrays.xml │ ├── attrs.xml │ ├── chnroute.xml │ ├── colors.xml │ ├── configs.xml │ ├── dimen.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ ├── network_security_config.xml │ ├── pref_all.xml │ ├── shortcuts.xml │ └── tracker.xml ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /README.md: -------------------------------------------------------------------------------- 1 | # Maying 2 | A ShadowsocksRR client for Android, written in Java. 3 | Modified from [https://github.com/xhvay/ShadowsocksRR](https://github.com/xhvay/ShadowsocksRR) 4 | 5 | 6 | 7 | ### PREREQUISITES 8 | 9 | * JDK 1.8 10 | * AndroidStudio 3.5 11 | * Android Build Tools 29+ 12 | * Android NDK 19+ 13 | 14 | ### COMMUNICATION 15 | 16 | - TG channel: [拾趣](https://t.me/peekfun) 17 | - TG group: [经常改名](http://t.me/joinchat/K5hKwle9NveVqnzucnuxQw) -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.4.1) 2 | 3 | include_directories(src/main/cpp/cpufeatures) 4 | include_directories(src/main/cpp/ancillary) 5 | 6 | find_library( log-lib 7 | log ) 8 | 9 | add_library( system 10 | SHARED 11 | src/main/cpp/system.cpp ) 12 | 13 | add_library( cpufeatures 14 | SHARED 15 | src/main/cpp/cpufeatures/cpu-features.c ) 16 | 17 | add_library( ancillary 18 | SHARED 19 | src/main/cpp/ancillary/fd_recv.c 20 | src/main/cpp/ancillary/fd_send.c ) 21 | 22 | target_link_libraries( system 23 | cpufeatures 24 | ancillary 25 | ${log-lib}) -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | ext { 2 | supportVersion = '28.0.0' 3 | } 4 | apply plugin: 'com.android.application' 5 | apply plugin: 'kotlin-android' 6 | apply plugin: 'kotlin-android-extensions' 7 | 8 | buildscript { 9 | ext { 10 | support_version = "28.0.0" 11 | compile_Version = 29 12 | min_version = 21 13 | target_version = 28 14 | } 15 | } 16 | 17 | android { 18 | compileSdkVersion compile_Version 19 | lintOptions { 20 | abortOnError false 21 | } 22 | defaultConfig { 23 | applicationId "co.tgbot.peekfun" 24 | minSdkVersion min_version 25 | targetSdkVersion target_version 26 | versionCode 112 // multiDex的一些相关配置,这样配置可以让你的编译速度更快 27 | dexOptions { 28 | // 让它不要对Lib做preDexing 29 | preDexLibraries = false 30 | // 开启incremental dexing,优化编译效率,这个功能android studio默认是关闭的 31 | // incremental true 32 | // 增加java堆内存大小 33 | javaMaxHeapSize "4g" 34 | } 35 | versionName "1.0.8" 36 | externalNativeBuild { 37 | cmake { 38 | cppFlags "-frtti -fexceptions" 39 | abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64" 40 | } 41 | } 42 | multiDexEnabled true 43 | proguardFiles 44 | } 45 | buildTypes { 46 | release { 47 | minifyEnabled false 48 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 49 | } 50 | } 51 | externalNativeBuild { 52 | cmake { 53 | path "CMakeLists.txt" 54 | } 55 | } 56 | sourceSets { 57 | main { 58 | jniLibs.srcDirs = ['libs'] 59 | } 60 | } 61 | compileOptions { 62 | sourceCompatibility JavaVersion.VERSION_1_8 63 | targetCompatibility JavaVersion.VERSION_1_8 64 | } 65 | } 66 | 67 | dependencies { 68 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 69 | 70 | 71 | implementation fileTree(dir: 'libs', include: ['*.jar']) 72 | //noinspection GradleCompatible 73 | implementation 'androidx.appcompat:appcompat:1.0.2' 74 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 75 | implementation 'com.google.android.material:material:1.0.0' 76 | implementation 'androidx.gridlayout:gridlayout:1.0.0' 77 | implementation 'androidx.coordinatorlayout:coordinatorlayout:1.0.0' 78 | 79 | implementation 'androidx.recyclerview:recyclerview:1.0.0' 80 | 81 | implementation 'com.evernote:android-job:1.3.0-rc1' 82 | implementation "android.arch.work:work-runtime:1.0.1" 83 | implementation "com.github.clans:fab:1.6.4" 84 | implementation "com.github.jorgecastilloprz:fabprogresscircle:1.01" 85 | implementation "com.google.android.gms:play-services-analytics:17.0.0" 86 | implementation "com.google.android.gms:play-services-gcm:17.0.0" 87 | implementation "com.j256.ormlite:ormlite-android:5.1" 88 | implementation "com.mikepenz:fastadapter:2.1.5" 89 | implementation "com.mikepenz:iconics-core:2.8.2" 90 | implementation "com.mikepenz:materialdrawer:5.8.1" 91 | implementation 'com.mikepenz:materialize:1.2.1' 92 | implementation "com.twofortyfouram:android-plugin-api-for-locale:1.0.4" 93 | implementation "dnsjava:dnsjava:2.1.9" 94 | implementation 'eu.chainfire:libsuperuser:latest.release' 95 | implementation "me.dm7.barcodescanner:zxing:1.9.13" 96 | implementation "net.glxn.qrgen:android:2.0" 97 | implementation 'com.squareup.okhttp3:okhttp:4.1.1' 98 | implementation "com.google.code.findbugs:jsr305:3.0.2" 99 | 100 | 101 | } 102 | 103 | 104 | repositories { 105 | mavenCentral() 106 | } 107 | -------------------------------------------------------------------------------- /app/libs/arm64-v8a/libpdnsd.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/arm64-v8a/libpdnsd.so -------------------------------------------------------------------------------- /app/libs/arm64-v8a/libproxychains4.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/arm64-v8a/libproxychains4.so -------------------------------------------------------------------------------- /app/libs/arm64-v8a/libredsocks.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/arm64-v8a/libredsocks.so -------------------------------------------------------------------------------- /app/libs/arm64-v8a/libssr-local.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/arm64-v8a/libssr-local.so -------------------------------------------------------------------------------- /app/libs/arm64-v8a/libtun2socks.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/arm64-v8a/libtun2socks.so -------------------------------------------------------------------------------- /app/libs/armeabi-v7a/libpdnsd.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/armeabi-v7a/libpdnsd.so -------------------------------------------------------------------------------- /app/libs/armeabi-v7a/libproxychains4.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/armeabi-v7a/libproxychains4.so -------------------------------------------------------------------------------- /app/libs/armeabi-v7a/libredsocks.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/armeabi-v7a/libredsocks.so -------------------------------------------------------------------------------- /app/libs/armeabi-v7a/libssr-local.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/armeabi-v7a/libssr-local.so -------------------------------------------------------------------------------- /app/libs/armeabi-v7a/libtun2socks.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/armeabi-v7a/libtun2socks.so -------------------------------------------------------------------------------- /app/libs/x86/libpdnsd.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86/libpdnsd.so -------------------------------------------------------------------------------- /app/libs/x86/libproxychains4.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86/libproxychains4.so -------------------------------------------------------------------------------- /app/libs/x86/libredsocks.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86/libredsocks.so -------------------------------------------------------------------------------- /app/libs/x86/libssr-local.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86/libssr-local.so -------------------------------------------------------------------------------- /app/libs/x86/tun2socks.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86/tun2socks.so -------------------------------------------------------------------------------- /app/libs/x86_64/libpdnsd.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86_64/libpdnsd.so -------------------------------------------------------------------------------- /app/libs/x86_64/libproxychains4.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86_64/libproxychains4.so -------------------------------------------------------------------------------- /app/libs/x86_64/libredsocks.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86_64/libredsocks.so -------------------------------------------------------------------------------- /app/libs/x86_64/libssr-local.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86_64/libssr-local.so -------------------------------------------------------------------------------- /app/libs/x86_64/tun2socks.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/libs/x86_64/tun2socks.so -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | 23 | -keep class co.tgbot.peekfun.System { *; } 24 | -keep class okhttp3.** { *; } 25 | -keep interface okhttp3.** { *; } 26 | -keep class okio.** { *; } 27 | -keep interface okio.** { *; } 28 | -dontwarn okio.** 29 | -dontwarn com.google.android.gms.internal.** 30 | -dontwarn com.j256.ormlite.** 31 | -dontwarn org.xbill.** 32 | -dontwarn javax.annotation.Nullable 33 | -dontwarn javax.annotation.ParametersAreNonnullByDefault -------------------------------------------------------------------------------- /app/src/main/aidl/co/tgbot/peekfun/aidl/IShadowsocksService.aidl: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.aidl; 2 | 3 | import co.tgbot.peekfun.aidl.IShadowsocksServiceCallback; 4 | 5 | interface IShadowsocksService { 6 | int getState(); 7 | String getProfileName(); 8 | 9 | oneway void registerCallback(IShadowsocksServiceCallback cb); 10 | oneway void unregisterCallback(IShadowsocksServiceCallback cb); 11 | 12 | oneway void use(in int profileId); 13 | void useSync(in int profileId); 14 | } 15 | -------------------------------------------------------------------------------- /app/src/main/aidl/co/tgbot/peekfun/aidl/IShadowsocksServiceCallback.aidl: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.aidl; 2 | 3 | interface IShadowsocksServiceCallback { 4 | oneway void stateChanged(int state, String profileName, String msg); 5 | oneway void trafficUpdated(long txRate, long rxRate, long txTotal, long rxTotal); 6 | } 7 | -------------------------------------------------------------------------------- /app/src/main/assets/acl/bypass-lan.acl: -------------------------------------------------------------------------------- 1 | [proxy_all] 2 | 3 | [bypass_list] 4 | 0.0.0.0/8 5 | 10.0.0.0/8 6 | 100.64.0.0/10 7 | 127.0.0.0/8 8 | 169.254.0.0/16 9 | 172.16.0.0/12 10 | 192.0.0.0/29 11 | 192.0.2.0/24 12 | 192.88.99.0/24 13 | 192.168.0.0/16 14 | 198.18.0.0/15 15 | 198.51.100.0/24 16 | 203.0.113.0/24 17 | 224.0.0.0/3 18 | -------------------------------------------------------------------------------- /app/src/main/assets/fonts/Iceland.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/assets/fonts/Iceland.ttf -------------------------------------------------------------------------------- /app/src/main/cpp/ancillary/ancillary.h: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * libancillary - black magic on Unix domain sockets 3 | * (C) Nicolas George 4 | * ancillary.h - public header 5 | ***************************************************************************/ 6 | 7 | /* 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 22 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef ANCILLARY_H__ 32 | #define ANCILLARY_H__ 33 | 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | /*************************************************************************** 39 | * Start of the readable part. 40 | ***************************************************************************/ 41 | 42 | #define ANCIL_MAX_N_FDS 960 43 | /* 44 | * Maximum number of fds that can be sent or received using the "esay" 45 | * functions; this is so that all can fit in one page. 46 | */ 47 | 48 | extern int 49 | ancil_send_fds_with_buffer(int, const int *, unsigned, void *); 50 | /* 51 | * ancil_send_fds_with_buffer(sock, n_fds, fds, buffer) 52 | * 53 | * Sends the file descriptors in the array pointed by fds, of length n_fds 54 | * on the socket sock. 55 | * buffer is a writeable memory area large enough to hold the required data 56 | * structures. 57 | * Returns: -1 and errno in case of error, 0 in case of success. 58 | */ 59 | 60 | extern int 61 | ancil_recv_fds_with_buffer(int, int *, unsigned, void *); 62 | /* 63 | * ancil_recv_fds_with_buffer(sock, n_fds, fds, buffer) 64 | * 65 | * Receives *n_fds file descriptors into the array pointed by fds 66 | * from the socket sock. 67 | * buffer is a writeable memory area large enough to hold the required data 68 | * structures. 69 | * Returns: -1 and errno in case of error, the actual number of received fd 70 | * in case of success 71 | */ 72 | 73 | #define ANCIL_FD_BUFFER(n) \ 74 | struct { \ 75 | struct cmsghdr h; \ 76 | int fd[n]; \ 77 | } 78 | /* ANCIL_FD_BUFFER(n) 79 | * 80 | * A structure type suitable to be used as buffer for n file descriptors. 81 | * Requires . 82 | * Example: 83 | * ANCIL_FD_BUFFER(42) buffer; 84 | * ancil_recv_fds_with_buffer(sock, 42, my_fds, &buffer); 85 | */ 86 | 87 | extern int 88 | ancil_send_fds(int, const int *, unsigned); 89 | /* 90 | * ancil_send_fds(sock, n_fds, fds) 91 | * 92 | * Sends the file descriptors in the array pointed by fds, of length n_fds 93 | * on the socket sock. 94 | * n_fds must not be greater than ANCIL_MAX_N_FDS. 95 | * Returns: -1 and errno in case of error, 0 in case of success. 96 | */ 97 | 98 | extern int 99 | ancil_recv_fds(int, int *, unsigned); 100 | /* 101 | * ancil_recv_fds(sock, n_fds, fds) 102 | * 103 | * Receives *n_fds file descriptors into the array pointed by fds 104 | * from the socket sock. 105 | * *n_fds must not be greater than ANCIL_MAX_N_FDS. 106 | * Returns: -1 and errno in case of error, the actual number of received fd 107 | * in case of success. 108 | */ 109 | 110 | 111 | extern int 112 | ancil_send_fd(int, int); 113 | /* ancil_recv_fd(sock, fd); 114 | * 115 | * Sends the file descriptor fd on the socket sock. 116 | * Returns : -1 and errno in case of error, 0 in case of success. 117 | */ 118 | 119 | extern int 120 | ancil_recv_fd(int, int *); 121 | /* ancil_send_fd(sock, &fd); 122 | * 123 | * Receives the file descriptor fd from the socket sock. 124 | * Returns : -1 and errno in case of error, 0 in case of success. 125 | */ 126 | 127 | #ifdef __cplusplus 128 | } 129 | #endif 130 | 131 | #endif /* ANCILLARY_H__ */ 132 | -------------------------------------------------------------------------------- /app/src/main/cpp/ancillary/fd_recv.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * libancillary - black magic on Unix domain sockets 3 | * (C) Nicolas George 4 | * fd_send.c - receiving file descriptors 5 | ***************************************************************************/ 6 | 7 | /* 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 22 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _XPG4_2 /* Solaris sucks */ 32 | # define _XPG4_2 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #if defined(__FreeBSD__) 41 | # include /* FreeBSD sucks */ 42 | #endif 43 | 44 | #include "ancillary.h" 45 | 46 | int 47 | ancil_recv_fds_with_buffer(int sock, int *fds, unsigned n_fds, void *buffer) 48 | { 49 | struct msghdr msghdr; 50 | char nothing; 51 | struct iovec nothing_ptr; 52 | struct cmsghdr *cmsg; 53 | int i; 54 | 55 | nothing_ptr.iov_base = ¬hing; 56 | nothing_ptr.iov_len = 1; 57 | msghdr.msg_name = NULL; 58 | msghdr.msg_namelen = 0; 59 | msghdr.msg_iov = ¬hing_ptr; 60 | msghdr.msg_iovlen = 1; 61 | msghdr.msg_flags = 0; 62 | msghdr.msg_control = buffer; 63 | msghdr.msg_controllen = sizeof(struct cmsghdr) + sizeof(int) * n_fds; 64 | cmsg = CMSG_FIRSTHDR(&msghdr); 65 | cmsg->cmsg_len = msghdr.msg_controllen; 66 | cmsg->cmsg_level = SOL_SOCKET; 67 | cmsg->cmsg_type = SCM_RIGHTS; 68 | for(i = 0; i < n_fds; i++) 69 | ((int *)CMSG_DATA(cmsg))[i] = -1; 70 | 71 | if(recvmsg(sock, &msghdr, 0) < 0) 72 | return(-1); 73 | for(i = 0; i < n_fds; i++) 74 | fds[i] = ((int *)CMSG_DATA(cmsg))[i]; 75 | n_fds = (cmsg->cmsg_len - sizeof(struct cmsghdr)) / sizeof(int); 76 | return(n_fds); 77 | } 78 | 79 | #ifndef SPARE_RECV_FDS 80 | int 81 | ancil_recv_fds(int sock, int *fd, unsigned n_fds) 82 | { 83 | ANCIL_FD_BUFFER(ANCIL_MAX_N_FDS) buffer; 84 | 85 | assert(n_fds <= ANCIL_MAX_N_FDS); 86 | return(ancil_recv_fds_with_buffer(sock, fd, n_fds, &buffer)); 87 | } 88 | #endif /* SPARE_RECV_FDS */ 89 | 90 | #ifndef SPARE_RECV_FD 91 | int 92 | ancil_recv_fd(int sock, int *fd) 93 | { 94 | ANCIL_FD_BUFFER(1) buffer; 95 | 96 | return(ancil_recv_fds_with_buffer(sock, fd, 1, &buffer) == 1 ? 0 : -1); 97 | } 98 | #endif /* SPARE_RECV_FD */ 99 | -------------------------------------------------------------------------------- /app/src/main/cpp/ancillary/fd_send.c: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | * libancillary - black magic on Unix domain sockets 3 | * (C) Nicolas George 4 | * fd_send.c - sending file descriptors 5 | ***************************************************************************/ 6 | 7 | /* 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions are met: 10 | * 11 | * 1. Redistributions of source code must retain the above copyright notice, 12 | * this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 3. The name of the author may not be used to endorse or promote products 17 | * derived from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 20 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 22 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 24 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 25 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 27 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 28 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | */ 30 | 31 | #ifndef _XPG4_2 /* Solaris sucks */ 32 | # define _XPG4_2 33 | #endif 34 | 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #if defined(__FreeBSD__) 41 | # include /* FreeBSD sucks */ 42 | #endif 43 | 44 | #include "ancillary.h" 45 | 46 | int 47 | ancil_send_fds_with_buffer(int sock, const int *fds, unsigned n_fds, void *buffer) 48 | { 49 | struct msghdr msghdr; 50 | char nothing = '!'; 51 | struct iovec nothing_ptr; 52 | struct cmsghdr *cmsg; 53 | int i; 54 | 55 | nothing_ptr.iov_base = ¬hing; 56 | nothing_ptr.iov_len = 1; 57 | msghdr.msg_name = NULL; 58 | msghdr.msg_namelen = 0; 59 | msghdr.msg_iov = ¬hing_ptr; 60 | msghdr.msg_iovlen = 1; 61 | msghdr.msg_flags = 0; 62 | msghdr.msg_control = buffer; 63 | msghdr.msg_controllen = sizeof(struct cmsghdr) + sizeof(int) * n_fds; 64 | cmsg = CMSG_FIRSTHDR(&msghdr); 65 | cmsg->cmsg_len = msghdr.msg_controllen; 66 | cmsg->cmsg_level = SOL_SOCKET; 67 | cmsg->cmsg_type = SCM_RIGHTS; 68 | for(i = 0; i < n_fds; i++) 69 | ((int *)CMSG_DATA(cmsg))[i] = fds[i]; 70 | return(sendmsg(sock, &msghdr, 0) >= 0 ? 0 : -1); 71 | } 72 | 73 | #ifndef SPARE_SEND_FDS 74 | int 75 | ancil_send_fds(int sock, const int *fds, unsigned n_fds) 76 | { 77 | ANCIL_FD_BUFFER(ANCIL_MAX_N_FDS) buffer; 78 | 79 | assert(n_fds <= ANCIL_MAX_N_FDS); 80 | return(ancil_send_fds_with_buffer(sock, fds, n_fds, &buffer)); 81 | } 82 | #endif /* SPARE_SEND_FDS */ 83 | 84 | #ifndef SPARE_SEND_FD 85 | int 86 | ancil_send_fd(int sock, int fd) 87 | { 88 | ANCIL_FD_BUFFER(1) buffer; 89 | 90 | return(ancil_send_fds_with_buffer(sock, &fd, 1, &buffer)); 91 | } 92 | #endif /* SPARE_SEND_FD */ 93 | -------------------------------------------------------------------------------- /app/src/main/cpp/system.cpp: -------------------------------------------------------------------------------- 1 | #define LOG_TAG "Shadowsocks" 2 | 3 | #include "jni.h" 4 | #include "cpufeatures/cpu-features.h" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | //#include 11 | 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define LOGI(...) do { __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__); } while(0) 19 | #define LOGW(...) do { __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__); } while(0) 20 | #define LOGE(...) do { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__); } while(0) 21 | 22 | jstring Java_co_tgbot_peekfun_system_getabi(JNIEnv *env, jobject thiz) { 23 | AndroidCpuFamily family = android_getCpuFamily(); 24 | uint64_t features = android_getCpuFeatures(); 25 | const char *abi; 26 | 27 | if (family == ANDROID_CPU_FAMILY_X86) { 28 | abi = "x86"; 29 | } else if (family == ANDROID_CPU_FAMILY_ARM64) { 30 | abi = "arm64-v8a"; 31 | } else if (family == ANDROID_CPU_FAMILY_MIPS) { 32 | abi = "mips"; 33 | } else if (family == ANDROID_CPU_FAMILY_ARM) { 34 | // if (features & ANDROID_CPU_ARM_FEATURE_ARMv7) { 35 | abi = "armeabi-v7a"; 36 | // } else { 37 | // abi = "armeabi"; 38 | // } 39 | } else { 40 | abi = ""; 41 | } 42 | return env->NewStringUTF(abi); 43 | } 44 | 45 | jint Java_co_tgbot_peekfun_system_exec(JNIEnv *env, jobject thiz, jstring cmd) { 46 | const char *cmd_str = env->GetStringUTFChars(cmd, 0); 47 | 48 | pid_t pid; 49 | 50 | /* Fork off the parent process */ 51 | pid = fork(); 52 | if (pid < 0) { 53 | env->ReleaseStringUTFChars(cmd, cmd_str); 54 | return -1; 55 | } 56 | 57 | if (pid > 0) { 58 | env->ReleaseStringUTFChars(cmd, cmd_str); 59 | return pid; 60 | } 61 | 62 | execl("/system/bin/sh", "sh", "-c", cmd_str, NULL); 63 | env->ReleaseStringUTFChars(cmd, cmd_str); 64 | 65 | return 1; 66 | } 67 | 68 | void Java_co_tgbot_peekfun_system_jniclose(JNIEnv *env, jobject thiz, jint fd) { 69 | close(fd); 70 | } 71 | 72 | jint Java_co_tgbot_peekfun_system_sendfd(JNIEnv *env, jobject thiz, jint tun_fd, jstring path) { 73 | int fd; 74 | struct sockaddr_un addr; 75 | const char *sock_str = env->GetStringUTFChars(path, 0); 76 | 77 | if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { 78 | LOGE("socket() failed: %s (socket fd = %d)\n", strerror(errno), fd); 79 | return (jint)-1; 80 | } 81 | 82 | memset(&addr, 0, sizeof(addr)); 83 | addr.sun_family = AF_UNIX; 84 | strncpy(addr.sun_path, sock_str, sizeof(addr.sun_path)-1); 85 | 86 | if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { 87 | LOGE("connect() failed: %s (fd = %d)\n", strerror(errno), fd); 88 | close(fd); 89 | return (jint)-1; 90 | } 91 | 92 | if (ancil_send_fd(fd, tun_fd)) { 93 | LOGE("ancil_send_fd: %s", strerror(errno)); 94 | close(fd); 95 | return (jint)-1; 96 | } 97 | 98 | close(fd); 99 | env->ReleaseStringUTFChars(path, sock_str); 100 | return 0; 101 | } 102 | 103 | static const char *classPathName = "co/tgbot/peekfun/System"; 104 | 105 | static JNINativeMethod method_table[] = { 106 | { "jniclose", "(I)V", 107 | (void*) Java_co_tgbot_peekfun_system_jniclose }, 108 | { "sendfd", "(ILjava/lang/String;)I", 109 | (void*) Java_co_tgbot_peekfun_system_sendfd }, 110 | { "exec", "(Ljava/lang/String;)I", 111 | (void*) Java_co_tgbot_peekfun_system_exec }, 112 | { "getABI", "()Ljava/lang/String;", 113 | (void*) Java_co_tgbot_peekfun_system_getabi } 114 | }; 115 | 116 | 117 | 118 | /* 119 | * Register several native methods for one class. 120 | */ 121 | static int registerNativeMethods(JNIEnv* env, const char* className, 122 | JNINativeMethod* gMethods, int numMethods) 123 | { 124 | jclass clazz; 125 | 126 | clazz = env->FindClass(className); 127 | if (clazz == NULL) { 128 | LOGE("Native registration unable to find class '%s'", className); 129 | return JNI_FALSE; 130 | } 131 | if (env->RegisterNatives(clazz, gMethods, numMethods) < 0) { 132 | LOGE("RegisterNatives failed for '%s'", className); 133 | return JNI_FALSE; 134 | } 135 | 136 | return JNI_TRUE; 137 | } 138 | 139 | /* 140 | * Register native methods for all classes we know about. 141 | * 142 | * returns JNI_TRUE on success. 143 | */ 144 | static int registerNatives(JNIEnv* env) 145 | { 146 | if (!registerNativeMethods(env, classPathName, method_table, 147 | sizeof(method_table) / sizeof(method_table[0]))) { 148 | return JNI_FALSE; 149 | } 150 | 151 | return JNI_TRUE; 152 | } 153 | 154 | /* 155 | * This is called by the VM when the shared library is first loaded. 156 | */ 157 | 158 | typedef union { 159 | JNIEnv* env; 160 | void* venv; 161 | } UnionJNIEnvToVoid; 162 | 163 | jint JNI_OnLoad(JavaVM* vm, void* reserved) { 164 | UnionJNIEnvToVoid uenv; 165 | uenv.venv = NULL; 166 | jint result = -1; 167 | JNIEnv* env = NULL; 168 | 169 | LOGI("JNI_OnLoad"); 170 | 171 | if (vm->GetEnv(&uenv.venv, JNI_VERSION_1_4) != JNI_OK) { 172 | LOGE("ERROR: GetEnv failed"); 173 | goto bail; 174 | } 175 | env = uenv.env; 176 | 177 | if (registerNatives(env) != JNI_TRUE) { 178 | LOGE("ERROR: registerNatives failed"); 179 | goto bail; 180 | } 181 | 182 | result = JNI_VERSION_1_4; 183 | 184 | bail: 185 | return result; 186 | } -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/BootReceiver.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.content.BroadcastReceiver; 42 | import android.content.ComponentName; 43 | import android.content.Context; 44 | import android.content.Intent; 45 | import android.content.pm.PackageManager; 46 | 47 | import co.tgbot.peekfun.utils.Utils; 48 | 49 | public class BootReceiver extends BroadcastReceiver { 50 | 51 | public static boolean getEnabled(Context context) { 52 | PackageManager pm = context.getPackageManager(); 53 | ComponentName cn = new ComponentName(context, BootReceiver.class); 54 | return PackageManager.COMPONENT_ENABLED_STATE_ENABLED == pm.getComponentEnabledSetting(cn); 55 | } 56 | 57 | public static void setEnabled(Context context, boolean enabled) { 58 | PackageManager pm = context.getPackageManager(); 59 | ComponentName cn = new ComponentName(context, BootReceiver.class); 60 | int state = enabled ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : PackageManager.COMPONENT_ENABLED_STATE_DISABLED; 61 | pm.setComponentEnabledSetting(cn, state, PackageManager.DONT_KILL_APP); 62 | } 63 | 64 | @Override 65 | public void onReceive(Context context, Intent intent) { 66 | Utils.startSsService(context); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/GuardedProcess.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | 3 | import android.util.Log; 4 | 5 | import co.tgbot.peekfun.utils.VayLog; 6 | 7 | import java.io.BufferedReader; 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | import java.io.InputStreamReader; 11 | import java.lang.System; 12 | import java.util.List; 13 | import java.util.concurrent.Semaphore; 14 | 15 | public class GuardedProcess { 16 | 17 | private static final String TAG = GuardedProcess.class.getSimpleName(); 18 | private final List cmd; 19 | 20 | private Thread guardThread; 21 | private boolean isDestroyed; 22 | private Process process; 23 | private boolean isRestart = false; 24 | 25 | public GuardedProcess(List cmd) { 26 | this.cmd = cmd; 27 | } 28 | 29 | public GuardedProcess start() throws InterruptedException { 30 | return start(null); 31 | } 32 | 33 | public GuardedProcess start(final RestartCallback onRestartCallback) throws InterruptedException { 34 | final Semaphore semaphore = new Semaphore(1); 35 | semaphore.acquire(); 36 | 37 | guardThread = new Thread(new Runnable() { 38 | @Override 39 | public void run() { 40 | try { 41 | RestartCallback callback = null; 42 | while (!isDestroyed) { 43 | VayLog.i(TAG, "start process: " + cmd); 44 | long startTime = System.currentTimeMillis(); 45 | 46 | process = new ProcessBuilder(cmd).redirectErrorStream(true).start(); 47 | 48 | InputStream is = process.getInputStream(); 49 | new StreamLogger(is, TAG).start(); 50 | 51 | if (callback == null) { 52 | callback = onRestartCallback; 53 | } else { 54 | callback.onRestart(); 55 | } 56 | 57 | semaphore.release(); 58 | process.waitFor(); 59 | 60 | synchronized (this) { 61 | if (isRestart) { 62 | isRestart = false; 63 | } else { 64 | if (System.currentTimeMillis() - startTime < 1000) { 65 | Log.w(TAG, "process exit too fast, stop guard: " + cmd); 66 | isDestroyed = true; 67 | } 68 | } 69 | } 70 | 71 | } 72 | } catch (Exception ignored) { 73 | VayLog.i(TAG, "thread interrupt, destroy process: " + cmd); 74 | if (process!=null) { 75 | process.destroy(); 76 | } 77 | } finally { 78 | semaphore.release(); 79 | } 80 | } 81 | }, "GuardThread-" + cmd); 82 | 83 | guardThread.start(); 84 | semaphore.acquire(); 85 | return this; 86 | } 87 | 88 | public void destroy() { 89 | isDestroyed = true; 90 | guardThread.interrupt(); 91 | if (process!=null){ 92 | process.destroy(); 93 | } 94 | try { 95 | guardThread.join(); 96 | } catch (InterruptedException e) { 97 | // Ignored 98 | } 99 | } 100 | 101 | public void restart() { 102 | synchronized (this) { 103 | isRestart = true; 104 | if (process!=null){ 105 | process.destroy(); 106 | } 107 | } 108 | } 109 | 110 | public int waitFor() throws InterruptedException { 111 | guardThread.join(); 112 | return 0; 113 | } 114 | 115 | /** 116 | * restart callback 117 | */ 118 | public interface RestartCallback { 119 | 120 | /** 121 | * restart callback 122 | */ 123 | void onRestart(); 124 | } 125 | 126 | public class StreamLogger extends Thread { 127 | 128 | private InputStream is; 129 | private String tag; 130 | 131 | public StreamLogger(InputStream is, String tag) { 132 | this.is = is; 133 | this.tag = tag; 134 | } 135 | 136 | @Override 137 | public void run() { 138 | BufferedReader bufferedReader = null; 139 | try { 140 | bufferedReader = new BufferedReader(new InputStreamReader(is)); 141 | String temp = null; 142 | while ((temp = bufferedReader.readLine()) != null) { 143 | VayLog.e(tag, temp); 144 | } 145 | } catch (Exception e) { 146 | int i = 0; 147 | // Ignore 148 | } finally { 149 | try { 150 | if (bufferedReader != null) { 151 | bufferedReader.close(); 152 | } 153 | } catch (IOException e) { 154 | // Ignore 155 | } 156 | } 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/QuickToggleShortcut.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | 3 | 4 | import android.app.Activity; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.pm.ShortcutManager; 8 | import android.os.Build; 9 | import android.os.Bundle; 10 | import android.os.RemoteException; 11 | 12 | import co.tgbot.peekfun.R; 13 | import co.tgbot.peekfun.utils.Constants; 14 | import co.tgbot.peekfun.utils.ToastUtils; 15 | import co.tgbot.peekfun.utils.Utils; 16 | 17 | import androidx.annotation.Nullable; 18 | 19 | /** 20 | * @author Mygod 21 | */ 22 | public class QuickToggleShortcut extends Activity { 23 | 24 | private ServiceBoundContext mServiceBoundContext; 25 | 26 | @Override 27 | protected void attachBaseContext(Context newBase) { 28 | super.attachBaseContext(newBase); 29 | mServiceBoundContext = new ServiceBoundContext(newBase) { 30 | @Override 31 | protected void onServiceConnected() { 32 | try { 33 | int state = bgService.getState(); 34 | switch (state) { 35 | case Constants.State.STOPPED: 36 | ToastUtils.showShort(R.string.loading); 37 | Utils.startSsService(this); 38 | break; 39 | case Constants.State.CONNECTED: 40 | Utils.stopSsService(this); 41 | break; 42 | default: 43 | // ignore 44 | break; 45 | } 46 | } catch (RemoteException e) { 47 | e.printStackTrace(); 48 | } 49 | finish(); 50 | } 51 | }; 52 | } 53 | 54 | @Override 55 | protected void onCreate(@Nullable Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | String action = getIntent().getAction(); 58 | 59 | if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) { 60 | setResult(Activity.RESULT_OK, new Intent() 61 | .putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, QuickToggleShortcut.class)) 62 | .putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.quick_toggle)) 63 | .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, 64 | Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher))); 65 | finish(); 66 | } else { 67 | mServiceBoundContext.attachService(); 68 | if (Build.VERSION.SDK_INT >= 25) { 69 | ShortcutManager service = getSystemService(ShortcutManager.class); 70 | if (service != null) { 71 | service.reportShortcutUsed("toggle"); 72 | } 73 | } 74 | } 75 | } 76 | 77 | @Override 78 | protected void onDestroy() { 79 | mServiceBoundContext.detachService(); 80 | super.onDestroy(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/ServiceBoundService.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.app.Service; 42 | import android.content.ComponentName; 43 | import android.content.Context; 44 | import android.content.Intent; 45 | import android.content.ServiceConnection; 46 | import android.os.IBinder; 47 | import android.os.RemoteException; 48 | 49 | import co.tgbot.peekfun.aidl.IShadowsocksService; 50 | import co.tgbot.peekfun.aidl.IShadowsocksServiceCallback; 51 | import co.tgbot.peekfun.utils.Constants; 52 | import co.tgbot.peekfun.utils.VayLog; 53 | 54 | /** 55 | * @author Mygod 56 | */ 57 | public abstract class ServiceBoundService extends Service implements IBinder.DeathRecipient { 58 | 59 | private static final String TAG = ServiceBoundService.class.getSimpleName(); 60 | 61 | private IBinder binder; 62 | protected IShadowsocksService bgService; 63 | 64 | private IShadowsocksServiceCallback callback; 65 | private ShadowsocksServiceConnection connection; 66 | private boolean callbackRegistered; 67 | 68 | public class ShadowsocksServiceConnection implements ServiceConnection { 69 | @Override 70 | public void onServiceConnected(ComponentName name, IBinder service) { 71 | try { 72 | binder = service; 73 | service.linkToDeath(ServiceBoundService.this, 0); 74 | bgService = IShadowsocksService.Stub.asInterface(service); 75 | registerCallback(); 76 | ServiceBoundService.this.onServiceConnected(); 77 | } catch (RemoteException e) { 78 | VayLog.e(TAG, "onServiceConnected", e); 79 | } 80 | } 81 | 82 | @Override 83 | public void onServiceDisconnected(ComponentName name) { 84 | unregisterCallback(); 85 | ServiceBoundService.this.onServiceDisconnected(); 86 | bgService = null; 87 | binder = null; 88 | } 89 | } 90 | 91 | /** 92 | * register callback 93 | */ 94 | private void registerCallback() { 95 | if (bgService != null && callback != null && !callbackRegistered) { 96 | try { 97 | bgService.registerCallback(callback); 98 | callbackRegistered = true; 99 | } catch (Exception e) { 100 | VayLog.e(TAG, "registerCallback", e); 101 | } 102 | } 103 | } 104 | 105 | /** 106 | * unregister callback 107 | */ 108 | protected void unregisterCallback() { 109 | if (bgService != null && callback != null && callbackRegistered) { 110 | try { 111 | bgService.unregisterCallback(callback); 112 | } catch (Exception e) { 113 | VayLog.e(TAG, "unregisterCallback", e); 114 | } 115 | callbackRegistered = false; 116 | } 117 | } 118 | 119 | protected void onServiceConnected() { 120 | } 121 | 122 | protected void onServiceDisconnected() { 123 | } 124 | 125 | @Override 126 | public void binderDied() { 127 | } 128 | 129 | public void attachService() { 130 | attachService(null); 131 | } 132 | 133 | public void attachService(IShadowsocksServiceCallback.Stub callback) { 134 | this.callback = callback; 135 | if (bgService == null) { 136 | Class clazz = null; 137 | clazz = ShadowsocksVpnService.class; 138 | 139 | Intent intent = new Intent(this, clazz); 140 | intent.setAction(Constants.Action.SERVICE); 141 | 142 | connection = new ShadowsocksServiceConnection(); 143 | bindService(intent, connection, Context.BIND_AUTO_CREATE); 144 | } 145 | } 146 | 147 | /** 148 | * detach service 149 | */ 150 | public void detachService() { 151 | unregisterCallback(); 152 | callback = null; 153 | if (connection != null) { 154 | try { 155 | unbindService(connection); 156 | } catch (Exception e) { 157 | VayLog.e(TAG, "detachService", e); 158 | } 159 | connection = null; 160 | } 161 | 162 | if (binder != null) { 163 | binder.unlinkToDeath(this, 0); 164 | binder = null; 165 | } 166 | 167 | bgService = null; 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/ShadowsocksBackupAgent.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | 3 | import android.app.backup.BackupAgentHelper; 4 | import android.app.backup.FileBackupHelper; 5 | import android.app.backup.SharedPreferencesBackupHelper; 6 | 7 | import co.tgbot.peekfun.database.DBHelper; 8 | 9 | public class ShadowsocksBackupAgent extends BackupAgentHelper { 10 | 11 | /** 12 | * The names of the SharedPreferences groups that the application maintains. These 13 | * are the same strings that are passed to getSharedPreferences(String, int). 14 | */ 15 | private static final String PREFS_DISPLAY = "co.tgbot.peekfun_preferences"; 16 | 17 | /** 18 | * An arbitrary string used within the BackupAgentHelper implementation to 19 | * identify the SharedPreferencesBackupHelper's data. 20 | */ 21 | private static final String MY_PREFS_BACKUP_KEY = "co.tgbot.peekfun"; 22 | 23 | private static final String DATABASE = "co.tgbot.peekfun.database.profile"; 24 | 25 | @Override 26 | public void onCreate() { 27 | super.onCreate(); 28 | SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, PREFS_DISPLAY); 29 | addHelper(MY_PREFS_BACKUP_KEY, helper); 30 | addHelper(DATABASE, new FileBackupHelper(this, "../databases/" + DBHelper.PROFILE)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/ShadowsocksRunnerActivity.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.app.Activity; 42 | import android.app.KeyguardManager; 43 | import android.content.BroadcastReceiver; 44 | import android.content.Context; 45 | import android.content.Intent; 46 | import android.content.IntentFilter; 47 | import android.net.VpnService; 48 | import android.os.Bundle; 49 | import android.os.Handler; 50 | import android.os.RemoteException; 51 | 52 | import co.tgbot.peekfun.utils.VayLog; 53 | 54 | import androidx.annotation.Nullable; 55 | 56 | public class ShadowsocksRunnerActivity extends Activity { 57 | private static final String TAG = ShadowsocksRunnerActivity.class.getSimpleName(); 58 | private static final int REQUEST_CONNECT = 1; 59 | 60 | private Handler handler = new Handler(); 61 | 62 | private BroadcastReceiver receiver; 63 | 64 | private ServiceBoundContext mServiceBoundContext; 65 | 66 | @Override 67 | protected void attachBaseContext(Context newBase) { 68 | super.attachBaseContext(newBase); 69 | mServiceBoundContext = new ServiceBoundContext(newBase) { 70 | @Override 71 | protected void onServiceConnected() { 72 | handler.postDelayed(new Runnable() { 73 | @Override 74 | public void run() { 75 | if (bgService != null) { 76 | startBackgroundService(); 77 | } 78 | } 79 | }, 1000); 80 | } 81 | }; 82 | } 83 | 84 | private void startBackgroundService() { 85 | if (ShadowsocksApplication.app.isNatEnabled()) { 86 | try { 87 | mServiceBoundContext.bgService.use(ShadowsocksApplication.app.profileId()); 88 | finish(); 89 | } catch (RemoteException e) { 90 | e.printStackTrace(); 91 | } 92 | } else { 93 | Intent intent = VpnService.prepare(ShadowsocksRunnerActivity.this); 94 | if (intent != null) { 95 | startActivityForResult(intent, REQUEST_CONNECT); 96 | } else { 97 | onActivityResult(REQUEST_CONNECT, Activity.RESULT_OK, null); 98 | } 99 | } 100 | } 101 | 102 | @Override 103 | protected void onCreate(@Nullable Bundle savedInstanceState) { 104 | super.onCreate(savedInstanceState); 105 | KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE); 106 | boolean locked = km.inKeyguardRestrictedInputMode(); 107 | if (locked) { 108 | IntentFilter filter = new IntentFilter(Intent.ACTION_USER_PRESENT); 109 | receiver = new BroadcastReceiver() { 110 | @Override 111 | public void onReceive(Context context, Intent intent) { 112 | if (Intent.ACTION_USER_PRESENT.equals(intent.getAction())) { 113 | mServiceBoundContext.attachService(); 114 | } 115 | } 116 | }; 117 | registerReceiver(receiver, filter); 118 | } else { 119 | mServiceBoundContext.attachService(); 120 | } 121 | finish(); 122 | } 123 | 124 | @Override 125 | protected void onDestroy() { 126 | super.onDestroy(); 127 | mServiceBoundContext.detachService(); 128 | if (receiver != null) { 129 | unregisterReceiver(receiver); 130 | receiver = null; 131 | } 132 | } 133 | 134 | @Override 135 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 136 | super.onActivityResult(requestCode, resultCode, data); 137 | if (resultCode == RESULT_OK) { 138 | if (mServiceBoundContext.bgService != null) { 139 | try { 140 | mServiceBoundContext.bgService.use(ShadowsocksApplication.app.profileId()); 141 | } catch (RemoteException e) { 142 | e.printStackTrace(); 143 | } 144 | } 145 | } else { 146 | VayLog.e(TAG, "Failed to start VpnService"); 147 | } 148 | finish(); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/ShadowsocksRunnerService.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.app.Service; 42 | import android.content.Intent; 43 | import android.net.VpnService; 44 | import android.os.Handler; 45 | import android.os.IBinder; 46 | import android.os.RemoteException; 47 | 48 | import co.tgbot.peekfun.aidl.IShadowsocksServiceCallback; 49 | import co.tgbot.peekfun.utils.VayLog; 50 | 51 | import androidx.annotation.Nullable; 52 | 53 | public class ShadowsocksRunnerService extends ServiceBoundService { 54 | 55 | private static final String TAG = ShadowsocksRunnerService.class.getSimpleName(); 56 | 57 | private Handler handler = new Handler(); 58 | 59 | @Nullable 60 | @Override 61 | public IBinder onBind(Intent intent) { 62 | return null; 63 | } 64 | 65 | @Override 66 | public int onStartCommand(Intent intent, int flags, int startId) { 67 | detachService(); 68 | attachService(mCallback); 69 | return Service.START_STICKY; 70 | } 71 | 72 | @Override 73 | protected void onServiceConnected() { 74 | if (bgService != null) { 75 | if (ShadowsocksApplication.app.isNatEnabled()) { 76 | startBackgroundService(); 77 | } else if (VpnService.prepare(ShadowsocksRunnerService.this) == null) { 78 | startBackgroundService(); 79 | } else { 80 | handler.postDelayed(mStopSelfRunnable, 10000); 81 | } 82 | } 83 | } 84 | 85 | @Override 86 | protected void onServiceDisconnected() { 87 | super.onServiceDisconnected(); 88 | } 89 | 90 | private void startBackgroundService() { 91 | try { 92 | bgService.use(ShadowsocksApplication.app.profileId()); 93 | } catch (RemoteException e) { 94 | VayLog.e(TAG, "startBackgroundService", e); 95 | ShadowsocksApplication.app.track(e); 96 | } 97 | } 98 | 99 | @Override 100 | public void onCreate() { 101 | super.onCreate(); 102 | } 103 | 104 | @Override 105 | public void onDestroy() { 106 | super.onDestroy(); 107 | detachService(); 108 | } 109 | 110 | /** 111 | * callback 112 | */ 113 | private IShadowsocksServiceCallback.Stub mCallback = new IShadowsocksServiceCallback.Stub() { 114 | @Override 115 | public void stateChanged(int state, String profileName, String msg) throws RemoteException { 116 | } 117 | 118 | @Override 119 | public void trafficUpdated(long txRate, long rxRate, long txTotal, long rxTotal) throws RemoteException { 120 | } 121 | }; 122 | 123 | /** 124 | * stop self runnable 125 | */ 126 | private Runnable mStopSelfRunnable = new Runnable() { 127 | @Override 128 | public void run() { 129 | stopSelf(); 130 | } 131 | }; 132 | } 133 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/ShadowsocksVpnThread.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | 3 | 4 | import android.net.LocalServerSocket; 5 | import android.net.LocalSocket; 6 | import android.net.LocalSocketAddress; 7 | 8 | import co.tgbot.peekfun.utils.IOUtils; 9 | import co.tgbot.peekfun.utils.VayLog; 10 | 11 | import java.io.File; 12 | import java.io.FileDescriptor; 13 | import java.io.IOException; 14 | import java.io.InputStream; 15 | import java.io.OutputStream; 16 | import java.lang.reflect.Method; 17 | import java.util.concurrent.ScheduledExecutorService; 18 | import java.util.concurrent.ScheduledThreadPoolExecutor; 19 | import java.util.concurrent.ThreadFactory; 20 | 21 | import androidx.annotation.NonNull; 22 | 23 | public class ShadowsocksVpnThread extends Thread { 24 | 25 | private static final String TAG = ShadowsocksVpnThread.class.getSimpleName(); 26 | 27 | private static final String PATH = BaseVpnService.protectPath; 28 | private final ShadowsocksVpnService vpnService; 29 | 30 | private boolean isRunning = true; 31 | private LocalServerSocket serverSocket; 32 | private ScheduledExecutorService pool; 33 | 34 | public ShadowsocksVpnThread(ShadowsocksVpnService vpnService) { 35 | this.vpnService = vpnService; 36 | pool = new ScheduledThreadPoolExecutor(4, new ThreadFactory() { 37 | @Override 38 | public Thread newThread(@NonNull Runnable r) { 39 | Thread thread = new Thread(r); 40 | thread.setName(TAG); 41 | return thread; 42 | } 43 | }); 44 | } 45 | 46 | public void closeServerSocket() { 47 | if (serverSocket != null) { 48 | try { 49 | serverSocket.close(); 50 | } catch (Exception e) { 51 | // Ignore 52 | } 53 | serverSocket = null; 54 | } 55 | } 56 | 57 | public void stopThread() { 58 | isRunning = false; 59 | closeServerSocket(); 60 | } 61 | 62 | @Override 63 | public void run() { 64 | boolean deleteFlag = new File(PATH).delete(); 65 | VayLog.d(TAG, "run() delete file = " + deleteFlag); 66 | 67 | if (!initServerSocket()) { 68 | return; 69 | } 70 | 71 | while (isRunning) { 72 | try { 73 | final LocalSocket socket = serverSocket.accept(); 74 | // handle local socket 75 | handleLocalSocket(socket); 76 | } catch (IOException e) { 77 | VayLog.e(TAG, "Error when accept socket", e); 78 | ShadowsocksApplication.app.track(e); 79 | 80 | initServerSocket(); 81 | } 82 | } 83 | } 84 | 85 | /** 86 | * handle local socket 87 | * 88 | * @param socket local socket object 89 | */ 90 | private void handleLocalSocket(final LocalSocket socket) { 91 | pool.execute(new Runnable() { 92 | @Override 93 | public void run() { 94 | InputStream input = null; 95 | OutputStream output = null; 96 | try { 97 | input = socket.getInputStream(); 98 | output = socket.getOutputStream(); 99 | 100 | // check read state 101 | int state = input.read(); 102 | VayLog.d(TAG, "handleLocalSocket() read state = " + state); 103 | 104 | FileDescriptor[] fds = socket.getAncillaryFileDescriptors(); 105 | 106 | if (fds != null && fds.length > 0) { 107 | Method getIntMethod = getInt(); 108 | int fd = 0; 109 | if (getIntMethod != null) { 110 | fd = (int) getInt().invoke(fds[0]); 111 | } 112 | boolean ret = vpnService.protect(fd); 113 | 114 | // Trick to close file decriptor 115 | System.jniclose(fd); 116 | 117 | if (ret) { 118 | output.write(0); 119 | } else { 120 | output.write(1); 121 | } 122 | } 123 | 124 | // close stream 125 | IOUtils.close(input); 126 | IOUtils.close(output); 127 | } catch (Exception e) { 128 | VayLog.e(TAG, "handleLocalSocket() Error when protect socket", e); 129 | ShadowsocksApplication.app.track(e); 130 | } finally { 131 | // close socket 132 | try { 133 | socket.close(); 134 | } catch (Exception e) { 135 | // Ignore; 136 | } 137 | } 138 | } 139 | }); 140 | } 141 | 142 | /** 143 | * init server socket 144 | * 145 | * @return init failed return false. 146 | */ 147 | private boolean initServerSocket() { 148 | // if not running, do not init 149 | if (!isRunning) { 150 | return false; 151 | } 152 | 153 | try { 154 | LocalSocket localSocket = new LocalSocket(); 155 | localSocket.bind(new LocalSocketAddress(PATH, LocalSocketAddress.Namespace.FILESYSTEM)); 156 | serverSocket = new LocalServerSocket(localSocket.getFileDescriptor()); 157 | return true; 158 | } catch (IOException e) { 159 | VayLog.e(TAG, "unable to bind", e); 160 | ShadowsocksApplication.app.track(e); 161 | return false; 162 | } 163 | } 164 | 165 | private Method getInt() { 166 | try { 167 | return FileDescriptor.class.getDeclaredMethod("getInt$"); 168 | } catch (NoSuchMethodException e) { 169 | e.printStackTrace(); 170 | } 171 | return null; 172 | } 173 | } 174 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/System.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | 3 | public class System { 4 | static { 5 | java.lang.System.loadLibrary("system"); 6 | } 7 | 8 | public static native int exec(String cmd); 9 | 10 | public static native String getABI(); 11 | 12 | public static native int sendfd(int fd, String path); 13 | 14 | public static native void jniclose(int fd); 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/TaskerActivity.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | 3 | 4 | import android.content.res.Resources; 5 | import android.content.res.TypedArray; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.view.LayoutInflater; 9 | import android.view.View; 10 | import android.view.ViewGroup; 11 | import android.widget.CheckedTextView; 12 | import android.widget.Switch; 13 | 14 | import co.tgbot.peekfun.R; 15 | import co.tgbot.peekfun.database.Profile; 16 | import co.tgbot.peekfun.utils.TaskerSettings; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | import androidx.annotation.Nullable; 22 | import androidx.appcompat.app.AppCompatActivity; 23 | import androidx.appcompat.widget.Toolbar; 24 | import androidx.recyclerview.widget.DefaultItemAnimator; 25 | import androidx.recyclerview.widget.LinearLayoutManager; 26 | import androidx.recyclerview.widget.RecyclerView; 27 | 28 | import static co.tgbot.peekfun.ShadowsocksApplication.app; 29 | 30 | public class TaskerActivity extends AppCompatActivity { 31 | 32 | private TaskerSettings taskerOption; 33 | private Switch mSwitch; 34 | private ProfilesAdapter profilesAdapter; 35 | 36 | @Override 37 | protected void onCreate(@Nullable Bundle savedInstanceState) { 38 | super.onCreate(savedInstanceState); 39 | setContentView(R.layout.layout_tasker); 40 | 41 | profilesAdapter = new ProfilesAdapter(); 42 | 43 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 44 | toolbar.setTitle(R.string.app_name); 45 | toolbar.setNavigationIcon(R.drawable.ic_navigation_close); 46 | toolbar.setNavigationOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View v) { 49 | finish(); 50 | } 51 | }); 52 | 53 | taskerOption = TaskerSettings.fromIntent(getIntent()); 54 | mSwitch = (Switch) findViewById(R.id.serviceSwitch); 55 | mSwitch.setChecked(taskerOption.switchOn); 56 | RecyclerView profilesList = (RecyclerView) findViewById(R.id.profilesList); 57 | LinearLayoutManager lm = new LinearLayoutManager(this); 58 | profilesList.setLayoutManager(lm); 59 | profilesList.setItemAnimator(new DefaultItemAnimator()); 60 | profilesList.setAdapter(profilesAdapter); 61 | 62 | if (taskerOption.profileId >= 0) { 63 | int position = 0; 64 | List profiles = profilesAdapter.profiles; 65 | for (int i = 0; i < profiles.size(); i++) { 66 | Profile profile = profiles.get(i); 67 | if (profile.id == taskerOption.profileId) { 68 | position = i + 1; 69 | break; 70 | } 71 | } 72 | lm.scrollToPosition(position); 73 | } 74 | } 75 | 76 | private class ProfileViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { 77 | 78 | private Profile item; 79 | private CheckedTextView text; 80 | 81 | public ProfileViewHolder(View view) { 82 | super(view); 83 | TypedArray typedArray = obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground}); 84 | view.setBackgroundResource(typedArray.getResourceId(0, 0)); 85 | typedArray.recycle(); 86 | 87 | text = (CheckedTextView) itemView.findViewById(android.R.id.text1); 88 | itemView.setOnClickListener(this); 89 | } 90 | 91 | public void bindDefault() { 92 | item = null; 93 | text.setText(R.string.profile_default); 94 | text.setChecked(taskerOption.profileId < 0); 95 | } 96 | 97 | public void bind(Profile item) { 98 | this.item = item; 99 | text.setText(item.name); 100 | text.setChecked(taskerOption.profileId == item.id); 101 | } 102 | 103 | @Override 104 | public void onClick(View v) { 105 | taskerOption.switchOn = mSwitch.isChecked(); 106 | taskerOption.profileId = item == null ? -1 : item.id; 107 | setResult(RESULT_OK, taskerOption.toIntent(TaskerActivity.this)); 108 | finish(); 109 | } 110 | } 111 | 112 | private class ProfilesAdapter extends RecyclerView.Adapter { 113 | 114 | private List profiles; 115 | private String name; 116 | 117 | public ProfilesAdapter() { 118 | profiles = app.profileManager.getAllProfiles(); 119 | if (profiles == null) { 120 | profiles = new ArrayList<>(); 121 | } 122 | 123 | String version = Build.VERSION.SDK_INT >= 21 ? "material" : "holo"; 124 | name = "select_dialog_singlechoice_" + version; 125 | } 126 | 127 | public List profiles() { 128 | List allProfiles = app.profileManager.getAllProfiles(); 129 | if (allProfiles == null) { 130 | return new ArrayList<>(); 131 | } else { 132 | return allProfiles; 133 | } 134 | } 135 | 136 | @Override 137 | public int getItemCount() { 138 | return 1 + profiles().size(); 139 | } 140 | 141 | @Override 142 | public void onBindViewHolder(ProfileViewHolder vh, int i) { 143 | if (i == 0) { 144 | vh.bindDefault(); 145 | } else { 146 | vh.bind(profiles().get(i - 1)); 147 | } 148 | } 149 | 150 | @Override 151 | public ProfileViewHolder onCreateViewHolder(ViewGroup vg, int i) { 152 | View view = LayoutInflater.from(vg.getContext()) 153 | .inflate(Resources.getSystem().getIdentifier(name, "layout", "android"), vg, false); 154 | return new ProfileViewHolder(view); 155 | } 156 | } 157 | } 158 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/TaskerReceiver.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun; 2 | 3 | 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | 8 | import co.tgbot.peekfun.database.Profile; 9 | import co.tgbot.peekfun.utils.TaskerSettings; 10 | import co.tgbot.peekfun.utils.Utils; 11 | 12 | /** 13 | * @author CzBiX 14 | */ 15 | public class TaskerReceiver extends BroadcastReceiver { 16 | @Override 17 | public void onReceive(Context context, Intent intent) { 18 | TaskerSettings settings = TaskerSettings.fromIntent(intent); 19 | Profile profile = ShadowsocksApplication.app.profileManager.getProfile(settings.profileId); 20 | 21 | if (profile != null) { 22 | ShadowsocksApplication.app.switchProfile(settings.profileId); 23 | } 24 | 25 | if (settings.switchOn) { 26 | Utils.startSsService(context); 27 | } else { 28 | Utils.stopSsService(context); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/database/Profile.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.database; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2013 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.util.Base64; 42 | 43 | import com.j256.ormlite.field.DataType; 44 | import com.j256.ormlite.field.DatabaseField; 45 | 46 | import java.util.Date; 47 | import java.util.Locale; 48 | 49 | public class Profile { 50 | 51 | @DatabaseField(generatedId = true) 52 | public int id = 0; 53 | 54 | @DatabaseField 55 | public String name = "Maying"; 56 | 57 | @DatabaseField 58 | public String host = "1.1.1.1"; 59 | 60 | @DatabaseField 61 | public int localPort = 1080; 62 | 63 | @DatabaseField 64 | public int remotePort = 8388; 65 | 66 | @DatabaseField 67 | public String password = ""; 68 | 69 | @DatabaseField 70 | public String protocol = "origin"; 71 | 72 | @DatabaseField 73 | public String protocol_param = ""; 74 | 75 | @DatabaseField 76 | public String obfs = "plain"; 77 | 78 | @DatabaseField 79 | public String obfs_param = ""; 80 | 81 | @DatabaseField 82 | public String method = "aes-256-cfb"; 83 | 84 | @DatabaseField 85 | public String route = "ACL4SSR-banAD"; 86 | 87 | @DatabaseField 88 | public boolean proxyApps = false; 89 | 90 | @DatabaseField 91 | public boolean bypass = false; 92 | 93 | @DatabaseField 94 | public boolean udpdns = false; 95 | 96 | @DatabaseField 97 | public String url_group = "Maying"; 98 | 99 | @DatabaseField 100 | public String dns = "8.8.8.8:53"; 101 | 102 | @DatabaseField 103 | public String china_dns = "114.114.114.114:53,223.5.5.5:53"; 104 | 105 | @DatabaseField 106 | public boolean ipv6 = false; 107 | 108 | @DatabaseField(dataType = DataType.LONG_STRING) 109 | public String individual = ""; 110 | 111 | @DatabaseField 112 | public long tx = 0; 113 | 114 | @DatabaseField 115 | public long rx = 0; 116 | 117 | @DatabaseField 118 | public long elapsed = 0; 119 | 120 | @DatabaseField 121 | public long tcpdelay = 0; 122 | 123 | @DatabaseField 124 | public final Date date = new java.util.Date(); 125 | 126 | @DatabaseField 127 | public long userOrder = 0; 128 | 129 | @Override 130 | public String toString() { 131 | String result = Base64.encodeToString(String.format(Locale.ENGLISH, 132 | "%s:%d:%s:%s:%s:%s/?obfsparam=%s&protoparam=%s&remarks=%s&group=%s", 133 | host, remotePort, protocol, method, obfs, 134 | Base64.encodeToString(String.format(Locale.ENGLISH, "%s", password).getBytes(), Base64.NO_PADDING | Base64.URL_SAFE | Base64.NO_WRAP), 135 | Base64.encodeToString(String.format(Locale.ENGLISH, "%s", obfs_param).getBytes(), Base64.NO_PADDING | Base64.URL_SAFE | Base64.NO_WRAP), 136 | Base64.encodeToString(String.format(Locale.ENGLISH, "%s", protocol_param).getBytes(), Base64.NO_PADDING | Base64.URL_SAFE | Base64.NO_WRAP), 137 | Base64.encodeToString(String.format(Locale.ENGLISH, "%s", name).getBytes(), Base64.NO_PADDING | Base64.URL_SAFE | Base64.NO_WRAP), 138 | Base64.encodeToString(String.format(Locale.ENGLISH, "%s", url_group).getBytes(), Base64.NO_PADDING | Base64.URL_SAFE | Base64.NO_WRAP) 139 | ).getBytes(), 140 | Base64.NO_PADDING | Base64.URL_SAFE | Base64.NO_WRAP); 141 | return "ssr://" + result; 142 | } 143 | 144 | /** 145 | * is method unsafe 146 | */ 147 | public boolean isMethodUnsafe() { 148 | return "table".equalsIgnoreCase(method) || "rc4".equalsIgnoreCase(method); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/database/SSRSub.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.database; 2 | 3 | 4 | import com.j256.ormlite.field.DatabaseField; 5 | 6 | public class SSRSub { 7 | @DatabaseField(generatedId = true) 8 | public int id = 0; 9 | 10 | @DatabaseField 11 | public String url = ""; 12 | 13 | @DatabaseField 14 | public String url_group = ""; 15 | } 16 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/database/SSRSubManager.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.database; 2 | 3 | 4 | import co.tgbot.peekfun.utils.VayLog; 5 | import co.tgbot.peekfun.ShadowsocksApplication; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | public class SSRSubManager { 11 | 12 | private static final String TAG = SSRSubManager.class.getSimpleName(); 13 | private final DBHelper dbHelper; 14 | private List mSSRSubAddedListeners; 15 | 16 | public SSRSubManager(DBHelper helper) { 17 | this.dbHelper = helper; 18 | mSSRSubAddedListeners = new ArrayList<>(20); 19 | } 20 | 21 | public SSRSub createSSRSub(SSRSub p) { 22 | SSRSub ssrsub; 23 | if (p == null) { 24 | ssrsub = new SSRSub(); 25 | } else { 26 | ssrsub = p; 27 | } 28 | ssrsub.id = 0; 29 | 30 | try { 31 | dbHelper.ssrsubDao.createOrUpdate(ssrsub); 32 | invokeSSRSubAdded(ssrsub); 33 | } catch (Exception e) { 34 | VayLog.e(TAG, "addSSRSub", e); 35 | ShadowsocksApplication.app.track(e); 36 | } 37 | return ssrsub; 38 | } 39 | 40 | public boolean updateSSRSub(SSRSub ssrsub) { 41 | try { 42 | dbHelper.ssrsubDao.update(ssrsub); 43 | return true; 44 | } catch (Exception e) { 45 | VayLog.e(TAG, "updateSSRSub", e); 46 | ShadowsocksApplication.app.track(e); 47 | return false; 48 | } 49 | } 50 | 51 | public SSRSub getSSRSub(int id) { 52 | try { 53 | return dbHelper.ssrsubDao.queryForId(id); 54 | } catch (Exception e) { 55 | VayLog.e(TAG, "getSSRSub", e); 56 | ShadowsocksApplication.app.track(e); 57 | return null; 58 | } 59 | } 60 | 61 | public boolean delSSRSub(int id) { 62 | try { 63 | dbHelper.ssrsubDao.deleteById(id); 64 | return true; 65 | } catch (Exception e) { 66 | VayLog.e(TAG, "delSSRSub", e); 67 | ShadowsocksApplication.app.track(e); 68 | return false; 69 | } 70 | } 71 | 72 | public SSRSub getFirstSSRSub() { 73 | try { 74 | List result = dbHelper.ssrsubDao.query(dbHelper.ssrsubDao.queryBuilder().limit(1L).prepare()); 75 | if (result != null && !result.isEmpty()) { 76 | return result.get(0); 77 | } else { 78 | return null; 79 | } 80 | } catch (Exception e) { 81 | VayLog.e(TAG, "getAllSSRSubs", e); 82 | ShadowsocksApplication.app.track(e); 83 | return null; 84 | } 85 | } 86 | 87 | public List getAllSSRSubs() { 88 | try { 89 | return dbHelper.ssrsubDao.query(dbHelper.ssrsubDao.queryBuilder().prepare()); 90 | } catch (Exception e) { 91 | VayLog.e(TAG, "getAllSSRSubs", e); 92 | ShadowsocksApplication.app.track(e); 93 | return null; 94 | } 95 | } 96 | 97 | public SSRSub createDefault() { 98 | SSRSub ssrSub = new SSRSub(); 99 | ssrSub.url = "https://raw.githubusercontent.com/breakwa11/breakwa11.github.io/master/free/freenodeplain.txt"; 100 | ssrSub.url_group = "Maying"; 101 | return createSSRSub(ssrSub); 102 | } 103 | 104 | /** 105 | * add ssr sub added listener 106 | * 107 | * @param l callback 108 | */ 109 | public void addSSRSubAddedListener(SSRSubAddedListener l) { 110 | if (mSSRSubAddedListeners == null) { 111 | return; 112 | } 113 | 114 | // adding listener 115 | if (!mSSRSubAddedListeners.contains(l)) { 116 | mSSRSubAddedListeners.add(l); 117 | } 118 | } 119 | 120 | /** 121 | * remove ssr sub added listener 122 | * 123 | * @param l callback 124 | */ 125 | public void removeSSRSubAddedListener(SSRSubAddedListener l) { 126 | if (mSSRSubAddedListeners == null || mSSRSubAddedListeners.isEmpty()) { 127 | return; 128 | } 129 | 130 | // remove listener 131 | if (mSSRSubAddedListeners.contains(l)) { 132 | mSSRSubAddedListeners.remove(l); 133 | } 134 | } 135 | 136 | /** 137 | * invoke ssr sub added listener 138 | * 139 | * @param ssrSub ssr sub param 140 | */ 141 | private void invokeSSRSubAdded(SSRSub ssrSub) { 142 | if (mSSRSubAddedListeners == null || mSSRSubAddedListeners.isEmpty()) { 143 | return; 144 | } 145 | 146 | // iteration invoke listener 147 | for (SSRSubAddedListener l : mSSRSubAddedListeners) { 148 | if (l != null) { 149 | l.onSSRSubAdded(ssrSub); 150 | } 151 | } 152 | } 153 | 154 | public interface SSRSubAddedListener { 155 | 156 | /** 157 | * ssr sub added 158 | * 159 | * @param ssrSub ssr sub object 160 | */ 161 | void onSSRSubAdded(SSRSub ssrSub); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/job/AclSyncJob.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.job; 2 | 3 | import com.evernote.android.job.Job; 4 | import com.evernote.android.job.JobRequest; 5 | import co.tgbot.peekfun.utils.IOUtils; 6 | import co.tgbot.peekfun.utils.VayLog; 7 | import co.tgbot.peekfun.ShadowsocksApplication; 8 | 9 | import java.io.IOException; 10 | import java.io.InputStream; 11 | import java.net.URL; 12 | import java.util.concurrent.TimeUnit; 13 | 14 | import androidx.annotation.NonNull; 15 | 16 | /** 17 | * @author Mygod 18 | */ 19 | public class AclSyncJob extends Job { 20 | 21 | public static final String TAG = AclSyncJob.class.getSimpleName(); 22 | 23 | private final String route; 24 | 25 | public AclSyncJob(String route) { 26 | this.route = route; 27 | } 28 | 29 | public static int schedule(String route) { 30 | return new JobRequest.Builder(AclSyncJob.TAG + ':' + route) 31 | .setExecutionWindow(1, TimeUnit.DAYS.toMillis(28)) 32 | .setRequirementsEnforced(true) 33 | .setRequiredNetworkType(JobRequest.NetworkType.UNMETERED) 34 | .setRequiresCharging(true) 35 | .setUpdateCurrent(true) 36 | .build().schedule(); 37 | } 38 | 39 | @NonNull 40 | @Override 41 | protected Result onRunJob(Params params) { 42 | String filename = route + ".acl"; 43 | InputStream is = null; 44 | try { 45 | if ("self".equals(route)) { 46 | // noinspection JavaAccessorMethodCalledAsEmptyParen 47 | is = new URL("https://raw.githubusercontent.com/shadowsocksr/shadowsocksr-android/nokcp/src/main/assets/acl/" + filename).openConnection().getInputStream(); 48 | IOUtils.writeString(ShadowsocksApplication.app.getApplicationInfo().dataDir + '/' + filename, IOUtils.readString(is)); 49 | } 50 | return Result.SUCCESS; 51 | } catch (IOException e) { 52 | VayLog.e(TAG, "onRunJob", e); 53 | ShadowsocksApplication.app.track(e); 54 | return Result.RESCHEDULE; 55 | } catch (Exception e) { 56 | // unknown failures, probably shouldn't retry 57 | VayLog.e(TAG, "onRunJob", e); 58 | ShadowsocksApplication.app.track(e); 59 | return Result.FAILURE; 60 | } finally { 61 | try { 62 | if (is != null) { 63 | is.close(); 64 | } 65 | } catch (IOException e) { 66 | VayLog.e(TAG, "onRunJob", e); 67 | ShadowsocksApplication.app.track(e); 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/job/DonaldTrump.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.job; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import com.evernote.android.job.Job; 42 | import com.evernote.android.job.JobCreator; 43 | import co.tgbot.peekfun.utils.VayLog; 44 | 45 | /** 46 | * “I create jobs all day long. 47 | * - Donald Trump, 2015 48 | *

49 | * Source: http://www.cnn.com/2015/09/24/politics/donald-trump-marco-rubio-foreign-policy/ 50 | * 51 | * @author !Mygod 52 | */ 53 | public class DonaldTrump implements JobCreator { 54 | 55 | private static final String TAG = DonaldTrump.class.getSimpleName(); 56 | 57 | @Override 58 | public Job create(String tag) { 59 | String[] parts = tag.split(":"); 60 | 61 | if (AclSyncJob.TAG.equals(parts[0])) { 62 | return new AclSyncJob(parts[1]); 63 | } else if (SSRSubUpdateJob.TAG.equals(parts[0])) { 64 | return new SSRSubUpdateJob(); 65 | } else { 66 | VayLog.w(TAG, "Unknown job tag: " + tag); 67 | return null; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/job/SSRSubUpdateJob.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.job; 2 | 3 | 4 | import android.util.Log; 5 | 6 | import com.evernote.android.job.Job; 7 | import com.evernote.android.job.JobRequest; 8 | 9 | import co.tgbot.peekfun.R; 10 | import co.tgbot.peekfun.database.SSRSub; 11 | import co.tgbot.peekfun.network.ssrsub.SubUpdateCallback; 12 | import co.tgbot.peekfun.network.ssrsub.SubUpdateHelper; 13 | import co.tgbot.peekfun.utils.Constants; 14 | import co.tgbot.peekfun.utils.ToastUtils; 15 | import co.tgbot.peekfun.utils.VayLog; 16 | import co.tgbot.peekfun.ShadowsocksApplication; 17 | 18 | import java.util.List; 19 | import java.util.concurrent.TimeUnit; 20 | 21 | import androidx.annotation.NonNull; 22 | 23 | /** 24 | * @author Mygod 25 | */ 26 | public class SSRSubUpdateJob extends Job { 27 | 28 | public static final String TAG = SSRSubUpdateJob.class.getSimpleName(); 29 | 30 | public static int schedule() { 31 | return new JobRequest.Builder(SSRSubUpdateJob.TAG) 32 | .setPeriodic(TimeUnit.HOURS.toMillis(1)) 33 | .setRequirementsEnforced(true) 34 | .setRequiresCharging(false) 35 | .setUpdateCurrent(true) 36 | .build().schedule(); 37 | } 38 | 39 | @NonNull 40 | @Override 41 | protected Result onRunJob(Params params) { 42 | if (ShadowsocksApplication.app.settings.getInt(Constants.Key.ssrsub_autoupdate, 0) == 1) { 43 | List subs = ShadowsocksApplication.app.ssrsubManager.getAllSSRSubs(); 44 | SubUpdateHelper.Companion.instance().updateSub(subs, new SubUpdateCallback() { 45 | @Override 46 | public void onSuccess(String subname) { 47 | VayLog.d(TAG, "onRunJob() update sub success!"); 48 | ToastUtils.showShort(getContext().getString(R.string.sub_autoupdate_success, subname)); 49 | Log.i("sub", subname); 50 | } 51 | 52 | @Override 53 | public void onFailed() { 54 | VayLog.e(TAG, "onRunJob() update sub failed!"); 55 | } 56 | }); 57 | return Result.SUCCESS; 58 | } else { 59 | return Result.RESCHEDULE; 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/network/ping/PingCallback.kt: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.network.ping 2 | 3 | 4 | import co.tgbot.peekfun.database.Profile 5 | 6 | /** 7 | * ping callback 8 | * 9 | * Created by vay on 2018/07/18 10 | */ 11 | open class PingCallback() { 12 | 13 | /** 14 | * get test result message 15 | */ 16 | /** 17 | * set test result message 18 | * 19 | * @param resultMsg test result message 20 | */ 21 | open var resultMsg: String = "" 22 | get() {return field} 23 | set(value) {field = value} 24 | 25 | /** 26 | * ping success 27 | * 28 | * @param elapsed ping elapsed 29 | */ 30 | open fun onSuccess(profile: Profile, elapsed: Long) { 31 | } 32 | 33 | /** 34 | * ping failed 35 | */ 36 | open fun onFailed(profile: Profile?) {} 37 | 38 | /** 39 | * ping finished 40 | */ 41 | open fun onFinished(profile: Profile?) {} 42 | } 43 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/network/request/RequestCallback.kt: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.network.request 2 | 3 | 4 | /** 5 | * request callback 6 | * 7 | * Created by vay on 2018/07/18 8 | */ 9 | open class RequestCallback { 10 | 11 | var start:Long = 0 12 | get() { 13 | return field 14 | } 15 | set(value) { 16 | field = value 17 | } 18 | 19 | 20 | /** 21 | * request success 22 | * 23 | * @param code response code 24 | * @param response response result 25 | */ 26 | open fun onSuccess(code: Int, response: String) {} 27 | 28 | /** 29 | * request failed 30 | * 31 | * @param code failed code 32 | * @param msg failed msg 33 | */ 34 | open fun onFailed(code: Int, msg: String) {} 35 | 36 | /** 37 | * request finished 38 | */ 39 | open fun onFinished() {} 40 | 41 | /** 42 | * is request ok 43 | * 44 | * @param code response code 45 | */ 46 | open fun isRequestOk(code: Int): Boolean { 47 | return code == 200||code==204 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/network/ssrsub/SubUpdateCallback.kt: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.network.ssrsub 2 | 3 | 4 | /** 5 | * Created by vay on 2018/07/19 6 | */ 7 | open class SubUpdateCallback { 8 | 9 | /** 10 | * success 11 | */ 12 | open fun onSuccess(subname:String) {} 13 | 14 | /** 15 | * failed 16 | */ 17 | open fun onFailed() {} 18 | 19 | /** 20 | * finished 21 | */ 22 | open fun onFinished() {} 23 | } 24 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/preferences/NumberPickerPreference.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.preferences; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.content.Context; 42 | import android.content.res.TypedArray; 43 | import android.os.Bundle; 44 | import android.util.AttributeSet; 45 | import android.view.View; 46 | import android.view.ViewGroup; 47 | import android.view.Window; 48 | import android.view.WindowManager; 49 | import android.widget.NumberPicker; 50 | 51 | import co.tgbot.peekfun.R; 52 | 53 | public class NumberPickerPreference extends SummaryDialogPreference { 54 | 55 | private NumberPicker picker; 56 | private int value; 57 | 58 | public NumberPickerPreference(Context context) { 59 | this(context, null); 60 | } 61 | 62 | public NumberPickerPreference(Context context, AttributeSet attrs) { 63 | super(context, attrs); 64 | picker = new NumberPicker(context); 65 | 66 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumberPickerPreference); 67 | setMin(a.getInt(R.styleable.NumberPickerPreference_min, 0)); 68 | setMax(a.getInt(R.styleable.NumberPickerPreference_max, Integer.MAX_VALUE - 1)); 69 | a.recycle(); 70 | } 71 | 72 | public int getValue() { 73 | return this.value; 74 | } 75 | 76 | public int getMin() { 77 | if (picker == null) { 78 | return 0; 79 | } 80 | 81 | return picker.getMinValue(); 82 | } 83 | 84 | public int getMax() { 85 | if (picker == null) { 86 | return 0; 87 | } 88 | 89 | return picker.getMaxValue(); 90 | } 91 | 92 | public void setValue(int i) { 93 | if (i == getValue()) { 94 | return; 95 | } 96 | 97 | picker.setValue(i); 98 | value = picker.getValue(); 99 | persistInt(value); 100 | notifyChanged(); 101 | } 102 | 103 | public void setMin(int value) { 104 | if (picker == null) { 105 | return; 106 | } 107 | 108 | picker.setMinValue(value); 109 | } 110 | 111 | public void setMax(int value) { 112 | if (picker == null) { 113 | return; 114 | } 115 | 116 | picker.setMaxValue(value); 117 | } 118 | 119 | @Override 120 | protected void showDialog(Bundle state) { 121 | super.showDialog(state); 122 | Window window = getDialog().getWindow(); 123 | if (window != null) { 124 | window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); 125 | } 126 | } 127 | 128 | @Override 129 | protected View onCreateDialogView() { 130 | ViewGroup parent = (ViewGroup) picker.getParent(); 131 | if (parent != null) { 132 | parent.removeView(picker); 133 | } 134 | return picker; 135 | } 136 | 137 | @Override 138 | protected void onDialogClosed(boolean positiveResult) { 139 | picker.clearFocus(); 140 | super.onDialogClosed(positiveResult); 141 | 142 | if (positiveResult) { 143 | int value = picker.getValue(); 144 | if (callChangeListener(value)) { 145 | setValue(value); 146 | return; 147 | } 148 | } 149 | picker.setValue(value); 150 | } 151 | 152 | @Override 153 | protected Object onGetDefaultValue(TypedArray a, int index) { 154 | return a.getInt(index, getMin()); 155 | } 156 | 157 | @Override 158 | protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) { 159 | int defValue = (int) defaultValue; 160 | int value = restorePersistedValue ? getPersistedInt(defValue) : defValue; 161 | setValue(value); 162 | } 163 | 164 | @Override 165 | public Object getSummaryValue() { 166 | return getValue(); 167 | } 168 | } 169 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/preferences/PasswordEditTextPreference.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.preferences; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.content.Context; 42 | import android.preference.EditTextPreference; 43 | import android.text.TextUtils; 44 | import android.util.AttributeSet; 45 | 46 | public class PasswordEditTextPreference extends EditTextPreference { 47 | 48 | private final CharSequence mDefaultSummary; 49 | 50 | public PasswordEditTextPreference(Context context, AttributeSet attrs) { 51 | this(context, attrs, android.R.attr.editTextPreferenceStyle); 52 | } 53 | 54 | public PasswordEditTextPreference(Context context, AttributeSet attrs, int defStyle) { 55 | super(context, attrs, defStyle); 56 | mDefaultSummary = getSummary(); 57 | } 58 | 59 | @Override 60 | public void setText(String text) { 61 | super.setText(text); 62 | setSummary(text); 63 | } 64 | 65 | @Override 66 | public void setSummary(CharSequence summary) { 67 | if (TextUtils.isEmpty(summary)) { 68 | super.setSummary(mDefaultSummary); 69 | } else { 70 | // convert password to "*" 71 | StringBuilder sb = new StringBuilder(); 72 | for (int i = 0; i < summary.length(); i++) { 73 | sb.append("*"); 74 | } 75 | super.setSummary(sb.toString()); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/preferences/SummaryDialogPreference.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.preferences; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.content.Context; 42 | import android.preference.DialogPreference; 43 | import android.util.AttributeSet; 44 | 45 | import java.util.Locale; 46 | 47 | /** 48 | * Make your preference support %s in summary. Override getSummaryValue to customize what to put in. 49 | * @author Mygod 50 | */ 51 | public abstract class SummaryDialogPreference extends DialogPreference { 52 | 53 | public SummaryDialogPreference(Context context) { 54 | super(context, null); 55 | } 56 | 57 | public SummaryDialogPreference(Context context, AttributeSet attrs) { 58 | super(context, attrs); 59 | } 60 | 61 | /** 62 | * Returns the summary of this SummaryPreference. If the summary has a String formatting marker in it 63 | * (i.e. "%s" or "%1$s"), then the current entry value will be substituted in its place. 64 | * 65 | * @return the summary with appropriate string substitution 66 | */ 67 | @Override 68 | public CharSequence getSummary() { 69 | return String.format(Locale.ENGLISH, super.getSummary().toString(), getSummaryValue()); 70 | } 71 | 72 | /** 73 | * get summary value 74 | * @return summary value 75 | */ 76 | public abstract Object getSummaryValue(); 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/preferences/SummaryEditTextPreference.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.preferences; 2 | 3 | 4 | import android.content.Context; 5 | import android.preference.EditTextPreference; 6 | import android.text.TextUtils; 7 | import android.util.AttributeSet; 8 | 9 | public class SummaryEditTextPreference extends EditTextPreference { 10 | 11 | private final CharSequence mDefaultSummary; 12 | 13 | public SummaryEditTextPreference(Context context, AttributeSet attrs) { 14 | this(context, attrs, android.R.attr.editTextPreferenceStyle); 15 | } 16 | 17 | public SummaryEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) { 18 | super(context, attrs, defStyleAttr); 19 | mDefaultSummary = getSummary(); 20 | } 21 | 22 | @Override 23 | public void setText(String text) { 24 | super.setText(text); 25 | setSummary(text); 26 | } 27 | 28 | @Override 29 | public void setSummary(CharSequence summary) { 30 | if (TextUtils.isEmpty(summary)) { 31 | super.setSummary(mDefaultSummary); 32 | } else { 33 | super.setSummary(summary); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/preferences/SummaryPreference.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.preferences; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.content.Context; 42 | import android.preference.Preference; 43 | import android.util.AttributeSet; 44 | 45 | import java.util.Locale; 46 | 47 | /** 48 | * Make your preference support %s in summary. Override getSummaryValue to customize what to put in. 49 | * @author Mygod 50 | */ 51 | public abstract class SummaryPreference extends Preference { 52 | 53 | public SummaryPreference(Context context) { 54 | super(context, null); 55 | } 56 | 57 | public SummaryPreference(Context context, AttributeSet attrs) { 58 | super(context, attrs); 59 | } 60 | 61 | /** 62 | * Returns the summary of this SummaryPreference. If the summary has a String formatting marker in it 63 | * (i.e. "%s" or "%1$s"), then the current entry value will be substituted in its place. 64 | * 65 | * @return the summary with appropriate string substitution 66 | */ 67 | @Override 68 | public CharSequence getSummary() { 69 | return String.format(Locale.ENGLISH, super.getSummary().toString(), getSummaryValue()); 70 | } 71 | 72 | /** 73 | * get summary value 74 | * @return summary value 75 | */ 76 | public abstract Object getSummaryValue(); 77 | } 78 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/utils/IOUtils.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.utils; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import java.io.FileWriter; 42 | import java.io.IOException; 43 | import java.io.InputStream; 44 | import java.io.OutputStream; 45 | import java.io.Reader; 46 | import java.io.Writer; 47 | import java.net.HttpURLConnection; 48 | 49 | public class IOUtils { 50 | 51 | private static final String TAG = IOUtils.class.getSimpleName(); 52 | private static final int BUFFER_SIZE = 32 * 1024; 53 | 54 | /** 55 | * in copy to out 56 | * 57 | * @param in input stream 58 | * @param out output stream 59 | * @throws IOException io write error 60 | */ 61 | public static void copy(InputStream in, OutputStream out) throws IOException { 62 | byte[] buffer = new byte[BUFFER_SIZE]; 63 | int temp; 64 | while ((temp = in.read(buffer)) != -1) { 65 | out.write(buffer, 0, temp); 66 | } 67 | out.flush(); 68 | } 69 | 70 | /** 71 | * read string by input stream 72 | * 73 | * @param in input stream 74 | * @return read failed return "" 75 | * @throws IOException io write error 76 | */ 77 | public static String readString(InputStream in) throws IOException { 78 | StringBuilder builder = new StringBuilder(); 79 | byte[] buffer = new byte[BUFFER_SIZE]; 80 | int temp; 81 | while ((temp = in.read(buffer)) != -1) { 82 | builder.append(new String(buffer, 0, temp)); 83 | } 84 | return builder.toString(); 85 | } 86 | 87 | /** 88 | * write string 89 | * 90 | * @param file file path 91 | * @param content string content 92 | * @return write failed return false. 93 | */ 94 | public static boolean writeString(String file, String content) { 95 | FileWriter writer = null; 96 | try { 97 | writer = new FileWriter(file); 98 | writer.write(content); 99 | return true; 100 | } catch (IOException e) { 101 | VayLog.e(TAG, "writeString", e); 102 | return false; 103 | } finally { 104 | try { 105 | if (writer != null) { 106 | writer.close(); 107 | } 108 | } catch (IOException e) { 109 | e.printStackTrace(); 110 | } 111 | } 112 | } 113 | 114 | public static void close(InputStream inputStream) { 115 | try { 116 | if (inputStream != null) { 117 | inputStream.close(); 118 | } 119 | } catch (IOException e) { 120 | // ignored 121 | } 122 | } 123 | 124 | public static void close(OutputStream outputStream) { 125 | try { 126 | if (outputStream != null) { 127 | outputStream.close(); 128 | } 129 | } catch (IOException e) { 130 | // Ignored 131 | } 132 | } 133 | 134 | public static void close(Writer writer) { 135 | try { 136 | if (writer != null) { 137 | writer.close(); 138 | } 139 | } catch (IOException e) { 140 | // Ignored 141 | } 142 | } 143 | 144 | public static void close(Reader reader) { 145 | try { 146 | if (reader != null) { 147 | reader.close(); 148 | } 149 | } catch (IOException e) { 150 | // Ignored 151 | } 152 | } 153 | 154 | public static void disconnect(HttpURLConnection conn) { 155 | if (conn != null) { 156 | conn.disconnect(); 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/utils/TaskerSettings.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.utils; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.content.Context; 42 | import android.content.Intent; 43 | import android.os.Bundle; 44 | 45 | import co.tgbot.peekfun.R; 46 | import co.tgbot.peekfun.database.Profile; 47 | import co.tgbot.peekfun.ShadowsocksApplication; 48 | 49 | public class TaskerSettings { 50 | 51 | private static final String KEY_SWITCH_ON = "switch_on"; 52 | private static final String KEY_PROFILE_ID = "profile_id"; 53 | 54 | public boolean switchOn; 55 | public int profileId; 56 | 57 | public TaskerSettings(Bundle bundle) { 58 | switchOn = bundle.getBoolean(KEY_SWITCH_ON, true); 59 | profileId = bundle.getInt(KEY_PROFILE_ID, -1); 60 | } 61 | 62 | public static TaskerSettings fromIntent(Intent intent) { 63 | Bundle bundle; 64 | if (intent.hasExtra(com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE)) { 65 | bundle = intent.getBundleExtra(com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE); 66 | } else { 67 | bundle = Bundle.EMPTY; 68 | } 69 | return new TaskerSettings(bundle); 70 | } 71 | 72 | public Intent toIntent(Context context) { 73 | Bundle bundle = new Bundle(); 74 | if (!switchOn) { 75 | bundle.putBoolean(KEY_SWITCH_ON, false); 76 | } 77 | 78 | if (profileId >= 0) { 79 | bundle.putInt(KEY_PROFILE_ID, profileId); 80 | } 81 | String value; 82 | Profile p = ShadowsocksApplication.app.profileManager.getProfile(profileId); 83 | if (p != null) { 84 | int strId = switchOn ? R.string.start_service : R.string.stop_service; 85 | value = context.getString(strId, p.name); 86 | } else { 87 | int strId = switchOn ? R.string.start_service_default : R.string.stop; 88 | value = context.getString(strId); 89 | } 90 | Intent intent = new Intent(); 91 | intent.putExtra(com.twofortyfouram.locale.api.Intent.EXTRA_BUNDLE, bundle); 92 | intent.putExtra(com.twofortyfouram.locale.api.Intent.EXTRA_STRING_BLURB, value); 93 | return intent; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/utils/TcpFastOpen.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.utils; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import java.io.File; 42 | import java.util.List; 43 | import java.util.regex.Matcher; 44 | import java.util.regex.Pattern; 45 | 46 | import eu.chainfire.libsuperuser.Shell; 47 | 48 | /** 49 | * @author Mygod 50 | */ 51 | public class TcpFastOpen { 52 | 53 | private static final Pattern p = Pattern.compile("^(\\d+)\\.(\\d+)\\.(\\d+)"); 54 | 55 | /** 56 | * Is kernel version >= 3.7.1. 57 | */ 58 | public static boolean supported() { 59 | Matcher m = p.matcher(System.getProperty("os.version")); 60 | while (m.find()) { 61 | int kernel = Integer.parseInt(m.group(1)); 62 | if (kernel < 3) { 63 | return false; 64 | } else if (kernel > 3) { 65 | return true; 66 | } else { 67 | int major = Integer.parseInt(m.group(2)); 68 | if (major < 7) { 69 | return false; 70 | } else if (major > 7) { 71 | return true; 72 | } else { 73 | return Integer.parseInt(m.group(3)) >= 1; 74 | } 75 | } 76 | } 77 | return false; 78 | } 79 | 80 | public static boolean sendEnabled() { 81 | File file = new File("/proc/sys/net/ipv4/tcp_fastopen"); 82 | return file.canRead() && (Integer.parseInt(Utils.readAllLines(file)) & 1) > 0; 83 | } 84 | 85 | public static String enabled(boolean value) { 86 | if (sendEnabled() != value) { 87 | boolean suAvailable = Shell.SU.available(); 88 | if (suAvailable) { 89 | int valueFlag = value ? 3 : 0; 90 | String[] cmds = { 91 | "if echo " + valueFlag + " > /proc/sys/net/ipv4/tcp_fastopen; then", 92 | " echo Success.", 93 | "else", 94 | " echo Failed.", 95 | }; 96 | 97 | List res = Shell.run("su", cmds, null, true); 98 | if (res != null && !res.isEmpty()) { 99 | return Utils.makeString(res, "\n"); 100 | } 101 | } 102 | } 103 | 104 | return null; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/utils/ToastUtils.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.utils; 2 | 3 | import android.content.Context; 4 | import android.widget.Toast; 5 | 6 | /** 7 | * Created by vay on 2018/03/07. 8 | */ 9 | public class ToastUtils { 10 | 11 | private static Toast mToast; 12 | private static Context sContext; 13 | 14 | public static void init(Context context) { 15 | sContext = context; 16 | } 17 | 18 | public static void showLong(String str){ 19 | cancelToast(); 20 | mToast = Toast.makeText(getContext(), str, Toast.LENGTH_LONG); 21 | mToast.show(); 22 | } 23 | 24 | public static void showLong(int strId){ 25 | cancelToast(); 26 | mToast = Toast.makeText(getContext(), strId, Toast.LENGTH_LONG); 27 | mToast.show(); 28 | } 29 | 30 | public static void showShort(String str){ 31 | cancelToast(); 32 | mToast = Toast.makeText(getContext(), str, Toast.LENGTH_SHORT); 33 | mToast.show(); 34 | } 35 | 36 | public static void showShort(int strId){ 37 | cancelToast(); 38 | mToast = Toast.makeText(getContext(), strId, Toast.LENGTH_SHORT); 39 | mToast.show(); 40 | } 41 | 42 | private static void cancelToast(){ 43 | if(mToast != null){ 44 | mToast.cancel(); 45 | } 46 | } 47 | 48 | /** 49 | * get context 50 | * 51 | * @return 52 | */ 53 | private static Context getContext() { 54 | return sContext; 55 | } 56 | } -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/utils/TrafficMonitor.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.utils; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import co.tgbot.peekfun.R; 42 | import co.tgbot.peekfun.ShadowsocksApplication; 43 | 44 | import java.text.DecimalFormat; 45 | 46 | public class TrafficMonitor { 47 | // Bytes per second 48 | public static long txRate; 49 | public static long rxRate; 50 | 51 | // Bytes for the current session 52 | public static long txTotal; 53 | public static long rxTotal; 54 | 55 | // Bytes for the last query 56 | public static long txLast; 57 | public static long rxLast; 58 | public static long timestampLast; 59 | public static boolean dirty = true; 60 | 61 | private static String[] units = {"KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB", "BB", "NB", "DB", "CB"}; 62 | private static DecimalFormat numberFormat = new DecimalFormat("@@@"); 63 | 64 | public static String formatTraffic(long size) { 65 | double n = size; 66 | int i = -1; 67 | while (n >= 1000) { 68 | n /= 1024; 69 | i = i + 1; 70 | } 71 | if (i < 0) { 72 | return size + " " + ShadowsocksApplication.app.getResources().getQuantityString(R.plurals.bytes, (int) size); 73 | } else { 74 | return numberFormat.format(n) + ' ' + units[i]; 75 | } 76 | } 77 | 78 | public static boolean updateRate() { 79 | long now = System.currentTimeMillis(); 80 | long delta = now - timestampLast; 81 | boolean updated = false; 82 | if (delta != 0) { 83 | if (dirty) { 84 | txRate = (txTotal - txLast) * 1000 / delta; 85 | rxRate = (rxTotal - rxLast) * 1000 / delta; 86 | txLast = txTotal; 87 | rxLast = rxTotal; 88 | dirty = false; 89 | updated = true; 90 | } else { 91 | if (txRate != 0) { 92 | txRate = 0; 93 | updated = true; 94 | } 95 | if (rxRate != 0) { 96 | rxRate = 0; 97 | updated = true; 98 | } 99 | } 100 | timestampLast = now; 101 | } 102 | return updated; 103 | } 104 | 105 | public static void update(Long tx, Long rx) { 106 | if (txTotal != tx) { 107 | txTotal = tx; 108 | dirty = true; 109 | } 110 | 111 | if (rxTotal != rx) { 112 | rxTotal = rx; 113 | dirty = true; 114 | } 115 | } 116 | 117 | public static void reset() { 118 | txRate = 0; 119 | rxRate = 0; 120 | txTotal = 0; 121 | rxTotal = 0; 122 | txLast = 0; 123 | rxLast = 0; 124 | dirty = true; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/utils/Typefaces.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.utils; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.content.Context; 42 | import android.graphics.Typeface; 43 | 44 | import co.tgbot.peekfun.ShadowsocksApplication; 45 | 46 | import java.util.Hashtable; 47 | 48 | public class Typefaces { 49 | 50 | private static final String TAG = Typefaces.class.getSimpleName(); 51 | private static final Hashtable cache = new Hashtable<>(); 52 | 53 | public static Typeface get(Context c, String assetPath) { 54 | synchronized (cache) { 55 | if (!cache.containsKey(assetPath)) { 56 | try { 57 | cache.put(assetPath, Typeface.createFromAsset(c.getAssets(), assetPath)); 58 | } catch (Exception e) { 59 | VayLog.e(TAG, "Could not get typeface '" + assetPath + "' because " + e.getMessage()); 60 | ShadowsocksApplication.app.track(e); 61 | return null; 62 | } 63 | } 64 | return cache.get(assetPath); 65 | } 66 | } 67 | } -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/utils/VayLog.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.utils; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.util.Log; 42 | 43 | import co.tgbot.peekfun.BuildConfig; 44 | 45 | /** 46 | * Created by vay on 2018/03/05. 47 | */ 48 | public class VayLog { 49 | 50 | private final static String DEFAULT_TAG = "VayLog"; 51 | 52 | private static boolean LOGGABLE = BuildConfig.DEBUG; 53 | 54 | public static void d(String str) { 55 | d(DEFAULT_TAG, str); 56 | } 57 | 58 | public static void d(String tag, String str) { 59 | if (LOGGABLE) { 60 | Log.d(tag, str + ""); 61 | } 62 | } 63 | 64 | public static void w(String str) { 65 | w(DEFAULT_TAG, str); 66 | } 67 | 68 | public static void w(String tag, String str) { 69 | if (LOGGABLE) { 70 | Log.w(tag, str + ""); 71 | } 72 | } 73 | 74 | public static void e(String str) { 75 | e(DEFAULT_TAG, str); 76 | } 77 | 78 | public static void e(String tag, String str) { 79 | e(tag, str, null); 80 | } 81 | 82 | public static void e(String tag, String msg, Throwable e) { 83 | if (LOGGABLE) { 84 | Log.e(tag, msg + "", e); 85 | } 86 | } 87 | 88 | public static void i(String str) { 89 | i(DEFAULT_TAG, str + ""); 90 | } 91 | 92 | public static void i(String tag, String str) { 93 | if (LOGGABLE) { 94 | Log.i(tag, str + ""); 95 | } 96 | } 97 | 98 | public static void v(String str) { 99 | v(DEFAULT_TAG, str + ""); 100 | } 101 | 102 | public static void v(String tag, String str) { 103 | if (LOGGABLE) { 104 | Log.v(tag, str + ""); 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/widget/FloatingActionMenuBehavior.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.widget; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.animation.ValueAnimator; 42 | import android.content.Context; 43 | import android.util.AttributeSet; 44 | import android.view.View; 45 | 46 | import com.github.clans.fab.FloatingActionMenu; 47 | import com.google.android.material.snackbar.Snackbar; 48 | 49 | import java.util.List; 50 | 51 | import androidx.coordinatorlayout.widget.CoordinatorLayout; 52 | import androidx.interpolator.view.animation.FastOutSlowInInterpolator; 53 | 54 | /** 55 | * Behavior for com.github.clans.fab.FloatingActionMenu that is aware of Snackbars and scrolling. 56 | * 57 | * @author Mygod 58 | */ 59 | public class FloatingActionMenuBehavior extends CoordinatorLayout.Behavior { 60 | 61 | private ValueAnimator fabTranslationYAnimator; 62 | private float fabTranslationY; 63 | 64 | public FloatingActionMenuBehavior(Context context, AttributeSet attrs) { 65 | super(context, attrs); 66 | } 67 | 68 | @Override 69 | public boolean layoutDependsOn(CoordinatorLayout parent, FloatingActionMenu child, View dependency) { 70 | return dependency instanceof Snackbar.SnackbarLayout; 71 | } 72 | 73 | @Override 74 | public boolean onDependentViewChanged(CoordinatorLayout parent, final FloatingActionMenu child, View dependency) { 75 | float targetTransY = 0; 76 | List dependencies = parent.getDependencies(child); 77 | for (View view : dependencies) { 78 | if (view instanceof Snackbar.SnackbarLayout && parent.doViewsOverlap(child, view)) { 79 | float value = view.getTranslationY() - view.getHeight(); 80 | if (value <= targetTransY) { 81 | targetTransY = value; 82 | } 83 | } 84 | } 85 | 86 | if (targetTransY > 0) { 87 | targetTransY = 0; 88 | } 89 | 90 | if (fabTranslationY != targetTransY) { 91 | float currentTransY = child.getTranslationY(); 92 | if (fabTranslationYAnimator != null && fabTranslationYAnimator.isRunning()) { 93 | fabTranslationYAnimator.cancel(); 94 | } 95 | if (child.isShown() && Math.abs(currentTransY - targetTransY) > child.getHeight() * 0.667F) { 96 | if (fabTranslationYAnimator == null) { 97 | fabTranslationYAnimator = new ValueAnimator(); 98 | fabTranslationYAnimator.setInterpolator(new FastOutSlowInInterpolator()); 99 | fabTranslationYAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { 100 | @Override 101 | public void onAnimationUpdate(ValueAnimator animation) { 102 | child.setTranslationY((float) animation.getAnimatedValue()); 103 | } 104 | }); 105 | } 106 | fabTranslationYAnimator.setFloatValues(currentTransY, targetTransY); 107 | fabTranslationYAnimator.start(); 108 | } else { 109 | child.setTranslationY(targetTransY); 110 | } 111 | fabTranslationY = targetTransY; 112 | } 113 | return false; 114 | } 115 | 116 | @Override 117 | public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, FloatingActionMenu child, View directTargetChild, View target, int nestedScrollAxes) { 118 | return true; 119 | } 120 | 121 | @Override 122 | public void onNestedScroll(CoordinatorLayout parent, FloatingActionMenu child, View target, int dxConsumed, int dyConsumed, int dxUnconsumed, int dyUnconsumed) { 123 | super.onNestedScroll(parent, child, target, dxConsumed, dyConsumed, dxUnconsumed, dyUnconsumed); 124 | int dy = dyConsumed + dyUnconsumed; 125 | if (child.isMenuButtonHidden()) { 126 | if (dy < 0) { 127 | child.showMenuButton(true); 128 | } 129 | } else if (dy > 0) { 130 | child.hideMenuButton(true); 131 | } 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /app/src/main/java/co/tgbot/peekfun/widget/UndoSnackbarManager.java: -------------------------------------------------------------------------------- 1 | package co.tgbot.peekfun.widget; 2 | /* 3 | * Shadowsocks - A co.tgbot.peekfun client for Android 4 | * Copyright (C) 2014 5 | * 6 | * This program is free software: you can redistribute it and/or modify 7 | * it under the terms of the GNU General Public License as published by 8 | * the Free Software Foundation, either version 3 of the License, or 9 | * (at your option) any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | * GNU General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU General Public License 17 | * along with this program. If not, see . 18 | * 19 | * 20 | * ___====-_ _-====___ 21 | * _--^^^#####// \\#####^^^--_ 22 | * _-^##########// ( ) \\##########^-_ 23 | * -############// |\^^/| \\############- 24 | * _/############// (@::@) \\############\_ 25 | * /#############(( \\// ))#############\ 26 | * -###############\\ (oo) //###############- 27 | * -#################\\ / VV \ //#################- 28 | * -###################\\/ \//###################- 29 | * _#/|##########/\######( /\ )######/\##########|\#_ 30 | * |/ |#/\#/\#/\/ \#/\##\ | | /##/\#/ \/\#/\#/\#| \| 31 | * ` |/ V V ` V \#\| | | |/#/ V ' V V \| ' 32 | * ` ` ` ` / | | | | \ ' ' ' ' 33 | * ( | | | | ) 34 | * __\ | | | | /__ 35 | * (vvv(VVV)(VVV)vvv) 36 | * 37 | * HERE BE DRAGONS 38 | * 39 | */ 40 | 41 | import android.util.SparseArray; 42 | import android.view.View; 43 | 44 | import co.tgbot.peekfun.R; 45 | import com.google.android.material.snackbar.Snackbar; 46 | 47 | /** 48 | * @author Mygod 49 | */ 50 | public class UndoSnackbarManager { 51 | 52 | private final View view; 53 | private OnUndoListener undo; 54 | private OnCommitListener commit; 55 | 56 | private SparseArray recycleBin; 57 | private Snackbar last; 58 | 59 | private Snackbar.Callback removedCallback = new Snackbar.Callback() { 60 | @Override 61 | public void onDismissed(Snackbar transientBottomBar, int event) { 62 | if (event == Snackbar.Callback.DISMISS_EVENT_SWIPE || event == Snackbar.Callback.DISMISS_EVENT_MANUAL || 63 | event == Snackbar.Callback.DISMISS_EVENT_TIMEOUT) { 64 | if (commit != null) { 65 | commit.onCommit(recycleBin); 66 | } 67 | recycleBin.clear(); 68 | } 69 | last = null; 70 | } 71 | }; 72 | 73 | /** 74 | * @param view The view to find a parent from. 75 | * @param undo Callback for undoing removals. 76 | * @param commit Callback for committing removals. 77 | * @tparam T Item type. 78 | */ 79 | public UndoSnackbarManager(View view, OnUndoListener undo, OnCommitListener commit) { 80 | recycleBin = new SparseArray<>(); 81 | this.view = view; 82 | this.undo = undo; 83 | this.commit = commit; 84 | } 85 | 86 | public void remove(int index, T item) { 87 | recycleBin.append(index, item); 88 | int count = recycleBin.size(); 89 | last = Snackbar.make(view, view.getResources().getQuantityString(R.plurals.removed, count, count), Snackbar.LENGTH_LONG) 90 | .setCallback(removedCallback) 91 | .setAction(R.string.undo, new View.OnClickListener() { 92 | @Override 93 | public void onClick(View v) { 94 | if (undo != null) { 95 | undo.onUndo(recycleBin); 96 | } 97 | recycleBin.clear(); 98 | } 99 | }); 100 | last.show(); 101 | } 102 | 103 | public void flush() { 104 | if (last != null) { 105 | last.dismiss(); 106 | } 107 | } 108 | 109 | public interface OnCommitListener { 110 | 111 | /** 112 | * commit recycle bin 113 | * @param commit commit list 114 | */ 115 | void onCommit(SparseArray commit); 116 | } 117 | 118 | public interface OnUndoListener { 119 | 120 | /** 121 | * undo recycle bin 122 | * @param undo undo list 123 | */ 124 | void onUndo(SparseArray undo); 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-anydpi-v21/ic_action_settings.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-anydpi-v21/ic_navigation_close.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-anydpi-v21/ic_qu_camera_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 15 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-anydpi-v21/ic_qu_shadowsocks_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 11 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-hdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_navigation_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-hdpi/ic_navigation_close.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-hdpi/ic_stat_shadowsocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-hdpi/ic_stat_shadowsocks.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-mdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_navigation_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-mdpi/ic_navigation_close.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-mdpi/ic_stat_shadowsocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-mdpi/ic_stat_shadowsocks.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-v21/background_stat.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-xhdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_navigation_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-xhdpi/ic_navigation_close.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xhdpi/ic_stat_shadowsocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-xhdpi/ic_stat_shadowsocks.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-xxhdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_navigation_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-xxhdpi/ic_navigation_close.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/ic_stat_shadowsocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-xxhdpi/ic_stat_shadowsocks.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_action_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-xxxhdpi/ic_action_settings.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxxhdpi/ic_navigation_close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/drawable-xxxhdpi/ic_navigation_close.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/background_stat.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_arrow_drop_down.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_click.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_click_white.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_content_add.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_content_copy.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_content_create.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_content_paste.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_device_nfc.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_down.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_http.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_image_camera_alt.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 13 | 14 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_rss.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_social_share.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_start_busy.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 13 | 16 | 17 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_start_connected.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 12 | 15 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_start_idle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 12 | 17 | 20 | 23 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_tcp.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /app/src/main/res/layout-w400dp/layout_main_stat_title.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_apps.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 16 | 28 | 40 | 41 | 44 | 49 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_apps_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 8 | 9 | 18 | 19 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_edittext.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_front_proxy.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 23 | 24 | 31 | 38 | 39 | 46 | 52 | 53 | 60 | 66 | 67 | 74 | 80 | 81 | 88 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_main_stat_title.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_profiles.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 14 | 15 | 16 | 21 | 22 | 29 | 30 | 31 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 53 | 54 | 64 | 65 | 75 | 76 | 86 | 87 | 97 | 98 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_profiles_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 15 | 30 | 40 | 50 | 60 | 61 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_quick_switch.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | 16 | 17 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_scanner.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_ssr_sub.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 23 | 24 | 31 | 32 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_ssr_sub_item.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 14 | 26 | 27 | -------------------------------------------------------------------------------- /app/src/main/res/layout/layout_tasker.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 11 | 17 | 18 | 21 | 22 | -------------------------------------------------------------------------------- /app/src/main/res/layout/toolbar_light_dark.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/menu/app_manager_menu.xml: -------------------------------------------------------------------------------- 1 |

3 | 8 | 14 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/res/menu/profile_manager_menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 10 | 16 | 22 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/raw/gtm_default_container: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/app/src/main/res/raw/gtm_default_container -------------------------------------------------------------------------------- /app/src/main/res/values-ja-v21/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 選択したアプリにプロキシを設定する 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values-ru-v21/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Установить прокси для выбранных приложений 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/dimen.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -28dp 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Set proxy for selected apps 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/values-v21/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 8 | 9 | 18 | 19 | 24 | 25 | 30 | 31 | 34 | 35 | 38 | 39 | 46 | 47 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /app/src/main/res/xml/network_security_config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/xml/shortcuts.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 10 | 11 | 15 | 18 | 19 | 23 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /app/src/main/res/xml/tracker.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 604800 5 | 6 | 7 | true 8 | 9 | 10 | true 11 | 12 | 13 | 14 | Shadowsocks ScreenView 15 | 16 | 17 | 18 | Shadowsocks EcommerceView 19 | 20 | 21 | 22 | UA-37082941-1 23 | 24 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | ext.kotlin_version = '1.3.50'//kotlin的版本 6 | 7 | 8 | repositories { 9 | google() 10 | jcenter() 11 | } 12 | dependencies { 13 | classpath 'com.android.tools.build:gradle:3.5.0' 14 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 15 | 16 | 17 | // NOTE: Do not place your application dependencies here; they belong 18 | // in the individual module build.gradle files 19 | } 20 | } 21 | 22 | allprojects { 23 | repositories { 24 | google() 25 | jcenter() 26 | } 27 | } 28 | 29 | task clean(type: Delete) { 30 | delete rootProject.buildDir 31 | } 32 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shadowsocksrr/Maying/ce295e29b821564ad99def8c6efc0dfa1871a66d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sun Sep 08 21:05:43 CST 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem http://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 34 | 35 | @rem Find java.exe 36 | if defined JAVA_HOME goto findJavaFromJavaHome 37 | 38 | set JAVA_EXE=java.exe 39 | %JAVA_EXE% -version >NUL 2>&1 40 | if "%ERRORLEVEL%" == "0" goto init 41 | 42 | echo. 43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 44 | echo. 45 | echo Please set the JAVA_HOME variable in your environment to match the 46 | echo location of your Java installation. 47 | 48 | goto fail 49 | 50 | :findJavaFromJavaHome 51 | set JAVA_HOME=%JAVA_HOME:"=% 52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 53 | 54 | if exist "%JAVA_EXE%" goto init 55 | 56 | echo. 57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 58 | echo. 59 | echo Please set the JAVA_HOME variable in your environment to match the 60 | echo location of your Java installation. 61 | 62 | goto fail 63 | 64 | :init 65 | @rem Get command-line arguments, handling Windows variants 66 | 67 | if not "%OS%" == "Windows_NT" goto win9xME_args 68 | 69 | :win9xME_args 70 | @rem Slurp the command line arguments. 71 | set CMD_LINE_ARGS= 72 | set _SKIP=2 73 | 74 | :win9xME_args_slurp 75 | if "x%~1" == "x" goto execute 76 | 77 | set CMD_LINE_ARGS=%* 78 | 79 | :execute 80 | @rem Setup the command line 81 | 82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 83 | 84 | @rem Execute Gradle 85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 86 | 87 | :end 88 | @rem End local scope for the variables with windows NT shell 89 | if "%ERRORLEVEL%"=="0" goto mainEnd 90 | 91 | :fail 92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 93 | rem the _cmd.exe /c_ return code! 94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 95 | exit /b 1 96 | 97 | :mainEnd 98 | if "%OS%"=="Windows_NT" endlocal 99 | 100 | :omega 101 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------