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.IBinder;
import android.os.PackageTagsList; import android.os.PackageTagsList;
import android.os.Process; import android.os.Process;
import android.os.SystemProperties;
import android.os.UserHandle; import android.os.UserHandle;
import android.service.voice.VoiceInteractionManagerInternal; import android.service.voice.VoiceInteractionManagerInternal;
import android.service.voice.VoiceInteractionManagerInternal.HotwordDetectionServiceIdentity; import android.service.voice.VoiceInteractionManagerInternal.HotwordDetectionServiceIdentity;
@@ -68,6 +69,8 @@ public final class AppOpsPolicy implements AppOpsManagerInternal.CheckOpsDelegat
private static final String ACTIVITY_RECOGNITION_TAGS = private static final String ACTIVITY_RECOGNITION_TAGS =
"android:activity_recognition_allow_listed_tags"; "android:activity_recognition_allow_listed_tags";
private static final String ACTIVITY_RECOGNITION_TAGS_SEPARATOR = ";"; 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 @NonNull
private final Object mLock = new Object(); 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. // The HotwordDetectionService APIs aren't ready yet for Auto or TV.
return !(pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE) if (pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)
|| pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK)); || pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK)) {
return false;
}
return SYSPROP_HOTWORD_DETECTION_SERVICE_REQUIRED;
} }
@Override @Override

View File

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