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

Commit 3742322d authored by Kevin Han's avatar Kevin Han
Browse files

Clean up NotificationRowBinderImpl

Clean up a few things in NotificationRowBinderImpl

*Remove a bunch of dead parameters and methodsd
*Split logic into three main helper methods
   1) bindRow - called once when row is made
   2) updateRow - called to update row view state whenever the
   notification is updated
   3) inflateContentViews - called to initiate row content inflation
   whenever notification is updated
*Try to move other logic to appropriate places
  -Mainly move targetSdk resolution to be right after setting the sbn
  instead of after the row is inflated. This also makes icons neater to
  manage since we can immediately set the tag

Bug: 145749521
Test: atest SystemUITests
Change-Id: Id59a28c0fbbe1df5ffc4ec8eef58d760b8c6df05
parent 661a6fdd
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -558,6 +558,10 @@ public class NotificationEntryManager implements
                ranking,
                mFgsFeatureController.isForegroundServiceDismissalEnabled(),
                SystemClock.uptimeMillis());
        for (NotifCollectionListener listener : mNotifCollectionListeners) {
            listener.onEntryBind(entry, notification);
        }
        mAllNotifications.add(entry);

        mLeakDetector.trackInstance(entry);

@@ -612,7 +616,9 @@ public class NotificationEntryManager implements
        updateRankingAndSort(ranking, "updateNotificationInternal");
        StatusBarNotification oldSbn = entry.getSbn();
        entry.setSbn(notification);
        mGroupManager.onEntryUpdated(entry, oldSbn);
        for (NotifCollectionListener listener : mNotifCollectionListeners) {
            listener.onEntryBind(entry, notification);
        }        mGroupManager.onEntryUpdated(entry, oldSbn);

        mLogger.logNotifUpdated(entry.getKey());
        for (NotificationEntryListener listener : mNotificationEntryListeners) {
+3 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ import com.android.systemui.statusbar.FeatureFlags;
import com.android.systemui.statusbar.notification.collection.coalescer.CoalescedEvent;
import com.android.systemui.statusbar.notification.collection.coalescer.GroupCoalescer;
import com.android.systemui.statusbar.notification.collection.coalescer.GroupCoalescer.BatchableNotificationHandler;
import com.android.systemui.statusbar.notification.collection.notifcollection.BindEntryEvent;
import com.android.systemui.statusbar.notification.collection.notifcollection.CleanUpEntryEvent;
import com.android.systemui.statusbar.notification.collection.notifcollection.CollectionReadyForBuildListener;
import com.android.systemui.statusbar.notification.collection.notifcollection.DismissedByUserStats;
@@ -389,6 +390,7 @@ public class NotifCollection implements Dumpable {
        if (entry == null) {
            // A new notification!
            entry = new NotificationEntry(sbn, ranking, SystemClock.uptimeMillis());
            mEventQueue.add(new BindEntryEvent(entry, sbn));
            mNotificationSet.put(sbn.getKey(), entry);

            mLogger.logNotifPosted(sbn.getKey());
@@ -409,6 +411,7 @@ public class NotifCollection implements Dumpable {
            entry.mCancellationReason = REASON_NOT_CANCELED;

            entry.setSbn(sbn);
            mEventQueue.add(new BindEntryEvent(entry, sbn));

            mLogger.logNotifUpdated(sbn.getKey());
            mEventQueue.add(new EntryUpdatedEvent(entry));
+0 −9
Original line number Diff line number Diff line
@@ -408,15 +408,6 @@ public final class NotificationEntry extends ListEntry {
        return wasBubble != isBubble();
    }

    /**
     * Resets the notification entry to be re-used.
     */
    public void reset() {
        if (row != null) {
            row.reset();
        }
    }

    @NotificationSectionsManager.PriorityBucket
    public int getBucket() {
        return mBucket;
+56 −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.collection

import android.content.Context
import android.content.pm.PackageManager
import android.service.notification.StatusBarNotification
import android.util.Log
import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
import com.android.systemui.statusbar.phone.StatusBar
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class TargetSdkResolver @Inject constructor(
    private val context: Context,
    private val collection: CommonNotifCollection
) {
    init {
        collection.addCollectionListener(object : NotifCollectionListener {
            override fun onEntryBind(entry: NotificationEntry, sbn: StatusBarNotification) {
                entry.targetSdk = resolveNotificationSdk(sbn)
            }
        })
    }

    private fun resolveNotificationSdk(sbn: StatusBarNotification): Int {
        val pmUser = StatusBar.getPackageManagerForUser(context, sbn.user.identifier)
        var targetSdk = 0
        // Extract target SDK version.
        try {
            val info = pmUser.getApplicationInfo(sbn.packageName, 0)
            targetSdk = info.targetSdkVersion
        } catch (ex: PackageManager.NameNotFoundException) {
            Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.packageName, ex)
        }
        return targetSdk
    }

    private val TAG = "TargetSdkResolver"
}
 No newline at end of file
+43 −51
Original line number Diff line number Diff line
@@ -16,13 +16,11 @@

package com.android.systemui.statusbar.notification.collection.inflation;

import static java.util.Objects.requireNonNull;

import android.annotation.Nullable;
import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.service.notification.StatusBarNotification;
import android.util.Log;
import android.view.ViewGroup;

import com.android.internal.util.NotificationMessagingUtil;
@@ -44,9 +42,6 @@ import com.android.systemui.statusbar.notification.row.RowContentBindStage;
import com.android.systemui.statusbar.notification.row.RowInflaterTask;
import com.android.systemui.statusbar.notification.row.dagger.ExpandableNotificationRowComponent;
import com.android.systemui.statusbar.notification.stack.NotificationListContainer;
import com.android.systemui.statusbar.phone.StatusBar;

import java.util.Objects;

import javax.inject.Inject;
import javax.inject.Provider;
@@ -128,14 +123,13 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
    public void inflateViews(NotificationEntry entry, Runnable onDismissRunnable)
            throws InflationException {
        ViewGroup parent = mListContainer.getViewParentForNotification(entry);
        PackageManager pmUser = StatusBar.getPackageManagerForUser(mContext,
                entry.getSbn().getUser().getIdentifier());

        final StatusBarNotification sbn = entry.getSbn();
        if (entry.rowExists()) {
            mIconManager.updateIcons(entry);
            entry.reset();
            updateNotification(entry, pmUser, sbn, entry.getRow());
            ExpandableNotificationRow row = entry.getRow();
            row.reset();
            updateRow(entry, row);
            inflateContentViews(entry, row);
            entry.getRowController().setOnDismissRunnable(onDismissRunnable);
        } else {
            mIconManager.createIcons(entry);
@@ -155,21 +149,27 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
                                component.getExpandableNotificationRowController();
                        rowController.init();
                        entry.setRowController(rowController);
                        bindRow(entry, pmUser, sbn, row);
                        updateNotification(entry, pmUser, sbn, row);
                        bindRow(entry, row);
                        updateRow(entry, row);
                        inflateContentViews(entry, row);
                    });
        }
    }

    //TODO: This method associates a row with an entry, but eventually needs to not do that
    private void bindRow(NotificationEntry entry, PackageManager pmUser,
            StatusBarNotification sbn, ExpandableNotificationRow row) {
    /**
     * Bind row to various controllers and managers. This is only called when the row is first
     * created.
     *
     * TODO: This method associates a row with an entry, but eventually needs to not do that
     */
    private void bindRow(NotificationEntry entry, ExpandableNotificationRow row) {
        mListContainer.bindRow(row);
        mNotificationRemoteInputManager.bindRow(row);
        row.setOnActivatedListener(mPresenter);
        entry.setRow(row);
        row.setEntry(entry);
        mNotifBindPipeline.manageRow(entry, row);
        mBindRowCallback.onBindRow(entry, pmUser, sbn, row);
        mBindRowCallback.onBindRow(row);
    }

    /**
@@ -184,11 +184,10 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
            NotificationUiAdjustment newAdjustment) {
        if (NotificationUiAdjustment.needReinflate(oldAdjustment, newAdjustment)) {
            if (entry.rowExists()) {
                entry.reset();
                PackageManager pmUser = StatusBar.getPackageManagerForUser(
                        mContext,
                        entry.getSbn().getUser().getIdentifier());
                updateNotification(entry, pmUser, entry.getSbn(), entry.getRow());
                ExpandableNotificationRow row = entry.getRow();
                row.reset();
                updateRow(entry, row);
                inflateContentViews(entry, row);
            } else {
                // Once the RowInflaterTask is done, it will pick up the updated entry, so
                // no-op here.
@@ -202,59 +201,52 @@ public class NotificationRowBinderImpl implements NotificationRowBinder {
        }
    }

    private void updateNotification(
    /**
     * Update row after the notification has updated.
     *
     * @param entry notification that has updated
     */
    private void updateRow(
            NotificationEntry entry,
            PackageManager pmUser,
            StatusBarNotification sbn,
            ExpandableNotificationRow row) {

        // Extract target SDK version.
        try {
            ApplicationInfo info = pmUser.getApplicationInfo(sbn.getPackageName(), 0);
            entry.targetSdk = info.targetSdkVersion;
        } catch (PackageManager.NameNotFoundException ex) {
            Log.e(TAG, "Failed looking up ApplicationInfo for " + sbn.getPackageName(), ex);
        }
        row.setLegacy(entry.targetSdk >= Build.VERSION_CODES.GINGERBREAD
                && entry.targetSdk < Build.VERSION_CODES.LOLLIPOP);

        // TODO: should this be happening somewhere else?
        mIconManager.updateIconTags(entry, entry.targetSdk);

        row.setOnActivatedListener(mPresenter);
        // bind the click event to the content area
        requireNonNull(mNotificationClicker).register(row, entry.getSbn());
    }

    /**
     * Inflate the row's basic content views.
     */
    private void inflateContentViews(
            NotificationEntry entry,
            ExpandableNotificationRow row) {
        final boolean useIncreasedCollapsedHeight =
                mMessagingUtil.isImportantMessaging(sbn, entry.getImportance());
                mMessagingUtil.isImportantMessaging(entry.getSbn(), entry.getImportance());
        final boolean isLowPriority = entry.isAmbient();

        RowContentBindParams params = mRowContentBindStage.getStageParams(entry);
        params.setUseIncreasedCollapsedHeight(useIncreasedCollapsedHeight);
        params.setUseLowPriority(entry.isAmbient());

        //TODO: Replace this API with RowContentBindParams directly
        // TODO: Replace this API with RowContentBindParams directly. Also move to a separate
        // redaction controller.
        row.setNeedsRedaction(mNotificationLockscreenUserManager.needsRedaction(entry));

        params.rebindAllContentViews();
        mRowContentBindStage.requestRebind(entry, en -> {
            row.setUsesIncreasedCollapsedHeight(useIncreasedCollapsedHeight);
            row.setIsLowPriority(isLowPriority);
            mInflationCallback.onAsyncInflationFinished(en);
        });

        // bind the click event to the content area
        Objects.requireNonNull(mNotificationClicker).register(row, sbn);
    }

    /** Callback for when a row is bound to an entry. */
    public interface BindRowCallback {
        /**
         * Called when a new notification and row is created.
         *
         * @param entry  entry for the notification
         * @param pmUser package manager for user
         * @param sbn    notification
         * @param row    row for the notification
         * Called when a new row is created and bound to a notification.
         */
        void onBindRow(NotificationEntry entry, PackageManager pmUser,
                StatusBarNotification sbn, ExpandableNotificationRow row);
        void onBindRow(ExpandableNotificationRow row);
    }
}
Loading