Skip to content

Commit 7d55a19

Browse files
committed
fix multiple unresponsive and unclosable overlays can be opened
1 parent 35b1fa8 commit 7d55a19

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

android/src/main/java/flutter/overlay/window/flutter_overlay_window/FlutterOverlayWindowPlugin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import android.net.Uri;
77
import android.os.Build;
88
import android.provider.Settings;
9+
910
import androidx.annotation.NonNull;
1011
import androidx.annotation.Nullable;
1112

@@ -51,7 +52,7 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin
5152
}
5253

5354
@Override
54-
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
55+
public synchronized void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
5556
pendingResult = result;
5657
if (call.method.equals("checkPermission")) {
5758
result.success(checkOverlayPermission());
@@ -110,7 +111,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
110111
} else {
111112
result.notImplemented();
112113
}
113-
114114
}
115115

116116
@Override

android/src/main/java/flutter/overlay/window/flutter_overlay_window/OverlayService.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ public IBinder onBind(Intent intent) {
7676
public void onDestroy() {
7777
Log.d("OverLay", "Destroying the overlay window service");
7878
isRunning = false;
79+
if (windowManager != null) {
80+
windowManager.removeView(flutterView);
81+
windowManager = null;
82+
}
83+
flutterView.detachFromFlutterEngine();
84+
flutterView = null;
7985
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
8086
notificationManager.cancel(OverlayConstants.NOTIFICATION_ID);
8187
if(CachedMessageChannels.overlayMessageChannel != null){
@@ -89,21 +95,9 @@ public void onDestroy() {
8995
public int onStartCommand(Intent intent, int flags, int startId) {
9096
mResources = getApplicationContext().getResources();
9197
boolean isCloseWindow = intent.getBooleanExtra(INTENT_EXTRA_IS_CLOSE_WINDOW, false);
92-
if (isCloseWindow) {
93-
if (windowManager != null) {
94-
windowManager.removeView(flutterView);
95-
windowManager = null;
96-
flutterView.detachFromFlutterEngine();
97-
stopSelf();
98-
}
99-
isRunning = false;
100-
return START_STICKY;
101-
}
102-
if (windowManager != null) {
103-
windowManager.removeView(flutterView);
104-
windowManager = null;
105-
flutterView.detachFromFlutterEngine();
98+
if (isCloseWindow || windowManager != null) {
10699
stopSelf();
100+
return START_STICKY;
107101
}
108102
isRunning = true;
109103
Log.d("onStartCommand", "Service started");
@@ -128,7 +122,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
128122

129123
BasicMessageChannel<Object> overlayMessageChannel = new BasicMessageChannel<>(FlutterEngineCache.getInstance().get(OverlayConstants.CACHED_TAG).getDartExecutor().getBinaryMessenger(), OverlayConstants.MESSENGER_TAG, JSONMessageCodec.INSTANCE);
130124
overlayMessageChannel.setMessageHandler((message, reply) -> {
131-
if(CachedMessageChannels.mainAppMessageChannel == null) {
125+
if (CachedMessageChannels.mainAppMessageChannel == null) {
132126
reply.reply(false);
133127
return;
134128
}

0 commit comments

Comments
 (0)