diff options
| -rw-r--r-- | core/java/android/app/NotificationChannel.java | 16 | ||||
| -rw-r--r-- | core/tests/coretests/src/android/app/NotificationChannelTest.java | 26 |
2 files changed, 35 insertions, 7 deletions
diff --git a/core/java/android/app/NotificationChannel.java b/core/java/android/app/NotificationChannel.java index 1b29b7a294df..32e9542e91a7 100644 --- a/core/java/android/app/NotificationChannel.java +++ b/core/java/android/app/NotificationChannel.java @@ -761,14 +761,22 @@ public final class NotificationChannel implements Parcelable { this.mVibrationEnabled = effect != null; this.mVibrationEffect = effect; if (Flags.notifChannelCropVibrationEffects() && effect != null) { - // Try converting to a vibration pattern and trimming that array. If not convertible - // to a pattern directly, try trimming the vibration effect if possible and storing - // that version instead. long[] pattern = effect.computeCreateWaveformOffOnTimingsOrNull(); if (pattern != null) { - setVibrationPattern(pattern); + // If this effect has an equivalent pattern, AND the pattern needs to be truncated + // due to being too long, we delegate to setVibrationPattern to re-generate the + // effect as well. Otherwise, we use the effect (already set above) and converted + // pattern directly. + if (pattern.length > MAX_VIBRATION_LENGTH) { + setVibrationPattern(pattern); + } else { + this.mVibrationPattern = pattern; + } } else { + // If not convertible to a pattern directly, try trimming the vibration effect if + // possible and storing that version instead. this.mVibrationEffect = getTrimmedVibrationEffect(mVibrationEffect); + this.mVibrationPattern = null; } } else { this.mVibrationPattern = diff --git a/core/tests/coretests/src/android/app/NotificationChannelTest.java b/core/tests/coretests/src/android/app/NotificationChannelTest.java index e47ef2df48b9..e19f887c1284 100644 --- a/core/tests/coretests/src/android/app/NotificationChannelTest.java +++ b/core/tests/coretests/src/android/app/NotificationChannelTest.java @@ -47,12 +47,13 @@ import android.os.RemoteException; import android.os.VibrationEffect; import android.platform.test.annotations.EnableFlags; import android.platform.test.annotations.Presubmit; +import android.platform.test.annotations.UsesFlags; +import android.platform.test.flag.junit.FlagsParameterization; import android.platform.test.flag.junit.SetFlagsRule; import android.provider.MediaStore.Audio.AudioColumns; import android.test.mock.MockContentResolver; import android.util.Xml; -import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import com.android.modules.utils.TypedXmlPullParser; @@ -61,6 +62,7 @@ import com.android.modules.utils.TypedXmlSerializer; import com.google.common.base.Strings; import org.junit.Before; +import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -71,14 +73,28 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.lang.reflect.Field; import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; -@RunWith(AndroidJUnit4.class) +import platform.test.runner.parameterized.ParameterizedAndroidJunit4; +import platform.test.runner.parameterized.Parameters; + +@RunWith(ParameterizedAndroidJunit4.class) +@UsesFlags(android.app.Flags.class) @SmallTest @Presubmit public class NotificationChannelTest { + @ClassRule + public static final SetFlagsRule.ClassRule mSetFlagsClassRule = new SetFlagsRule.ClassRule(); + + @Parameters(name = "{0}") + public static List<FlagsParameterization> getParams() { + return FlagsParameterization.allCombinationsOf( + Flags.FLAG_NOTIF_CHANNEL_CROP_VIBRATION_EFFECTS); + } + @Rule - public final SetFlagsRule mSetFlagsRule = new SetFlagsRule(); + public final SetFlagsRule mSetFlagsRule; private final String CLASS = "android.app.NotificationChannel"; @@ -86,6 +102,10 @@ public class NotificationChannelTest { ContentProvider mContentProvider; IContentProvider mIContentProvider; + public NotificationChannelTest(FlagsParameterization flags) { + mSetFlagsRule = mSetFlagsClassRule.createSetFlagsRule(flags); + } + @Before public void setUp() throws Exception { mContext = mock(Context.class); |