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

Commit f7554ff7 authored by Andy Wickham's avatar Andy Wickham
Browse files

Use new AssistUtils(Base) to override SysUI Assist invocations.

AssistUtils#getSysUiAssistOverrideInvocationTypes(): Sent
over SysUiProxy to request overriding these invocation types.

AssistUtils#tryStartAssistOverride(): Called by OverviewProxy
(TouchInteractionService) for previously requested overrides.
Also used within Launcher for Taskbar and QSB to override
other invocation logic. May return false to indicate that
the override was not handled, so a fallback may be desired.

Bug: 295874732
Test: Manual
Change-Id: I488f3b7da1feb2663feab5d04dfa8d605c070efb
parent 7c183e29
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@

  <string name="nav_handle_long_press_handler_class" translatable="false"></string>

  <string name="assist_utils_class" translatable="false"></string>

  <string name="secondary_display_predictions_class" translatable="false">com.android.launcher3.secondarydisplay.SecondaryDisplayPredictionsImpl</string>

  <string name="taskbar_model_callbacks_factory_class" translatable="false">com.android.launcher3.taskbar.TaskbarModelCallbacksFactory</string>
+10 −5
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import com.android.quickstep.OverviewCommandHelper;
import com.android.quickstep.SystemUiProxy;
import com.android.quickstep.TaskUtils;
import com.android.quickstep.TouchInteractionService;
import com.android.quickstep.util.AssistUtilsBase;
import com.android.quickstep.views.DesktopTaskView;

import java.io.PrintWriter;
@@ -158,7 +159,7 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
        switch (buttonType) {
            case BUTTON_HOME:
                logEvent(LAUNCHER_TASKBAR_HOME_BUTTON_LONGPRESS);
                startAssistant();
                onLongPressHome();
                return true;
            case BUTTON_A11Y:
                logEvent(LAUNCHER_TASKBAR_A11Y_BUTTON_LONGPRESS);
@@ -307,14 +308,18 @@ public class TaskbarNavButtonController implements TaskbarControllers.LoggableTa
        }
    }

    private void startAssistant() {
    private void onLongPressHome() {
        if (mScreenPinned || !mAssistantLongPressEnabled) {
            return;
        }
        // Attempt to start Assist with AssistUtils, otherwise fall back to SysUi's implementation.
        if (!AssistUtilsBase.newInstance(mService.getApplicationContext()).tryStartAssistOverride(
                INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS)) {
            Bundle args = new Bundle();
            args.putInt(INVOCATION_TYPE_KEY, INVOCATION_TYPE_HOME_BUTTON_LONG_PRESS);
            mSystemUiProxy.startAssistant(args);
        }
    }

    private void showQuickSettings() {
        mSystemUiProxy.toggleNotificationPanel();
+14 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import com.android.internal.view.AppearanceRegion;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.Preconditions;
import com.android.launcher3.util.SplitConfigurationOptions;
import com.android.quickstep.util.AssistUtilsBase;
import com.android.systemui.shared.recents.ISystemUiProxy;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.RecentsAnimationControllerCompat;
@@ -250,6 +251,8 @@ public class SystemUiProxy implements ISystemUiProxy {
        setBackToLauncherCallback(mBackToLauncherCallback, mBackToLauncherRunner);
        setUnfoldAnimationListener(mUnfoldAnimationListener);
        setDesktopTaskListener(mDesktopTaskListener);
        setAssistantOverridesRequested(
                AssistUtilsBase.newInstance(mContext).getSysUiAssistOverrideInvocationTypes());
    }

    /**
@@ -373,6 +376,17 @@ public class SystemUiProxy implements ISystemUiProxy {
        }
    }

    @Override
    public void setAssistantOverridesRequested(int[] invocationTypes) {
        if (mSystemUiProxy != null) {
            try {
                mSystemUiProxy.setAssistantOverridesRequested(invocationTypes);
            } catch (RemoteException e) {
                Log.w(TAG, "Failed call setAssistantOverridesRequested", e);
            }
        }
    }

    @Override
    public void notifyAccessibilityButtonClicked(int displayId) {
        if (mSystemUiProxy != null) {
+15 −0
Original line number Diff line number Diff line
@@ -117,6 +117,7 @@ import com.android.quickstep.inputconsumers.TaskbarUnstashInputConsumer;
import com.android.quickstep.inputconsumers.TrackpadStatusBarInputConsumer;
import com.android.quickstep.util.ActiveGestureLog;
import com.android.quickstep.util.ActiveGestureLog.CompoundString;
import com.android.quickstep.util.AssistUtilsBase;
import com.android.systemui.shared.recents.IOverviewProxy;
import com.android.systemui.shared.recents.ISystemUiProxy;
import com.android.systemui.shared.system.ActivityManagerWrapper;
@@ -280,6 +281,20 @@ public class TouchInteractionService extends Service {
            }));
        }

        /**
         * Sent when the assistant has been invoked with the given type (defined in AssistManager)
         * and should be shown. This method is used if SystemUiProxy#setAssistantOverridesRequested
         * was previously called including this invocation type.
         */
        @Override
        public void onAssistantOverrideInvoked(int invocationType) {
            executeForTouchInteractionService(tis -> {
                if (!AssistUtilsBase.newInstance(tis).tryStartAssistOverride(invocationType)) {
                    Log.w(TAG, "Failed to invoke Assist override");
                }
            });
        }

        @Override
        public void onNavigationBarSurface(SurfaceControl surface) {
            // TODO: implement
+45 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.quickstep.util;

import android.content.Context;

import com.android.launcher3.R;
import com.android.launcher3.util.ResourceBasedOverride;

/** Utilities to work with Assistant functionality. */
public class AssistUtilsBase implements ResourceBasedOverride {

    public AssistUtilsBase() {}

    /** Creates AssistUtils as specified by overrides */
    public static AssistUtilsBase newInstance(Context context) {
        return Overrides.getObject(AssistUtilsBase.class, context, R.string.assist_utils_class);
    }

    /** @return Array of AssistUtils.INVOCATION_TYPE_* that we want to handle instead of SysUI. */
    public int[] getSysUiAssistOverrideInvocationTypes() {
        return new int[0];
    }

    /**
     * @return {@code true} if the override was handled, i.e. an assist surface was shown or the
     * request should be ignored. {@code false} means the caller should start assist another way.
     */
    public boolean tryStartAssistOverride(int invocationType) {
        return false;
    }
}
Loading