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

chore(adb): lint the driver #4696

Merged
merged 1 commit into from
Dec 13, 2020
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
Binary file modified bin/android-driver.apk
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
/*
* Copyright (c) Microsoft Corporation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -16,12 +16,10 @@

package com.microsoft.playwright.androiddriver;

import android.bluetooth.BluetoothClass;
import android.graphics.Point;
import android.graphics.Rect;
import android.net.LocalServerSocket;
import android.net.LocalSocket;
import android.os.Bundle;
import android.view.accessibility.AccessibilityNodeInfo;

import androidx.test.ext.junit.runners.AndroidJUnit4;
Expand All @@ -32,7 +30,6 @@
import androidx.test.uiautomator.Direction;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.UiObject2;
import androidx.test.uiautomator.UiSelector;
import androidx.test.uiautomator.Until;

import org.json.JSONArray;
Expand All @@ -48,7 +45,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.regex.Pattern;

/**
Expand All @@ -60,12 +56,13 @@
@SdkSuppress(minSdkVersion = 21)
public class InstrumentedTest {

@SuppressWarnings("ConstantConditions")
private static BySelector parseSelector(JSONObject param) throws JSONException{
JSONObject selector = param.getJSONObject("selector");
BySelector result = null;
if (selector.has("checkable")) {
boolean value = selector.getBoolean("checkable");
result = result != null ? result.checkable(value) : By.checkable(value);
result = result != null ? result.checked(value) : By.checkable(value);
}
if (selector.has("checked")) {
boolean value = selector.getBoolean("checked");
Expand Down Expand Up @@ -146,7 +143,7 @@ private static int parseTimeout(JSONObject params) throws JSONException {

private static Point parsePoint(JSONObject params, String propertyName) throws JSONException {
JSONObject point = params.getJSONObject(propertyName);
return new Point(params.getInt("x"), params.getInt("y"));
return new Point(point.getInt("x"), point.getInt("y"));
}

private static Direction parseDirection(JSONObject params) throws JSONException {
Expand Down Expand Up @@ -313,6 +310,7 @@ private static AccessibilityNodeInfo getRootA11yNode(UiDevice device) {
getQueryController.setAccessible(true);
Object queryController = getQueryController.invoke(device);

assert queryController != null;
Method getRootNode = queryController.getClass().getDeclaredMethod("getRootNode");
getRootNode.setAccessible(true);
return (AccessibilityNodeInfo) getRootNode.invoke(queryController);
Expand Down Expand Up @@ -343,6 +341,7 @@ public void main() {
DataInputStream dis = new DataInputStream(is);
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());

//noinspection InfiniteLoopStatement
while (true) {
int id = 0;
String method = null;
Expand All @@ -356,7 +355,7 @@ public void main() {
id = message.getInt("id");
method = message.getString("method");
params = message.getJSONObject("params");
} catch (JSONException e) {
} catch (JSONException ignored) {
}
if (method == null)
continue;
Expand All @@ -365,6 +364,7 @@ public void main() {
response.put("id", id);
response.put("result", params);
try {
assert params != null;
switch (method) {
case "wait":
wait(device, params);
Expand Down