From 2d50a97d8b8a26ea6c08f9ac8990f19bd1c56aa2 Mon Sep 17 00:00:00 2001 From: Frank Afriat Date: Tue, 15 Jan 2019 18:38:02 +0200 Subject: [PATCH] Fix start on boot on 8.1 --- app/src/main/AndroidManifest.xml | 1 + .../java/ru/meefik/linuxdeploy/EnvUtils.java | 2 +- .../ru/meefik/linuxdeploy/ExecService.java | 28 ++++++++----------- 3 files changed, 13 insertions(+), 18 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 5c43aafe..926b424d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -108,6 +108,7 @@ diff --git a/app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java b/app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java index b1bb9490..ba233979 100644 --- a/app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java +++ b/app/src/main/java/ru/meefik/linuxdeploy/EnvUtils.java @@ -494,7 +494,7 @@ static void execService(Context c, String cmd, String args) { Intent service = new Intent(c, ExecService.class); service.putExtra("cmd", cmd); service.putExtra("args", args); - c.startService(service); + ExecService.enqueueWork(c, service); } /** diff --git a/app/src/main/java/ru/meefik/linuxdeploy/ExecService.java b/app/src/main/java/ru/meefik/linuxdeploy/ExecService.java index 9ce58a8d..dda70dda 100644 --- a/app/src/main/java/ru/meefik/linuxdeploy/ExecService.java +++ b/app/src/main/java/ru/meefik/linuxdeploy/ExecService.java @@ -4,24 +4,19 @@ import android.content.Context; import android.content.Intent; import android.os.IBinder; +import android.support.annotation.NonNull; +import android.support.v4.app.JobIntentService; -public class ExecService extends Service { +public class ExecService extends JobIntentService { - Context mContext; + public static final int JOB_ID = 1; - @Override - public void onCreate() { - super.onCreate(); - mContext = getBaseContext(); - } - - @Override - public IBinder onBind(Intent arg0) { - return null; + public static void enqueueWork(Context context, Intent work) { + enqueueWork(context, ExecService.class, JOB_ID, work); } @Override - public int onStartCommand(Intent intent, int flags, int startId) { + protected void onHandleWork(@NonNull Intent intent) { if (intent != null) { final String cmd = intent.getStringExtra("cmd"); final String args = intent.getStringExtra("args"); @@ -30,20 +25,19 @@ public int onStartCommand(Intent intent, int flags, int startId) { public void run() { switch (cmd) { case "telnetd": - EnvUtils.telnetd(mContext, args); + EnvUtils.telnetd(getBaseContext(), args); break; case "httpd": - EnvUtils.httpd(mContext, args); + EnvUtils.httpd(getBaseContext(), args); break; default: - PrefStore.showNotification(mContext, null); - EnvUtils.cli(mContext, cmd, args); + PrefStore.showNotification(getBaseContext(), null); + EnvUtils.cli(getBaseContext(), cmd, args); } } }); thread.start(); } - return super.onStartCommand(intent, flags, startId); } }