├── .github ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── ISSUE_TEMPLATE.md ├── .gitignore ├── LICENSE ├── README.md ├── README_CN.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── me │ │ └── ele │ │ └── demo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── me │ │ │ └── ele │ │ │ └── trojan │ │ │ └── demo │ │ │ ├── CustomApplication.java │ │ │ ├── DemoHook.java │ │ │ ├── HttpRecordHelper.java │ │ │ ├── MainActivity.java │ │ │ ├── RecordRequestInterceptor.java │ │ │ └── upload │ │ │ └── DemoLeanCloudUploader.java │ └── res │ │ ├── color │ │ └── selector_blue.xml │ │ ├── drawable-xxhdpi │ │ ├── tab_explore.png │ │ ├── tab_explore_normal.png │ │ ├── tab_home.png │ │ ├── tab_home_normal.png │ │ ├── tab_profile.png │ │ └── tab_profile_normal.png │ │ ├── drawable │ │ ├── selector_menu_home.xml │ │ ├── selector_tab_article.xml │ │ └── selector_tab_mine.xml │ │ ├── layout │ │ ├── activity_list_view.xml │ │ ├── activity_main.xml │ │ ├── activity_recycle_view.xml │ │ ├── activity_view_pager.xml │ │ ├── activity_write_file2.xml │ │ ├── article_frag_layout.xml │ │ ├── custom_tab_item.xml │ │ ├── lib_frag_layout.xml │ │ ├── mine_frag_layout.xml │ │ └── text_item.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 │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── me │ └── ele │ └── trojan │ └── demo │ └── ExampleUnitTest.java ├── assets ├── trojan_banner.png └── trojan_license.png ├── build.gradle ├── decrypt ├── trojan_decrypt.c ├── trojan_decrypt.py └── trojan_decrypt.so ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── trojan ├── .gitignore ├── CMakeLists.txt ├── build.gradle ├── proguard-rules.pro └── src ├── androidTest └── java │ └── me │ └── ele │ └── trojan │ └── ExampleInstrumentedTest.java └── main ├── AndroidManifest.xml ├── cpp ├── ErrInfo.cpp ├── ErrInfo.h ├── JNIHelp.cpp ├── JNIHelp.h ├── LogWriter.cpp ├── LogWriter.h ├── Logger.h ├── tea │ ├── TEACipher.cpp │ ├── TEACipher.h │ ├── base64.cpp │ └── base64.h └── trojan-lib.cpp ├── java └── me │ └── ele │ └── trojan │ ├── Trojan.java │ ├── TrojanManager.java │ ├── config │ ├── LogConstants.java │ ├── TrojanConfig.java │ └── TrojanConstants.java │ ├── executor │ └── TrojanExecutor.java │ ├── helper │ ├── FileHelper.java │ ├── PerformanceHelper.java │ └── PermissionHelper.java │ ├── internal │ ├── ActivityLife.java │ └── ExceptionHandler.java │ ├── lancet │ └── LancetHook.java │ ├── listener │ ├── PrepareUploadListener.java │ └── WaitUploadListener.java │ ├── log │ └── Logger.java │ ├── receiver │ └── TrojanReceiver.java │ ├── record │ ├── ILogFormatter.java │ ├── ILogRecorder.java │ ├── ILogWriter.java │ └── impl │ │ ├── LogFormatter.java │ │ ├── LogRecorder.java │ │ ├── MmapLogWriter.java │ │ └── NormalLogWriter.java │ ├── upload │ ├── ILogUploader.java │ └── impl │ │ └── LogUploader.java │ └── utils │ ├── AppUtils.java │ ├── DateUtils.java │ ├── DeviceUtils.java │ ├── GsonUtils.java │ ├── IOUtil.java │ ├── NetworkUtils.java │ ├── StringUtils.java │ └── TagUtil.java └── res └── values └── strings.xml /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 6 | 7 | ## Our Standards 8 | 9 | Examples of behavior that contributes to creating a positive environment include: 10 | 11 | * Using welcoming and inclusive language 12 | * Being respectful of differing viewpoints and experiences 13 | * Gracefully accepting constructive criticism 14 | * Focusing on what is best for the community 15 | * Showing empathy towards other community members 16 | 17 | Examples of unacceptable behavior by participants include: 18 | 19 | * The use of sexualized language or imagery and unwelcome sexual attention or advances 20 | * Trolling, insulting/derogatory comments, and personal or political attacks 21 | * Public or private harassment 22 | * Publishing others' private information, such as a physical or electronic address, without explicit permission 23 | * Other conduct which could reasonably be considered inappropriate in a professional setting 24 | 25 | ## Our Responsibilities 26 | 27 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 28 | 29 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 30 | 31 | ## Scope 32 | 33 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 34 | 35 | ## Enforcement 36 | 37 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at xiaofeng.zhong@ele.me. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 38 | 39 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 40 | 41 | ## Attribution 42 | 43 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] 44 | 45 | [homepage]: http://contributor-covenant.org 46 | [version]: http://contributor-covenant.org/version/1/4/ 47 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | This document contains information and guidelines about contributing to this project. 4 | Please read it before you start participating. 5 | 6 | **Topics** 7 | 8 | * [Asking Questions](#asking-questions) 9 | * [Reporting Issues](#reporting-issues) 10 | * [Developers Certificate of Origin](#developers-certificate-of-origin) 11 | 12 | ## Asking Questions 13 | 14 | We don't use GitHub as a support forum. 15 | For any usage questions that are not specific to the project itself, 16 | please ask on [Stack Overflow](https://stackoverflow.com) instead. 17 | By doing so, you'll be more likely to quickly solve your problem, 18 | and you'll allow anyone else with the same question to find the answer. 19 | This also allows maintainers to focus on improving the project for others. 20 | 21 | ## Reporting Issues 22 | 23 | A great way to contribute to the project 24 | is to send a detailed issue when you encounter an problem. 25 | We always appreciate a well-written, thorough bug report. 26 | 27 | Check that the project issues database 28 | doesn't already include that problem or suggestion before submitting an issue. 29 | If you find a match, add a quick "+1" or "I have this problem too." 30 | Doing this helps prioritize the most common problems and requests. 31 | 32 | When reporting issues, please include the following: 33 | 34 | * The version of Xcode you're using 35 | * The version of iOS or macOS you're targeting 36 | * The full output of any stack trace or compiler error 37 | * A code snippet that reproduces the described behavior, if applicable 38 | * Any other details that would be useful in understanding the problem 39 | 40 | This information will help us review and fix your issue faster. 41 | 42 | ## Developer's Certificate of Origin 43 | 44 | By making a contribution to this project, I certify that: 45 | 46 | - (a) The contribution was created in whole or in part by me and I 47 | have the right to submit it under the open source license 48 | indicated in the file; or 49 | 50 | - (b) The contribution is based upon previous work that, to the best 51 | of my knowledge, is covered under an appropriate open source 52 | license and I have the right under that license to submit that 53 | work with modifications, whether created in whole or in part 54 | by me, under the same open source license (unless I am 55 | permitted to submit under a different license), as indicated 56 | in the file; or 57 | 58 | - (c) The contribution was provided directly to me by some other 59 | person who certified (a), (b) or (c) and I have not modified 60 | it. 61 | 62 | - (d) I understand and agree that this project and the contribution 63 | are public and that a record of the contribution (including all 64 | personal information I submit with it, including my sign-off) is 65 | maintained indefinitely and may be redistributed consistent with 66 | this project or the open source license(s) involved. 67 | 68 | --- 69 | 70 | *Some of the ideas and wording for the statements above were based on work by the [Alamofire](https://github.com/Alamofire/Alamofire/blob/master/CONTRIBUTING.md) communities. We commend them for their efforts to facilitate collaboration in their projects.* 71 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### Check List 2 | 3 | Thanks for considering to open an issue. Before you submit your issue, please confirm these boxes are checked. 4 | 5 | - [ ] I have read the [README.md](https://github.com/ELELogistics/Trojan/blob/master/README.md), but there is no information I need. 6 | - [ ] I have searched in [existing issues](https://github.com/ELELogistics/Trojan/issues?utf8=%E2%9C%93&q=is%3Aissue), but did find a same one. 7 | 8 | ### Issue Description 9 | 10 | #### Description 11 | 12 | [Tell us about the issue] 13 | 14 | #### Reproduce 15 | 16 | [The steps to reproduce this issue. What are the parameters, where did you put your code, etc.] 17 | 18 | #### Other Comment 19 | 20 | [Add anything else here] 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | .idea 5 | .DS_Store 6 | /build 7 | /captures 8 | .externalNativeBuild 9 | -------------------------------------------------------------------------------- /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 | ![](/assets/trojan_banner.png) 2 | 3 |

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | 15 | [Trojan](https://github.com/ELELogistics/Trojan) is a stable and efficient mobile lightweight log SDK that not only records general logs, such as Http, power changes, component life cycles, but also records the definition of the log, which it is useful to analysis problems through the user logs. Here is the following characteristics: 16 | 17 | * Concise API, it is easy to achieve diary record function through a few lines of code; 18 | * Use the AOP technologies [Lancet](https://github.com/eleme/lancet) SDK, it is comfortable to collect common logs, also support incremental compile; 19 | * Use mmap technology to ensure the efficiency of log records; 20 | * Scalability, developers can customize the log file to achieve the purpose of the upload; 21 | * Small traffic overhead, remote control user log file upload or not by online configuration; 22 | * High stability, it is very stable at many apps. 23 | 24 | > [中文介绍](/README_CN.md) 25 | 26 | ## Overview 27 | 28 | In the open source [Trojan](https://github.com/ELELogistics/Trojan) SDK, we have collected basic logs such as Activity and Fragment lifecycles, View Click events, network status changes, phone battery status changes, also include collecting [KLog](https://github.com/ZhaoKaiQiang/KLog) logs, if KLog is not used in the project, it can be customized according to the project specific conditions. Considering that the implementation framework for network modules is different at fact, there are [OkHttp](https://github.com/square/okhttp), [Volley](https://github.com/google/volley), [Android-Async-Http](https://github.com/loopj/android-async-http), etc. Therefore, this part of collecting network logs is not suitable for customization. Users can use [Lancet](https://github.com/eleme/lancet) to collect logs at the specific network framework. In [Demo](https://github.com/ELELogistics/Trojan/blob/master/app/src/main/java/me/ele/trojan/demo/DemoHook.java), we can achieve acquisition Http request and response functions in OkHttp, it can be used as a reference. As for business-related logs, users should collect by self. 29 | 30 | ## Installation 31 | 32 | Add in the root directory's build.gradle: 33 | 34 | ```java 35 | buildscript { 36 |     dependencies { 37 |         ...... 38 |         classpath 'me.ele:lancet-plugin:1.0.2' 39 |     } 40 | } 41 | ``` 42 | 43 | Add in the app directory's build.gradle: 44 | 45 | ```java 46 | apply plugin: 'me.ele.lancet' 47 | 48 | dependencies { 49 |     ...... 50 |     provided 'me.ele:lancet-base:1.0.2' 51 |     compile 'me.ele:trojan-library:0.0.5' 52 | } 53 | ``` 54 | 55 | ## Use 56 | 57 | ### 1. Initialization 58 | 59 | Add in the custom Application: 60 | 61 | ```java 62 | TrojanConfig config = new TrojanConfig.Builder(this) 63 | // Set user information 64 | .userInfo("xxxx") 65 | // Set device id 66 | .deviceId("xxxx") 67 | // Set cipher key if need encry log 68 | .cipherKey("xxxx") 69 | // Optional, save log file in sdcard by default 70 | .logDir("xxxx") 71 | // Console log switch, the default is open 72 | .enableLog(true) 73 | .build(); 74 | Trojan.init(config); 75 | ``` 76 | 77 | Special Note: 78 | 79 | 1. The log files are stored in sdcard by default and will not be lost even if the application is uninstalled; 80 | 2. To be compatible with multiple processes, log files stored in their respective directories; 81 | 3. The log is not encrypted by default, we currently only provide TEA encryption in view for high efficiency。 82 | 83 | ### 2. Record the log 84 | 85 | Trojan provides two ways to recode log: 86 | 87 | Firstly: 88 | 89 | ```java 90 | Trojan.log("Trojan", "We have a nice day!"); 91 | ``` 92 | 93 | Secondly: 94 | 95 | ```java 96 | List msgList = new LinkedList <>(); 97 | msgList.add("Hello Trojan!"); 98 | msgList.add("We have a nice day!"); 99 | msgList.add("Hello world!"); 100 | Trojan.log("Trojan", msgList); 101 | ``` 102 | 103 | By default, a single line log is not encrypted, and if you need to encrypt it, the following is used: 104 | 105 | ```java 106 | Trojan.log("Trojan", "We have a nice day!", true); 107 | ``` 108 | 109 | ### 3. User Information 110 | 111 | When the user information changes or switch users, you can call: 112 | 113 | ```java 114 | Trojan.refreshUser("new user info"); 115 | ``` 116 | 117 | Of course, if the user logs out, you can pass a null value: 118 | 119 | ```java 120 | Trojan.refreshUser(null); 121 | ``` 122 | 123 | ### 4. Upload Solution 124 | 125 | In [Demo](https://github.com/ELELogistics/Trojan/blob/master/app/src/main/java/me/ele/trojan/demo/upload/DemoLeanCloudUploader.java) we provided free and simple way such as [LeanCloud](https://leancloud.cn/) to upload log file, you can browse, download and download log file. 126 | 127 | ### 5. Data Decryption 128 | 129 | When we set the encryption key, we can encrypt a single log to ensure the security of sensitive data. We must decrypt the encrypted data When we analyze the log. Use the [decryption script](/decrypt/trojan_decrypt.py) as follows: 130 | 131 | 1. Compile and generate decryption SO library on MAC, The so library has been generated in the repository. This step can be omitted: 132 | 133 | ```java 134 | gcc -shared -Wl,-install_name,trojan_decrypt.so -o trojan_decrypt.so -fPIC trojan_decrypt.c 135 | 136 | ``` 137 | 2. Call python script to decrypt the data on MAC, you need to pass in the decryption key and file path to be decrypted, it should be noted that the path of the python script: 138 | 139 | ```java 140 | python ./trojan_decrypt.py cipher-key cipher-file-path 141 | 142 | ``` 143 | 144 | ## PS 145 | 146 | Through the above steps, you can integrate [Trojan](https://github.com/ELELogistics/Trojan) SDK to record user's log, That is very simple! If you have any questions about the use of Lancet, you can get more details by [Readme](https://github.com/eleme/lancet/blob/dev/README_zh.md). 147 | 148 | ## License 149 | 150 | ![](/assets/trojan_license.png) 151 | 152 | Trojan is available under the Apache-2.0 license. See the [LICENSE](/LICENSE) file for more info. 153 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | ![](/assets/trojan_banner.png) 2 | 3 |

4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |

14 | 15 | [Trojan](https://github.com/ELELogistics/Trojan)是一个稳定高效的移动端轻量级日志SDK,既可以记录通用日志,比如网络请求、电量变化、页面生命周期,也可以记录自定义的日志,从而可以通过用户日志来帮助我们定位分析问题。具有以下特点: 16 | 17 | * 简洁的 API,通过几行代码就可以接入,实现日记记录功能; 18 | * 使用 AOP 技术 [Lancet](https://github.com/eleme/lancet) 框架插桩收集通用日志,并且支持增量编译; 19 | * 使用 mmap 技术,保证日记记录的高效性; 20 | * 扩展性高,开发者可以自定义日志文件的上传功能; 21 | * 流量开销小,支持在线配置,远程控制用户日志文件上传与否; 22 | * 稳定性高,目前已稳定运行在饿了么物流团队众包等多个 APP 上。 23 | 24 | > [English Introduction](/README.md) 25 | 26 | ## 综述 27 | 28 | 在开源的 [Trojan](https://github.com/ELELogistics/Trojan) SDK中,目前采集了 Activity 和 Fragment 生命周期,View Click 事件,网络状态变化,手机电量状态变化等基础日志,还通过 AOP 技术插桩 [KLog](https://github.com/ZhaoKaiQiang/KLog)采集 Log 日志,要是项目中未使用 KLog,也可以根据项目情况具体定制。考虑到每个项目中网络模块的实现框架都不尽相同,有 [OkHttp](https://github.com/square/okhttp)、[Volley](https://github.com/google/volley)、[Android-Async-Http](https://github.com/loopj/android-async-http) 等等,所以采集网络日志这一部分不方便统一处理,需要使用者通过 [Lancet](https://github.com/eleme/lancet) 插桩具体网络框架来收集日志。在 [Demo](https://github.com/ELELogistics/Trojan/blob/master/app/src/main/java/me/ele/trojan/demo/DemoHook.java) 中具体以 OkHttp 为例,实现采集 Http request 和 response 的功能,可作为参考。而与业务相关的日志,需要使用者自己采集。 29 | 30 | ## 配置 31 | 32 | 在根目录的 build.gradle 添加: 33 | 34 | ```java 35 | buildscript { 36 | dependencies { 37 | ....... 38 | classpath 'me.ele:lancet-plugin:1.0.2' 39 | } 40 | } 41 | ``` 42 | 43 | 在 app 目录的 'build.gradle' 添加: 44 | 45 | ```java 46 | apply plugin: 'me.ele.lancet' 47 | 48 | dependencies { 49 | ...... 50 | provided 'me.ele:lancet-base:1.0.2' 51 | compile 'me.ele:trojan-library:0.0.5' 52 | } 53 | ``` 54 | 55 | ## 使用 56 | 57 | ### 1. 初始化 58 | 59 | 在自定义的 `Application` 添加: 60 | 61 | ```java 62 | TrojanConfig config = new TrojanConfig.Builder(this) 63 | // Set user information 64 | .userInfo("xxxx") 65 | // Set device id 66 | .deviceId("xxxx") 67 | // Set cipher key if need encry log 68 | .cipherKey("xxxx") 69 | // Optional, save log file in sdcard by default 70 | .logDir("xxxx") 71 | // Console log switch, the default is open 72 | .enableLog(true) 73 | .build(); 74 | Trojan.init(config); 75 | ``` 76 | 77 | 特别说明: 78 | 79 | 1. 日志文件默认保存在 sdcard 中,即使应用被卸载,也不会丢失日志; 80 | 2. 为兼容多进程,避免文件相互干扰,日志文件保存在各自的目录下,目录以进程名来命名; 81 | 3. 默认情况下日志不加密,考虑到加密的高效性,目前仅提供TEA加密方式。 82 | 83 | ### 2. 记录日志 84 | 85 | Trojan 提供两种方式记录日志: 86 | 87 | 第一种: 88 | 89 | ```java 90 | Trojan.log("Trojan", "We have a nice day!"); 91 | ``` 92 | 93 | 第二种: 94 | 95 | ```java 96 | List msgList = new LinkedList<>(); 97 | msgList.add("Hello Trojan!"); 98 | msgList.add("We have a nice day!"); 99 | msgList.add("Hello world!"); 100 | Trojan.log("Trojan", msgList); 101 | ``` 102 | 103 | 默认情况下,对于单行日志不加密,如果需要加密,则使用如下: 104 | 105 | ```java 106 | Trojan.log("Trojan", "We have a nice day!", true); 107 | ``` 108 | 109 | ### 3. 用户信息 110 | 111 | 当用户信息发生改变或者切换用户时,可以调用: 112 | 113 | ```java 114 | Trojan.refreshUser("new user info"); 115 | ``` 116 | 117 | 当然了,要是用户登出,可以传空值,即表示登出操作: 118 | 119 | ```java 120 | Trojan.refreshUser(null); 121 | ``` 122 | 123 | ### 4. 上传方案 124 | 125 | 针对日志上传,在 [Demo](https://github.com/ELELogistics/Trojan/blob/master/app/src/main/java/me/ele/trojan/demo/upload/DemoLeanCloudUploader.java) 中提供了 [LeanCloud](https://leancloud.cn/) 这种免费简单的方式,可以实现上传、浏览、下载等文件服务的基本功能,可供参考。 126 | 127 | ### 5. 数据解密 128 | 129 | 当设置了加密秘钥,为保证敏感数据的安全性,可以加密单行日志,在日志分析时就需要对加密数据进行解密。[解密脚本](/decrypt/trojan_decrypt.py)使用如下: 130 | 131 | 1. 在MAC上编译生成解密SO库,在仓库中已经生成了so库,这一步可以省略: 132 | 133 | ```java 134 | gcc -shared -Wl,-install_name,trojan_decrypt.so -o trojan_decrypt.so -fPIC trojan_decrypt.c 135 | 136 | ``` 137 | 2. 在MAC上调用python脚本解密数据,需要传入解密秘钥和待解密的文件路径,需要注意的是python脚本的路径要对: 138 | 139 | ```java 140 | python ./trojan_decrypt.py cipher-key cipher-file-path 141 | 142 | ``` 143 | 144 | ## 备注 145 | 146 | 通过集成 [Trojan](https://github.com/ELELogistics/Trojan),可以轻松实现用户日志的记录功能,是不是很简单呀!要是对 Lancet 的使用有疑问,大家可以参考 [https://github.com/eleme/lancet/blob/dev/README_zh.md](https://github.com/eleme/lancet/blob/dev/README_zh.md),这里就不赘述。 147 | 148 | ## 协议 149 | 150 | ![](/assets/trojan_license.png) 151 | 152 | Trojan基于Apache-2.0协议进行分发和使用,更多信息参见[协议](/LICENSE)文件。 153 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | apply plugin: 'me.ele.lancet' 3 | 4 | android { 5 | 6 | compileSdkVersion 23 7 | buildToolsVersion '25.0.2' 8 | defaultConfig { 9 | applicationId "me.ele.trojan.demo" 10 | minSdkVersion 15 11 | targetSdkVersion 23 12 | versionCode 1 13 | versionName "1.0" 14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 15 | } 16 | buildTypes { 17 | release { 18 | minifyEnabled false 19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 20 | } 21 | debug { 22 | debuggable true 23 | jniDebuggable true 24 | } 25 | } 26 | lintOptions { 27 | abortOnError false 28 | } 29 | } 30 | 31 | dependencies { 32 | testCompile 'junit:junit:4.12' 33 | compile fileTree(include: ['*.jar'], dir: 'libs') 34 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 35 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 36 | exclude group: 'com.android.support', module: 'support-annotations' 37 | }) 38 | 39 | compile 'com.android.support:design:23.4.0' 40 | compile 'com.android.support:recyclerview-v7:23.4.0' 41 | compile 'com.android.support:appcompat-v7:23.4.0' 42 | 43 | compile 'cn.leancloud.android:avoscloud-sdk:v4.4.4' 44 | compile "com.squareup.retrofit2:converter-gson:2.0.1" 45 | 46 | provided "me.ele:lancet-base:1.0.2" 47 | 48 | compile project(':trojan') 49 | //compile 'me.ele:trojan-library:0.0.2' 50 | 51 | //debugCompile project(path: ':trojan', configuration: 'debug') 52 | //releaseCompile project(path: ':trojan', configuration: 'release') 53 | 54 | } 55 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/eleme/Downloads/android-sdk-macosx/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/me/ele/demo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package me.ele.demo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will executeRecord on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("me.ele.trojantest", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /app/src/main/java/me/ele/trojan/demo/CustomApplication.java: -------------------------------------------------------------------------------- 1 | package me.ele.trojan.demo; 2 | 3 | import android.app.Application; 4 | import android.os.Environment; 5 | 6 | import me.ele.trojan.Trojan; 7 | import me.ele.trojan.config.TrojanConfig; 8 | 9 | /** 10 | * Created by wangallen on 2017/6/7. 11 | */ 12 | 13 | public class CustomApplication extends Application { 14 | 15 | @Override 16 | public void onCreate() { 17 | super.onCreate(); 18 | 19 | TrojanConfig config = new TrojanConfig.Builder(this) 20 | .userInfo("520") 21 | .deviceId("726e78ec-c351-3a52-ac02-ec04e689a9f3") 22 | .enableLog(true) 23 | .cipherKey("1234567890abcdef") 24 | .build(); 25 | Trojan.init(config); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /app/src/main/java/me/ele/trojan/demo/DemoHook.java: -------------------------------------------------------------------------------- 1 | package me.ele.trojan.demo; 2 | 3 | import android.util.Log; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import me.ele.lancet.base.Origin; 9 | import me.ele.lancet.base.annotations.Insert; 10 | import me.ele.lancet.base.annotations.NameRegex; 11 | import me.ele.lancet.base.annotations.Proxy; 12 | import me.ele.lancet.base.annotations.TargetClass; 13 | import me.ele.trojan.Trojan; 14 | import me.ele.trojan.log.Logger; 15 | import okhttp3.Interceptor; 16 | import okhttp3.Response; 17 | 18 | /** 19 | * Created by michaelzhong on 2017/12/26. 20 | */ 21 | 22 | public class DemoHook { 23 | 24 | @Proxy("e") 25 | @TargetClass("android.util.Log") 26 | public static int e(String tag, String msg) { 27 | Trojan.log(tag, msg); 28 | return (int) Origin.call(); 29 | } 30 | 31 | 32 | @TargetClass("okhttp3.OkHttpClient") 33 | @NameRegex("okhttp3/RealCall") 34 | @Proxy("interceptors") 35 | public List networkInterceptors() { 36 | // record the http request 37 | Logger.i("networkInterceptors"); 38 | List interceptors = (List) Origin.call(); 39 | List newList = new ArrayList<>(interceptors.size() + 1); 40 | newList.addAll(interceptors); 41 | newList.add(new RecordRequestInterceptor()); 42 | return newList; 43 | } 44 | 45 | @Insert("getResponseWithInterceptorChain") 46 | @TargetClass(value = "okhttp3.RealCall") 47 | private Response getResponseWithInterceptorChain() throws Throwable { 48 | // record the http response 49 | Logger.i("getResponseWithInterceptorChain"); 50 | Response response = (Response) Origin.call(); 51 | try { 52 | HttpRecordHelper.recordResponse(response); 53 | } catch (Exception ex) { 54 | ex.printStackTrace(); 55 | } 56 | return response; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /app/src/main/java/me/ele/trojan/demo/HttpRecordHelper.java: -------------------------------------------------------------------------------- 1 | package me.ele.trojan.demo; 2 | 3 | import java.io.EOFException; 4 | import java.io.IOException; 5 | import java.nio.charset.Charset; 6 | import java.util.LinkedList; 7 | import java.util.List; 8 | 9 | import me.ele.trojan.Trojan; 10 | import me.ele.trojan.log.Logger; 11 | import okhttp3.MediaType; 12 | import okhttp3.Request; 13 | import okhttp3.Response; 14 | import okhttp3.ResponseBody; 15 | import okio.Buffer; 16 | import okio.BufferedSource; 17 | 18 | /** 19 | * Created by panda on 2017/12/12. 20 | */ 21 | 22 | public class HttpRecordHelper { 23 | 24 | private static final Charset UTF8 = Charset.forName("UTF-8"); 25 | 26 | public static void recordRequest(Request request) { 27 | String method = request.method(); 28 | String url = request.url().toString(); 29 | Logger.i("recordRequest-->method:" + method + ",url:" + url); 30 | List msgList = new LinkedList<>(); 31 | msgList.add(method); 32 | msgList.add(url); 33 | Trojan.log("TrojanRequest", msgList); 34 | } 35 | 36 | public static Response recordResponse(Response response) throws IOException { 37 | ResponseBody responseBody = response.body(); 38 | long contentLength = responseBody.contentLength(); 39 | 40 | BufferedSource source = responseBody.source(); 41 | source.request(Long.MAX_VALUE); // Buffer the entire body. 42 | Buffer buffer = source.buffer(); 43 | 44 | Charset charset = UTF8; 45 | MediaType contentType = responseBody.contentType(); 46 | if (contentType != null) { 47 | charset = contentType.charset(UTF8); 48 | } 49 | 50 | List msgList = new LinkedList<>(); 51 | msgList.add(response.request().method()); 52 | msgList.add(response.request().url().toString()); 53 | 54 | if (isPlaintext(buffer) && contentLength != 0) { 55 | msgList.add(buffer.clone().readString(charset)); 56 | } else { 57 | msgList.add("<-- END HTTP (binary " + buffer.size() + "-byte body omitted)"); 58 | } 59 | Trojan.log("TrojanResponse", msgList); 60 | 61 | return response; 62 | } 63 | 64 | /** 65 | * Returns true if the body in question probably contains human readable text. Uses a small sample 66 | * of code points to detect unicode control characters commonly used in binary file signatures. 67 | */ 68 | private static boolean isPlaintext(Buffer buffer) { 69 | try { 70 | Buffer prefix = new Buffer(); 71 | long byteCount = buffer.size() < 64 ? buffer.size() : 64; 72 | buffer.copyTo(prefix, 0, byteCount); 73 | for (int i = 0; i < 16; i++) { 74 | if (prefix.exhausted()) { 75 | break; 76 | } 77 | int codePoint = prefix.readUtf8CodePoint(); 78 | if (Character.isISOControl(codePoint) && !Character.isWhitespace(codePoint)) { 79 | return false; 80 | } 81 | } 82 | return true; 83 | } catch (EOFException e) { 84 | return false; // Truncated UTF-8 sequence. 85 | } 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/me/ele/trojan/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package me.ele.trojan.demo; 2 | 3 | import android.Manifest; 4 | import android.content.pm.PackageManager; 5 | import android.os.Bundle; 6 | import android.support.v4.app.ActivityCompat; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.view.View; 9 | 10 | import java.io.File; 11 | import java.io.IOException; 12 | import java.util.List; 13 | 14 | import me.ele.trojan.Trojan; 15 | import me.ele.trojan.demo.upload.DemoLeanCloudUploader; 16 | import me.ele.trojan.listener.WaitUploadListener; 17 | import me.ele.trojan.log.Logger; 18 | import me.ele.trojan.utils.DateUtils; 19 | 20 | public class MainActivity extends AppCompatActivity implements View.OnClickListener { 21 | 22 | private static final String TAG = "Trojan"; 23 | 24 | private static final int REQUEST_WRITE_PERMISSION_CODE = 888; 25 | 26 | private static final String DEMO_USER_A = "520"; 27 | 28 | private static final String DEMO_USER_B = "214"; 29 | 30 | private String trojanUser = DEMO_USER_A; 31 | 32 | private DemoLeanCloudUploader uploader; 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_main); 38 | 39 | requestWritePermissions(); 40 | 41 | uploader = new DemoLeanCloudUploader(this); 42 | 43 | findViewById(R.id.btn_request_permission).setOnClickListener(this); 44 | findViewById(R.id.btn_write_log).setOnClickListener(this); 45 | findViewById(R.id.btn_write_big_log).setOnClickListener(this); 46 | findViewById(R.id.btn_write_encrypt_log).setOnClickListener(this); 47 | findViewById(R.id.btn_change_user).setOnClickListener(this); 48 | findViewById(R.id.btn_upload_log_file).setOnClickListener(this); 49 | findViewById(R.id.btn_get_log_by_date).setOnClickListener(this); 50 | } 51 | 52 | private void requestWritePermissions() { 53 | int hasWritePermission = ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE); 54 | if (hasWritePermission != PackageManager.PERMISSION_GRANTED) { 55 | ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, REQUEST_WRITE_PERMISSION_CODE); 56 | return; 57 | } else { 58 | Logger.e(TAG, "permission granted"); 59 | } 60 | } 61 | 62 | @Override 63 | public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { 64 | switch (requestCode) { 65 | case REQUEST_WRITE_PERMISSION_CODE: 66 | Logger.e(TAG, "got writer permission now"); 67 | break; 68 | } 69 | } 70 | 71 | @Override 72 | public void onClick(View v) { 73 | final int viewId = v.getId(); 74 | if (viewId == R.id.btn_request_permission) { 75 | requestWritePermissions(); 76 | } else if (viewId == R.id.btn_write_log) { 77 | Trojan.log(TAG, "Have a nice day from Trojan!"); 78 | } else if (viewId == R.id.btn_write_big_log) { 79 | for (int i = 0; i < 10000; i++) { 80 | Trojan.log(TAG, "Have a nice day from Trojan by " + (i + 1) + "!"); 81 | } 82 | } else if (viewId == R.id.btn_write_encrypt_log) { 83 | Trojan.log(TAG, 1, "Have a nice day from Trojan, 饿了么物流移动组!", true); 84 | } else if (viewId == R.id.btn_change_user) { 85 | if (trojanUser.equals(DEMO_USER_A)) { 86 | trojanUser = DEMO_USER_B; 87 | } else { 88 | trojanUser = DEMO_USER_A; 89 | } 90 | Trojan.refreshUser(trojanUser); 91 | } else if (viewId == R.id.btn_upload_log_file) { 92 | Trojan.prepareUploadLogFileAsync(new WaitUploadListener() { 93 | @Override 94 | public void onReadyToUpload(final String user, final String device, final List waitUploadFileList) { 95 | Logger.e("MainActivity->onReadyToUpload:" + waitUploadFileList); 96 | if (waitUploadFileList == null || waitUploadFileList.size() == 0) { 97 | return; 98 | } 99 | new Thread() { 100 | @Override 101 | public void run() { 102 | for (File logFile : waitUploadFileList) { 103 | try { 104 | uploader.uploadLogFile(user, device, logFile); 105 | } catch (IOException e) { 106 | e.printStackTrace(); 107 | } catch (Exception e) { 108 | e.printStackTrace(); 109 | } 110 | } 111 | } 112 | }.start(); 113 | } 114 | 115 | @Override 116 | public void onReadyFail() { 117 | Logger.e("MainActivity->onReadyFail"); 118 | } 119 | }); 120 | } else if (viewId == R.id.btn_get_log_by_date) { 121 | new Thread() { 122 | @Override 123 | public void run() { 124 | Logger.e("MainActivity->2018-04-01:" + Trojan.prepareUploadLogFileSync("2018-04-01")); 125 | Logger.e("MainActivity->2018-05-01:" + Trojan.prepareUploadLogFileSync("2018-05-01")); 126 | Logger.e("MainActivity->2018-04-08:" + Trojan.prepareUploadLogFileSync("2018-04-08")); 127 | Logger.e("MainActivity->2018-04-10:" + Trojan.prepareUploadLogFileSync(DateUtils.getDate())); 128 | } 129 | }.start(); 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /app/src/main/java/me/ele/trojan/demo/RecordRequestInterceptor.java: -------------------------------------------------------------------------------- 1 | package me.ele.trojan.demo; 2 | 3 | import java.io.IOException; 4 | 5 | import okhttp3.Interceptor; 6 | import okhttp3.Request; 7 | import okhttp3.Response; 8 | 9 | /** 10 | * Created by panda on 2017/12/19. 11 | */ 12 | 13 | public class RecordRequestInterceptor implements Interceptor { 14 | @Override 15 | public Response intercept(Chain chain) throws IOException { 16 | Request request = chain.request(); 17 | HttpRecordHelper.recordRequest(request); 18 | return chain.proceed(request); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /app/src/main/java/me/ele/trojan/demo/upload/DemoLeanCloudUploader.java: -------------------------------------------------------------------------------- 1 | package me.ele.trojan.demo.upload; 2 | 3 | import android.content.Context; 4 | import android.text.TextUtils; 5 | 6 | import com.avos.avoscloud.AVException; 7 | import com.avos.avoscloud.AVFile; 8 | import com.avos.avoscloud.AVOSCloud; 9 | 10 | import java.io.File; 11 | import java.io.FileNotFoundException; 12 | 13 | import me.ele.trojan.config.TrojanConstants; 14 | import me.ele.trojan.log.Logger; 15 | 16 | /** 17 | * Created by michaelzhong on 2017/11/7. 18 | */ 19 | 20 | public class DemoLeanCloudUploader { 21 | 22 | private static final String APPLICATION_ID = "gtzw5LbEtLc3OyXBodNKdsnU-gzGzoHsz"; 23 | 24 | private static final String CLIENT_KEY = "QC72vlbV7m06lsfuJeCz0uiB"; 25 | 26 | public DemoLeanCloudUploader(Context context) { 27 | AVOSCloud.initialize(context, APPLICATION_ID, CLIENT_KEY); 28 | } 29 | 30 | public void uploadLogFile(String user, String device, File gzFile) throws Exception { 31 | Logger.i("DemoLeanCloudUploader-->uploadLogFile,gzFile:" + gzFile); 32 | if (gzFile == null || !gzFile.isFile()) { 33 | Logger.e("DemoLeanCloudUploader-->uploadLogFile,not exists"); 34 | return; 35 | } 36 | String leanCloudFileName = getLeanCloudFileName(user, device, gzFile.getName()); 37 | Logger.i("DemoLeanCloudUploader-->uploadLogFile,leanCloudFileName:" + leanCloudFileName); 38 | try { 39 | AVFile avFile = AVFile.withAbsoluteLocalPath(leanCloudFileName, gzFile.getAbsolutePath()); 40 | avFile.save(); 41 | gzFile.delete(); 42 | Logger.i("DemoLeanCloudUploader-->uploadLogFile,success"); 43 | } catch (FileNotFoundException ex) { 44 | ex.printStackTrace(); 45 | throw ex; 46 | } catch (AVException avException) { 47 | avException.printStackTrace(); 48 | throw avException; 49 | } 50 | } 51 | 52 | private String getLeanCloudFileName(String user, String device, String logFileName) { 53 | StringBuilder fileNameBuilder = new StringBuilder(); 54 | if (!TextUtils.isEmpty(user)) { 55 | fileNameBuilder.append(user); 56 | fileNameBuilder.append("-"); 57 | } 58 | fileNameBuilder.append(logFileName.replace(TrojanConstants.GZ, "")); 59 | if (!TextUtils.isEmpty(device)) { 60 | fileNameBuilder.append("-"); 61 | fileNameBuilder.append(device); 62 | } 63 | fileNameBuilder.append(TrojanConstants.GZ); 64 | return fileNameBuilder.toString(); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /app/src/main/res/color/selector_blue.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/tab_explore.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eleme/Trojan/7e2e566fb158521872e0c4767e612d5501caff6b/app/src/main/res/drawable-xxhdpi/tab_explore.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/tab_explore_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eleme/Trojan/7e2e566fb158521872e0c4767e612d5501caff6b/app/src/main/res/drawable-xxhdpi/tab_explore_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/tab_home.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eleme/Trojan/7e2e566fb158521872e0c4767e612d5501caff6b/app/src/main/res/drawable-xxhdpi/tab_home.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/tab_home_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eleme/Trojan/7e2e566fb158521872e0c4767e612d5501caff6b/app/src/main/res/drawable-xxhdpi/tab_home_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/tab_profile.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eleme/Trojan/7e2e566fb158521872e0c4767e612d5501caff6b/app/src/main/res/drawable-xxhdpi/tab_profile.png -------------------------------------------------------------------------------- /app/src/main/res/drawable-xxhdpi/tab_profile_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eleme/Trojan/7e2e566fb158521872e0c4767e612d5501caff6b/app/src/main/res/drawable-xxhdpi/tab_profile_normal.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/selector_menu_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/selector_tab_article.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/selector_tab_mine.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_list_view.xml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 20 | 21 |