|
18 | 18 | import com.wmods.wppenhacer.xposed.bridge.client.BaseClient; |
19 | 19 | import com.wmods.wppenhacer.xposed.bridge.client.BridgeClient; |
20 | 20 | import com.wmods.wppenhacer.xposed.bridge.client.ProviderClient; |
21 | | -import com.wmods.wppenhacer.xposed.core.components.AlertDialogWpp; |
22 | 21 | import com.wmods.wppenhacer.xposed.core.components.FMessageWpp; |
23 | 22 | import com.wmods.wppenhacer.xposed.core.devkit.Unobfuscator; |
24 | 23 | import com.wmods.wppenhacer.xposed.core.devkit.UnobfuscatorCache; |
|
38 | 37 | import java.util.HashSet; |
39 | 38 | import java.util.List; |
40 | 39 | import java.util.concurrent.CompletableFuture; |
| 40 | +import java.util.concurrent.TimeUnit; |
41 | 41 |
|
42 | 42 | import de.robv.android.xposed.XC_MethodHook; |
43 | 43 | import de.robv.android.xposed.XSharedPreferences; |
@@ -680,25 +680,37 @@ public static void addListenerActivity(ActivityChangeState listener) { |
680 | 680 | } |
681 | 681 |
|
682 | 682 | public static WaeIIFace getClientBridge() throws Exception { |
683 | | - if (client == null || client.getService() == null || !client.getService().asBinder().isBinderAlive() |
684 | | - || !client.getService().asBinder().pingBinder()) { |
685 | | - WppCore.getCurrentActivity().runOnUiThread(() -> { |
686 | | - var dialog = new AlertDialogWpp(WppCore.getCurrentActivity()); |
687 | | - dialog.setTitle("Bridge Error"); |
688 | | - dialog.setMessage( |
689 | | - "The Connection with WaEnhancer was lost, it is necessary to reconnect with WaEnhancer in order to reestablish the connection."); |
690 | | - dialog.setPositiveButton("reconnect", (dialog1, which) -> { |
691 | | - client.tryReconnect(); |
692 | | - dialog.dismiss(); |
693 | | - }); |
694 | | - dialog.setNegativeButton("cancel", null); |
695 | | - dialog.show(); |
696 | | - }); |
697 | | - throw new Exception("Failed connect to Bridge"); |
| 683 | + if (!isBridgeConnected()) { |
| 684 | + synchronized (WppCore.class) { |
| 685 | + if (!isBridgeConnected()) { |
| 686 | + if (client == null) { |
| 687 | + throw new Exception("Bridge client not initialized"); |
| 688 | + } |
| 689 | + XposedBridge.log("Bridge disconnected. Trying automatic synchronous reconnect"); |
| 690 | + boolean reconnected = false; |
| 691 | + try { |
| 692 | + reconnected = Boolean.TRUE.equals(client.connect().get(4, TimeUnit.SECONDS)); |
| 693 | + } catch (Throwable e) { |
| 694 | + XposedBridge.log(e); |
| 695 | + } |
| 696 | + if (!reconnected || !isBridgeConnected()) { |
| 697 | + throw new Exception("Failed connect to Bridge"); |
| 698 | + } |
| 699 | + } |
| 700 | + } |
698 | 701 | } |
699 | 702 | return client.getService(); |
700 | 703 | } |
701 | 704 |
|
| 705 | + private static boolean isBridgeConnected() { |
| 706 | + var currentClient = client; |
| 707 | + if (currentClient == null) { |
| 708 | + return false; |
| 709 | + } |
| 710 | + var service = currentClient.getService(); |
| 711 | + return service != null && service.asBinder().isBinderAlive() && service.asBinder().pingBinder(); |
| 712 | + } |
| 713 | + |
702 | 714 | public interface ActivityChangeState { |
703 | 715 |
|
704 | 716 | void onChange(Activity activity, ChangeType type); |
|
0 commit comments