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

Commit 165ce066 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Fix assist for hardware long-press

Activating the assistant will now route through SysUI, so
we have the logic whether to start an activity or to start a voice
interaction session in one single place.

Bug: 22201770
Change-Id: I0f4699533aea2a1e595ee25a844434c82f548c01
parent 588932a5
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -30,6 +30,6 @@ interface ISearchManager {
   List<ResolveInfo> getGlobalSearchActivities();
   ComponentName getGlobalSearchActivity();
   ComponentName getWebSearchActivity();
   ComponentName getAssistIntent(int userHandle);
   boolean launchAssistAction(String hint, int userHandle, in Bundle args);
   void launchAssist(in Bundle args);
   boolean launchLegacyAssist(String hint, int userHandle, in Bundle args);
}
+26 −23
Original line number Diff line number Diff line
@@ -946,27 +946,9 @@ public class SearchManager
     *
     * @hide
     */
    public Intent getAssistIntent(Context context, boolean inclContext) {
        return getAssistIntent(context, inclContext, UserHandle.myUserId());
    }

    /**
     * Gets an intent for launching installed assistant activity, or null if not available.
     * @return The assist intent.
     *
     * @hide
     */
    public Intent getAssistIntent(Context context, boolean inclContext, int userHandle) {
    public Intent getAssistIntent(boolean inclContext) {
        try {
            if (mService == null) {
                return null;
            }
            ComponentName comp = mService.getAssistIntent(userHandle);
            if (comp == null) {
                return null;
            }
            Intent intent = new Intent(Intent.ACTION_ASSIST);
            intent.setComponent(comp);
            if (inclContext) {
                IActivityManager am = ActivityManagerNative.getDefault();
                Bundle extras = am.getAssistContextExtras(ActivityManager.ASSIST_CONTEXT_BASIC);
@@ -982,17 +964,38 @@ public class SearchManager
    }

    /**
     * Launch an assist action for the current top activity.
     * Starts the assistant.
     *
     * @param args the args to pass to the assistant
     *
     * @hide
     */
    public void launchAssist(Bundle args) {
        try {
            if (mService == null) {
                return;
            }
            mService.launchAssist(args);
        } catch (RemoteException re) {
            Log.e(TAG, "launchAssist() failed: " + re);
        }
    }

    /**
     * Starts the legacy assistant (i.e. the {@link Intent#ACTION_ASSIST}).
     *
     * @param args the args to pass to the assistant
     *
     * @hide
     */
    public boolean launchAssistAction(String hint, int userHandle, Bundle args) {
    public boolean launchLegacyAssist(String hint, int userHandle, Bundle args) {
        try {
            if (mService == null) {
                return false;
            }
            return mService.launchAssistAction(hint, userHandle, args);
            return mService.launchLegacyAssist(hint, userHandle, args);
        } catch (RemoteException re) {
            Log.e(TAG, "launchAssistAction() failed: " + re);
            Log.e(TAG, "launchAssist() failed: " + re);
            return false;
        }
    }
+13 −6
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
@@ -42,9 +45,10 @@ public class AssistUtils {
                ServiceManager.getService(Context.VOICE_INTERACTION_MANAGER_SERVICE));
    }

    public void showSessionForActiveService(IVoiceInteractionSessionShowCallback showCallback) {
    public void showSessionForActiveService(Bundle args,
            IVoiceInteractionSessionShowCallback showCallback) {
        try {
            mVoiceInteractionManagerService.showSessionForActiveService(showCallback);
            mVoiceInteractionManagerService.showSessionForActiveService(args, showCallback);
        } catch (RemoteException e) {
            Log.w(TAG, "Failed to call showSessionForActiveService", e);
        }
@@ -118,11 +122,14 @@ public class AssistUtils {
        }

        Intent intent = ((SearchManager) mContext.getSystemService(Context.SEARCH_SERVICE))
                .getAssistIntent(mContext, false, userId);
        if (intent != null) {
            return intent.getComponent();
                .getAssistIntent(false);
        PackageManager pm = mContext.getPackageManager();
        ResolveInfo info = pm.resolveActivityAsUser(intent, PackageManager.MATCH_DEFAULT_ONLY,
                userId);
        if (info != null) {
            return new ComponentName(info.activityInfo.applicationInfo.packageName,
                    info.activityInfo.name);
        }

        return null;
    }

+3 −1
Original line number Diff line number Diff line
@@ -93,9 +93,11 @@ interface IVoiceInteractionManagerService {
     * Shows the session for the currently active service. Used to start a new session from system
     * affordances.
     *
     * @param args the bundle to pass as arguments to the voice interaction session
     * @param showCallback callback to be notified when the session was shown
     */
    void showSessionForActiveService(IVoiceInteractionSessionShowCallback showCallback);
    void showSessionForActiveService(in Bundle args,
            IVoiceInteractionSessionShowCallback showCallback);

    /**
     * Hides the session from the active service, if it is showing.
+1 −1
Original line number Diff line number Diff line
@@ -4419,7 +4419,7 @@ public class PhoneWindow extends Window implements MenuBuilder.Callback {
            Bundle args = new Bundle();
            args.putInt(Intent.EXTRA_ASSIST_INPUT_DEVICE_ID, event.getDeviceId());
            return ((SearchManager)getContext().getSystemService(Context.SEARCH_SERVICE))
                    .launchAssistAction(null, UserHandle.myUserId(), args);
                    .launchLegacyAssist(null, UserHandle.myUserId(), args);
        }
        return result;
    }
Loading