Skip to content

Commit 24fac26

Browse files
committed
feature: fixing logs
1 parent 13514bc commit 24fac26

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

android/src/main/java/com/onesignal/flutter/BackgroundExecutor.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@
3434
* callback dispatcher, used to invoke Dart callbacks while backgrounded.
3535
*/
3636
public class BackgroundExecutor implements MethodCallHandler {
37-
private static final String TAG = "BackgroundExecutor";
37+
private static final String TAG = "OneSignal - BackgroundExecutor";
38+
private static final String CHANNEL = "OneSignalBackground";
39+
private static final String OSK = "one_signal_key";
3840
private static final String CALLBACK_HANDLE_KEY = "callback_handle";
3941
private static final String USER_CALLBACK_HANDLE_KEY = "user_callback_handle";
4042

@@ -69,7 +71,7 @@ public static void setPluginRegistrant(
6971
public static void setCallbackDispatcher(long callbackHandle) {
7072
Context context = ContextHolder.getApplicationContext();
7173
SharedPreferences prefs =
72-
context.getSharedPreferences("one_signal_key", 0);
74+
context.getSharedPreferences(OSK, 0);
7375
prefs.edit().putLong(CALLBACK_HANDLE_KEY, callbackHandle).apply();
7476
}
7577

@@ -82,7 +84,7 @@ public void onMethodCall(MethodCall call, @NonNull Result result) {
8284
// is running. From this point forward, the Android side of this plugin can send
8385
// callback handles through the background method channel, and the Dart side will execute
8486
// the Dart methods corresponding to those callback handles.
85-
Log.i("OneSignal", "Background channel ready");
87+
Log.i(TAG, "Background channel ready");
8688

8789
result.success(true);
8890
} else {
@@ -128,7 +130,7 @@ private void onInitialized() {
128130
* </ul>
129131
*/
130132
public void startBackgroundIsolate(IsolateStatusHandler isolate) {
131-
Log.i("OneSignal", "Starting background isolate.");
133+
Log.i(TAG, "Starting background isolate.");
132134
if (isNotRunning()) {
133135
long callbackHandle = getPluginCallbackHandle();
134136
if (callbackHandle != 0) {
@@ -268,7 +270,7 @@ private long getUserCallbackHandle() {
268270
}
269271
SharedPreferences prefs =
270272
ContextHolder.getApplicationContext()
271-
.getSharedPreferences("one_signal_key", 0);
273+
.getSharedPreferences(OSK, 0);
272274
return prefs.getLong(USER_CALLBACK_HANDLE_KEY, 0);
273275
}
274276

@@ -279,7 +281,7 @@ private long getUserCallbackHandle() {
279281
public static void setUserCallbackHandle(long callbackHandle) {
280282
Context context = ContextHolder.getApplicationContext();
281283
SharedPreferences prefs =
282-
context.getSharedPreferences("one_signal_key", 0);
284+
context.getSharedPreferences(OSK, 0);
283285
prefs.edit().putLong(USER_CALLBACK_HANDLE_KEY, callbackHandle).apply();
284286
}
285287

@@ -290,15 +292,14 @@ private long getPluginCallbackHandle() {
290292
}
291293
SharedPreferences prefs =
292294
ContextHolder.getApplicationContext()
293-
.getSharedPreferences("one_signal_key", 0);
295+
.getSharedPreferences(OSK, 0);
294296
return prefs.getLong(CALLBACK_HANDLE_KEY, 0);
295297
}
296298

297299
// This channel is responsible for sending requests from Android to Dart to execute Dart
298300
// callbacks in the background isolate.
299301
private void initializeMethodChannel(BinaryMessenger isolate) {
300-
backgroundChannel =
301-
new MethodChannel(isolate, "OneSignalBackground");
302+
backgroundChannel = new MethodChannel(isolate, CHANNEL);
302303
backgroundChannel.setMethodCallHandler(this);
303304
}
304305
}

android/src/main/java/com/onesignal/flutter/XNotificationServiceExtension.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
public class XNotificationServiceExtension implements OSRemoteNotificationReceivedHandler {
2323

24+
private static final String TAG = "OneSignal - XNotificationServiceExtension";
2425
public static BackgroundExecutor be;
2526
public static HashMap<String, OSNotificationReceivedEvent> notificationReceivedEventCache = new HashMap<>();
2627

@@ -29,28 +30,28 @@ public void remoteNotificationReceived(Context context, OSNotificationReceivedEv
2930
OSNotification notification = notificationReceivedEvent.getNotification();
3031
XNotificationServiceExtension.notificationReceivedEventCache.put(notification.getNotificationId(), notificationReceivedEvent);
3132
JSONObject data = notification.getAdditionalData();
32-
Log.i("OneSignal", "Received Notification Data: " + data.toString());
33-
// notificationReceivedEvent.complete(null);
33+
Log.i(TAG, "Received Notification Data: " + data.toString());
3434

3535
if (ContextHolder.getApplicationContext() == null) {
3636
ContextHolder.setApplicationContext(context.getApplicationContext());
3737
}
3838
if (XNotificationServiceExtension.be == null) {
3939
XNotificationServiceExtension.be = new BackgroundExecutor();
4040
}
41-
Log.i("OneSignal", "Checking isolated BackgroundExecutor.");
41+
Log.i(TAG, "Checking isolated BackgroundExecutor.");
4242
try {
4343
HashMap<String, Object> receivedMap = OneSignalSerializer.convertNotificationReceivedEventToMap(notificationReceivedEvent);
4444
XNotificationServiceExtension.be.startBackgroundIsolate(new IsolateStatusHandler() {
4545
@Override
4646
public void done() {
4747
if (XNotificationServiceExtension.be != null) {
48+
Log.i(TAG, "Executing dart code in isolate.");
4849
XNotificationServiceExtension.be.executeDartCallbackInBackgroundIsolate(receivedMap);
4950
}
5051
}
5152
});
5253
} catch (Exception e) {
53-
Log.i("OneSignal", "Exception on XNotificationServiceExtension", e);
54+
Log.i(TAG, "Exception while executing dart code in isolate", e);
5455
}
5556
}
5657
}

0 commit comments

Comments
 (0)