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

Commit 58bb1aba authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes Ifa55ca19,I7c05b19a

* changes:
  Move a bunch of row setters into an init method.
  Convert NotificationContentInflater to singleton
parents 28e81646 5182c9f5
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -584,7 +584,15 @@ public class NotificationRemoteInputManager implements Dumpable {

    public void bindRow(ExpandableNotificationRow row) {
        row.setRemoteInputController(mRemoteInputController);
        row.setRemoteViewClickHandler(mOnClickHandler);
    }

    /**
     * Return on-click handler for notification remote views
     *
     * @return on-click handler
     */
    public RemoteViews.OnClickHandler getRemoteViewsOnClickHandler() {
        return mOnClickHandler;
    }

    @VisibleForTesting
+3 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.systemui.statusbar;

import android.content.Context;

import com.android.systemui.statusbar.notification.row.NotificationRowModule;

import javax.inject.Singleton;

import dagger.Module;
@@ -26,7 +28,7 @@ import dagger.Provides;
/**
 * Dagger Module providing common dependencies of StatusBar.
 */
@Module
@Module(includes = {NotificationRowModule.class})
public class StatusBarDependenciesModule {
    /**
     * Provides our instance of CommandQueue which is considered optional.
+27 −19
Original line number Diff line number Diff line
@@ -41,8 +41,8 @@ import com.android.systemui.statusbar.notification.NotificationClicker;
import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
import com.android.systemui.statusbar.notification.row.NotificationContentInflater;
import com.android.systemui.statusbar.notification.row.NotificationGutsManager;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder;
import com.android.systemui.statusbar.notification.row.RowInflaterTask;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
import com.android.systemui.statusbar.phone.KeyguardBypassController;
@@ -67,6 +67,7 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
    private final NotificationInterruptionStateProvider mNotificationInterruptionStateProvider;

    private final Context mContext;
    private final NotificationRowContentBinder mRowContentBinder;
    private final NotificationMessagingUtil mMessagingUtil;
    private final ExpandableNotificationRow.ExpansionLogger mExpansionLogger =
            this::logNotificationExpansion;
@@ -79,7 +80,7 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
    private NotificationPresenter mPresenter;
    private NotificationListContainer mListContainer;
    private HeadsUpManager mHeadsUpManager;
    private NotificationContentInflater.InflationCallback mInflationCallback;
    private NotificationRowContentBinder.InflationCallback mInflationCallback;
    private ExpandableNotificationRow.OnAppOpsClickListener mOnAppOpsClickListener;
    private BindRowCallback mBindRowCallback;
    private NotificationClicker mNotificationClicker;
@@ -90,6 +91,7 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
            Context context,
            NotificationRemoteInputManager notificationRemoteInputManager,
            NotificationLockscreenUserManager notificationLockscreenUserManager,
            NotificationRowContentBinder rowContentBinder,
            @Named(ALLOW_NOTIFICATION_LONG_PRESS_NAME) boolean allowLongPress,
            KeyguardBypassController keyguardBypassController,
            StatusBarStateController statusBarStateController,
@@ -98,6 +100,7 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
            NotificationInterruptionStateProvider notificationInterruptionStateProvider,
            NotificationLogger logger) {
        mContext = context;
        mRowContentBinder = rowContentBinder;
        mMessagingUtil = new NotificationMessagingUtil(context);
        mNotificationRemoteInputManager = notificationRemoteInputManager;
        mNotificationLockscreenUserManager = notificationLockscreenUserManager;
@@ -124,7 +127,7 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
        mOnAppOpsClickListener = mGutsManager::openGuts;
    }

    public void setInflationCallback(NotificationContentInflater.InflationCallback callback) {
    public void setInflationCallback(NotificationRowContentBinder.InflationCallback callback) {
        mInflationCallback = callback;
    }

@@ -163,19 +166,6 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
    private void bindRow(NotificationEntry entry, PackageManager pmUser,
            StatusBarNotification sbn, ExpandableNotificationRow row,
            Runnable onDismissRunnable) {
        row.setExpansionLogger(mExpansionLogger, entry.getSbn().getKey());
        row.setBypassController(mKeyguardBypassController);
        row.setStatusBarStateController(mStatusBarStateController);
        row.setGroupManager(mGroupManager);
        row.setHeadsUpManager(mHeadsUpManager);
        row.setOnExpandClickListener(mPresenter);
        row.setInflationCallback(mInflationCallback);
        if (mAllowLongPress) {
            row.setLongPressListener(mGutsManager::openGuts);
        }
        mListContainer.bindRow(row);
        mNotificationRemoteInputManager.bindRow(row);

        // 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.
@@ -193,15 +183,33 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
        } catch (PackageManager.NameNotFoundException e) {
            // Do nothing
        }
        row.setAppName(appname);

        row.initialize(
                appname,
                sbn.getKey(),
                mExpansionLogger,
                mKeyguardBypassController,
                mGroupManager,
                mHeadsUpManager,
                mRowContentBinder,
                mPresenter);

        // TODO: Either move these into ExpandableNotificationRow#initialize or out of row entirely
        row.setStatusBarStateController(mStatusBarStateController);
        row.setInflationCallback(mInflationCallback);
        row.setAppOpsOnClickListener(mOnAppOpsClickListener);
        if (mAllowLongPress) {
            row.setLongPressListener(mGutsManager::openGuts);
        }
        mListContainer.bindRow(row);
        mNotificationRemoteInputManager.bindRow(row);

        row.setOnDismissRunnable(onDismissRunnable);
        row.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
        if (ENABLE_REMOTE_INPUT) {
            row.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);
        }

        row.setAppOpsOnClickListener(mOnAppOpsClickListener);

        mBindRowCallback.onBindRow(entry, pmUser, sbn, row);
    }

+29 −44
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
import android.widget.Chronometer;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RemoteViews;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
@@ -150,7 +149,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    private StatusBarStateController mStatusbarStateController;
    private KeyguardBypassController mBypassController;
    private LayoutListener mLayoutListener;
    private final NotificationContentInflater mNotificationInflater;
    private NotificationRowContentBinder mNotificationContentBinder;
    private int mIconTransformContentShift;
    private int mIconTransformContentShiftNoIcon;
    private int mMaxHeadsUpHeightBeforeN;
@@ -464,7 +463,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
     * Inflate views based off the inflation flags set. Inflation happens asynchronously.
     */
    public void inflateViews() {
        mNotificationInflater.bindContent(mEntry, this, mInflationFlags, mBindParams,
        mNotificationContentBinder.bindContent(mEntry, this, mInflationFlags, mBindParams,
                false /* forceInflate */, mInflationCallback);
    }

@@ -478,7 +477,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        // View should not be reinflated in the future
        clearInflationFlags(inflationFlag);
        Runnable freeViewRunnable =
                () -> mNotificationInflater.unbindContent(mEntry, this, inflationFlag);
                () -> mNotificationContentBinder.unbindContent(mEntry, this, inflationFlag);
        switch (inflationFlag) {
            case FLAG_CONTENT_VIEW_HEADS_UP:
                getPrivateLayout().performWhenContentInactive(VISIBLE_TYPE_HEADSUP,
@@ -742,23 +741,10 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return mIsHeadsUp || mHeadsupDisappearRunning;
    }


    public void setGroupManager(NotificationGroupManager groupManager) {
        mGroupManager = groupManager;
        mPrivateLayout.setGroupManager(groupManager);
    }

    public void setRemoteInputController(RemoteInputController r) {
        mPrivateLayout.setRemoteInputController(r);
    }

    public void setAppName(String appName) {
        mAppName = appName;
        if (mMenuRow != null && mMenuRow.getMenuView() != null) {
            mMenuRow.setAppName(mAppName);
        }
    }

    public void addChildNotification(ExpandableNotificationRow row) {
        addChildNotification(row, -1);
    }
@@ -852,7 +838,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            mIsChildInGroup = isChildInGroup;
            if (mIsLowPriority) {
                int flags = FLAG_CONTENT_VIEW_CONTRACTED | FLAG_CONTENT_VIEW_EXPANDED;
                mNotificationInflater.bindContent(mEntry, this, flags, mBindParams,
                mNotificationContentBinder.bindContent(mEntry, this, flags, mBindParams,
                        false /* forceInflate */, mInflationCallback);
            }
        }
@@ -1105,10 +1091,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return mPrivateLayout.getContractedNotificationHeader();
    }

    public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) {
        mOnExpandClickListener = onExpandClickListener;
    }

    public void setLongPressListener(LongPressListener longPressListener) {
        mLongPressListener = longPressListener;
    }
@@ -1131,10 +1113,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
    }

    public void setHeadsUpManager(HeadsUpManager headsUpManager) {
        mHeadsUpManager = headsUpManager;
    }

    public HeadsUpManager getHeadsUpManager() {
        return mHeadsUpManager;
    }
@@ -1259,7 +1237,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            l.reInflateViews();
        }
        mEntry.getSbn().clearPackageContext();
        mNotificationInflater.bindContent(mEntry, this, mInflationFlags, mBindParams,
        mNotificationContentBinder.bindContent(mEntry, this, mInflationFlags, mBindParams,
                true /* forceInflate */, mInflationCallback);
    }

