Remove dependency on Identity in HotwordAudioStreamManager
android.media.permission.Identity is not needed for AppOpsManager calls and is an unnecessary coupling. Bug: 258323047 Test: None with this change; pure refactoring Change-Id: I1c70f95a73e36c2793e87116b426d55ce359b74b Merged-In: I1c70f95a73e36c2793e87116b426d55ce359b74b
This commit is contained in:
committed by
Ivan Chiang
parent
27c97de8ae
commit
53007b4d5b
@@ -23,7 +23,6 @@ import static com.android.server.voiceinteraction.HotwordDetectionConnection.DEB
|
|||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.app.AppOpsManager;
|
import android.app.AppOpsManager;
|
||||||
import android.media.permission.Identity;
|
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
import android.os.PersistableBundle;
|
import android.os.PersistableBundle;
|
||||||
import android.service.voice.HotwordAudioStream;
|
import android.service.voice.HotwordAudioStream;
|
||||||
@@ -52,13 +51,18 @@ final class HotwordAudioStreamManager {
|
|||||||
private static final int MAX_COPY_BUFFER_LENGTH_BYTES = 65_536;
|
private static final int MAX_COPY_BUFFER_LENGTH_BYTES = 65_536;
|
||||||
|
|
||||||
private final AppOpsManager mAppOpsManager;
|
private final AppOpsManager mAppOpsManager;
|
||||||
private final Identity mVoiceInteractorIdentity;
|
private final int mVoiceInteractorUid;
|
||||||
|
private final String mVoiceInteractorPackageName;
|
||||||
|
private final String mVoiceInteractorAttributionTag;
|
||||||
private final ExecutorService mExecutorService = Executors.newCachedThreadPool();
|
private final ExecutorService mExecutorService = Executors.newCachedThreadPool();
|
||||||
|
|
||||||
HotwordAudioStreamManager(@NonNull AppOpsManager appOpsManager,
|
HotwordAudioStreamManager(@NonNull AppOpsManager appOpsManager,
|
||||||
@NonNull Identity voiceInteractorIdentity) {
|
int voiceInteractorUid, @NonNull String voiceInteractorPackageName,
|
||||||
|
@NonNull String voiceInteractorAttributionTag) {
|
||||||
mAppOpsManager = appOpsManager;
|
mAppOpsManager = appOpsManager;
|
||||||
mVoiceInteractorIdentity = voiceInteractorIdentity;
|
mVoiceInteractorUid = voiceInteractorUid;
|
||||||
|
mVoiceInteractorPackageName = voiceInteractorPackageName;
|
||||||
|
mVoiceInteractorAttributionTag = voiceInteractorAttributionTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -152,8 +156,8 @@ final class HotwordAudioStreamManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mAppOpsManager.startOpNoThrow(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD,
|
if (mAppOpsManager.startOpNoThrow(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD,
|
||||||
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
|
mVoiceInteractorUid, mVoiceInteractorPackageName,
|
||||||
mVoiceInteractorIdentity.attributionTag, OP_MESSAGE) == MODE_ALLOWED) {
|
mVoiceInteractorAttributionTag, OP_MESSAGE) == MODE_ALLOWED) {
|
||||||
try {
|
try {
|
||||||
// TODO(b/244599891): Set timeout, close after inactivity
|
// TODO(b/244599891): Set timeout, close after inactivity
|
||||||
mExecutorService.invokeAll(tasks);
|
mExecutorService.invokeAll(tasks);
|
||||||
@@ -162,14 +166,15 @@ final class HotwordAudioStreamManager {
|
|||||||
bestEffortPropagateError(e.getMessage());
|
bestEffortPropagateError(e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
mAppOpsManager.finishOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD,
|
mAppOpsManager.finishOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD,
|
||||||
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
|
mVoiceInteractorUid, mVoiceInteractorPackageName,
|
||||||
mVoiceInteractorIdentity.attributionTag);
|
mVoiceInteractorAttributionTag);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bestEffortPropagateError(
|
bestEffortPropagateError(
|
||||||
"Failed to obtain RECORD_AUDIO_HOTWORD permission for "
|
"Failed to obtain RECORD_AUDIO_HOTWORD permission for voice interactor with"
|
||||||
+ SoundTriggerSessionPermissionsDecorator.toString(
|
+ " uid=" + mVoiceInteractorUid
|
||||||
mVoiceInteractorIdentity));
|
+ " packageName=" + mVoiceInteractorPackageName
|
||||||
|
+ " attributionTag=" + mVoiceInteractorAttributionTag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -233,7 +233,8 @@ final class HotwordDetectionConnection {
|
|||||||
mVoiceInteractorIdentity = voiceInteractorIdentity;
|
mVoiceInteractorIdentity = voiceInteractorIdentity;
|
||||||
mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
|
mAppOpsManager = mContext.getSystemService(AppOpsManager.class);
|
||||||
mHotwordAudioStreamManager = new HotwordAudioStreamManager(mAppOpsManager,
|
mHotwordAudioStreamManager = new HotwordAudioStreamManager(mAppOpsManager,
|
||||||
mVoiceInteractorIdentity);
|
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
|
||||||
|
mVoiceInteractorIdentity.attributionTag);
|
||||||
mDetectionComponentName = serviceName;
|
mDetectionComponentName = serviceName;
|
||||||
mUser = userId;
|
mUser = userId;
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
|
|||||||
Reference in New Issue
Block a user