Skip to content

Commit

Permalink
Making recreate faster after fullscreen or hideCutout toggles were sw…
Browse files Browse the repository at this point in the history
…itched
  • Loading branch information
twaik committed Jul 17, 2024
1 parent e220d29 commit 49ec43a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/termux/x11/CmdEntryPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
50 changes: 33 additions & 17 deletions app/src/main/java/com/termux/x11/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@
import com.termux.x11.utils.X11ToolbarViewPager;

import java.util.Map;
import java.util.Objects;

@SuppressLint("ApplySharedPref")
@SuppressWarnings({"deprecation", "unused"})
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.");
Expand All @@ -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);
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 49ec43a

Please sign in to comment.