Loading core/java/android/app/NotificationChannel.java +21 −38 Original line number Diff line number Diff line Loading @@ -404,35 +404,24 @@ public final class NotificationChannel implements Parcelable { mDeletedTime = in.readLong(); mImportanceLockedDefaultApp = in.readBoolean(); // Add new fields above this line and not after vibration effect! When // notif_channel_estimate_effect_size is true, we use parcel size to detect whether the // vibration effect might be too large to handle, so this must remain at the end lest any // following fields cause the data to get incorrectly dropped. // Add new fields above this line and not after vibration effect! We use parcel size to // detect whether the vibration effect might be too large to handle, so this must remain at // the end lest any following fields cause the data to get incorrectly dropped. mVibrationPattern = in.createLongArray(); if (mVibrationPattern != null && mVibrationPattern.length > MAX_VIBRATION_LENGTH) { mVibrationPattern = Arrays.copyOf(mVibrationPattern, MAX_VIBRATION_LENGTH); } boolean largeEffect = false; if (Flags.notifChannelEstimateEffectSize()) { // Note that we must check the length of remaining data in the parcel before reading in // the data. largeEffect = (in.dataAvail() > MAX_SERIALIZED_VIBRATION_LENGTH); } boolean largeEffect = (in.dataAvail() > MAX_SERIALIZED_VIBRATION_LENGTH); if (Flags.notificationChannelVibrationEffectApi()) { mVibrationEffect = in.readInt() != 0 ? VibrationEffect.CREATOR.createFromParcel(in) : null; if (Flags.notifChannelCropVibrationEffects() && mVibrationEffect != null) { if (Flags.notifChannelEstimateEffectSize()) { if (mVibrationEffect != null && largeEffect) { // Try trimming the effect if the remaining parcel size is large. If trimming is // not applicable for the effect, rather than serializing to XML (expensive) to // check the exact serialized length, we just reject the effect. if (largeEffect) { mVibrationEffect = mVibrationEffect.cropToLengthOrNull( MAX_VIBRATION_LENGTH); } } else { mVibrationEffect = getTrimmedVibrationEffect(mVibrationEffect); } mVibrationEffect = mVibrationEffect.cropToLengthOrNull(MAX_VIBRATION_LENGTH); } } } Loading Loading @@ -751,11 +740,9 @@ public final class NotificationChannel implements Parcelable { public void setVibrationPattern(long[] vibrationPattern) { this.mVibrationEnabled = vibrationPattern != null && vibrationPattern.length > 0; this.mVibrationPattern = vibrationPattern; if (Flags.notifChannelCropVibrationEffects()) { if (vibrationPattern != null && vibrationPattern.length > MAX_VIBRATION_LENGTH) { this.mVibrationPattern = Arrays.copyOf(vibrationPattern, MAX_VIBRATION_LENGTH); } } if (Flags.notificationChannelVibrationEffectApi()) { try { this.mVibrationEffect = Loading Loading @@ -802,7 +789,7 @@ public final class NotificationChannel implements Parcelable { public void setVibrationEffect(@Nullable VibrationEffect effect) { this.mVibrationEnabled = effect != null; this.mVibrationEffect = effect; if (Flags.notifChannelCropVibrationEffects() && effect != null) { if (effect != null) { long[] pattern = effect.computeCreateWaveformOffOnTimingsOrNull(); if (pattern != null) { // If this effect has an equivalent pattern, AND the pattern needs to be truncated Loading @@ -821,9 +808,8 @@ public final class NotificationChannel implements Parcelable { this.mVibrationPattern = null; } } else { this.mVibrationPattern = mVibrationEffect == null ? null : mVibrationEffect.computeCreateWaveformOffOnTimingsOrNull(); // effect is set to null, so also set pattern to null. this.mVibrationPattern = null; } } Loading Loading @@ -1269,8 +1255,7 @@ public final class NotificationChannel implements Parcelable { // Restore the effect only if it is not null. This allows to avoid undoing a // `setVibrationPattern` call above, if that was done with a non-null pattern // (e.g. back up from a version that did not support `setVibrationEffect`), or // when notif_channel_crop_vibration_effects is true, if there is an equivalent // vibration pattern available. // if there is an equivalent vibration pattern available. setVibrationEffect(vibrationEffect); } } Loading Loading @@ -1467,13 +1452,11 @@ public final class NotificationChannel implements Parcelable { if (getVibrationPattern() != null) { out.attribute(null, ATT_VIBRATION, longArrayToString(getVibrationPattern())); } if (getVibrationEffect() != null) { if (!Flags.notifChannelCropVibrationEffects() || getVibrationPattern() == null) { // When notif_channel_crop_vibration_effects is on, only serialize the vibration // effect if we do not already have an equivalent vibration pattern. if (getVibrationEffect() != null && getVibrationPattern() == null) { // Only serialize the vibration effect if we do not already have an equivalent // vibration pattern. out.attribute(null, ATT_VIBRATION_EFFECT, vibrationToString(getVibrationEffect())); } } if (getUserLockedFields() != 0) { out.attributeInt(null, ATT_USER_LOCKED, getUserLockedFields()); } Loading core/java/android/app/notification.aconfig +0 −20 Original line number Diff line number Diff line Loading @@ -106,26 +106,6 @@ flag { bug: "368817201" } flag { name: "notif_channel_crop_vibration_effects" namespace: "systemui" description: "Limits the size of vibration effects that can be stored in a NotificationChannel" bug: "345881518" metadata { purpose: PURPOSE_BUGFIX } } flag { name: "notif_channel_estimate_effect_size" namespace: "systemui" description: "When reading vibration effects from parcel, estimate size instead of unnecessarily serializing to XML" bug: "391908451" metadata { purpose: PURPOSE_BUGFIX } } flag { name: "evenly_divided_call_style_action_layout" namespace: "systemui" Loading core/tests/coretests/src/android/app/NotificationChannelTest.java +5 −14 Original line number Diff line number Diff line Loading @@ -91,9 +91,7 @@ public class NotificationChannelTest { @Parameters(name = "{0}") public static List<FlagsParameterization> getParams() { return FlagsParameterization.allCombinationsOf( Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS, Flags.FLAG_NOTIF_CHANNEL_ESTIMATE_EFFECT_SIZE); return FlagsParameterization.allCombinationsOf(); } @Rule Loading Loading @@ -286,8 +284,7 @@ public class NotificationChannelTest { } @Test @EnableFlags({Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API, Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS}) @EnableFlags(Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API) public void testLongVibrationFields_canWriteToXml() throws Exception { NotificationChannel channel = new NotificationChannel("id", "name", 3); // populate pattern with contents Loading @@ -313,9 +310,7 @@ public class NotificationChannelTest { } @Test @EnableFlags({Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API, Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS, Flags.FLAG_NOTIF_CHANNEL_ESTIMATE_EFFECT_SIZE}) @EnableFlags(Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API) public void testVibrationEffect_droppedIfTooLargeAndNotTrimmable() { NotificationChannel channel = new NotificationChannel("id", "name", 3); // populate pattern with contents Loading @@ -332,9 +327,7 @@ public class NotificationChannelTest { } @Test @EnableFlags({Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API, Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS, Flags.FLAG_NOTIF_CHANNEL_ESTIMATE_EFFECT_SIZE}) @EnableFlags(Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API) public void testVibrationEffect_trimmedIfLargeAndTrimmable() { NotificationChannel channel = new NotificationChannel("id", "name", 3); // populate pattern with contents Loading @@ -353,9 +346,7 @@ public class NotificationChannelTest { } @Test @EnableFlags({Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API, Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS, Flags.FLAG_NOTIF_CHANNEL_ESTIMATE_EFFECT_SIZE}) @EnableFlags(Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API) public void testVibrationEffect_keptIfSmall() { NotificationChannel channel = new NotificationChannel("id", "name", 3); VibrationEffect effect = VibrationEffect.createOneShot(1, 100); Loading Loading
core/java/android/app/NotificationChannel.java +21 −38 Original line number Diff line number Diff line Loading @@ -404,35 +404,24 @@ public final class NotificationChannel implements Parcelable { mDeletedTime = in.readLong(); mImportanceLockedDefaultApp = in.readBoolean(); // Add new fields above this line and not after vibration effect! When // notif_channel_estimate_effect_size is true, we use parcel size to detect whether the // vibration effect might be too large to handle, so this must remain at the end lest any // following fields cause the data to get incorrectly dropped. // Add new fields above this line and not after vibration effect! We use parcel size to // detect whether the vibration effect might be too large to handle, so this must remain at // the end lest any following fields cause the data to get incorrectly dropped. mVibrationPattern = in.createLongArray(); if (mVibrationPattern != null && mVibrationPattern.length > MAX_VIBRATION_LENGTH) { mVibrationPattern = Arrays.copyOf(mVibrationPattern, MAX_VIBRATION_LENGTH); } boolean largeEffect = false; if (Flags.notifChannelEstimateEffectSize()) { // Note that we must check the length of remaining data in the parcel before reading in // the data. largeEffect = (in.dataAvail() > MAX_SERIALIZED_VIBRATION_LENGTH); } boolean largeEffect = (in.dataAvail() > MAX_SERIALIZED_VIBRATION_LENGTH); if (Flags.notificationChannelVibrationEffectApi()) { mVibrationEffect = in.readInt() != 0 ? VibrationEffect.CREATOR.createFromParcel(in) : null; if (Flags.notifChannelCropVibrationEffects() && mVibrationEffect != null) { if (Flags.notifChannelEstimateEffectSize()) { if (mVibrationEffect != null && largeEffect) { // Try trimming the effect if the remaining parcel size is large. If trimming is // not applicable for the effect, rather than serializing to XML (expensive) to // check the exact serialized length, we just reject the effect. if (largeEffect) { mVibrationEffect = mVibrationEffect.cropToLengthOrNull( MAX_VIBRATION_LENGTH); } } else { mVibrationEffect = getTrimmedVibrationEffect(mVibrationEffect); } mVibrationEffect = mVibrationEffect.cropToLengthOrNull(MAX_VIBRATION_LENGTH); } } } Loading Loading @@ -751,11 +740,9 @@ public final class NotificationChannel implements Parcelable { public void setVibrationPattern(long[] vibrationPattern) { this.mVibrationEnabled = vibrationPattern != null && vibrationPattern.length > 0; this.mVibrationPattern = vibrationPattern; if (Flags.notifChannelCropVibrationEffects()) { if (vibrationPattern != null && vibrationPattern.length > MAX_VIBRATION_LENGTH) { this.mVibrationPattern = Arrays.copyOf(vibrationPattern, MAX_VIBRATION_LENGTH); } } if (Flags.notificationChannelVibrationEffectApi()) { try { this.mVibrationEffect = Loading Loading @@ -802,7 +789,7 @@ public final class NotificationChannel implements Parcelable { public void setVibrationEffect(@Nullable VibrationEffect effect) { this.mVibrationEnabled = effect != null; this.mVibrationEffect = effect; if (Flags.notifChannelCropVibrationEffects() && effect != null) { if (effect != null) { long[] pattern = effect.computeCreateWaveformOffOnTimingsOrNull(); if (pattern != null) { // If this effect has an equivalent pattern, AND the pattern needs to be truncated Loading @@ -821,9 +808,8 @@ public final class NotificationChannel implements Parcelable { this.mVibrationPattern = null; } } else { this.mVibrationPattern = mVibrationEffect == null ? null : mVibrationEffect.computeCreateWaveformOffOnTimingsOrNull(); // effect is set to null, so also set pattern to null. this.mVibrationPattern = null; } } Loading Loading @@ -1269,8 +1255,7 @@ public final class NotificationChannel implements Parcelable { // Restore the effect only if it is not null. This allows to avoid undoing a // `setVibrationPattern` call above, if that was done with a non-null pattern // (e.g. back up from a version that did not support `setVibrationEffect`), or // when notif_channel_crop_vibration_effects is true, if there is an equivalent // vibration pattern available. // if there is an equivalent vibration pattern available. setVibrationEffect(vibrationEffect); } } Loading Loading @@ -1467,13 +1452,11 @@ public final class NotificationChannel implements Parcelable { if (getVibrationPattern() != null) { out.attribute(null, ATT_VIBRATION, longArrayToString(getVibrationPattern())); } if (getVibrationEffect() != null) { if (!Flags.notifChannelCropVibrationEffects() || getVibrationPattern() == null) { // When notif_channel_crop_vibration_effects is on, only serialize the vibration // effect if we do not already have an equivalent vibration pattern. if (getVibrationEffect() != null && getVibrationPattern() == null) { // Only serialize the vibration effect if we do not already have an equivalent // vibration pattern. out.attribute(null, ATT_VIBRATION_EFFECT, vibrationToString(getVibrationEffect())); } } if (getUserLockedFields() != 0) { out.attributeInt(null, ATT_USER_LOCKED, getUserLockedFields()); } Loading
core/java/android/app/notification.aconfig +0 −20 Original line number Diff line number Diff line Loading @@ -106,26 +106,6 @@ flag { bug: "368817201" } flag { name: "notif_channel_crop_vibration_effects" namespace: "systemui" description: "Limits the size of vibration effects that can be stored in a NotificationChannel" bug: "345881518" metadata { purpose: PURPOSE_BUGFIX } } flag { name: "notif_channel_estimate_effect_size" namespace: "systemui" description: "When reading vibration effects from parcel, estimate size instead of unnecessarily serializing to XML" bug: "391908451" metadata { purpose: PURPOSE_BUGFIX } } flag { name: "evenly_divided_call_style_action_layout" namespace: "systemui" Loading
core/tests/coretests/src/android/app/NotificationChannelTest.java +5 −14 Original line number Diff line number Diff line Loading @@ -91,9 +91,7 @@ public class NotificationChannelTest { @Parameters(name = "{0}") public static List<FlagsParameterization> getParams() { return FlagsParameterization.allCombinationsOf( Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS, Flags.FLAG_NOTIF_CHANNEL_ESTIMATE_EFFECT_SIZE); return FlagsParameterization.allCombinationsOf(); } @Rule Loading Loading @@ -286,8 +284,7 @@ public class NotificationChannelTest { } @Test @EnableFlags({Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API, Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS}) @EnableFlags(Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API) public void testLongVibrationFields_canWriteToXml() throws Exception { NotificationChannel channel = new NotificationChannel("id", "name", 3); // populate pattern with contents Loading @@ -313,9 +310,7 @@ public class NotificationChannelTest { } @Test @EnableFlags({Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API, Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS, Flags.FLAG_NOTIF_CHANNEL_ESTIMATE_EFFECT_SIZE}) @EnableFlags(Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API) public void testVibrationEffect_droppedIfTooLargeAndNotTrimmable() { NotificationChannel channel = new NotificationChannel("id", "name", 3); // populate pattern with contents Loading @@ -332,9 +327,7 @@ public class NotificationChannelTest { } @Test @EnableFlags({Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API, Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS, Flags.FLAG_NOTIF_CHANNEL_ESTIMATE_EFFECT_SIZE}) @EnableFlags(Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API) public void testVibrationEffect_trimmedIfLargeAndTrimmable() { NotificationChannel channel = new NotificationChannel("id", "name", 3); // populate pattern with contents Loading @@ -353,9 +346,7 @@ public class NotificationChannelTest { } @Test @EnableFlags({Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API, Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS, Flags.FLAG_NOTIF_CHANNEL_ESTIMATE_EFFECT_SIZE}) @EnableFlags(Flags.FLAG_NOTIFICATION_CHANNEL_VIBRATION_EFFECT_API) public void testVibrationEffect_keptIfSmall() { NotificationChannel channel = new NotificationChannel("id", "name", 3); VibrationEffect effect = VibrationEffect.createOneShot(1, 100); Loading