diff options
| author | 2024-09-30 10:35:56 +0000 | |
|---|---|---|
| committer | 2024-09-30 10:35:56 +0000 | |
| commit | 5ade2514bb9a03158e11e5cd2f39ff006885c68b (patch) | |
| tree | f07fd4c32612e997754379a89ad8ead5f95283a9 | |
| parent | df183795a9fd9b1d97b763ee3ddfae8157c2327c (diff) | |
| parent | 091882d75e206e97b9277541a85c28f0c1565dc6 (diff) | |
Merge "Verify that params passed to NotifActivityStarter are not null" into main
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java | 9 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/util/kotlin/Nullability.kt (renamed from packages/SystemUI/src/com/android/systemui/util/kotlin/nullability.kt) | 12 |
2 files changed, 21 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java index ee961955df39..93db2db918b0 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarNotificationActivityStarter.java @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/util/kotlin/nullability.kt b/packages/SystemUI/src/com/android/systemui/util/kotlin/Nullability.kt index 298dacde8128..1c760bedff58 100644 --- a/packages/SystemUI/src/com/android/systemui/util/kotlin/nullability.kt +++ b/packages/SystemUI/src/com/android/systemui/util/kotlin/Nullability.kt @@ -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.") + } +} |