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

Commit 874b269d authored by Matías Hernández's avatar Matías Hernández Committed by Automerger Merge Worker
Browse files

Merge "Visit Uris added by WearableExtender" into udc-qpr-dev am: 60c7e016

parents e07b8343 60c7e016
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -2171,6 +2171,10 @@ public class Notification implements Parcelable
            }
        }
        private void visitUris(@NonNull Consumer<Uri> visitor) {
            visitIconUri(visitor, getIcon());
        }
        @Override
        public Action clone() {
            return new Action(
@@ -2858,7 +2862,7 @@ public class Notification implements Parcelable
        if (actions != null) {
            for (Action action : actions) {
                visitIconUri(visitor, action.getIcon());
                action.visitUris(visitor);
            }
        }
@@ -2939,6 +2943,11 @@ public class Notification implements Parcelable
        if (mBubbleMetadata != null) {
            visitIconUri(visitor, mBubbleMetadata.getIcon());
        }
        if (extras != null && extras.containsKey(WearableExtender.EXTRA_WEARABLE_EXTENSIONS)) {
            WearableExtender extender = new WearableExtender(this);
            extender.visitUris(visitor);
        }
    }
    /**
@@ -11715,6 +11724,12 @@ public class Notification implements Parcelable
                mFlags &= ~mask;
            }
        }
        private void visitUris(@NonNull Consumer<Uri> visitor) {
            for (Action action : mActions) {
                action.visitUris(visitor);
            }
        }
    }
    /**
+20 −0
Original line number Diff line number Diff line
@@ -5909,6 +5909,26 @@ public class NotificationManagerServiceTest extends UiServiceTestCase {
        verify(visitor, times(1)).accept(eq(verificationIcon.getUri()));
    }
    @Test
    public void testVisitUris_wearableExtender() {
        Icon actionIcon = Icon.createWithContentUri("content://media/action");
        Icon wearActionIcon = Icon.createWithContentUri("content://media/wearAction");
        PendingIntent intent = PendingIntent.getActivity(mContext, 0, new Intent(),
                PendingIntent.FLAG_IMMUTABLE);
        Notification n = new Notification.Builder(mContext, "a")
                .setSmallIcon(android.R.drawable.sym_def_app_icon)
                .addAction(new Notification.Action.Builder(actionIcon, "Hey!", intent).build())
                .extend(new Notification.WearableExtender().addAction(
                        new Notification.Action.Builder(wearActionIcon, "Wear!", intent).build()))
                .build();
        Consumer<Uri> visitor = (Consumer<Uri>) spy(Consumer.class);
        n.visitUris(visitor);
        verify(visitor).accept(eq(actionIcon.getUri()));
        verify(visitor).accept(eq(wearActionIcon.getUri()));
    }
    @Test
    public void testSetNotificationPolicy_preP_setOldFields() {
        ZenModeHelper mZenModeHelper = mock(ZenModeHelper.class);
+30 −5
Original line number Diff line number Diff line
@@ -67,6 +67,8 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Executable;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
@@ -88,7 +90,6 @@ public class NotificationVisitUrisTest extends UiServiceTestCase {
    // This list should be emptied! Items can be removed as bugs are fixed.
    private static final Multimap<Class<?>, String> KNOWN_BAD =
            ImmutableMultimap.<Class<?>, String>builder()
                    .put(Notification.WearableExtender.class, "addAction") // TODO: b/281044385
                    .put(Person.Builder.class, "setUri") // TODO: b/281044385
                    .put(RemoteViews.class, "setRemoteAdapter") // TODO: b/281044385
                    .build();
@@ -164,7 +165,7 @@ public class NotificationVisitUrisTest extends UiServiceTestCase {
                /* extenderClass= */ Notification.WearableExtender.class,
                /* actionExtenderClass= */ Notification.Action.WearableExtender.class,
                /* includeRemoteViews= */ true);
        assertThat(notification.includedUris.size()).isAtLeast(730);
        assertThat(notification.includedUris.size()).isAtLeast(900);
    }

    @Test
@@ -450,19 +451,43 @@ public class NotificationVisitUrisTest extends UiServiceTestCase {
            Set<Class<?>> excludingClasses, SpecialParameterGenerator specialGenerator) {
        Log.i(TAG, "About to generate parameters for " + ReflectionUtils.methodToString(executable)
                + " in " + where);
        Class<?>[] parameterTypes = executable.getParameterTypes();
        Type[] parameterTypes = executable.getGenericParameterTypes();
        Object[] parameterValues = new Object[parameterTypes.length];
        for (int i = 0; i < parameterTypes.length; i++) {
            parameterValues[i] = generateObject(
            parameterValues[i] = generateParameter(
                    parameterTypes[i],
                    where.plus(executable,
                            String.format("[%d,%s]", i, parameterTypes[i].getName())),
                            String.format("[%d,%s]", i, parameterTypes[i].getTypeName())),
                    excludingClasses,
                    specialGenerator);
        }
        return parameterValues;
    }

    private static Object generateParameter(Type parameterType, Location where,
            Set<Class<?>> excludingClasses, SpecialParameterGenerator specialGenerator) {
        if (parameterType instanceof Class<?> parameterClass) {
            return generateObject(
                    parameterClass,
                    where,
                    excludingClasses,
                    specialGenerator);
        } else if (parameterType instanceof ParameterizedType parameterizedType) {
            if (parameterizedType.getRawType().equals(List.class)
                    && parameterizedType.getActualTypeArguments()[0] instanceof Class<?>) {
                ArrayList listValue = new ArrayList();
                for (int i = 0; i < NUM_ELEMENTS_IN_ARRAY; i++) {
                    listValue.add(
                            generateObject((Class<?>) parameterizedType.getActualTypeArguments()[0],
                                    where, excludingClasses, specialGenerator));
                }
                return listValue;
            }
        }
        throw new IllegalArgumentException(
                "I have no idea how to produce a(n) " + parameterType + ", sorry");
    }

    private static class ReflectionUtils {
        static Set<Class<?>> getConcreteSubclasses(Class<?> clazz, Class<?> containerClass) {
            return Arrays.stream(containerClass.getDeclaredClasses())