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
This commit is contained in:
Colin Cross
2023-08-09 16:25:07 -07:00
committed by Cherrypicker Worker
parent bb637e04f0
commit e892df24ca
2 changed files with 11 additions and 10 deletions
@@ -101,10 +101,10 @@ constructor(
@SuppressLint("UseSwitchCompatOrMaterialCode") @SuppressLint("UseSwitchCompatOrMaterialCode")
override fun onFinishInflate() { override fun onFinishInflate() {
super.onFinishInflate() super.onFinishInflate()
val taskbarSwitchOption = findViewById<LinearLayout>(R.id.taskbar_switch_option) val taskbarSwitchOption = requireViewById<LinearLayout>(R.id.taskbar_switch_option)
val alwaysShowTaskbarSwitch = findViewById<Switch>(R.id.taskbar_pinning_switch) val alwaysShowTaskbarSwitch = requireViewById<Switch>(R.id.taskbar_pinning_switch)
val navigationModeChangeOption = val navigationModeChangeOption =
findViewById<LinearLayout>(R.id.navigation_mode_switch_option) requireViewById<LinearLayout>(R.id.navigation_mode_switch_option)
alwaysShowTaskbarSwitch.isChecked = alwaysShowTaskbarOn alwaysShowTaskbarSwitch.isChecked = alwaysShowTaskbarOn
taskbarSwitchOption.setOnClickListener { taskbarSwitchOption.setOnClickListener {
alwaysShowTaskbarSwitch.isClickable = true alwaysShowTaskbarSwitch.isClickable = true
@@ -156,18 +156,19 @@ class SplitSelectDataHolder(
*/ */
fun setSecondTask(pendingIntent: PendingIntent) { fun setSecondTask(pendingIntent: PendingIntent) {
secondPendingIntent = pendingIntent secondPendingIntent = pendingIntent
secondUser = pendingIntent.creatorUserHandle!! secondUser = pendingIntent.creatorUserHandle
} }
private fun getShortcutInfo(intent: Intent?, user: UserHandle?): ShortcutInfo? { private fun getShortcutInfo(intent: Intent?, user: UserHandle): ShortcutInfo? {
if (intent?.getPackage() == null) { val intentPackage = intent?.getPackage()
if (intentPackage == null) {
return null return null
} }
val shortcutId = intent.getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID) val shortcutId = intent.getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID)
?: return null ?: return null
try { try {
val context: Context = context.createPackageContextAsUser( val context: Context = context.createPackageContextAsUser(
intent.getPackage(), 0 /* flags */, user) intentPackage, 0 /* flags */, user)
return ShortcutInfo.Builder(context, shortcutId).build() return ShortcutInfo.Builder(context, shortcutId).build()
} catch (e: PackageManager.NameNotFoundException) { } catch (e: PackageManager.NameNotFoundException) {
Log.w(TAG, "Failed to create a ShortcutInfo for " + intent.getPackage()) Log.w(TAG, "Failed to create a ShortcutInfo for " + intent.getPackage())
@@ -250,7 +251,7 @@ class SplitSelectDataHolder(
* convert [secondIntent] * convert [secondIntent]
*/ */
private fun convertIntentsToFinalTypes() { private fun convertIntentsToFinalTypes() {
initialShortcut = getShortcutInfo(initialIntent, initialUser) initialShortcut = getShortcutInfo(initialIntent, checkNotNull(initialUser))
initialPendingIntent = getPendingIntent(initialIntent, initialUser) initialPendingIntent = getPendingIntent(initialIntent, initialUser)
initialIntent = null initialIntent = null
@@ -264,7 +265,7 @@ class SplitSelectDataHolder(
return return
} }
secondShortcut = getShortcutInfo(secondIntent, secondUser) secondShortcut = getShortcutInfo(secondIntent, checkNotNull(secondUser))
secondPendingIntent = getPendingIntent(secondIntent, secondUser) secondPendingIntent = getPendingIntent(secondIntent, secondUser)
secondIntent = null secondIntent = null
} }
@@ -405,4 +406,4 @@ class SplitSelectDataHolder(
writer.println("$prefix\tinitialShortcut= $initialShortcut") writer.println("$prefix\tinitialShortcut= $initialShortcut")
writer.println("$prefix\tsecondShortcut= $secondShortcut") writer.println("$prefix\tsecondShortcut= $secondShortcut")
} }
} }