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

Commit 0af6fa70 authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Voice Interaction from within an Activity

This allows an app to show a voice search button
and invoke a voice interaction session for use
within the activity. Once the activity exits, the
session is stopped.

Test application has a new activity that
demonstrates it with the test voice interaction
service.

This initial version is functional enough for
an integration test, with some more tests
and improvements to come later.

Bug: 22791070
Change-Id: Ib1e5bc8cae1fde40570c999b9cf4bb29efe4916d
parent b9dd234a
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -1183,6 +1183,7 @@ package android {
    field public static final int summaryOn = 16843247; // 0x10101ef
    field public static final int supportsAssist = 16844016; // 0x10104f0
    field public static final int supportsLaunchVoiceAssistFromKeyguard = 16844017; // 0x10104f1
    field public static final int supportsLocalInteraction = 16844048; // 0x1010510
    field public static final int supportsPictureInPicture = 16844024; // 0x10104f8
    field public static final int supportsRtl = 16843695; // 0x10103af
    field public static final int supportsSwitchingToNextInputMethod = 16843755; // 0x10103eb
@@ -3436,6 +3437,7 @@ package android.app {
    method public boolean isDestroyed();
    method public boolean isFinishing();
    method public boolean isImmersive();
    method public boolean isLocalVoiceInteractionSupported();
    method public boolean isTaskRoot();
    method public boolean isVoiceInteraction();
    method public boolean isVoiceInteractionRoot();
@@ -3477,6 +3479,8 @@ package android.app {
    method public boolean onKeyMultiple(int, int, android.view.KeyEvent);
    method public boolean onKeyShortcut(int, android.view.KeyEvent);
    method public boolean onKeyUp(int, android.view.KeyEvent);
    method public void onLocalVoiceInteractionStarted();
    method public void onLocalVoiceInteractionStopped();
    method public void onLowMemory();
    method public boolean onMenuItemSelected(int, android.view.MenuItem);
    method public boolean onMenuOpened(int, android.view.Menu);
@@ -3591,12 +3595,14 @@ package android.app {
    method public void startIntentSenderForResult(android.content.IntentSender, int, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException;
    method public void startIntentSenderFromChild(android.app.Activity, android.content.IntentSender, int, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException;
    method public void startIntentSenderFromChild(android.app.Activity, android.content.IntentSender, int, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException;
    method public void startLocalVoiceInteraction(android.os.Bundle);
    method public void startLockTask();
    method public deprecated void startManagingCursor(android.database.Cursor);
    method public boolean startNextMatchingActivity(android.content.Intent);
    method public boolean startNextMatchingActivity(android.content.Intent, android.os.Bundle);
    method public void startPostponedEnterTransition();
    method public void startSearch(java.lang.String, boolean, android.os.Bundle, boolean);
    method public void stopLocalVoiceInteraction();
    method public void stopLockTask();
    method public deprecated void stopManagingCursor(android.database.Cursor);
    method public void takeKeyEvents(boolean);
@@ -34005,6 +34011,7 @@ package android.service.voice {
    method public void setTheme(int);
    method public void show(android.os.Bundle, int);
    method public void startVoiceActivity(android.content.Intent);
    field public static final int SHOW_SOURCE_ACTIVITY = 16; // 0x10
    field public static final int SHOW_SOURCE_APPLICATION = 8; // 0x8
    field public static final int SHOW_SOURCE_ASSIST_GESTURE = 4; // 0x4
    field public static final int SHOW_WITH_ASSIST = 1; // 0x1
+7 −0
Original line number Diff line number Diff line
@@ -1282,6 +1282,7 @@ package android {
    field public static final int summaryOn = 16843247; // 0x10101ef
    field public static final int supportsAssist = 16844016; // 0x10104f0
    field public static final int supportsLaunchVoiceAssistFromKeyguard = 16844017; // 0x10104f1
    field public static final int supportsLocalInteraction = 16844048; // 0x1010510
    field public static final int supportsPictureInPicture = 16844024; // 0x10104f8
    field public static final int supportsRtl = 16843695; // 0x10103af
    field public static final int supportsSwitchingToNextInputMethod = 16843755; // 0x10103eb
@@ -3551,6 +3552,7 @@ package android.app {
    method public boolean isDestroyed();
    method public boolean isFinishing();
    method public boolean isImmersive();
    method public boolean isLocalVoiceInteractionSupported();
    method public boolean isTaskRoot();
    method public boolean isVoiceInteraction();
    method public boolean isVoiceInteractionRoot();
@@ -3593,6 +3595,8 @@ package android.app {
    method public boolean onKeyMultiple(int, int, android.view.KeyEvent);
    method public boolean onKeyShortcut(int, android.view.KeyEvent);
    method public boolean onKeyUp(int, android.view.KeyEvent);
    method public void onLocalVoiceInteractionStarted();
    method public void onLocalVoiceInteractionStopped();
    method public void onLowMemory();
    method public boolean onMenuItemSelected(int, android.view.MenuItem);
    method public boolean onMenuOpened(int, android.view.Menu);
@@ -3707,12 +3711,14 @@ package android.app {
    method public void startIntentSenderForResult(android.content.IntentSender, int, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException;
    method public void startIntentSenderFromChild(android.app.Activity, android.content.IntentSender, int, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException;
    method public void startIntentSenderFromChild(android.app.Activity, android.content.IntentSender, int, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException;
    method public void startLocalVoiceInteraction(android.os.Bundle);
    method public void startLockTask();
    method public deprecated void startManagingCursor(android.database.Cursor);
    method public boolean startNextMatchingActivity(android.content.Intent);
    method public boolean startNextMatchingActivity(android.content.Intent, android.os.Bundle);
    method public void startPostponedEnterTransition();
    method public void startSearch(java.lang.String, boolean, android.os.Bundle, boolean);
    method public void stopLocalVoiceInteraction();
    method public void stopLockTask();
    method public deprecated void stopManagingCursor(android.database.Cursor);
    method public void takeKeyEvents(boolean);
@@ -36248,6 +36254,7 @@ package android.service.voice {
    method public void setTheme(int);
    method public void show(android.os.Bundle, int);
    method public void startVoiceActivity(android.content.Intent);
    field public static final int SHOW_SOURCE_ACTIVITY = 16; // 0x10
    field public static final int SHOW_SOURCE_APPLICATION = 8; // 0x8
    field public static final int SHOW_SOURCE_ASSIST_GESTURE = 4; // 0x4
    field public static final int SHOW_WITH_ASSIST = 1; // 0x1
+7 −0
Original line number Diff line number Diff line
@@ -1183,6 +1183,7 @@ package android {
    field public static final int summaryOn = 16843247; // 0x10101ef
    field public static final int supportsAssist = 16844016; // 0x10104f0
    field public static final int supportsLaunchVoiceAssistFromKeyguard = 16844017; // 0x10104f1
    field public static final int supportsLocalInteraction = 16844048; // 0x1010510
    field public static final int supportsPictureInPicture = 16844024; // 0x10104f8
    field public static final int supportsRtl = 16843695; // 0x10103af
    field public static final int supportsSwitchingToNextInputMethod = 16843755; // 0x10103eb
@@ -3436,6 +3437,7 @@ package android.app {
    method public boolean isDestroyed();
    method public boolean isFinishing();
    method public boolean isImmersive();
    method public boolean isLocalVoiceInteractionSupported();
    method public boolean isTaskRoot();
    method public boolean isVoiceInteraction();
    method public boolean isVoiceInteractionRoot();
@@ -3477,6 +3479,8 @@ package android.app {
    method public boolean onKeyMultiple(int, int, android.view.KeyEvent);
    method public boolean onKeyShortcut(int, android.view.KeyEvent);
    method public boolean onKeyUp(int, android.view.KeyEvent);
    method public void onLocalVoiceInteractionStarted();
    method public void onLocalVoiceInteractionStopped();
    method public void onLowMemory();
    method public boolean onMenuItemSelected(int, android.view.MenuItem);
    method public boolean onMenuOpened(int, android.view.Menu);
@@ -3591,12 +3595,14 @@ package android.app {
    method public void startIntentSenderForResult(android.content.IntentSender, int, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException;
    method public void startIntentSenderFromChild(android.app.Activity, android.content.IntentSender, int, android.content.Intent, int, int, int) throws android.content.IntentSender.SendIntentException;
    method public void startIntentSenderFromChild(android.app.Activity, android.content.IntentSender, int, android.content.Intent, int, int, int, android.os.Bundle) throws android.content.IntentSender.SendIntentException;
    method public void startLocalVoiceInteraction(android.os.Bundle);
    method public void startLockTask();
    method public deprecated void startManagingCursor(android.database.Cursor);
    method public boolean startNextMatchingActivity(android.content.Intent);
    method public boolean startNextMatchingActivity(android.content.Intent, android.os.Bundle);
    method public void startPostponedEnterTransition();
    method public void startSearch(java.lang.String, boolean, android.os.Bundle, boolean);
    method public void stopLocalVoiceInteraction();
    method public void stopLockTask();
    method public deprecated void stopManagingCursor(android.database.Cursor);
    method public void takeKeyEvents(boolean);
@@ -34019,6 +34025,7 @@ package android.service.voice {
    method public void setTheme(int);
    method public void show(android.os.Bundle, int);
    method public void startVoiceActivity(android.content.Intent);
    field public static final int SHOW_SOURCE_ACTIVITY = 16; // 0x10
    field public static final int SHOW_SOURCE_APPLICATION = 8; // 0x8
    field public static final int SHOW_SOURCE_ASSIST_GESTURE = 4; // 0x4
    field public static final int SHOW_WITH_ASSIST = 1; // 0x1
+65 −0
Original line number Diff line number Diff line
@@ -1267,6 +1267,15 @@ public class Activity extends ContextThemeWrapper
        mCalled = true;
    }

    void setVoiceInteractor(IVoiceInteractor voiceInteractor) {
        if (voiceInteractor == null) {
            mVoiceInteractor = null;
        } else {
            mVoiceInteractor = new VoiceInteractor(voiceInteractor, this, this,
                    Looper.myLooper());
        }
    }

    /**
     * Check whether this activity is running as part of a voice interaction with the user.
     * If true, it should perform its interaction with the user through the
@@ -1300,6 +1309,62 @@ public class Activity extends ContextThemeWrapper
        return mVoiceInteractor;
    }

    /**
     * Queries whether the currently enabled voice interaction service supports returning
     * a voice interactor for use by the activity. This is valid only for the duration of the
     * activity.
     *
     * @return whether the current voice interaction service supports local voice interaction
     */
    public boolean isLocalVoiceInteractionSupported() {
        try {
            return ActivityManagerNative.getDefault().supportsLocalVoiceInteraction();
        } catch (RemoteException re) {
        }
        return false;
    }

    /**
     * Starts a local voice interaction session. When ready,
     * {@link #onLocalVoiceInteractionStarted()} is called. You can pass a bundle of private options
     * to the registered voice interaction service.
     * @param privateOptions a Bundle of private arguments to the current voice interaction service
     */
    public void startLocalVoiceInteraction(Bundle privateOptions) {
        try {
            ActivityManagerNative.getDefault().startLocalVoiceInteraction(mToken, privateOptions);
        } catch (RemoteException re) {
        }
    }

    /**
     * Callback to indicate that {@link #startLocalVoiceInteraction(Bundle)} has resulted in a
     * voice interaction session being started. You can now retrieve a voice interactor using
     * {@link #getVoiceInteractor()}.
     */
    public void onLocalVoiceInteractionStarted() {
        Log.i(TAG, "onLocalVoiceInteractionStarted! " + getVoiceInteractor());
    }

    /**
     * Callback to indicate that the local voice interaction has stopped for some
     * reason.
     */
    public void onLocalVoiceInteractionStopped() {
        Log.i(TAG, "onLocalVoiceInteractionStopped :( " + getVoiceInteractor());
    }

    /**
     * Request to terminate the current voice interaction that was previously started
     * using {@link #startLocalVoiceInteraction(Bundle)}.
     */
    public void stopLocalVoiceInteraction() {
        try {
            ActivityManagerNative.getDefault().stopLocalVoiceInteraction(mToken);
        } catch (RemoteException re) {
        }
    }

    /**
     * This is called for activities that set launchMode to "singleTop" in
     * their package, or if a client used the {@link Intent#FLAG_ACTIVITY_SINGLE_TOP}
+8 −0
Original line number Diff line number Diff line
@@ -18,6 +18,10 @@ package android.app;

import android.annotation.NonNull;
import android.content.ComponentName;
import android.os.IBinder;
import android.service.voice.IVoiceInteractionSession;

import com.android.internal.app.IVoiceInteractor;

/**
 * Activity manager local system service interface.
@@ -64,4 +68,8 @@ public abstract class ActivityManagerInternal {
     * @param userId The user being cleaned up.
     */
    public abstract void onUserRemoved(int userId);

    public abstract void onLocalVoiceInteractionStarted(IBinder callingActivity,
            IVoiceInteractionSession mSession,
            IVoiceInteractor mInteractor);
}
Loading