Skip to content

Commit ae260fa

Browse files
Fix old bug where termux app would crash if sessions list ListView was 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.
1 parent d9b5344 commit ae260fa

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

app/src/main/java/com/termux/app/TermuxService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,11 @@ private void executeForegroundCommand(Intent intent, String executablePath, Stri
319319
TermuxAppSharedPreferences preferences = new TermuxAppSharedPreferences(this);
320320
preferences.setCurrentSession(newSession.mHandle);
321321

322+
// Notify {@link TermuxSessionsListViewController} that sessions list has been updated if
323+
// activity in is foreground
324+
if(mTermuxSessionClient != null)
325+
mTermuxSessionClient.terminalSessionListNotifyUpdated();
326+
322327
// Launch the main Termux app, which will now show the current session:
323328
startActivity(new Intent(this, TermuxActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
324329
}

app/src/main/java/com/termux/app/terminal/TermuxSessionClient.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void onTitleChanged(TerminalSession updatedSession) {
6868
mActivity.showToast(toToastTitle(updatedSession), true);
6969
}
7070

71-
mActivity.terminalSessionListNotifyUpdated();
71+
terminalSessionListNotifyUpdated();
7272
}
7373

7474
@Override
@@ -101,7 +101,7 @@ public void onSessionFinished(final TerminalSession finishedSession) {
101101
}
102102
}
103103

104-
mActivity.terminalSessionListNotifyUpdated();
104+
terminalSessionListNotifyUpdated();
105105
}
106106

107107
@Override
@@ -152,7 +152,7 @@ void noteSessionInfo() {
152152
TerminalSession session = mActivity.getCurrentSession();
153153
final int indexOfSession = mActivity.getTermuxService().getSessions().indexOf(session);
154154
mActivity.showToast(toToastTitle(session), false);
155-
mActivity.terminalSessionListNotifyUpdated();
155+
terminalSessionListNotifyUpdated();
156156

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

179179
DialogUtils.textInput(mActivity, R.string.session_rename_title, sessionToRename.mSessionName, R.string.session_rename_positive_button, text -> {
180180
sessionToRename.mSessionName = text;
181-
mActivity.terminalSessionListNotifyUpdated();
181+
terminalSessionListNotifyUpdated();
182182
}, -1, null, -1, null, null);
183183
}
184184

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

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

265+
public void terminalSessionListNotifyUpdated() {
266+
mActivity.terminalSessionListNotifyUpdated();
267+
}
268+
265269

266270

267271
String toToastTitle(TerminalSession session) {

0 commit comments

Comments
 (0)