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

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

Merge changes I001413f1,Id59a28c0 into rvc-dev

* changes:
  Remove setInflationCallback
  Clean up NotificationRowBinderImpl
parents ced11b60 bd142939
Loading
Loading
Loading
Loading
+44 −35
Original line number Diff line number Diff line
@@ -88,14 +88,11 @@ import dagger.Lazy;
 * @see #getActiveNotificationUnfiltered(String) to check if a key exists
 * @see #getPendingNotificationsIterator() for an iterator over the pending notifications
 * @see #getPendingOrActiveNotif(String) to find a notification exists for that key in any list
 * @see #getPendingAndActiveNotifications() to get the entire set of Notifications that we're
 * aware of
 * @see #getActiveNotificationsForCurrentUser() to see every notification that the current user owns
 */
public class NotificationEntryManager implements
        CommonNotifCollection,
        Dumpable,
        InflationCallback,
        VisualStabilityManager.Callback {
    private static final String TAG = "NotificationEntryMgr";
    private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG);
@@ -309,12 +306,7 @@ public class NotificationEntryManager implements
     *
     * WARNING: this will call back into us.  Don't hold any locks.
     */
    @Override
    public void handleInflationException(NotificationEntry n, Exception e) {
        handleInflationException(n.getSbn(), e);
    }

    public void handleInflationException(StatusBarNotification n, Exception e) {
    private void handleInflationException(StatusBarNotification n, Exception e) {
        removeNotificationInternal(
                n.getKey(), null, null, true /* forceRemove */, false /* removedByUser */,
                REASON_ERROR);
@@ -323,6 +315,12 @@ public class NotificationEntryManager implements
        }
    }

    private final InflationCallback mInflationCallback = new InflationCallback() {
        @Override
        public void handleInflationException(NotificationEntry entry, Exception e) {
            NotificationEntryManager.this.handleInflationException(entry.getSbn(), e);
        }

        @Override
        public void onAsyncInflationFinished(NotificationEntry entry) {
            mPendingNotifications.remove(entry.getKey());
@@ -347,6 +345,7 @@ public class NotificationEntryManager implements
                }
            }
        }
    };

    private final NotificationHandler mNotifListener = new NotificationHandler() {
        @Override
@@ -558,6 +557,10 @@ public class NotificationEntryManager implements
                ranking,
                mFgsFeatureController.isForegroundServiceDismissalEnabled(),
                SystemClock.uptimeMillis());
        for (NotifCollectionListener listener : mNotifCollectionListeners) {
            listener.onEntryBind(entry, notification);
        }
        mAllNotifications.add(entry);

        mLeakDetector.trackInstance(entry);

@@ -568,8 +571,10 @@ public class NotificationEntryManager implements
        // Construct the expanded view.
        if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) {
            mNotificationRowBinderLazy.get()
                    .inflateViews(entry, () -> performRemoveNotification(notification,
                            REASON_CANCEL));
                    .inflateViews(
                            entry,
                            () -> performRemoveNotification(notification, REASON_CANCEL),
                            mInflationCallback);
        }

        abortExistingInflation(key, "addNotification");
@@ -612,7 +617,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) {
@@ -624,8 +631,10 @@ public class NotificationEntryManager implements

        if (!mFeatureFlags.isNewNotifPipelineRenderingEnabled()) {
            mNotificationRowBinderLazy.get()
                    .inflateViews(entry, () -> performRemoveNotification(notification,
                            REASON_CANCEL));
                    .inflateViews(
                            entry,
                            () -> performRemoveNotification(notification, REASON_CANCEL),
                            mInflationCallback);
        }

        updateNotifications("updateNotificationInternal");
+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));
+28 −30
Original line number Diff line number Diff line
@@ -47,7 +47,6 @@ public class NotifInflaterImpl implements NotifInflater {
    private final NotifPipeline mNotifPipeline;

    private NotificationRowBinderImpl mNotificationRowBinder;
    private InflationCallback mExternalInflationCallback;

    @Inject
    public NotifInflaterImpl(
@@ -66,17 +65,11 @@ public class NotifInflaterImpl implements NotifInflater {
     */
    public void setRowBinder(NotificationRowBinderImpl rowBinder) {
        mNotificationRowBinder = rowBinder;
        mNotificationRowBinder.setInflationCallback(mInflationCallback);
    }

    @Override
    public void setInflationCallback(InflationCallback callback) {
        mExternalInflationCallback = callback;
    }

    @Override
    public void rebindViews(NotificationEntry entry) {
        inflateViews(entry);
    public void rebindViews(NotificationEntry entry, InflationCallback callback) {
        inflateViews(entry, callback);
    }

    /**
@@ -84,11 +77,14 @@ public class NotifInflaterImpl implements NotifInflater {
     * views are bound.
     */
    @Override
    public void inflateViews(NotificationEntry entry) {
    public void inflateViews(NotificationEntry entry, InflationCallback callback) {
        try {
            requireBinder().inflateViews(entry, getDismissCallback(entry));
            requireBinder().inflateViews(
                    entry,
                    getDismissCallback(entry),
                    wrapInflationCallback(callback));
        } catch (InflationException e) {
            // logged in mInflationCallback.handleInflationException
            mNotifErrorManager.setInflationError(entry, e);
        }
    }

@@ -121,16 +117,9 @@ public class NotifInflaterImpl implements NotifInflater {
        };
    }

    private NotificationRowBinderImpl requireBinder() {
        if (mNotificationRowBinder == null) {
            throw new RuntimeException("NotificationRowBinder must be attached before using "
                    + "NotifInflaterImpl.");
        }
        return mNotificationRowBinder;
    }

    private final NotificationContentInflater.InflationCallback mInflationCallback =
            new NotificationContentInflater.InflationCallback() {
    private NotificationContentInflater.InflationCallback wrapInflationCallback(
            InflationCallback callback) {
        return new NotificationContentInflater.InflationCallback() {
            @Override
            public void handleInflationException(
                    NotificationEntry entry,
@@ -141,9 +130,18 @@ public class NotifInflaterImpl implements NotifInflater {
            @Override
            public void onAsyncInflationFinished(NotificationEntry entry) {
                mNotifErrorManager.clearInflationError(entry);
                    if (mExternalInflationCallback != null) {
                        mExternalInflationCallback.onInflationFinished(entry);
                if (callback != null) {
                    callback.onInflationFinished(entry);
                }
            }
        };
    }

    private NotificationRowBinderImpl requireBinder() {
        if (mNotificationRowBinder == null) {
            throw new RuntimeException("NotificationRowBinder must be attached before using "
                    + "NotifInflaterImpl.");
        }
        return mNotificationRowBinder;
    }
}
+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
Loading