Skip to content

Commit

Permalink
fix multiple unresponsive and unclosable overlays can be opened
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiisdev committed Feb 5, 2024
1 parent 3a6fbeb commit c5f99e5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Expand Down Expand Up @@ -51,7 +52,7 @@ public void onAttachedToEngine(@NonNull FlutterPluginBinding flutterPluginBindin
}

@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
public synchronized void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
pendingResult = result;
if (call.method.equals("checkPermission")) {
result.success(checkOverlayPermission());
Expand Down Expand Up @@ -110,7 +111,6 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
} else {
result.notImplemented();
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public IBinder onBind(Intent intent) {
public void onDestroy() {
Log.d("OverLay", "Destroying the overlay window service");
isRunning = false;
if (windowManager != null) {
windowManager.removeView(flutterView);
windowManager = null;
}
flutterView.detachFromFlutterEngine();
flutterView = null;
NotificationManager notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.cancel(OverlayConstants.NOTIFICATION_ID);
if(CachedMessageChannels.overlayMessageChannel != null){
Expand All @@ -89,21 +95,9 @@ public void onDestroy() {
public int onStartCommand(Intent intent, int flags, int startId) {
mResources = getApplicationContext().getResources();
boolean isCloseWindow = intent.getBooleanExtra(INTENT_EXTRA_IS_CLOSE_WINDOW, false);
if (isCloseWindow) {
if (windowManager != null) {
windowManager.removeView(flutterView);
windowManager = null;
flutterView.detachFromFlutterEngine();
stopSelf();
}
isRunning = false;
return START_STICKY;
}
if (windowManager != null) {
windowManager.removeView(flutterView);
windowManager = null;
flutterView.detachFromFlutterEngine();
if (isCloseWindow || windowManager != null) {
stopSelf();
return START_STICKY;
}
isRunning = true;
Log.d("onStartCommand", "Service started");
Expand All @@ -128,7 +122,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {

BasicMessageChannel<Object> overlayMessageChannel = new BasicMessageChannel<>(FlutterEngineCache.getInstance().get(OverlayConstants.CACHED_TAG).getDartExecutor().getBinaryMessenger(), OverlayConstants.MESSENGER_TAG, JSONMessageCodec.INSTANCE);
overlayMessageChannel.setMessageHandler((message, reply) -> {
if(CachedMessageChannels.mainAppMessageChannel == null) {
if (CachedMessageChannels.mainAppMessageChannel == null) {
reply.reply(false);
return;
}
Expand Down

0 comments on commit c5f99e5

Please sign in to comment.