Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix dump, etc.. #60

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 3 additions & 26 deletions DEVELOP.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,9 @@
## minitouch

测试数据


```
d 0 800 1000 50
c
u 0
c
```

d 0 600 800 50
c
u 0
c

## Use APK as commandline

运行

```bash
APK=$(adb shell pm path com.github.uiautomator | cut -d: -f2)
adb shell export CLASSPATH="$APK"\; \
exec app_process /system/bin com.github.uiautomator.MinitouchAgent
```

测试

```bash
adb forward tcp:7788 localabstract:minitouchagent
nc localhost 7788
```
exec app_process /system/bin com.github.uiautomator.Console --version
```
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@
import android.os.Looper;
import android.os.RemoteException;
import android.os.SystemClock;
import androidx.test.InstrumentationRegistry;

import androidx.core.accessibilityservice.AccessibilityServiceInfoCompat;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.uiautomator.Configurator;
import androidx.test.uiautomator.Direction;
import androidx.test.uiautomator.StaleObjectException;
Expand Down Expand Up @@ -69,8 +71,8 @@

public class AutomatorServiceImpl implements AutomatorService {

private final HashSet<String> watchers = new HashSet<String>();
private final ConcurrentHashMap<String, UiObject> uiObjects = new ConcurrentHashMap<String, UiObject>();
private final HashSet<String> watchers = new HashSet<>();
private final ConcurrentHashMap<String, UiObject> uiObjects = new ConcurrentHashMap<>();
private SoundPool soundPool = new SoundPool(100, AudioManager.STREAM_MUSIC, 0);

Handler handler = new Handler(Looper.getMainLooper());
Expand All @@ -84,13 +86,19 @@ public class AutomatorServiceImpl implements AutomatorService {
public AutomatorServiceImpl() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
uiAutomation = mInstrumentation.getUiAutomation();

// https://developer.android.com/reference/androidx/core/accessibilityservice/AccessibilityServiceInfoCompat#FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY()
// https://www.jianshu.com/p/a8ccd607e172
// improve accessibility support for "android.webkit.WebView"
uiAutomation.getServiceInfo().flags |= AccessibilityServiceInfoCompat.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;

device = UiDevice.getInstance(mInstrumentation);
touchController = new TouchController(mInstrumentation);

handler.post(new Runnable() {
@Override
public void run() {
AutomatorServiceImpl.this.clipboard = (ClipboardManager) InstrumentationRegistry.getTargetContext().getSystemService(Context.CLIPBOARD_SERVICE);
AutomatorServiceImpl.this.clipboard = (ClipboardManager) mInstrumentation.getTargetContext().getSystemService(Context.CLIPBOARD_SERVICE);
}
});
// play music when loaded
Expand Down Expand Up @@ -119,7 +127,7 @@ private UiAutomation getUiAutomation() {
/**
* It's to play a section music to test
*
* @return
* @return bool
*/
@Override
public boolean playSound(String path) {
Expand Down Expand Up @@ -167,7 +175,7 @@ public boolean makeToast(final String text, final int duration) {
handler.post(new Runnable() {
@Override
public void run() {
ToastHelper.makeText(InstrumentationRegistry.getTargetContext(), text, duration).show();
ToastHelper.makeText(mInstrumentation.getTargetContext(), text, duration).show();
}
});
return true;
Expand Down Expand Up @@ -292,12 +300,16 @@ public String dumpWindowHierarchy(boolean compressed, String filename) {
*/
@Override
public String dumpWindowHierarchy(boolean compressed) {
device.setCompressedLayoutHeirarchy(compressed);
device.setCompressedLayoutHierarchy(compressed);
ByteArrayOutputStream os = new ByteArrayOutputStream();
try {
// Original code: device.dumpWindowHierarchy(os);
// The bellow code fix xml encode error
AccessibilityNodeInfoDumper.dumpWindowHierarchy(device, os);
// The old code have xml encode error
// It seems the new androidx.uiautomator dump looks fine.
device.dumpWindowHierarchy(os);
// alternative
// sometimes java.lang.NullPointerException raises
// AccessibilityNodeInfoDumper.dumpWindowHierarchy(device, os);
return os.toString("UTF-8");
} catch (IOException e) {
Log.d("dumpWindowHierarchy got IOException: " + e);
Expand All @@ -323,7 +335,7 @@ public String dumpWindowHierarchy(boolean compressed) {
*/
@Override
public String takeScreenshot(String filename, float scale, int quality) throws NotImplementedException {
File f = new File(InstrumentationRegistry.getTargetContext().getFilesDir(), filename);
File f = new File(mInstrumentation.getTargetContext().getFilesDir(), filename);
device.takeScreenshot(f, scale, quality);
if (f.exists()) return f.getAbsolutePath();
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static void d(String msg) {
android.util.Log.d(TAG, msg);
}

public static void i(String msg, String s) {
public static void i(String msg) {
android.util.Log.i(TAG, msg);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import androidx.test.filters.SdkSuppress;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.Configurator;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObjectNotFoundException;
import androidx.test.uiautomator.Until;
Expand Down Expand Up @@ -90,7 +89,7 @@ public JsonError resolveError(Throwable throwable, Method method, List<JsonNode>
}

private void launchPackage(String packageName) {
Log.i(TAG, "Launch " + packageName);
Log.i("Launch " + packageName);
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
Context context = InstrumentationRegistry.getContext();
final Intent intent = context.getPackageManager()
Expand All @@ -111,7 +110,7 @@ private void launchService() throws RemoteException {
String launcherPackage = device.getLauncherPackageName();
Boolean ready = device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);
if (!ready) {
Log.i(TAG, "Wait for launcher timeout");
Log.i("Wait for launcher timeout");
return;
}

Expand Down Expand Up @@ -141,6 +140,7 @@ private void stopMonitorService(Context context) {
@Test
@LargeTest
public void testUIAutomatorStub() throws InterruptedException {
Log.i("server started");
while (server.isAlive()) {
Thread.sleep(100);
}
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/com/github/uiautomator/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ private void listenAndServe(){
System.exit(1);
}

MinitouchAgent minitouch = new MinitouchAgent(size.x, size.y, handler, "minitouchagent");
MinicapAgent minicap = new MinicapAgent(size.x, size.y, "minicapagent");
RotationAgent rotation = new RotationAgent("rotationagent");
minitouch.start();
minicap.start();
rotation.start();

Looper.loop();
Expand Down
23 changes: 14 additions & 9 deletions app/src/main/java/com/github/uiautomator/IdentifyActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
Log.i(TAG, "theme " + activityTheme);
Float brightness = 0.1f;
Integer backgroundColor = Color.BLACK;
if (activityTheme != null && "RED".equals(activityTheme)) {
if ("RED".equals(activityTheme)) {
backgroundColor = Color.RED;
brightness = 1.0f;
}
Expand All @@ -73,12 +73,12 @@ protected void onCreate(Bundle savedInstanceState) {
layout.addView(createData(Build.VERSION.RELEASE + " (SDK " + Build.VERSION.SDK_INT + ")"));
layout.addView(createLabel("OPERATOR"));
layout.addView(createData(tm.getSimOperatorName()));
layout.addView(createLabel("PHONE"));
layout.addView(createData(tm.getLine1Number()));
layout.addView(createLabel("IMEI"));
layout.addView(createData(tm.getDeviceId()));
layout.addView(createLabel("ICCID"));
layout.addView(createData(tm.getSimSerialNumber()));
// layout.addView(createLabel("PHONE"));
// layout.addView(createData(tm.getLine1Number()));
// layout.addView(createLabel("IMEI"));
// layout.addView(createData(tm.getDeviceId()));
// layout.addView(createLabel("ICCID"));
// layout.addView(createData(tm.getSimSerialNumber()));

requestWindowFeature(Window.FEATURE_NO_TITLE);
ensureVisibility(brightness);
Expand Down Expand Up @@ -119,8 +119,13 @@ private void ensureVisibility(Float brightness) {
private String getProperty(String name, String defaultValue) {
try {
Class<?> SystemProperties = Class.forName("android.os.SystemProperties");
Method get = SystemProperties.getMethod("get", String.class, String.class);
return (String) get.invoke(SystemProperties, name, defaultValue);
try {
Method get = SystemProperties.getMethod("get", String.class, String.class);
return (String) get.invoke(SystemProperties, name, defaultValue);
} catch (NoSuchMethodException e) {
Method get = SystemProperties.getMethod("get", String.class);
return (String) get.invoke(SystemProperties, name);
}
} catch (ClassNotFoundException e) {
Log.e(TAG, "Class.forName() failed", e);
return defaultValue;
Expand Down
Loading
Loading