Merge "Send the HotwordDetectionService UID to AudioPolicy" into sc-dev am: 298c5093dc
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15465671 Change-Id: Ie2e9e6555743653fcf798fa1cb876fc454807d06
This commit is contained in:
@@ -2429,6 +2429,12 @@ android_media_AudioSystem_setAssistantUid(JNIEnv *env, jobject thiz, jint uid)
|
|||||||
return (jint)nativeToJavaStatus(status);
|
return (jint)nativeToJavaStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static jint android_media_AudioSystem_setHotwordDetectionServiceUid(JNIEnv *env, jobject thiz,
|
||||||
|
jint uid) {
|
||||||
|
status_t status = AudioSystem::setHotwordDetectionServiceUid(uid);
|
||||||
|
return (jint)nativeToJavaStatus(status);
|
||||||
|
}
|
||||||
|
|
||||||
static jint
|
static jint
|
||||||
android_media_AudioSystem_setA11yServicesUids(JNIEnv *env, jobject thiz, jintArray uids) {
|
android_media_AudioSystem_setA11yServicesUids(JNIEnv *env, jobject thiz, jintArray uids) {
|
||||||
std::vector<uid_t> nativeUidsVector;
|
std::vector<uid_t> nativeUidsVector;
|
||||||
@@ -2799,6 +2805,8 @@ static const JNINativeMethod gMethods[] =
|
|||||||
{"setSurroundFormatEnabled", "(IZ)I",
|
{"setSurroundFormatEnabled", "(IZ)I",
|
||||||
(void *)android_media_AudioSystem_setSurroundFormatEnabled},
|
(void *)android_media_AudioSystem_setSurroundFormatEnabled},
|
||||||
{"setAssistantUid", "(I)I", (void *)android_media_AudioSystem_setAssistantUid},
|
{"setAssistantUid", "(I)I", (void *)android_media_AudioSystem_setAssistantUid},
|
||||||
|
{"setHotwordDetectionServiceUid", "(I)I",
|
||||||
|
(void *)android_media_AudioSystem_setHotwordDetectionServiceUid},
|
||||||
{"setA11yServicesUids", "([I)I", (void *)android_media_AudioSystem_setA11yServicesUids},
|
{"setA11yServicesUids", "([I)I", (void *)android_media_AudioSystem_setA11yServicesUids},
|
||||||
{"isHapticPlaybackSupported", "()Z",
|
{"isHapticPlaybackSupported", "()Z",
|
||||||
(void *)android_media_AudioSystem_isHapticPlaybackSupported},
|
(void *)android_media_AudioSystem_isHapticPlaybackSupported},
|
||||||
|
|||||||
@@ -38,6 +38,17 @@ public abstract class AudioManagerInternal {
|
|||||||
|
|
||||||
public abstract void updateRingerModeAffectedStreamsInternal();
|
public abstract void updateRingerModeAffectedStreamsInternal();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notify the UID of the currently active {@link android.service.voice.HotwordDetectionService}.
|
||||||
|
*
|
||||||
|
* <p>The caller is expected to take care of any performance implications, e.g. by using a
|
||||||
|
* background thread to call this method.</p>
|
||||||
|
*
|
||||||
|
* @param uid UID of the currently active service or {@link android.os.Process#INVALID_UID} if
|
||||||
|
* none.
|
||||||
|
*/
|
||||||
|
public abstract void setHotwordDetectionServiceUid(int uid);
|
||||||
|
|
||||||
public abstract void setAccessibilityServiceUids(IntArray uids);
|
public abstract void setAccessibilityServiceUids(IntArray uids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1768,6 +1768,13 @@ public class AudioSystem
|
|||||||
*/
|
*/
|
||||||
public static native int setAssistantUid(int uid);
|
public static native int setAssistantUid(int uid);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Communicate UID of the current {@link android.service.voice.HotwordDetectionService} to audio
|
||||||
|
* policy service.
|
||||||
|
* @hide
|
||||||
|
*/
|
||||||
|
public static native int setHotwordDetectionServiceUid(int uid);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @hide
|
* @hide
|
||||||
* Communicate UIDs of active accessibility services to audio policy service.
|
* Communicate UIDs of active accessibility services to audio policy service.
|
||||||
|
|||||||
@@ -736,6 +736,11 @@ public class AudioService extends IAudioService.Stub
|
|||||||
private VolumePolicy mVolumePolicy = VolumePolicy.DEFAULT;
|
private VolumePolicy mVolumePolicy = VolumePolicy.DEFAULT;
|
||||||
private long mLoweredFromNormalToVibrateTime;
|
private long mLoweredFromNormalToVibrateTime;
|
||||||
|
|
||||||
|
// Uid of the active hotword detection service to check if caller is the one or not.
|
||||||
|
@GuardedBy("mHotwordDetectionServiceUidLock")
|
||||||
|
private int mHotwordDetectionServiceUid = android.os.Process.INVALID_UID;
|
||||||
|
private final Object mHotwordDetectionServiceUidLock = new Object();
|
||||||
|
|
||||||
// Array of Uids of valid accessibility services to check if caller is one of them
|
// Array of Uids of valid accessibility services to check if caller is one of them
|
||||||
private final Object mAccessibilityServiceUidsLock = new Object();
|
private final Object mAccessibilityServiceUidsLock = new Object();
|
||||||
@GuardedBy("mAccessibilityServiceUidsLock")
|
@GuardedBy("mAccessibilityServiceUidsLock")
|
||||||
@@ -1337,6 +1342,9 @@ public class AudioService extends IAudioService.Stub
|
|||||||
updateAssistantUId(true);
|
updateAssistantUId(true);
|
||||||
AudioSystem.setRttEnabled(mRttEnabled);
|
AudioSystem.setRttEnabled(mRttEnabled);
|
||||||
}
|
}
|
||||||
|
synchronized (mHotwordDetectionServiceUidLock) {
|
||||||
|
AudioSystem.setHotwordDetectionServiceUid(mHotwordDetectionServiceUid);
|
||||||
|
}
|
||||||
synchronized (mAccessibilityServiceUidsLock) {
|
synchronized (mAccessibilityServiceUidsLock) {
|
||||||
AudioSystem.setA11yServicesUids(mAccessibilityServiceUids);
|
AudioSystem.setA11yServicesUids(mAccessibilityServiceUids);
|
||||||
}
|
}
|
||||||
@@ -9107,6 +9115,16 @@ public class AudioService extends IAudioService.Stub
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setHotwordDetectionServiceUid(int uid) {
|
||||||
|
synchronized (mHotwordDetectionServiceUidLock) {
|
||||||
|
if (mHotwordDetectionServiceUid != uid) {
|
||||||
|
mHotwordDetectionServiceUid = uid;
|
||||||
|
AudioSystem.setHotwordDetectionServiceUid(mHotwordDetectionServiceUid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setAccessibilityServiceUids(IntArray uids) {
|
public void setAccessibilityServiceUids(IntArray uids) {
|
||||||
synchronized (mAccessibilityServiceUidsLock) {
|
synchronized (mAccessibilityServiceUidsLock) {
|
||||||
|
|||||||
@@ -366,6 +366,14 @@ public class AudioSystemAdapter implements AudioSystem.RoutingUpdateCallback {
|
|||||||
return AudioSystem.muteMicrophone(on);
|
return AudioSystem.muteMicrophone(on);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Same as {@link AudioSystem#setHotwordDetectionServiceUid(int)}
|
||||||
|
* Communicate UID of current HotwordDetectionService to audio policy service.
|
||||||
|
*/
|
||||||
|
public int setHotwordDetectionServiceUid(int uid) {
|
||||||
|
return AudioSystem.setHotwordDetectionServiceUid(uid);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Same as {@link AudioSystem#setCurrentImeUid(int)}
|
* Same as {@link AudioSystem#setCurrentImeUid(int)}
|
||||||
* Communicate UID of current InputMethodService to audio policy service.
|
* Communicate UID of current InputMethodService to audio policy service.
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ import android.content.PermissionChecker;
|
|||||||
import android.hardware.soundtrigger.IRecognitionStatusCallback;
|
import android.hardware.soundtrigger.IRecognitionStatusCallback;
|
||||||
import android.hardware.soundtrigger.SoundTrigger;
|
import android.hardware.soundtrigger.SoundTrigger;
|
||||||
import android.media.AudioFormat;
|
import android.media.AudioFormat;
|
||||||
|
import android.media.AudioManagerInternal;
|
||||||
import android.media.permission.Identity;
|
import android.media.permission.Identity;
|
||||||
import android.media.permission.PermissionUtil;
|
import android.media.permission.PermissionUtil;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
@@ -44,6 +45,7 @@ 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;
|
||||||
|
import android.os.Process;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.SharedMemory;
|
import android.os.SharedMemory;
|
||||||
@@ -275,6 +277,7 @@ final class HotwordDetectionConnection {
|
|||||||
LocalServices.getService(PermissionManagerServiceInternal.class)
|
LocalServices.getService(PermissionManagerServiceInternal.class)
|
||||||
.setHotwordDetectionServiceProvider(null);
|
.setHotwordDetectionServiceProvider(null);
|
||||||
mIdentity = null;
|
mIdentity = null;
|
||||||
|
updateServiceUidForAudioPolicy(Process.INVALID_UID);
|
||||||
}
|
}
|
||||||
mCancellationTaskFuture.cancel(/* may interrupt */ true);
|
mCancellationTaskFuture.cancel(/* may interrupt */ true);
|
||||||
if (mAudioFlinger != null) {
|
if (mAudioFlinger != null) {
|
||||||
@@ -893,6 +896,8 @@ final class HotwordDetectionConnection {
|
|||||||
connection.run(service -> service.ping(new IRemoteCallback.Stub() {
|
connection.run(service -> service.ping(new IRemoteCallback.Stub() {
|
||||||
@Override
|
@Override
|
||||||
public void sendResult(Bundle bundle) throws RemoteException {
|
public void sendResult(Bundle bundle) throws RemoteException {
|
||||||
|
// TODO: Exit if the service has been unbound already (though there's a very low
|
||||||
|
// chance this happens).
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
Slog.d(TAG, "updating hotword UID " + Binder.getCallingUid());
|
Slog.d(TAG, "updating hotword UID " + Binder.getCallingUid());
|
||||||
}
|
}
|
||||||
@@ -902,10 +907,21 @@ final class HotwordDetectionConnection {
|
|||||||
LocalServices.getService(PermissionManagerServiceInternal.class)
|
LocalServices.getService(PermissionManagerServiceInternal.class)
|
||||||
.setHotwordDetectionServiceProvider(() -> uid);
|
.setHotwordDetectionServiceProvider(() -> uid);
|
||||||
mIdentity = new HotwordDetectionServiceIdentity(uid, mVoiceInteractionServiceUid);
|
mIdentity = new HotwordDetectionServiceIdentity(uid, mVoiceInteractionServiceUid);
|
||||||
|
updateServiceUidForAudioPolicy(uid);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateServiceUidForAudioPolicy(int uid) {
|
||||||
|
mScheduledExecutorService.execute(() -> {
|
||||||
|
final AudioManagerInternal audioManager =
|
||||||
|
LocalServices.getService(AudioManagerInternal.class);
|
||||||
|
if (audioManager != null) {
|
||||||
|
audioManager.setHotwordDetectionServiceUid(uid);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static void bestEffortClose(Closeable closeable) {
|
private static void bestEffortClose(Closeable closeable) {
|
||||||
try {
|
try {
|
||||||
closeable.close();
|
closeable.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user