20
20
import android .widget .ArrayAdapter ;
21
21
22
22
import com .termux .R ;
23
- import com .termux .app .TermuxConstants .TERMUX_APP .TERMUX_ACTIVITY ;
24
- import com .termux .app .TermuxConstants .TERMUX_APP .TERMUX_SERVICE ;
25
- import com .termux .app .settings .preferences .TermuxAppSharedPreferences ;
23
+ import com .termux .shared .termux .TermuxConstants ;
24
+ import com .termux .shared .termux .TermuxConstants .TERMUX_APP .TERMUX_ACTIVITY ;
25
+ import com .termux .shared .termux .TermuxConstants .TERMUX_APP .TERMUX_SERVICE ;
26
+ import com .termux .shared .settings .preferences .TermuxAppSharedPreferences ;
26
27
import com .termux .app .terminal .TermuxSession ;
27
28
import com .termux .app .terminal .TermuxSessionClient ;
28
29
import com .termux .app .terminal .TermuxSessionClientBase ;
29
- import com .termux .app . utils .Logger ;
30
- import com .termux .app . utils .NotificationUtils ;
31
- import com .termux .app . utils .PermissionUtils ;
32
- import com .termux .app .shell .ShellUtils ;
33
- import com .termux .app . utils .DataUtils ;
30
+ import com .termux .shared . logger .Logger ;
31
+ import com .termux .shared . notification .NotificationUtils ;
32
+ import com .termux .shared . packages .PermissionUtils ;
33
+ import com .termux .shared .shell .ShellUtils ;
34
+ import com .termux .shared . data .DataUtils ;
34
35
import com .termux .app .models .ExecutionCommand ;
35
36
import com .termux .app .models .ExecutionCommand .ExecutionState ;
36
37
import com .termux .app .terminal .TermuxTask ;
37
38
import com .termux .terminal .TerminalEmulator ;
38
39
import com .termux .terminal .TerminalSession ;
39
40
import com .termux .terminal .TerminalSessionClient ;
40
41
41
- import java .io .File ;
42
42
import java .util .ArrayList ;
43
43
import java .util .List ;
44
44
58
58
*/
59
59
public final class TermuxService extends Service {
60
60
61
- private static final String NOTIFICATION_CHANNEL_ID = "termux_notification_channel" ;
62
- private static final String NOTIFICATION_CHANNEL_NAME = TermuxConstants .TERMUX_APP_NAME + " App" ;
63
- public static final int NOTIFICATION_ID = 1337 ;
64
-
65
61
private static int EXECUTION_ID = 1000 ;
66
62
67
63
/** This service is only bound from inside the same process and never uses IPC. */
@@ -95,7 +91,7 @@ class LocalBinder extends Binder {
95
91
/** The basic implementation of the {@link TerminalSessionClient} interface to be used by {@link TerminalSession}
96
92
* that does not hold activity references.
97
93
*/
98
- final TermuxSessionClientBase mTermuxSessionClientBase = new TermuxSessionClientBase ();;
94
+ final TermuxSessionClientBase mTermuxSessionClientBase = new TermuxSessionClientBase ();
99
95
100
96
/** The wake lock and wifi lock are always acquired and released together. */
101
97
private PowerManager .WakeLock mWakeLock ;
@@ -183,7 +179,7 @@ public boolean onUnbind(Intent intent) {
183
179
/** Make service run in foreground mode. */
184
180
private void runStartForeground () {
185
181
setupNotificationChannel ();
186
- startForeground (NOTIFICATION_ID , buildNotification ());
182
+ startForeground (TermuxConstants . TERMUX_APP_NOTIFICATION_ID , buildNotification ());
187
183
}
188
184
189
185
/** Make service leave foreground mode. */
@@ -366,7 +362,7 @@ public synchronized TermuxTask createTermuxTask(ExecutionCommand executionComman
366
362
if (newTermuxTask == null ) {
367
363
Logger .logError (LOG_TAG , "Failed to execute new termux task command for:\n " + executionCommand .getCommandIdAndLabelLogString ());
368
364
return null ;
369
- };
365
+ }
370
366
371
367
mTermuxTasks .add (newTermuxTask );
372
368
@@ -436,7 +432,7 @@ public synchronized TermuxSession createTermuxSession(ExecutionCommand execution
436
432
if (newTermuxSession == null ) {
437
433
Logger .logError (LOG_TAG , "Failed to execute new termux session command for:\n " + executionCommand .getCommandIdAndLabelLogString ());
438
434
return null ;
439
- };
435
+ }
440
436
441
437
mTermuxSessions .add (newTermuxSession );
442
438
@@ -593,13 +589,13 @@ private Notification buildNotification() {
593
589
// Set notification text
594
590
int sessionCount = getTermuxSessionsSize ();
595
591
int taskCount = mTermuxTasks .size ();
596
- String notifiationText = sessionCount + " session" + (sessionCount == 1 ? "" : "s" );
592
+ String notificationText = sessionCount + " session" + (sessionCount == 1 ? "" : "s" );
597
593
if (taskCount > 0 ) {
598
- notifiationText += ", " + taskCount + " task" + (taskCount == 1 ? "" : "s" );
594
+ notificationText += ", " + taskCount + " task" + (taskCount == 1 ? "" : "s" );
599
595
}
600
596
601
597
final boolean wakeLockHeld = mWakeLock != null ;
602
- if (wakeLockHeld ) notifiationText += " (wake lock held)" ;
598
+ if (wakeLockHeld ) notificationText += " (wake lock held)" ;
603
599
604
600
605
601
// Set notification priority
@@ -610,8 +606,8 @@ private Notification buildNotification() {
610
606
611
607
// Build the notification
612
608
Notification .Builder builder = NotificationUtils .geNotificationBuilder (this ,
613
- NOTIFICATION_CHANNEL_ID , priority ,
614
- getText (R .string .application_name ), notifiationText , null ,
609
+ TermuxConstants . TERMUX_APP_NOTIFICATION_CHANNEL_ID , priority ,
610
+ getText (R .string .application_name ), notificationText , null ,
615
611
pendingIntent , NotificationUtils .NOTIFICATION_MODE_SILENT );
616
612
if (builder == null ) return null ;
617
613
@@ -647,8 +643,8 @@ private Notification buildNotification() {
647
643
private void setupNotificationChannel () {
648
644
if (Build .VERSION .SDK_INT < Build .VERSION_CODES .O ) return ;
649
645
650
- NotificationUtils .setupNotificationChannel (this , NOTIFICATION_CHANNEL_ID ,
651
- NOTIFICATION_CHANNEL_NAME , NotificationManager .IMPORTANCE_LOW );
646
+ NotificationUtils .setupNotificationChannel (this , TermuxConstants . TERMUX_APP_NOTIFICATION_CHANNEL_ID ,
647
+ TermuxConstants . TERMUX_APP_NOTIFICATION_CHANNEL_NAME , NotificationManager .IMPORTANCE_LOW );
652
648
}
653
649
654
650
/** Update the shown foreground service notification after making any changes that affect it. */
@@ -657,7 +653,7 @@ void updateNotification() {
657
653
// Exit if we are updating after the user disabled all locks with no sessions or tasks running.
658
654
requestStopService ();
659
655
} else {
660
- ((NotificationManager ) getSystemService (Context .NOTIFICATION_SERVICE )).notify (NOTIFICATION_ID , buildNotification ());
656
+ ((NotificationManager ) getSystemService (Context .NOTIFICATION_SERVICE )).notify (TermuxConstants . TERMUX_APP_NOTIFICATION_ID , buildNotification ());
661
657
}
662
658
}
663
659
0 commit comments