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

Commit 32c0da21 authored by Ivan Chiang's avatar Ivan Chiang
Browse files

[VoiceInteraction] Add two callbacks to notify the client side

Notify the client side when the system preapres to show session.
Notfiy the client side when show session failed

Test: atest CtsVoiceInteractionTestCases
Bug: 236104300
Change-Id: Iac916cd2b28efbd015245636ec890e054f9f0d00
parent 33eca2dd
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -40503,7 +40503,9 @@ package android.service.voice {
    method public android.os.IBinder onBind(android.content.Intent);
    method @NonNull public java.util.Set<java.lang.String> onGetSupportedVoiceActions(@NonNull java.util.Set<java.lang.String>);
    method public void onLaunchVoiceAssistFromKeyguard();
    method public void onPrepareToShowSession(@NonNull android.os.Bundle, int);
    method public void onReady();
    method public void onShowSessionFailed();
    method public void onShutdown();
    method public void setDisabledShowContext(int);
    method public final void setUiHints(@NonNull android.os.Bundle);
+4 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.service.voice;

import android.os.Bundle;

import com.android.internal.app.IVoiceActionCheckCallback;

/**
@@ -28,4 +30,6 @@ oneway interface IVoiceInteractionService {
    void launchVoiceAssistFromKeyguard();
    void getActiveServiceSupportedActions(in List<String> voiceActions,
     in IVoiceActionCheckCallback callback);
    void prepareToShowSession(in Bundle args, int flags);
    void showSessionFailed();
}
+39 −0
Original line number Diff line number Diff line
@@ -160,6 +160,20 @@ public class VoiceInteractionService extends Service {
                            voiceActions,
                            callback));
        }

        @Override
        public void prepareToShowSession(Bundle args, int flags) {
            Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage(
                    VoiceInteractionService::onPrepareToShowSession,
                    VoiceInteractionService.this, args, flags));
        }

        @Override
        public void showSessionFailed() {
            Handler.getMain().executeOrSendMessage(PooledLambda.obtainMessage(
                    VoiceInteractionService::onShowSessionFailed,
                    VoiceInteractionService.this));
        }
    };

    IVoiceInteractionManagerService mSystemService;
@@ -183,6 +197,31 @@ public class VoiceInteractionService extends Service {
    public void onLaunchVoiceAssistFromKeyguard() {
    }

    /**
     * Notify the interactor when the system prepares to show session. The system is going to
     * bind the session service.
     *
     * @param args  The arguments that were supplied to {@link #showSession(Bundle, int)}.
     * @param flags The show flags originally provided to {@link #showSession(Bundle, int)}.
     * @see #showSession(Bundle, int)
     * @see #onShowSessionFailed()
     * @see VoiceInteractionSession#onShow(Bundle, int)
     * @see VoiceInteractionSession#show(Bundle, int)
     */
    public void onPrepareToShowSession(@NonNull Bundle args, int flags) {
    }

    /**
     * Called when the show session failed. E.g. When the system bound the session service failed.
     *
     * @see #showSession(Bundle, int)
     * @see #onPrepareToShowSession(Bundle, int)
     * @see VoiceInteractionSession#onShow(Bundle, int)
     * @see VoiceInteractionSession#show(Bundle, int)
     */
    public void onShowSessionFailed() {
    }

    /**
     * Check whether the given service component is the currently active
     * VoiceInteractionService.
+18 −0
Original line number Diff line number Diff line
@@ -251,11 +251,29 @@ class VoiceInteractionManagerServiceImpl implements VoiceInteractionSessionConne
            @Nullable String attributionTag,
            @Nullable IVoiceInteractionSessionShowCallback showCallback,
            @Nullable IBinder activityToken) {
        try {
            if (mService != null) {
                mService.prepareToShowSession(args, flags);
            }
        } catch (RemoteException e) {
            Slog.w(TAG, "RemoteException while calling prepareToShowSession", e);
        }

        if (mActiveSession == null) {
            mActiveSession = new VoiceInteractionSessionConnection(mServiceStub,
                    mSessionComponentName, mUser, mContext, this,
                    mInfo.getServiceInfo().applicationInfo.uid, mHandler);
        }
        if (!mActiveSession.mBound) {
            try {
                if (mService != null) {
                    mService.showSessionFailed();
                }
            } catch (RemoteException e) {
                Slog.w(TAG, "RemoteException while calling showSessionFailed", e);
            }
        }

        List<ActivityAssistInfo> allVisibleActivities =
                LocalServices.getService(ActivityTaskManagerInternal.class)
                        .getTopVisibleActivities();