From 61722016377e992b5e2e63d5886684f8ac195c7e Mon Sep 17 00:00:00 2001 From: Rhed Jao Date: Fri, 30 Jul 2021 15:52:05 +0800 Subject: [PATCH] DO NOT MERGE Apply a maximum char count to the load label api The system is overwhelmed by an enormous label string returned by the load label api. This cl truncates the label string if it exceeds the maximum safe length. Also update the max safe label length to 1000 characters, which is enough. Bug: 67013844 Test: atest PackageManagerTest Change-Id: Ia4d768cc93a47cfb8b6f7c4b6dc73abd801809bd Merged-in: Ia4d768cc93a47cfb8b6f7c4b6dc73abd801809bd --- core/java/android/content/pm/PackageItemInfo.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/java/android/content/pm/PackageItemInfo.java b/core/java/android/content/pm/PackageItemInfo.java index d0ab8f713de83..aa8e84262049b 100644 --- a/core/java/android/content/pm/PackageItemInfo.java +++ b/core/java/android/content/pm/PackageItemInfo.java @@ -49,7 +49,7 @@ import java.util.Comparator; */ public class PackageItemInfo { /** The maximum length of a safe label, in characters */ - private static final int MAX_SAFE_LABEL_LENGTH = 50000; + private static final int MAX_SAFE_LABEL_LENGTH = 1000; /** @hide */ public static final float DEFAULT_MAX_LABEL_SIZE_PX = 500f; @@ -198,7 +198,9 @@ public class PackageItemInfo { return loadSafeLabel(pm, DEFAULT_MAX_LABEL_SIZE_PX, SAFE_STRING_FLAG_TRIM | SAFE_STRING_FLAG_FIRST_LINE); } else { - return loadUnsafeLabel(pm); + // Trims the label string to the MAX_SAFE_LABEL_LENGTH. This is to prevent that the + // system is overwhelmed by an enormous string returned by the application. + return TextUtils.trimToSize(loadUnsafeLabel(pm), MAX_SAFE_LABEL_LENGTH); } }