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

Commit 091882d7 authored by Ioana Alexandru's avatar Ioana Alexandru
Browse files

Verify that params passed to NotifActivityStarter are not null

Bug: 369599778
Test: builds, existing tests pass
Flag: EXEMPT logging only (but could crash development)
Change-Id: I1bd051d114a955f11e26cf70a80c4c3b96378024
parent da44fb35
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static android.app.ActivityOptions.MODE_BACKGROUND_ACTIVITY_START_ALLOWED
import static android.service.notification.NotificationListenerService.REASON_CLICK;

import static com.android.systemui.statusbar.phone.CentralSurfaces.getActivityOptions;
import static com.android.systemui.util.kotlin.NullabilityKt.expectNotNull;

import android.app.ActivityManager;
import android.app.ActivityOptions;
@@ -112,6 +113,8 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
                boolean showOverTheLockScreen);
    }

    private final static String TAG = "StatusBarNotificationActivityStarter";

    private final Context mContext;
    private final int mDisplayId;

@@ -229,6 +232,7 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
     */
    @Override
    public void onNotificationBubbleIconClicked(NotificationEntry entry) {
        expectNotNull(TAG, "entry", entry);
        Runnable action = () -> {
            mBubblesManagerOptional.ifPresent(bubblesManager ->
                    bubblesManager.onUserChangedBubble(entry, !entry.isBubble()));
@@ -255,6 +259,8 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
     */
    @Override
    public void onNotificationClicked(NotificationEntry entry, ExpandableNotificationRow row) {
        expectNotNull(TAG, "entry", entry);
        expectNotNull(TAG, "row", row);
        mLogger.logStartingActivityFromClick(entry, row.isHeadsUpState(),
                mKeyguardStateController.isVisible(),
                mNotificationShadeWindowController.getPanelExpanded());
@@ -437,6 +443,7 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
     */
    @Override
    public void onDragSuccess(NotificationEntry entry) {
        expectNotNull(TAG, "entry", entry);
        // this method is not responsible for intent sending.
        // will focus follow operation only after drag-and-drop that notification.
        final NotificationVisibility nv = mVisibilityProvider.obtain(entry, true);
@@ -529,6 +536,8 @@ public class StatusBarNotificationActivityStarter implements NotificationActivit
    @Override
    public void startNotificationGutsIntent(final Intent intent, final int appUid,
            ExpandableNotificationRow row) {
        expectNotNull(TAG, "intent", intent);
        expectNotNull(TAG, "row", row);
        boolean animate = mActivityStarter.shouldAnimateLaunch(true /* isActivityIntent */);
        ActivityStarter.OnDismissAction onDismissAction = new ActivityStarter.OnDismissAction() {
            @Override
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.util.kotlin

import android.util.Log
import java.util.Optional

/**
@@ -28,3 +29,14 @@ inline fun <T : Any, R> transform(value: T?, block: (T) -> R): R? = value?.let(b
 */
@Suppress("NOTHING_TO_INLINE")
inline fun <T> Optional<T>.getOrNull(): T? = orElse(null)

/**
 * Utility method to check if a value that is technically nullable is actually null. If it is null,
 * this will crash development builds (but just log on production/droidfood builds). It can be used
 * as a first step to verify if a nullable value can be made non-nullable instead.
 */
fun <T> expectNotNull(logTag: String, name: String, nullable: T?) {
    if (nullable == null) {
        Log.wtf(logTag, "Expected value of $name to not be null.")
    }
}