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

Commit 58f920e0 authored by lpeter's avatar lpeter
Browse files

Use the PersistableBundle instead of the Bundle

It will be more secure to use PersistableBundle
instead of Bundle for passing the configrations
data from VoiceInteractor to HotwordDetectionService.

Bug: 176938300
Test: Test: atest CtsVoiceInteractionTestCases
Test: atest CtsVoiceInteractionTestCases --instant
Change-Id: I19a412cca5e2cd5f9f79a112a9d7da8fd3a00a38
parent 04678587
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -10372,7 +10372,7 @@ package android.service.voice {
    ctor public HotwordDetectionService();
    method @Nullable public final android.os.IBinder onBind(@NonNull android.content.Intent);
    method public void onDetectFromDspSource(@NonNull android.os.ParcelFileDescriptor, @NonNull android.media.AudioFormat, long, @NonNull android.service.voice.HotwordDetectionService.DspHotwordDetectionCallback);
    method public void onUpdateState(@Nullable android.os.Bundle, @Nullable android.os.SharedMemory);
    method public void onUpdateState(@Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory);
    field public static final String SERVICE_INTERFACE = "android.service.voice.HotwordDetectionService";
  }
@@ -10397,7 +10397,7 @@ package android.service.voice {
  public class VoiceInteractionService extends android.app.Service {
    method @NonNull public final android.service.voice.AlwaysOnHotwordDetector createAlwaysOnHotwordDetector(String, java.util.Locale, android.service.voice.AlwaysOnHotwordDetector.Callback);
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION) public final android.service.voice.AlwaysOnHotwordDetector createAlwaysOnHotwordDetector(String, java.util.Locale, @Nullable android.os.Bundle, @Nullable android.os.SharedMemory, android.service.voice.AlwaysOnHotwordDetector.Callback);
    method @NonNull @RequiresPermission(android.Manifest.permission.MANAGE_HOTWORD_DETECTION) public final android.service.voice.AlwaysOnHotwordDetector createAlwaysOnHotwordDetector(String, java.util.Locale, @Nullable android.os.PersistableBundle, @Nullable android.os.SharedMemory, android.service.voice.AlwaysOnHotwordDetector.Callback);
    method @NonNull @RequiresPermission("android.permission.MANAGE_VOICE_KEYPHRASES") public final android.media.voice.KeyphraseModelManager createKeyphraseModelManager();
  }
