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

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

Merge changes from topic "unbind-id" into main

* changes:
  Add logic to unbind based on callback completions
  Add unbind timeout based on secure settings values
  Adding secure setting keys to enable setting the timeout values for both ondeviceintelligence services
parents 7cc9eae1 19b56ffb
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -11172,6 +11172,35 @@ public final class Settings {
        public static final String VISUAL_QUERY_ACCESSIBILITY_DETECTION_ENABLED =
                "visual_query_accessibility_detection_enabled";
        /**
         * Timeout to be used for unbinding to the configured remote
         * {@link android.service.ondeviceintelligence.OnDeviceIntelligenceService} if there are no
         * requests in the queue. A value of -1 represents to never unbind.
         *
         * @hide
         */
        public static final String ON_DEVICE_INTELLIGENCE_UNBIND_TIMEOUT_MS =
                "on_device_intelligence_unbind_timeout_ms";
        /**
         * Timeout that represents maximum idle time before which a callback should be populated.
         *
         * @hide
         */
        public static final String ON_DEVICE_INTELLIGENCE_IDLE_TIMEOUT_MS =
                "on_device_intelligence_idle_timeout_ms";
        /**
         * Timeout to be used for unbinding to the configured remote
         * {@link android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService} if there
         * are no requests in the queue. A value of -1 represents to never unbind.
         *
         * @hide
         */
        public static final String ON_DEVICE_INFERENCE_UNBIND_TIMEOUT_MS =
                "on_device_inference_unbind_timeout_ms";
        /**
         * Control whether Night display is currently activated.
         * @hide
+4 −1
Original line number Diff line number Diff line
@@ -274,6 +274,9 @@ public class SecureSettings {
        Settings.Secure.SCREEN_RESOLUTION_MODE,
        Settings.Secure.ACCESSIBILITY_GESTURE_TARGETS,
        Settings.Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL,
        Settings.Secure.CHARGE_OPTIMIZATION_MODE
        Settings.Secure.CHARGE_OPTIMIZATION_MODE,
        Settings.Secure.ON_DEVICE_INTELLIGENCE_UNBIND_TIMEOUT_MS,
        Settings.Secure.ON_DEVICE_INFERENCE_UNBIND_TIMEOUT_MS,
        Settings.Secure.ON_DEVICE_INTELLIGENCE_IDLE_TIMEOUT_MS,
    };
}
+4 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.provider.settings.validators;

import static android.provider.settings.validators.SettingsValidators.ACCESSIBILITY_SHORTCUT_TARGET_LIST_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.ANY_INTEGER_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.ANY_LONG_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.ANY_STRING_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.AUTOFILL_SERVICE_VALIDATOR;
import static android.provider.settings.validators.SettingsValidators.BOOLEAN_VALIDATOR;
@@ -433,5 +434,8 @@ public class SecureSettingsValidators {
        VALIDATORS.put(Secure.ACCESSIBILITY_DISPLAY_DALTONIZER_SATURATION_LEVEL,
                new InclusiveIntegerRangeValidator(0, 10));
        VALIDATORS.put(Secure.CHARGE_OPTIMIZATION_MODE, new InclusiveIntegerRangeValidator(0, 10));
        VALIDATORS.put(Secure.ON_DEVICE_INFERENCE_UNBIND_TIMEOUT_MS, ANY_LONG_VALIDATOR);
        VALIDATORS.put(Secure.ON_DEVICE_INTELLIGENCE_UNBIND_TIMEOUT_MS, ANY_LONG_VALIDATOR);
        VALIDATORS.put(Secure.ON_DEVICE_INTELLIGENCE_IDLE_TIMEOUT_MS, NONE_NEGATIVE_LONG_VALIDATOR);
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -239,6 +239,18 @@ public class SettingsValidators {
        }
    };

    static final Validator ANY_LONG_VALIDATOR = value -> {
        if (value == null) {
            return true;
        }
        try {
            Long.parseLong(value);
            return true;
        } catch (NumberFormatException e) {
            return false;
        }
    };

    static final Validator CREDENTIAL_SERVICE_VALIDATOR = new Validator() {
        @Override
        public boolean validate(String value) {
+15 −3
Original line number Diff line number Diff line
@@ -41,7 +41,10 @@ import android.system.ErrnoException;
import android.system.Os;
import android.util.Log;

import com.android.internal.infra.AndroidFuture;

import java.util.concurrent.Executor;
import java.util.concurrent.TimeoutException;

/**
 * Util methods for ensuring the Bundle passed in various methods are read-only and restricted to
@@ -183,7 +186,8 @@ public class BundleUtil {

    public static IStreamingResponseCallback wrapWithValidation(
            IStreamingResponseCallback streamingResponseCallback,
            Executor resourceClosingExecutor) {
            Executor resourceClosingExecutor,
            AndroidFuture future) {
        return new IStreamingResponseCallback.Stub() {
            @Override
            public void onNewContent(Bundle processedResult) throws RemoteException {
@@ -203,6 +207,7 @@ public class BundleUtil {
                    streamingResponseCallback.onSuccess(resultBundle);
                } finally {
                    resourceClosingExecutor.execute(() -> tryCloseResource(resultBundle));
                    future.complete(null);
                }
            }

@@ -210,6 +215,7 @@ public class BundleUtil {
            public void onFailure(int errorCode, String errorMessage,
                    PersistableBundle errorParams) throws RemoteException {
                streamingResponseCallback.onFailure(errorCode, errorMessage, errorParams);
                future.completeExceptionally(new TimeoutException());
            }

            @Override
@@ -237,7 +243,8 @@ public class BundleUtil {
    }

    public static IResponseCallback wrapWithValidation(IResponseCallback responseCallback,
            Executor resourceClosingExecutor) {
            Executor resourceClosingExecutor,
            AndroidFuture future) {
        return new IResponseCallback.Stub() {
            @Override
            public void onSuccess(Bundle resultBundle)
@@ -247,6 +254,7 @@ public class BundleUtil {
                    responseCallback.onSuccess(resultBundle);
                } finally {
                    resourceClosingExecutor.execute(() -> tryCloseResource(resultBundle));
                    future.complete(null);
                }
            }

@@ -254,6 +262,7 @@ public class BundleUtil {
            public void onFailure(int errorCode, String errorMessage,
                    PersistableBundle errorParams) throws RemoteException {
                responseCallback.onFailure(errorCode, errorMessage, errorParams);
                future.completeExceptionally(new TimeoutException());
            }

            @Override
@@ -280,17 +289,20 @@ public class BundleUtil {
    }


    public static ITokenInfoCallback wrapWithValidation(ITokenInfoCallback responseCallback) {
    public static ITokenInfoCallback wrapWithValidation(ITokenInfoCallback responseCallback,
            AndroidFuture future) {
        return new ITokenInfoCallback.Stub() {
            @Override
            public void onSuccess(TokenInfo tokenInfo) throws RemoteException {
                responseCallback.onSuccess(tokenInfo);
                future.complete(null);
            }

            @Override
            public void onFailure(int errorCode, String errorMessage, PersistableBundle errorParams)
                    throws RemoteException {
                responseCallback.onFailure(errorCode, errorMessage, errorParams);
                future.completeExceptionally(new TimeoutException());
            }
        };
    }
Loading