@@ -43,6 +43,7 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
43
43
@ Deprecated
44
44
private static final String METHOD_WAKEUP = "registerWakeup" ;
45
45
46
+ private static final String METHOD_DEBUG = "setDebug" ;
46
47
private static final String METHOD_CONFIG = "config" ;
47
48
private static final String METHOD_CLIPBOARD_ENABLED = "clipBoardEnabled" ;
48
49
private static final String METHOD_SERIAL_ENABLED = "serialEnabled" ;
@@ -52,7 +53,6 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
52
53
private static final String METHOD_REGISTER = "reportRegister" ;
53
54
private static final String METHOD_EFFECT_POINT = "reportEffectPoint" ;
54
55
private static final String METHOD_SHARE = "reportShare" ;
55
-
56
56
private static final String METHOD_OPID = "getOpid" ;
57
57
private static final String METHOD_CHANNEL = "setChannel" ;
58
58
@@ -67,13 +67,15 @@ public class OpeninstallFlutterPlugin implements FlutterPlugin, MethodCallHandle
67
67
private Configuration configuration = null ;
68
68
69
69
private boolean alwaysCallback = false ;
70
+ private boolean debuggable = true ;
70
71
71
72
72
73
@ Override
73
74
public void onAttachedToEngine (@ NonNull FlutterPluginBinding binding ) {
74
75
flutterPluginBinding = binding ;
75
76
channel = new MethodChannel (flutterPluginBinding .getBinaryMessenger (), "openinstall_flutter_plugin" );
76
77
channel .setMethodCallHandler (this );
78
+ OpenInstall .preInit (flutterPluginBinding .getApplicationContext ());
77
79
}
78
80
79
81
@ Override
@@ -92,8 +94,13 @@ public void onReattachedToActivityForConfigChanges(@NonNull ActivityPluginBindin
92
94
93
95
@ Override
94
96
public void onMethodCall (MethodCall call , @ NonNull final Result result ) {
95
- Log .d (TAG , "invoke " + call .method );
96
- if (METHOD_CONFIG .equalsIgnoreCase (call .method )) {
97
+ debugLog ("invoke " + call .method );
98
+ if (METHOD_DEBUG .equalsIgnoreCase (call .method )) {
99
+ Boolean enabled = call .argument ("enabled" );
100
+ debuggable = enabled == null ? true : enabled ;
101
+ OpenInstall .setDebug (debuggable );
102
+ result .success ("OK" );
103
+ } else if (METHOD_CONFIG .equalsIgnoreCase (call .method )) {
97
104
config (call );
98
105
result .success ("OK" );
99
106
} else if (METHOD_CLIPBOARD_ENABLED .equalsIgnoreCase (call .method )) {
@@ -236,7 +243,7 @@ private void config(MethodCall call) {
236
243
}
237
244
238
245
configuration = builder .build ();
239
- // Log.d(TAG, String.format("Configuration: adEnabled=%s, oaid=%s, gaid=%s, macDisabled=%s, imeiDisabled=%s, "
246
+ // debugLog( String.format("Configuration: adEnabled=%s, oaid=%s, gaid=%s, macDisabled=%s, imeiDisabled=%s, "
240
247
// + "androidId=%s, serialNumber=%s, imei=%s, mac=%s",
241
248
// configuration.isAdEnabled(), configuration.getOaid(), configuration.getGaid(),
242
249
// configuration.isMacDisabled(), configuration.isImeiDisabled(),
@@ -252,56 +259,48 @@ private boolean checkBoolean(Boolean bool) {
252
259
253
260
private void init () {
254
261
Context context = flutterPluginBinding .getApplicationContext ();
255
- if (context != null ) {
256
- OpenInstall .init (context , configuration );
257
- initialized = true ;
258
- if (intentHolder != null ) {
259
- wakeup (intentHolder );
260
- intentHolder = null ;
261
- }
262
- } else {
263
- Log .d (TAG , "Context is null, can't init" );
262
+ OpenInstall .init (context , configuration );
263
+ initialized = true ;
264
+ if (intentHolder != null ) {
265
+ wakeup (intentHolder );
266
+ intentHolder = null ;
264
267
}
265
268
}
266
269
267
270
@ Deprecated
268
271
private void initWithPermission () {
269
272
Activity activity = activityPluginBinding .getActivity ();
270
- if (activity == null ) {
271
- Log .d (TAG , "Activity is null, can't initWithPermission, replace with init" );
272
- init ();
273
- } else {
274
- activityPluginBinding .addRequestPermissionsResultListener (permissionsResultListener );
275
- OpenInstall .initWithPermission (activity , configuration , new Runnable () {
276
- @ Override
277
- public void run () {
278
- activityPluginBinding .removeRequestPermissionsResultListener (permissionsResultListener );
279
- initialized = true ;
280
- if (intentHolder != null ) {
281
- wakeup (intentHolder );
282
- intentHolder = null ;
283
- }
273
+ activityPluginBinding .addRequestPermissionsResultListener (permissionsResultListener );
274
+ OpenInstall .initWithPermission (activity , configuration , new Runnable () {
275
+ @ Override
276
+ public void run () {
277
+ activityPluginBinding .removeRequestPermissionsResultListener (permissionsResultListener );
278
+ initialized = true ;
279
+ if (intentHolder != null ) {
280
+ wakeup (intentHolder );
281
+ intentHolder = null ;
284
282
}
285
- });
286
- }
283
+ }
284
+ });
287
285
}
288
286
289
287
@ Override
290
288
public boolean onNewIntent (Intent intent ) {
289
+ debugLog ("onNewIntent" );
291
290
wakeup (intent );
292
291
return false ;
293
292
}
294
293
295
294
296
295
private void wakeup (Intent intent ) {
297
296
if (initialized ) {
298
- Log . d ( TAG , "getWakeUp : alwaysCallback=" + alwaysCallback );
297
+ debugLog ( "getWakeUp : alwaysCallback=" + alwaysCallback );
299
298
if (alwaysCallback ) {
300
299
OpenInstall .getWakeUpAlwaysCallback (intent , new AppWakeUpListener () {
301
300
@ Override
302
301
public void onWakeUpFinish (AppData appData , Error error ) {
303
302
if (error != null ) { // 可忽略,仅调试使用
304
- Log . d ( TAG , "getWakeUpAlwaysCallback : " + error .getErrorMsg ());
303
+ debugLog ( "getWakeUpAlwaysCallback : " + error .getErrorMsg ());
305
304
}
306
305
channel .invokeMethod (METHOD_WAKEUP_NOTIFICATION , data2Map (appData ));
307
306
}
@@ -338,6 +337,12 @@ private static Map<String, Object> data2Map(AppData data) {
338
337
return result ;
339
338
}
340
339
340
+ private void debugLog (String message ) {
341
+ if (debuggable ) {
342
+ Log .d (TAG , message );
343
+ }
344
+ }
345
+
341
346
@ Override
342
347
public void onDetachedFromEngine (@ NonNull FlutterPluginBinding binding ) {
343
348
0 commit comments