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

Commit f3284257 authored by Ahaan Ugale's avatar Ahaan Ugale Committed by Android (Google) Code Review
Browse files

Merge "VoiceInteraction: Handle session delivery failure." into sc-dev

parents d7a26390 4d8bb5d0
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package android.service.voice;

import android.os.Bundle;

import android.service.voice.IVoiceInteractionSession;

/**
 * @hide
 */
+19 −2
Original line number Diff line number Diff line
@@ -21,11 +21,14 @@ import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.util.Log;

import com.android.internal.app.IVoiceInteractionManagerService;
import com.android.internal.os.HandlerCaller;
import com.android.internal.os.SomeArgs;
@@ -38,6 +41,8 @@ import java.io.PrintWriter;
 */
public abstract class VoiceInteractionSessionService extends Service {

    private static final String TAG = "VoiceInteractionSession";

    static final int MSG_NEW_SESSION = 1;

    IVoiceInteractionManagerService mSystemService;
@@ -120,10 +125,22 @@ public abstract class VoiceInteractionSessionService extends Service {
            mSession = null;
        }
        mSession = onNewSession(args);
        try {
            mSystemService.deliverNewSession(token, mSession.mSession, mSession.mInteractor);
        if (deliverSession(token)) {
            mSession.doCreate(mSystemService, token);
        } else {
            // TODO(b/178777121): Add an onError() method to let the application know what happened.
            mSession.doDestroy();
            mSession = null;
        }
    }

    private boolean deliverSession(IBinder token) {
        try {
            return mSystemService.deliverNewSession(token, mSession.mSession, mSession.mInteractor);
        } catch (DeadObjectException ignored) {
        } catch (RemoteException e) {
            Log.e(TAG, "Failed to deliver session: " + e);
        }
        return false;
    }
}