Skip to content

Commit 917ab72

Browse files
authored
Fix dump, etc.. (#60)
- remove atx-agent check - use new dumpHierarchy - add FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY - fix ToastActivity not check permissions bug
1 parent fa828af commit 917ab72

11 files changed

Lines changed: 62 additions & 944 deletions

File tree

DEVELOP.md

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,9 @@
1-
## minitouch
2-
3-
测试数据
4-
5-
6-
```
7-
d 0 800 1000 50
8-
c
9-
u 0
10-
c
11-
```
12-
13-
d 0 600 800 50
14-
c
15-
u 0
16-
c
17-
1+
## Use APK as commandline
182

193
运行
204

215
```bash
226
APK=$(adb shell pm path com.github.uiautomator | cut -d: -f2)
237
adb shell export CLASSPATH="$APK"\; \
24-
exec app_process /system/bin com.github.uiautomator.MinitouchAgent
25-
```
26-
27-
测试
28-
29-
```bash
30-
adb forward tcp:7788 localabstract:minitouchagent
31-
nc localhost 7788
32-
```
8+
exec app_process /system/bin com.github.uiautomator.Console --version
9+
```

app/src/androidTest/java/com/github/uiautomator/stub/AutomatorServiceImpl.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@
3535
import android.os.Looper;
3636
import android.os.RemoteException;
3737
import android.os.SystemClock;
38-
import androidx.test.InstrumentationRegistry;
38+
39+
import androidx.core.accessibilityservice.AccessibilityServiceInfoCompat;
40+
import androidx.test.platform.app.InstrumentationRegistry;
3941
import androidx.test.uiautomator.Configurator;
4042
import androidx.test.uiautomator.Direction;
4143
import androidx.test.uiautomator.StaleObjectException;
@@ -69,8 +71,8 @@
6971

7072
public class AutomatorServiceImpl implements AutomatorService {
7173

72-
private final HashSet<String> watchers = new HashSet<String>();
73-
private final ConcurrentHashMap<String, UiObject> uiObjects = new ConcurrentHashMap<String, UiObject>();
74+
private final HashSet<String> watchers = new HashSet<>();
75+
private final ConcurrentHashMap<String, UiObject> uiObjects = new ConcurrentHashMap<>();
7476
private SoundPool soundPool = new SoundPool(100, AudioManager.STREAM_MUSIC, 0);
7577

7678
Handler handler = new Handler(Looper.getMainLooper());
@@ -84,13 +86,19 @@ public class AutomatorServiceImpl implements AutomatorService {
8486
public AutomatorServiceImpl() {
8587
mInstrumentation = InstrumentationRegistry.getInstrumentation();
8688
uiAutomation = mInstrumentation.getUiAutomation();
89+
90+
// https://developer.android.com/reference/androidx/core/accessibilityservice/AccessibilityServiceInfoCompat#FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY()
91+
// https://www.jianshu.com/p/a8ccd607e172
92+
// improve accessibility support for "android.webkit.WebView"
93+
uiAutomation.getServiceInfo().flags |= AccessibilityServiceInfoCompat.FLAG_REQUEST_ENHANCED_WEB_ACCESSIBILITY;
94+
8795
device = UiDevice.getInstance(mInstrumentation);
8896
touchController = new TouchController(mInstrumentation);
8997

9098
handler.post(new Runnable() {
9199
@Override
92100
public void run() {
93-
AutomatorServiceImpl.this.clipboard = (ClipboardManager) InstrumentationRegistry.getTargetContext().getSystemService(Context.CLIPBOARD_SERVICE);
101+
AutomatorServiceImpl.this.clipboard = (ClipboardManager) mInstrumentation.getTargetContext().getSystemService(Context.CLIPBOARD_SERVICE);
94102
}
95103
});
96104
// play music when loaded
@@ -119,7 +127,7 @@ private UiAutomation getUiAutomation() {
119127
/**
120128
* It's to play a section music to test
121129
*
122-
* @return
130+
* @return bool
123131
*/
124132
@Override
125133
public boolean playSound(String path) {
@@ -167,7 +175,7 @@ public boolean makeToast(final String text, final int duration) {
167175
handler.post(new Runnable() {
168176
@Override
169177
public void run() {
170-
ToastHelper.makeText(InstrumentationRegistry.getTargetContext(), text, duration).show();
178+
ToastHelper.makeText(mInstrumentation.getTargetContext(), text, duration).show();
171179
}
172180
});
173181
return true;
@@ -292,12 +300,16 @@ public String dumpWindowHierarchy(boolean compressed, String filename) {
292300
*/
293301
@Override
294302
public String dumpWindowHierarchy(boolean compressed) {
295-
device.setCompressedLayoutHeirarchy(compressed);
303+
device.setCompressedLayoutHierarchy(compressed);
296304
ByteArrayOutputStream os = new ByteArrayOutputStream();
297305
try {
298306
// Original code: device.dumpWindowHierarchy(os);
299-
// The bellow code fix xml encode error
300-
AccessibilityNodeInfoDumper.dumpWindowHierarchy(device, os);
307+
// The old code have xml encode error
308+
// It seems the new androidx.uiautomator dump looks fine.
309+
device.dumpWindowHierarchy(os);
310+
// alternative
311+
// sometimes java.lang.NullPointerException raises
312+
// AccessibilityNodeInfoDumper.dumpWindowHierarchy(device, os);
301313
return os.toString("UTF-8");
302314
} catch (IOException e) {
303315
Log.d("dumpWindowHierarchy got IOException: " + e);
@@ -323,7 +335,7 @@ public String dumpWindowHierarchy(boolean compressed) {
323335
*/
324336
@Override
325337
public String takeScreenshot(String filename, float scale, int quality) throws NotImplementedException {
326-
File f = new File(InstrumentationRegistry.getTargetContext().getFilesDir(), filename);
338+
File f = new File(mInstrumentation.getTargetContext().getFilesDir(), filename);
327339
device.takeScreenshot(f, scale, quality);
328340
if (f.exists()) return f.getAbsolutePath();
329341
return null;

app/src/androidTest/java/com/github/uiautomator/stub/Log.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static void d(String msg) {
3030
android.util.Log.d(TAG, msg);
3131
}
3232

33-
public static void i(String msg, String s) {
33+
public static void i(String msg) {
3434
android.util.Log.i(TAG, msg);
3535
}
3636

app/src/androidTest/java/com/github/uiautomator/stub/Stub.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import androidx.test.filters.SdkSuppress;
3232
import androidx.test.runner.AndroidJUnit4;
3333
import androidx.test.uiautomator.By;
34-
import androidx.test.uiautomator.Configurator;
3534
import androidx.test.uiautomator.UiDevice;
3635
import androidx.test.uiautomator.UiObjectNotFoundException;
3736
import androidx.test.uiautomator.Until;
@@ -90,7 +89,7 @@ public JsonError resolveError(Throwable throwable, Method method, List<JsonNode>
9089
}
9190

9291
private void launchPackage(String packageName) {
93-
Log.i(TAG, "Launch " + packageName);
92+
Log.i("Launch " + packageName);
9493
UiDevice device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
9594
Context context = InstrumentationRegistry.getContext();
9695
final Intent intent = context.getPackageManager()
@@ -111,7 +110,7 @@ private void launchService() throws RemoteException {
111110
String launcherPackage = device.getLauncherPackageName();
112111
Boolean ready = device.wait(Until.hasObject(By.pkg(launcherPackage).depth(0)), LAUNCH_TIMEOUT);
113112
if (!ready) {
114-
Log.i(TAG, "Wait for launcher timeout");
113+
Log.i("Wait for launcher timeout");
115114
return;
116115
}
117116

@@ -141,6 +140,7 @@ private void stopMonitorService(Context context) {
141140
@Test
142141
@LargeTest
143142
public void testUIAutomatorStub() throws InterruptedException {
143+
Log.i("server started");
144144
while (server.isAlive()) {
145145
Thread.sleep(100);
146146
}

app/src/main/java/com/github/uiautomator/Console.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ private void listenAndServe(){
8181
System.exit(1);
8282
}
8383

84-
MinitouchAgent minitouch = new MinitouchAgent(size.x, size.y, handler, "minitouchagent");
85-
MinicapAgent minicap = new MinicapAgent(size.x, size.y, "minicapagent");
8684
RotationAgent rotation = new RotationAgent("rotationagent");
87-
minitouch.start();
88-
minicap.start();
8985
rotation.start();
9086

9187
Looper.loop();

app/src/main/java/com/github/uiautomator/IdentifyActivity.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected void onCreate(Bundle savedInstanceState) {
4848
Log.i(TAG, "theme " + activityTheme);
4949
Float brightness = 0.1f;
5050
Integer backgroundColor = Color.BLACK;
51-
if (activityTheme != null && "RED".equals(activityTheme)) {
51+
if ("RED".equals(activityTheme)) {
5252
backgroundColor = Color.RED;
5353
brightness = 1.0f;
5454
}
@@ -73,12 +73,12 @@ protected void onCreate(Bundle savedInstanceState) {
7373
layout.addView(createData(Build.VERSION.RELEASE + " (SDK " + Build.VERSION.SDK_INT + ")"));
7474
layout.addView(createLabel("OPERATOR"));
7575
layout.addView(createData(tm.getSimOperatorName()));
76-
layout.addView(createLabel("PHONE"));
77-
layout.addView(createData(tm.getLine1Number()));
78-
layout.addView(createLabel("IMEI"));
79-
layout.addView(createData(tm.getDeviceId()));
80-
layout.addView(createLabel("ICCID"));
81-
layout.addView(createData(tm.getSimSerialNumber()));
76+
// layout.addView(createLabel("PHONE"));
77+
// layout.addView(createData(tm.getLine1Number()));
78+
// layout.addView(createLabel("IMEI"));
79+
// layout.addView(createData(tm.getDeviceId()));
80+
// layout.addView(createLabel("ICCID"));
81+
// layout.addView(createData(tm.getSimSerialNumber()));
8282

8383
requestWindowFeature(Window.FEATURE_NO_TITLE);
8484
ensureVisibility(brightness);
@@ -119,8 +119,13 @@ private void ensureVisibility(Float brightness) {
119119
private String getProperty(String name, String defaultValue) {
120120
try {
121121
Class<?> SystemProperties = Class.forName("android.os.SystemProperties");
122-
Method get = SystemProperties.getMethod("get", String.class, String.class);
123-
return (String) get.invoke(SystemProperties, name, defaultValue);
122+
try {
123+
Method get = SystemProperties.getMethod("get", String.class, String.class);
124+
return (String) get.invoke(SystemProperties, name, defaultValue);
125+
} catch (NoSuchMethodException e) {
126+
Method get = SystemProperties.getMethod("get", String.class);
127+
return (String) get.invoke(SystemProperties, name);
128+
}
124129
} catch (ClassNotFoundException e) {
125130
Log.e(TAG, "Class.forName() failed", e);
126131
return defaultValue;

0 commit comments

Comments
 (0)