diff --git a/app/src/main/java/com/termux/x11/CmdEntryPoint.java b/app/src/main/java/com/termux/x11/CmdEntryPoint.java index 5a8a6bb45..dcbaf281b 100644 --- a/app/src/main/java/com/termux/x11/CmdEntryPoint.java +++ b/app/src/main/java/com/termux/x11/CmdEntryPoint.java @@ -67,10 +67,10 @@ void sendBroadcast() { // We should not care about multiple instances, it should be called only by `Termux:X11` app // which is single instance... Bundle bundle = new Bundle(); - bundle.putBinder("", this); + bundle.putBinder(null, this); Intent intent = new Intent(ACTION_START); - intent.putExtra("", bundle); + intent.putExtra(null, bundle); intent.setPackage(targetPackage); if (getuid() == 0 || getuid() == 2000) diff --git a/app/src/main/java/com/termux/x11/MainActivity.java b/app/src/main/java/com/termux/x11/MainActivity.java index 036e21d3e..2301cf34d 100644 --- a/app/src/main/java/com/termux/x11/MainActivity.java +++ b/app/src/main/java/com/termux/x11/MainActivity.java @@ -70,7 +70,6 @@ import com.termux.x11.utils.X11ToolbarViewPager; import java.util.Map; -import java.util.Objects; @SuppressLint("ApplySharedPref") @SuppressWarnings({"deprecation", "unused"}) @@ -107,17 +106,7 @@ public void onReceive(Context context, Intent intent) { if (ACTION_START.equals(intent.getAction())) { try { Log.v("LorieBroadcastReceiver", "Got new ACTION_START intent"); - IBinder b = Objects.requireNonNull(intent.getBundleExtra("")).getBinder(""); - service = ICmdEntryInterface.Stub.asInterface(b); - Objects.requireNonNull(service).asBinder().linkToDeath(() -> { - service = null; - CmdEntryPoint.requestConnection(); - - Log.v("Lorie", "Disconnected"); - runOnUiThread(() -> clientConnectedStateChanged(false)); - }, 0); - - onReceiveConnection(); + onReceiveConnection(intent); } catch (Exception e) { Log.e("MainActivity", "Something went wrong while we extracted connection details from binder.", e); } @@ -247,6 +236,8 @@ && checkSelfPermission(Manifest.permission.POST_NOTIFICATIONS) != PERMISSION_GRA && !shouldShowRequestPermissionRationale(Manifest.permission.POST_NOTIFICATIONS)) { requestPermissions(new String[] { Manifest.permission.POST_NOTIFICATIONS }, 0); } + + onReceiveConnection(getIntent()); } @Override @@ -474,7 +465,23 @@ public boolean onTouch(View v, MotionEvent e) { }); } - void onReceiveConnection() { + void onReceiveConnection(Intent intent) { + Bundle bundle = intent == null ? null : intent.getBundleExtra(null); + IBinder ibinder = bundle == null ? null : bundle.getBinder(null); + if (ibinder == null) + return; + + service = ICmdEntryInterface.Stub.asInterface(ibinder); + try { + service.asBinder().linkToDeath(() -> { + service = null; + CmdEntryPoint.requestConnection(); + + Log.v("Lorie", "Disconnected"); + runOnUiThread(() -> clientConnectedStateChanged(false)); + }, 0); + } catch (RemoteException ignored) {} + try { if (service != null && service.asBinder().isBinderAlive()) { Log.v("LorieBroadcastReceiver", "Extracting logcat fd."); @@ -483,6 +490,9 @@ void onReceiveConnection() { LorieView.startLogcat(logcatOutput.detachFd()); tryConnect(); + + if (intent != getIntent()) + getIntent().putExtra(null, bundle); } } catch (Exception e) { Log.e("MainActivity", "Something went wrong while we were establishing connection", e); @@ -512,24 +522,30 @@ void tryConnect() { } void onPreferencesChanged(String key) { + if ("additionalKbdVisible".equals(key)) + return; + + handler.removeCallbacks(this::onPreferencesChangedCallback); + handler.postDelayed(this::onPreferencesChangedCallback, 100); + } + + void onPreferencesChangedCallback() { prefs.recheckStoringSecondaryDisplayPreferences(); if (oldXrMode != prefs.xrMode.get() && XrActivity.isSupported() && prefs.xrMode.get() != this instanceof XrActivity) { startActivity(Intent.makeRestartActivityTask(getComponentName())); finish(); - } - - if ("additionalKbdVisible".equals(key)) return; + } + onWindowFocusChanged(hasWindowFocus()); LorieView lorieView = getLorieView(); mInputHandler.reloadPreferences(prefs); lorieView.reloadPreferences(prefs); setTerminalToolbarView(); - onWindowFocusChanged(hasWindowFocus()); lorieView.triggerCallback();