Skip to content

Commit

Permalink
refactor: try tcpip connection first
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Feb 12, 2024
1 parent 3152f46 commit fd0a1ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
11 changes: 7 additions & 4 deletions app/src/main/java/xtr/keymapper/server/RemoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ public RemoteService() {

public static void main(String[] args) {
loadLibraries();
Looper.prepare();
Looper.prepareMainLooper();
new RemoteService(args);
Looper.loop();
}

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

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

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

// Socket should stay alive
private static LocalSocket socket;
public static LocalSocket socket;

public RemoteServiceSocketClient() {
public RemoteServiceSocketClient() throws IOException {
if (socket == null) {
socket = new LocalSocket();
try {
socket.connect(new LocalSocketAddress("xtmapper-a3e11694"));
} catch (IOException e) {
throw new RuntimeException(e);
}
socket.connect(new LocalSocketAddress("xtmapper-a3e11694"));
}
}
public static class ParcelableByteArray {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ private <T> T readTypedObject(android.os.Parcelable.Creator<T> c) {
return obj;
}

// blocking
public RemoteServiceSocketServer(RemoteService mService) {
this.mService = mService;
try {
Expand Down

0 comments on commit fd0a1ff

Please sign in to comment.