@@ -105,8 +105,6 @@ public final class TermuxActivity extends Activity implements ServiceConnection
105
105
private static final String BROADCAST_TERMUX_OPENED = TermuxConstants .TERMUX_PACKAGE_NAME + ".app.OPENED" ;
106
106
107
107
/** The main view of the activity showing the terminal. Initialized in onCreate(). */
108
- @ SuppressWarnings ("NullableProblems" )
109
- @ NonNull
110
108
TerminalView mTerminalView ;
111
109
112
110
ExtraKeysView mExtraKeysView ;
@@ -366,7 +364,7 @@ void sendOpenedBroadcast() {
366
364
for (ResolveInfo info : matches ) {
367
365
Intent explicitBroadcast = new Intent (broadcast );
368
366
ComponentName cname = new ComponentName (info .activityInfo .applicationInfo .packageName ,
369
- info .activityInfo .name );
367
+ info .activityInfo .name );
370
368
explicitBroadcast .setComponent (cname );
371
369
sendBroadcast (explicitBroadcast );
372
370
}
@@ -488,7 +486,10 @@ public View getView(int position, View convertView, @NonNull ViewGroup parent) {
488
486
}
489
487
490
488
TerminalSession sessionAtRow = getItem (position );
491
- boolean sessionRunning = sessionAtRow .isRunning ();
489
+ if (sessionAtRow == null ) return row ;
490
+
491
+ boolean sessionRunning = false ;
492
+ sessionRunning = sessionAtRow .isRunning ();
492
493
493
494
TextView firstLineView = row .findViewById (R .id .row_line );
494
495
if (mIsUsingBlackUI ) {
@@ -577,6 +578,7 @@ public void switchToSession(boolean forward) {
577
578
578
579
@ SuppressLint ("InflateParams" )
579
580
void renameSession (final TerminalSession sessionToRename ) {
581
+ if (sessionToRename == null ) return ;
580
582
DialogUtils .textInput (this , R .string .session_rename_title , sessionToRename .mSessionName , R .string .session_rename_positive_button , text -> {
581
583
sessionToRename .mSessionName = text ;
582
584
mListViewAdapter .notifyDataSetChanged ();
@@ -629,6 +631,7 @@ protected void onStop() {
629
631
getDrawer ().closeDrawers ();
630
632
}
631
633
634
+ @ SuppressLint ("RtlHardcoded" )
632
635
@ Override
633
636
public void onBackPressed () {
634
637
if (getDrawer ().isDrawerOpen (Gravity .LEFT )) {
@@ -825,7 +828,10 @@ static LinkedHashSet<CharSequence> extractUrls(String text) {
825
828
}
826
829
827
830
void showUrlSelection () {
828
- String text = getCurrentTermSession ().getEmulator ().getScreen ().getTranscriptTextWithFullLinesJoined ();
831
+ String text = null ;
832
+ if (getCurrentTermSession () != null ) {
833
+ text = getCurrentTermSession ().getEmulator ().getScreen ().getTranscriptTextWithFullLinesJoined ();
834
+ }
829
835
LinkedHashSet <CharSequence > urlSet = extractUrls (text );
830
836
if (urlSet .isEmpty ()) {
831
837
new AlertDialog .Builder (this ).setMessage (R .string .select_url_no_found ).show ();
@@ -896,11 +902,14 @@ public boolean onContextItemSelected(MenuItem item) {
896
902
return true ;
897
903
case CONTEXTMENU_KILL_PROCESS_ID :
898
904
final AlertDialog .Builder b = new AlertDialog .Builder (this );
905
+ final TerminalSession terminalSession = getCurrentTermSession ();
906
+ if (terminalSession == null ) return true ;
907
+
899
908
b .setIcon (android .R .drawable .ic_dialog_alert );
900
909
b .setMessage (R .string .confirm_kill_process );
901
910
b .setPositiveButton (android .R .string .yes , (dialog , id ) -> {
902
911
dialog .dismiss ();
903
- getCurrentTermSession () .finishIfRunning ();
912
+ terminalSession .finishIfRunning ();
904
913
});
905
914
b .setNegativeButton (android .R .string .no , null );
906
915
b .show ();
@@ -952,7 +961,7 @@ public boolean onContextItemSelected(MenuItem item) {
952
961
}
953
962
954
963
@ Override
955
- public void onRequestPermissionsResult (int requestCode , @ NonNull String permissions [] , @ NonNull int [] grantResults ) {
964
+ public void onRequestPermissionsResult (int requestCode , @ NonNull String [] permissions , @ NonNull int [] grantResults ) {
956
965
if (requestCode == REQUESTCODE_PERMISSION_STORAGE && grantResults .length > 0 && grantResults [0 ] == PackageManager .PERMISSION_GRANTED ) {
957
966
TermuxInstaller .setupStorageSymlinks (this );
958
967
}
@@ -969,7 +978,9 @@ void doPaste() {
969
978
if (clipData == null ) return ;
970
979
CharSequence paste = clipData .getItemAt (0 ).coerceToText (this );
971
980
if (!TextUtils .isEmpty (paste ))
972
- getCurrentTermSession ().getEmulator ().paste (paste .toString ());
981
+ if (getCurrentTermSession () != null ) {
982
+ getCurrentTermSession ().getEmulator ().paste (paste .toString ());
983
+ }
973
984
}
974
985
975
986
/** The current session as stored or the last one if that does not exist. */
0 commit comments