├── .gitattributes ├── .github └── workflows │ └── android.yml ├── .gitignore ├── LICENSE ├── README.md ├── README_en.md ├── app ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro ├── release │ └── output-metadata.json └── src │ ├── androidTest │ └── java │ │ └── io │ │ └── github │ │ └── acedroidx │ │ └── frp │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── assets │ │ ├── frpc.toml │ │ └── frps.toml │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── acedroidx │ │ │ └── frp │ │ │ ├── AboutActivity.kt │ │ │ ├── AutoStartBroadReceiver.kt │ │ │ ├── ConfigActivity.kt │ │ │ ├── FrpConfig.kt │ │ │ ├── FrpType.kt │ │ │ ├── IntentExtraKey.kt │ │ │ ├── MainActivity.kt │ │ │ ├── PreferencesKey.kt │ │ │ ├── ShellService.kt │ │ │ ├── ShellServiceAction.kt │ │ │ ├── ShellThread.kt │ │ │ └── ui │ │ │ └── theme │ │ │ ├── Color.kt │ │ │ ├── Theme.kt │ │ │ └── Type.kt │ ├── jniLibs │ │ ├── arm64-v8a │ │ │ ├── libfrpc.so │ │ │ └── libfrps.so │ │ ├── armeabi-v7a │ │ │ ├── libfrpc.so │ │ │ └── libfrps.so │ │ └── x86_64 │ │ │ ├── libfrpc.so │ │ │ └── libfrps.so │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_baseline_delete_24.xml │ │ ├── ic_launcher_background.xml │ │ ├── ic_pencil_24dp.xml │ │ └── ic_rename.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── resources.properties │ │ ├── values-night │ │ └── themes.xml │ │ ├── values-zh │ │ └── strings.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── io │ └── github │ └── acedroidx │ └── frp │ └── ExampleUnitTest.kt ├── build.gradle.kts ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── image ├── image1.png ├── image1_en.png ├── image2.png └── image2_en.png ├── keystore.example.properties └── settings.gradle.kts /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.github/workflows/android.yml: -------------------------------------------------------------------------------- 1 | name: Android CI 2 | 3 | on: 4 | push: 5 | workflow_dispatch: 6 | 7 | jobs: 8 | build: 9 | 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - uses: actions/checkout@v4 14 | - name: set up JDK 17 15 | uses: actions/setup-java@v4 16 | with: 17 | java-version: '17' 18 | distribution: 'temurin' 19 | cache: gradle 20 | 21 | # https://docs.github.com/en/actions/security-for-github-actions/security-guides/using-secrets-in-github-actions#storing-base64-binary-blobs-as-secrets 22 | - name: Retrieve the secret and decode it to a file 23 | env: 24 | STORE_FILE: ${{ secrets.STORE_FILE }} 25 | run: | 26 | echo $STORE_FILE | base64 --decode > keystore.jks 27 | 28 | - name: Generate blank keystore.properties to bypass gradle check 29 | run: touch keystore.properties 30 | 31 | - name: Grant execute permission for gradlew 32 | run: chmod +x gradlew 33 | - name: Build with Gradle 34 | run: ./gradlew assembleRelease 35 | env: 36 | KEY_ALIAS: ${{ secrets.KEY_ALIAS }} 37 | KEY_PASSWORD: ${{ secrets.KEY_PASSWORD }} 38 | STORE_FILE: ${{ secrets.STORE_FILE }} 39 | STORE_PASSWORD: ${{ secrets.STORE_PASSWORD }} 40 | 41 | - name: Upload artifact 42 | uses: actions/upload-artifact@v4 43 | with: 44 | name: frp-Android-artifact 45 | path: app/build/outputs/apk/release/*.apk -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | *.aab 5 | 6 | # Files for the ART/Dalvik VM 7 | *.dex 8 | 9 | # Java class files 10 | *.class 11 | 12 | # Generated files 13 | bin/ 14 | gen/ 15 | out/ 16 | # Uncomment the following line in case you need and you don't have the release build type files in your app 17 | # release/ 18 | 19 | # Gradle files 20 | .gradle/ 21 | build/ 22 | 23 | # Local configuration file (sdk path, etc) 24 | local.properties 25 | 26 | # Proguard folder generated by Eclipse 27 | proguard/ 28 | 29 | # Log Files 30 | *.log 31 | 32 | # Android Studio Navigation editor temp files 33 | .navigation/ 34 | 35 | # Android Studio captures folder 36 | captures/ 37 | 38 | # IntelliJ 39 | *.iml 40 | .idea/workspace.xml 41 | .idea/tasks.xml 42 | .idea/gradle.xml 43 | .idea/assetWizardSettings.xml 44 | .idea/dictionaries 45 | .idea/libraries 46 | # Android Studio 3 in .gitignore file. 47 | .idea/caches 48 | .idea/modules.xml 49 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you 50 | .idea/navEditor.xml 51 | 52 | # Keystore files 53 | # Uncomment the following lines if you do not want to check your keystore files in. 54 | #*.jks 55 | #*.keystore 56 | 57 | # External native build folder generated in Android Studio 2.2 and later 58 | .externalNativeBuild 59 | 60 | # Google Services (e.g. APIs or Firebase) 61 | # google-services.json 62 | 63 | # Freeline 64 | freeline.py 65 | freeline/ 66 | freeline_project_description.json 67 | 68 | # fastlane 69 | fastlane/report.xml 70 | fastlane/Preview.html 71 | fastlane/screenshots 72 | fastlane/test_output 73 | fastlane/readme.md 74 | 75 | # Version control 76 | vcs.xml 77 | 78 | # lint 79 | lint/intermediates/ 80 | lint/generated/ 81 | lint/outputs/ 82 | lint/tmp/ 83 | # lint/reports/ 84 | 85 | keystore.properties 86 | .idea 87 | 88 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # frp-Android 2 | A frp client for Android 3 | 一个Android的frpc客户端 4 | 5 | 简体中文 | [English](README_en.md) 6 | 7 |
8 | image1.png 9 | image2.png 10 |
11 | 12 | ## 编译方法 13 | 14 | 如果您想自定义frp内核,可以通过Github Actions或通过Android Studio编译 15 | 16 | ### 通过Github Actions编译 17 | 18 | 1. 将您的apk签名密钥文件转为base64,以下为Linux示例 19 | ```shell 20 | base64 -w 0 keystore.jks > keystore.jks.base64 21 | ``` 22 | 2. fork本项目 23 | 3. 转到Github项目的此页面:Settings > Secrets and variables > Actions > Repository secrets 24 | 4. 添加以下四个环境变量: 25 | ```KEY_ALIAS``` ```KEY_PASSWORD``` ```STORE_FILE``` ```STORE_PASSWORD``` 26 | 其中```STORE_FILE```的内容为步骤1的base64,其他环境变量内容请根据您的密钥文件自行填写 27 | 5. Push提交自动触发编译或在Actions页面手动触发 28 | 29 | ### 通过Android Studio编译 30 | 31 | 1. 在项目根目录创建apk签名密钥设置文件```keystore.properties```,内容参考同级的```keystore.example.properties``` 32 | 2. 使用Android Studio进行编译打包 33 | 34 | ## 常见问题 35 | ### 项目的frp内核(libfrpc.so)是怎么来的? 36 | 直接从[frp的release](https://github.com/fatedier/frp/releases)里把对应ABI的Linux版本压缩包解压之后重命名frpc为libfrpc.so 37 | 项目不是在代码里调用so中的方法,而是把so作为一个可执行文件,然后通过shell去执行对应的命令 38 | 因为Golang的零依赖特性,所以可以直接在Android里通过shell运行可执行文件 39 | 40 | ### 开机自启与后台保活 41 | 按照原生Android规范设计,如有问题请在系统设置内允许开机自启/后台运行相关选项 -------------------------------------------------------------------------------- /README_en.md: -------------------------------------------------------------------------------- 1 | # frp-Android 2 | A frp client for Android 3 | 一个Android的frpc客户端 4 | 5 | [简体中文](README.md) | English 6 | 7 |
8 | image1_en.png 9 | image2_en.png 10 |
11 | 12 | ## Compilation Methods 13 | 14 | If you wish to customize the frp kernel, you can compile it via Github Actions or through Android Studio. 15 | 16 | ### Compiling via Github Actions 17 | 18 | 1. Convert your APK signing key file to base64; here's a Linux example: 19 | ```shell 20 | base64 -w 0 keystore.jks > keystore.jks.base64 21 | ``` 22 | 2. Fork this project. 23 | 3. Navigate to this page of the Github project: Settings > Secrets and variables > Actions > Repository secrets. 24 | 4. Add the following four environment variables: 25 | ```KEY_ALIAS``` ```KEY_PASSWORD``` ```STORE_FILE``` ```STORE_PASSWORD``` 26 | The content for ```STORE_FILE``` should be the base64 from step 1, while you should fill in the other environment variables according to your key file. 27 | 5. A push commit will automatically trigger compilation, or you can manually trigger it on the Actions page. 28 | 29 | ### Compiling via Android Studio 30 | 31 | 1. Create an APK signing key configuration file named ```keystore.properties``` at the root directory of the project, referencing the existing ```keystore.example.properties``` file at the same level. 32 | 2. Compile and package using Android Studio. 33 | 34 | ## FAQs 35 | ### Where does the frp kernel (libfrpc.so) of the project come from? 36 | It is obtained directly by extracting the corresponding ABI Linux version archive from [frp's release](https://github.com/fatedier/frp/releases), renaming frpc to libfrpc.so. 37 | The project does not invoke methods from the so file within its code but treats the so as an executable file, executing the corresponding command through shell. 38 | Due to Golang's zero-dependency characteristic, the executable file can be run directly through shell in Android. 39 | 40 | ### Start at bootup and background keep-alive 41 | Designed according to the native Android specification, if there is any problem, please allow boot/background options in the system settings. -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | import java.io.FileInputStream 2 | import java.util.Properties 3 | 4 | plugins { 5 | id("com.android.application") 6 | id("org.jetbrains.kotlin.android") 7 | id("org.jetbrains.kotlin.plugin.compose") 8 | id("org.jetbrains.kotlin.plugin.parcelize") 9 | } 10 | 11 | val keystorePropertiesFile = rootProject.file("keystore.properties") 12 | val keystoreProperties = Properties() 13 | keystoreProperties.load(FileInputStream(keystorePropertiesFile)) 14 | 15 | android { 16 | androidResources { 17 | generateLocaleConfig = true 18 | } 19 | 20 | buildFeatures { 21 | buildConfig = true 22 | compose = true 23 | } 24 | 25 | signingConfigs { 26 | create("AceKeystore") { 27 | keyAlias = System.getenv("KEY_ALIAS") ?: keystoreProperties["keyAlias"] as String 28 | keyPassword = 29 | System.getenv("KEY_PASSWORD") ?: keystoreProperties["keyPassword"] as String 30 | storeFile = 31 | if (System.getenv("STORE_FILE") != null && System.getenv("STORE_FILE") != "") file("../keystore.jks") else file( 32 | keystoreProperties["storeFile"] as String 33 | ) 34 | storePassword = 35 | System.getenv("STORE_PASSWORD") ?: keystoreProperties["storePassword"] as String 36 | } 37 | } 38 | 39 | defaultConfig { 40 | applicationId = "io.github.acedroidx.frp" 41 | minSdk = 23 42 | targetSdk = 35 43 | compileSdk = 35 44 | versionCode = 8 45 | versionName = "1.2.1" 46 | 47 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" 48 | 49 | signingConfig = signingConfigs.getByName("AceKeystore") 50 | 51 | buildConfigField("String", "FrpVersion", "\"0.61.1\"") 52 | buildConfigField("String", "FrpcFileName", "\"libfrpc.so\"") 53 | buildConfigField("String", "FrpsFileName", "\"libfrps.so\"") 54 | buildConfigField("String", "FrpcConfigFileName", "\"frpc.toml\"") 55 | buildConfigField("String", "FrpsConfigFileName", "\"frps.toml\"") 56 | } 57 | 58 | buildTypes { 59 | getByName("release") { 60 | isMinifyEnabled = false 61 | isShrinkResources = false 62 | proguardFiles( 63 | // Includes the default ProGuard rules files that are packaged with 64 | // the Android Gradle plugin. To learn more, go to the section about 65 | // R8 configuration files. 66 | getDefaultProguardFile("proguard-android-optimize.txt"), 67 | // Includes a local, custom Proguard rules file 68 | "proguard-rules.pro" 69 | ) 70 | signingConfig = signingConfigs.getByName("AceKeystore") 71 | } 72 | getByName("debug") { 73 | signingConfig = signingConfigs.getByName("AceKeystore") 74 | } 75 | } 76 | compileOptions { 77 | sourceCompatibility = JavaVersion.VERSION_17 78 | targetCompatibility = JavaVersion.VERSION_17 79 | } 80 | kotlinOptions { 81 | jvmTarget = "17" 82 | } 83 | packaging { 84 | jniLibs { 85 | useLegacyPackaging = true 86 | } 87 | } 88 | splits { 89 | abi { 90 | isEnable = true 91 | reset() 92 | include("arm64-v8a", "x86_64", "armeabi-v7a") 93 | isUniversalApk = true 94 | } 95 | } 96 | namespace = "io.github.acedroidx.frp" 97 | } 98 | 99 | dependencies { 100 | implementation("org.jetbrains.kotlin:kotlin-stdlib:2.1.0") 101 | implementation("androidx.core:core-ktx:1.15.0") 102 | implementation("androidx.appcompat:appcompat:1.7.0") 103 | implementation("com.google.android.material:material:1.12.0") 104 | implementation("androidx.constraintlayout:constraintlayout:2.2.0") 105 | 106 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.8.7") 107 | implementation("androidx.lifecycle:lifecycle-service:2.8.7") 108 | implementation("androidx.lifecycle:lifecycle-runtime-compose:2.8.7") 109 | 110 | val composeBom = platform("androidx.compose:compose-bom:2024.12.01") 111 | implementation(composeBom) 112 | androidTestImplementation(composeBom) 113 | implementation("androidx.compose.material3:material3") 114 | // Android Studio Preview support 115 | implementation("androidx.compose.ui:ui-tooling-preview") 116 | debugImplementation("androidx.compose.ui:ui-tooling") 117 | // UI Tests 118 | androidTestImplementation("androidx.compose.ui:ui-test-junit4") 119 | debugImplementation("androidx.compose.ui:ui-test-manifest") 120 | // Optional - Integration with activities 121 | implementation("androidx.activity:activity-compose") 122 | 123 | testImplementation("junit:junit:4.13.2") 124 | androidTestImplementation("androidx.test.ext:junit:1.2.1") 125 | androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1") 126 | } -------------------------------------------------------------------------------- /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.kts. 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 -------------------------------------------------------------------------------- /app/release/output-metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 2, 3 | "artifactType": { 4 | "type": "APK", 5 | "kind": "Directory" 6 | }, 7 | "applicationId": "io.github.acedroidx.frp", 8 | "variantName": "processReleaseResources", 9 | "elements": [ 10 | { 11 | "type": "SINGLE", 12 | "filters": [], 13 | "versionCode": 1, 14 | "versionName": "1.0", 15 | "outputFile": "app-release.apk" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /app/src/androidTest/java/io/github/acedroidx/frp/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("io.github.acedroidx.frp", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 21 | 22 | 23 | 24 | 27 | 28 | 33 | 36 | 37 | 38 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /app/src/main/assets/frpc.toml: -------------------------------------------------------------------------------- 1 | serverAddr = "" 2 | serverPort = 7000 3 | dnsServer = "114.114.114.114" 4 | 5 | [log] 6 | level = "debug" 7 | disablePrintColor = true 8 | 9 | [[visitors]] 10 | name = "p2p_visitor" 11 | type = "xtcp" 12 | serverName = "" 13 | secretKey = "" 14 | bindAddr = "127.0.0.1" 15 | bindPort = 6000 -------------------------------------------------------------------------------- /app/src/main/assets/frps.toml: -------------------------------------------------------------------------------- 1 | bindPort = 7000 -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/AboutActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | import android.os.Bundle 4 | import androidx.activity.ComponentActivity 5 | import androidx.activity.compose.setContent 6 | import androidx.activity.enableEdgeToEdge 7 | import androidx.compose.foundation.gestures.Orientation 8 | import androidx.compose.foundation.gestures.rememberScrollableState 9 | import androidx.compose.foundation.gestures.scrollable 10 | import androidx.compose.foundation.layout.Arrangement 11 | import androidx.compose.foundation.layout.Box 12 | import androidx.compose.foundation.layout.Column 13 | import androidx.compose.foundation.layout.padding 14 | import androidx.compose.foundation.rememberScrollState 15 | import androidx.compose.foundation.verticalScroll 16 | import androidx.compose.material3.ExperimentalMaterial3Api 17 | import androidx.compose.material3.MaterialTheme 18 | import androidx.compose.material3.Scaffold 19 | import androidx.compose.material3.Text 20 | import androidx.compose.material3.TopAppBar 21 | import androidx.compose.runtime.Composable 22 | import androidx.compose.ui.Modifier 23 | import androidx.compose.ui.platform.LocalUriHandler 24 | import androidx.compose.ui.text.LinkAnnotation 25 | import androidx.compose.ui.text.SpanStyle 26 | import androidx.compose.ui.text.TextLinkStyles 27 | import androidx.compose.ui.text.buildAnnotatedString 28 | import androidx.compose.ui.text.withLink 29 | import androidx.compose.ui.tooling.preview.Preview 30 | import androidx.compose.ui.unit.dp 31 | import io.github.acedroidx.frp.ui.theme.FrpTheme 32 | 33 | class AboutActivity : ComponentActivity() { 34 | 35 | @OptIn(ExperimentalMaterial3Api::class) 36 | override fun onCreate(savedInstanceState: Bundle?) { 37 | super.onCreate(savedInstanceState) 38 | 39 | enableEdgeToEdge() 40 | setContent { 41 | FrpTheme { 42 | Scaffold(topBar = { 43 | TopAppBar(title = { 44 | Text("frp for Android - ${BuildConfig.VERSION_NAME}/${BuildConfig.FrpVersion}") 45 | }) 46 | }) { contentPadding -> 47 | // Screen content 48 | Box( 49 | modifier = Modifier 50 | .padding(contentPadding) 51 | .verticalScroll(rememberScrollState()) 52 | .scrollable(orientation = Orientation.Vertical, 53 | state = rememberScrollableState { delta -> 0f }) 54 | ) { 55 | MainContent() 56 | } 57 | } 58 | } 59 | } 60 | } 61 | 62 | @Preview(showBackground = true) 63 | @Composable 64 | fun MainContent() { 65 | val uriHandler = LocalUriHandler.current 66 | Column(verticalArrangement = Arrangement.spacedBy(16.dp)) { 67 | Text(buildAnnotatedString { 68 | append("Github: ") 69 | val link = LinkAnnotation.Url( 70 | "https://github.com/AceDroidX/frp-Android", 71 | TextLinkStyles(SpanStyle(color = MaterialTheme.colorScheme.primary)) 72 | ) { 73 | val url = (it as LinkAnnotation.Url).url 74 | uriHandler.openUri(url) 75 | } 76 | withLink(link) { append("https://github.com/AceDroidX/frp-Android") } 77 | }) 78 | Text(buildAnnotatedString { 79 | append("Github: ") 80 | val link = LinkAnnotation.Url( 81 | "https://github.com/fatedier/frp", 82 | TextLinkStyles(SpanStyle(color = MaterialTheme.colorScheme.primary)) 83 | ) { 84 | val url = (it as LinkAnnotation.Url).url 85 | uriHandler.openUri(url) 86 | } 87 | withLink(link) { append("https://github.com/fatedier/frp") } 88 | }) 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/AutoStartBroadReceiver.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | import android.content.BroadcastReceiver 4 | import android.content.Context 5 | import android.content.Intent 6 | import android.os.Build 7 | import androidx.appcompat.app.AppCompatActivity 8 | 9 | class AutoStartBroadReceiver : BroadcastReceiver() { 10 | private val ACTION = "android.intent.action.BOOT_COMPLETED" 11 | override fun onReceive(context: Context, intent: Intent) { 12 | //开机启动 13 | val editor = context.getSharedPreferences("data", AppCompatActivity.MODE_PRIVATE) 14 | val auto_start = editor.getBoolean(PreferencesKey.AUTO_START, false) 15 | if (ACTION == intent.action && auto_start) { 16 | val frpcConfigSet = editor.getStringSet(PreferencesKey.AUTO_START_FRPC_LIST, emptySet()) 17 | val frpsConfigSet = editor.getStringSet(PreferencesKey.AUTO_START_FRPS_LIST, emptySet()) 18 | val frpcConfigList = frpcConfigSet?.map { FrpConfig(FrpType.FRPC, it) } 19 | val frpsConfigList = frpsConfigSet?.map { FrpConfig(FrpType.FRPS, it) } 20 | val configList = (frpsConfigList ?: emptyList()) + (frpcConfigList ?: emptyList()) 21 | if (configList.isEmpty()) return 22 | //开机启动 23 | val mainIntent = Intent(context, ShellService::class.java) 24 | mainIntent.setAction(ShellServiceAction.START) 25 | mainIntent.putParcelableArrayListExtra(IntentExtraKey.FrpConfig, ArrayList(configList)) 26 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 27 | context.startForegroundService(mainIntent) 28 | } else { 29 | context.startService(mainIntent) 30 | } 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/ConfigActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | import android.content.SharedPreferences 4 | import android.os.Build 5 | import android.os.Bundle 6 | import android.util.Log 7 | import android.widget.Toast 8 | import androidx.activity.ComponentActivity 9 | import androidx.activity.compose.setContent 10 | import androidx.activity.enableEdgeToEdge 11 | import androidx.compose.foundation.gestures.Orientation 12 | import androidx.compose.foundation.gestures.rememberScrollableState 13 | import androidx.compose.foundation.gestures.scrollable 14 | import androidx.compose.foundation.layout.Arrangement 15 | import androidx.compose.foundation.layout.Box 16 | import androidx.compose.foundation.layout.Column 17 | import androidx.compose.foundation.layout.Row 18 | import androidx.compose.foundation.layout.fillMaxWidth 19 | import androidx.compose.foundation.layout.padding 20 | import androidx.compose.foundation.rememberScrollState 21 | import androidx.compose.foundation.verticalScroll 22 | import androidx.compose.material3.AlertDialog 23 | import androidx.compose.material3.Button 24 | import androidx.compose.material3.ExperimentalMaterial3Api 25 | import androidx.compose.material3.Icon 26 | import androidx.compose.material3.MaterialTheme 27 | import androidx.compose.material3.Scaffold 28 | import androidx.compose.material3.Switch 29 | import androidx.compose.material3.Text 30 | import androidx.compose.material3.TextButton 31 | import androidx.compose.material3.TextField 32 | import androidx.compose.material3.TopAppBar 33 | import androidx.compose.runtime.Composable 34 | import androidx.compose.runtime.getValue 35 | import androidx.compose.runtime.mutableStateOf 36 | import androidx.compose.runtime.remember 37 | import androidx.compose.runtime.setValue 38 | import androidx.compose.ui.Alignment 39 | import androidx.compose.ui.Modifier 40 | import androidx.compose.ui.res.painterResource 41 | import androidx.compose.ui.res.stringResource 42 | import androidx.compose.ui.text.font.FontFamily 43 | import androidx.compose.ui.tooling.preview.Preview 44 | import androidx.compose.ui.unit.dp 45 | import androidx.lifecycle.compose.collectAsStateWithLifecycle 46 | import io.github.acedroidx.frp.ui.theme.FrpTheme 47 | import kotlinx.coroutines.flow.MutableStateFlow 48 | import java.io.File 49 | 50 | class ConfigActivity : ComponentActivity() { 51 | private val configEditText = MutableStateFlow("") 52 | private val isAutoStart = MutableStateFlow(false) 53 | private lateinit var configFile: File 54 | private lateinit var autoStartPreferencesKey: String 55 | private lateinit var preferences: SharedPreferences 56 | 57 | @OptIn(ExperimentalMaterial3Api::class) 58 | override fun onCreate(savedInstanceState: Bundle?) { 59 | super.onCreate(savedInstanceState) 60 | 61 | val frpConfig = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { 62 | intent?.extras?.getParcelable(IntentExtraKey.FrpConfig, FrpConfig::class.java) 63 | } else { 64 | @Suppress("DEPRECATION") intent?.extras?.getParcelable(IntentExtraKey.FrpConfig) 65 | } 66 | if (frpConfig == null) { 67 | Log.e("adx", "frp config is null") 68 | Toast.makeText(this, "frp config is null", Toast.LENGTH_SHORT).show() 69 | setResult(RESULT_CANCELED) 70 | finish() 71 | return 72 | } 73 | configFile = frpConfig.getFile(this) 74 | autoStartPreferencesKey = frpConfig.type.getAutoStartPreferencesKey() 75 | preferences = getSharedPreferences("data", MODE_PRIVATE) 76 | readConfig() 77 | readIsAutoStart() 78 | 79 | enableEdgeToEdge() 80 | setContent { 81 | FrpTheme { 82 | Scaffold(topBar = { 83 | TopAppBar(title = { 84 | Text("frp for Android - ${BuildConfig.VERSION_NAME}/${BuildConfig.FrpVersion}") 85 | }) 86 | }) { contentPadding -> 87 | // Screen content 88 | Box( 89 | modifier = Modifier 90 | .padding(contentPadding) 91 | .verticalScroll(rememberScrollState()) 92 | .scrollable(orientation = Orientation.Vertical, 93 | state = rememberScrollableState { delta -> 0f }) 94 | ) { 95 | MainContent() 96 | } 97 | } 98 | } 99 | } 100 | } 101 | 102 | @Preview(showBackground = true) 103 | @Composable 104 | fun MainContent() { 105 | val openDialog = remember { mutableStateOf(false) } 106 | Column( 107 | modifier = Modifier 108 | .fillMaxWidth() 109 | .padding(12.dp) 110 | ) { 111 | Row( 112 | verticalAlignment = Alignment.CenterVertically, 113 | horizontalArrangement = Arrangement.spacedBy(16.dp) 114 | ) { 115 | Button(onClick = { saveConfig();closeActivity() }) { 116 | Text(stringResource(R.string.saveConfigButton)) 117 | } 118 | Button(onClick = { closeActivity() }) { 119 | Text(stringResource(R.string.dontSaveConfigButton)) 120 | } 121 | Button(onClick = { openDialog.value = true }) { 122 | Text(stringResource(R.string.rename)) 123 | } 124 | } 125 | Row( 126 | verticalAlignment = Alignment.CenterVertically, 127 | horizontalArrangement = Arrangement.spacedBy(16.dp) 128 | ) { 129 | Text(stringResource(R.string.auto_start_switch)) 130 | Switch(checked = isAutoStart.collectAsStateWithLifecycle(false).value, 131 | onCheckedChange = { setAutoStart(it) }) 132 | } 133 | TextField( 134 | configEditText.collectAsStateWithLifecycle("").value, 135 | onValueChange = { configEditText.value = it }, 136 | textStyle = MaterialTheme.typography.bodyMedium.merge(fontFamily = FontFamily.Monospace) 137 | ) 138 | } 139 | if (openDialog.value) { 140 | RenameDialog(configFile.name.removeSuffix(".toml")) { openDialog.value = false } 141 | } 142 | } 143 | 144 | @Composable 145 | fun RenameDialog( 146 | originName: String, 147 | onClose: () -> Unit, 148 | ) { 149 | var text by remember { mutableStateOf(originName) } 150 | AlertDialog(title = { 151 | Text(stringResource(R.string.rename)) 152 | }, icon = { 153 | Icon( 154 | painterResource(id = R.drawable.ic_rename), contentDescription = "Rename Icon" 155 | ) 156 | }, text = { 157 | TextField(text, onValueChange = { text = it }) 158 | }, onDismissRequest = { 159 | onClose() 160 | }, confirmButton = { 161 | TextButton(onClick = { 162 | renameConfig("$text.toml") 163 | onClose() 164 | }) { 165 | Text(stringResource(R.string.confirm)) 166 | } 167 | }, dismissButton = { 168 | TextButton(onClick = { 169 | onClose() 170 | }) { 171 | Text(stringResource(R.string.dismiss)) 172 | } 173 | }) 174 | } 175 | 176 | fun readConfig() { 177 | if (configFile.exists()) { 178 | val mReader = configFile.bufferedReader() 179 | val mRespBuff = StringBuffer() 180 | val buff = CharArray(1024) 181 | var ch = 0 182 | while (mReader.read(buff).also { ch = it } != -1) { 183 | mRespBuff.append(buff, 0, ch) 184 | } 185 | mReader.close() 186 | configEditText.value = mRespBuff.toString() 187 | } else { 188 | Log.e("adx", "config file is not exist") 189 | Toast.makeText(this, "config file is not exist", Toast.LENGTH_SHORT).show() 190 | } 191 | } 192 | 193 | fun saveConfig() { 194 | configFile.writeText(configEditText.value) 195 | } 196 | 197 | fun renameConfig(newName: String) { 198 | val originAutoStart = isAutoStart.value 199 | setAutoStart(false) 200 | val newFile = File(configFile.parent, newName) 201 | configFile.renameTo(newFile) 202 | configFile = newFile 203 | setAutoStart(originAutoStart) 204 | } 205 | 206 | fun readIsAutoStart() { 207 | isAutoStart.value = 208 | preferences.getStringSet(autoStartPreferencesKey, emptySet())?.contains(configFile.name) 209 | ?: false 210 | } 211 | 212 | fun setAutoStart(value: Boolean) { 213 | val editor = preferences.edit() 214 | val set = preferences.getStringSet(autoStartPreferencesKey, emptySet())?.toMutableSet() 215 | if (value) { 216 | set?.add(configFile.name) 217 | } else { 218 | set?.remove(configFile.name) 219 | } 220 | editor.putStringSet(autoStartPreferencesKey, set) 221 | editor.apply() 222 | isAutoStart.value = value 223 | } 224 | 225 | fun closeActivity() { 226 | setResult(RESULT_OK) 227 | finish() 228 | } 229 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/FrpConfig.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | import android.content.Context 4 | import android.os.Parcelable 5 | import kotlinx.parcelize.Parcelize 6 | import java.io.File 7 | 8 | @Parcelize 9 | data class FrpConfig( 10 | val type: FrpType, 11 | val fileName: String, 12 | ) : Parcelable { 13 | override fun toString(): String { 14 | return "[$type]$fileName" 15 | } 16 | 17 | fun getDir(context: Context): File { 18 | return this.type.getDir(context) 19 | } 20 | 21 | fun getFile(context: Context): File { 22 | return File(this.getDir(context), this.fileName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/FrpType.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | import android.content.Context 4 | import java.io.File 5 | 6 | enum class FrpType(val typeName: String) { 7 | FRPC("frpc"), FRPS("frps"); 8 | 9 | fun getDir(context: Context): File { 10 | return File(context.filesDir, this.typeName) 11 | } 12 | 13 | fun getLibName(): String { 14 | return when (this) { 15 | FRPC -> BuildConfig.FrpcFileName 16 | FRPS -> BuildConfig.FrpsFileName 17 | } 18 | } 19 | 20 | fun getAutoStartPreferencesKey(): String { 21 | return when (this) { 22 | FRPC -> PreferencesKey.AUTO_START_FRPC_LIST 23 | FRPS -> PreferencesKey.AUTO_START_FRPS_LIST 24 | } 25 | } 26 | 27 | fun getConfigAssetsName(): String { 28 | return when (this) { 29 | FRPC -> BuildConfig.FrpcConfigFileName 30 | FRPS -> BuildConfig.FrpsConfigFileName 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/IntentExtraKey.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | object IntentExtraKey { 4 | const val FrpConfig = "FrpConfig" 5 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | import android.Manifest 4 | import android.app.NotificationChannel 5 | import android.app.NotificationManager 6 | import android.content.ComponentName 7 | import android.content.Intent 8 | import android.content.ServiceConnection 9 | import android.content.SharedPreferences 10 | import android.content.pm.PackageManager 11 | import android.os.Build 12 | import android.os.Bundle 13 | import android.os.IBinder 14 | import android.util.Log 15 | import android.widget.Toast 16 | import androidx.activity.ComponentActivity 17 | import androidx.activity.compose.setContent 18 | import androidx.activity.enableEdgeToEdge 19 | import androidx.activity.result.contract.ActivityResultContracts 20 | import androidx.compose.foundation.gestures.Orientation 21 | import androidx.compose.foundation.gestures.rememberScrollableState 22 | import androidx.compose.foundation.gestures.scrollable 23 | import androidx.compose.foundation.layout.Arrangement 24 | import androidx.compose.foundation.layout.Box 25 | import androidx.compose.foundation.layout.Column 26 | import androidx.compose.foundation.layout.Row 27 | import androidx.compose.foundation.layout.Spacer 28 | import androidx.compose.foundation.layout.fillMaxWidth 29 | import androidx.compose.foundation.layout.padding 30 | import androidx.compose.foundation.layout.size 31 | import androidx.compose.foundation.rememberScrollState 32 | import androidx.compose.foundation.shape.RoundedCornerShape 33 | import androidx.compose.foundation.text.selection.SelectionContainer 34 | import androidx.compose.foundation.verticalScroll 35 | import androidx.compose.material3.BasicAlertDialog 36 | import androidx.compose.material3.Button 37 | import androidx.compose.material3.Card 38 | import androidx.compose.material3.ExperimentalMaterial3Api 39 | import androidx.compose.material3.HorizontalDivider 40 | import androidx.compose.material3.Icon 41 | import androidx.compose.material3.IconButton 42 | import androidx.compose.material3.MaterialTheme 43 | import androidx.compose.material3.Scaffold 44 | import androidx.compose.material3.Switch 45 | import androidx.compose.material3.Text 46 | import androidx.compose.material3.TopAppBar 47 | import androidx.compose.runtime.Composable 48 | import androidx.compose.runtime.getValue 49 | import androidx.compose.runtime.mutableStateOf 50 | import androidx.compose.runtime.remember 51 | import androidx.compose.ui.Alignment 52 | import androidx.compose.ui.Modifier 53 | import androidx.compose.ui.platform.LocalClipboardManager 54 | import androidx.compose.ui.res.painterResource 55 | import androidx.compose.ui.res.stringResource 56 | import androidx.compose.ui.text.AnnotatedString 57 | import androidx.compose.ui.text.font.FontFamily 58 | import androidx.compose.ui.text.style.TextAlign 59 | import androidx.compose.ui.tooling.preview.Preview 60 | import androidx.compose.ui.unit.dp 61 | import androidx.core.content.ContextCompat 62 | import androidx.lifecycle.compose.collectAsStateWithLifecycle 63 | import androidx.lifecycle.lifecycleScope 64 | import io.github.acedroidx.frp.ui.theme.FrpTheme 65 | import kotlinx.coroutines.flow.MutableStateFlow 66 | import kotlinx.coroutines.launch 67 | import java.io.File 68 | import java.text.SimpleDateFormat 69 | import java.util.Date 70 | import java.util.Locale 71 | 72 | 73 | class MainActivity : ComponentActivity() { 74 | private val isStartup = MutableStateFlow(false) 75 | private val logText = MutableStateFlow("") 76 | private val frpcConfigList = MutableStateFlow>(emptyList()) 77 | private val frpsConfigList = MutableStateFlow>(emptyList()) 78 | private val runningConfigList = MutableStateFlow>(emptyList()) 79 | 80 | private lateinit var preferences: SharedPreferences 81 | 82 | private lateinit var mService: ShellService 83 | private var mBound: Boolean = false 84 | 85 | /** Defines callbacks for service binding, passed to bindService() */ 86 | private val connection = object : ServiceConnection { 87 | 88 | override fun onServiceConnected(className: ComponentName, service: IBinder) { 89 | // We've bound to LocalService, cast the IBinder and get LocalService instance 90 | val binder = service as ShellService.LocalBinder 91 | mService = binder.getService() 92 | mBound = true 93 | 94 | mService.lifecycleScope.launch { 95 | mService.processThreads.collect { processThreads -> 96 | runningConfigList.value = processThreads.keys.toList() 97 | } 98 | } 99 | mService.lifecycleScope.launch { 100 | mService.logText.collect { 101 | logText.value = it 102 | } 103 | } 104 | } 105 | 106 | override fun onServiceDisconnected(arg0: ComponentName) { 107 | mBound = false 108 | } 109 | } 110 | 111 | private val configActivityLauncher = 112 | registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { activityResult -> 113 | updateConfigList() 114 | } 115 | 116 | @OptIn(ExperimentalMaterial3Api::class) 117 | override fun onCreate(savedInstanceState: Bundle?) { 118 | super.onCreate(savedInstanceState) 119 | 120 | preferences = getSharedPreferences("data", MODE_PRIVATE) 121 | isStartup.value = preferences.getBoolean(PreferencesKey.AUTO_START, false) 122 | 123 | checkConfig() 124 | updateConfigList() 125 | checkNotificationPermission() 126 | createBGNotificationChannel() 127 | 128 | enableEdgeToEdge() 129 | setContent { 130 | FrpTheme { 131 | Scaffold(topBar = { 132 | TopAppBar(title = { 133 | Text("frp for Android - ${BuildConfig.VERSION_NAME}/${BuildConfig.FrpVersion}") 134 | }) 135 | }) { contentPadding -> 136 | // Screen content 137 | Box( 138 | modifier = Modifier 139 | .padding(contentPadding) 140 | .verticalScroll(rememberScrollState()) 141 | .scrollable(orientation = Orientation.Vertical, 142 | state = rememberScrollableState { delta -> 0f }) 143 | ) { 144 | MainContent() 145 | } 146 | } 147 | } 148 | } 149 | 150 | if (!mBound) { 151 | val intent = Intent(this, ShellService::class.java) 152 | bindService(intent, connection, BIND_AUTO_CREATE) 153 | } 154 | } 155 | 156 | @Preview(showBackground = true) 157 | @Composable 158 | fun MainContent() { 159 | val frpcConfigList by frpcConfigList.collectAsStateWithLifecycle(emptyList()) 160 | val frpsConfigList by frpsConfigList.collectAsStateWithLifecycle(emptyList()) 161 | val clipboardManager = LocalClipboardManager.current 162 | val logText by logText.collectAsStateWithLifecycle("") 163 | val openDialog = remember { mutableStateOf(false) } 164 | Column( 165 | modifier = Modifier 166 | .fillMaxWidth() 167 | .padding(12.dp) 168 | ) { 169 | if (frpcConfigList.isEmpty() && frpsConfigList.isEmpty()) { 170 | Text( 171 | stringResource(R.string.no_config), 172 | modifier = Modifier.fillMaxWidth(), 173 | textAlign = TextAlign.Center 174 | ) 175 | } 176 | if (frpcConfigList.isNotEmpty()) { 177 | Text("frpc", style = MaterialTheme.typography.titleLarge) 178 | } 179 | frpcConfigList.forEach { config -> FrpConfigItem(config) } 180 | if (frpsConfigList.isNotEmpty()) { 181 | Text("frps", style = MaterialTheme.typography.titleLarge) 182 | } 183 | frpsConfigList.forEach { config -> FrpConfigItem(config) } 184 | HorizontalDivider(thickness = 2.dp, modifier = Modifier.padding(vertical = 16.dp)) 185 | Row( 186 | verticalAlignment = Alignment.CenterVertically, 187 | horizontalArrangement = Arrangement.SpaceBetween, 188 | modifier = Modifier.fillMaxWidth() 189 | ) { 190 | Text(stringResource(R.string.auto_start_switch)) 191 | Switch(checked = isStartup.collectAsStateWithLifecycle(false).value, 192 | onCheckedChange = { 193 | val editor = preferences.edit() 194 | editor.putBoolean(PreferencesKey.AUTO_START, it) 195 | editor.apply() 196 | isStartup.value = it 197 | }) 198 | } 199 | Row( 200 | verticalAlignment = Alignment.CenterVertically, 201 | horizontalArrangement = Arrangement.SpaceAround, 202 | modifier = Modifier.fillMaxWidth() 203 | ) { 204 | Button(onClick = { 205 | openDialog.value = true 206 | }) { Text(stringResource(R.string.addConfigButton)) } 207 | Button(onClick = { 208 | startActivity(Intent(this@MainActivity, AboutActivity::class.java)) 209 | }) { Text(stringResource(R.string.aboutButton)) } 210 | } 211 | HorizontalDivider(thickness = 2.dp, modifier = Modifier.padding(vertical = 16.dp)) 212 | Row( 213 | verticalAlignment = Alignment.CenterVertically, 214 | horizontalArrangement = Arrangement.spacedBy(16.dp) 215 | ) { 216 | Text( 217 | stringResource(R.string.frp_log), style = MaterialTheme.typography.titleLarge 218 | ) 219 | Button(onClick = { mService.clearLog() }) { Text(stringResource(R.string.deleteButton)) } 220 | Button(onClick = { 221 | clipboardManager.setText(AnnotatedString(logText)) 222 | // Only show a toast for Android 12 and lower. 223 | if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.S_V2) Toast.makeText( 224 | this@MainActivity, getString(R.string.copied), Toast.LENGTH_SHORT 225 | ).show() 226 | }) { Text(stringResource(R.string.copy)) } 227 | } 228 | SelectionContainer { 229 | Text( 230 | if (logText == "") stringResource(R.string.no_log) else logText, 231 | style = MaterialTheme.typography.bodyMedium.merge(fontFamily = FontFamily.Monospace), 232 | modifier = Modifier.padding(vertical = 12.dp) 233 | ) 234 | } 235 | } 236 | if (openDialog.value) { 237 | CreateConfigDialog { openDialog.value = false } 238 | } 239 | } 240 | 241 | @Composable 242 | fun FrpConfigItem(config: FrpConfig) { 243 | val runningConfigList by runningConfigList.collectAsStateWithLifecycle(emptyList()) 244 | val isRunning = runningConfigList.contains(config) 245 | Row( 246 | verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxWidth() 247 | ) { 248 | Text(config.fileName) 249 | Spacer(Modifier.weight(1f)) 250 | IconButton( 251 | onClick = { startConfigActivity(config) }, 252 | enabled = !isRunning, 253 | modifier = Modifier.size(24.dp) 254 | ) { 255 | Icon( 256 | painter = painterResource(id = R.drawable.ic_pencil_24dp), 257 | contentDescription = "编辑" 258 | ) 259 | } 260 | IconButton( 261 | onClick = { deleteConfig(config) }, 262 | enabled = !isRunning, 263 | ) { 264 | Icon( 265 | painter = painterResource(id = R.drawable.ic_baseline_delete_24), 266 | contentDescription = "删除" 267 | ) 268 | } 269 | Switch(checked = isRunning, onCheckedChange = { 270 | if (it) (startShell(config)) else (stopShell(config)) 271 | }) 272 | } 273 | } 274 | 275 | @OptIn(ExperimentalMaterial3Api::class) 276 | @Composable 277 | @Preview(showBackground = true) 278 | fun CreateConfigDialog(onClose: () -> Unit = {}) { 279 | BasicAlertDialog(onDismissRequest = { onClose() }) { 280 | Card( 281 | modifier = Modifier 282 | .fillMaxWidth() 283 | .padding(16.dp), 284 | shape = RoundedCornerShape(16.dp), 285 | ) { 286 | Column( 287 | modifier = Modifier.padding(16.dp), 288 | verticalArrangement = Arrangement.spacedBy(16.dp) 289 | ) { 290 | Text( 291 | stringResource(R.string.create_frp_select), 292 | modifier = Modifier.fillMaxWidth(), 293 | textAlign = TextAlign.Center, 294 | style = MaterialTheme.typography.titleLarge 295 | ) 296 | Row( 297 | horizontalArrangement = Arrangement.SpaceAround, 298 | modifier = Modifier.fillMaxWidth() 299 | ) { 300 | Button(onClick = { startConfigActivity(FrpType.FRPC);onClose() }) { 301 | Text("frpc") 302 | } 303 | Button(onClick = { startConfigActivity(FrpType.FRPS);onClose() }) { 304 | Text("frps") 305 | } 306 | } 307 | } 308 | } 309 | } 310 | } 311 | 312 | override fun onDestroy() { 313 | super.onDestroy() 314 | if (mBound) { 315 | unbindService(connection) 316 | mBound = false 317 | } 318 | } 319 | 320 | fun checkConfig() { 321 | val frpcDir = FrpType.FRPC.getDir(this) 322 | if (frpcDir.exists() && !frpcDir.isDirectory) { 323 | frpcDir.delete() 324 | } 325 | if (!frpcDir.exists()) frpcDir.mkdirs() 326 | val frpsDir = FrpType.FRPS.getDir(this) 327 | if (frpsDir.exists() && !frpsDir.isDirectory) { 328 | frpsDir.delete() 329 | } 330 | if (!frpsDir.exists()) frpsDir.mkdirs() 331 | // v1.1旧版本配置迁移 332 | // 遍历文件夹内的所有文件 333 | this.filesDir.listFiles()?.forEach { file -> 334 | if (file.isFile && file.name.endsWith(".toml")) { 335 | // 构建目标文件路径 336 | val destination = File(frpcDir, file.name) 337 | // 移动文件 338 | if (file.renameTo(destination)) { 339 | Log.d("adx", "Moved: ${file.name} to ${destination.absolutePath}") 340 | } else { 341 | Log.e("adx", "Failed to move: ${file.name}") 342 | } 343 | } 344 | } 345 | } 346 | 347 | private fun deleteConfig(config: FrpConfig) { 348 | val file = config.getFile(this) 349 | if (file.exists()) { 350 | file.delete() 351 | } 352 | updateConfigList() 353 | } 354 | 355 | private fun startConfigActivity(type: FrpType) { 356 | val currentDate = Date() 357 | val formatter = SimpleDateFormat("yyyy-MM-dd HH.mm.ss", Locale.getDefault()) 358 | val formattedDateTime = formatter.format(currentDate) 359 | val fileName = "$formattedDateTime.toml" 360 | val file = File(type.getDir(this), fileName) 361 | file.writeBytes(resources.assets.open(type.getConfigAssetsName()).readBytes()) 362 | val config = FrpConfig(type, fileName) 363 | startConfigActivity(config) 364 | } 365 | 366 | private fun startConfigActivity(config: FrpConfig) { 367 | val intent = Intent(this, ConfigActivity::class.java) 368 | intent.putExtra(IntentExtraKey.FrpConfig, config) 369 | configActivityLauncher.launch(intent) 370 | } 371 | 372 | private fun startShell(config: FrpConfig) { 373 | val intent = Intent(this, ShellService::class.java) 374 | intent.setAction(ShellServiceAction.START) 375 | intent.putExtra(IntentExtraKey.FrpConfig, arrayListOf(config)) 376 | startService(intent) 377 | } 378 | 379 | private fun stopShell(config: FrpConfig) { 380 | val intent = Intent(this, ShellService::class.java) 381 | intent.setAction(ShellServiceAction.STOP) 382 | intent.putExtra(IntentExtraKey.FrpConfig, arrayListOf(config)) 383 | startService(intent) 384 | } 385 | 386 | private fun checkNotificationPermission() { 387 | val requestPermissionLauncher = registerForActivityResult( 388 | ActivityResultContracts.RequestPermission() 389 | ) { isGranted: Boolean -> 390 | if (isGranted) { 391 | // Permission is granted. Continue the action or workflow in your 392 | // app. 393 | } else { 394 | // Explain to the user that the feature is unavailable because the 395 | // feature requires a permission that the user has denied. At the 396 | // same time, respect the user's decision. Don't link to system 397 | // settings in an effort to convince the user to change their 398 | // decision. 399 | } 400 | } 401 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { 402 | if (ContextCompat.checkSelfPermission( 403 | this, Manifest.permission.POST_NOTIFICATIONS 404 | ) != PackageManager.PERMISSION_GRANTED 405 | ) { 406 | requestPermissionLauncher.launch(Manifest.permission.POST_NOTIFICATIONS) 407 | } 408 | } 409 | } 410 | 411 | private fun createBGNotificationChannel() { 412 | // Create the NotificationChannel, but only on API 26+ because 413 | // the NotificationChannel class is new and not in the support library 414 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 415 | val name = getString(R.string.notification_channel_name) 416 | val descriptionText = getString(R.string.notification_channel_desc) 417 | val importance = NotificationManager.IMPORTANCE_MIN 418 | val channel = NotificationChannel("shell_bg", name, importance).apply { 419 | description = descriptionText 420 | } 421 | // Register the channel with the system 422 | val notificationManager: NotificationManager = 423 | getSystemService(NOTIFICATION_SERVICE) as NotificationManager 424 | notificationManager.createNotificationChannel(channel) 425 | } 426 | } 427 | 428 | private fun updateConfigList() { 429 | frpcConfigList.value = (FrpType.FRPC.getDir(this).list()?.toList() ?: listOf()).map { 430 | FrpConfig(FrpType.FRPC, it) 431 | } 432 | frpsConfigList.value = (FrpType.FRPS.getDir(this).list()?.toList() ?: listOf()).map { 433 | FrpConfig(FrpType.FRPS, it) 434 | } 435 | 436 | // 检查自启动列表中是否含有已经删除的配置 437 | val frpcAutoStartList = 438 | preferences.getStringSet(PreferencesKey.AUTO_START_FRPC_LIST, emptySet())?.filter { 439 | frpcConfigList.value.contains( 440 | FrpConfig(FrpType.FRPC, it) 441 | ) 442 | } 443 | with(preferences.edit()) { 444 | putStringSet(PreferencesKey.AUTO_START_FRPC_LIST, frpcAutoStartList?.toSet()) 445 | apply() 446 | } 447 | val frpsAutoStartList = 448 | preferences.getStringSet(PreferencesKey.AUTO_START_FRPS_LIST, emptySet())?.filter { 449 | frpsConfigList.value.contains( 450 | FrpConfig(FrpType.FRPS, it) 451 | ) 452 | } 453 | with(preferences.edit()) { 454 | putStringSet(PreferencesKey.AUTO_START_FRPS_LIST, frpsAutoStartList?.toSet()) 455 | apply() 456 | } 457 | } 458 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/PreferencesKey.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | object PreferencesKey { 4 | const val AUTO_START = "auto_start" 5 | const val AUTO_START_FRPC_LIST = "auto_start_frpc_list" 6 | const val AUTO_START_FRPS_LIST = "auto_start_frps_list" 7 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/ShellService.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | import android.app.Notification 4 | import android.app.PendingIntent 5 | import android.content.Intent 6 | import android.content.pm.PackageManager 7 | import android.os.Binder 8 | import android.os.Build 9 | import android.os.IBinder 10 | import android.util.Log 11 | import android.widget.Toast 12 | import androidx.core.app.NotificationCompat 13 | import androidx.lifecycle.LifecycleService 14 | import kotlinx.coroutines.flow.MutableStateFlow 15 | import kotlinx.coroutines.flow.StateFlow 16 | import kotlinx.coroutines.flow.asStateFlow 17 | import kotlinx.coroutines.flow.update 18 | import java.io.File 19 | import java.util.Random 20 | 21 | 22 | class ShellService : LifecycleService() { 23 | private val _processThreads = MutableStateFlow(mutableMapOf()) 24 | val processThreads = _processThreads.asStateFlow() 25 | 26 | private val _logText = MutableStateFlow("") 27 | val logText: StateFlow = _logText 28 | 29 | fun clearLog() { 30 | _logText.value = "" 31 | } 32 | 33 | // Binder given to clients 34 | private val binder = LocalBinder() 35 | 36 | // Random number generator 37 | private val mGenerator = Random() 38 | 39 | /** method for clients */ 40 | val randomNumber: Int 41 | get() = mGenerator.nextInt(100) 42 | 43 | /** 44 | * Class used for the client Binder. Because we know this service always 45 | * runs in the same process as its clients, we don't need to deal with IPC. 46 | */ 47 | inner class LocalBinder : Binder(), IBinder { 48 | // Return this instance of LocalService so clients can call public methods 49 | fun getService(): ShellService = this@ShellService 50 | } 51 | 52 | override fun onBind(intent: Intent): IBinder { 53 | super.onBind(intent) 54 | return binder 55 | } 56 | 57 | override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { 58 | super.onStartCommand(intent, flags, startId) 59 | val frpConfig: ArrayList? = 60 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { 61 | intent?.extras?.getParcelableArrayList( 62 | IntentExtraKey.FrpConfig, FrpConfig::class.java 63 | ) 64 | } else { 65 | @Suppress("DEPRECATION") intent?.extras?.getParcelableArrayList(IntentExtraKey.FrpConfig) 66 | } 67 | if (frpConfig == null) { 68 | Log.e("adx", "frpConfig is null") 69 | Toast.makeText(this, "frpConfig is null", Toast.LENGTH_SHORT).show() 70 | return START_NOT_STICKY 71 | } 72 | when (intent?.action) { 73 | ShellServiceAction.START -> { 74 | for (config in frpConfig) { 75 | startFrp(config) 76 | } 77 | Toast.makeText(this, getString(R.string.service_start_toast), Toast.LENGTH_SHORT) 78 | .show() 79 | startForeground(1, showNotification()) 80 | } 81 | 82 | ShellServiceAction.STOP -> { 83 | for (config in frpConfig) { 84 | stopFrp(config) 85 | } 86 | startForeground(1, showNotification()) 87 | if (_processThreads.value.isEmpty()) { 88 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 89 | stopForeground(STOP_FOREGROUND_REMOVE) 90 | } else { 91 | @Suppress("DEPRECATION") stopForeground(true) 92 | } 93 | stopSelf() 94 | Toast.makeText(this, getString(R.string.service_stop_toast), Toast.LENGTH_SHORT) 95 | .show() 96 | } 97 | } 98 | } 99 | return START_NOT_STICKY 100 | } 101 | 102 | private fun startFrp(config: FrpConfig) { 103 | Log.d("adx", "start config is $config") 104 | val dir = config.getDir(this) 105 | val file = config.getFile(this) 106 | if (!file.exists()) { 107 | Log.w("adx", "file is not exist,service won't start") 108 | Toast.makeText(this, "file is not exist,service won't start", Toast.LENGTH_SHORT).show() 109 | return 110 | } 111 | if (_processThreads.value.contains(config)) { 112 | Log.w("adx", "frp is already running") 113 | Toast.makeText(this, "frp is already running", Toast.LENGTH_SHORT).show() 114 | return 115 | } 116 | val ainfo = packageManager.getApplicationInfo( 117 | packageName, PackageManager.GET_SHARED_LIBRARY_FILES 118 | ) 119 | val commandList = 120 | listOf("${ainfo.nativeLibraryDir}/${config.type.getLibName()}", "-c", config.fileName) 121 | Log.d("adx", "${dir}\n${commandList}") 122 | try { 123 | val thread = runCommand(commandList, dir) 124 | _processThreads.update { it.toMutableMap().apply { put(config, thread) } } 125 | } catch (e: Exception) { 126 | Log.e("adx", e.stackTraceToString()) 127 | Toast.makeText(this, e.message, Toast.LENGTH_LONG).show() 128 | stopSelf() 129 | } 130 | } 131 | 132 | private fun stopFrp(config: FrpConfig) { 133 | val thread = _processThreads.value.get(config) 134 | // thread?.interrupt() 135 | thread?.stopProcess() 136 | _processThreads.update { 137 | it.toMutableMap().apply { remove(config) } 138 | } 139 | } 140 | 141 | override fun onDestroy() { 142 | super.onDestroy() 143 | if (!_processThreads.value.isEmpty()) { 144 | _processThreads.value.forEach { 145 | // it.value.interrupt() 146 | it.value.stopProcess() 147 | } 148 | _processThreads.update { it.clear();it } 149 | } 150 | } 151 | 152 | private fun runCommand(command: List, dir: File): ShellThread { 153 | val process_thread = ShellThread(command, dir) { _logText.value += it + "\n" } 154 | process_thread.start() 155 | return process_thread; 156 | } 157 | 158 | private fun showNotification(): Notification { 159 | val pendingIntent: PendingIntent = 160 | Intent(this, MainActivity::class.java).let { notificationIntent -> 161 | PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE) 162 | } 163 | val notification = NotificationCompat.Builder(this, "shell_bg") 164 | .setSmallIcon(R.drawable.ic_launcher_foreground) 165 | .setContentTitle(getString(R.string.frp_notification_title)).setContentText( 166 | getString( 167 | R.string.frp_notification_content, _processThreads.value.size 168 | ) 169 | ) 170 | //.setTicker("test") 171 | .setContentIntent(pendingIntent) 172 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { 173 | return notification.setForegroundServiceBehavior(Notification.FOREGROUND_SERVICE_IMMEDIATE) 174 | .build() 175 | } else { 176 | return notification.build() 177 | } 178 | } 179 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/ShellServiceAction.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | object ShellServiceAction { 4 | const val START = "io.github.acedroidx.frp.START" 5 | // const val AUTO_START = "io.github.acedroidx.frp.AUTO_START" 6 | const val STOP = "io.github.acedroidx.frp.STOP" 7 | // const val PAUSE = "io.github.acedroidx.frp.PAUSE" 8 | // const val CONTINUE = "io.github.acedroidx.frp.CONTINUE" 9 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/ShellThread.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp 2 | 3 | import android.os.Build 4 | import java.io.File 5 | import java.io.InterruptedIOException 6 | 7 | class ShellThread( 8 | val command: List, 9 | val dir: File, 10 | val envp: Map = emptyMap(), 11 | val outputCallback: (text: String) -> Unit 12 | ) : Thread() { 13 | private lateinit var process: Process 14 | 15 | override fun run() { 16 | try { 17 | val processBuilder = ProcessBuilder(command) 18 | processBuilder.directory(dir) 19 | envp.forEach { (key, value) -> 20 | processBuilder.environment()[key] = value 21 | } 22 | processBuilder.redirectErrorStream(true) // 合并错误流 23 | 24 | process = processBuilder.start() 25 | 26 | // 处理输出流 27 | process.inputStream.bufferedReader().use { reader -> 28 | try { 29 | var line: String? = null 30 | while (!isInterrupted && reader.readLine().also { line = it } != null) { 31 | line?.let { outputCallback(it) } 32 | } 33 | } catch (e: InterruptedIOException) { 34 | // 线程被中断 35 | outputCallback("Thread interrupted: ${e.message}") 36 | } 37 | } 38 | 39 | // 等待进程结束并读取退出码 40 | val exitCode = process.waitFor() 41 | outputCallback("Process exited with code: $exitCode") 42 | 43 | } catch (e: Exception) { 44 | e.printStackTrace() 45 | outputCallback("Error: ${e.javaClass.simpleName} - ${e.message}") 46 | } finally { 47 | stopProcess() 48 | } 49 | } 50 | 51 | fun stopProcess() { 52 | try { 53 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 54 | process.destroyForcibly() 55 | } else { 56 | process.destroy() 57 | } 58 | } catch (e: Exception) { 59 | e.printStackTrace() 60 | outputCallback("Error stopping process: ${e.message}") 61 | } 62 | } 63 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp.ui.theme 2 | 3 | import androidx.compose.ui.graphics.Color 4 | 5 | val Purple80 = Color(0xFFD0BCFF) 6 | val PurpleGrey80 = Color(0xFFCCC2DC) 7 | val Pink80 = Color(0xFFEFB8C8) 8 | 9 | val Purple40 = Color(0xFF6650a4) 10 | val PurpleGrey40 = Color(0xFF625b71) 11 | val Pink40 = Color(0xFF7D5260) -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/ui/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp.ui.theme 2 | 3 | import android.os.Build 4 | import androidx.compose.foundation.isSystemInDarkTheme 5 | import androidx.compose.material3.MaterialTheme 6 | import androidx.compose.material3.darkColorScheme 7 | import androidx.compose.material3.dynamicDarkColorScheme 8 | import androidx.compose.material3.dynamicLightColorScheme 9 | import androidx.compose.material3.lightColorScheme 10 | import androidx.compose.runtime.Composable 11 | import androidx.compose.ui.platform.LocalContext 12 | 13 | private val DarkColorScheme = darkColorScheme( 14 | primary = Purple80, 15 | secondary = PurpleGrey80, 16 | tertiary = Pink80 17 | ) 18 | 19 | private val LightColorScheme = lightColorScheme( 20 | primary = Purple40, 21 | secondary = PurpleGrey40, 22 | tertiary = Pink40 23 | 24 | /* Other default colors to override 25 | background = Color(0xFFFFFBFE), 26 | surface = Color(0xFFFFFBFE), 27 | onPrimary = Color.White, 28 | onSecondary = Color.White, 29 | onTertiary = Color.White, 30 | onBackground = Color(0xFF1C1B1F), 31 | onSurface = Color(0xFF1C1B1F), 32 | */ 33 | ) 34 | 35 | @Composable 36 | fun FrpTheme( 37 | darkTheme: Boolean = isSystemInDarkTheme(), 38 | // Dynamic color is available on Android 12+ 39 | dynamicColor: Boolean = true, 40 | content: @Composable () -> Unit 41 | ) { 42 | val colorScheme = when { 43 | dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { 44 | val context = LocalContext.current 45 | if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) 46 | } 47 | 48 | darkTheme -> DarkColorScheme 49 | else -> LightColorScheme 50 | } 51 | 52 | MaterialTheme( 53 | colorScheme = colorScheme, 54 | typography = Typography, 55 | content = content 56 | ) 57 | } -------------------------------------------------------------------------------- /app/src/main/java/io/github/acedroidx/frp/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | package io.github.acedroidx.frp.ui.theme 2 | 3 | import androidx.compose.material3.Typography 4 | import androidx.compose.ui.text.TextStyle 5 | import androidx.compose.ui.text.font.FontFamily 6 | import androidx.compose.ui.text.font.FontWeight 7 | import androidx.compose.ui.unit.sp 8 | 9 | // Set of Material typography styles to start with 10 | val Typography = Typography( 11 | bodyLarge = TextStyle( 12 | fontFamily = FontFamily.Default, 13 | fontWeight = FontWeight.Normal, 14 | fontSize = 16.sp, 15 | lineHeight = 24.sp, 16 | letterSpacing = 0.5.sp 17 | ) 18 | /* Other default text styles to override 19 | titleLarge = TextStyle( 20 | fontFamily = FontFamily.Default, 21 | fontWeight = FontWeight.Normal, 22 | fontSize = 22.sp, 23 | lineHeight = 28.sp, 24 | letterSpacing = 0.sp 25 | ), 26 | labelSmall = TextStyle( 27 | fontFamily = FontFamily.Default, 28 | fontWeight = FontWeight.Medium, 29 | fontSize = 11.sp, 30 | lineHeight = 16.sp, 31 | letterSpacing = 0.5.sp 32 | ) 33 | */ 34 | ) -------------------------------------------------------------------------------- /app/src/main/jniLibs/arm64-v8a/libfrpc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/jniLibs/arm64-v8a/libfrpc.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/arm64-v8a/libfrps.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/jniLibs/arm64-v8a/libfrps.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi-v7a/libfrpc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/jniLibs/armeabi-v7a/libfrpc.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi-v7a/libfrps.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/jniLibs/armeabi-v7a/libfrps.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86_64/libfrpc.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/jniLibs/x86_64/libfrpc.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86_64/libfrps.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/jniLibs/x86_64/libfrps.so -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_baseline_delete_24.xml: -------------------------------------------------------------------------------- 1 | 7 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_pencil_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_rename.xml: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AceDroidX/frp-Android/919ae1f5228cb79f807f3c064259525a51d7cf16/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/resources.properties: -------------------------------------------------------------------------------- 1 | unqualifiedResLocale=en-US -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |