Java Code Examples for android.os.FileUtils#readTextFile()
The following examples show how to use
android.os.FileUtils#readTextFile() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RescueParty.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
/** * Hacky test to check if the device has an active USB connection, which is * a good proxy for someone doing local development work. */ private static boolean isUsbActive() { if (SystemProperties.getBoolean(PROP_VIRTUAL_DEVICE, false)) { Slog.v(TAG, "Assuming virtual device is connected over USB"); return true; } try { final String state = FileUtils .readTextFile(new File("/sys/class/android_usb/android0/state"), 128, ""); return "CONFIGURED".equals(state.trim()); } catch (Throwable t) { Slog.w(TAG, "Failed to determine if device was on USB", t); return false; } }
Example 2
Source File: MemoryStatUtil.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private static String readFileContents(String path) { final File file = new File(path); if (!file.exists()) { if (DEBUG_METRICS) Slog.i(TAG, path + " not found"); return null; } try { return FileUtils.readTextFile(file, 0 /* max */, null /* ellipsis */); } catch (IOException e) { Slog.e(TAG, "Failed to read file:", e); return null; } }
Example 3
Source File: SystemServer.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
private void performPendingShutdown() { final String shutdownAction = SystemProperties.get( ShutdownThread.SHUTDOWN_ACTION_PROPERTY, ""); if (shutdownAction != null && shutdownAction.length() > 0) { boolean reboot = (shutdownAction.charAt(0) == '1'); final String reason; if (shutdownAction.length() > 1) { reason = shutdownAction.substring(1, shutdownAction.length()); } else { reason = null; } // If it's a pending reboot into recovery to apply an update, // always make sure uncrypt gets executed properly when needed. // If '/cache/recovery/block.map' hasn't been created, stop the // reboot which will fail for sure, and get a chance to capture a // bugreport when that's still feasible. (Bug: 26444951) if (reason != null && reason.startsWith(PowerManager.REBOOT_RECOVERY_UPDATE)) { File packageFile = new File(UNCRYPT_PACKAGE_FILE); if (packageFile.exists()) { String filename = null; try { filename = FileUtils.readTextFile(packageFile, 0, null); } catch (IOException e) { Slog.e(TAG, "Error reading uncrypt package file", e); } if (filename != null && filename.startsWith("/data")) { if (!new File(BLOCK_MAP_FILE).exists()) { Slog.e(TAG, "Can't find block map file, uncrypt failed or " + "unexpected runtime restart?"); return; } } } } Runnable runnable = new Runnable() { @Override public void run() { synchronized (this) { ShutdownThread.rebootOrShutdown(null, reboot, reason); } } }; // ShutdownThread must run on a looper capable of displaying the UI. Message msg = Message.obtain(UiThread.getHandler(), runnable); msg.setAsynchronous(true); UiThread.getHandler().sendMessage(msg); } }