Loading core/java/android/os/RecoverySystem.java +3 −119 Original line number Diff line number Diff line Loading @@ -36,16 +36,12 @@ import android.util.Log; import android.view.Display; import android.view.WindowManager; import com.android.internal.logging.MetricsLogger; import libcore.io.Streams; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; Loading Loading @@ -97,7 +93,7 @@ public class RecoverySystem { /** Used to communicate with recovery. See bootable/recovery/recovery.cpp. */ private static final File RECOVERY_DIR = new File("/cache/recovery"); private static final File LOG_FILE = new File(RECOVERY_DIR, "log"); private static final File LAST_INSTALL_FILE = new File(RECOVERY_DIR, "last_install"); private static final String LAST_INSTALL_PATH = "last_install"; private static final String LAST_PREFIX = "last_"; private static final String ACTION_EUICC_FACTORY_RESET = "com.android.internal.action.EUICC_FACTORY_RESET"; Loading Loading @@ -935,116 +931,6 @@ public class RecoverySystem { throw new IOException("Reboot failed (no permissions?)"); } // Read last_install; then report time (in seconds) and I/O (in MiB) for // this update to tron. // Only report on the reboots immediately after an OTA update. private static void parseLastInstallLog(Context context) { try (BufferedReader in = new BufferedReader(new FileReader(LAST_INSTALL_FILE))) { String line = null; int bytesWrittenInMiB = -1, bytesStashedInMiB = -1; int timeTotal = -1; int uncryptTime = -1; int sourceVersion = -1; int temperatureStart = -1; int temperatureEnd = -1; int temperatureMax = -1; int errorCode = -1; int causeCode = -1; while ((line = in.readLine()) != null) { // Here is an example of lines in last_install: // ... // time_total: 101 // bytes_written_vendor: 51074 // bytes_stashed_vendor: 200 int numIndex = line.indexOf(':'); if (numIndex == -1 || numIndex + 1 >= line.length()) { continue; } String numString = line.substring(numIndex + 1).trim(); long parsedNum; try { parsedNum = Long.parseLong(numString); } catch (NumberFormatException ignored) { Log.e(TAG, "Failed to parse numbers in " + line); continue; } final int MiB = 1024 * 1024; int scaled; try { if (line.startsWith("bytes")) { scaled = Math.toIntExact(parsedNum / MiB); } else { scaled = Math.toIntExact(parsedNum); } } catch (ArithmeticException ignored) { Log.e(TAG, "Number overflows in " + line); continue; } if (line.startsWith("time")) { timeTotal = scaled; } else if (line.startsWith("uncrypt_time")) { uncryptTime = scaled; } else if (line.startsWith("source_build")) { sourceVersion = scaled; } else if (line.startsWith("bytes_written")) { bytesWrittenInMiB = (bytesWrittenInMiB == -1) ? scaled : bytesWrittenInMiB + scaled; } else if (line.startsWith("bytes_stashed")) { bytesStashedInMiB = (bytesStashedInMiB == -1) ? scaled : bytesStashedInMiB + scaled; } else if (line.startsWith("temperature_start")) { temperatureStart = scaled; } else if (line.startsWith("temperature_end")) { temperatureEnd = scaled; } else if (line.startsWith("temperature_max")) { temperatureMax = scaled; } else if (line.startsWith("error")) { errorCode = scaled; } else if (line.startsWith("cause")) { causeCode = scaled; } } // Don't report data to tron if corresponding entry isn't found in last_install. if (timeTotal != -1) { MetricsLogger.histogram(context, "ota_time_total", timeTotal); } if (uncryptTime != -1) { MetricsLogger.histogram(context, "ota_uncrypt_time", uncryptTime); } if (sourceVersion != -1) { MetricsLogger.histogram(context, "ota_source_version", sourceVersion); } if (bytesWrittenInMiB != -1) { MetricsLogger.histogram(context, "ota_written_in_MiBs", bytesWrittenInMiB); } if (bytesStashedInMiB != -1) { MetricsLogger.histogram(context, "ota_stashed_in_MiBs", bytesStashedInMiB); } if (temperatureStart != -1) { MetricsLogger.histogram(context, "ota_temperature_start", temperatureStart); } if (temperatureEnd != -1) { MetricsLogger.histogram(context, "ota_temperature_end", temperatureEnd); } if (temperatureMax != -1) { MetricsLogger.histogram(context, "ota_temperature_max", temperatureMax); } if (errorCode != -1) { MetricsLogger.histogram(context, "ota_non_ab_error_code", errorCode); } if (causeCode != -1) { MetricsLogger.histogram(context, "ota_non_ab_cause_code", causeCode); } } catch (IOException e) { Log.e(TAG, "Failed to read lines in last_install", e); } } /** * Called after booting to process and remove recovery-related files. * @return the log file from recovery, or null if none was found. Loading @@ -1062,9 +948,6 @@ public class RecoverySystem { Log.e(TAG, "Error reading recovery log", e); } if (log != null) { parseLastInstallLog(context); } // Only remove the OTA package if it's partially processed (uncrypt'd). boolean reservePackage = BLOCK_MAP_FILE.exists(); Loading Loading @@ -1095,7 +978,8 @@ public class RecoverySystem { // GmsCore to avoid re-downloading everything again. String[] names = RECOVERY_DIR.list(); for (int i = 0; names != null && i < names.length; i++) { if (names[i].startsWith(LAST_PREFIX)) continue; // Do not remove the last_install file since the recovery-persist takes care of it. if (names[i].startsWith(LAST_PREFIX) || names[i].equals(LAST_INSTALL_PATH)) continue; if (reservePackage && names[i].equals(BLOCK_MAP_FILE.getName())) continue; if (reservePackage && names[i].equals(UNCRYPT_PACKAGE_FILE.getName())) continue; Loading Loading
core/java/android/os/RecoverySystem.java +3 −119 Original line number Diff line number Diff line Loading @@ -36,16 +36,12 @@ import android.util.Log; import android.view.Display; import android.view.WindowManager; import com.android.internal.logging.MetricsLogger; import libcore.io.Streams; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; Loading Loading @@ -97,7 +93,7 @@ public class RecoverySystem { /** Used to communicate with recovery. See bootable/recovery/recovery.cpp. */ private static final File RECOVERY_DIR = new File("/cache/recovery"); private static final File LOG_FILE = new File(RECOVERY_DIR, "log"); private static final File LAST_INSTALL_FILE = new File(RECOVERY_DIR, "last_install"); private static final String LAST_INSTALL_PATH = "last_install"; private static final String LAST_PREFIX = "last_"; private static final String ACTION_EUICC_FACTORY_RESET = "com.android.internal.action.EUICC_FACTORY_RESET"; Loading Loading @@ -935,116 +931,6 @@ public class RecoverySystem { throw new IOException("Reboot failed (no permissions?)"); } // Read last_install; then report time (in seconds) and I/O (in MiB) for // this update to tron. // Only report on the reboots immediately after an OTA update. private static void parseLastInstallLog(Context context) { try (BufferedReader in = new BufferedReader(new FileReader(LAST_INSTALL_FILE))) { String line = null; int bytesWrittenInMiB = -1, bytesStashedInMiB = -1; int timeTotal = -1; int uncryptTime = -1; int sourceVersion = -1; int temperatureStart = -1; int temperatureEnd = -1; int temperatureMax = -1; int errorCode = -1; int causeCode = -1; while ((line = in.readLine()) != null) { // Here is an example of lines in last_install: // ... // time_total: 101 // bytes_written_vendor: 51074 // bytes_stashed_vendor: 200 int numIndex = line.indexOf(':'); if (numIndex == -1 || numIndex + 1 >= line.length()) { continue; } String numString = line.substring(numIndex + 1).trim(); long parsedNum; try { parsedNum = Long.parseLong(numString); } catch (NumberFormatException ignored) { Log.e(TAG, "Failed to parse numbers in " + line); continue; } final int MiB = 1024 * 1024; int scaled; try { if (line.startsWith("bytes")) { scaled = Math.toIntExact(parsedNum / MiB); } else { scaled = Math.toIntExact(parsedNum); } } catch (ArithmeticException ignored) { Log.e(TAG, "Number overflows in " + line); continue; } if (line.startsWith("time")) { timeTotal = scaled; } else if (line.startsWith("uncrypt_time")) { uncryptTime = scaled; } else if (line.startsWith("source_build")) { sourceVersion = scaled; } else if (line.startsWith("bytes_written")) { bytesWrittenInMiB = (bytesWrittenInMiB == -1) ? scaled : bytesWrittenInMiB + scaled; } else if (line.startsWith("bytes_stashed")) { bytesStashedInMiB = (bytesStashedInMiB == -1) ? scaled : bytesStashedInMiB + scaled; } else if (line.startsWith("temperature_start")) { temperatureStart = scaled; } else if (line.startsWith("temperature_end")) { temperatureEnd = scaled; } else if (line.startsWith("temperature_max")) { temperatureMax = scaled; } else if (line.startsWith("error")) { errorCode = scaled; } else if (line.startsWith("cause")) { causeCode = scaled; } } // Don't report data to tron if corresponding entry isn't found in last_install. if (timeTotal != -1) { MetricsLogger.histogram(context, "ota_time_total", timeTotal); } if (uncryptTime != -1) { MetricsLogger.histogram(context, "ota_uncrypt_time", uncryptTime); } if (sourceVersion != -1) { MetricsLogger.histogram(context, "ota_source_version", sourceVersion); } if (bytesWrittenInMiB != -1) { MetricsLogger.histogram(context, "ota_written_in_MiBs", bytesWrittenInMiB); } if (bytesStashedInMiB != -1) { MetricsLogger.histogram(context, "ota_stashed_in_MiBs", bytesStashedInMiB); } if (temperatureStart != -1) { MetricsLogger.histogram(context, "ota_temperature_start", temperatureStart); } if (temperatureEnd != -1) { MetricsLogger.histogram(context, "ota_temperature_end", temperatureEnd); } if (temperatureMax != -1) { MetricsLogger.histogram(context, "ota_temperature_max", temperatureMax); } if (errorCode != -1) { MetricsLogger.histogram(context, "ota_non_ab_error_code", errorCode); } if (causeCode != -1) { MetricsLogger.histogram(context, "ota_non_ab_cause_code", causeCode); } } catch (IOException e) { Log.e(TAG, "Failed to read lines in last_install", e); } } /** * Called after booting to process and remove recovery-related files. * @return the log file from recovery, or null if none was found. Loading @@ -1062,9 +948,6 @@ public class RecoverySystem { Log.e(TAG, "Error reading recovery log", e); } if (log != null) { parseLastInstallLog(context); } // Only remove the OTA package if it's partially processed (uncrypt'd). boolean reservePackage = BLOCK_MAP_FILE.exists(); Loading Loading @@ -1095,7 +978,8 @@ public class RecoverySystem { // GmsCore to avoid re-downloading everything again. String[] names = RECOVERY_DIR.list(); for (int i = 0; names != null && i < names.length; i++) { if (names[i].startsWith(LAST_PREFIX)) continue; // Do not remove the last_install file since the recovery-persist takes care of it. if (names[i].startsWith(LAST_PREFIX) || names[i].equals(LAST_INSTALL_PATH)) continue; if (reservePackage && names[i].equals(BLOCK_MAP_FILE.getName())) continue; if (reservePackage && names[i].equals(UNCRYPT_PACKAGE_FILE.getName())) continue; Loading