Skip to content

Commit

Permalink
优化性能
Browse files Browse the repository at this point in the history
  • Loading branch information
yanglikai committed Jan 6, 2020
1 parent c432d6a commit a057c54
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
8 changes: 3 additions & 5 deletions app/src/main/java/com/kevin/testool/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected void onCreate(Bundle savedInstanceState) {
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.CHANGE_WIFI_STATE}, 1);
}
}
if (!AdbUtils.hasRootPermission()){
if (!AdbUtils.isAdbEnable()){
new AlertDialog.Builder(MainActivity.this)
.setTitle("提示:")
.setMessage("请先开启root权限, 或 usb连接电脑 输入\"adb tcpip 5555\"执行测试")
Expand Down Expand Up @@ -709,10 +709,8 @@ public void afterTextChanged(Editable s) {
JSONObject mysql = null;
try {
mysql = Common.CONFIG().getJSONObject("MYSQL");
dbUrl.setText("");
dbUser.setText("test");
// dbUrl.setText(String.format("url: %s", mysql.getString("url")));
// dbUser.setText(String.format("username: %s", mysql.getString("user")));
dbUrl.setText(String.format("url: %s", mysql.getString("url")));
dbUser.setText(String.format("username: %s", mysql.getString("user")));
// dbPassword.setText(String.format("password:%s",mysql.getString("password")));
dbPassword.setText(String.format("password: %s","*******"));
} catch (JSONException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Boolean checkIfExist(Boolean refresh,String key, String value, int
}
if (key.length() == 0){
if (refresh) {
AdbUtils.runShellCommand("am instrument -w -r -e debug false -e class 'com.github.uiautomator.GetDumpTest' com.github.uiautomator.test/android.support.test.runner.AndroidJUnitRunner\n", 0);
get_elements(true, "", "", 0);
}
try {
String content = MyFile.readFile(Environment.getExternalStorageDirectory().getPath() + File.separator + "window_dump.xml");
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/kevin/testool/common/Common.java
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ public static void generateBugreport(final String logFileName) {
new Thread() {
@Override
public void run() {
AdbUtils.runShellCommand("bugreport > " + bugreportFile + "\n", 600);
AdbUtils.runShellCommand("bugreport > " + bugreportFile, 600000);
try {
MyFile.ZipFolder(logFileName, logFileName.replace(".txt", ".zip"));
MyFile.deleteFile(logFileName);
Expand Down
40 changes: 30 additions & 10 deletions app/src/main/java/com/kevin/testool/utils/AdbUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,21 @@ public static boolean isProcessRunning(String processName) throws Exception {
* @return 当前app是否有root权限
*/
public static boolean hasRootPermission() {
Log.d(TAG, "hasRootPermission: " + rooted);
Process process = null;
DataOutputStream os = null;
if (rooted != null){
return rooted;
}
// if (rooted != null){
// logUtil.d(TAG, "hasRootPermission: " + rooted);
// return rooted;
// }
try {
process = Runtime.getRuntime().exec("su");
// process = Runtime.getRuntime().exec("echo hello");
os = new DataOutputStream(process.getOutputStream());
os.writeBytes("exit\n");
os.flush();
process.waitFor();
if (process.exitValue() != 0) {
rooted = false;
} else {
rooted = true;
}
// logUtil.d("", process.exitValue()+"");
rooted = process.exitValue() == 0;
} catch (Exception e) {
e.printStackTrace();
rooted = false;
Expand All @@ -81,10 +78,33 @@ public static boolean hasRootPermission() {
}
}
}
// Log.d(TAG, "hasRootPermission: " + rooted);
logUtil.d(TAG, "hasRootPermission: " + rooted);
return rooted;
}

/**
* 是否可以执行adb命令
* @return boolean
*/
public static boolean isAdbEnable(){
final boolean[] result = new boolean[1];
if (hasRootPermission()){
return true;
} else {
Thread isAdb = new Thread(new Runnable() {
@Override
public void run() {
result[0] = CmdTools.generateConnection();
}
});
isAdb.start();
while (isAdb.isAlive()){
SystemClock.sleep(100);
}
return result[0];
}
}

/**
* Root身份执行shell命令,不关注输出结果
*
Expand Down

0 comments on commit a057c54

Please sign in to comment.