diff options
author | 2018-04-25 21:29:06 +0000 | |
---|---|---|
committer | 2018-04-25 21:29:06 +0000 | |
commit | 63b534768e710ae7a0649f9a92d2402ec9ebdf38 (patch) | |
tree | 8bf9ff2f3b1e15bdfd41b7dd203e12111e42e973 | |
parent | 0b7bbdb60d6e0c017f08dca9454d9e9e0260831d (diff) | |
parent | 19402f557b8725e03158757039a61640b9a379df (diff) |
Merge "Remove PendingIntent based soundTrigger"
4 files changed, 8 insertions, 211 deletions
diff --git a/config/hiddenapi-light-greylist.txt b/config/hiddenapi-light-greylist.txt index f971da89aa52..71f126f3245f 100644 --- a/config/hiddenapi-light-greylist.txt +++ b/config/hiddenapi-light-greylist.txt @@ -1454,7 +1454,6 @@ Landroid/media/session/MediaSessionLegacyHelper;->getHelper(Landroid/content/Con Landroid/media/soundtrigger/SoundTriggerDetector$EventPayload;->getCaptureSession()Ljava/lang/Integer; Landroid/media/soundtrigger/SoundTriggerDetector$EventPayload;->getData()[B Landroid/media/soundtrigger/SoundTriggerManager;->loadSoundModel(Landroid/hardware/soundtrigger/SoundTrigger$SoundModel;)I -Landroid/media/soundtrigger/SoundTriggerManager;->startRecognition(Ljava/util/UUID;Landroid/app/PendingIntent;Landroid/hardware/soundtrigger/SoundTrigger$RecognitionConfig;)I Landroid/media/soundtrigger/SoundTriggerManager;->startRecognition(Ljava/util/UUID;Landroid/os/Bundle;Landroid/content/ComponentName;Landroid/hardware/soundtrigger/SoundTrigger$RecognitionConfig;)I Landroid/media/soundtrigger/SoundTriggerManager;->stopRecognition(Ljava/util/UUID;)I Landroid/media/soundtrigger/SoundTriggerManager;->unloadSoundModel(Ljava/util/UUID;)I diff --git a/core/java/com/android/internal/app/ISoundTriggerService.aidl b/core/java/com/android/internal/app/ISoundTriggerService.aidl index 93730df7dd47..b8a2dff95c37 100644 --- a/core/java/com/android/internal/app/ISoundTriggerService.aidl +++ b/core/java/com/android/internal/app/ISoundTriggerService.aidl @@ -43,15 +43,10 @@ interface ISoundTriggerService { int loadGenericSoundModel(in SoundTrigger.GenericSoundModel soundModel); int loadKeyphraseSoundModel(in SoundTrigger.KeyphraseSoundModel soundModel); - int startRecognitionForIntent(in ParcelUuid soundModelId, in PendingIntent callbackIntent, - in SoundTrigger.RecognitionConfig config); - - int startRecognitionForService(in ParcelUuid soundModelId, in Bundle params, in ComponentName callbackIntent,in SoundTrigger.RecognitionConfig config); - /** For both ...Intent and ...Service based usage */ - int stopRecognitionForIntent(in ParcelUuid soundModelId); + int stopRecognitionForService(in ParcelUuid soundModelId); int unloadSoundModel(in ParcelUuid soundModelId); diff --git a/media/java/android/media/soundtrigger/SoundTriggerManager.java b/media/java/android/media/soundtrigger/SoundTriggerManager.java index c9ec7526fd6a..107ce8ed6d04 100644 --- a/media/java/android/media/soundtrigger/SoundTriggerManager.java +++ b/media/java/android/media/soundtrigger/SoundTriggerManager.java @@ -262,25 +262,6 @@ public final class SoundTriggerManager { } /** - * Starts recognition on the given model id. All events from the model will be sent to the - * PendingIntent. - * @hide - */ - @RequiresPermission(android.Manifest.permission.MANAGE_SOUND_TRIGGER) - public int startRecognition(UUID soundModelId, PendingIntent callbackIntent, - RecognitionConfig config) { - if (soundModelId == null || callbackIntent == null || config == null) { - return STATUS_ERROR; - } - try { - return mSoundTriggerService.startRecognitionForIntent(new ParcelUuid(soundModelId), - callbackIntent, config); - } catch (RemoteException e) { - throw e.rethrowFromSystemServer(); - } - } - - /** * Starts recognition for the given model id. All events from the model will be sent to the * service. * @@ -324,7 +305,7 @@ public final class SoundTriggerManager { return STATUS_ERROR; } try { - return mSoundTriggerService.stopRecognitionForIntent(new ParcelUuid(soundModelId)); + return mSoundTriggerService.stopRecognitionForService(new ParcelUuid(soundModelId)); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java index cd524a517376..f8526effa0df 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java @@ -32,7 +32,6 @@ import static com.android.internal.util.function.pooled.PooledLambda.obtainMessa import android.Manifest; import android.annotation.NonNull; import android.annotation.Nullable; -import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -49,7 +48,6 @@ import android.hardware.soundtrigger.SoundTrigger.SoundModel; import android.media.soundtrigger.ISoundTriggerDetectionService; import android.media.soundtrigger.ISoundTriggerDetectionServiceClient; import android.media.soundtrigger.SoundTriggerDetectionService; -import android.media.soundtrigger.SoundTriggerManager; import android.os.Binder; import android.os.Bundle; import android.os.Handler; @@ -67,7 +65,6 @@ import android.util.Slog; import com.android.internal.annotations.GuardedBy; import com.android.internal.app.ISoundTriggerService; -import com.android.internal.util.DumpUtils; import com.android.internal.util.Preconditions; import com.android.server.SystemService; @@ -100,7 +97,6 @@ public class SoundTriggerService extends SystemService { private final TreeMap<UUID, SoundModel> mLoadedModels; private Object mCallbacksLock; private final TreeMap<UUID, IRecognitionStatusCallback> mCallbacks; - private PowerManager.WakeLock mWakelock; /** Number of ops run by the {@link RemoteSoundTriggerDetectionService} per package name */ @GuardedBy("mLock") @@ -296,28 +292,17 @@ public class SoundTriggerService extends SystemService { Preconditions.checkNotNull(detectionService); Preconditions.checkNotNull(config); - return startRecognitionForInt(soundModelId, - new RemoteSoundTriggerDetectionService(soundModelId.getUuid(), - params, detectionService, Binder.getCallingUserHandle(), config), config); - - } - - @Override - public int startRecognitionForIntent(ParcelUuid soundModelId, PendingIntent callbackIntent, - SoundTrigger.RecognitionConfig config) { - return startRecognitionForInt(soundModelId, - new LocalSoundTriggerRecognitionStatusIntentCallback(soundModelId.getUuid(), - callbackIntent, config), config); - } - - private int startRecognitionForInt(ParcelUuid soundModelId, - IRecognitionStatusCallback callback, SoundTrigger.RecognitionConfig config) { enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER); + if (!isInitialized()) return STATUS_ERROR; if (DEBUG) { Slog.i(TAG, "startRecognition(): id = " + soundModelId); } + IRecognitionStatusCallback callback = + new RemoteSoundTriggerDetectionService(soundModelId.getUuid(), params, + detectionService, Binder.getCallingUserHandle(), config); + synchronized (mLock) { SoundModel soundModel = mLoadedModels.get(soundModelId.getUuid()); if (soundModel == null) { @@ -334,12 +319,6 @@ public class SoundTriggerService extends SystemService { } int ret; switch (soundModel.type) { - case SoundModel.TYPE_KEYPHRASE: { - KeyphraseSoundModel keyphraseSoundModel = (KeyphraseSoundModel) soundModel; - ret = mSoundTriggerHelper.startKeyphraseRecognition( - keyphraseSoundModel.keyphrases[0].id, keyphraseSoundModel, callback, - config); - } break; case SoundModel.TYPE_GENERIC_SOUND: ret = mSoundTriggerHelper.startGenericRecognition(soundModel.uuid, (GenericSoundModel) soundModel, callback, config); @@ -361,7 +340,7 @@ public class SoundTriggerService extends SystemService { } @Override - public int stopRecognitionForIntent(ParcelUuid soundModelId) { + public int stopRecognitionForService(ParcelUuid soundModelId) { enforceCallingPermission(Manifest.permission.MANAGE_SOUND_TRIGGER); if (!isInitialized()) return STATUS_ERROR; if (DEBUG) { @@ -384,10 +363,6 @@ public class SoundTriggerService extends SystemService { } int ret; switch (soundModel.type) { - case SoundModel.TYPE_KEYPHRASE: - ret = mSoundTriggerHelper.stopKeyphraseRecognition( - ((KeyphraseSoundModel)soundModel).keyphrases[0].id, callback); - break; case SoundModel.TYPE_GENERIC_SOUND: ret = mSoundTriggerHelper.stopGenericRecognition(soundModel.uuid, callback); break; @@ -457,138 +432,6 @@ public class SoundTriggerService extends SystemService { } } - private final class LocalSoundTriggerRecognitionStatusIntentCallback - extends IRecognitionStatusCallback.Stub { - private UUID mUuid; - private PendingIntent mCallbackIntent; - private RecognitionConfig mRecognitionConfig; - - public LocalSoundTriggerRecognitionStatusIntentCallback(UUID modelUuid, - PendingIntent callbackIntent, - RecognitionConfig config) { - mUuid = modelUuid; - mCallbackIntent = callbackIntent; - mRecognitionConfig = config; - } - - @Override - public boolean pingBinder() { - return mCallbackIntent != null; - } - - @Override - public void onKeyphraseDetected(SoundTrigger.KeyphraseRecognitionEvent event) { - if (mCallbackIntent == null) { - return; - } - grabWakeLock(); - - Slog.w(TAG, "Keyphrase sound trigger event: " + event); - Intent extras = new Intent(); - extras.putExtra(SoundTriggerManager.EXTRA_MESSAGE_TYPE, - SoundTriggerManager.FLAG_MESSAGE_TYPE_RECOGNITION_EVENT); - extras.putExtra(SoundTriggerManager.EXTRA_RECOGNITION_EVENT, event); - try { - mCallbackIntent.send(mContext, 0, extras, mCallbackCompletedHandler, null); - if (!mRecognitionConfig.allowMultipleTriggers) { - removeCallback(/*releaseWakeLock=*/false); - } - } catch (PendingIntent.CanceledException e) { - removeCallback(/*releaseWakeLock=*/true); - } - } - - @Override - public void onGenericSoundTriggerDetected(SoundTrigger.GenericRecognitionEvent event) { - if (mCallbackIntent == null) { - return; - } - grabWakeLock(); - - Slog.w(TAG, "Generic sound trigger event: " + event); - Intent extras = new Intent(); - extras.putExtra(SoundTriggerManager.EXTRA_MESSAGE_TYPE, - SoundTriggerManager.FLAG_MESSAGE_TYPE_RECOGNITION_EVENT); - extras.putExtra(SoundTriggerManager.EXTRA_RECOGNITION_EVENT, event); - try { - mCallbackIntent.send(mContext, 0, extras, mCallbackCompletedHandler, null); - if (!mRecognitionConfig.allowMultipleTriggers) { - removeCallback(/*releaseWakeLock=*/false); - } - } catch (PendingIntent.CanceledException e) { - removeCallback(/*releaseWakeLock=*/true); - } - } - - @Override - public void onError(int status) { - if (mCallbackIntent == null) { - return; - } - grabWakeLock(); - - Slog.i(TAG, "onError: " + status); - Intent extras = new Intent(); - extras.putExtra(SoundTriggerManager.EXTRA_MESSAGE_TYPE, - SoundTriggerManager.FLAG_MESSAGE_TYPE_RECOGNITION_ERROR); - extras.putExtra(SoundTriggerManager.EXTRA_STATUS, status); - try { - mCallbackIntent.send(mContext, 0, extras, mCallbackCompletedHandler, null); - // Remove the callback, but wait for the intent to finish before we let go of the - // wake lock - removeCallback(/*releaseWakeLock=*/false); - } catch (PendingIntent.CanceledException e) { - removeCallback(/*releaseWakeLock=*/true); - } - } - - @Override - public void onRecognitionPaused() { - if (mCallbackIntent == null) { - return; - } - grabWakeLock(); - - Slog.i(TAG, "onRecognitionPaused"); - Intent extras = new Intent(); - extras.putExtra(SoundTriggerManager.EXTRA_MESSAGE_TYPE, - SoundTriggerManager.FLAG_MESSAGE_TYPE_RECOGNITION_PAUSED); - try { - mCallbackIntent.send(mContext, 0, extras, mCallbackCompletedHandler, null); - } catch (PendingIntent.CanceledException e) { - removeCallback(/*releaseWakeLock=*/true); - } - } - - @Override - public void onRecognitionResumed() { - if (mCallbackIntent == null) { - return; - } - grabWakeLock(); - - Slog.i(TAG, "onRecognitionResumed"); - Intent extras = new Intent(); - extras.putExtra(SoundTriggerManager.EXTRA_MESSAGE_TYPE, - SoundTriggerManager.FLAG_MESSAGE_TYPE_RECOGNITION_RESUMED); - try { - mCallbackIntent.send(mContext, 0, extras, mCallbackCompletedHandler, null); - } catch (PendingIntent.CanceledException e) { - removeCallback(/*releaseWakeLock=*/true); - } - } - - private void removeCallback(boolean releaseWakeLock) { - mCallbackIntent = null; - synchronized (mCallbacksLock) { - mCallbacks.remove(mUuid); - if (releaseWakeLock) { - mWakelock.release(); - } - } - } - } - /** * Counts the number of operations added in the last 24 hours. */ @@ -1060,27 +903,6 @@ public class SoundTriggerService extends SystemService { } } - private void grabWakeLock() { - synchronized (mCallbacksLock) { - if (mWakelock == null) { - PowerManager pm = ((PowerManager) mContext.getSystemService(Context.POWER_SERVICE)); - mWakelock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); - } - mWakelock.acquire(); - } - } - - private PendingIntent.OnFinished mCallbackCompletedHandler = new PendingIntent.OnFinished() { - @Override - public void onSendFinished(PendingIntent pendingIntent, Intent intent, int resultCode, - String resultData, Bundle resultExtras) { - // We're only ever invoked when the callback is done, so release the lock. - synchronized (mCallbacksLock) { - mWakelock.release(); - } - } - }; - public final class LocalSoundTriggerService extends SoundTriggerInternal { private final Context mContext; private SoundTriggerHelper mSoundTriggerHelper; |