Skip to content

Commit 12f910c

Browse files
Move Termux app specific logic out of PermissionUtils
1 parent 94c5f36 commit 12f910c

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,13 @@ private void startTermuxActivity() {
640640
// For android >= 10, apps require Display over other apps permission to start foreground activities
641641
// from background (services). If it is not granted, then TermuxSessions that are started will
642642
// show in Termux notification but will not run until user manually clicks the notification.
643-
if (PermissionUtils.validateDisplayOverOtherAppsPermissionForPostAndroid10(this)) {
643+
if (PermissionUtils.validateDisplayOverOtherAppsPermissionForPostAndroid10(this, true)) {
644644
TermuxActivity.startTermuxActivity(this);
645+
} else {
646+
TermuxAppSharedPreferences preferences = TermuxAppSharedPreferences.build(this);
647+
if (preferences == null) return;
648+
if (preferences.arePluginErrorNotificationsEnabled())
649+
Logger.showToast(this, this.getString(R.string.error_display_over_other_apps_permission_not_granted), true);
645650
}
646651
}
647652

app/src/main/res/values/strings.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191

9292

9393

94+
<!-- TermuxService -->
95+
<string name="error_display_over_other_apps_permission_not_granted">&TERMUX_APP_NAME; requires \"Display over other apps\" permission to start terminal sessions from background on Android >= 10. Grants it from Settings -> Apps -> &TERMUX_APP_NAME; -> Advanced</string>
96+
97+
98+
9499
<!-- Termux RunCommandService -->
95100
<string name="error_run_command_service_invalid_intent_action">Invalid intent action to RunCommandService: `%1$s`</string>
96101
<string name="error_run_command_service_mandatory_extra_missing">Mandatory extra missing to RunCommandService: \"%1$s\"</string>

termux-shared/src/main/java/com/termux/shared/packages/PermissionUtils.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
import androidx.core.content.ContextCompat;
1414

1515
import com.termux.shared.R;
16-
import com.termux.shared.termux.TermuxConstants;
1716
import com.termux.shared.logger.Logger;
18-
import com.termux.shared.settings.preferences.TermuxAppSharedPreferences;
1917

2018
import java.util.Arrays;
2119

@@ -81,20 +79,16 @@ public static void requestDisplayOverOtherAppsPermission(Activity context, int r
8179
context.startActivityForResult(intent, requestCode);
8280
}
8381

84-
public static boolean validateDisplayOverOtherAppsPermissionForPostAndroid10(Context context) {
82+
public static boolean validateDisplayOverOtherAppsPermissionForPostAndroid10(Context context, boolean logResults) {
8583
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return true;
8684

8785
if (!PermissionUtils.checkDisplayOverOtherAppsPermission(context)) {
88-
Logger.logWarn(LOG_TAG, TermuxConstants.TERMUX_APP_NAME + " App does not have Display over other apps (SYSTEM_ALERT_WINDOW) permission");
89-
90-
TermuxAppSharedPreferences preferences = TermuxAppSharedPreferences.build(context);
91-
if (preferences == null) return false;
92-
93-
if (preferences.arePluginErrorNotificationsEnabled())
94-
Logger.showToast(context, context.getString(R.string.error_display_over_other_apps_permission_not_granted), true);
86+
if (logResults)
87+
Logger.logWarn(LOG_TAG, context.getPackageName() + " does not have Display over other apps (SYSTEM_ALERT_WINDOW) permission");
9588
return false;
9689
} else {
97-
Logger.logDebug(LOG_TAG, TermuxConstants.TERMUX_APP_NAME + " App already has Display over other apps (SYSTEM_ALERT_WINDOW) permission");
90+
if (logResults)
91+
Logger.logDebug(LOG_TAG, context.getPackageName() + " already has Display over other apps (SYSTEM_ALERT_WINDOW) permission");
9892
return true;
9993
}
10094
}

termux-shared/src/main/res/values/strings.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
<!-- PermissionUtils -->
2727
<string name="message_sudo_please_grant_permissions">Please grant permissions on next screen</string>
28-
<string name="error_display_over_other_apps_permission_not_granted">&TERMUX_APP_NAME; requires \"Display over other apps\" permission to start terminal sessions from background on Android >= 10. Grants it from Settings -> Apps -> &TERMUX_APP_NAME; -> Advanced</string>
2928

3029

3130

0 commit comments

Comments
 (0)