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

Commit 866ff00e authored by Samuel Fufa's avatar Samuel Fufa
Browse files

Add a "Dismiss" option for predicted apps in Launcher

Test: LongPress on a pridicted app to see dismiss options.
Bug:139020180
Change-Id: I877863c65def0d845c0ae2f0987fe7a4f6277565
parent 237441a2
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -118,6 +118,7 @@ enum ControlType {
  APP_USAGE_SETTINGS = 18;
  BACK_GESTURE = 19;
  UNDO = 20;
  DISMISS_PREDICTION = 21;
}

enum TipType {
+28 −6
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.launcher3.appprediction;

import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_GRID;

import android.annotation.TargetApi;
import android.app.prediction.AppPredictionContext;
import android.app.prediction.AppPredictionManager;
@@ -34,13 +32,15 @@ import android.os.UserHandle;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.annotation.WorkerThread;

import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.appprediction.PredictionUiStateManager.Client;
import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.util.UiThreadHelper;

import androidx.annotation.UiThread;
import androidx.annotation.WorkerThread;
import static com.android.launcher3.InvariantDeviceProfile.CHANGE_FLAG_GRID;

/**
 * Subclass of app tracker which publishes the data to the prediction engine and gets back results.
@@ -174,6 +174,7 @@ public class PredictionAppTracker extends AppLaunchTracker {
                new AppTargetId("shortcut:" + shortcutId), packageName, user)
                .setClassName(shortcutId)
                .build();

        sendLaunch(target, container);
    }

@@ -189,11 +190,32 @@ public class PredictionAppTracker extends AppLaunchTracker {
        }
    }

    @Override
    @UiThread
    private void sendLaunch(AppTarget target, String container) {
        AppTargetEvent event = new AppTargetEvent.Builder(target, AppTargetEvent.ACTION_LAUNCH)
    public void onDismissApp(ComponentName cn, UserHandle user, String container) {
        if (cn == null) return;
        AppTarget target = new AppTarget.Builder(
                new AppTargetId("app: " + cn), cn.getPackageName(), user)
                .setClassName(cn.getClassName())
                .build();
        sendDismiss(target, container);
    }

    @UiThread
    private void sendEvent(AppTarget target, String container, int eventId) {
        AppTargetEvent event = new AppTargetEvent.Builder(target, eventId)
                .setLaunchLocation(container == null ? CONTAINER_DEFAULT : container)
                .build();
        Message.obtain(mMessageHandler, MSG_LAUNCH, event).sendToTarget();
    }

    @UiThread
    private void sendLaunch(AppTarget target, String container) {
        sendEvent(target, container, AppTargetEvent.ACTION_LAUNCH);
    }

    @UiThread
    private void sendDismiss(AppTarget target, String container) {
        sendEvent(target, container, AppTargetEvent.ACTION_DISMISS);
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import com.android.launcher3.ItemInfo;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.R;
import com.android.launcher3.WorkspaceItemInfo;
import com.android.launcher3.allapps.AllAppsStore;
@@ -290,7 +291,9 @@ public class PredictionRowView extends LinearLayout implements
        for (ComponentKeyMapper mapper : components) {
            ItemInfoWithIcon info = mapper.getApp(getAppsStore());
            if (info != null) {
                predictedApps.add(info);
                ItemInfoWithIcon predictedApp = info.clone();
                predictedApp.container = LauncherSettings.Favorites.CONTAINER_PREDICTION;
                predictedApps.add(predictedApp);
            } else {
                if (FeatureFlags.IS_DOGFOOD_BUILD) {
                    Log.e(TAG, "Predicted app not found: " + mapper);
+3 −0
Original line number Diff line number Diff line
@@ -105,6 +105,9 @@
    <!-- Label for install drop target. [CHAR_LIMIT=20] -->
    <string name="install_drop_target_label">Install</string>

    <!-- Label for install dismiss prediction. -->
    <string translatable="false" name="dismiss_prediction_label">Dismiss prediction</string>

    <!-- Permissions: -->
    <skip />
    <!-- Permission short label -->
+7 −0
Original line number Diff line number Diff line
@@ -85,6 +85,8 @@ public class AppInfo extends ItemInfoWithIcon {
        componentName = info.componentName;
        title = Utilities.trim(info.title);
        intent = new Intent(info.intent);
        user = info.user;
        runtimeStatusFlags = info.runtimeStatusFlags;
    }

    @Override
@@ -127,4 +129,9 @@ public class AppInfo extends ItemInfoWithIcon {
            info.runtimeStatusFlags |= FLAG_ADAPTIVE_ICON;
        }
    }

    @Override
    public AppInfo clone() {
        return new AppInfo(this);
    }
}
Loading