diff options
89 files changed, 302 insertions, 291 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/ManageEducationView.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/ManageEducationView.kt index e95e8e5cdaea..1b41f793311d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/ManageEducationView.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/ManageEducationView.kt @@ -41,9 +41,9 @@ class ManageEducationView constructor(context: Context, positioner: BubblePositi private val ANIMATE_DURATION: Long = 200 private val positioner: BubblePositioner = positioner - private val manageView by lazy { findViewById<ViewGroup>(R.id.manage_education_view) } - private val manageButton by lazy { findViewById<Button>(R.id.manage_button) } - private val gotItButton by lazy { findViewById<Button>(R.id.got_it) } + private val manageView by lazy { requireViewById<ViewGroup>(R.id.manage_education_view) } + private val manageButton by lazy { requireViewById<Button>(R.id.manage_button) } + private val gotItButton by lazy { requireViewById<Button>(R.id.got_it) } private var isHiding = false private var realManageButtonRect = Rect() @@ -122,7 +122,7 @@ class ManageEducationView constructor(context: Context, positioner: BubblePositi manageButton .setOnClickListener { hide() - expandedView.findViewById<View>(R.id.manage_button).performClick() + expandedView.requireViewById<View>(R.id.manage_button).performClick() } gotItButton.setOnClickListener { hide() } setOnClickListener { hide() } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/StackEducationView.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/StackEducationView.kt index d0598cd28582..5e3a077a3716 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/StackEducationView.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/StackEducationView.kt @@ -48,9 +48,9 @@ class StackEducationView constructor( private val positioner: BubblePositioner = positioner private val controller: BubbleController = controller - private val view by lazy { findViewById<View>(R.id.stack_education_layout) } - private val titleTextView by lazy { findViewById<TextView>(R.id.stack_education_title) } - private val descTextView by lazy { findViewById<TextView>(R.id.stack_education_description) } + private val view by lazy { requireViewById<View>(R.id.stack_education_layout) } + private val titleTextView by lazy { requireViewById<TextView>(R.id.stack_education_title) } + private val descTextView by lazy { requireViewById<TextView>(R.id.stack_education_description) } var isHiding = false private set diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt index 91bb155d9d01..8d1433595223 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/desktopmode/DesktopTasksController.kt @@ -398,17 +398,18 @@ class DesktopTasksController( request: TransitionRequestInfo ): WindowContainerTransaction? { // Check if we should skip handling this transition + val triggerTask = request.triggerTask val shouldHandleRequest = when { // Only handle open or to front transitions request.type != TRANSIT_OPEN && request.type != TRANSIT_TO_FRONT -> false // Only handle when it is a task transition - request.triggerTask == null -> false + triggerTask == null -> false // Only handle standard type tasks - request.triggerTask.activityType != ACTIVITY_TYPE_STANDARD -> false + triggerTask.activityType != ACTIVITY_TYPE_STANDARD -> false // Only handle fullscreen or freeform tasks - request.triggerTask.windowingMode != WINDOWING_MODE_FULLSCREEN && - request.triggerTask.windowingMode != WINDOWING_MODE_FREEFORM -> false + triggerTask.windowingMode != WINDOWING_MODE_FULLSCREEN && + triggerTask.windowingMode != WINDOWING_MODE_FREEFORM -> false // Otherwise process it else -> true } @@ -417,27 +418,30 @@ class DesktopTasksController( return null } - val task: RunningTaskInfo = request.triggerTask - val activeTasks = desktopModeTaskRepository.getActiveTasks(task.displayId) + if (triggerTask == null) { + return null + } + + val activeTasks = desktopModeTaskRepository.getActiveTasks(triggerTask.displayId) // Check if we should switch a fullscreen task to freeform - if (task.windowingMode == WINDOWING_MODE_FULLSCREEN) { + if (triggerTask.windowingMode == WINDOWING_MODE_FULLSCREEN) { // If there are any visible desktop tasks, switch the task to freeform if (activeTasks.any { desktopModeTaskRepository.isVisibleTask(it) }) { KtProtoLog.d( WM_SHELL_DESKTOP_MODE, "DesktopTasksController: switch fullscreen task to freeform on transition" + " taskId=%d", - task.taskId + triggerTask.taskId ) return WindowContainerTransaction().also { wct -> - addMoveToDesktopChanges(wct, task.token) + addMoveToDesktopChanges(wct, triggerTask.token) } } } // CHeck if we should switch a freeform task to fullscreen - if (task.windowingMode == WINDOWING_MODE_FREEFORM) { + if (triggerTask.windowingMode == WINDOWING_MODE_FREEFORM) { // If no visible desktop tasks, switch this task to freeform as the transition came // outside of this controller if (activeTasks.none { desktopModeTaskRepository.isVisibleTask(it) }) { @@ -445,10 +449,10 @@ class DesktopTasksController( WM_SHELL_DESKTOP_MODE, "DesktopTasksController: switch freeform task to fullscreen oon transition" + " taskId=%d", - task.taskId + triggerTask.taskId ) return WindowContainerTransaction().also { wct -> - addMoveToFullscreenChanges(wct, task.token) + addMoveToFullscreenChanges(wct, triggerTask.token) } } } @@ -471,7 +475,7 @@ class DesktopTasksController( token: WindowContainerToken ) { wct.setWindowingMode(token, WINDOWING_MODE_FULLSCREEN) - wct.setBounds(token, null) + wct.setBounds(token, Rect()) if (isDesktopDensityOverrideSet()) { wct.setDensityDpi(token, getFullscreenDensityDpi()) } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeAppControlsWindowDecorationViewHolder.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeAppControlsWindowDecorationViewHolder.kt index b67acd5c15bb..1aacb4dd739c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeAppControlsWindowDecorationViewHolder.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeAppControlsWindowDecorationViewHolder.kt @@ -23,13 +23,13 @@ internal class DesktopModeAppControlsWindowDecorationViewHolder( appIcon: Drawable ) : DesktopModeWindowDecorationViewHolder(rootView) { - private val captionView: View = rootView.findViewById(R.id.desktop_mode_caption) - private val captionHandle: View = rootView.findViewById(R.id.caption_handle) - private val openMenuButton: View = rootView.findViewById(R.id.open_menu_button) - private val closeWindowButton: ImageButton = rootView.findViewById(R.id.close_window) - private val expandMenuButton: ImageButton = rootView.findViewById(R.id.expand_menu_button) - private val appNameTextView: TextView = rootView.findViewById(R.id.application_name) - private val appIconImageView: ImageView = rootView.findViewById(R.id.application_icon) + private val captionView: View = rootView.requireViewById(R.id.desktop_mode_caption) + private val captionHandle: View = rootView.requireViewById(R.id.caption_handle) + private val openMenuButton: View = rootView.requireViewById(R.id.open_menu_button) + private val closeWindowButton: ImageButton = rootView.requireViewById(R.id.close_window) + private val expandMenuButton: ImageButton = rootView.requireViewById(R.id.expand_menu_button) + private val appNameTextView: TextView = rootView.requireViewById(R.id.application_name) + private val appIconImageView: ImageView = rootView.requireViewById(R.id.application_icon) init { captionView.setOnTouchListener(onCaptionTouchListener) @@ -45,7 +45,9 @@ internal class DesktopModeAppControlsWindowDecorationViewHolder( override fun bindData(taskInfo: RunningTaskInfo) { val captionDrawable = captionView.background as GradientDrawable - captionDrawable.setColor(taskInfo.taskDescription.statusBarColor) + taskInfo.taskDescription?.statusBarColor?.let { + captionDrawable.setColor(it) + } closeWindowButton.imageTintList = ColorStateList.valueOf( getCaptionCloseButtonColor(taskInfo)) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeFocusedWindowDecorationViewHolder.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeFocusedWindowDecorationViewHolder.kt index 47a12a0cb71c..9374ac95e83d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeFocusedWindowDecorationViewHolder.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeFocusedWindowDecorationViewHolder.kt @@ -17,8 +17,8 @@ internal class DesktopModeFocusedWindowDecorationViewHolder( onCaptionButtonClickListener: View.OnClickListener ) : DesktopModeWindowDecorationViewHolder(rootView) { - private val captionView: View = rootView.findViewById(R.id.desktop_mode_caption) - private val captionHandle: ImageButton = rootView.findViewById(R.id.caption_handle) + private val captionView: View = rootView.requireViewById(R.id.desktop_mode_caption) + private val captionHandle: ImageButton = rootView.requireViewById(R.id.caption_handle) init { captionView.setOnTouchListener(onCaptionTouchListener) @@ -27,9 +27,10 @@ internal class DesktopModeFocusedWindowDecorationViewHolder( } override fun bindData(taskInfo: RunningTaskInfo) { - val captionColor = taskInfo.taskDescription.statusBarColor - val captionDrawable = captionView.background as GradientDrawable - captionDrawable.setColor(captionColor) + taskInfo.taskDescription?.statusBarColor?.let { captionColor -> + val captionDrawable = captionView.background as GradientDrawable + captionDrawable.setColor(captionColor) + } captionHandle.imageTintList = ColorStateList.valueOf(getCaptionHandleBarColor(taskInfo)) } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeWindowDecorationViewHolder.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeWindowDecorationViewHolder.kt index 514ea52cb8ae..b4ecbf5f3e32 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeWindowDecorationViewHolder.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/viewholder/DesktopModeWindowDecorationViewHolder.kt @@ -23,6 +23,9 @@ internal abstract class DesktopModeWindowDecorationViewHolder(rootView: View) { * with the caption background color. */ protected fun shouldUseLightCaptionColors(taskInfo: RunningTaskInfo): Boolean { - return Color.valueOf(taskInfo.taskDescription.statusBarColor).luminance() < 0.5 + return taskInfo.taskDescription + ?.let { taskDescription -> + Color.valueOf(taskDescription.statusBarColor).luminance() < 0.5 + } ?: false } } diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt index 48dd08f206c1..a2c76839fea7 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/DialogLaunchAnimator.kt @@ -249,7 +249,7 @@ constructor( // intent is to launch a dialog from another dialog. val animatedParent = openedDialogs.firstOrNull { - it.dialog.window.decorView.viewRootImpl == controller.viewRoot + it.dialog.window?.decorView?.viewRootImpl == controller.viewRoot } val controller = animatedParent?.dialogContentWithBackground?.let { @@ -336,7 +336,7 @@ constructor( ): ActivityLaunchAnimator.Controller? { val animatedDialog = openedDialogs.firstOrNull { - it.dialog.window.decorView.viewRootImpl == view.viewRootImpl + it.dialog.window?.decorView?.viewRootImpl == view.viewRootImpl } ?: return null return createActivityLaunchController(animatedDialog, cujType) @@ -417,7 +417,7 @@ constructor( animatedDialog.prepareForStackDismiss() // Remove the dim. - dialog.window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) + dialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) } override fun onLaunchAnimationEnd(isExpandingFullyAbove: Boolean) { @@ -867,7 +867,7 @@ private class AnimatedDialog( } // Show the background dim. - dialog.window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) + dialog.window?.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) startAnimation( isLaunching = true, @@ -947,7 +947,7 @@ private class AnimatedDialog( isLaunching = false, onLaunchAnimationStart = { // Remove the dim background as soon as we start the animation. - dialog.window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) + dialog.window?.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND) }, onLaunchAnimationEnd = { val dialogContentWithBackground = this.dialogContentWithBackground!! diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt index 1a03ede98d12..6c4b695ed709 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/GhostedViewLaunchAnimatorController.kt @@ -206,8 +206,9 @@ constructor( return } - backgroundView = FrameLayout(launchContainer.context) - launchContainerOverlay.add(backgroundView) + backgroundView = FrameLayout(launchContainer.context).also { + launchContainerOverlay.add(it) + } // We wrap the ghosted view background and use it to draw the expandable background. Its // alpha will be set to 0 as soon as we start drawing the expanding background. @@ -319,7 +320,7 @@ constructor( backgroundDrawable?.wrapped?.alpha = startBackgroundAlpha GhostView.removeGhost(ghostedView) - launchContainerOverlay.remove(backgroundView) + backgroundView?.let { launchContainerOverlay.remove(it) } if (ghostedView is LaunchableView) { // Restore the ghosted view visibility. diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/LaunchAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/LaunchAnimator.kt index 142fd21d4a16..d6eba2e7064d 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/LaunchAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/LaunchAnimator.kt @@ -283,7 +283,7 @@ class LaunchAnimator(private val timings: Timings, private val interpolators: In animator.addListener( object : AnimatorListenerAdapter() { - override fun onAnimationStart(animation: Animator?, isReverse: Boolean) { + override fun onAnimationStart(animation: Animator, isReverse: Boolean) { if (DEBUG) { Log.d(TAG, "Animation started") } @@ -295,7 +295,7 @@ class LaunchAnimator(private val timings: Timings, private val interpolators: In launchContainerOverlay.add(windowBackgroundLayer) } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { if (DEBUG) { Log.d(TAG, "Animation ended") } diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt index b555fa583588..8dc74951d332 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/TextAnimator.kt @@ -42,7 +42,9 @@ interface TypefaceVariantCache { return baseTypeface } - val axes = FontVariationAxis.fromFontVariationSettings(fVar).toMutableList() + val axes = FontVariationAxis.fromFontVariationSettings(fVar) + ?.toMutableList() + ?: mutableListOf() axes.removeIf { !baseTypeface.isSupportedAxes(it.getOpenTypeTagValue()) } if (axes.isEmpty()) { return baseTypeface @@ -120,8 +122,8 @@ class TextAnimator( } addListener( object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) = textInterpolator.rebase() - override fun onAnimationCancel(animation: Animator?) = textInterpolator.rebase() + override fun onAnimationEnd(animation: Animator) = textInterpolator.rebase() + override fun onAnimationCancel(animation: Animator) = textInterpolator.rebase() } ) } @@ -302,11 +304,11 @@ class TextAnimator( if (onAnimationEnd != null) { val listener = object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { onAnimationEnd.run() animator.removeListener(this) } - override fun onAnimationCancel(animation: Animator?) { + override fun onAnimationCancel(animation: Animator) { animator.removeListener(this) } } diff --git a/packages/SystemUI/animation/src/com/android/systemui/animation/ViewHierarchyAnimator.kt b/packages/SystemUI/animation/src/com/android/systemui/animation/ViewHierarchyAnimator.kt index 8e79e3ce1742..68d745621c87 100644 --- a/packages/SystemUI/animation/src/com/android/systemui/animation/ViewHierarchyAnimator.kt +++ b/packages/SystemUI/animation/src/com/android/systemui/animation/ViewHierarchyAnimator.kt @@ -1020,7 +1020,7 @@ class ViewHierarchyAnimator { } } - override fun onAnimationCancel(animation: Animator?) { + override fun onAnimationCancel(animation: Animator) { cancelled = true } } diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/WeatherData.kt b/packages/SystemUI/plugin/src/com/android/systemui/plugins/WeatherData.kt index a4b1ceeebfa3..c1cc3bd3c563 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/WeatherData.kt +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/WeatherData.kt @@ -52,7 +52,7 @@ constructor( private fun readIntFromBundle(extras: Bundle, key: String): Int? = try { - extras.getString(key).toInt() + extras.getString(key)?.toInt() } catch (e: Exception) { null } diff --git a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt index 070a45170d04..bca9c31052b9 100644 --- a/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt +++ b/packages/SystemUI/screenshot/src/com/android/systemui/testing/screenshot/ViewScreenshotTestRule.kt @@ -145,6 +145,7 @@ open class ViewScreenshotTestRule( activityRule.scenario.onActivity { activity -> dialog = dialogProvider(activity).apply { + val window = checkNotNull(window) // Make sure that the dialog draws full screen and fits the whole display // instead of the system bars. window.setDecorFitsSystemWindows(false) @@ -175,7 +176,7 @@ open class ViewScreenshotTestRule( } private fun Dialog.toBitmap(): Bitmap { - val window = window + val window = checkNotNull(window) return window.decorView.toBitmap(window) } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerKt.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerKt.kt index c1429335292f..5edd283bf131 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerKt.kt +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/ActivityManagerKt.kt @@ -27,6 +27,6 @@ object ActivityManagerKt { */ fun ActivityManager.isInForeground(packageName: String): Boolean { val tasks: List<ActivityManager.RunningTaskInfo> = getRunningTasks(1) - return tasks.isNotEmpty() && packageName == tasks[0].topActivity.packageName + return tasks.isNotEmpty() && packageName == tasks[0].topActivity?.packageName } } diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/system/smartspace/SmartspaceState.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/system/smartspace/SmartspaceState.kt index d7e61d60aa55..ebc57d2f8af7 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/system/smartspace/SmartspaceState.kt +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/system/smartspace/SmartspaceState.kt @@ -31,15 +31,15 @@ class SmartspaceState() : Parcelable { var visibleOnScreen = false constructor(parcel: Parcel) : this() { - this.boundsOnScreen = parcel.readParcelable(Rect::javaClass.javaClass.classLoader) + this.boundsOnScreen = parcel.readParcelable(Rect::javaClass.javaClass.classLoader) ?: Rect() this.selectedPage = parcel.readInt() this.visibleOnScreen = parcel.readBoolean() } - override fun writeToParcel(dest: Parcel?, flags: Int) { - dest?.writeParcelable(boundsOnScreen, 0) - dest?.writeInt(selectedPage) - dest?.writeBoolean(visibleOnScreen) + override fun writeToParcel(dest: Parcel, flags: Int) { + dest.writeParcelable(boundsOnScreen, 0) + dest.writeInt(selectedPage) + dest.writeBoolean(visibleOnScreen) } override fun describeContents(): Int { diff --git a/packages/SystemUI/shared/src/com/android/systemui/unfold/util/NaturalRotationUnfoldProgressProvider.kt b/packages/SystemUI/shared/src/com/android/systemui/unfold/util/NaturalRotationUnfoldProgressProvider.kt index aca9907fec1b..dac130d684bd 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/unfold/util/NaturalRotationUnfoldProgressProvider.kt +++ b/packages/SystemUI/shared/src/com/android/systemui/unfold/util/NaturalRotationUnfoldProgressProvider.kt @@ -39,7 +39,7 @@ class NaturalRotationUnfoldProgressProvider( fun init() { rotationChangeProvider.addCallback(rotationListener) - rotationListener.onRotationChanged(context.display.rotation) + context.display?.rotation?.let { rotationListener.onRotationChanged(it) } } private val rotationListener = RotationListener { rotation -> diff --git a/packages/SystemUI/src/com/android/keyguard/BouncerKeyguardMessageArea.kt b/packages/SystemUI/src/com/android/keyguard/BouncerKeyguardMessageArea.kt index 084295343bb0..734df940fd37 100644 --- a/packages/SystemUI/src/com/android/keyguard/BouncerKeyguardMessageArea.kt +++ b/packages/SystemUI/src/com/android/keyguard/BouncerKeyguardMessageArea.kt @@ -105,7 +105,7 @@ open class BouncerKeyguardMessageArea(context: Context?, attrs: AttributeSet?) : hideAnimator.addListener( object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { super@BouncerKeyguardMessageArea.setMessage(msg, animate) } } @@ -118,7 +118,7 @@ open class BouncerKeyguardMessageArea(context: Context?, attrs: AttributeSet?) : showAnimator.addListener( object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { textAboutToShow = null } } diff --git a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt index 8ea4c31a5ac9..0b41c8b39609 100644 --- a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt +++ b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt @@ -110,20 +110,20 @@ constructor( } value.smallClock.view.addOnAttachStateChangeListener( object : OnAttachStateChangeListener { - override fun onViewAttachedToWindow(p0: View?) { + override fun onViewAttachedToWindow(p0: View) { value.events.onTimeFormatChanged(DateFormat.is24HourFormat(context)) } - override fun onViewDetachedFromWindow(p0: View?) { + override fun onViewDetachedFromWindow(p0: View) { } }) value.largeClock.view.addOnAttachStateChangeListener( object : OnAttachStateChangeListener { - override fun onViewAttachedToWindow(p0: View?) { + override fun onViewAttachedToWindow(p0: View) { value.events.onTimeFormatChanged(DateFormat.is24HourFormat(context)) } - override fun onViewDetachedFromWindow(p0: View?) { + override fun onViewDetachedFromWindow(p0: View) { } }) } diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java index 6854c97c3415..ad0d52755424 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusViewController.java @@ -23,6 +23,7 @@ import static com.android.internal.jank.InteractionJankMonitor.CUJ_LOCKSCREEN_CL import android.animation.Animator; import android.animation.ValueAnimator; +import android.annotation.NonNull; import android.annotation.Nullable; import android.content.res.Configuration; import android.graphics.Rect; diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleController.kt index 6f0f6331ef50..66689250e95f 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleController.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleController.kt @@ -230,7 +230,7 @@ class AuthRippleController @Inject constructor( lightRevealScrim.revealAmount = animator.animatedValue as Float } addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { // Reset light reveal scrim to the default, so the CentralSurfaces // can handle any subsequent light reveal changes // (ie: from dozing changes) diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleView.kt b/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleView.kt index 5ede16d221b7..4c2dc41fb759 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleView.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthRippleView.kt @@ -147,12 +147,12 @@ class AuthRippleView(context: Context?, attrs: AttributeSet?) : View(context, at retractDwellAnimator = AnimatorSet().apply { playTogether(retractDwellRippleAnimator, retractAlphaAnimator) addListener(object : AnimatorListenerAdapter() { - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { dwellPulseOutAnimator?.cancel() drawDwell = true } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { drawDwell = false resetDwellAlpha() } @@ -182,13 +182,13 @@ class AuthRippleView(context: Context?, attrs: AttributeSet?) : View(context, at invalidate() } addListener(object : AnimatorListenerAdapter() { - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { retractDwellAnimator?.cancel() dwellPulseOutAnimator?.cancel() drawDwell = true } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { drawDwell = false resetDwellAlpha() } @@ -239,14 +239,14 @@ class AuthRippleView(context: Context?, attrs: AttributeSet?) : View(context, at expandDwellRippleAnimator ) addListener(object : AnimatorListenerAdapter() { - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { retractDwellAnimator?.cancel() fadeDwellAnimator?.cancel() visibility = VISIBLE drawDwell = true } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { drawDwell = false } }) @@ -273,12 +273,12 @@ class AuthRippleView(context: Context?, attrs: AttributeSet?) : View(context, at unlockedRippleAnimator = rippleAnimator.apply { addListener(object : AnimatorListenerAdapter() { - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { drawRipple = true visibility = VISIBLE } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { onAnimationEnd?.run() drawRipple = false visibility = GONE @@ -327,7 +327,7 @@ class AuthRippleView(context: Context?, attrs: AttributeSet?) : View(context, at } } - override fun onDraw(canvas: Canvas?) { + override fun onDraw(canvas: Canvas) { // To reduce overdraw, we mask the effect to a circle whose radius is big enough to cover // the active effect area. Values here should be kept in sync with the // animation implementation in the ripple shader. (Twice bigger) diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt index 54aef00a5a8c..9e8370e3fbf5 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt @@ -117,7 +117,7 @@ constructor( private var overlayView: View? = null set(value) { field?.let { oldView -> - val lottie = oldView.findViewById(R.id.sidefps_animation) as LottieAnimationView + val lottie = oldView.requireViewById(R.id.sidefps_animation) as LottieAnimationView lottie.pauseAnimation() windowManager.removeView(oldView) orientationListener.disable() @@ -262,7 +262,7 @@ constructor( } overlayOffsets = offsets - val lottie = view.findViewById(R.id.sidefps_animation) as LottieAnimationView + val lottie = view.requireViewById(R.id.sidefps_animation) as LottieAnimationView view.rotation = display.asSideFpsAnimationRotation( offsets.isYAligned(), diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsFpmEmptyView.kt b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsFpmEmptyView.kt index 8352d0aeab35..5dafa61f9a27 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsFpmEmptyView.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/UdfpsFpmEmptyView.kt @@ -38,7 +38,8 @@ class UdfpsFpmEmptyView( override fun getDrawable(): UdfpsDrawable = fingerprintDrawable fun updateAccessibilityViewLocation(sensorBounds: Rect) { - val fingerprintAccessibilityView: View = findViewById(R.id.udfps_enroll_accessibility_view) + val fingerprintAccessibilityView: View = + requireViewById(R.id.udfps_enroll_accessibility_view) val params: ViewGroup.LayoutParams = fingerprintAccessibilityView.layoutParams params.width = sensorBounds.width() params.height = sensorBounds.height() diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/CredentialInteractor.kt b/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/CredentialInteractor.kt index 1f1a1b5c83bd..2a026675adcb 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/CredentialInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/domain/interactor/CredentialInteractor.kt @@ -89,7 +89,7 @@ constructor( ) val hat = gkResponse.gatekeeperHAT lockPatternUtils.removeGatekeeperPasswordHandle(pwHandle) - emit(CredentialStatus.Success.Verified(hat)) + emit(CredentialStatus.Success.Verified(checkNotNull(hat))) } else if (response.timeout > 0) { // if requests are being throttled, update the error message every // second until the temporary lock has expired @@ -226,8 +226,7 @@ private fun Context.getLastAttemptBeforeWipeProfileMessage( is BiometricPromptRequest.Credential.Password -> DevicePolicyResources.Strings.SystemUi.BIOMETRIC_DIALOG_WORK_PASSWORD_LAST_ATTEMPT } - return devicePolicyManager.resources.getString(id) { - // use fallback a string if not found + val getFallbackString = { val defaultId = when (request) { is BiometricPromptRequest.Credential.Pin -> @@ -239,6 +238,8 @@ private fun Context.getLastAttemptBeforeWipeProfileMessage( } getString(defaultId) } + + return devicePolicyManager.resources?.getString(id, getFallbackString) ?: getFallbackString() } private fun Context.getLastAttemptBeforeWipeUserMessage( @@ -266,8 +267,8 @@ private fun Context.getNowWipingMessage( DevicePolicyResources.Strings.SystemUi.BIOMETRIC_DIALOG_WORK_LOCK_FAILED_ATTEMPTS else -> DevicePolicyResources.UNDEFINED } - return devicePolicyManager.resources.getString(id) { - // use fallback a string if not found + + val getFallbackString = { val defaultId = when (userType) { UserType.PRIMARY -> @@ -279,4 +280,6 @@ private fun Context.getNowWipingMessage( } getString(defaultId) } + + return devicePolicyManager.resources?.getString(id, getFallbackString) ?: getFallbackString() } diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/ui/CredentialPasswordView.kt b/packages/SystemUI/src/com/android/systemui/biometrics/ui/CredentialPasswordView.kt index a3f34ce7471d..b940ec85efbf 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/ui/CredentialPasswordView.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/ui/CredentialPasswordView.kt @@ -122,7 +122,7 @@ class CredentialPasswordView(context: Context, attrs: AttributeSet?) : titleView.ellipsize = TextUtils.TruncateAt.MARQUEE titleView.marqueeRepeatLimit = -1 // select to enable marquee unless a screen reader is enabled - titleView.isSelected = accessibilityManager.shouldMarquee() + titleView.isSelected = accessibilityManager?.shouldMarquee() ?: false } else { titleView.isSingleLine = false titleView.ellipsize = null diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt b/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt index 8486c3f96b21..a881c07021fc 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewBinder.kt @@ -88,27 +88,27 @@ object BiometricViewBinder { val textColorHint = view.resources.getColor(R.color.biometric_dialog_gray, view.context.theme) - val titleView = view.findViewById<TextView>(R.id.title) - val subtitleView = view.findViewById<TextView>(R.id.subtitle) - val descriptionView = view.findViewById<TextView>(R.id.description) + val titleView = view.requireViewById<TextView>(R.id.title) + val subtitleView = view.requireViewById<TextView>(R.id.subtitle) + val descriptionView = view.requireViewById<TextView>(R.id.description) // set selected for marquee titleView.isSelected = true subtitleView.isSelected = true descriptionView.movementMethod = ScrollingMovementMethod() - val iconViewOverlay = view.findViewById<LottieAnimationView>(R.id.biometric_icon_overlay) - val iconView = view.findViewById<LottieAnimationView>(R.id.biometric_icon) - val indicatorMessageView = view.findViewById<TextView>(R.id.indicator) + val iconViewOverlay = view.requireViewById<LottieAnimationView>(R.id.biometric_icon_overlay) + val iconView = view.requireViewById<LottieAnimationView>(R.id.biometric_icon) + val indicatorMessageView = view.requireViewById<TextView>(R.id.indicator) // Negative-side (left) buttons - val negativeButton = view.findViewById<Button>(R.id.button_negative) - val cancelButton = view.findViewById<Button>(R.id.button_cancel) - val credentialFallbackButton = view.findViewById<Button>(R.id.button_use_credential) + val negativeButton = view.requireViewById<Button>(R.id.button_negative) + val cancelButton = view.requireViewById<Button>(R.id.button_cancel) + val credentialFallbackButton = view.requireViewById<Button>(R.id.button_use_credential) // Positive-side (right) buttons - val confirmationButton = view.findViewById<Button>(R.id.button_confirm) - val retryButton = view.findViewById<Button>(R.id.button_try_again) + val confirmationButton = view.requireViewById<Button>(R.id.button_confirm) + val retryButton = view.requireViewById<Button>(R.id.button_try_again) // TODO(b/251476085): temporary workaround for the unsafe callbacks & legacy controllers val adapter = diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewSizeBinder.kt b/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewSizeBinder.kt index 1dffa80a084f..2b06f3aa4df3 100644 --- a/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewSizeBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/biometrics/ui/binder/BiometricViewSizeBinder.kt @@ -71,7 +71,7 @@ object BiometricViewSizeBinder { } } - val iconHolderView = view.findViewById<View>(R.id.biometric_icon_frame) + val iconHolderView = view.requireViewById<View>(R.id.biometric_icon_frame) val iconPadding = view.resources.getDimension(R.dimen.biometric_dialog_icon_padding) val fullSizeYOffset = view.resources.getDimension(R.dimen.biometric_dialog_medium_to_large_translation_offset) @@ -198,7 +198,7 @@ object BiometricViewSizeBinder { } private fun View.isLandscape(): Boolean { - val r = context.display.rotation + val r = context.display?.rotation return r == Surface.ROTATION_90 || r == Surface.ROTATION_270 } diff --git a/packages/SystemUI/src/com/android/systemui/charging/WiredChargingRippleController.kt b/packages/SystemUI/src/com/android/systemui/charging/WiredChargingRippleController.kt index 5ca36ab39dba..ddb097491988 100644 --- a/packages/SystemUI/src/com/android/systemui/charging/WiredChargingRippleController.kt +++ b/packages/SystemUI/src/com/android/systemui/charging/WiredChargingRippleController.kt @@ -156,9 +156,9 @@ class WiredChargingRippleController @Inject constructor( } windowLayoutParams.packageName = context.opPackageName rippleView.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener { - override fun onViewDetachedFromWindow(view: View?) {} + override fun onViewDetachedFromWindow(view: View) {} - override fun onViewAttachedToWindow(view: View?) { + override fun onViewAttachedToWindow(view: View) { layoutRipple() rippleView.startRipple(Runnable { windowManager.removeView(rippleView) @@ -176,7 +176,7 @@ class WiredChargingRippleController @Inject constructor( val height = bounds.height() val maxDiameter = Integer.max(width, height) * 2f rippleView.setMaxSize(maxDiameter, maxDiameter) - when (context.display.rotation) { + when (context.display?.rotation) { Surface.ROTATION_0 -> { rippleView.setCenter( width * normalizedPortPosX, height * normalizedPortPosY) diff --git a/packages/SystemUI/src/com/android/systemui/classifier/FalsingA11yDelegate.kt b/packages/SystemUI/src/com/android/systemui/classifier/FalsingA11yDelegate.kt index 63d57cc3fc8d..a9f3b77ceb5e 100644 --- a/packages/SystemUI/src/com/android/systemui/classifier/FalsingA11yDelegate.kt +++ b/packages/SystemUI/src/com/android/systemui/classifier/FalsingA11yDelegate.kt @@ -29,7 +29,7 @@ import javax.inject.Inject */ class FalsingA11yDelegate @Inject constructor(private val falsingCollector: FalsingCollector) : View.AccessibilityDelegate() { - override fun performAccessibilityAction(host: View?, action: Int, args: Bundle?): Boolean { + override fun performAccessibilityAction(host: View, action: Int, args: Bundle?): Boolean { if (action == ACTION_CLICK) { falsingCollector.onA11yAction() } diff --git a/packages/SystemUI/src/com/android/systemui/common/ui/data/repository/ConfigurationRepository.kt b/packages/SystemUI/src/com/android/systemui/common/ui/data/repository/ConfigurationRepository.kt index 3e6ac86e2417..c0d1951c22ce 100644 --- a/packages/SystemUI/src/com/android/systemui/common/ui/data/repository/ConfigurationRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/common/ui/data/repository/ConfigurationRepository.kt @@ -100,7 +100,7 @@ constructor( .stateIn(scope, SharingStarted.WhileSubscribed(), getResolutionScale()) override fun getResolutionScale(): Float { - context.display.getDisplayInfo(displayInfo.value) + context.display?.getDisplayInfo(displayInfo.value) val maxDisplayMode = displayUtils.getMaximumResolutionDisplayMode(displayInfo.value.supportedModes) maxDisplayMode?.let { diff --git a/packages/SystemUI/src/com/android/systemui/contrast/ContrastDialog.kt b/packages/SystemUI/src/com/android/systemui/contrast/ContrastDialog.kt index f17d0f307473..0b327a19ef81 100644 --- a/packages/SystemUI/src/com/android/systemui/contrast/ContrastDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/contrast/ContrastDialog.kt @@ -66,9 +66,9 @@ class ContrastDialog( contrastButtons = mapOf( - CONTRAST_LEVEL_STANDARD to findViewById(R.id.contrast_button_standard), - CONTRAST_LEVEL_MEDIUM to findViewById(R.id.contrast_button_medium), - CONTRAST_LEVEL_HIGH to findViewById(R.id.contrast_button_high) + CONTRAST_LEVEL_STANDARD to requireViewById(R.id.contrast_button_standard), + CONTRAST_LEVEL_MEDIUM to requireViewById(R.id.contrast_button_medium), + CONTRAST_LEVEL_HIGH to requireViewById(R.id.contrast_button_high) ) contrastButtons.forEach { (contrastLevel, contrastButton) -> diff --git a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt index e8c97bf77271..4a534e9cc74d 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/controller/ControlsControllerImpl.kt @@ -190,7 +190,7 @@ class ControlsControllerImpl @Inject constructor ( PREFS_CONTROLS_SEEDING_COMPLETED, mutableSetOf<String>()) val servicePackageSet = serviceInfoSet.map { it.packageName } prefs.edit().putStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, - completedSeedingPackageSet.intersect(servicePackageSet)).apply() + completedSeedingPackageSet?.intersect(servicePackageSet) ?: emptySet()).apply() var changed = false favoriteComponentSet.subtract(serviceInfoSet).forEach { diff --git a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt index 59fa7f53fc17..da571b3af086 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/management/ControlsFavoritingActivity.kt @@ -216,7 +216,7 @@ open class ControlsFavoritingActivity @Inject constructor( ControlsAnimations.enterAnimation(pageIndicator).apply { addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { // Position the tooltip if necessary after animations are complete // so we can get the position on screen. The tooltip is not // rooted in the layout root. diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ChallengeDialogs.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ChallengeDialogs.kt index ff55b76d4db7..a13f717bc77d 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ChallengeDialogs.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ChallengeDialogs.kt @@ -106,10 +106,8 @@ object ChallengeDialogs { } ) - getWindow().apply { - setType(WINDOW_TYPE) - setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) - } + window?.setType(WINDOW_TYPE) + window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) setOnShowListener(DialogInterface.OnShowListener { _ -> val editText = requireViewById<EditText>(R.id.controls_pin_input) editText.setHint(instructions) @@ -153,9 +151,7 @@ object ChallengeDialogs { ) } return builder.create().apply { - getWindow().apply { - setType(WINDOW_TYPE) - } + window?.setType(WINDOW_TYPE) } } diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt index c04bc8792223..abe342320858 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ControlViewHolder.kt @@ -384,7 +384,7 @@ class ControlViewHolder( ) } addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { stateAnimator = null } }) @@ -438,7 +438,7 @@ class ControlViewHolder( duration = 200L interpolator = Interpolators.LINEAR addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { statusRowUpdater.invoke() } }) @@ -450,7 +450,7 @@ class ControlViewHolder( statusAnimator = AnimatorSet().apply { playSequentially(fadeOut, fadeIn) addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { status.alpha = STATUS_ALPHA_ENABLED statusAnimator = null } diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/DetailDialog.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/DetailDialog.kt index be50a1468f07..98f17f409184 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/DetailDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/DetailDialog.kt @@ -132,8 +132,8 @@ class DetailDialog( init { // To pass touches to the task inside TaskView. - window.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL) - window.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY) + window?.addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL) + window?.addPrivateFlags(WindowManager.LayoutParams.PRIVATE_FLAG_TRUSTED_OVERLAY) setContentView(R.layout.controls_detail_dialog) @@ -182,7 +182,7 @@ class DetailDialog( } // consume all insets to achieve slide under effect - window.getDecorView().setOnApplyWindowInsetsListener { + checkNotNull(window).decorView.setOnApplyWindowInsetsListener { v: View, insets: WindowInsets -> val l = v.getPaddingLeft() val r = v.getPaddingRight() @@ -202,7 +202,7 @@ class DetailDialog( } fun getTaskViewBounds(): Rect { - val wm = context.getSystemService(WindowManager::class.java) + val wm = checkNotNull(context.getSystemService(WindowManager::class.java)) val windowMetrics = wm.getCurrentWindowMetrics() val rect = windowMetrics.bounds val metricInsets = windowMetrics.windowInsets diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt index ad2b785ea5c5..dbbda9aad518 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/RenderInfo.kt @@ -67,7 +67,8 @@ data class RenderInfo( iconMap.put(resourceId, icon) } } - return RenderInfo(icon!!.constantState.newDrawable(context.resources), fg, bg) + return RenderInfo( + checkNotNull(icon?.constantState).newDrawable(context.resources), fg, bg) } fun registerComponentIcon(componentName: ComponentName, icon: Drawable) { diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt index 84cda5a541e3..3c2bfa0efc39 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/StatusBehavior.kt @@ -94,10 +94,8 @@ class StatusBehavior : Behavior { ) } cvh.visibleDialog = builder.create().apply { - getWindow().apply { - setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY) - show() - } + window?.setType(WindowManager.LayoutParams.TYPE_VOLUME_OVERLAY) + show() } } } diff --git a/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt b/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt index 1461135d3d3b..b2c95a63ad72 100644 --- a/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt +++ b/packages/SystemUI/src/com/android/systemui/controls/ui/ToggleRangeBehavior.kt @@ -244,7 +244,7 @@ class ToggleRangeBehavior : Behavior { cvh.clipLayer.level = it.animatedValue as Int } addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { rangeAnimator = null } }) @@ -335,7 +335,7 @@ class ToggleRangeBehavior : Behavior { } override fun onScroll( - e1: MotionEvent, + e1: MotionEvent?, e2: MotionEvent, xDiff: Float, yDiff: Float diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/backlight/ui/view/KeyboardBacklightDialog.kt b/packages/SystemUI/src/com/android/systemui/keyboard/backlight/ui/view/KeyboardBacklightDialog.kt index 70783418ddb4..b5b56b2b2108 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/backlight/ui/view/KeyboardBacklightDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/backlight/ui/view/KeyboardBacklightDialog.kt @@ -161,7 +161,7 @@ class KeyboardBacklightDialog( } private fun updateIconTile() { - val iconTile = rootView.findViewById(BACKLIGHT_ICON_ID) as ImageView + val iconTile = rootView.requireViewById(BACKLIGHT_ICON_ID) as ImageView val backgroundDrawable = iconTile.background as ShapeDrawable if (currentLevel == 0) { iconTile.setColorFilter(dimmedIconColor) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt index c019d21e00ed..5d7a3d432dcb 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/quickaffordance/QuickAccessWalletKeyguardQuickAffordanceConfig.kt @@ -59,7 +59,7 @@ constructor( conflatedCallbackFlow { val callback = object : QuickAccessWalletClient.OnWalletCardsRetrievedCallback { - override fun onWalletCardsRetrieved(response: GetWalletCardsResponse?) { + override fun onWalletCardsRetrieved(response: GetWalletCardsResponse) { val hasCards = response?.walletCards?.isNotEmpty() == true trySendWithFailureLogging( state( @@ -71,7 +71,7 @@ constructor( ) } - override fun onWalletCardRetrievalError(error: GetWalletCardsError?) { + override fun onWalletCardRetrievalError(error: GetWalletCardsError) { Log.e(TAG, "Wallet card retrieval error, message: \"${error?.message}\"") trySendWithFailureLogging( KeyguardQuickAffordanceConfig.LockScreenState.Hidden, @@ -133,13 +133,13 @@ constructor( return suspendCancellableCoroutine { continuation -> val callback = object : QuickAccessWalletClient.OnWalletCardsRetrievedCallback { - override fun onWalletCardsRetrieved(response: GetWalletCardsResponse?) { + override fun onWalletCardsRetrieved(response: GetWalletCardsResponse) { continuation.resumeWith( Result.success(response?.walletCards ?: emptyList()) ) } - override fun onWalletCardRetrievalError(error: GetWalletCardsError?) { + override fun onWalletCardRetrievalError(error: GetWalletCardsError) { continuation.resumeWith(Result.success(emptyList())) } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt index 9621f03f63a0..6a58879c58b8 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/DeviceEntryFaceAuthRepository.kt @@ -538,7 +538,7 @@ constructor( // We always want to invoke face detect in the main thread. faceAuthLogger.faceDetectionStarted() faceManager?.detectFace( - detectCancellationSignal, + checkNotNull(detectCancellationSignal), detectionCallback, FaceAuthenticateOptions.Builder().setUserId(currentUserId).build() ) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepository.kt index 482e9a3d09d7..5654faaa6266 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/LightRevealScrimRepository.kt @@ -136,12 +136,13 @@ constructor( private fun constructCircleRevealFromPoint(point: Point): LightRevealEffect { return with(point) { + val display = checkNotNull(context.display) CircleReveal( x, y, startRadius = 0, endRadius = - max(max(x, context.display.width - x), max(y, context.display.height - y)), + max(max(x, display.width - x), max(y, display.height - y)), ) } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBottomAreaViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBottomAreaViewBinder.kt index 5ad6e5196f66..30ca6affcc0c 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBottomAreaViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardBottomAreaViewBinder.kt @@ -488,7 +488,7 @@ object KeyguardBottomAreaViewBinder { return true } - override fun onLongClickUseDefaultHapticFeedback(view: View?) = false + override fun onLongClickUseDefaultHapticFeedback(view: View) = false } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt index b92d10474ccd..ece6ff278507 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt @@ -97,7 +97,7 @@ constructor( private var host: SurfaceControlViewHost val surfacePackage: SurfaceControlViewHost.SurfacePackage - get() = host.surfacePackage + get() = checkNotNull(host.surfacePackage) private lateinit var largeClockHostView: FrameLayout private lateinit var smallClockHostView: FrameLayout diff --git a/packages/SystemUI/src/com/android/systemui/lifecycle/RepeatWhenAttached.kt b/packages/SystemUI/src/com/android/systemui/lifecycle/RepeatWhenAttached.kt index e06483990c90..5f7991e62cd7 100644 --- a/packages/SystemUI/src/com/android/systemui/lifecycle/RepeatWhenAttached.kt +++ b/packages/SystemUI/src/com/android/systemui/lifecycle/RepeatWhenAttached.kt @@ -70,7 +70,7 @@ fun View.repeatWhenAttached( var lifecycleOwner: ViewLifecycleOwner? = null val onAttachListener = object : View.OnAttachStateChangeListener { - override fun onViewAttachedToWindow(v: View?) { + override fun onViewAttachedToWindow(v: View) { Assert.isMainThread() lifecycleOwner?.onDestroy() lifecycleOwner = @@ -81,7 +81,7 @@ fun View.repeatWhenAttached( ) } - override fun onViewDetachedFromWindow(v: View?) { + override fun onViewDetachedFromWindow(v: View) { lifecycleOwner?.onDestroy() lifecycleOwner = null } diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/models/player/SeekBarViewModel.kt b/packages/SystemUI/src/com/android/systemui/media/controls/models/player/SeekBarViewModel.kt index 35f5a8ca4345..a91917ab97c2 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/models/player/SeekBarViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/models/player/SeekBarViewModel.kt @@ -514,7 +514,7 @@ constructor( * Returns true when the down event of the scroll hits within the target box of the thumb. */ override fun onScroll( - eventStart: MotionEvent, + eventStart: MotionEvent?, event: MotionEvent, distanceX: Float, distanceY: Float @@ -528,7 +528,7 @@ constructor( * Gestures that include a fling are considered a false gesture on the seek bar. */ override fun onFling( - eventStart: MotionEvent, + eventStart: MotionEvent?, event: MotionEvent, velocityX: Float, velocityY: Float diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataFilter.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataFilter.kt index 207df6bc4422..a1291a4d6b0f 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataFilter.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataFilter.kt @@ -149,11 +149,7 @@ constructor( // Check if smartspace has explicitly specified whether to re-activate resumable media. // The default behavior is to trigger if the smartspace data is active. val shouldTriggerResume = - if (data.cardAction?.extras?.containsKey(EXTRA_KEY_TRIGGER_RESUME) == true) { - data.cardAction.extras.getBoolean(EXTRA_KEY_TRIGGER_RESUME, true) - } else { - true - } + data.cardAction?.extras?.getBoolean(EXTRA_KEY_TRIGGER_RESUME, true) ?: true val shouldReactivate = shouldTriggerResume && !hasActiveMedia() && hasAnyMedia() && data.isActive @@ -269,9 +265,7 @@ constructor( "Cannot create dismiss action click action: extras missing dismiss_intent." ) } else if ( - dismissIntent.getComponent() != null && - dismissIntent.getComponent().getClassName() == - EXPORTED_SMARTSPACE_TRAMPOLINE_ACTIVITY_NAME + dismissIntent.component?.className == EXPORTED_SMARTSPACE_TRAMPOLINE_ACTIVITY_NAME ) { // Dismiss the card Smartspace data through Smartspace trampoline activity. context.startActivity(dismissIntent) diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt index 69f02f785b03..721052b6e571 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt @@ -23,6 +23,7 @@ import android.app.Notification.EXTRA_SUBSTITUTE_APP_NAME import android.app.PendingIntent import android.app.StatusBarManager import android.app.UriGrantsManager +import android.app.smartspace.SmartspaceAction import android.app.smartspace.SmartspaceConfig import android.app.smartspace.SmartspaceManager import android.app.smartspace.SmartspaceSession @@ -1650,20 +1651,18 @@ class MediaDataManager( * SmartspaceTarget's data is invalid. */ private fun toSmartspaceMediaData(target: SmartspaceTarget): SmartspaceMediaData { - var dismissIntent: Intent? = null - if (target.baseAction != null && target.baseAction.extras != null) { - dismissIntent = - target.baseAction.extras.getParcelable(EXTRAS_SMARTSPACE_DISMISS_INTENT_KEY) - as Intent? - } + val baseAction: SmartspaceAction? = target.baseAction + val dismissIntent = + baseAction?.extras?.getParcelable(EXTRAS_SMARTSPACE_DISMISS_INTENT_KEY) as Intent? val isActive = when { !mediaFlags.isPersistentSsCardEnabled() -> true - target.baseAction == null -> true - else -> - target.baseAction.extras.getString(EXTRA_KEY_TRIGGER_SOURCE) != - EXTRA_VALUE_TRIGGER_PERIODIC + baseAction == null -> true + else -> { + val triggerSource = baseAction.extras?.getString(EXTRA_KEY_TRIGGER_SOURCE) + triggerSource != EXTRA_VALUE_TRIGGER_PERIODIC + } } packageName(target)?.let { diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaSessionBasedFilter.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaSessionBasedFilter.kt index d6f941de1b6d..6a8ffb7d8c42 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaSessionBasedFilter.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaSessionBasedFilter.kt @@ -65,7 +65,7 @@ constructor( private val sessionListener = object : MediaSessionManager.OnActiveSessionsChangedListener { - override fun onActiveSessionsChanged(controllers: List<MediaController>) { + override fun onActiveSessionsChanged(controllers: List<MediaController>?) { handleControllersChanged(controllers) } } @@ -190,16 +190,18 @@ constructor( } } - private fun handleControllersChanged(controllers: List<MediaController>) { + private fun handleControllersChanged(controllers: List<MediaController>?) { packageControllers.clear() - controllers.forEach { controller -> + controllers?.forEach { controller -> packageControllers.get(controller.packageName)?.let { tokens -> tokens.add(controller) } ?: run { val tokens = mutableListOf(controller) packageControllers.put(controller.packageName, tokens) } } - tokensWithNotifications.retainAll(controllers.map { TokenId(it.sessionToken) }) + controllers?.map { TokenId(it.sessionToken) }?.let { + tokensWithNotifications.retainAll(it) + } } /** diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/IlluminationDrawable.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/IlluminationDrawable.kt index b46ebb22ff05..b9cc772e7136 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/IlluminationDrawable.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/IlluminationDrawable.kt @@ -195,7 +195,7 @@ class IlluminationDrawable : Drawable() { } addListener( object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { backgroundAnimation = null } } diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/LightSourceDrawable.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/LightSourceDrawable.kt index 937a618df68f..646d1d0ff0fc 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/LightSourceDrawable.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/LightSourceDrawable.kt @@ -98,11 +98,11 @@ class LightSourceDrawable : Drawable() { addListener( object : AnimatorListenerAdapter() { var cancelled = false - override fun onAnimationCancel(animation: Animator?) { + override fun onAnimationCancel(animation: Animator) { cancelled = true } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { if (cancelled) { return } @@ -226,7 +226,7 @@ class LightSourceDrawable : Drawable() { ) addListener( object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { rippleData.progress = 0f rippleAnimation = null invalidateSelf() @@ -270,11 +270,8 @@ class LightSourceDrawable : Drawable() { return bounds } - override fun onStateChange(stateSet: IntArray?): Boolean { + override fun onStateChange(stateSet: IntArray): Boolean { val changed = super.onStateChange(stateSet) - if (stateSet == null) { - return changed - } val wasPressed = pressed var enabled = false diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselScrollHandler.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselScrollHandler.kt index 1ace3168780a..ce50a11cd85d 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselScrollHandler.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselScrollHandler.kt @@ -127,19 +127,19 @@ class MediaCarouselScrollHandler( object : GestureDetector.SimpleOnGestureListener() { override fun onFling( eStart: MotionEvent?, - eCurrent: MotionEvent?, + eCurrent: MotionEvent, vX: Float, vY: Float ) = onFling(vX, vY) override fun onScroll( down: MotionEvent?, - lastMotion: MotionEvent?, + lastMotion: MotionEvent, distanceX: Float, distanceY: Float - ) = onScroll(down!!, lastMotion!!, distanceX) + ) = onScroll(down!!, lastMotion, distanceX) - override fun onDown(e: MotionEvent?): Boolean { + override fun onDown(e: MotionEvent): Boolean { if (falsingProtectionNeeded) { falsingCollector.onNotificationStartDismissing() } diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt index fe8ebafdf9b4..c1c757e424dc 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt @@ -180,20 +180,20 @@ constructor( object : AnimatorListenerAdapter() { private var cancelled: Boolean = false - override fun onAnimationCancel(animation: Animator?) { + override fun onAnimationCancel(animation: Animator) { cancelled = true animationPending = false rootView?.removeCallbacks(startAnimation) } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { isCrossFadeAnimatorRunning = false if (!cancelled) { applyTargetStateIfNotAnimating() } } - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { cancelled = false animationPending = false } @@ -606,7 +606,7 @@ constructor( val viewHost = UniqueObjectHostView(context) viewHost.addOnAttachStateChangeListener( object : View.OnAttachStateChangeListener { - override fun onViewAttachedToWindow(p0: View?) { + override fun onViewAttachedToWindow(p0: View) { if (rootOverlay == null) { rootView = viewHost.viewRootImpl.view rootOverlay = (rootView!!.overlay as ViewGroupOverlay) @@ -614,7 +614,7 @@ constructor( viewHost.removeOnAttachStateChangeListener(this) } - override fun onViewDetachedFromWindow(p0: View?) {} + override fun onViewDetachedFromWindow(p0: View) {} } ) return viewHost diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHost.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHost.kt index be570b4a1119..631a0b8471b8 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHost.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHost.kt @@ -144,12 +144,12 @@ constructor( setListeningToMediaData(true) hostView.addOnAttachStateChangeListener( object : OnAttachStateChangeListener { - override fun onViewAttachedToWindow(v: View?) { + override fun onViewAttachedToWindow(v: View) { setListeningToMediaData(true) updateViewVisibility() } - override fun onViewDetachedFromWindow(v: View?) { + override fun onViewDetachedFromWindow(v: View) { setListeningToMediaData(false) } } diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/SquigglyProgress.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/SquigglyProgress.kt index 583c626d2156..16dfc2130402 100644 --- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/SquigglyProgress.kt +++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/SquigglyProgress.kt @@ -117,7 +117,7 @@ class SquigglyProgress : Drawable() { } addListener( object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { heightAnimator = null } } diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt index bbd3d33e45c8..da8e106d3019 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttChipControllerReceiver.kt @@ -201,13 +201,13 @@ open class MediaTttChipControllerReceiver @Inject constructor( } override fun updateView(newInfo: ChipReceiverInfo, currentView: ViewGroup) { - val packageName = newInfo.routeInfo.clientPackageName + val packageName: String? = newInfo.routeInfo.clientPackageName var iconInfo = MediaTttUtils.getIconInfoFromPackageName( context, packageName, isReceiver = true, ) { - logger.logPackageNotFound(packageName) + packageName?.let { logger.logPackageNotFound(it) } } if (newInfo.appNameOverride != null) { diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttReceiverRippleController.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttReceiverRippleController.kt index 50138024e268..fbf7e25981da 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttReceiverRippleController.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/MediaTttReceiverRippleController.kt @@ -68,9 +68,9 @@ constructor( ) rippleView.addOnAttachStateChangeListener( object : View.OnAttachStateChangeListener { - override fun onViewDetachedFromWindow(view: View?) {} + override fun onViewDetachedFromWindow(view: View) {} - override fun onViewAttachedToWindow(view: View?) { + override fun onViewAttachedToWindow(view: View) { if (view == null) { return } diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/ReceiverChipRippleView.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/ReceiverChipRippleView.kt index 0b0535df6228..35018f190394 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/ReceiverChipRippleView.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/receiver/ReceiverChipRippleView.kt @@ -54,7 +54,7 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi // Reset all listeners to animator. animator.removeAllListeners() animator.addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { onAnimationEnd?.run() isStarted = false } @@ -86,7 +86,7 @@ class ReceiverChipRippleView(context: Context?, attrs: AttributeSet?) : RippleVi invalidate() } animator.addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { animation?.let { visibility = GONE } onAnimationEnd?.run() isStarted = false diff --git a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt index f75f8b9a18f7..87d0098805b3 100644 --- a/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt +++ b/packages/SystemUI/src/com/android/systemui/media/taptotransfer/sender/MediaTttSenderCoordinator.kt @@ -162,7 +162,7 @@ constructor( logger: MediaTttSenderLogger, instanceId: InstanceId, ): ChipbarInfo { - val packageName = routeInfo.clientPackageName + val packageName = checkNotNull(routeInfo.clientPackageName) val otherDeviceName = if (routeInfo.name.isBlank()) { context.getString(R.string.media_ttt_default_device_type) diff --git a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/view/MediaProjectionRecentsViewController.kt b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/view/MediaProjectionRecentsViewController.kt index c816446d5c25..64de9bd76122 100644 --- a/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/view/MediaProjectionRecentsViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/mediaprojection/appselector/view/MediaProjectionRecentsViewController.kt @@ -88,7 +88,7 @@ constructor( .inflate(R.layout.media_projection_recent_tasks, parent, /* attachToRoot= */ false) as ViewGroup - val container = recentsRoot.findViewById<View>(R.id.media_projection_recent_tasks_container) + val container = recentsRoot.requireViewById<View>(R.id.media_projection_recent_tasks_container) container.setTaskHeightSize() val progress = recentsRoot.requireViewById<View>(R.id.media_projection_recent_tasks_loader) diff --git a/packages/SystemUI/src/com/android/systemui/people/ui/view/PeopleViewBinder.kt b/packages/SystemUI/src/com/android/systemui/people/ui/view/PeopleViewBinder.kt index d8a429e5bb1a..a821d3ce8c07 100644 --- a/packages/SystemUI/src/com/android/systemui/people/ui/view/PeopleViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/people/ui/view/PeopleViewBinder.kt @@ -140,13 +140,13 @@ object PeopleViewBinder { LayoutInflater.from(context) .inflate(R.layout.people_space_activity_no_conversations, /* root= */ view) - noConversationsView.findViewById<View>(R.id.got_it_button).setOnClickListener { + noConversationsView.requireViewById<View>(R.id.got_it_button).setOnClickListener { onGotItClicked() } // The Tile preview has colorBackground as its background. Change it so it's different than // the activity's background. - val item = noConversationsView.findViewById<LinearLayout>(android.R.id.background) + val item = noConversationsView.requireViewById<LinearLayout>(android.R.id.background) val shape = item.background as GradientDrawable val ta = context.theme.obtainStyledAttributes( diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/BaseScreenSharePermissionDialog.kt b/packages/SystemUI/src/com/android/systemui/screenrecord/BaseScreenSharePermissionDialog.kt index b34004397520..23894a3f7835 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/BaseScreenSharePermissionDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/BaseScreenSharePermissionDialog.kt @@ -50,22 +50,20 @@ open class BaseScreenSharePermissionDialog( public override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - window.apply { - addPrivateFlags(WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS) - setGravity(Gravity.CENTER) - } + window?.addPrivateFlags(WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS) + window?.setGravity(Gravity.CENTER) setContentView(R.layout.screen_share_dialog) - dialogTitle = findViewById(R.id.screen_share_dialog_title) - warning = findViewById(R.id.text_warning) - startButton = findViewById(android.R.id.button1) - cancelButton = findViewById(android.R.id.button2) + dialogTitle = requireViewById(R.id.screen_share_dialog_title) + warning = requireViewById(R.id.text_warning) + startButton = requireViewById(android.R.id.button1) + cancelButton = requireViewById(android.R.id.button2) updateIcon() initScreenShareOptions() createOptionsView(getOptionsViewLayoutId()) } private fun updateIcon() { - val icon = findViewById<ImageView>(R.id.screen_share_dialog_icon) + val icon = requireViewById<ImageView>(R.id.screen_share_dialog_icon) if (dialogIconTint != null) { icon.setColorFilter(context.getColor(dialogIconTint)) } @@ -92,7 +90,7 @@ open class BaseScreenSharePermissionDialog( options ) adapter.setDropDownViewResource(R.layout.screen_share_dialog_spinner_item_text) - screenShareModeSpinner = findViewById(R.id.screen_share_mode_spinner) + screenShareModeSpinner = requireViewById(R.id.screen_share_mode_spinner) screenShareModeSpinner.adapter = adapter screenShareModeSpinner.onItemSelectedListener = this } diff --git a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialog.kt b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialog.kt index 604d44967e68..e8683fbea735 100644 --- a/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/screenrecord/ScreenRecordPermissionDialog.kt @@ -100,11 +100,11 @@ class ScreenRecordPermissionDialog( @LayoutRes override fun getOptionsViewLayoutId(): Int = R.layout.screen_record_options private fun initRecordOptionsView() { - audioSwitch = findViewById(R.id.screenrecord_audio_switch) - tapsSwitch = findViewById(R.id.screenrecord_taps_switch) - tapsView = findViewById(R.id.show_taps) + audioSwitch = requireViewById(R.id.screenrecord_audio_switch) + tapsSwitch = requireViewById(R.id.screenrecord_taps_switch) + tapsView = requireViewById(R.id.show_taps) updateTapsViewVisibility() - options = findViewById(R.id.screen_recording_options) + options = requireViewById(R.id.screen_recording_options) val a: ArrayAdapter<*> = ScreenRecordingAdapter(context, android.R.layout.simple_spinner_dropdown_item, MODES) a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt index 3af75cef3d4c..5f53b594a4b6 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeHeaderController.kt @@ -126,11 +126,11 @@ constructor( private lateinit var carrierIconSlots: List<String> private lateinit var mShadeCarrierGroupController: ShadeCarrierGroupController - private val batteryIcon: BatteryMeterView = header.findViewById(R.id.batteryRemainingIcon) - private val clock: Clock = header.findViewById(R.id.clock) - private val date: TextView = header.findViewById(R.id.date) - private val iconContainer: StatusIconContainer = header.findViewById(R.id.statusIcons) - private val mShadeCarrierGroup: ShadeCarrierGroup = header.findViewById(R.id.carrier_group) + private val batteryIcon: BatteryMeterView = header.requireViewById(R.id.batteryRemainingIcon) + private val clock: Clock = header.requireViewById(R.id.clock) + private val date: TextView = header.requireViewById(R.id.date) + private val iconContainer: StatusIconContainer = header.requireViewById(R.id.statusIcons) + private val mShadeCarrierGroup: ShadeCarrierGroup = header.requireViewById(R.id.carrier_group) private var roundedCorners = 0 private var cutout: DisplayCutout? = null @@ -555,7 +555,7 @@ constructor( inner class CustomizerAnimationListener( private val enteringCustomizing: Boolean, ) : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { super.onAnimationEnd(animation) header.animate().setListener(null) if (enteringCustomizing) { @@ -563,7 +563,7 @@ constructor( } } - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { super.onAnimationStart(animation) if (!enteringCustomizing) { customizing = false diff --git a/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt index b7551cf3408e..e284ac5b6a77 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt +++ b/packages/SystemUI/src/com/android/systemui/shade/ShadeModule.kt @@ -80,7 +80,7 @@ abstract class ShadeModule { fun providesNotificationStackScrollLayout( notificationShadeWindowView: NotificationShadeWindowView, ): NotificationStackScrollLayout { - return notificationShadeWindowView.findViewById(R.id.notification_stack_scroller) + return notificationShadeWindowView.requireViewById(R.id.notification_stack_scroller) } // TODO(b/277762009): Only allow this view's controller to inject the view. See above. @@ -89,7 +89,7 @@ abstract class ShadeModule { fun providesNotificationPanelView( notificationShadeWindowView: NotificationShadeWindowView, ): NotificationPanelView { - return notificationShadeWindowView.findViewById(R.id.notification_panel) + return notificationShadeWindowView.requireViewById(R.id.notification_panel) } @Provides @@ -97,7 +97,7 @@ abstract class ShadeModule { fun providesLightRevealScrim( notificationShadeWindowView: NotificationShadeWindowView, ): LightRevealScrim { - return notificationShadeWindowView.findViewById(R.id.light_reveal_scrim) + return notificationShadeWindowView.requireViewById(R.id.light_reveal_scrim) } // TODO(b/277762009): Only allow this view's controller to inject the view. See above. @@ -106,7 +106,7 @@ abstract class ShadeModule { fun providesAuthRippleView( notificationShadeWindowView: NotificationShadeWindowView, ): AuthRippleView? { - return notificationShadeWindowView.findViewById(R.id.auth_ripple) + return notificationShadeWindowView.requireViewById(R.id.auth_ripple) } // TODO(b/277762009): Only allow this view's controller to inject the view. See above. @@ -115,7 +115,7 @@ abstract class ShadeModule { fun providesLockIconView( notificationShadeWindowView: NotificationShadeWindowView, ): LockIconView { - return notificationShadeWindowView.findViewById(R.id.lock_icon_view) + return notificationShadeWindowView.requireViewById(R.id.lock_icon_view) } // TODO(b/277762009): Only allow this view's controller to inject the view. See above. @@ -124,7 +124,7 @@ abstract class ShadeModule { fun providesTapAgainView( notificationPanelView: NotificationPanelView, ): TapAgainView { - return notificationPanelView.findViewById(R.id.shade_falsing_tap_again) + return notificationPanelView.requireViewById(R.id.shade_falsing_tap_again) } // TODO(b/277762009): Only allow this view's controller to inject the view. See above. @@ -134,7 +134,7 @@ abstract class ShadeModule { fun providesShadeHeaderView( notificationShadeWindowView: NotificationShadeWindowView, ): MotionLayout { - val stub = notificationShadeWindowView.findViewById<ViewStub>(R.id.qs_header_stub) + val stub = notificationShadeWindowView.requireViewById<ViewStub>(R.id.qs_header_stub) val layoutId = R.layout.combined_qs_header stub.layoutResource = layoutId return stub.inflate() as MotionLayout @@ -151,7 +151,7 @@ abstract class ShadeModule { @SysUISingleton @Named(SHADE_HEADER) fun providesBatteryMeterView(@Named(SHADE_HEADER) view: MotionLayout): BatteryMeterView { - return view.findViewById(R.id.batteryRemainingIcon) + return view.requireViewById(R.id.batteryRemainingIcon) } @Provides @@ -185,7 +185,7 @@ abstract class ShadeModule { fun providesOngoingPrivacyChip( @Named(SHADE_HEADER) header: MotionLayout, ): OngoingPrivacyChip { - return header.findViewById(R.id.privacy_chip) + return header.requireViewById(R.id.privacy_chip) } @Provides @@ -194,7 +194,7 @@ abstract class ShadeModule { fun providesStatusIconContainer( @Named(SHADE_HEADER) header: MotionLayout, ): StatusIconContainer { - return header.findViewById(R.id.statusIcons) + return header.requireViewById(R.id.statusIcons) } } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BatteryStatusChip.kt b/packages/SystemUI/src/com/android/systemui/statusbar/BatteryStatusChip.kt index 37140ec2aa32..520976746785 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BatteryStatusChip.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BatteryStatusChip.kt @@ -37,8 +37,8 @@ class BatteryStatusChip @JvmOverloads constructor(context: Context, attrs: Attri init { inflate(context, R.layout.battery_status_chip, this) - roundedContainer = findViewById(R.id.rounded_container) - batteryMeterView = findViewById(R.id.battery_meter_view) + roundedContainer = requireViewById(R.id.rounded_container) + batteryMeterView = requireViewById(R.id.battery_meter_view) updateResources() } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt b/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt index 823bb355a307..b2b6e1424f98 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/LightRevealScrim.kt @@ -419,15 +419,14 @@ constructor( revealGradientCenter.y = top + (revealGradientHeight / 2f) } - override fun onDraw(canvas: Canvas?) { + override fun onDraw(canvas: Canvas) { if ( - canvas == null || - revealGradientWidth <= 0 || - revealGradientHeight <= 0 || - revealAmount == 0f + revealGradientWidth <= 0 || + revealGradientHeight <= 0 || + revealAmount == 0f ) { if (revealAmount < 1f) { - canvas?.drawColor(revealGradientEndColor) + canvas.drawColor(revealGradientEndColor) } return } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/LockscreenShadeTransitionController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/LockscreenShadeTransitionController.kt index c098f455512a..2d65c3884abf 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/LockscreenShadeTransitionController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/LockscreenShadeTransitionController.kt @@ -475,7 +475,7 @@ class LockscreenShadeTransitionController @Inject constructor( } if (endlistener != null) { dragDownAnimator.addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { endlistener.invoke() } }) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt b/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt index 750272d65659..17b4e3baef13 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/MediaArtworkProcessor.kt @@ -66,7 +66,7 @@ class MediaArtworkProcessor @Inject constructor() { inBitmap = oldIn.copy(Bitmap.Config.ARGB_8888, false /* isMutable */) oldIn.recycle() } - val outBitmap = Bitmap.createBitmap(inBitmap.width, inBitmap.height, + val outBitmap = Bitmap.createBitmap(inBitmap?.width ?: 0, inBitmap?.height ?: 0, Bitmap.Config.ARGB_8888) input = Allocation.createFromBitmap(renderScript, inBitmap, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt index b624115dc5e7..59c63aa28d0f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShadeDepthController.kt @@ -272,7 +272,7 @@ class NotificationShadeDepthController @Inject constructor( blurUtils.blurRadiusOfRatio(animation.animatedValue as Float) } addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { keyguardAnimator = null wakeAndUnlockBlurRadius = 0f } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/events/PrivacyDotViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/events/PrivacyDotViewController.kt index eddb6835318d..d1e0a7193948 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/events/PrivacyDotViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/events/PrivacyDotViewController.kt @@ -234,7 +234,7 @@ open class PrivacyDotViewController @Inject constructor( } // Set the dot's view gravity to hug the status bar - (corner.findViewById<View>(R.id.privacy_dot) + (corner.requireViewById<View>(R.id.privacy_dot) .layoutParams as FrameLayout.LayoutParams) .gravity = rotatedCorner.innerGravity() } @@ -255,7 +255,7 @@ open class PrivacyDotViewController @Inject constructor( // in every rotation. The only thing we need to check is rtl val rtl = state.layoutRtl val size = Point() - tl.context.display.getRealSize(size) + tl.context.display?.getRealSize(size) val currentRotation = RotationUtils.getExactRotation(tl.context) val displayWidth: Int diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt index 6c1dc8c0a51d..fe1144e0deac 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt @@ -165,7 +165,11 @@ constructor( now.isBefore(Instant.ofEpochMilli(t.expiryTimeMillis)) } if (weatherTarget != null) { - val weatherData = WeatherData.fromBundle(weatherTarget.baseAction.extras) + val weatherData = weatherTarget.baseAction?.extras?.let { extras -> + WeatherData.fromBundle( + extras, + ) + } if (weatherData != null) { keyguardUpdateMonitor.sendWeatherData(weatherData) } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ViewGroupFadeHelper.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ViewGroupFadeHelper.kt index 16f1a45ba83f..1b43922f652a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/ViewGroupFadeHelper.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/ViewGroupFadeHelper.kt @@ -74,7 +74,7 @@ class ViewGroupFadeHelper { root.setTag(R.id.view_group_fade_helper_previous_value_tag, newAlpha) } addListener(object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { endRunnable?.run() } }) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorListView.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorListView.kt index 38a1579222b1..9c4aa072a83d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorListView.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/ChannelEditorListView.kt @@ -60,7 +60,7 @@ class ChannelEditorListView(c: Context, attrs: AttributeSet) : LinearLayout(c, a override fun onFinishInflate() { super.onFinishInflate() - appControlRow = findViewById(R.id.app_control) + appControlRow = requireViewById(R.id.app_control) } /** @@ -143,9 +143,9 @@ class AppControlView(c: Context, attrs: AttributeSet) : LinearLayout(c, attrs) { lateinit var switch: Switch override fun onFinishInflate() { - iconView = findViewById(R.id.icon) - channelName = findViewById(R.id.app_name) - switch = findViewById(R.id.toggle) + iconView = requireViewById(R.id.icon) + channelName = requireViewById(R.id.app_name) + switch = requireViewById(R.id.toggle) setOnClickListener { switch.toggle() } } @@ -174,9 +174,9 @@ class ChannelRow(c: Context, attrs: AttributeSet) : LinearLayout(c, attrs) { override fun onFinishInflate() { super.onFinishInflate() - channelName = findViewById(R.id.channel_name) - channelDescription = findViewById(R.id.channel_description) - switch = findViewById(R.id.toggle) + channelName = requireViewById(R.id.channel_name) + channelDescription = requireViewById(R.id.channel_description) + switch = requireViewById(R.id.toggle) switch.setOnCheckedChangeListener { _, b -> channel?.let { controller.proposeEditForChannel(it, if (b) it.importance else IMPORTANCE_NONE) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt index 1827a46958f8..2a4eba486089 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/ActivityStarterImpl.kt @@ -879,8 +879,8 @@ constructor( val packages: Array<String> = context.resources.getStringArray(R.array.system_ui_packages) for (pkg in packages) { - if (intent.component == null) break - if (pkg == intent.component.packageName) { + val componentName = intent.component ?: break + if (pkg == componentName.packageName) { return UserHandle(UserHandle.myUserId()) } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.kt index d433814d7ce4..d832b6b75200 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.kt @@ -32,6 +32,7 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardBottomAreaViewModel import com.android.systemui.plugins.ActivityStarter import com.android.systemui.plugins.FalsingManager import com.android.systemui.statusbar.VibratorHelper +import com.android.systemui.util.animation.requiresRemeasuring /** * Renders the bottom area of the lock-screen. Concerned primarily with the quick affordance UI @@ -94,7 +95,7 @@ constructor( ambientIndicationArea?.let { nonNullAmbientIndicationArea -> // remove old ambient indication from its parent val originalAmbientIndicationView = - oldBottomArea.findViewById<View>(R.id.ambient_indication_container) + oldBottomArea.requireViewById<View>(R.id.ambient_indication_container) (originalAmbientIndicationView.parent as ViewGroup).removeView( originalAmbientIndicationView ) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt index e6cb68ff17a9..0f6d6244354a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBarViewController.kt @@ -67,8 +67,8 @@ class PhoneStatusBarViewController private constructor( override fun onViewAttached() { if (moveFromCenterAnimationController == null) return - val statusBarLeftSide: View = mView.findViewById(R.id.status_bar_start_side_except_heads_up) - val systemIconArea: ViewGroup = mView.findViewById(R.id.status_bar_end_side_content) + val statusBarLeftSide: View = mView.requireViewById(R.id.status_bar_start_side_except_heads_up) + val systemIconArea: ViewGroup = mView.requireViewById(R.id.status_bar_end_side_content) val viewsToAnimate = arrayOf( statusBarLeftSide, diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt index c850d4f9c56b..ad1817019284 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt @@ -117,11 +117,11 @@ class StatusBarContentInsetsProvider @Inject constructor( * status bar area is contiguous. */ fun currentRotationHasCornerCutout(): Boolean { - val cutout = context.display.cutout ?: return false + val cutout = checkNotNull(context.display).cutout ?: return false val topBounds = cutout.boundingRectTop val point = Point() - context.display.getRealSize(point) + checkNotNull(context.display).getRealSize(point) return topBounds.left <= 0 || topBounds.right >= point.x } @@ -161,7 +161,7 @@ class StatusBarContentInsetsProvider @Inject constructor( */ fun getStatusBarContentInsetsForRotation(@Rotation rotation: Int): Pair<Int, Int> = traceSection(tag = "StatusBarContentInsetsProvider.getStatusBarContentInsetsForRotation") { - val displayCutout = context.display.cutout + val displayCutout = checkNotNull(context.display).cutout val key = getCacheKey(rotation, displayCutout) val screenBounds = context.resources.configuration.windowConfiguration.maxBounds @@ -198,7 +198,7 @@ class StatusBarContentInsetsProvider @Inject constructor( fun getStatusBarContentAreaForRotation( @Rotation rotation: Int ): Rect { - val displayCutout = context.display.cutout + val displayCutout = checkNotNull(context.display).cutout val key = getCacheKey(rotation, displayCutout) return insetsCache[key] ?: getAndSetCalculatedAreaForRotation( rotation, displayCutout, getResourcesForRotation(rotation, context), key) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt index 135307accd13..5a90edde342e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt @@ -101,18 +101,18 @@ class UnlockedScreenOffAnimationController @Inject constructor( } } addListener(object : AnimatorListenerAdapter() { - override fun onAnimationCancel(animation: Animator?) { + override fun onAnimationCancel(animation: Animator) { if (lightRevealScrim.revealEffect !is CircleReveal) { lightRevealScrim.revealAmount = 1f } } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { lightRevealAnimationPlaying = false interactionJankMonitor.end(CUJ_SCREEN_OFF) } - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { interactionJankMonitor.begin( mCentralSurfaces.notificationShadeWindowView, CUJ_SCREEN_OFF) } @@ -339,7 +339,7 @@ class UnlockedScreenOffAnimationController @Inject constructor( // portrait. If we're in another orientation, disable the screen off animation so we don't // animate in the keyguard AOD UI sideways or upside down. if (!keyguardStateController.isKeyguardScreenRotationAllowed && - context.display.rotation != Surface.ROTATION_0) { + context.display?.rotation != Surface.ROTATION_0) { return false } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/userswitcher/StatusBarUserSwitcherContainer.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/userswitcher/StatusBarUserSwitcherContainer.kt index 270c592ae4fd..12594771a0df 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/userswitcher/StatusBarUserSwitcherContainer.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/userswitcher/StatusBarUserSwitcherContainer.kt @@ -34,7 +34,7 @@ class StatusBarUserSwitcherContainer( override fun onFinishInflate() { super.onFinishInflate() - text = findViewById(R.id.current_user_name) - avatar = findViewById(R.id.current_user_avatar) + text = requireViewById(R.id.current_user_name) + avatar = requireViewById(R.id.current_user_avatar) } }
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt index 49504827e073..ffb743ff926c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/DeviceControlsControllerImpl.kt @@ -128,7 +128,8 @@ public class DeviceControlsControllerImpl @Inject constructor( val prefs = userContextProvider.userContext.getSharedPreferences( PREFS_CONTROLS_FILE, Context.MODE_PRIVATE) - val seededPackages = prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, emptySet()) + val seededPackages = + prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, emptySet()) ?: emptySet() val controlsController = controlsComponent.getControlsController().get() val componentsToSeed = mutableListOf<ComponentName>() @@ -174,7 +175,8 @@ public class DeviceControlsControllerImpl @Inject constructor( } private fun addPackageToSeededSet(prefs: SharedPreferences, pkg: String) { - val seededPackages = prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, emptySet()) + val seededPackages = + prefs.getStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, emptySet()) ?: emptySet() val updatedPkgs = seededPackages.toMutableSet() updatedPkgs.add(pkg) prefs.edit().putStringSet(PREFS_CONTROLS_SEEDING_COMPLETED, updatedPkgs).apply() diff --git a/packages/SystemUI/src/com/android/systemui/stylus/StylusManager.kt b/packages/SystemUI/src/com/android/systemui/stylus/StylusManager.kt index 27aaa6828036..eb7d339f5b42 100644 --- a/packages/SystemUI/src/com/android/systemui/stylus/StylusManager.kt +++ b/packages/SystemUI/src/com/android/systemui/stylus/StylusManager.kt @@ -353,8 +353,8 @@ constructor( // before CoreStartables run, and will not be removed. // In many cases, it reports the battery level of the stylus. registerBatteryListener(deviceId) - } else if (device.bluetoothAddress != null) { - onStylusBluetoothConnected(deviceId, device.bluetoothAddress) + } else { + device.bluetoothAddress?.let { onStylusBluetoothConnected(deviceId, it) } } } } diff --git a/packages/SystemUI/src/com/android/systemui/user/UserSwitcherFullscreenDialog.kt b/packages/SystemUI/src/com/android/systemui/user/UserSwitcherFullscreenDialog.kt index 72786efc416d..5ad963035e36 100644 --- a/packages/SystemUI/src/com/android/systemui/user/UserSwitcherFullscreenDialog.kt +++ b/packages/SystemUI/src/com/android/systemui/user/UserSwitcherFullscreenDialog.kt @@ -60,7 +60,7 @@ class UserSwitchFullscreenDialog( override fun getWidth(): Int { val displayMetrics = context.resources.displayMetrics.apply { - context.display.getRealMetrics(this) + checkNotNull(context.display).getRealMetrics(this) } return displayMetrics.widthPixels } diff --git a/packages/SystemUI/src/com/android/systemui/user/UserSwitcherPopupMenu.kt b/packages/SystemUI/src/com/android/systemui/user/UserSwitcherPopupMenu.kt index 088cd93bdf7e..ee84580ac4ec 100644 --- a/packages/SystemUI/src/com/android/systemui/user/UserSwitcherPopupMenu.kt +++ b/packages/SystemUI/src/com/android/systemui/user/UserSwitcherPopupMenu.kt @@ -52,22 +52,22 @@ class UserSwitcherPopupMenu( override fun show() { // need to call show() first in order to construct the listView super.show() - val listView = getListView() + listView?.apply { + isVerticalScrollBarEnabled = false + isHorizontalScrollBarEnabled = false - listView.setVerticalScrollBarEnabled(false) - listView.setHorizontalScrollBarEnabled(false) + // Creates a transparent spacer between items + val shape = ShapeDrawable() + shape.alpha = 0 + divider = shape + dividerHeight = res.getDimensionPixelSize( + R.dimen.bouncer_user_switcher_popup_divider_height) - // Creates a transparent spacer between items - val shape = ShapeDrawable() - shape.setAlpha(0) - listView.setDivider(shape) - listView.setDividerHeight(res.getDimensionPixelSize( - R.dimen.bouncer_user_switcher_popup_divider_height)) - - val height = res.getDimensionPixelSize(R.dimen.bouncer_user_switcher_popup_header_height) - listView.addHeaderView(createSpacer(height), null, false) - listView.addFooterView(createSpacer(height), null, false) - setWidth(findMaxWidth(listView)) + val height = res.getDimensionPixelSize(R.dimen.bouncer_user_switcher_popup_header_height) + addHeaderView(createSpacer(height), null, false) + addFooterView(createSpacer(height), null, false) + setWidth(findMaxWidth(this)) + } super.show() } diff --git a/packages/SystemUI/src/com/android/systemui/user/legacyhelper/ui/LegacyUserUiHelper.kt b/packages/SystemUI/src/com/android/systemui/user/legacyhelper/ui/LegacyUserUiHelper.kt index e74232df3ac3..7f16e47abce1 100644 --- a/packages/SystemUI/src/com/android/systemui/user/legacyhelper/ui/LegacyUserUiHelper.kt +++ b/packages/SystemUI/src/com/android/systemui/user/legacyhelper/ui/LegacyUserUiHelper.kt @@ -67,7 +67,7 @@ object LegacyUserUiHelper { val resourceId: Int? = getGuestUserRecordNameResourceId(record) return when { resourceId != null -> context.getString(resourceId) - record.info != null -> record.info.name + record.info != null -> checkNotNull(record.info.name) else -> context.getString( getUserSwitcherActionTextResourceId( diff --git a/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt b/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt index 56c5d3b433ff..7866d7673937 100644 --- a/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt +++ b/packages/SystemUI/src/com/android/systemui/util/animation/TransitionLayout.kt @@ -223,11 +223,11 @@ class TransitionLayout @JvmOverloads constructor( } } - override fun dispatchDraw(canvas: Canvas?) { - canvas?.save() - canvas?.clipRect(boundsRect) + override fun dispatchDraw(canvas: Canvas) { + canvas.save() + canvas.clipRect(boundsRect) super.dispatchDraw(canvas) - canvas?.restore() + canvas.restore() } private fun updateBounds() { diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/SideFpsControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/biometrics/SideFpsControllerTest.kt index 2908e753c2fe..565e22f4fc25 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/SideFpsControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/SideFpsControllerTest.kt @@ -164,7 +164,7 @@ class SideFpsControllerTest : SysuiTestCase() { context.addMockSystemService(WindowManager::class.java, windowManager) whenEver(layoutInflater.inflate(R.layout.sidefps_view, null, false)).thenReturn(sideFpsView) - whenEver(sideFpsView.findViewById<LottieAnimationView>(eq(R.id.sidefps_animation))) + whenEver(sideFpsView.requireViewById<LottieAnimationView>(eq(R.id.sidefps_animation))) .thenReturn(mock(LottieAnimationView::class.java)) with(mock(ViewPropertyAnimator::class.java)) { whenEver(sideFpsView.animate()).thenReturn(this) diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt index 2da2e9238d0a..8fe7010260ac 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/ShadeHeaderControllerTest.kt @@ -134,18 +134,18 @@ class ShadeHeaderControllerTest : SysuiTestCase() { @Before fun setup() { - whenever<Clock>(view.findViewById(R.id.clock)).thenReturn(clock) + whenever<Clock>(view.requireViewById(R.id.clock)).thenReturn(clock) whenever(clock.context).thenReturn(mockedContext) - whenever<TextView>(view.findViewById(R.id.date)).thenReturn(date) + whenever<TextView>(view.requireViewById(R.id.date)).thenReturn(date) whenever(date.context).thenReturn(mockedContext) - whenever<ShadeCarrierGroup>(view.findViewById(R.id.carrier_group)).thenReturn(carrierGroup) + whenever<ShadeCarrierGroup>(view.requireViewById(R.id.carrier_group)).thenReturn(carrierGroup) - whenever<BatteryMeterView>(view.findViewById(R.id.batteryRemainingIcon)) + whenever<BatteryMeterView>(view.requireViewById(R.id.batteryRemainingIcon)) .thenReturn(batteryMeterView) - whenever<StatusIconContainer>(view.findViewById(R.id.statusIcons)).thenReturn(statusIcons) + whenever<StatusIconContainer>(view.requireViewById(R.id.statusIcons)).thenReturn(statusIcons) viewContext = Mockito.spy(context) whenever(view.context).thenReturn(viewContext) |