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

Commit eb22efaa authored by Charles Chen's avatar Charles Chen
Browse files

Allow disk read for VisualQueryDetectionService

Allow isolated process to read the files from applications internal storage via read-only mmap channel.

Bug: 289185455
Test: Manual && atest CtsVoiceInteractionTestCases
Change-Id: I47538463be549e693882bccbf91264341ce91754
parent 86ada35b
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IHotwordRecognitionStatusCallback;
import com.android.internal.app.IVoiceInteractionManagerService;
import com.android.internal.app.IVoiceInteractionSoundTriggerSession;
import com.android.internal.infra.AndroidFuture;

import java.io.PrintWriter;
import java.lang.annotation.Retention;
@@ -1710,6 +1711,11 @@ public class AlwaysOnHotwordDetector extends AbstractDetector {
            Slog.i(TAG, "onProcessRestarted");
            mHandler.sendEmptyMessage(MSG_PROCESS_RESTARTED);
        }

        @Override
        public void onOpenFile(String filename, AndroidFuture future) throws RemoteException {
            throw new UnsupportedOperationException("Hotword cannot access files from the disk.");
        }
    }

    void onDetectorRemoteException() {
+6 −0
Original line number Diff line number Diff line
@@ -227,6 +227,12 @@ public abstract class HotwordDetectionService extends Service
        public void stopDetection() {
            HotwordDetectionService.this.onStopDetection();
        }

        @Override
        public void registerRemoteStorageService(IDetectorSessionStorageService
                detectorSessionStorageService) {
            throw new UnsupportedOperationException("Hotword cannot access files from the disk.");
        }
    };

    @Override
+30 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.service.voice;

import com.android.internal.infra.AndroidFuture;

/**
 * @hide
 */
oneway interface IDetectorSessionStorageService {
    /**
     * Called when a file open request is sent. Only files with the given names under the internal
     * app storage, i.e., {@link Context#getFilesDir()} can be opened.
     */
    void openFile(in String filename, in AndroidFuture future);
}
+7 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.os.IRemoteCallback;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.SharedMemory;
import android.service.voice.IDetectorSessionStorageService;
import android.service.voice.IDetectorSessionVisualQueryDetectionCallback;
import android.service.voice.IDspHotwordDetectionCallback;
import android.view.contentcapture.IContentCaptureManager;
@@ -71,4 +72,10 @@ oneway interface ISandboxedDetectionService {
    void ping(in IRemoteCallback callback);

    void stopDetection();

    /**
     * Registers the interface stub to talk to the voice interaction service for initialization/
     * detection unrelated functionalities.
     */
    void registerRemoteStorageService(in IDetectorSessionStorageService detectorSessionStorageService);
}
+6 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.util.Slog;

import com.android.internal.app.IHotwordRecognitionStatusCallback;
import com.android.internal.app.IVoiceInteractionManagerService;
import com.android.internal.infra.AndroidFuture;

import java.io.PrintWriter;
import java.util.concurrent.Executor;
@@ -302,6 +303,11 @@ class SoftwareHotwordDetector extends AbstractDetector {
            Binder.withCleanCallingIdentity(() -> mExecutor.execute(
                    () -> mCallback.onHotwordDetectionServiceRestarted()));
        }

        @Override
        public void onOpenFile(String filename, AndroidFuture future) throws RemoteException {
            throw new UnsupportedOperationException("Hotword cannot access files from the disk.");
        }
    }

    /** @hide */
Loading