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

Commit 6e008116 authored by Yuichiro Hanada's avatar Yuichiro Hanada
Browse files

Fix crash when IntentFilter doesn't have any data type

Flag: EXEMPT simple bug fix
Bug: 380315215
Test: atest ShareTargetPredictorTest
Change-Id: I9993d8abaf0945702fe29b04cbb00aa206e0d72b
parent c87646be
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));