Merge "Revert^2 "[hotword] remove exemption for pixel devices"" into udc-dev

This commit is contained in:
Felix Oghina
2023-05-19 19:06:49 +00:00
committed by Android (Google) Code Review
2 changed files with 30 additions and 14 deletions

View File

@@ -37,6 +37,7 @@ import android.os.Bundle;
import android.os.IBinder;
import android.os.PackageTagsList;
import android.os.Process;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.service.voice.VoiceInteractionManagerInternal;
import android.service.voice.VoiceInteractionManagerInternal.HotwordDetectionServiceIdentity;
@@ -68,6 +69,8 @@ public final class AppOpsPolicy implements AppOpsManagerInternal.CheckOpsDelegat
private static final String ACTIVITY_RECOGNITION_TAGS =
"android:activity_recognition_allow_listed_tags";
private static final String ACTIVITY_RECOGNITION_TAGS_SEPARATOR = ";";
private static final boolean SYSPROP_HOTWORD_DETECTION_SERVICE_REQUIRED =
SystemProperties.getBoolean("ro.hotword.detection_service_required", false);
@NonNull
private final Object mLock = new Object();
@@ -199,10 +202,16 @@ public final class AppOpsPolicy implements AppOpsManagerInternal.CheckOpsDelegat
}
}
private static boolean isHotwordDetectionServiceRequired(PackageManager pm) {
/**
* @hide
*/
public static boolean isHotwordDetectionServiceRequired(PackageManager pm) {
// The HotwordDetectionService APIs aren't ready yet for Auto or TV.
return !(pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)
|| pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK));
if (pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)
|| pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
return false;
}
return SYSPROP_HOTWORD_DETECTION_SERVICE_REQUIRED;
}
@Override

View File

@@ -84,6 +84,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.app.IHotwordRecognitionStatusCallback;
import com.android.internal.infra.AndroidFuture;
import com.android.server.LocalServices;
import com.android.server.policy.AppOpsPolicy;
import com.android.server.voiceinteraction.VoiceInteractionManagerServiceImpl.DetectorRemoteExceptionListener;
import java.io.Closeable;
@@ -742,18 +743,24 @@ abstract class DetectorSession {
void enforcePermissionsForDataDelivery() {
Binder.withCleanCallingIdentity(() -> {
synchronized (mLock) {
int result = PermissionChecker.checkPermissionForPreflight(
mContext, RECORD_AUDIO, /* pid */ -1, mVoiceInteractorIdentity.uid,
mVoiceInteractorIdentity.packageName);
if (result != PermissionChecker.PERMISSION_GRANTED) {
throw new SecurityException(
"Failed to obtain permission RECORD_AUDIO for identity "
+ mVoiceInteractorIdentity);
if (AppOpsPolicy.isHotwordDetectionServiceRequired(mContext.getPackageManager())) {
int result = PermissionChecker.checkPermissionForPreflight(
mContext, RECORD_AUDIO, /* pid */ -1, mVoiceInteractorIdentity.uid,
mVoiceInteractorIdentity.packageName);
if (result != PermissionChecker.PERMISSION_GRANTED) {
throw new SecurityException(
"Failed to obtain permission RECORD_AUDIO for identity "
+ mVoiceInteractorIdentity);
}
int hotwordOp = AppOpsManager.strOpToOp(
AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD);
mAppOpsManager.noteOpNoThrow(hotwordOp,
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
mVoiceInteractorIdentity.attributionTag, HOTWORD_DETECTION_OP_MESSAGE);
} else {
enforcePermissionForDataDelivery(mContext, mVoiceInteractorIdentity,
RECORD_AUDIO, HOTWORD_DETECTION_OP_MESSAGE);
}
int hotwordOp = AppOpsManager.strOpToOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD);
mAppOpsManager.noteOpNoThrow(hotwordOp,
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
mVoiceInteractorIdentity.attributionTag, HOTWORD_DETECTION_OP_MESSAGE);
enforcePermissionForDataDelivery(mContext, mVoiceInteractorIdentity,
CAPTURE_AUDIO_HOTWORD, HOTWORD_DETECTION_OP_MESSAGE);
}