diff options
author | Matt Garnes <matt@cyngn.com> | 2015-09-04 18:02:20 -0700 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-28 13:30:32 -0700 |
commit | b09f7797429af5c0034d1a6c52c2a47a35b0e428 (patch) | |
tree | 90d7b719101a9df1d88da2801ccf3144f20b997b /services/core/java/com/android/server/audio/AudioService.java | |
parent | 66ed04e967adb4bb5545ecf06ce692c6e5b790ea (diff) | |
download | frameworks_base-b09f7797429af5c0034d1a6c52c2a47a35b0e428.zip frameworks_base-b09f7797429af5c0034d1a6c52c2a47a35b0e428.tar.gz frameworks_base-b09f7797429af5c0034d1a6c52c2a47a35b0e428.tar.bz2 |
Add broadcast and query API for AudioSource.HOTWORD.
- When the AudioSource.HOTWORD input becomes active or is released, send
a Broadcast with the package name and the new state of the audio input
to any applications that hold CAPTURE_AUDIO_OUTPUT.
- Store the package name of the application that controls the hOTWORD
input or set it to null if the input is not in use.
- Add a new method to AudioService to retrieve the package name of the
application that currently controls the HOTWORD input.
Change-Id: I2f11888f3711d23b6287a4de7b81d361734a8f3b
Diffstat (limited to 'services/core/java/com/android/server/audio/AudioService.java')
-rw-r--r-- | services/core/java/com/android/server/audio/AudioService.java | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/services/core/java/com/android/server/audio/AudioService.java b/services/core/java/com/android/server/audio/AudioService.java index cde2d7c..e60d9cf 100644 --- a/services/core/java/com/android/server/audio/AudioService.java +++ b/services/core/java/com/android/server/audio/AudioService.java @@ -59,6 +59,7 @@ import android.media.AudioFormat; import android.media.AudioManager; import android.media.AudioManagerInternal; import android.media.AudioPort; +import android.media.AudioRecord; import android.media.AudioRoutesInfo; import android.media.IAudioFocusDispatcher; import android.media.IAudioRoutesObserver; @@ -405,6 +406,15 @@ public class AudioService extends IAudioService.Stub { * @see System#MUTE_STREAMS_AFFECTED */ private int mMuteAffectedStreams; + /** @see #handleHotwordInput **/ + private Object mHotwordInputLock = new Object(); + + /** The package name of the application that is + * currently using the HOTWORD input. + */ + // protected by mHotwordInputLock + private String mHotwordAudioInputPackage; + /** * NOTE: setVibrateSetting(), getVibrateSetting(), shouldVibrate() are deprecated. * mVibrateSetting is just maintained during deprecation period but vibration policy is @@ -1601,6 +1611,46 @@ public class AudioService extends IAudioService.Stub { sendVolumeUpdate(streamType, oldIndex, index, flags); } + /** + * Retrieve the package name of the application that currently controls + * the {@link android.media.MediaRecorder.AudioSource#HOTWORD} input. + * @return The package name of the application that controls the input + * or null if no package currently controls it. + */ + public String getCurrentHotwordInputPackageName() { + return mHotwordAudioInputPackage; + } + + /** + * Handle the change of state of the HOTWORD input. + * + * When the {@link android.media.MediaRecorder.AudioSource#HOTWORD} input is + * in use, send a broadcast to alert the new state and store the name of the current + * package that controls the input in mHotwordAudioInputPackage. + * @param listening Whether the input is being listened to. + */ + public void handleHotwordInput(boolean listening) { + synchronized (mHotwordInputLock) { + Intent broadcastIntent = new Intent(Intent.ACTION_HOTWORD_INPUT_CHANGED); + String[] packages = mContext.getPackageManager().getPackagesForUid( + Binder.getCallingUid()); + if (packages.length > 0) { + if (listening) { + mHotwordAudioInputPackage = packages[0]; + } + broadcastIntent.putExtra(Intent.EXTRA_CURRENT_PACKAGE_NAME, packages[0]); + } + broadcastIntent.putExtra(Intent.EXTRA_HOTWORD_INPUT_STATE, + listening ? AudioRecord.RECORDSTATE_RECORDING : + AudioRecord.RECORDSTATE_STOPPED); + // Set the currently listening package to null if listening has stopped. + if (!listening) { + mHotwordAudioInputPackage = null; + } + sendBroadcastToAll(broadcastIntent, Manifest.permission.CAPTURE_AUDIO_HOTWORD); + } + } + /** @see AudioManager#forceVolumeControlStream(int) */ public void forceVolumeControlStream(int streamType, IBinder cb) { synchronized(mForceControlStreamLock) { @@ -1653,11 +1703,15 @@ public class AudioService extends IAudioService.Stub { } private void sendBroadcastToAll(Intent intent) { + sendBroadcastToAll(intent, null); + } + + private void sendBroadcastToAll(Intent intent, String receiverPermission) { intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT); intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND); final long ident = Binder.clearCallingIdentity(); try { - mContext.sendBroadcastAsUser(intent, UserHandle.ALL); + mContext.sendBroadcastAsUser(intent, UserHandle.ALL, receiverPermission); } finally { Binder.restoreCallingIdentity(ident); } |