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

Commit ad044d91 authored by lyn's avatar lyn
Browse files

Bind PipelineEntry to ENRController

Bug: 406555775
Test: compile and send bundled test notif
Flag: com.android.systemui.notification_bundle_ui
Change-Id: I1f81100080d3d26d6c393679c51023c0cecebc64
parent ad91a8bf
Loading
Loading
Loading
Loading
+1 −5
Original line number Diff line number Diff line
@@ -78,9 +78,6 @@ import org.mockito.kotlin.atLeastOnce
@TestableLooper.RunWithLooper
class ExpandableNotificationRowControllerTest : SysuiTestCase() {

    private val appName = "MyApp"
    private val notifKey = "MyNotifKey"

    private val kosmos = testKosmos()

    private lateinit var entry: NotificationEntry
@@ -143,8 +140,7 @@ class ExpandableNotificationRowControllerTest : SysuiTestCase() {
            smartReplyController,
            pluginManager,
            systemClock,
            appName,
            notifKey,
            context,
            keyguardBypassController,
            groupMembershipManager,
            groupExpansionManager,
+1 −1
Original line number Diff line number Diff line
@@ -155,7 +155,7 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
                        ExpandableNotificationRowComponent component =
                                mExpandableNotificationRowComponentBuilder
                                        .expandableNotificationRow(row)
                                        .notificationEntry(entry)
                                        .pipelineEntry(entry)
                                        .onExpandClickListener(mPresenter)
                                        .build();
                        ExpandableNotificationRowController rowController =
+11 −2
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.statusbar.notification.collection.coordinator.Bundle
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow
import com.android.systemui.statusbar.notification.row.RowInflaterTask
import com.android.systemui.statusbar.notification.row.RowInflaterTaskLogger
import com.android.systemui.statusbar.notification.row.dagger.ExpandableNotificationRowComponent
import com.android.systemui.statusbar.notification.stack.NotificationListContainer
import com.android.systemui.util.time.SystemClock
import dagger.Lazy
@@ -39,6 +40,7 @@ import javax.inject.Provider
 */
@SysUISingleton
class BundleBarn @Inject constructor(
    private val rowComponent: ExpandableNotificationRowComponent.Builder,
    private val rowInflaterTaskProvider: Provider<RowInflaterTask>,
    private val listContainer: NotificationListContainer,
    val context: Context? = null,
@@ -73,8 +75,15 @@ class BundleBarn @Inject constructor(
        val inflationFinishedListener: (ExpandableNotificationRow) -> Unit = { row ->
            // A subset of NotificationRowBinderImpl.inflateViews
            debugLog("finished inflating: ${bundleEntry.key}")
            // TODO(b/402628023) set up expandableNotificationRowComponentBuilder
            //  and call controller.init(bundleEntry)
            val component = rowComponent
                    .expandableNotificationRow(row)
                    .pipelineEntry(bundleEntry)
                    .onExpandClickListener(presenterLazy?.get())
                    .build()
            val controller =
                component.expandableNotificationRowController
            controller.init(bundleEntry)
            keyToControllerMap[bundleEntry.key] = controller
        }
        debugLog("calling inflate: ${bundleEntry.key}")
        keyToControllerMap[bundleEntry.key] = null
+40 −11
Original line number Diff line number Diff line
@@ -21,10 +21,14 @@ import static com.android.systemui.statusbar.NotificationRemoteInputManager.ENAB
import static com.android.systemui.statusbar.StatusBarState.KEYGUARD;
import static com.android.systemui.statusbar.notification.NotificationUtils.logKey;
import static com.android.systemui.util.kotlin.JavaAdapterKt.collectFlow;
import android.content.Context;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.UserHandle;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
@@ -47,6 +51,7 @@ import com.android.systemui.statusbar.SmartReplyController;
import com.android.systemui.statusbar.notification.ColorUpdateLogger;
import com.android.systemui.statusbar.notification.FeedbackIcon;
import com.android.systemui.statusbar.notification.collection.EntryAdapterFactory;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.PipelineEntry;
import com.android.systemui.statusbar.notification.collection.provider.NotificationDismissibilityProvider;
import com.android.systemui.statusbar.notification.collection.render.GroupExpansionManager;
@@ -55,13 +60,12 @@ import com.android.systemui.statusbar.notification.collection.render.NodeControl
import com.android.systemui.statusbar.notification.collection.render.NotifViewController;
import com.android.systemui.statusbar.notification.headsup.HeadsUpManager;
import com.android.systemui.statusbar.notification.people.PeopleNotificationIdentifier;
import com.android.systemui.statusbar.notification.row.dagger.AppName;
import com.android.systemui.statusbar.notification.row.dagger.NotificationKey;
import com.android.systemui.statusbar.notification.row.dagger.NotificationRowScope;
import com.android.systemui.statusbar.notification.shared.NotificationBundleUi;
import com.android.systemui.statusbar.notification.stack.NotificationChildrenContainerLogger;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
import com.android.systemui.statusbar.notification.stack.ui.view.NotificationRowStatsLogger;
import com.android.systemui.statusbar.phone.CentralSurfaces;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
import com.android.systemui.statusbar.policy.SmartReplyConstants;
import com.android.systemui.statusbar.policy.dagger.RemoteInputViewSubcomponent;
@@ -92,8 +96,6 @@ public class ExpandableNotificationRowController implements NotifViewController
    private final ActivatableNotificationViewController mActivatableNotificationViewController;
    private final PluginManager mPluginManager;
    private final SystemClock mClock;
    private final String mAppName;
    private final String mNotificationKey;
    private final ColorUpdateLogger mColorUpdateLogger;
    private final KeyguardBypassController mKeyguardBypassController;
    private final GroupMembershipManager mGroupMembershipManager;
@@ -124,6 +126,7 @@ public class ExpandableNotificationRowController implements NotifViewController
    private final NotificationSettingsController mSettingsController;
    private final EntryAdapterFactory mEntryAdapterFactory;
    private final WindowRootViewBlurInteractor mWindowRootViewBlurInteractor;
    private final Context mContext;

    @VisibleForTesting
    final NotificationSettingsController.Listener mSettingsListener =
@@ -252,7 +255,6 @@ public class ExpandableNotificationRowController implements NotifViewController
                }
            };


    @Inject
    public ExpandableNotificationRowController(
            ExpandableNotificationRow view,
@@ -267,8 +269,7 @@ public class ExpandableNotificationRowController implements NotifViewController
            SmartReplyController smartReplyController,
            PluginManager pluginManager,
            SystemClock clock,
            @AppName String appName,
            @NotificationKey String notificationKey,
            Context context,
            KeyguardBypassController keyguardBypassController,
            GroupMembershipManager groupMembershipManager,
            GroupExpansionManager groupExpansionManager,
@@ -293,13 +294,12 @@ public class ExpandableNotificationRowController implements NotifViewController
            EntryAdapterFactory entryAdapterFactory,
            WindowRootViewBlurInteractor windowRootViewBlurInteractor) {
        mView = view;
        mContext = context;
        mListContainer = listContainer;
        mRemoteInputViewSubcomponentFactory = rivSubcomponentFactory;
        mActivatableNotificationViewController = activatableNotificationViewController;
        mPluginManager = pluginManager;
        mClock = clock;
        mAppName = appName;
        mNotificationKey = notificationKey;
        mKeyguardBypassController = keyguardBypassController;
        mGroupMembershipManager = groupMembershipManager;
        mGroupExpansionManager = groupExpansionManager;
@@ -332,6 +332,35 @@ public class ExpandableNotificationRowController implements NotifViewController
        mWindowRootViewBlurInteractor = windowRootViewBlurInteractor;
    }

    String loadsGutsAppName(Context context, PipelineEntry pipelineEntry) {
        if (pipelineEntry instanceof NotificationEntry notificationEntry) {
            StatusBarNotification statusBarNotification = notificationEntry.getSbn();
            if (statusBarNotification == null) {
                return "";
            }
            // Get the app name.
            // Note that Notification.Builder#bindHeaderAppName has similar logic
            // but since this field is used in the guts, it must be accurate.
            // Therefore we will only show the application label, or, failing that, the
            // package name. No substitutions.
            PackageManager pmUser = CentralSurfaces.getPackageManagerForUser(
                    context, statusBarNotification.getUser().getIdentifier());
            final String pkg = statusBarNotification.getPackageName();
            try {
                final ApplicationInfo info = pmUser.getApplicationInfo(pkg,
                        PackageManager.MATCH_UNINSTALLED_PACKAGES
                                | PackageManager.MATCH_DISABLED_COMPONENTS);
                if (info != null) {
                    return String.valueOf(pmUser.getApplicationLabel(info));
                }
            } catch (PackageManager.NameNotFoundException e) {
                // Do nothing
            }
            return pkg;
        }
        return "";
    }

    /**
     * Initialize the controller.
     */
@@ -341,8 +370,8 @@ public class ExpandableNotificationRowController implements NotifViewController
                mEntryAdapterFactory.create(entry),
                entry,
                mRemoteInputViewSubcomponentFactory,
                mAppName,
                mNotificationKey,
                loadsGutsAppName(mContext, entry),
                entry.getKey(),
                mLoggerCallback,
                mKeyguardBypassController,
                mGroupMembershipManager,
+8 −45
Original line number Diff line number Diff line
@@ -16,24 +16,19 @@

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

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.service.notification.StatusBarNotification;

import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.PipelineEntry;
import com.android.systemui.statusbar.notification.row.ActivatableNotificationView;
import com.android.systemui.statusbar.notification.row.BigPictureIconManager;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRowController;
import com.android.systemui.statusbar.phone.CentralSurfaces;

import dagger.Binds;
import dagger.BindsInstance;
import dagger.Module;
import dagger.Provides;
import dagger.Subcomponent;


/**
 * Dagger Component for a {@link ExpandableNotificationRow}.
 */
@@ -44,7 +39,6 @@ import dagger.Subcomponent;
})
@NotificationRowScope
public interface ExpandableNotificationRowComponent {

