Merge "Revert^2 "[hotword] remove exemption for pixel devices"" into udc-dev am: 8e3c3bd264 am: 535e6b4cc5
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23260396 Change-Id: I02fa4997c50130709892752d9b73502e9f2140e8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user