Skip to content

Commit

Permalink
Fix old bug where termux app would crash if sessions list ListView wa…
Browse files Browse the repository at this point in the history
…s not notified of new sessions

To reproduce:
1. Create 2 sessions.
2. From either session, run a random `RUN_COMMAND` intent command with `am` command and shift to the other session.

Termux app would crash and throw the `The content of the adapter has changed but ListView did not receive a notification.` exception. TermuxService was previously not notifying the ListView of the sessions list that a new session has been added, if the activity was in foreground.
  • Loading branch information
agnostic-apollo committed Mar 19, 2021
1 parent d9b5344 commit ae260fa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/src/main/java/com/termux/app/TermuxService.java
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,11 @@ private void executeForegroundCommand(Intent intent, String executablePath, Stri
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(this);
preferences.setCurrentSession(newSession.mHandle);

// Notify {@link TermuxSessionsListViewController} that sessions list has been updated if
// activity in is foreground
if(mTermuxSessionClient != null)
mTermuxSessionClient.terminalSessionListNotifyUpdated();

// Launch the main Termux app, which will now show the current session:
startActivity(new Intent(this, TermuxActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void onTitleChanged(TerminalSession updatedSession) {
mActivity.showToast(toToastTitle(updatedSession), true);
}

mActivity.terminalSessionListNotifyUpdated();
terminalSessionListNotifyUpdated();
}

@Override
Expand Down Expand Up @@ -101,7 +101,7 @@ public void onSessionFinished(final TerminalSession finishedSession) {
}
}

mActivity.terminalSessionListNotifyUpdated();
terminalSessionListNotifyUpdated();
}

@Override
Expand Down Expand Up @@ -152,7 +152,7 @@ void noteSessionInfo() {
TerminalSession session = mActivity.getCurrentSession();
final int indexOfSession = mActivity.getTermuxService().getSessions().indexOf(session);
mActivity.showToast(toToastTitle(session), false);
mActivity.terminalSessionListNotifyUpdated();
terminalSessionListNotifyUpdated();

final ListView termuxSessionsListView = mActivity.findViewById(R.id.terminal_sessions_list);
termuxSessionsListView.setItemChecked(indexOfSession, true);
Expand All @@ -178,7 +178,7 @@ public void renameSession(final TerminalSession sessionToRename) {

DialogUtils.textInput(mActivity, R.string.session_rename_title, sessionToRename.mSessionName, R.string.session_rename_positive_button, text -> {
sessionToRename.mSessionName = text;
mActivity.terminalSessionListNotifyUpdated();
terminalSessionListNotifyUpdated();
}, -1, null, -1, null, null);
}

Expand Down Expand Up @@ -250,7 +250,7 @@ public void removeFinishedSession(TerminalSession finishedSession) {
TermuxService service = mActivity.getTermuxService();

int index = service.removeTerminalSession(finishedSession);
mActivity.terminalSessionListNotifyUpdated();
terminalSessionListNotifyUpdated();
if (mActivity.getTermuxService().getSessions().isEmpty()) {
// There are no sessions to show, so finish the activity.
mActivity.finishActivityIfNotFinishing();
Expand All @@ -262,6 +262,10 @@ public void removeFinishedSession(TerminalSession finishedSession) {
}
}

public void terminalSessionListNotifyUpdated() {
mActivity.terminalSessionListNotifyUpdated();
}



String toToastTitle(TerminalSession session) {
Expand Down

0 comments on commit ae260fa

Please sign in to comment.