Set a cap while package manager is dumping the critical info

Also, log 'Relax SCAN_REQUIRE_KNOWN' to the system log instead.
It would be logged each time when the device boot-up, and the device
could suffer from message bloat.

Bug: 120549172
Test: adb push a large file to /data/system/uiderrors.txt; \
      adb shell dumpsys package
Change-Id: Ie7114a701b397ffe2ee98faf4ead8ac5633c09c7
This commit is contained in:
Rhed Jao
2020-10-22 19:22:39 +08:00
parent 5657694a20
commit 0f498dff26
2 changed files with 16 additions and 6 deletions

View File

@@ -12227,9 +12227,8 @@ public class PackageManagerService extends IPackageManager.Stub
// user-installed version of the application will be ignored.
if ((scanFlags & SCAN_REQUIRE_KNOWN) != 0) {
if (mExpectingBetter.containsKey(pkg.getPackageName())) {
logCriticalInfo(Log.WARN,
"Relax SCAN_REQUIRE_KNOWN requirement for package "
+ pkg.getPackageName());
Slog.w(TAG, "Relax SCAN_REQUIRE_KNOWN requirement for package "
+ pkg.getPackageName());
} else {
PackageSetting known = mSettings.getPackageLPr(pkg.getPackageName());
if (known != null) {

View File

@@ -103,7 +103,8 @@ import java.util.zip.GZIPInputStream;
* {@hide}
*/
public class PackageManagerServiceUtils {
private final static long SEVEN_DAYS_IN_MILLISECONDS = 7 * 24 * 60 * 60 * 1000;
private static final long SEVEN_DAYS_IN_MILLISECONDS = 7 * 24 * 60 * 60 * 1000;
private static final long MAX_CRITICAL_INFO_DUMP_SIZE = 3 * 1000 * 1000; // 3MB
public final static Predicate<PackageSetting> REMOVE_IF_NULL_PKG =
pkgSetting -> pkgSetting.pkg == null;
@@ -349,7 +350,12 @@ public class PackageManagerServiceUtils {
}
public static void dumpCriticalInfo(ProtoOutputStream proto) {
try (BufferedReader in = new BufferedReader(new FileReader(getSettingsProblemFile()))) {
final File file = getSettingsProblemFile();
final long skipSize = file.length() - MAX_CRITICAL_INFO_DUMP_SIZE;
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
if (skipSize > 0) {
in.skip(skipSize);
}
String line = null;
while ((line = in.readLine()) != null) {
if (line.contains("ignored: updated version")) continue;
@@ -360,7 +366,12 @@ public class PackageManagerServiceUtils {
}
public static void dumpCriticalInfo(PrintWriter pw, String msg) {
try (BufferedReader in = new BufferedReader(new FileReader(getSettingsProblemFile()))) {
final File file = getSettingsProblemFile();
final long skipSize = file.length() - MAX_CRITICAL_INFO_DUMP_SIZE;
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
if (skipSize > 0) {
in.skip(skipSize);
}
String line = null;
while ((line = in.readLine()) != null) {
if (line.contains("ignored: updated version")) continue;