├── .gitignore
├── LICENSE
├── README-Chinese.md
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zxy
│ │ └── recovery
│ │ └── test
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zxy
│ │ │ └── recovery
│ │ │ └── test
│ │ │ ├── App.java
│ │ │ ├── BaseActivity.java
│ │ │ ├── MainActivity.java
│ │ │ ├── TestActivity.java
│ │ │ └── TestActivity2.java
│ └── res
│ │ ├── layout
│ │ ├── activity_main.xml
│ │ ├── activity_test.xml
│ │ └── activity_test2.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-v21
│ │ └── styles.xml
│ │ ├── values-w820dp
│ │ └── dimens.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── zxy
│ └── recovery
│ └── test
│ └── ExampleUnitTest.java
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── recovery
├── .gitignore
├── build.gradle
├── proguard-rules.pro
├── publish.gradle
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── zxy
│ │ └── recovery
│ │ └── ExampleInstrumentedTest.java
│ ├── main
│ ├── AndroidManifest.xml
│ ├── java
│ │ └── com
│ │ │ └── zxy
│ │ │ └── recovery
│ │ │ ├── callback
│ │ │ ├── RecoveryActivityLifecycleCallback.java
│ │ │ └── RecoveryCallback.java
│ │ │ ├── core
│ │ │ ├── ActivityManagerDelegate.java
│ │ │ ├── ActivityStackCompat.java
│ │ │ ├── CrashData.java
│ │ │ ├── Recovery.java
│ │ │ ├── RecoveryActivity.java
│ │ │ ├── RecoveryComponentHook.java
│ │ │ ├── RecoveryHandler.java
│ │ │ └── RecoveryStore.java
│ │ │ ├── exception
│ │ │ ├── RecoveryException.java
│ │ │ └── ReflectException.java
│ │ │ └── tools
│ │ │ ├── DefaultHandlerUtil.java
│ │ │ ├── RecoveryLog.java
│ │ │ ├── RecoverySharedPrefsUtil.java
│ │ │ ├── RecoveryUtil.java
│ │ │ ├── Reflect.java
│ │ │ └── SharedPreferencesCompat.java
│ └── res
│ │ ├── drawable-xhdpi
│ │ └── ic_recovery_page.png
│ │ ├── drawable
│ │ └── recovery_default_btn_selector.xml
│ │ ├── layout
│ │ ├── activity_recovery.xml
│ │ └── layout_recovery_debug.xml
│ │ ├── menu
│ │ ├── menu_recovery.xml
│ │ └── menu_recovery_sub.xml
│ │ ├── values-en
│ │ └── strings.xml
│ │ ├── values-v21
│ │ └── styles.xml
│ │ └── values
│ │ ├── colors.xml
│ │ ├── dimens.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── zxy
│ └── recovery
│ └── ExampleUnitTest.java
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Android template
3 | # Built application files
4 | *.apk
5 | *.ap_
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 |
18 | # Gradle files
19 | .gradle/
20 | build/
21 |
22 | # Local configuration file (sdk path, etc)
23 | local.properties
24 |
25 | # Proguard folder generated by Eclipse
26 | proguard/
27 |
28 | # Log Files
29 | *.log
30 |
31 | # Android Studio Navigation editor temp files
32 | .navigation/
33 |
34 | # Android Studio captures folder
35 | captures/
36 |
37 | # Intellij
38 | *.iml
39 | .idea/
40 |
41 | # Keystore files
42 | *.jks
43 |
44 |
--------------------------------------------------------------------------------
/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-Chinese.md:
--------------------------------------------------------------------------------
1 | # **Recovery**
2 | A crash recovery framework!
3 |
4 | ----
5 |
6 | [  ](https://bintray.com/sunzxyong/maven/Recovery/_latestVersion)[](https://github.com/Sunzxyong/Recovery/blob/master/LICENSE)
7 |
8 | [英文文档](https://github.com/Sunzxyong/Recovery/blob/master/README.md)
9 |
10 | # **Introduce**
11 |
12 | [博客介绍](http://zhengxiaoyong.me/2016/09/05/Android%E8%BF%90%E8%A1%8C%E6%97%B6Crash%E8%87%AA%E5%8A%A8%E6%81%A2%E5%A4%8D%E6%A1%86%E6%9E%B6-Recovery)
13 |
14 | “Recovery”帮助你自动处理程序在运行时的Crash,它含有以下几点功能
15 |
16 | * 自动恢复Activity Stack和数据
17 | * 支持只恢复栈顶Activity
18 | * Crash信息的显示与保存
19 | * 应用重启或者清空缓存
20 | * 一分钟内两次恢复失败不再恢复而进行重启应用
21 |
22 | # **Art**
23 | 
24 |
25 | # **Usage**
26 | ## **Reference**
27 | **Gradle**
28 |
29 | ```
30 | compile 'com.zxy.android:recovery:0.0.3'
31 | ```
32 |
33 | **Maven**
34 |
35 | ```
36 |
37 | com.zxy.android
38 | recovery
39 | 0.0.3
40 | pom
41 |
42 | ```
43 | ## **Init**
44 | 在你自定义的Application中初始化
45 |
46 | ```java
47 | Recovery.getInstance()
48 | .debug(true)
49 | .recoverInBackground(false)
50 | .recoverStack(true)
51 | .mainPage(MainActivity.class)
52 | .callback(new MyCrashCallback())
53 | .init(this);
54 | ```
55 | 并且在manifest中授权
56 |
57 | ```
58 | android.permission.GET_TASKS
59 | ```
60 | ## **Arguments**
61 |
62 | | Argument | Type | Function |
63 | | :-: | :-: | :-: |
64 | | debug | boolean | 是否开启debug模式 |
65 | | recoverInBackgroud | boolean | 当应用在后台时发生Crash,是否需要进行恢复 |
66 | | recoverStack | boolean | 是否恢复整个Activity Stack,否则将恢复栈顶Activity |
67 | | mainPage | Class extends Activity> | 回退的界面 |
68 | | callback | RecoveryCallback | 发生Crash时的回调 |
69 |
70 | ## **Callback**
71 |
72 | ```
73 | public interface RecoveryCallback {
74 |
75 | void stackTrace(String stackTrace);
76 |
77 | void cause(String cause);
78 |
79 | void exception(String throwExceptionType, String throwClassName, String throwMethodName, int throwLineNumber);
80 | }
81 | ```
82 |
83 | ## **Custom Theme**
84 |
85 | 自定义RecoveryActivity的主题,需重写以下styles属性:
86 |
87 | ```
88 | #F44336
89 | #D32F2F
90 | #BDBDBD
91 | #FFFFFF
92 | ```
93 | ## **Crash File Path**
94 | > {SDCard Dir}/Android/data/{packageName}/files/recovery_crash/
95 |
96 | # **LICENSE**
97 |
98 | ```
99 | Copyright 2016 zhengxiaoyong
100 |
101 | Licensed under the Apache License, Version 2.0 (the "License");
102 | you may not use this file except in compliance with the License.
103 | You may obtain a copy of the License at
104 |
105 | http://www.apache.org/licenses/LICENSE-2.0
106 |
107 | Unless required by applicable law or agreed to in writing, software
108 | distributed under the License is distributed on an "AS IS" BASIS,
109 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
110 | See the License for the specific language governing permissions and
111 | limitations under the License.
112 | ```
113 |
114 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # **Recovery**
2 | A crash recovery framework!
3 |
4 | ----
5 |
6 | [  ](https://bintray.com/sunzxyong/maven/Recovery/_latestVersion)[](https://github.com/Sunzxyong/Recovery/blob/master/LICENSE)
7 |
8 | [中文文档](https://github.com/Sunzxyong/Recovery/blob/master/README-Chinese.md)
9 |
10 | # **Introduction**
11 |
12 | [Blog entry with introduction](http://zhengxiaoyong.me/2016/09/05/Android%E8%BF%90%E8%A1%8C%E6%97%B6Crash%E8%87%AA%E5%8A%A8%E6%81%A2%E5%A4%8D%E6%A1%86%E6%9E%B6-Recovery)
13 |
14 | “Recovery” can help you to automatically handle application crash in runtime. It provides you with following functionality:
15 |
16 | * Automatic recovery activity with stack and data;
17 | * Ability to recover to the top activity;
18 | * A way to view and save crash info;
19 | * Ability to restart and clear the cache;
20 | * Allows you to do a restart instead of recovering if failed twice in one minute.
21 |
22 | # **Art**
23 | 
24 |
25 | # **Usage**
26 | ## **Installation**
27 | **Using Gradle**
28 |
29 | ```gradle
30 | compile 'com.zxy.android:recovery:0.0.3'
31 | ```
32 |
33 | **Using Maven**
34 |
35 | ```xml
36 |
37 | com.zxy.android
38 | recovery
39 | 0.0.3
40 | pom
41 |
42 | ```
43 |
44 | ## **Initialization**
45 | You can use this code sample to initialize Recovery in your application:
46 |
47 | ```java
48 | Recovery.getInstance()
49 | .debug(true)
50 | .recoverInBackground(false)
51 | .recoverStack(true)
52 | .mainPage(MainActivity.class)
53 | .callback(new MyCrashCallback())
54 | .init(this);
55 | ```
56 | and grant permission:
57 |
58 | ```
59 | android.permission.GET_TASKS
60 | ```
61 | ## **Arguments**
62 |
63 | | Argument | Type | Function |
64 | | :-: | :-: | :-: |
65 | | debug | boolean | Whether to open the debug mode |
66 | | recoverInBackgroud | boolean | When the App in the background, whether to restore the stack |
67 | | recoverStack | boolean | Whether to restore the activity stack, or to restore the top activity |
68 | | mainPage | Class extends Activity> | Initial page activity |
69 | | callback | RecoveryCallback | Crash info callback|
70 |
71 | ## **Callback**
72 |
73 | ```java
74 | public interface RecoveryCallback {
75 |
76 | void stackTrace(String stackTrace);
77 |
78 | void cause(String cause);
79 |
80 | void exception(
81 | String throwExceptionType,
82 | String throwClassName,
83 | String throwMethodName,
84 | int throwLineNumber
85 | );
86 | }
87 | ```
88 |
89 | ## **Custom Theme**
90 |
91 | You can customize UI by setting these properties in your styles file:
92 |
93 | ```xml
94 | #F44336
95 | #D32F2F
96 | #BDBDBD
97 | #FFFFFF
98 | ```
99 |
100 | ## **Crash File Path**
101 | > {SDCard Dir}/Android/data/{packageName}/files/recovery_crash/
102 |
103 | # **LICENSE**
104 |
105 | ```
106 | Copyright 2016 zhengxiaoyong
107 |
108 | Licensed under the Apache License, Version 2.0 (the "License");
109 | you may not use this file except in compliance with the License.
110 | You may obtain a copy of the License at
111 |
112 | http://www.apache.org/licenses/LICENSE-2.0
113 |
114 | Unless required by applicable law or agreed to in writing, software
115 | distributed under the License is distributed on an "AS IS" BASIS,
116 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
117 | See the License for the specific language governing permissions and
118 | limitations under the License.
119 | ```
120 |
121 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 24
5 | buildToolsVersion "24.0.0"
6 | defaultConfig {
7 | applicationId "com.zxy.recovery.test"
8 | minSdkVersion 14
9 | targetSdkVersion 24
10 | versionCode 1
11 | versionName "1.0"
12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13 | }
14 | buildTypes {
15 | release {
16 | minifyEnabled false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25 | exclude group: 'com.android.support', module: 'support-annotations'
26 | })
27 | compile project(':recovery')
28 | // compile 'com.zxy.android:recovery:0.0.2'
29 | compile 'com.android.support:appcompat-v7:24.2.0'
30 | compile 'com.android.support:design:24.2.0'
31 | testCompile 'junit:junit:4.12'
32 | }
33 |
--------------------------------------------------------------------------------
/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/Sunzxyong/Library/Android/sdk/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/com/zxy/recovery/test/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.test;
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 execute 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("com.zxy.recovery.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
14 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zxy/recovery/test/App.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.test;
2 |
3 | import android.app.Application;
4 | import android.util.Log;
5 |
6 | import com.zxy.recovery.callback.RecoveryCallback;
7 | import com.zxy.recovery.core.Recovery;
8 |
9 | /**
10 | * Created by zhengxiaoyong on 16/8/26.
11 | */
12 | public class App extends Application {
13 |
14 | @Override
15 | public void onCreate() {
16 | super.onCreate();
17 |
18 | Recovery.getInstance()
19 | .debug(true)
20 | .recoverInBackground(false)
21 | .recoverStack(true)
22 | .mainPage(MainActivity.class)
23 | .callback(new MyCrashCallback())
24 | .init(this);
25 | }
26 |
27 | static final class MyCrashCallback implements RecoveryCallback {
28 | @Override
29 | public void stackTrace(String exceptionMessage) {
30 | Log.e("zxy", "exceptionMessage:" + exceptionMessage);
31 | }
32 |
33 | @Override
34 | public void cause(String cause) {
35 | Log.e("zxy", "cause:" + cause);
36 | }
37 |
38 | @Override
39 | public void exception(String exceptionType, String throwClassName, String throwMethodName, int throwLineNumber) {
40 | Log.e("zxy", "exceptionClassName:" + exceptionType);
41 | Log.e("zxy", "throwClassName:" + throwClassName);
42 | Log.e("zxy", "throwMethodName:" + throwMethodName);
43 | Log.e("zxy", "throwLineNumber:" + throwLineNumber);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zxy/recovery/test/BaseActivity.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.test;
2 |
3 | import android.os.Bundle;
4 | import android.support.annotation.Nullable;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.util.Log;
7 |
8 | import com.zxy.recovery.core.ActivityStackCompat;
9 | import com.zxy.recovery.core.Recovery;
10 |
11 | /**
12 | * Created by zhengxiaoyong on 16/8/30.
13 | */
14 | public class BaseActivity extends AppCompatActivity {
15 | @Override
16 | protected void onCreate(@Nullable Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | }
19 |
20 | @Override
21 | protected void onStart() {
22 | super.onStart();
23 | getWindow().getDecorView().post(new Runnable() {
24 | @Override
25 | public void run() {
26 | int count = ActivityStackCompat.getActivityCount(Recovery.getInstance().getContext());
27 | Log.e("zxy", "realCount: " + count);
28 | String baseActivity = ActivityStackCompat.getBaseActivityName(Recovery.getInstance().getContext());
29 | Log.e("zxy", "realBaseActivityName: " + baseActivity);
30 | }
31 | });
32 |
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zxy/recovery/test/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.test;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | public class MainActivity extends BaseActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_main);
14 | }
15 |
16 | public void onClick(View view) {
17 | if (view.getId() == R.id.btn) {
18 | Activity activity = null;
19 | activity.finish();
20 | } else if (view.getId() == R.id.btn2) {
21 | Intent intent = new Intent(MainActivity.this, TestActivity.class);
22 | startActivity(intent);
23 | }
24 | }
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zxy/recovery/test/TestActivity.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.test;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 | import android.view.Window;
8 |
9 | public class TestActivity extends BaseActivity {
10 |
11 | @Override
12 | protected void onCreate(Bundle savedInstanceState) {
13 | requestWindowFeature(Window.FEATURE_NO_TITLE);
14 | super.onCreate(savedInstanceState);
15 | setContentView(R.layout.activity_test);
16 | // new Thread(new Runnable() {
17 | // int i = 0;
18 | //
19 | // @Override
20 | // public void run() {
21 | // while (true) {
22 | // if (i == 3) {
23 | // Activity activity = null;
24 | // activity.finish();
25 | // }
26 | // try {
27 | // Thread.sleep(1000);
28 | // } catch (InterruptedException e) {
29 | // e.printStackTrace();
30 | // }
31 | // i++;
32 | // }
33 | // }
34 | // }).start();
35 | }
36 |
37 | public void onClick(View view) {
38 | if (view.getId() == R.id.btn) {
39 | Activity activity = null;
40 | activity.finish();
41 | } else if (view.getId() == R.id.btn2) {
42 | Intent intent = new Intent(TestActivity.this, TestActivity2.class);
43 | startActivity(intent);
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/zxy/recovery/test/TestActivity2.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.test;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.view.View;
7 |
8 | public class TestActivity2 extends BaseActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.activity_test2);
14 | }
15 |
16 | public void onClick(View view) {
17 | if (view.getId() == R.id.btn) {
18 | Activity activity = null;
19 | activity.finish();
20 | } else if (view.getId() == R.id.btn2) {
21 | startActivity(new Intent(this, MainActivity.class));
22 | }
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
18 |
19 |
24 |
25 |
31 |
32 |
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_test.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
19 |
20 |
25 |
26 |
32 |
33 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_test2.xml:
--------------------------------------------------------------------------------
1 |
2 |
13 |
14 |
22 |
23 |
28 |
29 |
35 |
36 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/80945540/Recovery/64e11e186ac8a4e81e6c0c74ae6a40e9f1e101d1/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/80945540/Recovery/64e11e186ac8a4e81e6c0c74ae6a40e9f1e101d1/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/80945540/Recovery/64e11e186ac8a4e81e6c0c74ae6a40e9f1e101d1/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/80945540/Recovery/64e11e186ac8a4e81e6c0c74ae6a40e9f1e101d1/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/80945540/Recovery/64e11e186ac8a4e81e6c0c74ae6a40e9f1e101d1/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #3F51B5
4 | #303F9F
5 | #FF4081
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | RecoveryTest
3 | Main2Activity
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/app/src/test/java/com/zxy/recovery/test/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.test;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | mavenCentral()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:2.2.0-rc1'
10 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7'
11 | classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5'
12 | // NOTE: Do not place your application dependencies here; they belong
13 | // in the individual module build.gradle files
14 | }
15 | }
16 |
17 | allprojects {
18 | repositories {
19 | jcenter()
20 | mavenCentral()
21 | }
22 | }
23 |
24 | task clean(type: Delete) {
25 | delete rootProject.buildDir
26 | }
27 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/80945540/Recovery/64e11e186ac8a4e81e6c0c74ae6a40e9f1e101d1/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Aug 25 16:50:33 CST 2016
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/recovery/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/recovery/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 | apply plugin: 'com.github.dcendents.android-maven'
3 | apply plugin: 'com.jfrog.bintray'
4 | android {
5 | compileSdkVersion 24
6 | buildToolsVersion "24.0.0"
7 | resourcePrefix ""
8 | defaultConfig {
9 | minSdkVersion 14
10 | targetSdkVersion 24
11 | versionCode 1
12 | versionName "1.0"
13 |
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 |
16 | }
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | }
24 |
25 | dependencies {
26 | compile fileTree(include: ['*.jar'], dir: 'libs')
27 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
28 | exclude group: 'com.android.support', module: 'support-annotations'
29 | })
30 | compile 'com.android.support:appcompat-v7:24.2.0'
31 | testCompile 'junit:junit:4.12'
32 | }
33 |
34 | ext {
35 | upload_group_id = 'com.zxy.android'
36 | upload_version = '0.0.3'
37 |
38 | site_url = 'https://github.com/Sunzxyong/Recovery'
39 | git_url = 'https://github.com/Sunzxyong/Recovery.git'
40 | git_issue_url = 'https://github.com/Sunzxyong/Recovery/issues'
41 |
42 | bintray_pkg_repo = 'maven'
43 | bintray_pkg_name = 'Recovery'
44 | bintray_pkg_desc = 'A crash recover framework'
45 |
46 | developer_id = 'Sunzxyong'
47 | developer_name = 'zhengxiaoyong'
48 | developer_email = '1175151739@qq.com'
49 | }
50 |
51 | apply from: 'publish.gradle'
--------------------------------------------------------------------------------
/recovery/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/Sunzxyong/Library/Android/sdk/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 |
--------------------------------------------------------------------------------
/recovery/publish.gradle:
--------------------------------------------------------------------------------
1 | def siteUrl = project.site_url
2 | def gitUrl = project.git_url
3 | def issueUrl = project.git_issue_url
4 |
5 | group = project.upload_group_id
6 | version = project.upload_version
7 |
8 | Properties properties = new Properties()
9 | properties.load(project.rootProject.file('local.properties').newDataInputStream())
10 |
11 | bintray {
12 | user = properties.getProperty("bintray.user")
13 | key = properties.getProperty("bintray.apikey")
14 | configurations = ['archives']
15 | pkg {
16 | repo = project.bintray_pkg_repo
17 | name = project.bintray_pkg_name
18 | desc = project.bintray_pkg_desc
19 | websiteUrl = siteUrl
20 | issueTrackerUrl = issueUrl
21 | vcsUrl = gitUrl
22 | licenses = ['Apache-2.0']
23 | labels = ['aar', 'android', project.name]
24 | publish = true
25 | publicDownloadNumbers = true
26 | }
27 | }
28 |
29 | install {
30 | repositories.mavenInstaller {
31 | // This generates POM.xml with proper parameters
32 | pom {
33 | project {
34 | packaging 'aar'
35 | name project.bintray_pkg_name
36 | url siteUrl
37 |
38 | licenses {
39 | license {
40 | name 'The Apache Software License, Version 2.0'
41 | url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
42 | }
43 | }
44 | developers {
45 | developer {
46 | id project.developer_id
47 | name project.developer_name
48 | email project.developer_email
49 | }
50 | }
51 | scm {
52 | connection gitUrl
53 | developerConnection gitUrl
54 | url siteUrl
55 | }
56 | }
57 | }
58 | }
59 | }
60 |
61 | task sourcesJar(type: Jar) {
62 | from android.sourceSets.main.java.srcDirs
63 | classifier = 'sources'
64 | }
65 |
66 | task javadoc(type: Javadoc) {
67 | source = android.sourceSets.main.java.srcDirs
68 | classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
69 | }
70 |
71 | task javadocJar(type: Jar, dependsOn: javadoc) {
72 | classifier = 'javadoc'
73 | from javadoc.destinationDir
74 | }
75 | artifacts {
76 | archives javadocJar
77 | archives sourcesJar
78 | }
79 |
80 | task findConventions << {
81 | println project.getConvention()
82 | }
--------------------------------------------------------------------------------
/recovery/src/androidTest/java/com/zxy/recovery/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery;
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 execute 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("com.zxy.recovery.test", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/recovery/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
7 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/callback/RecoveryActivityLifecycleCallback.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.callback;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.content.Intent;
6 | import android.os.Bundle;
7 | import android.view.View;
8 | import android.view.Window;
9 |
10 | import com.zxy.recovery.core.Recovery;
11 | import com.zxy.recovery.core.RecoveryActivity;
12 | import com.zxy.recovery.core.RecoveryStore;
13 | import com.zxy.recovery.tools.Reflect;
14 |
15 | /**
16 | * Created by zhengxiaoyong on 16/8/28.
17 | */
18 | public class RecoveryActivityLifecycleCallback implements Application.ActivityLifecycleCallbacks {
19 |
20 | @Override
21 | public void onActivityCreated(final Activity activity, Bundle savedInstanceState) {
22 | boolean isLegal = RecoveryStore.getInstance().verifyActivity(activity);
23 | if (!isLegal)
24 | return;
25 | if (activity.getIntent().getBooleanExtra(RecoveryActivity.RECOVERY_MODE_ACTIVE, false)) {
26 | Reflect.on(Recovery.class).method("registerRecoveryProxy").invoke(Recovery.getInstance());
27 | }
28 | Window window = activity.getWindow();
29 | if (window != null) {
30 | View decorView = window.getDecorView();
31 | if (decorView == null)
32 | return;
33 | decorView.post(new Runnable() {
34 | @Override
35 | public void run() {
36 | RecoveryStore.getInstance().putActivity(activity);
37 | Object o = activity.getIntent().clone();
38 | RecoveryStore.getInstance().setIntent((Intent) o);
39 | }
40 | });
41 | }
42 | }
43 |
44 | @Override
45 | public void onActivityStarted(Activity activity) {
46 | }
47 |
48 | @Override
49 | public void onActivityResumed(Activity activity) {
50 | }
51 |
52 | @Override
53 | public void onActivityPaused(Activity activity) {
54 | }
55 |
56 | @Override
57 | public void onActivityStopped(Activity activity) {
58 | }
59 |
60 | @Override
61 | public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
62 |
63 | }
64 |
65 | @Override
66 | public void onActivityDestroyed(Activity activity) {
67 | RecoveryStore.getInstance().removeActivity(activity);
68 | }
69 |
70 | }
71 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/callback/RecoveryCallback.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.callback;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/8/29.
5 | */
6 | public interface RecoveryCallback {
7 |
8 | void stackTrace(String stackTrace);
9 |
10 | void cause(String cause);
11 |
12 | void exception(String throwExceptionType, String throwClassName, String throwMethodName, int throwLineNumber);
13 | }
14 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/core/ActivityManagerDelegate.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.core;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.text.TextUtils;
6 |
7 | import com.zxy.recovery.tools.RecoveryLog;
8 | import com.zxy.recovery.tools.RecoveryUtil;
9 |
10 | import java.lang.reflect.InvocationHandler;
11 | import java.lang.reflect.Method;
12 |
13 | /**
14 | * Created by zhengxiaoyong on 16/8/30.
15 | */
16 | class ActivityManagerDelegate implements InvocationHandler {
17 |
18 | private Object mBaseActivityManagerProxy;
19 |
20 | ActivityManagerDelegate(Object o) {
21 | this.mBaseActivityManagerProxy = o;
22 | }
23 |
24 | @Override
25 | public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
26 | String methodName = method.getName();
27 | switch (methodName) {
28 | case "finishActivity":
29 | // case "finishActivityAffinity":
30 | Class extends Activity> clazz = Recovery.getInstance().getMainPageClass();
31 | if (clazz == null)
32 | break;
33 | int count = ActivityStackCompat.getActivityCount(Recovery.getInstance().getContext());
34 | String baseActivityName = ActivityStackCompat.getBaseActivityName(Recovery.getInstance().getContext());
35 | if (TextUtils.isEmpty(baseActivityName))
36 | break;
37 | RecoveryLog.e("currentActivityCount: " + count);
38 | RecoveryLog.e("baseActivityName: " + baseActivityName);
39 | if (count == 1 && !clazz.getName().equals(baseActivityName)) {
40 | Intent intent = new Intent(Recovery.getInstance().getContext(), clazz);
41 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
42 | if (RecoveryUtil.isIntentAvailable(Recovery.getInstance().getContext(), intent))
43 | Recovery.getInstance().getContext().startActivity(intent);
44 | }
45 | break;
46 | default:
47 | break;
48 |
49 | }
50 |
51 | return method.invoke(mBaseActivityManagerProxy, args);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/core/ActivityStackCompat.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.core;
2 |
3 | import android.app.ActivityManager;
4 | import android.content.ComponentName;
5 | import android.content.Context;
6 | import android.os.Build;
7 |
8 | import java.util.List;
9 |
10 | /**
11 | * Created by zhengxiaoyong on 16/8/30.
12 | */
13 | public class ActivityStackCompat {
14 |
15 | private static ActivityManager.AppTask getTopTaskAfterL(Context context) {
16 | ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
17 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
18 | return activityManager.getAppTasks().get(0);
19 | return null;
20 | }
21 |
22 | private static ActivityManager.RunningTaskInfo getTopTaskBeforeL(Context context) {
23 | ActivityManager activityManager = (ActivityManager) context
24 | .getSystemService(Context.ACTIVITY_SERVICE);
25 | List tasks = null;
26 | try {
27 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
28 | tasks = activityManager.getRunningTasks(1);
29 | } catch (Exception e) {
30 | return null;
31 | }
32 | if (tasks == null || tasks.size() == 0)
33 | return null;
34 | return tasks.get(0);
35 | }
36 |
37 | /**
38 | * @param context Context.
39 | * @return Number of activities in this task.
40 | */
41 | public static int getActivityCount(Context context) {
42 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
43 | ActivityManager.AppTask appTask = getTopTaskAfterL(context);
44 | if (appTask == null)
45 | return 0;
46 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
47 | return appTask.getTaskInfo().numActivities;
48 | } else {
49 | //or mActivities
50 | return RecoveryStore.getInstance().getRunningActivityCount();
51 | }
52 | } else {
53 | ActivityManager.RunningTaskInfo taskInfo = getTopTaskBeforeL(context);
54 | if (taskInfo == null)
55 | return 0;
56 | return taskInfo.numActivities;
57 | }
58 | }
59 |
60 | public static String getBaseActivityName(Context context) {
61 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
62 | ActivityManager.AppTask appTask = getTopTaskAfterL(context);
63 | if (appTask == null)
64 | return null;
65 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
66 | return appTask.getTaskInfo().baseActivity.getClassName();
67 | } else {
68 | ComponentName componentName = RecoveryStore.getInstance().getBaseActivity();
69 | return componentName == null ? null : componentName.getClassName();
70 | }
71 | } else {
72 | ActivityManager.RunningTaskInfo taskInfo = getTopTaskBeforeL(context);
73 | if (taskInfo == null)
74 | return null;
75 | return taskInfo.baseActivity.getClassName();
76 | }
77 | }
78 |
79 | }
80 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/core/CrashData.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.core;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/8/30.
5 | */
6 | public class CrashData {
7 |
8 | public long crashTime;
9 |
10 | public int crashCount;
11 |
12 | public boolean shouldRestart;
13 |
14 | private CrashData() {
15 | }
16 |
17 | public static CrashData newInstance() {
18 | return new CrashData();
19 | }
20 |
21 | public CrashData time(long time) {
22 | this.crashTime = time;
23 | return this;
24 | }
25 |
26 | public CrashData count(int count) {
27 | this.crashCount = count;
28 | return this;
29 | }
30 |
31 | public CrashData restart(boolean restart) {
32 | this.shouldRestart = restart;
33 | return this;
34 | }
35 |
36 | @Override
37 | public String toString() {
38 | return "CrashData{" +
39 | "crashCount=" + crashCount +
40 | ", crashTime=" + crashTime +
41 | ", shouldRestart=" + shouldRestart +
42 | '}';
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/core/Recovery.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.core;
2 |
3 | import android.app.Activity;
4 | import android.app.Application;
5 | import android.content.Context;
6 | import android.os.Build;
7 |
8 | import com.zxy.recovery.callback.RecoveryActivityLifecycleCallback;
9 | import com.zxy.recovery.callback.RecoveryCallback;
10 | import com.zxy.recovery.exception.RecoveryException;
11 | import com.zxy.recovery.tools.RecoveryLog;
12 | import com.zxy.recovery.tools.RecoveryUtil;
13 |
14 | /**
15 | * Created by zhengxiaoyong on 16/8/26.
16 | */
17 | public class Recovery {
18 |
19 | private volatile static Recovery sInstance;
20 |
21 | private static final Object LOCK = new Object();
22 |
23 | private Context mContext;
24 |
25 | private boolean isDebug = false;
26 |
27 | /**
28 | * The default to restore the stack.
29 | */
30 | private boolean isRecoverStack = true;
31 |
32 | /**
33 | * The default is not restore the background process.
34 | */
35 | private boolean isRecoverInBackground = false;
36 |
37 | private Class extends Activity> mMainPageClass;
38 |
39 | private RecoveryCallback mCallback;
40 |
41 | private Recovery() {
42 | }
43 |
44 | public static Recovery getInstance() {
45 | if (sInstance == null) {
46 | synchronized (LOCK) {
47 | if (sInstance == null) {
48 | sInstance = new Recovery();
49 | }
50 | }
51 | }
52 | return sInstance;
53 | }
54 |
55 | public void init(Context context) {
56 | if (context == null)
57 | throw new RecoveryException("Context can not be null!");
58 | if (!(context instanceof Application))
59 | context = context.getApplicationContext();
60 | mContext = context;
61 | registerRecoveryHandler();
62 | registerRecoveryLifecycleCallback();
63 | }
64 |
65 | public Recovery debug(boolean isDebug) {
66 | this.isDebug = isDebug;
67 | return this;
68 | }
69 |
70 | public Recovery recoverStack(boolean isRecoverStack) {
71 | this.isRecoverStack = isRecoverStack;
72 | return this;
73 | }
74 |
75 | public Recovery recoverInBackground(boolean isRecoverInBackground) {
76 | this.isRecoverInBackground = isRecoverInBackground;
77 | return this;
78 | }
79 |
80 | public Recovery mainPage(Class extends Activity> clazz) {
81 | this.mMainPageClass = clazz;
82 | return this;
83 | }
84 |
85 | public Recovery callback(RecoveryCallback callback) {
86 | this.mCallback = callback;
87 | return this;
88 | }
89 |
90 | private void registerRecoveryHandler() {
91 | RecoveryHandler.newInstance(Thread.getDefaultUncaughtExceptionHandler()).setCallback(mCallback).register();
92 | }
93 |
94 | private void registerRecoveryLifecycleCallback() {
95 | ((Application) mContext).registerActivityLifecycleCallbacks(new RecoveryActivityLifecycleCallback());
96 | }
97 |
98 | private void registerRecoveryProxy() {
99 | //OS version in the 5.0 ~ 6.0 don`t register agent
100 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Build.VERSION.SDK_INT < Build.VERSION_CODES.M)
101 | return;
102 | if (mMainPageClass == null)
103 | return;
104 | if (!RecoveryUtil.isMainProcess(RecoveryUtil.checkNotNull(mContext, "The context is not initialized")))
105 | return;
106 | new Thread(new Runnable() {
107 | @Override
108 | public void run() {
109 | while (true) {
110 | boolean isSuccess = RecoveryComponentHook.hookActivityManagerProxy();
111 | RecoveryLog.e("hook is success:" + isSuccess);
112 | if (isSuccess)
113 | break;
114 | }
115 | }
116 | }).start();
117 | }
118 |
119 | public Context getContext() {
120 | return RecoveryUtil.checkNotNull(mContext, "The context is not initialized");
121 | }
122 |
123 | public boolean isDebug() {
124 | return isDebug;
125 | }
126 |
127 | boolean isRecoverInBackground() {
128 | return isRecoverInBackground;
129 | }
130 |
131 | boolean isRecoverStack() {
132 | return isRecoverStack;
133 | }
134 |
135 | Class extends Activity> getMainPageClass() {
136 | return mMainPageClass;
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/core/RecoveryActivity.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.core;
2 |
3 | import android.content.DialogInterface;
4 | import android.content.Intent;
5 | import android.os.Bundle;
6 | import android.support.v7.app.AlertDialog;
7 | import android.support.v7.app.AppCompatActivity;
8 | import android.support.v7.widget.Toolbar;
9 | import android.view.KeyEvent;
10 | import android.view.Menu;
11 | import android.view.MenuItem;
12 | import android.view.View;
13 | import android.widget.Button;
14 | import android.widget.ImageButton;
15 | import android.widget.TextView;
16 | import android.widget.Toast;
17 |
18 | import com.zxy.recovery.R;
19 | import com.zxy.recovery.tools.RecoverySharedPrefsUtil;
20 | import com.zxy.recovery.tools.RecoveryUtil;
21 | import com.zxy.recovery.tools.Reflect;
22 |
23 | import java.io.File;
24 | import java.io.FileWriter;
25 | import java.io.IOException;
26 | import java.text.SimpleDateFormat;
27 | import java.util.ArrayList;
28 | import java.util.Date;
29 | import java.util.Locale;
30 |
31 | /**
32 | * Created by zhengxiaoyong on 16/8/26.
33 | */
34 | public final class RecoveryActivity extends AppCompatActivity {
35 |
36 | public static final String RECOVERY_MODE_ACTIVE = "recovery_mode_active";
37 |
38 | private static final String DEFAULT_CRASH_FILE_DIR_NAME = "recovery_crash";
39 |
40 | private boolean isDebugMode = false;
41 |
42 | private boolean isDebugModeActive = false;
43 |
44 | private RecoveryStore.ExceptionData mExceptionData;
45 |
46 | private Toolbar mToolbar;
47 |
48 | private String mStackTrace;
49 |
50 | private String mCause;
51 |
52 | private Button mRecoverBtn;
53 |
54 | private Button mRestartBtn;
55 |
56 | private Button mRestartClearBtn;
57 |
58 | private View mMainLayout;
59 |
60 | private View mDebugLayout;
61 |
62 | private TextView mExceptionTypeTv;
63 |
64 | private TextView mClassNameTv;
65 |
66 | private TextView mMethodNameTv;
67 |
68 | private TextView mLineNumberTv;
69 |
70 | private TextView mStackTraceTv;
71 |
72 | private TextView mCauseTv;
73 |
74 | private TextView mCrashTipsTv;
75 |
76 | @Override
77 | protected void onCreate(Bundle savedInstanceState) {
78 | super.onCreate(savedInstanceState);
79 | setContentView(R.layout.activity_recovery);
80 | setupToolbar();
81 | initView();
82 | initData();
83 | setupEvent();
84 | }
85 |
86 | private void setupToolbar() {
87 | mToolbar = (Toolbar) findViewById(R.id.toolbar);
88 | setSupportActionBar(mToolbar);
89 | if (getSupportActionBar() != null)
90 | getSupportActionBar().setDisplayShowTitleEnabled(false);
91 | mToolbar.setTitle(RecoveryUtil.getAppName(this));
92 | mToolbar.setNavigationOnClickListener(new View.OnClickListener() {
93 | @Override
94 | public void onClick(View v) {
95 | isDebugModeActive = false;
96 | showMainView();
97 | setDisplayHomeAsUpEnabled(false);
98 | }
99 | });
100 | }
101 |
102 | @Override
103 | public boolean onCreateOptionsMenu(Menu menu) {
104 | if (!isDebugMode)
105 | return false;
106 | if (isDebugModeActive) {
107 | getMenuInflater().inflate(R.menu.menu_recovery_sub, menu);
108 | return true;
109 | }
110 | getMenuInflater().inflate(R.menu.menu_recovery, menu);
111 | return true;
112 | }
113 |
114 | @Override
115 | public boolean onOptionsItemSelected(MenuItem item) {
116 | int id = item.getItemId();
117 | if (id == R.id.action_debug) {
118 | isDebugModeActive = true;
119 | showDebugView();
120 | setDisplayHomeAsUpEnabled(true);
121 | } else if (id == R.id.action_save) {
122 | boolean isSuccess = saveCrashData();
123 | Toast.makeText(this, isSuccess ? "Save success!" : "Save failed!", Toast.LENGTH_SHORT).show();
124 | }
125 | return super.onOptionsItemSelected(item);
126 | }
127 |
128 | private void initView() {
129 | mMainLayout = findViewById(R.id.recovery_main_layout);
130 | mDebugLayout = findViewById(R.id.recovery_debug_layout);
131 | mRecoverBtn = (Button) findViewById(R.id.btn_recover);
132 | mRestartBtn = (Button) findViewById(R.id.btn_restart);
133 | mRestartClearBtn = (Button) findViewById(R.id.btn_restart_clear);
134 | mExceptionTypeTv = (TextView) findViewById(R.id.tv_type);
135 | mClassNameTv = (TextView) findViewById(R.id.tv_class_name);
136 | mMethodNameTv = (TextView) findViewById(R.id.tv_method_name);
137 | mLineNumberTv = (TextView) findViewById(R.id.tv_line_number);
138 | mStackTraceTv = (TextView) findViewById(R.id.tv_stack_trace);
139 | mCauseTv = (TextView) findViewById(R.id.tv_cause);
140 | mCrashTipsTv = (TextView) findViewById(R.id.tv_crash_tips);
141 | }
142 |
143 | private void initData() {
144 | isDebugMode = isDebugMode();
145 | if (isDebugMode)
146 | invalidateOptionsMenu();
147 | mExceptionData = getExceptionData();
148 | mCause = getCause();
149 | mStackTrace = getStackTrace();
150 | }
151 |
152 | private void setupEvent() {
153 | mRecoverBtn.setOnClickListener(new View.OnClickListener() {
154 | @Override
155 | public void onClick(View v) {
156 | boolean restart = RecoverySharedPrefsUtil.shouldRestartApp();
157 | if (restart) {
158 | RecoverySharedPrefsUtil.clear();
159 | restart();
160 | return;
161 | }
162 | if (isRecoverStack()) {
163 | recoverActivityStack();
164 | } else {
165 | recoverTopActivity();
166 | }
167 | }
168 | });
169 |
170 | mRestartBtn.setOnClickListener(new View.OnClickListener() {
171 | @Override
172 | public void onClick(View v) {
173 | boolean restart = RecoverySharedPrefsUtil.shouldRestartApp();
174 | if (restart)
175 | RecoverySharedPrefsUtil.clear();
176 | restart();
177 | }
178 | });
179 |
180 | mRestartClearBtn.setOnClickListener(new View.OnClickListener() {
181 | @Override
182 | public void onClick(View v) {
183 | AlertDialog dialog = new AlertDialog.Builder(RecoveryActivity.this)
184 | .setTitle(getResources().getString(R.string.recovery_dialog_tips))
185 | .setMessage(getResources().getString(R.string.recovery_dialog_tips_msg))
186 | .setPositiveButton(getResources().getString(R.string.recovery_dialog_sure), new DialogInterface.OnClickListener() {
187 | @Override
188 | public void onClick(DialogInterface dialog, int which) {
189 | if (dialog != null)
190 | dialog.dismiss();
191 | RecoveryUtil.clearApplicationData();
192 | restart();
193 | }
194 | }).setNegativeButton(getResources().getString(R.string.recovery_dialog_cancel), new DialogInterface.OnClickListener() {
195 | @Override
196 | public void onClick(DialogInterface dialog, int which) {
197 | if (dialog != null)
198 | dialog.dismiss();
199 | }
200 | }).create();
201 | dialog.setCanceledOnTouchOutside(false);
202 | dialog.show();
203 | }
204 | });
205 |
206 | mCrashTipsTv.setText(String.format(getResources().getString(R.string.recovery_crash_tips_msg), RecoveryUtil.getAppName(this)));
207 |
208 | if (mExceptionData != null) {
209 | String type = mExceptionData.type == null ? "" : mExceptionData.type;
210 | String name = mExceptionData.className == null ? "" : mExceptionData.className;
211 | mExceptionTypeTv.setText(String.format(getResources().getString(R.string.recovery_exception_type), type.substring(type.lastIndexOf('.') + 1)));
212 | mClassNameTv.setText(String.format(getResources().getString(R.string.recovery_class_name), name.substring(name.lastIndexOf('.') + 1)));
213 | mMethodNameTv.setText(String.format(getResources().getString(R.string.recovery_method_name), mExceptionData.methodName));
214 | mLineNumberTv.setText(String.format(getResources().getString(R.string.recovery_line_number), mExceptionData.lineNumber));
215 | }
216 | mCauseTv.setText(String.valueOf(mCause));
217 | mStackTraceTv.setText(String.valueOf(mStackTrace));
218 | }
219 |
220 | private boolean isDebugMode() {
221 | return getIntent().getBooleanExtra(RecoveryStore.IS_DEBUG, false);
222 | }
223 |
224 | private RecoveryStore.ExceptionData getExceptionData() {
225 | return getIntent().getParcelableExtra(RecoveryStore.EXCEPTION_DATA);
226 | }
227 |
228 | private String getCause() {
229 | return getIntent().getStringExtra(RecoveryStore.EXCEPTION_CAUSE);
230 | }
231 |
232 | private String getStackTrace() {
233 | return getIntent().getStringExtra(RecoveryStore.STACK_TRACE);
234 | }
235 |
236 | private void restart() {
237 | Intent launchIntent = getApplication().getPackageManager().getLaunchIntentForPackage(this.getPackageName());
238 | if (launchIntent != null) {
239 | launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
240 | startActivity(launchIntent);
241 | overridePendingTransition(0, 0);
242 | }
243 | finish();
244 | }
245 |
246 | private void recoverTopActivity() {
247 | Intent intent = getRecoveryIntent();
248 | if (intent != null && RecoveryUtil.isIntentAvailable(this, intent)) {
249 | intent.setExtrasClassLoader(getClassLoader());
250 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
251 | intent.putExtra(RECOVERY_MODE_ACTIVE, true);
252 | startActivity(intent);
253 | overridePendingTransition(0, 0);
254 | finish();
255 | return;
256 | }
257 | restart();
258 | }
259 |
260 | private boolean isRecoverStack() {
261 | boolean hasRecoverStack = getIntent().hasExtra(RecoveryStore.RECOVERY_STACK);
262 | return !hasRecoverStack || getIntent().getBooleanExtra(RecoveryStore.RECOVERY_STACK, true);
263 | }
264 |
265 | private void recoverActivityStack() {
266 | ArrayList intents = getRecoveryIntents();
267 | if (intents != null && !intents.isEmpty()) {
268 | ArrayList availableIntents = new ArrayList<>();
269 | for (Intent tmp : intents) {
270 | if (tmp != null && RecoveryUtil.isIntentAvailable(this, tmp)) {
271 | tmp.setExtrasClassLoader(getClassLoader());
272 | availableIntents.add(tmp);
273 | }
274 | }
275 | if (!availableIntents.isEmpty()) {
276 | availableIntents.get(availableIntents.size() - 1).putExtra(RECOVERY_MODE_ACTIVE, true);
277 | startActivities(availableIntents.toArray(new Intent[availableIntents.size()]));
278 | overridePendingTransition(0, 0);
279 | finish();
280 | return;
281 | }
282 | }
283 | restart();
284 | }
285 |
286 | private Intent getRecoveryIntent() {
287 | boolean hasRecoverIntent = getIntent().hasExtra(RecoveryStore.RECOVERY_INTENT);
288 | if (!hasRecoverIntent)
289 | return null;
290 | return getIntent().getParcelableExtra(RecoveryStore.RECOVERY_INTENT);
291 | }
292 |
293 | private ArrayList getRecoveryIntents() {
294 | boolean hasRecoveryIntents = getIntent().hasExtra(RecoveryStore.RECOVERY_INTENTS);
295 | if (!hasRecoveryIntents)
296 | return null;
297 | return getIntent().getParcelableArrayListExtra(RecoveryStore.RECOVERY_INTENTS);
298 | }
299 |
300 | private boolean saveCrashData() {
301 | SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA);
302 | String date = format.format(new Date(System.currentTimeMillis()));
303 | File dir = new File(getExternalFilesDir(null) + File.separator + DEFAULT_CRASH_FILE_DIR_NAME);
304 | if (!dir.exists())
305 | dir.mkdirs();
306 | File file = new File(dir, String.valueOf(date) + ".txt");
307 | FileWriter writer = null;
308 | try {
309 | writer = new FileWriter(file);
310 | writer.write("\nException:\n" + (mExceptionData == null ? null : mExceptionData.toString()) + "\n\n");
311 | writer.write("Cause:\n" + mCause + "\n\n");
312 | writer.write("StackTrace:\n" + mStackTrace + "\n\n");
313 | writer.flush();
314 | } catch (IOException e) {
315 | e.printStackTrace();
316 | return false;
317 | } finally {
318 | if (writer != null)
319 | try {
320 | writer.close();
321 | } catch (IOException e) {
322 | e.printStackTrace();
323 | }
324 | }
325 | return true;
326 | }
327 |
328 | private void killProcess() {
329 | android.os.Process.killProcess(android.os.Process.myPid());
330 | System.exit(10);
331 | }
332 |
333 | private void setDisplayHomeAsUpEnabled(boolean enabled) {
334 | if (getSupportActionBar() != null)
335 | getSupportActionBar().setDisplayHomeAsUpEnabled(enabled);
336 | final ImageButton navButton = (ImageButton) Reflect.on(Toolbar.class).field("mNavButtonView").get(mToolbar);
337 | if (navButton != null) {
338 | if (enabled) {
339 | navButton.setVisibility(View.VISIBLE);
340 | } else {
341 | navButton.setVisibility(View.GONE);
342 | }
343 | }
344 | invalidateOptionsMenu();
345 | }
346 |
347 | private void showDebugView() {
348 | mMainLayout.setVisibility(View.GONE);
349 | mDebugLayout.setVisibility(View.VISIBLE);
350 | }
351 |
352 | private void showMainView() {
353 | mMainLayout.setVisibility(View.VISIBLE);
354 | mDebugLayout.setVisibility(View.GONE);
355 | }
356 |
357 | @Override
358 | public boolean onKeyDown(int keyCode, KeyEvent event) {
359 | if (event.getKeyCode() == KeyEvent.KEYCODE_BACK && isDebugModeActive) {
360 | isDebugModeActive = false;
361 | showMainView();
362 | setDisplayHomeAsUpEnabled(false);
363 | return true;
364 | }
365 | return super.onKeyDown(keyCode, event);
366 | }
367 |
368 | @Override
369 | protected void onStop() {
370 | super.onStop();
371 | finish();
372 | }
373 |
374 | @Override
375 | public void finish() {
376 | super.finish();
377 | killProcess();
378 | }
379 |
380 | }
381 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/core/RecoveryComponentHook.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.core;
2 |
3 | import com.zxy.recovery.tools.RecoveryLog;
4 | import com.zxy.recovery.tools.Reflect;
5 |
6 | import java.lang.reflect.Proxy;
7 |
8 | /**
9 | * Created by zhengxiaoyong on 16/8/30.
10 | */
11 | final class RecoveryComponentHook {
12 |
13 | static boolean hookActivityManagerProxy() {
14 | //Singleton
15 | Object gDefault = Reflect.on("android.app.ActivityManagerNative").field("gDefault").get(null);
16 | if (gDefault == null)
17 | return false;
18 | Object currentActivityManagerProxy = Reflect.on("android.util.Singleton").field("mInstance").get(gDefault);
19 | if (currentActivityManagerProxy == null)
20 | return false;
21 | try {
22 | ActivityManagerDelegate delegate = new ActivityManagerDelegate(currentActivityManagerProxy);
23 | if (currentActivityManagerProxy.getClass().isInstance(delegate))
24 | return true;
25 | Class>[] interfaces = Class.forName("android.app.ActivityManagerNative").getInterfaces();
26 | Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(), interfaces, delegate);
27 | Reflect.on("android.util.Singleton").field("mInstance").set(gDefault, proxy);
28 | } catch (ClassNotFoundException e) {
29 | e.printStackTrace();
30 | RecoveryLog.e(e.toString());
31 | }
32 | return true;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/core/RecoveryHandler.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.core;
2 |
3 | import android.content.Intent;
4 | import android.text.TextUtils;
5 |
6 | import com.zxy.recovery.callback.RecoveryCallback;
7 | import com.zxy.recovery.tools.DefaultHandlerUtil;
8 | import com.zxy.recovery.tools.RecoverySharedPrefsUtil;
9 | import com.zxy.recovery.tools.RecoveryUtil;
10 |
11 | import java.io.PrintWriter;
12 | import java.io.StringWriter;
13 |
14 | /**
15 | * Created by zhengxiaoyong on 16/8/26.
16 | */
17 | final class RecoveryHandler implements Thread.UncaughtExceptionHandler {
18 |
19 | private Thread.UncaughtExceptionHandler mDefaultUncaughtExceptionHandler;
20 |
21 | private RecoveryCallback mCallback;
22 |
23 | private RecoveryStore.ExceptionData mExceptionData;
24 |
25 | private String mStackTrace;
26 |
27 | private String mCause;
28 |
29 | private RecoveryHandler(Thread.UncaughtExceptionHandler defHandler) {
30 | mDefaultUncaughtExceptionHandler = defHandler;
31 | }
32 |
33 | static RecoveryHandler newInstance(Thread.UncaughtExceptionHandler defHandler) {
34 | return new RecoveryHandler(defHandler);
35 | }
36 |
37 | @Override
38 | public synchronized void uncaughtException(Thread t, Throwable e) {
39 |
40 | RecoverySharedPrefsUtil.recordCrashData();
41 |
42 | StringWriter sw = new StringWriter();
43 | PrintWriter pw = new PrintWriter(sw);
44 | e.printStackTrace(pw);
45 | pw.flush();
46 |
47 | String stackTrace = sw.toString();
48 | String cause = e.getMessage();
49 | Throwable rootTr = e;
50 | while (e.getCause() != null) {
51 | e = e.getCause();
52 | if (e.getStackTrace() != null && e.getStackTrace().length > 0)
53 | rootTr = e;
54 | String msg = e.getMessage();
55 | if (!TextUtils.isEmpty(msg))
56 | cause = msg;
57 | }
58 |
59 | String exceptionType = rootTr.getClass().getName();
60 |
61 | String throwClassName;
62 | String throwMethodName;
63 | int throwLineNumber;
64 |
65 | if (rootTr.getStackTrace().length > 0) {
66 | StackTraceElement trace = rootTr.getStackTrace()[0];
67 | throwClassName = trace.getClassName();
68 | throwMethodName = trace.getMethodName();
69 | throwLineNumber = trace.getLineNumber();
70 | } else {
71 | throwClassName = "unknown";
72 | throwMethodName = "unknown";
73 | throwLineNumber = 0;
74 | }
75 |
76 | mExceptionData = RecoveryStore.ExceptionData.newInstance()
77 | .type(exceptionType)
78 | .className(throwClassName)
79 | .methodName(throwMethodName)
80 | .lineNumber(throwLineNumber);
81 |
82 | mStackTrace = stackTrace;
83 | mCause = cause;
84 |
85 | if (mCallback != null) {
86 | mCallback.stackTrace(stackTrace);
87 | mCallback.cause(cause);
88 | mCallback.exception(exceptionType, throwClassName, throwMethodName, throwLineNumber);
89 | }
90 |
91 | if (!DefaultHandlerUtil.isSystemDefaultUncaughtExceptionHandler(mDefaultUncaughtExceptionHandler)) {
92 | if (mDefaultUncaughtExceptionHandler == null)
93 | startRecoverActivity();
94 | mDefaultUncaughtExceptionHandler.uncaughtException(t, e);
95 | } else {
96 | startRecoverActivity();
97 | }
98 | }
99 |
100 | RecoveryHandler setCallback(RecoveryCallback callback) {
101 | mCallback = callback;
102 | return this;
103 | }
104 |
105 | private void startRecoverActivity() {
106 | if (RecoveryUtil.isAppInBackground(Recovery.getInstance().getContext())
107 | && !Recovery.getInstance().isRecoverInBackground()) {
108 | killProcess();
109 | return;
110 | }
111 | Intent intent = new Intent();
112 | intent.setClass(Recovery.getInstance().getContext(), RecoveryActivity.class);
113 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
114 | if (RecoveryStore.getInstance().getIntent() != null)
115 | intent.putExtra(RecoveryStore.RECOVERY_INTENT, RecoveryStore.getInstance().getIntent());
116 | if (!RecoveryStore.getInstance().getIntents().isEmpty())
117 | intent.putParcelableArrayListExtra(RecoveryStore.RECOVERY_INTENTS, RecoveryStore.getInstance().getIntents());
118 | intent.putExtra(RecoveryStore.RECOVERY_STACK, Recovery.getInstance().isRecoverStack());
119 | intent.putExtra(RecoveryStore.IS_DEBUG, Recovery.getInstance().isDebug());
120 | if (mExceptionData != null)
121 | intent.putExtra(RecoveryStore.EXCEPTION_DATA, mExceptionData);
122 | if (mStackTrace != null)
123 | intent.putExtra(RecoveryStore.STACK_TRACE, mStackTrace);
124 | if (mCause != null)
125 | intent.putExtra(RecoveryStore.EXCEPTION_CAUSE, mCause);
126 | Recovery.getInstance().getContext().startActivity(intent);
127 | killProcess();
128 | }
129 |
130 | void register() {
131 | Thread.setDefaultUncaughtExceptionHandler(this);
132 | }
133 |
134 | private void killProcess() {
135 | android.os.Process.killProcess(android.os.Process.myPid());
136 | System.exit(10);
137 | }
138 |
139 | }
140 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/core/RecoveryStore.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.core;
2 |
3 | import android.app.Activity;
4 | import android.content.ComponentName;
5 | import android.content.Intent;
6 | import android.os.Parcel;
7 | import android.os.Parcelable;
8 |
9 | import java.lang.ref.WeakReference;
10 | import java.util.ArrayList;
11 | import java.util.List;
12 | import java.util.concurrent.CopyOnWriteArrayList;
13 | import java.util.concurrent.atomic.AtomicInteger;
14 |
15 | /**
16 | * Created by zhengxiaoyong on 16/8/28.
17 | */
18 | public final class RecoveryStore {
19 |
20 | static final String RECOVERY_INTENT = "recovery_intent";
21 |
22 | static final String RECOVERY_INTENTS = "recovery_intents";
23 |
24 | static final String RECOVERY_STACK = "recovery_stack";
25 |
26 | static final String IS_DEBUG = "recovery_is_debug";
27 |
28 | static final String STACK_TRACE = "recovery_stack_trace";
29 |
30 | static final String EXCEPTION_DATA = "recovery_exception_data";
31 |
32 | static final String EXCEPTION_CAUSE = "recovery_exception_cause";
33 |
34 | private volatile static RecoveryStore sInstance;
35 |
36 | private static final Object LOCK = new Object();
37 |
38 | private List> mRunningActivities;
39 |
40 | private Intent mIntent;
41 |
42 | private RecoveryStore() {
43 | mRunningActivities = new CopyOnWriteArrayList<>();
44 | }
45 |
46 | public static RecoveryStore getInstance() {
47 | if (sInstance == null) {
48 | synchronized (LOCK) {
49 | if (sInstance == null) {
50 | sInstance = new RecoveryStore();
51 | }
52 | }
53 | }
54 | return sInstance;
55 | }
56 |
57 | public Intent getIntent() {
58 | return mIntent;
59 | }
60 |
61 | public synchronized void setIntent(Intent intent) {
62 | mIntent = intent;
63 | }
64 |
65 | public boolean verifyActivity(Activity activity) {
66 | return activity != null && !RecoveryActivity.class.isInstance(activity);
67 | }
68 |
69 | public List> getRunningActivities() {
70 | return mRunningActivities;
71 | }
72 |
73 | public void putActivity(Activity activity) {
74 | WeakReference weakReference = new WeakReference<>(activity);
75 | mRunningActivities.add(weakReference);
76 | }
77 |
78 | public void removeActivity(Activity activity) {
79 | for (WeakReference activityWeakReference : mRunningActivities) {
80 | if (activityWeakReference == null)
81 | continue;
82 | Activity tmpActivity = activityWeakReference.get();
83 | if (tmpActivity == null)
84 | continue;
85 | if (tmpActivity == activity) {
86 | mRunningActivities.remove(activityWeakReference);
87 | break;
88 | }
89 | }
90 | }
91 |
92 | int getRunningActivityCount() {
93 | AtomicInteger count = new AtomicInteger(0);
94 | for (WeakReference activityWeakReference : mRunningActivities) {
95 | if (activityWeakReference == null)
96 | continue;
97 | Activity activity = activityWeakReference.get();
98 | if (activity == null)
99 | continue;
100 | count.set(count.incrementAndGet());
101 | }
102 | return count.get();
103 | }
104 |
105 | ComponentName getBaseActivity() {
106 | for (WeakReference activityWeakReference : mRunningActivities) {
107 | if (activityWeakReference == null)
108 | continue;
109 | Activity tmpActivity = activityWeakReference.get();
110 | if (tmpActivity == null)
111 | continue;
112 | return tmpActivity.getComponentName();
113 | }
114 | return null;
115 | }
116 |
117 | ArrayList getIntents() {
118 | ArrayList intentList = new ArrayList<>();
119 | for (WeakReference activityWeakReference : mRunningActivities) {
120 | if (activityWeakReference == null)
121 | continue;
122 | Activity tmpActivity = activityWeakReference.get();
123 | if (tmpActivity == null)
124 | continue;
125 | intentList.add((Intent) tmpActivity.getIntent().clone());
126 | }
127 | return intentList;
128 | }
129 |
130 | static final class ExceptionData implements Parcelable {
131 | String type;
132 | String className;
133 | String methodName;
134 | int lineNumber;
135 |
136 | @Override
137 | public int describeContents() {
138 | return 0;
139 | }
140 |
141 | @Override
142 | public void writeToParcel(Parcel dest, int flags) {
143 | dest.writeString(this.type);
144 | dest.writeString(this.className);
145 | dest.writeString(this.methodName);
146 | dest.writeInt(this.lineNumber);
147 | }
148 |
149 | ExceptionData() {
150 | }
151 |
152 | public static ExceptionData newInstance() {
153 | return new ExceptionData();
154 | }
155 |
156 | public ExceptionData type(String type) {
157 | this.type = type;
158 | return this;
159 | }
160 |
161 | public ExceptionData className(String className) {
162 | this.className = className;
163 | return this;
164 | }
165 |
166 | public ExceptionData methodName(String methodName) {
167 | this.methodName = methodName;
168 | return this;
169 | }
170 |
171 | public ExceptionData lineNumber(int lineNumber) {
172 | this.lineNumber = lineNumber;
173 | return this;
174 | }
175 |
176 | protected ExceptionData(Parcel in) {
177 | this.type = in.readString();
178 | this.className = in.readString();
179 | this.methodName = in.readString();
180 | this.lineNumber = in.readInt();
181 | }
182 |
183 | public static final Creator CREATOR = new Creator() {
184 | @Override
185 | public ExceptionData createFromParcel(Parcel source) {
186 | return new ExceptionData(source);
187 | }
188 |
189 | @Override
190 | public ExceptionData[] newArray(int size) {
191 | return new ExceptionData[size];
192 | }
193 | };
194 |
195 | @Override
196 | public String toString() {
197 | return "ExceptionData{" +
198 | "className='" + className + '\'' +
199 | ", type='" + type + '\'' +
200 | ", methodName='" + methodName + '\'' +
201 | ", lineNumber=" + lineNumber +
202 | '}';
203 | }
204 | }
205 | }
206 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/exception/RecoveryException.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.exception;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/8/28.
5 | */
6 | public class RecoveryException extends RuntimeException {
7 | public RecoveryException(String message) {
8 | super(message);
9 | }
10 |
11 | public RecoveryException(String message, Throwable cause) {
12 | super(message, cause);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/exception/ReflectException.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.exception;
2 |
3 | /**
4 | * Created by zhengxiaoyong on 16/8/28.
5 | */
6 | public class ReflectException extends RuntimeException {
7 | public ReflectException() {
8 | super();
9 | }
10 |
11 | public ReflectException(String detailMessage) {
12 | super(detailMessage);
13 | }
14 |
15 | public ReflectException(String detailMessage, Throwable throwable) {
16 | super(detailMessage, throwable);
17 | }
18 |
19 | public ReflectException(Throwable throwable) {
20 | super(throwable);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/tools/DefaultHandlerUtil.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.tools;
2 |
3 |
4 | import com.zxy.recovery.exception.RecoveryException;
5 |
6 | /**
7 | * Created by zgxiaoyong on 16/8/28.
8 | */
9 | public class DefaultHandlerUtil {
10 |
11 | private DefaultHandlerUtil() {
12 | throw new RecoveryException("Stub!");
13 | }
14 |
15 | private static Thread.UncaughtExceptionHandler getDefaultUncaughtExceptionHandler() {
16 | Object object = Reflect.on("com.android.internal.os.RuntimeInit$UncaughtHandler").constructor().newInstance();
17 | return object == null ? null : (Thread.UncaughtExceptionHandler) object;
18 | }
19 |
20 | public static boolean isSystemDefaultUncaughtExceptionHandler(Thread.UncaughtExceptionHandler handler) {
21 | Thread.UncaughtExceptionHandler defHandler = getDefaultUncaughtExceptionHandler();
22 | return defHandler != null && defHandler.getClass().isInstance(handler);
23 | }
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/tools/RecoveryLog.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.tools;
2 |
3 | import android.util.Log;
4 |
5 | import com.zxy.recovery.core.Recovery;
6 |
7 | /**
8 | * Created by zhengxiaoyong on 16/8/26.
9 | */
10 | public class RecoveryLog {
11 |
12 | private static final String TAG = "Recovery";
13 |
14 | public static void e(String message) {
15 | if (Recovery.getInstance().isDebug())
16 | Log.e(TAG, message);
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/tools/RecoverySharedPrefsUtil.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.tools;
2 |
3 | import com.zxy.recovery.core.CrashData;
4 | import com.zxy.recovery.core.Recovery;
5 | import com.zxy.recovery.exception.RecoveryException;
6 |
7 | /**
8 | * Created by zhengxiaoyong on 16/8/27.
9 | */
10 | public class RecoverySharedPrefsUtil {
11 |
12 | private static final long DEFAULT_TIME_INTERVAL = 60 * 1000;
13 |
14 | private static final int DEFAULT_MAX_COUNT = 3;
15 |
16 | private static final String SHARED_PREFS_NAME = "recovery_info";
17 |
18 | private static final String CRASH_COUNT = "crash_count";
19 |
20 | private static final String CRASH_TIME = "crash_time";
21 |
22 | private static final String SHOULD_RESTART_APP = "should_restart_app";
23 |
24 | private RecoverySharedPrefsUtil() {
25 | throw new RecoveryException("Stub!");
26 | }
27 |
28 | public static void recordCrashData() {
29 | int count = 0;
30 | long time = 0L;
31 | boolean shouldRestart = false;
32 | try {
33 | count = Integer.parseInt(get(CRASH_COUNT, String.valueOf(0)));
34 | time = Long.parseLong(get(CRASH_TIME, String.valueOf(0L)));
35 | } catch (Exception e) {
36 | count = 0;
37 | time = 0L;
38 | RecoveryLog.e(e.getMessage());
39 | }
40 | count = Math.max(count, 0);
41 | time = Math.max(time, 0L);
42 |
43 | count += 1;
44 | time = time == 0L ? System.currentTimeMillis() : time;
45 |
46 | long interval = System.currentTimeMillis() - time;
47 | if (count >= DEFAULT_MAX_COUNT && interval <= DEFAULT_TIME_INTERVAL) {
48 | shouldRestart = true;
49 | count = 0;
50 | time = 0L;
51 | } else {
52 | if (count >= DEFAULT_MAX_COUNT || interval > DEFAULT_TIME_INTERVAL) {
53 | count = 1;
54 | time = System.currentTimeMillis();
55 | }
56 | }
57 | CrashData data = CrashData.newInstance()
58 | .count(count)
59 | .time(time)
60 | .restart(shouldRestart);
61 | RecoveryLog.e(data.toString());
62 | saveCrashData(data);
63 | }
64 |
65 | private static void saveCrashData(CrashData data) {
66 | if (data == null)
67 | return;
68 | SharedPreferencesCompat.newBuilder(Recovery.getInstance().getContext(), SHARED_PREFS_NAME)
69 | .put(CRASH_COUNT, String.valueOf(data.crashCount))
70 | .put(CRASH_TIME, String.valueOf(data.crashTime))
71 | .put(SHOULD_RESTART_APP, String.valueOf(data.shouldRestart))
72 | .apply();
73 | }
74 |
75 | public static boolean shouldRestartApp() {
76 | return Boolean.parseBoolean(get(SHOULD_RESTART_APP, String.valueOf(false)));
77 | }
78 |
79 | public static void clear() {
80 | SharedPreferencesCompat.clear(Recovery.getInstance().getContext(), SHARED_PREFS_NAME);
81 | }
82 |
83 | private static void put(String key, String value) {
84 | SharedPreferencesCompat.put(Recovery.getInstance().getContext(), SHARED_PREFS_NAME, key, value);
85 | }
86 |
87 | private static String get(String key, String defValue) {
88 | return SharedPreferencesCompat.get(Recovery.getInstance().getContext(), SHARED_PREFS_NAME, key, defValue);
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/tools/RecoveryUtil.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.tools;
2 |
3 | import android.app.ActivityManager;
4 | import android.app.Application;
5 | import android.content.Context;
6 | import android.content.Intent;
7 | import android.content.pm.ApplicationInfo;
8 | import android.content.pm.PackageManager;
9 | import android.content.pm.ResolveInfo;
10 | import android.os.Environment;
11 |
12 | import com.zxy.recovery.core.Recovery;
13 | import com.zxy.recovery.exception.RecoveryException;
14 | import com.zxy.recovery.exception.ReflectException;
15 |
16 | import java.io.File;
17 | import java.util.List;
18 |
19 | /**
20 | * Created by zhengxiaoyong on 16/8/28.
21 | */
22 | public class RecoveryUtil {
23 |
24 | private RecoveryUtil() {
25 | throw new RecoveryException("Stub!");
26 | }
27 |
28 | public static T checkNotNull(T t, String message) {
29 | if (t == null)
30 | throw new ReflectException(String.valueOf(message));
31 | return t;
32 | }
33 |
34 | public static boolean isIntentAvailable(Context context, Intent intent) {
35 | if (context == null || intent == null)
36 | return false;
37 | PackageManager packageManager = context.getApplicationContext().getPackageManager();
38 | List list = packageManager.queryIntentActivities(intent,
39 | PackageManager.MATCH_DEFAULT_ONLY);
40 | return list.size() > 0;
41 | }
42 |
43 | public static boolean isAppInBackground(Context context) {
44 | ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
45 | List appProcesses = activityManager.getRunningAppProcesses();
46 | if (appProcesses == null)
47 | return true;
48 | for (ActivityManager.RunningAppProcessInfo appProcess : appProcesses) {
49 | if (appProcess.processName.equals(context.getPackageName())) {
50 | return appProcess.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_BACKGROUND;
51 | }
52 | }
53 | return false;
54 | }
55 |
56 | public static String getAppName(Context context) {
57 | PackageManager packageManager = null;
58 | ApplicationInfo applicationInfo = null;
59 | if (!(context instanceof Application))
60 | context = context.getApplicationContext();
61 | try {
62 | packageManager = context.getPackageManager();
63 | applicationInfo = packageManager.getApplicationInfo(context.getPackageName(), 0);
64 | } catch (PackageManager.NameNotFoundException e) {
65 | applicationInfo = null;
66 | }
67 | CharSequence charSequence = packageManager.getApplicationLabel(applicationInfo);
68 | return charSequence == null ? "" : (String) charSequence;
69 | }
70 |
71 | public static boolean isMainProcess(Context context) {
72 | try {
73 | ActivityManager am = ((ActivityManager) context
74 | .getSystemService(Context.ACTIVITY_SERVICE));
75 | List processInfo = am.getRunningAppProcesses();
76 | String mainProcessName = context.getPackageName();
77 | int myPid = android.os.Process.myPid();
78 | for (ActivityManager.RunningAppProcessInfo info : processInfo) {
79 | if (info.pid == myPid && mainProcessName.equals(info.processName)) {
80 | return true;
81 | }
82 | }
83 | } catch (Exception e) {
84 | e.printStackTrace();
85 | }
86 | return false;
87 | }
88 |
89 | private static File getDataDir() {
90 | return new File(File.separator + "data" + File.separator + "data" + File.separator + Recovery.getInstance().getContext().getPackageName());
91 | }
92 |
93 | private static File getExternalDataDir() {
94 | File file = null;
95 | if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
96 | file = Recovery.getInstance().getContext().getExternalCacheDir();
97 | }
98 | return file == null ? null : file.getParentFile();
99 | }
100 |
101 | private static boolean clearAppData(File dir) {
102 | if (dir == null || !dir.isDirectory() || !dir.exists())
103 | return false;
104 | File[] files = dir.listFiles();
105 | int length = files.length;
106 | for (int i = 0; i < length; i++) {
107 | File file = files[i];
108 | if (file == null)
109 | continue;
110 | if (file.isFile() && file.exists()) {
111 | boolean result = file.delete();
112 | RecoveryLog.e(file.getName() + (result ? " delete success!" : " delete failed!"));
113 | continue;
114 | }
115 | if (file.isDirectory() && file.exists()) {
116 | clearAppData(file);
117 | }
118 | }
119 | return true;
120 | }
121 |
122 | public static void clearApplicationData() {
123 | clearAppData(getDataDir());
124 | clearAppData(getExternalDataDir());
125 | }
126 | }
127 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/tools/Reflect.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.tools;
2 |
3 | import android.text.TextUtils;
4 |
5 | import com.zxy.recovery.exception.ReflectException;
6 |
7 | import java.lang.reflect.Constructor;
8 | import java.lang.reflect.Field;
9 | import java.lang.reflect.InvocationTargetException;
10 | import java.lang.reflect.Method;
11 | import java.lang.reflect.Modifier;
12 |
13 | /**
14 | * Created by zhengxiaoyong on 16/8/26.
15 | */
16 | public class Reflect {
17 |
18 | private Class> mReflectObjectClazz;
19 |
20 | private Reflect(String className) {
21 | checkNotEmpty(className, "ClassName can not be empty!");
22 | try {
23 | this.mReflectObjectClazz = Class.forName(className);
24 | } catch (ClassNotFoundException e) {
25 | throw new ReflectException("Class:" + className + " can not be found!", e.getCause());
26 | }
27 | }
28 |
29 | private Reflect(Class> clazz) {
30 | checkNotNull(clazz, "Reflect class can not be null!");
31 | this.mReflectObjectClazz = clazz;
32 | }
33 |
34 | public static Reflect on(String className) {
35 | return new Reflect(className);
36 | }
37 |
38 | public static Reflect on(Class> clazz) {
39 | return new Reflect(clazz);
40 | }
41 |
42 | public final ReflectMethod method(String methodName, Class>... types) {
43 | checkNotEmpty(methodName, "MethodName can not be empty!");
44 | Method method;
45 | try {
46 | if (types == null || types.length == 0) {
47 | method = mReflectObjectClazz.getDeclaredMethod(methodName);
48 | } else {
49 | method = mReflectObjectClazz.getDeclaredMethod(methodName, types);
50 | }
51 | method.setAccessible(true);
52 | return ReflectMethod.create(method);
53 | } catch (NoSuchMethodException e) {
54 | e.printStackTrace();
55 | }
56 | return ReflectMethod.create(null);
57 | }
58 |
59 | public static final class ReflectMethod {
60 | private Method method;
61 |
62 | private ReflectMethod(Method method) {
63 | this.method = method;
64 | }
65 |
66 | static ReflectMethod create(Method method) {
67 | return new ReflectMethod(method);
68 | }
69 |
70 | public Method obtain() {
71 | return method;
72 | }
73 |
74 | public Object invoke(Object invoker, Object... params) {
75 | if (method == null)
76 | return null;
77 | if (invoker == null) {
78 | if ((method.getModifiers() & Modifier.STATIC) == 0)
79 | throw new ReflectException("Invoker can not be null!");
80 | }
81 | try {
82 | if (params == null || params.length == 0)
83 | return method.invoke(invoker);
84 | return method.invoke(invoker, params);
85 | } catch (IllegalAccessException e) {
86 | e.printStackTrace();
87 | } catch (InvocationTargetException e) {
88 | e.printStackTrace();
89 | }
90 | return null;
91 | }
92 | }
93 |
94 | public final ReflectField field(String fieldName) {
95 | checkNotEmpty(fieldName, "FieldName can not be empty!");
96 | try {
97 | Field field = mReflectObjectClazz.getDeclaredField(fieldName);
98 | field.setAccessible(true);
99 | return ReflectField.create(field);
100 | } catch (NoSuchFieldException e) {
101 | e.printStackTrace();
102 | }
103 | return ReflectField.create(null);
104 | }
105 |
106 | public static final class ReflectField {
107 | private Field field;
108 |
109 | private ReflectField(Field field) {
110 | this.field = field;
111 | }
112 |
113 | static ReflectField create(Field field) {
114 | return new ReflectField(field);
115 | }
116 |
117 | public Field obtain() {
118 | return field;
119 | }
120 |
121 | public void set(Object target, Object value) {
122 | if (field == null)
123 | return;
124 | if (target == null) {
125 | if ((field.getModifiers() & Modifier.STATIC) == 0)
126 | throw new ReflectException("Target object can not be null!");
127 | }
128 | try {
129 | field.set(target, value);
130 | } catch (IllegalAccessException e) {
131 | e.printStackTrace();
132 | }
133 | }
134 |
135 | public Object get(Object target) {
136 | if (field == null)
137 | return null;
138 | if (target == null) {
139 | if ((field.getModifiers() & Modifier.STATIC) == 0)
140 | throw new ReflectException("Target object can not be null!");
141 | }
142 | try {
143 | return field.get(target);
144 | } catch (IllegalAccessException e) {
145 | e.printStackTrace();
146 | }
147 | return null;
148 | }
149 | }
150 |
151 | public final ReflectConstructor constructor(Class>... types) {
152 | Constructor constructor;
153 | try {
154 | if (types == null || types.length == 0) {
155 | constructor = mReflectObjectClazz.getDeclaredConstructor();
156 | } else {
157 | constructor = mReflectObjectClazz.getDeclaredConstructor(types);
158 | }
159 | constructor.setAccessible(true);
160 | return ReflectConstructor.create(constructor);
161 | } catch (NoSuchMethodException e) {
162 | e.printStackTrace();
163 | }
164 | return ReflectConstructor.create(null);
165 | }
166 |
167 | public static final class ReflectConstructor {
168 | private Constructor constructor;
169 |
170 | private ReflectConstructor(Constructor constructor) {
171 | this.constructor = constructor;
172 | }
173 |
174 | static ReflectConstructor create(Constructor constructor) {
175 | return new ReflectConstructor(constructor);
176 | }
177 |
178 | public Constructor obtain() {
179 | return constructor;
180 | }
181 |
182 | public Object newInstance(Object... params) {
183 | if (constructor == null)
184 | return null;
185 | try {
186 | if (params == null || params.length == 0)
187 | return constructor.newInstance();
188 | return constructor.newInstance(params);
189 | } catch (InstantiationException e) {
190 | e.printStackTrace();
191 | } catch (IllegalAccessException e) {
192 | e.printStackTrace();
193 | } catch (InvocationTargetException e) {
194 | e.printStackTrace();
195 | }
196 | return null;
197 | }
198 | }
199 |
200 | public Object newInstance() {
201 | if (mReflectObjectClazz == null)
202 | return null;
203 | try {
204 | return mReflectObjectClazz.newInstance();
205 | } catch (InstantiationException e) {
206 | e.printStackTrace();
207 | } catch (IllegalAccessException e) {
208 | e.printStackTrace();
209 | }
210 | return null;
211 | }
212 |
213 |
214 | private static void checkNotNull(T t, String message) {
215 | if (t == null)
216 | throw new ReflectException(String.valueOf(message));
217 | }
218 |
219 | private static void checkNotEmpty(String t, String message) {
220 | if (TextUtils.isEmpty(t))
221 | throw new ReflectException(String.valueOf(message));
222 | }
223 |
224 | }
225 |
--------------------------------------------------------------------------------
/recovery/src/main/java/com/zxy/recovery/tools/SharedPreferencesCompat.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery.tools;
2 |
3 |
4 | import android.content.Context;
5 | import android.content.SharedPreferences;
6 | import android.os.Process;
7 | import android.support.annotation.NonNull;
8 | import android.text.TextUtils;
9 |
10 | import java.util.Map;
11 | import java.util.Set;
12 | import java.util.concurrent.ExecutorService;
13 | import java.util.concurrent.Executors;
14 | import java.util.concurrent.ThreadFactory;
15 |
16 | /**
17 | * Created by zhengxiaoyong on 16/8/27.
18 | */
19 | public class SharedPreferencesCompat {
20 |
21 | private SharedPreferencesCompat() {
22 | throw new SharedPreferencesException("Stub!");
23 | }
24 |
25 | private static SharedPreferences getSharedPrefs(Context context, String sharedPrefsName) {
26 | checkNotNull(context, "Context can not be null!");
27 | checkNotEmpty(sharedPrefsName, "SharedPreferences name can not be empty!");
28 | return context.getSharedPreferences(sharedPrefsName, Context.MODE_PRIVATE);
29 | }
30 |
31 | public static void put(Context context, String sharedPrefsName, String key, String value) {
32 | checkNotEmpty(key, "SharedPreferences key can not be empty!");
33 | checkNotNull(value, "SharedPreferences value can not be null!");
34 | SharedPreferences.Editor editor = getSharedPrefs(context, sharedPrefsName).edit();
35 | editor.putString(key, value);
36 | SharedPreferencesEditorCompat.apply(editor);
37 | }
38 |
39 | public static String get(Context context, String sharedPrefsName, String key, String defValue) {
40 | checkNotEmpty(key, "SharedPreferences key can not be empty!");
41 | return getSharedPrefs(context, sharedPrefsName).getString(key, defValue);
42 | }
43 |
44 | public static void clear(Context context, String sharedPrefsName) {
45 | SharedPreferences.Editor editor = getSharedPrefs(context, sharedPrefsName).edit();
46 | editor.clear();
47 | SharedPreferencesEditorCompat.apply(editor);
48 | }
49 |
50 | public static void remove(Context context, String sharedPrefsName, String key) {
51 | checkNotEmpty(key, "SharedPreferences key can not be empty!");
52 | SharedPreferences.Editor editor = getSharedPrefs(context, sharedPrefsName).edit();
53 | editor.remove(key);
54 | SharedPreferencesEditorCompat.apply(editor);
55 | }
56 |
57 | public static Map getAll(Context context, String sharedPrefsName) {
58 | checkNotNull(context, "Context can not be null!");
59 | return getSharedPrefs(context, sharedPrefsName).getAll();
60 | }
61 |
62 | public static boolean contains(Context context, String sharedPrefsName, String key) {
63 | checkNotEmpty(key, "SharedPreferences key can not be empty!");
64 | return getSharedPrefs(context, sharedPrefsName).contains(key);
65 | }
66 |
67 | public static Set getStringSet(Context context, String sharedPrefsName, String key, Set defValues) {
68 | checkNotEmpty(key, "SharedPreferences key can not be empty!");
69 | return getSharedPrefs(context, sharedPrefsName).getStringSet(key, defValues);
70 | }
71 |
72 | public static Builder newBuilder(Context context, String sharedPrefsName) {
73 | return new Builder(context, sharedPrefsName);
74 | }
75 |
76 | public static final class Builder {
77 |
78 | private SharedPreferences.Editor mEditor;
79 |
80 | private Builder(Context context, String sharedPrefsName) {
81 | mEditor = getSharedPrefs(context, sharedPrefsName).edit();
82 | }
83 |
84 | public Builder put(String key, String value) {
85 | checkNotEmpty(key, "SharedPreferences key can not be empty!");
86 | checkNotNull(value, "SharedPreferences value can not be null!");
87 | mEditor.putString(key, value);
88 | return this;
89 | }
90 |
91 | public void apply() {
92 | SharedPreferencesEditorCompat.apply(mEditor);
93 | }
94 |
95 | }
96 |
97 | private static void checkNotNull(T t, String message) {
98 | if (t == null)
99 | throw new SharedPreferencesException(String.valueOf(message));
100 | }
101 |
102 | private static void checkNotEmpty(String t, String message) {
103 | if (TextUtils.isEmpty(t))
104 | throw new SharedPreferencesException(String.valueOf(message));
105 | }
106 |
107 | private static final class SharedPreferencesException extends RuntimeException {
108 | public SharedPreferencesException(String message, Throwable cause) {
109 | super(message, cause);
110 | }
111 |
112 | public SharedPreferencesException(String message) {
113 | super(message);
114 | }
115 | }
116 |
117 | private static final class SharedPreferencesEditorCompat {
118 |
119 | private static final ExecutorService SINGLE_THREAD_POOL;
120 |
121 | static {
122 | SINGLE_THREAD_POOL = Executors.newFixedThreadPool(1, new SharedPreferencesThreadFactory());
123 | }
124 |
125 | static void apply(final SharedPreferences.Editor editor) {
126 | try {
127 | editor.apply();
128 | } catch (Throwable e) {
129 | SINGLE_THREAD_POOL.submit(new Runnable() {
130 | @Override
131 | public void run() {
132 | editor.commit();
133 | }
134 | });
135 | }
136 | }
137 | }
138 |
139 | private static final class SharedPreferencesThreadFactory implements ThreadFactory {
140 |
141 | private static final String THREAD_NAME = "SharedPreferencesThread";
142 |
143 | @Override
144 | public Thread newThread(@NonNull final Runnable r) {
145 | Runnable wrapper = new Runnable() {
146 | @Override
147 | public void run() {
148 | try {
149 | Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
150 | } catch (Throwable t) {
151 | t.printStackTrace();
152 | }
153 | r.run();
154 | }
155 | };
156 | Thread thread = new Thread(wrapper, THREAD_NAME);
157 | if (thread.isDaemon())
158 | thread.setDaemon(false);
159 | return thread;
160 | }
161 | }
162 | }
--------------------------------------------------------------------------------
/recovery/src/main/res/drawable-xhdpi/ic_recovery_page.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/80945540/Recovery/64e11e186ac8a4e81e6c0c74ae6a40e9f1e101d1/recovery/src/main/res/drawable-xhdpi/ic_recovery_page.png
--------------------------------------------------------------------------------
/recovery/src/main/res/drawable/recovery_default_btn_selector.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
9 | -
10 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/recovery/src/main/res/layout/activity_recovery.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
12 |
23 |
24 |
33 |
34 |
38 |
39 |
48 |
49 |
54 |
55 |
66 |
67 |
76 |
77 |
86 |
87 |
96 |
97 |
98 |
99 |
--------------------------------------------------------------------------------
/recovery/src/main/res/layout/layout_recovery_debug.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
24 |
25 |
29 |
30 |
42 |
43 |
55 |
56 |
68 |
69 |
81 |
82 |
83 |
92 |
93 |
98 |
99 |
110 |
111 |
120 |
121 |
126 |
127 |
135 |
136 |
141 |
142 |
--------------------------------------------------------------------------------
/recovery/src/main/res/menu/menu_recovery.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/recovery/src/main/res/menu/menu_recovery_sub.xml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/recovery/src/main/res/values-en/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Debug
4 | Save
5 | Restart and clear
6 | Restart
7 | Recover
8 | Tips
9 | Sure
10 | Cancel
11 | This will clear all the data and restart the application.
12 | ExceptionType: %s
13 | ClassName: %s
14 | MethodName: %s
15 | LineNumber: %d
16 | %s.An error occurred when used\nPlease try to recover or restart the application.
17 |
--------------------------------------------------------------------------------
/recovery/src/main/res/values-v21/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
--------------------------------------------------------------------------------
/recovery/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #F44336
4 | #D32F2F
5 | #BDBDBD
6 | #FFFFFF
7 |
--------------------------------------------------------------------------------
/recovery/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 8dp
5 | 4dp
6 |
7 | 14sp
8 |
9 |
--------------------------------------------------------------------------------
/recovery/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Debug
3 | Save
4 | 重启并清空缓存
5 | 重启应用
6 | 恢复界面
7 | 提示
8 | 确定
9 | 取消
10 | 此操作将清空应用的所有数据并重新启动应用!
11 | ExceptionType: %s
12 | ClassName: %s
13 | MethodName: %s
14 | LineNumber: %d
15 | %s在使用时发生一个错误\n请尝试恢复或重启应用!
16 |
17 |
--------------------------------------------------------------------------------
/recovery/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/recovery/src/test/java/com/zxy/recovery/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.zxy.recovery;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.*;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 | @Test
14 | public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app', ':recovery'
2 |
--------------------------------------------------------------------------------