Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.FileReader;
  3. import java.io.IOException;
  4. import java.util.Properties;
  5. import java.util.Scanner;
  6.  
  7. import static com.automation.util.FileUtil.readPropertyFile;
  8.  
  9. /**
  10. * Created by Sundeep Machado on 09/09/16.
  11. */
  12. public class ADBUtil {
  13. public static ProcessBuilder pb = null;
  14. public static Process pc = null;
  15.  
  16.  
  17. public static void printADBLog( String tag ){
  18. Properties prop = readPropertyFile();
  19. clearADBLogs();
  20. pb = new ProcessBuilder("adb", "logcat", "-s", tag);
  21. File output = new File(prop.getProperty("adbLogFile"));
  22.  
  23. if(output.delete()){
  24. System.out.println("ADB File Deleted");
  25. }
  26. pb.redirectOutput(output);
  27. try {
  28. pc = pb.start();
  29. } catch (IOException e) {
  30. e.printStackTrace();
  31. }
  32.  
  33.  
  34. }
  35.  
  36.  
  37. /**
  38. * Clear the ADB logcat
  39. */
  40. public static void clearADBLogs(){
  41.  
  42. pb = new ProcessBuilder("adb", "logcat", "-c");
  43. try {
  44. pc = pb.start();
  45. } catch (IOException e) {
  46. e.printStackTrace();
  47. }
  48. pc.destroy();
  49.  
  50. }
  51.  
  52. /**
  53. * Stop the ADB logging service
  54. * @throws IOException
  55. */
  56. public static void stopADBLogger() throws IOException {
  57.  
  58. pc.destroy();
  59.  
  60. }
  61.  
  62. /**
  63. * This function waits till the ADb tag is present in log file
  64. */
  65.  
  66. public static void waitTillTagPresent(String f, String searchString){
  67.  
  68. boolean result = false;
  69. Scanner in = null;
  70. do {
  71. try {
  72. in = new Scanner(new FileReader(f));
  73. while (in.hasNextLine() && !result) {
  74. result = in.nextLine().indexOf(searchString) >= 0;
  75. }
  76. } catch (IOException e) {
  77. e.printStackTrace();
  78. } finally {
  79. try {
  80. in.close();
  81. } catch (Exception e) { /* ignore */ }
  82. }
  83. }
  84. while (result=false);
  85.  
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement