Skip to content

Commit

Permalink
fix: call Looper.loop()
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Feb 15, 2024
1 parent fd0a1ff commit 248558b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions app/src/main/java/xtr/keymapper/server/RemoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.util.Log;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import xtr.keymapper.ActivityObserver;
Expand All @@ -22,6 +23,7 @@ public class RemoteService extends IRemoteService.Stub {
private OnKeyEventListener mOnKeyEventListener;
private boolean isWaylandClient = false;
private ActivityObserverService activityObserverService;
private static IRemoteService service = null;

public RemoteService() {

Expand All @@ -31,6 +33,7 @@ public static void main(String[] args) {
loadLibraries();
Looper.prepareMainLooper();
new RemoteService(args);
Looper.loop();
}

public RemoteService(String[] args) {
Expand Down Expand Up @@ -181,12 +184,17 @@ public static void loadLibraries() {
}

public static IRemoteService getInstance(){
try {
return new RemoteServiceSocketClient();
} catch (Throwable tr) {
Log.e(tr.toString(), tr.getMessage(), tr);
return IRemoteService.Stub.asInterface(ServiceManager.getService("xtmapper"));
if (service == null) {
try {
service = new RemoteServiceSocketClient();
} catch (IOException e) {
Log.e(e.toString(), e.getMessage(), e);
RemoteServiceSocketClient.socket = null;
}
if (RemoteServiceSocketClient.socket == null)
service = IRemoteService.Stub.asInterface(ServiceManager.getService("xtmapper"));
}
return service;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class RemoteServiceSocketClient implements IRemoteService {

// Socket should stay alive
public static LocalSocket socket;
public static LocalSocket socket = null;

public RemoteServiceSocketClient() throws IOException {
if (socket == null) {
Expand Down

0 comments on commit 248558b

Please sign in to comment.