1
1
package com .instabug .flutter .modules ;
2
2
3
- import android .os .Handler ;
4
- import android .os .Looper ;
5
3
import android .util .Log ;
6
4
7
5
import androidx .annotation .NonNull ;
8
- import androidx .annotation .Nullable ;
9
6
10
7
import com .instabug .apm .APM ;
11
8
import com .instabug .apm .model .ExecutionTrace ;
12
9
import com .instabug .apm .networking .APMNetworkLogger ;
13
10
import com .instabug .flutter .generated .ApmPigeon ;
14
11
import com .instabug .flutter .util .ArgsRegistry ;
15
12
import com .instabug .flutter .util .Reflection ;
13
+ import com .instabug .flutter .util .ThreadManager ;
16
14
17
15
import org .json .JSONObject ;
18
16
@@ -33,148 +31,109 @@ public static void init(BinaryMessenger messenger) {
33
31
34
32
@ Override
35
33
public void setEnabled (@ NonNull Boolean isEnabled ) {
36
- new Handler (Looper .getMainLooper ()).post (new Runnable () {
37
- @ Override
38
- public void run () {
39
- try {
40
- APM .setEnabled (isEnabled );
41
- } catch (Exception e ) {
42
- e .printStackTrace ();
43
- }
44
- }
45
- });
34
+ try {
35
+ APM .setEnabled (isEnabled );
36
+ } catch (Exception e ) {
37
+ e .printStackTrace ();
38
+ }
46
39
}
47
40
48
41
@ Override
49
42
public void setColdAppLaunchEnabled (@ NonNull Boolean isEnabled ) {
50
- new Handler (Looper .getMainLooper ()).post (new Runnable () {
51
- @ Override
52
- public void run () {
53
- try {
54
- APM .setAppLaunchEnabled (isEnabled );
55
- } catch (Exception e ) {
56
- e .printStackTrace ();
57
- }
58
- }
59
- });
43
+ try {
44
+ APM .setAppLaunchEnabled (isEnabled );
45
+ } catch (Exception e ) {
46
+ e .printStackTrace ();
47
+ }
60
48
}
61
49
62
50
@ Override
63
51
public void setAutoUITraceEnabled (@ NonNull Boolean isEnabled ) {
64
- new Handler (Looper .getMainLooper ()).post (new Runnable () {
65
- @ Override
66
- public void run () {
67
- try {
68
- APM .setAutoUITraceEnabled (isEnabled );
69
- } catch (Exception e ) {
70
- e .printStackTrace ();
71
- }
72
- }
73
- });
52
+ try {
53
+ APM .setAutoUITraceEnabled (isEnabled );
54
+ } catch (Exception e ) {
55
+ e .printStackTrace ();
56
+ }
74
57
}
75
58
76
59
@ Override
77
60
public void setLogLevel (@ NonNull String level ) {
78
- new Handler (Looper .getMainLooper ()).post (new Runnable () {
79
- @ Override
80
- public void run () {
81
- try {
82
- if (ArgsRegistry .getDeserializedValue (level ) == null ) {
83
- return ;
84
- }
85
- APM .setLogLevel ((int ) ArgsRegistry .getRawValue (level ));
86
- } catch (Exception e ) {
87
- e .printStackTrace ();
88
- }
89
- }
90
- });
91
- }
92
-
93
- @ Nullable
94
- @ Override
95
- public String startExecutionTrace (@ NonNull String id , @ NonNull String name ) {
96
61
try {
97
- String result = null ;
98
- ExecutionTrace trace = APM .startExecutionTrace (name );
99
- if (trace != null ) {
100
- result = id ;
101
- traces .put (id , trace );
62
+ if (ArgsRegistry .getDeserializedValue (level ) == null ) {
63
+ return ;
102
64
}
103
- return result ;
65
+ APM . setLogLevel (( int ) ArgsRegistry . getRawValue ( level )) ;
104
66
} catch (Exception e ) {
105
67
e .printStackTrace ();
106
- return null ;
107
68
}
108
69
}
109
70
110
71
@ Override
111
- public void setExecutionTraceAttribute (@ NonNull String id , @ NonNull String key , @ NonNull String value ) {
112
- new Handler (Looper .getMainLooper ()).post (new Runnable () {
113
- @ Override
114
- public void run () {
115
- try {
116
- traces .get (id ).setAttribute (key , value );
117
- } catch (Exception e ) {
118
- e .printStackTrace ();
72
+ public void startExecutionTrace (@ NonNull String id , @ NonNull String name , ApmPigeon .Result <String > result ) {
73
+ ThreadManager .runOnBackground (
74
+ new Runnable () {
75
+ @ Override
76
+ public void run () {
77
+ try {
78
+ ExecutionTrace trace = APM .startExecutionTrace (name );
79
+ if (trace != null ) {
80
+ traces .put (id , trace );
81
+ result .success (id );
82
+ } else {
83
+ result .success (null );
84
+ }
85
+ } catch (Exception e ) {
86
+ e .printStackTrace ();
87
+ result .success (null );
88
+ }
89
+ }
119
90
}
120
- }
121
- });
91
+ );
92
+ }
93
+
94
+ @ Override
95
+ public void setExecutionTraceAttribute (@ NonNull String id , @ NonNull String key , @ NonNull String value ) {
96
+ try {
97
+ traces .get (id ).setAttribute (key , value );
98
+ } catch (Exception e ) {
99
+ e .printStackTrace ();
100
+ }
122
101
}
123
102
124
103
@ Override
125
104
public void endExecutionTrace (@ NonNull String id ) {
126
- new Handler (Looper .getMainLooper ()).post (new Runnable () {
127
- @ Override
128
- public void run () {
129
- try {
130
- traces .get (id ).end ();
131
- } catch (Exception e ) {
132
- e .printStackTrace ();
133
- }
134
- }
135
- });
105
+ try {
106
+ traces .get (id ).end ();
107
+ } catch (Exception e ) {
108
+ e .printStackTrace ();
109
+ }
136
110
}
137
111
138
112
@ Override
139
113
public void startUITrace (@ NonNull String name ) {
140
- new Handler (Looper .getMainLooper ()).post (new Runnable () {
141
- @ Override
142
- public void run () {
143
- try {
144
- APM .startUITrace (name );
145
- } catch (Exception e ) {
146
- e .printStackTrace ();
147
- }
148
- }
149
- });
114
+ try {
115
+ APM .startUITrace (name );
116
+ } catch (Exception e ) {
117
+ e .printStackTrace ();
118
+ }
150
119
}
151
120
152
121
@ Override
153
122
public void endUITrace () {
154
- new Handler (Looper .getMainLooper ()).post (new Runnable () {
155
- @ Override
156
- public void run () {
157
- try {
158
- APM .endUITrace ();
159
- } catch (Exception e ) {
160
- e .printStackTrace ();
161
- }
162
- }
163
- });
123
+ try {
124
+ APM .endUITrace ();
125
+ } catch (Exception e ) {
126
+ e .printStackTrace ();
127
+ }
164
128
}
165
129
166
130
@ Override
167
131
public void endAppLaunch () {
168
- new Handler (Looper .getMainLooper ()).post (new Runnable () {
169
- @ Override
170
- public void run () {
171
- try {
172
- APM .endAppLaunch ();
173
- } catch (Exception e ) {
174
- e .printStackTrace ();
175
- }
176
- }
177
- });
132
+ try {
133
+ APM .endAppLaunch ();
134
+ } catch (Exception e ) {
135
+ e .printStackTrace ();
136
+ }
178
137
}
179
138
180
139
@ Override
0 commit comments