From e892df24ca3de29297ceacc700657e1cd1bece19 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Wed, 9 Aug 2023 16:25:07 -0700 Subject: [PATCH] Fix kotlin nullable errors in Launcher3 Fix kotlin nullable errors that were exposed by setting the retention of android.annotation.NonNull and android.annotation.Nullable to class retention. Bug: 294110802 Test: builds (cherry picked from https://googleplex-android-review.googlesource.com/q/commit:2608381792389b60ba37c08afcea09dca3c6ff9c) Merged-In: I26edfec35dca14abe90b08e3c74de0446eda95d2 Change-Id: I26edfec35dca14abe90b08e3c74de0446eda95d2 --- .../launcher3/taskbar/TaskbarDividerPopupView.kt | 6 +++--- .../quickstep/util/SplitSelectDataHolder.kt | 15 ++++++++------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt index a347908473..17d10d3574 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarDividerPopupView.kt @@ -101,10 +101,10 @@ constructor( @SuppressLint("UseSwitchCompatOrMaterialCode") override fun onFinishInflate() { super.onFinishInflate() - val taskbarSwitchOption = findViewById(R.id.taskbar_switch_option) - val alwaysShowTaskbarSwitch = findViewById(R.id.taskbar_pinning_switch) + val taskbarSwitchOption = requireViewById(R.id.taskbar_switch_option) + val alwaysShowTaskbarSwitch = requireViewById(R.id.taskbar_pinning_switch) val navigationModeChangeOption = - findViewById(R.id.navigation_mode_switch_option) + requireViewById(R.id.navigation_mode_switch_option) alwaysShowTaskbarSwitch.isChecked = alwaysShowTaskbarOn taskbarSwitchOption.setOnClickListener { alwaysShowTaskbarSwitch.isClickable = true diff --git a/quickstep/src/com/android/quickstep/util/SplitSelectDataHolder.kt b/quickstep/src/com/android/quickstep/util/SplitSelectDataHolder.kt index e073264998..f32e9bc450 100644 --- a/quickstep/src/com/android/quickstep/util/SplitSelectDataHolder.kt +++ b/quickstep/src/com/android/quickstep/util/SplitSelectDataHolder.kt @@ -156,18 +156,19 @@ class SplitSelectDataHolder( */ fun setSecondTask(pendingIntent: PendingIntent) { secondPendingIntent = pendingIntent - secondUser = pendingIntent.creatorUserHandle!! + secondUser = pendingIntent.creatorUserHandle } - private fun getShortcutInfo(intent: Intent?, user: UserHandle?): ShortcutInfo? { - if (intent?.getPackage() == null) { + private fun getShortcutInfo(intent: Intent?, user: UserHandle): ShortcutInfo? { + val intentPackage = intent?.getPackage() + if (intentPackage == null) { return null } val shortcutId = intent.getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID) ?: return null try { val context: Context = context.createPackageContextAsUser( - intent.getPackage(), 0 /* flags */, user) + intentPackage, 0 /* flags */, user) return ShortcutInfo.Builder(context, shortcutId).build() } catch (e: PackageManager.NameNotFoundException) { Log.w(TAG, "Failed to create a ShortcutInfo for " + intent.getPackage()) @@ -250,7 +251,7 @@ class SplitSelectDataHolder( * convert [secondIntent] */ private fun convertIntentsToFinalTypes() { - initialShortcut = getShortcutInfo(initialIntent, initialUser) + initialShortcut = getShortcutInfo(initialIntent, checkNotNull(initialUser)) initialPendingIntent = getPendingIntent(initialIntent, initialUser) initialIntent = null @@ -264,7 +265,7 @@ class SplitSelectDataHolder( return } - secondShortcut = getShortcutInfo(secondIntent, secondUser) + secondShortcut = getShortcutInfo(secondIntent, checkNotNull(secondUser)) secondPendingIntent = getPendingIntent(secondIntent, secondUser) secondIntent = null } @@ -405,4 +406,4 @@ class SplitSelectDataHolder( writer.println("$prefix\tinitialShortcut= $initialShortcut") writer.println("$prefix\tsecondShortcut= $secondShortcut") } -} \ No newline at end of file +}