Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 155ea55d authored by Yuri Lin's avatar Yuri Lin Committed by Android (Google) Code Review
Browse files

Merge "Update handling of vibration effects that don't need cropping" into main

parents c9451a4c 4db9092a
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -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) {
                // 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 =
+23 −3
Original line number Diff line number Diff line
@@ -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);