Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f4b4021 authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Android (Google) Code Review
Browse files

Merge "Fix crash when IntentFilter doesn't have any data type" into main

parents 268ba5e8 6e008116
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -213,7 +213,8 @@ class ShareTargetPredictor extends AppTargetPredictor {
    }

    private int getShareEventType(IntentFilter intentFilter) {
        String mimeType = intentFilter != null ? intentFilter.getDataType(0) : null;
        String mimeType = (intentFilter != null && intentFilter.countDataTypes() > 0)
                ? intentFilter.getDataType(0) : null;
        return getDataManager().mimeTypeToShareEventType(mimeType);
    }

+19 −0
Original line number Diff line number Diff line
@@ -285,6 +285,25 @@ public final class ShareTargetPredictorTest {
        verify(mDataManager, never()).getShareShortcuts(any(), anyInt());
    }

    @Test
    public void testPredictTargets_emptyIntentFilter() {
        Bundle bundle = new Bundle();
        IntentFilter filter = new IntentFilter();
        bundle.putObject(ChooserActivity.APP_PREDICTION_INTENT_FILTER_KEY, filter);
        AppPredictionContext predictionContext = new AppPredictionContext.Builder(mContext)
                .setUiSurface(UI_SURFACE_SHARE)
                .setPredictedTargetCount(NUM_PREDICTED_TARGETS)
                .setExtras(bundle)
                .build();
        mPredictor = new ShareTargetPredictor(
                predictionContext, mUpdatePredictionsMethod, mDataManager, USER_ID, mContext);

        mPredictor.predictTargets();

        verify(mUpdatePredictionsMethod).accept(mAppTargetCaptor.capture());
        assertThat(mAppTargetCaptor.getValue()).isEmpty();
    }

    @Test
    public void testPredictTargets_noSharingHistoryRankedByShortcutRank() {
        mShareShortcuts.add(buildShareShortcut(PACKAGE_1, CLASS_1, "sc1", 3));