From 6ee42dcf70adbc77d4c923383df627f83a574b1d Mon Sep 17 00:00:00 2001 From: Alan Chen Date: Mon, 15 Apr 2024 15:53:22 -0700 Subject: Fix NPE when edit action is null Make editButtonRunnable null when there is no valid editSharingTarget to prevent a NPE that will crash the app creating the sharesheet. This will remove the edit button in ChooserContentPreviewUi when no editor is available. Bug: 330383989 Test: manual - see recording in issue Change-Id: I3d84ce548bf303062bf6b3bd0a2e6c396ddbb86c --- .../android/intentresolver/ChooserActionFactory.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'java') diff --git a/java/src/com/android/intentresolver/ChooserActionFactory.java b/java/src/com/android/intentresolver/ChooserActionFactory.java index ffe83fa6..79998fbc 100644 --- a/java/src/com/android/intentresolver/ChooserActionFactory.java +++ b/java/src/com/android/intentresolver/ChooserActionFactory.java @@ -99,7 +99,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio private final Context mContext; @Nullable private Runnable mCopyButtonRunnable; - private Runnable mEditButtonRunnable; + @Nullable private Runnable mEditButtonRunnable; private final ImmutableList mCustomActions; private final Consumer mExcludeSharedTextAction; @Nullable private final ShareResultSender mShareResultSender; @@ -158,7 +158,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio ChooserActionFactory( Context context, @Nullable Runnable copyButtonRunnable, - Runnable editButtonRunnable, + @Nullable Runnable editButtonRunnable, List customActions, Consumer onUpdateSharedTextIsExcluded, EventLog log, @@ -174,10 +174,12 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio mFinishCallback = finishCallback; if (mShareResultSender != null) { - mEditButtonRunnable = () -> { - mShareResultSender.onActionSelected(ShareAction.SYSTEM_EDIT); - editButtonRunnable.run(); - }; + if (mEditButtonRunnable != null) { + mEditButtonRunnable = () -> { + mShareResultSender.onActionSelected(ShareAction.SYSTEM_EDIT); + editButtonRunnable.run(); + }; + } if (mCopyButtonRunnable != null) { mCopyButtonRunnable = () -> { mShareResultSender.onActionSelected(ShareAction.SYSTEM_COPY); @@ -281,6 +283,7 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio return clipData; } + @Nullable private static TargetInfo getEditSharingTarget( Context context, Intent originalIntent, @@ -325,11 +328,13 @@ public final class ChooserActionFactory implements ChooserContentPreviewUi.Actio return dri; } + @Nullable private static Runnable makeEditButtonRunnable( - TargetInfo editSharingTarget, + @Nullable TargetInfo editSharingTarget, Callable firstVisibleImageQuery, ActionActivityStarter activityStarter, EventLog log) { + if (editSharingTarget == null) return null; return () -> { // Log share completion via edit. log.logActionSelected(EventLog.SELECTION_TYPE_EDIT); -- cgit v1.2.3-59-g8ed1b