Skip to content

Commit c82e165

Browse files
author
朱辉\harry
committed
清理adb forward
1 parent f58d8a0 commit c82e165

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/main/java/com/yeetor/minicap/Minicap.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ private void removeForward(AdbForward forward) {
170170
device.removeForward(forward.getPort(), forward.getLocalabstract(), IDevice.DeviceUnixSocketNamespace.ABSTRACT);
171171
} catch (Exception e) {
172172
e.printStackTrace();
173-
System.out.println("remove forward failed");
174173
}
175174
}
176175

@@ -412,8 +411,8 @@ private void onStartup(boolean success) {
412411
private void onClose() {
413412
for (MinicapListener listener : listenerList) {
414413
listener.onClose(this);
415-
removeForward(forward);
416414
}
415+
removeForward(forward);
417416
}
418417

419418
private void onBanner(Banner banner) {

src/main/java/com/yeetor/minitouch/Minitouch.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ public AdbForward createForward() {
9797
return forward;
9898
}
9999

100+
private void removeForward(AdbForward forward) {
101+
if (forward == null || !forward.isForward()) {
102+
return;
103+
}
104+
try {
105+
device.removeForward(forward.getPort(), forward.getLocalabstract(), IDevice.DeviceUnixSocketNamespace.ABSTRACT);
106+
} catch (Exception e) {
107+
}
108+
}
109+
100110
public void start() {
101111
AdbForward forward = createForward();
102112
String command = "/data/local/tmp/minitouch" + " -n " + forward.getLocalabstract();
@@ -247,5 +257,6 @@ private void onClose() {
247257
for (MinitouchListener listener : listenerList) {
248258
listener.onClose(this);
249259
}
260+
removeForward(forward);
250261
}
251262
}

0 commit comments

Comments
 (0)