Merge "Allow HotwordDetectionService access to audioflinger." into sc-dev am: a8a6a45f68

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14671365

Change-Id: I3a95a75409117ccc9c3e254a83a18a9cd392923f
This commit is contained in:
Ahaan Ugale
2021-06-14 05:15:46 +00:00
committed by Automerger Merge Worker
5 changed files with 31 additions and 1 deletions

View File

@@ -31,6 +31,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.hardware.soundtrigger.SoundTrigger; import android.hardware.soundtrigger.SoundTrigger;
import android.media.AudioFormat; import android.media.AudioFormat;
import android.media.AudioSystem;
import android.os.Bundle; import android.os.Bundle;
import android.os.IBinder; import android.os.IBinder;
import android.os.IRemoteCallback; import android.os.IRemoteCallback;
@@ -186,6 +187,11 @@ public abstract class HotwordDetectionService extends Service {
} }
} }
@Override
public void updateAudioFlinger(IBinder audioFlinger) {
AudioSystem.setAudioFlingerBinder(audioFlinger);
}
@Override @Override
public void updateContentCaptureManager(IContentCaptureManager manager, public void updateContentCaptureManager(IContentCaptureManager manager,
ContentCaptureOptions options) { ContentCaptureOptions options) {

View File

@@ -19,6 +19,7 @@ package android.service.voice;
import android.content.ContentCaptureOptions; import android.content.ContentCaptureOptions;
import android.hardware.soundtrigger.SoundTrigger; import android.hardware.soundtrigger.SoundTrigger;
import android.media.AudioFormat; import android.media.AudioFormat;
import android.os.IBinder;
import android.os.IRemoteCallback; import android.os.IRemoteCallback;
import android.os.ParcelFileDescriptor; import android.os.ParcelFileDescriptor;
import android.os.PersistableBundle; import android.os.PersistableBundle;
@@ -50,6 +51,8 @@ oneway interface IHotwordDetectionService {
in SharedMemory sharedMemory, in SharedMemory sharedMemory,
in IRemoteCallback callback); in IRemoteCallback callback);
void updateAudioFlinger(in IBinder audioFlinger);
void updateContentCaptureManager( void updateContentCaptureManager(
in IContentCaptureManager contentCaptureManager, in IContentCaptureManager contentCaptureManager,
in ContentCaptureOptions options); in ContentCaptureOptions options);

View File

@@ -42,6 +42,7 @@
#include "android_media_AudioFormat.h" #include "android_media_AudioFormat.h"
#include "android_media_AudioProfile.h" #include "android_media_AudioProfile.h"
#include "android_media_MicrophoneInfo.h" #include "android_media_MicrophoneInfo.h"
#include "android_util_Binder.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -850,6 +851,11 @@ android_media_AudioSystem_checkAudioFlinger(JNIEnv *env, jobject clazz)
return (jint) check_AudioSystem_Command(AudioSystem::checkAudioFlinger()); return (jint) check_AudioSystem_Command(AudioSystem::checkAudioFlinger());
} }
static void android_media_AudioSystem_setAudioFlingerBinder(JNIEnv *env, jobject clazz,
jobject audioFlinger) {
AudioSystem::setAudioFlingerBinder(android::ibinderForJavaObject(env, audioFlinger));
}
static void convertAudioGainConfigToNative(JNIEnv *env, static void convertAudioGainConfigToNative(JNIEnv *env,
struct audio_gain_config *nAudioGainConfig, struct audio_gain_config *nAudioGainConfig,
const jobject jAudioGainConfig, const jobject jAudioGainConfig,
@@ -2728,6 +2734,8 @@ static const JNINativeMethod gMethods[] =
{"getOutputLatency", "(I)I", (void *)android_media_AudioSystem_getOutputLatency}, {"getOutputLatency", "(I)I", (void *)android_media_AudioSystem_getOutputLatency},
{"setLowRamDevice", "(ZJ)I", (void *)android_media_AudioSystem_setLowRamDevice}, {"setLowRamDevice", "(ZJ)I", (void *)android_media_AudioSystem_setLowRamDevice},
{"checkAudioFlinger", "()I", (void *)android_media_AudioSystem_checkAudioFlinger}, {"checkAudioFlinger", "()I", (void *)android_media_AudioSystem_checkAudioFlinger},
{"setAudioFlingerBinder", "(Landroid/os/IBinder;)V",
(void *)android_media_AudioSystem_setAudioFlingerBinder},
{"listAudioPorts", "(Ljava/util/ArrayList;[I)I", {"listAudioPorts", "(Ljava/util/ArrayList;[I)I",
(void *)android_media_AudioSystem_listAudioPorts}, (void *)android_media_AudioSystem_listAudioPorts},
{"createAudioPatch", {"createAudioPatch",

View File

@@ -27,6 +27,7 @@ import android.content.pm.PackageManager;
import android.media.audiofx.AudioEffect; import android.media.audiofx.AudioEffect;
import android.media.audiopolicy.AudioMix; import android.media.audiopolicy.AudioMix;
import android.os.Build; import android.os.Build;
import android.os.IBinder;
import android.os.Vibrator; import android.os.Vibrator;
import android.telephony.TelephonyManager; import android.telephony.TelephonyManager;
import android.util.Log; import android.util.Log;
@@ -1655,6 +1656,8 @@ public class AudioSystem
/** @hide */ /** @hide */
@UnsupportedAppUsage @UnsupportedAppUsage
public static native int checkAudioFlinger(); public static native int checkAudioFlinger();
/** @hide */
public static native void setAudioFlingerBinder(IBinder audioFlinger);
/** @hide */ /** @hide */
public static native int listAudioPorts(ArrayList<AudioPort> ports, int[] generation); public static native int listAudioPorts(ArrayList<AudioPort> ports, int[] generation);

View File

@@ -156,8 +156,9 @@ final class HotwordDetectionConnection {
updateStateLocked(options, sharedMemory); updateStateLocked(options, sharedMemory);
return; return;
} }
updateStateWithCallbackLocked(options, sharedMemory, callback); updateAudioFlinger();
updateContentCaptureManager(); updateContentCaptureManager();
updateStateWithCallbackLocked(options, sharedMemory, callback);
} }
private void updateStateWithCallbackLocked(PersistableBundle options, private void updateStateWithCallbackLocked(PersistableBundle options,
@@ -229,6 +230,15 @@ final class HotwordDetectionConnection {
}); });
} }
private void updateAudioFlinger() {
// TODO: Consider using a proxy that limits the exposed API surface.
IBinder audioFlinger = ServiceManager.getService("media.audio_flinger");
if (audioFlinger == null) {
throw new IllegalStateException("Service media.audio_flinger wasn't found.");
}
mRemoteHotwordDetectionService.post(service -> service.updateAudioFlinger(audioFlinger));
}
private void updateContentCaptureManager() { private void updateContentCaptureManager() {
IBinder b = ServiceManager IBinder b = ServiceManager
.getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE); .getService(Context.CONTENT_CAPTURE_MANAGER_SERVICE);