fix(automator): RootAutomator (x, y) not correct on some devices

This commit is contained in:
hyb1996
2018-09-16 01:49:33 +08:00
parent 91d5eab872
commit c5c9aaa8e1
7 changed files with 18 additions and 16 deletions

Binary file not shown.

View File

@@ -8,8 +8,8 @@ android {
applicationId "org.autojs.autojs" applicationId "org.autojs.autojs"
minSdkVersion 17 minSdkVersion 17
targetSdkVersion 23 targetSdkVersion 23
versionCode 414 versionCode 416
versionName "4.0.2 Alpha9" versionName "4.0.2 Alpha11"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
multiDexEnabled true multiDexEnabled true
ndk { ndk {

View File

@@ -192,7 +192,7 @@ public class CodeEditText extends AppCompatEditText {
return; return;
} }
JavaScriptHighlighter.HighlightTokens highlightTokens = mHighlightTokens; JavaScriptHighlighter.HighlightTokens highlightTokens = mHighlightTokens;
Log.d(LOG_TAG, "drawText: tokens = " + highlightTokens); //Log.d(LOG_TAG, "drawText: tokens = " + highlightTokens);
Layout layout = getLayout(); Layout layout = getLayout();
int lineCount = getLineCount(); int lineCount = getLineCount();
int textLength = highlightTokens == null ? 0 : highlightTokens.getText().length(); int textLength = highlightTokens == null ? 0 : highlightTokens.getText().length();

View File

@@ -13,6 +13,7 @@ import com.stardust.autojs.runtime.exception.ScriptInterruptedException;
import com.stardust.util.ScreenMetrics; import com.stardust.util.ScreenMetrics;
import java.io.IOException; import java.io.IOException;
import java.util.Locale;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import static com.stardust.autojs.core.inputevent.InputEventCodes.*; import static com.stardust.autojs.core.inputevent.InputEventCodes.*;
@@ -45,7 +46,7 @@ public class RootAutomator implements Shell.Callback {
mContext = context; mContext = context;
mShell = new Shell(true); mShell = new Shell(true);
mShell.setCallback(this); mShell.setCallback(this);
if(waitForReady){ if (waitForReady) {
waitForReady(); waitForReady();
} }
} }
@@ -61,11 +62,11 @@ public class RootAutomator implements Shell.Callback {
} }
private void waitForReady() throws IOException { private void waitForReady() throws IOException {
if(mReady){ if (mReady) {
return; return;
} }
synchronized (mReadyLock){ synchronized (mReadyLock) {
if(mReady){ if (mReady) {
return; return;
} }
try { try {
@@ -168,7 +169,7 @@ public class RootAutomator implements Shell.Callback {
} }
public void touchDown(int x, int y, int id) throws IOException { public void touchDown(int x, int y, int id) throws IOException {
if(mSlotIdMap.size() == 0){ if (mSlotIdMap.size() == 0) {
touchDown0(x, y, id); touchDown0(x, y, id);
return; return;
} }
@@ -199,17 +200,17 @@ public class RootAutomator implements Shell.Callback {
} }
public void touchUp(int id) throws IOException { public void touchUp(int id) throws IOException {
int slotId ; int slotId;
int i = mSlotIdMap.indexOfKey(id); int i = mSlotIdMap.indexOfKey(id);
if( i < 0){ if (i < 0) {
slotId = 0; slotId = 0;
}else { } else {
slotId = mSlotIdMap.valueAt(i); slotId = mSlotIdMap.valueAt(i);
mSlotIdMap.removeAt(i); mSlotIdMap.removeAt(i);
} }
sendEvent(EV_ABS, ABS_MT_SLOT, slotId); sendEvent(EV_ABS, ABS_MT_SLOT, slotId);
sendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0xffffffff); sendEvent(EV_ABS, ABS_MT_TRACKING_ID, 0xffffffff);
if(mSlotIdMap.size() == 0){ if (mSlotIdMap.size() == 0) {
sendEvent(EV_KEY, BTN_TOUCH, 0x00000000); sendEvent(EV_KEY, BTN_TOUCH, 0x00000000);
sendEvent(EV_KEY, BTN_TOOL_FINGER, 0x00000000); sendEvent(EV_KEY, BTN_TOOL_FINGER, 0x00000000);
} }
@@ -281,9 +282,10 @@ public class RootAutomator implements Shell.Callback {
String deviceNameOrPath = RootAutomatorEngine.getDeviceNameOrPath(mContext, InputDevices.getTouchDeviceName()); String deviceNameOrPath = RootAutomatorEngine.getDeviceNameOrPath(mContext, InputDevices.getTouchDeviceName());
Log.d(LOG_TAG, "deviceNameOrPath: " + deviceNameOrPath); Log.d(LOG_TAG, "deviceNameOrPath: " + deviceNameOrPath);
mShell.exec("chmod 777 " + path); mShell.exec("chmod 777 " + path);
String command = path + " -d " + deviceNameOrPath; String command = String.format(Locale.getDefault(), "%s -d %s -sw %d -sh %d", path, deviceNameOrPath,
ScreenMetrics.getDeviceScreenWidth(), ScreenMetrics.getDeviceScreenHeight());
mShell.exec(command); mShell.exec(command);
synchronized (mReadyLock){ synchronized (mReadyLock) {
Log.d(LOG_TAG, "notify ready"); Log.d(LOG_TAG, "notify ready");
mReady = true; mReady = true;
mReadyLock.notifyAll(); mReadyLock.notifyAll();

View File

@@ -62,7 +62,7 @@ public class Shell extends AbstractShell {
} }
} }
private static final boolean DEBUG = false; private static final boolean DEBUG = true;
private static final String TAG = "Shell"; private static final String TAG = "Shell";
private volatile TermSession mTermSession; private volatile TermSession mTermSession;

View File

@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":414},"path":"commonRelease-4.0.2 Alpha9.apk","properties":{"packageId":"org.autojs.autojs","split":"","minSdkVersion":"17"}}] [{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":415},"path":"commonRelease-4.0.2 Alpha10.apk","properties":{"packageId":"org.autojs.autojs","split":"","minSdkVersion":"17"}}]