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

Commit 77f4bee9 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Send share events to App Predictor."

parents cba2c7c2 f2b0d34e
Loading
Loading
Loading
Loading
+37 −2
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.app.prediction.AppPredictionContext;
import android.app.prediction.AppPredictionManager;
import android.app.prediction.AppPredictor;
import android.app.prediction.AppTarget;
import android.app.prediction.AppTargetEvent;
import android.app.prediction.AppTargetId;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
@@ -111,6 +113,7 @@ public class ChooserActivity extends ResolverActivity {
    private static final boolean USE_PREDICTION_MANAGER_FOR_DIRECT_TARGETS = false;
    // TODO(b/123088566) Share these in a better way.
    private static final String APP_PREDICTION_SHARE_UI_SURFACE = "share";
    public static final String LAUNCH_LOCATON_DIRECT_SHARE = "direct_share";
    private static final int APP_PREDICTION_SHARE_TARGET_QUERY_PACKAGE_LIMIT = 20;
    public static final String APP_PREDICTION_INTENT_FILTER_KEY = "intent_filter";
    private AppPredictor mAppPredictor;
@@ -787,9 +790,11 @@ public class ChooserActivity extends ResolverActivity {
        // Do nothing. We'll send the voice stuff ourselves.
    }

    // TODO(b/123377860) Send clicked ShortcutInfo to mAppPredictor
    void updateModelAndChooserCounts(TargetInfo info) {
        if (info != null) {
            if (USE_PREDICTION_MANAGER_FOR_DIRECT_TARGETS) {
                sendClickToAppPredictor(info);
            }
            final ResolveInfo ri = info.getResolveInfo();
            Intent targetIntent = getTargetIntent();
            if (ri != null && ri.activityInfo != null && targetIntent != null) {
@@ -809,6 +814,32 @@ public class ChooserActivity extends ResolverActivity {
        mIsSuccessfullySelected = true;
    }

    private void sendClickToAppPredictor(TargetInfo targetInfo) {
        if (!(targetInfo instanceof ChooserTargetInfo)) {
            return;
        }
        ChooserTarget chooserTarget = ((ChooserTargetInfo) targetInfo).getChooserTarget();
        ComponentName componentName = chooserTarget.getComponentName();
        Bundle extras = chooserTarget.getIntentExtras();
        if (extras == null) {
            return;
        }
        String shortcutId = extras.getString(Intent.EXTRA_SHORTCUT_ID);
        if (shortcutId == null) {
            return;
        }
        mAppPredictor.notifyAppTargetEvent(
                new AppTargetEvent.Builder(
                    new AppTarget(
                        new AppTargetId(shortcutId),
                        componentName.getPackageName(),
                        componentName.getClassName(),
                        getUser()),
                    AppTargetEvent.ACTION_LAUNCH
                ).setLaunchLocation(LAUNCH_LOCATON_DIRECT_SHARE)
                .build());
    }

    void onRefinementResult(TargetInfo selectedTarget, Intent matchingIntent) {
        if (mRefinementResultReceiver != null) {
            mRefinementResultReceiver.destroy();
@@ -1128,6 +1159,10 @@ public class ChooserActivity extends ResolverActivity {
            return mBadgeContentDescription;
        }

        public ChooserTarget getChooserTarget() {
            return mChooserTarget;
        }

        @Override
        public TargetInfo cloneFilledIn(Intent fillInIntent, int flags) {
            return new ChooserTargetInfo(this, fillInIntent, flags);