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

Commit 5a24dadd authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Adding overload for listFeatures to pass filterParams" into main

parents 05342b9a b635d0e6
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@
  *
  * @hide
  */
// Next available field id: 12
interface IOnDeviceIntelligenceManager {
      @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE)")
      void getVersion(in RemoteCallback remoteCallback) = 1;
@@ -51,6 +52,11 @@ interface IOnDeviceIntelligenceManager {
      @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE)")
      void listFeatures(in IListFeaturesCallback listFeaturesCallback) = 3;

      @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE)")
      @JavaPassthrough(annotation="@android.annotation.FlaggedApi(android.app.ondeviceintelligence.flags.Flags.FLAG_ON_DEVICE_INTELLIGENCE_25Q4)")
      void listFeaturesWithFilter(in PersistableBundle featureParamsFilter,
            in IListFeaturesCallback listFeaturesCallback) = 11;

      @JavaPassthrough(annotation="@android.annotation.RequiresPermission(android.Manifest.permission.USE_ON_DEVICE_INTELLIGENCE)")
      void getFeatureDetails(in Feature feature, in IFeatureDetailsCallback featureDetailsCallback) = 4;

+40 −0
Original line number Diff line number Diff line
@@ -203,6 +203,46 @@ public final class OnDeviceIntelligenceManager {
        }
    }

    /**
     * Asynchronously get a list of features that are supported for the caller, with an option to
     * filter the features based on the provided params.
     *
     * @param featureParamsFilter params to be used for filtering the features.
     * @param callbackExecutor    executor to run the callback on.
     * @param featureListReceiver callback to populate the list of features.
     */
    @RequiresPermission(Manifest.permission.USE_ON_DEVICE_INTELLIGENCE)
    @FlaggedApi(FLAG_ON_DEVICE_INTELLIGENCE_25Q4)
    public void listFeatures(
            @NonNull PersistableBundle featureParamsFilter,
            @NonNull @CallbackExecutor Executor callbackExecutor,
            @NonNull OutcomeReceiver<List<Feature>,
                    OnDeviceIntelligenceException> featureListReceiver) {
        try {
            IListFeaturesCallback callback =
                    new IListFeaturesCallback.Stub() {
                        @Override
                        public void onSuccess(List<Feature> result) {
                            Binder.withCleanCallingIdentity(() -> callbackExecutor.execute(
                                    () -> featureListReceiver.onResult(result)));
                        }

                        @Override
                        public void onFailure(int errorCode, String errorMessage,
                                PersistableBundle errorParams) {
                            Binder.withCleanCallingIdentity(() -> callbackExecutor.execute(
                                    () -> featureListReceiver.onError(
                                            new OnDeviceIntelligenceException(
                                                    errorCode, errorMessage, errorParams))));
                        }
                    };
            mService.listFeaturesWithFilter(featureParamsFilter, callback);
        } catch (RemoteException e) {
            throw e.rethrowFromSystemServer();
        }
    }


    /**
     * This method should be used to fetch details about a feature which need some additional
     * computation, that can be inefficient to return in all calls to {@link #getFeature}. Callers
+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ oneway interface IOnDeviceIntelligenceService {
    void getVersion(in RemoteCallback remoteCallback);
    void getFeature(int callerUid, int featureId, in IFeatureCallback featureCallback);
    void listFeatures(int callerUid, in IListFeaturesCallback listFeaturesCallback);
    void listFeaturesWithFilter(int callerUid, in PersistableBundle featureParamsFilter,
            in IListFeaturesCallback listFeaturesCallback);
    void getFeatureDetails(int callerUid, in Feature feature, in IFeatureDetailsCallback featureDetailsCallback);
    void getReadOnlyFileDescriptor(in String fileName, in AndroidFuture<ParcelFileDescriptor> future);
    void getReadOnlyFeatureFileDescriptorMap(in Feature feature, in RemoteCallback remoteCallback);
+31 −0
Original line number Diff line number Diff line
@@ -158,6 +158,20 @@ public abstract class OnDeviceIntelligenceService extends Service {
                                    wrapListFeaturesCallback(listFeaturesCallback)));
                }

                @Override
                public void listFeaturesWithFilter(int callerUid,
                        PersistableBundle featureParamsFilter,
                        IListFeaturesCallback listFeaturesCallback) {
                    Objects.requireNonNull(featureParamsFilter);
                    Objects.requireNonNull(listFeaturesCallback);
                    mHandler.executeOrSendMessage(
                            obtainMessage(
                                    OnDeviceIntelligenceService::onListFeatures,
                                    OnDeviceIntelligenceService.this, callerUid,
                                    featureParamsFilter,
                                    wrapListFeaturesCallback(listFeaturesCallback)));
                }

                @Override
                public void getFeature(int callerUid, int id, IFeatureCallback featureCallback) {
                    Objects.requireNonNull(featureCallback);
@@ -567,6 +581,23 @@ public abstract class OnDeviceIntelligenceService extends Service {
    public abstract void onListFeatures(int callerUid, @NonNull OutcomeReceiver<List<Feature>,
            OnDeviceIntelligenceException> listFeaturesCallback);

    /**
     * List all features which are available in the remote implementation which match the given
     * filter. The implementation might choose to provide only a certain list of features based on
     * the caller.
     *
     * @param callerUid            UID of the caller that initiated this call chain.
     * @param featureParamsFilter  params to filter the features.
     * @param listFeaturesCallback callback to populate the features list.
     */
    @FlaggedApi(FLAG_ON_DEVICE_INTELLIGENCE_25Q4)
    public void onListFeatures(int callerUid,
            @NonNull PersistableBundle featureParamsFilter,
            @NonNull OutcomeReceiver<List<Feature>,
                    OnDeviceIntelligenceException> listFeaturesCallback) {
    }


    /**
     * Provides a long value representing the version of the remote implementation processing
     * requests.
+44 −0
Original line number Diff line number Diff line
@@ -325,6 +325,50 @@ public class OnDeviceIntelligenceManagerService extends SystemService {
                        });
            }

            @Override
            public void listFeaturesWithFilter(PersistableBundle featureParamsFilter,
                    IListFeaturesCallback listFeaturesCallback)
                    throws RemoteException {
                Slog.i(TAG, "OnDeviceIntelligenceManagerInternal listFeaturesWithFilter");
                Objects.requireNonNull(featureParamsFilter);
                Objects.requireNonNull(listFeaturesCallback);
                mContext.enforceCallingPermission(
                        Manifest.permission.USE_ON_DEVICE_INTELLIGENCE, TAG);
                if (!mIsServiceEnabled) {
                    Slog.w(TAG, "Service not available");
                    listFeaturesCallback.onFailure(
                        OnDeviceIntelligenceException.ON_DEVICE_INTELLIGENCE_SERVICE_UNAVAILABLE,
                        "OnDeviceIntelligenceManagerService is unavailable",
                        PersistableBundle.EMPTY);
                    return;
                }
                ensureRemoteIntelligenceServiceInitialized();
                int callerUid = Binder.getCallingUid();
                mRemoteOnDeviceIntelligenceService.postAsync(
                        service -> {
                            AndroidFuture future = new AndroidFuture();
                            service.listFeaturesWithFilter(callerUid, featureParamsFilter,
                                    new IListFeaturesCallback.Stub() {
                                        @Override
                                        public void onSuccess(List<Feature> result)
                                                throws RemoteException {
                                            listFeaturesCallback.onSuccess(result);
                                            future.complete(null);
                                        }

                                        @Override
                                        public void onFailure(int errorCode, String errorMessage,
                                                PersistableBundle errorParams)
                                                throws RemoteException {
                                            listFeaturesCallback.onFailure(errorCode, errorMessage,
                                                    errorParams);
                                            future.completeExceptionally(new TimeoutException());
                                        }
                                    });
                            return future.orTimeout(getIdleTimeoutMs(), TimeUnit.MILLISECONDS);
                        });
            }

            @Override
            public void getFeatureDetails(Feature feature,
                    IFeatureDetailsCallback featureDetailsCallback)