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

Commit 1fa68518 authored by Ibrahim Yilmaz's avatar Ibrahim Yilmaz Committed by Android (Google) Code Review
Browse files

Merge "Create RemoteViews Factory Container" into main

parents 63ab1df3 d74605a6
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -22,11 +22,9 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag
import com.android.systemui.statusbar.notification.row.NotificationRowModule.NOTIF_REMOTEVIEWS_FACTORIES
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import javax.inject.Named

/**
 * Implementation of [NotifLayoutInflaterFactory]. This class uses a set of
@@ -37,8 +35,7 @@ class NotifLayoutInflaterFactory
constructor(
    @Assisted private val row: ExpandableNotificationRow,
    @Assisted @InflationFlag val layoutType: Int,
    @Named(NOTIF_REMOTEVIEWS_FACTORIES)
    private val remoteViewsFactories: Set<@JvmSuppressWildcards NotifRemoteViewsFactory>
    private val notifRemoteViewsFactoryContainer: NotifRemoteViewsFactoryContainer
) : LayoutInflater.Factory2 {

    override fun onCreateView(
@@ -49,7 +46,7 @@ constructor(
    ): View? {
        var handledFactory: NotifRemoteViewsFactory? = null
        var result: View? = null
        for (layoutFactory in remoteViewsFactories) {
        for (layoutFactory in notifRemoteViewsFactoryContainer.factories) {
            layoutFactory.instantiate(row, layoutType, parent, name, context, attrs)?.run {
                check(handledFactory == null) {
                    "$layoutFactory tries to produce name:$name with type:$layoutType. " +
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.statusbar.notification.row

import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import javax.inject.Inject

interface NotifRemoteViewsFactoryContainer {
    val factories: Set<NotifRemoteViewsFactory>
}

class NotifRemoteViewsFactoryContainerImpl
@Inject
constructor(
    featureFlags: FeatureFlags,
    precomputedTextViewFactory: PrecomputedTextViewFactory,
    bigPictureLayoutInflaterFactory: BigPictureLayoutInflaterFactory,
    callLayoutSetDataAsyncFactory: CallLayoutSetDataAsyncFactory,
) : NotifRemoteViewsFactoryContainer {
    override val factories: Set<NotifRemoteViewsFactory> = buildSet {
        add(precomputedTextViewFactory)
        if (featureFlags.isEnabled(Flags.BIGPICTURE_NOTIFICATION_LAZY_LOADING)) {
            add(bigPictureLayoutInflaterFactory)
        }
        if (featureFlags.isEnabled(Flags.CALL_LAYOUT_ASYNC_SET_DATA)) {
            add(callLayoutSetDataAsyncFactory)
        }
    }
}
+7 −31
Original line number Diff line number Diff line
@@ -17,26 +17,15 @@
package com.android.systemui.statusbar.notification.row;

import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;

import dagger.Binds;
import dagger.Module;
import dagger.Provides;
import dagger.multibindings.ElementsIntoSet;

import java.util.HashSet;
import java.util.Set;

import javax.inject.Named;

/**
 * Dagger Module containing notification row and view inflation implementations.
 */
@Module
public abstract class NotificationRowModule {
    public static final String NOTIF_REMOTEVIEWS_FACTORIES =
            "notif_remoteviews_factories";

