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

Commit 509291c5 authored by Sandeep Bandaru's avatar Sandeep Bandaru Committed by Android (Google) Code Review
Browse files

Merge "Implement `onInferenceInfo` callback for `ProcessingCallback`" into main

parents fb587517 8b811b38
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
package android.app.ondeviceintelligence;

import android.app.ondeviceintelligence.InferenceInfo;
import android.os.PersistableBundle;
import android.os.Bundle;
import android.os.RemoteCallback;
@@ -13,4 +14,5 @@ oneway interface IResponseCallback {
    void onSuccess(in Bundle resultBundle) = 1;
    void onFailure(int errorCode, in String errorMessage, in PersistableBundle errorParams) = 2;
    void onDataAugmentRequest(in Bundle processedContent, in RemoteCallback responseCallback) = 3;
    void onInferenceInfo(in InferenceInfo info) = 4;
}
+2 −0
Original line number Diff line number Diff line
package android.app.ondeviceintelligence;

import android.app.ondeviceintelligence.InferenceInfo;
import android.os.PersistableBundle;
import android.os.RemoteCallback;
import android.os.Bundle;
@@ -15,4 +16,5 @@ oneway interface IStreamingResponseCallback {
    void onSuccess(in Bundle result) = 2;
    void onFailure(int errorCode, in String errorMessage, in PersistableBundle errorParams) = 3;
    void onDataAugmentRequest(in Bundle processedContent, in RemoteCallback responseCallback) = 4;
    void onInferenceInfo(in InferenceInfo info) = 5;
}
+25 −0
Original line number Diff line number Diff line
@@ -79,6 +79,16 @@ public final class OnDeviceIntelligenceManager {
    public static final String AUGMENT_REQUEST_CONTENT_BUNDLE_KEY =
            "AugmentRequestContentBundleKey";

    /**
     * The key for a boolean extra in the request {@link Bundle} to indicate if the caller wants to
     * receive {@link InferenceInfo} in the {@link ProcessingCallback#onInferenceInfo} callback.
     *
     * @hide
     */
    @SystemApi
    @FlaggedApi(FLAG_ON_DEVICE_INTELLIGENCE_25Q4)
    public static final String KEY_REQUEST_INFERENCE_INFO = "request_inference_info";

    private static final String TAG = "OnDeviceIntelligence";
    private final Context mContext;
    private final IOnDeviceIntelligenceManager mService;
@@ -440,6 +450,13 @@ public final class OnDeviceIntelligenceManager {
                                callbackExecutor.execute(() -> contentCallback.sendResult(bundle));
                            })));
                }

                @Override
                public void onInferenceInfo(InferenceInfo info) {
                    Binder.withCleanCallingIdentity(
                            () -> callbackExecutor.execute(
                                    () -> processingCallback.onInferenceInfo(info)));
                }
            };


@@ -525,6 +542,14 @@ public final class OnDeviceIntelligenceManager {
                                                () -> contentCallback.sendResult(bundle));
                                    })));
                }

                @Override
                public void onInferenceInfo(InferenceInfo info) {
                    Binder.withCleanCallingIdentity(() -> {
                        callbackExecutor.execute(
                                () -> streamingProcessingCallback.onInferenceInfo(info));
                    });
                }
            };

            mService.processRequestStreaming(
+15 −0
Original line number Diff line number Diff line
@@ -17,10 +17,12 @@
package android.app.ondeviceintelligence;

import static android.app.ondeviceintelligence.flags.Flags.FLAG_ENABLE_ON_DEVICE_INTELLIGENCE;
import static android.app.ondeviceintelligence.flags.Flags.FLAG_ON_DEVICE_INTELLIGENCE_25Q4;

import android.annotation.FlaggedApi;
import android.annotation.NonNull;
import android.annotation.SystemApi;
import android.app.ondeviceintelligence.InferenceInfo;
import android.os.Bundle;
import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.InferenceParams;
import android.app.ondeviceintelligence.OnDeviceIntelligenceManager.ResponseParams;
@@ -69,4 +71,17 @@ public interface ProcessingCallback {
            @NonNull Consumer<@InferenceParams Bundle> contentConsumer) {
        contentConsumer.accept(Bundle.EMPTY);
    }

    /**
     * Invoked when inference info is available for the given request.
     * This callback is invoked only when the
     * {@link OnDeviceIntelligenceManager#KEY_REQUEST_INFERENCE_INFO}
     * is set to true in the associated request {@link Bundle}.
     *
     * @param info the inference info associated with the request.
     * @see InferenceInfo
     */
    @FlaggedApi(FLAG_ON_DEVICE_INTELLIGENCE_25Q4)
    default void onInferenceInfo(@NonNull InferenceInfo info) {
    }
}
+19 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import android.annotation.SuppressLint;
import android.annotation.SystemApi;
import android.app.Service;
import android.app.ondeviceintelligence.Feature;
import android.app.ondeviceintelligence.InferenceInfo;
import android.app.ondeviceintelligence.IProcessingSignal;
import android.app.ondeviceintelligence.IResponseCallback;
import android.app.ondeviceintelligence.IStreamingResponseCallback;
@@ -532,6 +533,15 @@ public abstract class OnDeviceSandboxedInferenceService extends Service {
                    Slog.e(TAG, "Error sending augment request: " + e);
                }
            }

            @Override
            public void onInferenceInfo(@NonNull InferenceInfo info) {
                try {
                    callback.onInferenceInfo(info);
                } catch (RemoteException e) {
                    Slog.e(TAG, "Error sending inference info: " + e);
                }
            }
        };
    }

@@ -577,6 +587,15 @@ public abstract class OnDeviceSandboxedInferenceService extends Service {
                    Slog.e(TAG, "Error sending augment request: " + e);
                }
            }

            @Override
            public void onInferenceInfo(@NonNull InferenceInfo info) {
                try {
                    callback.onInferenceInfo(info);
                } catch (RemoteException e) {
                    Slog.e(TAG, "Error sending inference info: " + e);
                }
            }
        };
    }

Loading