Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static boolean isNetworkAdbEnabled() {
        String result = propReader("service.adb.tcp.port");
        return !result.contains("-1") && result.contains("service.adb.tcp.port");
    }

    private static String propReader(String filter) {
        Process process = null;
        try {
            process = new ProcessBuilder().command("/system/bin/getprop").redirectErrorStream(true).start();
        } catch (IOException e) {
            e.printStackTrace();
        }

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

        StringBuilder log = new StringBuilder();
        String line;
        try {
            while ((line = bufferedReader.readLine()) != null) {
                if (line.contains(filter))
                    log.append(line + "\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        process.destroy();
        return log.toString();
    }
}