sessions: failsafe session is now accessible via separate launcher icon

Also enables session autoclosing so no more "annoying" messages
about "process completed - press enter". There autoclosing will be
performed on exit codes '0' and '130'.

On Android TV devices old behaviour will be used - auto close enabled for all
sessions when amount of running sessions >1.
This commit is contained in:
Leonid Plyushch
2019-02-11 20:10:33 +02:00
committed by Fredrik Fornwall
parent bda80547ad
commit fe41cd486f
4 changed files with 51 additions and 5 deletions

View File

@@ -37,14 +37,25 @@
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </intent-filter>
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LEANBACK_LAUNCHER" /> <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter> </intent-filter>
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" /> <meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts" />
</activity> </activity>
<activity
android:name="com.termux.app.TermuxFailsafeActivity"
android:label="@string/app_failsafe_mode" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity <activity
android:name="com.termux.app.TermuxHelpActivity" android:name="com.termux.app.TermuxHelpActivity"
android:exported="false" android:exported="false"

View File

@@ -367,8 +367,18 @@ public final class TermuxActivity extends Activity implements ServiceConnection
showToast(toToastTitle(finishedSession) + " - exited", true); showToast(toToastTitle(finishedSession) + " - exited", true);
} }
if (mTermService.getSessions().size() > 1) { if (getPackageManager().hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
removeFinishedSession(finishedSession); // On Android TV devices we need to use older behaviour because we may
// not be able to have multiple launcher icons.
if (mTermService.getSessions().size() > 1) {
removeFinishedSession(finishedSession);
}
} else {
// Once we have a separate launcher icon for the failsafe session, it
// should be safe to auto-close session on exit code '0' or '130'.
if (finishedSession.getExitStatus() == 0 || finishedSession.getExitStatus() == 130) {
removeFinishedSession(finishedSession);
}
} }
mListViewAdapter.notifyDataSetChanged(); mListViewAdapter.notifyDataSetChanged();
@@ -465,8 +475,13 @@ public final class TermuxActivity extends Activity implements ServiceConnection
TermuxInstaller.setupIfNeeded(TermuxActivity.this, () -> { TermuxInstaller.setupIfNeeded(TermuxActivity.this, () -> {
if (mTermService == null) return; // Activity might have been destroyed. if (mTermService == null) return; // Activity might have been destroyed.
try { try {
Bundle bundle = getIntent().getExtras();
boolean launchFailsafe = false;
if (bundle != null) {
launchFailsafe = bundle.getBoolean(TermuxFailsafeActivity.TERMUX_FAILSAFE_SESSION_ACTION, false);
}
clearTemporaryDirectory(); clearTemporaryDirectory();
addNewSession(false, null); addNewSession(launchFailsafe, null);
} catch (WindowManager.BadTokenException e) { } catch (WindowManager.BadTokenException e) {
// Activity finished - ignore. // Activity finished - ignore.
} }

View File

@@ -0,0 +1,19 @@
package com.termux.app;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public final class TermuxFailsafeActivity extends Activity {
public static final String TERMUX_FAILSAFE_SESSION_ACTION = "com.termux.app.failsafe_session";
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
Intent intent = new Intent(TermuxFailsafeActivity.this, TermuxActivity.class);
intent.putExtra(TERMUX_FAILSAFE_SESSION_ACTION, true);
startActivity(intent);
finish();
}
}

View File

@@ -2,6 +2,7 @@
<resources> <resources>
<string name="application_name">Termux</string> <string name="application_name">Termux</string>
<string name="shared_user_label">Termux user</string> <string name="shared_user_label">Termux user</string>
<string name="app_failsafe_mode">Termux (failsafe)</string>
<string name="new_session">New session</string> <string name="new_session">New session</string>
<string name="new_session_failsafe">Failsafe</string> <string name="new_session_failsafe">Failsafe</string>
<string name="toggle_soft_keyboard">Keyboard</string> <string name="toggle_soft_keyboard">Keyboard</string>