1
1
package com .termux .boot ;
2
2
3
3
import android .annotation .SuppressLint ;
4
+ import android .app .job .JobInfo ;
5
+ import android .app .job .JobScheduler ;
6
+ import android .content .BroadcastReceiver ;
7
+ import android .content .ComponentName ;
4
8
import android .content .Context ;
5
9
import android .content .Intent ;
6
- import android .net .Uri ;
7
- import android .support .v4 .content .WakefulBroadcastReceiver ;
10
+ import android .os .PersistableBundle ;
8
11
import android .util .Log ;
9
12
10
13
import java .io .File ;
11
14
import java .util .Arrays ;
12
15
import java .util .Comparator ;
13
16
14
- public class BootReceiver extends WakefulBroadcastReceiver {
15
-
16
- // Constants from TermuxService.
17
- private static final String TERMUX_SERVICE = "com.termux.app.TermuxService" ;
18
- private static final String ACTION_EXECUTE = "com.termux.service_execute" ;
19
- private static final String EXTRA_EXECUTE_IN_BACKGROUND = "com.termux.execute.background" ;
17
+ public class BootReceiver extends BroadcastReceiver {
20
18
21
19
@ Override
22
20
public void onReceive (Context context , Intent intent ) {
@@ -43,13 +41,18 @@ public int compare(File f1, File f2) {
43
41
logMessage .append (file .getName ());
44
42
45
43
ensureFileReadableAndExecutable (file );
46
- Uri scriptUri = new Uri .Builder ().scheme ("com.termux.file" ).path (file .getAbsolutePath ()).build ();
47
44
48
- Intent executeIntent = new Intent (ACTION_EXECUTE , scriptUri );
49
- executeIntent .setClassName ("com.termux" , TERMUX_SERVICE );
50
- executeIntent .putExtra (EXTRA_EXECUTE_IN_BACKGROUND , true );
45
+ PersistableBundle extras = new PersistableBundle ();
46
+ extras .putString (BootJobService .SCRIPT_FILE_PATH , file .getAbsolutePath ());
51
47
52
- startWakefulService (context , executeIntent );
48
+ ComponentName serviceComponent = new ComponentName (context , BootJobService .class );
49
+ JobInfo job = new JobInfo .Builder (0 , serviceComponent )
50
+ .setExtras (extras )
51
+ .setOverrideDeadline (3 * 1000 )
52
+ .build ();
53
+ JobScheduler jobScheduler = (JobScheduler ) context .getSystemService (Context .JOB_SCHEDULER_SERVICE );
54
+ assert jobScheduler != null ;
55
+ jobScheduler .schedule (job );
53
56
}
54
57
55
58
if (logMessage .length () > 0 ) {
0 commit comments