RESTRICT AUTOMERGE Disable the Trusted Hotword requirement am: 0e7131f309
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15606284 Change-Id: Ib9aea75358729ae4bff436c02679fcd43aab2aa2
This commit is contained in:
@@ -196,9 +196,8 @@ public final class AppOpsPolicy implements AppOpsManagerInternal.CheckOpsDelegat
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isHotwordDetectionServiceRequired(PackageManager pm) {
|
private static boolean isHotwordDetectionServiceRequired(PackageManager pm) {
|
||||||
// The HotwordDetectionService APIs aren't ready yet for Auto or TV.
|
// Usage of the HotwordDetectionService won't be enforced until a later release.
|
||||||
return !(pm.hasSystemFeature(PackageManager.FEATURE_AUTOMOTIVE)
|
return false;
|
||||||
|| pm.hasSystemFeature(PackageManager.FEATURE_LEANBACK));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -125,16 +125,25 @@ public class SoundTriggerMiddlewarePermission implements ISoundTriggerMiddleware
|
|||||||
* originator temporarily doesn't have the right permissions to use this service.
|
* originator temporarily doesn't have the right permissions to use this service.
|
||||||
*/
|
*/
|
||||||
private void enforcePermissionsForPreflight(@NonNull Identity identity) {
|
private void enforcePermissionsForPreflight(@NonNull Identity identity) {
|
||||||
enforcePermissionForPreflight(mContext, identity, RECORD_AUDIO);
|
enforcePermissionForPreflight(mContext, identity, RECORD_AUDIO,
|
||||||
enforcePermissionForPreflight(mContext, identity, CAPTURE_AUDIO_HOTWORD);
|
/* allowSoftDenial= */ true);
|
||||||
|
enforcePermissionForPreflight(mContext, identity, CAPTURE_AUDIO_HOTWORD,
|
||||||
|
/* allowSoftDenial= */ true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws a {@link SecurityException} iff the originator has permission to receive data.
|
* Throws a {@link SecurityException} iff the originator has permission to receive data.
|
||||||
*/
|
*/
|
||||||
void enforcePermissionsForDataDelivery(@NonNull Identity identity, @NonNull String reason) {
|
void enforcePermissionsForDataDelivery(@NonNull Identity identity, @NonNull String reason) {
|
||||||
enforcePermissionForDataDelivery(mContext, identity, RECORD_AUDIO,
|
// SoundTrigger data is treated the same as Hotword-source audio. This should incur the
|
||||||
reason);
|
// HOTWORD op instead of the RECORD_AUDIO op. The RECORD_AUDIO permission is still required,
|
||||||
|
// and since this is a data delivery check, soft denials aren't accepted.
|
||||||
|
enforcePermissionForPreflight(mContext, identity, RECORD_AUDIO,
|
||||||
|
/* allowSoftDenial= */ false);
|
||||||
|
int hotwordOp = AppOpsManager.strOpToOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD);
|
||||||
|
mContext.getSystemService(AppOpsManager.class).noteOpNoThrow(hotwordOp, identity.uid,
|
||||||
|
identity.packageName, identity.attributionTag, reason);
|
||||||
|
|
||||||
enforcePermissionForDataDelivery(mContext, identity, CAPTURE_AUDIO_HOTWORD,
|
enforcePermissionForDataDelivery(mContext, identity, CAPTURE_AUDIO_HOTWORD,
|
||||||
reason);
|
reason);
|
||||||
}
|
}
|
||||||
@@ -163,20 +172,25 @@ public class SoundTriggerMiddlewarePermission implements ISoundTriggerMiddleware
|
|||||||
/**
|
/**
|
||||||
* Throws a {@link SecurityException} if originator permanently doesn't have the given
|
* Throws a {@link SecurityException} if originator permanently doesn't have the given
|
||||||
* permission.
|
* permission.
|
||||||
* Soft (temporary) denials are considered OK for preflight purposes.
|
|
||||||
*
|
*
|
||||||
* @param context A {@link Context}, used for permission checks.
|
* @param context A {@link Context}, used for permission checks.
|
||||||
* @param identity The identity to check.
|
* @param identity The identity to check.
|
||||||
* @param permission The identifier of the permission we want to check.
|
* @param permission The identifier of the permission we want to check.
|
||||||
|
* @param allowSoftDenial If true, the operation succeeds even for soft (temporary) denials.
|
||||||
*/
|
*/
|
||||||
|
// TODO: Consider splitting up this method instead of using `allowSoftDenial`, to make it
|
||||||
|
// clearer when soft denials are not allowed.
|
||||||
private static void enforcePermissionForPreflight(@NonNull Context context,
|
private static void enforcePermissionForPreflight(@NonNull Context context,
|
||||||
@NonNull Identity identity, @NonNull String permission) {
|
@NonNull Identity identity, @NonNull String permission, boolean allowSoftDenial) {
|
||||||
final int status = PermissionUtil.checkPermissionForPreflight(context, identity,
|
final int status = PermissionUtil.checkPermissionForPreflight(context, identity,
|
||||||
permission);
|
permission);
|
||||||
switch (status) {
|
switch (status) {
|
||||||
case PermissionChecker.PERMISSION_GRANTED:
|
case PermissionChecker.PERMISSION_GRANTED:
|
||||||
case PermissionChecker.PERMISSION_SOFT_DENIED:
|
|
||||||
return;
|
return;
|
||||||
|
case PermissionChecker.PERMISSION_SOFT_DENIED:
|
||||||
|
if (allowSoftDenial) {
|
||||||
|
return;
|
||||||
|
} // else fall through
|
||||||
case PermissionChecker.PERMISSION_HARD_DENIED:
|
case PermissionChecker.PERMISSION_HARD_DENIED:
|
||||||
throw new SecurityException(
|
throw new SecurityException(
|
||||||
String.format("Failed to obtain permission %s for identity %s", permission,
|
String.format("Failed to obtain permission %s for identity %s", permission,
|
||||||
|
|||||||
@@ -23,11 +23,8 @@ import static android.service.voice.HotwordDetectionService.AUDIO_SOURCE_MICROPH
|
|||||||
import static android.service.voice.HotwordDetectionService.INITIALIZATION_STATUS_UNKNOWN;
|
import static android.service.voice.HotwordDetectionService.INITIALIZATION_STATUS_UNKNOWN;
|
||||||
import static android.service.voice.HotwordDetectionService.KEY_INITIALIZATION_STATUS;
|
import static android.service.voice.HotwordDetectionService.KEY_INITIALIZATION_STATUS;
|
||||||
|
|
||||||
import static com.android.server.voiceinteraction.SoundTriggerSessionPermissionsDecorator.enforcePermissionForPreflight;
|
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
import android.annotation.NonNull;
|
||||||
import android.annotation.Nullable;
|
import android.annotation.Nullable;
|
||||||
import android.app.AppOpsManager;
|
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.ContentCaptureOptions;
|
import android.content.ContentCaptureOptions;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -935,11 +932,12 @@ final class HotwordDetectionConnection {
|
|||||||
// TODO: Share this code with SoundTriggerMiddlewarePermission.
|
// TODO: Share this code with SoundTriggerMiddlewarePermission.
|
||||||
private void enforcePermissionsForDataDelivery() {
|
private void enforcePermissionsForDataDelivery() {
|
||||||
Binder.withCleanCallingIdentity(() -> {
|
Binder.withCleanCallingIdentity(() -> {
|
||||||
enforcePermissionForPreflight(mContext, mVoiceInteractorIdentity, RECORD_AUDIO);
|
// Hack to make sure we show the mic privacy-indicator since the Trusted Hotword
|
||||||
int hotwordOp = AppOpsManager.strOpToOp(AppOpsManager.OPSTR_RECORD_AUDIO_HOTWORD);
|
// requirement isn't being enforced for now. Normally, we would note the HOTWORD op here
|
||||||
mContext.getSystemService(AppOpsManager.class).noteOpNoThrow(hotwordOp,
|
// instead.
|
||||||
mVoiceInteractorIdentity.uid, mVoiceInteractorIdentity.packageName,
|
enforcePermissionForDataDelivery(mContext, mVoiceInteractorIdentity,
|
||||||
mVoiceInteractorIdentity.attributionTag, OP_MESSAGE);
|
RECORD_AUDIO, OP_MESSAGE);
|
||||||
|
|
||||||
enforcePermissionForDataDelivery(mContext, mVoiceInteractorIdentity,
|
enforcePermissionForDataDelivery(mContext, mVoiceInteractorIdentity,
|
||||||
CAPTURE_AUDIO_HOTWORD, OP_MESSAGE);
|
CAPTURE_AUDIO_HOTWORD, OP_MESSAGE);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user