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

Commit 72ffc42e authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Set NotifLayoutInflaterFactory Recursively to nested RemoteViews" into main

parents 5ec442d2 575d37a2
Loading
Loading
Loading
Loading
+44 −0
Original line number Diff line number Diff line
@@ -499,6 +499,9 @@ public class RemoteViews implements Parcelable, Filter {
     * The factory callbacks will be called on the background thread so the implementation needs
     * to be thread safe.
     *
     * Note this only sets the factory to the top-level, use
     * {@link RemoteViews#visitRemoteViews(Consumer)} if nested RemoteViews also need to be set.
     *
     * @hide
     */
    public void setLayoutInflaterFactory(@Nullable LayoutInflater.Factory2 factory) {
@@ -734,6 +737,15 @@ public class RemoteViews implements Parcelable, Filter {
            return false;
        }

        /**
         * See {@link RemoteViews#visitRemoteViews(Consumer)}.
         */
        protected void visitRemoteViews(
                @NonNull Consumer<RemoteViews> visitor
        ) {
            // Nothing to visit by default.
        }

        /** See {@link RemoteViews#visitUris(Consumer)}. **/
        public void visitUris(@NonNull Consumer<Uri> visitor) {
            // Nothing to visit by default.
@@ -845,6 +857,31 @@ public class RemoteViews implements Parcelable, Filter {
        return mCollectionCache.mIdToUriMapping.size() > 0;
    }

    /**
     * A helper function to let the visitor visit this, and the nested RemoteViews recursively.
     *
     * @hide
     */
    public void visitRemoteViews(@NonNull Consumer<RemoteViews> visitor) {
        visitor.accept(this);
        if (mActions != null) {
            for (int i = 0; i < mActions.size(); i++) {
                mActions.get(i).visitRemoteViews(visitor);
            }
        }
        if (mSizedRemoteViews != null) {
            for (int i = 0; i < mSizedRemoteViews.size(); i++) {
                mSizedRemoteViews.get(i).visitRemoteViews(visitor);
            }
        }
        if (mLandscape != null) {
            mLandscape.visitRemoteViews(visitor);
        }
        if (mPortrait != null) {
            mPortrait.visitRemoteViews(visitor);
        }
    }

    /**
     * Note all {@link Uri} that are referenced internally, with the expectation that Uri permission
     * grants will need to be issued to ensure the recipient of this object is able to render its
@@ -4242,6 +4279,13 @@ public class RemoteViews implements Parcelable, Filter {
            return VIEW_GROUP_ACTION_ADD_TAG;
        }

        @Override
        protected void visitRemoteViews(
                @NonNull Consumer<RemoteViews> visitor
        ) {
            mNestedViews.visitRemoteViews(visitor);
        }

        @Override
        public void visitUris(@NonNull Consumer<Uri> visitor) {
            mNestedViews.visitUris(visitor);
+14 −18
Original line number Diff line number Diff line
@@ -939,26 +939,22 @@ constructor(
            row: ExpandableNotificationRow,
            provider: NotifLayoutInflaterFactory.Provider,
        ): NewRemoteViews {
            contracted?.let {
                it.layoutInflaterFactory = provider.provide(row, FLAG_CONTENT_VIEW_CONTRACTED)
            }
            expanded?.let {
                it.layoutInflaterFactory = provider.provide(row, FLAG_CONTENT_VIEW_EXPANDED)
            }
            headsUp?.let {
                it.layoutInflaterFactory = provider.provide(row, FLAG_CONTENT_VIEW_HEADS_UP)
            }
            public?.let {
                it.layoutInflaterFactory = provider.provide(row, FLAG_CONTENT_VIEW_PUBLIC)

            fun RemoteViews?.setLayoutInflaterFactoryRecursively(@InflationFlag layoutType: Int) {
                val layoutInflaterFactory = provider.provide(row, layoutType)
                this?.visitRemoteViews { it.layoutInflaterFactory = layoutInflaterFactory }
            }

            contracted.setLayoutInflaterFactoryRecursively(FLAG_CONTENT_VIEW_CONTRACTED)
            expanded.setLayoutInflaterFactoryRecursively(FLAG_CONTENT_VIEW_EXPANDED)
            headsUp.setLayoutInflaterFactoryRecursively(FLAG_CONTENT_VIEW_HEADS_UP)
            public.setLayoutInflaterFactoryRecursively(FLAG_CONTENT_VIEW_PUBLIC)

            if (android.app.Flags.notificationsRedesignAppIcons()) {
                normalGroupHeader?.let {
                    it.layoutInflaterFactory = provider.provide(row, FLAG_GROUP_SUMMARY_HEADER)
                }
                minimizedGroupHeader?.let {
                    it.layoutInflaterFactory =
                        provider.provide(row, FLAG_LOW_PRIORITY_GROUP_SUMMARY_HEADER)
                }
                normalGroupHeader.setLayoutInflaterFactoryRecursively(FLAG_GROUP_SUMMARY_HEADER)
                minimizedGroupHeader.setLayoutInflaterFactoryRecursively(
                    FLAG_LOW_PRIORITY_GROUP_SUMMARY_HEADER
                )
            }
            return this
        }