use of java.io.InputStreamReader in project AsmackService by rtreffer.
the class Client method findDNS.
/**
* Retrieve a list of currently configured DNS servers.
* @return The server array.
*/
public String[] findDNS() {
try {
Process process = Runtime.getRuntime().exec("getprop");
InputStream inputStream = process.getInputStream();
LineNumberReader lnr = new LineNumberReader(new InputStreamReader(inputStream));
String line = null;
HashSet<String> server = new HashSet<String>(6);
while ((line = lnr.readLine()) != null) {
int split = line.indexOf("]: [");
if (split == -1) {
continue;
}
String property = line.substring(1, split);
String value = line.substring(split + 4, line.length() - 1);
if (property.endsWith(".dns") || property.endsWith(".dns1") || property.endsWith(".dns2")) {
server.add(value);
}
}
if (server.size() > 0) {
return server.toArray(new String[server.size()]);
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
use of java.io.InputStreamReader in project platform_frameworks_base by android.
the class Bpf2Apf method main.
/**
* Convert the output of "tcpdump -d" (human readable BPF program dump) piped in stdin into an
* APF program and output it via stdout.
*/
public static void main(String[] args) throws Exception {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line = null;
StringBuilder responseData = new StringBuilder();
ApfGenerator gen = new ApfGenerator();
while ((line = in.readLine()) != null) convertLine(line, gen);
System.out.write(gen.generate());
}
use of java.io.InputStreamReader in project platform_frameworks_base by android.
the class ConfigParser method parsePasspointConfig.
/**
* Parse the Hotspot 2.0 Release 1 configuration data into a {@link PasspointConfiguration}
* object. The configuration data is a base64 encoded MIME multipart data. Below is
* the format of the decoded message:
*
* Content-Type: multipart/mixed; boundary={boundary}
* Content-Transfer-Encoding: base64
*
* --{boundary}
* Content-Type: application/x-passpoint-profile
* Content-Transfer-Encoding: base64
*
* [base64 encoded Passpoint profile data]
* --{boundary}
* Content-Type: application/x-x509-ca-cert
* Content-Transfer-Encoding: base64
*
* [base64 encoded X509 CA certificate data]
* --{boundary}
* Content-Type: application/x-pkcs12
* Content-Transfer-Encoding: base64
*
* [base64 encoded PKCS#12 ASN.1 structure containing client certificate chain]
* --{boundary}
*
* @param mimeType MIME type of the encoded data.
* @param data A base64 encoded MIME multipart message containing the Passpoint profile
* (required), CA (Certificate Authority) certificate (optional), and client
* certificate chain (optional).
* @return {@link PasspointConfiguration}
*/
public static PasspointConfiguration parsePasspointConfig(String mimeType, byte[] data) {
// Verify MIME type.
if (!TextUtils.equals(mimeType, TYPE_WIFI_CONFIG)) {
Log.e(TAG, "Unexpected MIME type: " + mimeType);
return null;
}
try {
// Decode the data.
byte[] decodedData = Base64.decode(new String(data, StandardCharsets.ISO_8859_1), Base64.DEFAULT);
Map<String, byte[]> mimeParts = parseMimeMultipartMessage(new LineNumberReader(new InputStreamReader(new ByteArrayInputStream(decodedData), StandardCharsets.ISO_8859_1)));
return createPasspointConfig(mimeParts);
} catch (IOException | IllegalArgumentException e) {
Log.e(TAG, "Failed to parse installation file: " + e.getMessage());
return null;
}
}
use of java.io.InputStreamReader in project platform_frameworks_base by android.
the class ActivityManagerService method addErrorToDropBox.
/**
* Write a description of an error (crash, WTF, ANR) to the drop box.
* @param eventType to include in the drop box tag ("crash", "wtf", etc.)
* @param process which caused the error, null means the system server
* @param activity which triggered the error, null if unknown
* @param parent activity related to the error, null if unknown
* @param subject line related to the error, null if absent
* @param report in long form describing the error, null if absent
* @param dataFile text file to include in the report, null if none
* @param crashInfo giving an application stack trace, null if absent
*/
public void addErrorToDropBox(String eventType, ProcessRecord process, String processName, ActivityRecord activity, ActivityRecord parent, String subject, final String report, final File dataFile, final ApplicationErrorReport.CrashInfo crashInfo) {
// NOTE -- this must never acquire the ActivityManagerService lock,
// otherwise the watchdog may be prevented from resetting the system.
final String dropboxTag = processClass(process) + "_" + eventType;
final DropBoxManager dbox = (DropBoxManager) mContext.getSystemService(Context.DROPBOX_SERVICE);
// Exit early if the dropbox isn't configured to accept this report type.
if (dbox == null || !dbox.isTagEnabled(dropboxTag))
return;
// Rate-limit how often we're willing to do the heavy lifting below to
// collect and record logs; currently 5 logs per 10 second period.
final long now = SystemClock.elapsedRealtime();
if (now - mWtfClusterStart > 10 * DateUtils.SECOND_IN_MILLIS) {
mWtfClusterStart = now;
mWtfClusterCount = 1;
} else {
if (mWtfClusterCount++ >= 5)
return;
}
final StringBuilder sb = new StringBuilder(1024);
appendDropBoxProcessHeaders(process, processName, sb);
if (process != null) {
sb.append("Foreground: ").append(process.isInterestingToUserLocked() ? "Yes" : "No").append("\n");
}
if (activity != null) {
sb.append("Activity: ").append(activity.shortComponentName).append("\n");
}
if (parent != null && parent.app != null && parent.app.pid != process.pid) {
sb.append("Parent-Process: ").append(parent.app.processName).append("\n");
}
if (parent != null && parent != activity) {
sb.append("Parent-Activity: ").append(parent.shortComponentName).append("\n");
}
if (subject != null) {
sb.append("Subject: ").append(subject).append("\n");
}
sb.append("Build: ").append(Build.FINGERPRINT).append("\n");
if (Debug.isDebuggerConnected()) {
sb.append("Debugger: Connected\n");
}
sb.append("\n");
// Do the rest in a worker thread to avoid blocking the caller on I/O
// (After this point, we shouldn't access AMS internal data structures.)
Thread worker = new Thread("Error dump: " + dropboxTag) {
@Override
public void run() {
if (report != null) {
sb.append(report);
}
String setting = Settings.Global.ERROR_LOGCAT_PREFIX + dropboxTag;
int lines = Settings.Global.getInt(mContext.getContentResolver(), setting, 0);
int maxDataFileSize = DROPBOX_MAX_SIZE - sb.length() - lines * RESERVED_BYTES_PER_LOGCAT_LINE;
if (dataFile != null && maxDataFileSize > 0) {
try {
sb.append(FileUtils.readTextFile(dataFile, maxDataFileSize, "\n\n[[TRUNCATED]]"));
} catch (IOException e) {
Slog.e(TAG, "Error reading " + dataFile, e);
}
}
if (crashInfo != null && crashInfo.stackTrace != null) {
sb.append(crashInfo.stackTrace);
}
if (lines > 0) {
sb.append("\n");
// Merge several logcat streams, and take the last N lines
InputStreamReader input = null;
try {
java.lang.Process logcat = new ProcessBuilder("/system/bin/timeout", "-k", "15s", "10s", "/system/bin/logcat", "-v", "threadtime", "-b", "events", "-b", "system", "-b", "main", "-b", "crash", "-t", String.valueOf(lines)).redirectErrorStream(true).start();
try {
logcat.getOutputStream().close();
} catch (IOException e) {
}
try {
logcat.getErrorStream().close();
} catch (IOException e) {
}
input = new InputStreamReader(logcat.getInputStream());
int num;
char[] buf = new char[8192];
while ((num = input.read(buf)) > 0) sb.append(buf, 0, num);
} catch (IOException e) {
Slog.e(TAG, "Error running logcat", e);
} finally {
if (input != null)
try {
input.close();
} catch (IOException e) {
}
}
}
dbox.addText(dropboxTag, sb.toString());
}
};
if (process == null) {
// If process is null, we are being called from some internal code
// and may be about to die -- run this synchronously.
worker.run();
} else {
worker.start();
}
}
use of java.io.InputStreamReader in project platform_frameworks_base by android.
the class InputManagerService method getKeyboardLayoutOverlay.
// Native callback.
private String[] getKeyboardLayoutOverlay(InputDeviceIdentifier identifier) {
if (!mSystemReady) {
return null;
}
String keyboardLayoutDescriptor = getCurrentKeyboardLayoutForInputDevice(identifier);
if (keyboardLayoutDescriptor == null) {
return null;
}
final String[] result = new String[2];
visitKeyboardLayout(keyboardLayoutDescriptor, new KeyboardLayoutVisitor() {
@Override
public void visitKeyboardLayout(Resources resources, int keyboardLayoutResId, KeyboardLayout layout) {
try {
result[0] = layout.getDescriptor();
result[1] = Streams.readFully(new InputStreamReader(resources.openRawResource(keyboardLayoutResId)));
} catch (IOException ex) {
} catch (NotFoundException ex) {
}
}
});
if (result[0] == null) {
Slog.w(TAG, "Could not get keyboard layout with descriptor '" + keyboardLayoutDescriptor + "'.");
return null;
}
return result;
}
Aggregations