diff options
| author | 2020-05-08 11:09:35 -0700 | |
|---|---|---|
| committer | 2020-09-10 13:27:08 -0700 | |
| commit | c79176dc646bb00402ee467500cd978d2d9f5c34 (patch) | |
| tree | a5c92adf0db6ab240a584f364c967278c4df187d | |
| parent | 1a619f03895189efdaa4db944b1cbd14d41b94c9 (diff) | |
Require identity information in SoundTrigger.java
Deprecate the way to attach to SoundTrigger that doesn't include
identity information. Plumb that up to the SoundTriggerService layer,
where it is temporarily provided in a backward-compatible way instead
of with the actual identity.
Change-Id: Icc2bf3b80300bd2b75c81d253986b4e1582737ca
Bug: 163865561
3 files changed, 27 insertions, 4 deletions
diff --git a/core/java/android/hardware/soundtrigger/SoundTrigger.java b/core/java/android/hardware/soundtrigger/SoundTrigger.java index eb138fcb8f1d..0f1c2a59965b 100644 --- a/core/java/android/hardware/soundtrigger/SoundTrigger.java +++ b/core/java/android/hardware/soundtrigger/SoundTrigger.java @@ -2116,7 +2116,7 @@ public class SoundTrigger { * @hide */ @UnsupportedAppUsage - public static SoundTriggerModule attachModule(int moduleId, + private static SoundTriggerModule attachModule(int moduleId, @NonNull StatusListener listener, @Nullable Handler handler) { // TODO(ytai): This is a temporary hack to retain prior behavior, which makes diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java index edbdd4e94ac8..c10551545ec8 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerHelper.java @@ -59,6 +59,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.UUID; +import java.util.function.BiFunction; /** * Helper for {@link SoundTrigger} APIs. Supports two types of models: @@ -116,6 +117,9 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { private PowerSaveModeListener mPowerSaveModeListener; + private final BiFunction<Integer, SoundTrigger.StatusListener, SoundTriggerModule> + mModuleProvider; + // Handler to process call state changes will delay to allow time for the audio // and sound trigger HALs to process the end of call notifications // before we re enable pending recognition requests. @@ -123,8 +127,11 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { private static final int MSG_CALL_STATE_CHANGED = 0; private static final int CALL_INACTIVE_MSG_DELAY_MS = 1000; - SoundTriggerHelper(Context context) { + SoundTriggerHelper(Context context, + @NonNull BiFunction<Integer, SoundTrigger.StatusListener, + SoundTriggerModule> moduleProvider) { ArrayList <ModuleProperties> modules = new ArrayList<>(); + mModuleProvider = moduleProvider; int status = SoundTrigger.listModules(modules); mContext = context; mTelephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); @@ -264,7 +271,7 @@ public class SoundTriggerHelper implements SoundTrigger.StatusListener { private int prepareForRecognition(ModelData modelData) { if (mModule == null) { - mModule = SoundTrigger.attachModule(mModuleProperties.getId(), this, null); + mModule = mModuleProvider.apply(mModuleProperties.getId(), this); if (mModule == null) { Slog.w(TAG, "prepareForRecognition: cannot attach to sound trigger module"); return STATUS_ERROR; diff --git a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java index 26d46dbd2ab7..94d40edd9090 100644 --- a/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java +++ b/services/voiceinteraction/java/com/android/server/soundtrigger/SoundTriggerService.java @@ -35,6 +35,7 @@ import static com.android.internal.util.function.pooled.PooledLambda.obtainMessa import android.Manifest; import android.annotation.NonNull; import android.annotation.Nullable; +import android.app.ActivityThread; import android.content.ComponentName; import android.content.Context; import android.content.Intent; @@ -57,6 +58,7 @@ import android.media.MediaRecorder; import android.media.soundtrigger.ISoundTriggerDetectionService; import android.media.soundtrigger.ISoundTriggerDetectionServiceClient; import android.media.soundtrigger.SoundTriggerDetectionService; +import android.media.soundtrigger_middleware.Identity; import android.os.Binder; import android.os.Bundle; import android.os.Handler; @@ -223,7 +225,21 @@ public class SoundTriggerService extends SystemService { private synchronized void initSoundTriggerHelper() { if (mSoundTriggerHelper == null) { - mSoundTriggerHelper = new SoundTriggerHelper(mContext); + Identity middlemanIdentity = new Identity(); + middlemanIdentity.packageName = ActivityThread.currentOpPackageName(); + + mSoundTriggerHelper = new SoundTriggerHelper(mContext, (moduleId, + listener) -> { + // TODO(ytai): This is a temporary hack to retain prior behavior, which + // makes + // assumptions about process affinity and Binder context. + Identity originatorIdentity = new Identity(); + originatorIdentity.uid = Binder.getCallingUid(); + originatorIdentity.pid = Binder.getCallingUid(); + + return SoundTrigger.attachModuleAsMiddleman(moduleId, listener, null, + middlemanIdentity, originatorIdentity); + }); } } |