diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 4e95702bc3..f76da1e67f 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -196,7 +196,8 @@
+ android:exported="true"
+ android:enabled="true" />
= Build.VERSION_CODES.Q) {
+ if (!Settings.canDrawOverlays(context)) {
+ startActivity(new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION));
+ }
+ }
+
mIsOnResumeAfterOnCreate = true;
if (savedInstanceState != null)
@@ -257,9 +272,17 @@ public void onCreate(Bundle savedInstanceState) {
FileReceiverActivity.updateFileReceiverActivityComponentsState(this);
try {
+ Intent serviceIntent;
// Start the {@link TermuxService} and make it run regardless of who is bound to it
- Intent serviceIntent = new Intent(this, TermuxService.class);
- startService(serviceIntent);
+ // O is Oreo, Android 8
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ serviceIntent = new Intent(context, TermuxService.class);
+ context.startForegroundService(serviceIntent);
+ }
+ else {
+ serviceIntent = new Intent(this, TermuxService.class);
+ startService(serviceIntent);
+ }
// Attempt to bind to the service, this will call the {@link #onServiceConnected(ComponentName, IBinder)}
// callback if it succeeds.
diff --git a/app/src/main/java/com/termux/app/TermuxService.java b/app/src/main/java/com/termux/app/TermuxService.java
index 8025d0bd2c..b7707101ec 100644
--- a/app/src/main/java/com/termux/app/TermuxService.java
+++ b/app/src/main/java/com/termux/app/TermuxService.java
@@ -159,10 +159,9 @@ public int onStartCommand(Intent intent, int flags, int startId) {
break;
}
}
-
- // If this service really do get killed, there is no point restarting it automatically - let the user do on next
- // start of {@link Term):
- return Service.START_NOT_STICKY;
+ // If Service.START_NOT_STICKY is used this service will be killed when device not connected to charger
+ // (probably only for Xiaomi Redmi 7A with Android 10)
+ return Service.START_STICKY;
}
@Override
diff --git a/app/src/main/java/com/termux/app/event/SystemEventReceiver.java b/app/src/main/java/com/termux/app/event/SystemEventReceiver.java
index efc710f312..769a213a3d 100644
--- a/app/src/main/java/com/termux/app/event/SystemEventReceiver.java
+++ b/app/src/main/java/com/termux/app/event/SystemEventReceiver.java
@@ -5,10 +5,12 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
+import android.os.Build;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
+import com.termux.app.TermuxService;
import com.termux.shared.data.IntentUtils;
import com.termux.shared.logger.Logger;
import com.termux.shared.termux.TermuxUtils;
@@ -51,8 +53,20 @@ public void onReceive(@NonNull Context context, @Nullable Intent intent) {
}
}
+ private void runTermuxService(@NonNull Context context) {
+ Intent serviceIntent = new Intent(context, TermuxService.class);
+ // O is Oreo, Android 8
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ context.startForegroundService(serviceIntent);
+ }
+ else {
+ context.startService(serviceIntent);
+ }
+ }
+
public synchronized void onActionBootCompleted(@NonNull Context context, @NonNull Intent intent) {
TermuxShellManager.onActionBootCompleted(context, intent);
+ runTermuxService(context);
}
public synchronized void onActionPackageUpdated(@NonNull Context context, @NonNull Intent intent) {