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

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

Merge changes from topic...

Merge changes from topic "revert-34326798-revert-34253595-odi-q4-updateProcessKeys-EYLOFWYJAI-BKHVQIYXWS" into main

* changes:
  Move `sanitizeStateParams` ahead of Bundle modifications
  Revert "Revert "Added constants class for Bundle keys used in `#..."
parents fd2c3657 9be540ab
Loading
Loading
Loading
Loading
+23 −4
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.app.ondeviceintelligence.OnDeviceIntelligenceManager.AUGME
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 static android.app.ondeviceintelligence.flags.Flags.FLAG_ON_DEVICE_INTELLIGENCE_25Q4;
import static com.android.internal.util.function.pooled.PooledLambda.obtainMessage;

import android.annotation.CallSuper;
@@ -147,11 +146,26 @@ public abstract class OnDeviceSandboxedInferenceService extends Service {
     */
    public static final String MODEL_UNLOADED_BROADCAST_INTENT =
        "android.service.ondeviceintelligence.MODEL_UNLOADED";

    /**
     * Defines keys for the {@link #updateProcessingState(Bundle, OutcomeReceiver)}
     * bundle in {@link #onUpdateProcessingState(Bundle, OutcomeReceiver)}.
     *
     * @hide
     */
    public static final String DEVICE_CONFIG_UPDATE_BUNDLE_KEY = "device_config_update";
    @FlaggedApi(FLAG_ON_DEVICE_INTELLIGENCE_25Q4)
    @SystemApi
    public static final class UpdateProcessingStateKeys {
        private UpdateProcessingStateKeys() {}

        /**
         * Key for the {@code processingState} bundle in
         * {@link #onUpdateProcessingState(Bundle, OutcomeReceiver)}, where the value is a
         * {@link PersistableBundle} containing the device config flags matching the
         * configured device-config namespace under
         * {@link R.string.config_defaultOnDeviceIntelligenceDeviceConfigNamespace}.
         */
        public static final String KEY_DEVICE_CONFIG_UPDATE = "device_config_update";
    }

    /**
     * Listener for inference service lifecycle events.
@@ -411,7 +425,12 @@ public abstract class OnDeviceSandboxedInferenceService extends Service {
     * configuration, files or state.
     *
     * @param processingState contains updated state and params that are to be applied to the
     *                        processing environmment,
     *                        processing environment.
     *                        The expected keys are constants defined
     *                        in {@link UpdateProcessingStateKeys}.
     *                        There can be other custom keys sent via
     *                        {@link OnDeviceIntelligenceService} but these would be
     *                        specific to configured remote package implementation.
     * @param callback        callback to populate the update status and if there are params
     *                        associated with the status.
     */
+1 −0
Original line number Diff line number Diff line
@@ -153,6 +153,7 @@ public class BundleUtil {
     * description.
     *
     * @throws BadParcelableException when the bundle does not meet the read-only requirements.
     * TODO: b/429180295 - Change to custom exception so callers are forced to handle it.
     */
    public static void sanitizeStateParams(
            @StateParams Bundle bundle) {
+16 −14
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@

package com.android.server.ondeviceintelligence;

import static android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService.DEVICE_CONFIG_UPDATE_BUNDLE_KEY;
import static android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService.UpdateProcessingStateKeys.KEY_DEVICE_CONFIG_UPDATE;
import static android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService.MODEL_LOADED_BUNDLE_KEY;
import static android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService.MODEL_UNLOADED_BUNDLE_KEY;
import static android.service.ondeviceintelligence.OnDeviceSandboxedInferenceService.MODEL_LOADED_BROADCAST_INTENT;
@@ -732,10 +732,12 @@ public class OnDeviceIntelligenceManagerService extends SystemService {
            public void updateProcessingState(
                    Bundle processingState,
                    IProcessingUpdateStatusCallback callback) {
              sanitizeStateParams(processingState);
              callbackExecutor.execute(() -> {
                    AndroidFuture<Void> result = null;
                    try {
                        sanitizeStateParams(processingState);
                        // Reserved for use by system-server.
                        processingState.remove(KEY_DEVICE_CONFIG_UPDATE);
                        ensureRemoteInferenceServiceInitialized();
                        result = mRemoteInferenceService.post(
                                service -> service.updateProcessingState(
@@ -898,7 +900,7 @@ public class OnDeviceIntelligenceManagerService extends SystemService {
            persistableBundle.putString(key, props.getString(key, ""));
        }
        Bundle bundle = new Bundle();
        bundle.putParcelable(DEVICE_CONFIG_UPDATE_BUNDLE_KEY, persistableBundle);
        bundle.putParcelable(KEY_DEVICE_CONFIG_UPDATE, persistableBundle);
        ensureRemoteInferenceServiceInitialized();
        mRemoteInferenceService.run(service -> service.updateProcessingState(
                bundle,