1212import android .widget .Toast ;
1313
1414import java .io .IOException ;
15+ import java .util .List ;
1516
17+ import cn .hikyson .godeye .core .GodEye ;
1618import cn .hikyson .godeye .core .GodEyeHelper ;
1719import cn .hikyson .godeye .core .exceptions .UninstallException ;
20+ import cn .hikyson .godeye .core .internal .modules .crash .CrashInfo ;
21+ import cn .hikyson .godeye .core .internal .modules .network .NetworkInfo ;
22+ import cn .hikyson .godeye .core .internal .modules .sm .BlockInfo ;
1823import cn .hikyson .godeye .core .internal .modules .startup .StartupInfo ;
19- import cn .hikyson .godeye .monitor .GodEyeMonitor ;
24+ import io .reactivex .android .schedulers .AndroidSchedulers ;
25+ import io .reactivex .disposables .CompositeDisposable ;
26+ import io .reactivex .functions .Consumer ;
2027import okhttp3 .OkHttpClient ;
2128import okhttp3 .Request ;
2229import okhttp3 .Response ;
2330import xcrash .XCrash ;
2431
2532public class MainActivity extends Activity {
33+ CompositeDisposable mCompositeDisposable ;
2634
2735 @ Override
2836 protected void onCreate (Bundle savedInstanceState ) {
@@ -47,11 +55,13 @@ public void run() {
4755 });
4856 }
4957 });
58+ observeWhenRelease ();
5059 }
5160
5261 @ Override
5362 protected void onDestroy () {
5463 super .onDestroy ();
64+ cleanupWhenRlease ();
5565 }
5666
5767 public void request (View view ) {
@@ -102,19 +112,76 @@ public void jumpToLeak(View view) {
102112 }
103113
104114 private static String getNote () {
105- String openAddress = "AndroidGodEye dashboard is available on [http://localhost:5390/index.html], use plugin to open it." ;
106- String condition = "Install Android Studio plugin(Named 'AndroidGodEye') [https://plugins.jetbrains.com/plugin/12114-androidgodeye] to view details ." ;
107- String logcat = "You can find the address in logcat by search 'AndroidGodEye monitor is running at port' ." ;
108- return openAddress + " \n \n " + condition + " \n \n " + logcat ;
109- }
110-
111- private void openBrowser ( String url ) {
112- Intent intent = new Intent ( Intent . ACTION_VIEW ) ;
113- intent . setData ( Uri . parse ( url )) ;
114- startActivity ( intent );
115+ if ( "debug" . equalsIgnoreCase ( BuildConfig . BUILD_TYPE )) {
116+ String note1 = "This is a debug apk. Debug monitor is opened. Notification config is opened ." ;
117+ String openAddress = "AndroidGodEye dashboard is available on [http://localhost:5390/index.html], use plugin to open it ." ;
118+ String condition = "Install Android Studio plugin(Named 'AndroidGodEye') [https://plugins.jetbrains.com/plugin/12114-androidgodeye] to view details." ;
119+ String logcat = "You can find the address in logcat by search 'AndroidGodEye monitor is running at port'." ;
120+ return openAddress + " \n \n " + condition + " \n \n " + logcat ;
121+ } else {
122+ String note1 = "This is a release apk. Debug monitor is closed. Notification config is closed." ;
123+ return note1 ;
124+ }
115125 }
116126
117127 public void makeCrash (View view ) {
118128 XCrash .testJavaCrash (true );
119129 }
130+
131+ private void observeWhenRelease () {
132+ if (!"debug" .equalsIgnoreCase (BuildConfig .BUILD_TYPE )) {
133+ mCompositeDisposable = new CompositeDisposable ();
134+ try {
135+ mCompositeDisposable .add (GodEye .instance ().observeModule (GodEye .ModuleName .NETWORK , new Consumer <NetworkInfo >() {
136+ @ Override
137+ public void accept (NetworkInfo networkInfo ) throws Exception {
138+ AndroidSchedulers .mainThread ().scheduleDirect (new Runnable () {
139+ @ Override
140+ public void run () {
141+ Toast .makeText (MainActivity .this , "This is NetworkInfo message from release:" + networkInfo .summary , Toast .LENGTH_LONG ).show ();
142+ }
143+ });
144+ }
145+ }));
146+ } catch (UninstallException e ) {
147+ e .printStackTrace ();
148+ }
149+ try {
150+ mCompositeDisposable .add (GodEye .instance ().observeModule (GodEye .ModuleName .SM , new Consumer <BlockInfo >() {
151+ @ Override
152+ public void accept (BlockInfo blockInfo ) throws Exception {
153+ AndroidSchedulers .mainThread ().scheduleDirect (new Runnable () {
154+ @ Override
155+ public void run () {
156+ Toast .makeText (MainActivity .this , "This is BlockInfo message from release:" + blockInfo .toString (), Toast .LENGTH_LONG ).show ();
157+ }
158+ });
159+ }
160+ }));
161+ } catch (UninstallException e ) {
162+ e .printStackTrace ();
163+ }
164+ try {
165+ mCompositeDisposable .add (GodEye .instance ().observeModule (GodEye .ModuleName .CRASH , new Consumer <List <CrashInfo >>() {
166+ @ Override
167+ public void accept (List <CrashInfo > crashInfos ) throws Exception {
168+ AndroidSchedulers .mainThread ().scheduleDirect (new Runnable () {
169+ @ Override
170+ public void run () {
171+ Toast .makeText (MainActivity .this , "This is CrashInfo message from release:" + crashInfos .toString (), Toast .LENGTH_LONG ).show ();
172+ }
173+ });
174+ }
175+ }));
176+ } catch (UninstallException e ) {
177+ e .printStackTrace ();
178+ }
179+ }
180+ }
181+
182+ private void cleanupWhenRlease () {
183+ if (mCompositeDisposable != null ) {
184+ mCompositeDisposable .dispose ();
185+ }
186+ }
120187}
0 commit comments