Loading services/core/java/com/android/server/notification/ZenModeHelper.java +9 −1 Original line number Diff line number Diff line Loading @@ -149,6 +149,8 @@ public class ZenModeHelper { private static final String IMPLICIT_RULE_ID_PREFIX = "implicit_"; // + pkg_name private static final int MAX_ICON_RESOURCE_NAME_LENGTH = 1000; /** * Send new activation AutomaticZenRule statuses to apps with a min target SDK version */ Loading Loading @@ -2645,7 +2647,13 @@ public class ZenModeHelper { requireNonNull(packageName); try { final Resources res = mPm.getResourcesForApplication(packageName); return res.getResourceName(resId); String resourceName = res.getResourceName(resId); if (resourceName != null && resourceName.length() > MAX_ICON_RESOURCE_NAME_LENGTH) { Slog.e(TAG, "Resource name for ID=" + resId + " in package " + packageName + " is too long (" + resourceName.length() + "); ignoring it"); return null; } return resourceName; } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { Slog.e(TAG, "Resource name for ID=" + resId + " not found in package " + packageName + ". Resource IDs may change when the application is upgraded, and the system" Loading services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -6168,6 +6168,23 @@ public class ZenModeHelperTest extends UiServiceTestCase { .isEqualTo(previousManualZenPolicy); } @Test @EnableFlags(Flags.FLAG_MODES_API) public void addRule_iconIdWithResourceNameTooLong_ignoresIcon() { int resourceId = 999; String veryLongResourceName = "com.android.server.notification:drawable/" + "omg_this_is_one_long_resource_name".repeat(100); when(mResources.getResourceName(resourceId)).thenReturn(veryLongResourceName); when(mResources.getIdentifier(veryLongResourceName, null, null)).thenReturn(resourceId); String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), new AutomaticZenRule.Builder("Rule", CONDITION_ID).setIconResId(resourceId).build(), UPDATE_ORIGIN_APP, "reason", CUSTOM_PKG_UID); AutomaticZenRule storedRule = mZenModeHelper.getAutomaticZenRule(ruleId); assertThat(storedRule.getIconResId()).isEqualTo(0); } private static void addZenRule(ZenModeConfig config, String id, String ownerPkg, int zenMode, @Nullable ZenPolicy zenPolicy) { ZenRule rule = new ZenRule(); Loading Loading
services/core/java/com/android/server/notification/ZenModeHelper.java +9 −1 Original line number Diff line number Diff line Loading @@ -149,6 +149,8 @@ public class ZenModeHelper { private static final String IMPLICIT_RULE_ID_PREFIX = "implicit_"; // + pkg_name private static final int MAX_ICON_RESOURCE_NAME_LENGTH = 1000; /** * Send new activation AutomaticZenRule statuses to apps with a min target SDK version */ Loading Loading @@ -2645,7 +2647,13 @@ public class ZenModeHelper { requireNonNull(packageName); try { final Resources res = mPm.getResourcesForApplication(packageName); return res.getResourceName(resId); String resourceName = res.getResourceName(resId); if (resourceName != null && resourceName.length() > MAX_ICON_RESOURCE_NAME_LENGTH) { Slog.e(TAG, "Resource name for ID=" + resId + " in package " + packageName + " is too long (" + resourceName.length() + "); ignoring it"); return null; } return resourceName; } catch (PackageManager.NameNotFoundException | Resources.NotFoundException e) { Slog.e(TAG, "Resource name for ID=" + resId + " not found in package " + packageName + ". Resource IDs may change when the application is upgraded, and the system" Loading
services/tests/uiservicestests/src/com/android/server/notification/ZenModeHelperTest.java +17 −0 Original line number Diff line number Diff line Loading @@ -6168,6 +6168,23 @@ public class ZenModeHelperTest extends UiServiceTestCase { .isEqualTo(previousManualZenPolicy); } @Test @EnableFlags(Flags.FLAG_MODES_API) public void addRule_iconIdWithResourceNameTooLong_ignoresIcon() { int resourceId = 999; String veryLongResourceName = "com.android.server.notification:drawable/" + "omg_this_is_one_long_resource_name".repeat(100); when(mResources.getResourceName(resourceId)).thenReturn(veryLongResourceName); when(mResources.getIdentifier(veryLongResourceName, null, null)).thenReturn(resourceId); String ruleId = mZenModeHelper.addAutomaticZenRule(mContext.getPackageName(), new AutomaticZenRule.Builder("Rule", CONDITION_ID).setIconResId(resourceId).build(), UPDATE_ORIGIN_APP, "reason", CUSTOM_PKG_UID); AutomaticZenRule storedRule = mZenModeHelper.getAutomaticZenRule(ruleId); assertThat(storedRule.getIconResId()).isEqualTo(0); } private static void addZenRule(ZenModeConfig config, String id, String ownerPkg, int zenMode, @Nullable ZenPolicy zenPolicy) { ZenRule rule = new ZenRule(); Loading