summaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorJavier <dev.git@javispedro.com>2020-02-16 23:52:36 +0100
committerJavier <dev.git@javispedro.com>2020-02-16 23:52:36 +0100
commit2c104cf650052b544edc384f55798aacb44efbeb (patch)
treefbe819a03c98a45616162aaaf0a5f09407149d0f /app/src/main/java
parent139a04da8b0810d12a8780dd6c3ae2f11ca9268f (diff)
downloadvndroid-2c104cf650052b544edc384f55798aacb44efbeb.tar.gz
vndroid-2c104cf650052b544edc384f55798aacb44efbeb.zip
fix non-sticky service
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/com/javispedro/vndroid/KeyEventOutput.java12
-rw-r--r--app/src/main/java/com/javispedro/vndroid/ServerService.java9
-rw-r--r--app/src/main/java/com/javispedro/vndroid/SettingsActivity.java12
3 files changed, 21 insertions, 12 deletions
diff --git a/app/src/main/java/com/javispedro/vndroid/KeyEventOutput.java b/app/src/main/java/com/javispedro/vndroid/KeyEventOutput.java
index 3ec4319..f72fe49 100644
--- a/app/src/main/java/com/javispedro/vndroid/KeyEventOutput.java
+++ b/app/src/main/java/com/javispedro/vndroid/KeyEventOutput.java
@@ -22,6 +22,8 @@ public class KeyEventOutput implements KeyActionHandler {
ControlService service = ControlService.getInstance();
if (service != null) {
return service.findFocus(AccessibilityNodeInfo.FOCUS_INPUT);
+ } else {
+ Log.w(TAG, "accessibility service not enabled, cannot control keyboard");
}
return null;
}
@@ -32,7 +34,7 @@ public class KeyEventOutput implements KeyActionHandler {
}
public void postKeyEvent(int key, boolean state) {
- if (state) Log.d(TAG, "keysym pressed: " + Integer.toHexString(key));
+ if (state) Log.d(TAG, "keysym pressed: 0x" + Integer.toHexString(key));
for (KeyHandler handler : handlers) {
boolean handled;
if (state) {
@@ -49,8 +51,12 @@ public class KeyEventOutput implements KeyActionHandler {
@Override
public void postText(CharSequence text) {
AccessibilityNodeInfo node = getFocusNode();
- if (node == null || !node.isEditable()) {
- Log.d(TAG, "no input focus or not editable");
+ if (node == null) {
+ Log.d(TAG, "no input focus");
+ return;
+ }
+ if (!node.isEditable()) {
+ Log.d(TAG, "input focus is not editable");
return;
}
diff --git a/app/src/main/java/com/javispedro/vndroid/ServerService.java b/app/src/main/java/com/javispedro/vndroid/ServerService.java
index b39f175..f8c8f9b 100644
--- a/app/src/main/java/com/javispedro/vndroid/ServerService.java
+++ b/app/src/main/java/com/javispedro/vndroid/ServerService.java
@@ -23,7 +23,7 @@ import java.util.List;
public class ServerService extends Service {
private static final String TAG = ServerService.class.getSimpleName();
- public static final String ACTION_START_SERVER = "ACTION_START_SERVER";
+ public static final String ACTION_INIT_SERVICE = "ACTION_INIT_SERVICE";
public static final String ACTION_STOP_SERVER = "ACTION_STOP_SERVER";
public class ServerBinder extends Binder {
@@ -67,11 +67,10 @@ public class ServerService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
- Log.d(TAG, "onStartCommand intent=" + intent);
switch (intent.getAction()) {
- case ACTION_START_SERVER:
- startServer();
- return START_REDELIVER_INTENT;
+ case ACTION_INIT_SERVICE:
+ // Nothing to do
+ return START_STICKY;
case ACTION_STOP_SERVER:
stopServer();
return START_NOT_STICKY;
diff --git a/app/src/main/java/com/javispedro/vndroid/SettingsActivity.java b/app/src/main/java/com/javispedro/vndroid/SettingsActivity.java
index 676af3d..f595eac 100644
--- a/app/src/main/java/com/javispedro/vndroid/SettingsActivity.java
+++ b/app/src/main/java/com/javispedro/vndroid/SettingsActivity.java
@@ -2,7 +2,6 @@ package com.javispedro.vndroid;
import android.app.Activity;
import android.content.ComponentName;
-import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.projection.MediaProjectionManager;
@@ -83,7 +82,6 @@ public class SettingsActivity extends AppCompatActivity {
}
private void setServerEnabled(boolean state) {
- Log.d(TAG, "setServerEnabled: " + state);
ServerService server = serverConnection.getServer();
if (state) {
if (server == null) {
@@ -183,12 +181,18 @@ public class SettingsActivity extends AppCompatActivity {
public void bind(Activity activity, ServerService.ServerStatusCallback callback) {
this.callback = callback;
- activity.bindService(new Intent(activity, ServerService.class), this, Context.BIND_AUTO_CREATE);
+ Intent intent = new Intent(activity, ServerService.class);
+ intent.setAction(ServerService.ACTION_INIT_SERVICE);
+ activity.startService(intent);
+ activity.bindService(intent, this, 0);
}
public void close(Activity activity) {
- server.setServerStatusCallback(null);
+ if (server != null) {
+ server.setServerStatusCallback(null);
+ }
activity.unbindService(this);
+ callback = null;
}
public boolean connected() {