From 4cc251e6c1bd5e06ef24a92e08aae043cf3f2587 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. This relands I26edfec35dca14abe90b08e3c74de0446eda95d2 with a fix in SplitSelectDataHolder.kt to call createPackageContext when user is null instead of asserting that it is not null. Bug: 294110802 Test: builds Test: WMShellFlickerServiceTests Change-Id: I4525d0fa83a1db9cc5cff90f340fc3f863537c01 Merged-In: I4525d0fa83a1db9cc5cff90f340fc3f863537c01 --- .../android/quickstep/util/SplitSelectDataHolder.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/quickstep/src/com/android/quickstep/util/SplitSelectDataHolder.kt b/quickstep/src/com/android/quickstep/util/SplitSelectDataHolder.kt index f32e9bc450..3ff461adf3 100644 --- a/quickstep/src/com/android/quickstep/util/SplitSelectDataHolder.kt +++ b/quickstep/src/com/android/quickstep/util/SplitSelectDataHolder.kt @@ -159,7 +159,7 @@ class SplitSelectDataHolder( secondUser = pendingIntent.creatorUserHandle } - private fun getShortcutInfo(intent: Intent?, user: UserHandle): ShortcutInfo? { + private fun getShortcutInfo(intent: Intent?, user: UserHandle?): ShortcutInfo? { val intentPackage = intent?.getPackage() if (intentPackage == null) { return null @@ -167,8 +167,12 @@ class SplitSelectDataHolder( val shortcutId = intent.getStringExtra(ShortcutKey.EXTRA_SHORTCUT_ID) ?: return null try { - val context: Context = context.createPackageContextAsUser( - intentPackage, 0 /* flags */, user) + val context: Context = + if (user != null) { + context.createPackageContextAsUser(intentPackage, 0 /* flags */, user) + } else { + context.createPackageContext(intentPackage, 0 /* *flags */) + } return ShortcutInfo.Builder(context, shortcutId).build() } catch (e: PackageManager.NameNotFoundException) { Log.w(TAG, "Failed to create a ShortcutInfo for " + intent.getPackage())