From 7b468b86871b26e164c9bf8163fe7ca810ddbe08 Mon Sep 17 00:00:00 2001 From: Adam Bookatz Date: Fri, 26 Jan 2024 13:26:01 -0800 Subject: ChooserAdapter: fix NPE for non-work profiles For some non-work profiles (Communal, and maybe Private), the getListAdapterForUserHandle is returning null. The method is indeed nullable. But we run getCount on it without doing a null-check, causing crashes for such profiles. This previously couldn't have happened, since shouldShowTabs() returns false in these cases, and the evaluation was skipped; however, ag/I8273cf365a1e00b1acff4030086f1a044ad7531f moved that check to later, so we are hitting this problem. Bug: 322523699 Bug: 320369524 Bug: 320615143 Bug: 322497953 Test: atest IntentResolver-tests-unit Change-Id: I82303d6a6a1be1066f5c3e05c53f6a70d486bf5a --- java/src/com/android/intentresolver/ChooserActivity.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'java/src') diff --git a/java/src/com/android/intentresolver/ChooserActivity.java b/java/src/com/android/intentresolver/ChooserActivity.java index 82e46a57..e30c198a 100644 --- a/java/src/com/android/intentresolver/ChooserActivity.java +++ b/java/src/com/android/intentresolver/ChooserActivity.java @@ -1651,8 +1651,9 @@ public class ChooserActivity extends Hilt_ChooserActivity implements if (!shouldShowContentPreview()) { return false; } - boolean isEmpty = mMultiProfilePagerAdapter.getListAdapterForUserHandle( - UserHandle.of(UserHandle.myUserId())).getCount() == 0; + ResolverListAdapter adapter = mMultiProfilePagerAdapter.getListAdapterForUserHandle( + UserHandle.of(UserHandle.myUserId())); + boolean isEmpty = adapter == null || adapter.getCount() == 0; return (mFeatureFlags.scrollablePreview() || shouldShowTabs()) && (!isEmpty || shouldShowContentPreviewWhenEmpty()); } -- cgit v1.2.3-59-g8ed1b