@@ -1634,10 +1612,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        mBindParams.usesIncreasedHeadsUpHeight = use;
    }

    public void setRemoteViewClickHandler(RemoteViews.OnClickHandler remoteViewClickHandler) {
        mNotificationInflater.setRemoteViewClickHandler(remoteViewClickHandler);
    }

    /**
     * Set callback for notification content inflation
     *
@@ -1652,7 +1626,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            mNeedsRedaction = needsRedaction;
            if (needsRedaction) {
                setInflationFlags(FLAG_CONTENT_VIEW_PUBLIC);
                mNotificationInflater.bindContent(mEntry, this, FLAG_CONTENT_VIEW_PUBLIC,
                mNotificationContentBinder.bindContent(mEntry, this, FLAG_CONTENT_VIEW_PUBLIC,
                        mBindParams, false /* forceInflate */, mInflationCallback);
            } else {
                clearInflationFlags(FLAG_CONTENT_VIEW_PUBLIC);
@@ -1661,18 +1635,12 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
    }

    @VisibleForTesting
    public NotificationContentInflater getNotificationInflater() {
        return mNotificationInflater;
    }

    public interface ExpansionLogger {
        void logNotificationExpansion(String key, boolean userAction, boolean expanded);
    }

    public ExpandableNotificationRow(Context context, AttributeSet attrs) {
        super(context, attrs);
        mNotificationInflater = new NotificationContentInflater();
        mMenuRow = new NotificationMenuRow(mContext);
        mImageResolver = new NotificationInlineImageResolver(context,
                new NotificationInlineImageCache());
@@ -1680,8 +1648,30 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        initDimens();
    }

    public void setBypassController(KeyguardBypassController bypassController) {
    /**
     * Initialize row.
     */
    public void initialize(
            String appName,
            String notificationKey,
            ExpansionLogger logger,
            KeyguardBypassController bypassController,
            NotificationGroupManager groupManager,
            HeadsUpManager headsUpManager,
            NotificationRowContentBinder rowContentBinder,
            OnExpandClickListener onExpandClickListener) {
        mAppName = appName;
        if (mMenuRow != null && mMenuRow.getMenuView() != null) {
            mMenuRow.setAppName(mAppName);
        }
        mLogger = logger;
        mLoggingKey = notificationKey;
        mBypassController = bypassController;
        mGroupManager = groupManager;
        mPrivateLayout.setGroupManager(groupManager);
        mHeadsUpManager = headsUpManager;
        mNotificationContentBinder = rowContentBinder;
        mOnExpandClickListener = onExpandClickListener;
    }

    public void setStatusBarStateController(StatusBarStateController statusBarStateController) {
@@ -2920,11 +2910,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return 0;
    }

    public void setExpansionLogger(ExpansionLogger logger, String key) {
        mLogger = logger;
        mLoggingKey = key;
    }

    public void onExpandedByGesture(boolean userExpanded) {
        int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER;
        if (mGroupManager.isSummaryOfGroup(mEntry.getSbn())) {
+75 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 android.widget.RemoteViews;

import androidx.annotation.Nullable;

import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.row.NotificationRowContentBinder.InflationFlag;

/**
 * Caches {@link RemoteViews} for a notification's content views.
 */
public interface NotifRemoteViewCache {

    /**
     * Whether the notification has the remote view cached
     *
     * @param entry notification
     * @param flag inflation flag for content view
     * @return true if the remote view is cached
     */
    boolean hasCachedView(NotificationEntry entry, @InflationFlag int flag);

    /**
     * Get the remote view for the content flag specified.
     *
     * @param entry notification
     * @param flag inflation flag for the content view
     * @return the remote view if it is cached, null otherwise
     */
    @Nullable RemoteViews getCachedView(NotificationEntry entry, @InflationFlag int flag);

    /**
     * Cache a remote view for a given content flag on a notification.
     *
     * @param entry notification
     * @param flag inflation flag for the content view
     * @param remoteView remote view to store
     */
    void putCachedView(
            NotificationEntry entry,
            @InflationFlag int flag,
            RemoteViews remoteView);

    /**
     * Remove a cached remote view for a given content flag on a notification.
     *
     * @param entry notification
     * @param flag inflation flag for the content view
     */
    void removeCachedView(NotificationEntry entry, @InflationFlag int flag);

    /**
     * Clear a notification's remote view cache.
     *
     * @param entry notification
     */
    void clearCache(NotificationEntry entry);
}
Loading