    /**
     * Builder for {@link NotificationRowComponent}.
     */
@@ -56,7 +50,7 @@ public interface ExpandableNotificationRowComponent {
        @BindsInstance
        Builder expandableNotificationRow(ExpandableNotificationRow view);
        @BindsInstance
        Builder notificationEntry(NotificationEntry entry);
        Builder pipelineEntry(PipelineEntry pipelineEntry);
        @BindsInstance
        Builder onExpandClickListener(ExpandableNotificationRow.OnExpandClickListener presenter);
        ExpandableNotificationRowComponent build();
@@ -78,47 +72,16 @@ public interface ExpandableNotificationRowComponent {
     * Dagger Module that extracts interesting properties from an ExpandableNotificationRow.
     */
    @Module
    abstract class ExpandableNotificationRowModule {

    class ExpandableNotificationRowModule {
        /** ExpandableNotificationRow is provided as an instance of ActivatableNotificationView. */
        @Binds
        abstract ActivatableNotificationView bindExpandableView(ExpandableNotificationRow view);

        @Provides
        static StatusBarNotification provideStatusBarNotification(
                NotificationEntry notificationEntry) {
            return notificationEntry.getSbn();
        ActivatableNotificationView bindExpandableView(ExpandableNotificationRow view) {
            return view;
        }

        @Provides
        @NotificationKey
        static String provideNotificationKey(StatusBarNotification statusBarNotification) {
            return statusBarNotification.getKey();
        }

        @Provides
        @AppName
        static String provideAppName(Context context, StatusBarNotification statusBarNotification) {
            // Get the app name.
            // Note that Notification.Builder#bindHeaderAppName has similar logic
            // but since this field is used in the guts, it must be accurate.
            // Therefore we will only show the application label, or, failing that, the
            // package name. No substitutions.
            PackageManager pmUser = CentralSurfaces.getPackageManagerForUser(
                    context, statusBarNotification.getUser().getIdentifier());
            final String pkg = statusBarNotification.getPackageName();
            try {
                final ApplicationInfo info = pmUser.getApplicationInfo(pkg,
                        PackageManager.MATCH_UNINSTALLED_PACKAGES
                                | PackageManager.MATCH_DISABLED_COMPONENTS);
                if (info != null) {
                    return String.valueOf(pmUser.getApplicationLabel(info));
                }
            } catch (PackageManager.NameNotFoundException e) {
                // Do nothing
            }

            return pkg;
        NotificationEntry provideNotificationEntry(PipelineEntry pipelineEntry) {
            return (NotificationEntry) pipelineEntry;
        }
    }
}