    /**
     * Provides notification row content binder instance.
@@ -54,24 +43,11 @@ public abstract class NotificationRowModule {
    public abstract NotifRemoteViewCache provideNotifRemoteViewCache(
            NotifRemoteViewCacheImpl cacheImpl);

    /** Provides view factories to be inflated in notification content. */
    @Provides
    @ElementsIntoSet
    @Named(NOTIF_REMOTEVIEWS_FACTORIES)
    static Set<NotifRemoteViewsFactory> provideNotifRemoteViewsFactories(
            FeatureFlags featureFlags,
            PrecomputedTextViewFactory precomputedTextViewFactory,
            BigPictureLayoutInflaterFactory bigPictureLayoutInflaterFactory,
            CallLayoutSetDataAsyncFactory callLayoutSetDataAsyncFactory
    ) {
        final Set<NotifRemoteViewsFactory> replacementFactories = new HashSet<>();
        replacementFactories.add(precomputedTextViewFactory);
        if (featureFlags.isEnabled(Flags.BIGPICTURE_NOTIFICATION_LAZY_LOADING)) {
            replacementFactories.add(bigPictureLayoutInflaterFactory);
        }
        if (featureFlags.isEnabled(Flags.CALL_LAYOUT_ASYNC_SET_DATA)) {
            replacementFactories.add(callLayoutSetDataAsyncFactory);
        }
        return replacementFactories;
    }
    /**
     * Provides notification remote view factory container
     */
    @Binds
    @SysUISingleton
    public abstract NotifRemoteViewsFactoryContainer provideNotifRemoteViewsFactoryContainer(
            NotifRemoteViewsFactoryContainerImpl containerImpl);
}
+18 −4
Original line number Diff line number Diff line
@@ -62,7 +62,7 @@ class NotifLayoutInflaterFactoryTest : SysuiTestCase() {
    fun onCreateView_noMatchingViewForName_returnNull() {
        // GIVEN we have ViewFactories that replaces TextViews in expanded and collapsed layouts
        val layoutType = FLAG_CONTENT_VIEW_EXPANDED
        inflaterFactory = NotifLayoutInflaterFactory(row, layoutType, viewFactorySpies)
        inflaterFactory = createNotifLayoutInflaterFactory(row, layoutType, viewFactorySpies)

        // WHEN we try to inflate an ImageView for the expanded layout
        val createdView = inflaterFactory.onCreateView("ImageView", context, attrs)
@@ -78,7 +78,7 @@ class NotifLayoutInflaterFactoryTest : SysuiTestCase() {
    fun onCreateView_noMatchingViewForLayoutType_returnNull() {
        // GIVEN we have ViewFactories that replaces TextViews in expanded and collapsed layouts
        val layoutType = FLAG_CONTENT_VIEW_HEADS_UP
        inflaterFactory = NotifLayoutInflaterFactory(row, layoutType, viewFactorySpies)
        inflaterFactory = createNotifLayoutInflaterFactory(row, layoutType, viewFactorySpies)

        // WHEN we try to inflate a TextView for the heads-up layout
        val createdView = inflaterFactory.onCreateView("TextView", context, attrs)
@@ -94,7 +94,7 @@ class NotifLayoutInflaterFactoryTest : SysuiTestCase() {
    fun onCreateView_matchingViews_returnReplacementView() {
        // GIVEN we have ViewFactories that replaces TextViews in expanded and collapsed layouts
        val layoutType = FLAG_CONTENT_VIEW_EXPANDED
        inflaterFactory = NotifLayoutInflaterFactory(row, layoutType, viewFactorySpies)
        inflaterFactory = createNotifLayoutInflaterFactory(row, layoutType, viewFactorySpies)

        // WHEN we try to inflate a TextView for the expanded layout
        val createdView = inflaterFactory.onCreateView("TextView", context, attrs)
@@ -110,7 +110,7 @@ class NotifLayoutInflaterFactoryTest : SysuiTestCase() {
        // GIVEN we have two factories that replaces TextViews in expanded layouts
        val layoutType = FLAG_CONTENT_VIEW_EXPANDED
        inflaterFactory =
            NotifLayoutInflaterFactory(
            createNotifLayoutInflaterFactory(
                row,
                layoutType,
                setOf(
@@ -147,4 +147,18 @@ class NotifLayoutInflaterFactoryTest : SysuiTestCase() {
                    null
                }
        }

    private fun createNotifLayoutInflaterFactory(
        row: ExpandableNotificationRow,
        layoutType: Int,
        notifRemoteViewsFactoryContainer: Set<NotifRemoteViewsFactory>
    ) =
        NotifLayoutInflaterFactory(
            row,
            layoutType,
            object : NotifRemoteViewsFactoryContainer {
                override val factories: Set<NotifRemoteViewsFactory> =
                    notifRemoteViewsFactoryContainer
            }
        )
}