+7 −7
Original line number Diff line number Diff line
@@ -41,10 +41,10 @@ import android.media.permission.Identity;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.SharedMemory;
import android.util.Slog;
@@ -494,8 +494,8 @@ public class AlwaysOnHotwordDetector {
     * @param supportHotwordDetectionService {@code true} if hotword detection service should be
     * triggered, otherwise {@code false}.
     * @param options Application configuration data provided by the
     * {@link VoiceInteractionService}. The system strips out any remotable objects or other
     * contents that can be used to communicate with other processes.
     * {@link VoiceInteractionService}. PersistableBundle does not allow any remotable objects or
     * other contents that can be used to communicate with other processes.
     * @param sharedMemory The unrestricted data blob provided by the
     * {@link VoiceInteractionService}. Use this to provide the hotword models data or other
     * such data to the trusted process.
@@ -505,7 +505,7 @@ public class AlwaysOnHotwordDetector {
    public AlwaysOnHotwordDetector(String text, Locale locale, Callback callback,
            KeyphraseEnrollmentInfo keyphraseEnrollmentInfo,
            IVoiceInteractionManagerService modelManagementService, int targetSdkVersion,
            boolean supportHotwordDetectionService, @Nullable Bundle options,
            boolean supportHotwordDetectionService, @Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory) {
        mText = text;
        mLocale = locale;
@@ -534,8 +534,8 @@ public class AlwaysOnHotwordDetector {
     * Set configuration and pass read-only data to hotword detection service.
     *
     * @param options Application configuration data provided by the
     * {@link VoiceInteractionService}. The system strips out any remotable objects or other
     * contents that can be used to communicate with other processes.
     * {@link VoiceInteractionService}. PersistableBundle does not allow any remotable objects or
     * other contents that can be used to communicate with other processes.
     * @param sharedMemory The unrestricted data blob provided by the
     * {@link VoiceInteractionService}. Use this to provide the hotword models data or other
     * such data to the trusted process.
@@ -544,7 +544,7 @@ public class AlwaysOnHotwordDetector {
     *
     * @hide
     */
    public final void setHotwordDetectionServiceConfig(@Nullable Bundle options,
    public final void setHotwordDetectionServiceConfig(@Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory) {
        if (DBG) {
            Slog.d(TAG, "setHotwordDetectionServiceConfig()");
+10 −8
Original line number Diff line number Diff line
@@ -27,11 +27,11 @@ import android.annotation.SystemApi;
import android.app.Service;
import android.content.Intent;
import android.media.AudioFormat;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.SharedMemory;
import android.util.Log;
@@ -82,7 +82,8 @@ public abstract class HotwordDetectionService extends Service {
        }

        @Override
        public void setConfig(Bundle options, SharedMemory sharedMemory) throws RemoteException {
        public void setConfig(PersistableBundle options, SharedMemory sharedMemory)
                throws RemoteException {
            if (DBG) {
                Log.d(TAG, "#setConfig");
            }
@@ -137,13 +138,13 @@ public abstract class HotwordDetectionService extends Service {

    /**
     * Called when the {@link VoiceInteractionService#createAlwaysOnHotwordDetector(String, Locale,
     * Bundle, SharedMemory, AlwaysOnHotwordDetector.Callback)} or {@link AlwaysOnHotwordDetector#
     * setHotwordDetectionServiceConfig(Bundle, SharedMemory)} requests an update of the hotword
     * detection parameters.
     * PersistableBundle, SharedMemory, AlwaysOnHotwordDetector.Callback)} or
     * {@link AlwaysOnHotwordDetector#setHotwordDetectionServiceConfig(PersistableBundle,
     * SharedMemory)} requests an update of the hotword detection parameters.
     *
     * @param options Application configuration data provided by the
     * {@link VoiceInteractionService}. The system strips out any remotable objects or other
     * contents that can be used to communicate with other processes.
     * {@link VoiceInteractionService}. PersistableBundle does not allow any remotable objects or
     * other contents that can be used to communicate with other processes.
     * @param sharedMemory The unrestricted data blob provided by the
     * {@link VoiceInteractionService}. Use this to provide the hotword models data or other
     * such data to the trusted process.
@@ -151,7 +152,8 @@ public abstract class HotwordDetectionService extends Service {
     * @hide
     */
    @SystemApi
    public void onUpdateState(@Nullable Bundle options, @Nullable SharedMemory sharedMemory) {
    public void onUpdateState(@Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory) {
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -17,8 +17,8 @@
package android.service.voice;

import android.media.AudioFormat;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle;
import android.os.SharedMemory;
import android.service.voice.IDspHotwordDetectionCallback;

@@ -34,5 +34,5 @@ oneway interface IHotwordDetectionService {
    long timeoutMillis,
    in IDspHotwordDetectionCallback callback);

    void setConfig(in Bundle options, in SharedMemory sharedMemory);
    void setConfig(in PersistableBundle options, in SharedMemory sharedMemory);
}
+5 −4
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.media.voice.KeyphraseModelManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.PersistableBundle;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.SharedMemory;
@@ -342,8 +343,8 @@ public class VoiceInteractionService extends Service {
     * @param keyphrase The keyphrase that's being used, for example "Hello Android".
     * @param locale The locale for which the enrollment needs to be performed.
     * @param options Application configuration data provided by the
     * {@link VoiceInteractionService}. The system strips out any remotable objects or other
     * contents that can be used to communicate with other processes.
     * {@link VoiceInteractionService}. PersistableBundle does not allow any remotable objects or
     * other contents that can be used to communicate with other processes.
     * @param sharedMemory The unrestricted data blob provided by the
     * {@link VoiceInteractionService}. Use this to provide the hotword models data or other
     * such data to the trusted process.
@@ -358,7 +359,7 @@ public class VoiceInteractionService extends Service {
    public final AlwaysOnHotwordDetector createAlwaysOnHotwordDetector(
            @SuppressLint("MissingNullability") String keyphrase,  // TODO: nullability properly
            @SuppressLint({"MissingNullability", "UseIcu"}) Locale locale,
            @Nullable Bundle options,
            @Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory,
            @SuppressLint("MissingNullability") AlwaysOnHotwordDetector.Callback callback) {
        return createAlwaysOnHotwordDetectorInternal(keyphrase, locale,
@@ -370,7 +371,7 @@ public class VoiceInteractionService extends Service {
            @SuppressLint("MissingNullability") String keyphrase,  // TODO: nullability properly
            @SuppressLint({"MissingNullability", "UseIcu"}) Locale locale,
            boolean supportHotwordDetectionService,
            @Nullable Bundle options,
            @Nullable PersistableBundle options,
            @Nullable SharedMemory sharedMemory,
            @SuppressLint("MissingNullability") AlwaysOnHotwordDetector.Callback callback) {
        if (mSystemService == null) {
Loading