Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.util.Properties;
- import java.util.Scanner;
- import static com.automation.util.FileUtil.readPropertyFile;
- /**
- * Created by Sundeep Machado on 09/09/16.
- */
- public class ADBUtil {
- public static ProcessBuilder pb = null;
- public static Process pc = null;
- public static void printADBLog( String tag ){
- Properties prop = readPropertyFile();
- clearADBLogs();
- pb = new ProcessBuilder("adb", "logcat", "-s", tag);
- File output = new File(prop.getProperty("adbLogFile"));
- if(output.delete()){
- System.out.println("ADB File Deleted");
- }
- pb.redirectOutput(output);
- try {
- pc = pb.start();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- /**
- * Clear the ADB logcat
- */
- public static void clearADBLogs(){
- pb = new ProcessBuilder("adb", "logcat", "-c");
- try {
- pc = pb.start();
- } catch (IOException e) {
- e.printStackTrace();
- }
- pc.destroy();
- }
- /**
- * Stop the ADB logging service
- * @throws IOException
- */
- public static void stopADBLogger() throws IOException {
- pc.destroy();
- }
- /**
- * This function waits till the ADb tag is present in log file
- */
- public static void waitTillTagPresent(String f, String searchString){
- boolean result = false;
- Scanner in = null;
- do {
- try {
- in = new Scanner(new FileReader(f));
- while (in.hasNextLine() && !result) {
- result = in.nextLine().indexOf(searchString) >= 0;
- }
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- in.close();
- } catch (Exception e) { /* ignore */ }
- }
- }
- while (result=false);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement