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

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

Merge "[DO NOT MERGE] Prevent RemoteViews crashing SystemUi" into tm-dev

parents 26e6bddf 10752edb
Loading
Loading
Loading
Loading
+29 −10
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.content.pm.LauncherActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PointF;
import android.graphics.Rect;
@@ -312,6 +313,14 @@ public class AppWidgetHostView extends FrameLayout {
            super.onLayout(changed, left, top, right, bottom);
        } catch (final RuntimeException e) {
            Log.e(TAG, "Remote provider threw runtime exception, using error view instead.", e);
            handleViewError();
        }
    }

    /**
     * Remove bad view and replace with error message view
     */
    private void handleViewError() {
        removeViewInLayout(mView);
        View child = getErrorView();
        prepareView(child);
@@ -323,7 +332,6 @@ public class AppWidgetHostView extends FrameLayout {
        mView = child;
        mViewMode = VIEW_MODE_ERROR;
    }
    }

    /**
     * Provide guidance about the size of this widget to the AppWidgetManager. The widths and
@@ -940,4 +948,15 @@ public class AppWidgetHostView extends FrameLayout {
            reapplyLastRemoteViews();
        }
    }

    @Override
    protected void dispatchDraw(@NonNull Canvas canvas) {
        try {
            super.dispatchDraw(canvas);
        } catch (Exception e) {
            // Catch draw exceptions that may be caused by RemoteViews
            Log.e(TAG, "Drawing view failed: " + e);
            post(this::handleViewError);
        }
    }
}
+5 −2
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ import android.widget.ImageView;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.statusbar.IStatusBarService;
import com.android.internal.util.ContrastColorUtil;
import com.android.internal.widget.CachingIconView;
import com.android.internal.widget.CallLayout;
@@ -1551,7 +1552,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            NotificationGutsManager gutsManager,
            MetricsLogger metricsLogger,
            SmartReplyConstants smartReplyConstants,
            SmartReplyController smartReplyController) {
            SmartReplyController smartReplyController,
            IStatusBarService statusBarService) {
        mEntry = entry;
        mAppName = appName;
        if (mMenuRow == null) {
@@ -1580,7 +1582,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
                    mPeopleNotificationIdentifier,
                    rivSubcomponentFactory,
                    smartReplyConstants,
                    smartReplyController);
                    smartReplyController,
                    statusBarService);
        }
        mOnUserInteractionCallback = onUserInteractionCallback;
        mBubblesManagerOptional = bubblesManagerOptional;
+7 −3
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.internal.logging.MetricsLogger;
import com.android.internal.statusbar.IStatusBarService;
import com.android.systemui.classifier.FalsingCollector;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.Flags;
@@ -100,8 +101,8 @@ public class ExpandableNotificationRowController implements NotifViewController
    private final Optional<BubblesManager> mBubblesManagerOptional;
    private final SmartReplyConstants mSmartReplyConstants;
    private final SmartReplyController mSmartReplyController;

    private final ExpandableNotificationRowDragController mDragController;
    private final IStatusBarService mStatusBarService;

    @Inject
    public ExpandableNotificationRowController(
@@ -133,7 +134,8 @@ public class ExpandableNotificationRowController implements NotifViewController
            FeatureFlags featureFlags,
            PeopleNotificationIdentifier peopleNotificationIdentifier,
            Optional<BubblesManager> bubblesManagerOptional,
            ExpandableNotificationRowDragController dragController) {
            ExpandableNotificationRowDragController dragController,
            IStatusBarService statusBarService) {
        mView = view;
        mListContainer = listContainer;
        mRemoteInputViewSubcomponentFactory = rivSubcomponentFactory;
@@ -164,6 +166,7 @@ public class ExpandableNotificationRowController implements NotifViewController
        mMetricsLogger = metricsLogger;
        mSmartReplyConstants = smartReplyConstants;
        mSmartReplyController = smartReplyController;
        mStatusBarService = statusBarService;
    }

    /**
@@ -194,7 +197,8 @@ public class ExpandableNotificationRowController implements NotifViewController
                mNotificationGutsManager,
                mMetricsLogger,
                mSmartReplyConstants,
                mSmartReplyController
                mSmartReplyController,
                mStatusBarService
        );
        mView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
        if (mAllowLongPress) {
+53 −1
Original line number Diff line number Diff line
@@ -21,10 +21,13 @@ import android.annotation.Nullable;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.RemoteException;
import android.provider.Settings;
import android.service.notification.StatusBarNotification;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.IndentingPrintWriter;
@@ -39,6 +42,7 @@ import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.statusbar.IStatusBarService;
import com.android.systemui.R;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.statusbar.RemoteInputController;
@@ -129,6 +133,7 @@ public class NotificationContentView extends FrameLayout implements Notification
    private Runnable mExpandedVisibleListener;
    private PeopleNotificationIdentifier mPeopleIdentifier;
    private RemoteInputViewSubcomponent.Factory mRemoteInputSubcomponentFactory;
    private IStatusBarService mStatusBarService;

    /**
     * List of listeners for when content views become inactive (i.e. not the showing view).
@@ -194,11 +199,13 @@ public class NotificationContentView extends FrameLayout implements Notification
            PeopleNotificationIdentifier peopleNotificationIdentifier,
            RemoteInputViewSubcomponent.Factory rivSubcomponentFactory,
            SmartReplyConstants smartReplyConstants,
            SmartReplyController smartReplyController) {
            SmartReplyController smartReplyController,
            IStatusBarService statusBarService) {
        mPeopleIdentifier = peopleNotificationIdentifier;
        mRemoteInputSubcomponentFactory = rivSubcomponentFactory;
        mSmartReplyConstants = smartReplyConstants;
        mSmartReplyController = smartReplyController;
        mStatusBarService = statusBarService;
    }

    public void reinflate() {
@@ -2090,4 +2097,49 @@ public class NotificationContentView extends FrameLayout implements Notification
        @Nullable RemoteInputView mView;
        @Nullable RemoteInputViewController mController;
    }

    @VisibleForTesting
    protected void setContractedWrapper(NotificationViewWrapper contractedWrapper) {
        mContractedWrapper = contractedWrapper;
    }
    @VisibleForTesting
    protected void setExpandedWrapper(NotificationViewWrapper expandedWrapper) {
        mExpandedWrapper = expandedWrapper;
    }
    @VisibleForTesting
    protected void setHeadsUpWrapper(NotificationViewWrapper headsUpWrapper) {
        mHeadsUpWrapper = headsUpWrapper;
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        try {
            super.dispatchDraw(canvas);
        } catch (Exception e) {
            // Catch draw exceptions that may be caused by RemoteViews
            Log.e(TAG, "Drawing view failed: " + e);
            cancelNotification(e);
        }
    }

    private void cancelNotification(Exception exception) {
        try {
            setVisibility(GONE);
            final StatusBarNotification sbn = mNotificationEntry.getSbn();
            if (mStatusBarService != null) {
                // report notification inflation errors back up
                // to notification delegates
                mStatusBarService.onNotificationError(
                        sbn.getPackageName(),
                        sbn.getTag(),
                        sbn.getId(),
                        sbn.getUid(),
                        sbn.getInitialPid(),
                        exception.getMessage(),
                        sbn.getUser().getIdentifier());
            }
        } catch (RemoteException ex) {
            Log.e(TAG, "cancelNotification failed: " + ex);
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -281,7 +281,8 @@ public class NotificationEntryManagerInflationTest extends SysuiTestCase {
                                mock(FeatureFlags.class),
                                mPeopleNotificationIdentifier,
                                Optional.of(mock(BubblesManager.class)),
                                mock(ExpandableNotificationRowDragController.class)));
                                mock(ExpandableNotificationRowDragController.class),
                                mock(IStatusBarService.class)));

        when(mNotificationRowComponentBuilder.activatableNotificationView(any()))
                .thenReturn(mNotificationRowComponentBuilder);
Loading